diff options
author | John Ankarström <john@ankarstrom.se> | 2022-07-15 03:04:22 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-07-15 03:04:22 +0200 |
commit | 7153a258427d3e401914de800bfdf1c7165cab71 (patch) | |
tree | 7aa97f2c9e4dd97b6c67bedb09ef03d7f2b3f19d /c/common.cpp | |
parent | 0e56160e859d32adffb7c9df3cd78cde0bff8df8 (diff) | |
download | EpisodeBrowser-7153a258427d3e401914de800bfdf1c7165cab71.tar.gz |
Replace Library::Load with try_make_unique template.
Diffstat (limited to 'c/common.cpp')
-rw-r--r-- | c/common.cpp | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/c/common.cpp b/c/common.cpp index bcc5fd0..89cc426 100644 --- a/c/common.cpp +++ b/c/common.cpp @@ -1,3 +1,4 @@ +#include <stdexcept> #include <memory> #include <windows.h> #include <SWI-Prolog.h> @@ -30,23 +31,16 @@ TCHAR *TszFromSz(const char *sz, int iCp) Library::Library(const TCHAR *tszLibrary) { - m_hModule = LoadLibrary(tszLibrary); + if (!(m_hModule = LoadLibrary(tszLibrary))) + throw std::invalid_argument("Library not found."); } Library::~Library() { - if (m_hModule) - FreeLibrary(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; + return ::GetProcAddress(m_hModule, szProc); } |