Showing results for Code - The Old New Thing

May 26, 2011
Post comments count0
Post likes count0

How do IsThemeActive, IsAppThemed, and IsCompositionActive differ?

Raymond Chen
Raymond Chen

There are three functions which test very similar things, and sometimes applications pick the wrong one. Here's the rundown: Note that these functions do not answer the question "Is the application using the visual-styles-enabled version of the common controls library?" That question is harder to answer because the decision to use the visual-sty...

Code
May 25, 2011
Post comments count0
Post likes count1

WinMain is just the conventional name for the Win32 process entry point

Raymond Chen
Raymond Chen

is the conventional name for the user-provided entry point in a Win32 program. Just like in 16-bit Windows, where the complicated entry point requirements were converted by language-provided startup code into a call to the the user's function, the language startup code for 32-bit programs also does the work of converting the raw entry point in...

Code
May 20, 2011
Post comments count0
Post likes count0

BeginBufferedPaint: It's not just for buffered painting any more

Raymond Chen
Raymond Chen

I covered the function in my 2008 PDC presentation, but one thing I didn't mention is that the buffered paint functions are very handy even if you have no intention of painting. Since the buffered paint functions maintain a cache (provided that you remembed to call ), you can use to get a temporary bitmap even if you have no intention of actu...

Code
May 16, 2011
Post comments count0
Post likes count0

Multithreaded UI code may be just as hard as multithreaded non-UI code, but the consequences are different

Raymond Chen
Raymond Chen

Commenter Tim Smith claims that the problems with multithreaded UI code are not significantly more than plain multithreaded code. While that may be true on a theoretical level, the situations are quite different in practice. Regardless of whether your multithreaded code does UI or not, you have to deal with race conditions, synchronization, cache...

Code
May 12, 2011
Post comments count0
Post likes count0

Looking at the world through kernel-colored glasses

Raymond Chen
Raymond Chen

During a discussion of the proper way of cancelling I/O, the question was raised as to whether it was safe to free the I/O buffer, close the event handle, and free the structure immediately after the call to . The response from the kernel developer was telling. That's fine. We write back to the buffer under a try/except, so if the memory is free...

Code
May 11, 2011
Post comments count0
Post likes count0

Why double-null-terminated strings instead of an array of pointers to strings?

Raymond Chen
Raymond Chen

I mentioned this in passing in my description of the format of double-null-terminated strings, but I think it deserves calling out. Double-null-terminated strings may be difficult to create and modify, but they are very easy to serialize: You just write out the bytes as a blob. This property is very convenient when you have to copy around the lis...

Code
May 6, 2011
Post comments count0
Post likes count0

A function pointer cast is a bug waiting to happen

Raymond Chen
Raymond Chen

A customer reported an application compatibility bug in Windows. We have some code that manages a Win32 button control. During button creation, we subclass the window by calling . On the previous version of Windows, the subclass procedure receives the following messages, in order: We do not handle any of these messages and pass them thro...

Code
May 5, 2011
Post comments count0
Post likes count0

Your program loads libraries by their short name and you don't even realize it

Raymond Chen
Raymond Chen

In the discussion of the problems that occur if you load the same DLL by both its short and long names, Xepol asserted that any program which loads a DLL by its short name "would have ONLY itself to blame for making stupid, unpredictable, asinine assumptions" and that Windows should "change the loader to NOT load any dll with a short name where the...

Code
Apr 29, 2011
Post comments count0
Post likes count0

Why is there a RestoreLastError function that does the same thing as SetLastError?

Raymond Chen
Raymond Chen

Matt Pietrek noticed that and do exactly the same thing and wondered why there's a separate function for it. It's to assist in debugging and diagnostics. Say you're debugging a problem and when you call you get . It would really help a lot if you could figure out who set the error code to . If you set a breakpoint on , you find that people...

Code