Skip to content

Commit 8f46dea

Browse files
authored
Code Quality: Introduced ComPtr.As() to QI easily (#16382)
1 parent ca1612c commit 8f46dea

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/Files.App.CsWin32/Windows.Win32.ComHeapPtr.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public unsafe struct ComHeapPtr<T> : IDisposable where T : unmanaged
1616
private T* _ptr;
1717

1818
public bool IsNull
19-
=> _ptr == default;
19+
=> _ptr == null;
2020

2121
public ComHeapPtr(T* ptr)
2222
{

src/Files.App.CsWin32/Windows.Win32.ComPtr.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public unsafe struct ComPtr<T> : IDisposable where T : unmanaged
1616
private T* _ptr;
1717

1818
public bool IsNull
19-
=> _ptr == default;
19+
=> _ptr == null;
2020

2121
public ComPtr(T* ptr)
2222
{
@@ -38,6 +38,14 @@ public ComPtr(T* ptr)
3838
return (T**)Unsafe.AsPointer(ref Unsafe.AsRef(in this));
3939
}
4040

41+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
42+
public readonly ComPtr<U> As<U>(Guid riid) where U : unmanaged
43+
{
44+
ComPtr<U> pNewPtr = default;
45+
((IUnknown*)_ptr)->QueryInterface(&riid, (void**)pNewPtr.GetAddressOf());
46+
return pNewPtr;
47+
}
48+
4149
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4250
public void Dispose()
4351
{

0 commit comments

Comments
 (0)