From ef545cca207f8389ab6ce7cadda670cb42e6fedb Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Thu, 23 Nov 2023 14:58:28 +0800 Subject: [PATCH] =?UTF-8?q?fix=20bug-740:=20=E4=B8=BA=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E6=A1=86=E6=9F=A5=E6=89=BE=E7=88=B6=E7=AA=97=E5=8F=A3=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E9=80=9A=E8=BF=87=E9=85=8D=E7=BD=AE=EF=BC=88[twain-ap?= =?UTF-8?q?p]check-main-wnd-thread-id=3D0/1=EF=BC=89=E5=86=B3=E5=AE=9A?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E9=9C=80=E8=A6=81=E5=90=8C=E4=B8=80=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=EF=BC=8C=E9=BB=98=E8=AE=A4=E4=B8=8D=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E3=80=82A+=E7=A8=8B=E5=BA=8F=E5=BC=BA=E5=88=B6=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sane/scanner.cpp | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/sane/scanner.cpp b/sane/scanner.cpp index fa53683..c1db35b 100644 --- a/sane/scanner.cpp +++ b/sane/scanner.cpp @@ -241,13 +241,16 @@ namespace callback return ""; } + static bool check_wnd_thread_id = false; static BOOL CALLBACK main_wnd(HWND hwnd, LPARAM param) { - DWORD pid = 0; + DWORD pid = 0, + tid = GetWindowThreadProcessId(hwnd, &pid); - GetWindowThreadProcessId(hwnd, &pid); if (pid != GetCurrentProcessId()) return TRUE; + if (check_wnd_thread_id && tid != GetCurrentThreadId()) + return TRUE; if (((void**)param)[1] == NULL) { @@ -293,6 +296,11 @@ namespace callback HWND wnd[2] = { NULL }; EnumWindows(main_wnd, (LPARAM)wnd); + { + wchar_t mw[128] = { 0 }; + swprintf_s(mw, _countof(mw) - 1, L"find_main_wnd of thread %u = 0x%x\r\n", GetCurrentThreadId(), wnd[0]); + log_info(mw, 1); + } return wnd[0]; } @@ -3816,11 +3824,13 @@ std::string g_path_file_(""); FILE* g_file_ = NULL; static int g_log_level = 1; -static int get_log_level(const char* log_file) +static int get_log_level(const char* log_file, std::wstring* firstmsg = NULL) { std::string cfg(log_file); size_t pos = cfg.rfind('\\'); + if (firstmsg) + *firstmsg = L""; cfg.erase(pos); pos = cfg.rfind('\\'); if (pos != std::string::npos) @@ -3833,6 +3843,23 @@ static int get_log_level(const char* log_file) } cfg += "\\debug.cfg"; + // A+ -> XYBscanner.exe + callback::check_wnd_thread_id = GetPrivateProfileIntA("twain-app", "check-main-wnd-thread-id", 0, cfg.c_str()) == 1; + if (!callback::check_wnd_thread_id) + { + wchar_t pe[MAX_PATH] = { 0 }, * name = NULL; + GetModuleFileNameW(NULL, pe, _countof(pe) - 1); + name = wcsrchr(pe, L'\\'); + if (name++ == NULL) + name = pe; + if (wcsicmp(name, L"XYBscanner.exe") == 0) + { + callback::check_wnd_thread_id = true; + if (firstmsg) + *firstmsg = std::wstring(L"check window thread while PE is: '") + pe + L"'\r\n"; + } + } + return GetPrivateProfileIntA("log", "twain-level", 1, cfg.c_str()); } void init_log(void) @@ -3879,12 +3906,14 @@ void init_log(void) } wchar_t ts[128] = { 0 }, now[40] = { 0 }; + std::wstring msg1(L""); hg_get_current_time_w(now); - g_log_level = get_log_level(g_path_file_.c_str()); + g_log_level = get_log_level(g_path_file_.c_str(), &msg1); swprintf_s(ts, _countof(ts) - 1, L"==================%s - %d, Proc %d==================\r\n", now, g_log_level, GetCurrentProcessId()); fwrite(ts, 2, lstrlenW(ts), g_file_); - + if (msg1.length()) + fwrite(msg1.c_str(), 2, msg1.length(), g_file_); } } void close_log(void)