View Full Version : Open GL Program Instances....
How do you make sure that there is only one instance of your program running?
10-16-2000, 03:40 PM
Not really OpenGL related but, there are several ways to do that. Assuming Windows, one way is to broadcast a custom defined message and see if any apps respond. You could also enumerate the names of the various open windows, and check them. Or enumerate the currently running processes.
You could also check for an app defined global atom, and create it if it is not present. Just be sure to always destroy the atom, even when the app crashes.
[This message has been edited by DFrey (edited 10-16-2000).]
How exactly would you go about doing that?
10-17-2000, 11:03 PM
In former times the parameter hPrevInstance in your WinMain() function indicated that.
No this is what Microsoft recommends in the MSDN: (msdn.microsoft.com search for WinMain)
[in] Handle to the previous instance of the application. For a Win32-based application, this parameter is always NULL.
If you need to detect whether another instance already exists, create a uniquely named mutex using the CreateMutex function. CreateMutex will succeed even if the mutex already exists, but the GetLastError function will return ERROR_ALREADY_EXISTS. This indicates that another instance of your application exists, because it created the mutex first.
Not to be annoying or anything but i dont really understand all that...i am still a beginner so could you explain a bit more?
10-18-2000, 10:02 AM
if(!hmutex | | GetLastError()==ERROR_ALREADY_EXISTS)
Where hmutex is a HANDLE. Also make sure you destroy the mutex handle when the program exits (normally or abnormally) by calling CloseHandle(hmutex); Windows should automatically close the handle when the program exits but I don't trust it. http://www.opengl.org/discussion_boards/ubb/tongue.gif
You should probably also use a better mutex name than MYAPPMUTEX.
[This message has been edited by DFrey (edited 10-18-2000).]
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.