aboutsummaryrefslogtreecommitdiff
path: root/c/common.cpp
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-07-15 00:39:07 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-07-15 00:39:07 +0200
commit0e22414d042207269f916298b236f1be341ddeea (patch)
treec7f57ee6882eda6d9a59712f9da753120086bc9e /c/common.cpp
parent31c03c4ddba65199c8c444c75b684b6cfaa629d9 (diff)
downloadEpisodeBrowser-0e22414d042207269f916298b236f1be341ddeea.tar.gz
Add wrapper for LoadLibrary, FreeLibrary.
Diffstat (limited to 'c/common.cpp')
-rw-r--r--c/common.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/c/common.cpp b/c/common.cpp
index 63adb53..93f97eb 100644
--- a/c/common.cpp
+++ b/c/common.cpp
@@ -1,3 +1,4 @@
+#include <memory>
#include <windows.h>
#include <SWI-Prolog.h>
@@ -27,3 +28,28 @@ TszFromSz(const char *sz, int iCp)
return tsz;
}
+
+Library::Library(const TCHAR *tszLibrary)
+{
+ m_hModule = LoadLibrary(tszLibrary);
+}
+
+Library::~Library()
+{
+ if (m_hModule)
+ FreeLibrary(m_hModule);
+}
+
+FARPROC
+Library::GetProcAddress(const char *szProc)
+{
+ return m_hModule? ::GetProcAddress(m_hModule, szProc): NULL;
+}
+
+std::unique_ptr<Library>
+Library::Load(const TCHAR *tszLibrary)
+{
+ auto upLib = std::make_unique<Library>(tszLibrary);
+ if (!upLib->m_hModule) upLib = nullptr;
+ return upLib;
+}