The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

Feb 6, 2014
Post comments count 0
Post likes count 1

If an asynchronous I/O completes synchronously, is the hEvent in the OVERLAPPED structure signaled anyway?

Raymond Chen

Yes. When an I/O completes (whether synchronously or asynchronously), the event is signaled and completion status notifications are queued. The function can be used to wait on an I/O that has already completed; it will merely return immediately. If you ask whether the I/O has completed, and the I/O completed synchronously, it will correctly report, "Yeah, of course it completed. Heck, it completed a long time ago!" In other words, you can logically treat the case of an asynchronous I/O request completing synchronously as if it had completed asynchronously. It just completes asynchronously before you even blin...

Feb 5, 2014
Post comments count 0
Post likes count 1

How do I prevent folders like My Pictures from being recreated?

Raymond Chen

Another converse of How do I programmatically create folders like My Pictures if they were manually deleted? and Why do folders like "My Pictures" come back after I delete them? is How do I prevent folders like My Pictures from being recreated? Starting in Windows 7, there is a group policy called Disable Known Folders which lets you specify a list of known folders which should be disabled. If somebody tries to create a known folder programmatically, the call will fail with . Note that this policy only blocks creation of the folder. If the folder already exists, then the policy has no effect. (You're l...

Feb 4, 2014
Post comments count 0
Post likes count 1

Racing email against a snail

Raymond Chen

The Windows team double-dogfoods Windows Server and Exchange Server, and while this is good for both products, it can be quite frustrating when something goes wrong. I remember back in the early days of the Windows 95 project, the mail servers once got so messed up that some email messages were not delivered for several days. After a colleague told me that he had just received an email message that I had sent several days earlier, I went to the library to look up the typical speed of a garden snail. (This was back in the days when you had to use an actual library to look up facts, and cat videos were avail...

Feb 3, 2014
Post comments count 0
Post likes count 0

The new research citation format, if students got to design it

Raymond Chen

References ¹ The Internets. ² Ibid. ³ Ibid.

Feb 3, 2014
Post comments count 0
Post likes count 1

How can I make a WNDPROC or DLGPROC a member of my C++ class?

Raymond Chen

Continuing my discussion of How can I make a callback function a member of my C++ class? Common special cases for wanting to use a member function as a callback function are the window procedure and its cousin the dialog procedure. The question, then, is where to put the reference data. Let's start with window procedures. The function and its close friend let you pass your reference data as the final parameter, prototyped as . As noted in the documentation, that value is passed back to the window procedure by the and messages as part of the structure. One of the first messages passed to a window is , s...

Jan 31, 2014
Post comments count 0
Post likes count 0

Why chicken wings dominate Super Bowl snack time

Raymond Chen

This upcoming Sunday is the biggest sports day of the year in the United States: The championship game for the professional American Football league. The entire country grinds to a halt. The most famous secondary effect of the game is the commercials. So many people watch the game that television advertisement costs are the highest for the Super Bowl, which means that companies will produce spectacular ads specifically for the Super Bowl, which means that more people watch the Super Bowl just for the ads. Another secondary effect of the Super Bowl is the spike in chicken wing sales. The United States chicken ...

Jan 31, 2014
Post comments count 0
Post likes count 1

Non-psychic debugging: If somebody's complaining that a collection should be empty but isn't, you might want to see what's in there

Raymond Chen

A programmer on the GHI team (yes, the same GHI team) reported that they were hitting an assertion failure using an internal library and asked for help debugging it. "Can somebody help me figure out which factory it is that did not get unregistered?" I didn't work on this internal library, but on the other hand I'm not afraid to look inside. Let's see what a looks like. No psychic powers needed here. I just followed my nose. The assertion says that a list is not empty. Therefore, we should look to see what is on the list. As a general rule, code is not intentionally written to be impossible to un...

Jan 30, 2014
Post comments count 0
Post likes count 1

Can process IDs be greater than 64000? Because we're seeing process IDs greater than 64000

Raymond Chen

A customer asked what to me was a very strange question. Can process IDs be greater than 64000? Because we're seeing process IDs greater than 64000. This is a strange question because the answer is right there: You're seeing process IDs greater than 64000 with your very own eyes. Do you doubt the evidence right there in front of you? It's like asking, "Is it possible to have an orange with no seeds? Because I have an orange with no seeds." We saw some time ago that process IDs can get very high indeed, although the kernel tries to keep the numbers small purely for cosmetic reasons. The customer explai...

Jan 29, 2014
Post comments count 0
Post likes count 1

One of my favorite error codes: Optional parameter missing

Raymond Chen

The error Optional parameter missing sounds awfully paradoxical, doesn't it. I mean, if the parameter is optional, why are you complaining that it's missing? This KB article explains why, specifically, the part that says, "If a parameter is omitted, the calling program must…". For those who don't want to click through, here's the deal: Methods described in a type library can declare parameters as optional. Optional parameters must come at the end of the parameter list, of course. The catch is how you programmatically invoke a method that contains optional parameters. If you want to call a method that h...