HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
synchapi.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 : synchapi);
14
15hi_export namespace hi {
16inline namespace v1 {
17
18[[nodiscard]] inline std::expected<HANDLE, win32_error> win32_CreateEvent(
19 SECURITY_ATTRIBUTES const *event_attributes = nullptr,
20 bool manual_reset = true,
21 bool initial_state = false,
22 std::optional<std::string> name = std::nullopt) noexcept
23{
24 auto name_wstr = std::wstring{};
25 wchar_t const *name_cstr = nullptr;
26 if (name) {
27 if (auto name_wstr_ = win32_MultiByteToWideChar(*name)) {
28 name_wstr = *name_wstr_;
29 name_cstr = name_wstr.c_str();
30 } else {
31 return std::unexpected{name_wstr_.error()};
32 }
33 }
34
35 if (auto r = CreateEventW(const_cast<SECURITY_ATTRIBUTES *>(event_attributes), manual_reset, initial_state, name_cstr); r != NULL) {
36 return r;
37 } else {
38 return std::unexpected{win32_GetLastError()};
39 }
40}
41
42} // namespace v1
43}
Rules for working with win32 headers.
The HikoGUI namespace.
Definition array_generic.hpp:20
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
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
T c_str(T... args)
T unexpected(T... args)