I am learning to use Mutexes and I tried to create a basic mutex using CreateMutex then see if the mutex is there via using OpenMutex().
However....
I did created 2 projects (CreateMutant.sln, IdentifyMutant.sln):
CreateMutant.cpp:
1 2 3 4 5 6 7 8
#include<Windows.h>
#include<conio.h>
int main()
{
CreateMutex(0,false,"TESTMUTEX");
_getch(); //Halt Program
}
IdentifyMutant.cpp:
1 2 3 4 5 6 7 8 9
#include<Windows.h>
#include<conio.h>
HANDLE h = OpenMutex(0, true, "TESTMUTEX");
if ( h == 0)
{
MessageBoxA(0,"We did not get any handle","Error",MB_ICONERROR);
}
_getch();
When I start - CreateMutant.exe there is no error: IT WORKS!
then I while CreateMutant.exe is still running I start IdentifyMutant.exe.
BUT IdentifyMutant.exe gives me a error code 2:
ERROR_FILE_NOT_FOUND
2 (0x2)
The system cannot find the file specified.
I found the Error, it is not SYNCHRONIZE but instead MUTEX_ALL_ACCESS similar to OpenProcess function dwDesiredAccess parameter.
Forgive me for wasting your precious time.