为了防止多次启动同一个应用程序,可以使用进程锁的方式来进行处理
在进程入口加入以下代码:
static HANDLE g_hMutex = NULL;
g_hMutex = ::CreateMutex(NULL, TRUE, _T("appmutex_for_[APPNAME]"));
DWORD dwRet = GetLastError();
if (dwRet == ERROR_ALREADY_EXISTS)
{
return FALSE;
}
在进程结束时加入以下代码:
if (g_hMutex)
{
::ReleaseMutex(g_hMutex);
::CloseHandle(g_hMutex);
g_hMutex = NULL;
}
即可实现该功能
浙公网安备 33010602011771号