void NameMutexExample (void) {
HANDLE hMutex;
TCHAR szMsg[100];
hMutex = CreateMutex (
NULL, //No security descriptor
FALSE, //Mutex object not owned
TEXT("NameOfMutexObject")); //Object name
if (NULL == hMutex) {
//Your code to deal with the error goes here.
//Here is one example of what might be done.
wsprintf (szMsg, TEXT("CreateMutex error: %d."), GetLastError ());
MessageBox (NULL, szMsg, TEXT("Error"), MB_OK);
else {
//Not an error -- deal with success
if ( ERROR_ALREDAY_EXISTS == GetLastError ())
MessageBox (NULL, TEXT("CreateMutex opened existing mutex."),
TEXT("Results"),MB_OK);
else
MessageBox (NULL, TEXT("CreateMutex created new mutex."),
TEXT("Result"), MB_OK);
}
} //End of NamedMutexExamle code