Jump to content
  • Advertisement
Sign in to follow this  
Raxvan

application detection

This topic is 4839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi all I am creating a project and i am just at the beginning. if a have the game already opened and i accidental enter again the game is there a way to detect the first game application and stop the second application or give a warning message?

Share this post


Link to post
Share on other sites
Advertisement
If your platform is Windows and your application creates a window you can use FindWindow() from the Win32 API to search for an active window of your application and terminate the program if one is found.

Example:

int main()
{
if(FindWindow("MyWindowClassName", NULL))
{
MessageBox(0, "Application already running", "Error", 0);
return(0);
}
else
{
// Create window here
}
}


If your program does not create a window, you could always create a named mutex and look for that instead. I suppose even creating a global atom would do although an object that is automatically cleaned up by the OS is probably best in case your app crashes and leaves something behind.


arm.

Share this post


Link to post
Share on other sites
Alternatively, you can tell Windows to create a mutex for you when your program starts. If you try and run your program again without exiting, you will fail to create the mutex, since you already created it. If it fails, you know there is another instance of your program running.
Quote:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createmutex.asp
If the function fails, the return value is NULL. To get extended error information, call GetLastError.

If the mutex is a named mutex and the object existed before this function call, the return value is a handle to the existing object and GetLastError returns ERROR_ALREADY_EXISTS

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!