Codechange: [WIN32] Add a wrapper around GetProcAddress()
This commit is contained in:
@@ -13,8 +13,47 @@
|
||||
#include <windows.h>
|
||||
bool MyShowCursor(bool show, bool toggle = false);
|
||||
|
||||
typedef void (*Function)(int);
|
||||
bool LoadLibraryList(Function proc[], const char *dll);
|
||||
class DllLoader {
|
||||
public:
|
||||
explicit DllLoader(LPCTSTR filename)
|
||||
{
|
||||
this->hmodule = ::LoadLibrary(filename);
|
||||
if (this->hmodule == nullptr) this->success = false;
|
||||
}
|
||||
|
||||
|
||||
~DllLoader()
|
||||
{
|
||||
::FreeLibrary(this->hmodule);
|
||||
}
|
||||
|
||||
bool Success() { return this->success; }
|
||||
|
||||
class ProcAddress {
|
||||
public:
|
||||
explicit ProcAddress(void *p) : p(p) {}
|
||||
|
||||
template <typename T, typename = std::enable_if_t<std::is_function_v<T>>>
|
||||
operator T *() const
|
||||
{
|
||||
return reinterpret_cast<T *>(this->p);
|
||||
}
|
||||
|
||||
private:
|
||||
void *p;
|
||||
};
|
||||
|
||||
ProcAddress GetProcAddress(const char *proc_name)
|
||||
{
|
||||
void *p = reinterpret_cast<void *>(::GetProcAddress(this->hmodule, proc_name));
|
||||
if (p == nullptr) this->success = false;
|
||||
return ProcAddress(p);
|
||||
}
|
||||
|
||||
private:
|
||||
HMODULE hmodule = nullptr;
|
||||
bool success = true;
|
||||
};
|
||||
|
||||
char *convert_from_fs(const wchar_t *name, char *utf8_buf, size_t buflen);
|
||||
wchar_t *convert_to_fs(const char *name, wchar_t *utf16_buf, size_t buflen);
|
||||
|
||||
Reference in New Issue
Block a user