2017-01-20 08:36:52 -05:00
|
|
|
#pragma once
|
|
|
|
|
2017-01-19 16:23:59 -05:00
|
|
|
namespace Utils
|
|
|
|
{
|
|
|
|
class Library
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Library() : module(nullptr), freeOnDestroy(false) {};
|
2018-12-17 08:29:18 -05:00
|
|
|
Library(const std::string& buffer, bool freeOnDestroy = true);
|
2017-01-19 16:23:59 -05:00
|
|
|
~Library();
|
|
|
|
|
|
|
|
bool valid();
|
|
|
|
HMODULE getModule();
|
|
|
|
|
|
|
|
template <typename T>
|
2018-12-17 08:29:18 -05:00
|
|
|
std::function<T> get(const std::string& process)
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
|
|
|
if (!this->valid())
|
|
|
|
{
|
2017-01-20 16:41:03 -05:00
|
|
|
throw std::runtime_error("Library not loaded!");
|
2017-01-19 16:23:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return reinterpret_cast<T*>(GetProcAddress(this->getModule(), process.data()));
|
|
|
|
}
|
|
|
|
|
2017-03-26 12:00:06 -04:00
|
|
|
void free();
|
|
|
|
|
2017-01-19 16:23:59 -05:00
|
|
|
private:
|
|
|
|
HMODULE module;
|
|
|
|
bool freeOnDestroy;
|
|
|
|
};
|
|
|
|
}
|