swg-launchpad/singleinstance.h
2013-11-13 13:54:48 +01:00

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