Skip to content

Commit 96ca966

Browse files
authored
Merge pull request #287 from appergb/fix/windows-ime-static-crt
fix(windows-ime): 静态链接 CRT 防 host 进程 MSVCP140 劫持(修 QQ 切微软拼音崩溃)
2 parents 2bd77fe + 901e9df commit 96ca966

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

openless-all/app/windows-ime/OpenLessIme.vcxproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@
7575
<PreprocessorDefinitions>WIN32;_WINDOWS;_USRDLL;OPENLESSIME_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
7676
<ConformanceMode>true</ConformanceMode>
7777
<LanguageStandard>stdcpp17</LanguageStandard>
78+
<!-- 静态链接 CRT:让 OpenLessIme.dll 自带 MSVCP / VCRUNTIME / UCRT,
79+
避免被宿主进程(如 QQ)app/ 目录下的私有 MSVCP140 副本劫持。
80+
QQ 把 MSVCP140.dll 放在 versions/<ver>/resources/app/,DLL 搜索
81+
顺序优先 → 我们的 std::* 调用会跑 QQ 那份旧版 → ABI 漂移 → 0xc0000005。
82+
DLL 大小 +~300 KB;DLL 内部 STL 不再可跨边界共享(我们也不需要)。 -->
83+
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
7884
</ClCompile>
7985
<Link>
8086
<SubSystem>Windows</SubSystem>
@@ -89,6 +95,7 @@
8995
<PreprocessorDefinitions>WIN32;_WINDOWS;_USRDLL;OPENLESSIME_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
9096
<ConformanceMode>true</ConformanceMode>
9197
<LanguageStandard>stdcpp17</LanguageStandard>
98+
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
9299
</ClCompile>
93100
<Link>
94101
<SubSystem>Windows</SubSystem>
@@ -105,6 +112,7 @@
105112
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;OPENLESSIME_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
106113
<ConformanceMode>true</ConformanceMode>
107114
<LanguageStandard>stdcpp17</LanguageStandard>
115+
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
108116
</ClCompile>
109117
<Link>
110118
<SubSystem>Windows</SubSystem>
@@ -123,6 +131,7 @@
123131
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;OPENLESSIME_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
124132
<ConformanceMode>true</ConformanceMode>
125133
<LanguageStandard>stdcpp17</LanguageStandard>
134+
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
126135
</ClCompile>
127136
<Link>
128137
<SubSystem>Windows</SubSystem>

openless-all/app/windows-ime/src/dllmain.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ LONG g_object_count = 0;
1313
BOOL APIENTRY DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) {
1414
UNREFERENCED_PARAMETER(reserved);
1515

16+
// 不调用 DisableThreadLibraryCalls:DLL 现在用 /MT 静态链接 CRT,CRT 需要
17+
// DLL_THREAD_ATTACH / DLL_THREAD_DETACH 通知做 per-thread TLS 初始化与清理。
18+
// 在 host 进程(如 QQ / Office)切输入法新建 input thread 时禁用通知,会让
19+
// 静态 CRT 的 thread-local 资源泄漏 / 行为不稳定,反而把这次想修的崩溃问题
20+
// 重新引回来。详见 Microsoft 文档 DisableThreadLibraryCalls 备注。
1621
if (reason == DLL_PROCESS_ATTACH) {
1722
g_module = instance;
18-
DisableThreadLibraryCalls(instance);
1923
}
2024

2125
return TRUE;

0 commit comments

Comments
 (0)