iw4x-client/src/Utils/Library.hpp
2020-12-09 13:13:34 -06:00

33 lines
563 B
C++

#pragma once
namespace Utils
{
class Library
{
public:
Library() : _module(nullptr), freeOnDestroy(false) {};
Library(const std::string& buffer, bool freeOnDestroy = true);
~Library();
bool valid();
HMODULE getModule();
template <typename T>
std::function<T> get(const std::string& process)
{
if (!this->valid())
{
throw std::runtime_error("Library not loaded!");
}
return reinterpret_cast<T*>(GetProcAddress(this->getModule(), process.data()));
}
void free();
private:
HMODULE _module;
bool freeOnDestroy;
};
}