iw4x-client/src/Utils/Library.hpp

33 lines
563 B
C++
Raw Normal View History

2017-01-20 08:36:52 -05:00
#pragma once
2017-01-19 16:23:59 -05:00
namespace Utils
{
class Library
{
public:
2020-12-09 14:13:34 -05:00
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())
{
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:
2020-12-09 14:13:34 -05:00
HMODULE _module;
2017-01-19 16:23:59 -05:00
bool freeOnDestroy;
};
}