CommonLibVR
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 
11 namespace 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__*;
24  using HMODULE = HINSTANCE;
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 
32  // general constants
33  inline const auto INVALID_HANDLE_VALUE{ reinterpret_cast<HANDLE>(static_cast<std::intptr_t>(-1)) };
34  inline constexpr auto MAX_PATH{ 260u };
35 }
36 
37 namespace REX::W32
38 {
39  struct FILETIME
40  {
41  constexpr FILETIME() noexcept = default;
42 
43  constexpr FILETIME(std::uint64_t a_value) noexcept
44  {
45  *this = std::bit_cast<FILETIME>(a_value);
46  }
47 
48  constexpr operator std::uint64_t() const noexcept
49  {
50  return std::bit_cast<std::uint64_t>(*this);
51  }
52 
53  std::uint32_t lo; // 00
54  std::uint32_t hi; // 04
55  };
56  static_assert(sizeof(FILETIME) == 0x8);
57 }
58 
59 namespace REX::W32
60 {
61  struct GUID
62  {
63  constexpr GUID() noexcept = default;
64 
65  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 :
66  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] }
67  {}
68 
69  friend bool operator==(const GUID& a_lhs, const GUID& a_rhs) noexcept
70  {
71  return std::memcmp(&a_lhs, &a_rhs, sizeof(a_lhs)) == 0;
72  }
73 
74  friend bool operator!=(const GUID& a_lhs, const GUID& a_rhs) noexcept
75  {
76  return !(a_lhs == a_rhs);
77  }
78 
79  std::uint32_t data1; // 00
80  std::uint16_t data2; // 04
81  std::uint16_t data3; // 08
82  std::uint8_t data4[8]; // 10
83  };
84  static_assert(sizeof(GUID) == 0x10);
85 
86  using UUID = GUID;
87  using IID = GUID;
88 }
89 
90 namespace REX::W32
91 {
92  struct POINT
93  {
94  constexpr POINT() noexcept = default;
95 
96  constexpr POINT(std::int32_t a_x, std::int32_t a_y) noexcept :
97  x(a_x), y(a_y)
98  {}
99 
100  std::int32_t x; // 00
101  std::int32_t y; // 04
102  };
103  static_assert(sizeof(POINT) == 0x8);
104 }
105 
106 namespace REX::W32
107 {
108  struct RECT
109  {
110  constexpr RECT() noexcept = default;
111 
112  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 :
113  x1(a_x1), y1(a_y1), x2(a_x2), y2(a_y2)
114  {}
115 
116  std::int32_t x1; // 00
117  std::int32_t y1; // 04
118  std::int32_t x2; // 08
119  std::int32_t y2; // 10
120  };
121  static_assert(sizeof(RECT) == 0x10);
122 }
123 
124 namespace REX::W32
125 {
126  struct SIZE
127  {
128  std::int32_t x; // 00
129  std::int32_t y; // 04
130  };
131  static_assert(sizeof(SIZE) == 0x8);
132 }
133 
134 namespace REX::W32
135 {
137  {
138  void* debugInfo; // 00
139  std::int32_t lockCount; // 08
140  std::int32_t recursionCount; // 0C
143  std::uintptr_t spinCount; // 20
144  };
145  static_assert(sizeof(CRITICAL_SECTION) == 0x28);
146 
148  {
149  std::uint32_t length; // 00
150  void* securityDescriptor; // 04
152  };
153  static_assert(sizeof(SECURITY_ATTRIBUTES) == 0x18);
154 
156  {
157  struct
158  {
159  std::uint32_t lo;
160  std::uint32_t hi;
161  };
162  std::uint64_t value;
163  };
164 }
Definition: BSDirectInputManager.h:8
void * HANDLE
Definition: BASE.h:14
struct HPALETTE__ * HPALETTE
Definition: BASE.h:26
struct HDC__ * HDC
Definition: BASE.h:18
std::int32_t BOOL
Definition: BASE.h:13
struct HCURSOR__ * HCURSOR
Definition: BASE.h:17
struct HPEN__ * HPEN
Definition: BASE.h:27
struct HSTRING__ * HSTRING
Definition: BASE.h:29
constexpr auto MAX_PATH
Definition: BASE.h:34
struct HICON__ * HICON
Definition: BASE.h:20
struct HMENU__ * HMENU
Definition: BASE.h:23
struct HMONITOR__ * HMONITOR
Definition: BASE.h:25
HINSTANCE HMODULE
Definition: BASE.h:24
struct HBITMAP__ * HBITMAP
Definition: BASE.h:15
struct HWND__ * HWND
Definition: BASE.h:30
std::int32_t HRESULT
Definition: BASE.h:28
struct HBRUSH__ * HBRUSH
Definition: BASE.h:16
struct HINSTANCE__ * HINSTANCE
Definition: BASE.h:21
const auto INVALID_HANDLE_VALUE
Definition: BASE.h:33
struct HFONT__ * HFONT
Definition: BASE.h:19
struct HKEY__ * HKEY
Definition: BASE.h:22
Definition: EffectArchetypes.h:65
Definition: BASE.h:137
HANDLE lockSemaphore
Definition: BASE.h:142
std::uintptr_t spinCount
Definition: BASE.h:143
HANDLE owningThread
Definition: BASE.h:141
std::int32_t recursionCount
Definition: BASE.h:140
std::int32_t lockCount
Definition: BASE.h:139
void * debugInfo
Definition: BASE.h:138
Definition: BASE.h:40
constexpr FILETIME() noexcept=default
std::uint32_t lo
Definition: BASE.h:53
std::uint32_t hi
Definition: BASE.h:54
Definition: BASE.h:62
friend bool operator!=(const GUID &a_lhs, const GUID &a_rhs) noexcept
Definition: BASE.h:74
constexpr GUID() noexcept=default
std::uint8_t data4[8]
Definition: BASE.h:82
friend bool operator==(const GUID &a_lhs, const GUID &a_rhs) noexcept
Definition: BASE.h:69
std::uint32_t data1
Definition: BASE.h:79
std::uint16_t data3
Definition: BASE.h:81
std::uint16_t data2
Definition: BASE.h:80
Definition: BASE.h:93
constexpr POINT() noexcept=default
std::int32_t y
Definition: BASE.h:101
std::int32_t x
Definition: BASE.h:100
Definition: BASE.h:109
constexpr RECT() noexcept=default
std::int32_t x1
Definition: BASE.h:116
std::int32_t x2
Definition: BASE.h:118
std::int32_t y1
Definition: BASE.h:117
std::int32_t y2
Definition: BASE.h:119
Definition: BASE.h:148
std::uint32_t length
Definition: BASE.h:149
BOOL inheritHandle
Definition: BASE.h:151
void * securityDescriptor
Definition: BASE.h:150
Definition: BASE.h:127
std::int32_t y
Definition: BASE.h:129
std::int32_t x
Definition: BASE.h:128
Definition: BASE.h:156
std::uint32_t hi
Definition: BASE.h:160
std::uint32_t lo
Definition: BASE.h:159
std::uint64_t value
Definition: BASE.h:162