Modified DynLib/PluginManager interface

Former-commit-id: 2dae56cad852a46c9bac828cc7775a4da42c96cf
This commit is contained in:
Lynix
2014-01-05 15:30:27 +01:00
parent 3625713914
commit 3dd8b8fce1
6 changed files with 30 additions and 34 deletions

View File

@@ -9,34 +9,34 @@
#include <memory>
#include <Nazara/Core/Debug.hpp>
NzDynLibImpl::NzDynLibImpl(NzDynLib* parent) :
m_parent(parent)
NzDynLibImpl::NzDynLibImpl(NzDynLib* parent)
{
NazaraUnused(parent);
}
NzDynLibFunc NzDynLibImpl::GetSymbol(const NzString& symbol) const
NzDynLibFunc NzDynLibImpl::GetSymbol(const NzString& symbol, NzString* errorMessage) const
{
NzDynLibFunc sym = reinterpret_cast<NzDynLibFunc>(GetProcAddress(m_handle, symbol.GetConstBuffer()));
if (!sym)
m_parent->SetLastError(NzError::GetLastSystemError());
*errorMessage = NzError::GetLastSystemError();
return sym;
}
bool NzDynLibImpl::Load(const NzString& libraryPath)
bool NzDynLibImpl::Load(const NzString& libraryPath, bool appendExtension, NzString* errorMessage)
{
NzString path = libraryPath;
if (!path.EndsWith(".dll"))
if (appendExtension && !path.EndsWith(".dll"))
path += ".dll";
std::unique_ptr<wchar_t[]> wPath(path.GetWideBuffer());
m_handle = LoadLibraryExW(wPath.get(), nullptr, LOAD_WITH_ALTERED_SEARCH_PATH);
m_handle = LoadLibraryW(wPath.get());
if (m_handle)
return true;
else
{
m_parent->SetLastError(NzError::GetLastSystemError());
*errorMessage = NzError::GetLastSystemError();
return false;
}
}

View File

@@ -19,13 +19,12 @@ class NzDynLibImpl : NzNonCopyable
NzDynLibImpl(NzDynLib* m_parent);
~NzDynLibImpl() = default;
NzDynLibFunc GetSymbol(const NzString& symbol) const;
bool Load(const NzString& libraryPath);
NzDynLibFunc GetSymbol(const NzString& symbol, NzString* errorMessage) const;
bool Load(const NzString& libraryPath, bool appendExtension, NzString* errorMessage);
void Unload();
private:
HMODULE m_handle;
NzDynLib* m_parent;
};
#endif // NAZARA_DYNLIBIMPL_HPP