Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
MinimalWindowsApi.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3//=====================================================================================================================
4// Implementation of a minimal subset of the Windows API required for inline function definitions and platform-specific
5// interfaces in Core. Use of this file allows avoiding including large platform headers in the public engine API.
6//
7// Win32 API functions are declared in the "Windows" namespace to avoid conflicts if the real Windows.h is included
8// later, but are mapped to the same imported symbols by the linker due to C-style linkage.
9//=====================================================================================================================
10
11#pragma once
12
13#include "CoreTypes.h"
14
15#ifdef __clang__
16 #define MINIMAL_WINDOWS_API
17#else
18 #define MINIMAL_WINDOWS_API extern "C" __declspec(dllimport)
19#endif
20
21// The 10.0.18362.0 SDK introduces an error if the packing isn't the default for the platform.
23
24// Undefine Windows types that we're going to redefine. This should be done by HideWindowsPlatformTypes.h after including any system headers,
25// but it's less friction to just undefine them here.
26#pragma push_macro("TRUE")
27#pragma push_macro("FALSE")
28#undef TRUE
29#undef FALSE
30
31// Use strongly typed handles
32#ifndef STRICT
33#define STRICT
34#endif
35
36// With STRICT enabled, handles are implemented as opaque struct pointers. We can prototype these structs here and
37// typedef them under the Windows namespace below. Since typedefs are only aliases rather than types in their own
38// right, this allows using handles from the Windows:: namespace interchangably with their native definition.
39struct HINSTANCE__;
40struct HWND__;
41struct HKEY__;
42struct HDC__;
43struct HICON__;
44struct _RTL_SRWLOCK;
45
46// Other types
47struct tagPROCESSENTRY32W;
48struct _EXCEPTION_POINTERS;
49struct _OVERLAPPED;
50struct _RTL_CRITICAL_SECTION;
51union _LARGE_INTEGER;
52
53// Global constants
54#define WINDOWS_MAX_PATH 260
55#define WINDOWS_PF_COMPARE_EXCHANGE128 14
56
57// Standard calling convention for Win32 functions
58#define WINAPI __stdcall
59
60// Minimal subset of the Windows API required for interfaces and inline functions
61namespace Windows
62{
63 // Typedefs for basic Windows types
64 typedef int32 BOOL;
65 typedef unsigned char BYTE;
66 typedef BYTE BOOLEAN;
67 typedef unsigned long DWORD;
68 typedef DWORD* LPDWORD;
69 typedef long LONG;
70 typedef long* LPLONG;
71 typedef int64 LONGLONG;
73 typedef void* LPVOID;
74 typedef const void* LPCVOID;
75 typedef const wchar_t* LPCTSTR;
76
77 // Typedefs for standard handles
78 typedef void* HANDLE;
79 typedef HINSTANCE__* HINSTANCE;
81 typedef HWND__* HWND;
82 typedef HKEY__* HKEY;
83 typedef HDC__* HDC;
84 typedef HICON__* HICON;
85 typedef HICON__* HCURSOR;
86
87 // Other typedefs
88 typedef tagPROCESSENTRY32W PROCESSENTRY32;
89 typedef _EXCEPTION_POINTERS* LPEXCEPTION_POINTERS;
90 typedef _RTL_CRITICAL_SECTION* LPCRITICAL_SECTION;
91 typedef _OVERLAPPED* LPOVERLAPPED;
92 typedef _LARGE_INTEGER* LPLARGE_INTEGER;
93
94 typedef _RTL_SRWLOCK RTL_SRWLOCK, *PRTL_SRWLOCK;
96
97 // Opaque SRWLOCK structure
98 struct SRWLOCK
99 {
100 void* Ptr;
101 };
102
103 // Constants
104 static constexpr BOOL TRUE = 1;
105 static constexpr BOOL FALSE = 0;
106
107 // Modules
110
111 // Critical sections
119
127
129 {
131 }
132
134 {
136 }
137
139 {
140 return TryAcquireSRWLockShared((PSRWLOCK)SRWLock);
141 }
142
144 {
146 }
147
149 {
151 }
152
154 {
156 }
157
159 {
161 }
162
163 // I/O
165 MINIMAL_WINDOWS_API BOOL WINAPI GetOverlappedResult(HANDLE hFile, LPOVERLAPPED lpOverlapped, LPDWORD lpNumberOfBytesTransferred, BOOL bWait);
166 MINIMAL_WINDOWS_API BOOL WINAPI WriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped);
167 MINIMAL_WINDOWS_API BOOL WINAPI ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped);
168
169 // Timing
171
172 // Thread-local storage functions
178
179 // System
181
182 // For structures which are opaque
183 struct CRITICAL_SECTION { void* Opaque1[1]; long Opaque2[2]; void* Opaque3[3]; };
184 struct OVERLAPPED { void *Opaque[3]; unsigned long Opaque2[2]; };
186
188 {
189 return ConnectNamedPipe(hNamedPipe, (LPOVERLAPPED)lpOverlapped);
190 }
191
192 FORCEINLINE BOOL WINAPI GetOverlappedResult(HANDLE hFile, OVERLAPPED* lpOverlapped, LPDWORD lpNumberOfBytesTransferred, BOOL bWait)
193 {
194 return GetOverlappedResult(hFile, (LPOVERLAPPED)lpOverlapped, lpNumberOfBytesTransferred, bWait);
195 }
196
197 FORCEINLINE BOOL WINAPI WriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, OVERLAPPED* lpOverlapped)
198 {
199 return WriteFile(hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, (LPOVERLAPPED)lpOverlapped);
200 }
201
202 FORCEINLINE BOOL WINAPI ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, OVERLAPPED* lpOverlapped)
203 {
204 return ReadFile(hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, (LPOVERLAPPED)lpOverlapped);
205 }
206
208 {
210 }
211
213 {
214 return InitializeCriticalSectionAndSpinCount((LPCRITICAL_SECTION)lpCriticalSection, dwSpinCount);
215 }
216
218 {
219 return SetCriticalSectionSpinCount((LPCRITICAL_SECTION)lpCriticalSection, dwSpinCount);
220 }
221
223 {
224 return TryEnterCriticalSection((LPCRITICAL_SECTION)lpCriticalSection);
225 }
226
228 {
230 }
231
233 {
235 }
236
238 {
240 }
241
243 {
245 }
246}
247
248// Restore the definitions for TRUE and FALSE
249#pragma pop_macro("FALSE")
250#pragma pop_macro("TRUE")
251
252// Restore the packing setting
#define WINAPI
#define MINIMAL_WINDOWS_API
#define FORCEINLINE
Definition Platform.h:644
#define PRAGMA_POP_PLATFORM_DEFAULT_PACKING
#define PRAGMA_PUSH_PLATFORM_DEFAULT_PACKING
FORCEINLINE void WINAPI ReleaseSRWLockExclusive(SRWLOCK *SRWLock)
MINIMAL_WINDOWS_API void WINAPI AcquireSRWLockExclusive(PSRWLOCK SRWLock)
MINIMAL_WINDOWS_API BOOL WINAPI TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue)
FORCEINLINE BOOLEAN WINAPI TryAcquireSRWLockExclusive(SRWLOCK *SRWLock)
MINIMAL_WINDOWS_API void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
FORCEINLINE BOOL WINAPI InitializeCriticalSectionAndSpinCount(CRITICAL_SECTION *lpCriticalSection, DWORD dwSpinCount)
MINIMAL_WINDOWS_API BOOL WINAPI QueryPerformanceCounter(LPLARGE_INTEGER Cycles)
unsigned long DWORD
FORCEINLINE void WINAPI AcquireSRWLockShared(SRWLOCK *SRWLock)
_RTL_SRWLOCK * PRTL_SRWLOCK
FORCEINLINE void WINAPI LeaveCriticalSection(CRITICAL_SECTION *lpCriticalSection)
MINIMAL_WINDOWS_API BOOL WINAPI FreeLibrary(HMODULE hModule)
FORCEINLINE BOOL WINAPI WriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, OVERLAPPED *lpOverlapped)
MINIMAL_WINDOWS_API DWORD WINAPI GetCurrentThreadId()
MINIMAL_WINDOWS_API LPVOID WINAPI TlsGetValue(DWORD dwTlsIndex)
FORCEINLINE BOOL WINAPI ConnectNamedPipe(HANDLE hNamedPipe, OVERLAPPED *lpOverlapped)
FORCEINLINE BOOLEAN WINAPI TryAcquireSRWLockShared(SRWLOCK *SRWLock)
FORCEINLINE void WINAPI InitializeSRWLock(SRWLOCK *SRWLock)
MINIMAL_WINDOWS_API void WINAPI InitializeCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
tagPROCESSENTRY32W PROCESSENTRY32
static constexpr BOOL TRUE
MINIMAL_WINDOWS_API BOOLEAN WINAPI TryAcquireSRWLockShared(PSRWLOCK SRWLock)
HICON__ * HICON
MINIMAL_WINDOWS_API BOOL WINAPI TryEnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
LONGLONG * LPLONGLONG
MINIMAL_WINDOWS_API BOOL WINAPI InitializeCriticalSectionAndSpinCount(LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount)
FORCEINLINE void WINAPI ReleaseSRWLockShared(SRWLOCK *SRWLock)
FORCEINLINE BOOL WINAPI GetOverlappedResult(HANDLE hFile, OVERLAPPED *lpOverlapped, LPDWORD lpNumberOfBytesTransferred, BOOL bWait)
MINIMAL_WINDOWS_API HMODULE WINAPI LoadLibraryW(LPCTSTR lpFileName)
MINIMAL_WINDOWS_API void WINAPI AcquireSRWLockShared(PSRWLOCK SRWLock)
_LARGE_INTEGER * LPLARGE_INTEGER
_EXCEPTION_POINTERS * LPEXCEPTION_POINTERS
FORCEINLINE void WINAPI AcquireSRWLockExclusive(SRWLOCK *SRWLock)
const void * LPCVOID
HWND__ * HWND
FORCEINLINE BOOL WINAPI QueryPerformanceCounter(LARGE_INTEGER *Cycles)
MINIMAL_WINDOWS_API void WINAPI ReleaseSRWLockShared(PSRWLOCK SRWLock)
MINIMAL_WINDOWS_API BOOL WINAPI WriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped)
DWORD * LPDWORD
RTL_SRWLOCK * PSRWLOCK
_RTL_SRWLOCK RTL_SRWLOCK
MINIMAL_WINDOWS_API BOOLEAN WINAPI TryAcquireSRWLockExclusive(PSRWLOCK SRWLock)
_RTL_CRITICAL_SECTION * LPCRITICAL_SECTION
MINIMAL_WINDOWS_API BOOL WINAPI GetOverlappedResult(HANDLE hFile, LPOVERLAPPED lpOverlapped, LPDWORD lpNumberOfBytesTransferred, BOOL bWait)
FORCEINLINE DWORD WINAPI SetCriticalSectionSpinCount(CRITICAL_SECTION *lpCriticalSection, DWORD dwSpinCount)
MINIMAL_WINDOWS_API void WINAPI ReleaseSRWLockExclusive(PSRWLOCK SRWLock)
unsigned char BYTE
const wchar_t * LPCTSTR
MINIMAL_WINDOWS_API BOOL WINAPI TlsFree(DWORD dwTlsIndex)
HINSTANCE HMODULE
MINIMAL_WINDOWS_API void WINAPI EnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
MINIMAL_WINDOWS_API DWORD WINAPI SetCriticalSectionSpinCount(LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount)
FORCEINLINE BOOL WINAPI TryEnterCriticalSection(CRITICAL_SECTION *lpCriticalSection)
FORCEINLINE BOOL WINAPI ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, OVERLAPPED *lpOverlapped)
MINIMAL_WINDOWS_API BOOL WINAPI IsProcessorFeaturePresent(DWORD ProcessorFeature)
FORCEINLINE void WINAPI InitializeCriticalSection(CRITICAL_SECTION *lpCriticalSection)
FORCEINLINE void WINAPI EnterCriticalSection(CRITICAL_SECTION *lpCriticalSection)
MINIMAL_WINDOWS_API BOOL WINAPI ConnectNamedPipe(HANDLE hNamedPipe, LPOVERLAPPED lpOverlapped)
static constexpr BOOL FALSE
MINIMAL_WINDOWS_API void WINAPI InitializeSRWLock(PSRWLOCK SRWLock)
HICON__ * HCURSOR
_OVERLAPPED * LPOVERLAPPED
HINSTANCE__ * HINSTANCE
MINIMAL_WINDOWS_API DWORD WINAPI TlsAlloc()
HKEY__ * HKEY
FORCEINLINE void WINAPI DeleteCriticalSection(CRITICAL_SECTION *lpCriticalSection)
MINIMAL_WINDOWS_API BOOL WINAPI ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped)
MINIMAL_WINDOWS_API void WINAPI DeleteCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
unsigned long Opaque2[2]