The Old New Thing

How is the CommandLineToArgvW function intended to be used?

The function does some basic command line parsing. A customer reported that it was producing strange results when you passed an empty string as the first parameter: Well, okay, yeah, but huh? The first parameter to is supposed to be the value returned by . That's the command line, and that's what was designed to parse. If you pass ...

Hey there token, long time no see! (Did you do something with your hair?)

Consider a system where you have a lot of secured objects, and suppose further that checking whether a user has access to an object is a slow operation. This is not as rare as you might think: Even though a single access check against a security descriptor with a small number of ACEs might be fast, you can have objects with complicated ...

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 ...