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 <mike.kaganski@collabora.com>
This commit is contained in:
Mike Kaganski 2020-09-30 11:29:46 +03:00
parent 528cc99c57
commit 37b81dd54a
3 changed files with 16 additions and 1 deletions

View file

@ -37,6 +37,7 @@ $(eval $(call gb_Executable_add_exception_objects,twain32shim,\
))
$(eval $(call gb_Executable_use_system_win32_libs,twain32shim,\
Ole32 \
shell32 \
))

View file

@ -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;

View file

@ -11,6 +11,7 @@
#pragma once
#include <prewin.h>
#include <Shlobj.h>
#include <postwin.h>
#include <exception>
#include <string>