From 13552f7bb7b1f73a510b1b7fc8118a59c5ed9754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnter=20Obiltschnig?= Date: Sat, 17 Aug 2019 10:04:16 +0200 Subject: [PATCH] added SharedLibrary::setSearchPath(); set minimum required Windows version to XP SP2 (0x0502) --- Foundation/include/Poco/Platform_WIN32.h | 6 +++--- Foundation/include/Poco/SharedLibrary.h | 10 ++++++++++ Foundation/include/Poco/SharedLibrary_HPUX.h | 1 + Foundation/include/Poco/SharedLibrary_UNIX.h | 3 ++- Foundation/include/Poco/SharedLibrary_VX.h | 1 + Foundation/include/Poco/SharedLibrary_WIN32.h | 1 + Foundation/include/Poco/SharedLibrary_WIN32U.h | 1 + Foundation/include/Poco/UnWindows.h | 8 ++++---- Foundation/src/SharedLibrary.cpp | 6 ++++++ Foundation/src/SharedLibrary_HPUX.cpp | 8 +++++++- Foundation/src/SharedLibrary_UNIX.cpp | 8 +++++++- Foundation/src/SharedLibrary_VX.cpp | 10 ++++++++-- Foundation/src/SharedLibrary_WIN32.cpp | 12 +++++++++++- Foundation/src/SharedLibrary_WIN32U.cpp | 14 +++++++++++++- 14 files changed, 75 insertions(+), 14 deletions(-) diff --git a/Foundation/include/Poco/Platform_WIN32.h b/Foundation/include/Poco/Platform_WIN32.h index 65bc8299a..ab5c791d0 100644 --- a/Foundation/include/Poco/Platform_WIN32.h +++ b/Foundation/include/Poco/Platform_WIN32.h @@ -119,12 +119,12 @@ #endif #define _WIN32_WINNT WINVER #elif !defined(_WIN32_WINNT) - // last resort = Win XP, SP1 is minimum supported - #define _WIN32_WINNT 0x0501 + // last resort = Win XP, SP2 is minimum supported + #define _WIN32_WINNT 0x0502 #ifdef NTDDI_VERSION #undef NTDDI_VERSION #endif - #define NTDDI_VERSION 0x05010100 + #define NTDDI_VERSION 0x05020000 #endif #endif // POCO_FORCE_MIN_WINDOWS_OS_SUPPORT diff --git a/Foundation/include/Poco/SharedLibrary.h b/Foundation/include/Poco/SharedLibrary.h index 83af4bd4b..52292c741 100644 --- a/Foundation/include/Poco/SharedLibrary.h +++ b/Foundation/include/Poco/SharedLibrary.h @@ -122,6 +122,16 @@ public: /// (e.g., "d.so", "d.dll") unless the library has /// been compiled with -DPOCO_NO_SHARED_LIBRARY_DEBUG_SUFFIX. + static bool setSearchPath(const std::string& path); + /// Adds the given path to the list of paths shared libraries + /// are searched in. + /// + /// Returns true if the path was set, otherwise false. + /// + /// Currently only supported on Windows, where it calls + /// SetDllDirectory(). On all other platforms, does not + /// do anything and returns false. + private: SharedLibrary(const SharedLibrary&); SharedLibrary& operator = (const SharedLibrary&); diff --git a/Foundation/include/Poco/SharedLibrary_HPUX.h b/Foundation/include/Poco/SharedLibrary_HPUX.h index cfb1955fc..06a6f51bc 100644 --- a/Foundation/include/Poco/SharedLibrary_HPUX.h +++ b/Foundation/include/Poco/SharedLibrary_HPUX.h @@ -37,6 +37,7 @@ protected: void* findSymbolImpl(const std::string& name); const std::string& getPathImpl() const; static std::string suffixImpl(); + static bool setSearchPathImpl(const std::string& path); private: std::string _path; diff --git a/Foundation/include/Poco/SharedLibrary_UNIX.h b/Foundation/include/Poco/SharedLibrary_UNIX.h index 66d1a5a69..1f0c288ad 100644 --- a/Foundation/include/Poco/SharedLibrary_UNIX.h +++ b/Foundation/include/Poco/SharedLibrary_UNIX.h @@ -31,7 +31,7 @@ protected: enum Flags { SHLIB_GLOBAL_IMPL = 1, - SHLIB_LOCAL_IMPL = 2 + SHLIB_LOCAL_IMPL = 2 }; SharedLibraryImpl(); @@ -42,6 +42,7 @@ protected: void* findSymbolImpl(const std::string& name); const std::string& getPathImpl() const; static std::string suffixImpl(); + static bool setSearchPathImpl(const std::string& path); private: std::string _path; diff --git a/Foundation/include/Poco/SharedLibrary_VX.h b/Foundation/include/Poco/SharedLibrary_VX.h index 80dda66dd..916edad47 100644 --- a/Foundation/include/Poco/SharedLibrary_VX.h +++ b/Foundation/include/Poco/SharedLibrary_VX.h @@ -37,6 +37,7 @@ protected: void* findSymbolImpl(const std::string& name); const std::string& getPathImpl() const; static std::string suffixImpl(); + static bool setSearchPathImpl(const std::string& path); private: std::string _path; diff --git a/Foundation/include/Poco/SharedLibrary_WIN32.h b/Foundation/include/Poco/SharedLibrary_WIN32.h index 4bfe338b4..6b7fc2945 100644 --- a/Foundation/include/Poco/SharedLibrary_WIN32.h +++ b/Foundation/include/Poco/SharedLibrary_WIN32.h @@ -36,6 +36,7 @@ protected: void* findSymbolImpl(const std::string& name); const std::string& getPathImpl() const; static std::string suffixImpl(); + static bool setSearchPathImpl(const std::string& path); private: std::string _path; diff --git a/Foundation/include/Poco/SharedLibrary_WIN32U.h b/Foundation/include/Poco/SharedLibrary_WIN32U.h index ee6a87b6f..3e51c9c95 100644 --- a/Foundation/include/Poco/SharedLibrary_WIN32U.h +++ b/Foundation/include/Poco/SharedLibrary_WIN32U.h @@ -36,6 +36,7 @@ protected: void* findSymbolImpl(const std::string& name); const std::string& getPathImpl() const; static std::string suffixImpl(); + static bool setSearchPathImpl(const std::string& path); private: std::string _path; diff --git a/Foundation/include/Poco/UnWindows.h b/Foundation/include/Poco/UnWindows.h index 0888c5964..a54b4a94c 100644 --- a/Foundation/include/Poco/UnWindows.h +++ b/Foundation/include/Poco/UnWindows.h @@ -58,11 +58,11 @@ #if !defined(_WIN32_WCE) #if defined(_WIN32_WINNT) - #if (_WIN32_WINNT < 0x0501) + #if (_WIN32_WINNT < 0x0502) #error Unsupported Windows version. #endif #elif defined(NTDDI_VERSION) - #if (NTDDI_VERSION < 0x05010100) + #if (NTDDI_VERSION < 0x05020000) #error Unsupported Windows version. #endif #elif !defined(_WIN32_WINNT) @@ -73,8 +73,8 @@ // best to determine the appropriate values // and may redefine these. See Platform_WIN32.h // for details. - #define _WIN32_WINNT 0x0501 - #define NTDDI_VERSION 0x05010100 + #define _WIN32_WINNT 0x0502 + #define NTDDI_VERSION 0x05020000 #endif #endif diff --git a/Foundation/src/SharedLibrary.cpp b/Foundation/src/SharedLibrary.cpp index e2e00f833..542f9e810 100644 --- a/Foundation/src/SharedLibrary.cpp +++ b/Foundation/src/SharedLibrary.cpp @@ -106,4 +106,10 @@ std::string SharedLibrary::suffix() } +bool SharedLibrary::setSearchPath(const std::string& path) +{ + return setSearchPathImpl(path); +} + + } // namespace Poco diff --git a/Foundation/src/SharedLibrary_HPUX.cpp b/Foundation/src/SharedLibrary_HPUX.cpp index 01ca727e1..668bb5f64 100644 --- a/Foundation/src/SharedLibrary_HPUX.cpp +++ b/Foundation/src/SharedLibrary_HPUX.cpp @@ -59,7 +59,7 @@ void SharedLibraryImpl::unloadImpl() bool SharedLibraryImpl::isLoadedImpl() const { - return _handle != 0; + return _handle != 0; } @@ -91,4 +91,10 @@ std::string SharedLibraryImpl::suffixImpl() } +bool SharedLibraryImpl::setSearchPathImpl(const std::string&) +{ + return false; +} + + } // namespace Poco diff --git a/Foundation/src/SharedLibrary_UNIX.cpp b/Foundation/src/SharedLibrary_UNIX.cpp index d848db542..4a3dc2ffb 100644 --- a/Foundation/src/SharedLibrary_UNIX.cpp +++ b/Foundation/src/SharedLibrary_UNIX.cpp @@ -74,7 +74,7 @@ void SharedLibraryImpl::unloadImpl() bool SharedLibraryImpl::isLoadedImpl() const { - return _handle != 0; + return _handle != 0; } @@ -127,4 +127,10 @@ std::string SharedLibraryImpl::suffixImpl() } +bool SharedLibraryImpl::setSearchPathImpl(const std::string&) +{ + return false; +} + + } // namespace Poco diff --git a/Foundation/src/SharedLibrary_VX.cpp b/Foundation/src/SharedLibrary_VX.cpp index 3084fb2f7..bb2b14681 100644 --- a/Foundation/src/SharedLibrary_VX.cpp +++ b/Foundation/src/SharedLibrary_VX.cpp @@ -99,14 +99,14 @@ void SharedLibraryImpl::unloadImpl() bool SharedLibraryImpl::isLoadedImpl() const { - return _moduleId != 0; + return _moduleId != 0; } void* SharedLibraryImpl::findSymbolImpl(const std::string& name) { poco_assert (_moduleId != 0); - + FastMutex::ScopedLock lock(_mutex); MODULE_INFO mi; @@ -132,4 +132,10 @@ std::string SharedLibraryImpl::suffixImpl() } +bool SharedLibraryImpl::setSearchPathImpl(const std::string&) +{ + return false; +} + + } // namespace Poco diff --git a/Foundation/src/SharedLibrary_WIN32.cpp b/Foundation/src/SharedLibrary_WIN32.cpp index 147a046bd..340a742e8 100644 --- a/Foundation/src/SharedLibrary_WIN32.cpp +++ b/Foundation/src/SharedLibrary_WIN32.cpp @@ -63,7 +63,7 @@ void SharedLibraryImpl::unloadImpl() bool SharedLibraryImpl::isLoadedImpl() const { - return _handle != 0; + return _handle != 0; } @@ -95,4 +95,14 @@ std::string SharedLibraryImpl::suffixImpl() } +bool SharedLibraryImpl::setSearchPathImpl(const std::string& path) +{ +#if _WIN32_WINNT >= 0x0502 + return SetDllDirectoryA(path.c_str()) != 0; +#else + return false; +#endif +} + + } // namespace Poco diff --git a/Foundation/src/SharedLibrary_WIN32U.cpp b/Foundation/src/SharedLibrary_WIN32U.cpp index 49127c426..b4f697ea0 100644 --- a/Foundation/src/SharedLibrary_WIN32U.cpp +++ b/Foundation/src/SharedLibrary_WIN32U.cpp @@ -68,7 +68,7 @@ void SharedLibraryImpl::unloadImpl() bool SharedLibraryImpl::isLoadedImpl() const { - return _handle != 0; + return _handle != 0; } @@ -106,4 +106,16 @@ std::string SharedLibraryImpl::suffixImpl() } +bool SharedLibraryImpl::setSearchPathImpl(const std::string& path) +{ +#if _WIN32_WINNT >= 0x0502 + std::wstring wpath; + Poco::UnicodeConverter::toUTF16(path, wpath); + return SetDllDirectoryW(wpath.c_str()) != 0; +#else + return false; +#endif +} + + } // namespace Poco