The Old New Thing

If you protect a write with a critical section, you may also want to protect the read

It is common to have a critical section which protects against concurrent writes to a variable or collection of variables. But if you protect a write with a critical section, you may also want to protect the read, because the read might race against the write. Adam Rosenfield shared his experience with this issue in a comment from a few ...
Comments are closed.0 0
Code

Things I've written that have amused other people, Episode 8

In a technical discussion, I opened a reply with Bob's paper which I haven't yet read points out that... Some people wrote to me to say that the've added this quote to their file in the hopes of being able to use it themselves someday. For those who are curious, I found the technical discussion in question. It had to do with whether the...

Why is CLIPFORMAT defined to be a WORD rather than a UINT?

Commenter Ivo wants to know if the function returns a , why is the data type defined to be a ? Since a is smaller than a , you have to stick in a cast every time you assign the result of to a . Rewind to 16-bit Windows. Back in those days, a and a were the same size, namely, 16 bits. As a result, people got lazy about the ...

How to insert a large number of items into a treeview efficiently

Just a quick tip today. If you need to insert a large number of items into a treeview, like tens of thousands, then it's much more efficient to insert them "backwards". (I'm ignoring for now the usability question of having a treeview that large in the first place.) In other words, instead of do it this way: Why is backwards-insertion ...
Comments are closed.0 0
Code

How can I extend the deadline for responding to the PBT_APMSUSPEND message?

A customer observed that starting in Windows Vista, the deadline for responding to the message was reduced from twenty seconds to two seconds. Their program needs more than two seconds to prepare for a suspend and they wanted to know how they could extend the deadline. The program communicates with a device, and if they don't properly ...
Comments are closed.0 0
Code

It is not unreasonable to expect uninitialized garbage to change at any time, you don't need to ask for an explanation

A customer admitted that they had a bug in their code: One bug in the above code is in the final parameter passed to : It's supposed to be the count in bytes, but the calculation appends only one byte for the terminating null instead of a full . In other words, it should be For concreteness, let's say the original string was five s in ...
Comments are closed.0 0
Code

The Control Panel search results understand common misspellings, too

Here's a little trick. Open your Start menu and type scrensaver into the search box. That's right, spell it with only one e. Hey, it still found the Control Panel options for managing your screen saver. If you enable Improve my search results by using online Help in Windows Help and Support, this sends your search query to a back-end server ...

Why not use animated GIFs as a lightweight alternative to AVIs in the animation common control?

Commenter Vilx- wondered why animated GIFs weren't used as the animation format for the shell animation common control. After all, "they are even more lightweight than AVIs." Animated GIFs are certainly more lightweight than general AVIs, since AVI is just a container format, so decoding a general AVI means decoding any encoding format ...

Why does Internet Explorer not call DLL_PROCESS_DETACH on my DLL when I call ExitProcess?

A customer asked a question, but as is often the case, the question was much more telling than the answer. We have an Internet Explorer plug-in which calls to force Internet Explorer to exit. We found that when we do this, our plug-in does not receive a notification. What could be preventing our plug-in from receiving the notification...
Comments are closed.0 0
Code

Why can't I install this DLL via Regsvr32 /i?

A customer asked for help installing a particular DLL. They ran the command but got the error "SomeDll.dll was loaded, but the DllInstall entry point was not found. This file can not be registered." A DLL needs to be specifically written to be used with the command. You can't just grab some random DLL and expect to work. As we saw last ...