From 3fc2c054c505b8c99c3f8e64561de242bcd7d3b3 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Fri, 24 Feb 2023 11:38:03 +0300 Subject: [PATCH] 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 --- dbaccess/Executable_odbcconfig.mk | 5 ----- dbaccess/win32/source/odbcconfig/odbcconfig.cxx | 12 ++++++------ include/systools/win32/odbccp32.hxx | 6 ++++++ 3 files changed, 12 insertions(+), 11 deletions(-) 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 -#include +#include + +#include // 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("SQLGetInstalledDriversW", sBuf, nBufSize, nullptr); } + bool SQLManageDataSources(HWND hwndParent) + { + using proc_t = BOOL __stdcall(HWND); + return Invoke("SQLManageDataSources", hwndParent); + } + private: template bool Invoke(const char* func, Args... args) const {