HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
processthreadsapi.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 "base.hpp"
9#include <expected>
10#include <string>
11#include <system_error>
12
13hi_export_module(hikogui.win32.processthreadsapi);
14
15hi_export namespace hi {
16inline namespace v1 {
17
18[[nodiscard]] hi_inline std::expected<uint32_t, win32_error> win32_GetExitCodeProcess(HANDLE process_handle) noexcept
19{
20 DWORD exit_code = 0;
22 if (exit_code == STILL_ACTIVE) {
23 return std::unexpected{win32_error::status_pending};
24 } else {
25 return exit_code;
26 }
27 } else {
28 return std::unexpected{win32_GetLastError()};
29 }
30}
31
32template<typename StartupInfo>
33[[nodiscard]] hi_inline std::expected<PROCESS_INFORMATION, win32_error> win32_CreateProcess(
34 std::optional<std::string> application_name,
35 std::optional<std::string> command_line,
38 bool inherit_handles,
39 uint32_t creation_flags,
40 void const *environment,
41 std::optional<std::string> current_directory,
43{
45 wchar_t const *application_name_cstr = nullptr;
46 if (application_name) {
50 } else {
52 }
53 }
54
56 wchar_t *command_line_cstr = nullptr;
57 if (command_line) {
61 } else {
62 return std::unexpected{command_line_wstr_.error()};
63 }
64 }
65
67 wchar_t *current_directory_cstr = nullptr;
72 } else {
74 }
75 }
76
77 auto r = PROCESS_INFORMATION{};
78
85 static_cast<DWORD>(creation_flags),
86 const_cast<void *>(environment),
88 const_cast<STARTUPINFOW *>(reinterpret_cast<STARTUPINFOW const *>(&startup_info)),
89 &r)) {
90 return std::unexpected{win32_GetLastError()};
91 }
92
93 return r;
94}
95
96} // namespace v1
97}
Rules for working with win32 headers.
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
The HikoGUI namespace.
Definition recursive_iterator.hpp:15
hi_inline 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:119
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:378
T c_str(T... args)
T data(T... args)
T unexpected(T... args)