From a7d19030b872967c4224607c454273a2e65a5ed4 Mon Sep 17 00:00:00 2001 From: Yonggang Luo Date: Mon, 30 May 2022 03:16:48 +0800 Subject: [PATCH] Turn to use __uuidof, now wsl/winadapter.h are platform independent Signed-off-by: Yonggang Luo --- googletest/feature_support_test.cpp | 4 - include/dxguids/dxguids.h | 13 +- include/wsl/stubs/basetsd.h | 404 +++++++++++++++++++++++++++ include/wsl/stubs/rpcndr.h | 66 +++++ include/wsl/stubs/unknwnbase.h | 2 +- include/wsl/winadapter.h | 415 ---------------------------- include/wsl/wrladapter.h | 14 +- src/dxguids.cpp | 2 - test/feature_check_test.cpp | 4 - test/test.cpp | 4 - 10 files changed, 485 insertions(+), 443 deletions(-) create mode 100644 include/wsl/stubs/basetsd.h diff --git a/googletest/feature_support_test.cpp b/googletest/feature_support_test.cpp index a39ea90..0394384 100644 --- a/googletest/feature_support_test.cpp +++ b/googletest/feature_support_test.cpp @@ -2,11 +2,7 @@ // Licensed under the MIT License. #include "gtest/gtest.h" -#ifndef _WIN32 #include -#elif defined(__MINGW32__) -#include -#endif #include #include diff --git a/include/dxguids/dxguids.h b/include/dxguids/dxguids.h index dc1534b..9c7def9 100644 --- a/include/dxguids/dxguids.h +++ b/include/dxguids/dxguids.h @@ -22,23 +22,24 @@ constexpr inline bool ConstexprIsEqualGUID(REFGUID a, REFGUID b) a.Data4[7] == b.Data4[7]; } +template GUID uuidof() = delete; +template GUID uuidof(T*) { return uuidof(); } +template GUID uuidof(T**) { return uuidof(); } +template GUID uuidof(T&) { return uuidof(); } + // Each COM interface (e.g. ID3D12Device) has a unique interface ID (IID) associated with it. With MSVC, the IID is defined // along with the interface declaration using compiler intrinsics (__declspec(uuid(...)); the IID can then be retrieved // using __uuidof. These intrinsics are not supported with all toolchains, so these helpers redefine IID values that can be // used with the various adapter COM helpers (ComPtr, IID_PPV_ARGS, etc.) for Linux. IIDs are stable and cannot change, but as // a precaution we statically assert the values are as expected when compiling for Windows. -#ifdef _WIN32 -// winadapter.h isn't included when building for Windows, so the base function template needs to be declared. -template GUID uuidof() = delete; #if defined(_MSC_VER) #define _DXGUIDS_SUPPORT_STATIC_ASSERT_IID -#elif defined(__MINGW32__) +#elif defined(__CRT_UUID_DECL) /* match _mingw.h */ #if __cpp_constexpr >= 200704l && __cpp_inline_variables >= 201606L #define _DXGUIDS_SUPPORT_STATIC_ASSERT_IID #endif /* __cpp_constexpr >= 200704l && __cpp_inline_variables >= 201606L */ #endif /* _MSC_VER */ -#endif /* _WIN32 */ #ifdef _DXGUIDS_SUPPORT_STATIC_ASSERT_IID #define _WINADAPTER_ASSERT_IID(InterfaceName) \ @@ -47,7 +48,7 @@ static_assert(ConstexprIsEqualGUID(uuidof(), __uuidof(InterfaceNa #define _WINADAPTER_ASSERT_IID(InterfaceName) #endif -#if defined(_WIN32) && defined(__MINGW32__) +#ifdef __CRT_UUID_DECL #define WINADAPTER_IID(InterfaceName, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ template <> constexpr GUID uuidof() \ { \ diff --git a/include/wsl/stubs/basetsd.h b/include/wsl/stubs/basetsd.h new file mode 100644 index 0000000..9803ee8 --- /dev/null +++ b/include/wsl/stubs/basetsd.h @@ -0,0 +1,404 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +#pragma once + +// These #defines prevent the idl-generated headers from trying to include +// Windows.h from the SDK rather than this one. +#define RPC_NO_WINDOWS_H +#define COM_NO_WINDOWS_H + +// Allcaps type definitions +#include +#include +#include +#include + +// Note: using fixed-width here to match Windows widths +// Specifically this is different for 'long' vs 'LONG' +typedef uint8_t UINT8; +typedef int8_t INT8; +typedef uint16_t UINT16; +typedef int16_t INT16; +typedef uint32_t UINT32, UINT, ULONG, DWORD, BOOL, WINBOOL; +typedef int32_t INT32, INT, LONG; +typedef uint64_t UINT64, ULONG_PTR; +typedef int64_t INT64, LONG_PTR; +typedef void VOID, *HANDLE, *RPC_IF_HANDLE, *LPVOID; +typedef const void *LPCVOID; +typedef size_t SIZE_T; +typedef float FLOAT; +typedef double DOUBLE; +typedef unsigned char BYTE; +typedef int HWND; +typedef int PALETTEENTRY; +typedef int HDC; +typedef uint16_t WORD; +typedef void* PVOID; +typedef char BOOLEAN; +typedef uint64_t ULONGLONG; +typedef uint16_t USHORT, *PUSHORT; +typedef int64_t LONGLONG, *PLONGLONG; +typedef int64_t LONG_PTR, *PLONG_PTR; +typedef int64_t LONG64, *PLONG64; +typedef uint64_t ULONG64, *PULONG64; +typedef wchar_t WCHAR, *PWSTR; +typedef uint8_t UCHAR, *PUCHAR; +typedef uint64_t ULONG_PTR, *PULONG_PTR; +typedef uint64_t UINT_PTR, *PUINT_PTR; +typedef int64_t INT_PTR, *PINT_PTR; + +// Note: WCHAR is not the same between Windows and Linux, to enable +// string manipulation APIs to work with resulting strings. +// APIs to D3D/DXCore will work on Linux wchars, but beware with +// interactions directly with the Windows kernel. +typedef char CHAR, *PSTR, *LPSTR, TCHAR, *PTSTR; +typedef const char *LPCSTR, *PCSTR, *LPCTSTR, *PCTSTR; +typedef wchar_t WCHAR, *PWSTR, *LPWSTR, *PWCHAR; +typedef const wchar_t *LPCWSTR, *PCWSTR; + +#undef LONG_MAX +#define LONG_MAX INT_MAX +#undef ULONG_MAX +#define ULONG_MAX UINT_MAX + +// Misc defines +#define MIDL_INTERFACE(x) interface +#define __analysis_assume(x) +#define TRUE 1u +#define FALSE 0u +#define DECLSPEC_UUID(x) +#define DECLSPEC_NOVTABLE +#define DECLSPEC_SELECTANY +#ifdef __cplusplus +#define EXTERN_C extern "C" +#else +#define EXTERN_C extern +#endif +#define APIENTRY +#define OUT +#define IN +#define CONST const +#define MAX_PATH 260 +#define GENERIC_ALL 0x10000000L +#define C_ASSERT(expr) static_assert((expr)) +#define _countof(a) (sizeof(a) / sizeof(*(a))) + +typedef struct tagRECTL +{ + LONG left; + LONG top; + LONG right; + LONG bottom; +} RECTL; + +typedef struct tagPOINT +{ + int x; + int y; +} POINT; + +typedef struct _GUID { + uint32_t Data1; + uint16_t Data2; + uint16_t Data3; + uint8_t Data4[ 8 ]; +} GUID; + +#ifdef INITGUID +#ifdef __cplusplus +#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 } } +#else +#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 } } +#endif +#else +#define DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) EXTERN_C const GUID name +#endif + +typedef GUID IID; +typedef GUID UUID; +typedef GUID CLSID; +#ifdef __cplusplus +#define REFGUID const GUID & +#define REFIID const IID & +#define REFCLSID const IID & + +__inline int InlineIsEqualGUID(REFGUID rguid1, REFGUID rguid2) +{ + return ( + ((uint32_t *)&rguid1)[0] == ((uint32_t *)&rguid2)[0] && + ((uint32_t *)&rguid1)[1] == ((uint32_t *)&rguid2)[1] && + ((uint32_t *)&rguid1)[2] == ((uint32_t *)&rguid2)[2] && + ((uint32_t *)&rguid1)[3] == ((uint32_t *)&rguid2)[3]); +} + +inline bool operator==(REFGUID guidOne, REFGUID guidOther) +{ + return !!InlineIsEqualGUID(guidOne, guidOther); +} + +inline bool operator!=(REFGUID guidOne, REFGUID guidOther) +{ + return !(guidOne == guidOther); +} + +#else +#define REFGUID const GUID * +#define REFIID const IID * +#define REFCLSID const IID * +#endif + +// SAL annotations +#define _In_ +#define _In_z_ +#define _In_opt_ +#define _In_opt_z_ +#define _In_reads_(x) +#define _In_reads_opt_(x) +#define _In_reads_bytes_(x) +#define _In_reads_bytes_opt_(x) +#define _In_range_(x, y) +#define _In_bytecount_(x) +#define _Out_ +#define _Out_opt_ +#define _Outptr_ +#define _Outptr_opt_result_z_ +#define _Outptr_opt_result_bytebuffer_(x) +#define _COM_Outptr_ +#define _COM_Outptr_result_maybenull_ +#define _COM_Outptr_opt_ +#define _COM_Outptr_opt_result_maybenull_ +#define _Out_writes_(x) +#define _Out_writes_z_(x) +#define _Out_writes_opt_(x) +#define _Out_writes_all_(x) +#define _Out_writes_all_opt_(x) +#define _Out_writes_to_opt_(x, y) +#define _Out_writes_bytes_(x) +#define _Out_writes_bytes_all_(x) +#define _Out_writes_bytes_all_opt_(x) +#define _Out_writes_bytes_opt_(x) +#define _Inout_ +#define _Inout_opt_ +#define _Inout_updates_(x) +#define _Inout_updates_bytes_(x) +#define _Field_size_(x) +#define _Field_size_opt_(x) +#define _Field_size_bytes_(x) +#define _Field_size_full_(x) +#define _Field_size_full_opt_(x) +#define _Field_size_bytes_full_(x) +#define _Field_size_bytes_full_opt_(x) +#define _Field_size_bytes_part_(x, y) +#define _Field_range_(x, y) +#define _Field_z_ +#define _Check_return_ +#define _IRQL_requires_(x) +#define _IRQL_requires_min_(x) +#define _IRQL_requires_max_(x) +#define _At_(x, y) +#define _Always_(x) +#define _Return_type_success_(x) +#define _Translates_Win32_to_HRESULT_(x) +#define _Maybenull_ +#define _Outptr_result_maybenull_ +#define _Outptr_result_nullonfailure_ +#define _Analysis_assume_(x) +#define _Success_(x) +#define _In_count_(x) +#define _In_opt_count_(x) +#define _Use_decl_annotations_ + +// Calling conventions +#define __cdecl +#define __stdcall +#define STDMETHODCALLTYPE +#define STDAPICALLTYPE +#define STDAPI EXTERN_C HRESULT STDAPICALLTYPE +#define WINAPI + +#define interface struct +#if defined (__cplusplus) && !defined (CINTERFACE) +#define STDMETHOD(method) virtual HRESULT STDMETHODCALLTYPE method +#define STDMETHOD_(type, method) virtual type STDMETHODCALLTYPE method +#define PURE = 0 +#define THIS_ +#define THIS void +#define DECLARE_INTERFACE(iface) interface DECLSPEC_NOVTABLE iface +#define DECLARE_INTERFACE_(iface, baseiface) interface DECLSPEC_NOVTABLE iface : public baseiface + +interface IUnknown; +extern "C++" +{ + template void** IID_PPV_ARGS_Helper(T** pp) + { + static_cast(*pp); + return reinterpret_cast(pp); + } +} +#define IID_PPV_ARGS(ppType) __uuidof (**(ppType)), IID_PPV_ARGS_Helper (ppType) +#else +#define STDMETHOD(method) HRESULT (STDMETHODCALLTYPE *method) +#define STDMETHOD_(type, method) type (STDMETHODCALLTYPE *method) +#define PURE +#define THIS_ INTERFACE *This, +#define THIS INTERFACE *This +#ifdef CONST_VTABLE +#define DECLARE_INTERFACE(iface) typedef interface iface { const struct iface##Vtbl *lpVtbl; } iface; typedef const struct iface##Vtbl iface##Vtbl; const struct iface##Vtbl +#else +#define DECLARE_INTERFACE(iface) typedef interface iface { struct iface##Vtbl *lpVtbl; } iface; typedef struct iface##Vtbl iface##Vtbl; struct iface##Vtbl +#endif +#define DECLARE_INTERFACE_(iface, baseiface) DECLARE_INTERFACE (iface) +#endif + +#define IFACEMETHOD(method) /*override*/ STDMETHOD (method) +#define IFACEMETHOD_(type, method) /*override*/ STDMETHOD_(type, method) +#ifndef BEGIN_INTERFACE +#define BEGIN_INTERFACE +#define END_INTERFACE +#endif + +// Error codes +typedef LONG HRESULT; +#define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0) +#define FAILED(hr) (((HRESULT)(hr)) < 0) +#define S_OK ((HRESULT)0L) +#define S_FALSE ((HRESULT)1L) +#define E_NOTIMPL ((HRESULT)0x80004001L) +#define E_OUTOFMEMORY ((HRESULT)0x8007000EL) +#define E_INVALIDARG ((HRESULT)0x80070057L) +#define E_NOINTERFACE ((HRESULT)0x80004002L) +#define E_POINTER ((HRESULT)0x80004003L) +#define E_HANDLE ((HRESULT)0x80070006L) +#define E_ABORT ((HRESULT)0x80004004L) +#define E_FAIL ((HRESULT)0x80004005L) +#define E_ACCESSDENIED ((HRESULT)0x80070005L) +#define E_UNEXPECTED ((HRESULT)0x8000FFFFL) +#define DXGI_ERROR_INVALID_CALL ((HRESULT)0x887A0001L) +#define DXGI_ERROR_NOT_FOUND ((HRESULT)0x887A0002L) +#define DXGI_ERROR_MORE_DATA ((HRESULT)0x887A0003L) +#define DXGI_ERROR_UNSUPPORTED ((HRESULT)0x887A0004L) +#define DXGI_ERROR_DEVICE_REMOVED ((HRESULT)0x887A0005L) +#define DXGI_ERROR_DEVICE_HUNG ((HRESULT)0x887A0006L) +#define DXGI_ERROR_DEVICE_RESET ((HRESULT)0x887A0007L) +#define DXGI_ERROR_DRIVER_INTERNAL_ERROR ((HRESULT)0x887A0020L) + +typedef struct _LUID +{ + ULONG LowPart; + LONG HighPart; +} LUID; + +typedef struct _RECT +{ + int left; + int top; + int right; + int bottom; +} RECT; + +typedef union _LARGE_INTEGER { + struct { + uint32_t LowPart; + uint32_t HighPart; + } u; + int64_t QuadPart; +} LARGE_INTEGER; +typedef LARGE_INTEGER *PLARGE_INTEGER; + +typedef union _ULARGE_INTEGER { + struct { + uint32_t LowPart; + uint32_t HighPart; + } u; + uint64_t QuadPart; +} ULARGE_INTEGER; +typedef ULARGE_INTEGER *PULARGE_INTEGER; + +#define DECLARE_HANDLE(name) \ + struct name##__ { \ + int unused; \ + }; \ + typedef struct name##__ *name + +typedef struct _SECURITY_ATTRIBUTES { + DWORD nLength; + LPVOID lpSecurityDescriptor; + WINBOOL bInheritHandle; +} SECURITY_ATTRIBUTES; + +struct STATSTG; + +#ifdef __cplusplus +// ENUM_FLAG_OPERATORS +// Define operator overloads to enable bit operations on enum values that are +// used to define flags. Use DEFINE_ENUM_FLAG_OPERATORS(YOUR_TYPE) to enable these +// operators on YOUR_TYPE. +extern "C++" { + template + struct _ENUM_FLAG_INTEGER_FOR_SIZE; + + template <> + struct _ENUM_FLAG_INTEGER_FOR_SIZE<1> + { + typedef int8_t type; + }; + + template <> + struct _ENUM_FLAG_INTEGER_FOR_SIZE<2> + { + typedef int16_t type; + }; + + template <> + struct _ENUM_FLAG_INTEGER_FOR_SIZE<4> + { + typedef int32_t type; + }; + + template <> + struct _ENUM_FLAG_INTEGER_FOR_SIZE<8> + { + typedef int64_t type; + }; + + // used as an approximation of std::underlying_type + template + struct _ENUM_FLAG_SIZED_INTEGER + { + typedef typename _ENUM_FLAG_INTEGER_FOR_SIZE::type type; + }; + +} +#define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) \ +extern "C++" { \ +inline constexpr ENUMTYPE operator | (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER::type)a) | ((_ENUM_FLAG_SIZED_INTEGER::type)b)); } \ +inline ENUMTYPE &operator |= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER::type &)a) |= ((_ENUM_FLAG_SIZED_INTEGER::type)b)); } \ +inline constexpr ENUMTYPE operator & (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER::type)a) & ((_ENUM_FLAG_SIZED_INTEGER::type)b)); } \ +inline ENUMTYPE &operator &= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER::type &)a) &= ((_ENUM_FLAG_SIZED_INTEGER::type)b)); } \ +inline constexpr ENUMTYPE operator ~ (ENUMTYPE a) { return ENUMTYPE(~((_ENUM_FLAG_SIZED_INTEGER::type)a)); } \ +inline constexpr ENUMTYPE operator ^ (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER::type)a) ^ ((_ENUM_FLAG_SIZED_INTEGER::type)b)); } \ +inline ENUMTYPE &operator ^= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER::type &)a) ^= ((_ENUM_FLAG_SIZED_INTEGER::type)b)); } \ +} +#else +#define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) /* */ +#endif + +// D3DX12 uses these +#include +#define HeapAlloc(heap, flags, size) malloc(size) +#define HeapFree(heap, flags, ptr) free(ptr) + +#if defined(lint) +// Note: lint -e530 says don't complain about uninitialized variables for +// this variable. Error 527 has to do with unreachable code. +// -restore restores checking to the -save state +#define UNREFERENCED_PARAMETER(P) \ + /*lint -save -e527 -e530 */ \ + { \ + (P) = (P); \ + } \ + /*lint -restore */ +#else +#define UNREFERENCED_PARAMETER(P) (P) +#endif diff --git a/include/wsl/stubs/rpcndr.h b/include/wsl/stubs/rpcndr.h index db3ca74..68aa390 100644 --- a/include/wsl/stubs/rpcndr.h +++ b/include/wsl/stubs/rpcndr.h @@ -3,6 +3,9 @@ // Stub header to satisfy d3d12.h include #pragma once + +#include "basetsd.h" + #define __RPCNDR_H_VERSION__ #ifdef CONST_VTABLE @@ -10,3 +13,66 @@ #else #define CONST_VTBL #endif + +/* Macros for __uuidof template-based emulation */ +#if defined(__cplusplus) +#if __cpp_constexpr >= 200704l && __cpp_inline_variables >= 201606L +#define __wsl_stub_uuidof_use_constexpr 1 +#else +#define __wsl_stub_uuidof_use_constexpr 0 +#endif +#ifndef __GNUC__ +#error "Only support for compilers that support for `GNU C++ extension`" +#endif +extern "C++" { +#if __wsl_stub_uuidof_use_constexpr + __extension__ template struct __wsl_stub_uuidof_s; + __extension__ template constexpr const GUID &__wsl_stub_uuidof(); +#else + __extension__ template const GUID &__wsl_stub_uuidof(); +#endif +} + +#if __wsl_stub_uuidof_use_constexpr +#define __CRT_UUID_DECL(type, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ + extern "C++" \ + { \ + template <> \ + struct __wsl_stub_uuidof_s \ + { \ + static constexpr IID __uuid_inst = { \ + l, w1, w2, {b1, b2, b3, b4, b5, b6, b7, b8}}; \ + }; \ + template <> \ + constexpr const GUID &__wsl_stub_uuidof() \ + { \ + return __wsl_stub_uuidof_s::__uuid_inst; \ + } \ + template <> \ + constexpr const GUID &__wsl_stub_uuidof() \ + { \ + return __wsl_stub_uuidof_s::__uuid_inst; \ + } \ + } +#else +#define __CRT_UUID_DECL(type, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ + extern "C++" \ + { \ + template <> \ + inline const GUID &__wsl_stub_uuidof() \ + { \ + static const IID __uuid_inst = { \ + l, w1, w2, {b1, b2, b3, b4, b5, b6, b7, b8}}; \ + return __uuid_inst; \ + } \ + template <> \ + inline const GUID &__wsl_stub_uuidof() \ + { \ + return __wsl_stub_uuidof(); \ + } \ + } +#endif +#define __uuidof(type) __wsl_stub_uuidof<__typeof(type)>() +#else +#define __CRT_UUID_DECL(type, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) +#endif diff --git a/include/wsl/stubs/unknwnbase.h b/include/wsl/stubs/unknwnbase.h index 3f29404..5c546f2 100644 --- a/include/wsl/stubs/unknwnbase.h +++ b/include/wsl/stubs/unknwnbase.h @@ -77,7 +77,7 @@ extern "C++" STDMETHODCALLTYPE QueryInterface(_COM_Outptr_ Q * *pp) { - return QueryInterface(uuidof(), (void **)pp); + return QueryInterface(__uuidof(Q), (void **)pp); } END_INTERFACE }; diff --git a/include/wsl/winadapter.h b/include/wsl/winadapter.h index 960b386..ccb2b3c 100644 --- a/include/wsl/winadapter.h +++ b/include/wsl/winadapter.h @@ -3,419 +3,4 @@ #pragma once -// These #defines prevent the idl-generated headers from trying to include -// Windows.h from the SDK rather than this one. -#define RPC_NO_WINDOWS_H -#define COM_NO_WINDOWS_H - -// Allcaps type definitions -#include -#include -#include -#include - -// Note: using fixed-width here to match Windows widths -// Specifically this is different for 'long' vs 'LONG' -typedef uint8_t UINT8; -typedef int8_t INT8; -typedef uint16_t UINT16; -typedef int16_t INT16; -typedef uint32_t UINT32, UINT, ULONG, DWORD, BOOL, WINBOOL; -typedef int32_t INT32, INT, LONG; -typedef uint64_t UINT64, ULONG_PTR; -typedef int64_t INT64, LONG_PTR; -typedef void VOID, *HANDLE, *RPC_IF_HANDLE, *LPVOID; -typedef const void *LPCVOID; -typedef size_t SIZE_T; -typedef float FLOAT; -typedef double DOUBLE; -typedef unsigned char BYTE; -typedef int HWND; -typedef int PALETTEENTRY; -typedef int HDC; -typedef uint16_t WORD; -typedef void* PVOID; -typedef char BOOLEAN; -typedef uint64_t ULONGLONG; -typedef uint16_t USHORT, *PUSHORT; -typedef int64_t LONGLONG, *PLONGLONG; -typedef int64_t LONG_PTR, *PLONG_PTR; -typedef int64_t LONG64, *PLONG64; -typedef uint64_t ULONG64, *PULONG64; -typedef wchar_t WCHAR, *PWSTR; -typedef uint8_t UCHAR, *PUCHAR; -typedef uint64_t ULONG_PTR, *PULONG_PTR; -typedef uint64_t UINT_PTR, *PUINT_PTR; -typedef int64_t INT_PTR, *PINT_PTR; - -// Note: WCHAR is not the same between Windows and Linux, to enable -// string manipulation APIs to work with resulting strings. -// APIs to D3D/DXCore will work on Linux wchars, but beware with -// interactions directly with the Windows kernel. -typedef char CHAR, *PSTR, *LPSTR, TCHAR, *PTSTR; -typedef const char *LPCSTR, *PCSTR, *LPCTSTR, *PCTSTR; -typedef wchar_t WCHAR, *PWSTR, *LPWSTR, *PWCHAR; -typedef const wchar_t *LPCWSTR, *PCWSTR; - -#undef LONG_MAX -#define LONG_MAX INT_MAX -#undef ULONG_MAX -#define ULONG_MAX UINT_MAX - -// Misc defines -#define MIDL_INTERFACE(x) interface -#define __analysis_assume(x) -#define TRUE 1u -#define FALSE 0u -#define DECLSPEC_UUID(x) -#define DECLSPEC_NOVTABLE -#define DECLSPEC_SELECTANY -#ifdef __cplusplus -#define EXTERN_C extern "C" -#else -#define EXTERN_C extern -#endif -#define APIENTRY -#define OUT -#define IN -#define CONST const -#define MAX_PATH 260 -#define GENERIC_ALL 0x10000000L -#define C_ASSERT(expr) static_assert((expr)) -#define _countof(a) (sizeof(a) / sizeof(*(a))) - -typedef struct tagRECTL -{ - LONG left; - LONG top; - LONG right; - LONG bottom; -} RECTL; - -typedef struct tagPOINT -{ - int x; - int y; -} POINT; - -typedef struct _GUID { - uint32_t Data1; - uint16_t Data2; - uint16_t Data3; - uint8_t Data4[ 8 ]; -} GUID; - -#ifdef __cplusplus -template GUID uuidof() = delete; -template GUID uuidof(T*) { return uuidof(); } -template GUID uuidof(T**) { return uuidof(); } -template GUID uuidof(T&) { return uuidof(); } -#define __uuidof(x) uuidof(x) -#endif - -#ifdef INITGUID -#ifdef __cplusplus -#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 } } -#else -#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 } } -#endif -#else -#define DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) EXTERN_C const GUID name -#endif - -typedef GUID IID; -typedef GUID UUID; -typedef GUID CLSID; -#ifdef __cplusplus -#define REFGUID const GUID & -#define REFIID const IID & -#define REFCLSID const IID & - -__inline int InlineIsEqualGUID(REFGUID rguid1, REFGUID rguid2) -{ - return ( - ((uint32_t *)&rguid1)[0] == ((uint32_t *)&rguid2)[0] && - ((uint32_t *)&rguid1)[1] == ((uint32_t *)&rguid2)[1] && - ((uint32_t *)&rguid1)[2] == ((uint32_t *)&rguid2)[2] && - ((uint32_t *)&rguid1)[3] == ((uint32_t *)&rguid2)[3]); -} - -inline bool operator==(REFGUID guidOne, REFGUID guidOther) -{ - return !!InlineIsEqualGUID(guidOne, guidOther); -} - -inline bool operator!=(REFGUID guidOne, REFGUID guidOther) -{ - return !(guidOne == guidOther); -} - -#else -#define REFGUID const GUID * -#define REFIID const IID * -#define REFCLSID const IID * -#endif - -// SAL annotations -#define _In_ -#define _In_z_ -#define _In_opt_ -#define _In_opt_z_ -#define _In_reads_(x) -#define _In_reads_opt_(x) -#define _In_reads_bytes_(x) -#define _In_reads_bytes_opt_(x) -#define _In_range_(x, y) -#define _In_bytecount_(x) -#define _Out_ -#define _Out_opt_ -#define _Outptr_ -#define _Outptr_opt_result_z_ -#define _Outptr_opt_result_bytebuffer_(x) -#define _COM_Outptr_ -#define _COM_Outptr_result_maybenull_ -#define _COM_Outptr_opt_ -#define _COM_Outptr_opt_result_maybenull_ -#define _Out_writes_(x) -#define _Out_writes_z_(x) -#define _Out_writes_opt_(x) -#define _Out_writes_all_(x) -#define _Out_writes_all_opt_(x) -#define _Out_writes_to_opt_(x, y) -#define _Out_writes_bytes_(x) -#define _Out_writes_bytes_all_(x) -#define _Out_writes_bytes_all_opt_(x) -#define _Out_writes_bytes_opt_(x) -#define _Inout_ -#define _Inout_opt_ -#define _Inout_updates_(x) -#define _Inout_updates_bytes_(x) -#define _Field_size_(x) -#define _Field_size_opt_(x) -#define _Field_size_bytes_(x) -#define _Field_size_full_(x) -#define _Field_size_full_opt_(x) -#define _Field_size_bytes_full_(x) -#define _Field_size_bytes_full_opt_(x) -#define _Field_size_bytes_part_(x, y) -#define _Field_range_(x, y) -#define _Field_z_ -#define _Check_return_ -#define _IRQL_requires_(x) -#define _IRQL_requires_min_(x) -#define _IRQL_requires_max_(x) -#define _At_(x, y) -#define _Always_(x) -#define _Return_type_success_(x) -#define _Translates_Win32_to_HRESULT_(x) -#define _Maybenull_ -#define _Outptr_result_maybenull_ -#define _Outptr_result_nullonfailure_ -#define _Analysis_assume_(x) -#define _Success_(x) -#define _In_count_(x) -#define _In_opt_count_(x) -#define _Use_decl_annotations_ - -// Calling conventions -#define __cdecl -#define __stdcall -#define STDMETHODCALLTYPE -#define STDAPICALLTYPE -#define STDAPI EXTERN_C HRESULT STDAPICALLTYPE -#define WINAPI - -#define interface struct -#if defined (__cplusplus) && !defined (CINTERFACE) -#define STDMETHOD(method) virtual HRESULT STDMETHODCALLTYPE method -#define STDMETHOD_(type, method) virtual type STDMETHODCALLTYPE method -#define PURE = 0 -#define THIS_ -#define THIS void -#define DECLARE_INTERFACE(iface) interface DECLSPEC_NOVTABLE iface -#define DECLARE_INTERFACE_(iface, baseiface) interface DECLSPEC_NOVTABLE iface : public baseiface - -interface IUnknown; -extern "C++" -{ - template void** IID_PPV_ARGS_Helper(T** pp) - { - static_cast(*pp); - return reinterpret_cast(pp); - } -} -#define IID_PPV_ARGS(ppType) __uuidof (**(ppType)), IID_PPV_ARGS_Helper (ppType) -#else -#define STDMETHOD(method) HRESULT (STDMETHODCALLTYPE *method) -#define STDMETHOD_(type, method) type (STDMETHODCALLTYPE *method) -#define PURE -#define THIS_ INTERFACE *This, -#define THIS INTERFACE *This -#ifdef CONST_VTABLE -#define DECLARE_INTERFACE(iface) typedef interface iface { const struct iface##Vtbl *lpVtbl; } iface; typedef const struct iface##Vtbl iface##Vtbl; const struct iface##Vtbl -#else -#define DECLARE_INTERFACE(iface) typedef interface iface { struct iface##Vtbl *lpVtbl; } iface; typedef struct iface##Vtbl iface##Vtbl; struct iface##Vtbl -#endif -#define DECLARE_INTERFACE_(iface, baseiface) DECLARE_INTERFACE (iface) -#endif - -#define IFACEMETHOD(method) /*override*/ STDMETHOD (method) -#define IFACEMETHOD_(type, method) /*override*/ STDMETHOD_(type, method) -#ifndef BEGIN_INTERFACE -#define BEGIN_INTERFACE -#define END_INTERFACE -#endif - -// Error codes -typedef LONG HRESULT; -#define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0) -#define FAILED(hr) (((HRESULT)(hr)) < 0) -#define S_OK ((HRESULT)0L) -#define S_FALSE ((HRESULT)1L) -#define E_NOTIMPL ((HRESULT)0x80004001L) -#define E_OUTOFMEMORY ((HRESULT)0x8007000EL) -#define E_INVALIDARG ((HRESULT)0x80070057L) -#define E_NOINTERFACE ((HRESULT)0x80004002L) -#define E_POINTER ((HRESULT)0x80004003L) -#define E_HANDLE ((HRESULT)0x80070006L) -#define E_ABORT ((HRESULT)0x80004004L) -#define E_FAIL ((HRESULT)0x80004005L) -#define E_ACCESSDENIED ((HRESULT)0x80070005L) -#define E_UNEXPECTED ((HRESULT)0x8000FFFFL) -#define DXGI_ERROR_INVALID_CALL ((HRESULT)0x887A0001L) -#define DXGI_ERROR_NOT_FOUND ((HRESULT)0x887A0002L) -#define DXGI_ERROR_MORE_DATA ((HRESULT)0x887A0003L) -#define DXGI_ERROR_UNSUPPORTED ((HRESULT)0x887A0004L) -#define DXGI_ERROR_DEVICE_REMOVED ((HRESULT)0x887A0005L) -#define DXGI_ERROR_DEVICE_HUNG ((HRESULT)0x887A0006L) -#define DXGI_ERROR_DEVICE_RESET ((HRESULT)0x887A0007L) -#define DXGI_ERROR_DRIVER_INTERNAL_ERROR ((HRESULT)0x887A0020L) - -typedef struct _LUID -{ - ULONG LowPart; - LONG HighPart; -} LUID; - -typedef struct _RECT -{ - int left; - int top; - int right; - int bottom; -} RECT; - -typedef union _LARGE_INTEGER { - struct { - uint32_t LowPart; - uint32_t HighPart; - } u; - int64_t QuadPart; -} LARGE_INTEGER; -typedef LARGE_INTEGER *PLARGE_INTEGER; - -typedef union _ULARGE_INTEGER { - struct { - uint32_t LowPart; - uint32_t HighPart; - } u; - uint64_t QuadPart; -} ULARGE_INTEGER; -typedef ULARGE_INTEGER *PULARGE_INTEGER; - -#define DECLARE_HANDLE(name) \ - struct name##__ { \ - int unused; \ - }; \ - typedef struct name##__ *name - -typedef struct _SECURITY_ATTRIBUTES { - DWORD nLength; - LPVOID lpSecurityDescriptor; - WINBOOL bInheritHandle; -} SECURITY_ATTRIBUTES; - -struct STATSTG; - -#ifdef __cplusplus -// ENUM_FLAG_OPERATORS -// Define operator overloads to enable bit operations on enum values that are -// used to define flags. Use DEFINE_ENUM_FLAG_OPERATORS(YOUR_TYPE) to enable these -// operators on YOUR_TYPE. -extern "C++" { - template - struct _ENUM_FLAG_INTEGER_FOR_SIZE; - - template <> - struct _ENUM_FLAG_INTEGER_FOR_SIZE<1> - { - typedef int8_t type; - }; - - template <> - struct _ENUM_FLAG_INTEGER_FOR_SIZE<2> - { - typedef int16_t type; - }; - - template <> - struct _ENUM_FLAG_INTEGER_FOR_SIZE<4> - { - typedef int32_t type; - }; - - template <> - struct _ENUM_FLAG_INTEGER_FOR_SIZE<8> - { - typedef int64_t type; - }; - - // used as an approximation of std::underlying_type - template - struct _ENUM_FLAG_SIZED_INTEGER - { - typedef typename _ENUM_FLAG_INTEGER_FOR_SIZE::type type; - }; - -} -#define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) \ -extern "C++" { \ -inline constexpr ENUMTYPE operator | (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER::type)a) | ((_ENUM_FLAG_SIZED_INTEGER::type)b)); } \ -inline ENUMTYPE &operator |= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER::type &)a) |= ((_ENUM_FLAG_SIZED_INTEGER::type)b)); } \ -inline constexpr ENUMTYPE operator & (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER::type)a) & ((_ENUM_FLAG_SIZED_INTEGER::type)b)); } \ -inline ENUMTYPE &operator &= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER::type &)a) &= ((_ENUM_FLAG_SIZED_INTEGER::type)b)); } \ -inline constexpr ENUMTYPE operator ~ (ENUMTYPE a) { return ENUMTYPE(~((_ENUM_FLAG_SIZED_INTEGER::type)a)); } \ -inline constexpr ENUMTYPE operator ^ (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER::type)a) ^ ((_ENUM_FLAG_SIZED_INTEGER::type)b)); } \ -inline ENUMTYPE &operator ^= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER::type &)a) ^= ((_ENUM_FLAG_SIZED_INTEGER::type)b)); } \ -} -#else -#define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) /* */ -#endif - -// D3DX12 uses these -#include -#define HeapAlloc(heap, flags, size) malloc(size) -#define HeapFree(heap, flags, ptr) free(ptr) - -#if defined(lint) -// Note: lint -e530 says don't complain about uninitialized variables for -// this variable. Error 527 has to do with unreachable code. -// -restore restores checking to the -save state -#define UNREFERENCED_PARAMETER(P) \ - /*lint -save -e527 -e530 */ \ - { \ - (P) = (P); \ - } \ - /*lint -restore */ -#else -#define UNREFERENCED_PARAMETER(P) (P) -#endif - #include - -#if defined(__cplusplus) && !defined(CINTERFACE) -template <> constexpr GUID uuidof() -{ - return { 0x00000000, 0x0000, 0x0000, { 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } }; -} -#endif diff --git a/include/wsl/wrladapter.h b/include/wsl/wrladapter.h index f9138a0..fcfd894 100644 --- a/include/wsl/wrladapter.h +++ b/include/wsl/wrladapter.h @@ -320,7 +320,7 @@ namespace WRL (std::is_same::value) && !std::is_same::value, void *>::type * = 0) const throw() { - return ptr_->QueryInterface(uuidof(), ptr); + return ptr_->QueryInterface(__uuidof(U), ptr); } HRESULT CopyTo(_Outptr_result_maybenull_ InterfaceType** ptr) const throw() @@ -338,21 +338,21 @@ namespace WRL template HRESULT CopyTo(_Outptr_result_nullonfailure_ U** ptr) const throw() { - return ptr_->QueryInterface(uuidof(), reinterpret_cast(ptr)); + return ptr_->QueryInterface(__uuidof(U), reinterpret_cast(ptr)); } // query for U interface template HRESULT As(_Inout_ Details::ComPtrRef> p) const throw() { - return ptr_->QueryInterface(uuidof(), p); + return ptr_->QueryInterface(__uuidof(U), p); } // query for U interface template HRESULT As(_Out_ ComPtr* p) const throw() { - return ptr_->QueryInterface(uuidof(), reinterpret_cast(p->ReleaseAndGetAddressOf())); + return ptr_->QueryInterface(__uuidof(U), reinterpret_cast(p->ReleaseAndGetAddressOf())); } // query for riid interface and return as IUnknown @@ -385,7 +385,7 @@ namespace WRL *ppvObject = nullptr; bool isRefDelegated = false; // Prefer InlineIsEqualGUID over other forms since it's better perf on 4-byte aligned data, which is almost always the case. - if (InlineIsEqualGUID(riid, uuidof())) + if (InlineIsEqualGUID(riid, __uuidof(IUnknown))) { *ppvObject = implements->CastToUnknown(); static_cast(*ppvObject)->AddRef(); @@ -439,7 +439,7 @@ namespace WRL static bool CanCastTo(_In_ T* ptr, REFIID riid, _Outptr_ void **ppv) noexcept { // Prefer InlineIsEqualGUID over other forms since it's better perf on 4-byte aligned data, which is almost always the case. - if (InlineIsEqualGUID(riid, uuidof())) + if (InlineIsEqualGUID(riid, __uuidof(Base))) { *ppv = static_cast(ptr); return true; @@ -553,7 +553,7 @@ namespace WRL HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv, bool *pRefDelegated = nullptr) noexcept { // Prefer InlineIsEqualGUID over other forms since it's better perf on 4-byte aligned data, which is almost always the case. - if (InlineIsEqualGUID(riid, uuidof())) + if (InlineIsEqualGUID(riid, __uuidof(I0))) { *ppv = reinterpret_cast(reinterpret_cast(this)); return S_OK; diff --git a/src/dxguids.cpp b/src/dxguids.cpp index e4dd2d5..cff98f4 100644 --- a/src/dxguids.cpp +++ b/src/dxguids.cpp @@ -4,9 +4,7 @@ // This file's sole purpose is to initialize the GUIDs declared using the DEFINE_GUID macro. #define INITGUID -#ifndef _WIN32 #include -#endif #include #include diff --git a/test/feature_check_test.cpp b/test/feature_check_test.cpp index 8266659..6332a2b 100644 --- a/test/feature_check_test.cpp +++ b/test/feature_check_test.cpp @@ -1,11 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -#ifndef _WIN32 #include -#elif defined(__MINGW32__) -#include -#endif #include #include diff --git a/test/test.cpp b/test/test.cpp index 82b61e7..c18382f 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -1,11 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -#ifndef _WIN32 #include -#elif defined(__MINGW32__) -#include -#endif #include #include