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) {};
2016-09-16 18:14:59 -04:00
Library(std::string buffer, bool freeOnDestroy = true);
~Library();
bool valid();
HMODULE getModule();
2016-09-16 18:14:59 -04:00
template <typename T>
std::function<T> get(std::string process)
2016-09-16 18:14:59 -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()));
2016-09-16 18:14:59 -04:00
}
private:
HMODULE module;
bool freeOnDestroy;
2016-09-16 18:14:59 -04:00
};
}