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
/// 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&);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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