Index: src/ch/TShellExtensionClient.cpp =================================================================== diff -u -r8068e0c351055554340ac9755d1bc846893bf2b8 -rb2102d724fda96a2533b866dbf1efca9f499713b --- src/ch/TShellExtensionClient.cpp (.../TShellExtensionClient.cpp) (revision 8068e0c351055554340ac9755d1bc846893bf2b8) +++ src/ch/TShellExtensionClient.cpp (.../TShellExtensionClient.cpp) (revision b2102d724fda96a2533b866dbf1efca9f499713b) @@ -44,6 +44,8 @@ HRESULT hResult = CoInitializeEx(nullptr, COINIT_MULTITHREADED); if(SUCCEEDED(hResult)) m_bInitialized = true; + else if(hResult == RPC_E_CHANGED_MODE) + return S_FALSE; return hResult; } Index: src/ch/ch.cpp =================================================================== diff -u -rf8fcbbd1d2321cf0c8be79526c449384af654e49 -rb2102d724fda96a2533b866dbf1efca9f499713b --- src/ch/ch.cpp (.../ch.cpp) (revision f8fcbbd1d2321cf0c8be79526c449384af654e49) +++ src/ch/ch.cpp (.../ch.cpp) (revision b2102d724fda96a2533b866dbf1efca9f499713b) @@ -329,21 +329,31 @@ m_spLog = logger::MakeLogger(logger::TAsyncMultiLogger::GetInstance()->CreateLoggerData(strLogPath, m_spAppLoggerConfig), L"App"); LOG_INFO(m_spLog) << _T("============================ Initializing Copy Handler ============================"); - LOG_INFO(m_spLog) << _T(""); // ================================= COM ======================================== LOG_INFO(m_spLog) << _T("Initializing COM"); HRESULT hResult = CoInitializeEx(nullptr, COINIT_MULTITHREADED); if(FAILED(hResult)) { - CString strMsg; - strMsg.Format(_T("Cannot initialize COM, the application will now exit (result = 0x%lx)"), hResult); + // NOTE: with CH code (including external libraries directly referenced by it) the RPC_E_CHANGED_MODE error code + // should not occur. One of the users reported such problem - it is unclear whether there is something being injected + // into CH process or there is some other problem. It seems that RPC_E_CHANGED_MODE error is not a blocker to CH use, + // so we're allowing the initialization to continue. + if(hResult != RPC_E_CHANGED_MODE) + { + CString strMsg; + strMsg.Format(_T("Cannot initialize COM, the application will now exit (result = 0x%lx)"), hResult); - LOG_ERROR(m_spLog) << strMsg; - AfxMessageBox(strMsg, MB_ICONERROR | MB_OK); - return FALSE; + LOG_ERROR(m_spLog) << strMsg; + AfxMessageBox(strMsg, MB_ICONERROR | MB_OK); + return FALSE; + } + + LOG_WARNING(m_spLog) << L"COM already initialized (CoInitializeEx returned RPC_E_CHANGED_MODE)"; } + else + m_bComInitialized = true; // ================================= Resource manager ======================================== LOG_INFO(m_spLog) << _T("Initializing resource manager..."); @@ -792,8 +802,13 @@ m_tShellExtClient.Close(); - LOG_INFO(m_spLog) << _T("Pre-exit step - uninitializing COM"); - CoUninitialize(); + if(m_bComInitialized) + { + LOG_INFO(m_spLog) << _T("Pre-exit step - uninitializing COM"); + CoUninitialize(); + } + else + LOG_WARNING(m_spLog) << _T("COM was not initialized by CH. Leaving uninit to original caller."); LOG_INFO(m_spLog) << _T("============================ Leaving Copy Handler ============================"); Index: src/ch/ch.h =================================================================== diff -u -ra08ca9e12d93e9a036a5cf739348ff3ef2a58be8 -rb2102d724fda96a2533b866dbf1efca9f499713b --- src/ch/ch.h (.../ch.h) (revision a08ca9e12d93e9a036a5cf739348ff3ef2a58be8) +++ src/ch/ch.h (.../ch.h) (revision b2102d724fda96a2533b866dbf1efca9f499713b) @@ -75,6 +75,7 @@ logger::TMultiLoggerConfigPtr m_spEngineLoggerConfig; CWnd *m_pMainWindow; + bool m_bComInitialized = false; DECLARE_MESSAGE_MAP()