#include <windows.h>
// program starts only once
BOOL checkStartOnlyOne ()
{
BOOL bFlag = false; // exit program: false
// Create a mutex
HANDLE hMutex = CreateMutex (NULL, FALSE, L "fortest_abc123");
// Check the error code
if ( the GetLastError () == ERROR_ALREADY_EXISTS)
{
// If the mutex already exists and reset release mutex handle
the CloseHandle (hMutex);
hMutex = NULL;
}
the else
{
bFlag = to true;
}
return bFlag;
}