diff options
Diffstat (limited to 'src/os/windows/win32.h')
-rw-r--r-- | src/os/windows/win32.h | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/src/os/windows/win32.h b/src/os/windows/win32.h index bf88e312a..1d3127330 100644 --- a/src/os/windows/win32.h +++ b/src/os/windows/win32.h @@ -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); |