added SharedLibrary::setSearchPath()

This commit is contained in:
Günter Obiltschnig 2019-08-17 10:04:48 +02:00
parent df4cb29ea5
commit 325cfcb3c2
12 changed files with 68 additions and 7 deletions

View File

@ -122,6 +122,16 @@ public:
/// (e.g., "d.so", "d.dll") unless the library has /// (e.g., "d.so", "d.dll") unless the library has
/// been compiled with -DPOCO_NO_SHARED_LIBRARY_DEBUG_SUFFIX. /// 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: private:
SharedLibrary(const SharedLibrary&); SharedLibrary(const SharedLibrary&);
SharedLibrary& operator = (const SharedLibrary&); SharedLibrary& operator = (const SharedLibrary&);

View File

@ -37,6 +37,7 @@ protected:
void* findSymbolImpl(const std::string& name); void* findSymbolImpl(const std::string& name);
const std::string& getPathImpl() const; const std::string& getPathImpl() const;
static std::string suffixImpl(); static std::string suffixImpl();
static bool setSearchPathImpl(const std::string& path);
private: private:
std::string _path; std::string _path;

View File

@ -42,6 +42,7 @@ protected:
void* findSymbolImpl(const std::string& name); void* findSymbolImpl(const std::string& name);
const std::string& getPathImpl() const; const std::string& getPathImpl() const;
static std::string suffixImpl(); static std::string suffixImpl();
static bool setSearchPathImpl(const std::string& path);
private: private:
std::string _path; std::string _path;

View File

@ -37,6 +37,7 @@ protected:
void* findSymbolImpl(const std::string& name); void* findSymbolImpl(const std::string& name);
const std::string& getPathImpl() const; const std::string& getPathImpl() const;
static std::string suffixImpl(); static std::string suffixImpl();
static bool setSearchPathImpl(const std::string& path);
private: private:
std::string _path; std::string _path;

View File

@ -36,6 +36,7 @@ protected:
void* findSymbolImpl(const std::string& name); void* findSymbolImpl(const std::string& name);
const std::string& getPathImpl() const; const std::string& getPathImpl() const;
static std::string suffixImpl(); static std::string suffixImpl();
static bool setSearchPathImpl(const std::string& path);
private: private:
std::string _path; std::string _path;

View File

@ -36,6 +36,7 @@ protected:
void* findSymbolImpl(const std::string& name); void* findSymbolImpl(const std::string& name);
const std::string& getPathImpl() const; const std::string& getPathImpl() const;
static std::string suffixImpl(); static std::string suffixImpl();
static bool setSearchPathImpl(const std::string& path);
private: private:
std::string _path; std::string _path;

View File

@ -106,4 +106,10 @@ std::string SharedLibrary::suffix()
} }
bool SharedLibrary::setSearchPath(const std::string& path)
{
return setSearchPathImpl(path);
}
} // namespace Poco } // namespace Poco

View File

@ -91,4 +91,10 @@ std::string SharedLibraryImpl::suffixImpl()
} }
bool SharedLibraryImpl::setSearchPathImpl(const std::string&)
{
return false;
}
} // namespace Poco } // namespace Poco

View File

@ -127,4 +127,10 @@ std::string SharedLibraryImpl::suffixImpl()
} }
bool SharedLibraryImpl::setSearchPathImpl(const std::string&)
{
return false;
}
} // namespace Poco } // namespace Poco

View File

@ -132,4 +132,10 @@ std::string SharedLibraryImpl::suffixImpl()
} }
bool SharedLibraryImpl::setSearchPathImpl(const std::string&)
{
return false;
}
} // namespace Poco } // namespace Poco

View File

@ -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 } // namespace Poco

View File

@ -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 } // namespace Poco