diff --git a/library_win32.cpp b/library_win32.cpp index 35a446c7..00d48121 100644 --- a/library_win32.cpp +++ b/library_win32.cpp @@ -22,16 +22,26 @@ library::library (const std::experimental::filesystem::path &path): } +//----------------------------------------------------------------------------- +library::library (library &&rhs): + m_handle (nullptr) +{ + std::swap (m_handle, rhs.m_handle); +} + + +//----------------------------------------------------------------------------- +library& +library::operator= (cruft::library &&rhs) +{ + std::swap (m_handle, rhs.m_handle); + return *this; +} + + //----------------------------------------------------------------------------- library::~library () { - FreeLibrary (m_handle); -} - - -/////////////////////////////////////////////////////////////////////////////// -void* -library::symbol (const char *name) -{ - return reinterpret_cast (GetProcAddress (m_handle, name)); + if (m_handle) + FreeLibrary (m_handle); } diff --git a/library_win32.hpp b/library_win32.hpp index 26e8635b..0d01a49a 100644 --- a/library_win32.hpp +++ b/library_win32.hpp @@ -9,6 +9,8 @@ #ifndef __UTIL_LIBRARY_WIN32_HPP #define __UTIL_LIBRARY_WIN32_HPP +#include + #include #include @@ -18,9 +20,21 @@ namespace cruft { class library { public: explicit library (const std::experimental::filesystem::path&); + library (library const&) = delete; + library& operator=(library const&) = delete; + library (library&&); + library& operator= (library&&); + ~library (); - void* symbol (const char *name); + template + FunctionT + symbol (const char *name) + { + return cast::ffs ( + GetProcAddress (m_handle, name) + ); + } private: HMODULE m_handle;