From 12ba6569fbadaabb83638140a2c7028a42081bce Mon Sep 17 00:00:00 2001 From: Johan Laanstra Date: Mon, 6 Nov 2023 21:08:30 -0800 Subject: [PATCH] Use Attach to avoid extra AddRef. --- src/cswinrt/strings/WinRT.cs | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/src/cswinrt/strings/WinRT.cs b/src/cswinrt/strings/WinRT.cs index 85a486b58..08000d5e7 100644 --- a/src/cswinrt/strings/WinRT.cs +++ b/src/cswinrt/strings/WinRT.cs @@ -373,7 +373,7 @@ public unsafe (FactoryObjectReference obj, int hr) GetA int hr = _GetActivationFactory(MarshalString.GetAbi(ref __runtimeClassId), &instancePtr); if (hr == 0) { - var objRef = FactoryObjectReference.FromAbi(instancePtr); + var objRef = FactoryObjectReference.Attach(ref instancePtr); return (objRef, hr); } else @@ -432,34 +432,7 @@ public static unsafe (FactoryObjectReference obj, int hr) GetActivationFactor int hr = Platform.RoGetActivationFactory(MarshalString.GetAbi(ref __runtimeClassId), &iid, &instancePtr); if (hr == 0) { - var objRef = FactoryObjectReference.FromAbi(instancePtr); - return (objRef, hr); - } - else - { - return (null, hr); - } - } - } - finally - { - MarshalInspectable.DisposeAbi(instancePtr); - } - } - - public static unsafe (ObjectReference 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(instancePtr); + var objRef = FactoryObjectReference.Attach(ref instancePtr); return (objRef, hr); } else