feat(SharedLibrary): add more detailed error description when LoadLibrary fails

This commit is contained in:
Alex Fabijanic
2020-09-09 15:46:42 +02:00
parent 013c867615
commit 85e83643fe

View File

@@ -16,6 +16,9 @@
#include "Poco/UnicodeConverter.h" #include "Poco/UnicodeConverter.h"
#include "Poco/Path.h" #include "Poco/Path.h"
#include "Poco/UnWindows.h" #include "Poco/UnWindows.h"
#include "Poco/Error.h"
#include "Poco/Format.h"
#include "Poco/String.h"
namespace Poco { namespace Poco {
@@ -48,7 +51,13 @@ void SharedLibraryImpl::loadImpl(const std::string& path, int /*flags*/)
std::wstring upath; std::wstring upath;
UnicodeConverter::toUTF16(path, upath); UnicodeConverter::toUTF16(path, upath);
_handle = LoadLibraryExW(upath.c_str(), 0, flags); _handle = LoadLibraryExW(upath.c_str(), 0, flags);
if (!_handle) throw LibraryLoadException(path); if (!_handle)
{
int errn = static_cast<int>(Error::last());
std::string err;
Poco::format(err, "Error %d while loading [%s]: [%s]", errn, path, Poco::trim(Error::getMessage(errn)));
throw LibraryLoadException(err);
}
_path = path; _path = path;
} }