iw4x-client/src/Utils/Library.hpp

33 lines
547 B
C++
Raw Normal View History

2017-01-20 08:36:52 -05:00
#pragma once
2017-01-19 16:23:59 -05:00
namespace Utils
{
class Library
{
public:
Library() : module(nullptr), freeOnDestroy(false) {};
Library(std::string buffer, bool freeOnDestroy = true);
~Library();
bool valid();
HMODULE getModule();
template <typename T>
std::function<T> get(std::string process)
{
if (!this->valid())
{
throw std::runtime_error("Library not loaded!");
2017-01-19 16:23:59 -05:00
}
return reinterpret_cast<T*>(GetProcAddress(this->getModule(), process.data()));
}
2017-03-26 12:00:06 -04:00
void free();
2017-01-19 16:23:59 -05:00
private:
HMODULE module;
bool freeOnDestroy;
};
}