summaryrefslogtreecommitdiff
path: root/src/win32
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2021-03-08 13:44:10 +0100
committerMax Kellermann <max@musicpd.org>2021-03-08 13:46:36 +0100
commit6a75c48dba2baacb7ca02a607f5ff80ca2f375d8 (patch)
tree08516fcb3e2b47901bf5a691f4e99c1bbda3da95 /src/win32
parent48bdd09f6458b93605fd5700a6e0fe9b8ccd22aa (diff)
win32/HResult: add MakeHResultError()
None of the current FormatHResultError() callers need the format string.
Diffstat (limited to 'src/win32')
-rw-r--r--src/win32/Com.hxx4
-rw-r--r--src/win32/ComPtr.hxx2
-rw-r--r--src/win32/HResult.hxx7
3 files changed, 10 insertions, 3 deletions
diff --git a/src/win32/Com.hxx b/src/win32/Com.hxx
index a2aa062a1..34350b62d 100644
--- a/src/win32/Com.hxx
+++ b/src/win32/Com.hxx
@@ -31,7 +31,7 @@ public:
COM() {
if (HRESULT result = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
FAILED(result)) {
- throw FormatHResultError(
+ throw MakeHResultError(
result,
"Unable to initialize COM with COINIT_MULTITHREADED");
}
@@ -39,7 +39,7 @@ public:
COM(bool) {
if (HRESULT result = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
FAILED(result)) {
- throw FormatHResultError(
+ throw MakeHResultError(
result,
"Unable to initialize COM with COINIT_APARTMENTTHREADED");
}
diff --git a/src/win32/ComPtr.hxx b/src/win32/ComPtr.hxx
index 01a8ef525..c7efa88b8 100644
--- a/src/win32/ComPtr.hxx
+++ b/src/win32/ComPtr.hxx
@@ -85,7 +85,7 @@ public:
::CoCreateInstance(class_id, unknown_outer, class_context,
__uuidof(T), reinterpret_cast<void **>(&ptr));
if (FAILED(result)) {
- throw FormatHResultError(result, "Unable to create instance");
+ throw MakeHResultError(result, "Unable to create instance");
}
}
diff --git a/src/win32/HResult.hxx b/src/win32/HResult.hxx
index 2f48c08f2..e61447fb6 100644
--- a/src/win32/HResult.hxx
+++ b/src/win32/HResult.hxx
@@ -74,6 +74,13 @@ static inline const std::error_category &hresult_category() noexcept {
return hresult_category_instance;
}
+inline std::system_error
+MakeHResultError(HRESULT result, const char *msg) noexcept
+{
+ return std::system_error(std::error_code(result, hresult_category()),
+ msg);
+}
+
gcc_printf(2, 3) std::system_error
FormatHResultError(HRESULT result, const char *fmt, ...) noexcept;