Skip to content

Commit

Permalink
Create an import library for 'msctf.dll'
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 (#837).

The idea is the same as my previous commit for input.dll [1].

Note that this commit only creates an import library with unit tests,
and the production code has not been updated to use it yet.  Thus there
must be no observable behavior change (yet).

#codehealth

 [1]: f470414

PiperOrigin-RevId: 576415439
  • Loading branch information
yukawa authored and hiroyuki-komatsu committed Oct 25, 2023
1 parent 13bb7cc commit 006084c
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/win32/base/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,31 @@ mozc_cc_test(
],
)

lexan.cc_windows_dll(
name = "msctf_dll",
srcs = [
"msctf_dll.cc",
],
tags = MOZC_TAGS.WIN_ONLY,
target_compatible_with = ["@platforms//os:windows"],
win_def_file = "msctf_dll.def",
deps = [
"//base:logging",
],
)

mozc_cc_test(
name = "msctf_dll_test",
srcs = ["msctf_dll_test.cc"],
tags = MOZC_TAGS.WIN_ONLY,
target_compatible_with = ["@platforms//os:windows"],
deps = [
":msctf_dll",
"//testing:gunit_main",
"@com_microsoft_wil//:wil",
],
)

mozc_cc_library(
name = "string_util",
srcs = ["string_util.cc"],
Expand Down
60 changes: 60 additions & 0 deletions src/win32/base/msctf_dll.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2010-2021, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// This file will be used to create an import library. Functions in this
// file must not be called directly.

#include <windows.h>

#include "base/logging.h"

class ITfCategoryMgr;
class ITfLangBarItemMgr;
class ITfInputProcessorProfiles;

extern "C" UINT WINAPI
TF_CreateCategoryMgr(__out ITfCategoryMgr **profile_mgr) {
CHECK(false) << "This is a stub function to create an import library. "
<< "Shouldn't be called from anywhere.";
return 0;
}

extern "C" UINT WINAPI
TF_CreateInputProcessorProfiles(__out ITfInputProcessorProfiles **pplbim) {
CHECK(false) << "This is a stub function to create an import library. "
<< "Shouldn't be called from anywhere.";
return 0;
}

extern "C" UINT WINAPI
TF_CreateLangBarItemMgr(__out ITfLangBarItemMgr **pplbim) {
CHECK(false) << "This is a stub function to create an import library. "
<< "Shouldn't be called from anywhere.";
return 0;
}
6 changes: 6 additions & 0 deletions src/win32/base/msctf_dll.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
LIBRARY msctf.dll

EXPORTS
TF_CreateCategoryMgr
TF_CreateInputProcessorProfiles
TF_CreateLangBarItemMgr
70 changes: 70 additions & 0 deletions src/win32/base/msctf_dll_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2010-2021, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <combaseapi.h>
#include <msctf.h>
#include <wil/com.h>
#include <windows.h>

#include "testing/gunit.h"

namespace {

void AssertComIsNotInitialized() {
APTTYPE type = APTTYPE_CURRENT;
APTTYPEQUALIFIER filter = APTTYPEQUALIFIER_NONE;
HRESULT result = ::CoGetApartmentType(&type, &filter);
EXPECT_EQ(result, CO_E_NOTINITIALIZED);
}

TEST(MsctfDllTest, CreateITfCategoryMgr) {
AssertComIsNotInitialized();

wil::com_ptr_nothrow<ITfCategoryMgr> obj;
HRESULT result = TF_CreateCategoryMgr(&obj);
EXPECT_EQ(result, S_OK);
}

TEST(MsctfDllTest, CreateInputProcessorProfiles) {
AssertComIsNotInitialized();

wil::com_ptr_nothrow<ITfInputProcessorProfiles> obj;
HRESULT result = TF_CreateInputProcessorProfiles(&obj);
EXPECT_EQ(result, S_OK);
}

TEST(MsctfDllTest, CreateLangBarItemMgr) {
AssertComIsNotInitialized();

wil::com_ptr_nothrow<ITfLangBarItemMgr> obj;
HRESULT result = TF_CreateLangBarItemMgr(&obj);
EXPECT_EQ(result, S_OK);
}

} // namespace
34 changes: 34 additions & 0 deletions src/win32/base/win32_base.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,39 @@
},
},
},
{
'target_name': 'msctf_dll_import_lib',
'type': 'shared_library',
'sources': [
'msctf_dll.cc',
'msctf_dll.def',
],
'dependencies': [
'<(mozc_src_dir)/base/base.gyp:base',
],
'msvs_settings': {
'VCLinkerTool': {
'AdditionalOptions': [
'/ignore:4070',
],
},
},
},
{
'target_name': 'msctf_dll_test',
'type': 'executable',
'sources': [
'msctf_dll_test.cc',
],
'dependencies': [
'<(mozc_src_dir)/base/base.gyp:base',
'<(mozc_src_dir)/testing/testing.gyp:gtest_main',
'msctf_dll_import_lib',
],
'variables': {
'test_size': 'small',
},
},
{
'target_name': 'imframework_util',
'type': 'static_library',
Expand Down Expand Up @@ -209,6 +242,7 @@
'dependencies': [
'ime_impl_base_test',
'imframework_util_test',
'msctf_dll_test',
'text_icon_test',
'win32_base_test',
],
Expand Down

0 comments on commit 006084c

Please sign in to comment.