CreateMutex problem...why is it not working correctly?
Posted on 2006-11-20
Here is my function...
My main window is an ATL Dialog window
LONG result = 0;
HANDLE hMutex = ::CreateMutex(NULL, FALSE, _T("MYAPPLICATION_MUTEX"));
if (WaitForSingleObject(hMutex, INFINITE) == WAIT_OBJECT_0)
MessageBox(NULL, "WaitForMutex", "", MB_OK);
If I run the app twice, in first app, I click on Test button (which calls Test() function)
The Messagebox "WaitForMutex" shows up (I don't close this messagebox window)
In second instance of app, I do the same, the "WaitForMutex" message box DOES NOT COME UP, the app is waiting (this is of course what I want)
But here's the weird thing... I can go back to original app, and click on the Test button again (which I shouldn't be able to, because MessageBox call is supposed to be a modal call), I get A SECOND "WaitForMutex" messagebox window...(or more if I click on test button more), now even if MessageBox window was modeless, I still SHOULD NOT get more messagebox windows with "WaitForMutex".....Why is this happening???
(Test app does nothing else, I just call Test() function and that's it)