The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

Aug 15, 2006
Post comments count 0
Post likes count 0

Cool web site: Bill Monk

Raymond Chen

One of my friends introduced me to Bill Monk, which is like PayPal but without the money. You and your friends sign up, and then you can let the site keep track of who owe whom how much. Of course, whether this is useful to you depends on how you and your friends actually deal with money and small debts. With some of my friends, we use the "It'll all even out in the end" strategy. We'll take turns paying for dinner and events based on the "I think it's my turn" honor system. With another group of friends, the bills are neatly tabulated and reckonings sent out by email for settlement. They use this system sinc...

Aug 15, 2006
Post comments count 0
Post likes count 1

Do not change program semantics in the debug build

Raymond Chen

What you don't want is a problem that goes away when you debug it. It is expected that a program have additional debugging code inside blocks. After all, that's why it's a debug build. But what you definitely don't want to do is have that debugging to fundamentally change the program's behavior. You can perform additional validation. You can raise assertion failures. You can track resources. It can be slower and consume additional resources, but you had better not alter code flow. This code is wrong: The debug version behaves fundamentally differently from the retail version. If somebody calls this functio...

Aug 14, 2006
Post comments count 0
Post likes count 0

The cultural anthropology of getting on a bicycle

Raymond Chen

I can tell where you grew up by watching you get on a bicycle. Well, sort of. In my limited experience, I've observed two distinct ways of getting on a bicycle. The first is what I'll call the Chinese method, since it's the dominant technique in China, Taiwan, and Japan, as far as I can tell. To get on a bicycle using the Chinese method, stand to the side of the bicycle (let's say, the left side) with both hands on the handlebars in the normal riding position. Put the left pedal at the bottom of its stroke and place your left foot on it. Now ride the bicycle like a scooter, pushing off with your right foot, unt...

Aug 14, 2006
Post comments count 0
Post likes count 1

Why can't I see all of the 4GB of RAM in my machine?

Raymond Chen

Here's a question that came from a customer: I have set my boot options to /3GB /NOPAE. Even though the server has 4GB of physical memory, we see only 3.5GB of physical memory on the server after it boots up. However, when we change the boot options to /PAE, we can observe 4GB of memory. Furthermore, when I enable only /PAE, even though the physical memory is 4GB, I can see 4GB. Without /PAE, even though the physical memory is 4GB, I can see 3.5GB. What is the reason for this? Remember that in the absence of the /PAE switch, the Windows memory manager is limited to a 4GB physical address space. Most of that ad...

Aug 11, 2006
Post comments count 0
Post likes count 0

Exploiting the inattentive, episode 2: The unlabeled line

Raymond Chen

In Episode 1 we learned that "Snide" brand powdered laundry detergent comes with a scoop that holds 5/8 cup detergent, even though the directions call for only 3/8 cup. The intent here is to get people to use more detergent than necessary, thereby increasing sales. A box of detergent which should be sufficient for 30 loads ends up running out after only 18. Consider it "technically legal" mislabeling. I returned to Snide brand powdered laundry detergent this week and discovered that they have taken this little trick to a new level. The markings on the side of the scoop read like this: ...

Aug 11, 2006
Post comments count 0
Post likes count 2

Why does SetWindowsHookEx take an HINSTANCE parameter?

Raymond Chen

An anonymous commenter asked why the function takes an parameter if the first thing it's going to do is convert the instance handle into a file name. Because that's not how it worked in 16-bit Windows. In 16-bit Windows there was no such thing as hook injection. All 16-bit Windows applications ran in the same address space, so there was no need to inject anything anywhere. Consequently, there was no need to convert the instance handle into a file name in order to inject it. Instead, the instance handle was used to increment the reference count on the module so that the hook procedure wouldn't get unloaded w...

Aug 10, 2006
Post comments count 0
Post likes count 0

Space scientist James Van Allen (1914–2006)

Raymond Chen

Discoverer of the Van Allen radiation belts and one of the TIME magazine men of the year for 1960 James Van Allen died yesterday. (What a coincidence. What are the odds that the person to discover the Van Allen radiation belts would also be named Van Allen?) I never met the man, but I met his granddaughter. She has an amazing facility with languages and became fluent in Japanese after spending a year as an exchange student. Her Japanese was so good that at one point, a girl came up to her and asked, "How do you get your skin so pale?", mistaking her for a native who had undergone some sort of bleaching process ...

Aug 10, 2006
Post comments count 0
Post likes count 0

One way people abused hooks in 16-bit Windows

Raymond Chen

We saw last time how windows hooks were implemented in 16-bit Windows. Even though the was an opaque data type that should have been treated like a handle, many programs "knew enough to be dangerous" and took advantage of the fact that the was just a pointer to the previous hook procedure. The most common way of abusing this knowledge was by unhooking from the windows hook chain the wrong way. Instead of calling the function to unhook a windows hook, they called again! Specifically, they removed their hook by simply reinstalling the previous hook at the head of the chain: This code worked in spite of i...

Aug 9, 2006
Post comments count 0
Post likes count 0

How were window hooks implemented in 16-bit Windows?

Raymond Chen

The mechanism for keeping track of window hooks was very different in 16-bit Windows. The functions involved were , and . The first two functions still exist today, but the third one has been replaced with a macro: Disclaimer: All code below is "reconstructed from memory". The spirit of the code is intact, but the precise details may be off. To install a windows hook in 16-bit Windows, you started by calling : The return value from must be saved in a global variable, which we gave the somewhat provocative name . The hook procedure itself went something like this: And then when you were finished, you...