Anybody know how I would go about detecting other instances of a program, to ensure that only one instance is ever running?
Anybody know how I would go about detecting other instances of a program, to ensure that only one instance is ever running?
Code:void function(void) { function(); }
The common technique is to use mutexes.
http://msdn.microsoft.com/en-us/libr...27(VS.85).aspx
Simply CreateMutex() when the program starts and CloseHandle() on exit (optional). If CreateMutex() fails and GetLastError() returns ERROR_ALREADY_EXISTS, then you know one instance is already running.
Last edited by maxorator; 01-14-2009 at 03:10 PM.
"The Internet treats censorship as damage and routes around it." - John Gilmore
Did you try a search?
8 years ago I posted code to do this with file mapping. Many others have posted similar code.
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill
First codes on Win32 mutexes appeared more than 8 years ago
Google Groups : first reference : 1995... : 14 years ago...
Well, in this case, it's a pseudo-standalone screensaver, which you can activate on command in addition to letting Windows activate it for you. It wouldn't really hurt anything, I suppose, to have multiple instances, but I like to be neat. Thanks, guys.
Code:void function(void) { function(); }