From df8f63aafbb24844ce58abc0047cde76b2628ab3 Mon Sep 17 00:00:00 2001
From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com>
Date: Fri, 21 Jul 2023 12:40:42 -0700
Subject: [PATCH 1/8] OwnershipTransfer
---
.../SharedTypes.ComInterfaces.IBoolImpl.cs | 31 ++
.../SharedTypes.ComInterfaces.IFloatImpl.cs | 31 ++
...SharedTypes.ComInterfaces.IIntArrayImpl.cs | 31 ++
.../SharedTypes.ComInterfaces.IIntImpl.cs | 31 ++
...haredTypes.ComInterfaces.IInterfaceImpl.cs | 31 ++
...Types.ComInterfaces.IJaggedIntArrayImpl.cs | 31 ++
...ngFails.ICollectionMarshallingFailsImpl.cs | 31 ++
...ils.IJaggedIntArrayMarshallingFailsImpl.cs | 31 ++
.../SharedTypes.ComInterfaces.IBool.cs | 142 ++++++
...ComInterfaces.ICustomCollectionStateful.cs | 336 ++++++++++++
...nterfaces.ICustomStringMarshallingUtf16.cs | 10 +-
.../SharedTypes.ComInterfaces.IDerived.cs | 10 +-
.../SharedTypes.ComInterfaces.IEnumUnknown.cs | 30 +-
.../SharedTypes.ComInterfaces.IFloat.cs | 135 +++++
...SharedTypes.ComInterfaces.IGetAndSetInt.cs | 10 +-
.../SharedTypes.ComInterfaces.IGetIntArray.cs | 11 +-
.../SharedTypes.ComInterfaces.IInt.cs | 273 ++++++++++
.../SharedTypes.ComInterfaces.IIntArray.cs | 448 ++++++++++++++++
.../SharedTypes.ComInterfaces.IInterface.cs | 328 ++++++++++++
...aredTypes.ComInterfaces.IJaggedIntArray.cs | 411 +++++++++++++++
...haredTypes.ComInterfaces.IPointProvider.cs | 2 +
.../SharedTypes.ComInterfaces.IRefStrings.cs | 224 ++++++++
...omInterfaces.IStringMarshallingOverride.cs | 27 +-
...faces.IStringMarshallingOverrideDerived.cs | 27 +-
...edTypes.ComInterfaces.IUTF16Marshalling.cs | 10 +-
...redTypes.ComInterfaces.IUTF8Marshalling.cs | 10 +-
...allingFails.ICollectionMarshallingFails.cs | 240 +++++++++
...ngFails.IJaggedIntArrayMarshallingFails.cs | 481 ++++++++++++++++++
...llingFails.IStringArrayMarshallingFails.cs | 78 ++-
.../NativeToManagedStubs.g.cs | 385 +++++++-------
30 files changed, 3632 insertions(+), 244 deletions(-)
create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IBoolImpl.cs
create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IFloatImpl.cs
create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IIntArrayImpl.cs
create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IIntImpl.cs
create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IInterfaceImpl.cs
create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IJaggedIntArrayImpl.cs
create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFailsImpl.cs
create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFailsImpl.cs
create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IBool.cs
create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.ICustomCollectionStateful.cs
create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IFloat.cs
create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInt.cs
create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs
create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs
create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IJaggedIntArray.cs
create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs
create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.cs
create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.cs
diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IBoolImpl.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IBoolImpl.cs
new file mode 100644
index 0000000..dc789be
--- /dev/null
+++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IBoolImpl.cs
@@ -0,0 +1,31 @@
+//
+file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass
+{
+ private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables;
+ public static System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* GetComInterfaceEntries(out int count)
+ {
+ count = 1;
+ if (s_vtables == null)
+ {
+ System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* vtables = (System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry*)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(ComClassInformation), sizeof(System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry) * 1);
+ System.Runtime.InteropServices.Marshalling.IIUnknownDerivedDetails details;
+ details = System.Runtime.InteropServices.Marshalling.StrategyBasedComWrappers.DefaultIUnknownInterfaceDetailsStrategy.GetIUnknownDerivedDetails(typeof(SharedTypes.ComInterfaces.IBool).TypeHandle);
+ vtables[0] = new()
+ {
+ IID = details.Iid,
+ Vtable = (nint)details.ManagedVirtualMethodTable
+ };
+ s_vtables = vtables;
+ }
+
+ return s_vtables;
+ }
+}
+
+namespace SharedTypes.ComInterfaces
+{
+ [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute]
+ internal partial class IBoolImpl
+ {
+ }
+}
diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IFloatImpl.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IFloatImpl.cs
new file mode 100644
index 0000000..7966d77
--- /dev/null
+++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IFloatImpl.cs
@@ -0,0 +1,31 @@
+//
+file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass
+{
+ private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables;
+ public static System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* GetComInterfaceEntries(out int count)
+ {
+ count = 1;
+ if (s_vtables == null)
+ {
+ System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* vtables = (System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry*)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(ComClassInformation), sizeof(System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry) * 1);
+ System.Runtime.InteropServices.Marshalling.IIUnknownDerivedDetails details;
+ details = System.Runtime.InteropServices.Marshalling.StrategyBasedComWrappers.DefaultIUnknownInterfaceDetailsStrategy.GetIUnknownDerivedDetails(typeof(SharedTypes.ComInterfaces.IFloat).TypeHandle);
+ vtables[0] = new()
+ {
+ IID = details.Iid,
+ Vtable = (nint)details.ManagedVirtualMethodTable
+ };
+ s_vtables = vtables;
+ }
+
+ return s_vtables;
+ }
+}
+
+namespace SharedTypes.ComInterfaces
+{
+ [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute]
+ internal partial class IFloatImpl
+ {
+ }
+}
diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IIntArrayImpl.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IIntArrayImpl.cs
new file mode 100644
index 0000000..ed25de3
--- /dev/null
+++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IIntArrayImpl.cs
@@ -0,0 +1,31 @@
+//
+file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass
+{
+ private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables;
+ public static System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* GetComInterfaceEntries(out int count)
+ {
+ count = 1;
+ if (s_vtables == null)
+ {
+ System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* vtables = (System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry*)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(ComClassInformation), sizeof(System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry) * 1);
+ System.Runtime.InteropServices.Marshalling.IIUnknownDerivedDetails details;
+ details = System.Runtime.InteropServices.Marshalling.StrategyBasedComWrappers.DefaultIUnknownInterfaceDetailsStrategy.GetIUnknownDerivedDetails(typeof(SharedTypes.ComInterfaces.IIntArray).TypeHandle);
+ vtables[0] = new()
+ {
+ IID = details.Iid,
+ Vtable = (nint)details.ManagedVirtualMethodTable
+ };
+ s_vtables = vtables;
+ }
+
+ return s_vtables;
+ }
+}
+
+namespace SharedTypes.ComInterfaces
+{
+ [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute]
+ internal partial class IIntArrayImpl
+ {
+ }
+}
diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IIntImpl.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IIntImpl.cs
new file mode 100644
index 0000000..6384685
--- /dev/null
+++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IIntImpl.cs
@@ -0,0 +1,31 @@
+//
+file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass
+{
+ private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables;
+ public static System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* GetComInterfaceEntries(out int count)
+ {
+ count = 1;
+ if (s_vtables == null)
+ {
+ System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* vtables = (System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry*)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(ComClassInformation), sizeof(System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry) * 1);
+ System.Runtime.InteropServices.Marshalling.IIUnknownDerivedDetails details;
+ details = System.Runtime.InteropServices.Marshalling.StrategyBasedComWrappers.DefaultIUnknownInterfaceDetailsStrategy.GetIUnknownDerivedDetails(typeof(SharedTypes.ComInterfaces.IInt).TypeHandle);
+ vtables[0] = new()
+ {
+ IID = details.Iid,
+ Vtable = (nint)details.ManagedVirtualMethodTable
+ };
+ s_vtables = vtables;
+ }
+
+ return s_vtables;
+ }
+}
+
+namespace SharedTypes.ComInterfaces
+{
+ [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute]
+ internal partial class IIntImpl
+ {
+ }
+}
diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IInterfaceImpl.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IInterfaceImpl.cs
new file mode 100644
index 0000000..3d23a8d
--- /dev/null
+++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IInterfaceImpl.cs
@@ -0,0 +1,31 @@
+//
+file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass
+{
+ private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables;
+ public static System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* GetComInterfaceEntries(out int count)
+ {
+ count = 1;
+ if (s_vtables == null)
+ {
+ System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* vtables = (System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry*)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(ComClassInformation), sizeof(System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry) * 1);
+ System.Runtime.InteropServices.Marshalling.IIUnknownDerivedDetails details;
+ details = System.Runtime.InteropServices.Marshalling.StrategyBasedComWrappers.DefaultIUnknownInterfaceDetailsStrategy.GetIUnknownDerivedDetails(typeof(SharedTypes.ComInterfaces.IInterface).TypeHandle);
+ vtables[0] = new()
+ {
+ IID = details.Iid,
+ Vtable = (nint)details.ManagedVirtualMethodTable
+ };
+ s_vtables = vtables;
+ }
+
+ return s_vtables;
+ }
+}
+
+namespace SharedTypes.ComInterfaces
+{
+ [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute]
+ internal partial class IInterfaceImpl
+ {
+ }
+}
diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IJaggedIntArrayImpl.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IJaggedIntArrayImpl.cs
new file mode 100644
index 0000000..93367ac
--- /dev/null
+++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IJaggedIntArrayImpl.cs
@@ -0,0 +1,31 @@
+//
+file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass
+{
+ private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables;
+ public static System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* GetComInterfaceEntries(out int count)
+ {
+ count = 1;
+ if (s_vtables == null)
+ {
+ System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* vtables = (System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry*)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(ComClassInformation), sizeof(System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry) * 1);
+ System.Runtime.InteropServices.Marshalling.IIUnknownDerivedDetails details;
+ details = System.Runtime.InteropServices.Marshalling.StrategyBasedComWrappers.DefaultIUnknownInterfaceDetailsStrategy.GetIUnknownDerivedDetails(typeof(SharedTypes.ComInterfaces.IJaggedIntArray).TypeHandle);
+ vtables[0] = new()
+ {
+ IID = details.Iid,
+ Vtable = (nint)details.ManagedVirtualMethodTable
+ };
+ s_vtables = vtables;
+ }
+
+ return s_vtables;
+ }
+}
+
+namespace SharedTypes.ComInterfaces
+{
+ [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute]
+ internal partial class IJaggedIntArrayImpl
+ {
+ }
+}
diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFailsImpl.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFailsImpl.cs
new file mode 100644
index 0000000..dc8a052
--- /dev/null
+++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFailsImpl.cs
@@ -0,0 +1,31 @@
+//
+file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass
+{
+ private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables;
+ public static System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* GetComInterfaceEntries(out int count)
+ {
+ count = 1;
+ if (s_vtables == null)
+ {
+ System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* vtables = (System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry*)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(ComClassInformation), sizeof(System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry) * 1);
+ System.Runtime.InteropServices.Marshalling.IIUnknownDerivedDetails details;
+ details = System.Runtime.InteropServices.Marshalling.StrategyBasedComWrappers.DefaultIUnknownInterfaceDetailsStrategy.GetIUnknownDerivedDetails(typeof(SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails).TypeHandle);
+ vtables[0] = new()
+ {
+ IID = details.Iid,
+ Vtable = (nint)details.ManagedVirtualMethodTable
+ };
+ s_vtables = vtables;
+ }
+
+ return s_vtables;
+ }
+}
+
+namespace SharedTypes.ComInterfaces.MarshallingFails
+{
+ [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute]
+ internal partial class ICollectionMarshallingFailsImpl
+ {
+ }
+}
diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFailsImpl.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFailsImpl.cs
new file mode 100644
index 0000000..b963a90
--- /dev/null
+++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFailsImpl.cs
@@ -0,0 +1,31 @@
+//
+file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass
+{
+ private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables;
+ public static System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* GetComInterfaceEntries(out int count)
+ {
+ count = 1;
+ if (s_vtables == null)
+ {
+ System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* vtables = (System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry*)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(ComClassInformation), sizeof(System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry) * 1);
+ System.Runtime.InteropServices.Marshalling.IIUnknownDerivedDetails details;
+ details = System.Runtime.InteropServices.Marshalling.StrategyBasedComWrappers.DefaultIUnknownInterfaceDetailsStrategy.GetIUnknownDerivedDetails(typeof(SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails).TypeHandle);
+ vtables[0] = new()
+ {
+ IID = details.Iid,
+ Vtable = (nint)details.ManagedVirtualMethodTable
+ };
+ s_vtables = vtables;
+ }
+
+ return s_vtables;
+ }
+}
+
+namespace SharedTypes.ComInterfaces.MarshallingFails
+{
+ [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute]
+ internal partial class IJaggedIntArrayMarshallingFailsImpl
+ {
+ }
+}
diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IBool.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IBool.cs
new file mode 100644
index 0000000..f7d3ac7
--- /dev/null
+++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IBool.cs
@@ -0,0 +1,142 @@
+//
+#pragma warning disable CS0612, CS0618
+file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType
+{
+ public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 214, 62, 157, 90, 23, 204, 185, 79, 143, 130, 0, 112, 72, 155, 114, 19 }));
+
+ private static void** _vtable;
+ public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable());
+}
+
+[System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute]
+file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IBool
+{
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")]
+ [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute]
+ bool global::SharedTypes.ComInterfaces.IBool.Get()
+ {
+ var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IBool));
+ bool __retVal;
+ sbyte __retVal_native;
+ int __invokeRetVal;
+ {
+ __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, &__retVal_native);
+ }
+
+ System.GC.KeepAlive(this);
+ // Unmarshal - Convert native data to managed data.
+ System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal);
+ __retVal = __retVal_native != 0;
+ return __retVal;
+ }
+
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")]
+ [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute]
+ void global::SharedTypes.ComInterfaces.IBool.Set(bool value)
+ {
+ var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IBool));
+ sbyte __value_native;
+ int __invokeRetVal;
+ // Marshal - Convert managed data to native data.
+ __value_native = (sbyte)(value ? 1 : 0);
+ {
+ __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, __value_native);
+ }
+
+ System.GC.KeepAlive(this);
+ // Unmarshal - Convert native data to managed data.
+ System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal);
+ }
+}
+
+file unsafe partial interface InterfaceImplementation
+{
+ [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })]
+ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, sbyte* __invokeRetValUnmanaged__param)
+ {
+ global::SharedTypes.ComInterfaces.IBool @this = default;
+ sbyte __invokeRetValUnmanaged__out = default;
+ sbyte __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param;
+ bool __invokeRetVal = default;
+ int __retVal = default;
+ _ = __invokeRetValUnmanaged__out;
+ try
+ {
+ // Unmarshal - Convert native data to managed data.
+ __retVal = 0; // S_OK
+ @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native);
+ __invokeRetVal = @this.Get();
+ // Marshal - Convert managed data to native data.
+ __invokeRetValUnmanaged__out = (sbyte)(__invokeRetVal ? 1 : 0);
+ }
+ catch (System.Exception __exception)
+ {
+ __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception);
+ return __retVal;
+ }
+
+ // AssignOut - Assign to parameters
+ *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out;
+ return __retVal;
+ }
+
+ [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })]
+ internal static int ABI_Set(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, sbyte __value_native)
+ {
+ global::SharedTypes.ComInterfaces.IBool @this = default;
+ bool value = default;
+ int __retVal = default;
+ try
+ {
+ // Unmarshal - Convert native data to managed data.
+ __retVal = 0; // S_OK
+ value = __value_native != 0;
+ @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native);
+ @this.Set(value);
+ }
+ catch (System.Exception __exception)
+ {
+ __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception);
+ return __retVal;
+ }
+
+ return __retVal;
+ }
+}
+
+file unsafe partial interface InterfaceImplementation
+{
+ internal static void** CreateManagedVirtualFunctionTable()
+ {
+ void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IBool), sizeof(void*) * 5);
+ {
+ nint v0, v1, v2;
+ System.Runtime.InteropServices.ComWrappers.GetIUnknownImpl(out v0, out v1, out v2);
+ vtable[0] = (void*)v0;
+ vtable[1] = (void*)v1;
+ vtable[2] = (void*)v2;
+ }
+
+ {
+ vtable[3] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Get;
+ vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Set;
+ }
+
+ return vtable;
+ }
+}
+
+namespace SharedTypes.ComInterfaces
+{
+ [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute]
+ internal partial interface IBool
+ {
+ }
+}
+
+namespace SharedTypes.ComInterfaces
+{
+ internal partial interface IBool
+ {
+ }
+}
\ No newline at end of file
diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.ICustomCollectionStateful.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.ICustomCollectionStateful.cs
new file mode 100644
index 0000000..01dc341
--- /dev/null
+++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.ICustomCollectionStateful.cs
@@ -0,0 +1,336 @@
+//
+#pragma warning disable CS0612, CS0618
+file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType
+{
+ public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 124, 183, 82, 10, 139, 224, 116, 66, 161, 244, 26, 43, 242, 192, 126, 96 }));
+
+ private static void** _vtable;
+ public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable());
+}
+
+[System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute]
+file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.ICustomCollectionStateful
+{
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")]
+ [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute]
+ global::SharedTypes.ComInterfaces.TestCollection global::SharedTypes.ComInterfaces.ICustomCollectionStateful.Method(global::SharedTypes.ComInterfaces.TestCollection p, int pSize, in global::SharedTypes.ComInterfaces.TestCollection pIn, in int pInSize, int pRefSize, ref global::SharedTypes.ComInterfaces.TestCollection pRef, out global::SharedTypes.ComInterfaces.TestCollection pOut, out int pOutSize)
+ {
+ var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.ICustomCollectionStateful));
+ System.Runtime.CompilerServices.Unsafe.SkipInit(out pOut);
+ System.Runtime.CompilerServices.Unsafe.SkipInit(out pOutSize);
+ byte* __p_native = default;
+ byte* __pIn_native = default;
+ byte* __pRef_native = default;
+ byte* __pOut_native = default;
+ global::SharedTypes.ComInterfaces.TestCollection __retVal = default;
+ byte* __retVal_native = default;
+ int __invokeRetVal = default;
+ // Setup - Perform required setup.
+ scoped global::SharedTypes.ComInterfaces.Marshaller.Ref __retVal_native__marshaller = new();
+ int __retVal_native__numElements;
+ System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements);
+ scoped global::SharedTypes.ComInterfaces.Marshaller.Ref __pOut_native__marshaller = new();
+ int __pOut_native__numElements;
+ System.Runtime.CompilerServices.Unsafe.SkipInit(out __pOut_native__numElements);
+ scoped global::SharedTypes.ComInterfaces.Marshaller.Ref __pRef_native__marshaller = new();
+ int __pRef_native__numElements;
+ int __pRef_native__lastIndexMarshalled = 0;
+ System.Runtime.CompilerServices.Unsafe.SkipInit(out __pRef_native__numElements);
+ scoped global::SharedTypes.ComInterfaces.Marshaller.Ref __pIn_native__marshaller = new();
+ int __pIn_native__numElements;
+ int __pIn_native__lastIndexMarshalled = 0;
+ System.Runtime.CompilerServices.Unsafe.SkipInit(out __pIn_native__numElements);
+ scoped global::SharedTypes.ComInterfaces.Marshaller.Ref __p_native__marshaller = new();
+ int __p_native__numElements;
+ int __p_native__lastIndexMarshalled = 0;
+ System.Runtime.CompilerServices.Unsafe.SkipInit(out __p_native__numElements);
+ try
+ {
+ // Marshal - Convert managed data to native data.
+ __pRef_native__marshaller.FromManaged(pRef);
+ {
+ System.ReadOnlySpan __pRef_native__managedSpan = __pRef_native__marshaller.GetManagedValuesSource();
+ System.Span __pRef_native__nativeSpan = __pRef_native__marshaller.GetUnmanagedValuesDestination();
+ for (int __i0 = 0; __i0 < __pRef_native__managedSpan.Length; ++__i0, ++__pRef_native__lastIndexMarshalled)
+ {
+ __pRef_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.ElementMarshaller.ConvertToUnmanaged(__pRef_native__managedSpan[__i0]);
+ }
+ }
+
+ __pIn_native__marshaller.FromManaged(pIn);
+ {
+ System.ReadOnlySpan __pIn_native__managedSpan = __pIn_native__marshaller.GetManagedValuesSource();
+ System.Span __pIn_native__nativeSpan = __pIn_native__marshaller.GetUnmanagedValuesDestination();
+ for (int __i0 = 0; __i0 < __pIn_native__managedSpan.Length; ++__i0, ++__pIn_native__lastIndexMarshalled)
+ {
+ __pIn_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.ElementMarshaller.ConvertToUnmanaged(__pIn_native__managedSpan[__i0]);
+ }
+ }
+
+ __p_native__marshaller.FromManaged(p);
+ {
+ System.ReadOnlySpan __p_native__managedSpan = __p_native__marshaller.GetManagedValuesSource();
+ System.Span __p_native__nativeSpan = __p_native__marshaller.GetUnmanagedValuesDestination();
+ for (int __i0 = 0; __i0 < __p_native__managedSpan.Length; ++__i0, ++__p_native__lastIndexMarshalled)
+ {
+ __p_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.ElementMarshaller.ConvertToUnmanaged(__p_native__managedSpan[__i0]);
+ }
+ }
+
+ // Pin - Pin data in preparation for calling the P/Invoke.
+ fixed (int* __pOutSize_native = &pOutSize)
+ fixed (int* __pInSize_native = &pInSize)
+ {
+ // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned.
+ __pRef_native = __pRef_native__marshaller.ToUnmanaged();
+ __pIn_native = __pIn_native__marshaller.ToUnmanaged();
+ __p_native = __p_native__marshaller.ToUnmanaged();
+ __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __p_native, pSize, &__pIn_native, __pInSize_native, pRefSize, &__pRef_native, &__pOut_native, __pOutSize_native, &__retVal_native);
+ }
+
+ System.GC.KeepAlive(this);
+ // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception.
+ __retVal_native__marshaller.FromUnmanaged(__retVal_native);
+ __pOut_native__marshaller.FromUnmanaged(__pOut_native);
+ __pRef_native__marshaller.FromUnmanaged(__pRef_native);
+ // Unmarshal - Convert native data to managed data.
+ System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal);
+ __retVal_native__numElements = 10;
+ {
+ System.ReadOnlySpan __retVal_native__nativeSpan = __retVal_native__marshaller.GetUnmanagedValuesSource(__retVal_native__numElements);
+ System.Span __retVal_native__managedSpan = __retVal_native__marshaller.GetManagedValuesDestination(__retVal_native__numElements);
+ for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0)
+ {
+ __retVal_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.ElementMarshaller.ConvertToManaged(__retVal_native__nativeSpan[__i0]);
+ }
+ }
+
+ __retVal = __retVal_native__marshaller.ToManaged();
+ __pOut_native__numElements = pOutSize;
+ {
+ System.ReadOnlySpan __pOut_native__nativeSpan = __pOut_native__marshaller.GetUnmanagedValuesSource(__pOut_native__numElements);
+ System.Span __pOut_native__managedSpan = __pOut_native__marshaller.GetManagedValuesDestination(__pOut_native__numElements);
+ for (int __i0 = 0; __i0 < __pOut_native__numElements; ++__i0)
+ {
+ __pOut_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.ElementMarshaller.ConvertToManaged(__pOut_native__nativeSpan[__i0]);
+ }
+ }
+
+ pOut = __pOut_native__marshaller.ToManaged();
+ __pRef_native__numElements = pRefSize;
+ {
+ System.ReadOnlySpan __pRef_native__nativeSpan = __pRef_native__marshaller.GetUnmanagedValuesSource(__pRef_native__numElements);
+ System.Span __pRef_native__managedSpan = __pRef_native__marshaller.GetManagedValuesDestination(__pRef_native__numElements);
+ for (int __i0 = 0; __i0 < __pRef_native__numElements; ++__i0)
+ {
+ __pRef_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.ElementMarshaller.ConvertToManaged(__pRef_native__nativeSpan[__i0]);
+ }
+ }
+
+ pRef = __pRef_native__marshaller.ToManaged();
+ }
+ finally
+ {
+ // Cleanup - Perform required cleanup.
+ __retVal_native__marshaller.Free();
+ __pOut_native__marshaller.Free();
+ _ = __pRef_native__lastIndexMarshalled;
+ __pRef_native__marshaller.Free();
+ _ = __pIn_native__lastIndexMarshalled;
+ __pIn_native__marshaller.Free();
+ _ = __p_native__lastIndexMarshalled;
+ __p_native__marshaller.Free();
+ }
+
+ return __retVal;
+ }
+}
+
+file unsafe partial interface InterfaceImplementation
+{
+ [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })]
+ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, byte* __p_native, int pSize, byte** __pIn_native__param, int* __pInSize_native__param, int pRefSize, byte** __pRef_native__param, byte** __pOut_native__param, int* __pOutSize_native__param, byte** __invokeRetValUnmanaged__param)
+ {
+ global::SharedTypes.ComInterfaces.ICustomCollectionStateful @this = default;
+ global::SharedTypes.ComInterfaces.TestCollection p = default;
+ byte* __pIn_native = *__pIn_native__param;
+ global::SharedTypes.ComInterfaces.TestCollection pIn = default;
+ int __pInSize_native = *__pInSize_native__param;
+ int pInSize = default;
+ byte* __pRef_native__out = default;
+ byte* __pRef_native = *__pRef_native__param;
+ global::SharedTypes.ComInterfaces.TestCollection pRef = default;
+ byte* __pOut_native__out = default;
+ byte* __pOut_native = *__pOut_native__param;
+ global::SharedTypes.ComInterfaces.TestCollection pOut = default;
+ int __pOutSize_native__out = default;
+ int __pOutSize_native = *__pOutSize_native__param;
+ int pOutSize = default;
+ byte* __invokeRetValUnmanaged__out = default;
+ byte* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param;
+ global::SharedTypes.ComInterfaces.TestCollection __invokeRetVal = default;
+ int __retVal = default;
+ _ = __pRef_native__out;
+ _ = __pOut_native__out;
+ _ = __pOutSize_native__out;
+ _ = __invokeRetValUnmanaged__out;
+ // Setup - Perform required setup.
+ scoped global::SharedTypes.ComInterfaces.Marshaller.Ref __invokeRetValUnmanaged__marshaller = new();
+ int __invokeRetValUnmanaged__numElements;
+ System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements);
+ scoped global::SharedTypes.ComInterfaces.Marshaller.Ref __pOut_native__marshaller = new();
+ int __pOut_native__numElements;
+ System.Runtime.CompilerServices.Unsafe.SkipInit(out __pOut_native__numElements);
+ scoped global::SharedTypes.ComInterfaces.Marshaller.Ref __pRef_native__marshaller = new();
+ int __pRef_native__numElements;
+ int __pRef_native__lastIndexMarshalled = 0;
+ System.Runtime.CompilerServices.Unsafe.SkipInit(out __pRef_native__numElements);
+ scoped global::SharedTypes.ComInterfaces.Marshaller.Ref __pIn_native__marshaller = new();
+ int __pIn_native__numElements;
+ System.Runtime.CompilerServices.Unsafe.SkipInit(out __pIn_native__numElements);
+ scoped global::SharedTypes.ComInterfaces.Marshaller.Ref __p_native__marshaller = new();
+ int __p_native__numElements;
+ System.Runtime.CompilerServices.Unsafe.SkipInit(out __p_native__numElements);
+ try
+ {
+ // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception.
+ __pRef_native__marshaller.FromUnmanaged(__pRef_native);
+ __pIn_native__marshaller.FromUnmanaged(__pIn_native);
+ __p_native__marshaller.FromUnmanaged(__p_native);
+ // Unmarshal - Convert native data to managed data.
+ __retVal = 0; // S_OK
+ __pRef_native__numElements = pRefSize;
+ {
+ System.ReadOnlySpan __pRef_native__nativeSpan = __pRef_native__marshaller.GetUnmanagedValuesSource(__pRef_native__numElements);
+ System.Span __pRef_native__managedSpan = __pRef_native__marshaller.GetManagedValuesDestination(__pRef_native__numElements);
+ for (int __i0 = 0; __i0 < __pRef_native__numElements; ++__i0)
+ {
+ __pRef_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.ElementMarshaller.ConvertToManaged(__pRef_native__nativeSpan[__i0]);
+ }
+ }
+
+ pRef = __pRef_native__marshaller.ToManaged();
+ pInSize = __pInSize_native;
+ __pIn_native__numElements = pInSize;
+ {
+ System.ReadOnlySpan __pIn_native__nativeSpan = __pIn_native__marshaller.GetUnmanagedValuesSource(__pIn_native__numElements);
+ System.Span __pIn_native__managedSpan = __pIn_native__marshaller.GetManagedValuesDestination(__pIn_native__numElements);
+ for (int __i0 = 0; __i0 < __pIn_native__numElements; ++__i0)
+ {
+ __pIn_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.ElementMarshaller.ConvertToManaged(__pIn_native__nativeSpan[__i0]);
+ }
+ }
+
+ pIn = __pIn_native__marshaller.ToManaged();
+ __p_native__numElements = pSize;
+ {
+ System.ReadOnlySpan __p_native__nativeSpan = __p_native__marshaller.GetUnmanagedValuesSource(__p_native__numElements);
+ System.Span __p_native__managedSpan = __p_native__marshaller.GetManagedValuesDestination(__p_native__numElements);
+ for (int __i0 = 0; __i0 < __p_native__numElements; ++__i0)
+ {
+ __p_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.ElementMarshaller.ConvertToManaged(__p_native__nativeSpan[__i0]);
+ }
+ }
+
+ p = __p_native__marshaller.ToManaged();
+ @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native);
+ __invokeRetVal = @this.Method(p, pSize, in pIn, in pInSize, pRefSize, ref pRef, out pOut, out pOutSize);
+ // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned.
+ __invokeRetValUnmanaged = __invokeRetValUnmanaged__marshaller.ToUnmanaged();
+ __pOut_native = __pOut_native__marshaller.ToUnmanaged();
+ __pRef_native = __pRef_native__marshaller.ToUnmanaged();
+ // Marshal - Convert managed data to native data.
+ __invokeRetValUnmanaged__marshaller.FromManaged(__invokeRetVal);
+ {
+ System.ReadOnlySpan __invokeRetValUnmanaged__managedSpan = __invokeRetValUnmanaged__marshaller.GetManagedValuesSource();
+ System.Span __invokeRetValUnmanaged__nativeSpan = __invokeRetValUnmanaged__marshaller.GetUnmanagedValuesDestination();
+ __invokeRetValUnmanaged__nativeSpan.Clear();
+ __invokeRetValUnmanaged__out = (byte*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref __invokeRetValUnmanaged__nativeSpan.GetPinnableReference());
+ for (int __i0 = 0; __i0 < __invokeRetValUnmanaged__managedSpan.Length; ++__i0)
+ {
+ __invokeRetValUnmanaged__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.ElementMarshaller.ConvertToUnmanaged(__invokeRetValUnmanaged__managedSpan[__i0]);
+ }
+ }
+
+ __pOutSize_native__out = pOutSize;
+ __pOut_native__marshaller.FromManaged(pOut);
+ {
+ System.ReadOnlySpan __pOut_native__managedSpan = __pOut_native__marshaller.GetManagedValuesSource();
+ System.Span __pOut_native__nativeSpan = __pOut_native__marshaller.GetUnmanagedValuesDestination();
+ __pOut_native__nativeSpan.Clear();
+ __pOut_native__out = (byte*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref __pOut_native__nativeSpan.GetPinnableReference());
+ for (int __i0 = 0; __i0 < __pOut_native__managedSpan.Length; ++__i0)
+ {
+ __pOut_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.ElementMarshaller.ConvertToUnmanaged(__pOut_native__managedSpan[__i0]);
+ }
+ }
+
+ __pRef_native__marshaller.FromManaged(pRef);
+ {
+ System.ReadOnlySpan __pRef_native__managedSpan = __pRef_native__marshaller.GetManagedValuesSource();
+ System.Span __pRef_native__nativeSpan = __pRef_native__marshaller.GetUnmanagedValuesDestination();
+ __pRef_native__out = (byte*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref __pRef_native__nativeSpan.GetPinnableReference());
+ for (int __i0 = 0; __i0 < __pRef_native__managedSpan.Length; ++__i0, ++__pRef_native__lastIndexMarshalled)
+ {
+ __pRef_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.ElementMarshaller.ConvertToUnmanaged(__pRef_native__managedSpan[__i0]);
+ }
+ }
+ }
+ catch (System.Exception __exception)
+ {
+ __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception);
+ // Cleanup - Perform required cleanup.
+ _ = __pRef_native__lastIndexMarshalled;
+ __pRef_native__marshaller.Free();
+ return __retVal;
+ }
+
+ // AssignOut - Assign to parameters
+ *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out;
+ *__pOutSize_native__param = __pOutSize_native__out;
+ *__pOut_native__param = __pOut_native__out;
+ *__pRef_native__param = __pRef_native__out;
+ // Cleanup - Perform required cleanup.
+ _ = __pRef_native__lastIndexMarshalled;
+ __pRef_native__marshaller.Free();
+ __pIn_native__marshaller.Free();
+ __p_native__marshaller.Free();
+ return __retVal;
+ }
+}
+
+file unsafe partial interface InterfaceImplementation
+{
+ internal static void** CreateManagedVirtualFunctionTable()
+ {
+ void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.ICustomCollectionStateful), sizeof(void*) * 4);
+ {
+ nint v0, v1, v2;
+ System.Runtime.InteropServices.ComWrappers.GetIUnknownImpl(out v0, out v1, out v2);
+ vtable[0] = (void*)v0;
+ vtable[1] = (void*)v1;
+ vtable[2] = (void*)v2;
+ }
+
+ {
+ vtable[3] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Method;
+ }
+
+ return vtable;
+ }
+}
+
+namespace SharedTypes.ComInterfaces
+{
+ [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute]
+ partial interface ICustomCollectionStateful
+ {
+ }
+}
+
+namespace SharedTypes.ComInterfaces
+{
+ partial interface ICustomCollectionStateful
+ {
+ }
+}
\ No newline at end of file
diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.ICustomStringMarshallingUtf16.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.ICustomStringMarshallingUtf16.cs
index 350e9ab..c73d2be 100644
--- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.ICustomStringMarshallingUtf16.cs
+++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.ICustomStringMarshallingUtf16.cs
@@ -63,9 +63,11 @@ file unsafe partial interface InterfaceImplementation
internal static int ABI_GetString(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, ushort** __invokeRetValUnmanaged__param)
{
global::SharedTypes.ComInterfaces.ICustomStringMarshallingUtf16 @this = default;
- ref ushort* __invokeRetValUnmanaged = ref *__invokeRetValUnmanaged__param;
+ ushort* __invokeRetValUnmanaged__out = default;
+ ushort* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param;
string __invokeRetVal = default;
int __retVal = default;
+ _ = __invokeRetValUnmanaged__out;
try
{
// Unmarshal - Convert native data to managed data.
@@ -73,13 +75,16 @@ internal static int ABI_GetString(System.Runtime.InteropServices.ComWrappers.Com
@this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native);
__invokeRetVal = @this.GetString();
// Marshal - Convert managed data to native data.
- __invokeRetValUnmanaged = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__invokeRetVal);
+ __invokeRetValUnmanaged__out = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__invokeRetVal);
}
catch (System.Exception __exception)
{
__retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception);
+ return __retVal;
}
+ // AssignOut - Assign to parameters
+ *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out;
return __retVal;
}
@@ -100,6 +105,7 @@ internal static int ABI_SetString(System.Runtime.InteropServices.ComWrappers.Com
catch (System.Exception __exception)
{
__retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception);
+ return __retVal;
}
return __retVal;
diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IDerived.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IDerived.cs
index 68edcfb..8fd929d 100644
--- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IDerived.cs
+++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IDerived.cs
@@ -111,6 +111,7 @@ internal static int ABI_SetName(System.Runtime.InteropServices.ComWrappers.ComIn
catch (System.Exception __exception)
{
__retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception);
+ return __retVal;
}
return __retVal;
@@ -120,9 +121,11 @@ internal static int ABI_SetName(System.Runtime.InteropServices.ComWrappers.ComIn
internal static int ABI_GetName(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, ushort** __invokeRetValUnmanaged__param)
{
global::SharedTypes.ComInterfaces.IDerived @this = default;
- ref ushort* __invokeRetValUnmanaged = ref *__invokeRetValUnmanaged__param;
+ ushort* __invokeRetValUnmanaged__out = default;
+ ushort* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param;
string __invokeRetVal = default;
int __retVal = default;
+ _ = __invokeRetValUnmanaged__out;
try
{
// Unmarshal - Convert native data to managed data.
@@ -130,13 +133,16 @@ internal static int ABI_GetName(System.Runtime.InteropServices.ComWrappers.ComIn
@this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native);
__invokeRetVal = @this.GetName();
// Marshal - Convert managed data to native data.
- __invokeRetValUnmanaged = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__invokeRetVal);
+ __invokeRetValUnmanaged__out = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__invokeRetVal);
}
catch (System.Exception __exception)
{
__retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception);
+ return __retVal;
}
+ // AssignOut - Assign to parameters
+ *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out;
return __retVal;
}
}
diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IEnumUnknown.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IEnumUnknown.cs
index ec54555..329e916 100644
--- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IEnumUnknown.cs
+++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IEnumUnknown.cs
@@ -129,12 +129,15 @@ internal static int ABI_Next(System.Runtime.InteropServices.ComWrappers.ComInter
{
global::SharedTypes.ComInterfaces.IEnumUnknown @this = default;
object[] rgelt = default;
- ref uint __pceltFetched_native = ref *__pceltFetched_native__param;
+ uint __pceltFetched_native__out = default;
+ uint __pceltFetched_native = *__pceltFetched_native__param;
uint pceltFetched = default;
int __retVal = default;
+ _ = __pceltFetched_native__out;
// Setup - Perform required setup.
int __rgelt_native__numElements;
System.Runtime.CompilerServices.Unsafe.SkipInit(out __rgelt_native__numElements);
+ System.Span __rgelt_native__out;
try
{
// Unmarshal - Convert native data to managed data.
@@ -143,24 +146,32 @@ internal static int ABI_Next(System.Runtime.InteropServices.ComWrappers.ComInter
@this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native);
@this.Next(celt, rgelt, out pceltFetched);
// Marshal - Convert managed data to native data.
- __pceltFetched_native = pceltFetched;
+ __pceltFetched_native__out = pceltFetched;
{
__rgelt_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller