The Old New Thing

Separating the metadata from the DIB pixels: Precalculating the BITMAPINFO

Last time, we saw that you can use the function to draw a DIB with an alternate color table without having to modify the . In that version of the function, we selected the into a device context in preparation for drawing from it, but in fact that step isn't necessary for drawing. It was merely necessary to get the original color table so ...

If dynamic DLL dependencies were tracked, they'd be all backwards

Whenever the issue of DLL dependencies arises, I can count on somebody arguing that these dynamic dependencies should be tracked, even if doing so cannot be proven to be reliable. Even if one could walk the call stack reliably, you would still get it wrong. The example I gave originally was the common helper library, where loads via an ...

A 32-bit application can allocate more than 4GB of memory, and you don't need 64-bit Windows to do it

Commenter Herb wondered how a 32-bit program running on 64-bit Windows can allocate more than 4GB of memory. Easy: The same way it allocates more than 4GB of memory on 32-bit Windows! Over a year before Herb asked the question, I had already answered it in the tediously boring two-week series on the myths surrounding the /3GB switch. Here's...

If you want to consume all the virtual address space, well, then go ahead and consume it, you don’t need my help

Commenter Matthew Chaboud asks if there's an easy way to consume all the virtual address space below 4GB, short of, well, actually allocating it. "It seems like there should be a cleaner way to do this." If you want to consume all the virtual address space, then call until you turn blue. Programs shouldn't care what address they get back ...

The thread that gets the DLL_PROCESS_DETACH notification is not necessarily the one that got the DLL_PROCESS_ATTACH notification

The thread that gets the notification is not necessarily the one that got the notification. This is obvious if you think about it, because the thread that got the notification might not even exist any longer when the DLL is unloaded. How can something that doesn't exist send a notification? Even so, many people fail to realize this. You ...

You can’t leave a critical section you never entered

If you call on a critical section you never entered, the behavior is undefined. Critical sections are an extremly high-traffic code path. Intense work goes into making them as fast as possible. Customers like to ask questions like "Exactly how many cycles does it take to enter a critical section? We're not going to use them if they're too ...

The dangers of mixing synchronous and asynchronous state

The window manager distinguishes between synchronous state (the state of the world based on what messages your program has received) and asynchronous state (the actual state of the world this very instant). We saw this earlier when discussing the difference between GetKeyState and GetAsyncKeyState. Here are some other functions and their ...

Why can’t I rotate the display with ChangeDisplaySettingsEx?

If you have one of those cool swively LCD displays (or if you decided to build your own), you naturally want to tell your video card to display rotated output, so you can take advantage of the portrait orientation. And naturally you would think that calling the and using the field of the structure would do the trick. And then you would ...