Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Open GL Program Instances....

  1. #1
    Guest

    Open GL Program Instances....

    How do you make sure that there is only one instance of your program running?

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jun 2000
    Location
    Shreveport, LA, USA
    Posts
    1,505

    Re: Open GL Program Instances....

    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).]

  3. #3
    Guest

    Re: Open GL Program Instances....

    How exactly would you go about doing that?

  4. #4
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,453

    Re: Open GL Program Instances....

    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)
    >>>
    hPrevInstance
    [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.
    <<<

  5. #5
    Guest

    Re: Open GL Program Instances....

    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?

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Jun 2000
    Location
    Shreveport, LA, USA
    Posts
    1,505

    Re: Open GL Program Instances....

    Something like:
    Code :
    	hmutex=CreateMutex(NULL,FALSE,"MYAPPMUTEX");
    	if(!hmutex | | GetLastError()==ERROR_ALREADY_EXISTS)
    		return FALSE;
    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.

    You should probably also use a better mutex name than MYAPPMUTEX.




    [This message has been edited by DFrey (edited 10-18-2000).]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •