basic/CppunitTest_basic_macros.mk               |    2 
 basic/qa/cppunit/test_vba.cxx                   |    9 +---
 dbaccess/Executable_odbcconfig.mk               |    5 --
 dbaccess/win32/source/odbcconfig/odbcconfig.cxx |   12 ++---
 include/systools/win32/odbccp32.hxx             |   54 ++++++++++++++++++++++++
 solenv/gbuild/platform/com_MSC_class.mk         |    7 +--
 6 files changed, 67 insertions(+), 22 deletions(-)

New commits:
commit e403bf00af7767060f624077840921ceab04895d
Author:     Mike Kaganski <[email protected]>
AuthorDate: Fri Feb 24 15:13:39 2023 +0300
Commit:     Mike Kaganski <[email protected]>
CommitDate: Fri Feb 24 17:05:53 2023 +0000

    Fix build in a specific VS2022 environment
    
    Building libraries in setup_native using VS2022 failed for me reproducibly
    for some time, with
    
      mt.exe : general error c101008d: Failed to write the updated manifest to 
the resource of file "C:/lo/src/build/instdir/program/reg_dlls.dll". The file 
or directory is corrupted and unreadable.
      make[1]: *** [C:/lo/src/core/setup_native/Library_reg_dlls.mk:10: 
C:/lo/src/build/instdir/program/reg_dlls.dll] Error 139
    
      mt.exe : general error c101008d: Failed to write the updated manifest to 
the resource of file "C:/lo/src/build/instdir/program/reg4allmsdoc.dll". The 
file or directory is corrupted and unreadable.
      make[1]: *** [C:/lo/src/core/setup_native/Library_reg4allmsdoc.mk:10: 
C:/lo/src/build/instdir/program/reg4allmsdoc.dll] Error 139
    
      mt.exe : general error c101008d: Failed to write the updated manifest to 
the resource of file "C:/lo/src/build/instdir/program/regactivex.dll". The file 
or directory is corrupted and unreadable.
      make[1]: *** [C:/lo/src/core/setup_native/Library_regactivex.mk:10: 
C:/lo/src/build/instdir/program/regactivex.dll] Error 139
    
      mt.exe : general error c101008d: Failed to write the updated manifest to 
the resource of file "C:/lo/src/build/instdir/program/sdqsmsi.dll". The file or 
directory is corrupted and unreadable.
      make[1]: *** [C:/lo/src/core/setup_native/Library_sdqsmsi.mk:10: 
C:/lo/src/build/instdir/program/sdqsmsi.dll] Error 139
    
      mt.exe : general error c101008d: Failed to write the updated manifest to 
the resource of file "C:/lo/src/build/instdir/program/sellangmsi.dll". The file 
or directory is corrupted and unreadable.
      make[1]: *** [C:/lo/src/core/setup_native/Library_sellangmsi.mk:10: 
C:/lo/src/build/instdir/program/sellangmsi.dll] Error 139
    
      mt.exe : general error c101008d: Failed to write the updated manifest to 
the resource of file "C:/lo/src/build/instdir/program/shlxtmsi.dll". The file 
or directory is corrupted and unreadable.
      make[1]: *** [C:/lo/src/core/setup_native/Library_shlxtmsi.mk:10: 
C:/lo/src/build/instdir/program/shlxtmsi.dll] Error 139
    
      mt.exe : general error c101008d: Failed to write the updated manifest to 
the resource of file "C:/lo/src/build/instdir/program/sn_tools.dll". The file 
or directory is corrupted and unreadable.
      make[1]: *** [C:/lo/src/core/setup_native/Library_sn_tools.mk:10: 
C:/lo/src/build/instdir/program/sn_tools.dll] Error 139
    
      mt.exe : general error c101008d: Failed to write the updated manifest to 
the resource of file "C:/lo/src/build/instdir/program/odbcconfig.exe". The file 
or directory is corrupted and unreadable.
      make[1]: *** [C:/lo/src/core/dbaccess/Executable_odbcconfig.mk:10: 
C:/lo/src/build/instdir/program/odbcconfig.exe] Error 139
    
      mt.exe : general error c101008d: Failed to write the updated manifest to 
the resource of file "C:/lo/src/build/instdir/program/instooofiltmsi.dll". The 
file or directory is corrupted and unreadable.
      make[1]: *** [C:/lo/src/core/setup_native/Library_instooofiltmsi.mk:10: 
C:/lo/src/build/instdir/program/instooofiltmsi.dll] Error 139
    
      mt.exe : general error c101008d: Failed to write the updated manifest to 
the resource of file "C:/lo/src/build/instdir/program/qslnkmsi.dll". The file 
or directory is corrupted and unreadable.
      make[1]: *** [C:/lo/src/core/setup_native/Library_qslnkmsi.mk:10: 
C:/lo/src/build/instdir/program/qslnkmsi.dll] Error 139
    
      mt.exe : general error c101008d: Failed to write the updated manifest to 
the resource of file "C:/lo/src/build/instdir/program/inst_msu_msi.dll". The 
file or directory is corrupted and unreadable.
      make[1]: *** [C:/lo/src/core/setup_native/Library_inst_msu_msi.mk:10: 
C:/lo/src/build/instdir/program/inst_msu_msi.dll] Error 139
    
    It is caused by the -U_DLL and the first entries in 
gb_Library_use_system_win32_libs:
    libcmt, libcpmt, libucrt, libvcruntime. They are needed to make the 
denerated DLLs
    standalone, not dependent on presence of VCRT on the target system (they 
are called
    from installer, when VCRT may not yet be present).
    
    It seems to work OK for others, but somehow, this conflicts with the 
fastlink option
    on my system, so just avoid it selectively for these DLLs.
    
    Change-Id: I61f829682eb051944202bc7ef3578d6f43733030
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147628
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>

diff --git a/solenv/gbuild/platform/com_MSC_class.mk 
b/solenv/gbuild/platform/com_MSC_class.mk
index 157edc310f72..ba42b0ba48df 100644
--- a/solenv/gbuild/platform/com_MSC_class.mk
+++ b/solenv/gbuild/platform/com_MSC_class.mk
@@ -268,7 +268,7 @@ $(call gb_Helper_abbreviate_dirs,\
                $(if $(filter Library 
CppunitTest,$(TARGETTYPE)),$(gb_Library_TARGETTYPEFLAGS)) \
                $(if $(filter StaticLibrary,$(TARGETTYPE)),-LIB) \
                $(if $(filter 
Executable,$(TARGETTYPE)),$(gb_Executable_TARGETTYPEFLAGS)) \
-               $(if $(T_SYMBOLS),$(if $(filter Executable Library 
CppunitTest,$(TARGETTYPE)),$(gb_Windows_PE_TARGETTYPEFLAGS_DEBUGINFO)),) \
+               $(if $(T_SYMBOLS),$(if $(filter Executable Library 
CppunitTest,$(TARGETTYPE)),$(call 
gb_Windows_PE_TARGETTYPEFLAGS_DEBUGINFO,$(DEFS))),) \
                $(if $(filter YES,$(TARGETGUI)), 
-SUBSYSTEM:WINDOWS$(gb_MSC_SUBSYSTEM_VERSION), 
-SUBSYSTEM:CONSOLE$(gb_MSC_SUBSYSTEM_VERSION)) \
                $(if $(filter YES,$(LIBRARY_X64)), -MACHINE:X64) \
                $(if $(filter YES,$(PE_X86)), -MACHINE:X86) \
@@ -332,9 +332,10 @@ gb_Windows_PE_TARGETTYPEFLAGS := \
 # link.exe in -LIB mode doesn't understand -debug, use it only for EXEs and 
DLLs
 ifeq ($(gb_ENABLE_DBGUTIL),$(true))
 # fastlink is faster but pdb files reference .obj files
-gb_Windows_PE_TARGETTYPEFLAGS_DEBUGINFO := -debug:fastlink
+# but don't do that for setup_native DLLs: this produces make error 139 in 
some configurations
+gb_Windows_PE_TARGETTYPEFLAGS_DEBUGINFO = $(if $(filter 
-U_DLL,$(1)),-debug,-debug:fastlink)
 else
-gb_Windows_PE_TARGETTYPEFLAGS_DEBUGINFO := -debug
+gb_Windows_PE_TARGETTYPEFLAGS_DEBUGINFO = -debug
 endif
 
 ifeq ($(ENABLE_LTO),TRUE)
commit 3fc2c054c505b8c99c3f8e64561de242bcd7d3b3
Author:     Mike Kaganski <[email protected]>
AuthorDate: Fri Feb 24 11:38:03 2023 +0300
Commit:     Mike Kaganski <[email protected]>
CommitDate: Fri Feb 24 17:05:49 2023 +0000

    Fix build in a specific VS2022 environment
    
    Building Executable_odbcconfig using VS2022 failed for me reproducibly
    for some time, with
    
      mt.exe : general error c101008d: Failed to write the updated manifest to 
the resource of file "C:/lo/src/build/instdir/program/odbcconfig.exe". The file 
or directory is corrupted and unreadable.
      make[1]: *** [C:/lo/src/core/dbaccess/Executable_odbcconfig.mk:10: 
C:/lo/src/build/instdir/program/odbcconfig.exe] Error 139
    
    It is caused by linking odbccp32, and legacy_stdio_definitions required
    by the latter with current versions of UCRT.
    
    It seems to work OK for others; but being unable to find what's different
    on my system, I have this workaround, using run-time loading instead.
    
    Change-Id: Iab1fe7747ca6e677d89a120778ca805465a05611
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147627
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>

diff --git a/dbaccess/Executable_odbcconfig.mk 
b/dbaccess/Executable_odbcconfig.mk
index 862c77b3b5af..2156128469e3 100644
--- a/dbaccess/Executable_odbcconfig.mk
+++ b/dbaccess/Executable_odbcconfig.mk
@@ -15,11 +15,6 @@ $(eval $(call gb_Executable_use_libraries,odbcconfig,\
     comphelper \
 ))
 
-$(eval $(call gb_Executable_use_system_win32_libs,odbcconfig,\
-       legacy_stdio_definitions \
-       odbccp32 \
-))
-
 $(eval $(call gb_Library_use_sdk_api,odbcconfig))
 
 $(eval $(call gb_Executable_add_exception_objects,odbcconfig,\
diff --git a/dbaccess/win32/source/odbcconfig/odbcconfig.cxx 
b/dbaccess/win32/source/odbcconfig/odbcconfig.cxx
index 0cc48725c5e1..127d840c839e 100644
--- a/dbaccess/win32/source/odbcconfig/odbcconfig.cxx
+++ b/dbaccess/win32/source/odbcconfig/odbcconfig.cxx
@@ -18,11 +18,9 @@
  */
 
 
-#if !defined WIN32_LEAN_AND_MEAN
-# define WIN32_LEAN_AND_MEAN
-#endif
-#include <windows.h>
-#include <odbcinst.h>
+#include <sal/config.h>
+
+#include <systools/win32/odbccp32.hxx>
 
 // displays the error text for the last error (GetLastError), and returns this 
error value
 static int displayLastError()
@@ -102,7 +100,9 @@ extern "C" int APIENTRY wWinMain( HINSTANCE _hAppInstance, 
HINSTANCE, LPWSTR, in
     if ( !IsWindow( hAppWindow ) )
         return displayLastError();
 
-    if (!SQLManageDataSources(hAppWindow))
+    // Have a odbccp32 variable, to not call FreeLibrary before 
displayLastError
+    sal::systools::odbccp32 odbccp32;
+    if (!odbccp32.SQLManageDataSources(hAppWindow))
         return displayLastError();
 
     return 0;
diff --git a/include/systools/win32/odbccp32.hxx 
b/include/systools/win32/odbccp32.hxx
index 51b1a10c9576..bbfaf9eecbd9 100644
--- a/include/systools/win32/odbccp32.hxx
+++ b/include/systools/win32/odbccp32.hxx
@@ -33,6 +33,12 @@ public:
         return Invoke<proc_t>("SQLGetInstalledDriversW", sBuf, nBufSize, 
nullptr);
     }
 
+    bool SQLManageDataSources(HWND hwndParent)
+    {
+        using proc_t = BOOL __stdcall(HWND);
+        return Invoke<proc_t>("SQLManageDataSources", hwndParent);
+    }
+
 private:
     template <typename proc_t, typename... Args> bool Invoke(const char* func, 
Args... args) const
     {
commit 1786ddbde4b44575321aa6b9d9d367a964969063
Author:     Mike Kaganski <[email protected]>
AuthorDate: Fri Feb 24 10:30:50 2023 +0300
Commit:     Mike Kaganski <[email protected]>
CommitDate: Fri Feb 24 17:05:43 2023 +0000

    Fix build in a specific VS2022 environment
    
    Building CppunitTest_basic_macros using VS2022 failed for me reproducibly
    for some time, with
    
      make[1]: *** [C:/lo/src/core/solenv/gbuild/LinkTarget.mk:841: 
C:/lo/src/build/workdir/LinkTarget/CppunitTest/test_basic_macros.dll] Error 139
    
    It is caused by linking odbccp32, and legacy_stdio_definitions required
    by the latter with current versions of UCRT.
    
    It seems to work OK for others; but being unable to find what's different
    on my system, I have this workaround, using run-time loading instead.
    
    Change-Id: Ic4094398f7510bc281dfa96f980f29f12f09d7ba
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147626
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>

diff --git a/basic/CppunitTest_basic_macros.mk 
b/basic/CppunitTest_basic_macros.mk
index 83a9221369f0..361bd5bb2d2f 100644
--- a/basic/CppunitTest_basic_macros.mk
+++ b/basic/CppunitTest_basic_macros.mk
@@ -45,9 +45,7 @@ $(eval $(call gb_CppunitTest_use_libraries,basic_macros, \
 ifeq ($(OS),WNT)
 $(eval $(call gb_CppunitTest_use_system_win32_libs,basic_macros, \
        oleaut32 \
-       legacy_stdio_definitions \
        odbc32 \
-       odbccp32 \
 ))
 endif
 
diff --git a/basic/qa/cppunit/test_vba.cxx b/basic/qa/cppunit/test_vba.cxx
index f048fee6dfda..b778d393019b 100644
--- a/basic/qa/cppunit/test_vba.cxx
+++ b/basic/qa/cppunit/test_vba.cxx
@@ -14,11 +14,7 @@
 #include <comphelper/processfactory.hxx>
 #include <o3tl/char16_t2wchar_t.hxx>
 
-#if !defined WIN32_LEAN_AND_MEAN
-# define WIN32_LEAN_AND_MEAN
-#endif
-#include <windows.h>
-#include <odbcinst.h>
+#include <systools/win32/odbccp32.hxx>
 #endif
 
 using namespace ::com::sun::star;
@@ -211,7 +207,8 @@ void VBATest::testMiscOLEStuff()
 
     const int nBufSize = 1024 * 4;
     wchar_t sBuf[nBufSize];
-    SQLGetInstalledDriversW( sBuf, nBufSize, nullptr );
+    if (!sal::systools::odbccp32().SQLGetInstalledDrivers(sBuf, nBufSize))
+        return;
 
     const wchar_t *pODBCDriverName = sBuf;
     bool bFound = false;
diff --git a/include/systools/win32/odbccp32.hxx 
b/include/systools/win32/odbccp32.hxx
new file mode 100644
index 000000000000..51b1a10c9576
--- /dev/null
+++ b/include/systools/win32/odbccp32.hxx
@@ -0,0 +1,48 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include <sal/config.h>
+
+#include <prewin.h>
+#include <postwin.h>
+
+namespace sal::systools
+{
+// Linking to odbccp32 requires also legacy_stdio_definitions; and that breaks
+// in some configurations, with make error 139. Load it dynamically instead.
+class odbccp32
+{
+public:
+    odbccp32()
+        : m_hDLL(LoadLibraryW(L"odbccp32.dll"))
+    {
+    }
+    ~odbccp32() { FreeLibrary(m_hDLL); }
+
+    bool SQLGetInstalledDrivers(LPWSTR sBuf, WORD nBufSize) const
+    {
+        using proc_t = BOOL __stdcall(LPWSTR, WORD, WORD*);
+        return Invoke<proc_t>("SQLGetInstalledDriversW", sBuf, nBufSize, 
nullptr);
+    }
+
+private:
+    template <typename proc_t, typename... Args> bool Invoke(const char* func, 
Args... args) const
+    {
+        if (auto pFunc = reinterpret_cast<proc_t*>(GetProcAddress(m_hDLL, 
func)))
+            return pFunc(args...);
+        return false;
+    }
+
+    HMODULE m_hDLL;
+};
+} // sal::systools
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */

Reply via email to