Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Quality: Introduced ComPtr.As() to QI easily #16382

Merged
merged 8 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Files.App.CsWin32/Windows.Win32.ComHeapPtr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public unsafe struct ComHeapPtr<T> : IDisposable where T : unmanaged
private T* _ptr;

public bool IsNull
=> _ptr == default;
=> _ptr == null;

public ComHeapPtr(T* ptr)
{
Expand Down
10 changes: 9 additions & 1 deletion src/Files.App.CsWin32/Windows.Win32.ComPtr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public unsafe struct ComPtr<T> : IDisposable where T : unmanaged
private T* _ptr;

public bool IsNull
=> _ptr == default;
=> _ptr == null;

public ComPtr(T* ptr)
{
Expand All @@ -38,6 +38,14 @@ public ComPtr(T* ptr)
return (T**)Unsafe.AsPointer(ref Unsafe.AsRef(in this));
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly ComPtr<U> As<U>(Guid riid) where U : unmanaged
{
ComPtr<U> pNewPtr = default;
((IUnknown*)_ptr)->QueryInterface(&riid, (void**)pNewPtr.GetAddressOf());
return pNewPtr;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Dispose()
{
Expand Down
Loading