win32/HResult: add MakeHResultError()

None of the current FormatHResultError() callers need the format string.
This commit is contained in:
Max Kellermann
2021-03-08 13:44:10 +01:00
parent 48bdd09f64
commit 6a75c48dba
7 changed files with 41 additions and 35 deletions

View File

@@ -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");
}

View File

@@ -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");
}
}

View File

@@ -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;