From 4da3fca44b894b68e34fc93165d2074562854d50 Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Wed, 19 Oct 2022 18:02:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DDLL=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E9=97=AE=E9=A2=98=EF=BC=88=E5=A5=BD=E5=88=86?= =?UTF-8?q?=E6=95=B0=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- twain/load_sane.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/twain/load_sane.cpp b/twain/load_sane.cpp index 67901e7..3695ee7 100644 --- a/twain/load_sane.cpp +++ b/twain/load_sane.cpp @@ -91,20 +91,27 @@ namespace load_sane_util { HMODULE h = LoadLibraryW(path_dll); int ret = GetLastError(); + wchar_t info[128] = { 0 }; + swprintf_s(info, _countof(info) - 1, L" = %d\r\n", ret); + OutputDebugStringW((L"[TWAIN]Load: " + std::wstring(path_dll) + info).c_str()); if (!h && ret == ERROR_MOD_NOT_FOUND) { std::wstring dir(path_dll); size_t pos = dir.rfind(L'\\'); wchar_t path[MAX_PATH] = { 0 }; - GetCurrentDirectoryW(_countof(path) - 1, path); + GetDllDirectoryW(_countof(path) - 1, path); if (pos != std::wstring::npos) dir.erase(pos); - SetCurrentDirectoryW(dir.c_str()); + OutputDebugStringW((L"[TWAIN]Load: try change directory to " + dir + L"\r\n").c_str()); + SetDllDirectoryW(dir.c_str()); h = LoadLibraryW(path_dll); ret = GetLastError(); - SetCurrentDirectoryW(path); + swprintf_s(info, _countof(info) - 1, L" = %d\r\n", ret); + OutputDebugStringW((L"[TWAIN]Load: " + std::wstring(path_dll) + info).c_str()); + OutputDebugStringW((L"[TWAIN]Load: restore directory to " + std::wstring(path) + L"\r\n").c_str()); + SetDllDirectoryW(path); } if (dll) @@ -142,6 +149,13 @@ namespace load_sane_util } bool is_ok(void) { + wchar_t info[128] = { 0 }; + swprintf_s(info, _countof(info) - 1, L"[TWAIN]Load: sane_inst: %s, is_on: %s, init: %s, uninit: %s\r\n" + , sane_inst != NULL ? "ok" : "not found" + , is_on != NULL ? "ok" : "not found" + , init != NULL ? "ok" : "not found" + , uninit != NULL ? "ok" : "not found"); + return sane_inst != NULL && is_on != NULL && init != NULL && uninit != NULL; } bool is_online(SCANNERID guid)