HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
winnls.hpp
1
2#pragma once
3
5#include "base.hpp"
6#include <expected>
7#include <string>
8#include <system_error>
9
10hi_export_module(hikogui.win32.winnls);
11
12namespace hi { inline namespace v1 {
13
14hi_export [[nodiscard]] inline std::expected<std::string, win32_error> win32_GetUserDefaultLocaleName() noexcept
15{
16 auto code = win32_error{};
17
18 auto name = std::wstring{};
19 name.resize_and_overwrite(LOCALE_NAME_MAX_LENGTH - 1, [&code](wchar_t *p, size_t count) {
20 if (auto actual_count = ::GetUserDefaultLocaleName(p, static_cast<int>(count + 1))) {
21 return actual_count - 1;
22 } else {
23 code = win32_GetLastError();
24 return 0;
25 }
26 });
27
28 if (static_cast<bool>(code)) {
29 return std::unexpected{code};
30 }
31
32 return win32_WideCharToMultiByte(name);;
33}
34
35}}
Rules for working with win32 headers.
@ code
Text is a piece of programming-code; a variable name, a function name.
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
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
T unexpected(T... args)