1
0
Эх сурвалжийг харах

Fixed issue with running multiple instances of the windows app at the same time

Scott Brogden 9 жил өмнө
parent
commit
9ff6d65ac7
1 өөрчлөгдсөн 9 нэмэгдсэн , 2 устгасан
  1. 9 2
      CP_Main.cpp

+ 9 - 2
CP_Main.cpp

@@ -261,10 +261,15 @@ BOOL CCP_MainApp::InitInstance()
 		csMutex += g_Opt.GetExeFileName();
 	}
 
-	m_hMutex = CreateMutex(NULL, FALSE, csMutex);
+	//create mutex doesn't like slashes, remove them, it always returns NULL with them in
+	csMutex.Replace(_T("\\"), _T("_"));
+
+	m_hMutex = CreateMutex(NULL, TRUE, csMutex);
 	DWORD dwError = GetLastError();
-	if(dwError == ERROR_ALREADY_EXISTS)
+	if(m_hMutex == NULL ||
+		dwError == ERROR_ALREADY_EXISTS)
 	{
+		Log(StrF(_T("Ditto is already running, closing, mutex: %s"), csMutex));
 		HWND hWnd = (HWND)CGetSetOptions::GetMainHWND();
 		if(hWnd)
 			::SendMessage(hWnd, WM_SHOW_TRAY_ICON, TRUE, TRUE);
@@ -272,6 +277,8 @@ BOOL CCP_MainApp::InitInstance()
 		return TRUE;
 	}
 
+	Log(StrF(_T("Starting up ditto with mutex: %s"), csMutex));
+
 	CString csFile = CGetSetOptions::GetLanguageFile();
 	if(m_Language.LoadLanguageFile(csFile) == false)
 	{