-
January 20th, 2014, 01:15 AM
#1
Check "Application Running .."
Hi ,
For my project I need to check whether my application instance is already running or not.
I got the following code from Net ..
[code]
HANDLE mutex;
mutex = CreateMutex( NULL, TRUE, _T("MYAPPNAME"));
if ( GetLastError() == ERROR_ALREADY_EXISTS )
{
// There's another instance running. What do you do?
AfxMessageBox(_T("Application Already Exists"));
PostQuitMessage(0);
ExitThread(0);
return;
}
[\code]
The code works fine .. but the code even works fine , even if I pass any string as a parameter to CreateMutex.
for e.g.
mutex = CreateMutex( NULL, TRUE, _T("QQQQ"));
How it is working fine ? I am confused .. PL help
-
January 20th, 2014, 02:11 AM
#2
Re: Check "Application Running .."
Victor Nijegorodov
-
January 20th, 2014, 03:59 AM
#3
Re: Check "Application Running .."
-
January 20th, 2014, 08:59 AM
#4
Re: Check "Application Running .."
For uniqueness, it's handy to just generate a guid (from the tools\create guid menu item in Visual Studio).
_T("81804F9D-84EB-472F-8E33-1073424CE635")
Also, read up on the global namespace for mutex naming, in case multiple users are logged in or remoted in to the same machine.
P.S. Don't use the guid I've posted above because I'm using it.
-
January 21st, 2014, 07:43 AM
#5
Re: Check "Application Running .."
Originally Posted by Arjay
P.S. Don't use the guid I've posted above because I'm using it.
Not smart should've created a new one "just in case".
-
January 21st, 2014, 11:23 PM
#6
Re: Check "Application Running .."
Thank you all .. I will read more on this
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
|