Skip to content

Commit

Permalink
Prevent multiple instances of the program.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryandw11 committed Dec 16, 2021
1 parent 18c554e commit 392a3eb
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions AutoClickerDL/AutoClickerDL.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ LRESULT CALLBACK SettingsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam

// Main method.
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) {
// Prevent more than 1 instance of the program from running.
HANDLE mutexHandle = CreateMutex(NULL, TRUE, L"com_ryandw11_autoclickerdl");
if (GetLastError() == ERROR_ALREADY_EXISTS) {
MessageBox(NULL, L"AutoClickerDL is already running! Please close the exisiting instance of the program before opening it again.", L"AutoClickerDL Already Open", MB_OK | MB_ICONERROR);
return 0;
}

// Class name of the window.
const wchar_t CLASS_NAME[] = L"AutoClickerDL Window Class";

Expand Down Expand Up @@ -210,6 +217,9 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
DispatchMessage(&msg);
}

ReleaseMutex(mutexHandle);
CloseHandle(mutexHandle);

return 0;
}

Expand Down

0 comments on commit 392a3eb

Please sign in to comment.