• R/O
  • HTTP
  • SSH
  • HTTPS

xkeymacs: Commit


Commit MetaInfo

Revision98c0a1605ea8514bb51fe6d478b443c686dd2553 (tree)
Time2018-04-01 16:34:34
AuthorKazuhiro Fujieda <fujieda@user...>
CommiterKazuhiro Fujieda

Log Message

Reduce invocations of CoInitializeEx

Change Summary

Incremental Difference

--- a/xkeymacsdll/TSFHandler.cpp
+++ b/xkeymacsdll/TSFHandler.cpp
@@ -32,15 +32,19 @@ void TSFHandler::InitSink()
3232 {
3333 if (TLS::GetTSFHandler())
3434 return;
35- HRESULT hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
36- if (FAILED(hr)) {
37- DebugLog("CoInitializeEx failed.");
38- return;
39- }
40- if (hr == S_FALSE)
41- CoUninitialize();
4235 ITfThreadMgr *thread;
43- if (FAILED(CoCreateInstance(CLSID_TF_ThreadMgr, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&thread)))) {
36+ HRESULT hr = CoCreateInstance(CLSID_TF_ThreadMgr, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&thread));
37+ if (hr == CO_E_NOTINITIALIZED) {
38+ hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
39+ if (FAILED(hr)) {
40+ DebugLog("CoInitializeEx failed.");
41+ return;
42+ }
43+ if (hr == S_FALSE)
44+ CoUninitialize();
45+ hr = CoCreateInstance(CLSID_TF_ThreadMgr, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&thread));
46+ }
47+ if (FAILED(hr)) {
4448 DebugLog("CoCreateInstance for ThreadMgr failed.");
4549 return;
4650 }
--- a/xkeymacsdll/xkeymacsdll.cpp
+++ b/xkeymacsdll/xkeymacsdll.cpp
@@ -243,7 +243,6 @@ void CXkeymacsDll::ShowHookState()
243243 LRESULT CALLBACK CXkeymacsDll::CallWndProc(int nCode, WPARAM wParam, LPARAM lParam)
244244 {
245245 SetKeyboardHook();
246- TSFHandler::InitSink();
247246 if (nCode >= 0) {
248247 const CWPSTRUCT *cwps = reinterpret_cast<CWPSTRUCT *>(lParam);
249248 switch (cwps->message) {
@@ -341,6 +340,7 @@ LRESULT CALLBACK CXkeymacsDll::ShellProc(int nCode, WPARAM wParam, LPARAM lParam
341340 void CXkeymacsDll::InitKeyboardProc()
342341 {
343342 AppName::Init();
343+ TSFHandler::InitSink();
344344 if (m_CurrentConfig == NULL ||
345345 _tcsnicmp(m_CurrentConfig->AppName, AppName::GetAppName(), 0xF) || // PROCESSENTRY32 has only 0xF bytes of Name
346346 !CUtils::IsMatchWindowText(m_CurrentConfig->WindowText)) {
Show on old repository browser