본문 바로가기
IT-개발,DB

[개발/MFC] 중복실행 방지하기

by SB리치퍼슨 2011. 9. 20.
[개발/MFC] 중복실행 방지하기

TCHAR szAppName[] = _T("sbrich");
HANDLE  hMutex  = NULL;
 
bool IsSecondInstance()
{
bool isSecondInstance = false;
hMutex = CreateMutex(NULL, NULL, szAppName);
int iLastError          = GetLastError();
 
if(hMutex && (ERROR_ACCESS_DENIED == iLastError || ERROR_ALREADY_EXISTS == iLastError))
{
ReleaseMutex(hMutex);
hMutex = NULL;
isSecondInstance = true;
}
 
return isSecondInstance;
}


int  main()
{
if(IsSecondInstance())
{
MessageBox(NULL, _T("One Instance Is Already Running."), _T("Information"), 0);
return 0;
}
 
/*App Code Goes Here...*/
 
ReleaseMutex(m_hMutex);
m_hMutex    =   NULL;
return 0;
}

반응형

댓글