The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

A possibly unbeatable record for the shortest amount of time between an email message and its resend
Nov 13, 2013
Post comments count 0
Post likes count 0

A possibly unbeatable record for the shortest amount of time between an email message and its resend

Raymond Chen
Raymond Chen

I occasionally bring up the issue of people who ask a question and then repeat the question, especially people who repeat the question with some impatience. At the time, the record for the shortest time between the message and its repeat was eight minutes. But I think I have something unbeatable. From: X To: ABC Team I hit this crash in ABC. Can somebody take a look at it? A half hour later, somebody replied: From: A To: X, ABC Team This looks like the problem is really in the DEF component. You should have the DEF team look at it. Person X waited a few hours, then got impatient. From: X T...

Microspeak: Spinning up or kicking off a build
Nov 12, 2013
Post comments count 0
Post likes count 0

Microspeak: Spinning up or kicking off a build

Raymond Chen
Raymond Chen

Round and round.

How did Raymond discover his carrier-screaming talent? And his homemade Marauder's Map
Nov 11, 2013
Post comments count 0
Post likes count 0

How did Raymond discover his carrier-screaming talent? And his homemade Marauder's Map

Raymond Chen
Raymond Chen

George wonders, "I am curious how Raymond found about his talent. Maybe it will be an interesting post." This isn't like a superhero who discovers as a young adult that he has powers beyond that of mortal men. And there was no radioactive spider. It was a simple case of problem-solving. The basic way of checking whether the mainframe was up was to go into the lab and see if the terminals responded. But of course this meant having to hang around in the lab building all day. The next way of checking whether the mainframe was up was to stay in your dorm room doing some other work while listening to a portable ...

What's the point of the various …WhenCallbackReturns functions?
Nov 8, 2013
Post comments count 0
Post likes count 0

What's the point of the various …WhenCallbackReturns functions?

Raymond Chen
Raymond Chen

The thread pool provides a number of functions named . What's the point of all these functions? Why can't you just do the operation yourself immediately before returning? We saw last time. What's the point of the others? Basically, the same thing as . It's a way to release a resource after execution has left the function and the callback is marked as complete. In the case of a synchronization resource, that resource may be what's keeping somebody from unloading your DLL, or it might protect a race condition between the callback function and a function that tries to cancel the callback.

Partially eliminating the need for SetThreadpoolCallbackLibrary and reducing the cost of FreeLibraryAndExitThread
Nov 7, 2013
Post comments count 0
Post likes count 0

Partially eliminating the need for SetThreadpoolCallbackLibrary and reducing the cost of FreeLibraryAndExitThread

Raymond Chen
Raymond Chen

Update: Daniel points out that there is still a race condition here, so this trick won't work. Rats. The documentation for the says This prevents a deadlock from occurring when one thread in DllMain is waiting for the callback to end, and another thread that is executing the callback attempts to acquire the loader lock. If the DLL containing the callback might be unloaded, the cleanup code in DllMain must cancel outstanding callbacks before releasing the object. Managing callbacks created with a that specifies a callback library is somewhat processor-intensive. You should consider other options for en...

CoUninitalize will ask a DLL if it is okay to unload now, but the answer is a foregone conclusion
Nov 6, 2013
Post comments count 0
Post likes count 0

CoUninitalize will ask a DLL if it is okay to unload now, but the answer is a foregone conclusion

Raymond Chen
Raymond Chen

The entry point is exported by COM in-proc servers. COM host applications call periodically to ask COM to do DLL housecleaning, and in response, COM asks each DLL if it is okay to be unloaded. If so, then COM unloads the DLL. What is not well-known is that COM also does DLL housecleaning when you shut down the last apartment by calling . When that happens, COM will still go around asking each DLL whether it's okay to be unloaded, but the question is merely a formality, because regardless of your answer, COM will unload you anyway. The story here is that COM is being shut down for the process, so COM knows ...

What is the point of FreeLibraryAndExitThread?
Nov 5, 2013
Post comments count 0
Post likes count 0

What is the point of FreeLibraryAndExitThread?

Raymond Chen
Raymond Chen

The function seems pointless. I mean, all the function does is Who needs such a trivial function? If I wanted to do that, I could just write it myself. And then you discover that occasionally your program crashes. What's going on? Let's rewind and look at the original problem. Originally, you had code that did something like this: This worked great, until somebody did this to your DLL: This code fragment calls your function and then immediately unloads the DLL, presumably because all they wanted to do was call that one function. Now you have a problem: That call frees your DLL, while your i...

The complexity of modern voting, or at least modern dream voting
Nov 4, 2013
Post comments count 0
Post likes count 0

The complexity of modern voting, or at least modern dream voting

Raymond Chen
Raymond Chen

I dreamed that I arrived at my polling station just before it closed, but the ballot was not what I expected. Instead of voting on political candidates or referenda, I was voting on music from the 1980's. I ended up voting for an Anne Murray song because it was the only one I recognized, and it wasn't a bad song.

Manipulating the zone identifier to specify where a file was download from
Nov 4, 2013
Post comments count 0
Post likes count 0

Manipulating the zone identifier to specify where a file was download from

Raymond Chen
Raymond Chen

When you download a file via Internet Explorer, the file is tagged with a little bit of information known as a zone identifier which remembers where the file was downloaded from. This is what tells Explorer to put up the "Yo, did you really want to run this program?" prompt and which is taken into account by applications so that they can do things like disable scripting and macros when they open the document, just in case the file is malicious. Today's Little Program is really three Little Programs: One to read the zone identifier, one to set the zone identifier, and one to clear it. The first program takes...