The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

ReadDirectoryChangesW reads directory changes, but what if the directory doesn’t change?
Aug 12, 2011
Post comments count 0
Post likes count 1

ReadDirectoryChangesW reads directory changes, but what if the directory doesn’t change?

Raymond Chen
Raymond Chen

Not all changes within a directory result in the directory changing.

The ways people mess up IUnknown::QueryInterface, episode 4
Aug 11, 2011
Post comments count 0
Post likes count 0

The ways people mess up IUnknown::QueryInterface, episode 4

Raymond Chen
Raymond Chen

One of the rules for is so obvious that nobody even bothers to state it explicitly as a rule: "If somebody asks you for an interface, and you return , then the pointer you return must point to the interface the caller requested." (This feels like the software version of dumb warning labels.) During compatibility testing for Windows Vista, we found a shell extension that behaved rather strangely. Eventually, the problem was traced to a broken implementation which depended subtly on the order in which interfaces were queried. The shell asked for the and interfaces in the following order: One parti...

Slim reader/writer locks don't remember who the owners are, so you'll have to find them some other way
Aug 10, 2011
Post comments count 0
Post likes count 0

Slim reader/writer locks don't remember who the owners are, so you'll have to find them some other way

Raymond Chen
Raymond Chen

The slim reader/writer lock is a very convenient synchronization facility, but one of the downsides is that it doesn't keep track of who the current owners are. When your thread is stuck waiting to acquire a slim reader/writer lock, a natural thing to want to know is which threads own the resource your stuck thread waiting for. Since there's not facility for going from the waiting thread to the owning threads, you'll just have to find the owning threads some other way. Here's the thread that is waiting for the lock in shared mode: Okay, how do you find the thread that owns the lock? First, slim reader/wr...

Why does the Shift+F10 menu differ from the right-click menu?
Aug 9, 2011
Post comments count 0
Post likes count 0

Why does the Shift+F10 menu differ from the right-click menu?

Raymond Chen
Raymond Chen

The Shift+F10 key is a keyboard shortcut for calling up the context menu on the selected item. but if you look closely, you might discover that the right-click menu and the Shift+F10 menu differ in subtle ways. Shouldn't they be the same? After all, that's the point of being a keyboard shortcut, right? Let's set aside the possibility that a program might be intentionally making them different, in violation of UI guidelines. For example, a poorly-designed program might use the message as the trigger to display the context menu instead of using the message, in which case Shift+F10 won't do anything at all. Or t...

What does the CreateProcess function do if there is no space between the program name and the arguments?
Aug 8, 2011
Post comments count 0
Post likes count 0

What does the CreateProcess function do if there is no space between the program name and the arguments?

Raymond Chen
Raymond Chen

In an old discussion of why the function modifies its command line, commenter Random832 asked, "What if there is no space between the program name and arguments - like "cmd/?" - where does it put the null then?" The function requires a space between the program name and arguments. If you leave out the space, then the arguments are considered as part of the program name (and you'll almost certainly get back). It sounds like Random832 has confused command line parsing with command line parsing. Clearly the two parsers are different; you can see this even without playing with spaces between the program na...

Menu item states are not reliable until they are shown because they aren't needed until then
Aug 5, 2011
Post comments count 0
Post likes count 0

Menu item states are not reliable until they are shown because they aren't needed until then

Raymond Chen
Raymond Chen

A question arrived from a customer (with the rather unhelpful subject line Question for Microsoft) wondering why, when they call and then ask for the states of the various menu items like , the menu item states don't reflect reality. The menu item states don't synchronize with reality until the user actually opens the system menu. There is no requirement that applications keep menu item states continuously in sync. After all, that's why we have messages like : To tell the application, "Whoa, we're about to show this menu, so you might want to comb its hair and pick the food out of its teeth so it can be seen by...

Why doesn't b match word boundaries correctly?
Aug 4, 2011
Post comments count 0
Post likes count 0

Why doesn't b match word boundaries correctly?

Raymond Chen
Raymond Chen

A colleague of mine was having trouble getting the metacharacter in a regular expression to work. Of course, when somebody asks a question like that, you first have to establish what their definition of "work" is. Fortunately, he provided some examples: "The last two entries are just sanity checks to make sure I didn't make some stupid mistake like passing the parameters in the wrong order. I want to search for a string that contains %1 with word boundaries on either side, something I would normally use \b for. Is there something special about the % character? Notice that the match succeeds when I look for the...

A shell extension is a guest in someone else's house; don't go changing the code page
Aug 3, 2011
Post comments count 0
Post likes count 0

A shell extension is a guest in someone else's house; don't go changing the code page

Raymond Chen
Raymond Chen

A customer reported a problem with their shell extension: We want to format a floating point number according to the user's default locale. We do this by calling to convert the value from floating point to text with a period (U+002E) as the decimal separator, then using to apply the user's preferred grouping character, decimal separator, etc. We found, however, that if the user is running in (say) German, we find that sometimes (but not always) the function follows the German locale and uses a comma (U+002C) as the decimal separator with no thousands separator. This format prevents the function from working...

An even easier way to get Windows Media Player to single-step a video
Aug 2, 2011
Post comments count 0
Post likes count 0

An even easier way to get Windows Media Player to single-step a video

Raymond Chen
Raymond Chen

Since my original article explaining how to get Windows Media Player to single-step a video, I've learned that there's an even easier way. Backward-stepping is dependent upon the codec; some of them will go backward to the previous keyframe. The person who tipped me off to this feature: The developer who implemented it. Remember: Sharing a tip does not imply that I approve of the situation that led to the need for the tip in the first place.