Article Preview
Buy Now
COLUMN
Allow only one application instance to run at the same time.
About using the Windows API to create a mutex object.
Issue: 2.2 (October/November 2003)
Author: Christian Schmitz
Author Bio: Christian Schmitz is the creator of the Monkeybread Software REALbasic Plugins.
Article Description: No description available.
Article Length (in bytes): 10,746
Starting Page Number: 42
Article Number: 2220
Resource File(s):
2220.zip Updated: 2013-03-11 19:07:57
Related Web Link(s):
http://msdn.microsoft.com/library/en-us/dllproc/base/releasemutex.asp
Excerpt of article text...
What do we want?
If you double click an application file in Windows, you will notice that the application is launched even if it is already running. So you can launch several application instances from one application file in Windows.
For many applications this is not what developers want. So they do some magic stuff to avoid the second application instance. You can do this several ways:
1. You can check the temporary folder to see if there is a special file there. If the file exists you have a second copy running, else you create the file. As your application will fail to delete the file when it crashes, we don't use this way to solve our problem.
2. If you do networking in your application via sockets, you can handle the case of a special string being received from an incoming socket by responding with some other string. When your application is started, have it open a connection to "127.0.0.1" (localhost). If the connection is accepted and the other side answers with the correct string, you know your application is already running.
...End of Excerpt. Please purchase the magazine to read the full article.