From 0cacfe7a2d392ff847213cdd7a3dec6690d68f0f Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 26 Jan 2024 01:29:22 +0100 Subject: [PATCH] Also use ActivationFactory.Get() in Win2D CLI sample --- .../ICanvasFactoryNative.cs | 23 ------------------- .../Backend/Win32Application.cs | 12 ++++------ 2 files changed, 4 insertions(+), 31 deletions(-) diff --git a/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs b/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs index a137a438..49bfa283 100644 --- a/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs +++ b/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs @@ -3,8 +3,6 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using TerraFX.Interop.Windows; using TerraFX.Interop; -using WinRT; -using WinRT.Interop; #pragma warning disable CS0649, IDE0055, IDE1006 @@ -79,25 +77,4 @@ internal unsafe struct ICanvasFactoryNative : IUnknown.Interface dpi, wrapper); } - - /// - /// The managed interface for . - /// - [Guid("695C440D-04B3-4EDD-BFD9-63E51E9F7202")] - [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.Cli/Backend/Win32Application.cs b/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/Win32Application.cs index 3f3d5a79..4eef52a2 100644 --- a/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/Win32Application.cs +++ b/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/Win32Application.cs @@ -117,15 +117,11 @@ internal sealed class Win32Application using ComPtr canvasFactoryNative = default; // Get the activation factory for CanvasDevice - using (ComPtr canvasFactoryNativeUnknown = default) + using (IObjectReference canvasDeviceActivationFactory = ActivationFactory.Get( + typeName: "Microsoft.Graphics.Canvas.CanvasDevice", + iid: Windows.__uuidof())) { - ICanvasFactoryNative.Interface canvasDeviceActivationFactory = CanvasDevice.As(); - - canvasFactoryNativeUnknown.Attach((IUnknown*)MarshalInterface.FromManaged(canvasDeviceActivationFactory)); - - hresult = canvasFactoryNativeUnknown.CopyTo(canvasFactoryNative.GetAddressOf()); - - ExceptionHelpers.ThrowExceptionForHR(hresult); + canvasFactoryNative.Attach((ICanvasFactoryNative*)canvasDeviceActivationFactory.GetRef()); } // Create a Win2D wrapper for the swapchain