HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
hresult_error_intf.hpp
1// Copyright Take Vos 2024.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "../macros.hpp"
8#include "win32_error_intf.hpp"
9#include <Windows.h>
10#include <errhandlingapi.h>
11#include <system_error>
12
13hi_export_module(hikogui.win32 : win32_error_intf);
14
15hi_export namespace hi { inline namespace v1 {
16
17enum class hresult_error : int32_t {
18 ok = S_OK,
19 unspecified_error = E_FAIL,
20 invalid_argument = E_INVALIDARG,
21};
22
23}} // namespace hi::v1
24
25hi_export template<>
26struct std::is_error_code_enum<hi::hresult_error> : std::true_type {};
27
28hi_export namespace hi { inline namespace v1 {
29
31 char const *name() const noexcept override
32 {
33 return "hresult";
34 }
35
36 std::string message(int code) const override;
37
38 bool equivalent(int code, std::error_condition const & condition) const noexcept override
39 {
40 switch (static_cast<hi::hresult_error>(code)) {
41 case hi::hresult_error::invalid_argument:
42 return condition == std::errc::invalid_argument;
43 default:
44 return false;
45 };
46 }
47};
48
49inline auto global_hresult_error_category = hresult_error_category{};
50
51[[nodiscard]] inline std::error_code make_error_code(hresult_error code) noexcept
52{
53 return {static_cast<int>(code), global_hresult_error_category};
54}
55
56[[nodiscard]] inline hresult_error to_win32_error(win32_error code) noexcept
57{
58 return static_cast<hresult_error>(__HRESULT_FROM_WIN32(static_cast<DWORD>(code)));
59}
60
61}}
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Definition hresult_error_intf.hpp:30