diff --git a/src/ComputeSharp.Win32.D2D1/ComputeSharp.Win32.D2D1.projitems b/src/ComputeSharp.Win32.D2D1/ComputeSharp.Win32.D2D1.projitems
index 0a1d313a..11abcfc6 100644
--- a/src/ComputeSharp.Win32.D2D1/ComputeSharp.Win32.D2D1.projitems
+++ b/src/ComputeSharp.Win32.D2D1/ComputeSharp.Win32.D2D1.projitems
@@ -57,6 +57,7 @@
+
diff --git a/src/ComputeSharp.Win32.D3D12/ComPtr`1.cs b/src/ComputeSharp.Win32.D3D12/ComPtr`1.cs
index 319b21e0..d169d455 100644
--- a/src/ComputeSharp.Win32.D3D12/ComPtr`1.cs
+++ b/src/ComputeSharp.Win32.D3D12/ComPtr`1.cs
@@ -87,7 +87,7 @@ internal unsafe struct ComPtr : IDisposable
/// The target raw pointer to copy the address of the current COM object to.
/// The result of for the target type .
public readonly HRESULT CopyTo(U** ptr)
- where U : unmanaged
+ where U : unmanaged, IComObject
{
return ((IUnknown*)ptr_)->QueryInterface(__uuidof(), (void**)ptr);
}
@@ -96,7 +96,7 @@ internal unsafe struct ComPtr : IDisposable
/// The target raw pointer to copy the address of the current COM object to.
/// The result of for the target type .
public readonly HRESULT CopyTo(ComPtr* p)
- where U : unmanaged
+ where U : unmanaged, IComObject
{
return ((IUnknown*)ptr_)->QueryInterface(__uuidof(), (void**)p->ReleaseAndGetAddressOf());
}
@@ -105,7 +105,7 @@ internal unsafe struct ComPtr : IDisposable
/// The target reference to copy the address of the current COM object to.
/// The result of for the target type .
public readonly HRESULT CopyTo(ref ComPtr other)
- where U : unmanaged
+ where U : unmanaged, IComObject
{
U* ptr;
HRESULT result = ((IUnknown*)ptr_)->QueryInterface(__uuidof(), (void**)&ptr);
diff --git a/src/ComputeSharp.Win32.D3D12/ComputeSharp.Win32.D3D12.projitems b/src/ComputeSharp.Win32.D3D12/ComputeSharp.Win32.D3D12.projitems
index 193d17bc..bba670be 100644
--- a/src/ComputeSharp.Win32.D3D12/ComputeSharp.Win32.D3D12.projitems
+++ b/src/ComputeSharp.Win32.D3D12/ComputeSharp.Win32.D3D12.projitems
@@ -215,6 +215,7 @@
+
diff --git a/src/ComputeSharp.Win32.D3D12/Windows/other/helper-types/IComObject.cs b/src/ComputeSharp.Win32.D3D12/Windows/other/helper-types/IComObject.cs
new file mode 100644
index 00000000..cc0adfd4
--- /dev/null
+++ b/src/ComputeSharp.Win32.D3D12/Windows/other/helper-types/IComObject.cs
@@ -0,0 +1,14 @@
+using System;
+
+namespace ComputeSharp.Win32;
+
+///
+/// An interface for a COM object, with a specific IID.
+///
+internal unsafe interface IComObject
+{
+ ///
+ /// Gets a pointer to the IID for the object type.
+ ///
+ static abstract Guid* IID { get; }
+}
\ No newline at end of file
diff --git a/src/ComputeSharp.Win32.D3D12/Windows/shared/uuids/Windows.Manual.cs b/src/ComputeSharp.Win32.D3D12/Windows/shared/uuids/Windows.Manual.cs
index 42b890d5..94eebd83 100644
--- a/src/ComputeSharp.Win32.D3D12/Windows/shared/uuids/Windows.Manual.cs
+++ b/src/ComputeSharp.Win32.D3D12/Windows/shared/uuids/Windows.Manual.cs
@@ -7,50 +7,28 @@ using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
-#pragma warning disable IDE1006
-
namespace ComputeSharp.Win32;
internal static partial class Windows
{
- /// Retrieves the GUID of of a specified type.
- /// A value of type .
- /// The type to retrieve the GUID for.
- /// A value wrapping a pointer to the GUID data for the input type. This value can be either converted to a pointer, or implicitly assigned to a value.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe UuidOfType __uuidof(T value) // for type inference similar to C++'s __uuidof
- where T : unmanaged
- {
- return new UuidOfType(UUID.RIID);
- }
-
- /// Retrieves the GUID of of a specified type.
- /// A pointer to a value of type .
- /// The type to retrieve the GUID for.
- /// A value wrapping a pointer to the GUID data for the input type. This value can be either converted to a pointer, or implicitly assigned to a value.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe UuidOfType __uuidof(T* value) // for type inference similar to C++'s __uuidof
- where T : unmanaged
- {
- return new UuidOfType(UUID.RIID);
- }
-
/// Retrieves the GUID of of a specified type.
/// The type to retrieve the GUID for.
/// A value wrapping a pointer to the GUID data for the input type. This value can be either converted to a pointer, or implicitly assigned to a value.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe UuidOfType __uuidof()
- where T : unmanaged
+ where T : unmanaged, IComObject
{
- return new UuidOfType(UUID.RIID);
+ return new UuidOfType(T.IID);
}
/// A proxy type that wraps a pointer to GUID data. Values of this type can be implicitly converted to and assigned to * or parameters.
[EditorBrowsable(EditorBrowsableState.Never)]
+
public readonly unsafe ref struct UuidOfType
{
private readonly Guid* riid;
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal UuidOfType(Guid* riid)
{
this.riid = riid;
@@ -58,29 +36,12 @@ internal static partial class Windows
/// Reads a value from the GUID buffer for a given instance.
/// The input instance to read data for.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator Guid(UuidOfType guid) => *guid.riid;
/// Returns the * pointer to the GUID buffer for a given instance.
/// The input instance to read data for.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator Guid*(UuidOfType guid) => guid.riid;
}
-
- /// A helper type to provide static GUID buffers for specific types.
- /// The type to allocate a GUID buffer for.
- private static unsafe class UUID
- where T : unmanaged
- {
- /// The pointer to the value for the current type.
- /// The target memory area should never be written to.
- public static readonly Guid* RIID = CreateRIID();
-
- /// Allocates memory for a value and initializes it.
- /// A pointer to memory holding the value for the current type.
- private static Guid* CreateRIID()
- {
- var p = (Guid*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(T), sizeof(Guid));
- *p = typeof(T).GUID;
- return p;
- }
- }
}
\ No newline at end of file