[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - extensions/Executable_twain32shim.mk extensions/source

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Wed Sep 30 10:40:20 UTC 2020


 extensions/Executable_twain32shim.mk      |    1 +
 extensions/source/scanner/twain32shim.cxx |   15 ++++++++++++++-
 extensions/source/scanner/twain32shim.hxx |    1 +
 3 files changed, 16 insertions(+), 1 deletion(-)

New commits:
commit e3970b941db8783692beb606b7d9de4f833cb31b
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Wed Sep 30 11:29:46 2020 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Wed Sep 30 12:39:46 2020 +0200

    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 at collabora.com>
    (cherry picked from commit 37b81dd54a915223780a6b5efa54ce45db332604)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103655
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>

diff --git a/extensions/Executable_twain32shim.mk b/extensions/Executable_twain32shim.mk
index 6f53ca3924ab..1caa721f3e1d 100644
--- a/extensions/Executable_twain32shim.mk
+++ b/extensions/Executable_twain32shim.mk
@@ -27,6 +27,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 b72df438d596..591236e77e74 100644
--- a/extensions/source/scanner/twain32shim.hxx
+++ b/extensions/source/scanner/twain32shim.hxx
@@ -12,6 +12,7 @@
 #define INCLUDED_EXTENSIONS_SOURCE_SCANNER_TWAIN32SHIM_HXX
 
 #include <prewin.h>
+#include <Shlobj.h>
 #include <postwin.h>
 #include <exception>
 #include <string>


More information about the Libreoffice-commits mailing list