mirror of
https://github.com/swgemu/Launchpad
synced 2026-08-16 20:26:03 -04:00
29 lines
606 B
C++
29 lines
606 B
C++
#ifndef SINGLEINSTANCE_H
|
|
#define SINGLEINSTANCE_H
|
|
|
|
#include "Windows.h"
|
|
|
|
class SingleInstance {
|
|
protected:
|
|
HANDLE instanceMutex;
|
|
DWORD lastError;
|
|
public:
|
|
SingleInstance(TCHAR* mutexName) {
|
|
instanceMutex = CreateMutex(NULL, FALSE, mutexName);
|
|
lastError = GetLastError();
|
|
}
|
|
|
|
~SingleInstance() {
|
|
if (instanceMutex) {
|
|
CloseHandle(instanceMutex);
|
|
instanceMutex = NULL;
|
|
}
|
|
}
|
|
|
|
bool isAnotherInstanceRunning() {
|
|
return (ERROR_ALREADY_EXISTS == lastError);
|
|
}
|
|
|
|
};
|
|
|
|
#endif // SINGLEINSTANCE_H
|