How to catch if another instance of the program is running?
Printable View
How to catch if another instance of the program is running?
The usual way in Win32 is to have the program create a named global semaphore/mutex/whatever first thing. They can be queried for. If it already exists, the app is already running.
Here is an example:
Code:HANDLE g_hMutex;
//Create A Mutex
g_hMutex = CreateMutex( NULL, TRUE, "Program Name"); //Create A Mutex To Keep The Program From Running More Than Once
if (g_hMutex && (GetLastError() == ERROR_ALREADY_EXISTS ))
return 0;
Thanks a lot
If the problem is that you don't want more then one instance of your app to run. Then you should google on Singelton classes. It's a verey common way to just make one instance of an app run.