5#include "../macros.hpp"
13hi_export_module(hikogui.win32.errhandlingapi);
15namespace hi {
inline namespace v1 {
17hi_export
enum class win32_error : uint32_t {
29namespace hi {
inline namespace v1 {
32 char const *name()
const noexcept override
41 switch (
static_cast<hi::win32_error
>(code)) {
42 case hi::win32_error::file_not_found:
43 return condition == std::errc::no_such_file_or_directory;
44 case hi::win32_error::more_data:
45 return condition == std::errc::message_size;
46 case hi::win32_error::invalid_data:
47 return condition == std::errc::bad_message;
58 return {
static_cast<int>(code), global_win32_error_category};
80 auto s_len =
static_cast<int>(
static_cast<unsigned int>(s.size()));
86 auto r =
std::string(
static_cast<size_t>(
static_cast<std::make_signed_t<size_t>
>(
r_len)),
'\0');
87 r.resize_and_overwrite(
r_len, [&](
char *p,
size_t count) {
88 return ::WideCharToMultiByte(
code_page, flags, s.data(),
s_len, p,
static_cast<int>(count),
nullptr,
nullptr);
112 auto s_len =
static_cast<int>(
static_cast<unsigned int>(s.size()));
119 r.resize_and_overwrite(
r_len, [&](
wchar_t *p,
size_t count) {
120 return ::MultiByteToWideChar(
code_page, flags, s.data(),
s_len, p,
static_cast<int>(count));
143 while (first != last) {
169hi_export [[
nodiscard]]
inline std::expected<std::string, win32_error> win32_FormatMessage(win32_error error_code)
noexcept
194hi_export
inline std::string win32_error_category::message(
int code)
const
196 if (
auto msg = win32_FormatMessage(
static_cast<win32_error
>(code))) {
Rules for working with win32 headers.
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
hi_export std::expected< std::string, win32_error > win32_WideCharToMultiByte(std::wstring_view s, unsigned int code_page=CP_UTF8, uint32_t flags=0) noexcept
Convert a win32-API compatible std::wstring to a multi-byte std::string.
Definition base.hpp:73
hi_export std::expected< std::vector< std::string >, win32_error > win32_MultiSZToStringVector(wchar_t const *first, wchar_t const *last) noexcept
Convert a win32 zero terminated list of zero terminated strings.
Definition base.hpp:139
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
hi_export std::expected< std::wstring, win32_error > win32_MultiByteToWideChar(std::string_view s, unsigned int code_page=CP_UTF8, uint32_t flags=0) noexcept
Convert a win32-API compatible std::wstring to a multi-byte std::string.
Definition base.hpp:105