The following code runs perfectly well on my XP SP2 machine, but the call to WaitForSingleObject waits indefinitely when running on my Vista machine:
HANDLE ghSemaphore;
ghSemaphore = CreateSemaphore(NULL, 0, 1, "COM_PHILOERTEL_FINA");
if (ghSemaphore == NULL) {
MessageBoxA(NULL,"Error creating semaphore","ERROR",0);
return FALSE;
}
MessageBoxA(NULL,"Semaphore created. Waiting for it to be triggered","ERROR",0);
WaitForSingleObject(ghSemaphore, INFINITE);
// got the semaphore, ready to rock
MessageBoxA(NULL,"Got the semaphore, ready to rock!","Notice",0);
Here's the thread that releases the semaphore:
ghSemaphore = OpenSemaphore(SEMAPHORE_ALL_ACCESS, FALSE, "COM_PHILOERTEL_FINA");
if (ghSemaphore == NULL) {
MessageBoxA(NULL,"Failed to open semaphore","ERROR",0);
return FALSE;
}
if (0 == ReleaseSemaphore(ghSemaphore, 1, NULL)) {
MessageBoxA(NULL,"Plugin was unable to release the semaphore","ERROR",0);
return FALSE;
}
The named semaphore was a recent addition that didn't do any good. Before that the threads were just sharing ghSemaphore with its anonymous semaphore. No apparent difference. Does anyone have any idea why this binary (compiled on the XP machine in VC6, Express Edition fwiw) wouldn't work in Vista? As I said above, the WaitForSingleObject call is what never finishes.
THanks!