From edce20642b6d177ee9877775cbfa9e05ebb4e404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Tue, 2 Aug 2022 23:31:21 +0200 Subject: Replace maybe_make. It seems unnecessary to throw exceptions when simply checking whether a library exists. --- c/common.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'c/common.cpp') 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 #include #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::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); -- cgit v1.2.3