Skip to content

Commit

Permalink
Prevent multiple instances, closes issue 14
Browse files Browse the repository at this point in the history
  • Loading branch information
nlp80 committed Oct 20, 2018
1 parent ac7966a commit fb532f6
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions irFFB/irFFB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ WCHAR szTitle[MAX_LOADSTRING];
WCHAR szWindowClass[MAX_LOADSTRING];
NOTIFYICONDATA niData;

HANDLE globalMutex;

HANDLE debugHnd = INVALID_HANDLE_VALUE;
wchar_t debugLastMsg[512];
LONG debugRepeat = 0;
Expand Down Expand Up @@ -583,6 +585,11 @@ int APIENTRY wWinMain(

}

globalMutex = CreateMutex(NULL, false, L"Global\\irFFB_Mutex");

if (GetLastError() == ERROR_ALREADY_EXISTS)
exit(0);

INITCOMMONCONTROLSEX ccEx;

HANDLE handles[1];
Expand Down Expand Up @@ -1644,6 +1651,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
hidGuardian->stop(GetCurrentProcessId());
if (debugHnd != INVALID_HANDLE_VALUE)
CloseHandle(debugHnd);
CloseHandle(globalMutex);
exit(0);
}
break;
Expand Down

0 comments on commit fb532f6

Please sign in to comment.