CommonLibSSE (Parapets fork)
WinAPI.h
Go to the documentation of this file.
1 #pragma once
2 
3 namespace SKSE::WinAPI
4 {
5  inline constexpr auto CP_UTF8{ static_cast<unsigned int>(65001) };
6  inline constexpr auto IMAGE_SCN_MEM_EXECUTE{ static_cast<std::uint32_t>(0x20000000) };
7  inline constexpr auto IMAGE_SCN_MEM_WRITE{ static_cast<std::uint32_t>(0x80000000) };
8  inline const auto INVALID_HANDLE_VALUE{ reinterpret_cast<void*>(static_cast<std::intptr_t>(-1)) };
9  inline constexpr auto MAX_PATH{ static_cast<std::uint32_t>(260) };
10  inline constexpr auto MEM_RELEASE{ static_cast<std::uint32_t>(0x00008000) };
11  inline constexpr auto PAGE_EXECUTE_READWRITE{ static_cast<std::uint32_t>(0x40) };
12 
14  {
15  public:
16  // members
17  void* DebugInfo; // 00
18  std::int32_t LockCount; // 08
19  std::int32_t RecursionCount; // 0C
20  void* OwningThread; // 10
21  void* LockSemaphore; // 18
22  std::uint64_t* SpinCount; // 20
23  };
24  static_assert(sizeof(CRITICAL_SECTION) == 0x28);
25 
26  struct _FILETIME
27  {
28  public:
29  // members
30  std::uint32_t dwLowDateTime; // 00
31  std::uint32_t dwHighDateTime; // 04
32  };
33  static_assert(sizeof(_FILETIME) == 0x8);
35 
36  struct HWND__;
37  using HWND = HWND__*;
38 
39  struct HINSTANCE__;
40  using HINSTANCE = HINSTANCE__*;
41 
43  {
44  public:
45  // members
46  std::uint32_t dwFileAttributes;
50  std::uint32_t nFileSizeHigh;
51  std::uint32_t nFileSizeLow;
52  std::uint32_t dwReserved0;
53  std::uint32_t dwReserved1;
56  };
57  static_assert(sizeof(_WIN32_FIND_DATAA) == 0x140);
59 
60  using WNDPROC = std::intptr_t (*)(HWND, std::uint32_t, std::uintptr_t, std::intptr_t);
61 
62  enum struct GetWindowLongIndex
63  {
64  EXSTYLE = -20,
65  HINSTANCE = -6,
66  HWNDPARENT = -8,
67  ID = -12,
68  STYLE = -16,
69  USERDATA = -21,
70  WNDPROC = -4,
71  };
73 
75  {
76  std::uint32_t Length; // 00
77  void* SecurityDescriptor; // 08
78  std::int32_t InheritHandle; // 10
79  };
80  static_assert(sizeof(SECURITY_ATTRIBUTES) == 0x18);
81 
82  struct HandleCloser
83  {
84  void operator()(void* a_handle) const noexcept;
85  };
86 
87  using ScopedHandle = std::unique_ptr<void, HandleCloser>;
88 
89  struct _GUID
90  {
91  constexpr auto operator<=>(const _GUID&) const noexcept = default;
92 
93  // members
94  std::uint32_t Data1; // 00
95  std::uint16_t Data2; // 04
96  std::uint16_t Data3; // 06
97  std::uint8_t Data4[8]; // 08
98  };
99  static_assert(sizeof(_GUID) == 0x10);
100  using GUID = _GUID;
101  using IID = GUID;
102  using REFIID = const IID&;
103  using CLSID = GUID;
104  using REFCLSID = const IID&;
105 
106  namespace DBT
107  {
108  enum DeviceChangeMessage : std::uintptr_t
109  {
110  DEVICEARRIVAL = 0x8000,
116  };
117 
118  enum struct DeviceType : std::uint32_t
119  {
120  OEM = 0x00000000,
121  DEVNODE = 0x00000001,
122  VOLUME = 0x00000002,
123  PORT = 0x00000003,
124  NET = 0x00000004,
125  DEVICEINTERFACE = 0x00000005,
126  HANDLE = 0x00000006,
127  };
129  };
130 
132  {
133  std::uint32_t dbch_size; // 0
135  std::uint32_t dbch_reserved; // 8
136  };
137  static_assert(sizeof(_DEV_BROADCAST_HDR) == 0xC);
139 
141  {
142  std::uint32_t dbcc_size; // 00
144  std::uint32_t dbcc_reserved; // 08
146  char dbcc_name[1]; // 1C
147  };
148  static_assert(sizeof(_DEV_BROADCAST_DEVICEINTERFACE_A) == 0x20);
151 
153  {
154  enum Flags
155  {
156  WINDOW_HANDLE = 0x00000000,
157  SERVICE_HANDLE = 0x00000001,
158 
159  ALL_INTERFACE_CLASSES = 0x00000004,
160  };
161  };
162 
164  {
165  void operator()(void* handle) const noexcept;
166  };
167 
168  using ScopedDeviceNotify = std::unique_ptr<void, DeviceNotifyCloser>;
169 
170  [[nodiscard]] std::intptr_t CallWindowProc(
171  WNDPROC a_prevWndFunc,
172  void* a_wnd,
173  std::uint32_t a_msg,
174  std::uintptr_t a_wParam,
175  std::intptr_t a_lParam);
176 
178  SECURITY_ATTRIBUTES* a_eventAttributes,
179  char* a_name,
180  std::uint32_t a_flags,
181  std::uint32_t a_desiredAccess);
182 
184  SECURITY_ATTRIBUTES* a_eventAttributes,
185  wchar_t* a_name,
186  std::uint32_t a_flags,
187  std::uint32_t a_desiredAccess);
188 
189  [[nodiscard]] void* GetCurrentModule() noexcept;
190 
191  [[nodiscard]] void* GetCurrentProcess() noexcept;
192 
193  [[nodiscard]] std::uint32_t GetCurrentThreadID() noexcept;
194 
195  [[nodiscard]] std::uint32_t GetEnvironmentVariable(
196  const char* a_name,
197  char* a_buffer,
198  std::uint32_t a_size) noexcept;
199 
200  [[nodiscard]] std::uint32_t GetEnvironmentVariable(
201  const wchar_t* a_name,
202  wchar_t* a_buffer,
203  std::uint32_t a_size) noexcept;
204 
205  [[nodiscard]] bool GetFileVersionInfo(
206  const char* a_filename,
207  std::uint32_t a_handle,
208  std::uint32_t a_len,
209  void* a_data) noexcept;
210 
211  [[nodiscard]] bool GetFileVersionInfo(
212  const wchar_t* a_filename,
213  std::uint32_t a_handle,
214  std::uint32_t a_len,
215  void* a_data) noexcept;
216 
217  [[nodiscard]] std::uint32_t GetFileVersionInfoSize(
218  const char* a_filename,
219  std::uint32_t* a_handle) noexcept;
220 
221  [[nodiscard]] std::uint32_t GetFileVersionInfoSize(
222  const wchar_t* a_filename,
223  std::uint32_t* a_handle) noexcept;
224 
225  [[nodiscard]] std::size_t GetMaxPath() noexcept;
226 
228  void* a_module,
229  char* a_filename,
230  std::uint32_t a_size) noexcept;
231 
233  void* a_module,
234  wchar_t* a_filename,
235  std::uint32_t a_size) noexcept;
236 
237  [[nodiscard]] void* GetModuleHandle(const char* a_moduleName) noexcept;
238 
239  [[nodiscard]] void* GetModuleHandle(const wchar_t* a_moduleName) noexcept;
240 
241  [[nodiscard]] void* GetProcAddress(
242  void* a_module,
243  const char* a_procName) noexcept;
244 
246  HWND a_wnd,
247  GetWindowLongIndex a_index) noexcept;
248 
249  std::int32_t MessageBox(
250  void* a_wnd,
251  const char* a_text,
252  const char* a_caption,
253  unsigned int a_type) noexcept;
254 
255  std::int32_t MessageBox(
256  void* a_wnd,
257  const wchar_t* a_text,
258  const wchar_t* a_caption,
259  unsigned int a_type) noexcept;
260 
262  unsigned int a_codePage,
263  std::uint32_t a_flags,
264  const char* a_multiByteStr,
265  int a_multiByte,
266  wchar_t* a_wideCharStr,
267  int a_wideChar);
268 
270  const char* a_outputString) noexcept;
271 
273  const wchar_t* a_outputString) noexcept;
274 
276  void* a_recipient,
277  void* a_notificationFilter,
278  std::uint32_t a_flags) noexcept;
279 
280  bool SetEvent(ScopedHandle& a_event) noexcept;
281 
283  HWND a_wnd,
284  GetWindowLongIndex a_index,
285  std::intptr_t a_newLong) noexcept;
286 
288  HWND a_wnd,
289  GetWindowLongIndex a_index,
290  void* a_newLong) noexcept;
291 
292  [[noreturn]] void TerminateProcess(
293  void* a_process,
294  unsigned int a_exitCode) noexcept;
295 
296  [[nodiscard]] void* TlsGetValue(std::uint32_t a_tlsIndex) noexcept;
297 
299  std::uint32_t a_tlsIndex,
300  void* a_tlsValue) noexcept;
301 
303  void* a_address,
304  std::size_t a_size,
305  std::uint32_t a_freeType) noexcept;
306 
307  [[nodiscard]] bool VerQueryValue(
308  const void* a_block,
309  const char* a_subBlock,
310  void** a_buffer,
311  unsigned int* a_len) noexcept;
312 
313  [[nodiscard]] bool VerQueryValue(
314  const void* a_block,
315  const wchar_t* a_subBlock,
316  void** a_buffer,
317  unsigned int* a_len) noexcept;
318 
319  [[nodiscard]] bool VirtualProtect(
320  void* a_address,
321  std::size_t a_size,
322  std::uint32_t a_newProtect,
323  std::uint32_t* a_oldProtect) noexcept;
324 
326  std::span<void* const> a_handles,
327  bool a_waitAll,
328  std::uint32_t a_milliseconds,
329  bool a_alertable);
330 
332  ScopedHandle& a_handle,
333  std::uint32_t a_milliseconds,
334  bool a_alertable) noexcept;
335 
336  [[nodiscard]] int WideCharToMultiByte(
337  unsigned int a_codePage,
338  std::uint32_t a_flags,
339  const wchar_t* a_wideCharStr,
340  int a_wideChar,
341  char* a_multiByteStr,
342  int a_multiByte,
343  const char* a_defaultChar,
344  int* a_usedDefaultChar);
345 }
346 
347 namespace RE::DirectX
348 {
349  struct XMFLOAT4X4
350  {
351  public:
352  // members
353  float m[4][4];
354  };
355  static_assert(sizeof(XMFLOAT4X4) == 0x40);
356 }
357 
358 namespace RE::XInput
359 {
361  {
362  public:
363  std::uint16_t wButtons; // 0
364  std::uint8_t bLeftTrigger; // 2
365  std::uint8_t bRightTrigger; // 3
366  std::int16_t sThumbLX; // 4
367  std::int16_t sThumbLY; // 6
368  std::int16_t sThumbRX; // 8
369  std::int16_t sThumbRY; // A
370  };
371  static_assert(sizeof(XINPUT_GAMEPAD) == 0xC);
372 
374  {
375  public:
376  std::uint32_t dwPacketNumber; // 00
378  };
379  static_assert(sizeof(XINPUT_STATE) == 0x10);
380 
382  {
383  std::uint16_t wLeftMotorSpeed; // 0
384  std::uint16_t wRightMotorSpeed; // 2
385  };
386  static_assert(sizeof(XINPUT_VIBRATION) == 0x4);
387 }
Definition: WinAPI.h:359
Definition: AbsorbEffect.h:6
DeviceChangeMessage
Definition: WinAPI.h:109
@ DEVICEREMOVEPENDING
Definition: WinAPI.h:113
@ DEVICEQUERYREMOVE
Definition: WinAPI.h:111
@ DEVICETYPESPECIFIC
Definition: WinAPI.h:115
@ DEVICEQUERYREMOVEFAILED
Definition: WinAPI.h:112
@ DEVICEREMOVECOMPLETE
Definition: WinAPI.h:114
@ DEVICEARRIVAL
Definition: WinAPI.h:110
DeviceType
Definition: WinAPI.h:119
Definition: WinAPI.h:4
std::uint32_t GetFileVersionInfoSize(const char *a_filename, std::uint32_t *a_handle) noexcept
std::uint32_t GetEnvironmentVariable(const char *a_name, char *a_buffer, std::uint32_t a_size) noexcept
void * TlsGetValue(std::uint32_t a_tlsIndex) noexcept
bool VirtualProtect(void *a_address, std::size_t a_size, std::uint32_t a_newProtect, std::uint32_t *a_oldProtect) noexcept
GetWindowLongIndex
Definition: WinAPI.h:63
_GUID GUID
Definition: WinAPI.h:100
std::size_t GetMaxPath() noexcept
void OutputDebugString(const char *a_outputString) noexcept
void * GetCurrentModule() noexcept
constexpr auto IMAGE_SCN_MEM_WRITE
Definition: WinAPI.h:7
std::uint32_t GetModuleFileName(void *a_module, char *a_filename, std::uint32_t a_size) noexcept
std::uint32_t GetCurrentThreadID() noexcept
std::uint32_t WaitForSingleObjectEx(ScopedHandle &a_handle, std::uint32_t a_milliseconds, bool a_alertable) noexcept
constexpr auto MEM_RELEASE
Definition: WinAPI.h:10
constexpr auto PAGE_EXECUTE_READWRITE
Definition: WinAPI.h:11
std::intptr_t GetWindowLongPtr(HWND a_wnd, GetWindowLongIndex a_index) noexcept
HWND__ * HWND
Definition: WinAPI.h:37
void * GetModuleHandle(const char *a_moduleName) noexcept
bool TlsSetValue(std::uint32_t a_tlsIndex, void *a_tlsValue) noexcept
std::unique_ptr< void, DeviceNotifyCloser > ScopedDeviceNotify
Definition: WinAPI.h:168
bool GetFileVersionInfo(const char *a_filename, std::uint32_t a_handle, std::uint32_t a_len, void *a_data) noexcept
constexpr auto IMAGE_SCN_MEM_EXECUTE
Definition: WinAPI.h:6
int MultiByteToWideChar(unsigned int a_codePage, std::uint32_t a_flags, const char *a_multiByteStr, int a_multiByte, wchar_t *a_wideCharStr, int a_wideChar)
ScopedDeviceNotify RegisterDeviceNotification(void *a_recipient, void *a_notificationFilter, std::uint32_t a_flags) noexcept
bool VerQueryValue(const void *a_block, const char *a_subBlock, void **a_buffer, unsigned int *a_len) noexcept
std::intptr_t CallWindowProc(WNDPROC a_prevWndFunc, void *a_wnd, std::uint32_t a_msg, std::uintptr_t a_wParam, std::intptr_t a_lParam)
void * GetProcAddress(void *a_module, const char *a_procName) noexcept
bool SetEvent(ScopedHandle &a_event) noexcept
std::int32_t MessageBox(void *a_wnd, const char *a_text, const char *a_caption, unsigned int a_type) noexcept
constexpr auto CP_UTF8
Definition: WinAPI.h:5
const auto INVALID_HANDLE_VALUE
Definition: WinAPI.h:8
HINSTANCE__ * HINSTANCE
Definition: WinAPI.h:40
ScopedHandle CreateEventEx(SECURITY_ATTRIBUTES *a_eventAttributes, char *a_name, std::uint32_t a_flags, std::uint32_t a_desiredAccess)
int WideCharToMultiByte(unsigned int a_codePage, std::uint32_t a_flags, const wchar_t *a_wideCharStr, int a_wideChar, char *a_multiByteStr, int a_multiByte, const char *a_defaultChar, int *a_usedDefaultChar)
_DEV_BROADCAST_DEVICEINTERFACE_A DEV_BROADCAST_DEVICEINTERFACE_A
Definition: WinAPI.h:149
std::unique_ptr< void, HandleCloser > ScopedHandle
Definition: WinAPI.h:87
void * GetCurrentProcess() noexcept
void TerminateProcess(void *a_process, unsigned int a_exitCode) noexcept
std::intptr_t(*)(HWND, std::uint32_t, std::uintptr_t, std::intptr_t) WNDPROC
Definition: WinAPI.h:60
bool VirtualFree(void *a_address, std::size_t a_size, std::uint32_t a_freeType) noexcept
std::uint32_t WaitForMultipleObjectsEx(std::span< void *const > a_handles, bool a_waitAll, std::uint32_t a_milliseconds, bool a_alertable)
constexpr auto MAX_PATH
Definition: WinAPI.h:9
std::intptr_t SetWindowLongPtr(HWND a_wnd, GetWindowLongIndex a_index, std::intptr_t a_newLong) noexcept
Definition: NiBinaryStream.h:94
Definition: WinAPI.h:350
Definition: WinAPI.h:361
std::int16_t sThumbRY
Definition: WinAPI.h:369
std::uint8_t bRightTrigger
Definition: WinAPI.h:365
std::uint16_t wButtons
Definition: WinAPI.h:363
std::int16_t sThumbLX
Definition: WinAPI.h:366
std::int16_t sThumbLY
Definition: WinAPI.h:367
std::uint8_t bLeftTrigger
Definition: WinAPI.h:364
std::int16_t sThumbRX
Definition: WinAPI.h:368
Definition: WinAPI.h:374
XINPUT_GAMEPAD Gamepad
Definition: WinAPI.h:377
std::uint32_t dwPacketNumber
Definition: WinAPI.h:376
Definition: WinAPI.h:382
std::uint16_t wRightMotorSpeed
Definition: WinAPI.h:384
std::uint16_t wLeftMotorSpeed
Definition: WinAPI.h:383
Definition: WinAPI.h:14
void * DebugInfo
Definition: WinAPI.h:17
void * LockSemaphore
Definition: WinAPI.h:21
std::uint64_t * SpinCount
Definition: WinAPI.h:22
std::int32_t LockCount
Definition: WinAPI.h:18
std::int32_t RecursionCount
Definition: WinAPI.h:19
void * OwningThread
Definition: WinAPI.h:20
Definition: WinAPI.h:153
Flags
Definition: WinAPI.h:155
@ ALL_INTERFACE_CLASSES
Definition: WinAPI.h:159
@ WINDOW_HANDLE
Definition: WinAPI.h:156
@ SERVICE_HANDLE
Definition: WinAPI.h:157
Definition: WinAPI.h:164
void operator()(void *handle) const noexcept
Definition: WinAPI.h:83
void operator()(void *a_handle) const noexcept
Definition: WinAPI.h:75
std::int32_t InheritHandle
Definition: WinAPI.h:78
void * SecurityDescriptor
Definition: WinAPI.h:77
std::uint32_t Length
Definition: WinAPI.h:76
char dbcc_name[1]
Definition: WinAPI.h:146
GUID dbcc_classguid
Definition: WinAPI.h:145
std::uint32_t dbcc_reserved
Definition: WinAPI.h:144
DBT::DeviceType dbcc_devicetype
Definition: WinAPI.h:143
std::uint32_t dbcc_size
Definition: WinAPI.h:142
Definition: WinAPI.h:132
DBT::DeviceType dbch_devicetype
Definition: WinAPI.h:134
std::uint32_t dbch_reserved
Definition: WinAPI.h:135
std::uint32_t dbch_size
Definition: WinAPI.h:133
Definition: WinAPI.h:27
std::uint32_t dwLowDateTime
Definition: WinAPI.h:30
std::uint32_t dwHighDateTime
Definition: WinAPI.h:31
Definition: WinAPI.h:90
constexpr auto operator<=>(const _GUID &) const noexcept=default
std::uint16_t Data2
Definition: WinAPI.h:95
std::uint16_t Data3
Definition: WinAPI.h:96
std::uint32_t Data1
Definition: WinAPI.h:94
std::uint8_t Data4[8]
Definition: WinAPI.h:97
Definition: WinAPI.h:43
std::uint32_t nFileSizeLow
Definition: WinAPI.h:51
char cFileName[MAX_PATH]
Definition: WinAPI.h:54
std::uint32_t dwReserved1
Definition: WinAPI.h:53
std::uint32_t dwFileAttributes
Definition: WinAPI.h:46
std::uint32_t nFileSizeHigh
Definition: WinAPI.h:50
FILETIME ftCreationTime
Definition: WinAPI.h:47
char cAlternateFileName[14]
Definition: WinAPI.h:55
std::uint32_t dwReserved0
Definition: WinAPI.h:52
FILETIME ftLastAccessTime
Definition: WinAPI.h:48
FILETIME ftLastWriteTime
Definition: WinAPI.h:49