Geoff Chappell - Software Analyst
From version 5.00 onwards, SHLWAPI provides a set of functions for working with global counters:
A global counter is in essence a named LONG in system memory. SHLWAPI contrives to present the counter like a named kernel object so that handles can be obtained to it by multiple processes, which may then increment, decrement or read the counter.
The SHGlobalCounterCreateNamed function either creates or opens a counter with a given name and a given initial value for the counter. The probably earlier function SHGlobalCounterCreate does the same but with the name formed from a GUID and with the initial value of a newly created counter being necessarily zero.
The SHGlobalCounterIncrement and SHGlobalCounterDecrement functions seem intended in principle to correspond closely to the standard API functions InterlockedIncrement and InterlockedDecrement. The standard functions act on a LONG variable that is specified by an address, which may be in memory shared among multiple processes. Both return what the variable got changed to. Both are atomic, in the sense that whatever reads and writes are performed on the variable in one thread cannot be interrupted by reads or writes performed on the variable in some other thread. The SHLWAPI functions seem intended to have all this same behaviour except that the LONG variable is specified by a handle, which eases reference to the variable from multiple processes and hides that the variable actually is implemented in (system) memory shared by all processes.
The SHGlobalCounterGetValue function reads the counter.
A side-effect of exposing an object to multiple processes, and especially for inheritance by child processes, is that SHLWAPI has to create some wide-ranging security attributes. These may be generally useful and are made accessible through the CreateAllAccessSecurityAttributes function.
All these functions are exported only by ordinal. None are yet documented.