How to Run only One Instance of my Application at a time
-
I want to run only one instance of my application at a time at my User's PC . if he try to run another instance by clicking on EXE ,, he will recvie an error message. i have a little idea , i thin it is by some static function and static data member to have count of instances. ... and there may b a rule of Constructor .. but i cant do it ..where to write and how any idea or Code sample thanx
-
I want to run only one instance of my application at a time at my User's PC . if he try to run another instance by clicking on EXE ,, he will recvie an error message. i have a little idea , i thin it is by some static function and static data member to have count of instances. ... and there may b a rule of Constructor .. but i cant do it ..where to write and how any idea or Code sample thanx
http://www.codeproject.com/cpp/avoidmultinstance.asp[^]
[
](http://www.canucks.com)"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!
-
I want to run only one instance of my application at a time at my User's PC . if he try to run another instance by clicking on EXE ,, he will recvie an error message. i have a little idea , i thin it is by some static function and static data member to have count of instances. ... and there may b a rule of Constructor .. but i cant do it ..where to write and how any idea or Code sample thanx
//---------------------------------------------------------------------------------------------------// //check if the application is already running... bool bAlreadyRunning; HANDLE hMutexOneInstance = CreateMutex( NULL, TRUE, "Pointer to a null-terminated string specifying the name of the mutex object."); bAlreadyRunning = ( GetLastError() == ERROR_ALREADY_EXISTS ); if ( hMutexOneInstance ) { ReleaseMutex( hMutexOneInstance ); } if ( bAlreadyRunning ) { //AfxMessageBox("Application is already running"); return FALSE; } //---------------------------------------------------------------------------------------------------// Include this code in the InitInstance of your app. This will do the trick for you.