HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
winnls.hpp
1// Copyright Take Vos 2023.
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
8#include "win32_error_intf.hpp"
9#include <expected>
10#include <string>
11#include <system_error>
12
13hi_export_module(hikogui.win32 : winnls);
14
15hi_export namespace hi { inline namespace v1 {
16
17[[nodiscard]] inline std::expected<std::string, win32_error> win32_GetUserDefaultLocaleName() noexcept
18{
19 auto code = win32_error{};
20
21 auto name = std::wstring{};
22 name.resize_and_overwrite(LOCALE_NAME_MAX_LENGTH - 1, [&code](wchar_t *p, size_t count) {
23 if (auto actual_count = ::GetUserDefaultLocaleName(p, static_cast<int>(count + 1))) {
24 return actual_count - 1;
25 } else {
26 code = win32_GetLastError();
27 return 0;
28 }
29 });
30
31 if (static_cast<bool>(code)) {
32 return std::unexpected{code};
33 }
34
35 return win32_WideCharToMultiByte(name);
36}
37
38}}
Rules for working with win32 headers.
@ code
Text is a piece of programming-code; a variable name, a function name.
The HikoGUI namespace.
Definition array_generic.hpp:20
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 stringapiset.hpp:26
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
T unexpected(T... args)