13static_assert(std::is_same_v<HRESULT, bicameral::HResult>,
"HResult は HRESULT と同じ型でなければならない");
23#define BICAMERAL_NAMED_RESULT(code) \
55#undef BICAMERAL_NAMED_RESULT
57 std::string_view
NameOf(HRESULT result) {
59 if (named.code == result)
68 wchar_t* buffer =
nullptr;
69 const DWORD flags = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
70 FORMAT_MESSAGE_IGNORE_INSERTS;
71 const DWORD length = FormatMessageW(flags,
nullptr,
static_cast<DWORD
>(result), 0,
72 reinterpret_cast<wchar_t*
>(&buffer), 0,
nullptr);
73 if (length == 0 || buffer ==
nullptr)
76 std::wstring_view text(buffer, length);
77 while (!text.empty() && (text.back() == L
'\r' || text.back() == L
'\n' || text.back() == L
' '))
78 text.remove_suffix(1);
80 std::string message =
ToUtf8(text);
89 const std::string_view name = NameOf(result);
90 const std::string message = SystemMessageOf(result);
91 std::string text = name.empty() ? std::format(
"0x{:08X}",
static_cast<unsigned long>(result))
92 : std::format(
"{} (0x{:08X})", name,
static_cast<unsigned long>(result));
94 text +=
": " + message;
100 const std::source_location& location) {
101 if (SUCCEEDED(result))
bool IsEnabled(Level level) const
void Write(Channel channel, Level level, std::string_view message, const std::source_location &location)
#define BICAMERAL_NAMED_RESULT(code)
constexpr std::array NAMED_RESULTS
std::string_view NameOf(HRESULT result)
std::string SystemMessageOf(HRESULT result)
bool CheckHresult(HResult result, Channel channel, std::string_view expression, const std::source_location &location)
std::string DescribeHresult(HResult result)
std::string ToUtf8(std::wstring_view text)