Last active
July 1, 2023 22:08
-
-
Save mistic100/2a40e96220f7482827d7 to your computer and use it in GitHub Desktop.
[C] Use Windows mutex to create a single instance app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
int main(int argc, char *argv[]) | |
{ | |
// ensure only one running instance | |
HANDLE hMutexHandle = CreateMutex(NULL, TRUE, L"my.mutex.name"); | |
if (GetLastError() == ERROR_ALREADY_EXISTS) | |
{ | |
return 0; | |
} | |
// rest of the program | |
ReleaseMutex(hMutexHandle); | |
CloseHandle(hMutexHandle); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment