aboutsummaryrefslogtreecommitdiff
path: root/c/common.cpp
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-08-02 23:31:21 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-08-02 23:31:21 +0200
commitedce20642b6d177ee9877775cbfa9e05ebb4e404 (patch)
treef37c2d7121b3de0491561a5bd33ecf004d3a67d2 /c/common.cpp
parentad4a1e4ac6b9452bb28936623035d01bb03f36f2 (diff)
downloadEpisodeBrowser-edce20642b6d177ee9877775cbfa9e05ebb4e404.tar.gz
Replace maybe_make.
It seems unnecessary to throw exceptions when simply checking whether a library exists.
Diffstat (limited to 'c/common.cpp')
-rw-r--r--c/common.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/c/common.cpp b/c/common.cpp
index fcf1da2..5d786da 100644
--- a/c/common.cpp
+++ b/c/common.cpp
@@ -1,3 +1,4 @@
+#include <utility>
#include <windows.h>
#include "common.h"
@@ -104,6 +105,15 @@ const wchar_t* Win32Error::WhatW() const noexcept
/* Library: Wrapper for loading and freeing dynamically linked libraries. */
+std::optional<Library> Library::Maybe(const wchar_t* const lib)
+{
+ HMODULE hModule = LoadLibrary(lib);
+ if (!hModule) return {};
+ return Library(hModule);
+}
+
+Library::Library(const HMODULE hModule) : m_hModule(hModule) {}
+
Library::Library(const wchar_t* const lib)
{
m_hModule = LoadLibrary(lib);