Skip to content

Commit

Permalink
Remove GetProcAddress to TF_CreateCategoryMgr
Browse files Browse the repository at this point in the history
This is a preparation to remove the dependency on CoCreateInstance from
mozc_tip{32,64}.dll to comply with GUID_TFCAT_TIPCAP_COMLESS (google#837).

With my previous commit [1], we now create an import library for
msctf.dll as part of our build process.  With this commit,
mozc_tip{32,64}.dll actually start importing TF_CreateCategoryMgr from
msctf.dll in an implicit manner.  This should be safer and more
efficient than relying on GetProcAddress as long as the API in question
is guaranteed to exist.

Note that we have already done the same optimization for input.dll [2].

There should be no user observable behavior change.

#codehealth

 [1]: 006084c
 [2]: f470414

PiperOrigin-RevId: 576674633
  • Loading branch information
yukawa authored and hiroyuki-komatsu committed Oct 25, 2023
1 parent 9b5e4ed commit 919c912
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/win32/tip/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ mozc_cc_library(
"//base/win32:hresult",
"//base/win32:hresultor",
"//protocol:commands_cc_proto",
"//win32/base:msctf_dll",
"//win32/base:win32_window_util",
"@com_google_absl//absl/base",
"@com_google_absl//absl/container:flat_hash_map",
Expand Down
1 change: 1 addition & 0 deletions src/win32/tip/tip.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
'../base/win32_base.gyp:ime_base',
'../base/win32_base.gyp:ime_impl_base',
'../base/win32_base.gyp:imframework_util',
'../base/win32_base.gyp:msctf_dll_import_lib',
'../base/win32_base.gyp:text_icon',
],
},
Expand Down
12 changes: 1 addition & 11 deletions src/win32/tip/tip_text_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,18 +240,8 @@ void EnsureKanaLockUnlocked() {

// A COM-independent way to instantiate Category Manager object.
wil::com_ptr_nothrow<ITfCategoryMgr> GetCategoryMgr() {
const HMODULE module = WinUtil::GetSystemModuleHandle(L"msctf.dll");
if (module == nullptr) {
return nullptr;
}
const auto tf_create_tegory_mgr =
reinterpret_cast<decltype(&TF_CreateCategoryMgr)>(
GetProcAddress(module, "TF_CreateCategoryMgr"));
if (tf_create_tegory_mgr == nullptr) {
return nullptr;
}
wil::com_ptr_nothrow<ITfCategoryMgr> ptr;
return SUCCEEDED(tf_create_tegory_mgr(&ptr)) ? ptr : nullptr;
return SUCCEEDED(TF_CreateCategoryMgr(&ptr)) ? ptr : nullptr;
}

// Custom hash function for wil::com_ptr_nothrow.
Expand Down

0 comments on commit 919c912

Please sign in to comment.