C++/(Windows)Create Mutex로 중복 실행 제어 Edit Diff Refresh Backlink Random Search History Help Setting Hide Show 실행 시 # BOOL CheckValidApp() { DWORD dwError; SECURITY_DESCRIPTOR sd = {0,}; InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION); SetSecurityDescriptorDacl(&sd, TRUE, 0, FALSE); SECURITY_ATTRIBUTES sa = {0,}; sa.nLength = sizeof(SECURITY_ATTRIBUTES); sa.lpSecurityDescriptor = &sd ; m_hMutex = ::CreateMutex(&sa, TRUE, _T("name_of_my_mutex")); dwError = ::GetLastError(); if (m_hMutex == NULL) return FALSE; if (dwError == ERROR_ALREADY_EXISTS) { DWORD dwWaitResult = 0; dwWaitResult = WaitForSingleObject(m_hMutex, 3000); switch(dwWaitResult) { case WAIT_TIMEOUT: ::ReleaseMutex(m_hMutex); ::CloseHandle(m_hMutex); return FALSE; case WAIT_OBJECT_0: return TRUE; case WAIT_ABANDONED: return TRUE; default: break; } return FALSE; } return TRUE; } 종료 시 # OnDestroy 등에서 뮤텍스 제거 이 글에는 0 개의 댓글이 있습니다. Please enable JavaScript to view the comments powered by Disqus. comments powered by Disqus