HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
win32_headers.hpp
Go to the documentation of this file.
1// Copyright Take Vos 2022.
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
16#pragma once
17
18#ifndef WIN32_NO_STATUS
19#error "-DWIN32_NO_STATUS must be defined as a compile option"
20#endif
21
22#include <Windows.h>
23#undef WIN32_NO_STATUS
24#include <ntstatus.h>
25#define WIN32_NO_STATUS
26#include <debugapi.h>
27#include <shellapi.h>
28#include <intrin.h>
29#include <winuser.h>
30
31// Window's registry.
32#include <winreg.h>
33#include <Uxtheme.h>
34
35// Cryptography
36#include <bcrypt.h>
37
38// Threading
39#include <synchapi.h>
40
41// File IO
42#include <ShlObj_core.h>
43
44// Networking
45#define IN
46#define OUT
47#include <WinSock2.h>
48
49// DirectX.
50#include <windowsx.h>
51#include <ddraw.h>
52#include <dwmapi.h>
53#include <dxgi.h>
54#include <dxgi1_6.h>
55
56// initguid allows some of the header files to define actual implementations of the GUID.
57// However this is incompatible with other headers which causes some values to become undefined.
58#include <initguid.h>
59
60// Multimedia and audio.
61#include <mmsystem.h>
62#include <mmeapi.h>
63#include <mmddk.h>
64#include <mmreg.h>
65#include <winioctl.h>
66#include <propsys.h>
67#include <ks.h>
68#include <ksmedia.h>
69#include <functiondiscoverykeys_devpkey.h>
70#include <mmdeviceapi.h>
71#include <endpointvolume.h>
72#include <audioclient.h>
73
74// The windows headers create all sort of insane macros.
75#undef IN
76#undef OUT
77#undef small
78
79#include "cast.hpp"
80#include "exception.hpp"
81#include <string_view>
82#include <string>
83
84namespace hi { inline namespace v1 {
85
88[[nodiscard]] inline std::wstring win32_string_to_wstring(std::string_view s)
89{
90 auto s_len = narrow_cast<int>(s.size());
91 auto r_len = MultiByteToWideChar(CP_UTF8, 0, s.data(), s_len, nullptr, 0);
92 if (r_len == 0) {
93 throw parse_error("win32_string_to_wstring()");
94 }
95
96 auto r = std::wstring(narrow_cast<size_t>(r_len), L'\0');
97 MultiByteToWideChar(CP_UTF8, 0, s.data(), s_len, r.data(), r_len);
98 return r;
99}
100
103[[nodiscard]] inline std::string win32_wstring_to_string(std::wstring_view s)
104{
105 auto s_len = narrow_cast<int>(s.size());
106 auto r_len = WideCharToMultiByte(CP_UTF8, 0, s.data(), s_len, nullptr, 0, nullptr, nullptr);
107 if (r_len == 0) {
108 throw parse_error("win32_wstring_to_string()");
109 }
110
111 auto r = std::string(narrow_cast<size_t>(r_len), '\0');
112 WideCharToMultiByte(CP_UTF8, 0, s.data(), s_len, r.data(), r_len, nullptr, nullptr);
113 return r;
114}
115
116
117}} // namespace hi::v1
Utilities for throwing exceptions and terminating the application.
Functions for casting values between types savely.
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
std::string win32_wstring_to_string(std::wstring_view s)
Convert a win32-API compatible std::wstring to a UTF-8 std::string.
Definition win32_headers.hpp:103
std::wstring win32_string_to_wstring(std::string_view s)
Convert a UTF-8 std::string to a win32-API compatible std::wstring.
Definition win32_headers.hpp:88
Exception thrown during parsing on an error.
Definition exception.hpp:63