The Old New Thing

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

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 . ...

What is the point of FreeLibraryAndExitThread?

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...

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

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 ...

On the various ways of getting the current time and date in Win32

There are a number of functions in Win32 that obtain the current date and time. Here's how they fit together: The starting point is . This returns the current time in UTC in the form of a structure. This also happens to be the time format used internally by the system, so this value can be retrieved with a minimum of fuss. You can also ...

Using GetLogicalProcessorInformationEx to see the relationship between logical and physical processors

Today's Little Program uses the function to print the mapping of logical processors to physical processors, as well as the mapping of logical processors to packages. (A dual-core processor is a single package with two cores. If those cores are themselves dual-hyperthreaded, then you have four logical processors total.) The helper ...

My, those threads start up really fast nowadays

Here's a little puzzle inspired by an actual bug: Can the assertion at the start of ever fire? Naturally, the answer is Yes, otherwise it wouldn't be a very interesting article. The assertion can fire if the worker thread starts running before the call the returns. In that case, the caller hasn't yet received the handle or ID of the ...

When should I use the FIND_FIRST_EX_LARGE_FETCH flag to FindFirstFileEx?

Windows 7 introduces a new flag to the function called . The documentation says that it "uses a larger buffer for directory queries, which can increase performance of the find operation." This is classic MSDN-style normative documentation: It provides "just the facts". Far be it for MSDN to tell you how to write your application; the job...

Opening and manipulating Internet Explorer windows programmatically

Today's Little Program takes the JavaScript application from a few years ago and converts it to C#. This was inspired by a customer who started with the question, "How can I close all Internet Explorer windows programmatically?" This was a strange request. After all, the user may be rather upset that their Amazon shopping spree was ...

The case of the redirected standard handles that won't close even though the child process has exited (and a smidge of Microspeak: reduction)

A customer had a supervisor process whose job is to launch two threads. Each thread in turn launches a child process, let's call them A and B, each with redirected standard handles. They spins up separate threads to read from the child processes' stdout in order to avoid deadlocks. What they've found is that even though child ...