Skip to content

Instantly share code, notes, and snippets.

@polovik
Last active August 29, 2015 13:59
Show Gist options
  • Save polovik/10714312 to your computer and use it in GitHub Desktop.
Save polovik/10714312 to your computer and use it in GitHub Desktop.
Verify unique instance of application in WinApi (Visual Studio C++)
int CALLBACK wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
{
// Avoid multiple instances of application
const WCHAR *applicationMutexName = L"autorun_st";
HANDLE mutexAppHandle = CreateMutex(NULL, TRUE, applicationMutexName);
if (GetLastError() == ERROR_ALREADY_EXISTS) {
CloseHandle(mutexAppHandle);
return EXIT_FAILURE;
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment