-
-
Save ademkocamaz/76a0fbd1ff03b0815024d782459c82e7 to your computer and use it in GitHub Desktop.
[C] Use Windows mutex to create a single instance app
This file contains hidden or 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