The Old New Thing

When are global objects constructed and destructed by Visual C++?

Today we're going to fill in the following chart: The C++ language specification provides some leeway to implementations on when global static objects are constructed. It can construct the object before begins, or it construct the object on demand according to complicated rules. You can read [basic.start.init] for the gory details. Let'...

If only DLLs can get DllMain notifications, how can an EXE receive a notification when a thread is created (for example)?

When a DLL is loaded, it receives a notification, and when it is unloaded (or when the process terminates), it gets a notification. DLLs also receive notifications when a thread is created and notifications when a thread exits. But what if you are an EXE? EXEs don't have a , so there is no way to receive these notifications. The trick ...

The GetCurrentThread function is like a check payable to Bearer: What it means depends on who's holding it

The function returns a pseudo-handle to the current thread. The documentation goes into significant detail on what this means, but I fear that it may have fallen into the trap of providing so much documentation that people decide to skip it. Okay, so first of all, what is a pseudo-handle? a pseudo-handle is a sentinel value for that is ...

Is there a way to disable a specific balloon notification without disabling all of them?

There is a group policy called Turn off all balloon notifications, but what if you want to turn off only one specific notification? The taskbar does not offer fine-grained policy control over balloon notifications. All you have is the giant sledgehammer that turns off all of them. If there is a specific balloon you want to disable, you have ...

Enumerating notification icons via UI Automation

Today's Little Program uses accessibility to enumerate the current notification icons (and possibly click on one of them). This could be done manually via , but the BCL folks conveniently created the namespace which contains classes that take a lot of the grunt work out of walking the accessibility tree. While it's true that the namespace...

Some parts of an interface can change but others can't

When I wrote about asking the compiler to answer calling convention questions, some people were concerned about whether this was a reliable mechanism or whether it was relying on something that can change in the future. This is a special case of the question, "What parts of an interface can change, and what can't?" And it all boils down to...

Standard handles are really meant for single-threaded programs

When I discussed the conventions for managing standard handles, Sven2 noted that I implied that you need to call with a new handle if you close the current handle and asked "Wouldn't it make more sense to call it the other way round? I.e., first set the new handle, then close the old one? It would ensure that any other thread that runs in ...

Enumerating cyclical decompositions with Stirling numbers

This whole enumeration nightmare-miniseries started off with Stirling numbers of the second kind. But what about Stirling numbers of the first kind? Those things ain't gonna enumerate themselves! The traditional formulation of the recursion for Stirling numbers of the first kind (unsigned version, since it's hard to enumerate negative ...