From 0e22414d042207269f916298b236f1be341ddeea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Fri, 15 Jul 2022 00:39:07 +0200 Subject: Add wrapper for LoadLibrary, FreeLibrary. --- c/common.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'c/common.cpp') 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 #include #include @@ -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::Load(const TCHAR *tszLibrary) +{ + auto upLib = std::make_unique(tszLibrary); + if (!upLib->m_hModule) upLib = nullptr; + return upLib; +} -- cgit v1.2.3