Showing tag results for Code

Jul 15, 2009
Post comments count0
Post likes count0

Separating the metadata from the DIB pixels: Precalculating the BITMAPINFO

Raymond Chen

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

Code
Jul 14, 2009
Post comments count0
Post likes count0

The fun and profit of manipulating the DIB color table can be done without having to modify it

Raymond Chen

If I were Michael Kaplan, I'd have a more clever title like I'm not touching you! or Look but don't touch or maybe Looking at a DIB through -colored glasses. We saw some time ago that you can manipulate the DIB color table to perform wholesale color remapping. But in fact you can do this even without modifying the DIB color table, which is a h...

Code
Jul 10, 2009
Post comments count0
Post likes count1

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

Raymond Chen

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

Code
Jul 6, 2009
Post comments count0
Post likes count1

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

Raymond Chen

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

Code
Jun 29, 2009
Post comments count0
Post likes count1

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

Raymond Chen

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

Code
Jun 26, 2009
Post comments count0
Post likes count1

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

Raymond Chen

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 can't ...

Code
Jun 19, 2009
Post comments count0
Post likes count1

You can’t leave a critical section you never entered

Raymond Chen

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

Code
Jun 18, 2009
Post comments count0
Post likes count1

The dangers of mixing synchronous and asynchronous state

Raymond Chen

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

Code
Jun 4, 2009
Post comments count0
Post likes count1

Why can’t I rotate the display with ChangeDisplaySettingsEx?

Raymond Chen

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

Code