The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

Charles Petzold is back with another edition of Programming Windows
May 17, 2012
Post comments count 0
Post likes count 0

Charles Petzold is back with another edition of Programming Windows

Raymond Chen
Raymond Chen

Back in the day (and perhaps still true today), Charles Petzold's Programming Windows was the definitive source for learning to program Windows. The book is so old that even I used it to learn Windows programming, back when everything was 16-bit and uphill both ways. The most recent edition is Programming Windows, 5th Edition, which was published way back in 1998. What has he been doing since then? My guess would have been "sitting on a beach in Hawaiʻi," but apparently he's been writing books on C# and Windows Forms and WPF and Silverlight. Hey, I could still be right: Maybe he writes the books while s...

How to view the stack of threads that were terminated as part of process teardown from the kernel debugger
May 17, 2012
Post comments count 0
Post likes count 0

How to view the stack of threads that were terminated as part of process teardown from the kernel debugger

Raymond Chen
Raymond Chen

As we saw some time ago, process shutdown is a multi-phase affair. After you call , all the threads are forcibly terminated. After that's done, each DLL is sent a notification. You may be debugging a problem with handling that suggests that some of those threads were not cleaned up properly. For example, you might assert that a reference count is zero, and you find during process shutdown that this assertion sometimes fires. Maybe you terminated a thread before it got a chance to release its reference? How can you test this theory if the thread is already gone? It so happens that when all the threads are te...

Sure, we do that: Context menu edition
May 16, 2012
Post comments count 0
Post likes count 0

Sure, we do that: Context menu edition

Raymond Chen
Raymond Chen

A customer reported a problem that occurred only when they installed a particular application. If they uninstalled it, then the problem went away. After installing the application, the "Run As" context menu option stopped working. The customer didn't provide any other details, but we were able to make an educated guess as to what was going on. A common programming error in context menu extensions occurs in extensions which add only one menu item. These extensions ignore the parameters to the and simply assume that the only reason the method can be called is if the user selected their menu item. After all, if y...

Microspeak: The parking lot
May 15, 2012
Post comments count 0
Post likes count 0

Microspeak: The parking lot

Raymond Chen
Raymond Chen

Mike Dunn wonders what the Microspeak term parking lot means. I'm not familiar with this term either, and the first document I turned up during my search was a PowerPoint presentation that said "Avoid using Microsoft jargon terms, such as parking lot and dogfood." Yeah, that wasn't much help. From what I can gather, the term parking lot started out as a term used during brainstorming sessions. You've got a bunch of people in a conference room tossing out all sorts of ideas. The traditional way of organizing the ideas is to write each one on a Post-It® note and stick it on the whiteboard. As more and more...

What is the historical reason for MulDiv(1, -0x80000000, -0x80000000) returning 2?
May 14, 2012
Post comments count 0
Post likes count 0

What is the historical reason for MulDiv(1, -0x80000000, -0x80000000) returning 2?

Raymond Chen
Raymond Chen

Commenter rs asks, "Why does Windows (historically) return 2 for while Wine returns zero?" The function multiplies the first two parameters and divides by the third. Therefore, the mathematically correct answer for MulDiv(1, -0x80000000, -0x80000000) is 1, because a × b ÷ b = a for all nonzero b. So both Windows and Wine get it wrong. I don't know why Wine gets it wrong, but I dug through the archives to figure out what happened to Windows. First, some background. What's the point of the function anyway? Back in the days of 16-bit Windows, floating point was very ...

Warum deine Mutter Deutsch spricht
May 11, 2012
Post comments count 0
Post likes count 0

Warum deine Mutter Deutsch spricht

Raymond Chen
Raymond Chen

This upcoming Sunday is Mother's Day in the United States. In recognition of the holiday last year, a local church displayed the following message on its message board: "God couldn't be / everywhere / so God made mothers / German speaking." This explains why your mother speaks German. POIDH The church in question has an evening German-language service, and the advertisement for that service juxtaposed against the Jewish proverb produced an unexpected result.

When you crash on a mov ebx, eax instruction, there aren't too many obvious explanations, so just try what you can
May 11, 2012
Post comments count 0
Post likes count 0

When you crash on a mov ebx, eax instruction, there aren't too many obvious explanations, so just try what you can

Raymond Chen
Raymond Chen

A computer running some tests encountered a mysterious crash: A colleague of mine quickly diagnosed the proximate cause. *Something* marked the code page PAGE_READWRITE, instead of PAGE_EXECUTE_READ. I suspect a bug in a driver. FOO is just a victim here. This diagnosis was met with astonishment. "Wow! What made you think to check the protection on the code page?" Well, let's see. We're crashing on a instruction. This does not access memory; it's a register-to-register operation. There's no way a properly functioning CPU can raise an exception on this instruction. At this point, what possibilities...

Cheap amusement: Searching for spelling errors in the registry
May 10, 2012
Post comments count 0
Post likes count 0

Cheap amusement: Searching for spelling errors in the registry

Raymond Chen
Raymond Chen

One source of cheap amusement is searching for spelling errors in the registry. For example, one program tried to register a new file extension, or at least they tried, except that they spelled wrong. And they wonder why that feature never worked. My discovery was that my registry contained the mysterious key . After some debugging, I finally found the culprit. There was a program on my computer that did the equivalent of this: One of my colleagues remarked, "With enough force, any peg will fit in any hole." I suspect that the code was not that aggressively wrong. It was probably something more subtle...

How do I hide a window without blocking on it?
May 9, 2012
Post comments count 0
Post likes count 0

How do I hide a window without blocking on it?

Raymond Chen
Raymond Chen

A customer was working on improving their application startup performance. They found that if their application was launched immediately after a fresh boot, the act of dismissing their splash screen was taking over 5% of their boot time. Their code removed the splash screen by calling . They suspect that the splash screen thread has, for some reason, stopped responding to messages, and while an investigation into that avenue was undertaken, a parallel investigation into reducing the cost of hiding the splash screen was also begun. One of the things they tried was to remove the style and call but they found tha...