From 901e9dfe3f2595ecf02d92c7f33de79205e07ff6 Mon Sep 17 00:00:00 2001 From: baiqing Date: Wed, 6 May 2026 19:07:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(windows-ime):=20=E7=A7=BB=E9=99=A4=20Disabl?= =?UTF-8?q?eThreadLibraryCalls=20=E2=80=94=20/MT=20=E4=B8=8B=E9=9C=80=20th?= =?UTF-8?q?read=20=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Codex P1 (PR #287):DLL 改用 /MT 静态链接 CRT 后,仍调 DisableThreadLibraryCalls(instance) 会让静态 CRT 拿不到 DLL_THREAD_DETACH 通知,per-thread TLS 初始化/清理断裂 — 在 host 进程(QQ / Office / 微软拼音切换)创建新 input thread 时反而把这次想修的崩溃问题重新引回。 Microsoft 文档 DisableThreadLibraryCalls 备注明确:使用 static CRT 的 DLL 不应禁用 thread library calls。 修复:删除该调用;保留 g_module 缓存。 --- openless-all/app/windows-ime/src/dllmain.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/openless-all/app/windows-ime/src/dllmain.cpp b/openless-all/app/windows-ime/src/dllmain.cpp index 84476ba2..624c79f7 100644 --- a/openless-all/app/windows-ime/src/dllmain.cpp +++ b/openless-all/app/windows-ime/src/dllmain.cpp @@ -13,9 +13,13 @@ LONG g_object_count = 0; BOOL APIENTRY DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) { UNREFERENCED_PARAMETER(reserved); + // 不调用 DisableThreadLibraryCalls:DLL 现在用 /MT 静态链接 CRT,CRT 需要 + // DLL_THREAD_ATTACH / DLL_THREAD_DETACH 通知做 per-thread TLS 初始化与清理。 + // 在 host 进程(如 QQ / Office)切输入法新建 input thread 时禁用通知,会让 + // 静态 CRT 的 thread-local 资源泄漏 / 行为不稳定,反而把这次想修的崩溃问题 + // 重新引回来。详见 Microsoft 文档 DisableThreadLibraryCalls 备注。 if (reason == DLL_PROCESS_ATTACH) { g_module = instance; - DisableThreadLibraryCalls(instance); } return TRUE;