Showing tag results for Code

May 23, 2012
Post comments count0
Post likes count0

GUIDs are designed to be unique, not random

Raymond Chen
Raymond Chen

A customer liaison asked, "My customer is looking for information on the GUID generation algorithm. They need to select N items randomly from a pool of M (jury selection), and their proposed algorithm is to assign each item a GUID, then sort the items by GUID and take the first N." (I've seen similar questions regarding using GUIDs f...

Code
May 11, 2012
Post comments count0
Post likes count0

When you crash on a mov ebx, eax instruction, there aren't too many obvious explanations, so just try what you can

Raymond Chen
Raymond Chen

A computer running some tests encountered a mysterious crash: A colleague of mine quickly diagnosed the proximate cause. *Something* marked the code page PAGE_READWRITE, instead of PAGE_EXECUTE_READ. I suspect a bug in a driver. FOO is just a victim here. This diagnosis was met with astonishment. "Wow! What made you think to check the pr...

Code
May 9, 2012
Post comments count0
Post likes count0

How do I hide a window without blocking on it?

Raymond Chen
Raymond Chen

A customer was working on improving their application startup performance. They found that if their application was launched immediately after a fresh boot, the act of dismissing their splash screen was taking over 5% of their boot time. Their code removed the splash screen by calling . They suspect that the splash screen thread has, for some reaso...

Code
May 4, 2012
Post comments count0
Post likes count0

How does the MultiByteToWideChar function treat invalid characters?

Raymond Chen
Raymond Chen

The flag controls how the function treats invalid characters. Some people claim that the following sentences in the documentation are contradictory: "Starting with Windows Vista, the function does not drop illegal code points if the application does not set the flag." "Windows XP: If this flag is not set, the function silently drops il...

Code
Apr 27, 2012
Post comments count0
Post likes count0

A process shutdown puzzle, Episode 2

Raymond Chen
Raymond Chen

A customer reported that their program would very sporadically crash in the function . The customer was kind enough to provide a stack trace at the point of the crash: The customer wondered, "Could the problem be that my cleanup group does not have a callback? MSDN seems to suggest that this is okay." The exception being thrown is , but that...

Code
Apr 20, 2012
Post comments count0
Post likes count0

What does INIT_ONCE_CTX_RESERVED_BITS mean?

Raymond Chen
Raymond Chen

Windows Vista adds the One-Time Initialization family of functions which address a common coding pattern: I want a specific chunk of code to run exactly once, even in the face of multiple calls from different threads. There are many implementations of this pattern, such as the infamous double-checked lock. The double-checked lock is very easy to...

Code
Apr 16, 2012
Post comments count0
Post likes count0

Why do we need IsDialogMessage at all?

Raymond Chen
Raymond Chen

alv wonders why we need the function at all. "All its activity could take place inside the window procedure of the modeless dialog itself", since when it doesn't have focus, it shouldn't be responding to messages anyway. Sure, that works great if the modeless dialog has focus. But it almost never does. What has focus is a control inside the mode...

Code
Apr 13, 2012
Post comments count0
Post likes count0

You already know the answer since you do it yourself

Raymond Chen
Raymond Chen

A customer was writing a program that performed virtual drag/drop. They were using the technique but found that many applications don't support drag/drop of virtual content. They support only . What's more, often these applications query for on not because they want to access the file, but just because they want to get the file names (for examp...

Code
Apr 9, 2012
Post comments count0
Post likes count0

There's the interface contract, and there are the implementations of the interface contract

Raymond Chen
Raymond Chen

Ivo wants to know whether it is legal to use as the icon parameters to . The documentation says that the parameters are optional, but some shell folder implementations treat them as mandatory. Yes, the parameters are technically optional, but it's also the case that many people mess up their implementation of the interface and treat them as mand...

Code
Apr 6, 2012
Post comments count0
Post likes count0

Registration-free COM the old-fashioned way: The car mp3 player

Raymond Chen
Raymond Chen

Windows XP introduced Registration-Free COM, permitting you to place your COM object registrations in a manifest rather than in the registry. Very handy when you want to support xcopy deployment or running directly off a thumb drive. And very much in keeping with the principle of not using a global solution for a local problem. (If you need y...

Code