CommonLibVR
Loading...
Searching...
No Matches
BASE.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef _INC_WINAPIFAMILY
4# error Windows API detected. Please move any Windows API includes after CommonLib, or remove them.
5#endif
6
7#define REX_W32_IMPORT(a_ret, a_name, ...) \
8 extern "C" __declspec(dllimport) a_ret __stdcall W32_IMPL_##a_name(...) noexcept; \
9 __pragma(comment(linker, "/alternatename:__imp_W32_IMPL_" #a_name "=__imp_" #a_name))
10
11namespace REX::W32
12{
13 using BOOL = std::int32_t;
14 using HANDLE = void*;
15 using HBITMAP = struct HBITMAP__*;
16 using HBRUSH = struct HBRUSH__*;
17 using HCURSOR = struct HCURSOR__*;
18 using HDC = struct HDC__*;
19 using HFONT = struct HFONT__*;
20 using HICON = struct HICON__*;
21 using HINSTANCE = struct HINSTANCE__*;
22 using HKEY = struct HKEY__*;
23 using HMENU = struct HMENU__*;
25 using HMONITOR = struct HMONITOR__*;
26 using HPALETTE = struct HPALETTE__*;
27 using HPEN = struct HPEN__*;
28 using HRESULT = std::int32_t;
29 using HSTRING = struct HSTRING__*;
30 using HWND = struct HWND__*;
31 using NTSTATUS = std::int32_t;
32
33 // general constants
34 inline const auto INVALID_HANDLE_VALUE{ reinterpret_cast<HANDLE>(static_cast<std::intptr_t>(-1)) };
35 inline constexpr auto MAX_PATH{ 260u };
36}
37
38namespace REX::W32
39{
40 struct FILETIME
41 {
42 constexpr FILETIME() noexcept = default;
43
44 constexpr FILETIME(std::uint64_t a_value) noexcept
45 {
46 *this = std::bit_cast<FILETIME>(a_value);
47 }
48
49 constexpr operator std::uint64_t() const noexcept
50 {
51 return std::bit_cast<std::uint64_t>(*this);
52 }
53
54 std::uint32_t lo{}; // 00
55 std::uint32_t hi{}; // 04
56 };
57 static_assert(sizeof(FILETIME) == 0x8);
58}
59
60namespace REX::W32
61{
62 struct GUID
63 {
64 constexpr GUID() noexcept = default;
65
66 constexpr GUID(const std::uint32_t a_data1, std::uint16_t const a_data2, const std::uint16_t a_data3, const std::array<std::uint8_t, 8>& a_data4) noexcept :
67 data1(a_data1), data2(a_data2), data3(a_data3), data4{ a_data4[0], a_data4[1], a_data4[2], a_data4[3], a_data4[4], a_data4[5], a_data4[6], a_data4[7] }
68 {}
69
70 friend bool operator==(const GUID& a_lhs, const GUID& a_rhs) noexcept
71 {
72 return std::memcmp(&a_lhs, &a_rhs, sizeof(a_lhs)) == 0;
73 }
74
75 friend bool operator!=(const GUID& a_lhs, const GUID& a_rhs) noexcept
76 {
77 return !(a_lhs == a_rhs);
78 }
79
80 std::uint32_t data1{}; // 00
81 std::uint16_t data2{}; // 04
82 std::uint16_t data3{}; // 08
83 std::uint8_t data4[8]{}; // 10
84 };
85 static_assert(sizeof(GUID) == 0x10);
86
87 using UUID = GUID;
88 using IID = GUID;
89}
90
91namespace REX::W32
92{
93 struct POINT
94 {
95 constexpr POINT() noexcept = default;
96
97 constexpr POINT(std::int32_t a_x, std::int32_t a_y) noexcept :
98 x(a_x), y(a_y)
99 {}
100
101 std::int32_t x{}; // 00
102 std::int32_t y{}; // 04
103 };
104 static_assert(sizeof(POINT) == 0x8);
105}
106
107namespace REX::W32
108{
109 struct RECT
110 {
111 constexpr RECT() noexcept = default;
112
113 constexpr RECT(const std::int32_t a_x1, const std::int32_t a_y1, const std::int32_t a_x2, const std::int32_t a_y2) noexcept :
114 x1(a_x1), y1(a_y1), x2(a_x2), y2(a_y2)
115 {}
116
117 std::int32_t x1{}; // 00
118 std::int32_t y1{}; // 04
119 std::int32_t x2{}; // 08
120 std::int32_t y2{}; // 10
121 };
122 static_assert(sizeof(RECT) == 0x10);
123}
124
125namespace REX::W32
126{
127 struct SIZE
128 {
129 std::int32_t x{}; // 00
130 std::int32_t y{}; // 04
131 };
132 static_assert(sizeof(SIZE) == 0x8);
133}
134
135namespace REX::W32
136{
138 {
139 void* debugInfo; // 00
140 std::int32_t lockCount; // 08
141 std::int32_t recursionCount; // 0C
144 std::uintptr_t spinCount; // 20
145 };
146 static_assert(sizeof(CRITICAL_SECTION) == 0x28);
147
149 {
150 std::uint32_t length; // 00
153 };
154 static_assert(sizeof(SECURITY_ATTRIBUTES) == 0x18);
155
157 {
158 struct
159 {
160 std::uint32_t lo;
161 std::int32_t hi;
162 };
163 std::int64_t value;
164 };
165 static_assert(sizeof(LARGE_INTEGER) == 0x8);
166
168 {
169 struct
170 {
171 std::uint32_t lo;
172 std::uint32_t hi;
173 };
174 std::uint64_t value;
175 };
176 static_assert(sizeof(ULARGE_INTEGER) == 0x8);
177
179 {
180 std::uint16_t length;
181 std::uint16_t maxLength;
182 wchar_t* buffer;
183 };
184 static_assert(sizeof(UNICODE_STRING) == 0x10);
185}
186
187namespace REX::W32
188{
189 constexpr bool SUCCESS(const HRESULT a_result)
190 {
191 return a_result >= 0;
192 }
193
194 constexpr bool NT_SUCCESS(const NTSTATUS a_status)
195 {
196 return a_status >= 0;
197 }
198}
Definition BSDirectInputManager.h:8
std::int32_t NTSTATUS
Definition BASE.h:31
void * HANDLE
Definition BASE.h:14
HMENU__ * HMENU
Definition BASE.h:23
HSTRING__ * HSTRING
Definition BASE.h:29
constexpr bool NT_SUCCESS(const NTSTATUS a_status)
Definition BASE.h:194
std::int32_t BOOL
Definition BASE.h:13
HINSTANCE__ * HINSTANCE
Definition BASE.h:21
HPEN__ * HPEN
Definition BASE.h:27
HBITMAP__ * HBITMAP
Definition BASE.h:15
HDC__ * HDC
Definition BASE.h:18
constexpr auto MAX_PATH
Definition BASE.h:35
HBRUSH__ * HBRUSH
Definition BASE.h:16
HFONT__ * HFONT
Definition BASE.h:19
HICON__ * HICON
Definition BASE.h:20
HPALETTE__ * HPALETTE
Definition BASE.h:26
HKEY__ * HKEY
Definition BASE.h:22
HINSTANCE HMODULE
Definition BASE.h:24
std::int32_t HRESULT
Definition BASE.h:28
HMONITOR__ * HMONITOR
Definition BASE.h:25
constexpr bool SUCCESS(const HRESULT a_result)
Definition BASE.h:189
HWND__ * HWND
Definition BASE.h:30
HCURSOR__ * HCURSOR
Definition BASE.h:17
const auto INVALID_HANDLE_VALUE
Definition BASE.h:34
Definition EffectArchetypes.h:65
Definition BASE.h:138
HANDLE lockSemaphore
Definition BASE.h:143
std::uintptr_t spinCount
Definition BASE.h:144
HANDLE owningThread
Definition BASE.h:142
std::int32_t recursionCount
Definition BASE.h:141
std::int32_t lockCount
Definition BASE.h:140
void * debugInfo
Definition BASE.h:139
Definition BASE.h:41
constexpr FILETIME() noexcept=default
std::uint32_t lo
Definition BASE.h:54
std::uint32_t hi
Definition BASE.h:55
constexpr operator std::uint64_t() const noexcept
Definition BASE.h:49
Definition BASE.h:63
friend bool operator!=(const GUID &a_lhs, const GUID &a_rhs) noexcept
Definition BASE.h:75
constexpr GUID() noexcept=default
std::uint8_t data4[8]
Definition BASE.h:83
friend bool operator==(const GUID &a_lhs, const GUID &a_rhs) noexcept
Definition BASE.h:70
std::uint32_t data1
Definition BASE.h:80
std::uint16_t data3
Definition BASE.h:82
std::uint16_t data2
Definition BASE.h:81
Definition BASE.h:94
constexpr POINT() noexcept=default
std::int32_t y
Definition BASE.h:102
std::int32_t x
Definition BASE.h:101
Definition BASE.h:110
constexpr RECT() noexcept=default
std::int32_t x1
Definition BASE.h:117
std::int32_t x2
Definition BASE.h:119
std::int32_t y1
Definition BASE.h:118
std::int32_t y2
Definition BASE.h:120
Definition BASE.h:149
std::uint32_t length
Definition BASE.h:150
BOOL inheritHandle
Definition BASE.h:152
void * securityDescriptor
Definition BASE.h:151
Definition BASE.h:128
std::int32_t y
Definition BASE.h:130
std::int32_t x
Definition BASE.h:129
Definition BASE.h:179
std::uint16_t length
Definition BASE.h:180
std::uint16_t maxLength
Definition BASE.h:181
wchar_t * buffer
Definition BASE.h:182
Definition BASE.h:157
std::int32_t hi
Definition BASE.h:161
std::uint32_t lo
Definition BASE.h:160
std::int64_t value
Definition BASE.h:163
Definition BASE.h:168
std::uint32_t hi
Definition BASE.h:172
std::uint32_t lo
Definition BASE.h:171
std::uint64_t value
Definition BASE.h:174