Showing results for November 2011 - The Old New Thing

Nov 30, 2011
0
0

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

Raymond Chen
Raymond Chen

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

Code
Nov 29, 2011
0
0

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

Raymond Chen
Raymond Chen

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

Non-Computer
Nov 28, 2011
0
0

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

Raymond Chen
Raymond Chen

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

History
Nov 25, 2011
0
0

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

Raymond Chen
Raymond Chen

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

Code
Nov 24, 2011
0
0

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

Raymond Chen
Raymond Chen

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

Code
Nov 23, 2011
0
0

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

Raymond Chen
Raymond Chen

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

Code
Nov 22, 2011
0
0

The Control Panel search results understand common misspellings, too

Raymond Chen
Raymond Chen

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

Other
Nov 21, 2011
0
0

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

Raymond Chen
Raymond Chen

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

History
Nov 18, 2011
0
0

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

Raymond Chen
Raymond Chen

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? As w...

Code
Nov 17, 2011
0
0

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

Raymond Chen
Raymond Chen

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 week, t...

Other