修复DLL加载路径问题(好分数)
This commit is contained in:
parent
6deaffbb21
commit
4da3fca44b
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue