Showing tag results for Code

Jul 27, 2009
Post comments count0
Post likes count1

Polling by sleeping versus polling by waiting with a timeout

Raymond Chen

Commenter Francois Boucher asks it's better to write a background worker thread that polls with and a flag, or polls by waiting for an event with a timeout? "Which scenario is better? The first one uses only 1 handle for the thread. The second one will use 2. But is the first scenario wasting more thread time? Is it worth using the event (ker...

Code
Jul 24, 2009
Post comments count0
Post likes count1

If you wished a language supported the preprocessor, you know, you can fix that

Raymond Chen

A customer had the following question about the message compiler, something that I had noted almost nobody uses. Well how do you do, we found somebody who actually uses it. Anyway, the question went like this (paraphrased, as always): Can I use symbolic constants in my .mc file? For example, I have a message file that goes like this: I hav...

Code
Jul 17, 2009
Post comments count0
Post likes count0

The disembodiment of DIBs from the DIB section

Raymond Chen

So far this week, we've separated the DIB metadata () from the pixels of a DIB section. But there's really no need for the DIB section at all! As long as you have the pixels and the metadata, you can draw bits. We demonstrate this by drawing a rather stupid-looking bitmap onto the screen, but doing so without the use of s at all! Start with a b...

Code
Jul 16, 2009
Post comments count0
Post likes count0

Caption contest: The pinball machine: Results

Raymond Chen

It's been quite a while, but a winner in the caption contest has been selected and the prize finally reached its destination. (Mostly due to procrastination on my part. Don't blame the postal service.) The winner is Scott from Australia with his entry Only 5,000 more referrals until MULTIBALL Even though it's kind of low-brow, it made me lau...

Code
Jul 16, 2009
Post comments count0
Post likes count0

Separating the metadata from the DIB pixels: Changing the raster operation

Raymond Chen

For a few days now, we've used the function in conjunction with a precomputed to draw a DIB with an alternate color table without modifying the . The function operates like a with raster operation . If you want another raster operation, you can use , which has a final raster operation parameter. Despite its name, you don't have to stretch w...

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