basetsd.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. // Copyright (c) Microsoft Corporation.
  2. // Licensed under the MIT License.
  3. #pragma once
  4. // These #defines prevent the idl-generated headers from trying to include
  5. // Windows.h from the SDK rather than this one.
  6. #define RPC_NO_WINDOWS_H
  7. #define COM_NO_WINDOWS_H
  8. // Allcaps type definitions
  9. #include <stddef.h>
  10. #include <stdint.h>
  11. #include <string.h>
  12. #include <limits.h>
  13. #include <sal.h>
  14. #if !defined(LLVM_SUPPORT_WIN_ADAPTER_H)
  15. // Note: using fixed-width here to match Windows widths
  16. // Specifically this is different for 'long' vs 'LONG'
  17. typedef uint8_t UINT8;
  18. typedef int8_t INT8;
  19. typedef uint16_t UINT16;
  20. typedef int16_t INT16;
  21. typedef uint32_t UINT32, UINT, ULONG, DWORD, BOOL, WINBOOL;
  22. typedef int32_t INT32, INT, LONG;
  23. typedef uint64_t UINT64, ULONG_PTR;
  24. typedef int64_t INT64, LONG_PTR;
  25. typedef void VOID, *HANDLE, *RPC_IF_HANDLE, *LPVOID;
  26. typedef const void *LPCVOID;
  27. typedef size_t SIZE_T;
  28. typedef float FLOAT;
  29. typedef double DOUBLE;
  30. typedef unsigned char BYTE;
  31. typedef HANDLE HWND;
  32. typedef HANDLE HMODULE;
  33. typedef size_t SIZE;
  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 int16_t SHORT, *PSHORT;
  41. typedef uint16_t USHORT, *PUSHORT;
  42. typedef int64_t LONGLONG, *PLONGLONG;
  43. typedef int64_t LONG_PTR, *PLONG_PTR;
  44. typedef int64_t LONG64, *PLONG64;
  45. typedef uint64_t ULONG64, *PULONG64;
  46. typedef wchar_t WCHAR, *PWSTR;
  47. typedef uint8_t UCHAR, *PUCHAR;
  48. typedef uint64_t ULONG_PTR, *PULONG_PTR;
  49. typedef uint64_t UINT_PTR, *PUINT_PTR;
  50. typedef int64_t INT_PTR, *PINT_PTR;
  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. #endif // !defined(LLVM_SUPPORT_WIN_ADAPTER_H)
  60. #undef LONG_MAX
  61. #define LONG_MAX INT_MAX
  62. #undef ULONG_MAX
  63. #define ULONG_MAX UINT_MAX
  64. // Misc defines
  65. #define MIDL_INTERFACE(x) interface
  66. #define __analysis_assume(x)
  67. #define TRUE 1u
  68. #define FALSE 0u
  69. #define DECLSPEC_UUID(x)
  70. #define DECLSPEC_NOVTABLE
  71. #define DECLSPEC_SELECTANY
  72. #ifdef __cplusplus
  73. #define EXTERN_C extern "C"
  74. #else
  75. #define EXTERN_C extern
  76. #endif
  77. #define APIENTRY
  78. #define OUT
  79. #define IN
  80. #define CONST const
  81. #define MAX_PATH 260
  82. #define GENERIC_ALL 0x10000000L
  83. #define C_ASSERT(expr) static_assert((expr))
  84. #define _countof(a) (sizeof(a) / sizeof(*(a)))
  85. typedef struct tagRECTL
  86. {
  87. LONG left;
  88. LONG top;
  89. LONG right;
  90. LONG bottom;
  91. } RECTL;
  92. typedef struct tagPOINT
  93. {
  94. int x;
  95. int y;
  96. } POINT;
  97. #if !defined(LLVM_SUPPORT_WIN_ADAPTER_H)
  98. typedef struct _GUID {
  99. uint32_t Data1;
  100. uint16_t Data2;
  101. uint16_t Data3;
  102. uint8_t Data4[ 8 ];
  103. } GUID;
  104. #ifdef INITGUID
  105. #ifdef __cplusplus
  106. #define DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) EXTERN_C const GUID DECLSPEC_SELECTANY name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
  107. #else
  108. #define DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) const GUID DECLSPEC_SELECTANY name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
  109. #endif
  110. #else
  111. #define DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) EXTERN_C const GUID name
  112. #endif
  113. typedef GUID IID;
  114. typedef GUID UUID;
  115. typedef GUID CLSID;
  116. #ifdef __cplusplus
  117. #define REFGUID const GUID &
  118. #define REFIID const IID &
  119. #define REFCLSID const IID &
  120. __inline int InlineIsEqualGUID(REFGUID rguid1, REFGUID rguid2)
  121. {
  122. return (
  123. ((uint32_t *)&rguid1)[0] == ((uint32_t *)&rguid2)[0] &&
  124. ((uint32_t *)&rguid1)[1] == ((uint32_t *)&rguid2)[1] &&
  125. ((uint32_t *)&rguid1)[2] == ((uint32_t *)&rguid2)[2] &&
  126. ((uint32_t *)&rguid1)[3] == ((uint32_t *)&rguid2)[3]);
  127. }
  128. inline bool operator==(REFGUID guidOne, REFGUID guidOther)
  129. {
  130. return !!InlineIsEqualGUID(guidOne, guidOther);
  131. }
  132. inline bool operator!=(REFGUID guidOne, REFGUID guidOther)
  133. {
  134. return !(guidOne == guidOther);
  135. }
  136. #else
  137. #define REFGUID const GUID *
  138. #define REFIID const IID *
  139. #define REFCLSID const IID *
  140. #endif
  141. #endif // !defined(LLVM_SUPPORT_WIN_ADAPTER_H)
  142. // Calling conventions
  143. #define __cdecl
  144. #define __stdcall
  145. #define STDMETHODCALLTYPE
  146. #define STDAPICALLTYPE
  147. #define STDAPI EXTERN_C HRESULT STDAPICALLTYPE
  148. #define WINAPI
  149. #define interface struct
  150. #if defined (__cplusplus) && !defined (CINTERFACE)
  151. #define STDMETHOD(method) virtual HRESULT STDMETHODCALLTYPE method
  152. #define STDMETHOD_(type, method) virtual type STDMETHODCALLTYPE method
  153. #define PURE = 0
  154. #define THIS_
  155. #define THIS void
  156. #define DECLARE_INTERFACE(iface) interface DECLSPEC_NOVTABLE iface
  157. #define DECLARE_INTERFACE_(iface, baseiface) interface DECLSPEC_NOVTABLE iface : public baseiface
  158. interface IUnknown;
  159. extern "C++"
  160. {
  161. template<typename T> void** IID_PPV_ARGS_Helper(T** pp)
  162. {
  163. (void)static_cast<IUnknown*>(*pp);
  164. return reinterpret_cast<void**>(pp);
  165. }
  166. }
  167. #define IID_PPV_ARGS(ppType) __uuidof (**(ppType)), IID_PPV_ARGS_Helper (ppType)
  168. #else
  169. #define STDMETHOD(method) HRESULT (STDMETHODCALLTYPE *method)
  170. #define STDMETHOD_(type, method) type (STDMETHODCALLTYPE *method)
  171. #define PURE
  172. #define THIS_ INTERFACE *This,
  173. #define THIS INTERFACE *This
  174. #ifdef CONST_VTABLE
  175. #define DECLARE_INTERFACE(iface) typedef interface iface { const struct iface##Vtbl *lpVtbl; } iface; typedef const struct iface##Vtbl iface##Vtbl; const struct iface##Vtbl
  176. #else
  177. #define DECLARE_INTERFACE(iface) typedef interface iface { struct iface##Vtbl *lpVtbl; } iface; typedef struct iface##Vtbl iface##Vtbl; struct iface##Vtbl
  178. #endif
  179. #define DECLARE_INTERFACE_(iface, baseiface) DECLARE_INTERFACE (iface)
  180. #endif
  181. #define IFACEMETHOD(method) /*override*/ STDMETHOD (method)
  182. #define IFACEMETHOD_(type, method) /*override*/ STDMETHOD_(type, method)
  183. #ifndef BEGIN_INTERFACE
  184. #define BEGIN_INTERFACE
  185. #define END_INTERFACE
  186. #endif
  187. #if !defined(LLVM_SUPPORT_WIN_ADAPTER_H)
  188. // Error codes
  189. typedef LONG HRESULT;
  190. #define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0)
  191. #define FAILED(hr) (((HRESULT)(hr)) < 0)
  192. #define S_OK ((HRESULT)0L)
  193. #define S_FALSE ((HRESULT)1L)
  194. #define E_NOTIMPL ((HRESULT)0x80004001L)
  195. #define E_OUTOFMEMORY ((HRESULT)0x8007000EL)
  196. #define E_INVALIDARG ((HRESULT)0x80070057L)
  197. #define E_NOINTERFACE ((HRESULT)0x80004002L)
  198. #define E_POINTER ((HRESULT)0x80004003L)
  199. #define E_HANDLE ((HRESULT)0x80070006L)
  200. #define E_ABORT ((HRESULT)0x80004004L)
  201. #define E_FAIL ((HRESULT)0x80004005L)
  202. #define E_ACCESSDENIED ((HRESULT)0x80070005L)
  203. #define E_UNEXPECTED ((HRESULT)0x8000FFFFL)
  204. #define DXGI_ERROR_INVALID_CALL ((HRESULT)0x887A0001L)
  205. #define DXGI_ERROR_NOT_FOUND ((HRESULT)0x887A0002L)
  206. #define DXGI_ERROR_MORE_DATA ((HRESULT)0x887A0003L)
  207. #define DXGI_ERROR_UNSUPPORTED ((HRESULT)0x887A0004L)
  208. #define DXGI_ERROR_DEVICE_REMOVED ((HRESULT)0x887A0005L)
  209. #define DXGI_ERROR_DEVICE_HUNG ((HRESULT)0x887A0006L)
  210. #define DXGI_ERROR_DEVICE_RESET ((HRESULT)0x887A0007L)
  211. #define DXGI_ERROR_DRIVER_INTERNAL_ERROR ((HRESULT)0x887A0020L)
  212. #endif // !defined(LLVM_SUPPORT_WIN_ADAPTER_H)
  213. typedef struct _LUID
  214. {
  215. ULONG LowPart;
  216. LONG HighPart;
  217. } LUID;
  218. typedef struct _RECT
  219. {
  220. int left;
  221. int top;
  222. int right;
  223. int bottom;
  224. } RECT;
  225. #if !defined(LLVM_SUPPORT_WIN_ADAPTER_H)
  226. typedef union _LARGE_INTEGER {
  227. struct {
  228. uint32_t LowPart;
  229. uint32_t HighPart;
  230. } u;
  231. int64_t QuadPart;
  232. } LARGE_INTEGER;
  233. typedef LARGE_INTEGER *PLARGE_INTEGER;
  234. typedef union _ULARGE_INTEGER {
  235. struct {
  236. uint32_t LowPart;
  237. uint32_t HighPart;
  238. } u;
  239. uint64_t QuadPart;
  240. } ULARGE_INTEGER;
  241. typedef ULARGE_INTEGER *PULARGE_INTEGER;
  242. #define DECLARE_HANDLE(name) \
  243. struct name##__ { \
  244. int unused; \
  245. }; \
  246. typedef struct name##__ *name
  247. typedef struct _SECURITY_ATTRIBUTES {
  248. DWORD nLength;
  249. LPVOID lpSecurityDescriptor;
  250. WINBOOL bInheritHandle;
  251. } SECURITY_ATTRIBUTES;
  252. struct STATSTG;
  253. #endif // !defined(LLVM_SUPPORT_WIN_ADAPTER_H)
  254. #ifdef __cplusplus
  255. // ENUM_FLAG_OPERATORS
  256. // Define operator overloads to enable bit operations on enum values that are
  257. // used to define flags. Use DEFINE_ENUM_FLAG_OPERATORS(YOUR_TYPE) to enable these
  258. // operators on YOUR_TYPE.
  259. extern "C++" {
  260. template <size_t S>
  261. struct _ENUM_FLAG_INTEGER_FOR_SIZE;
  262. template <>
  263. struct _ENUM_FLAG_INTEGER_FOR_SIZE<1>
  264. {
  265. typedef int8_t type;
  266. };
  267. template <>
  268. struct _ENUM_FLAG_INTEGER_FOR_SIZE<2>
  269. {
  270. typedef int16_t type;
  271. };
  272. template <>
  273. struct _ENUM_FLAG_INTEGER_FOR_SIZE<4>
  274. {
  275. typedef int32_t type;
  276. };
  277. template <>
  278. struct _ENUM_FLAG_INTEGER_FOR_SIZE<8>
  279. {
  280. typedef int64_t type;
  281. };
  282. // used as an approximation of std::underlying_type<T>
  283. template <class T>
  284. struct _ENUM_FLAG_SIZED_INTEGER
  285. {
  286. typedef typename _ENUM_FLAG_INTEGER_FOR_SIZE<sizeof(T)>::type type;
  287. };
  288. }
  289. #define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) \
  290. extern "C++" { \
  291. inline constexpr ENUMTYPE operator | (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a) | ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
  292. inline ENUMTYPE &operator |= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type &)a) |= ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
  293. inline constexpr ENUMTYPE operator & (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a) & ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
  294. inline ENUMTYPE &operator &= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type &)a) &= ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
  295. inline constexpr ENUMTYPE operator ~ (ENUMTYPE a) { return ENUMTYPE(~((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a)); } \
  296. inline constexpr ENUMTYPE operator ^ (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a) ^ ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
  297. inline ENUMTYPE &operator ^= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type &)a) ^= ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
  298. }
  299. #else
  300. #define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) /* */
  301. #endif
  302. // D3DX12 uses these
  303. #include <stdlib.h>
  304. #define HeapAlloc(heap, flags, size) malloc(size)
  305. #define HeapFree(heap, flags, ptr) free(ptr)
  306. #if defined(lint)
  307. // Note: lint -e530 says don't complain about uninitialized variables for
  308. // this variable. Error 527 has to do with unreachable code.
  309. // -restore restores checking to the -save state
  310. #define UNREFERENCED_PARAMETER(P) \
  311. /*lint -save -e527 -e530 */ \
  312. { \
  313. (P) = (P); \
  314. } \
  315. /*lint -restore */
  316. #else
  317. #define UNREFERENCED_PARAMETER(P) (P)
  318. #endif