| 1 |
// Copyright (c) Microsoft Corporation. |
| 2 |
// Licensed under the MIT License. |
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
// These #defines prevent the idl-generated headers from trying to include |
| 7 |
// Windows.h from the SDK rather than this one. |
| 8 |
#define RPC_NO_WINDOWS_H |
| 9 |
#define COM_NO_WINDOWS_H |
| 10 |
|
| 11 |
// Allcaps type definitions |
| 12 |
#include <stddef.h> |
| 13 |
#include <stdint.h> |
| 14 |
#include <string.h> |
| 15 |
#include <limits.h> |
| 16 |
|
| 17 |
// Note: using fixed-width here to match Windows widths |
| 18 |
// Specifically this is different for 'long' vs 'LONG' |
| 19 |
typedef uint8_t UINT8; |
| 20 |
typedef int8_t INT8; |
| 21 |
typedef uint16_t UINT16; |
| 22 |
typedef int16_t INT16; |
| 23 |
typedef uint32_t UINT32, UINT, ULONG, DWORD, BOOL; |
| 24 |
typedef int32_t INT32, INT, LONG; |
| 25 |
typedef uint64_t UINT64, ULONG_PTR; |
| 26 |
typedef int64_t INT64, LONG_PTR; |
| 27 |
typedef void VOID, *HANDLE, *RPC_IF_HANDLE, *LPVOID; |
| 28 |
typedef const void *LPCVOID; |
| 29 |
typedef size_t SIZE_T; |
| 30 |
typedef float FLOAT; |
| 31 |
typedef double DOUBLE; |
| 32 |
typedef unsigned char BYTE; |
| 33 |
typedef int HWND; |
| 34 |
typedef int PALETTEENTRY; |
| 35 |
typedef int HDC; |
| 36 |
typedef uint16_t WORD; |
| 37 |
typedef void* PVOID; |
| 38 |
typedef char BOOLEAN; |
| 39 |
typedef uint64_t ULONGLONG; |
| 40 |
typedef uint16_t USHORT, *PUSHORT; |
| 41 |
typedef int64_t LONGLONG, *PLONGLONG; |
| 42 |
typedef int64_t LONG_PTR, *PLONG_PTR; |
| 43 |
typedef int64_t LONG64, *PLONG64; |
| 44 |
typedef uint64_t ULONG64, *PULONG64; |
| 45 |
typedef wchar_t WCHAR, *PWSTR; |
| 46 |
typedef uint8_t UCHAR, *PUCHAR; |
| 47 |
typedef uint64_t ULONG_PTR, *PULONG_PTR; |
| 48 |
typedef uint64_t UINT_PTR, *PUINT_PTR; |
| 49 |
typedef int64_t INT_PTR, *PINT_PTR; |
| 50 |
|
| 51 |
// Note: WCHAR is not the same between Windows and Linux, to enable |
| 52 |
// string manipulation APIs to work with resulting strings. |
| 53 |
// APIs to D3D/DXCore will work on Linux wchars, but beware with |
| 54 |
// interactions directly with the Windows kernel. |
| 55 |
typedef char CHAR, *PSTR, *LPSTR, TCHAR, *PTSTR; |
| 56 |
typedef const char *LPCSTR, *PCSTR, *LPCTSTR, *PCTSTR; |
| 57 |
typedef wchar_t WCHAR, *PWSTR, *LPWSTR, *PWCHAR; |
| 58 |
typedef const wchar_t *LPCWSTR, *PCWSTR; |
| 59 |
|
| 60 |
#undef LONG_MAX |
| 61 |
#define LONG_MAX INT_MAX |
| 62 |
#undef ULONG_MAX |
| 63 |
#define ULONG_MAX UINT_MAX |
| 64 |
|
| 65 |
// Misc defines |
| 66 |
#define interface struct |
| 67 |
#define MIDL_INTERFACE(x) interface |
| 68 |
#define __analysis_assume(x) |
| 69 |
#define TRUE 1u |
| 70 |
#define FALSE 0u |
| 71 |
#define DECLARE_INTERFACE(iface) interface iface |
| 72 |
#define PURE = 0 |
| 73 |
#define THIS_ |
| 74 |
#define DECLSPEC_UUID(x) |
| 75 |
#define DECLSPEC_NOVTABLE |
| 76 |
#define DECLSPEC_SELECTANY |
| 77 |
#define EXTERN_C extern "C" |
| 78 |
#ifdef APIENTRY |
| 79 |
#undef APIENTRY |
| 80 |
#endif |
| 81 |
#define APIENTRY |
| 82 |
#define OUT |
| 83 |
#define IN |
| 84 |
#define CONST const |
| 85 |
#define MAX_PATH 260 |
| 86 |
#define C_ASSERT(expr) static_assert((expr)) |
| 87 |
#define _countof(a) (sizeof(a) / sizeof(*(a))) |
| 88 |
|
| 89 |
typedef struct tagRECTL |
| 90 |
{ |
| 91 |
LONG left; |
| 92 |
LONG top; |
| 93 |
LONG right; |
| 94 |
LONG bottom; |
| 95 |
} RECTL; |
| 96 |
|
| 97 |
typedef struct tagPOINT |
| 98 |
{ |
| 99 |
int x; |
| 100 |
int y; |
| 101 |
} POINT; |
| 102 |
|
| 103 |
typedef struct _GUID { |
| 104 |
uint32_t Data1; |
| 105 |
uint16_t Data2; |
| 106 |
uint16_t Data3; |
| 107 |
uint8_t Data4[ 8 ]; |
| 108 |
} GUID; |
| 109 |
|
| 110 |
#ifdef __cplusplus |
| 111 |
#ifdef INITGUID |
| 112 |
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) extern "C" const GUID name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } |
| 113 |
#else |
| 114 |
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) extern "C" const GUID name |
| 115 |
#endif |
| 116 |
|
| 117 |
template <typename T> GUID uuidof() = delete; |
| 118 |
template <typename T> GUID uuidof(T*) { return uuidof<T>(); } |
| 119 |
template <typename T> GUID uuidof(T**) { return uuidof<T>(); } |
| 120 |
template <typename T> GUID uuidof(T&) { return uuidof<T>(); } |
| 121 |
#define __uuidof(x) uuidof(x) |
| 122 |
#else |
| 123 |
#ifdef INITGUID |
| 124 |
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) const GUID name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } |
| 125 |
#else |
| 126 |
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) extern const GUID name |
| 127 |
#endif |
| 128 |
#endif |
| 129 |
|
| 130 |
typedef GUID IID; |
| 131 |
typedef GUID UUID; |
| 132 |
typedef GUID CLSID; |
| 133 |
#ifdef __cplusplus |
| 134 |
#define REFGUID const GUID & |
| 135 |
#define REFIID const IID & |
| 136 |
#define REFCLSID const IID & |
| 137 |
|
| 138 |
__inline int InlineIsEqualGUID(REFGUID rguid1, REFGUID rguid2) |
| 139 |
{ |
| 140 |
return ( |
| 141 |
((uint32_t *)&rguid1)[0] == ((uint32_t *)&rguid2)[0] && |
| 142 |
((uint32_t *)&rguid1)[1] == ((uint32_t *)&rguid2)[1] && |
| 143 |
((uint32_t *)&rguid1)[2] == ((uint32_t *)&rguid2)[2] && |
| 144 |
((uint32_t *)&rguid1)[3] == ((uint32_t *)&rguid2)[3]); |
| 145 |
} |
| 146 |
#else |
| 147 |
#define REFGUID const GUID * |
| 148 |
#define REFIID const IID * |
| 149 |
#define REFCLSID const IID * |
| 150 |
#endif |
| 151 |
|
| 152 |
// SAL annotations |
| 153 |
#define _In_ |
| 154 |
#define _In_z_ |
| 155 |
#define _In_opt_ |
| 156 |
#define _In_opt_z_ |
| 157 |
#define _In_reads_(x) |
| 158 |
#define _In_reads_opt_(x) |
| 159 |
#define _In_reads_bytes_(x) |
| 160 |
#define _In_reads_bytes_opt_(x) |
| 161 |
#define _In_range_(x, y) |
| 162 |
#define _In_bytecount_(x) |
| 163 |
#define _Out_ |
| 164 |
#define _Out_opt_ |
| 165 |
#define _Outptr_ |
| 166 |
#define _Outptr_opt_result_z_ |
| 167 |
#define _Outptr_opt_result_bytebuffer_(x) |
| 168 |
#define _COM_Outptr_ |
| 169 |
#define _COM_Outptr_result_maybenull_ |
| 170 |
#define _COM_Outptr_opt_ |
| 171 |
#define _COM_Outptr_opt_result_maybenull_ |
| 172 |
#define _Out_writes_(x) |
| 173 |
#define _Out_writes_z_(x) |
| 174 |
#define _Out_writes_opt_(x) |
| 175 |
#define _Out_writes_all_(x) |
| 176 |
#define _Out_writes_all_opt_(x) |
| 177 |
#define _Out_writes_to_opt_(x, y) |
| 178 |
#define _Out_writes_bytes_(x) |
| 179 |
#define _Out_writes_bytes_all_(x) |
| 180 |
#define _Out_writes_bytes_all_opt_(x) |
| 181 |
#define _Out_writes_bytes_opt_(x) |
| 182 |
#define _Inout_ |
| 183 |
#define _Inout_opt_ |
| 184 |
#define _Inout_updates_(x) |
| 185 |
#define _Inout_updates_bytes_(x) |
| 186 |
#define _Field_size_(x) |
| 187 |
#define _Field_size_opt_(x) |
| 188 |
#define _Field_size_bytes_(x) |
| 189 |
#define _Field_size_full_(x) |
| 190 |
#define _Field_size_bytes_full_(x) |
| 191 |
#define _Field_size_bytes_full_opt_(x) |
| 192 |
#define _Field_size_bytes_part_(x, y) |
| 193 |
#define _Field_range_(x, y) |
| 194 |
#define _Field_z_ |
| 195 |
#define _Check_return_ |
| 196 |
#define _IRQL_requires_(x) |
| 197 |
#define _IRQL_requires_min_(x) |
| 198 |
#define _IRQL_requires_max_(x) |
| 199 |
#define _At_(x, y) |
| 200 |
#define _Always_(x) |
| 201 |
#define _Return_type_success_(x) |
| 202 |
#define _Translates_Win32_to_HRESULT_(x) |
| 203 |
#define _Maybenull_ |
| 204 |
#define _Outptr_result_maybenull_ |
| 205 |
#define _Outptr_result_nullonfailure_ |
| 206 |
#define _Analysis_assume_(x) |
| 207 |
#define _Success_(x) |
| 208 |
#define _In_count_(x) |
| 209 |
#define _In_opt_count_(x) |
| 210 |
#define _Use_decl_annotations_ |
| 211 |
|
| 212 |
// Calling conventions |
| 213 |
#define __cdecl |
| 214 |
#define __stdcall |
| 215 |
#define STDMETHODCALLTYPE |
| 216 |
#define STDAPICALLTYPE |
| 217 |
#define STDAPI extern "C" HRESULT STDAPICALLTYPE |
| 218 |
#define WINAPI |
| 219 |
#define STDMETHOD(name) virtual HRESULT name |
| 220 |
#define STDMETHOD_(type,name) virtual type name |
| 221 |
#define IFACEMETHOD(method) /*__override*/ STDMETHOD(method) |
| 222 |
#define IFACEMETHOD_(type, method) /*__override*/ STDMETHOD_(type, method) |
| 223 |
|
| 224 |
// Error codes |
| 225 |
typedef LONG HRESULT; |
| 226 |
#define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0) |
| 227 |
#define FAILED(hr) (((HRESULT)(hr)) < 0) |
| 228 |
#define S_OK ((HRESULT)0L) |
| 229 |
#define S_FALSE ((HRESULT)1L) |
| 230 |
#define E_NOTIMPL ((HRESULT)0x80000001L) |
| 231 |
#define E_OUTOFMEMORY ((HRESULT)0x80000002L) |
| 232 |
#define E_INVALIDARG ((HRESULT)0x80000003L) |
| 233 |
#define E_NOINTERFACE ((HRESULT)0x80000004L) |
| 234 |
#define E_POINTER ((HRESULT)0x80000005L) |
| 235 |
#define E_HANDLE ((HRESULT)0x80000006L) |
| 236 |
#define E_ABORT ((HRESULT)0x80000007L) |
| 237 |
#define E_FAIL ((HRESULT)0x80000008L) |
| 238 |
#define E_ACCESSDENIED ((HRESULT)0x80000009L) |
| 239 |
#define E_UNEXPECTED ((HRESULT)0x8000FFFFL) |
| 240 |
#define DXGI_ERROR_DEVICE_HUNG ((HRESULT)0x887A0006L) |
| 241 |
#define DXGI_ERROR_DEVICE_REMOVED ((HRESULT)0x887A0005L) |
| 242 |
#define DXGI_ERROR_DEVICE_RESET ((HRESULT)0x887A0007L) |
| 243 |
#define DXGI_ERROR_DRIVER_INTERNAL_ERROR ((HRESULT)0x887A0020L) |
| 244 |
#define DXGI_ERROR_INVALID_CALL ((HRESULT)0x887A0001L) |
| 245 |
|
| 246 |
typedef struct _LUID |
| 247 |
{ |
| 248 |
ULONG LowPart; |
| 249 |
LONG HighPart; |
| 250 |
} LUID; |
| 251 |
|
| 252 |
struct RECT |
| 253 |
{ |
| 254 |
int left; |
| 255 |
int top; |
| 256 |
int right; |
| 257 |
int bottom; |
| 258 |
}; |
| 259 |
|
| 260 |
typedef union _LARGE_INTEGER { |
| 261 |
struct { |
| 262 |
uint32_t LowPart; |
| 263 |
uint32_t HighPart; |
| 264 |
} u; |
| 265 |
int64_t QuadPart; |
| 266 |
} LARGE_INTEGER; |
| 267 |
typedef LARGE_INTEGER *PLARGE_INTEGER; |
| 268 |
|
| 269 |
typedef union _ULARGE_INTEGER { |
| 270 |
struct { |
| 271 |
uint32_t LowPart; |
| 272 |
uint32_t HighPart; |
| 273 |
} u; |
| 274 |
uint64_t QuadPart; |
| 275 |
} ULARGE_INTEGER; |
| 276 |
typedef ULARGE_INTEGER *PULARGE_INTEGER; |
| 277 |
|
| 278 |
#define DECLARE_HANDLE(name) \ |
| 279 |
struct name##__ { \ |
| 280 |
int unused; \ |
| 281 |
}; \ |
| 282 |
typedef struct name##__ *name |
| 283 |
|
| 284 |
struct SECURITY_ATTRIBUTES; |
| 285 |
struct STATSTG; |
| 286 |
|
| 287 |
#ifdef __cplusplus |
| 288 |
// ENUM_FLAG_OPERATORS |
| 289 |
// Define operator overloads to enable bit operations on enum values that are |
| 290 |
// used to define flags. Use DEFINE_ENUM_FLAG_OPERATORS(YOUR_TYPE) to enable these |
| 291 |
// operators on YOUR_TYPE. |
| 292 |
extern "C++" { |
| 293 |
template <size_t S> |
| 294 |
struct _ENUM_FLAG_INTEGER_FOR_SIZE; |
| 295 |
|
| 296 |
template <> |
| 297 |
struct _ENUM_FLAG_INTEGER_FOR_SIZE<1> |
| 298 |
{ |
| 299 |
typedef int8_t type; |
| 300 |
}; |
| 301 |
|
| 302 |
template <> |
| 303 |
struct _ENUM_FLAG_INTEGER_FOR_SIZE<2> |
| 304 |
{ |
| 305 |
typedef int16_t type; |
| 306 |
}; |
| 307 |
|
| 308 |
template <> |
| 309 |
struct _ENUM_FLAG_INTEGER_FOR_SIZE<4> |
| 310 |
{ |
| 311 |
typedef int32_t type; |
| 312 |
}; |
| 313 |
|
| 314 |
template <> |
| 315 |
struct _ENUM_FLAG_INTEGER_FOR_SIZE<8> |
| 316 |
{ |
| 317 |
typedef int64_t type; |
| 318 |
}; |
| 319 |
|
| 320 |
// used as an approximation of std::underlying_type<T> |
| 321 |
template <class T> |
| 322 |
struct _ENUM_FLAG_SIZED_INTEGER |
| 323 |
{ |
| 324 |
typedef typename _ENUM_FLAG_INTEGER_FOR_SIZE<sizeof(T)>::type type; |
| 325 |
}; |
| 326 |
|
| 327 |
} |
| 328 |
#define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) \ |
| 329 |
extern "C++" { \ |
| 330 |
inline constexpr ENUMTYPE operator | (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a) | ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \ |
| 331 |
inline ENUMTYPE &operator |= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type &)a) |= ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \ |
| 332 |
inline constexpr ENUMTYPE operator & (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a) & ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \ |
| 333 |
inline ENUMTYPE &operator &= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type &)a) &= ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \ |
| 334 |
inline constexpr ENUMTYPE operator ~ (ENUMTYPE a) { return ENUMTYPE(~((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a)); } \ |
| 335 |
inline constexpr ENUMTYPE operator ^ (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a) ^ ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \ |
| 336 |
inline ENUMTYPE &operator ^= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type &)a) ^= ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \ |
| 337 |
} |
| 338 |
#endif |
| 339 |
|
| 340 |
// D3DX12 uses these |
| 341 |
#include <stdlib.h> |
| 342 |
#define HeapAlloc(heap, flags, size) malloc(size) |
| 343 |
#define HeapFree(heap, flags, ptr) free(ptr) |
| 344 |
|
| 345 |
#ifdef __cplusplus |
| 346 |
// IUnknown |
| 347 |
|
| 348 |
interface DECLSPEC_UUID("00000000-0000-0000-C000-000000000046") DECLSPEC_NOVTABLE IUnknown |
| 349 |
{ |
| 350 |
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) = 0; |
| 351 |
virtual ULONG STDMETHODCALLTYPE AddRef() = 0; |
| 352 |
virtual ULONG STDMETHODCALLTYPE Release() = 0; |
| 353 |
|
| 354 |
template <class Q> HRESULT STDMETHODCALLTYPE QueryInterface(Q** pp) { |
| 355 |
return QueryInterface(uuidof<Q>(), (void **)pp); |
| 356 |
} |
| 357 |
}; |
| 358 |
|
| 359 |
template <> constexpr GUID uuidof<IUnknown>() |
| 360 |
{ |
| 361 |
return { 0x00000000, 0x0000, 0x0000, { 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } }; |
| 362 |
} |
| 363 |
|
| 364 |
extern "C++" |
| 365 |
{ |
| 366 |
template<typename T> void** IID_PPV_ARGS_Helper(T** pp) |
| 367 |
{ |
| 368 |
static_cast<IUnknown*>(*pp); |
| 369 |
return reinterpret_cast<void**>(pp); |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
#define IID_PPV_ARGS(ppType) __uuidof(**(ppType)), IID_PPV_ARGS_Helper(ppType) |
| 374 |
#endif |
| 375 |
|
| 376 |
#if defined(lint) |
| 377 |
// Note: lint -e530 says don't complain about uninitialized variables for |
| 378 |
// this variable. Error 527 has to do with unreachable code. |
| 379 |
// -restore restores checking to the -save state |
| 380 |
#define UNREFERENCED_PARAMETER(P) \ |
| 381 |
/*lint -save -e527 -e530 */ \ |
| 382 |
{ \ |
| 383 |
(P) = (P); \ |
| 384 |
} \ |
| 385 |
/*lint -restore */ |
| 386 |
#else |
| 387 |
#define UNREFERENCED_PARAMETER(P) (P) |
| 388 |
#endif |