Skip to content

Commit

Permalink
Change to use ComPtr<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
shmuelie committed Aug 29, 2024
1 parent a7178d5 commit 19874ec
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Shmuelie.WinRTServer/Internal/BaseClassFactoryWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
using Shmuelie.WinRTServer.Windows;
using Shmuelie.WinRTServer.Windows.Com;
using Windows.Win32.Foundation;
using static Windows.Win32.PInvoke;
Expand All @@ -26,21 +27,20 @@ public unsafe HRESULT CreateInstance(void* pUnkOuter, Guid* riid, void** ppvObje
try
{
var instance = factory.CreateInstance();
var unknown = comWrappers.GetOrCreateComInterfaceForObject(instance, CreateComInterfaceFlags.None);
using ComPtr<IUnknown> unknown = default;
unknown.Attach((IUnknown*)comWrappers.GetOrCreateComInterfaceForObject(instance, CreateComInterfaceFlags.None));

if (riid->Equals(IUnknown.IID_Guid))
{
*ppvObject = (void*)unknown;
unknown.CopyTo((IUnknown**)ppvObject);
}
else
{
HRESULT hr = (HRESULT)Marshal.QueryInterface(unknown, ref *riid, out nint ppv);
Marshal.Release(unknown);
var hr = (HRESULT)unknown.CopyTo(riid, ppvObject);
if (hr.Failed)
{
return hr;
}
*ppvObject = (void*)ppv;
}

factory.OnInstanceCreated(instance);
Expand Down

0 comments on commit 19874ec

Please sign in to comment.