mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-30 14:17:56 +08:00
b5531a1f6b
* tool * log ccd and wmi/cimv2 * rename * spell * clean up * spellcheck
27 lines
563 B
C++
27 lines
563 B
C++
#pragma once
|
|
|
|
#include <optional>
|
|
#include <string>
|
|
#include <system_error>
|
|
#include <Windows.h>
|
|
|
|
inline std::optional<std::wstring> get_last_error_message(const DWORD dw)
|
|
{
|
|
std::optional<std::wstring> message;
|
|
try
|
|
{
|
|
const auto msg = std::system_category().message(dw);
|
|
message.emplace(begin(msg), end(msg));
|
|
}
|
|
catch (...)
|
|
{
|
|
}
|
|
return message;
|
|
}
|
|
|
|
inline std::wstring get_last_error_or_default(const DWORD dw)
|
|
{
|
|
auto message = get_last_error_message(dw);
|
|
return message.has_value() ? message.value() : L"";
|
|
}
|