From 37b81dd54a915223780a6b5efa54ce45db332604 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Wed, 30 Sep 2020 11:29:46 +0300 Subject: [PATCH] twain32shim: Windows directory might not be in DLL search path sometimes So try the full path to TWAIN_32.DLL if first try failed. Change-Id: I9ad262c91ebc7b3df63fbec3ffe34595ffd78c75 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103669 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- extensions/Executable_twain32shim.mk | 1 + extensions/source/scanner/twain32shim.cxx | 15 ++++++++++++++- extensions/source/scanner/twain32shim.hxx | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/extensions/Executable_twain32shim.mk b/extensions/Executable_twain32shim.mk index 3ac3ce8d43ed..f063f7d6e3b4 100644 --- a/extensions/Executable_twain32shim.mk +++ b/extensions/Executable_twain32shim.mk @@ -37,6 +37,7 @@ $(eval $(call gb_Executable_add_exception_objects,twain32shim,\ )) $(eval $(call gb_Executable_use_system_win32_libs,twain32shim,\ + Ole32 \ shell32 \ )) diff --git a/extensions/source/scanner/twain32shim.cxx b/extensions/source/scanner/twain32shim.cxx index 8ccd2bd1b32d..30cbba8558e4 100644 --- a/extensions/source/scanner/twain32shim.cxx +++ b/extensions/source/scanner/twain32shim.cxx @@ -254,7 +254,20 @@ void ImpTwain::ImplOpenSourceManager() { if (TWAINState::DSMunloaded == m_nCurState) { - if ((m_hMod = LoadLibraryW(L"TWAIN_32.DLL"))) + m_hMod = LoadLibraryW(L"TWAIN_32.DLL"); + if (!m_hMod) + { + // Windows directory might not be in DLL search path sometimes, so try the full path + PWSTR sPath; + if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Windows, 0, nullptr, &sPath))) + { + std::wstring sPathAndFile = sPath; + CoTaskMemFree(sPath); + sPathAndFile += L"\\TWAIN_32.DLL"; + m_hMod = LoadLibraryW(sPathAndFile.c_str()); + } + } + if (m_hMod) { m_nCurState = TWAINState::DSMloaded; diff --git a/extensions/source/scanner/twain32shim.hxx b/extensions/source/scanner/twain32shim.hxx index 9f42f0a4d5dc..c9e87ee8bb57 100644 --- a/extensions/source/scanner/twain32shim.hxx +++ b/extensions/source/scanner/twain32shim.hxx @@ -11,6 +11,7 @@ #pragma once #include +#include #include #include #include