Stopping multiple copies of application from opening
-
Hi all I have a program written in VC6 (running on XP) that I want to stop from having multiple copies open. I want it to check whether there is another instance of itself running on start up and close if there is. Using FindWindow() doesnt work as it finds itself! Thanks for any help Mike
-
Hi all I have a program written in VC6 (running on XP) that I want to stop from having multiple copies open. I want it to check whether there is another instance of itself running on start up and close if there is. Using FindWindow() doesnt work as it finds itself! Thanks for any help Mike
Consider creating a global named mutex. Each app does this: 1) Create mutex -- give it a unique name, possibly including a GUID 2) WaitForSingleObject -- to capture the mutex. If this fails, then there's someone else holding it. On exit, ReleaseMutex() to give it up -- and make it available again.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Peter Weyzen Staff Engineer [SoonR Inc -- PC Power delivered to your phone](http://www.soonr.com)
-
Hi all I have a program written in VC6 (running on XP) that I want to stop from having multiple copies open. I want it to check whether there is another instance of itself running on start up and close if there is. Using FindWindow() doesnt work as it finds itself! Thanks for any help Mike
You can try creating a named mutex with CreateMutex() API and checking the result with GetLastError(). When the second instance of the app tries to create it, GetLastError() will return ERROR_ALREADY_EXISTS as the mutex is already created by the first instance. http://vcfaq.mvps.org/mfc/2.htm
-
Hi all I have a program written in VC6 (running on XP) that I want to stop from having multiple copies open. I want it to check whether there is another instance of itself running on start up and close if there is. Using FindWindow() doesnt work as it finds itself! Thanks for any help Mike
See here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
Hi all I have a program written in VC6 (running on XP) that I want to stop from having multiple copies open. I want it to check whether there is another instance of itself running on start up and close if there is. Using FindWindow() doesnt work as it finds itself! Thanks for any help Mike
Use this code..
if(NULL!=:CreateMutex(NULL,TRUE,_T("SingleInstanceApp")))
{
long DwError = ::GetLastError();
if(dwError == ERROR_ALREDY_EXISTS)
EndDialog(IDOK)
}Hope it helps
-
Hi all I have a program written in VC6 (running on XP) that I want to stop from having multiple copies open. I want it to check whether there is another instance of itself running on start up and close if there is. Using FindWindow() doesnt work as it finds itself! Thanks for any help Mike
I would also have a look at the articles here on codeproject... (shocking idea, I know...) eg: Limiting an application to a single Instance - the MFC way[^] is a great one. Just read my comments at the end to make it work. Iain.
I have now moved to Sweden for love (awwww).