Showing tag results for Code

May 20, 2011
Post comments count0
Post likes count1

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 count1

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 count1

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 count1

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 count1

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 count1

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 count1

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

No, you can't ask whether your notification icon is visible or not

Raymond Chen
Raymond Chen

A customer asked what started out as a simple question, but by now you know that this sort of simple question only raises new questions: Is there a way that we can detect that the user has hidden our notification icon? No, there is no way to ask whether your notification icon is hidden or visible. Users decide which icons they want to see, and y...

Code
Apr 22, 2011
Post comments count0
Post likes count1

Even if you have a lock, you can borrow some lock-free techniques

Raymond Chen
Raymond Chen

Even if you prefer to use a lock (after all, they are much easier to program), you can borrow some lock-free techniques. For example, consider this: There are some concerns here. First of all, there's the lock hierarchy issue: If reticulating a spline takes the geometry lock, that may violate our lock hierarchy. If the lock is a hot lock, yo...

Code