Home
Tutorials
Code Snippets
Code Samples
Downloads
Links

The Blog
Our Projects
About
Contact

::Add RageStorm to Favorites!::

The Blog | Our Projects | Guest Book | About | Contact

 
Code Snippet - One Instance Simultaneously
Author:Arkon
Category:Win32API
File Size:444 Bytes
Uploaded at:27-Nov-02 07:24:56 pm
Description:
  A specific implementation using Mutex to limit an application to run only once at a time.
  
 HANDLE hMutex;
 hMutex = CreateMutex(NULL, FALSE, "QSoftObjName");
 if (GetLastError() == ERROR_ALREADY_EXISTS)
 {
  MessageBox(NULL, "You can open only one instance of <app name>!", "<app name>", MB_OK);
  CloseHandle(hMutex);   // The original code in the line above was "ReleaseMutex"   // which is wrong because this thread didn't create this mutex.   // Thanks again Torando...15/01/03
  return(0);
 }

 ReleaseMutex(hMutex); // Ofcourse, don't forget to clean up, thanks Tornado for reminding me :)
//BTW- There are a few other ways to achieve this goal...But this is the easiest one IMHO.
User Contributed Comments(None)
NOTE:
Comments that will hurt anyone in any way will be deleted.
Don't ask for features, advertise or curse.
If you want to leave a message to the author use the contacts,
if you have any question in relation to your comments please use the forum.
Comments which violate any of these requests will be deleted without further
notice. Use the comment system decently.

Post your comment:
Name:
email:
Comment:
::Top 5 Tutorials::
Embedded Python[116853]
2D Rotated Rectangles Collision Detection[88946]
Keyboard Hook[77243]
UDP[65798]
HTTP Proxy[41188]

::Top 5 Samples::
2D ColDet Rotated Rectangles[11557]
PS2 Mouse Driver[6953]
Wave Format Player[5788]
Reading FAT12[5615]
CodeGuru[5355]


All rights reserved to RageStorm © 2009