SHGlobalCounterIncrement

This function increments a global counter.

Declaration

LONG SHGlobalCounterIncrement (HANDLE hCounter);

Parameters

The hCounter argument provides a handle to the global counter, as obtained through some earlier call to either SHGlobalCounterCreate or SHGlobalCounterCreateNamed.

Return Value

The function returns the value that the counter got incremented to.

Behaviour

The global counter is implemented as the release count in a semaphore. The SHGlobalCounterIncrement function is little more than a call to ReleaseSemaphore with one as the requested increment of the release count.

For most practical purposes, this function is just like the standard API function InterlockedIncrement except that the 32-bit variable to act on is specified indirectly through a handle instead of directly through an address.

A significant difference in behaviour arises because the release count of a semaphore cannot be negative. If the counter is already MAXLONG (which, admittedly, is very unlikely in practice), then this function can increment the counter no further. There is no wrap around to MINLONG. The counter remains at MAXLONG and the function returns one.

Availability

The SHGlobalCounterIncrement function is exported from SHLWAPI as ordinal 224 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.