2016-09-16 18:14:59 -04:00
|
|
|
namespace Utils
|
|
|
|
{
|
|
|
|
class Library
|
|
|
|
{
|
|
|
|
public:
|
2016-11-20 08:09:07 -05:00
|
|
|
Library() : module(nullptr), freeOnDestroy(false) {};
|
2016-09-16 18:14:59 -04:00
|
|
|
Library(std::string buffer, bool freeOnDestroy = true);
|
|
|
|
~Library();
|
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
bool valid();
|
|
|
|
HMODULE getModule();
|
2016-09-16 18:14:59 -04:00
|
|
|
|
|
|
|
template <typename T>
|
2016-11-20 08:09:07 -05:00
|
|
|
std::function<T> get(std::string process)
|
2016-09-16 18:14:59 -04:00
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
if (!this->valid())
|
2016-09-16 18:14:59 -04:00
|
|
|
{
|
|
|
|
throw new std::runtime_error("Library not loaded!");
|
|
|
|
}
|
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
return reinterpret_cast<T*>(GetProcAddress(this->getModule(), process.data()));
|
2016-09-16 18:14:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-11-20 08:09:07 -05:00
|
|
|
HMODULE module;
|
|
|
|
bool freeOnDestroy;
|
2016-09-16 18:14:59 -04:00
|
|
|
};
|
|
|
|
}
|