|
-
June 30th, 1999, 09:22 AM
#1
NT - checking if another instance of a program is running
Hi!
I Use this code to check if another instance of a program is running. It works in win 95, but not in Windows NT.
If the program crasch in NT it is impossible to start it again, because the application thinks another instance is still running.
Is there any other way to solve this problem in windows NT?
/Beginner
<----------- CODE BEGIN --------------->
// Checking if another instance of a program is running
HANDLE hMapping;
int iRes;
hMapping = CreateFileMapping( (HANDLE) 0xffffffff,
NULL, PAGE_READONLY,
0, 32, "MyTestMap" );
loggfil.logga("WinMain - CreateFileMapping");
if( hMapping )
{ if( GetLastError() == ERROR_ALREADY_EXISTS )
{
loggfil.logga("WinMain - Another instance of ivclip is already running. Exiting.");
ExitProcess(1);
}
}
else
{ ExitProcess(1); }
-
June 30th, 1999, 09:40 AM
#2
Re: NT - checking if another instance of a program is running
you can try something like this in InitInstance() :
m_mutex = CreateMutex( NULL, TRUE, _T("MyApp"));
if( GetLastError() == ERROR_ALREADY_EXISTS) {
::MessageBox( NULL, _T("An instance is already running."),
_T("ERROR!"), MB_OK | MB_ICONEXCLAMATION );
return TRUE;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|