aboutsummaryrefslogtreecommitdiff
path: root/contrib/DirectX-Headers-1.618.2/include/wsl
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2025-12-02 16:39:36 -0800
committer3gg <3gg@shellblade.net>2025-12-02 16:39:36 -0800
commit6c8ae19be66cee247980a48e736a4e05d14de179 (patch)
treed860767907bf0cbe17ec66422e11bea700cf56d9 /contrib/DirectX-Headers-1.618.2/include/wsl
parent8f594c8ebd11f0e5f8a0c6369c3fe7383d250cbe (diff)
Immediate-mode renderer, triangle demo, shader compilation in cmake, Agility SDKHEADmain
Diffstat (limited to 'contrib/DirectX-Headers-1.618.2/include/wsl')
-rw-r--r--contrib/DirectX-Headers-1.618.2/include/wsl/stubs/basetsd.h406
-rw-r--r--contrib/DirectX-Headers-1.618.2/include/wsl/stubs/oaidl.h5
-rw-r--r--contrib/DirectX-Headers-1.618.2/include/wsl/stubs/ocidl.h5
-rw-r--r--contrib/DirectX-Headers-1.618.2/include/wsl/stubs/rpc.h5
-rw-r--r--contrib/DirectX-Headers-1.618.2/include/wsl/stubs/rpcndr.h78
-rw-r--r--contrib/DirectX-Headers-1.618.2/include/wsl/stubs/unknwn.h3
-rw-r--r--contrib/DirectX-Headers-1.618.2/include/wsl/stubs/unknwnbase.h124
-rw-r--r--contrib/DirectX-Headers-1.618.2/include/wsl/stubs/winapifamily.h6
-rw-r--r--contrib/DirectX-Headers-1.618.2/include/wsl/stubs/wrl/client.h6
-rw-r--r--contrib/DirectX-Headers-1.618.2/include/wsl/stubs/wrl/implements.h6
-rw-r--r--contrib/DirectX-Headers-1.618.2/include/wsl/winadapter.h6
-rw-r--r--contrib/DirectX-Headers-1.618.2/include/wsl/wrladapter.h803
12 files changed, 1453 insertions, 0 deletions
diff --git a/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/basetsd.h b/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/basetsd.h
new file mode 100644
index 0000000..4c75ef2
--- /dev/null
+++ b/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/basetsd.h
@@ -0,0 +1,406 @@
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'
19typedef uint8_t UINT8;
20typedef int8_t INT8;
21typedef uint16_t UINT16;
22typedef int16_t INT16;
23typedef uint32_t UINT32, UINT, ULONG, DWORD, BOOL, WINBOOL;
24typedef int32_t INT32, INT, LONG;
25typedef uint64_t UINT64, ULONG_PTR;
26typedef int64_t INT64, LONG_PTR;
27typedef void VOID, *HANDLE, *RPC_IF_HANDLE, *LPVOID;
28typedef const void *LPCVOID;
29typedef size_t SIZE_T;
30typedef float FLOAT;
31typedef double DOUBLE;
32typedef unsigned char BYTE;
33typedef int HWND;
34typedef int PALETTEENTRY;
35typedef int HDC;
36typedef uint16_t WORD;
37typedef void* PVOID;
38typedef char BOOLEAN;
39typedef uint64_t ULONGLONG;
40typedef uint16_t USHORT, *PUSHORT;
41typedef int64_t LONGLONG, *PLONGLONG;
42typedef int64_t LONG_PTR, *PLONG_PTR;
43typedef int64_t LONG64, *PLONG64;
44typedef uint64_t ULONG64, *PULONG64;
45typedef wchar_t WCHAR, *PWSTR;
46typedef uint8_t UCHAR, *PUCHAR;
47typedef uint64_t ULONG_PTR, *PULONG_PTR;
48typedef uint64_t UINT_PTR, *PUINT_PTR;
49typedef 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.
55typedef char CHAR, *PSTR, *LPSTR, TCHAR, *PTSTR;
56typedef const char *LPCSTR, *PCSTR, *LPCTSTR, *PCTSTR;
57typedef wchar_t WCHAR, *PWSTR, *LPWSTR, *PWCHAR;
58typedef 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 MIDL_INTERFACE(x) interface
67#define __analysis_assume(x)
68#define TRUE 1u
69#define FALSE 0u
70#define DECLSPEC_UUID(x)
71#define DECLSPEC_NOVTABLE
72#define DECLSPEC_SELECTANY
73#ifdef __cplusplus
74#define EXTERN_C extern "C"
75#else
76#define EXTERN_C extern
77#endif
78#define APIENTRY
79#define OUT
80#define IN
81#define CONST const
82#define MAX_PATH 260
83#define GENERIC_ALL 0x10000000L
84#define C_ASSERT(expr) static_assert((expr))
85#define _countof(a) (sizeof(a) / sizeof(*(a)))
86
87typedef struct tagRECTL
88{
89 LONG left;
90 LONG top;
91 LONG right;
92 LONG bottom;
93} RECTL;
94
95typedef struct tagPOINT
96{
97 int x;
98 int y;
99} POINT;
100
101typedef struct _GUID {
102 uint32_t Data1;
103 uint16_t Data2;
104 uint16_t Data3;
105 uint8_t Data4[ 8 ];
106} GUID;
107
108#ifdef INITGUID
109#ifdef __cplusplus
110#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 } }
111#else
112#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 } }
113#endif
114#else
115#define DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) EXTERN_C const GUID name
116#endif
117
118typedef GUID IID;
119typedef GUID UUID;
120typedef GUID CLSID;
121#ifdef __cplusplus
122#define REFGUID const GUID &
123#define REFIID const IID &
124#define REFCLSID const IID &
125
126__inline int InlineIsEqualGUID(REFGUID rguid1, REFGUID rguid2)
127{
128 return (
129 ((uint32_t *)&rguid1)[0] == ((uint32_t *)&rguid2)[0] &&
130 ((uint32_t *)&rguid1)[1] == ((uint32_t *)&rguid2)[1] &&
131 ((uint32_t *)&rguid1)[2] == ((uint32_t *)&rguid2)[2] &&
132 ((uint32_t *)&rguid1)[3] == ((uint32_t *)&rguid2)[3]);
133}
134
135inline bool operator==(REFGUID guidOne, REFGUID guidOther)
136{
137 return !!InlineIsEqualGUID(guidOne, guidOther);
138}
139
140inline bool operator!=(REFGUID guidOne, REFGUID guidOther)
141{
142 return !(guidOne == guidOther);
143}
144
145#else
146#define REFGUID const GUID *
147#define REFIID const IID *
148#define REFCLSID const IID *
149#endif
150
151// SAL annotations
152#define _In_
153#define _In_z_
154#define _In_opt_
155#define _In_opt_z_
156#define _In_reads_(x)
157#define _In_reads_opt_(x)
158#define _In_reads_bytes_(x)
159#define _In_reads_bytes_opt_(x)
160#define _In_range_(x, y)
161#define _In_bytecount_(x)
162#define _Out_
163#define _Out_opt_
164#define _Outptr_
165#define _Outptr_opt_result_z_
166#define _Outptr_opt_result_bytebuffer_(x)
167#define _COM_Outptr_
168#define _COM_Outptr_result_maybenull_
169#define _COM_Outptr_opt_
170#define _COM_Outptr_opt_result_maybenull_
171#define _Out_writes_(x)
172#define _Out_writes_z_(x)
173#define _Out_writes_opt_(x)
174#define _Out_writes_all_(x)
175#define _Out_writes_all_opt_(x)
176#define _Out_writes_to_opt_(x, y)
177#define _Out_writes_bytes_(x)
178#define _Out_writes_bytes_all_(x)
179#define _Out_writes_bytes_all_opt_(x)
180#define _Out_writes_bytes_opt_(x)
181#define _Inout_
182#define _Inout_opt_
183#define _Inout_updates_(x)
184#define _Inout_updates_bytes_(x)
185#define _Field_size_(x)
186#define _Field_size_opt_(x)
187#define _Field_size_bytes_(x)
188#define _Field_size_full_(x)
189#define _Field_size_full_opt_(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#define _Null_terminated_
212
213// Calling conventions
214#define __cdecl
215#define __stdcall
216#define STDMETHODCALLTYPE
217#define STDAPICALLTYPE
218#define STDAPI EXTERN_C HRESULT STDAPICALLTYPE
219#define WINAPI
220
221#define interface struct
222#if defined (__cplusplus) && !defined (CINTERFACE)
223#define STDMETHOD(method) virtual HRESULT STDMETHODCALLTYPE method
224#define STDMETHOD_(type, method) virtual type STDMETHODCALLTYPE method
225#define PURE = 0
226#define THIS_
227#define THIS void
228#define DECLARE_INTERFACE(iface) interface DECLSPEC_NOVTABLE iface
229#define DECLARE_INTERFACE_(iface, baseiface) interface DECLSPEC_NOVTABLE iface : public baseiface
230
231interface IUnknown;
232extern "C++"
233{
234 template<typename T> void** IID_PPV_ARGS_Helper(T** pp)
235 {
236 (void)static_cast<IUnknown*>(*pp);
237 return reinterpret_cast<void**>(pp);
238 }
239}
240#define IID_PPV_ARGS(ppType) __uuidof (**(ppType)), IID_PPV_ARGS_Helper (ppType)
241#else
242#define STDMETHOD(method) HRESULT (STDMETHODCALLTYPE *method)
243#define STDMETHOD_(type, method) type (STDMETHODCALLTYPE *method)
244#define PURE
245#define THIS_ INTERFACE *This,
246#define THIS INTERFACE *This
247#ifdef CONST_VTABLE
248#define DECLARE_INTERFACE(iface) typedef interface iface { const struct iface##Vtbl *lpVtbl; } iface; typedef const struct iface##Vtbl iface##Vtbl; const struct iface##Vtbl
249#else
250#define DECLARE_INTERFACE(iface) typedef interface iface { struct iface##Vtbl *lpVtbl; } iface; typedef struct iface##Vtbl iface##Vtbl; struct iface##Vtbl
251#endif
252#define DECLARE_INTERFACE_(iface, baseiface) DECLARE_INTERFACE (iface)
253#endif
254
255#define IFACEMETHOD(method) /*override*/ STDMETHOD (method)
256#define IFACEMETHOD_(type, method) /*override*/ STDMETHOD_(type, method)
257#ifndef BEGIN_INTERFACE
258#define BEGIN_INTERFACE
259#define END_INTERFACE
260#endif
261
262// Error codes
263typedef LONG HRESULT;
264#define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0)
265#define FAILED(hr) (((HRESULT)(hr)) < 0)
266#define S_OK ((HRESULT)0L)
267#define S_FALSE ((HRESULT)1L)
268#define E_NOTIMPL ((HRESULT)0x80004001L)
269#define E_OUTOFMEMORY ((HRESULT)0x8007000EL)
270#define E_INVALIDARG ((HRESULT)0x80070057L)
271#define E_NOINTERFACE ((HRESULT)0x80004002L)
272#define E_POINTER ((HRESULT)0x80004003L)
273#define E_HANDLE ((HRESULT)0x80070006L)
274#define E_ABORT ((HRESULT)0x80004004L)
275#define E_FAIL ((HRESULT)0x80004005L)
276#define E_ACCESSDENIED ((HRESULT)0x80070005L)
277#define E_UNEXPECTED ((HRESULT)0x8000FFFFL)
278#define DXGI_ERROR_INVALID_CALL ((HRESULT)0x887A0001L)
279#define DXGI_ERROR_NOT_FOUND ((HRESULT)0x887A0002L)
280#define DXGI_ERROR_MORE_DATA ((HRESULT)0x887A0003L)
281#define DXGI_ERROR_UNSUPPORTED ((HRESULT)0x887A0004L)
282#define DXGI_ERROR_DEVICE_REMOVED ((HRESULT)0x887A0005L)
283#define DXGI_ERROR_DEVICE_HUNG ((HRESULT)0x887A0006L)
284#define DXGI_ERROR_DEVICE_RESET ((HRESULT)0x887A0007L)
285#define DXGI_ERROR_DRIVER_INTERNAL_ERROR ((HRESULT)0x887A0020L)
286#define DXGI_ERROR_SDK_COMPONENT_MISSING ((HRESULT)0x887A002DL)
287
288typedef struct _LUID
289{
290 ULONG LowPart;
291 LONG HighPart;
292} LUID;
293
294typedef struct _RECT
295{
296 int left;
297 int top;
298 int right;
299 int bottom;
300} RECT;
301
302typedef union _LARGE_INTEGER {
303 struct {
304 uint32_t LowPart;
305 uint32_t HighPart;
306 } u;
307 int64_t QuadPart;
308} LARGE_INTEGER;
309typedef LARGE_INTEGER *PLARGE_INTEGER;
310
311typedef union _ULARGE_INTEGER {
312 struct {
313 uint32_t LowPart;
314 uint32_t HighPart;
315 } u;
316 uint64_t QuadPart;
317} ULARGE_INTEGER;
318typedef ULARGE_INTEGER *PULARGE_INTEGER;
319
320#define DECLARE_HANDLE(name) \
321 struct name##__ { \
322 int unused; \
323 }; \
324 typedef struct name##__ *name
325
326typedef struct _SECURITY_ATTRIBUTES {
327 DWORD nLength;
328 LPVOID lpSecurityDescriptor;
329 WINBOOL bInheritHandle;
330} SECURITY_ATTRIBUTES;
331
332struct STATSTG;
333
334#ifdef __cplusplus
335// ENUM_FLAG_OPERATORS
336// Define operator overloads to enable bit operations on enum values that are
337// used to define flags. Use DEFINE_ENUM_FLAG_OPERATORS(YOUR_TYPE) to enable these
338// operators on YOUR_TYPE.
339extern "C++" {
340 template <size_t S>
341 struct _ENUM_FLAG_INTEGER_FOR_SIZE;
342
343 template <>
344 struct _ENUM_FLAG_INTEGER_FOR_SIZE<1>
345 {
346 typedef int8_t type;
347 };
348
349 template <>
350 struct _ENUM_FLAG_INTEGER_FOR_SIZE<2>
351 {
352 typedef int16_t type;
353 };
354
355 template <>
356 struct _ENUM_FLAG_INTEGER_FOR_SIZE<4>
357 {
358 typedef int32_t type;
359 };
360
361 template <>
362 struct _ENUM_FLAG_INTEGER_FOR_SIZE<8>
363 {
364 typedef int64_t type;
365 };
366
367 // used as an approximation of std::underlying_type<T>
368 template <class T>
369 struct _ENUM_FLAG_SIZED_INTEGER
370 {
371 typedef typename _ENUM_FLAG_INTEGER_FOR_SIZE<sizeof(T)>::type type;
372 };
373
374}
375#define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) \
376extern "C++" { \
377inline constexpr ENUMTYPE operator | (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a) | ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
378inline ENUMTYPE &operator |= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type &)a) |= ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
379inline constexpr ENUMTYPE operator & (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a) & ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
380inline ENUMTYPE &operator &= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type &)a) &= ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
381inline constexpr ENUMTYPE operator ~ (ENUMTYPE a) { return ENUMTYPE(~((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a)); } \
382inline constexpr ENUMTYPE operator ^ (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a) ^ ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
383inline ENUMTYPE &operator ^= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type &)a) ^= ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
384}
385#else
386#define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) /* */
387#endif
388
389// D3DX12 uses these
390#include <stdlib.h>
391#define HeapAlloc(heap, flags, size) malloc(size)
392#define HeapFree(heap, flags, ptr) free(ptr)
393
394#if defined(lint)
395// Note: lint -e530 says don't complain about uninitialized variables for
396// this variable. Error 527 has to do with unreachable code.
397// -restore restores checking to the -save state
398#define UNREFERENCED_PARAMETER(P) \
399 /*lint -save -e527 -e530 */ \
400 { \
401 (P) = (P); \
402 } \
403 /*lint -restore */
404#else
405#define UNREFERENCED_PARAMETER(P) (P)
406#endif
diff --git a/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/oaidl.h b/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/oaidl.h
new file mode 100644
index 0000000..76f5b5f
--- /dev/null
+++ b/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/oaidl.h
@@ -0,0 +1,5 @@
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4// Stub header to satisfy d3d12.h include
5#pragma once \ No newline at end of file
diff --git a/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/ocidl.h b/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/ocidl.h
new file mode 100644
index 0000000..76f5b5f
--- /dev/null
+++ b/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/ocidl.h
@@ -0,0 +1,5 @@
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4// Stub header to satisfy d3d12.h include
5#pragma once \ No newline at end of file
diff --git a/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/rpc.h b/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/rpc.h
new file mode 100644
index 0000000..76f5b5f
--- /dev/null
+++ b/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/rpc.h
@@ -0,0 +1,5 @@
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4// Stub header to satisfy d3d12.h include
5#pragma once \ No newline at end of file
diff --git a/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/rpcndr.h b/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/rpcndr.h
new file mode 100644
index 0000000..68aa390
--- /dev/null
+++ b/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/rpcndr.h
@@ -0,0 +1,78 @@
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4// Stub header to satisfy d3d12.h include
5#pragma once
6
7#include "basetsd.h"
8
9#define __RPCNDR_H_VERSION__
10
11#ifdef CONST_VTABLE
12#define CONST_VTBL const
13#else
14#define CONST_VTBL
15#endif
16
17/* Macros for __uuidof template-based emulation */
18#if defined(__cplusplus)
19#if __cpp_constexpr >= 200704l && __cpp_inline_variables >= 201606L
20#define __wsl_stub_uuidof_use_constexpr 1
21#else
22#define __wsl_stub_uuidof_use_constexpr 0
23#endif
24#ifndef __GNUC__
25#error "Only support for compilers that support for `GNU C++ extension`"
26#endif
27extern "C++" {
28#if __wsl_stub_uuidof_use_constexpr
29 __extension__ template<typename T> struct __wsl_stub_uuidof_s;
30 __extension__ template<typename T> constexpr const GUID &__wsl_stub_uuidof();
31#else
32 __extension__ template<typename T> const GUID &__wsl_stub_uuidof();
33#endif
34}
35
36#if __wsl_stub_uuidof_use_constexpr
37#define __CRT_UUID_DECL(type, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
38 extern "C++" \
39 { \
40 template <> \
41 struct __wsl_stub_uuidof_s<type> \
42 { \
43 static constexpr IID __uuid_inst = { \
44 l, w1, w2, {b1, b2, b3, b4, b5, b6, b7, b8}}; \
45 }; \
46 template <> \
47 constexpr const GUID &__wsl_stub_uuidof<type>() \
48 { \
49 return __wsl_stub_uuidof_s<type>::__uuid_inst; \
50 } \
51 template <> \
52 constexpr const GUID &__wsl_stub_uuidof<type *>() \
53 { \
54 return __wsl_stub_uuidof_s<type>::__uuid_inst; \
55 } \
56 }
57#else
58#define __CRT_UUID_DECL(type, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
59 extern "C++" \
60 { \
61 template <> \
62 inline const GUID &__wsl_stub_uuidof<type>() \
63 { \
64 static const IID __uuid_inst = { \
65 l, w1, w2, {b1, b2, b3, b4, b5, b6, b7, b8}}; \
66 return __uuid_inst; \
67 } \
68 template <> \
69 inline const GUID &__wsl_stub_uuidof<type *>() \
70 { \
71 return __wsl_stub_uuidof<type>(); \
72 } \
73 }
74#endif
75#define __uuidof(type) __wsl_stub_uuidof<__typeof(type)>()
76#else
77#define __CRT_UUID_DECL(type, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)
78#endif
diff --git a/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/unknwn.h b/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/unknwn.h
new file mode 100644
index 0000000..e08ad1e
--- /dev/null
+++ b/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/unknwn.h
@@ -0,0 +1,3 @@
1#pragma once
2
3#include "unknwnbase.h"
diff --git a/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/unknwnbase.h b/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/unknwnbase.h
new file mode 100644
index 0000000..7a54651
--- /dev/null
+++ b/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/unknwnbase.h
@@ -0,0 +1,124 @@
1/*-------------------------------------------------------------------------------------
2 *
3 * Copyright (c) Microsoft Corporation
4 * Licensed under the MIT license
5 *
6 *-------------------------------------------------------------------------------------*/
7
8/* this ALWAYS GENERATED file contains the definitions for the interfaces */
9
10/* File created by MIDL compiler version 8.01.0627 */
11
12/* verify that the <rpcndr.h> version is high enough to compile this file*/
13#ifndef __REQUIRED_RPCNDR_H_VERSION__
14#define __REQUIRED_RPCNDR_H_VERSION__ 500
15#endif
16
17/* verify that the <rpcsal.h> version is high enough to compile this file*/
18#ifndef __REQUIRED_RPCSAL_H_VERSION__
19#define __REQUIRED_RPCSAL_H_VERSION__ 100
20#endif
21
22#include "rpc.h"
23#include "rpcndr.h"
24
25#ifndef __RPCNDR_H_VERSION__
26#error this stub requires an updated version of <rpcndr.h>
27#endif /* __RPCNDR_H_VERSION__ */
28
29#ifndef COM_NO_WINDOWS_H
30#include "windows.h"
31#include "ole2.h"
32#endif /*COM_NO_WINDOWS_H*/
33
34#ifndef __unknwnbase_h__
35#define __unknwnbase_h__
36
37#if defined(_MSC_VER) && (_MSC_VER >= 1020)
38#pragma once
39#endif
40
41/* Forward Declarations */
42
43#ifndef __IUnknown_FWD_DEFINED__
44#define __IUnknown_FWD_DEFINED__
45typedef interface IUnknown IUnknown;
46
47#endif /* __IUnknown_FWD_DEFINED__ */
48
49#ifndef __IUnknown_INTERFACE_DEFINED__
50#define __IUnknown_INTERFACE_DEFINED__
51
52/* interface IUnknown */
53/* [unique][uuid][object][local] */
54
55typedef /* [unique] */ IUnknown *LPUNKNOWN;
56
57EXTERN_C const IID IID_IUnknown;
58
59#if defined(__cplusplus) && !defined(CINTERFACE)
60extern "C++"
61{
62 MIDL_INTERFACE("00000000-0000-0000-c000-000000000046")
63 IUnknown
64 {
65 BEGIN_INTERFACE
66
67 virtual HRESULT STDMETHODCALLTYPE QueryInterface(
68 REFIID riid,
69 void **ppvObject) = 0;
70
71 virtual ULONG STDMETHODCALLTYPE AddRef() = 0;
72
73 virtual ULONG STDMETHODCALLTYPE Release() = 0;
74
75 template <class Q>
76 HRESULT
77 STDMETHODCALLTYPE
78 QueryInterface(_COM_Outptr_ Q * *pp)
79 {
80 return QueryInterface(__uuidof(Q), (void **)pp);
81 }
82 END_INTERFACE
83 };
84}
85#ifdef __CRT_UUID_DECL
86__CRT_UUID_DECL(IUnknown, 0x00000000, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46)
87#endif
88#else
89typedef struct IUnknownVtbl {
90 BEGIN_INTERFACE
91
92 /*** IUnknown methods ***/
93 HRESULT (STDMETHODCALLTYPE *QueryInterface)(
94 IUnknown *This,
95 REFIID riid,
96 void **ppvObject);
97
98 ULONG (STDMETHODCALLTYPE *AddRef)(
99 IUnknown *This);
100
101 ULONG (STDMETHODCALLTYPE *Release)(
102 IUnknown *This);
103
104 END_INTERFACE
105} IUnknownVtbl;
106
107interface IUnknown {
108 CONST_VTBL IUnknownVtbl* lpVtbl;
109};
110
111#ifdef COBJMACROS
112/*** IUnknown methods ***/
113#define IUnknown_QueryInterface(This,riid,ppvObject) (This)->lpVtbl->QueryInterface(This,riid,ppvObject)
114#define IUnknown_AddRef(This) (This)->lpVtbl->AddRef(This)
115#define IUnknown_Release(This) (This)->lpVtbl->Release(This)
116#endif
117
118#endif
119
120#endif /* __IUnknown_INTERFACE_DEFINED__ */
121
122DEFINE_GUID(IID_IUnknown, 0x00000000, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
123
124#endif /* __unknwnbase_h__ */
diff --git a/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/winapifamily.h b/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/winapifamily.h
new file mode 100644
index 0000000..064c4c2
--- /dev/null
+++ b/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/winapifamily.h
@@ -0,0 +1,6 @@
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4// Stub header to satisfy d3d12.h include. Unconditionally light up all APIs.
5#pragma once
6#define WINAPI_FAMILY_PARTITION(Partitions) 1 \ No newline at end of file
diff --git a/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/wrl/client.h b/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/wrl/client.h
new file mode 100644
index 0000000..64293a7
--- /dev/null
+++ b/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/wrl/client.h
@@ -0,0 +1,6 @@
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4// Stub to satisfy d3dx12.h include
5#pragma once
6#include <wsl/wrladapter.h> \ No newline at end of file
diff --git a/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/wrl/implements.h b/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/wrl/implements.h
new file mode 100644
index 0000000..5a3979e
--- /dev/null
+++ b/contrib/DirectX-Headers-1.618.2/include/wsl/stubs/wrl/implements.h
@@ -0,0 +1,6 @@
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4// Stub to satisfy DML TF runtime includes
5#pragma once
6#include <wsl/wrladapter.h> \ No newline at end of file
diff --git a/contrib/DirectX-Headers-1.618.2/include/wsl/winadapter.h b/contrib/DirectX-Headers-1.618.2/include/wsl/winadapter.h
new file mode 100644
index 0000000..ccb2b3c
--- /dev/null
+++ b/contrib/DirectX-Headers-1.618.2/include/wsl/winadapter.h
@@ -0,0 +1,6 @@
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#pragma once
5
6#include <unknwn.h>
diff --git a/contrib/DirectX-Headers-1.618.2/include/wsl/wrladapter.h b/contrib/DirectX-Headers-1.618.2/include/wsl/wrladapter.h
new file mode 100644
index 0000000..fcfd894
--- /dev/null
+++ b/contrib/DirectX-Headers-1.618.2/include/wsl/wrladapter.h
@@ -0,0 +1,803 @@
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#pragma once
5
6#include "winadapter.h"
7
8// defined by winadapter.h and needed by some windows headers, but conflicts
9// with some libc++ implementation headers
10#ifdef __in
11#undef __in
12#endif
13#ifdef __out
14#undef __out
15#endif
16
17#include <type_traits>
18#include <atomic>
19#include <memory>
20#include <new>
21#include <climits>
22#include <cassert>
23
24namespace Microsoft
25{
26namespace WRL
27{
28 namespace Details
29 {
30 struct BoolStruct { int Member; };
31 typedef int BoolStruct::* BoolType;
32
33 template <typename T> // T should be the ComPtr<T> or a derived type of it, not just the interface
34 class ComPtrRefBase
35 {
36 public:
37 typedef typename T::InterfaceType InterfaceType;
38
39 operator IUnknown**() const throw()
40 {
41 static_assert(__is_base_of(IUnknown, InterfaceType), "Invalid cast: InterfaceType does not derive from IUnknown");
42 return reinterpret_cast<IUnknown**>(ptr_->ReleaseAndGetAddressOf());
43 }
44
45 protected:
46 T* ptr_;
47 };
48
49 template <typename T>
50 class ComPtrRef : public Details::ComPtrRefBase<T> // T should be the ComPtr<T> or a derived type of it, not just the interface
51 {
52 using Super = Details::ComPtrRefBase<T>;
53 using InterfaceType = typename Super::InterfaceType;
54 public:
55 ComPtrRef(_In_opt_ T* ptr) throw()
56 {
57 this->ptr_ = ptr;
58 }
59
60 // Conversion operators
61 operator void**() const throw()
62 {
63 return reinterpret_cast<void**>(this->ptr_->ReleaseAndGetAddressOf());
64 }
65
66 // This is our operator ComPtr<U> (or the latest derived class from ComPtr (e.g. WeakRef))
67 operator T*() throw()
68 {
69 *this->ptr_ = nullptr;
70 return this->ptr_;
71 }
72
73 // We define operator InterfaceType**() here instead of on ComPtrRefBase<T>, since
74 // if InterfaceType is IUnknown or IInspectable, having it on the base will collide.
75 operator InterfaceType**() throw()
76 {
77 return this->ptr_->ReleaseAndGetAddressOf();
78 }
79
80 // This is used for IID_PPV_ARGS in order to do __uuidof(**(ppType)).
81 // It does not need to clear ptr_ at this point, it is done at IID_PPV_ARGS_Helper(ComPtrRef&) later in this file.
82 InterfaceType* operator *() throw()
83 {
84 return this->ptr_->Get();
85 }
86
87 // Explicit functions
88 InterfaceType* const * GetAddressOf() const throw()
89 {
90 return this->ptr_->GetAddressOf();
91 }
92
93 InterfaceType** ReleaseAndGetAddressOf() throw()
94 {
95 return this->ptr_->ReleaseAndGetAddressOf();
96 }
97 };
98 }
99
100 template <typename T>
101 class ComPtr
102 {
103 public:
104 typedef T InterfaceType;
105
106 protected:
107 InterfaceType *ptr_;
108 template<class U> friend class ComPtr;
109
110 void InternalAddRef() const throw()
111 {
112 if (ptr_ != nullptr)
113 {
114 ptr_->AddRef();
115 }
116 }
117
118 unsigned long InternalRelease() throw()
119 {
120 unsigned long ref = 0;
121 T* temp = ptr_;
122
123 if (temp != nullptr)
124 {
125 ptr_ = nullptr;
126 ref = temp->Release();
127 }
128
129 return ref;
130 }
131
132 public:
133 ComPtr() throw() : ptr_(nullptr)
134 {
135 }
136
137 ComPtr(decltype(nullptr)) throw() : ptr_(nullptr)
138 {
139 }
140
141 template<class U>
142 ComPtr(_In_opt_ U *other) throw() : ptr_(other)
143 {
144 InternalAddRef();
145 }
146
147 ComPtr(const ComPtr& other) throw() : ptr_(other.ptr_)
148 {
149 InternalAddRef();
150 }
151
152 // copy constructor that allows to instantiate class when U* is convertible to T*
153 template<class U>
154 ComPtr(const ComPtr<U> &other, typename std::enable_if<std::is_convertible<U*, T*>::value, void *>::type * = 0) throw() :
155 ptr_(other.ptr_)
156 {
157 InternalAddRef();
158 }
159
160 ComPtr(_Inout_ ComPtr &&other) throw() : ptr_(nullptr)
161 {
162 if (this != reinterpret_cast<ComPtr*>(&reinterpret_cast<unsigned char&>(other)))
163 {
164 Swap(other);
165 }
166 }
167
168 // Move constructor that allows instantiation of a class when U* is convertible to T*
169 template<class U>
170 ComPtr(_Inout_ ComPtr<U>&& other, typename std::enable_if<std::is_convertible<U*, T*>::value, void *>::type * = 0) throw() :
171 ptr_(other.ptr_)
172 {
173 other.ptr_ = nullptr;
174 }
175
176 ~ComPtr() throw()
177 {
178 InternalRelease();
179 }
180
181 ComPtr& operator=(decltype(nullptr)) throw()
182 {
183 InternalRelease();
184 return *this;
185 }
186
187 ComPtr& operator=(_In_opt_ T *other) throw()
188 {
189 if (ptr_ != other)
190 {
191 ComPtr(other).Swap(*this);
192 }
193 return *this;
194 }
195
196 template <typename U>
197 ComPtr& operator=(_In_opt_ U *other) throw()
198 {
199 ComPtr(other).Swap(*this);
200 return *this;
201 }
202
203 ComPtr& operator=(const ComPtr &other) throw()
204 {
205 if (ptr_ != other.ptr_)
206 {
207 ComPtr(other).Swap(*this);
208 }
209 return *this;
210 }
211
212 template<class U>
213 ComPtr& operator=(const ComPtr<U>& other) throw()
214 {
215 ComPtr(other).Swap(*this);
216 return *this;
217 }
218
219 ComPtr& operator=(_Inout_ ComPtr &&other) throw()
220 {
221 ComPtr(static_cast<ComPtr&&>(other)).Swap(*this);
222 return *this;
223 }
224
225 template<class U>
226 ComPtr& operator=(_Inout_ ComPtr<U>&& other) throw()
227 {
228 ComPtr(static_cast<ComPtr<U>&&>(other)).Swap(*this);
229 return *this;
230 }
231
232 void Swap(_Inout_ ComPtr&& r) throw()
233 {
234 T* tmp = ptr_;
235 ptr_ = r.ptr_;
236 r.ptr_ = tmp;
237 }
238
239 void Swap(_Inout_ ComPtr& r) throw()
240 {
241 T* tmp = ptr_;
242 ptr_ = r.ptr_;
243 r.ptr_ = tmp;
244 }
245
246 operator Details::BoolType() const throw()
247 {
248 return Get() != nullptr ? &Details::BoolStruct::Member : nullptr;
249 }
250
251 T* Get() const throw()
252 {
253 return ptr_;
254 }
255
256 InterfaceType* operator->() const throw()
257 {
258 return ptr_;
259 }
260
261 Details::ComPtrRef<ComPtr<T>> operator&() throw()
262 {
263 return Details::ComPtrRef<ComPtr<T>>(this);
264 }
265
266 const Details::ComPtrRef<const ComPtr<T>> operator&() const throw()
267 {
268 return Details::ComPtrRef<const ComPtr<T>>(this);
269 }
270
271 T* const* GetAddressOf() const throw()
272 {
273 return &ptr_;
274 }
275
276 T** GetAddressOf() throw()
277 {
278 return &ptr_;
279 }
280
281 T** ReleaseAndGetAddressOf() throw()
282 {
283 InternalRelease();
284 return &ptr_;
285 }
286
287 T* Detach() throw()
288 {
289 T* ptr = ptr_;
290 ptr_ = nullptr;
291 return ptr;
292 }
293
294 void Attach(_In_opt_ InterfaceType* other) throw()
295 {
296 if (ptr_ != nullptr)
297 {
298 auto ref = ptr_->Release();
299 // DBG_UNREFERENCED_LOCAL_VARIABLE(ref);
300 // Attaching to the same object only works if duplicate references are being coalesced. Otherwise
301 // re-attaching will cause the pointer to be released and may cause a crash on a subsequent dereference.
302 assert(ref != 0 || ptr_ != other);
303 }
304
305 ptr_ = other;
306 }
307
308 unsigned long Reset()
309 {
310 return InternalRelease();
311 }
312
313 // Previously, unsafe behavior could be triggered when 'this' is ComPtr<IInspectable> or ComPtr<IUnknown> and CopyTo is used to copy to another type U.
314 // The user will use operator& to convert the destination into a ComPtrRef, which can then implicit cast to IInspectable** and IUnknown**.
315 // If this overload of CopyTo is not present, it will implicitly cast to IInspectable or IUnknown and match CopyTo(InterfaceType**) instead.
316 // A valid polymoprhic downcast requires run-time type checking via QueryInterface, so CopyTo(InterfaceType**) will break type safety.
317 // This overload matches ComPtrRef before the implicit cast takes place, preventing the unsafe downcast.
318 template <typename U>
319 HRESULT CopyTo(Details::ComPtrRef<ComPtr<U>> ptr, typename std::enable_if<
320 (std::is_same<T, IUnknown>::value)
321 && !std::is_same<U*, T*>::value, void *>::type * = 0) const throw()
322 {
323 return ptr_->QueryInterface(__uuidof(U), ptr);
324 }
325
326 HRESULT CopyTo(_Outptr_result_maybenull_ InterfaceType** ptr) const throw()
327 {
328 InternalAddRef();
329 *ptr = ptr_;
330 return S_OK;
331 }
332
333 HRESULT CopyTo(REFIID riid, _Outptr_result_nullonfailure_ void** ptr) const throw()
334 {
335 return ptr_->QueryInterface(riid, ptr);
336 }
337
338 template<typename U>
339 HRESULT CopyTo(_Outptr_result_nullonfailure_ U** ptr) const throw()
340 {
341 return ptr_->QueryInterface(__uuidof(U), reinterpret_cast<void**>(ptr));
342 }
343
344 // query for U interface
345 template<typename U>
346 HRESULT As(_Inout_ Details::ComPtrRef<ComPtr<U>> p) const throw()
347 {
348 return ptr_->QueryInterface(__uuidof(U), p);
349 }
350
351 // query for U interface
352 template<typename U>
353 HRESULT As(_Out_ ComPtr<U>* p) const throw()
354 {
355 return ptr_->QueryInterface(__uuidof(U), reinterpret_cast<void**>(p->ReleaseAndGetAddressOf()));
356 }
357
358 // query for riid interface and return as IUnknown
359 HRESULT AsIID(REFIID riid, _Out_ ComPtr<IUnknown>* p) const throw()
360 {
361 return ptr_->QueryInterface(riid, reinterpret_cast<void**>(p->ReleaseAndGetAddressOf()));
362 }
363
364 }; // ComPtr
365
366
367 namespace Details
368 {
369 // Empty struct used as default template parameter
370 class Nil
371 {
372 };
373
374 // Empty struct used for validating template parameter types in Implements
375 struct ImplementsBase
376 {
377 };
378
379 class RuntimeClassBase
380 {
381 protected:
382 template<typename T>
383 static HRESULT AsIID(_In_ T* implements, REFIID riid, _Outptr_result_nullonfailure_ void **ppvObject) noexcept
384 {
385 *ppvObject = nullptr;
386 bool isRefDelegated = false;
387 // Prefer InlineIsEqualGUID over other forms since it's better perf on 4-byte aligned data, which is almost always the case.
388 if (InlineIsEqualGUID(riid, __uuidof(IUnknown)))
389 {
390 *ppvObject = implements->CastToUnknown();
391 static_cast<IUnknown*>(*ppvObject)->AddRef();
392 return S_OK;
393 }
394
395 HRESULT hr = implements->CanCastTo(riid, ppvObject, &isRefDelegated);
396 if (SUCCEEDED(hr) && !isRefDelegated)
397 {
398 static_cast<IUnknown*>(*ppvObject)->AddRef();
399 }
400
401#ifdef _MSC_VER
402#pragma warning(push)
403#pragma warning(disable: 6102) // '*ppvObject' is used but may not be initialized
404#endif
405 _Analysis_assume_(SUCCEEDED(hr) || (*ppvObject == nullptr));
406#ifdef _MSC_VER
407#pragma warning(pop)
408#endif
409 return hr;
410 }
411
412 public:
413 HRESULT RuntimeClassInitialize() noexcept
414 {
415 return S_OK;
416 }
417 };
418
419 // Interface traits provides casting and filling iids methods helpers
420 template<typename I0>
421 struct InterfaceTraits
422 {
423 typedef I0 Base;
424
425 template<typename T>
426 static Base* CastToBase(_In_ T* ptr) noexcept
427 {
428 return static_cast<Base*>(ptr);
429 }
430
431 template<typename T>
432 static IUnknown* CastToUnknown(_In_ T* ptr) noexcept
433 {
434 return static_cast<IUnknown*>(static_cast<Base*>(ptr));
435 }
436
437 template <typename T>
438 _Success_(return == true)
439 static bool CanCastTo(_In_ T* ptr, REFIID riid, _Outptr_ void **ppv) noexcept
440 {
441 // Prefer InlineIsEqualGUID over other forms since it's better perf on 4-byte aligned data, which is almost always the case.
442 if (InlineIsEqualGUID(riid, __uuidof(Base)))
443 {
444 *ppv = static_cast<Base*>(ptr);
445 return true;
446 }
447
448 return false;
449 }
450 };
451
452 // Specialization for Nil parameter
453 template<>
454 struct InterfaceTraits<Nil>
455 {
456 typedef Nil Base;
457
458 template <typename T>
459 _Success_(return == true)
460 static bool CanCastTo(_In_ T*, REFIID, _Outptr_ void **) noexcept
461 {
462 return false;
463 }
464 };
465
466 // ChainInterfaces - template allows specifying a derived COM interface along with its class hierarchy to allow QI for the base interfaces
467 template <typename I0, typename I1, typename I2 = Nil, typename I3 = Nil,
468 typename I4 = Nil, typename I5 = Nil, typename I6 = Nil,
469 typename I7 = Nil, typename I8 = Nil, typename I9 = Nil>
470 struct ChainInterfaces : I0
471 {
472 protected:
473 HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv) throw()
474 {
475 typename InterfaceTraits<I0>::Base* ptr = InterfaceTraits<I0>::CastToBase(this);
476
477 return (InterfaceTraits<I0>::CanCastTo(this, riid, ppv) ||
478 InterfaceTraits<I1>::CanCastTo(ptr, riid, ppv) ||
479 InterfaceTraits<I2>::CanCastTo(ptr, riid, ppv) ||
480 InterfaceTraits<I3>::CanCastTo(ptr, riid, ppv) ||
481 InterfaceTraits<I4>::CanCastTo(ptr, riid, ppv) ||
482 InterfaceTraits<I5>::CanCastTo(ptr, riid, ppv) ||
483 InterfaceTraits<I6>::CanCastTo(ptr, riid, ppv) ||
484 InterfaceTraits<I7>::CanCastTo(ptr, riid, ppv) ||
485 InterfaceTraits<I8>::CanCastTo(ptr, riid, ppv) ||
486 InterfaceTraits<I9>::CanCastTo(ptr, riid, ppv)) ? S_OK : E_NOINTERFACE;
487 }
488
489 IUnknown* CastToUnknown() throw()
490 {
491 return InterfaceTraits<I0>::CastToUnknown(this);
492 }
493 };
494
495 // Helper template used by Implements. This template traverses a list of interfaces and adds them as base class and information
496 // to enable QI.
497 template <typename ...TInterfaces>
498 struct ImplementsHelper;
499
500 template <typename T>
501 struct ImplementsMarker
502 {};
503
504 template <typename I0, bool isImplements>
505 struct MarkImplements;
506
507 template <typename I0>
508 struct MarkImplements<I0, false>
509 {
510 typedef I0 Type;
511 };
512
513 template <typename I0>
514 struct MarkImplements<I0, true>
515 {
516 typedef ImplementsMarker<I0> Type;
517 };
518
519 // AdjustImplements pre-processes the type list for more efficient builds.
520 template <typename ...Bases>
521 struct AdjustImplements;
522
523 template <typename I0, typename ...Bases>
524 struct AdjustImplements<I0, Bases...>
525 {
526 typedef ImplementsHelper<typename MarkImplements<I0, std::is_base_of<ImplementsBase, I0>::value>::Type, Bases...> Type;
527 };
528
529 // Use AdjustImplements to remove instances of "Nil" from the type list.
530 template <typename ...Bases>
531 struct AdjustImplements<Nil, Bases...>
532 {
533 typedef typename AdjustImplements<Bases...>::Type Type;
534 };
535
536 template <>
537 struct AdjustImplements<>
538 {
539 typedef ImplementsHelper<> Type;
540 };
541
542 // Specialization handles unadorned interfaces
543 template <typename I0, typename ...TInterfaces>
544 struct ImplementsHelper<I0, TInterfaces...> :
545 I0,
546 AdjustImplements<TInterfaces...>::Type
547 {
548 template <typename ...> friend struct ImplementsHelper;
549 friend class RuntimeClassBase;
550
551 protected:
552
553 HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv, bool *pRefDelegated = nullptr) noexcept
554 {
555 // Prefer InlineIsEqualGUID over other forms since it's better perf on 4-byte aligned data, which is almost always the case.
556 if (InlineIsEqualGUID(riid, __uuidof(I0)))
557 {
558 *ppv = reinterpret_cast<I0*>(reinterpret_cast<void*>(this));
559 return S_OK;
560 }
561 return AdjustImplements<TInterfaces...>::Type::CanCastTo(riid, ppv, pRefDelegated);
562 }
563
564 IUnknown* CastToUnknown() noexcept
565 {
566 return reinterpret_cast<I0*>(reinterpret_cast<void*>(this));
567 }
568 };
569
570
571 // Selector is used to "tag" base interfaces to be used in casting, since a runtime class may indirectly derive from
572 // the same interface or Implements<> template multiple times
573 template <typename base, typename disciminator>
574 struct Selector : public base
575 {
576 };
577
578 // Specialization handles types that derive from ImplementsHelper (e.g. nested Implements).
579 template <typename I0, typename ...TInterfaces>
580 struct ImplementsHelper<ImplementsMarker<I0>, TInterfaces...> :
581 Selector<I0, ImplementsHelper<ImplementsMarker<I0>, TInterfaces...>>,
582 Selector<typename AdjustImplements<TInterfaces...>::Type, ImplementsHelper<ImplementsMarker<I0>, TInterfaces...>>
583 {
584 template <typename ...> friend struct ImplementsHelper;
585 friend class RuntimeClassBase;
586
587 protected:
588 typedef Selector<I0, ImplementsHelper<ImplementsMarker<I0>, TInterfaces...>> CurrentType;
589 typedef Selector<typename AdjustImplements<TInterfaces...>::Type, ImplementsHelper<ImplementsMarker<I0>, TInterfaces...>> BaseType;
590
591 HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv, bool *pRefDelegated = nullptr) noexcept
592 {
593 HRESULT hr = CurrentType::CanCastTo(riid, ppv);
594 if (hr == E_NOINTERFACE)
595 {
596 hr = BaseType::CanCastTo(riid, ppv, pRefDelegated);
597 }
598 return hr;
599 }
600
601 IUnknown* CastToUnknown() noexcept
602 {
603 // First in list wins.
604 return CurrentType::CastToUnknown();
605 }
606 };
607
608 // terminal case specialization.
609 template <>
610 struct ImplementsHelper<>
611 {
612 template <typename ...> friend struct ImplementsHelper;
613 friend class RuntimeClassBase;
614
615 protected:
616 HRESULT CanCastTo(_In_ REFIID /*riid*/, _Outptr_ void ** /*ppv*/, bool * /*pRefDelegated*/ = nullptr) noexcept
617 {
618 return E_NOINTERFACE;
619 }
620
621 // IUnknown* CastToUnknown() noexcept; // not defined for terminal case.
622 };
623
624 // Specialization handles chaining interfaces
625 template <typename C0, typename C1, typename C2, typename C3, typename C4, typename C5, typename C6, typename C7, typename C8, typename C9, typename ...TInterfaces>
626 struct ImplementsHelper<ChainInterfaces<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9>, TInterfaces...> :
627 ChainInterfaces<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9>,
628 AdjustImplements<TInterfaces...>::Type
629 {
630 template <typename ...> friend struct ImplementsHelper;
631 friend class RuntimeClassBase;
632
633 protected:
634 typedef typename AdjustImplements<TInterfaces...>::Type BaseType;
635
636 HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv, bool *pRefDelegated = nullptr) noexcept
637 {
638 HRESULT hr = ChainInterfaces<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9>::CanCastTo(riid, ppv);
639 if (FAILED(hr))
640 {
641 hr = BaseType::CanCastTo(riid, ppv, pRefDelegated);
642 }
643
644 return hr;
645 }
646
647 IUnknown* CastToUnknown() noexcept
648 {
649 return ChainInterfaces<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9>::CastToUnknown();
650 }
651 };
652
653 // Implements - template implementing QI using the information provided through its template parameters
654 // Each template parameter has to be one of the following:
655 // * COM Interface
656 // * A class that implements one or more COM interfaces
657 // * ChainInterfaces template
658 template <typename I0, typename ...TInterfaces>
659 struct Implements :
660 AdjustImplements<I0, TInterfaces...>::Type,
661 ImplementsBase
662 {
663 public:
664 typedef I0 FirstInterface;
665 protected:
666 typedef typename AdjustImplements<I0, TInterfaces...>::Type BaseType;
667 template <typename ...> friend struct ImplementsHelper;
668 friend class RuntimeClassBase;
669
670 HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv) noexcept
671 {
672 return BaseType::CanCastTo(riid, ppv);
673 }
674
675 IUnknown* CastToUnknown() noexcept
676 {
677 return BaseType::CastToUnknown();
678 }
679 };
680
681 // Used on RuntimeClass to protect it from being constructed with new
682 class DontUseNewUseMake
683 {
684 private:
685 void* operator new(size_t) noexcept
686 {
687 assert(false);
688 return 0;
689 }
690
691 public:
692 void* operator new(size_t, _In_ void* placement) noexcept
693 {
694 return placement;
695 }
696 };
697
698 template <typename ...TInterfaces>
699 class RuntimeClassImpl :
700 public AdjustImplements<TInterfaces...>::Type,
701 public RuntimeClassBase,
702 public DontUseNewUseMake
703 {
704 public:
705 STDMETHOD(QueryInterface)(REFIID riid, _Outptr_result_nullonfailure_ void **ppvObject)
706 {
707 return Super::AsIID(this, riid, ppvObject);
708 }
709
710 STDMETHOD_(ULONG, AddRef)()
711 {
712 return InternalAddRef();
713 }
714
715 STDMETHOD_(ULONG, Release)()
716 {
717 ULONG ref = InternalRelease();
718 if (ref == 0)
719 {
720 this->~RuntimeClassImpl();
721 delete[] reinterpret_cast<char*>(this);
722 }
723
724 return ref;
725 }
726
727 protected:
728 using Super = RuntimeClassBase;
729 static const LONG c_lProtectDestruction = -(LONG_MAX / 2);
730
731 RuntimeClassImpl() noexcept = default;
732
733 virtual ~RuntimeClassImpl() noexcept
734 {
735 // Set refcount_ to -(LONG_MAX/2) to protect destruction and
736 // also catch mismatched Release in debug builds
737 refcount_ = static_cast<ULONG>(c_lProtectDestruction);
738 }
739
740 ULONG InternalAddRef() noexcept
741 {
742 return ++refcount_;
743 }
744
745 ULONG InternalRelease() noexcept
746 {
747 return --refcount_;
748 }
749
750 unsigned long GetRefCount() const noexcept
751 {
752 return refcount_;
753 }
754
755 std::atomic<ULONG> refcount_{1};
756 };
757 }
758
759 template <typename ...TInterfaces>
760 class Base : public Details::RuntimeClassImpl<TInterfaces...>
761 {
762 Base(const Base&) = delete;
763 Base& operator=(const Base&) = delete;
764
765 protected:
766 HRESULT CustomQueryInterface(REFIID /*riid*/, _Outptr_result_nullonfailure_ void** /*ppvObject*/, _Out_ bool *handled)
767 {
768 *handled = false;
769 return S_OK;
770 }
771
772 public:
773 Base() throw() = default;
774 typedef Base RuntimeClassT;
775 };
776
777 // Creates a Nano-COM object wrapped in a smart pointer.
778 template <typename T, typename ...TArgs>
779 ComPtr<T> Make(TArgs&&... args)
780 {
781 std::unique_ptr<char[]> buffer(new(std::nothrow) char[sizeof(T)]);
782 ComPtr<T> object;
783
784 if (buffer)
785 {
786 T* ptr = new (buffer.get())T(std::forward<TArgs>(args)...);
787 object.Attach(ptr);
788 buffer.release();
789 }
790
791 return object;
792 }
793
794 using Details::ChainInterfaces;
795}
796}
797
798// Overloaded global function to provide to IID_PPV_ARGS that support Details::ComPtrRef
799template<typename T>
800void** IID_PPV_ARGS_Helper(Microsoft::WRL::Details::ComPtrRef<T> pp) throw()
801{
802 return pp;
803}