The Old New Thing

Flushing your performance down the drain, that is

Some time ago, Larry Osterman discussed the severe performance consequences of flushing the registry, which is a specific case of the more general performance catch: Flushing anything will cost you dearly. A while back, I discussed the high cost of the "commit" function, and all the flush-type operations turn into a commit at the end of ...

What happens to a named object when all handles to it are closed?

A customer had a question about named kernel objects: I understand that handles in a process if leaked will be destroyed by the kernel when the process exits. My question would be around named objects. Would named objects hold their value indefinitely? If I run a small utility app to increment a named counting semaphore, the count of that ...

How do I recover the window handle passed to ShellExecute?

A customer had the following question: I'm using the function to launch a new process and am passing the handle to my application's main window as the parameter. From the new process, I want to get information from the old process, and to do that, I need the window handle. How can I recover that window handle from the new process? You can...

Be careful that your splash screen doesn't squander the foreground love

Commenter Erbi has a program which creates a splash screen on a background thread while the main thread initializes. "I create and then destroy this splash screen window just before creating and displaying the main window." The problem is that the main window fails to obtain foreground activation. Commenting out the code that creates the ...

When do I need to use GC.KeepAlive?

Finalization is the crazy wildcard in garbage collection. It operates "behind the GC", running after the GC has declared an object dead. Think about it: Finalizers run on objects that have no active references. How can be a reference to an object that has no references? That's just crazy-talk! Finalizers are a Ouija board, permitting dead ...

How can I find all objects of a particular type?

More than one customer has asked a question like this: I'm looking for a way to search for all instances of a particular type at runtime. My goal is to invoke a particular method on each of those instances. Note that I did not create these object myself or have any other access to them. Is this possible? Imagine what the world would be ...

Why is my icon being drawn at the wrong size when I call DrawIcon?

Some time ago I had a problem with icon drawing. When I tried to draw an icon with it ended up being drawn at the wrong size. A call to confirmed that the icon was 48×48, but it drew at 32×32. The answer is documented in a backwards sort of way in the function, which says at the bottom, To duplicate DrawIcon (hDC, X, Y, ...