[ Home | Contents | Search | Next | Previous | Up ]
Date: 11/30/99
Time: 12:36:43 AM
Q. Mutliple Instance problem in Win32!
A. You can create a named Mutex like this:
-------
char szAppName[14] = "MyApplication";
HANDLE hFirst;
int OwlMain(int /*argc*/, char* /*argv[]*/)
{
int Ret = 0;
hFirst = CreateMutex(NULL, FALSE, szAppName);
if (hFirst == (HANDLE)NULL)
return Ret;
else if (GetLastError() == ERROR_ALREADY_EXISTS) {
MessageBox(NULL, "Operation
Notice\n\nApplication already running!", szAppName, MB_OK |
MB_ICONINFORMATION);
CloseHandle(hFirst); // close this handle - not
the other one running.
return Ret;
}
// run application here and get Ret...
CloseHandle(hFirst);
return Ret;
}
- rj