The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

Don't be helpless: What might be the reason for a "Path not found" error?
Jun 6, 2012
Post comments count 0
Post likes count 0

Don't be helpless: What might be the reason for a "Path not found" error?

Raymond Chen
Raymond Chen

Internally at Microsoft, we have a programmer's tool which I will call Program Q. On the peer-to-peer mailing list for Program Q, somebody asked the following question: When I try to do a , instead of opening an editor window where I can modify the template, I get the following error: Can you help resolve this error? Okay, there is already everything you need in the error message. The program even converted the error number to error text for you. You just have to read it and think about what it's telling you. The file is . Therefore the path is . I leave you to determine the next step in ...

Microspeak: Turds
Jun 5, 2012
Post comments count 0
Post likes count 0

Microspeak: Turds

Raymond Chen
Raymond Chen

In Microspeak, a turd is a graphics glitch which results in old pixels appearing on the screen when they shouldn't. Perhaps they are not being erased properly, or instead of being erased, they move to an unwanted location. The source of the problem could be failing to mark a region for redrawing after something changed, or it could be that the drawing code ran into a problem and failed to draw over the old pixels. The problem might be that the code whose job it is to remove the object from the screen ran into a problem and didn't actually remove it, resulting in an on-screen object that nobody really is keeping t...

Why does PrintWindow hate CS_PARENTDC? Because EVERYBODY hates CS_PARENTDC!
Jun 4, 2012
Post comments count 0
Post likes count 0

Why does PrintWindow hate CS_PARENTDC? Because EVERYBODY hates CS_PARENTDC!

Raymond Chen
Raymond Chen

Commenter kero wants to know why the function hates . (And , and .) Because everybody hates ! (And , and .) We saw earlier that these class styles violate widely-held assumptions about how drawing works. I mean, who would have thought that asking for two device contexts would give you the same one back twice? Or that changes to one device context would secretly modify another (because they're really the same)? Or that a window procedure assumes that it will see only one device context ever? The function is really in a pickle when faced with a window with one of these class styles, because the whole point o...

The time I watched a total lunar eclipse from the top of a mountain
Jun 1, 2012
Post comments count 0
Post likes count 0

The time I watched a total lunar eclipse from the top of a mountain

Raymond Chen
Raymond Chen

One of my colleagues loves doing outdoorsy things, and he also loves space and astronomy. Many years ago, he invited a small number of us on an outing that combined both of his interests: A hike up a mountain to view the total lunar eclipse. Since an eclipse does not wait until you're ready, it's kind of important to stay on schedule or you'll end up missing the show. We started while it was still light out, and the people who were not seasoned hikers (like me) had to tough it out and keep going, because there was very little time in the schedule for taking breaks. (Because my colleague has been hiking so long t...

How do I prefetch data into my memory-mapped file?
Jun 1, 2012
Post comments count 0
Post likes count 0

How do I prefetch data into my memory-mapped file?

Raymond Chen
Raymond Chen

A customer created a memory mapping on a large file and found that when the memory manager wanted to page in data from that file, it did so in 32KB chunks. The customer wanted to know if there was a way to increase the chunk size for efficiency. The memory manager decides the chunk size for memory-mapped files, and the chunk size is currently set to eight pages, which on a system with 4KB pages, comes out to 32KB chunks. (Note that this chunk size is an internal parameter and is subject to change in future versions of Windows. I'm telling a story, not providing formal documentation.) You have a few options. Th...

What happens if I call KillTimer with a NULL hwnd?
May 31, 2012
Post comments count 0
Post likes count 0

What happens if I call KillTimer with a NULL hwnd?

Raymond Chen
Raymond Chen

A customer discovered a bug in their code and wanted some information on how serious it was, so they could assess how urgently they need to issue a fix. We have code that calls with a valid window handle, but then we destroy the window before we get around to calling . When we finally do call , we do so with a window handle. The calls are probably harmless, but are we leaking the timers? The customer's real concern was actually in the part of the problem they thought was a point of little concern. The window manager cleans up orphaned timers when the associated window is destroyed, so there is no timer leak...

What does a STATUS_OBJECT_TYPE_MISMATCH exception in LeaveCriticalSection mean?
May 30, 2012
Post comments count 0
Post likes count 0

What does a STATUS_OBJECT_TYPE_MISMATCH exception in LeaveCriticalSection mean?

Raymond Chen
Raymond Chen

It means the same thing as a exception.

Hazards of spelling autocorrection: defiance
May 29, 2012
Post comments count 0
Post likes count 0

Hazards of spelling autocorrection: defiance

Raymond Chen
Raymond Chen

On an internal mailing list, a colleague asked for some recommendations on a webcam. I was wondering if there are any models I should avoid or defiantly get. I got this mental image of my colleague giving the salesperson the finger as he handed over his credit card. My colleague explained, "That's an error I frequently make because Outlook by default autocorrects 'definatly' to 'defiantly' instead of 'definitely'. You should see the reaction from my manager when he asks me to do something and I write back, 'I'll defiantly do that.' I'm a terrible speller. That's why I went into math: Only single letters." Bu...

If my window hosts multiple windowless ActiveX controls, which one do I call IOleInPlaceActiveObject::TranslateAccelerator and IOleInPlaceObjectWindowless::OnWindowMessage on?
May 28, 2012
Post comments count 0
Post likes count 0

If my window hosts multiple windowless ActiveX controls, which one do I call IOleInPlaceActiveObject::TranslateAccelerator and IOleInPlaceObjectWindowless::OnWindowMessage on?

Raymond Chen
Raymond Chen

Commenter Farproc asks how one goes about hosting two windowless ActiveX controls in a single window. In particular, "none of the documentation explains how to choose which control to send and on?" Actually, the documentation does say. The documentation for says, "Active in-place objects must always be given the first chance at translating accelerator keystrokes." So you pass the message to the active in-place object. Your window may host multiple windowless ActiveX controls, but at most one of them is the active object at a time. And most of the time, none of them will be active. For example, in Word, most...