iw4x-client/src/Utils/Library.hpp

29 lines
549 B
C++
Raw Normal View History

2016-09-16 18:14:59 -04: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)
{
2016-09-16 18:22:01 -04:00
if (!this->Valid())
2016-09-16 18:14:59 -04:00
{
throw new std::runtime_error("Library not loaded!");
}
return reinterpret_cast<T*>(GetProcAddress(this->GetModule(), process.data()));
}
private:
HMODULE Module;
bool FreeOnDestroy;
};
}