iw4x-client/src/Utils/Library.hpp

29 lines
521 B
C++
Raw Normal View History

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 new std::runtime_error("Library not loaded!");
}
return reinterpret_cast<T*>(GetProcAddress(this->getModule(), process.data()));
}
private:
HMODULE module;
bool freeOnDestroy;
};
}