Or my favorite (again at teh begining of WinMain)
Code:
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)
{
CloseHandle(hMapping);
ExitProcess(1);
}
}
}
else
{
MessageBox(NULL, "Error creating file mapping.", "Error",MB_ICONERROR| MB_OK);
ExitProcess(1);
}
and CloseHandle(hMapping); on exit