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
55// initguid allows some of the header files to define actual implementations of the GUID.
56// However this is incompatible with other headers which causes some values to become undefined.
57#include <initguid.h>
58
59// Multimedia and audio.
60#include <mmsystem.h>
61#include <mmeapi.h>
62#include <mmddk.h>
63#include <mmreg.h>
64#include <winioctl.h>
65#include <propsys.h>
66#include <ks.h>
67#include <ksmedia.h>
68#include <functiondiscoverykeys_devpkey.h>
69#include <mmdeviceapi.h>
70#include <endpointvolume.h>
71#include <audioclient.h>
72
73// The windows headers create all sort of insane macros.
74#undef IN
75#undef OUT
76#undef small
77
78#include "cast.hpp"
79#include "exception.hpp"
80#include <string_view>
81#include <string>
82
83namespace hi { inline namespace v1 {
84
87[[nodiscard]] inline std::wstring win32_string_to_wstring(std::string_view s)
88{
89 auto s_len = narrow_cast<int>(s.size());
90 auto r_len = MultiByteToWideChar(CP_UTF8, 0, s.data(), s_len, nullptr, 0);
91 if (r_len == 0) {
92 throw parse_error("win32_string_to_wstring()");
93 }
94
95 auto r = std::wstring(narrow_cast<size_t>(r_len), L'\0');
96 MultiByteToWideChar(CP_UTF8, 0, s.data(), s_len, r.data(), r_len);
97 return r;
98}
99
102[[nodiscard]] inline std::string win32_wstring_to_string(std::wstring_view s)
103{
104 auto s_len = narrow_cast<int>(s.size());
105 auto r_len = WideCharToMultiByte(CP_UTF8, 0, s.data(), s_len, nullptr, 0, nullptr, nullptr);
106 if (r_len == 0) {
107 throw parse_error("win32_wstring_to_string()");
108 }
109
110 auto r = std::string(narrow_cast<size_t>(r_len), '\0');
111 WideCharToMultiByte(CP_UTF8, 0, s.data(), s_len, r.data(), r_len, nullptr, nullptr);
112 return r;
113}
114
115
116}} // namespace hi::v1
Utilities for throwing exceptions and terminating the application.
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:102
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:87
Exception thrown during parsing on an error.
Definition exception.hpp:50