Class to detect multiple launches of a desktop application.
For some applications, it's desired that only a single instance is allowed to be running systemwide. This class will create a global object that's visible systemwide and if this object is in existence when this class is queried, then it means that this class is running multiple times. If the function is_multi_launched() returns TRUE, then immediately exit the application since another is running elsewhere in the same system
{
exit(10);
}
DoStuff();
}
Class to detect multiple launches of a desktop application.
Definition burger.h:18580
uint_t is_multi_launched(const char *pSignature) noexcept
Test if this is the only instance of this class systemwide.
int BURGER_ANSIAPI main(int argc, const char **argv)
Definition detectlaunch.cpp:30
Burger::DetectMultiLaunch::is_multi_launched |
( |
const char * | pSignature | ) |
|
|
noexcept |
Test if this is the only instance of this class systemwide.
An object is created, for Windows, it's a FileMapping object of 32 bytes that stays in memory. If executed again, the recreation of the object will return a ERROR_ALREADY_EXISTS error that will tell the app there is already an instance running.
For Darwin, a named sem_t is created and if it's already created, it's assumed another instance already exists.
- Parameters
-
pSignature | Pointer to a UTF8 "C" string that's unique to the application |
- Returns
- TRUE if there is another instance of the application already running, FALSE if this is the only instance.