8#include "../macros.hpp"
9#include "win32_error_intf.hpp"
17hi_export_module(hikogui.win32 : winreg);
19hi_export
namespace hi {
inline namespace v1 {
39 return static_cast<win32_error
>(::RegDeleteKeyValueW(key, wpath->c_str(), wname->c_str()));
54 return static_cast<win32_error
>(::RegDeleteKeyW(key, wpath->c_str()));
66[[nodiscard]]
inline win32_error
win32_RegSetKeyValue(HKEY key, std::string_view path, std::string_view name, uint32_t value)
78 auto const dvalue =
static_cast<DWORD
>(value);
80 return static_cast<win32_error
>(::RegSetKeyValueW(key, wpath->c_str(), wname->c_str(), REG_DWORD, &dvalue,
sizeof(dvalue)));
92[[nodiscard]]
inline win32_error
win32_RegSetKeyValue(HKEY key, std::string_view path, std::string_view name, std::string_view value)
101 return wname.error();
106 return wvalue.error();
109 auto const wvalue_size =
static_cast<DWORD
>((wvalue->size() + 1) *
sizeof(
wchar_t));
111 return static_cast<win32_error
>(::RegSetKeyValueW(key, wpath->c_str(), wname->c_str(), REG_SZ, wvalue->c_str(), wvalue_size));
117[[nodiscard]]
inline std::expected<void, win32_error>
win32_RegGetValue_void(HKEY key, std::string_view path, std::string_view name)
129 auto status =
static_cast<win32_error
>(::RegGetValueW(key, wpath->c_str(), wname->c_str(), RRF_RT_ANY, NULL, NULL, NULL));
130 if (status == win32_error::success) {
144[[nodiscard]]
inline std::expected<uint32_t, win32_error>
win32_RegGetValue_dword(HKEY key, std::string_view path, std::string_view name)
noexcept
157 DWORD result_length =
sizeof(result);
158 DWORD result_type = 0;
159 auto const status =
static_cast<win32_error
>(::RegGetValueW(key, wpath->c_str(), wname->c_str(), RRF_RT_ANY, &result_type, &result, &result_length));
161 if (
static_cast<bool>(status)) {
165 return static_cast<uint32_t
>(result);
175[[nodiscard]]
inline std::expected<std::string, win32_error>
win32_RegGetValue_string(HKEY key, std::string_view path, std::string_view name)
noexcept
189 auto expected_size =
size_t{64};
190 for (
auto repeat = 0; repeat != 5; ++repeat) {
191 auto status = win32_error{};
193 result.resize_and_overwrite(expected_size, [&](
auto p,
auto n) {
195 auto result_length =
static_cast<DWORD
>((n + 1) *
sizeof(
wchar_t));
196 status =
static_cast<win32_error
>(::RegGetValueW(key, wpath->c_str(), wname->c_str(), RRF_RT_REG_SZ, NULL, p, &result_length));
198 expected_size = (result_length /
sizeof(wchar_t)) - 1;
203 case win32_error::success:
205 case win32_error::more_data:
224[[nodiscard]]
inline std::expected<std::vector<std::string>, win32_error>
240 for (
auto repeat = 0; repeat != 5; ++repeat) {
241 auto result_length =
static_cast<DWORD
>(result.size() *
sizeof(wchar_t));
243 static_cast<win32_error
>(::RegGetValueW(key, wpath->c_str(), wname->c_str(), RRF_RT_REG_MULTI_SZ, NULL, result.data(), &result_length));
246 case win32_error::success:
249 case win32_error::more_data:
250 assert(result_length % 2 == 0);
251 result.resize(result_length /
sizeof(
wchar_t));
273[[nodiscard]] std::expected<T, win32_error>
win32_RegGetValue(HKEY key, std::string_view path, std::string_view name) =
delete;
276[[nodiscard]]
inline std::expected<void, win32_error>
win32_RegGetValue(HKEY key, std::string_view path, std::string_view name)
281template<std::
integral T>
282[[nodiscard]]
inline std::expected<T, win32_error>
win32_RegGetValue(HKEY key, std::string_view path, std::string_view name)
285 return static_cast<T
>(*tmp);
292[[nodiscard]]
inline std::expected<std::string, win32_error>
win32_RegGetValue(HKEY key, std::string_view path, std::string_view name)
298[[nodiscard]]
inline std::expected<std::vector<std::string>, win32_error>
Rules for working with win32 headers.
The HikoGUI namespace.
Definition array_generic.hpp:20
win32_error win32_RegSetKeyValue(HKEY key, std::string_view path, std::string_view name, uint32_t value)
Write a DWORD registry value.
Definition winreg.hpp:66
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
std::expected< T, win32_error > win32_RegGetValue(HKEY key, std::string_view path, std::string_view name)=delete
Read from the registry value.
Definition winreg.hpp:282
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 stringapiset.hpp:92
win32_error win32_RegDeleteKeyValue(HKEY key, std::string_view path, std::string_view name) noexcept
Delete a registry value.
Definition winreg.hpp:27
std::expected< void, win32_error > win32_RegGetValue_void(HKEY key, std::string_view path, std::string_view name)
Check if a registry entry exists.
Definition winreg.hpp:117
win32_error win32_RegDeleteKey(HKEY key, std::string_view path) noexcept
Delete all registry values and the last part of the subkey.
Definition winreg.hpp:47
std::expected< uint32_t, win32_error > win32_RegGetValue_dword(HKEY key, std::string_view path, std::string_view name) noexcept
Read a DWORD registry value.
Definition winreg.hpp:144
std::expected< std::string, win32_error > win32_RegGetValue_string(HKEY key, std::string_view path, std::string_view name) noexcept
Read a strings from the registry value.
Definition winreg.hpp:175
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 stringapiset.hpp:58
std::expected< std::vector< std::string >, win32_error > win32_RegGetValue_multi_string(HKEY key, std::string_view path, std::string_view name) noexcept
Read a list of strings from the registry value.
Definition winreg.hpp:225
DOXYGEN BUG.
Definition algorithm_misc.hpp:20