The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

Oct 8, 2013
Post comments count 0
Post likes count 1

I wrote FAT on an airplane, for heaven’s sake

Raymond Chen

When you wrote code for 16-bit Windows, one of the things you spent time doing as part of performance tuning was deciding which functions should be grouped together in which segments. Code in 16-bit Windows executed out of code segments, each of which could be up to 64KB in size. When a code segment was loaded from disk, the entire segment was loaded, and when it was discarded, the entire segment was discarded. This meant that you could affect your application's performance in significant ways by choosing which functions go in which segments. For example, it was to your advantage to keep functions that are call...

Oct 7, 2013
Post comments count 0
Post likes count 1

But instead, they decided to build the Great Wheel

Raymond Chen

I dreamed that Seattle was building its own version of the Eiffel Tower. Just like the original, except that it was also a thrill ride similar to Round Up but you are seated. It turns out that the city of Seattle accepted my subconscious's instructions to replicate another city's famous landmark, but the message wasn't received loud and clear. Instead of making an Eiffel Tower knock-off, we decided to make a London Eye knock-off.

Oct 7, 2013
Post comments count 0
Post likes count 1

Printing the contents of the clipboard as text to stdout

Raymond Chen

The takes its stdin and puts it on the clipboard. But how do you get it out? That's today's Little Program. (I guess we could call it .) Okay, what do we have here? We open the clipboard and try to get the Unicode text on it. We then look for the null terminator within the first 0x10000000 bytes. Why do I stop at 256MB? Because I'm lazy and this lets me avoid worrying about integer overflow. This is a Little Program, remember. If you pass the command line switch, then the output is printed to stdout as the Unicode string itself. If you pass the command line switch, then the output is converted to AN...

Oct 4, 2013
Post comments count 0
Post likes count 1

What's the difference between CopyIcon and DuplicateIcon?

Raymond Chen

There are two functions that can be used to create one icon that is identical to another. One of them is . The other is . What's the difference? There isn't any difference. Both functions clone an icon. In fact, their implementations are basically line-for-line identical. Originally, there was just one function to clone an icon: . Windows 3.0 introduced Program Manager, and the developers of Program Manager wrote their own function called . Why? I have no idea. My guess is that they didn't realize that such a function already existed, so they inadvertently reinvented the wheel. Windows NT 3.1 came a...

Oct 3, 2013
Post comments count 0
Post likes count 1

The relationship between module resources and resource-derived objects in 32-bit Windows

Raymond Chen

Last time, we saw how 16-bit Windows converted resources attached to an EXE or DLL file (which I called module resources for lack of a better term) to user interface resources. As a refresher: During the conversion from 16-bit Windows to 32-bit Windows, some of these rules changed. Specifically, icons, cursors, and accelerator tables are no longer references to the resource. Instead, the resource is treated as a template from which the actual user interface resource is constructed. Uh-oh, what's up with those asterisks? Let's start with accelerator tables. In order to simulate the reference semantics of 16-...

Oct 2, 2013
Post comments count 0
Post likes count 1

The relationship between module resources and resource-derived objects in 16-bit Windows

Raymond Chen

As we saw last time, in 16-bit Windows, resources attached to an EXE or DLL file (which I called module resources for lack of a better term) were recorded in memory as discardable global memory blocks, and the window manager accessed them directly as needed. For example, if you had an icon or a cursor, the or was really a resource handle, and when the window manager needed to draw the icon or cursor, it would cast the icon or cursor handle to a global handle (since that's what it was under the hood), then call to access the raw resource data in order to copy the pixels onto the screen. Similarly, accelerator...

Oct 1, 2013
Post comments count 0
Post likes count 1

The management of memory for resources in 16-bit Windows, redux

Raymond Chen

Some time ago, I briefly ran down how 16-bit Windows managed memory for resources. But there's a detail that I neglected to mention: Ownership. As we saw, a resource handle was really a pointer to the resource directory entry of the resource from the corresponding module. This could be done with a 16-bit pointer because the segment portion of the pointer could be inferred from the module the resource belonged to. In fact, since modules could be relocated in memory at run time due to compaction, you had better not try to remember the segment portion of the pointer since it could change! The function located t...

Sep 30, 2013
Post comments count 0
Post likes count 1

Sometimes my dreams are entirely uneventful

Raymond Chen

I dreamed that I was washing dishes with my lovely wife.

Sep 30, 2013
Post comments count 0
Post likes count 1

Playing a sound every time the foreground window changes

Raymond Chen

Today's Little Program plays a little sound every time the foreground window changes. One of my colleagues wondered if such a program was possible, "so that I stop accidentally typing the second halves of paragraphs into windows that pop up and steal focus." It's not clear whether this program will actually solve the bigger problem, but it was fun writing the program, and maybe you can use it for something. This program installs an accessibility hook that listens for changes to the system foreground. And when it happens, we play a little sound. I chose the Windows 7 Speech Misrecognition sound because ...