Showing tag results for Code

Dec 7, 2011
Post comments count0
Post likes count0

GetParent, just as confusing as EnumClaw, but it's an actual function!

Raymond Chen
Raymond Chen

The function , documented as returning "the child or the parent of the window", was a joke, but there's a function whose behavior is just as confusing as the joke function : . The function returns the parent window, or owner window, or possibly neither. All that's left is for it to be a floor wax and it'll have everything covered. The idea behi...

Code
Dec 5, 2011
Post comments count0
Post likes count0

Why does my program still show up in the Programs and Features folder after my uninstaller exits?

Raymond Chen
Raymond Chen

A customer reported that they were having problems with their program entry in the Programs and Features folder (formerly known as Add and Remove Programs, formerly known as Add/Remove Programs). When the user goes to the Programs and Features folder, selects their program, and clicks Uninstall, the uninstaller runs, but after the uninstaller exits...

Code
Dec 2, 2011
Post comments count0
Post likes count0

Don't let more than one process try to read from stdin at the same time

Raymond Chen
Raymond Chen

A customer reported a problem with a program that ran a series of other programs in parallel. We have a main program (call it main.exe) that runs a bunch of child processes with stdout and stderr redirected. (We are not redirecting stdin.) We've found that some of the child processes get stuck inside the C runtime startup code on a call to on the...

Code
Nov 30, 2011
Post comments count0
Post likes count0

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

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

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

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

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

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

Raymond Chen
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 count0

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

Raymond Chen
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