Showing tag results for Code

Nov 30, 2011
Post comments count0
Post likes count1

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

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 25, 2011
Post comments count0
Post likes count1

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

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
Post comments count0
Post likes count1

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

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
Post comments count0
Post likes count1

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

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 18, 2011
Post comments count0
Post likes count1

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

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 16, 2011
Post comments count0
Post likes count1

How can I tell whether a COM pointer to a remote object is still valid?

Raymond Chen

A customer asked the rather suspicious question, "How do I check whether a pointer is valid in another process?" This question should make your head boggle with bewilderment. First of all, we've moved beyond to . Second of all, what the heck are you doing with a pointer in another process? You can't do anything with it! After some back-and-fort...

Code
Nov 4, 2011
Post comments count0
Post likes count1

How do I generate a unique 32-bit value for a time zone?

Raymond Chen

Public Service Announcement: Daylight Saving Time ends in most parts of the United States this weekend. Other parts of the world may change on a different day from the United States. A customer asked the following question: Given two structures, I would like to compute a for each that I can then compare to determine whether they represent t...

CodeTime
Nov 3, 2011
Post comments count0
Post likes count1

We've traced the call and it's coming from inside the house: A function call that always fails

Raymond Chen

A customer reported that they had a problem with a particular function added in Windows 7. The tricky bit was that the function was used only on very high-end hardware, not the sort of thing your average developer has lying around. The customer reported that the function always failed with error 122 () even though the buffer seems perfectl...

Code
Oct 28, 2011
Post comments count0
Post likes count1

Why isn't my transparent static control transparent?

Raymond Chen

A customer reported that their application uses transparent static controls positioned over a bitmap image control, but even though they set the Transparent property on the static control, the static control isn't transparent. The customer was kind enough to provide clear steps to illustrate the problem: Open Visual Studio 2005 or 2008. From the...

Code
Oct 26, 2011
Post comments count0
Post likes count1

How can I get notified when some other window is destroyed?

Raymond Chen

A customer wanted to know whether there was a method (other than polling) to monitor another window and find out when it gets destroyed. The goal was to automate some operation, and one of the steps was to wait until some program closed its XYZ window before moving on to the next step. Finding the XYZ window could be done with a , but since the wi...

Code