Something from the past, I first posted it over 10 years ago....
Originally Posted by Superfreak3
You should just remove the messagebox bit and exit.
Your app should call CloseHandle(hMapping) when it exists.
hMapping = CreateFileMapping(INVALID_HANDLE_VALUE, NULL,PAGE_READONLY, 0, 32, szAppName);
if (hMapping)// Check to see if app is already running
if (GetLastError() == ERROR_ALREADY_EXISTS)
sprintf(sBuffer,"%s is already running. Create another instance?",szAppName);
if(MessageBox(NULL, sBuffer,"Error",MB_ICONERROR| MB_YESNO)==IDNO)
MessageBox(NULL, "Error creating file mapping.", "Error",MB_ICONERROR| MB_OK);
How do you only allow one instance of an app?