diff --git a/tests/ComputeSharp.D2D1.WinUI.Tests/Helpers/Win2DHelper.cs b/tests/ComputeSharp.D2D1.WinUI.Tests/Helpers/Win2DHelper.cs
index 98f09388..e1900cbf 100644
--- a/tests/ComputeSharp.D2D1.WinUI.Tests/Helpers/Win2DHelper.cs
+++ b/tests/ComputeSharp.D2D1.WinUI.Tests/Helpers/Win2DHelper.cs
@@ -4,7 +4,6 @@ using Microsoft.Graphics.Canvas;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
using WinRT;
-using WinRT.Interop;
namespace ComputeSharp.D2D1.WinUI.Tests.Helpers;
@@ -21,20 +20,15 @@ internal static class Win2DHelper
/// The resulting managed wrapper for .
public static unsafe object GetOrCreate(ID2D1Image* d2D1Image, CanvasDevice? canvasDevice = null)
{
- using ComPtr activationFactoryUnknown = default;
-
- ICanvasFactoryNative activationFactory = CanvasDevice.As();
-
- activationFactoryUnknown.Attach((IUnknown*)MarshalInterface.FromManaged(activationFactory));
-
using ComPtr canvasFactoryNativeUnknown = default;
- Guid uuidOfCanvasFactoryNativeUnknown = new("695C440D-04B3-4EDD-BFD9-63E51E9F7202");
-
- //Get the ICanvasFactoryNative object
- int hresult = activationFactoryUnknown.CopyTo(&uuidOfCanvasFactoryNativeUnknown, (void**)canvasFactoryNativeUnknown.GetAddressOf());
-
- Marshal.ThrowExceptionForHR(hresult);
+ // Get the ICanvasFactoryNative object
+ using (IObjectReference canvasDeviceActivationFactory = ActivationFactory.Get(
+ typeName: "Microsoft.Graphics.Canvas.CanvasDevice",
+ iid: new Guid("695C440D-04B3-4EDD-BFD9-63E51E9F7202")))
+ {
+ canvasFactoryNativeUnknown.Attach((IUnknown*)canvasDeviceActivationFactory.GetRef());
+ }
using ComPtr canvasDeviceUnknown = default;
@@ -43,6 +37,8 @@ internal static class Win2DHelper
canvasDeviceUnknown.Attach((IUnknown*)MarshalInspectable.FromManaged(canvasDevice));
}
+ int hresult;
+
using ComPtr canvasDeviceInterfaceUnknown = default;
if (canvasDevice is not null)
@@ -51,6 +47,8 @@ internal static class Win2DHelper
// Get the ICanvasDevice object (as an IUnknown* as well)
hresult = canvasDeviceUnknown.CopyTo(&uuidOfCanvasDeviceInterface, (void**)canvasDeviceInterfaceUnknown.GetAddressOf());
+
+ Marshal.ThrowExceptionForHR(hresult);
}
using ComPtr wrapperUnknown = default;
@@ -115,25 +113,4 @@ internal static class Win2DHelper
Marshal.ThrowExceptionForHR(hresult);
}
-
- ///
- /// The managed interface for .
- ///
- [Guid("695C440D-04B3-4EDD-BFD9-63E51E9F7202")]
- [WindowsRuntimeType]
- [WindowsRuntimeHelperType(typeof(ICanvasFactoryNative))]
- public interface ICanvasFactoryNative
- {
- ///
- /// 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