Skip to content

Commit

Permalink
Use Attach to avoid extra AddRef.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlaanstra committed Nov 7, 2023
1 parent 0008648 commit 12ba656
Showing 1 changed file with 2 additions and 29 deletions.
31 changes: 2 additions & 29 deletions src/cswinrt/strings/WinRT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public unsafe (FactoryObjectReference<IActivationFactoryVftbl> obj, int hr) GetA
int hr = _GetActivationFactory(MarshalString.GetAbi(ref __runtimeClassId), &instancePtr);
if (hr == 0)
{
var objRef = FactoryObjectReference<IActivationFactoryVftbl>.FromAbi(instancePtr);
var objRef = FactoryObjectReference<IActivationFactoryVftbl>.Attach(ref instancePtr);
return (objRef, hr);
}
else
Expand Down Expand Up @@ -432,34 +432,7 @@ public static unsafe (FactoryObjectReference<I> obj, int hr) GetActivationFactor
int hr = Platform.RoGetActivationFactory(MarshalString.GetAbi(ref __runtimeClassId), &iid, &instancePtr);
if (hr == 0)
{
var objRef = FactoryObjectReference<I>.FromAbi(instancePtr);
return (objRef, hr);
}
else
{
return (null, hr);
}
}
}
finally
{
MarshalInspectable<object>.DisposeAbi(instancePtr);
}
}

public static unsafe (ObjectReference<IUnknownVftbl> obj, int hr) GetActivationFactory(string runtimeClassId, Guid iid)
{
var module = Instance; // Ensure COM is initialized
IntPtr instancePtr = IntPtr.Zero;
try
{
MarshalString.Pinnable __runtimeClassId = new(runtimeClassId);
fixed (void* ___runtimeClassId = __runtimeClassId)
{
int hr = Platform.RoGetActivationFactory(MarshalString.GetAbi(ref __runtimeClassId), &iid, &instancePtr);
if (hr == 0)
{
var objRef = ComWrappersSupport.GetObjectReferenceForInterface<IUnknownVftbl>(instancePtr);
var objRef = FactoryObjectReference<I>.Attach(ref instancePtr);
return (objRef, hr);
}
else
Expand Down

0 comments on commit 12ba656

Please sign in to comment.