diff --git a/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs index 0e1f8430..7c4df69a 100644 --- a/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs +++ b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs @@ -3,6 +3,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using TerraFX.Interop; using TerraFX.Interop.Windows; +using TerraFX.Interop.WinRT; #pragma warning disable CS0649, IDE1006 @@ -55,9 +56,9 @@ internal unsafe struct ICanvasFactoryNative [MethodImpl(MethodImplOptions.AggressiveInlining)] [VtblIndex(6)] [return: NativeTypeName("ULONG")] - public HRESULT GetOrCreate(ICanvasDevice* device, IUnknown* resource, float dpi, [NativeTypeName("IInspectable**")] void** wrapper) + public HRESULT GetOrCreate(ICanvasDevice* device, IUnknown* resource, float dpi, IInspectable** wrapper) { - return ((delegate* unmanaged[Stdcall])this.lpVtbl[6])( + return ((delegate* unmanaged[Stdcall])this.lpVtbl[6])( (ICanvasFactoryNative*)Unsafe.AsPointer(ref this), device, resource, diff --git a/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/Inspectable/IInspectable.cs b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/Inspectable/IInspectable.cs new file mode 100644 index 00000000..12fb85bc --- /dev/null +++ b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/Inspectable/IInspectable.cs @@ -0,0 +1,50 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +// Ported from winrt/inspectable.h in the Windows SDK for Windows 10.0.22621.0 +// Original source is Copyright © Microsoft. All rights reserved. + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using TerraFX.Interop.Windows; + +#pragma warning disable CS0649, IDE1006 + +namespace TerraFX.Interop.WinRT; + +/// +/// The native WinRT interface for IInspectable objects. +/// +[Guid("AF86E2E0-B12D-4C6A-9C5A-D7AA65101E90")] +[NativeTypeName("struct IInspectable : IUnknown")] +[NativeInheritance("IUnknown")] +internal unsafe struct IInspectable +{ + public void** lpVtbl; + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [VtblIndex(0)] + public HRESULT QueryInterface([NativeTypeName("const IID &")] Guid* riid, void** ppvObject) + { + return ((delegate* unmanaged[Stdcall])this.lpVtbl[0])((IInspectable*)Unsafe.AsPointer(ref this), riid, ppvObject); + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [VtblIndex(1)] + [return: NativeTypeName("ULONG")] + public uint AddRef() + { + return ((delegate* unmanaged[Stdcall])this.lpVtbl[1])((IInspectable*)Unsafe.AsPointer(ref this)); + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [VtblIndex(2)] + [return: NativeTypeName("ULONG")] + public uint Release() + { + return ((delegate* unmanaged[Stdcall])this.lpVtbl[2])((IInspectable*)Unsafe.AsPointer(ref this)); + } +} \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.UI/ComputeSharp.D2D1.UI.projitems b/src/ComputeSharp.D2D1.UI/ComputeSharp.D2D1.UI.projitems index 086fc849..7d30c6fc 100644 --- a/src/ComputeSharp.D2D1.UI/ComputeSharp.D2D1.UI.projitems +++ b/src/ComputeSharp.D2D1.UI/ComputeSharp.D2D1.UI.projitems @@ -18,6 +18,7 @@ + diff --git a/src/ComputeSharp.D2D1.UI/Helpers/ResourceManager.cs b/src/ComputeSharp.D2D1.UI/Helpers/ResourceManager.cs index 798354a8..efc9b107 100644 --- a/src/ComputeSharp.D2D1.UI/Helpers/ResourceManager.cs +++ b/src/ComputeSharp.D2D1.UI/Helpers/ResourceManager.cs @@ -56,16 +56,16 @@ internal static class ResourceManager factory: canvasFactoryNative.GetVoidAddressOf()).Assert(); } - using ComPtr wrapperUnknown = default; + using ComPtr wrapperInspectable = default; // Get or create a WinRT wrapper for the resource canvasFactoryNative.Get()->GetOrCreate( device: device, resource: resource, dpi: dpi, - wrapper: wrapperUnknown.GetVoidAddressOf()).Assert(); + wrapper: wrapperInspectable.GetAddressOf()).Assert(); // Get the runtime-provided RCW for the resulting WinRT wrapper - return RcwMarshaller.GetOrCreateManagedObject(wrapperUnknown.Get()); + return RcwMarshaller.GetOrCreateManagedObject((IUnknown*)wrapperInspectable.Get()); } }