From c86b198b467ff4ebf5329d49b53a9604163b43ee Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 16 Apr 2023 18:09:35 +0200 Subject: [PATCH] Stop using built-in COM interop in D2D1 sample --- .../ICanvasFactoryNative.cs | 21 +++++++++++++++---- .../Backend/Win32Application.cs | 3 +-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/samples/ComputeSharp.SwapChain.D2D1/Backend/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs b/samples/ComputeSharp.SwapChain.D2D1/Backend/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs index ba7a363a..c5bd740f 100644 --- a/samples/ComputeSharp.SwapChain.D2D1/Backend/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs +++ b/samples/ComputeSharp.SwapChain.D2D1/Backend/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs @@ -1,8 +1,10 @@ +using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using TerraFX.Interop.Windows; using TerraFX.Interop; -using System; +using WinRT; +using WinRT.Interop; #pragma warning disable CS0649, IDE1006 @@ -79,12 +81,23 @@ internal unsafe struct ICanvasFactoryNative : IUnknown.Interface } /// - /// The COM import interface for . + /// The managed interface for . /// [Guid("695C440D-04B3-4EDD-BFD9-63E51E9F7202")] - [ComImport] - [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [WindowsRuntimeType] + [WindowsRuntimeHelperType(typeof(Interface))] public interface Interface { + /// + /// The vtable type for . + /// + [Guid("695C440D-04B3-4EDD-BFD9-63E51E9F7202")] + public readonly struct Vftbl + { + /// + /// Allows CsWinRT to retrieve a pointer to the projection vtable (the name is hardcoded by convention). + /// + public static readonly IntPtr AbiToProjectionVftablePtr = IUnknownVftbl.AbiToProjectionVftblPtr; + } } } \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.D2D1/Backend/Win32Application.cs b/samples/ComputeSharp.SwapChain.D2D1/Backend/Win32Application.cs index c100ad18..18378ed5 100644 --- a/samples/ComputeSharp.SwapChain.D2D1/Backend/Win32Application.cs +++ b/samples/ComputeSharp.SwapChain.D2D1/Backend/Win32Application.cs @@ -1,6 +1,5 @@ using System; using System.Diagnostics.CodeAnalysis; -using System.Runtime.InteropServices; using ABI.Microsoft.Graphics.Canvas; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; @@ -122,7 +121,7 @@ internal sealed class Win32Application { ICanvasFactoryNative.Interface canvasDeviceActivationFactory = CanvasDevice.As(); - canvasFactoryNativeUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(canvasDeviceActivationFactory)); + canvasFactoryNativeUnknown.Attach((IUnknown*)MarshalInterface.FromManaged(canvasDeviceActivationFactory)); hresult = canvasFactoryNativeUnknown.CopyTo(canvasFactoryNative.GetAddressOf());