SHGlobalCounterCreate

This function creates or opens a global counter associated with a GUID.

Declaration

HANDLE SHGlobalCounterCreate (LPCGUID lpGuid);

Parameters

The lpGuid argument provides the address of a GUID that identifies the global counter.

Return Value

The function returns a handle to the counter, else NULL.

Behaviour

The global counter is implemented as the release count in a named semaphore. The name of the semaphore is “shell” followed by a period and then by a string representation of the given GUID.

The function attempts to create the semaphore, including to open a semaphore that already exists with the same name. If the semaphore gets newly created, it receives zero as its initial count and MAXLONG as its maximum count.

All being well, all semaphores for global counters are created with security descriptors that would permit all access to all users (as arranged through SHLWAPI’s own CreateAllAccessSecurityAttributes function). However, the function does seem prepared for the semaphore to exist already yet not grant full access (SEMAPHORE_ALL_ACCESS). If the semaphore does not open through CreateSemaphore, the function tries through OpenSemaphore but asking only for the least rights (SYNCHRONIZE and SEMAPHORE_MODIFY_STATE) that suffice for incrementing and decrementing the counter.

Availability

The SHGlobalCounterCreate function is exported from SHLWAPI as ordinal 222 in version 5.00 and higher.

Though this function dates from as long ago as 1999, it was still not documented by Microsoft in the MSDN Library at least as late as the CD edition dated January 2004.