diff --git a/src/ComputeSharp.D2D1.Uwp/Extensions/IUnknownExtensions.cs b/src/ComputeSharp.D2D1.Uwp/Extensions/IUnknownExtensions.cs
index 8b1e1b0c..11610412 100644
--- a/src/ComputeSharp.D2D1.Uwp/Extensions/IUnknownExtensions.cs
+++ b/src/ComputeSharp.D2D1.Uwp/Extensions/IUnknownExtensions.cs
@@ -8,7 +8,7 @@ namespace ComputeSharp.D2D1.Uwp.Extensions;
///
/// Helper methods for working with the type.
///
-internal static class IUnknownExtensions
+internal static unsafe class IUnknownExtensions
{
///
/// Checks whether two values have the same underlying COM object.
@@ -18,7 +18,7 @@ internal static class IUnknownExtensions
/// The first object to compare.
/// The second object to compare.
/// Whether and point to the same COM object.
- public static unsafe bool IsSameInstance(this ref T left, U* right)
+ public static bool IsSameInstance(this ref T left, U* right)
where T : unmanaged // IUnknown
where U : unmanaged // IUnknown
{
@@ -40,4 +40,18 @@ internal static class IUnknownExtensions
return leftUnknown.Get() == rightUnknown.Get();
}
+
+ ///
+ /// Copies the source object onto a target destination.
+ ///
+ /// The type of object being copied.
+ /// The source object.
+ /// The destination location.
+ public static void CopyTo(this ref T source, ref ComPtr destination)
+ where T : unmanaged // IUnknown
+ {
+ destination.Dispose();
+
+ destination = new ComPtr((T*)Unsafe.AsPointer(ref source));
+ }
}
\ No newline at end of file
diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasImageInterop.cs b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasImageInterop.cs
index c9056ade..8e3ab29e 100644
--- a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasImageInterop.cs
+++ b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasImageInterop.cs
@@ -12,7 +12,6 @@ using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
using Windows.Graphics.Effects;
using static ABI.Microsoft.Graphics.Canvas.WIN2D_GET_D2D_IMAGE_FLAGS;
-using Win32 = TerraFX.Interop.Windows.Windows;
namespace ComputeSharp.D2D1.Uwp;
@@ -117,11 +116,7 @@ unsafe partial class PixelShaderEffect
// Store the input realization device and canvas device for future uses
d2D1Device1.CopyTo(ref this.d2D1RealizationDevice).Assert();
-
- fixed (ICanvasDevice** canvasDevice = this.canvasDevice)
- {
- device->QueryInterface(Win32.__uuidof(), (void**)canvasDevice).Assert();
- }
+ device->CopyTo(ref this.canvasDevice);
}
// Create the effect, if it doesn't exist already