Skip to content

Commit

Permalink
Move IActivationFactoryMethods to WinRT.Runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Feb 1, 2024
1 parent 7bdf00b commit f5ca984
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
31 changes: 31 additions & 0 deletions src/WinRT.Runtime/Interop/IActivationFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// Licensed under the MIT License.

using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using WinRT;
using WinRT.Interop;

namespace WinRT.Interop
{
Expand Down Expand Up @@ -38,6 +40,35 @@ static class IActivationFactoryMethods
#endif

public static IntPtr AbiToProjectionVftablePtr => IActivationFactory.Vftbl.AbiToProjectionVftablePtr;

/// <summary>
/// Activates an instance from a given activation factory <see cref="IObjectReference"/> instance.
/// </summary>
/// <param name="objectReference">The input activation factory <see cref="IObjectReference"/> instance to use.</param>
/// <returns>The resulting <see cref="IObjectReference"/> instance created from <paramref name="objectReference"/>.</returns>
/// <remarks>
/// <para>This method assumes <paramref name="objectReference"/> is wrapping an <c>IActivationFactory</c> instance (with no validation).</para>
/// <para>This method is only meant to be used by the generated projections, and not by consumers of CsWinRT directly.</para>
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public static unsafe IObjectReference ActivateInstanceUnsafe(IObjectReference objectReference)
{
IntPtr thisPtr = objectReference.ThisPtr;
IntPtr instancePtr;

ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]<IntPtr, IntPtr*, int>**)thisPtr)[6](thisPtr, &instancePtr));

GC.KeepAlive(objectReference);

try
{
return ComWrappersSupport.GetObjectReferenceForInterface<IUnknownVftbl>(instancePtr);
}
finally
{
MarshalInspectable<object>.DisposeAbi(instancePtr);
}
}
}

[global::WinRT.ObjectReferenceWrapper(nameof(_obj))]
Expand Down
17 changes: 0 additions & 17 deletions src/cswinrt/strings/WinRT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,6 @@ public static void DynamicInvokeAbi(this System.Delegate del, object[] invoke_pa
}
}

internal static class IActivationFactoryMethods
{
public static unsafe ObjectReference<I> ActivateInstance<I>(IObjectReference obj)
{
IntPtr instancePtr;
global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]<IntPtr, IntPtr*, int>**)obj.ThisPtr)[6](obj.ThisPtr, &instancePtr));
try
{
return ComWrappersSupport.GetObjectReferenceForInterface<I>(instancePtr);
}
finally
{
MarshalInspectable<object>.DisposeAbi(instancePtr);
}
}
}

internal class ComponentActivationFactory : global::WinRT.Interop.IActivationFactory
{
public IntPtr ActivateInstance()
Expand Down

0 comments on commit f5ca984

Please sign in to comment.