7#include "../macros.hpp"
8#include "hresult_error_intf.hpp"
13hi_export_module(hikogui.win32 : win32_error_impl);
15hi_export
namespace hi {
18[[nodiscard]]
inline std::string hresult_error_category::message(
int code)
const
20 auto const code_ =
static_cast<uint32_t
>(
code);
22 auto const value =
code & 0xffff;
23 auto const facility = (
code >> 16) & 0x7ff;
24 auto const is_message_id = ((
code >> 27) & 1) != 0;
25 auto const is_ntstatus = ((
code >> 28) & 1) != 0;
26 auto const is_custom = ((
code >> 29) & 1) != 0;
27 auto const is_severe_failure = ((
code >> 30) & 1) != 0;
28 auto const is_failure = ((
code >> 31) & 1) != 0;
30 if (not is_ntstatus and not is_custom and not is_message_id and facility == 7) {
31 if (
auto msg = win32_FormatMessage(
static_cast<win32_error
>(value))) {
35 throw std::system_error(msg.error());
39 auto const facility_str = [&] {
41 return std::string{
"NTSTATUS"};
42 }
else if (is_custom) {
43 return std::string{
"Custom"};
44 }
else if (is_message_id) {
45 return std::string{
"Message ID"};
49 return std::string{
"RPC"};
51 return std::string{
"COM Dispatch"};
53 return std::string{
"OLE Storage"};
55 return std::string{
"COM/OLE Interface Management"};
57 return std::string{
"Win32"};
59 return std::string{
"Windows"};
61 return std::string{
"SSPI"};
63 return std::string{
"Control"};
65 return std::string{
"Client or Server Certificate"};
67 return std::format(
"Unknown Facility {}", facility);
72 auto const failure_str = [&] {
74 if (is_severe_failure) {
84 return std::format(
"HRESULT({}): {}: 0x{:08x}", facility_str, failure_str, code_);
@ code
Text is a piece of programming-code; a variable name, a function name.
Definition phrasing.hpp:50
The HikoGUI namespace.
Definition array_generic.hpp:21
The HikoGUI API version 1.
Definition array_generic.hpp:22