library/win32: conform to the template query signature

This commit is contained in:
Danny Robson 2018-08-20 16:13:49 +10:00
parent eb4a3be352
commit 7e1b14fe98
2 changed files with 34 additions and 10 deletions

View File

@ -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<void*> (GetProcAddress (m_handle, name));
if (m_handle)
FreeLibrary (m_handle);
}

View File

@ -9,6 +9,8 @@
#ifndef __UTIL_LIBRARY_WIN32_HPP
#define __UTIL_LIBRARY_WIN32_HPP
#include <cruft/util/cast.hpp>
#include <windows.h>
#include <experimental/filesystem>
@ -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 <typename FunctionT>
FunctionT
symbol (const char *name)
{
return cast::ffs<FunctionT> (
GetProcAddress (m_handle, name)
);
}
private:
HMODULE m_handle;