Some changes in DynLib internals

Former-commit-id: cfd8cbbdf30e2b0a6faa3a283c860001b07ae6de
This commit is contained in:
Lynix 2014-01-08 11:12:34 +01:00
parent 26a6158f8f
commit b85a5bd5d5
3 changed files with 11 additions and 13 deletions

View File

@ -5,6 +5,7 @@
#include <Nazara/Core/DynLib.hpp>
#include <Nazara/Core/Config.hpp>
#include <Nazara/Core/Error.hpp>
#include <memory>
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/Win32/DynLibImpl.hpp>
@ -66,14 +67,15 @@ bool NzDynLib::Load(const NzString& libraryPath, bool appendExtension)
Unload();
m_impl = new NzDynLibImpl(this);
if (!m_impl->Load(libraryPath, appendExtension, &m_lastError))
{
delete m_impl;
m_impl = nullptr;
NzString path = libraryPath;
if (appendExtension && !path.EndsWith(NAZARA_DYNLIB_EXTENSION))
path += NAZARA_DYNLIB_EXTENSION;
std::unique_ptr<NzDynLibImpl> impl(new NzDynLibImpl(this));
if (!impl->Load(path, &m_lastError))
return false;
}
m_impl = impl.release();
return true;
}

View File

@ -23,13 +23,9 @@ NzDynLibFunc NzDynLibImpl::GetSymbol(const NzString& symbol, NzString* errorMess
return sym;
}
bool NzDynLibImpl::Load(const NzString& libraryPath, bool appendExtension, NzString* errorMessage)
bool NzDynLibImpl::Load(const NzString& libraryPath, NzString* errorMessage)
{
NzString path = libraryPath;
if (appendExtension && !path.EndsWith(".dll"))
path += ".dll";
std::unique_ptr<wchar_t[]> wPath(path.GetWideBuffer());
std::unique_ptr<wchar_t[]> wPath(libraryPath.GetWideBuffer());
m_handle = LoadLibraryW(wPath.get());
if (m_handle)

View File

@ -20,7 +20,7 @@ class NzDynLibImpl : NzNonCopyable
~NzDynLibImpl() = default;
NzDynLibFunc GetSymbol(const NzString& symbol, NzString* errorMessage) const;
bool Load(const NzString& libraryPath, bool appendExtension, NzString* errorMessage);
bool Load(const NzString& libraryPath, NzString* errorMessage);
void Unload();
private: