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.GetManagedValuesDestination(rgelt).Length; - System.Span __rgelt_native__nativeSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__rgelt_native, __rgelt_native__numElements).GetPinnableReference()), __rgelt_native__numElements); +#pragma warning disable CS9081 + __rgelt_native__out = stackalloc System.IntPtr[__rgelt_native__numElements]; +#pragma warning restore CS9081 + System.Span __rgelt_native__nativeSpan = __rgelt_native__out; System.Span __rgelt_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(rgelt); for (int __i0 = 0; __i0 < __rgelt_native__numElements; ++__i0) { void* __rgelt_native__nativeSpan____i0__original = (void*)__rgelt_native__nativeSpan[__i0]; __rgelt_native__nativeSpan[__i0] = (System.IntPtr)(void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(__rgelt_native__managedSpan[__i0]); - global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__rgelt_native__nativeSpan____i0__original); } } } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } + // AssignOut - Assign to parameters + *__pceltFetched_native__param = __pceltFetched_native__out; + __rgelt_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__rgelt_native, __rgelt_native__numElements).GetPinnableReference()), __rgelt_native__numElements)); + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__rgelt_native); return __retVal; } @@ -179,6 +190,7 @@ internal static int ABI_Skip(System.Runtime.InteropServices.ComWrappers.ComInter catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } return __retVal; @@ -199,6 +211,7 @@ internal static int ABI_Reset(System.Runtime.InteropServices.ComWrappers.ComInte catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } return __retVal; @@ -208,9 +221,11 @@ internal static int ABI_Reset(System.Runtime.InteropServices.ComWrappers.ComInte internal static int ABI_Clone(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, void** __ppenum_native__param) { global::SharedTypes.ComInterfaces.IEnumUnknown @this = default; - ref void* __ppenum_native = ref *__ppenum_native__param; + void* __ppenum_native__out = default; + void* __ppenum_native = *__ppenum_native__param; global::SharedTypes.ComInterfaces.IEnumUnknown ppenum = default; int __retVal = default; + _ = __ppenum_native__out; try { // Unmarshal - Convert native data to managed data. @@ -218,13 +233,16 @@ internal static int ABI_Clone(System.Runtime.InteropServices.ComWrappers.ComInte @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Clone(out ppenum); // Marshal - Convert managed data to native data. - __ppenum_native = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(ppenum); + __ppenum_native__out = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(ppenum); } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } + // AssignOut - Assign to parameters + *__ppenum_native__param = __ppenum_native__out; return __retVal; } } diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IFloat.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IFloat.cs new file mode 100644 index 0000000..c703f8b --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IFloat.cs @@ -0,0 +1,135 @@ +// +#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[] { 169, 168, 164, 159, 143, 45, 168, 72, 182, 251, 180, 75, 95, 27, 159, 182 })); + + 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.IFloat +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + float global::SharedTypes.ComInterfaces.IFloat.Get() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IFloat)); + float __retVal; + int __invokeRetVal; + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, &__retVal); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IFloat.Set(float value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IFloat)); + int __invokeRetVal; + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, value); + } + + 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, float* __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IFloat @this = default; + float __invokeRetValUnmanaged__out = default; + float __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; + float __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 = __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; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Set(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, float value) + { + global::SharedTypes.ComInterfaces.IFloat @this = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @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.IFloat), 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 IFloat + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IFloat + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetAndSetInt.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetAndSetInt.cs index 16faf64..a9ebcb9 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetAndSetInt.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetAndSetInt.cs @@ -50,9 +50,11 @@ file unsafe partial interface InterfaceImplementation internal static int ABI_GetInt(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int* __invokeRetValUnmanaged__param) { global::SharedTypes.ComInterfaces.IGetAndSetInt @this = default; - ref int __invokeRetValUnmanaged = ref *__invokeRetValUnmanaged__param; + int __invokeRetValUnmanaged__out = default; + int __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int __invokeRetVal = default; int __retVal = default; + _ = __invokeRetValUnmanaged__out; try { // Unmarshal - Convert native data to managed data. @@ -60,13 +62,16 @@ internal static int ABI_GetInt(System.Runtime.InteropServices.ComWrappers.ComInt @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.GetInt(); // Marshal - Convert managed data to native data. - __invokeRetValUnmanaged = __invokeRetVal; + __invokeRetValUnmanaged__out = __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; } @@ -85,6 +90,7 @@ internal static int ABI_SetInt(System.Runtime.InteropServices.ComWrappers.ComInt 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.IGetIntArray.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetIntArray.cs index 946449e..288d4c9 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetIntArray.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetIntArray.cs @@ -52,9 +52,11 @@ file unsafe partial interface InterfaceImplementation internal static int ABI_GetInts(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int** __invokeRetValUnmanaged__param) { global::SharedTypes.ComInterfaces.IGetIntArray @this = default; - ref int* __invokeRetValUnmanaged = ref *__invokeRetValUnmanaged__param; + int* __invokeRetValUnmanaged__out = default; + int* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int[] __invokeRetVal = default; int __retVal = default; + _ = __invokeRetValUnmanaged__out; // Setup - Perform required setup. int __invokeRetValUnmanaged__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); @@ -65,14 +67,17 @@ internal static int ABI_GetInts(System.Runtime.InteropServices.ComWrappers.ComIn @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.GetInts(); // Marshal - Convert managed data to native data. - __invokeRetValUnmanaged = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__invokeRetVal).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__invokeRetValUnmanaged, __invokeRetValUnmanaged__numElements)); + __invokeRetValUnmanaged__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__invokeRetVal).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements)); } 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.IInt.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInt.cs new file mode 100644 index 0000000..ca67f27 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInt.cs @@ -0,0 +1,273 @@ +// +#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[] { 42, 31, 109, 238, 24, 52, 23, 67, 168, 124, 53, 72, 143, 101, 70, 171 })); + + 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.IInt +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + int global::SharedTypes.ComInterfaces.IInt.Get() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IInt)); + int __retVal; + int __invokeRetVal; + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, &__retVal); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IInt.Set(int value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IInt)); + int __invokeRetVal; + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, value); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IInt.SwapRef(ref int value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IInt)); + int __invokeRetVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __value_native = &value) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, __value_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IInt.GetOut(out int value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IInt)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out value); + int __invokeRetVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __value_native = &value) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, __value_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IInt.SetIn(in int value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IInt)); + int __invokeRetVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __value_native = &value) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__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, int* __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IInt @this = default; + int __invokeRetValUnmanaged__out = default; + int __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; + int __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 = __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; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Set(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int value) + { + global::SharedTypes.ComInterfaces.IInt @this = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @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; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_SwapRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int* __value_native__param) + { + global::SharedTypes.ComInterfaces.IInt @this = default; + int __value_native__out = default; + int __value_native = *__value_native__param; + int value = default; + int __retVal = default; + _ = __value_native__out; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + value = __value_native; + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.SwapRef(ref value); + // Marshal - Convert managed data to native data. + __value_native__out = value; + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_GetOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int* __value_native__param) + { + global::SharedTypes.ComInterfaces.IInt @this = default; + int __value_native__out = default; + int __value_native = *__value_native__param; + int value = default; + int __retVal = default; + _ = __value_native__out; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.GetOut(out value); + // Marshal - Convert managed data to native data. + __value_native__out = value; + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_SetIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int* __value_native__param) + { + global::SharedTypes.ComInterfaces.IInt @this = default; + int __value_native = *__value_native__param; + int value = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + value = __value_native; + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.SetIn(in 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.IInt), sizeof(void*) * 8); + { + 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; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_SwapRef; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_GetOut; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_SetIn; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IInt + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IInt + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs new file mode 100644 index 0000000..ce80daa --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs @@ -0,0 +1,448 @@ +// +#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[] { 169, 168, 164, 159, 143, 61, 168, 72, 182, 251, 180, 91, 95, 27, 159, 182 })); + + 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.IIntArray +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + int[] global::SharedTypes.ComInterfaces.IIntArray.GetReturn(out int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IIntArray)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out size); + int[] __retVal = default; + int* __retVal_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __size_native, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal_native__numElements = size; + __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal)); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_native__numElements = size; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + } + + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + int global::SharedTypes.ComInterfaces.IIntArray.GetOut(out int[] array) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IIntArray)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out array); + int* __array_native = default; + int __retVal = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__array_native, &__retVal); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __array_native__numElements = __retVal; + array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array)); + } + finally + { + // Cleanup - Perform required cleanup. + __array_native__numElements = __retVal; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native); + } + + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IIntArray.SetContents(int[] array, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IIntArray)); + int __invokeRetVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __array_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(array)) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, (int*)__array_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IIntArray.FillAscending(int[] array, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IIntArray)); + int __invokeRetVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __array_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(array)) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, (int*)__array_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IIntArray.PassIn(in int[] array, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IIntArray)); + int* __array_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __array_native__marshaller = new(); + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __array_native__marshaller.FromManaged(array, stackalloc int[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + __array_native__marshaller.GetManagedValuesSource().CopyTo(__array_native__marshaller.GetUnmanagedValuesDestination()); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __array_native__unused = __array_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __array_native = __array_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, &__array_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + __array_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IIntArray.SwapArray(ref int[] array, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IIntArray)); + int* __array_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __array_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(array, out __array_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(array).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__array_native, __array_native__numElements)); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this, &__array_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __array_native__numElements = size; + array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array)); + } + finally + { + // Cleanup - Perform required cleanup. + __array_native__numElements = size; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native); + } + } +} + +file unsafe partial interface InterfaceImplementation +{ + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_GetReturn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int* __size_native__param, int** __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IIntArray @this = default; + int __size_native__out = default; + int __size_native = *__size_native__param; + int size = default; + int* __invokeRetValUnmanaged__out = default; + int* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; + int[] __invokeRetVal = default; + int __retVal = default; + _ = __size_native__out; + _ = __invokeRetValUnmanaged__out; + // Setup - Perform required setup. + int __invokeRetValUnmanaged__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.GetReturn(out size); + // Marshal - Convert managed data to native data. + __size_native__out = size; + __invokeRetValUnmanaged__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__invokeRetVal).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements)); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__size_native__param = __size_native__out; + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_GetOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int** __array_native__param, int* __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IIntArray @this = default; + int* __array_native__out = default; + int* __array_native = *__array_native__param; + int[] array = default; + int __invokeRetValUnmanaged__out = default; + int __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; + int __invokeRetVal = default; + int __retVal = default; + _ = __array_native__out; + _ = __invokeRetValUnmanaged__out; + // Setup - Perform required setup. + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.GetOut(out array); + // Marshal - Convert managed data to native data. + __invokeRetValUnmanaged__out = __invokeRetVal; + __array_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(array, out __array_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(array).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__array_native__out, __array_native__numElements)); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + *__array_native__param = __array_native__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_SetContents(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int* __array_native, int size) + { + global::SharedTypes.ComInterfaces.IIntArray @this = default; + int[] array = default; + int __retVal = default; + // Setup - Perform required setup. + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __array_native__numElements = size; + array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array)); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.SetContents(array, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_FillAscending(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int* __array_native, int size) + { + global::SharedTypes.ComInterfaces.IIntArray @this = default; + int[] array = default; + int __retVal = default; + // Setup - Perform required setup. + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + System.Span __array_native__out; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array).Clear(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.FillAscending(array, size); + // Marshal - Convert managed data to native data. + { + __array_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(array).Length; +#pragma warning disable CS9081 + __array_native__out = stackalloc int[__array_native__numElements]; +#pragma warning restore CS9081 + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array).CopyTo(__array_native__out); + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + __array_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements).GetPinnableReference()), __array_native__numElements)); + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_PassIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int** __array_native__param, int size) + { + global::SharedTypes.ComInterfaces.IIntArray @this = default; + int* __array_native = *__array_native__param; + int[] array = default; + int __retVal = default; + // Setup - Perform required setup. + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __array_native__numElements = size; + array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array)); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.PassIn(in array, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_SwapArray(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int** __array_native__param, int size) + { + global::SharedTypes.ComInterfaces.IIntArray @this = default; + int* __array_native__out = default; + int* __array_native = *__array_native__param; + int[] array = default; + int __retVal = default; + _ = __array_native__out; + // Setup - Perform required setup. + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __array_native__numElements = size; + array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array)); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.SwapArray(ref array, size); + // Marshal - Convert managed data to native data. + __array_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(array, out __array_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(array).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__array_native__out, __array_native__numElements)); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // Cleanup - Perform required cleanup. + __array_native__numElements = size; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native__out); + return __retVal; + } + + // AssignOut - Assign to parameters + *__array_native__param = __array_native__out; + // Cleanup - Perform required cleanup. + __array_native__numElements = size; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native); + return __retVal; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IIntArray), sizeof(void*) * 9); + { + 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_GetReturn; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_GetOut; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_SetContents; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_FillAscending; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_PassIn; + vtable[8] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_SwapArray; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IIntArray + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IIntArray + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs new file mode 100644 index 0000000..eaeeea4 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs @@ -0,0 +1,328 @@ +// +#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[] { 152, 115, 133, 164, 251, 6, 110, 74, 129, 219, 53, 70, 27, 233, 153, 197 })); + + 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.IInterface +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.IInt global::SharedTypes.ComInterfaces.IInterface.Get() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IInterface)); + global::SharedTypes.ComInterfaces.IInt __retVal = default; + void* __retVal_native = default; + int __invokeRetVal = default; + try + { + { + __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 = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__retVal_native); + } + + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IInterface.SetInt(global::SharedTypes.ComInterfaces.IInt value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IInterface)); + void* __value_native = default; + int __invokeRetVal = default; + try + { + // Marshal - Convert managed data to native data. + __value_native = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(value); + { + __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); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__value_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IInterface.SwapRef(ref global::SharedTypes.ComInterfaces.IInt value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IInterface)); + void* __value_native = default; + int __invokeRetVal = default; + try + { + // Marshal - Convert managed data to native data. + __value_native = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(value); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__value_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + value = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__value_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__value_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IInterface.GetOut(out global::SharedTypes.ComInterfaces.IInt value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IInterface)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out value); + void* __value_native = default; + int __invokeRetVal = default; + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__value_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + value = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__value_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__value_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IInterface.InInt(in global::SharedTypes.ComInterfaces.IInt value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IInterface)); + void* __value_native = default; + int __invokeRetVal = default; + try + { + // Marshal - Convert managed data to native data. + __value_native = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(value); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, &__value_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__value_native); + } + } +} + +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, void** __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IInterface @this = default; + void* __invokeRetValUnmanaged__out = default; + void* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; + global::SharedTypes.ComInterfaces.IInt __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 = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.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; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_SetInt(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, void* __value_native) + { + global::SharedTypes.ComInterfaces.IInterface @this = default; + global::SharedTypes.ComInterfaces.IInt value = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + value = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__value_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.SetInt(value); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_SwapRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, void** __value_native__param) + { + global::SharedTypes.ComInterfaces.IInterface @this = default; + void* __value_native__out = default; + void* __value_native = *__value_native__param; + global::SharedTypes.ComInterfaces.IInt value = default; + int __retVal = default; + _ = __value_native__out; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + value = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__value_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.SwapRef(ref value); + // Marshal - Convert managed data to native data. + __value_native__out = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(value); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__value_native__out); + return __retVal; + } + + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__value_native); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_GetOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, void** __value_native__param) + { + global::SharedTypes.ComInterfaces.IInterface @this = default; + void* __value_native__out = default; + void* __value_native = *__value_native__param; + global::SharedTypes.ComInterfaces.IInt value = default; + int __retVal = default; + _ = __value_native__out; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.GetOut(out value); + // Marshal - Convert managed data to native data. + __value_native__out = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(value); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_InInt(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, void** __value_native__param) + { + global::SharedTypes.ComInterfaces.IInterface @this = default; + void* __value_native = *__value_native__param; + global::SharedTypes.ComInterfaces.IInt value = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + value = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__value_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.InInt(in 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.IInterface), sizeof(void*) * 8); + { + 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_SetInt; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_SwapRef; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_GetOut; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_InInt; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IInterface + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IInterface + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IJaggedIntArray.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IJaggedIntArray.cs new file mode 100644 index 0000000..54d662e --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IJaggedIntArray.cs @@ -0,0 +1,411 @@ +// +#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[] { 169, 168, 164, 159, 143, 61, 168, 72, 182, 251, 180, 91, 95, 27, 159, 182 })); + + 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.IJaggedIntArray +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + int[][] global::SharedTypes.ComInterfaces.IJaggedIntArray.Get(out int[] widths, out int length) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IJaggedIntArray)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out widths); + System.Runtime.CompilerServices.Unsafe.SkipInit(out length); + int* __widths_native = default; + int[][] __retVal = default; + System.IntPtr* __retVal_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __widths_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __length_native = &length) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, &__widths_native, __length_native, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __widths_native__numElements = length; + widths = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__widths_native, __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__widths_native, __widths_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(widths)); + __retVal_native__numElements = length; + __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + System.Span __retVal_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal); + for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + { + int __retVal_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__nativeSpan____i0__numElements); + __retVal_native__nativeSpan____i0__numElements = widths[__i0]; + __retVal_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((int*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((int*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal_native__managedSpan[__i0])); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + __widths_native__numElements = length; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__widths_native); + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__retVal_native, __retVal_native__numElements); + for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + { + int __retVal_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__nativeSpan____i0__numElements); + __retVal_native__nativeSpan____i0__numElements = widths[__i0]; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((int*)__retVal_native__nativeSpan[__i0]); + } + } + + __retVal_native__numElements = length; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + } + + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + int global::SharedTypes.ComInterfaces.IJaggedIntArray.Get2(out int[][] array, out int[] widths) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IJaggedIntArray)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out array); + System.Runtime.CompilerServices.Unsafe.SkipInit(out widths); + System.IntPtr* __array_native = default; + int* __widths_native = default; + int __retVal = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __widths_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__array_native, &__widths_native, &__retVal); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __widths_native__numElements = __retVal; + widths = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__widths_native, __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__widths_native, __widths_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(widths)); + __array_native__numElements = __retVal; + array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); + { + System.ReadOnlySpan __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements); + System.Span __array_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array); + for (int __i0 = 0; __i0 < __array_native__numElements; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan____i0__numElements = widths[__i0]; + __array_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((int*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((int*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__array_native__managedSpan[__i0])); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + __widths_native__numElements = __retVal; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__widths_native); + { + System.ReadOnlySpan __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__array_native, __array_native__numElements); + for (int __i0 = 0; __i0 < __array_native__nativeSpan.Length; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan____i0__numElements = widths[__i0]; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((int*)__array_native__nativeSpan[__i0]); + } + } + + __array_native__numElements = __retVal; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native); + } + + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IJaggedIntArray.Set(int[][] array, int[] widths, int length) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IJaggedIntArray)); + System.IntPtr* __array_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __array_native__marshaller = new(); + int __array_native__numElements; + int __array_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __array_native__marshaller.FromManaged(array, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __array_native__managedSpan = __array_native__marshaller.GetManagedValuesSource(); + System.Span __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __array_native__managedSpan.Length; ++__i0, ++__array_native__lastIndexMarshalled) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan[__i0] = (System.IntPtr)global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__array_native__managedSpan[__i0], out __array_native__nativeSpan____i0__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__array_native__managedSpan[__i0]).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((int*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements)); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __widths_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(widths)) + fixed (void* __array_native__unused = __array_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __array_native = __array_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, __array_native, (int*)__widths_native, length); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __array_native__lastIndexMarshalled; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + ; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((int*)__array_native__nativeSpan[__i0]); + } + } + + __array_native__marshaller.Free(); + } + } +} + +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, int** __widths_native__param, int* __length_native__param, System.IntPtr** __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IJaggedIntArray @this = default; + int* __widths_native__out = default; + int* __widths_native = *__widths_native__param; + int[] widths = default; + int __length_native__out = default; + int __length_native = *__length_native__param; + int length = default; + System.IntPtr* __invokeRetValUnmanaged__out = default; + System.IntPtr* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; + int[][] __invokeRetVal = default; + int __retVal = default; + _ = __widths_native__out; + _ = __length_native__out; + _ = __invokeRetValUnmanaged__out; + // Setup - Perform required setup. + int __widths_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); + int __invokeRetValUnmanaged__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Get(out widths, out length); + // Marshal - Convert managed data to native data. + __length_native__out = length; + __widths_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(widths, out __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(widths).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__widths_native__out, __widths_native__numElements)); + __invokeRetValUnmanaged__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); + { + System.ReadOnlySpan __invokeRetValUnmanaged__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__invokeRetVal); + System.Span __invokeRetValUnmanaged__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements); + __invokeRetValUnmanaged__nativeSpan.Clear(); + for (int __i0 = 0; __i0 < __invokeRetValUnmanaged__managedSpan.Length; ++__i0) + { + int __invokeRetValUnmanaged__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__nativeSpan____i0__numElements); + __invokeRetValUnmanaged__nativeSpan[__i0] = (System.IntPtr)global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetValUnmanaged__managedSpan[__i0], out __invokeRetValUnmanaged__nativeSpan____i0__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__invokeRetValUnmanaged__managedSpan[__i0]).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((int*)__invokeRetValUnmanaged__nativeSpan[__i0], __invokeRetValUnmanaged__nativeSpan____i0__numElements)); + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__length_native__param = __length_native__out; + *__widths_native__param = __widths_native__out; + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Get2(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, System.IntPtr** __array_native__param, int** __widths_native__param, int* __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IJaggedIntArray @this = default; + System.IntPtr* __array_native__out = default; + System.IntPtr* __array_native = *__array_native__param; + int[][] array = default; + int* __widths_native__out = default; + int* __widths_native = *__widths_native__param; + int[] widths = default; + int __invokeRetValUnmanaged__out = default; + int __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; + int __invokeRetVal = default; + int __retVal = default; + _ = __array_native__out; + _ = __widths_native__out; + _ = __invokeRetValUnmanaged__out; + // Setup - Perform required setup. + int __widths_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Get2(out array, out widths); + // Marshal - Convert managed data to native data. + __invokeRetValUnmanaged__out = __invokeRetVal; + __widths_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(widths, out __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(widths).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__widths_native__out, __widths_native__numElements)); + __array_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(array, out __array_native__numElements); + { + System.ReadOnlySpan __array_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(array); + System.Span __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__array_native__out, __array_native__numElements); + __array_native__nativeSpan.Clear(); + for (int __i0 = 0; __i0 < __array_native__managedSpan.Length; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan[__i0] = (System.IntPtr)global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__array_native__managedSpan[__i0], out __array_native__nativeSpan____i0__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__array_native__managedSpan[__i0]).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((int*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements)); + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + *__widths_native__param = __widths_native__out; + *__array_native__param = __array_native__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, System.IntPtr* __array_native, int* __widths_native, int length) + { + global::SharedTypes.ComInterfaces.IJaggedIntArray @this = default; + int[][] array = default; + int[] widths = default; + int __retVal = default; + // Setup - Perform required setup. + int __widths_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __widths_native__numElements = length; + widths = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__widths_native, __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__widths_native, __widths_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(widths)); + __array_native__numElements = length; + array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); + { + System.ReadOnlySpan __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements); + System.Span __array_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array); + for (int __i0 = 0; __i0 < __array_native__numElements; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan____i0__numElements = widths[__i0]; + __array_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((int*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((int*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__array_native__managedSpan[__i0])); + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Set(array, widths, length); + } + 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.IJaggedIntArray), sizeof(void*) * 6); + { + 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_Get2; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Set; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IJaggedIntArray + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IJaggedIntArray + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IPointProvider.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IPointProvider.cs index bb1ab1c..5c8dd39 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IPointProvider.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IPointProvider.cs @@ -57,6 +57,7 @@ file unsafe partial interface InterfaceImplementation catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsDefaultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } return __retVal; @@ -77,6 +78,7 @@ internal static int ABI_SetPoint(System.Runtime.InteropServices.ComWrappers.ComI 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.IRefStrings.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs new file mode 100644 index 0000000..e85a49a --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs @@ -0,0 +1,224 @@ +// +#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[] { 219, 183, 70, 81, 136, 5, 155, 70, 184, 229, 179, 128, 144, 162, 252, 21 })); + + 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.IRefStrings +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IRefStrings.RefString(ref string value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IRefStrings)); + byte* __value_native = default; + int __invokeRetVal = default; + try + { + // Marshal - Convert managed data to native data. + __value_native = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(value); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, &__value_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + value = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__value_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__value_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IRefStrings.InString(in string value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IRefStrings)); + byte* __value_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __value_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __value_native__marshaller.FromManaged(value, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __value_native = __value_native__marshaller.ToUnmanaged(); + __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); + } + finally + { + // Cleanup - Perform required cleanup. + __value_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IRefStrings.OutString(out string value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IRefStrings)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out value); + byte* __value_native = default; + int __invokeRetVal = default; + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__value_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + value = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__value_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__value_native); + } + } +} + +file unsafe partial interface InterfaceImplementation +{ + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_RefString(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, byte** __value_native__param) + { + global::SharedTypes.ComInterfaces.IRefStrings @this = default; + byte* __value_native__out = default; + byte* __value_native = *__value_native__param; + string value = default; + int __retVal = default; + _ = __value_native__out; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + value = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__value_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.RefString(ref value); + // Marshal - Convert managed data to native data. + __value_native__out = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(value); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__value_native__out); + return __retVal; + } + + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__value_native); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_InString(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, byte** __value_native__param) + { + global::SharedTypes.ComInterfaces.IRefStrings @this = default; + byte* __value_native = *__value_native__param; + string value = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + value = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__value_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.InString(in value); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_OutString(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, byte** __value_native__param) + { + global::SharedTypes.ComInterfaces.IRefStrings @this = default; + byte* __value_native__out = default; + byte* __value_native = *__value_native__param; + string value = default; + int __retVal = default; + _ = __value_native__out; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.OutString(out value); + // Marshal - Convert managed data to native data. + __value_native__out = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(value); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; + return __retVal; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IRefStrings), sizeof(void*) * 6); + { + 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_RefString; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_InString; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_OutString; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IRefStrings + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IRefStrings + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverride.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverride.cs index 2dc1608..eacd91a 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverride.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverride.cs @@ -115,9 +115,11 @@ internal static int ABI_StringMarshallingUtf8(System.Runtime.InteropServices.Com { global::SharedTypes.ComInterfaces.IStringMarshallingOverride @this = default; string input = default; - ref byte* __invokeRetValUnmanaged = ref *__invokeRetValUnmanaged__param; + byte* __invokeRetValUnmanaged__out = default; + byte* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; string __invokeRetVal = default; int __retVal = default; + _ = __invokeRetValUnmanaged__out; try { // Unmarshal - Convert native data to managed data. @@ -126,13 +128,16 @@ internal static int ABI_StringMarshallingUtf8(System.Runtime.InteropServices.Com @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.StringMarshallingUtf8(input); // Marshal - Convert managed data to native data. - __invokeRetValUnmanaged = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(__invokeRetVal); + __invokeRetValUnmanaged__out = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.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; } @@ -141,9 +146,11 @@ internal static int ABI_MarshalAsLPWString(System.Runtime.InteropServices.ComWra { global::SharedTypes.ComInterfaces.IStringMarshallingOverride @this = default; string input = 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. @@ -152,13 +159,16 @@ internal static int ABI_MarshalAsLPWString(System.Runtime.InteropServices.ComWra @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.MarshalAsLPWString(input); // 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; } @@ -167,9 +177,11 @@ internal static int ABI_MarshalUsingUtf16(System.Runtime.InteropServices.ComWrap { global::SharedTypes.ComInterfaces.IStringMarshallingOverride @this = default; string input = 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. @@ -178,13 +190,16 @@ internal static int ABI_MarshalUsingUtf16(System.Runtime.InteropServices.ComWrap @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.MarshalUsingUtf16(input); // 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.IStringMarshallingOverrideDerived.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.cs index ce333fc..94c7090 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.cs @@ -215,9 +215,11 @@ internal static int ABI_StringMarshallingUtf8_2(System.Runtime.InteropServices.C { global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived @this = default; string input = default; - ref byte* __invokeRetValUnmanaged = ref *__invokeRetValUnmanaged__param; + byte* __invokeRetValUnmanaged__out = default; + byte* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; string __invokeRetVal = default; int __retVal = default; + _ = __invokeRetValUnmanaged__out; try { // Unmarshal - Convert native data to managed data. @@ -226,13 +228,16 @@ internal static int ABI_StringMarshallingUtf8_2(System.Runtime.InteropServices.C @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.StringMarshallingUtf8_2(input); // Marshal - Convert managed data to native data. - __invokeRetValUnmanaged = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(__invokeRetVal); + __invokeRetValUnmanaged__out = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.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; } @@ -241,9 +246,11 @@ internal static int ABI_MarshalAsLPWString_2(System.Runtime.InteropServices.ComW { global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived @this = default; string input = 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. @@ -252,13 +259,16 @@ internal static int ABI_MarshalAsLPWString_2(System.Runtime.InteropServices.ComW @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.MarshalAsLPWString_2(input); // 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; } @@ -267,9 +277,11 @@ internal static int ABI_MarshalUsingUtf16_2(System.Runtime.InteropServices.ComWr { global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived @this = default; string input = 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. @@ -278,13 +290,16 @@ internal static int ABI_MarshalUsingUtf16_2(System.Runtime.InteropServices.ComWr @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.MarshalUsingUtf16_2(input); // 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.IUTF16Marshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF16Marshalling.cs index 6386ee3..9908149 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF16Marshalling.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF16Marshalling.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.IUTF16Marshalling @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.IUTF8Marshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF8Marshalling.cs index a7ad88a..eabdbc3 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF8Marshalling.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF8Marshalling.cs @@ -76,9 +76,11 @@ file unsafe partial interface InterfaceImplementation internal static int ABI_GetString(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, byte** __invokeRetValUnmanaged__param) { global::SharedTypes.ComInterfaces.IUTF8Marshalling @this = default; - ref byte* __invokeRetValUnmanaged = ref *__invokeRetValUnmanaged__param; + byte* __invokeRetValUnmanaged__out = default; + byte* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; string __invokeRetVal = default; int __retVal = default; + _ = __invokeRetValUnmanaged__out; try { // Unmarshal - Convert native data to managed data. @@ -86,13 +88,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 = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(__invokeRetVal); + __invokeRetValUnmanaged__out = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.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; } @@ -113,6 +118,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.MarshallingFails.ICollectionMarshallingFails.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.cs new file mode 100644 index 0000000..93ff174 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.cs @@ -0,0 +1,240 @@ +// +#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[] { 149, 115, 133, 164, 251, 6, 110, 74, 129, 219, 53, 70, 27, 233, 153, 197 })); + + 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.MarshallingFails.ICollectionMarshallingFails +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + int[] global::SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.Get(out int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out size); + int[] __retVal = default; + nint* __retVal_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __size_native, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal_native__numElements = size; + __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + System.Span __retVal_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal); + for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + { + __retVal_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.ConvertToManaged(__retVal_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__retVal_native, __retVal_native__numElements); + for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__retVal_native__nativeSpan[__i0]); + } + } + + __retVal_native__numElements = size; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + } + + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.Set(int[] value, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails)); + nint* __value_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __value_native__marshaller = new(); + int __value_native__numElements; + int __value_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __value_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __value_native__marshaller.FromManaged(value, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __value_native__managedSpan = __value_native__marshaller.GetManagedValuesSource(); + System.Span __value_native__nativeSpan = __value_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __value_native__managedSpan.Length; ++__i0, ++__value_native__lastIndexMarshalled) + { + __value_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.ConvertToUnmanaged(__value_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __value_native__unused = __value_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __value_native = __value_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, __value_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __value_native__nativeSpan = __value_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __value_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__value_native__nativeSpan[__i0]); + } + } + + __value_native__marshaller.Free(); + } + } +} + +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, int* __size_native__param, nint** __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails @this = default; + int __size_native__out = default; + int __size_native = *__size_native__param; + int size = default; + nint* __invokeRetValUnmanaged__out = default; + nint* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; + int[] __invokeRetVal = default; + int __retVal = default; + _ = __size_native__out; + _ = __invokeRetValUnmanaged__out; + // Setup - Perform required setup. + int __invokeRetValUnmanaged__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Get(out size); + // Marshal - Convert managed data to native data. + __size_native__out = size; + __invokeRetValUnmanaged__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); + { + System.ReadOnlySpan __invokeRetValUnmanaged__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__invokeRetVal); + System.Span __invokeRetValUnmanaged__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements); + __invokeRetValUnmanaged__nativeSpan.Clear(); + for (int __i0 = 0; __i0 < __invokeRetValUnmanaged__managedSpan.Length; ++__i0) + { + __invokeRetValUnmanaged__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.ConvertToUnmanaged(__invokeRetValUnmanaged__managedSpan[__i0]); + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__size_native__param = __size_native__out; + *__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, nint* __value_native, int size) + { + global::SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails @this = default; + int[] value = default; + int __retVal = default; + // Setup - Perform required setup. + int __value_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __value_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __value_native__numElements = size; + value = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__value_native, __value_native__numElements); + { + System.ReadOnlySpan __value_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__value_native, __value_native__numElements); + System.Span __value_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(value); + for (int __i0 = 0; __i0 < __value_native__numElements; ++__i0) + { + __value_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.ConvertToManaged(__value_native__nativeSpan[__i0]); + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Set(value, size); + } + 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.MarshallingFails.ICollectionMarshallingFails), 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.MarshallingFails +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface ICollectionMarshallingFails + { + } +} + +namespace SharedTypes.ComInterfaces.MarshallingFails +{ + internal partial interface ICollectionMarshallingFails + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.cs new file mode 100644 index 0000000..287f6e2 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.cs @@ -0,0 +1,481 @@ +// +#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[] { 169, 168, 164, 159, 143, 61, 168, 72, 182, 251, 180, 91, 95, 27, 159, 182 })); + + 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.MarshallingFails.IJaggedIntArrayMarshallingFails +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + int[][] global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.Get(out int[] widths, out int length) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out widths); + System.Runtime.CompilerServices.Unsafe.SkipInit(out length); + int* __widths_native = default; + int[][] __retVal = default; + System.IntPtr* __retVal_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __widths_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __length_native = &length) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, &__widths_native, __length_native, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __widths_native__numElements = length; + widths = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__widths_native, __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__widths_native, __widths_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(widths)); + __retVal_native__numElements = length; + __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + System.Span __retVal_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal); + for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + { + int __retVal_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__nativeSpan____i0__numElements); + __retVal_native__nativeSpan____i0__numElements = widths[__i0]; + __retVal_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((nint*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements); + { + System.ReadOnlySpan __retVal_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements); + System.Span __retVal_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal_native__managedSpan[__i0]); + for (int __i1 = 0; __i1 < __retVal_native__nativeSpan____i0__numElements; ++__i1) + { + __retVal_native__nativeSpan____i0__managedSpan[__i1] = global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.ConvertToManaged(__retVal_native__nativeSpan____i0__nativeSpan[__i1]); + } + } + } + } + } + finally + { + // Cleanup - Perform required cleanup. + __widths_native__numElements = length; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__widths_native); + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__retVal_native, __retVal_native__numElements); + for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + { + int __retVal_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__nativeSpan____i0__numElements); + __retVal_native__nativeSpan____i0__numElements = widths[__i0]; + { + System.ReadOnlySpan __retVal_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements); + for (int __i1 = 0; __i1 < __retVal_native__nativeSpan____i0__nativeSpan.Length; ++__i1) + { + global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__retVal_native__nativeSpan____i0__nativeSpan[__i1]); + } + } + + __retVal_native__nativeSpan____i0__numElements = widths[__i0]; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__retVal_native__nativeSpan[__i0]); + } + } + + __retVal_native__numElements = length; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + } + + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + int global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.Get2(out int[][] array, out int[] widths) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out array); + System.Runtime.CompilerServices.Unsafe.SkipInit(out widths); + System.IntPtr* __array_native = default; + int* __widths_native = default; + int __retVal = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __widths_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__array_native, &__widths_native, &__retVal); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __widths_native__numElements = __retVal; + widths = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__widths_native, __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__widths_native, __widths_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(widths)); + __array_native__numElements = __retVal; + array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); + { + System.ReadOnlySpan __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements); + System.Span __array_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array); + for (int __i0 = 0; __i0 < __array_native__numElements; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan____i0__numElements = widths[__i0]; + __array_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + { + System.ReadOnlySpan __array_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + System.Span __array_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__array_native__managedSpan[__i0]); + for (int __i1 = 0; __i1 < __array_native__nativeSpan____i0__numElements; ++__i1) + { + __array_native__nativeSpan____i0__managedSpan[__i1] = global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.ConvertToManaged(__array_native__nativeSpan____i0__nativeSpan[__i1]); + } + } + } + } + } + finally + { + // Cleanup - Perform required cleanup. + __widths_native__numElements = __retVal; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__widths_native); + { + System.ReadOnlySpan __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__array_native, __array_native__numElements); + for (int __i0 = 0; __i0 < __array_native__nativeSpan.Length; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan____i0__numElements = widths[__i0]; + { + System.ReadOnlySpan __array_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + for (int __i1 = 0; __i1 < __array_native__nativeSpan____i0__nativeSpan.Length; ++__i1) + { + global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__array_native__nativeSpan____i0__nativeSpan[__i1]); + } + } + + __array_native__nativeSpan____i0__numElements = widths[__i0]; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__array_native__nativeSpan[__i0]); + } + } + + __array_native__numElements = __retVal; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native); + } + + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.Set(int[][] array, int[] widths, int length) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails)); + System.IntPtr* __array_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __array_native__marshaller = new(); + int __array_native__numElements; + int __array_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __array_native__marshaller.FromManaged(array, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __array_native__managedSpan = __array_native__marshaller.GetManagedValuesSource(); + System.Span __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __array_native__managedSpan.Length; ++__i0, ++__array_native__lastIndexMarshalled) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan[__i0] = (System.IntPtr)global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__array_native__managedSpan[__i0], out __array_native__nativeSpan____i0__numElements); + { + System.ReadOnlySpan __array_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__array_native__managedSpan[__i0]); + System.Span __array_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan____i0__nativeSpan.Clear(); + for (int __i1 = 0; __i1 < __array_native__nativeSpan____i0__managedSpan.Length; ++__i1) + { + __array_native__nativeSpan____i0__nativeSpan[__i1] = global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.ConvertToUnmanaged(__array_native__nativeSpan____i0__managedSpan[__i1]); + } + } + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __widths_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(widths)) + fixed (void* __array_native__unused = __array_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __array_native = __array_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, __array_native, (int*)__widths_native, length); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __array_native__lastIndexMarshalled; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan____i0__numElements = 0; + { + System.ReadOnlySpan __array_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + for (int __i1 = 0; __i1 < __array_native__nativeSpan____i0__nativeSpan.Length; ++__i1) + { + global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__array_native__nativeSpan____i0__nativeSpan[__i1]); + } + }; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__array_native__nativeSpan[__i0]); + } + } + + __array_native__marshaller.Free(); + } + } +} + +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, int** __widths_native__param, int* __length_native__param, System.IntPtr** __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails @this = default; + int* __widths_native__out = default; + int* __widths_native = *__widths_native__param; + int[] widths = default; + int __length_native__out = default; + int __length_native = *__length_native__param; + int length = default; + System.IntPtr* __invokeRetValUnmanaged__out = default; + System.IntPtr* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; + int[][] __invokeRetVal = default; + int __retVal = default; + _ = __widths_native__out; + _ = __length_native__out; + _ = __invokeRetValUnmanaged__out; + // Setup - Perform required setup. + int __widths_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); + int __invokeRetValUnmanaged__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Get(out widths, out length); + // Marshal - Convert managed data to native data. + __length_native__out = length; + __widths_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(widths, out __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(widths).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__widths_native__out, __widths_native__numElements)); + __invokeRetValUnmanaged__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); + { + System.ReadOnlySpan __invokeRetValUnmanaged__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__invokeRetVal); + System.Span __invokeRetValUnmanaged__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements); + __invokeRetValUnmanaged__nativeSpan.Clear(); + for (int __i0 = 0; __i0 < __invokeRetValUnmanaged__managedSpan.Length; ++__i0) + { + int __invokeRetValUnmanaged__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__nativeSpan____i0__numElements); + __invokeRetValUnmanaged__nativeSpan[__i0] = (System.IntPtr)global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetValUnmanaged__managedSpan[__i0], out __invokeRetValUnmanaged__nativeSpan____i0__numElements); + { + System.ReadOnlySpan __invokeRetValUnmanaged__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__invokeRetValUnmanaged__managedSpan[__i0]); + System.Span __invokeRetValUnmanaged__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__invokeRetValUnmanaged__nativeSpan[__i0], __invokeRetValUnmanaged__nativeSpan____i0__numElements); + __invokeRetValUnmanaged__nativeSpan____i0__nativeSpan.Clear(); + for (int __i1 = 0; __i1 < __invokeRetValUnmanaged__nativeSpan____i0__managedSpan.Length; ++__i1) + { + __invokeRetValUnmanaged__nativeSpan____i0__nativeSpan[__i1] = global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.ConvertToUnmanaged(__invokeRetValUnmanaged__nativeSpan____i0__managedSpan[__i1]); + } + } + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__length_native__param = __length_native__out; + *__widths_native__param = __widths_native__out; + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Get2(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, System.IntPtr** __array_native__param, int** __widths_native__param, int* __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails @this = default; + System.IntPtr* __array_native__out = default; + System.IntPtr* __array_native = *__array_native__param; + int[][] array = default; + int* __widths_native__out = default; + int* __widths_native = *__widths_native__param; + int[] widths = default; + int __invokeRetValUnmanaged__out = default; + int __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; + int __invokeRetVal = default; + int __retVal = default; + _ = __array_native__out; + _ = __widths_native__out; + _ = __invokeRetValUnmanaged__out; + // Setup - Perform required setup. + int __widths_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Get2(out array, out widths); + // Marshal - Convert managed data to native data. + __invokeRetValUnmanaged__out = __invokeRetVal; + __widths_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(widths, out __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(widths).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__widths_native__out, __widths_native__numElements)); + __array_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(array, out __array_native__numElements); + { + System.ReadOnlySpan __array_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(array); + System.Span __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__array_native__out, __array_native__numElements); + __array_native__nativeSpan.Clear(); + for (int __i0 = 0; __i0 < __array_native__managedSpan.Length; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan[__i0] = (System.IntPtr)global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__array_native__managedSpan[__i0], out __array_native__nativeSpan____i0__numElements); + { + System.ReadOnlySpan __array_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__array_native__managedSpan[__i0]); + System.Span __array_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan____i0__nativeSpan.Clear(); + for (int __i1 = 0; __i1 < __array_native__nativeSpan____i0__managedSpan.Length; ++__i1) + { + __array_native__nativeSpan____i0__nativeSpan[__i1] = global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.ConvertToUnmanaged(__array_native__nativeSpan____i0__managedSpan[__i1]); + } + } + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + *__widths_native__param = __widths_native__out; + *__array_native__param = __array_native__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, System.IntPtr* __array_native, int* __widths_native, int length) + { + global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails @this = default; + int[][] array = default; + int[] widths = default; + int __retVal = default; + // Setup - Perform required setup. + int __widths_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __widths_native__numElements = length; + widths = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__widths_native, __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__widths_native, __widths_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(widths)); + __array_native__numElements = length; + array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); + { + System.ReadOnlySpan __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements); + System.Span __array_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array); + for (int __i0 = 0; __i0 < __array_native__numElements; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan____i0__numElements = widths[__i0]; + __array_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + { + System.ReadOnlySpan __array_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + System.Span __array_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__array_native__managedSpan[__i0]); + for (int __i1 = 0; __i1 < __array_native__nativeSpan____i0__numElements; ++__i1) + { + __array_native__nativeSpan____i0__managedSpan[__i1] = global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.ConvertToManaged(__array_native__nativeSpan____i0__nativeSpan[__i1]); + } + } + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Set(array, widths, length); + } + 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.MarshallingFails.IJaggedIntArrayMarshallingFails), sizeof(void*) * 6); + { + 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_Get2; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Set; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces.MarshallingFails +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IJaggedIntArrayMarshallingFails + { + } +} + +namespace SharedTypes.ComInterfaces.MarshallingFails +{ + internal partial interface IJaggedIntArrayMarshallingFails + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs index 71cc4e9..9acf26b 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs @@ -363,6 +363,7 @@ internal static int ABI_Param(System.Runtime.InteropServices.ComWrappers.ComInte catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } return __retVal; @@ -372,7 +373,7 @@ internal static int ABI_Param(System.Runtime.InteropServices.ComWrappers.ComInte internal static int ABI_InParam(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint** __value_native__param) { global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails @this = default; - ref nint* __value_native = ref *__value_native__param; + nint* __value_native = *__value_native__param; string[] value = default; int __retVal = default; // Setup - Perform required setup. @@ -399,6 +400,7 @@ internal static int ABI_InParam(System.Runtime.InteropServices.ComWrappers.ComIn catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } return __retVal; @@ -408,14 +410,14 @@ internal static int ABI_InParam(System.Runtime.InteropServices.ComWrappers.ComIn internal static int ABI_RefParam(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint** __value_native__param) { global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails @this = default; - ref nint* __value_native = ref *__value_native__param; + nint* __value_native__out = default; + nint* __value_native = *__value_native__param; string[] value = default; int __retVal = default; + _ = __value_native__out; // Setup - Perform required setup. int __value_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __value_native__numElements); - bool __value_native__ownOriginal = false; - nint* __value_native__original = __value_native; int __value_native__lastIndexMarshalled = 0; try { @@ -435,11 +437,10 @@ internal static int ABI_RefParam(System.Runtime.InteropServices.ComWrappers.ComI @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.RefParam(ref value); // Marshal - Convert managed data to native data. - __value_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(value, out __value_native__numElements); - __value_native__ownOriginal = true; + __value_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(value, out __value_native__numElements); { System.ReadOnlySpan __value_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(value); - System.Span __value_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__value_native, __value_native__numElements); + System.Span __value_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__value_native__out, __value_native__numElements); for (int __i0 = 0; __i0 < __value_native__managedSpan.Length; ++__i0, ++__value_native__lastIndexMarshalled) { __value_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToUnmanaged(__value_native__managedSpan[__i0]); @@ -449,18 +450,19 @@ internal static int ABI_RefParam(System.Runtime.InteropServices.ComWrappers.ComI catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); - } - finally - { // Cleanup - Perform required cleanup. - if (__value_native__ownOriginal) - { - _ = __value_native__lastIndexMarshalled; - __value_native__numElements = 10; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__value_native__original); - } + _ = __value_native__lastIndexMarshalled; + __value_native__numElements = 10; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__value_native__out); + return __retVal; } + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; + // Cleanup - Perform required cleanup. + _ = __value_native__lastIndexMarshalled; + __value_native__numElements = 10; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__value_native); return __retVal; } @@ -468,9 +470,11 @@ internal static int ABI_RefParam(System.Runtime.InteropServices.ComWrappers.ComI internal static int ABI_OutParam(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint** __value_native__param) { global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails @this = default; - ref nint* __value_native = ref *__value_native__param; + nint* __value_native__out = default; + nint* __value_native = *__value_native__param; string[] value = default; int __retVal = default; + _ = __value_native__out; // Setup - Perform required setup. int __value_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __value_native__numElements); @@ -481,10 +485,10 @@ internal static int ABI_OutParam(System.Runtime.InteropServices.ComWrappers.ComI @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.OutParam(out value); // Marshal - Convert managed data to native data. - __value_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(value, out __value_native__numElements); + __value_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(value, out __value_native__numElements); { System.ReadOnlySpan __value_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(value); - System.Span __value_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__value_native, __value_native__numElements); + System.Span __value_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__value_native__out, __value_native__numElements); __value_native__nativeSpan.Clear(); for (int __i0 = 0; __i0 < __value_native__managedSpan.Length; ++__i0) { @@ -495,8 +499,11 @@ internal static int ABI_OutParam(System.Runtime.InteropServices.ComWrappers.ComI catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; return __retVal; } @@ -509,6 +516,7 @@ internal static int ABI_ByValueOutParam(System.Runtime.InteropServices.ComWrappe // Setup - Perform required setup. int __value_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __value_native__numElements); + System.Span __value_native__out; try { // Unmarshal - Convert native data to managed data. @@ -519,7 +527,10 @@ internal static int ABI_ByValueOutParam(System.Runtime.InteropServices.ComWrappe // Marshal - Convert managed data to native data. { __value_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(value).Length; - System.Span __value_native__nativeSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__value_native, __value_native__numElements).GetPinnableReference()), __value_native__numElements); +#pragma warning disable CS9081 + __value_native__out = stackalloc nint[__value_native__numElements]; +#pragma warning restore CS9081 + System.Span __value_native__nativeSpan = __value_native__out; System.Span __value_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(value); for (int __i0 = 0; __i0 < __value_native__numElements; ++__i0) { @@ -531,8 +542,13 @@ internal static int ABI_ByValueOutParam(System.Runtime.InteropServices.ComWrappe catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } + // AssignOut - Assign to parameters + __value_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__value_native, __value_native__numElements).GetPinnableReference()), __value_native__numElements)); + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__value_native); return __retVal; } @@ -545,6 +561,7 @@ internal static int ABI_ByValueInOutParam(System.Runtime.InteropServices.ComWrap // Setup - Perform required setup. int __value_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __value_native__numElements); + System.Span __value_native__out; try { // Unmarshal - Convert native data to managed data. @@ -565,7 +582,10 @@ internal static int ABI_ByValueInOutParam(System.Runtime.InteropServices.ComWrap // Marshal - Convert managed data to native data. { __value_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(value).Length; - System.Span __value_native__nativeSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__value_native, __value_native__numElements).GetPinnableReference()), __value_native__numElements); +#pragma warning disable CS9081 + __value_native__out = stackalloc nint[__value_native__numElements]; +#pragma warning restore CS9081 + System.Span __value_native__nativeSpan = __value_native__out; System.Span __value_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(value); for (int __i0 = 0; __i0 < __value_native__numElements; ++__i0) { @@ -577,8 +597,13 @@ internal static int ABI_ByValueInOutParam(System.Runtime.InteropServices.ComWrap catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } + // AssignOut - Assign to parameters + __value_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__value_native, __value_native__numElements).GetPinnableReference()), __value_native__numElements)); + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__value_native); return __retVal; } @@ -586,9 +611,11 @@ internal static int ABI_ByValueInOutParam(System.Runtime.InteropServices.ComWrap internal static int ABI_ReturnValue(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint** __invokeRetValUnmanaged__param) { global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails @this = default; - ref nint* __invokeRetValUnmanaged = ref *__invokeRetValUnmanaged__param; + nint* __invokeRetValUnmanaged__out = default; + nint* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; string[] __invokeRetVal = default; int __retVal = default; + _ = __invokeRetValUnmanaged__out; // Setup - Perform required setup. int __invokeRetValUnmanaged__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); @@ -599,10 +626,10 @@ internal static int ABI_ReturnValue(System.Runtime.InteropServices.ComWrappers.C @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.ReturnValue(); // Marshal - Convert managed data to native data. - __invokeRetValUnmanaged = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); + __invokeRetValUnmanaged__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); { System.ReadOnlySpan __invokeRetValUnmanaged__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__invokeRetVal); - System.Span __invokeRetValUnmanaged__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__invokeRetValUnmanaged, __invokeRetValUnmanaged__numElements); + System.Span __invokeRetValUnmanaged__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements); __invokeRetValUnmanaged__nativeSpan.Clear(); for (int __i0 = 0; __i0 < __invokeRetValUnmanaged__managedSpan.Length; ++__i0) { @@ -613,8 +640,11 @@ internal static int ABI_ReturnValue(System.Runtime.InteropServices.ComWrappers.C 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.VtableIndexStubGenerator/NativeToManagedStubs.g.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeToManagedStubs.g.cs index 17b9691..d4dda1b 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeToManagedStubs.g.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeToManagedStubs.g.cs @@ -61,14 +61,18 @@ internal unsafe partial interface Native internal static void ABI_ExchangeData(void* __this_native, int* __x_native__param) { global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject @this; - ref int __x_native = ref *__x_native__param; + int __x_native__out = default; + int __x_native = *__x_native__param; int x; + _ = __x_native__out; // Unmarshal - Convert native data to managed data. x = __x_native; @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); @this.ExchangeData(ref x); // Marshal - Convert managed data to native data. - __x_native = x; + __x_native__out = x; + // AssignOut - Assign to parameters + *__x_native__param = __x_native__out; } } } @@ -90,8 +94,10 @@ internal static void ABI_SumAndSetData(void* __this_native, int* __values_native { global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject @this; int[] values; - ref int __oldValue_native = ref *__oldValue_native__param; + int __oldValue_native__out = default; + int __oldValue_native = *__oldValue_native__param; int oldValue; + _ = __oldValue_native__out; // Setup - Perform required setup. int __values_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); @@ -102,7 +108,9 @@ internal static void ABI_SumAndSetData(void* __this_native, int* __values_native @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); @this.SumAndSetData(values, numValues, out oldValue); // Marshal - Convert managed data to native data. - __oldValue_native = oldValue; + __oldValue_native__out = oldValue; + // AssignOut - Assign to parameters + *__oldValue_native__param = __oldValue_native__out; } } } @@ -123,38 +131,33 @@ internal unsafe partial interface Native internal static void ABI_SumAndSetData(void* __this_native, int** __values_native__param, int numValues, int* __oldValue_native__param) { global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject @this = default; - ref int* __values_native = ref *__values_native__param; + int* __values_native__out = default; + int* __values_native = *__values_native__param; int[] values = default; - ref int __oldValue_native = ref *__oldValue_native__param; + int __oldValue_native__out = default; + int __oldValue_native = *__oldValue_native__param; int oldValue = default; + _ = __values_native__out; + _ = __oldValue_native__out; // Setup - Perform required setup. int __values_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); - bool __values_native__ownOriginal = false; - int* __values_native__original = __values_native; - try - { - // Unmarshal - Convert native data to managed data. - __values_native__numElements = numValues; - values = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values)); - @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); - @this.SumAndSetData(ref values, numValues, out oldValue); - // Marshal - Convert managed data to native data. - __oldValue_native = oldValue; - __values_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); - __values_native__ownOriginal = true; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(values).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); - } - finally - { - // Cleanup - Perform required cleanup. - if (__values_native__ownOriginal) - { - __values_native__numElements = numValues; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values_native__original); - } - } + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; + values = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values)); + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.SumAndSetData(ref values, numValues, out oldValue); + // Marshal - Convert managed data to native data. + __oldValue_native__out = oldValue; + __values_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(values).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__values_native__out, __values_native__numElements)); + // AssignOut - Assign to parameters + *__oldValue_native__param = __oldValue_native__out; + *__values_native__param = __values_native__out; + // Cleanup - Perform required cleanup. + __values_native__numElements = numValues; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values_native); } } } @@ -258,29 +261,20 @@ internal unsafe partial interface Native internal static void ABI_ExchangeData(void* __this_native, int* __data_native__param) { global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject @this = default; - ref int __data_native = ref *__data_native__param; + int __data_native__out = default; + int __data_native = *__data_native__param; global::SharedTypes.IntWrapper data = default; - // Setup - Perform required setup. - bool __data_native__ownOriginal = false; - int __data_native__original = __data_native; - try - { - // Unmarshal - Convert native data to managed data. - data = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__data_native); - @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); - @this.ExchangeData(ref data); - // Marshal - Convert managed data to native data. - __data_native = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(data); - __data_native__ownOriginal = true; - } - finally - { - // Cleanup - Perform required cleanup. - if (__data_native__ownOriginal) - { - global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__data_native__original); - } - } + _ = __data_native__out; + // Unmarshal - Convert native data to managed data. + data = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__data_native); + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.ExchangeData(ref data); + // Marshal - Convert managed data to native data. + __data_native__out = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(data); + // AssignOut - Assign to parameters + *__data_native__param = __data_native__out; + // Cleanup - Perform required cleanup. + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__data_native); } } } @@ -302,8 +296,10 @@ internal static void ABI_SumAndSetData(void* __this_native, int* __values_native { global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject @this; global::SharedTypes.IntWrapper[] values; - ref int __oldValue_native = ref *__oldValue_native__param; + int __oldValue_native__out = default; + int __oldValue_native = *__oldValue_native__param; global::SharedTypes.IntWrapper oldValue; + _ = __oldValue_native__out; // Setup - Perform required setup. int __values_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); @@ -322,7 +318,9 @@ internal static void ABI_SumAndSetData(void* __this_native, int* __values_native @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); @this.SumAndSetData(values, numValues, out oldValue); // Marshal - Convert managed data to native data. - __oldValue_native = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(oldValue); + __oldValue_native__out = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(oldValue); + // AssignOut - Assign to parameters + *__oldValue_native__param = __oldValue_native__out; } } } @@ -343,62 +341,58 @@ internal unsafe partial interface Native internal static void ABI_SumAndSetData(void* __this_native, int** __values_native__param, int numValues, int* __oldValue_native__param) { global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject @this = default; - ref int* __values_native = ref *__values_native__param; + int* __values_native__out = default; + int* __values_native = *__values_native__param; global::SharedTypes.IntWrapper[] values = default; - ref int __oldValue_native = ref *__oldValue_native__param; + int __oldValue_native__out = default; + int __oldValue_native = *__oldValue_native__param; global::SharedTypes.IntWrapper oldValue = default; + _ = __values_native__out; + _ = __oldValue_native__out; // Setup - Perform required setup. int __values_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); - bool __values_native__ownOriginal = false; - int* __values_native__original = __values_native; int __values_native__lastIndexMarshalled = 0; - try + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; + values = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); { - // Unmarshal - Convert native data to managed data. - __values_native__numElements = numValues; - values = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); + System.ReadOnlySpan __values_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements); + System.Span __values_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values); + for (int __i0 = 0; __i0 < __values_native__numElements; ++__i0) { - System.ReadOnlySpan __values_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements); - System.Span __values_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values); - for (int __i0 = 0; __i0 < __values_native__numElements; ++__i0) - { - __values_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values_native__nativeSpan[__i0]); - } + __values_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values_native__nativeSpan[__i0]); } + } - @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); - @this.SumAndSetData(ref values, numValues, out oldValue); - // Marshal - Convert managed data to native data. - __oldValue_native = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(oldValue); - __values_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); - __values_native__ownOriginal = true; + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.SumAndSetData(ref values, numValues, out oldValue); + // Marshal - Convert managed data to native data. + __oldValue_native__out = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(oldValue); + __values_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); + { + System.ReadOnlySpan __values_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(values); + System.Span __values_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__values_native__out, __values_native__numElements); + for (int __i0 = 0; __i0 < __values_native__managedSpan.Length; ++__i0, ++__values_native__lastIndexMarshalled) { - System.ReadOnlySpan __values_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(values); - System.Span __values_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements); - for (int __i0 = 0; __i0 < __values_native__managedSpan.Length; ++__i0, ++__values_native__lastIndexMarshalled) - { - __values_native__nativeSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(__values_native__managedSpan[__i0]); - } + __values_native__nativeSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(__values_native__managedSpan[__i0]); } } - finally + + // AssignOut - Assign to parameters + *__oldValue_native__param = __oldValue_native__out; + *__values_native__param = __values_native__out; + // Cleanup - Perform required cleanup. { - // Cleanup - Perform required cleanup. - if (__values_native__ownOriginal) + System.ReadOnlySpan __values_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements); + for (int __i0 = 0; __i0 < __values_native__lastIndexMarshalled; ++__i0) { - { - System.ReadOnlySpan __values_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native__original, __values_native__numElements); - for (int __i0 = 0; __i0 < __values_native__lastIndexMarshalled; ++__i0) - { - global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values_native__nativeSpan[__i0]); - } - } - - __values_native__numElements = numValues; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values_native__original); + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values_native__nativeSpan[__i0]); } } + + __values_native__numElements = numValues; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values_native); } } } @@ -418,11 +412,12 @@ internal unsafe partial interface Native [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] internal static void ABI_MultiplyWithData(void* __this_native, int* __values123_native, int numValues) { - global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject @this; - global::SharedTypes.IntWrapper[] values123; + global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject @this = default; + global::SharedTypes.IntWrapper[] values123 = default; // Setup - Perform required setup. int __values123_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __values123_native__numElements); + System.Span __values123_native__out; // Unmarshal - Convert native data to managed data. __values123_native__numElements = numValues; values123 = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values123_native, __values123_native__numElements); @@ -440,7 +435,10 @@ internal static void ABI_MultiplyWithData(void* __this_native, int* __values123_ // Marshal - Convert managed data to native data. { __values123_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values123).Length; - System.Span __values123_native__nativeSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values123_native, __values123_native__numElements).GetPinnableReference()), __values123_native__numElements); +#pragma warning disable CS9081 + __values123_native__out = stackalloc int[__values123_native__numElements]; +#pragma warning restore CS9081 + System.Span __values123_native__nativeSpan = __values123_native__out; System.Span __values123_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values123); for (int __i0 = 0; __i0 < __values123_native__numElements; ++__i0) { @@ -449,6 +447,11 @@ internal static void ABI_MultiplyWithData(void* __this_native, int* __values123_ global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values123_native__nativeSpan____i0__original); } } + + // AssignOut - Assign to parameters + __values123_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values123_native, __values123_native__numElements).GetPinnableReference()), __values123_native__numElements)); + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values123_native); } } } @@ -470,38 +473,36 @@ internal static void ABI_SumAndSetData(void* __this_native, int* __values_native { global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObjectStateful @this = default; global::SharedTypes.IntWrapper[] values = default; - ref int __oldValue_native = ref *__oldValue_native__param; + int __oldValue_native__out = default; + int __oldValue_native = *__oldValue_native__param; global::SharedTypes.IntWrapper oldValue = default; + _ = __oldValue_native__out; // Setup - Perform required setup. global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.StatefulUnmanagedToManagedCollectionMarshaller.In __values_native__marshaller = new(); int __values_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); - try + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __values_native__marshaller.FromUnmanaged(__values_native); + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; { - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __values_native__marshaller.FromUnmanaged(__values_native); - // Unmarshal - Convert native data to managed data. - __values_native__numElements = numValues; + System.ReadOnlySpan __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesSource(__values_native__numElements); + System.Span __values_native__managedSpan = __values_native__marshaller.GetManagedValuesDestination(__values_native__numElements); + for (int __i0 = 0; __i0 < __values_native__numElements; ++__i0) { - System.ReadOnlySpan __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesSource(__values_native__numElements); - System.Span __values_native__managedSpan = __values_native__marshaller.GetManagedValuesDestination(__values_native__numElements); - for (int __i0 = 0; __i0 < __values_native__numElements; ++__i0) - { - __values_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values_native__nativeSpan[__i0]); - } + __values_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values_native__nativeSpan[__i0]); } - - values = __values_native__marshaller.ToManaged(); - @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObjectStateful)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); - @this.SumAndSetData(values, numValues, out oldValue); - // Marshal - Convert managed data to native data. - __oldValue_native = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(oldValue); - } - finally - { - // Cleanup - Perform required cleanup. - __values_native__marshaller.Free(); } + + values = __values_native__marshaller.ToManaged(); + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObjectStateful)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.SumAndSetData(values, numValues, out oldValue); + // Marshal - Convert managed data to native data. + __oldValue_native__out = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(oldValue); + // AssignOut - Assign to parameters + *__oldValue_native__param = __oldValue_native__out; + // Cleanup - Perform required cleanup. + __values_native__marshaller.Free(); } } } @@ -522,66 +523,63 @@ internal unsafe partial interface Native internal static void ABI_SumAndSetData(void* __this_native, int** __values_native__param, int numValues, int* __oldValue_native__param) { global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObjectStateful @this = default; - ref int* __values_native = ref *__values_native__param; + int* __values_native__out = default; + int* __values_native = *__values_native__param; global::SharedTypes.IntWrapper[] values = default; - ref int __oldValue_native = ref *__oldValue_native__param; + int __oldValue_native__out = default; + int __oldValue_native = *__oldValue_native__param; global::SharedTypes.IntWrapper oldValue = default; + _ = __values_native__out; + _ = __oldValue_native__out; // Setup - Perform required setup. global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.StatefulUnmanagedToManagedCollectionMarshaller.Ref __values_native__marshaller = new(); - bool __values_native__ownOriginal = false; - int* __values_native__original = __values_native; int __values_native__numElements; int __values_native__lastIndexMarshalled = 0; System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); - try + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __values_native__marshaller.FromUnmanaged(__values_native); + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; { - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __values_native__marshaller.FromUnmanaged(__values_native); - // Unmarshal - Convert native data to managed data. - __values_native__numElements = numValues; + System.ReadOnlySpan __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesSource(__values_native__numElements); + System.Span __values_native__managedSpan = __values_native__marshaller.GetManagedValuesDestination(__values_native__numElements); + for (int __i0 = 0; __i0 < __values_native__numElements; ++__i0) { - System.ReadOnlySpan __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesSource(__values_native__numElements); - System.Span __values_native__managedSpan = __values_native__marshaller.GetManagedValuesDestination(__values_native__numElements); - for (int __i0 = 0; __i0 < __values_native__numElements; ++__i0) - { - __values_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values_native__nativeSpan[__i0]); - } + __values_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values_native__nativeSpan[__i0]); } + } - values = __values_native__marshaller.ToManaged(); - @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObjectStateful)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); - @this.SumAndSetData(ref values, numValues, out oldValue); - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __values_native = __values_native__marshaller.ToUnmanaged(); - // Marshal - Convert managed data to native data. - __oldValue_native = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(oldValue); - __values_native__marshaller.FromManaged(values); - __values_native__ownOriginal = true; + values = __values_native__marshaller.ToManaged(); + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObjectStateful)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.SumAndSetData(ref values, numValues, out oldValue); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __values_native = __values_native__marshaller.ToUnmanaged(); + // Marshal - Convert managed data to native data. + __oldValue_native__out = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(oldValue); + __values_native__marshaller.FromManaged(values); + { + System.ReadOnlySpan __values_native__managedSpan = __values_native__marshaller.GetManagedValuesSource(); + System.Span __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesDestination(); + __values_native__out = (int*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref __values_native__nativeSpan.GetPinnableReference()); + for (int __i0 = 0; __i0 < __values_native__managedSpan.Length; ++__i0, ++__values_native__lastIndexMarshalled) { - System.ReadOnlySpan __values_native__managedSpan = __values_native__marshaller.GetManagedValuesSource(); - System.Span __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __values_native__managedSpan.Length; ++__i0, ++__values_native__lastIndexMarshalled) - { - __values_native__nativeSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(__values_native__managedSpan[__i0]); - } + __values_native__nativeSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(__values_native__managedSpan[__i0]); } } - finally + + // AssignOut - Assign to parameters + *__oldValue_native__param = __oldValue_native__out; + *__values_native__param = __values_native__out; + // Cleanup - Perform required cleanup. { - // Cleanup - Perform required cleanup. - if (__values_native__ownOriginal) + System.ReadOnlySpan __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesSource(__values_native__numElements); + for (int __i0 = 0; __i0 < __values_native__lastIndexMarshalled; ++__i0) { - { - System.ReadOnlySpan __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesSource(__values_native__numElements); - for (int __i0 = 0; __i0 < __values_native__lastIndexMarshalled; ++__i0) - { - global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values_native__nativeSpan[__i0]); - } - } + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values_native__nativeSpan[__i0]); } - - __values_native__marshaller.Free(); } + + __values_native__marshaller.Free(); } } } @@ -607,42 +605,51 @@ internal static void ABI_MultiplyWithData(void* __this_native, int* __values123_ global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.StatefulUnmanagedToManagedCollectionMarshaller.In __values123_native__marshaller = new(); int __values123_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __values123_native__numElements); - try + System.Span __values123_native__out; + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __values123_native__marshaller.FromUnmanaged(__values123_native); + // Unmarshal - Convert native data to managed data. + __values123_native__numElements = numValues; { - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __values123_native__marshaller.FromUnmanaged(__values123_native); - // Unmarshal - Convert native data to managed data. - __values123_native__numElements = numValues; + System.ReadOnlySpan __values123_native__nativeSpan = __values123_native__marshaller.GetUnmanagedValuesSource(__values123_native__numElements); + System.Span __values123_native__managedSpan = __values123_native__marshaller.GetManagedValuesDestination(__values123_native__numElements); + for (int __i0 = 0; __i0 < __values123_native__numElements; ++__i0) { - System.ReadOnlySpan __values123_native__nativeSpan = __values123_native__marshaller.GetUnmanagedValuesSource(__values123_native__numElements); - System.Span __values123_native__managedSpan = __values123_native__marshaller.GetManagedValuesDestination(__values123_native__numElements); - for (int __i0 = 0; __i0 < __values123_native__numElements; ++__i0) - { - __values123_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values123_native__nativeSpan[__i0]); - } + __values123_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values123_native__nativeSpan[__i0]); } + } - values123 = __values123_native__marshaller.ToManaged(); - @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObjectStateful)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); - @this.MultiplyWithData(values123, numValues); - // Marshal - Convert managed data to native data. + values123 = __values123_native__marshaller.ToManaged(); + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObjectStateful)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.MultiplyWithData(values123, numValues); + // Marshal - Convert managed data to native data. + { + __values123_native__numElements = __values123_native__marshaller.GetManagedValuesDestination(__values123_native__numElements).Length; +#pragma warning disable CS9081 + __values123_native__out = stackalloc int[__values123_native__numElements]; +#pragma warning restore CS9081 + System.Span __values123_native__nativeSpan = __values123_native__out; + System.Span __values123_native__managedSpan = __values123_native__marshaller.GetManagedValuesDestination(__values123_native__numElements); + for (int __i0 = 0; __i0 < __values123_native__numElements; ++__i0) { - __values123_native__numElements = __values123_native__marshaller.GetManagedValuesDestination(__values123_native__numElements).Length; - System.Span __values123_native__nativeSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __values123_native__marshaller.GetUnmanagedValuesSource(__values123_native__numElements).GetPinnableReference()), __values123_native__numElements); - System.Span __values123_native__managedSpan = __values123_native__marshaller.GetManagedValuesDestination(__values123_native__numElements); - for (int __i0 = 0; __i0 < __values123_native__numElements; ++__i0) - { - int __values123_native__nativeSpan____i0__original = __values123_native__nativeSpan[__i0]; - __values123_native__nativeSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(__values123_native__managedSpan[__i0]); - global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values123_native__nativeSpan____i0__original); - } + int __values123_native__nativeSpan____i0__original = __values123_native__nativeSpan[__i0]; + __values123_native__nativeSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(__values123_native__managedSpan[__i0]); + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values123_native__nativeSpan____i0__original); } } - finally + + // AssignOut - Assign to parameters + __values123_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __values123_native__marshaller.GetUnmanagedValuesSource(__values123_native__numElements).GetPinnableReference()), __values123_native__numElements)); + // Cleanup - Perform required cleanup. { - // Cleanup - Perform required cleanup. - __values123_native__marshaller.Free(); + System.ReadOnlySpan __values123_native__nativeSpan = __values123_native__marshaller.GetUnmanagedValuesSource(__values123_native__numElements); + for (int __i0 = 0; __i0 < __values123_native__nativeSpan.Length; ++__i0) + { + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values123_native__nativeSpan[__i0]); + } } + + __values123_native__marshaller.Free(); } } } From 1d463abe89f7076cf839833df2131ac524ada683 Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Fri, 21 Jul 2023 12:55:33 -0700 Subject: [PATCH 2/8] merge main --- .../SharedTypes.ComInterfaces.IBool.cs | 10 ++- ...ComInterfaces.ICustomCollectionStateful.cs | 52 +++++++----- .../SharedTypes.ComInterfaces.IFloat.cs | 10 ++- .../SharedTypes.ComInterfaces.IInt.cs | 31 +++++-- .../SharedTypes.ComInterfaces.IIntArray.cs | 81 +++++++++++++------ .../SharedTypes.ComInterfaces.IInterface.cs | 45 ++++++----- ...aredTypes.ComInterfaces.IJaggedIntArray.cs | 55 +++++++++---- .../SharedTypes.ComInterfaces.IRefStrings.cs | 35 ++++---- ...allingFails.ICollectionMarshallingFails.cs | 19 +++-- ...ngFails.IJaggedIntArrayMarshallingFails.cs | 55 +++++++++---- 10 files changed, 263 insertions(+), 130 deletions(-) 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 index c0be69e..f7d3ac7 100644 --- 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 @@ -55,9 +55,11 @@ file unsafe partial interface InterfaceImplementation internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, sbyte* __invokeRetValUnmanaged__param) { global::SharedTypes.ComInterfaces.IBool @this = default; - ref sbyte __invokeRetValUnmanaged = ref *__invokeRetValUnmanaged__param; + sbyte __invokeRetValUnmanaged__out = default; + sbyte __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; bool __invokeRetVal = default; int __retVal = default; + _ = __invokeRetValUnmanaged__out; try { // Unmarshal - Convert native data to managed data. @@ -65,13 +67,16 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Get(); // Marshal - Convert managed data to native data. - __invokeRetValUnmanaged = (sbyte)(__invokeRetVal ? 1 : 0); + __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; } @@ -92,6 +97,7 @@ internal static int ABI_Set(System.Runtime.InteropServices.ComWrappers.ComInterf 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.ICustomCollectionStateful.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.ICustomCollectionStateful.cs index e942d1c..01dc341 100644 --- 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 @@ -153,19 +153,27 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt { global::SharedTypes.ComInterfaces.ICustomCollectionStateful @this = default; global::SharedTypes.ComInterfaces.TestCollection p = default; - ref byte* __pIn_native = ref *__pIn_native__param; + byte* __pIn_native = *__pIn_native__param; global::SharedTypes.ComInterfaces.TestCollection pIn = default; - ref int __pInSize_native = ref *__pInSize_native__param; + int __pInSize_native = *__pInSize_native__param; int pInSize = default; - ref byte* __pRef_native = ref *__pRef_native__param; + byte* __pRef_native__out = default; + byte* __pRef_native = *__pRef_native__param; global::SharedTypes.ComInterfaces.TestCollection pRef = default; - ref byte* __pOut_native = ref *__pOut_native__param; + byte* __pOut_native__out = default; + byte* __pOut_native = *__pOut_native__param; global::SharedTypes.ComInterfaces.TestCollection pOut = default; - ref int __pOutSize_native = ref *__pOutSize_native__param; + int __pOutSize_native__out = default; + int __pOutSize_native = *__pOutSize_native__param; int pOutSize = default; - ref byte* __invokeRetValUnmanaged = ref *__invokeRetValUnmanaged__param; + 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; @@ -174,8 +182,6 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt int __pOut_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __pOut_native__numElements); scoped global::SharedTypes.ComInterfaces.Marshaller.Ref __pRef_native__marshaller = new(); - bool __pRef_native__ownOriginal = false; - byte* __pRef_native__original = __pRef_native; int __pRef_native__numElements; int __pRef_native__lastIndexMarshalled = 0; System.Runtime.CompilerServices.Unsafe.SkipInit(out __pRef_native__numElements); @@ -239,18 +245,20 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt 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 = pOutSize; + __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]); @@ -258,10 +266,10 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt } __pRef_native__marshaller.FromManaged(pRef); - __pRef_native__ownOriginal = true; { 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]); @@ -271,22 +279,22 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); - } - finally - { // Cleanup - Perform required cleanup. - __invokeRetValUnmanaged__marshaller.Free(); - __pOut_native__marshaller.Free(); - if (__pRef_native__ownOriginal) - { - _ = __pRef_native__lastIndexMarshalled; - } - + _ = __pRef_native__lastIndexMarshalled; __pRef_native__marshaller.Free(); - __pIn_native__marshaller.Free(); - __p_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; } } diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IFloat.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IFloat.cs index dca0a9a..c703f8b 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IFloat.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IFloat.cs @@ -50,9 +50,11 @@ file unsafe partial interface InterfaceImplementation internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, float* __invokeRetValUnmanaged__param) { global::SharedTypes.ComInterfaces.IFloat @this = default; - ref float __invokeRetValUnmanaged = ref *__invokeRetValUnmanaged__param; + float __invokeRetValUnmanaged__out = default; + float __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; float __invokeRetVal = default; int __retVal = default; + _ = __invokeRetValUnmanaged__out; try { // Unmarshal - Convert native data to managed data. @@ -60,13 +62,16 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Get(); // Marshal - Convert managed data to native data. - __invokeRetValUnmanaged = __invokeRetVal; + __invokeRetValUnmanaged__out = __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; } @@ -85,6 +90,7 @@ internal static int ABI_Set(System.Runtime.InteropServices.ComWrappers.ComInterf 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.IInt.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInt.cs index 1c1ed57..ca67f27 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInt.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInt.cs @@ -102,9 +102,11 @@ file unsafe partial interface InterfaceImplementation internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int* __invokeRetValUnmanaged__param) { global::SharedTypes.ComInterfaces.IInt @this = default; - ref int __invokeRetValUnmanaged = ref *__invokeRetValUnmanaged__param; + int __invokeRetValUnmanaged__out = default; + int __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int __invokeRetVal = default; int __retVal = default; + _ = __invokeRetValUnmanaged__out; try { // Unmarshal - Convert native data to managed data. @@ -112,13 +114,16 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Get(); // Marshal - Convert managed data to native data. - __invokeRetValUnmanaged = __invokeRetVal; + __invokeRetValUnmanaged__out = __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; } @@ -137,6 +142,7 @@ internal static int ABI_Set(System.Runtime.InteropServices.ComWrappers.ComInterf catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } return __retVal; @@ -146,9 +152,11 @@ internal static int ABI_Set(System.Runtime.InteropServices.ComWrappers.ComInterf internal static int ABI_SwapRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int* __value_native__param) { global::SharedTypes.ComInterfaces.IInt @this = default; - ref int __value_native = ref *__value_native__param; + int __value_native__out = default; + int __value_native = *__value_native__param; int value = default; int __retVal = default; + _ = __value_native__out; try { // Unmarshal - Convert native data to managed data. @@ -157,13 +165,16 @@ internal static int ABI_SwapRef(System.Runtime.InteropServices.ComWrappers.ComIn @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.SwapRef(ref value); // Marshal - Convert managed data to native data. - __value_native = value; + __value_native__out = value; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; return __retVal; } @@ -171,9 +182,11 @@ internal static int ABI_SwapRef(System.Runtime.InteropServices.ComWrappers.ComIn internal static int ABI_GetOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int* __value_native__param) { global::SharedTypes.ComInterfaces.IInt @this = default; - ref int __value_native = ref *__value_native__param; + int __value_native__out = default; + int __value_native = *__value_native__param; int value = default; int __retVal = default; + _ = __value_native__out; try { // Unmarshal - Convert native data to managed data. @@ -181,13 +194,16 @@ internal static int ABI_GetOut(System.Runtime.InteropServices.ComWrappers.ComInt @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.GetOut(out value); // Marshal - Convert managed data to native data. - __value_native = value; + __value_native__out = value; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; return __retVal; } @@ -195,7 +211,7 @@ internal static int ABI_GetOut(System.Runtime.InteropServices.ComWrappers.ComInt internal static int ABI_SetIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int* __value_native__param) { global::SharedTypes.ComInterfaces.IInt @this = default; - ref int __value_native = ref *__value_native__param; + int __value_native = *__value_native__param; int value = default; int __retVal = default; try @@ -209,6 +225,7 @@ internal static int ABI_SetIn(System.Runtime.InteropServices.ComWrappers.ComInte 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.IIntArray.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs index 0aa208e..ce80daa 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs @@ -193,11 +193,15 @@ file unsafe partial interface InterfaceImplementation internal static int ABI_GetReturn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int* __size_native__param, int** __invokeRetValUnmanaged__param) { global::SharedTypes.ComInterfaces.IIntArray @this = default; - ref int __size_native = ref *__size_native__param; + int __size_native__out = default; + int __size_native = *__size_native__param; int size = default; - ref int* __invokeRetValUnmanaged = ref *__invokeRetValUnmanaged__param; + int* __invokeRetValUnmanaged__out = default; + int* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int[] __invokeRetVal = default; int __retVal = default; + _ = __size_native__out; + _ = __invokeRetValUnmanaged__out; // Setup - Perform required setup. int __invokeRetValUnmanaged__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); @@ -208,15 +212,19 @@ internal static int ABI_GetReturn(System.Runtime.InteropServices.ComWrappers.Com @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.GetReturn(out size); // Marshal - Convert managed data to native data. - __size_native = size; - __invokeRetValUnmanaged = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__invokeRetVal).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__invokeRetValUnmanaged, __invokeRetValUnmanaged__numElements)); + __size_native__out = size; + __invokeRetValUnmanaged__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__invokeRetVal).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements)); } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } + // AssignOut - Assign to parameters + *__size_native__param = __size_native__out; + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; return __retVal; } @@ -224,11 +232,15 @@ internal static int ABI_GetReturn(System.Runtime.InteropServices.ComWrappers.Com internal static int ABI_GetOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int** __array_native__param, int* __invokeRetValUnmanaged__param) { global::SharedTypes.ComInterfaces.IIntArray @this = default; - ref int* __array_native = ref *__array_native__param; + int* __array_native__out = default; + int* __array_native = *__array_native__param; int[] array = default; - ref int __invokeRetValUnmanaged = ref *__invokeRetValUnmanaged__param; + int __invokeRetValUnmanaged__out = default; + int __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int __invokeRetVal = default; int __retVal = default; + _ = __array_native__out; + _ = __invokeRetValUnmanaged__out; // Setup - Perform required setup. int __array_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); @@ -239,15 +251,19 @@ internal static int ABI_GetOut(System.Runtime.InteropServices.ComWrappers.ComInt @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.GetOut(out array); // Marshal - Convert managed data to native data. - __invokeRetValUnmanaged = __invokeRetVal; - __array_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(array, out __array_native__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(array).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__array_native, __array_native__numElements)); + __invokeRetValUnmanaged__out = __invokeRetVal; + __array_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(array, out __array_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(array).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__array_native__out, __array_native__numElements)); } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + *__array_native__param = __array_native__out; return __retVal; } @@ -273,6 +289,7 @@ internal static int ABI_SetContents(System.Runtime.InteropServices.ComWrappers.C catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } return __retVal; @@ -287,6 +304,7 @@ internal static int ABI_FillAscending(System.Runtime.InteropServices.ComWrappers // Setup - Perform required setup. int __array_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + System.Span __array_native__out; try { // Unmarshal - Convert native data to managed data. @@ -295,13 +313,24 @@ internal static int ABI_FillAscending(System.Runtime.InteropServices.ComWrappers @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.FillAscending(array, size); // Marshal - Convert managed data to native data. - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array).CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.InteropServices.MemoryMarshal.GetReference(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements)), global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements).Length)); + { + __array_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(array).Length; +#pragma warning disable CS9081 + __array_native__out = stackalloc int[__array_native__numElements]; +#pragma warning restore CS9081 + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array).CopyTo(__array_native__out); + } } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } + // AssignOut - Assign to parameters + __array_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements).GetPinnableReference()), __array_native__numElements)); + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native); return __retVal; } @@ -309,7 +338,7 @@ internal static int ABI_FillAscending(System.Runtime.InteropServices.ComWrappers internal static int ABI_PassIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int** __array_native__param, int size) { global::SharedTypes.ComInterfaces.IIntArray @this = default; - ref int* __array_native = ref *__array_native__param; + int* __array_native = *__array_native__param; int[] array = default; int __retVal = default; // Setup - Perform required setup. @@ -328,6 +357,7 @@ internal static int ABI_PassIn(System.Runtime.InteropServices.ComWrappers.ComInt catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } return __retVal; @@ -337,14 +367,14 @@ internal static int ABI_PassIn(System.Runtime.InteropServices.ComWrappers.ComInt internal static int ABI_SwapArray(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int** __array_native__param, int size) { global::SharedTypes.ComInterfaces.IIntArray @this = default; - ref int* __array_native = ref *__array_native__param; + int* __array_native__out = default; + int* __array_native = *__array_native__param; int[] array = default; int __retVal = default; + _ = __array_native__out; // Setup - Perform required setup. int __array_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); - bool __array_native__ownOriginal = false; - int* __array_native__original = __array_native; try { // Unmarshal - Convert native data to managed data. @@ -355,24 +385,23 @@ internal static int ABI_SwapArray(System.Runtime.InteropServices.ComWrappers.Com @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.SwapArray(ref array, size); // Marshal - Convert managed data to native data. - __array_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(array, out __array_native__numElements); - __array_native__ownOriginal = true; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(array).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__array_native, __array_native__numElements)); + __array_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(array, out __array_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(array).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__array_native__out, __array_native__numElements)); } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); - } - finally - { // Cleanup - Perform required cleanup. - if (__array_native__ownOriginal) - { - __array_native__numElements = size; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native__original); - } + __array_native__numElements = size; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native__out); + return __retVal; } + // AssignOut - Assign to parameters + *__array_native__param = __array_native__out; + // Cleanup - Perform required cleanup. + __array_native__numElements = size; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native); return __retVal; } } diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs index ff6245f..eaeeea4 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs @@ -151,9 +151,11 @@ file unsafe partial interface InterfaceImplementation internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, void** __invokeRetValUnmanaged__param) { global::SharedTypes.ComInterfaces.IInterface @this = default; - ref void* __invokeRetValUnmanaged = ref *__invokeRetValUnmanaged__param; + void* __invokeRetValUnmanaged__out = default; + void* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; global::SharedTypes.ComInterfaces.IInt __invokeRetVal = default; int __retVal = default; + _ = __invokeRetValUnmanaged__out; try { // Unmarshal - Convert native data to managed data. @@ -161,13 +163,16 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Get(); // Marshal - Convert managed data to native data. - __invokeRetValUnmanaged = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(__invokeRetVal); + __invokeRetValUnmanaged__out = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.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; } @@ -188,6 +193,7 @@ internal static int ABI_SetInt(System.Runtime.InteropServices.ComWrappers.ComInt catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } return __retVal; @@ -197,12 +203,11 @@ internal static int ABI_SetInt(System.Runtime.InteropServices.ComWrappers.ComInt internal static int ABI_SwapRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, void** __value_native__param) { global::SharedTypes.ComInterfaces.IInterface @this = default; - ref void* __value_native = ref *__value_native__param; + void* __value_native__out = default; + void* __value_native = *__value_native__param; global::SharedTypes.ComInterfaces.IInt value = default; int __retVal = default; - // Setup - Perform required setup. - bool __value_native__ownOriginal = false; - void* __value_native__original = __value_native; + _ = __value_native__out; try { // Unmarshal - Convert native data to managed data. @@ -211,22 +216,20 @@ internal static int ABI_SwapRef(System.Runtime.InteropServices.ComWrappers.ComIn @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.SwapRef(ref value); // Marshal - Convert managed data to native data. - __value_native = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(value); - __value_native__ownOriginal = true; + __value_native__out = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(value); } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); - } - finally - { // Cleanup - Perform required cleanup. - if (__value_native__ownOriginal) - { - global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__value_native__original); - } + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__value_native__out); + return __retVal; } + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__value_native); return __retVal; } @@ -234,9 +237,11 @@ internal static int ABI_SwapRef(System.Runtime.InteropServices.ComWrappers.ComIn internal static int ABI_GetOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, void** __value_native__param) { global::SharedTypes.ComInterfaces.IInterface @this = default; - ref void* __value_native = ref *__value_native__param; + void* __value_native__out = default; + void* __value_native = *__value_native__param; global::SharedTypes.ComInterfaces.IInt value = default; int __retVal = default; + _ = __value_native__out; try { // Unmarshal - Convert native data to managed data. @@ -244,13 +249,16 @@ internal static int ABI_GetOut(System.Runtime.InteropServices.ComWrappers.ComInt @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.GetOut(out value); // Marshal - Convert managed data to native data. - __value_native = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(value); + __value_native__out = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(value); } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; return __retVal; } @@ -258,7 +266,7 @@ internal static int ABI_GetOut(System.Runtime.InteropServices.ComWrappers.ComInt internal static int ABI_InInt(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, void** __value_native__param) { global::SharedTypes.ComInterfaces.IInterface @this = default; - ref void* __value_native = ref *__value_native__param; + void* __value_native = *__value_native__param; global::SharedTypes.ComInterfaces.IInt value = default; int __retVal = default; try @@ -272,6 +280,7 @@ internal static int ABI_InInt(System.Runtime.InteropServices.ComWrappers.ComInte 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.IJaggedIntArray.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IJaggedIntArray.cs index f7d3efb..54d662e 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IJaggedIntArray.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IJaggedIntArray.cs @@ -211,13 +211,19 @@ file unsafe partial interface InterfaceImplementation internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int** __widths_native__param, int* __length_native__param, System.IntPtr** __invokeRetValUnmanaged__param) { global::SharedTypes.ComInterfaces.IJaggedIntArray @this = default; - ref int* __widths_native = ref *__widths_native__param; + int* __widths_native__out = default; + int* __widths_native = *__widths_native__param; int[] widths = default; - ref int __length_native = ref *__length_native__param; + int __length_native__out = default; + int __length_native = *__length_native__param; int length = default; - ref System.IntPtr* __invokeRetValUnmanaged = ref *__invokeRetValUnmanaged__param; + System.IntPtr* __invokeRetValUnmanaged__out = default; + System.IntPtr* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int[][] __invokeRetVal = default; int __retVal = default; + _ = __widths_native__out; + _ = __length_native__out; + _ = __invokeRetValUnmanaged__out; // Setup - Perform required setup. int __widths_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); @@ -230,13 +236,13 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Get(out widths, out length); // Marshal - Convert managed data to native data. - __length_native = length; - __widths_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(widths, out __widths_native__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(widths).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__widths_native, __widths_native__numElements)); - __invokeRetValUnmanaged = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); + __length_native__out = length; + __widths_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(widths, out __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(widths).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__widths_native__out, __widths_native__numElements)); + __invokeRetValUnmanaged__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); { System.ReadOnlySpan __invokeRetValUnmanaged__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__invokeRetVal); - System.Span __invokeRetValUnmanaged__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__invokeRetValUnmanaged, __invokeRetValUnmanaged__numElements); + System.Span __invokeRetValUnmanaged__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements); __invokeRetValUnmanaged__nativeSpan.Clear(); for (int __i0 = 0; __i0 < __invokeRetValUnmanaged__managedSpan.Length; ++__i0) { @@ -250,8 +256,13 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } + // AssignOut - Assign to parameters + *__length_native__param = __length_native__out; + *__widths_native__param = __widths_native__out; + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; return __retVal; } @@ -259,13 +270,19 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf internal static int ABI_Get2(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, System.IntPtr** __array_native__param, int** __widths_native__param, int* __invokeRetValUnmanaged__param) { global::SharedTypes.ComInterfaces.IJaggedIntArray @this = default; - ref System.IntPtr* __array_native = ref *__array_native__param; + System.IntPtr* __array_native__out = default; + System.IntPtr* __array_native = *__array_native__param; int[][] array = default; - ref int* __widths_native = ref *__widths_native__param; + int* __widths_native__out = default; + int* __widths_native = *__widths_native__param; int[] widths = default; - ref int __invokeRetValUnmanaged = ref *__invokeRetValUnmanaged__param; + int __invokeRetValUnmanaged__out = default; + int __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int __invokeRetVal = default; int __retVal = default; + _ = __array_native__out; + _ = __widths_native__out; + _ = __invokeRetValUnmanaged__out; // Setup - Perform required setup. int __widths_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); @@ -278,13 +295,13 @@ internal static int ABI_Get2(System.Runtime.InteropServices.ComWrappers.ComInter @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Get2(out array, out widths); // Marshal - Convert managed data to native data. - __invokeRetValUnmanaged = __invokeRetVal; - __widths_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(widths, out __widths_native__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(widths).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__widths_native, __widths_native__numElements)); - __array_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(array, out __array_native__numElements); + __invokeRetValUnmanaged__out = __invokeRetVal; + __widths_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(widths, out __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(widths).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__widths_native__out, __widths_native__numElements)); + __array_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(array, out __array_native__numElements); { System.ReadOnlySpan __array_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(array); - System.Span __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__array_native, __array_native__numElements); + System.Span __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__array_native__out, __array_native__numElements); __array_native__nativeSpan.Clear(); for (int __i0 = 0; __i0 < __array_native__managedSpan.Length; ++__i0) { @@ -298,8 +315,13 @@ internal static int ABI_Get2(System.Runtime.InteropServices.ComWrappers.ComInter catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + *__widths_native__param = __widths_native__out; + *__array_native__param = __array_native__out; return __retVal; } @@ -343,6 +365,7 @@ internal static int ABI_Set(System.Runtime.InteropServices.ComWrappers.ComInterf 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.IRefStrings.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs index a80f5a5..e85a49a 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs @@ -101,12 +101,11 @@ file unsafe partial interface InterfaceImplementation internal static int ABI_RefString(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, byte** __value_native__param) { global::SharedTypes.ComInterfaces.IRefStrings @this = default; - ref byte* __value_native = ref *__value_native__param; + byte* __value_native__out = default; + byte* __value_native = *__value_native__param; string value = default; int __retVal = default; - // Setup - Perform required setup. - bool __value_native__ownOriginal = false; - byte* __value_native__original = __value_native; + _ = __value_native__out; try { // Unmarshal - Convert native data to managed data. @@ -115,22 +114,20 @@ internal static int ABI_RefString(System.Runtime.InteropServices.ComWrappers.Com @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.RefString(ref value); // Marshal - Convert managed data to native data. - __value_native = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(value); - __value_native__ownOriginal = true; + __value_native__out = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(value); } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); - } - finally - { // Cleanup - Perform required cleanup. - if (__value_native__ownOriginal) - { - global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__value_native__original); - } + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__value_native__out); + return __retVal; } + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__value_native); return __retVal; } @@ -138,7 +135,7 @@ internal static int ABI_RefString(System.Runtime.InteropServices.ComWrappers.Com internal static int ABI_InString(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, byte** __value_native__param) { global::SharedTypes.ComInterfaces.IRefStrings @this = default; - ref byte* __value_native = ref *__value_native__param; + byte* __value_native = *__value_native__param; string value = default; int __retVal = default; try @@ -152,6 +149,7 @@ internal static int ABI_InString(System.Runtime.InteropServices.ComWrappers.ComI catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } return __retVal; @@ -161,9 +159,11 @@ internal static int ABI_InString(System.Runtime.InteropServices.ComWrappers.ComI internal static int ABI_OutString(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, byte** __value_native__param) { global::SharedTypes.ComInterfaces.IRefStrings @this = default; - ref byte* __value_native = ref *__value_native__param; + byte* __value_native__out = default; + byte* __value_native = *__value_native__param; string value = default; int __retVal = default; + _ = __value_native__out; try { // Unmarshal - Convert native data to managed data. @@ -171,13 +171,16 @@ internal static int ABI_OutString(System.Runtime.InteropServices.ComWrappers.Com @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.OutString(out value); // Marshal - Convert managed data to native data. - __value_native = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(value); + __value_native__out = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(value); } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; return __retVal; } } diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.cs index 7712c35..93ff174 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.cs @@ -122,11 +122,15 @@ file unsafe partial interface InterfaceImplementation internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int* __size_native__param, nint** __invokeRetValUnmanaged__param) { global::SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails @this = default; - ref int __size_native = ref *__size_native__param; + int __size_native__out = default; + int __size_native = *__size_native__param; int size = default; - ref nint* __invokeRetValUnmanaged = ref *__invokeRetValUnmanaged__param; + nint* __invokeRetValUnmanaged__out = default; + nint* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int[] __invokeRetVal = default; int __retVal = default; + _ = __size_native__out; + _ = __invokeRetValUnmanaged__out; // Setup - Perform required setup. int __invokeRetValUnmanaged__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); @@ -137,11 +141,11 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Get(out size); // Marshal - Convert managed data to native data. - __size_native = size; - __invokeRetValUnmanaged = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); + __size_native__out = size; + __invokeRetValUnmanaged__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); { System.ReadOnlySpan __invokeRetValUnmanaged__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__invokeRetVal); - System.Span __invokeRetValUnmanaged__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__invokeRetValUnmanaged, __invokeRetValUnmanaged__numElements); + System.Span __invokeRetValUnmanaged__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements); __invokeRetValUnmanaged__nativeSpan.Clear(); for (int __i0 = 0; __i0 < __invokeRetValUnmanaged__managedSpan.Length; ++__i0) { @@ -152,8 +156,12 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } + // AssignOut - Assign to parameters + *__size_native__param = __size_native__out; + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; return __retVal; } @@ -187,6 +195,7 @@ internal static int ABI_Set(System.Runtime.InteropServices.ComWrappers.ComInterf 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.MarshallingFails.IJaggedIntArrayMarshallingFails.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.cs index dad9839..287f6e2 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.cs @@ -258,13 +258,19 @@ file unsafe partial interface InterfaceImplementation internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int** __widths_native__param, int* __length_native__param, System.IntPtr** __invokeRetValUnmanaged__param) { global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails @this = default; - ref int* __widths_native = ref *__widths_native__param; + int* __widths_native__out = default; + int* __widths_native = *__widths_native__param; int[] widths = default; - ref int __length_native = ref *__length_native__param; + int __length_native__out = default; + int __length_native = *__length_native__param; int length = default; - ref System.IntPtr* __invokeRetValUnmanaged = ref *__invokeRetValUnmanaged__param; + System.IntPtr* __invokeRetValUnmanaged__out = default; + System.IntPtr* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int[][] __invokeRetVal = default; int __retVal = default; + _ = __widths_native__out; + _ = __length_native__out; + _ = __invokeRetValUnmanaged__out; // Setup - Perform required setup. int __widths_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); @@ -277,13 +283,13 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Get(out widths, out length); // Marshal - Convert managed data to native data. - __length_native = length; - __widths_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(widths, out __widths_native__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(widths).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__widths_native, __widths_native__numElements)); - __invokeRetValUnmanaged = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); + __length_native__out = length; + __widths_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(widths, out __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(widths).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__widths_native__out, __widths_native__numElements)); + __invokeRetValUnmanaged__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); { System.ReadOnlySpan __invokeRetValUnmanaged__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__invokeRetVal); - System.Span __invokeRetValUnmanaged__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__invokeRetValUnmanaged, __invokeRetValUnmanaged__numElements); + System.Span __invokeRetValUnmanaged__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements); __invokeRetValUnmanaged__nativeSpan.Clear(); for (int __i0 = 0; __i0 < __invokeRetValUnmanaged__managedSpan.Length; ++__i0) { @@ -305,8 +311,13 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } + // AssignOut - Assign to parameters + *__length_native__param = __length_native__out; + *__widths_native__param = __widths_native__out; + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; return __retVal; } @@ -314,13 +325,19 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf internal static int ABI_Get2(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, System.IntPtr** __array_native__param, int** __widths_native__param, int* __invokeRetValUnmanaged__param) { global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails @this = default; - ref System.IntPtr* __array_native = ref *__array_native__param; + System.IntPtr* __array_native__out = default; + System.IntPtr* __array_native = *__array_native__param; int[][] array = default; - ref int* __widths_native = ref *__widths_native__param; + int* __widths_native__out = default; + int* __widths_native = *__widths_native__param; int[] widths = default; - ref int __invokeRetValUnmanaged = ref *__invokeRetValUnmanaged__param; + int __invokeRetValUnmanaged__out = default; + int __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int __invokeRetVal = default; int __retVal = default; + _ = __array_native__out; + _ = __widths_native__out; + _ = __invokeRetValUnmanaged__out; // Setup - Perform required setup. int __widths_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); @@ -333,13 +350,13 @@ internal static int ABI_Get2(System.Runtime.InteropServices.ComWrappers.ComInter @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Get2(out array, out widths); // Marshal - Convert managed data to native data. - __invokeRetValUnmanaged = __invokeRetVal; - __widths_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(widths, out __widths_native__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(widths).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__widths_native, __widths_native__numElements)); - __array_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(array, out __array_native__numElements); + __invokeRetValUnmanaged__out = __invokeRetVal; + __widths_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(widths, out __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(widths).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__widths_native__out, __widths_native__numElements)); + __array_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(array, out __array_native__numElements); { System.ReadOnlySpan __array_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(array); - System.Span __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__array_native, __array_native__numElements); + System.Span __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__array_native__out, __array_native__numElements); __array_native__nativeSpan.Clear(); for (int __i0 = 0; __i0 < __array_native__managedSpan.Length; ++__i0) { @@ -361,8 +378,13 @@ internal static int ABI_Get2(System.Runtime.InteropServices.ComWrappers.ComInter catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + *__widths_native__param = __widths_native__out; + *__array_native__param = __array_native__out; return __retVal; } @@ -413,6 +435,7 @@ internal static int ABI_Set(System.Runtime.InteropServices.ComWrappers.ComInterf catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; } return __retVal; From 6c114d8b280bcec03e30c1dd6d2e44011e818259 Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Fri, 21 Jul 2023 13:45:35 -0700 Subject: [PATCH 3/8] don't discard value --- .../SharedTypes.ComInterfaces.IBool.cs | 1 - ...edTypes.ComInterfaces.ICustomCollectionStateful.cs | 4 ---- ...pes.ComInterfaces.ICustomStringMarshallingUtf16.cs | 1 - .../SharedTypes.ComInterfaces.IDerived.cs | 1 - .../SharedTypes.ComInterfaces.IEnumUnknown.cs | 2 -- .../SharedTypes.ComInterfaces.IFloat.cs | 1 - .../SharedTypes.ComInterfaces.IGetAndSetInt.cs | 1 - .../SharedTypes.ComInterfaces.IGetIntArray.cs | 1 - .../SharedTypes.ComInterfaces.IInt.cs | 3 --- .../SharedTypes.ComInterfaces.IIntArray.cs | 5 ----- .../SharedTypes.ComInterfaces.IInterface.cs | 3 --- .../SharedTypes.ComInterfaces.IJaggedIntArray.cs | 6 ------ .../SharedTypes.ComInterfaces.IRefStrings.cs | 2 -- ...dTypes.ComInterfaces.IStringMarshallingOverride.cs | 3 --- ...ComInterfaces.IStringMarshallingOverrideDerived.cs | 3 --- .../SharedTypes.ComInterfaces.IUTF16Marshalling.cs | 1 - .../SharedTypes.ComInterfaces.IUTF8Marshalling.cs | 1 - ...es.MarshallingFails.ICollectionMarshallingFails.cs | 2 -- ...arshallingFails.IJaggedIntArrayMarshallingFails.cs | 6 ------ ...s.MarshallingFails.IStringArrayMarshallingFails.cs | 3 --- .../NativeToManagedStubs.g.cs | 11 ----------- 21 files changed, 61 deletions(-) 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 index f7d3ac7..2f11089 100644 --- 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 @@ -59,7 +59,6 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf sbyte __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; bool __invokeRetVal = default; int __retVal = default; - _ = __invokeRetValUnmanaged__out; try { // Unmarshal - Convert native data to managed data. 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 index 01dc341..75a7221 100644 --- 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 @@ -170,10 +170,6 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt 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; 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 c73d2be..fcab101 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 @@ -67,7 +67,6 @@ internal static int ABI_GetString(System.Runtime.InteropServices.ComWrappers.Com ushort* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; string __invokeRetVal = default; int __retVal = default; - _ = __invokeRetValUnmanaged__out; try { // Unmarshal - Convert native data to managed data. 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 8fd929d..744bb04 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 @@ -125,7 +125,6 @@ internal static int ABI_GetName(System.Runtime.InteropServices.ComWrappers.ComIn ushort* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; string __invokeRetVal = default; int __retVal = default; - _ = __invokeRetValUnmanaged__out; try { // Unmarshal - Convert native data to managed data. 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 329e916..5e9ff42 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 @@ -133,7 +133,6 @@ internal static int ABI_Next(System.Runtime.InteropServices.ComWrappers.ComInter 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); @@ -225,7 +224,6 @@ internal static int ABI_Clone(System.Runtime.InteropServices.ComWrappers.ComInte void* __ppenum_native = *__ppenum_native__param; global::SharedTypes.ComInterfaces.IEnumUnknown ppenum = default; int __retVal = default; - _ = __ppenum_native__out; try { // Unmarshal - Convert native data to managed data. diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IFloat.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IFloat.cs index c703f8b..8b51500 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IFloat.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IFloat.cs @@ -54,7 +54,6 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf float __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; float __invokeRetVal = default; int __retVal = default; - _ = __invokeRetValUnmanaged__out; try { // Unmarshal - Convert native data to managed data. diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetAndSetInt.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetAndSetInt.cs index a9ebcb9..680e0b7 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetAndSetInt.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetAndSetInt.cs @@ -54,7 +54,6 @@ internal static int ABI_GetInt(System.Runtime.InteropServices.ComWrappers.ComInt int __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int __invokeRetVal = default; int __retVal = default; - _ = __invokeRetValUnmanaged__out; try { // Unmarshal - Convert native data to managed data. diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetIntArray.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetIntArray.cs index 288d4c9..80f9d14 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetIntArray.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetIntArray.cs @@ -56,7 +56,6 @@ internal static int ABI_GetInts(System.Runtime.InteropServices.ComWrappers.ComIn int* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int[] __invokeRetVal = default; int __retVal = default; - _ = __invokeRetValUnmanaged__out; // Setup - Perform required setup. int __invokeRetValUnmanaged__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInt.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInt.cs index ca67f27..d1aabb3 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInt.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInt.cs @@ -106,7 +106,6 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf int __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int __invokeRetVal = default; int __retVal = default; - _ = __invokeRetValUnmanaged__out; try { // Unmarshal - Convert native data to managed data. @@ -156,7 +155,6 @@ internal static int ABI_SwapRef(System.Runtime.InteropServices.ComWrappers.ComIn int __value_native = *__value_native__param; int value = default; int __retVal = default; - _ = __value_native__out; try { // Unmarshal - Convert native data to managed data. @@ -186,7 +184,6 @@ internal static int ABI_GetOut(System.Runtime.InteropServices.ComWrappers.ComInt int __value_native = *__value_native__param; int value = default; int __retVal = default; - _ = __value_native__out; try { // Unmarshal - Convert native data to managed data. diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs index ce80daa..a182bd7 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs @@ -200,8 +200,6 @@ internal static int ABI_GetReturn(System.Runtime.InteropServices.ComWrappers.Com int* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int[] __invokeRetVal = default; int __retVal = default; - _ = __size_native__out; - _ = __invokeRetValUnmanaged__out; // Setup - Perform required setup. int __invokeRetValUnmanaged__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); @@ -239,8 +237,6 @@ internal static int ABI_GetOut(System.Runtime.InteropServices.ComWrappers.ComInt int __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int __invokeRetVal = default; int __retVal = default; - _ = __array_native__out; - _ = __invokeRetValUnmanaged__out; // Setup - Perform required setup. int __array_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); @@ -371,7 +367,6 @@ internal static int ABI_SwapArray(System.Runtime.InteropServices.ComWrappers.Com int* __array_native = *__array_native__param; int[] array = default; int __retVal = default; - _ = __array_native__out; // Setup - Perform required setup. int __array_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs index eaeeea4..4739393 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs @@ -155,7 +155,6 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf void* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; global::SharedTypes.ComInterfaces.IInt __invokeRetVal = default; int __retVal = default; - _ = __invokeRetValUnmanaged__out; try { // Unmarshal - Convert native data to managed data. @@ -207,7 +206,6 @@ internal static int ABI_SwapRef(System.Runtime.InteropServices.ComWrappers.ComIn void* __value_native = *__value_native__param; global::SharedTypes.ComInterfaces.IInt value = default; int __retVal = default; - _ = __value_native__out; try { // Unmarshal - Convert native data to managed data. @@ -241,7 +239,6 @@ internal static int ABI_GetOut(System.Runtime.InteropServices.ComWrappers.ComInt void* __value_native = *__value_native__param; global::SharedTypes.ComInterfaces.IInt value = default; int __retVal = default; - _ = __value_native__out; try { // Unmarshal - Convert native data to managed data. diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IJaggedIntArray.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IJaggedIntArray.cs index 54d662e..ca41ba3 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IJaggedIntArray.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IJaggedIntArray.cs @@ -221,9 +221,6 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf System.IntPtr* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int[][] __invokeRetVal = default; int __retVal = default; - _ = __widths_native__out; - _ = __length_native__out; - _ = __invokeRetValUnmanaged__out; // Setup - Perform required setup. int __widths_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); @@ -280,9 +277,6 @@ internal static int ABI_Get2(System.Runtime.InteropServices.ComWrappers.ComInter int __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int __invokeRetVal = default; int __retVal = default; - _ = __array_native__out; - _ = __widths_native__out; - _ = __invokeRetValUnmanaged__out; // Setup - Perform required setup. int __widths_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs index e85a49a..4a2fbfd 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs @@ -105,7 +105,6 @@ internal static int ABI_RefString(System.Runtime.InteropServices.ComWrappers.Com byte* __value_native = *__value_native__param; string value = default; int __retVal = default; - _ = __value_native__out; try { // Unmarshal - Convert native data to managed data. @@ -163,7 +162,6 @@ internal static int ABI_OutString(System.Runtime.InteropServices.ComWrappers.Com byte* __value_native = *__value_native__param; string value = default; int __retVal = default; - _ = __value_native__out; try { // Unmarshal - Convert native data to managed data. diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverride.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverride.cs index eacd91a..6e6ba0b 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverride.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverride.cs @@ -119,7 +119,6 @@ internal static int ABI_StringMarshallingUtf8(System.Runtime.InteropServices.Com byte* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; string __invokeRetVal = default; int __retVal = default; - _ = __invokeRetValUnmanaged__out; try { // Unmarshal - Convert native data to managed data. @@ -150,7 +149,6 @@ internal static int ABI_MarshalAsLPWString(System.Runtime.InteropServices.ComWra ushort* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; string __invokeRetVal = default; int __retVal = default; - _ = __invokeRetValUnmanaged__out; try { // Unmarshal - Convert native data to managed data. @@ -181,7 +179,6 @@ internal static int ABI_MarshalUsingUtf16(System.Runtime.InteropServices.ComWrap ushort* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; string __invokeRetVal = default; int __retVal = default; - _ = __invokeRetValUnmanaged__out; try { // Unmarshal - Convert native data to managed data. diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.cs index 94c7090..991bba6 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.cs @@ -219,7 +219,6 @@ internal static int ABI_StringMarshallingUtf8_2(System.Runtime.InteropServices.C byte* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; string __invokeRetVal = default; int __retVal = default; - _ = __invokeRetValUnmanaged__out; try { // Unmarshal - Convert native data to managed data. @@ -250,7 +249,6 @@ internal static int ABI_MarshalAsLPWString_2(System.Runtime.InteropServices.ComW ushort* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; string __invokeRetVal = default; int __retVal = default; - _ = __invokeRetValUnmanaged__out; try { // Unmarshal - Convert native data to managed data. @@ -281,7 +279,6 @@ internal static int ABI_MarshalUsingUtf16_2(System.Runtime.InteropServices.ComWr ushort* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; string __invokeRetVal = default; int __retVal = default; - _ = __invokeRetValUnmanaged__out; try { // Unmarshal - Convert native data to managed data. diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF16Marshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF16Marshalling.cs index 9908149..00bb0d9 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF16Marshalling.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF16Marshalling.cs @@ -67,7 +67,6 @@ internal static int ABI_GetString(System.Runtime.InteropServices.ComWrappers.Com ushort* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; string __invokeRetVal = default; int __retVal = default; - _ = __invokeRetValUnmanaged__out; try { // Unmarshal - Convert native data to managed data. diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF8Marshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF8Marshalling.cs index eabdbc3..db5927f 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF8Marshalling.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF8Marshalling.cs @@ -80,7 +80,6 @@ internal static int ABI_GetString(System.Runtime.InteropServices.ComWrappers.Com byte* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; string __invokeRetVal = default; int __retVal = default; - _ = __invokeRetValUnmanaged__out; try { // Unmarshal - Convert native data to managed data. diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.cs index 93ff174..ad2fb93 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.cs @@ -129,8 +129,6 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf nint* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int[] __invokeRetVal = default; int __retVal = default; - _ = __size_native__out; - _ = __invokeRetValUnmanaged__out; // Setup - Perform required setup. int __invokeRetValUnmanaged__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.cs index 287f6e2..f12c30f 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.cs @@ -268,9 +268,6 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf System.IntPtr* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int[][] __invokeRetVal = default; int __retVal = default; - _ = __widths_native__out; - _ = __length_native__out; - _ = __invokeRetValUnmanaged__out; // Setup - Perform required setup. int __widths_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); @@ -335,9 +332,6 @@ internal static int ABI_Get2(System.Runtime.InteropServices.ComWrappers.ComInter int __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int __invokeRetVal = default; int __retVal = default; - _ = __array_native__out; - _ = __widths_native__out; - _ = __invokeRetValUnmanaged__out; // Setup - Perform required setup. int __widths_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs index 9acf26b..e56fc8e 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs @@ -414,7 +414,6 @@ internal static int ABI_RefParam(System.Runtime.InteropServices.ComWrappers.ComI nint* __value_native = *__value_native__param; string[] value = default; int __retVal = default; - _ = __value_native__out; // Setup - Perform required setup. int __value_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __value_native__numElements); @@ -474,7 +473,6 @@ internal static int ABI_OutParam(System.Runtime.InteropServices.ComWrappers.ComI nint* __value_native = *__value_native__param; string[] value = default; int __retVal = default; - _ = __value_native__out; // Setup - Perform required setup. int __value_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __value_native__numElements); @@ -615,7 +613,6 @@ internal static int ABI_ReturnValue(System.Runtime.InteropServices.ComWrappers.C nint* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; string[] __invokeRetVal = default; int __retVal = default; - _ = __invokeRetValUnmanaged__out; // Setup - Perform required setup. int __invokeRetValUnmanaged__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeToManagedStubs.g.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeToManagedStubs.g.cs index d4dda1b..5cebb50 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeToManagedStubs.g.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeToManagedStubs.g.cs @@ -64,7 +64,6 @@ internal static void ABI_ExchangeData(void* __this_native, int* __x_native__para int __x_native__out = default; int __x_native = *__x_native__param; int x; - _ = __x_native__out; // Unmarshal - Convert native data to managed data. x = __x_native; @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); @@ -97,7 +96,6 @@ internal static void ABI_SumAndSetData(void* __this_native, int* __values_native int __oldValue_native__out = default; int __oldValue_native = *__oldValue_native__param; int oldValue; - _ = __oldValue_native__out; // Setup - Perform required setup. int __values_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); @@ -137,8 +135,6 @@ internal static void ABI_SumAndSetData(void* __this_native, int** __values_nativ int __oldValue_native__out = default; int __oldValue_native = *__oldValue_native__param; int oldValue = default; - _ = __values_native__out; - _ = __oldValue_native__out; // Setup - Perform required setup. int __values_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); @@ -264,7 +260,6 @@ internal static void ABI_ExchangeData(void* __this_native, int* __data_native__p int __data_native__out = default; int __data_native = *__data_native__param; global::SharedTypes.IntWrapper data = default; - _ = __data_native__out; // Unmarshal - Convert native data to managed data. data = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__data_native); @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); @@ -299,7 +294,6 @@ internal static void ABI_SumAndSetData(void* __this_native, int* __values_native int __oldValue_native__out = default; int __oldValue_native = *__oldValue_native__param; global::SharedTypes.IntWrapper oldValue; - _ = __oldValue_native__out; // Setup - Perform required setup. int __values_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); @@ -347,8 +341,6 @@ internal static void ABI_SumAndSetData(void* __this_native, int** __values_nativ int __oldValue_native__out = default; int __oldValue_native = *__oldValue_native__param; global::SharedTypes.IntWrapper oldValue = default; - _ = __values_native__out; - _ = __oldValue_native__out; // Setup - Perform required setup. int __values_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); @@ -476,7 +468,6 @@ internal static void ABI_SumAndSetData(void* __this_native, int* __values_native int __oldValue_native__out = default; int __oldValue_native = *__oldValue_native__param; global::SharedTypes.IntWrapper oldValue = default; - _ = __oldValue_native__out; // Setup - Perform required setup. global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.StatefulUnmanagedToManagedCollectionMarshaller.In __values_native__marshaller = new(); int __values_native__numElements; @@ -529,8 +520,6 @@ internal static void ABI_SumAndSetData(void* __this_native, int** __values_nativ int __oldValue_native__out = default; int __oldValue_native = *__oldValue_native__param; global::SharedTypes.IntWrapper oldValue = default; - _ = __values_native__out; - _ = __oldValue_native__out; // Setup - Perform required setup. global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.StatefulUnmanagedToManagedCollectionMarshaller.Ref __values_native__marshaller = new(); int __values_native__numElements; From bdfe090f008dce3e25a6cc6763c553bce701149b Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Fri, 21 Jul 2023 14:15:29 -0700 Subject: [PATCH 4/8] Don't create _native when we don't unmarshal to managed callee --- .../SharedTypes.ComInterfaces.IBool.cs | 1 - ...haredTypes.ComInterfaces.ICustomCollectionStateful.cs | 9 +++------ ...dTypes.ComInterfaces.ICustomStringMarshallingUtf16.cs | 1 - .../SharedTypes.ComInterfaces.IDerived.cs | 1 - .../SharedTypes.ComInterfaces.IEnumUnknown.cs | 2 -- .../SharedTypes.ComInterfaces.IFloat.cs | 1 - .../SharedTypes.ComInterfaces.IGetAndSetInt.cs | 1 - .../SharedTypes.ComInterfaces.IGetIntArray.cs | 1 - .../SharedTypes.ComInterfaces.IInt.cs | 2 -- .../SharedTypes.ComInterfaces.IIntArray.cs | 4 ---- .../SharedTypes.ComInterfaces.IInterface.cs | 2 -- .../SharedTypes.ComInterfaces.IJaggedIntArray.cs | 6 ------ .../SharedTypes.ComInterfaces.IRefStrings.cs | 1 - ...aredTypes.ComInterfaces.IStringMarshallingOverride.cs | 3 --- ...es.ComInterfaces.IStringMarshallingOverrideDerived.cs | 3 --- .../SharedTypes.ComInterfaces.IUTF16Marshalling.cs | 1 - .../SharedTypes.ComInterfaces.IUTF8Marshalling.cs | 1 - ...faces.MarshallingFails.ICollectionMarshallingFails.cs | 2 -- ...s.MarshallingFails.IJaggedIntArrayMarshallingFails.cs | 6 ------ ...aces.MarshallingFails.IStringArrayMarshallingFails.cs | 2 -- .../NativeToManagedStubs.g.cs | 8 +------- 21 files changed, 4 insertions(+), 54 deletions(-) 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 index 2f11089..9cdd50d 100644 --- 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 @@ -56,7 +56,6 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf { global::SharedTypes.ComInterfaces.IBool @this = default; sbyte __invokeRetValUnmanaged__out = default; - sbyte __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; bool __invokeRetVal = default; int __retVal = default; try 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 index 75a7221..b581c2f 100644 --- 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 @@ -161,13 +161,10 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt 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; // Setup - Perform required setup. @@ -232,9 +229,9 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt @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(); + __invokeRetValUnmanaged__out = __invokeRetValUnmanaged__marshaller.ToUnmanaged(); + __pOut_native__out = __pOut_native__marshaller.ToUnmanaged(); + __pRef_native__out = __pRef_native__marshaller.ToUnmanaged(); // Marshal - Convert managed data to native data. __invokeRetValUnmanaged__marshaller.FromManaged(__invokeRetVal); { 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 fcab101..7115a78 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 @@ -64,7 +64,6 @@ internal static int ABI_GetString(System.Runtime.InteropServices.ComWrappers.Com { global::SharedTypes.ComInterfaces.ICustomStringMarshallingUtf16 @this = default; ushort* __invokeRetValUnmanaged__out = default; - ushort* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; string __invokeRetVal = default; int __retVal = default; try 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 744bb04..d21502b 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 @@ -122,7 +122,6 @@ internal static int ABI_GetName(System.Runtime.InteropServices.ComWrappers.ComIn { global::SharedTypes.ComInterfaces.IDerived @this = default; ushort* __invokeRetValUnmanaged__out = default; - ushort* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; string __invokeRetVal = default; int __retVal = default; try 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 5e9ff42..3a2a824 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 @@ -130,7 +130,6 @@ internal static int ABI_Next(System.Runtime.InteropServices.ComWrappers.ComInter global::SharedTypes.ComInterfaces.IEnumUnknown @this = default; object[] rgelt = default; uint __pceltFetched_native__out = default; - uint __pceltFetched_native = *__pceltFetched_native__param; uint pceltFetched = default; int __retVal = default; // Setup - Perform required setup. @@ -221,7 +220,6 @@ internal static int ABI_Clone(System.Runtime.InteropServices.ComWrappers.ComInte { global::SharedTypes.ComInterfaces.IEnumUnknown @this = default; void* __ppenum_native__out = default; - void* __ppenum_native = *__ppenum_native__param; global::SharedTypes.ComInterfaces.IEnumUnknown ppenum = default; int __retVal = default; try diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IFloat.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IFloat.cs index 8b51500..12ba740 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IFloat.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IFloat.cs @@ -51,7 +51,6 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf { global::SharedTypes.ComInterfaces.IFloat @this = default; float __invokeRetValUnmanaged__out = default; - float __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; float __invokeRetVal = default; int __retVal = default; try diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetAndSetInt.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetAndSetInt.cs index 680e0b7..2e6729f 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetAndSetInt.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetAndSetInt.cs @@ -51,7 +51,6 @@ internal static int ABI_GetInt(System.Runtime.InteropServices.ComWrappers.ComInt { global::SharedTypes.ComInterfaces.IGetAndSetInt @this = default; int __invokeRetValUnmanaged__out = default; - int __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int __invokeRetVal = default; int __retVal = default; try diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetIntArray.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetIntArray.cs index 80f9d14..aaf8435 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetIntArray.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetIntArray.cs @@ -53,7 +53,6 @@ internal static int ABI_GetInts(System.Runtime.InteropServices.ComWrappers.ComIn { global::SharedTypes.ComInterfaces.IGetIntArray @this = default; int* __invokeRetValUnmanaged__out = default; - int* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int[] __invokeRetVal = default; int __retVal = default; // Setup - Perform required setup. diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInt.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInt.cs index d1aabb3..f723e50 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInt.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInt.cs @@ -103,7 +103,6 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf { global::SharedTypes.ComInterfaces.IInt @this = default; int __invokeRetValUnmanaged__out = default; - int __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int __invokeRetVal = default; int __retVal = default; try @@ -181,7 +180,6 @@ internal static int ABI_GetOut(System.Runtime.InteropServices.ComWrappers.ComInt { global::SharedTypes.ComInterfaces.IInt @this = default; int __value_native__out = default; - int __value_native = *__value_native__param; int value = default; int __retVal = default; try diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs index a182bd7..309b6b3 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs @@ -194,10 +194,8 @@ internal static int ABI_GetReturn(System.Runtime.InteropServices.ComWrappers.Com { global::SharedTypes.ComInterfaces.IIntArray @this = default; int __size_native__out = default; - int __size_native = *__size_native__param; int size = default; int* __invokeRetValUnmanaged__out = default; - int* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int[] __invokeRetVal = default; int __retVal = default; // Setup - Perform required setup. @@ -231,10 +229,8 @@ internal static int ABI_GetOut(System.Runtime.InteropServices.ComWrappers.ComInt { global::SharedTypes.ComInterfaces.IIntArray @this = default; int* __array_native__out = default; - int* __array_native = *__array_native__param; int[] array = default; int __invokeRetValUnmanaged__out = default; - int __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int __invokeRetVal = default; int __retVal = default; // Setup - Perform required setup. diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs index 4739393..87c6e30 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs @@ -152,7 +152,6 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf { global::SharedTypes.ComInterfaces.IInterface @this = default; void* __invokeRetValUnmanaged__out = default; - void* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; global::SharedTypes.ComInterfaces.IInt __invokeRetVal = default; int __retVal = default; try @@ -236,7 +235,6 @@ internal static int ABI_GetOut(System.Runtime.InteropServices.ComWrappers.ComInt { global::SharedTypes.ComInterfaces.IInterface @this = default; void* __value_native__out = default; - void* __value_native = *__value_native__param; global::SharedTypes.ComInterfaces.IInt value = default; int __retVal = default; try diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IJaggedIntArray.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IJaggedIntArray.cs index ca41ba3..4533e6b 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IJaggedIntArray.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IJaggedIntArray.cs @@ -212,13 +212,10 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf { global::SharedTypes.ComInterfaces.IJaggedIntArray @this = default; int* __widths_native__out = default; - int* __widths_native = *__widths_native__param; int[] widths = default; int __length_native__out = default; - int __length_native = *__length_native__param; int length = default; System.IntPtr* __invokeRetValUnmanaged__out = default; - System.IntPtr* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int[][] __invokeRetVal = default; int __retVal = default; // Setup - Perform required setup. @@ -268,13 +265,10 @@ internal static int ABI_Get2(System.Runtime.InteropServices.ComWrappers.ComInter { global::SharedTypes.ComInterfaces.IJaggedIntArray @this = default; System.IntPtr* __array_native__out = default; - System.IntPtr* __array_native = *__array_native__param; int[][] array = default; int* __widths_native__out = default; - int* __widths_native = *__widths_native__param; int[] widths = default; int __invokeRetValUnmanaged__out = default; - int __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int __invokeRetVal = default; int __retVal = default; // Setup - Perform required setup. diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs index 4a2fbfd..b029fba 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs @@ -159,7 +159,6 @@ internal static int ABI_OutString(System.Runtime.InteropServices.ComWrappers.Com { global::SharedTypes.ComInterfaces.IRefStrings @this = default; byte* __value_native__out = default; - byte* __value_native = *__value_native__param; string value = default; int __retVal = default; try diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverride.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverride.cs index 6e6ba0b..b2c7800 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverride.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverride.cs @@ -116,7 +116,6 @@ internal static int ABI_StringMarshallingUtf8(System.Runtime.InteropServices.Com global::SharedTypes.ComInterfaces.IStringMarshallingOverride @this = default; string input = default; byte* __invokeRetValUnmanaged__out = default; - byte* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; string __invokeRetVal = default; int __retVal = default; try @@ -146,7 +145,6 @@ internal static int ABI_MarshalAsLPWString(System.Runtime.InteropServices.ComWra global::SharedTypes.ComInterfaces.IStringMarshallingOverride @this = default; string input = default; ushort* __invokeRetValUnmanaged__out = default; - ushort* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; string __invokeRetVal = default; int __retVal = default; try @@ -176,7 +174,6 @@ internal static int ABI_MarshalUsingUtf16(System.Runtime.InteropServices.ComWrap global::SharedTypes.ComInterfaces.IStringMarshallingOverride @this = default; string input = default; ushort* __invokeRetValUnmanaged__out = default; - ushort* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; string __invokeRetVal = default; int __retVal = default; try diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.cs index 991bba6..4071bfa 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.cs @@ -216,7 +216,6 @@ internal static int ABI_StringMarshallingUtf8_2(System.Runtime.InteropServices.C global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived @this = default; string input = default; byte* __invokeRetValUnmanaged__out = default; - byte* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; string __invokeRetVal = default; int __retVal = default; try @@ -246,7 +245,6 @@ internal static int ABI_MarshalAsLPWString_2(System.Runtime.InteropServices.ComW global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived @this = default; string input = default; ushort* __invokeRetValUnmanaged__out = default; - ushort* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; string __invokeRetVal = default; int __retVal = default; try @@ -276,7 +274,6 @@ internal static int ABI_MarshalUsingUtf16_2(System.Runtime.InteropServices.ComWr global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived @this = default; string input = default; ushort* __invokeRetValUnmanaged__out = default; - ushort* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; string __invokeRetVal = default; int __retVal = default; try diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF16Marshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF16Marshalling.cs index 00bb0d9..b3782e1 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF16Marshalling.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF16Marshalling.cs @@ -64,7 +64,6 @@ internal static int ABI_GetString(System.Runtime.InteropServices.ComWrappers.Com { global::SharedTypes.ComInterfaces.IUTF16Marshalling @this = default; ushort* __invokeRetValUnmanaged__out = default; - ushort* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; string __invokeRetVal = default; int __retVal = default; try diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF8Marshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF8Marshalling.cs index db5927f..3b78083 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF8Marshalling.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF8Marshalling.cs @@ -77,7 +77,6 @@ internal static int ABI_GetString(System.Runtime.InteropServices.ComWrappers.Com { global::SharedTypes.ComInterfaces.IUTF8Marshalling @this = default; byte* __invokeRetValUnmanaged__out = default; - byte* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; string __invokeRetVal = default; int __retVal = default; try diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.cs index ad2fb93..ae156d6 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.cs @@ -123,10 +123,8 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf { global::SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails @this = default; int __size_native__out = default; - int __size_native = *__size_native__param; int size = default; nint* __invokeRetValUnmanaged__out = default; - nint* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int[] __invokeRetVal = default; int __retVal = default; // Setup - Perform required setup. diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.cs index f12c30f..4037daa 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.cs @@ -259,13 +259,10 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf { global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails @this = default; int* __widths_native__out = default; - int* __widths_native = *__widths_native__param; int[] widths = default; int __length_native__out = default; - int __length_native = *__length_native__param; int length = default; System.IntPtr* __invokeRetValUnmanaged__out = default; - System.IntPtr* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int[][] __invokeRetVal = default; int __retVal = default; // Setup - Perform required setup. @@ -323,13 +320,10 @@ internal static int ABI_Get2(System.Runtime.InteropServices.ComWrappers.ComInter { global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails @this = default; System.IntPtr* __array_native__out = default; - System.IntPtr* __array_native = *__array_native__param; int[][] array = default; int* __widths_native__out = default; - int* __widths_native = *__widths_native__param; int[] widths = default; int __invokeRetValUnmanaged__out = default; - int __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; int __invokeRetVal = default; int __retVal = default; // Setup - Perform required setup. diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs index e56fc8e..91a773f 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs @@ -470,7 +470,6 @@ internal static int ABI_OutParam(System.Runtime.InteropServices.ComWrappers.ComI { global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails @this = default; nint* __value_native__out = default; - nint* __value_native = *__value_native__param; string[] value = default; int __retVal = default; // Setup - Perform required setup. @@ -610,7 +609,6 @@ internal static int ABI_ReturnValue(System.Runtime.InteropServices.ComWrappers.C { global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails @this = default; nint* __invokeRetValUnmanaged__out = default; - nint* __invokeRetValUnmanaged = *__invokeRetValUnmanaged__param; string[] __invokeRetVal = default; int __retVal = default; // Setup - Perform required setup. diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeToManagedStubs.g.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeToManagedStubs.g.cs index 5cebb50..d146508 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeToManagedStubs.g.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeToManagedStubs.g.cs @@ -94,7 +94,6 @@ internal static void ABI_SumAndSetData(void* __this_native, int* __values_native global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject @this; int[] values; int __oldValue_native__out = default; - int __oldValue_native = *__oldValue_native__param; int oldValue; // Setup - Perform required setup. int __values_native__numElements; @@ -133,7 +132,6 @@ internal static void ABI_SumAndSetData(void* __this_native, int** __values_nativ int* __values_native = *__values_native__param; int[] values = default; int __oldValue_native__out = default; - int __oldValue_native = *__oldValue_native__param; int oldValue = default; // Setup - Perform required setup. int __values_native__numElements; @@ -292,7 +290,6 @@ internal static void ABI_SumAndSetData(void* __this_native, int* __values_native global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject @this; global::SharedTypes.IntWrapper[] values; int __oldValue_native__out = default; - int __oldValue_native = *__oldValue_native__param; global::SharedTypes.IntWrapper oldValue; // Setup - Perform required setup. int __values_native__numElements; @@ -339,7 +336,6 @@ internal static void ABI_SumAndSetData(void* __this_native, int** __values_nativ int* __values_native = *__values_native__param; global::SharedTypes.IntWrapper[] values = default; int __oldValue_native__out = default; - int __oldValue_native = *__oldValue_native__param; global::SharedTypes.IntWrapper oldValue = default; // Setup - Perform required setup. int __values_native__numElements; @@ -466,7 +462,6 @@ internal static void ABI_SumAndSetData(void* __this_native, int* __values_native global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObjectStateful @this = default; global::SharedTypes.IntWrapper[] values = default; int __oldValue_native__out = default; - int __oldValue_native = *__oldValue_native__param; global::SharedTypes.IntWrapper oldValue = default; // Setup - Perform required setup. global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.StatefulUnmanagedToManagedCollectionMarshaller.In __values_native__marshaller = new(); @@ -518,7 +513,6 @@ internal static void ABI_SumAndSetData(void* __this_native, int** __values_nativ int* __values_native = *__values_native__param; global::SharedTypes.IntWrapper[] values = default; int __oldValue_native__out = default; - int __oldValue_native = *__oldValue_native__param; global::SharedTypes.IntWrapper oldValue = default; // Setup - Perform required setup. global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.StatefulUnmanagedToManagedCollectionMarshaller.Ref __values_native__marshaller = new(); @@ -542,7 +536,7 @@ internal static void ABI_SumAndSetData(void* __this_native, int** __values_nativ @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObjectStateful)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); @this.SumAndSetData(ref values, numValues, out oldValue); // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __values_native = __values_native__marshaller.ToUnmanaged(); + __values_native__out = __values_native__marshaller.ToUnmanaged(); // Marshal - Convert managed data to native data. __oldValue_native__out = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(oldValue); __values_native__marshaller.FromManaged(values); From e5928d0cb6c33f3258327f07f6381836843c2af8 Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Tue, 25 Jul 2023 16:27:00 -0700 Subject: [PATCH 5/8] More test types --- ...ypes.ComInterfaces.StatelessMarshalling.cs | 31 + ....ComInterfaces.IArrayOfStatefulElements.cs | 788 ++++++++++++++++++ ...ComInterfaces.IArrayOfStatelessElements.cs | 750 +++++++++++++++++ ...ComInterfaces.ICustomCollectionStateful.cs | 38 +- .../SharedTypes.ComInterfaces.IEnumUnknown.cs | 2 - .../SharedTypes.ComInterfaces.IIntArray.cs | 4 +- .../SharedTypes.ComInterfaces.IInterface.cs | 2 +- .../SharedTypes.ComInterfaces.IRefStrings.cs | 2 +- ...ces.IStatefulCollectionBlittableElement.cs | 421 ++++++++++ ...ces.IStatefulCollectionStatelessElement.cs | 579 +++++++++++++ ...ypes.ComInterfaces.IStatefulMarshalling.cs | 445 ++++++++++ ...es.IStatelessCollectionBlittableElement.cs | 390 +++++++++ ...es.IStatelessCollectionStatelessElement.cs | 390 +++++++++ ...pes.ComInterfaces.IStatelessMarshalling.cs | 373 +++++++++ ...llingFails.IStringArrayMarshallingFails.cs | 6 +- .../NativeToManagedStubs.g.cs | 19 +- 16 files changed, 4182 insertions(+), 58 deletions(-) create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessMarshalling.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IArrayOfStatefulElements.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IArrayOfStatelessElements.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulMarshalling.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessMarshalling.cs diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessMarshalling.cs new file mode 100644 index 0000000..ccfd5a6 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessMarshalling.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.IStatelessMarshalling).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 StatelessMarshalling + { + } +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IArrayOfStatefulElements.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IArrayOfStatefulElements.cs new file mode 100644 index 0000000..70c94f0 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IArrayOfStatefulElements.cs @@ -0,0 +1,788 @@ +// +#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[] { 191, 76, 150, 244, 175, 137, 11, 70, 132, 149, 16, 119, 130, 24, 119, 8 })); + + 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.IArrayOfStatefulElements +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IArrayOfStatefulElements.Method(global::SharedTypes.ComInterfaces.StatefulType[] param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatefulElements)); + nint* __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __param_native__marshaller = new(); + int __param_native__numElements; + int __param_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __param_native__managedSpan = __param_native__marshaller.GetManagedValuesSource(); + System.Span __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__managedSpan.Length; ++__i0, ++__param_native__lastIndexMarshalled) + { + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__nativeSpan____i0__marshaller = new(); + __param_native__nativeSpan____i0__marshaller.FromManaged(__param_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __param_native__unused = __param_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__nativeSpan____i0__marshaller = new(); + __param_native__nativeSpan____i0__marshaller.Free(); + } + } + + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IArrayOfStatefulElements.MethodIn(in global::SharedTypes.ComInterfaces.StatefulType[] param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatefulElements)); + nint* __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __param_native__marshaller = new(); + int __param_native__numElements; + int __param_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __param_native__managedSpan = __param_native__marshaller.GetManagedValuesSource(); + System.Span __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__managedSpan.Length; ++__i0, ++__param_native__lastIndexMarshalled) + { + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__nativeSpan____i0__marshaller = new(); + __param_native__nativeSpan____i0__marshaller.FromManaged(__param_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __param_native__unused = __param_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__nativeSpan____i0__marshaller = new(); + __param_native__nativeSpan____i0__marshaller.Free(); + } + } + + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IArrayOfStatefulElements.MethodOut(out global::SharedTypes.ComInterfaces.StatefulType[] param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatefulElements)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out param); + nint* __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __param_native__numElements = size; + param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__nativeSpan____i0__marshaller = new(); + __param_native__nativeSpan____i0__marshaller.FromUnmanaged(__param_native__nativeSpan[__i0]); + __param_native__managedSpan[__i0] = __param_native__nativeSpan____i0__marshaller.ToManaged(); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__param_native, __param_native__numElements); + for (int __i0 = 0; __i0 < __param_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__nativeSpan____i0__marshaller = new(); + __param_native__nativeSpan____i0__marshaller.Free(); + } + } + + __param_native__numElements = size; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__param_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IArrayOfStatefulElements.MethodRef(ref global::SharedTypes.ComInterfaces.StatefulType[] param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatefulElements)); + nint* __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + int __param_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __param_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(param, out __param_native__numElements); + { + System.ReadOnlySpan __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(param); + System.Span __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__param_native, __param_native__numElements); + for (int __i0 = 0; __i0 < __param_native__managedSpan.Length; ++__i0, ++__param_native__lastIndexMarshalled) + { + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__nativeSpan____i0__marshaller = new(); + __param_native__nativeSpan____i0__marshaller.FromManaged(__param_native__managedSpan[__i0]); + } + } + + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __param_native__numElements = size; + param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__nativeSpan____i0__marshaller = new(); + __param_native__nativeSpan____i0__marshaller.FromUnmanaged(__param_native__nativeSpan[__i0]); + __param_native__managedSpan[__i0] = __param_native__nativeSpan____i0__marshaller.ToManaged(); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__param_native, __param_native__numElements); + for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__nativeSpan____i0__marshaller = new(); + __param_native__nativeSpan____i0__marshaller.Free(); + } + } + + __param_native__numElements = size; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__param_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IArrayOfStatefulElements.MethodContentsIn(global::SharedTypes.ComInterfaces.StatefulType[] param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatefulElements)); + nint* __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __param_native__marshaller = new(); + int __param_native__numElements; + int __param_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __param_native__managedSpan = __param_native__marshaller.GetManagedValuesSource(); + System.Span __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__managedSpan.Length; ++__i0, ++__param_native__lastIndexMarshalled) + { + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__nativeSpan____i0__marshaller = new(); + __param_native__nativeSpan____i0__marshaller.FromManaged(__param_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __param_native__unused = __param_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, __param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__nativeSpan____i0__marshaller = new(); + __param_native__nativeSpan____i0__marshaller.Free(); + } + } + + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IArrayOfStatefulElements.MethodContentsOut(global::SharedTypes.ComInterfaces.StatefulType[] param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatefulElements)); + nint* __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __param_native__marshaller = new(); + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + __param_native__marshaller.GetUnmanagedValuesDestination().Clear(); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __param_native__unused = __param_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this, __param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + { + __param_native__numElements = __param_native__marshaller.GetManagedValuesSource().Length; + System.Span __param_native__managedSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __param_native__marshaller.GetManagedValuesSource().GetPinnableReference()), __param_native__numElements); + System.Span __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__nativeSpan____i0__marshaller = new(); + __param_native__nativeSpan____i0__marshaller.FromUnmanaged(__param_native__nativeSpan[__i0]); + __param_native__managedSpan[__i0] = __param_native__nativeSpan____i0__marshaller.ToManaged(); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__nativeSpan____i0__marshaller = new(); + __param_native__nativeSpan____i0__marshaller.Free(); + } + } + + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IArrayOfStatefulElements.MethodContentsInOut(global::SharedTypes.ComInterfaces.StatefulType[] param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatefulElements)); + nint* __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __param_native__marshaller = new(); + int __param_native__numElements; + int __param_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __param_native__managedSpan = __param_native__marshaller.GetManagedValuesSource(); + System.Span __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__managedSpan.Length; ++__i0, ++__param_native__lastIndexMarshalled) + { + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__nativeSpan____i0__marshaller = new(); + __param_native__nativeSpan____i0__marshaller.FromManaged(__param_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __param_native__unused = __param_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[9])(__this, __param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + { + __param_native__numElements = __param_native__marshaller.GetManagedValuesSource().Length; + System.Span __param_native__managedSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __param_native__marshaller.GetManagedValuesSource().GetPinnableReference()), __param_native__numElements); + System.Span __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__nativeSpan____i0__marshaller = new(); + __param_native__nativeSpan____i0__marshaller.FromUnmanaged(__param_native__nativeSpan[__i0]); + __param_native__managedSpan[__i0] = __param_native__nativeSpan____i0__marshaller.ToManaged(); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__nativeSpan____i0__marshaller = new(); + __param_native__nativeSpan____i0__marshaller.Free(); + } + } + + __param_native__marshaller.Free(); + } + } +} + +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, nint* __param_native, int size) + { + global::SharedTypes.ComInterfaces.IArrayOfStatefulElements @this = default; + global::SharedTypes.ComInterfaces.StatefulType[] param = default; + int __retVal = default; + // Setup - Perform required setup. + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __param_native__numElements = size; + param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__nativeSpan____i0__marshaller = new(); + __param_native__nativeSpan____i0__marshaller.FromUnmanaged(__param_native__nativeSpan[__i0]); + __param_native__managedSpan[__i0] = __param_native__nativeSpan____i0__marshaller.ToManaged(); + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Method(param, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint** __param_native__param, int size) + { + global::SharedTypes.ComInterfaces.IArrayOfStatefulElements @this = default; + nint* __param_native = *__param_native__param; + global::SharedTypes.ComInterfaces.StatefulType[] param = default; + int __retVal = default; + // Setup - Perform required setup. + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __param_native__numElements = size; + param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__nativeSpan____i0__marshaller = new(); + __param_native__nativeSpan____i0__marshaller.FromUnmanaged(__param_native__nativeSpan[__i0]); + __param_native__managedSpan[__i0] = __param_native__nativeSpan____i0__marshaller.ToManaged(); + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodIn(in param, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint** __param_native__param, int size) + { + global::SharedTypes.ComInterfaces.IArrayOfStatefulElements @this = default; + nint* __param_native__out = default; + global::SharedTypes.ComInterfaces.StatefulType[] param = default; + int __retVal = default; + // Setup - Perform required setup. + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodOut(out param, size); + // Marshal - Convert managed data to native data. + __param_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(param, out __param_native__numElements); + { + System.ReadOnlySpan __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(param); + System.Span __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__param_native__out, __param_native__numElements); + __param_native__nativeSpan.Clear(); + for (int __i0 = 0; __i0 < __param_native__managedSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__nativeSpan____i0__marshaller = new(); + __param_native__nativeSpan____i0__marshaller.FromManaged(__param_native__managedSpan[__i0]); + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint** __param_native__param, int size) + { + global::SharedTypes.ComInterfaces.IArrayOfStatefulElements @this = default; + nint* __param_native__out = default; + nint* __param_native = *__param_native__param; + global::SharedTypes.ComInterfaces.StatefulType[] param = default; + int __retVal = default; + // Setup - Perform required setup. + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + int __param_native__lastIndexMarshalled = 0; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __param_native__numElements = size; + param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__nativeSpan____i0__marshaller = new(); + __param_native__nativeSpan____i0__marshaller.FromUnmanaged(__param_native__nativeSpan[__i0]); + __param_native__managedSpan[__i0] = __param_native__nativeSpan____i0__marshaller.ToManaged(); + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodRef(ref param, size); + // Marshal - Convert managed data to native data. + __param_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(param, out __param_native__numElements); + { + System.ReadOnlySpan __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(param); + System.Span __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__param_native__out, __param_native__numElements); + for (int __i0 = 0; __i0 < __param_native__managedSpan.Length; ++__i0, ++__param_native__lastIndexMarshalled) + { + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__nativeSpan____i0__marshaller = new(); + __param_native__nativeSpan____i0__marshaller.FromManaged(__param_native__managedSpan[__i0]); + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native__out, __param_native__numElements); + for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__nativeSpan____i0__marshaller = new(); + __param_native__nativeSpan____i0__marshaller.Free(); + } + } + + __param_native__numElements = size; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__param_native__out); + return __retVal; + } + + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__nativeSpan____i0__marshaller = new(); + __param_native__nativeSpan____i0__marshaller.Free(); + } + } + + __param_native__numElements = size; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__param_native); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodContentsIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native, int size) + { + global::SharedTypes.ComInterfaces.IArrayOfStatefulElements @this = default; + global::SharedTypes.ComInterfaces.StatefulType[] param = default; + int __retVal = default; + // Setup - Perform required setup. + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __param_native__numElements = size; + param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__nativeSpan____i0__marshaller = new(); + __param_native__nativeSpan____i0__marshaller.FromUnmanaged(__param_native__nativeSpan[__i0]); + __param_native__managedSpan[__i0] = __param_native__nativeSpan____i0__marshaller.ToManaged(); + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodContentsIn(param, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodContentsOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native, int size) + { + global::SharedTypes.ComInterfaces.IArrayOfStatefulElements @this = default; + global::SharedTypes.ComInterfaces.StatefulType[] param = default; + int __retVal = default; + // Setup - Perform required setup. + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + System.Span __param_native__out; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param).Clear(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodContentsOut(param, size); + // Marshal - Convert managed data to native data. + { + __param_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param).Length; +#pragma warning disable CS9081 + __param_native__out = stackalloc nint[__param_native__numElements]; +#pragma warning restore CS9081 + System.Span __param_native__nativeSpan = __param_native__out; + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__nativeSpan____i0__marshaller = new(); + nint __param_native__nativeSpan____i0__original = __param_native__nativeSpan[__i0]; + __param_native__nativeSpan____i0__marshaller.FromManaged(__param_native__managedSpan[__i0]); + __param_native__nativeSpan[__i0] = __param_native__nativeSpan____i0__marshaller.ToUnmanaged(); + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + __param_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements).GetPinnableReference()), __param_native__numElements)); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodContentsInOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native, int size) + { + global::SharedTypes.ComInterfaces.IArrayOfStatefulElements @this = default; + global::SharedTypes.ComInterfaces.StatefulType[] param = default; + int __retVal = default; + // Setup - Perform required setup. + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + System.Span __param_native__out; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __param_native__numElements = size; + param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__nativeSpan____i0__marshaller = new(); + __param_native__nativeSpan____i0__marshaller.FromUnmanaged(__param_native__nativeSpan[__i0]); + __param_native__managedSpan[__i0] = __param_native__nativeSpan____i0__marshaller.ToManaged(); + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodContentsInOut(param, size); + // Marshal - Convert managed data to native data. + { + __param_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param).Length; +#pragma warning disable CS9081 + __param_native__out = stackalloc nint[__param_native__numElements]; +#pragma warning restore CS9081 + System.Span __param_native__nativeSpan = __param_native__out; + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__nativeSpan____i0__marshaller = new(); + nint __param_native__nativeSpan____i0__original = __param_native__nativeSpan[__i0]; + __param_native__nativeSpan____i0__marshaller.FromManaged(__param_native__managedSpan[__i0]); + __param_native__nativeSpan[__i0] = __param_native__nativeSpan____i0__marshaller.ToUnmanaged(); + __param_native__nativeSpan____i0__marshaller.Free(); + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + __param_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements).GetPinnableReference()), __param_native__numElements)); + return __retVal; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatefulElements), sizeof(void*) * 10); + { + 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; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodIn; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodOut; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodRef; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodContentsIn; + vtable[8] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodContentsOut; + vtable[9] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodContentsInOut; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IArrayOfStatefulElements + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IArrayOfStatefulElements + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IArrayOfStatelessElements.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IArrayOfStatelessElements.cs new file mode 100644 index 0000000..191ee2c --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IArrayOfStatelessElements.cs @@ -0,0 +1,750 @@ +// +#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[] { 191, 60, 150, 244, 175, 16, 11, 70, 132, 149, 16, 119, 130, 24, 119, 5 })); + + 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.IArrayOfStatelessElements +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IArrayOfStatelessElements.Method(global::SharedTypes.ComInterfaces.StatelessType[] param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatelessElements)); + nint* __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __param_native__marshaller = new(); + int __param_native__numElements; + int __param_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __param_native__managedSpan = __param_native__marshaller.GetManagedValuesSource(); + System.Span __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__managedSpan.Length; ++__i0, ++__param_native__lastIndexMarshalled) + { + __param_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__param_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __param_native__unused = __param_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan[__i0]); + } + } + + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IArrayOfStatelessElements.MethodIn(in global::SharedTypes.ComInterfaces.StatelessType[] param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatelessElements)); + nint* __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __param_native__marshaller = new(); + int __param_native__numElements; + int __param_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __param_native__managedSpan = __param_native__marshaller.GetManagedValuesSource(); + System.Span __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__managedSpan.Length; ++__i0, ++__param_native__lastIndexMarshalled) + { + __param_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__param_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __param_native__unused = __param_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan[__i0]); + } + } + + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IArrayOfStatelessElements.MethodOut(out global::SharedTypes.ComInterfaces.StatelessType[] param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatelessElements)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out param); + nint* __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __param_native__numElements = size; + param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + __param_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__param_native, __param_native__numElements); + for (int __i0 = 0; __i0 < __param_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan[__i0]); + } + } + + __param_native__numElements = size; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__param_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IArrayOfStatelessElements.MethodRef(ref global::SharedTypes.ComInterfaces.StatelessType[] param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatelessElements)); + nint* __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + int __param_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __param_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(param, out __param_native__numElements); + { + System.ReadOnlySpan __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(param); + System.Span __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__param_native, __param_native__numElements); + for (int __i0 = 0; __i0 < __param_native__managedSpan.Length; ++__i0, ++__param_native__lastIndexMarshalled) + { + __param_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__param_native__managedSpan[__i0]); + } + } + + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __param_native__numElements = size; + param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + __param_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__param_native, __param_native__numElements); + for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan[__i0]); + } + } + + __param_native__numElements = size; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__param_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IArrayOfStatelessElements.MethodContentsIn(global::SharedTypes.ComInterfaces.StatelessType[] param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatelessElements)); + nint* __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __param_native__marshaller = new(); + int __param_native__numElements; + int __param_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __param_native__managedSpan = __param_native__marshaller.GetManagedValuesSource(); + System.Span __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__managedSpan.Length; ++__i0, ++__param_native__lastIndexMarshalled) + { + __param_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__param_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __param_native__unused = __param_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, __param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan[__i0]); + } + } + + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IArrayOfStatelessElements.MethodContentsOut(global::SharedTypes.ComInterfaces.StatelessType[] param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatelessElements)); + nint* __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __param_native__marshaller = new(); + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + __param_native__marshaller.GetUnmanagedValuesDestination().Clear(); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __param_native__unused = __param_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this, __param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + { + __param_native__numElements = __param_native__marshaller.GetManagedValuesSource().Length; + System.Span __param_native__managedSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __param_native__marshaller.GetManagedValuesSource().GetPinnableReference()), __param_native__numElements); + System.Span __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + __param_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan[__i0]); + } + } + + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IArrayOfStatelessElements.MethodContentsInOut(global::SharedTypes.ComInterfaces.StatelessType[] param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatelessElements)); + nint* __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __param_native__marshaller = new(); + int __param_native__numElements; + int __param_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __param_native__managedSpan = __param_native__marshaller.GetManagedValuesSource(); + System.Span __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__managedSpan.Length; ++__i0, ++__param_native__lastIndexMarshalled) + { + __param_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__param_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __param_native__unused = __param_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[9])(__this, __param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + { + __param_native__numElements = __param_native__marshaller.GetManagedValuesSource().Length; + System.Span __param_native__managedSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __param_native__marshaller.GetManagedValuesSource().GetPinnableReference()), __param_native__numElements); + System.Span __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + __param_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan[__i0]); + } + } + + __param_native__marshaller.Free(); + } + } +} + +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, nint* __param_native, int size) + { + global::SharedTypes.ComInterfaces.IArrayOfStatelessElements @this = default; + global::SharedTypes.ComInterfaces.StatelessType[] param = default; + int __retVal = default; + // Setup - Perform required setup. + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __param_native__numElements = size; + param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + __param_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native__nativeSpan[__i0]); + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Method(param, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint** __param_native__param, int size) + { + global::SharedTypes.ComInterfaces.IArrayOfStatelessElements @this = default; + nint* __param_native = *__param_native__param; + global::SharedTypes.ComInterfaces.StatelessType[] param = default; + int __retVal = default; + // Setup - Perform required setup. + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __param_native__numElements = size; + param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + __param_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native__nativeSpan[__i0]); + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodIn(in param, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint** __param_native__param, int size) + { + global::SharedTypes.ComInterfaces.IArrayOfStatelessElements @this = default; + nint* __param_native__out = default; + global::SharedTypes.ComInterfaces.StatelessType[] param = default; + int __retVal = default; + // Setup - Perform required setup. + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodOut(out param, size); + // Marshal - Convert managed data to native data. + __param_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(param, out __param_native__numElements); + { + System.ReadOnlySpan __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(param); + System.Span __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__param_native__out, __param_native__numElements); + __param_native__nativeSpan.Clear(); + for (int __i0 = 0; __i0 < __param_native__managedSpan.Length; ++__i0) + { + __param_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__param_native__managedSpan[__i0]); + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint** __param_native__param, int size) + { + global::SharedTypes.ComInterfaces.IArrayOfStatelessElements @this = default; + nint* __param_native__out = default; + nint* __param_native = *__param_native__param; + global::SharedTypes.ComInterfaces.StatelessType[] param = default; + int __retVal = default; + // Setup - Perform required setup. + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + int __param_native__lastIndexMarshalled = 0; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __param_native__numElements = size; + param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + __param_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native__nativeSpan[__i0]); + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodRef(ref param, size); + // Marshal - Convert managed data to native data. + __param_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(param, out __param_native__numElements); + { + System.ReadOnlySpan __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(param); + System.Span __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__param_native__out, __param_native__numElements); + for (int __i0 = 0; __i0 < __param_native__managedSpan.Length; ++__i0, ++__param_native__lastIndexMarshalled) + { + __param_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__param_native__managedSpan[__i0]); + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native__out, __param_native__numElements); + for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan[__i0]); + } + } + + __param_native__numElements = size; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__param_native__out); + return __retVal; + } + + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan[__i0]); + } + } + + __param_native__numElements = size; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__param_native); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodContentsIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native, int size) + { + global::SharedTypes.ComInterfaces.IArrayOfStatelessElements @this = default; + global::SharedTypes.ComInterfaces.StatelessType[] param = default; + int __retVal = default; + // Setup - Perform required setup. + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __param_native__numElements = size; + param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + __param_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native__nativeSpan[__i0]); + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodContentsIn(param, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodContentsOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native, int size) + { + global::SharedTypes.ComInterfaces.IArrayOfStatelessElements @this = default; + global::SharedTypes.ComInterfaces.StatelessType[] param = default; + int __retVal = default; + // Setup - Perform required setup. + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + System.Span __param_native__out; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param).Clear(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodContentsOut(param, size); + // Marshal - Convert managed data to native data. + { + __param_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param).Length; +#pragma warning disable CS9081 + __param_native__out = stackalloc nint[__param_native__numElements]; +#pragma warning restore CS9081 + System.Span __param_native__nativeSpan = __param_native__out; + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + nint __param_native__nativeSpan____i0__original = __param_native__nativeSpan[__i0]; + __param_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__param_native__managedSpan[__i0]); + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + __param_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements).GetPinnableReference()), __param_native__numElements)); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodContentsInOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native, int size) + { + global::SharedTypes.ComInterfaces.IArrayOfStatelessElements @this = default; + global::SharedTypes.ComInterfaces.StatelessType[] param = default; + int __retVal = default; + // Setup - Perform required setup. + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + System.Span __param_native__out; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __param_native__numElements = size; + param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + __param_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native__nativeSpan[__i0]); + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodContentsInOut(param, size); + // Marshal - Convert managed data to native data. + { + __param_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param).Length; +#pragma warning disable CS9081 + __param_native__out = stackalloc nint[__param_native__numElements]; +#pragma warning restore CS9081 + System.Span __param_native__nativeSpan = __param_native__out; + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + nint __param_native__nativeSpan____i0__original = __param_native__nativeSpan[__i0]; + __param_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__param_native__managedSpan[__i0]); + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan____i0__original); + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + __param_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements).GetPinnableReference()), __param_native__numElements)); + return __retVal; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatelessElements), sizeof(void*) * 10); + { + 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; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodIn; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodOut; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodRef; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodContentsIn; + vtable[8] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodContentsOut; + vtable[9] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodContentsInOut; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IArrayOfStatelessElements + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IArrayOfStatelessElements + { + } +} \ 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 index b581c2f..d643c95 100644 --- 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 @@ -48,35 +48,8 @@ { // 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) @@ -238,11 +211,12 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt 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]); } + + __invokeRetValUnmanaged__out = (byte*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref __invokeRetValUnmanaged__nativeSpan.GetPinnableReference()); } __pOutSize_native__out = pOutSize; @@ -251,28 +225,30 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt 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]); } + + __pOut_native__out = (byte*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref __pOut_native__nativeSpan.GetPinnableReference()); } __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]); } + + __pRef_native__out = (byte*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref __pRef_native__nativeSpan.GetPinnableReference()); } } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); - // Cleanup - Perform required cleanup. + // CleanupFailure - Perform required cleanup. _ = __pRef_native__lastIndexMarshalled; __pRef_native__marshaller.Free(); 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 3a2a824..046fd5f 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 @@ -168,8 +168,6 @@ internal static int ABI_Next(System.Runtime.InteropServices.ComWrappers.ComInter // AssignOut - Assign to parameters *__pceltFetched_native__param = __pceltFetched_native__out; __rgelt_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__rgelt_native, __rgelt_native__numElements).GetPinnableReference()), __rgelt_native__numElements)); - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__rgelt_native); return __retVal; } diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs index 309b6b3..a4ae0e5 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs @@ -321,8 +321,6 @@ internal static int ABI_FillAscending(System.Runtime.InteropServices.ComWrappers // AssignOut - Assign to parameters __array_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements).GetPinnableReference()), __array_native__numElements)); - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native); return __retVal; } @@ -382,7 +380,7 @@ internal static int ABI_SwapArray(System.Runtime.InteropServices.ComWrappers.Com catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); - // Cleanup - Perform required cleanup. + // CleanupFailure - Perform required cleanup. __array_native__numElements = size; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native__out); return __retVal; diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs index 87c6e30..412526e 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs @@ -218,7 +218,7 @@ internal static int ABI_SwapRef(System.Runtime.InteropServices.ComWrappers.ComIn catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); - // Cleanup - Perform required cleanup. + // CleanupFailure - Perform required cleanup. global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__value_native__out); return __retVal; } diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs index b029fba..bc00514 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs @@ -118,7 +118,7 @@ internal static int ABI_RefString(System.Runtime.InteropServices.ComWrappers.Com catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); - // Cleanup - Perform required cleanup. + // CleanupFailure - Perform required cleanup. global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__value_native__out); return __retVal; } diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.cs new file mode 100644 index 0000000..fb151f4 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.cs @@ -0,0 +1,421 @@ +// +#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.IStatefulCollectionBlittableElement +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.Method(global::SharedTypes.ComInterfaces.StatefulCollection p, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement)); + byte* __p_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __p_native__marshaller = new(); + int __p_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __p_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __p_native__marshaller.FromManaged(p); + __p_native__marshaller.GetManagedValuesSource().CopyTo(__p_native__marshaller.GetUnmanagedValuesDestination()); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __p_native = __p_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __p_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + __p_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.MethodIn(in global::SharedTypes.ComInterfaces.StatefulCollection pIn, in int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement)); + byte* __pIn_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __pIn_native__marshaller = new(); + int __pIn_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pIn_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __pIn_native__marshaller.FromManaged(pIn); + __pIn_native__marshaller.GetManagedValuesSource().CopyTo(__pIn_native__marshaller.GetUnmanagedValuesDestination()); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pIn_native = __pIn_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__pIn_native, __size_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + __pIn_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.MethodRef(ref global::SharedTypes.ComInterfaces.StatefulCollection pRef, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement)); + byte* __pRef_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __pRef_native__marshaller = new(); + int __pRef_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pRef_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __pRef_native__marshaller.FromManaged(pRef); + __pRef_native__marshaller.GetManagedValuesSource().CopyTo(__pRef_native__marshaller.GetUnmanagedValuesDestination()); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pRef_native = __pRef_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__pRef_native, size); + } + + System.GC.KeepAlive(this); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __pRef_native__marshaller.FromUnmanaged(__pRef_native); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __pRef_native__numElements = size; + __pRef_native__marshaller.GetUnmanagedValuesSource(__pRef_native__numElements).CopyTo(__pRef_native__marshaller.GetManagedValuesDestination(__pRef_native__numElements)); + pRef = __pRef_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __pRef_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.MethodOut(out global::SharedTypes.ComInterfaces.StatefulCollection pOut, out int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out pOut); + System.Runtime.CompilerServices.Unsafe.SkipInit(out size); + byte* __pOut_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __pOut_native__marshaller = new(); + int __pOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pOut_native__numElements); + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__pOut_native, __size_native); + } + + System.GC.KeepAlive(this); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __pOut_native__marshaller.FromUnmanaged(__pOut_native); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __pOut_native__numElements = size; + __pOut_native__marshaller.GetUnmanagedValuesSource(__pOut_native__numElements).CopyTo(__pOut_native__marshaller.GetManagedValuesDestination(__pOut_native__numElements)); + pOut = __pOut_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __pOut_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatefulCollection global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.Return(int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement)); + global::SharedTypes.ComInterfaces.StatefulCollection __retVal = default; + byte* __retVal_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __retVal_native__marshaller = new(); + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, size, &__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); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal_native__numElements = size; + __retVal_native__marshaller.GetUnmanagedValuesSource(__retVal_native__numElements).CopyTo(__retVal_native__marshaller.GetManagedValuesDestination(__retVal_native__numElements)); + __retVal = __retVal_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_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 size) + { + global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement @this = default; + global::SharedTypes.ComInterfaces.StatefulCollection p = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __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. + __p_native__marshaller.FromUnmanaged(__p_native); + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __p_native__numElements = size; + __p_native__marshaller.GetUnmanagedValuesSource(__p_native__numElements).CopyTo(__p_native__marshaller.GetManagedValuesDestination(__p_native__numElements)); + p = __p_native__marshaller.ToManaged(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Method(p, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // Cleanup - Perform required cleanup. + __p_native__marshaller.Free(); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, byte** __pIn_native__param, int* __size_native__param) + { + global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement @this = default; + byte* __pIn_native = *__pIn_native__param; + global::SharedTypes.ComInterfaces.StatefulCollection pIn = default; + int __size_native = *__size_native__param; + int size = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __pIn_native__marshaller = new(); + int __pIn_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pIn_native__numElements); + try + { + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __pIn_native__marshaller.FromUnmanaged(__pIn_native); + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + size = __size_native; + __pIn_native__numElements = size; + __pIn_native__marshaller.GetUnmanagedValuesSource(__pIn_native__numElements).CopyTo(__pIn_native__marshaller.GetManagedValuesDestination(__pIn_native__numElements)); + pIn = __pIn_native__marshaller.ToManaged(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodIn(in pIn, in size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // Cleanup - Perform required cleanup. + __pIn_native__marshaller.Free(); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, byte** __pRef_native__param, int size) + { + global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement @this = default; + byte* __pRef_native__out = default; + byte* __pRef_native = *__pRef_native__param; + global::SharedTypes.ComInterfaces.StatefulCollection pRef = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __pRef_native__marshaller = new(); + int __pRef_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pRef_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); + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __pRef_native__numElements = size; + __pRef_native__marshaller.GetUnmanagedValuesSource(__pRef_native__numElements).CopyTo(__pRef_native__marshaller.GetManagedValuesDestination(__pRef_native__numElements)); + pRef = __pRef_native__marshaller.ToManaged(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodRef(ref pRef, size); + // Marshal - Convert managed data to native data. + __pRef_native__marshaller.FromManaged(pRef); + __pRef_native__marshaller.GetManagedValuesSource().CopyTo(__pRef_native__marshaller.GetUnmanagedValuesDestination()); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pRef_native__out = __pRef_native__marshaller.ToUnmanaged(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + __pRef_native__marshaller.Free(); + return __retVal; + } + + // AssignOut - Assign to parameters + *__pRef_native__param = __pRef_native__out; + // Cleanup - Perform required cleanup. + __pRef_native__marshaller.Free(); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, byte** __pOut_native__param, int* __size_native__param) + { + global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement @this = default; + byte* __pOut_native__out = default; + global::SharedTypes.ComInterfaces.StatefulCollection pOut = default; + int __size_native__out = default; + int size = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __pOut_native__marshaller = new(); + int __pOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pOut_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodOut(out pOut, out size); + // Marshal - Convert managed data to native data. + __size_native__out = size; + __pOut_native__marshaller.FromManaged(pOut); + __pOut_native__marshaller.GetManagedValuesSource().CopyTo(__pOut_native__marshaller.GetUnmanagedValuesDestination()); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pOut_native__out = __pOut_native__marshaller.ToUnmanaged(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__size_native__param = __size_native__out; + *__pOut_native__param = __pOut_native__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int size, byte** __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement @this = default; + byte* __invokeRetValUnmanaged__out = default; + global::SharedTypes.ComInterfaces.StatefulCollection __invokeRetVal = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __invokeRetValUnmanaged__marshaller = new(); + int __invokeRetValUnmanaged__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Return(size); + // Marshal - Convert managed data to native data. + __invokeRetValUnmanaged__marshaller.FromManaged(__invokeRetVal); + __invokeRetValUnmanaged__marshaller.GetManagedValuesSource().CopyTo(__invokeRetValUnmanaged__marshaller.GetUnmanagedValuesDestination()); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __invokeRetValUnmanaged__out = __invokeRetValUnmanaged__marshaller.ToUnmanaged(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + return __retVal; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement), sizeof(void*) * 8); + { + 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; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodIn; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodRef; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodOut; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Return; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + partial interface IStatefulCollectionBlittableElement + { + } +} + +namespace SharedTypes.ComInterfaces +{ + partial interface IStatefulCollectionBlittableElement + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.cs new file mode 100644 index 0000000..c12aea4 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.cs @@ -0,0 +1,579 @@ +// +#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.IStatefulCollectionStatelessElement +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.Method(global::SharedTypes.ComInterfaces.StatefulCollection p, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement)); + byte* __p_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __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. + __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.StatelessTypeMarshaller.ConvertToUnmanaged(__p_native__managedSpan[__i0]); + } + } + + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __p_native = __p_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __p_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __p_native__nativeSpan = __p_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __p_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__p_native__nativeSpan[__i0]); + } + } + + __p_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.MethodIn(in global::SharedTypes.ComInterfaces.StatefulCollection pIn, in int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement)); + byte* __pIn_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __pIn_native__marshaller = new(); + int __pIn_native__numElements; + int __pIn_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pIn_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __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.StatelessTypeMarshaller.ConvertToUnmanaged(__pIn_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pIn_native = __pIn_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__pIn_native, __size_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __pIn_native__nativeSpan = __pIn_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __pIn_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__pIn_native__nativeSpan[__i0]); + } + } + + __pIn_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.MethodRef(ref global::SharedTypes.ComInterfaces.StatefulCollection pRef, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement)); + byte* __pRef_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __pRef_native__marshaller = new(); + int __pRef_native__numElements; + int __pRef_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pRef_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.StatelessTypeMarshaller.ConvertToUnmanaged(__pRef_native__managedSpan[__i0]); + } + } + + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pRef_native = __pRef_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__pRef_native, size); + } + + System.GC.KeepAlive(this); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __pRef_native__marshaller.FromUnmanaged(__pRef_native); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __pRef_native__numElements = size; + { + 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.StatelessTypeMarshaller.ConvertToManaged(__pRef_native__nativeSpan[__i0]); + } + } + + pRef = __pRef_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __pRef_native__nativeSpan = __pRef_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __pRef_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__pRef_native__nativeSpan[__i0]); + } + } + + __pRef_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.MethodOut(out global::SharedTypes.ComInterfaces.StatefulCollection pOut, out int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out pOut); + System.Runtime.CompilerServices.Unsafe.SkipInit(out size); + byte* __pOut_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __pOut_native__marshaller = new(); + int __pOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pOut_native__numElements); + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__pOut_native, __size_native); + } + + System.GC.KeepAlive(this); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __pOut_native__marshaller.FromUnmanaged(__pOut_native); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __pOut_native__numElements = size; + { + 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.StatelessTypeMarshaller.ConvertToManaged(__pOut_native__nativeSpan[__i0]); + } + } + + pOut = __pOut_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __pOut_native__nativeSpan = __pOut_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __pOut_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__pOut_native__nativeSpan[__i0]); + } + } + + __pOut_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatefulCollection global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.Return(int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement)); + global::SharedTypes.ComInterfaces.StatefulCollection __retVal = default; + byte* __retVal_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __retVal_native__marshaller = new(); + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, size, &__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); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal_native__numElements = size; + { + 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.StatelessTypeMarshaller.ConvertToManaged(__retVal_native__nativeSpan[__i0]); + } + } + + __retVal = __retVal_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __retVal_native__nativeSpan = __retVal_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__retVal_native__nativeSpan[__i0]); + } + } + + __retVal_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 size) + { + global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement @this = default; + global::SharedTypes.ComInterfaces.StatefulCollection p = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __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. + __p_native__marshaller.FromUnmanaged(__p_native); + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __p_native__numElements = size; + { + 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.StatelessTypeMarshaller.ConvertToManaged(__p_native__nativeSpan[__i0]); + } + } + + p = __p_native__marshaller.ToManaged(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Method(p, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // Cleanup - Perform required cleanup. + __p_native__marshaller.Free(); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, byte** __pIn_native__param, int* __size_native__param) + { + global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement @this = default; + byte* __pIn_native = *__pIn_native__param; + global::SharedTypes.ComInterfaces.StatefulCollection pIn = default; + int __size_native = *__size_native__param; + int size = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __pIn_native__marshaller = new(); + int __pIn_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pIn_native__numElements); + try + { + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __pIn_native__marshaller.FromUnmanaged(__pIn_native); + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + size = __size_native; + __pIn_native__numElements = size; + { + 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.StatelessTypeMarshaller.ConvertToManaged(__pIn_native__nativeSpan[__i0]); + } + } + + pIn = __pIn_native__marshaller.ToManaged(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodIn(in pIn, in size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // Cleanup - Perform required cleanup. + __pIn_native__marshaller.Free(); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, byte** __pRef_native__param, int size) + { + global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement @this = default; + byte* __pRef_native__out = default; + byte* __pRef_native = *__pRef_native__param; + global::SharedTypes.ComInterfaces.StatefulCollection pRef = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __pRef_native__marshaller = new(); + int __pRef_native__numElements; + int __pRef_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pRef_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); + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __pRef_native__numElements = size; + { + 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.StatelessTypeMarshaller.ConvertToManaged(__pRef_native__nativeSpan[__i0]); + } + } + + pRef = __pRef_native__marshaller.ToManaged(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodRef(ref pRef, size); + // 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.StatelessTypeMarshaller.ConvertToUnmanaged(__pRef_native__managedSpan[__i0]); + } + } + + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pRef_native__out = __pRef_native__marshaller.ToUnmanaged(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + { + System.ReadOnlySpan __pRef_native__nativeSpan = __pRef_native__marshaller.GetUnmanagedValuesSource(__pRef_native__numElements); + for (int __i0 = 0; __i0 < __pRef_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__pRef_native__nativeSpan[__i0]); + } + } + + __pRef_native__marshaller.Free(); + return __retVal; + } + + // AssignOut - Assign to parameters + *__pRef_native__param = __pRef_native__out; + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __pRef_native__nativeSpan = __pRef_native__marshaller.GetUnmanagedValuesSource(__pRef_native__numElements); + for (int __i0 = 0; __i0 < __pRef_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__pRef_native__nativeSpan[__i0]); + } + } + + __pRef_native__marshaller.Free(); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, byte** __pOut_native__param, int* __size_native__param) + { + global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement @this = default; + byte* __pOut_native__out = default; + global::SharedTypes.ComInterfaces.StatefulCollection pOut = default; + int __size_native__out = default; + int size = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __pOut_native__marshaller = new(); + int __pOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pOut_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodOut(out pOut, out size); + // Marshal - Convert managed data to native data. + __size_native__out = size; + __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(); + for (int __i0 = 0; __i0 < __pOut_native__managedSpan.Length; ++__i0) + { + __pOut_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__pOut_native__managedSpan[__i0]); + } + } + + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pOut_native__out = __pOut_native__marshaller.ToUnmanaged(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__size_native__param = __size_native__out; + *__pOut_native__param = __pOut_native__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int size, byte** __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement @this = default; + byte* __invokeRetValUnmanaged__out = default; + global::SharedTypes.ComInterfaces.StatefulCollection __invokeRetVal = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __invokeRetValUnmanaged__marshaller = new(); + int __invokeRetValUnmanaged__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Return(size); + // 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(); + for (int __i0 = 0; __i0 < __invokeRetValUnmanaged__managedSpan.Length; ++__i0) + { + __invokeRetValUnmanaged__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__invokeRetValUnmanaged__managedSpan[__i0]); + } + } + + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __invokeRetValUnmanaged__out = __invokeRetValUnmanaged__marshaller.ToUnmanaged(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + return __retVal; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement), sizeof(void*) * 8); + { + 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; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodIn; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodRef; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodOut; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Return; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + partial interface IStatefulCollectionStatelessElement + { + } +} + +namespace SharedTypes.ComInterfaces +{ + partial interface IStatefulCollectionStatelessElement + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulMarshalling.cs new file mode 100644 index 0000000..71f1262 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulMarshalling.cs @@ -0,0 +1,445 @@ +// +#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[] { 93, 250, 49, 71, 3, 193, 34, 74, 135, 161, 88, 220, 237, 212, 169, 179 })); + + 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.IStatefulMarshalling +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulMarshalling.Method(global::SharedTypes.ComInterfaces.StatefulType param) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulMarshalling)); + nint __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __param_native); + } + + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __param_native__marshaller.OnInvoked(); + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulMarshalling.MethodIn(in global::SharedTypes.ComInterfaces.StatefulType param) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulMarshalling)); + nint __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__param_native); + } + + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __param_native__marshaller.OnInvoked(); + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulMarshalling.MethodOut(out global::SharedTypes.ComInterfaces.StatefulType param) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulMarshalling)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out param); + nint __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__marshaller = new(); + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__param_native); + } + + System.GC.KeepAlive(this); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __param_native__marshaller.FromUnmanaged(__param_native); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + param = __param_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulMarshalling.MethodRef(ref global::SharedTypes.ComInterfaces.StatefulType param) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulMarshalling)); + nint __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__param_native); + } + + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __param_native__marshaller.OnInvoked(); + System.GC.KeepAlive(this); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __param_native__marshaller.FromUnmanaged(__param_native); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + param = __param_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatefulType global::SharedTypes.ComInterfaces.IStatefulMarshalling.Return() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulMarshalling)); + global::SharedTypes.ComInterfaces.StatefulType __retVal = default; + nint __retVal_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __retVal_native__marshaller = new(); + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, &__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); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal = __retVal_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_native__marshaller.Free(); + } + + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatefulType global::SharedTypes.ComInterfaces.IStatefulMarshalling.ReturnPreserveSig() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulMarshalling)); + global::SharedTypes.ComInterfaces.StatefulType __retVal = default; + nint __retVal_native = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __retVal_native__marshaller = new(); + try + { + { + __retVal_native = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this); + } + + 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); + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_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, nint __param_native) + { + global::SharedTypes.ComInterfaces.IStatefulMarshalling @this = default; + global::SharedTypes.ComInterfaces.StatefulType param = default; + int __retVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__marshaller = new(); + try + { + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __param_native__marshaller.FromUnmanaged(__param_native); + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + param = __param_native__marshaller.ToManaged(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Method(param); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param) + { + global::SharedTypes.ComInterfaces.IStatefulMarshalling @this = default; + nint __param_native = *__param_native__param; + global::SharedTypes.ComInterfaces.StatefulType param = default; + int __retVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__marshaller = new(); + try + { + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __param_native__marshaller.FromUnmanaged(__param_native); + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + param = __param_native__marshaller.ToManaged(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodIn(in param); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param) + { + global::SharedTypes.ComInterfaces.IStatefulMarshalling @this = default; + nint __param_native__out = default; + global::SharedTypes.ComInterfaces.StatefulType param = default; + int __retVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__marshaller = new(); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodOut(out param); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __param_native__marshaller.OnInvoked(); + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native__out = __param_native__marshaller.ToUnmanaged(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param) + { + global::SharedTypes.ComInterfaces.IStatefulMarshalling @this = default; + nint __param_native__out = default; + nint __param_native = *__param_native__param; + global::SharedTypes.ComInterfaces.StatefulType param = default; + int __retVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__marshaller = new(); + try + { + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __param_native__marshaller.FromUnmanaged(__param_native); + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + param = __param_native__marshaller.ToManaged(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodRef(ref param); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __param_native__marshaller.OnInvoked(); + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native__out = __param_native__marshaller.ToUnmanaged(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + __param_native__marshaller.Free(); + return __retVal; + } + + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IStatefulMarshalling @this = default; + nint __invokeRetValUnmanaged__out = default; + global::SharedTypes.ComInterfaces.StatefulType __invokeRetVal = default; + int __retVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __invokeRetValUnmanaged__marshaller = new(); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Return(); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __invokeRetValUnmanaged__marshaller.OnInvoked(); + // Marshal - Convert managed data to native data. + __invokeRetValUnmanaged__marshaller.FromManaged(__invokeRetVal); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __invokeRetValUnmanaged__out = __invokeRetValUnmanaged__marshaller.ToUnmanaged(); + } + 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 nint ABI_ReturnPreserveSig(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native) + { + global::SharedTypes.ComInterfaces.IStatefulMarshalling @this = default; + global::SharedTypes.ComInterfaces.StatefulType __retVal = default; + nint __retVal_native = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __retVal_native__marshaller = new(); + try + { + // Unmarshal - Convert native data to managed data. + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __retVal = @this.ReturnPreserveSig(); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal_native__marshaller.OnInvoked(); + // Marshal - Convert managed data to native data. + __retVal_native__marshaller.FromManaged(__retVal); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __retVal_native = __retVal_native__marshaller.ToUnmanaged(); + } + catch (System.Exception __exception) + { + __retVal_native = System.Runtime.InteropServices.Marshalling.ExceptionAsDefaultMarshaller.ConvertToUnmanaged(__exception); + return __retVal_native; + } + + // Cleanup - Perform required cleanup. + __retVal_native__marshaller.Free(); + return __retVal_native; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IStatefulMarshalling), sizeof(void*) * 9); + { + 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; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodIn; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodOut; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodRef; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Return; + vtable[8] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_ReturnPreserveSig; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IStatefulMarshalling + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IStatefulMarshalling + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.cs new file mode 100644 index 0000000..05f385b --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.cs @@ -0,0 +1,390 @@ +// +#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.IStatelessCollectionBlittableElement +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.Method(global::SharedTypes.ComInterfaces.StatelessCollection p, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement)); + nint __p_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __p_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __p_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __p_native = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(p, out __p_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(p).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__p_native, __p_native__numElements)); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __p_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + ; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__p_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.MethodIn(in global::SharedTypes.ComInterfaces.StatelessCollection pIn, in int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement)); + nint __pIn_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __pIn_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pIn_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __pIn_native = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(pIn, out __pIn_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(pIn).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__pIn_native, __pIn_native__numElements)); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__pIn_native, __size_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + ; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pIn_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.MethodRef(ref global::SharedTypes.ComInterfaces.StatelessCollection pRef, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement)); + nint __pRef_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __pRef_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pRef_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __pRef_native = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(pRef, out __pRef_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(pRef).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__pRef_native, __pRef_native__numElements)); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__pRef_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __pRef_native__numElements = size; + pRef = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__pRef_native, __pRef_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__pRef_native, __pRef_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(pRef)); + } + finally + { + // Cleanup - Perform required cleanup. + __pRef_native__numElements = size; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pRef_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.MethodOut(out global::SharedTypes.ComInterfaces.StatelessCollection pOut, out int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out pOut); + System.Runtime.CompilerServices.Unsafe.SkipInit(out size); + nint __pOut_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __pOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pOut_native__numElements); + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__pOut_native, __size_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __pOut_native__numElements = size; + pOut = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__pOut_native, __pOut_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__pOut_native, __pOut_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(pOut)); + } + finally + { + // Cleanup - Perform required cleanup. + __pOut_native__numElements = size; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pOut_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatelessCollection global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.Return(int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement)); + global::SharedTypes.ComInterfaces.StatelessCollection __retVal = default; + nint __retVal_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, size, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal_native__numElements = size; + __retVal = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(__retVal)); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_native__numElements = size; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__retVal_native); + } + + 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, nint __p_native, int size) + { + global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement @this = default; + global::SharedTypes.ComInterfaces.StatelessCollection p = default; + int __retVal = default; + // Setup - Perform required setup. + int __p_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __p_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __p_native__numElements = size; + p = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__p_native, __p_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__p_native, __p_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(p)); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Method(p, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __pIn_native__param, int* __size_native__param) + { + global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement @this = default; + nint __pIn_native = *__pIn_native__param; + global::SharedTypes.ComInterfaces.StatelessCollection pIn = default; + int __size_native = *__size_native__param; + int size = default; + int __retVal = default; + // Setup - Perform required setup. + int __pIn_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pIn_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + size = __size_native; + __pIn_native__numElements = size; + pIn = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__pIn_native, __pIn_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__pIn_native, __pIn_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(pIn)); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodIn(in pIn, in size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __pRef_native__param, int size) + { + global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement @this = default; + nint __pRef_native__out = default; + nint __pRef_native = *__pRef_native__param; + global::SharedTypes.ComInterfaces.StatelessCollection pRef = default; + int __retVal = default; + // Setup - Perform required setup. + int __pRef_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pRef_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __pRef_native__numElements = size; + pRef = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__pRef_native, __pRef_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__pRef_native, __pRef_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(pRef)); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodRef(ref pRef, size); + // Marshal - Convert managed data to native data. + __pRef_native__out = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(pRef, out __pRef_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(pRef).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__pRef_native__out, __pRef_native__numElements)); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + __pRef_native__numElements = size; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pRef_native__out); + return __retVal; + } + + // AssignOut - Assign to parameters + *__pRef_native__param = __pRef_native__out; + // Cleanup - Perform required cleanup. + __pRef_native__numElements = size; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pRef_native); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __pOut_native__param, int* __size_native__param) + { + global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement @this = default; + nint __pOut_native__out = default; + global::SharedTypes.ComInterfaces.StatelessCollection pOut = default; + int __size_native__out = default; + int size = default; + int __retVal = default; + // Setup - Perform required setup. + int __pOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pOut_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodOut(out pOut, out size); + // Marshal - Convert managed data to native data. + __size_native__out = size; + __pOut_native__out = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(pOut, out __pOut_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(pOut).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__pOut_native__out, __pOut_native__numElements)); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__size_native__param = __size_native__out; + *__pOut_native__param = __pOut_native__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int size, nint* __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement @this = default; + nint __invokeRetValUnmanaged__out = default; + global::SharedTypes.ComInterfaces.StatelessCollection __invokeRetVal = default; + int __retVal = default; + // Setup - Perform required setup. + int __invokeRetValUnmanaged__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Return(size); + // Marshal - Convert managed data to native data. + __invokeRetValUnmanaged__out = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(__invokeRetVal).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements)); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + return __retVal; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement), sizeof(void*) * 8); + { + 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; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodIn; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodRef; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodOut; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Return; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + partial interface IStatelessCollectionBlittableElement + { + } +} + +namespace SharedTypes.ComInterfaces +{ + partial interface IStatelessCollectionBlittableElement + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.cs new file mode 100644 index 0000000..c2c1107 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.cs @@ -0,0 +1,390 @@ +// +#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.IStatelessCollectionStatelessElement +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.Method(global::SharedTypes.ComInterfaces.StatelessCollection p, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement)); + nint __p_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __p_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __p_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __p_native = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(p, out __p_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(p).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__p_native, __p_native__numElements)); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __p_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + ; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__p_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.MethodIn(in global::SharedTypes.ComInterfaces.StatelessCollection pIn, in int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement)); + nint __pIn_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __pIn_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pIn_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __pIn_native = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(pIn, out __pIn_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(pIn).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__pIn_native, __pIn_native__numElements)); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__pIn_native, __size_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + ; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pIn_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.MethodRef(ref global::SharedTypes.ComInterfaces.StatelessCollection pRef, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement)); + nint __pRef_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __pRef_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pRef_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __pRef_native = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(pRef, out __pRef_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(pRef).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__pRef_native, __pRef_native__numElements)); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__pRef_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __pRef_native__numElements = size; + pRef = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__pRef_native, __pRef_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__pRef_native, __pRef_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(pRef)); + } + finally + { + // Cleanup - Perform required cleanup. + __pRef_native__numElements = size; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pRef_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.MethodOut(out global::SharedTypes.ComInterfaces.StatelessCollection pOut, out int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out pOut); + System.Runtime.CompilerServices.Unsafe.SkipInit(out size); + nint __pOut_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __pOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pOut_native__numElements); + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__pOut_native, __size_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __pOut_native__numElements = size; + pOut = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__pOut_native, __pOut_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__pOut_native, __pOut_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(pOut)); + } + finally + { + // Cleanup - Perform required cleanup. + __pOut_native__numElements = size; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pOut_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatelessCollection global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.Return(int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement)); + global::SharedTypes.ComInterfaces.StatelessCollection __retVal = default; + nint __retVal_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, size, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal_native__numElements = size; + __retVal = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(__retVal)); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_native__numElements = size; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__retVal_native); + } + + 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, nint __p_native, int size) + { + global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement @this = default; + global::SharedTypes.ComInterfaces.StatelessCollection p = default; + int __retVal = default; + // Setup - Perform required setup. + int __p_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __p_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __p_native__numElements = size; + p = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__p_native, __p_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__p_native, __p_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(p)); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Method(p, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __pIn_native__param, int* __size_native__param) + { + global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement @this = default; + nint __pIn_native = *__pIn_native__param; + global::SharedTypes.ComInterfaces.StatelessCollection pIn = default; + int __size_native = *__size_native__param; + int size = default; + int __retVal = default; + // Setup - Perform required setup. + int __pIn_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pIn_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + size = __size_native; + __pIn_native__numElements = size; + pIn = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__pIn_native, __pIn_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__pIn_native, __pIn_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(pIn)); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodIn(in pIn, in size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __pRef_native__param, int size) + { + global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement @this = default; + nint __pRef_native__out = default; + nint __pRef_native = *__pRef_native__param; + global::SharedTypes.ComInterfaces.StatelessCollection pRef = default; + int __retVal = default; + // Setup - Perform required setup. + int __pRef_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pRef_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __pRef_native__numElements = size; + pRef = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__pRef_native, __pRef_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__pRef_native, __pRef_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(pRef)); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodRef(ref pRef, size); + // Marshal - Convert managed data to native data. + __pRef_native__out = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(pRef, out __pRef_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(pRef).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__pRef_native__out, __pRef_native__numElements)); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + __pRef_native__numElements = size; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pRef_native__out); + return __retVal; + } + + // AssignOut - Assign to parameters + *__pRef_native__param = __pRef_native__out; + // Cleanup - Perform required cleanup. + __pRef_native__numElements = size; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pRef_native); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __pOut_native__param, int* __size_native__param) + { + global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement @this = default; + nint __pOut_native__out = default; + global::SharedTypes.ComInterfaces.StatelessCollection pOut = default; + int __size_native__out = default; + int size = default; + int __retVal = default; + // Setup - Perform required setup. + int __pOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pOut_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodOut(out pOut, out size); + // Marshal - Convert managed data to native data. + __size_native__out = size; + __pOut_native__out = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(pOut, out __pOut_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(pOut).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__pOut_native__out, __pOut_native__numElements)); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__size_native__param = __size_native__out; + *__pOut_native__param = __pOut_native__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int size, nint* __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement @this = default; + nint __invokeRetValUnmanaged__out = default; + global::SharedTypes.ComInterfaces.StatelessCollection __invokeRetVal = default; + int __retVal = default; + // Setup - Perform required setup. + int __invokeRetValUnmanaged__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Return(size); + // Marshal - Convert managed data to native data. + __invokeRetValUnmanaged__out = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(__invokeRetVal).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements)); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + return __retVal; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement), sizeof(void*) * 8); + { + 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; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodIn; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodRef; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodOut; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Return; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + partial interface IStatelessCollectionStatelessElement + { + } +} + +namespace SharedTypes.ComInterfaces +{ + partial interface IStatelessCollectionStatelessElement + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessMarshalling.cs new file mode 100644 index 0000000..82d76b5 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessMarshalling.cs @@ -0,0 +1,373 @@ +// +#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[] { 93, 250, 50, 71, 5, 193, 35, 74, 135, 167, 88, 220, 237, 212, 169, 179 })); + + 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.IStatelessMarshalling +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessMarshalling.Method(global::SharedTypes.ComInterfaces.StatelessType param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessMarshalling)); + nint __param_native = default; + int __invokeRetVal = default; + try + { + // Marshal - Convert managed data to native data. + __param_native = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(param); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessMarshalling.MethodIn(in global::SharedTypes.ComInterfaces.StatelessType param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessMarshalling)); + nint __param_native = default; + int __invokeRetVal = default; + try + { + // Marshal - Convert managed data to native data. + __param_native = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(param); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessMarshalling.MethodOut(out global::SharedTypes.ComInterfaces.StatelessType param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessMarshalling)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out param); + nint __param_native = default; + int __invokeRetVal = default; + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + param = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessMarshalling.MethodRef(ref global::SharedTypes.ComInterfaces.StatelessType param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessMarshalling)); + nint __param_native = default; + int __invokeRetVal = default; + try + { + // Marshal - Convert managed data to native data. + __param_native = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(param); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + param = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatelessType global::SharedTypes.ComInterfaces.IStatelessMarshalling.Return() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessMarshalling)); + global::SharedTypes.ComInterfaces.StatelessType __retVal = default; + nint __retVal_native = default; + int __invokeRetVal = default; + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__retVal_native); + } + + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatelessType global::SharedTypes.ComInterfaces.IStatelessMarshalling.ReturnPreserveSig() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessMarshalling)); + global::SharedTypes.ComInterfaces.StatelessType __retVal = default; + nint __retVal_native = default; + try + { + { + __retVal_native = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + __retVal = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__retVal_native); + } + + 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, nint __param_native, int size) + { + global::SharedTypes.ComInterfaces.IStatelessMarshalling @this = default; + global::SharedTypes.ComInterfaces.StatelessType param = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + param = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Method(param, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param, int size) + { + global::SharedTypes.ComInterfaces.IStatelessMarshalling @this = default; + nint __param_native = *__param_native__param; + global::SharedTypes.ComInterfaces.StatelessType param = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + param = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodIn(in param, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param, int size) + { + global::SharedTypes.ComInterfaces.IStatelessMarshalling @this = default; + nint __param_native__out = default; + global::SharedTypes.ComInterfaces.StatelessType param = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodOut(out param, size); + // Marshal - Convert managed data to native data. + __param_native__out = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(param); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param, int size) + { + global::SharedTypes.ComInterfaces.IStatelessMarshalling @this = default; + nint __param_native__out = default; + nint __param_native = *__param_native__param; + global::SharedTypes.ComInterfaces.StatelessType param = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + param = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodRef(ref param, size); + // Marshal - Convert managed data to native data. + __param_native__out = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(param); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__out); + return __retVal; + } + + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IStatelessMarshalling @this = default; + nint __invokeRetValUnmanaged__out = default; + global::SharedTypes.ComInterfaces.StatelessType __invokeRetVal = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Return(); + // Marshal - Convert managed data to native data. + __invokeRetValUnmanaged__out = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.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; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static nint ABI_ReturnPreserveSig(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native) + { + global::SharedTypes.ComInterfaces.IStatelessMarshalling @this = default; + global::SharedTypes.ComInterfaces.StatelessType __retVal = default; + nint __retVal_native = default; + try + { + // Unmarshal - Convert native data to managed data. + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __retVal = @this.ReturnPreserveSig(); + // Marshal - Convert managed data to native data. + __retVal_native = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__retVal); + } + catch (System.Exception __exception) + { + __retVal_native = System.Runtime.InteropServices.Marshalling.ExceptionAsDefaultMarshaller.ConvertToUnmanaged(__exception); + return __retVal_native; + } + + return __retVal_native; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IStatelessMarshalling), sizeof(void*) * 9); + { + 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; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodIn; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodOut; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodRef; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Return; + vtable[8] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_ReturnPreserveSig; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IStatelessMarshalling + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IStatelessMarshalling + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs index 91a773f..af8dda8 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs @@ -449,7 +449,7 @@ internal static int ABI_RefParam(System.Runtime.InteropServices.ComWrappers.ComI catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); - // Cleanup - Perform required cleanup. + // CleanupFailure - Perform required cleanup. _ = __value_native__lastIndexMarshalled; __value_native__numElements = 10; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__value_native__out); @@ -544,8 +544,6 @@ internal static int ABI_ByValueOutParam(System.Runtime.InteropServices.ComWrappe // AssignOut - Assign to parameters __value_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__value_native, __value_native__numElements).GetPinnableReference()), __value_native__numElements)); - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__value_native); return __retVal; } @@ -599,8 +597,6 @@ internal static int ABI_ByValueInOutParam(System.Runtime.InteropServices.ComWrap // AssignOut - Assign to parameters __value_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__value_native, __value_native__numElements).GetPinnableReference()), __value_native__numElements)); - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__value_native); return __retVal; } diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeToManagedStubs.g.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeToManagedStubs.g.cs index d146508..add8a5f 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeToManagedStubs.g.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeToManagedStubs.g.cs @@ -400,8 +400,8 @@ internal unsafe partial interface Native [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] internal static void ABI_MultiplyWithData(void* __this_native, int* __values123_native, int numValues) { - global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject @this = default; - global::SharedTypes.IntWrapper[] values123 = default; + global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject @this; + global::SharedTypes.IntWrapper[] values123; // Setup - Perform required setup. int __values123_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __values123_native__numElements); @@ -438,8 +438,6 @@ internal static void ABI_MultiplyWithData(void* __this_native, int* __values123_ // AssignOut - Assign to parameters __values123_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values123_native, __values123_native__numElements).GetPinnableReference()), __values123_native__numElements)); - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values123_native); } } } @@ -535,21 +533,20 @@ internal static void ABI_SumAndSetData(void* __this_native, int** __values_nativ values = __values_native__marshaller.ToManaged(); @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObjectStateful)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); @this.SumAndSetData(ref values, numValues, out oldValue); - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __values_native__out = __values_native__marshaller.ToUnmanaged(); // Marshal - Convert managed data to native data. __oldValue_native__out = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(oldValue); __values_native__marshaller.FromManaged(values); { System.ReadOnlySpan __values_native__managedSpan = __values_native__marshaller.GetManagedValuesSource(); System.Span __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesDestination(); - __values_native__out = (int*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref __values_native__nativeSpan.GetPinnableReference()); for (int __i0 = 0; __i0 < __values_native__managedSpan.Length; ++__i0, ++__values_native__lastIndexMarshalled) { __values_native__nativeSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(__values_native__managedSpan[__i0]); } } + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __values_native__out = __values_native__marshaller.ToUnmanaged(); // AssignOut - Assign to parameters *__oldValue_native__param = __oldValue_native__out; *__values_native__param = __values_native__out; @@ -624,14 +621,6 @@ internal static void ABI_MultiplyWithData(void* __this_native, int* __values123_ // AssignOut - Assign to parameters __values123_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __values123_native__marshaller.GetUnmanagedValuesSource(__values123_native__numElements).GetPinnableReference()), __values123_native__numElements)); // Cleanup - Perform required cleanup. - { - System.ReadOnlySpan __values123_native__nativeSpan = __values123_native__marshaller.GetUnmanagedValuesSource(__values123_native__numElements); - for (int __i0 = 0; __i0 < __values123_native__nativeSpan.Length; ++__i0) - { - global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values123_native__nativeSpan[__i0]); - } - } - __values123_native__marshaller.Free(); } } From f8e22c20ad10ba535f342838493566c468cbfc62 Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Tue, 25 Jul 2023 16:32:27 -0700 Subject: [PATCH 6/8] Add PreserveSig method --- ...es.IStatelessCollectionBlittableElement.cs | 62 ++++++++++++++++++- ...es.IStatelessCollectionStatelessElement.cs | 62 ++++++++++++++++++- 2 files changed, 122 insertions(+), 2 deletions(-) diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.cs index 05f385b..40ff664 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.cs @@ -177,6 +177,38 @@ return __retVal; } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatelessCollection global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.ReturnPreserveSig(int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement)); + global::SharedTypes.ComInterfaces.StatelessCollection __retVal = default; + nint __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + { + __retVal_native = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = size; + __retVal = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(__retVal)); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_native__numElements = size; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__retVal_native); + } + + return __retVal; + } } file unsafe partial interface InterfaceImplementation @@ -347,13 +379,40 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; return __retVal; } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static nint ABI_ReturnPreserveSig(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int size) + { + global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement @this = default; + global::SharedTypes.ComInterfaces.StatelessCollection __retVal = default; + nint __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __retVal = @this.ReturnPreserveSig(size); + // Marshal - Convert managed data to native data. + __retVal_native = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(__retVal, out __retVal_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(__retVal).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__retVal_native, __retVal_native__numElements)); + } + catch (System.Exception __exception) + { + __retVal_native = System.Runtime.InteropServices.Marshalling.ExceptionAsDefaultMarshaller.ConvertToUnmanaged(__exception); + return __retVal_native; + } + + return __retVal_native; + } } file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() { - void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement), sizeof(void*) * 8); + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement), sizeof(void*) * 9); { nint v0, v1, v2; System.Runtime.InteropServices.ComWrappers.GetIUnknownImpl(out v0, out v1, out v2); @@ -368,6 +427,7 @@ file unsafe partial interface InterfaceImplementation vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodRef; vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodOut; vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Return; + vtable[8] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_ReturnPreserveSig; } return vtable; diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.cs index c2c1107..4422b00 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.cs @@ -177,6 +177,38 @@ return __retVal; } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatelessCollection global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.ReturnPreserveSig(int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement)); + global::SharedTypes.ComInterfaces.StatelessCollection __retVal = default; + nint __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + { + __retVal_native = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = size; + __retVal = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(__retVal)); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_native__numElements = size; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__retVal_native); + } + + return __retVal; + } } file unsafe partial interface InterfaceImplementation @@ -347,13 +379,40 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; return __retVal; } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static nint ABI_ReturnPreserveSig(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int size) + { + global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement @this = default; + global::SharedTypes.ComInterfaces.StatelessCollection __retVal = default; + nint __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __retVal = @this.ReturnPreserveSig(size); + // Marshal - Convert managed data to native data. + __retVal_native = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(__retVal, out __retVal_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(__retVal).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__retVal_native, __retVal_native__numElements)); + } + catch (System.Exception __exception) + { + __retVal_native = System.Runtime.InteropServices.Marshalling.ExceptionAsDefaultMarshaller.ConvertToUnmanaged(__exception); + return __retVal_native; + } + + return __retVal_native; + } } file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() { - void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement), sizeof(void*) * 8); + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement), sizeof(void*) * 9); { nint v0, v1, v2; System.Runtime.InteropServices.ComWrappers.GetIUnknownImpl(out v0, out v1, out v2); @@ -368,6 +427,7 @@ file unsafe partial interface InterfaceImplementation vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodRef; vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodOut; vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Return; + vtable[8] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_ReturnPreserveSig; } return vtable; From b623277df62fedb57ad04e9ffc678e94b804506f Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Wed, 26 Jul 2023 11:24:31 -0700 Subject: [PATCH 7/8] Add more test types --- ...terfaceGenerator.Tests.DerivedComObject.cs | 31 + ...nerator.Tests.IDerivedTests.DerivedImpl.cs | 40 + ...nerator.Tests.ManagedObjectExposedToCom.cs | 31 + ...hallingTests.CustomUtf16MarshalledClass.cs | 34 + ...ngMarshallingTests.Utf16MarshalledClass.cs | 34 + ...ingMarshallingTests.Utf8MarshalledClass.cs | 34 + ....ComInterfaces.ArrayOfStatelessElements.cs | 31 + .../SharedTypes.ComInterfaces.Derived.cs | 37 + .../SharedTypes.ComInterfaces.GetAndSetInt.cs | 31 + .../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 + ...gFails.IStringArrayMarshallingFailsImpl.cs | 31 + ...ypes.ComInterfaces.StatelessMarshalling.cs | 31 + ...ComInterfaces.IArrayOfStatelessElements.cs | 733 ++ .../SharedTypes.ComInterfaces.IBool.cs | 140 + ...nterfaces.ICustomStringMarshallingUtf16.cs | 139 + .../SharedTypes.ComInterfaces.IDerived.cs | 176 + .../SharedTypes.ComInterfaces.IEmpty.cs | 53 + .../SharedTypes.ComInterfaces.IEnumUnknown.cs | 265 + .../SharedTypes.ComInterfaces.IFloat.cs | 133 + ...SharedTypes.ComInterfaces.IGetAndSetInt.cs | 133 + .../SharedTypes.ComInterfaces.IGetIntArray.cs | 109 + .../SharedTypes.ComInterfaces.IInt.cs | 268 + .../SharedTypes.ComInterfaces.IIntArray.cs | 421 + .../SharedTypes.ComInterfaces.IInterface.cs | 306 + ...aredTypes.ComInterfaces.IJaggedIntArray.cs | 379 + ...haredTypes.ComInterfaces.IPointProvider.cs | 123 + .../SharedTypes.ComInterfaces.IRefStrings.cs | 213 + ...aredTypes.ComInterfaces.ISafeFileHandle.cs | 158 + ...ces.IStatefulCollectionBlittableElement.cs | 475 + ...ces.IStatefulCollectionStatelessElement.cs | 658 ++ ...ypes.ComInterfaces.IStatefulMarshalling.cs | 432 + ...es.IStatelessCollectionBlittableElement.cs | 435 + ...es.IStatelessCollectionStatelessElement.cs | 603 ++ ...pes.ComInterfaces.IStatelessMarshalling.cs | 356 + ...omInterfaces.IStringMarshallingOverride.cs | 218 + ...faces.IStringMarshallingOverrideDerived.cs | 304 + ...edTypes.ComInterfaces.IUTF16Marshalling.cs | 139 + ...redTypes.ComInterfaces.IUTF8Marshalling.cs | 152 + ...allingFails.ICollectionMarshallingFails.cs | 227 + ...ngFails.IJaggedIntArrayMarshallingFails.cs | 445 + ...llingFails.IStringArrayMarshallingFails.cs | 669 ++ .../ManagedToNativeStubs.g.cs | 575 ++ .../NativeInterfaces.g.cs | 65 + .../NativeToManagedStubs.g.cs | 630 ++ .../PopulateVTable.g.cs | 70 + .../LibraryImports.g.cs | 460 + .../LibraryImports.g.cs | 8225 +++++++++++++++++ 54 files changed, 19500 insertions(+) create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.DerivedComObject.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.IDerivedTests.DerivedImpl.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.ManagedObjectExposedToCom.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.StringMarshallingTests.CustomUtf16MarshalledClass.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.StringMarshallingTests.Utf16MarshalledClass.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.StringMarshallingTests.Utf8MarshalledClass.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.ArrayOfStatelessElements.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.Derived.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.GetAndSetInt.cs 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.ComClassGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFailsImpl.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessMarshalling.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IArrayOfStatelessElements.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.ICustomStringMarshallingUtf16.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IDerived.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IEmpty.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IEnumUnknown.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.IGetAndSetInt.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetIntArray.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.IPointProvider.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.ISafeFileHandle.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulMarshalling.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessMarshalling.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverride.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF16Marshalling.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF8Marshalling.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 create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/ManagedToNativeStubs.g.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeInterfaces.g.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeToManagedStubs.g.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/PopulateVTable.g.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs create mode 100644 LibraryImportGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.DerivedComObject.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.DerivedComObject.cs new file mode 100644 index 0000000..2feaa1e --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.DerivedComObject.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.IGetAndSetInt).TypeHandle); + vtables[0] = new() + { + IID = details.Iid, + Vtable = (nint)details.ManagedVirtualMethodTable + }; + s_vtables = vtables; + } + + return s_vtables; + } +} + +namespace ComInterfaceGenerator.Tests +{ + [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute] + partial class DerivedComObject + { + } +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.IDerivedTests.DerivedImpl.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.IDerivedTests.DerivedImpl.cs new file mode 100644 index 0000000..ac0a651 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.IDerivedTests.DerivedImpl.cs @@ -0,0 +1,40 @@ +// +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 = 2; + 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) * 2); + System.Runtime.InteropServices.Marshalling.IIUnknownDerivedDetails details; + details = System.Runtime.InteropServices.Marshalling.StrategyBasedComWrappers.DefaultIUnknownInterfaceDetailsStrategy.GetIUnknownDerivedDetails(typeof(SharedTypes.ComInterfaces.IDerived).TypeHandle); + vtables[0] = new() + { + IID = details.Iid, + Vtable = (nint)details.ManagedVirtualMethodTable + }; + details = System.Runtime.InteropServices.Marshalling.StrategyBasedComWrappers.DefaultIUnknownInterfaceDetailsStrategy.GetIUnknownDerivedDetails(typeof(SharedTypes.ComInterfaces.IGetAndSetInt).TypeHandle); + vtables[1] = new() + { + IID = details.Iid, + Vtable = (nint)details.ManagedVirtualMethodTable + }; + s_vtables = vtables; + } + + return s_vtables; + } +} + +namespace ComInterfaceGenerator.Tests +{ + public unsafe partial class IDerivedTests + { + [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute] + partial class DerivedImpl + { + } + } +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.ManagedObjectExposedToCom.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.ManagedObjectExposedToCom.cs new file mode 100644 index 0000000..8474903 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.ManagedObjectExposedToCom.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.IGetAndSetInt).TypeHandle); + vtables[0] = new() + { + IID = details.Iid, + Vtable = (nint)details.ManagedVirtualMethodTable + }; + s_vtables = vtables; + } + + return s_vtables; + } +} + +namespace ComInterfaceGenerator.Tests +{ + [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute] + partial class ManagedObjectExposedToCom + { + } +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.StringMarshallingTests.CustomUtf16MarshalledClass.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.StringMarshallingTests.CustomUtf16MarshalledClass.cs new file mode 100644 index 0000000..a51860f --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.StringMarshallingTests.CustomUtf16MarshalledClass.cs @@ -0,0 +1,34 @@ +// +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.ICustomStringMarshallingUtf16).TypeHandle); + vtables[0] = new() + { + IID = details.Iid, + Vtable = (nint)details.ManagedVirtualMethodTable + }; + s_vtables = vtables; + } + + return s_vtables; + } +} + +namespace ComInterfaceGenerator.Tests +{ + public unsafe partial class StringMarshallingTests + { + [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute] + internal partial class CustomUtf16MarshalledClass + { + } + } +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.StringMarshallingTests.Utf16MarshalledClass.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.StringMarshallingTests.Utf16MarshalledClass.cs new file mode 100644 index 0000000..5da6a72 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.StringMarshallingTests.Utf16MarshalledClass.cs @@ -0,0 +1,34 @@ +// +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.IUTF16Marshalling).TypeHandle); + vtables[0] = new() + { + IID = details.Iid, + Vtable = (nint)details.ManagedVirtualMethodTable + }; + s_vtables = vtables; + } + + return s_vtables; + } +} + +namespace ComInterfaceGenerator.Tests +{ + public unsafe partial class StringMarshallingTests + { + [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute] + internal partial class Utf16MarshalledClass + { + } + } +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.StringMarshallingTests.Utf8MarshalledClass.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.StringMarshallingTests.Utf8MarshalledClass.cs new file mode 100644 index 0000000..40e28d3 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.StringMarshallingTests.Utf8MarshalledClass.cs @@ -0,0 +1,34 @@ +// +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.IUTF8Marshalling).TypeHandle); + vtables[0] = new() + { + IID = details.Iid, + Vtable = (nint)details.ManagedVirtualMethodTable + }; + s_vtables = vtables; + } + + return s_vtables; + } +} + +namespace ComInterfaceGenerator.Tests +{ + public unsafe partial class StringMarshallingTests + { + [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute] + internal partial class Utf8MarshalledClass + { + } + } +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.ArrayOfStatelessElements.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.ArrayOfStatelessElements.cs new file mode 100644 index 0000000..b5c006b --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.ArrayOfStatelessElements.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.IArrayOfStatelessElements).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 ArrayOfStatelessElements + { + } +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.Derived.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.Derived.cs new file mode 100644 index 0000000..aaeb8ca --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.Derived.cs @@ -0,0 +1,37 @@ +// +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 = 2; + 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) * 2); + System.Runtime.InteropServices.Marshalling.IIUnknownDerivedDetails details; + details = System.Runtime.InteropServices.Marshalling.StrategyBasedComWrappers.DefaultIUnknownInterfaceDetailsStrategy.GetIUnknownDerivedDetails(typeof(SharedTypes.ComInterfaces.IDerived).TypeHandle); + vtables[0] = new() + { + IID = details.Iid, + Vtable = (nint)details.ManagedVirtualMethodTable + }; + details = System.Runtime.InteropServices.Marshalling.StrategyBasedComWrappers.DefaultIUnknownInterfaceDetailsStrategy.GetIUnknownDerivedDetails(typeof(SharedTypes.ComInterfaces.IGetAndSetInt).TypeHandle); + vtables[1] = 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 Derived + { + } +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.GetAndSetInt.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.GetAndSetInt.cs new file mode 100644 index 0000000..0395ffb --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.GetAndSetInt.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.IGetAndSetInt).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 GetAndSetInt + { + } +} 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.ComClassGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFailsImpl.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFailsImpl.cs new file mode 100644 index 0000000..9377f67 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFailsImpl.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.IStringArrayMarshallingFails).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 IStringArrayMarshallingFailsImpl + { + } +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessMarshalling.cs new file mode 100644 index 0000000..ccfd5a6 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessMarshalling.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.IStatelessMarshalling).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 StatelessMarshalling + { + } +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IArrayOfStatelessElements.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IArrayOfStatelessElements.cs new file mode 100644 index 0000000..c8eb16f --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IArrayOfStatelessElements.cs @@ -0,0 +1,733 @@ +// +#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[] { 191, 60, 150, 244, 175, 16, 11, 70, 132, 149, 16, 119, 130, 24, 119, 5 })); + + 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.IArrayOfStatelessElements +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IArrayOfStatelessElements.Method(global::SharedTypes.ComInterfaces.StatelessType[] param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatelessElements)); + nint* __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __param_native__marshaller = new(); + int __param_native__numElements; + int __param_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __param_native__managedSpan = __param_native__marshaller.GetManagedValuesSource(); + System.Span __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__managedSpan.Length; ++__i0, ++__param_native__lastIndexMarshalled) + { + __param_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__param_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __param_native__unused = __param_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan[__i0]); + } + } + + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IArrayOfStatelessElements.MethodIn(in global::SharedTypes.ComInterfaces.StatelessType[] param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatelessElements)); + nint* __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __param_native__marshaller = new(); + int __param_native__numElements; + int __param_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __param_native__managedSpan = __param_native__marshaller.GetManagedValuesSource(); + System.Span __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__managedSpan.Length; ++__i0, ++__param_native__lastIndexMarshalled) + { + __param_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__param_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __param_native__unused = __param_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan[__i0]); + } + } + + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IArrayOfStatelessElements.MethodOut(out global::SharedTypes.ComInterfaces.StatelessType[] param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatelessElements)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out param); + nint* __param_native; + int __invokeRetVal; + // Setup - Perform required setup. + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __param_native__numElements = size; + param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + __param_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native__nativeSpan[__i0]); + } + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IArrayOfStatelessElements.MethodRef(ref global::SharedTypes.ComInterfaces.StatelessType[] param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatelessElements)); + nint* __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + int __param_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __param_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(param, out __param_native__numElements); + { + System.ReadOnlySpan __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(param); + System.Span __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__param_native, __param_native__numElements); + for (int __i0 = 0; __i0 < __param_native__managedSpan.Length; ++__i0, ++__param_native__lastIndexMarshalled) + { + __param_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__param_native__managedSpan[__i0]); + } + } + + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __param_native__numElements = size; + param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + __param_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__param_native, __param_native__numElements); + for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan[__i0]); + } + } + + __param_native__numElements = size; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__param_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IArrayOfStatelessElements.MethodContentsIn(global::SharedTypes.ComInterfaces.StatelessType[] param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatelessElements)); + nint* __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __param_native__marshaller = new(); + int __param_native__numElements; + int __param_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __param_native__managedSpan = __param_native__marshaller.GetManagedValuesSource(); + System.Span __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__managedSpan.Length; ++__i0, ++__param_native__lastIndexMarshalled) + { + __param_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__param_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __param_native__unused = __param_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, __param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan[__i0]); + } + } + + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IArrayOfStatelessElements.MethodContentsOut(global::SharedTypes.ComInterfaces.StatelessType[] param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatelessElements)); + nint* __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __param_native__marshaller = new(); + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + __param_native__marshaller.GetUnmanagedValuesDestination().Clear(); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __param_native__unused = __param_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this, __param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + { + __param_native__numElements = __param_native__marshaller.GetManagedValuesSource().Length; + System.Span __param_native__managedSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __param_native__marshaller.GetManagedValuesSource().GetPinnableReference()), __param_native__numElements); + System.Span __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + __param_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IArrayOfStatelessElements.MethodContentsInOut(global::SharedTypes.ComInterfaces.StatelessType[] param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatelessElements)); + nint* __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __param_native__marshaller = new(); + int __param_native__numElements; + int __param_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __param_native__managedSpan = __param_native__marshaller.GetManagedValuesSource(); + System.Span __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__managedSpan.Length; ++__i0, ++__param_native__lastIndexMarshalled) + { + __param_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__param_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __param_native__unused = __param_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[9])(__this, __param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + { + __param_native__numElements = __param_native__marshaller.GetManagedValuesSource().Length; + System.Span __param_native__managedSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __param_native__marshaller.GetManagedValuesSource().GetPinnableReference()), __param_native__numElements); + System.Span __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + __param_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan[__i0]); + } + } + + __param_native__marshaller.Free(); + } + } +} + +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, nint* __param_native, int size) + { + global::SharedTypes.ComInterfaces.IArrayOfStatelessElements @this = default; + global::SharedTypes.ComInterfaces.StatelessType[] param = default; + int __retVal = default; + // Setup - Perform required setup. + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __param_native__numElements = size; + param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + __param_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native__nativeSpan[__i0]); + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Method(param, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint** __param_native__param, int size) + { + global::SharedTypes.ComInterfaces.IArrayOfStatelessElements @this = default; + nint* __param_native = *__param_native__param; + global::SharedTypes.ComInterfaces.StatelessType[] param = default; + int __retVal = default; + // Setup - Perform required setup. + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __param_native__numElements = size; + param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + __param_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native__nativeSpan[__i0]); + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodIn(in param, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint** __param_native__param, int size) + { + global::SharedTypes.ComInterfaces.IArrayOfStatelessElements @this = default; + nint* __param_native__out = default; + global::SharedTypes.ComInterfaces.StatelessType[] param = default; + int __retVal = default; + // Setup - Perform required setup. + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodOut(out param, size); + // Marshal - Convert managed data to native data. + __param_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(param, out __param_native__numElements); + { + System.ReadOnlySpan __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(param); + System.Span __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__param_native__out, __param_native__numElements); + __param_native__nativeSpan.Clear(); + for (int __i0 = 0; __i0 < __param_native__managedSpan.Length; ++__i0) + { + __param_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__param_native__managedSpan[__i0]); + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native__out, __param_native__numElements); + for (int __i0 = 0; __i0 < __param_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan[__i0]); + } + }; + return __retVal; + } + + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint** __param_native__param, int size) + { + global::SharedTypes.ComInterfaces.IArrayOfStatelessElements @this = default; + nint* __param_native__out = default; + nint* __param_native = *__param_native__param; + global::SharedTypes.ComInterfaces.StatelessType[] param = default; + int __retVal = default; + // Setup - Perform required setup. + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + int __param_native__lastIndexMarshalled = 0; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __param_native__numElements = size; + param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + __param_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native__nativeSpan[__i0]); + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodRef(ref param, size); + // Marshal - Convert managed data to native data. + __param_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(param, out __param_native__numElements); + { + System.ReadOnlySpan __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(param); + System.Span __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__param_native__out, __param_native__numElements); + for (int __i0 = 0; __i0 < __param_native__managedSpan.Length; ++__i0, ++__param_native__lastIndexMarshalled) + { + __param_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__param_native__managedSpan[__i0]); + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native__out, __param_native__numElements); + for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan[__i0]); + } + } + + __param_native__numElements = size; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__param_native__out); + return __retVal; + } + + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan[__i0]); + } + } + + __param_native__numElements = size; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__param_native); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodContentsIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native, int size) + { + global::SharedTypes.ComInterfaces.IArrayOfStatelessElements @this = default; + global::SharedTypes.ComInterfaces.StatelessType[] param = default; + int __retVal = default; + // Setup - Perform required setup. + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __param_native__numElements = size; + param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + __param_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native__nativeSpan[__i0]); + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodContentsIn(param, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodContentsOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native, int size) + { + global::SharedTypes.ComInterfaces.IArrayOfStatelessElements @this = default; + global::SharedTypes.ComInterfaces.StatelessType[] param = default; + int __retVal = default; + // Setup - Perform required setup. + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + System.Span __param_native__out; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param).Clear(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodContentsOut(param, size); + // Marshal - Convert managed data to native data. + { + __param_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param).Length; +#pragma warning disable CS9081 + __param_native__out = stackalloc nint[__param_native__numElements]; +#pragma warning restore CS9081 + System.Span __param_native__nativeSpan = __param_native__out; + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + nint __param_native__nativeSpan____i0__original = __param_native__nativeSpan[__i0]; + __param_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__param_native__managedSpan[__i0]); + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + __param_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements).GetPinnableReference()), __param_native__numElements)); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodContentsInOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native, int size) + { + global::SharedTypes.ComInterfaces.IArrayOfStatelessElements @this = default; + global::SharedTypes.ComInterfaces.StatelessType[] param = default; + int __retVal = default; + // Setup - Perform required setup. + int __param_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + System.Span __param_native__out; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __param_native__numElements = size; + param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + __param_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native__nativeSpan[__i0]); + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodContentsInOut(param, size); + // Marshal - Convert managed data to native data. + { + __param_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param).Length; +#pragma warning disable CS9081 + __param_native__out = stackalloc nint[__param_native__numElements]; +#pragma warning restore CS9081 + System.Span __param_native__nativeSpan = __param_native__out; + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + nint __param_native__nativeSpan____i0__original = __param_native__nativeSpan[__i0]; + __param_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__param_native__managedSpan[__i0]); + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan____i0__original); + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + __param_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements).GetPinnableReference()), __param_native__numElements)); + return __retVal; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatelessElements), sizeof(void*) * 10); + { + 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; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodIn; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodOut; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodRef; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodContentsIn; + vtable[8] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodContentsOut; + vtable[9] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodContentsInOut; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IArrayOfStatelessElements + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IArrayOfStatelessElements + { + } +} \ No newline at end of file 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..9cdd50d --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IBool.cs @@ -0,0 +1,140 @@ +// +#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; + bool __invokeRetVal = default; + int __retVal = default; + 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.ICustomStringMarshallingUtf16.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.ICustomStringMarshallingUtf16.cs new file mode 100644 index 0000000..5468fb7 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.ICustomStringMarshallingUtf16.cs @@ -0,0 +1,139 @@ +// +#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[] { 62, 95, 29, 225, 87, 221, 166, 65, 165, 158, 125, 17, 5, 81, 167, 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.ICustomStringMarshallingUtf16 +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + string global::SharedTypes.ComInterfaces.ICustomStringMarshallingUtf16.GetString() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.ICustomStringMarshallingUtf16)); + string __retVal; + ushort* __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 = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.ICustomStringMarshallingUtf16.SetString(string value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.ICustomStringMarshallingUtf16)); + int __invokeRetVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __value_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(value)) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, (ushort*)__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_GetString(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, ushort** __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.ICustomStringMarshallingUtf16 @this = default; + ushort* __invokeRetValUnmanaged__out = default; + string __invokeRetVal = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.GetString(); + // Marshal - Convert managed data to native data. + __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; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_SetString(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, ushort* __value_native) + { + global::SharedTypes.ComInterfaces.ICustomStringMarshallingUtf16 @this = default; + string value = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + value = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__value_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.SetString(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.ICustomStringMarshallingUtf16), 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_GetString; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_SetString; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface ICustomStringMarshallingUtf16 + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface ICustomStringMarshallingUtf16 + { + } +} \ No newline at end of file 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 new file mode 100644 index 0000000..31f6a4c --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IDerived.cs @@ -0,0 +1,176 @@ +// +#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[] { 100, 179, 13, 127, 4, 60, 135, 68, 145, 147, 75, 176, 93, 199, 182, 84 })); + + 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.IDerived +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IDerived.SetName(string name) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IDerived)); + int __invokeRetVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __name_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(name)) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, (ushort*)__name_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + string global::SharedTypes.ComInterfaces.IDerived.GetName() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IDerived)); + string __retVal; + ushort* __retVal_native; + int __invokeRetVal; + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + int global::SharedTypes.ComInterfaces.IDerived.GetInt() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IDerived)); + int __retVal; + int __invokeRetVal; + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, &__retVal); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IDerived.SetInt(int x) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IDerived)); + int __invokeRetVal; + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, x); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + + int global::SharedTypes.ComInterfaces.IGetAndSetInt.GetInt() => throw new System.Diagnostics.UnreachableException(); + void global::SharedTypes.ComInterfaces.IGetAndSetInt.SetInt(int x) => throw new System.Diagnostics.UnreachableException(); +} + +file unsafe partial interface InterfaceImplementation +{ + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_SetName(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, ushort* __name_native) + { + global::SharedTypes.ComInterfaces.IDerived @this = default; + string name = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + name = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__name_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.SetName(name); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_GetName(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, ushort** __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IDerived @this = default; + ushort* __invokeRetValUnmanaged__out = default; + string __invokeRetVal = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.GetName(); + // Marshal - Convert managed data to native data. + __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; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IDerived), sizeof(void*) * 7); + { + System.Runtime.InteropServices.NativeMemory.Copy(System.Runtime.InteropServices.Marshalling.StrategyBasedComWrappers.DefaultIUnknownInterfaceDetailsStrategy.GetIUnknownDerivedDetails(typeof(global::SharedTypes.ComInterfaces.IGetAndSetInt).TypeHandle).ManagedVirtualMethodTable, vtable, (nuint)(sizeof(void*) * 5)); + } + + { + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_SetName; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_GetName; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IDerived + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IDerived + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + new int GetInt() => ((global::SharedTypes.ComInterfaces.IGetAndSetInt)this).GetInt(); + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + new void SetInt(int x) => ((global::SharedTypes.ComInterfaces.IGetAndSetInt)this).SetInt(x); + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IEmpty.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IEmpty.cs new file mode 100644 index 0000000..ca13084 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IEmpty.cs @@ -0,0 +1,53 @@ +// +#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[] { 80, 159, 209, 149, 216, 242, 97, 78, 136, 75, 10, 145, 98, 234, 70, 70 })); + + 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.IEmpty +{ +} + +file unsafe partial interface InterfaceImplementation +{ +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IEmpty), sizeof(void*) * 3); + { + 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; + } + + { + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IEmpty + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IEmpty + { + } +} \ No newline at end of file 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 new file mode 100644 index 0000000..eeb9813 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IEnumUnknown.cs @@ -0,0 +1,265 @@ +// +#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[] { 0, 1, 0, 0, 0, 0, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70 })); + + 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.IEnumUnknown +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IEnumUnknown.Next(uint celt, object[] rgelt, out uint pceltFetched) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IEnumUnknown)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out pceltFetched); + System.IntPtr* __rgelt_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __rgelt_native__marshaller = new(); + int __rgelt_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __rgelt_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __rgelt_native__marshaller.FromManaged(rgelt, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + __rgelt_native__marshaller.GetUnmanagedValuesDestination().Clear(); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (uint* __pceltFetched_native = &pceltFetched) + fixed (void* __rgelt_native__unused = __rgelt_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __rgelt_native = __rgelt_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, celt, __rgelt_native, __pceltFetched_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + { + __rgelt_native__numElements = __rgelt_native__marshaller.GetManagedValuesSource().Length; + System.Span __rgelt_native__managedSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __rgelt_native__marshaller.GetManagedValuesSource().GetPinnableReference()), __rgelt_native__numElements); + System.Span __rgelt_native__nativeSpan = __rgelt_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __rgelt_native__numElements; ++__i0) + { + __rgelt_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged((void*)__rgelt_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + __rgelt_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IEnumUnknown.Skip(uint celt) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IEnumUnknown)); + int __invokeRetVal; + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, celt); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IEnumUnknown.Reset() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IEnumUnknown)); + int __invokeRetVal; + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IEnumUnknown.Clone(out global::SharedTypes.ComInterfaces.IEnumUnknown ppenum) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IEnumUnknown)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out ppenum); + void* __ppenum_native; + int __invokeRetVal; + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__ppenum_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + ppenum = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__ppenum_native); + } +} + +file unsafe partial interface InterfaceImplementation +{ + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Next(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, uint celt, System.IntPtr* __rgelt_native, uint* __pceltFetched_native__param) + { + global::SharedTypes.ComInterfaces.IEnumUnknown @this = default; + object[] rgelt = default; + uint __pceltFetched_native__out = default; + uint pceltFetched = default; + int __retVal = default; + // 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. + __retVal = 0; // S_OK + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(rgelt).Clear(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Next(celt, rgelt, out pceltFetched); + // Marshal - Convert managed data to native data. + __pceltFetched_native__out = pceltFetched; + { + __rgelt_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(rgelt).Length; +#pragma warning disable CS9081 + __rgelt_native__out = stackalloc System.IntPtr[__rgelt_native__numElements]; +#pragma warning restore CS9081 + System.Span __rgelt_native__nativeSpan = __rgelt_native__out; + System.Span __rgelt_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(rgelt); + for (int __i0 = 0; __i0 < __rgelt_native__numElements; ++__i0) + { + void* __rgelt_native__nativeSpan____i0__original = (void*)__rgelt_native__nativeSpan[__i0]; + __rgelt_native__nativeSpan[__i0] = (System.IntPtr)(void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(__rgelt_native__managedSpan[__i0]); + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__pceltFetched_native__param = __pceltFetched_native__out; + __rgelt_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__rgelt_native, __rgelt_native__numElements).GetPinnableReference()), __rgelt_native__numElements)); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Skip(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, uint celt) + { + global::SharedTypes.ComInterfaces.IEnumUnknown @this = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Skip(celt); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Reset(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native) + { + global::SharedTypes.ComInterfaces.IEnumUnknown @this = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Reset(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Clone(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, void** __ppenum_native__param) + { + global::SharedTypes.ComInterfaces.IEnumUnknown @this = default; + void* __ppenum_native__out = default; + global::SharedTypes.ComInterfaces.IEnumUnknown ppenum = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Clone(out ppenum); + // Marshal - Convert managed data to native data. + __ppenum_native__out = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(ppenum); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__ppenum_native__param = __ppenum_native__out; + return __retVal; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IEnumUnknown), sizeof(void*) * 7); + { + 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_Next; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Skip; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Reset; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Clone; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IEnumUnknown + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IEnumUnknown + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IFloat.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IFloat.cs new file mode 100644 index 0000000..12ba740 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IFloat.cs @@ -0,0 +1,133 @@ +// +#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[] { 169, 168, 164, 159, 143, 45, 168, 72, 182, 251, 180, 75, 95, 27, 159, 182 })); + + 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.IFloat +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + float global::SharedTypes.ComInterfaces.IFloat.Get() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IFloat)); + float __retVal; + int __invokeRetVal; + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, &__retVal); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IFloat.Set(float value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IFloat)); + int __invokeRetVal; + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, value); + } + + 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, float* __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IFloat @this = default; + float __invokeRetValUnmanaged__out = default; + float __invokeRetVal = default; + int __retVal = default; + 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 = __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; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Set(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, float value) + { + global::SharedTypes.ComInterfaces.IFloat @this = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @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.IFloat), 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 IFloat + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IFloat + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetAndSetInt.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetAndSetInt.cs new file mode 100644 index 0000000..2e6729f --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetAndSetInt.cs @@ -0,0 +1,133 @@ +// +#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[] { 3, 153, 63, 44, 134, 181, 177, 70, 136, 27, 173, 252, 233, 175, 71, 177 })); + + 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.IGetAndSetInt +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + int global::SharedTypes.ComInterfaces.IGetAndSetInt.GetInt() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IGetAndSetInt)); + int __retVal; + int __invokeRetVal; + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, &__retVal); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IGetAndSetInt.SetInt(int x) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IGetAndSetInt)); + int __invokeRetVal; + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, x); + } + + 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_GetInt(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int* __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IGetAndSetInt @this = default; + int __invokeRetValUnmanaged__out = default; + int __invokeRetVal = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.GetInt(); + // Marshal - Convert managed data to native data. + __invokeRetValUnmanaged__out = __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; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_SetInt(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int x) + { + global::SharedTypes.ComInterfaces.IGetAndSetInt @this = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.SetInt(x); + } + 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.IGetAndSetInt), 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_GetInt; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_SetInt; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IGetAndSetInt + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IGetAndSetInt + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetIntArray.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetIntArray.cs new file mode 100644 index 0000000..24128be --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetIntArray.cs @@ -0,0 +1,109 @@ +// +#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[] { 10, 42, 128, 125, 10, 99, 142, 76, 162, 31, 119, 28, 201, 3, 31, 185 })); + + 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.IGetIntArray +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + int[] global::SharedTypes.ComInterfaces.IGetIntArray.GetInts() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IGetIntArray)); + int[] __retVal; + int* __retVal_native; + int __invokeRetVal; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + { + __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_native__numElements = 10; + __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal)); + return __retVal; + } +} + +file unsafe partial interface InterfaceImplementation +{ + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_GetInts(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int** __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IGetIntArray @this = default; + int* __invokeRetValUnmanaged__out = default; + int[] __invokeRetVal = default; + int __retVal = default; + // Setup - Perform required setup. + int __invokeRetValUnmanaged__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.GetInts(); + // Marshal - Convert managed data to native data. + __invokeRetValUnmanaged__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__invokeRetVal).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements)); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + ; + return __retVal; + } + + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + return __retVal; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IGetIntArray), 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_GetInts; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IGetIntArray + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IGetIntArray + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInt.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInt.cs new file mode 100644 index 0000000..f723e50 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInt.cs @@ -0,0 +1,268 @@ +// +#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[] { 42, 31, 109, 238, 24, 52, 23, 67, 168, 124, 53, 72, 143, 101, 70, 171 })); + + 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.IInt +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + int global::SharedTypes.ComInterfaces.IInt.Get() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IInt)); + int __retVal; + int __invokeRetVal; + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, &__retVal); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IInt.Set(int value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IInt)); + int __invokeRetVal; + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, value); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IInt.SwapRef(ref int value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IInt)); + int __invokeRetVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __value_native = &value) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, __value_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IInt.GetOut(out int value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IInt)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out value); + int __invokeRetVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __value_native = &value) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, __value_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IInt.SetIn(in int value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IInt)); + int __invokeRetVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __value_native = &value) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__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, int* __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IInt @this = default; + int __invokeRetValUnmanaged__out = default; + int __invokeRetVal = default; + int __retVal = default; + 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 = __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; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Set(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int value) + { + global::SharedTypes.ComInterfaces.IInt @this = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @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; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_SwapRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int* __value_native__param) + { + global::SharedTypes.ComInterfaces.IInt @this = default; + int __value_native__out = default; + int __value_native = *__value_native__param; + int value = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + value = __value_native; + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.SwapRef(ref value); + // Marshal - Convert managed data to native data. + __value_native__out = value; + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_GetOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int* __value_native__param) + { + global::SharedTypes.ComInterfaces.IInt @this = default; + int __value_native__out = default; + int value = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.GetOut(out value); + // Marshal - Convert managed data to native data. + __value_native__out = value; + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_SetIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int* __value_native__param) + { + global::SharedTypes.ComInterfaces.IInt @this = default; + int __value_native = *__value_native__param; + int value = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + value = __value_native; + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.SetIn(in 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.IInt), sizeof(void*) * 8); + { + 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; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_SwapRef; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_GetOut; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_SetIn; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IInt + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IInt + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs new file mode 100644 index 0000000..79e5b82 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs @@ -0,0 +1,421 @@ +// +#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[] { 169, 168, 164, 159, 143, 61, 168, 72, 182, 251, 180, 91, 95, 27, 159, 182 })); + + 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.IIntArray +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + int[] global::SharedTypes.ComInterfaces.IIntArray.GetReturn(out int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IIntArray)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out size); + int[] __retVal; + int* __retVal_native; + int __invokeRetVal; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __size_native, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal_native__numElements = size; + __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal)); + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + int global::SharedTypes.ComInterfaces.IIntArray.GetOut(out int[] array) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IIntArray)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out array); + int* __array_native; + int __retVal; + int __invokeRetVal; + // Setup - Perform required setup. + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__array_native, &__retVal); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __array_native__numElements = __retVal; + array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array)); + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IIntArray.SetContents(int[] array, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IIntArray)); + int __invokeRetVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __array_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(array)) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, (int*)__array_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IIntArray.FillAscending(int[] array, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IIntArray)); + int __invokeRetVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __array_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(array)) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, (int*)__array_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IIntArray.PassIn(in int[] array, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IIntArray)); + int* __array_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __array_native__marshaller = new(); + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __array_native__marshaller.FromManaged(array, stackalloc int[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + __array_native__marshaller.GetManagedValuesSource().CopyTo(__array_native__marshaller.GetUnmanagedValuesDestination()); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __array_native__unused = __array_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __array_native = __array_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, &__array_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + __array_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IIntArray.SwapArray(ref int[] array, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IIntArray)); + int* __array_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __array_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(array, out __array_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(array).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__array_native, __array_native__numElements)); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this, &__array_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __array_native__numElements = size; + array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array)); + } + finally + { + // Cleanup - Perform required cleanup. + __array_native__numElements = size; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native); + } + } +} + +file unsafe partial interface InterfaceImplementation +{ + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_GetReturn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int* __size_native__param, int** __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IIntArray @this = default; + int __size_native__out = default; + int size = default; + int* __invokeRetValUnmanaged__out = default; + int[] __invokeRetVal = default; + int __retVal = default; + // Setup - Perform required setup. + int __invokeRetValUnmanaged__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.GetReturn(out size); + // Marshal - Convert managed data to native data. + __size_native__out = size; + __invokeRetValUnmanaged__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__invokeRetVal).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements)); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + ; + return __retVal; + } + + // AssignOut - Assign to parameters + *__size_native__param = __size_native__out; + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_GetOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int** __array_native__param, int* __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IIntArray @this = default; + int* __array_native__out = default; + int[] array = default; + int __invokeRetValUnmanaged__out = default; + int __invokeRetVal = default; + int __retVal = default; + // Setup - Perform required setup. + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.GetOut(out array); + // Marshal - Convert managed data to native data. + __invokeRetValUnmanaged__out = __invokeRetVal; + __array_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(array, out __array_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(array).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__array_native__out, __array_native__numElements)); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + ; + return __retVal; + } + + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + *__array_native__param = __array_native__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_SetContents(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int* __array_native, int size) + { + global::SharedTypes.ComInterfaces.IIntArray @this = default; + int[] array = default; + int __retVal = default; + // Setup - Perform required setup. + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __array_native__numElements = size; + array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array)); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.SetContents(array, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_FillAscending(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int* __array_native, int size) + { + global::SharedTypes.ComInterfaces.IIntArray @this = default; + int[] array = default; + int __retVal = default; + // Setup - Perform required setup. + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + System.Span __array_native__out; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array).Clear(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.FillAscending(array, size); + // Marshal - Convert managed data to native data. + { + __array_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(array).Length; +#pragma warning disable CS9081 + __array_native__out = stackalloc int[__array_native__numElements]; +#pragma warning restore CS9081 + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array).CopyTo(__array_native__out); + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + __array_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements).GetPinnableReference()), __array_native__numElements)); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_PassIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int** __array_native__param, int size) + { + global::SharedTypes.ComInterfaces.IIntArray @this = default; + int* __array_native = *__array_native__param; + int[] array = default; + int __retVal = default; + // Setup - Perform required setup. + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __array_native__numElements = size; + array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array)); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.PassIn(in array, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_SwapArray(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int** __array_native__param, int size) + { + global::SharedTypes.ComInterfaces.IIntArray @this = default; + int* __array_native__out = default; + int* __array_native = *__array_native__param; + int[] array = default; + int __retVal = default; + // Setup - Perform required setup. + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __array_native__numElements = size; + array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array)); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.SwapArray(ref array, size); + // Marshal - Convert managed data to native data. + __array_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(array, out __array_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(array).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__array_native__out, __array_native__numElements)); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + __array_native__numElements = size; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native__out); + return __retVal; + } + + // AssignOut - Assign to parameters + *__array_native__param = __array_native__out; + // Cleanup - Perform required cleanup. + __array_native__numElements = size; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native); + return __retVal; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IIntArray), sizeof(void*) * 9); + { + 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_GetReturn; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_GetOut; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_SetContents; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_FillAscending; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_PassIn; + vtable[8] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_SwapArray; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IIntArray + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IIntArray + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs new file mode 100644 index 0000000..48315bf --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs @@ -0,0 +1,306 @@ +// +#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[] { 152, 115, 133, 164, 251, 6, 110, 74, 129, 219, 53, 70, 27, 233, 153, 197 })); + + 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.IInterface +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.IInt global::SharedTypes.ComInterfaces.IInterface.Get() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IInterface)); + global::SharedTypes.ComInterfaces.IInt __retVal; + void* __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 = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__retVal_native); + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IInterface.SetInt(global::SharedTypes.ComInterfaces.IInt value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IInterface)); + void* __value_native = default; + int __invokeRetVal = default; + try + { + // Marshal - Convert managed data to native data. + __value_native = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(value); + { + __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); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__value_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IInterface.SwapRef(ref global::SharedTypes.ComInterfaces.IInt value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IInterface)); + void* __value_native = default; + int __invokeRetVal = default; + try + { + // Marshal - Convert managed data to native data. + __value_native = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(value); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__value_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + value = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__value_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__value_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IInterface.GetOut(out global::SharedTypes.ComInterfaces.IInt value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IInterface)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out value); + void* __value_native; + int __invokeRetVal; + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__value_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + value = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__value_native); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IInterface.InInt(in global::SharedTypes.ComInterfaces.IInt value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IInterface)); + void* __value_native = default; + int __invokeRetVal = default; + try + { + // Marshal - Convert managed data to native data. + __value_native = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(value); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, &__value_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__value_native); + } + } +} + +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, void** __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IInterface @this = default; + void* __invokeRetValUnmanaged__out = default; + global::SharedTypes.ComInterfaces.IInt __invokeRetVal = default; + int __retVal = default; + 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 = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.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; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_SetInt(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, void* __value_native) + { + global::SharedTypes.ComInterfaces.IInterface @this = default; + global::SharedTypes.ComInterfaces.IInt value = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + value = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__value_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.SetInt(value); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_SwapRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, void** __value_native__param) + { + global::SharedTypes.ComInterfaces.IInterface @this = default; + void* __value_native__out = default; + void* __value_native = *__value_native__param; + global::SharedTypes.ComInterfaces.IInt value = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + value = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__value_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.SwapRef(ref value); + // Marshal - Convert managed data to native data. + __value_native__out = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(value); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__value_native__out); + return __retVal; + } + + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__value_native); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_GetOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, void** __value_native__param) + { + global::SharedTypes.ComInterfaces.IInterface @this = default; + void* __value_native__out = default; + global::SharedTypes.ComInterfaces.IInt value = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.GetOut(out value); + // Marshal - Convert managed data to native data. + __value_native__out = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(value); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_InInt(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, void** __value_native__param) + { + global::SharedTypes.ComInterfaces.IInterface @this = default; + void* __value_native = *__value_native__param; + global::SharedTypes.ComInterfaces.IInt value = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + value = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__value_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.InInt(in 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.IInterface), sizeof(void*) * 8); + { + 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_SetInt; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_SwapRef; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_GetOut; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_InInt; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IInterface + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IInterface + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IJaggedIntArray.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IJaggedIntArray.cs new file mode 100644 index 0000000..007a504 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IJaggedIntArray.cs @@ -0,0 +1,379 @@ +// +#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[] { 169, 168, 164, 159, 143, 61, 168, 72, 182, 251, 180, 91, 95, 27, 159, 182 })); + + 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.IJaggedIntArray +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + int[][] global::SharedTypes.ComInterfaces.IJaggedIntArray.Get(out int[] widths, out int length) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IJaggedIntArray)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out widths); + System.Runtime.CompilerServices.Unsafe.SkipInit(out length); + int* __widths_native; + int[][] __retVal; + System.IntPtr* __retVal_native; + int __invokeRetVal; + // Setup - Perform required setup. + int __widths_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __length_native = &length) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, &__widths_native, __length_native, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __widths_native__numElements = length; + widths = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__widths_native, __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__widths_native, __widths_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(widths)); + __retVal_native__numElements = length; + __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + System.Span __retVal_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal); + for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + { + int __retVal_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__nativeSpan____i0__numElements); + __retVal_native__nativeSpan____i0__numElements = widths[__i0]; + __retVal_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((int*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((int*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal_native__managedSpan[__i0])); + } + } + + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + int global::SharedTypes.ComInterfaces.IJaggedIntArray.Get2(out int[][] array, out int[] widths) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IJaggedIntArray)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out array); + System.Runtime.CompilerServices.Unsafe.SkipInit(out widths); + System.IntPtr* __array_native; + int* __widths_native; + int __retVal; + int __invokeRetVal; + // Setup - Perform required setup. + int __widths_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__array_native, &__widths_native, &__retVal); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __widths_native__numElements = __retVal; + widths = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__widths_native, __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__widths_native, __widths_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(widths)); + __array_native__numElements = __retVal; + array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); + { + System.ReadOnlySpan __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements); + System.Span __array_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array); + for (int __i0 = 0; __i0 < __array_native__numElements; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan____i0__numElements = widths[__i0]; + __array_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((int*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((int*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__array_native__managedSpan[__i0])); + } + } + + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IJaggedIntArray.Set(int[][] array, int[] widths, int length) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IJaggedIntArray)); + System.IntPtr* __array_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __array_native__marshaller = new(); + int __array_native__numElements; + int __array_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __array_native__marshaller.FromManaged(array, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __array_native__managedSpan = __array_native__marshaller.GetManagedValuesSource(); + System.Span __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __array_native__managedSpan.Length; ++__i0, ++__array_native__lastIndexMarshalled) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan[__i0] = (System.IntPtr)global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__array_native__managedSpan[__i0], out __array_native__nativeSpan____i0__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__array_native__managedSpan[__i0]).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((int*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements)); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __widths_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(widths)) + fixed (void* __array_native__unused = __array_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __array_native = __array_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, __array_native, (int*)__widths_native, length); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __array_native__lastIndexMarshalled; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + ; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((int*)__array_native__nativeSpan[__i0]); + } + } + + __array_native__marshaller.Free(); + } + } +} + +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, int** __widths_native__param, int* __length_native__param, System.IntPtr** __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IJaggedIntArray @this = default; + int* __widths_native__out = default; + int[] widths = default; + int __length_native__out = default; + int length = default; + System.IntPtr* __invokeRetValUnmanaged__out = default; + int[][] __invokeRetVal = default; + int __retVal = default; + // Setup - Perform required setup. + int __widths_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); + int __invokeRetValUnmanaged__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Get(out widths, out length); + // Marshal - Convert managed data to native data. + __length_native__out = length; + __widths_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(widths, out __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(widths).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__widths_native__out, __widths_native__numElements)); + __invokeRetValUnmanaged__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); + { + System.ReadOnlySpan __invokeRetValUnmanaged__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__invokeRetVal); + System.Span __invokeRetValUnmanaged__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements); + __invokeRetValUnmanaged__nativeSpan.Clear(); + for (int __i0 = 0; __i0 < __invokeRetValUnmanaged__managedSpan.Length; ++__i0) + { + int __invokeRetValUnmanaged__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__nativeSpan____i0__numElements); + __invokeRetValUnmanaged__nativeSpan[__i0] = (System.IntPtr)global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetValUnmanaged__managedSpan[__i0], out __invokeRetValUnmanaged__nativeSpan____i0__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__invokeRetValUnmanaged__managedSpan[__i0]).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((int*)__invokeRetValUnmanaged__nativeSpan[__i0], __invokeRetValUnmanaged__nativeSpan____i0__numElements)); + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + ; + { + System.ReadOnlySpan __invokeRetValUnmanaged__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements); + for (int __i0 = 0; __i0 < __invokeRetValUnmanaged__nativeSpan.Length; ++__i0) + { + int __invokeRetValUnmanaged__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__nativeSpan____i0__numElements); + ; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((int*)__invokeRetValUnmanaged__nativeSpan[__i0]); + } + }; + return __retVal; + } + + // AssignOut - Assign to parameters + *__length_native__param = __length_native__out; + *__widths_native__param = __widths_native__out; + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Get2(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, System.IntPtr** __array_native__param, int** __widths_native__param, int* __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IJaggedIntArray @this = default; + System.IntPtr* __array_native__out = default; + int[][] array = default; + int* __widths_native__out = default; + int[] widths = default; + int __invokeRetValUnmanaged__out = default; + int __invokeRetVal = default; + int __retVal = default; + // Setup - Perform required setup. + int __widths_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Get2(out array, out widths); + // Marshal - Convert managed data to native data. + __invokeRetValUnmanaged__out = __invokeRetVal; + __widths_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(widths, out __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(widths).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__widths_native__out, __widths_native__numElements)); + __array_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(array, out __array_native__numElements); + { + System.ReadOnlySpan __array_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(array); + System.Span __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__array_native__out, __array_native__numElements); + __array_native__nativeSpan.Clear(); + for (int __i0 = 0; __i0 < __array_native__managedSpan.Length; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan[__i0] = (System.IntPtr)global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__array_native__managedSpan[__i0], out __array_native__nativeSpan____i0__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__array_native__managedSpan[__i0]).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((int*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements)); + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + ; + { + System.ReadOnlySpan __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native__out, __array_native__numElements); + for (int __i0 = 0; __i0 < __array_native__nativeSpan.Length; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + ; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((int*)__array_native__nativeSpan[__i0]); + } + }; + return __retVal; + } + + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + *__widths_native__param = __widths_native__out; + *__array_native__param = __array_native__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, System.IntPtr* __array_native, int* __widths_native, int length) + { + global::SharedTypes.ComInterfaces.IJaggedIntArray @this = default; + int[][] array = default; + int[] widths = default; + int __retVal = default; + // Setup - Perform required setup. + int __widths_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __widths_native__numElements = length; + widths = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__widths_native, __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__widths_native, __widths_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(widths)); + __array_native__numElements = length; + array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); + { + System.ReadOnlySpan __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements); + System.Span __array_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array); + for (int __i0 = 0; __i0 < __array_native__numElements; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan____i0__numElements = widths[__i0]; + __array_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((int*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((int*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__array_native__managedSpan[__i0])); + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Set(array, widths, length); + } + 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.IJaggedIntArray), sizeof(void*) * 6); + { + 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_Get2; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Set; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IJaggedIntArray + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IJaggedIntArray + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IPointProvider.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IPointProvider.cs new file mode 100644 index 0000000..5c8dd39 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IPointProvider.cs @@ -0,0 +1,123 @@ +// +#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[] { 20, 25, 70, 228, 2, 66, 159, 71, 132, 39, 98, 14, 145, 95, 132, 185 })); + + 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.IPointProvider +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::System.Drawing.Point global::SharedTypes.ComInterfaces.IPointProvider.GetPoint() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IPointProvider)); + global::System.Drawing.Point __retVal; + { + __retVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this); + } + + System.GC.KeepAlive(this); + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IPointProvider.SetPoint(global::System.Drawing.Point point) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IPointProvider)); + int __invokeRetVal; + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, point); + } + + 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 global::System.Drawing.Point ABI_GetPoint(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native) + { + global::SharedTypes.ComInterfaces.IPointProvider @this = default; + global::System.Drawing.Point __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __retVal = @this.GetPoint(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsDefaultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_SetPoint(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, global::System.Drawing.Point point) + { + global::SharedTypes.ComInterfaces.IPointProvider @this = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.SetPoint(point); + } + 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.IPointProvider), 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_GetPoint; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_SetPoint; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IPointProvider + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IPointProvider + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs new file mode 100644 index 0000000..a95a0ae --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs @@ -0,0 +1,213 @@ +// +#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[] { 219, 183, 70, 81, 136, 5, 155, 70, 184, 229, 179, 128, 144, 162, 252, 21 })); + + 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.IRefStrings +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IRefStrings.RefString(ref string value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IRefStrings)); + byte* __value_native = default; + int __invokeRetVal = default; + try + { + // Marshal - Convert managed data to native data. + __value_native = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(value); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, &__value_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + value = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__value_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__value_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IRefStrings.InString(in string value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IRefStrings)); + byte* __value_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __value_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __value_native__marshaller.FromManaged(value, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __value_native = __value_native__marshaller.ToUnmanaged(); + __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); + } + finally + { + // Cleanup - Perform required cleanup. + __value_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IRefStrings.OutString(out string value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IRefStrings)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out value); + byte* __value_native; + int __invokeRetVal; + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__value_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + value = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__value_native); + } +} + +file unsafe partial interface InterfaceImplementation +{ + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_RefString(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, byte** __value_native__param) + { + global::SharedTypes.ComInterfaces.IRefStrings @this = default; + byte* __value_native__out = default; + byte* __value_native = *__value_native__param; + string value = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + value = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__value_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.RefString(ref value); + // Marshal - Convert managed data to native data. + __value_native__out = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(value); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__value_native__out); + return __retVal; + } + + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__value_native); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_InString(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, byte** __value_native__param) + { + global::SharedTypes.ComInterfaces.IRefStrings @this = default; + byte* __value_native = *__value_native__param; + string value = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + value = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__value_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.InString(in value); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_OutString(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, byte** __value_native__param) + { + global::SharedTypes.ComInterfaces.IRefStrings @this = default; + byte* __value_native__out = default; + string value = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.OutString(out value); + // Marshal - Convert managed data to native data. + __value_native__out = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(value); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; + return __retVal; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IRefStrings), sizeof(void*) * 6); + { + 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_RefString; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_InString; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_OutString; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IRefStrings + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IRefStrings + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.ISafeFileHandle.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.ISafeFileHandle.cs new file mode 100644 index 0000000..2aad297 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.ISafeFileHandle.cs @@ -0,0 +1,158 @@ +// +#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 })); + public static void** ManagedVirtualMethodTable => null; +} + +[System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] +file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.ISafeFileHandle +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.ISafeFileHandle.Method(global::Microsoft.Win32.SafeHandles.SafeFileHandle p) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.ISafeFileHandle)); + nint __p_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller.ManagedToUnmanagedIn __p_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __p_native__marshaller.FromManaged(p); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __p_native = __p_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __p_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + __p_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.ISafeFileHandle.MethodIn(in global::Microsoft.Win32.SafeHandles.SafeFileHandle p) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.ISafeFileHandle)); + nint __p_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller.ManagedToUnmanagedIn __p_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __p_native__marshaller.FromManaged(p); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __p_native = __p_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__p_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + __p_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.ISafeFileHandle.MethodOut(out global::Microsoft.Win32.SafeHandles.SafeFileHandle p) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.ISafeFileHandle)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out p); + nint __p_native; + int __invokeRetVal; + // Setup - Perform required setup. + global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller.ManagedToUnmanagedOut __p_native__marshaller = new(); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__p_native); + } + + System.GC.KeepAlive(this); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __p_native__marshaller.FromUnmanaged(__p_native); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + p = __p_native__marshaller.ToManaged(); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.ISafeFileHandle.MethodRef(ref global::Microsoft.Win32.SafeHandles.SafeFileHandle p) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.ISafeFileHandle)); + bool __invokeSucceeded = default; + nint __p_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller.ManagedToUnmanagedRef __p_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __p_native__marshaller.FromManaged(p); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __p_native = __p_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__p_native); + } + + __invokeSucceeded = true; + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __p_native__marshaller.OnInvoked(); + System.GC.KeepAlive(this); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __p_native__marshaller.FromUnmanaged(__p_native); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + if (__invokeSucceeded) + { + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + p = __p_native__marshaller.ToManagedFinally(); + } + + // Cleanup - Perform required cleanup. + __p_native__marshaller.Free(); + } + } +} + +file unsafe partial interface InterfaceImplementation +{ +} + +file unsafe partial interface InterfaceImplementation +{ +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface ISafeFileHandle + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface ISafeFileHandle + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.cs new file mode 100644 index 0000000..b84d7a4 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.cs @@ -0,0 +1,475 @@ +// +#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.IStatefulCollectionBlittableElement +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.Method(global::SharedTypes.ComInterfaces.StatefulCollection p, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement)); + byte* __p_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __p_native__marshaller = new(); + int __p_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __p_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __p_native__marshaller.FromManaged(p); + __p_native__marshaller.GetManagedValuesSource().CopyTo(__p_native__marshaller.GetUnmanagedValuesDestination()); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __p_native = __p_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __p_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + __p_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.MethodIn(in global::SharedTypes.ComInterfaces.StatefulCollection pIn, in int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement)); + byte* __pIn_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __pIn_native__marshaller = new(); + int __pIn_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pIn_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __pIn_native__marshaller.FromManaged(pIn); + __pIn_native__marshaller.GetManagedValuesSource().CopyTo(__pIn_native__marshaller.GetUnmanagedValuesDestination()); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pIn_native = __pIn_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__pIn_native, __size_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + __pIn_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.MethodRef(ref global::SharedTypes.ComInterfaces.StatefulCollection pRef, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement)); + byte* __pRef_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __pRef_native__marshaller = new(); + int __pRef_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pRef_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __pRef_native__marshaller.FromManaged(pRef); + __pRef_native__marshaller.GetManagedValuesSource().CopyTo(__pRef_native__marshaller.GetUnmanagedValuesDestination()); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pRef_native = __pRef_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__pRef_native, size); + } + + System.GC.KeepAlive(this); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __pRef_native__marshaller.FromUnmanaged(__pRef_native); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __pRef_native__numElements = size; + __pRef_native__marshaller.GetUnmanagedValuesSource(__pRef_native__numElements).CopyTo(__pRef_native__marshaller.GetManagedValuesDestination(__pRef_native__numElements)); + pRef = __pRef_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __pRef_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.MethodOut(out global::SharedTypes.ComInterfaces.StatefulCollection pOut, out int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out pOut); + System.Runtime.CompilerServices.Unsafe.SkipInit(out size); + byte* __pOut_native; + int __invokeRetVal; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __pOut_native__marshaller = new(); + int __pOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pOut_native__numElements); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__pOut_native, __size_native); + } + + System.GC.KeepAlive(this); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __pOut_native__marshaller.FromUnmanaged(__pOut_native); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __pOut_native__numElements = size; + __pOut_native__marshaller.GetUnmanagedValuesSource(__pOut_native__numElements).CopyTo(__pOut_native__marshaller.GetManagedValuesDestination(__pOut_native__numElements)); + pOut = __pOut_native__marshaller.ToManaged(); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatefulCollection global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.Return(int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement)); + global::SharedTypes.ComInterfaces.StatefulCollection __retVal; + byte* __retVal_native; + int __invokeRetVal; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __retVal_native__marshaller = new(); + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, size, &__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); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal_native__numElements = size; + __retVal_native__marshaller.GetUnmanagedValuesSource(__retVal_native__numElements).CopyTo(__retVal_native__marshaller.GetManagedValuesDestination(__retVal_native__numElements)); + __retVal = __retVal_native__marshaller.ToManaged(); + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatefulCollection global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.ReturnPreserveSig(int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement)); + global::SharedTypes.ComInterfaces.StatefulCollection __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __retVal_native__marshaller = new(); + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + { + __retVal_native = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this, size); + } + + 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); + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = size; + __retVal_native__marshaller.GetUnmanagedValuesSource(__retVal_native__numElements).CopyTo(__retVal_native__marshaller.GetManagedValuesDestination(__retVal_native__numElements)); + __retVal = __retVal_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_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 size) + { + global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement @this = default; + global::SharedTypes.ComInterfaces.StatefulCollection p = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __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. + __p_native__marshaller.FromUnmanaged(__p_native); + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __p_native__numElements = size; + __p_native__marshaller.GetUnmanagedValuesSource(__p_native__numElements).CopyTo(__p_native__marshaller.GetManagedValuesDestination(__p_native__numElements)); + p = __p_native__marshaller.ToManaged(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Method(p, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // Cleanup - Perform required cleanup. + __p_native__marshaller.Free(); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, byte** __pIn_native__param, int* __size_native__param) + { + global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement @this = default; + byte* __pIn_native = *__pIn_native__param; + global::SharedTypes.ComInterfaces.StatefulCollection pIn = default; + int __size_native = *__size_native__param; + int size = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __pIn_native__marshaller = new(); + int __pIn_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pIn_native__numElements); + try + { + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __pIn_native__marshaller.FromUnmanaged(__pIn_native); + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + size = __size_native; + __pIn_native__numElements = size; + __pIn_native__marshaller.GetUnmanagedValuesSource(__pIn_native__numElements).CopyTo(__pIn_native__marshaller.GetManagedValuesDestination(__pIn_native__numElements)); + pIn = __pIn_native__marshaller.ToManaged(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodIn(in pIn, in size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // Cleanup - Perform required cleanup. + __pIn_native__marshaller.Free(); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, byte** __pRef_native__param, int size) + { + global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement @this = default; + byte* __pRef_native__out = default; + byte* __pRef_native = *__pRef_native__param; + global::SharedTypes.ComInterfaces.StatefulCollection pRef = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __pRef_native__marshaller = new(); + int __pRef_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pRef_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); + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __pRef_native__numElements = size; + __pRef_native__marshaller.GetUnmanagedValuesSource(__pRef_native__numElements).CopyTo(__pRef_native__marshaller.GetManagedValuesDestination(__pRef_native__numElements)); + pRef = __pRef_native__marshaller.ToManaged(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodRef(ref pRef, size); + // Marshal - Convert managed data to native data. + __pRef_native__marshaller.FromManaged(pRef); + __pRef_native__marshaller.GetManagedValuesSource().CopyTo(__pRef_native__marshaller.GetUnmanagedValuesDestination()); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pRef_native__out = __pRef_native__marshaller.ToUnmanaged(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + __pRef_native__marshaller.Free(); + return __retVal; + } + + // AssignOut - Assign to parameters + *__pRef_native__param = __pRef_native__out; + // Cleanup - Perform required cleanup. + __pRef_native__marshaller.Free(); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, byte** __pOut_native__param, int* __size_native__param) + { + global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement @this = default; + byte* __pOut_native__out = default; + global::SharedTypes.ComInterfaces.StatefulCollection pOut = default; + int __size_native__out = default; + int size = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __pOut_native__marshaller = new(); + int __pOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pOut_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodOut(out pOut, out size); + // Marshal - Convert managed data to native data. + __size_native__out = size; + __pOut_native__marshaller.FromManaged(pOut); + __pOut_native__marshaller.GetManagedValuesSource().CopyTo(__pOut_native__marshaller.GetUnmanagedValuesDestination()); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pOut_native__out = __pOut_native__marshaller.ToUnmanaged(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + __pOut_native__marshaller.Free(); + return __retVal; + } + + // AssignOut - Assign to parameters + *__size_native__param = __size_native__out; + *__pOut_native__param = __pOut_native__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int size, byte** __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement @this = default; + byte* __invokeRetValUnmanaged__out = default; + global::SharedTypes.ComInterfaces.StatefulCollection __invokeRetVal = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __invokeRetValUnmanaged__marshaller = new(); + int __invokeRetValUnmanaged__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Return(size); + // Marshal - Convert managed data to native data. + __invokeRetValUnmanaged__marshaller.FromManaged(__invokeRetVal); + __invokeRetValUnmanaged__marshaller.GetManagedValuesSource().CopyTo(__invokeRetValUnmanaged__marshaller.GetUnmanagedValuesDestination()); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __invokeRetValUnmanaged__out = __invokeRetValUnmanaged__marshaller.ToUnmanaged(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + __invokeRetValUnmanaged__marshaller.Free(); + 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 byte* ABI_ReturnPreserveSig(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int size) + { + global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement @this = default; + global::SharedTypes.ComInterfaces.StatefulCollection __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __retVal_native__marshaller = new(); + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __retVal = @this.ReturnPreserveSig(size); + // Marshal - Convert managed data to native data. + __retVal_native__marshaller.FromManaged(__retVal); + __retVal_native__marshaller.GetManagedValuesSource().CopyTo(__retVal_native__marshaller.GetUnmanagedValuesDestination()); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __retVal_native = __retVal_native__marshaller.ToUnmanaged(); + } + catch (System.Exception __exception) + { + __retVal_native = (byte*)System.Runtime.InteropServices.Marshalling.ExceptionAsDefaultMarshaller.ConvertToUnmanaged(__exception); + return __retVal_native; + } + + // Cleanup - Perform required cleanup. + __retVal_native__marshaller.Free(); + return __retVal_native; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement), sizeof(void*) * 9); + { + 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; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodIn; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodRef; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodOut; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Return; + vtable[8] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_ReturnPreserveSig; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + partial interface IStatefulCollectionBlittableElement + { + } +} + +namespace SharedTypes.ComInterfaces +{ + partial interface IStatefulCollectionBlittableElement + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.cs new file mode 100644 index 0000000..350d241 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.cs @@ -0,0 +1,658 @@ +// +#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.IStatefulCollectionStatelessElement +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.Method(global::SharedTypes.ComInterfaces.StatefulCollection p, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement)); + byte* __p_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __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. + __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.StatelessTypeMarshaller.ConvertToUnmanaged(__p_native__managedSpan[__i0]); + } + } + + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __p_native = __p_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __p_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __p_native__nativeSpan = __p_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __p_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__p_native__nativeSpan[__i0]); + } + } + + __p_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.MethodIn(in global::SharedTypes.ComInterfaces.StatefulCollection pIn, in int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement)); + byte* __pIn_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __pIn_native__marshaller = new(); + int __pIn_native__numElements; + int __pIn_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pIn_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __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.StatelessTypeMarshaller.ConvertToUnmanaged(__pIn_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pIn_native = __pIn_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__pIn_native, __size_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __pIn_native__nativeSpan = __pIn_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __pIn_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__pIn_native__nativeSpan[__i0]); + } + } + + __pIn_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.MethodRef(ref global::SharedTypes.ComInterfaces.StatefulCollection pRef, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement)); + byte* __pRef_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __pRef_native__marshaller = new(); + int __pRef_native__numElements; + int __pRef_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pRef_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.StatelessTypeMarshaller.ConvertToUnmanaged(__pRef_native__managedSpan[__i0]); + } + } + + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pRef_native = __pRef_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__pRef_native, size); + } + + System.GC.KeepAlive(this); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __pRef_native__marshaller.FromUnmanaged(__pRef_native); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __pRef_native__numElements = size; + { + 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.StatelessTypeMarshaller.ConvertToManaged(__pRef_native__nativeSpan[__i0]); + } + } + + pRef = __pRef_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __pRef_native__nativeSpan = __pRef_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __pRef_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__pRef_native__nativeSpan[__i0]); + } + } + + __pRef_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.MethodOut(out global::SharedTypes.ComInterfaces.StatefulCollection pOut, out int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out pOut); + System.Runtime.CompilerServices.Unsafe.SkipInit(out size); + byte* __pOut_native; + int __invokeRetVal; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __pOut_native__marshaller = new(); + int __pOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pOut_native__numElements); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__pOut_native, __size_native); + } + + System.GC.KeepAlive(this); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __pOut_native__marshaller.FromUnmanaged(__pOut_native); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __pOut_native__numElements = size; + { + 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.StatelessTypeMarshaller.ConvertToManaged(__pOut_native__nativeSpan[__i0]); + } + } + + pOut = __pOut_native__marshaller.ToManaged(); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatefulCollection global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.Return(int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement)); + global::SharedTypes.ComInterfaces.StatefulCollection __retVal; + byte* __retVal_native; + int __invokeRetVal; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __retVal_native__marshaller = new(); + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, size, &__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); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal_native__numElements = size; + { + 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.StatelessTypeMarshaller.ConvertToManaged(__retVal_native__nativeSpan[__i0]); + } + } + + __retVal = __retVal_native__marshaller.ToManaged(); + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatefulCollection global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.ReturnPreserveSig(int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement)); + global::SharedTypes.ComInterfaces.StatefulCollection __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __retVal_native__marshaller = new(); + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + { + __retVal_native = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this, size); + } + + 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); + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = size; + { + 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.StatelessTypeMarshaller.ConvertToManaged(__retVal_native__nativeSpan[__i0]); + } + } + + __retVal = __retVal_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __retVal_native__nativeSpan = __retVal_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__retVal_native__nativeSpan[__i0]); + } + } + + __retVal_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 size) + { + global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement @this = default; + global::SharedTypes.ComInterfaces.StatefulCollection p = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __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. + __p_native__marshaller.FromUnmanaged(__p_native); + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __p_native__numElements = size; + { + 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.StatelessTypeMarshaller.ConvertToManaged(__p_native__nativeSpan[__i0]); + } + } + + p = __p_native__marshaller.ToManaged(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Method(p, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // Cleanup - Perform required cleanup. + __p_native__marshaller.Free(); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, byte** __pIn_native__param, int* __size_native__param) + { + global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement @this = default; + byte* __pIn_native = *__pIn_native__param; + global::SharedTypes.ComInterfaces.StatefulCollection pIn = default; + int __size_native = *__size_native__param; + int size = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __pIn_native__marshaller = new(); + int __pIn_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pIn_native__numElements); + try + { + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __pIn_native__marshaller.FromUnmanaged(__pIn_native); + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + size = __size_native; + __pIn_native__numElements = size; + { + 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.StatelessTypeMarshaller.ConvertToManaged(__pIn_native__nativeSpan[__i0]); + } + } + + pIn = __pIn_native__marshaller.ToManaged(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodIn(in pIn, in size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // Cleanup - Perform required cleanup. + __pIn_native__marshaller.Free(); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, byte** __pRef_native__param, int size) + { + global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement @this = default; + byte* __pRef_native__out = default; + byte* __pRef_native = *__pRef_native__param; + global::SharedTypes.ComInterfaces.StatefulCollection pRef = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __pRef_native__marshaller = new(); + int __pRef_native__numElements; + int __pRef_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pRef_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); + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __pRef_native__numElements = size; + { + 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.StatelessTypeMarshaller.ConvertToManaged(__pRef_native__nativeSpan[__i0]); + } + } + + pRef = __pRef_native__marshaller.ToManaged(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodRef(ref pRef, size); + // 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.StatelessTypeMarshaller.ConvertToUnmanaged(__pRef_native__managedSpan[__i0]); + } + } + + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pRef_native__out = __pRef_native__marshaller.ToUnmanaged(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + { + System.ReadOnlySpan __pRef_native__nativeSpan = __pRef_native__marshaller.GetUnmanagedValuesSource(__pRef_native__numElements); + for (int __i0 = 0; __i0 < __pRef_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__pRef_native__nativeSpan[__i0]); + } + } + + __pRef_native__marshaller.Free(); + return __retVal; + } + + // AssignOut - Assign to parameters + *__pRef_native__param = __pRef_native__out; + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __pRef_native__nativeSpan = __pRef_native__marshaller.GetUnmanagedValuesSource(__pRef_native__numElements); + for (int __i0 = 0; __i0 < __pRef_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__pRef_native__nativeSpan[__i0]); + } + } + + __pRef_native__marshaller.Free(); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, byte** __pOut_native__param, int* __size_native__param) + { + global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement @this = default; + byte* __pOut_native__out = default; + global::SharedTypes.ComInterfaces.StatefulCollection pOut = default; + int __size_native__out = default; + int size = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __pOut_native__marshaller = new(); + int __pOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pOut_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodOut(out pOut, out size); + // Marshal - Convert managed data to native data. + __size_native__out = size; + __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(); + for (int __i0 = 0; __i0 < __pOut_native__managedSpan.Length; ++__i0) + { + __pOut_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__pOut_native__managedSpan[__i0]); + } + } + + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pOut_native__out = __pOut_native__marshaller.ToUnmanaged(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + { + System.ReadOnlySpan __pOut_native__nativeSpan = __pOut_native__marshaller.GetUnmanagedValuesSource(__pOut_native__numElements); + for (int __i0 = 0; __i0 < __pOut_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__pOut_native__nativeSpan[__i0]); + } + } + + __pOut_native__marshaller.Free(); + return __retVal; + } + + // AssignOut - Assign to parameters + *__size_native__param = __size_native__out; + *__pOut_native__param = __pOut_native__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int size, byte** __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement @this = default; + byte* __invokeRetValUnmanaged__out = default; + global::SharedTypes.ComInterfaces.StatefulCollection __invokeRetVal = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __invokeRetValUnmanaged__marshaller = new(); + int __invokeRetValUnmanaged__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Return(size); + // 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(); + for (int __i0 = 0; __i0 < __invokeRetValUnmanaged__managedSpan.Length; ++__i0) + { + __invokeRetValUnmanaged__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__invokeRetValUnmanaged__managedSpan[__i0]); + } + } + + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __invokeRetValUnmanaged__out = __invokeRetValUnmanaged__marshaller.ToUnmanaged(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + { + System.ReadOnlySpan __invokeRetValUnmanaged__nativeSpan = __invokeRetValUnmanaged__marshaller.GetUnmanagedValuesSource(__invokeRetValUnmanaged__numElements); + for (int __i0 = 0; __i0 < __invokeRetValUnmanaged__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__invokeRetValUnmanaged__nativeSpan[__i0]); + } + } + + __invokeRetValUnmanaged__marshaller.Free(); + 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 byte* ABI_ReturnPreserveSig(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int size) + { + global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement @this = default; + global::SharedTypes.ComInterfaces.StatefulCollection __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __retVal_native__marshaller = new(); + int __retVal_native__numElements; + int __retVal_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __retVal = @this.ReturnPreserveSig(size); + // Marshal - Convert managed data to native data. + __retVal_native__marshaller.FromManaged(__retVal); + { + System.ReadOnlySpan __retVal_native__managedSpan = __retVal_native__marshaller.GetManagedValuesSource(); + System.Span __retVal_native__nativeSpan = __retVal_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __retVal_native__managedSpan.Length; ++__i0, ++__retVal_native__lastIndexMarshalled) + { + __retVal_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__retVal_native__managedSpan[__i0]); + } + } + + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __retVal_native = __retVal_native__marshaller.ToUnmanaged(); + } + catch (System.Exception __exception) + { + __retVal_native = (byte*)System.Runtime.InteropServices.Marshalling.ExceptionAsDefaultMarshaller.ConvertToUnmanaged(__exception); + return __retVal_native; + } + + // Cleanup - Perform required cleanup. + __retVal_native__marshaller.Free(); + return __retVal_native; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement), sizeof(void*) * 9); + { + 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; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodIn; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodRef; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodOut; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Return; + vtable[8] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_ReturnPreserveSig; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + partial interface IStatefulCollectionStatelessElement + { + } +} + +namespace SharedTypes.ComInterfaces +{ + partial interface IStatefulCollectionStatelessElement + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulMarshalling.cs new file mode 100644 index 0000000..60d9ef0 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulMarshalling.cs @@ -0,0 +1,432 @@ +// +#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[] { 93, 250, 49, 71, 3, 193, 34, 74, 135, 161, 88, 220, 237, 212, 169, 179 })); + + 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.IStatefulMarshalling +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulMarshalling.Method(global::SharedTypes.ComInterfaces.StatefulType param) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulMarshalling)); + nint __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __param_native); + } + + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __param_native__marshaller.OnInvoked(); + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulMarshalling.MethodIn(in global::SharedTypes.ComInterfaces.StatefulType param) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulMarshalling)); + nint __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__param_native); + } + + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __param_native__marshaller.OnInvoked(); + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulMarshalling.MethodOut(out global::SharedTypes.ComInterfaces.StatefulType param) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulMarshalling)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out param); + nint __param_native; + int __invokeRetVal; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__marshaller = new(); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__param_native); + } + + System.GC.KeepAlive(this); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __param_native__marshaller.FromUnmanaged(__param_native); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + param = __param_native__marshaller.ToManaged(); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulMarshalling.MethodRef(ref global::SharedTypes.ComInterfaces.StatefulType param) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulMarshalling)); + nint __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__param_native); + } + + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __param_native__marshaller.OnInvoked(); + System.GC.KeepAlive(this); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __param_native__marshaller.FromUnmanaged(__param_native); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + param = __param_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatefulType global::SharedTypes.ComInterfaces.IStatefulMarshalling.Return() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulMarshalling)); + global::SharedTypes.ComInterfaces.StatefulType __retVal; + nint __retVal_native; + int __invokeRetVal; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __retVal_native__marshaller = new(); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, &__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); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal = __retVal_native__marshaller.ToManaged(); + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatefulType global::SharedTypes.ComInterfaces.IStatefulMarshalling.ReturnPreserveSig() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulMarshalling)); + global::SharedTypes.ComInterfaces.StatefulType __retVal = default; + nint __retVal_native = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __retVal_native__marshaller = new(); + try + { + { + __retVal_native = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this); + } + + 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); + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_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, nint __param_native) + { + global::SharedTypes.ComInterfaces.IStatefulMarshalling @this = default; + global::SharedTypes.ComInterfaces.StatefulType param = default; + int __retVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__marshaller = new(); + try + { + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __param_native__marshaller.FromUnmanaged(__param_native); + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + param = __param_native__marshaller.ToManaged(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Method(param); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param) + { + global::SharedTypes.ComInterfaces.IStatefulMarshalling @this = default; + nint __param_native = *__param_native__param; + global::SharedTypes.ComInterfaces.StatefulType param = default; + int __retVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__marshaller = new(); + try + { + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __param_native__marshaller.FromUnmanaged(__param_native); + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + param = __param_native__marshaller.ToManaged(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodIn(in param); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param) + { + global::SharedTypes.ComInterfaces.IStatefulMarshalling @this = default; + nint __param_native__out = default; + global::SharedTypes.ComInterfaces.StatefulType param = default; + int __retVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__marshaller = new(); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodOut(out param); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __param_native__marshaller.OnInvoked(); + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native__out = __param_native__marshaller.ToUnmanaged(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + __param_native__marshaller.Free(); + return __retVal; + } + + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param) + { + global::SharedTypes.ComInterfaces.IStatefulMarshalling @this = default; + nint __param_native__out = default; + nint __param_native = *__param_native__param; + global::SharedTypes.ComInterfaces.StatefulType param = default; + int __retVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__marshaller = new(); + try + { + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __param_native__marshaller.FromUnmanaged(__param_native); + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + param = __param_native__marshaller.ToManaged(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodRef(ref param); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __param_native__marshaller.OnInvoked(); + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native__out = __param_native__marshaller.ToUnmanaged(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + __param_native__marshaller.Free(); + return __retVal; + } + + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IStatefulMarshalling @this = default; + nint __invokeRetValUnmanaged__out = default; + global::SharedTypes.ComInterfaces.StatefulType __invokeRetVal = default; + int __retVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __invokeRetValUnmanaged__marshaller = new(); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Return(); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __invokeRetValUnmanaged__marshaller.OnInvoked(); + // Marshal - Convert managed data to native data. + __invokeRetValUnmanaged__marshaller.FromManaged(__invokeRetVal); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __invokeRetValUnmanaged__out = __invokeRetValUnmanaged__marshaller.ToUnmanaged(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + __invokeRetValUnmanaged__marshaller.Free(); + 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 nint ABI_ReturnPreserveSig(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native) + { + global::SharedTypes.ComInterfaces.IStatefulMarshalling @this = default; + global::SharedTypes.ComInterfaces.StatefulType __retVal = default; + nint __retVal_native = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __retVal_native__marshaller = new(); + try + { + // Unmarshal - Convert native data to managed data. + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __retVal = @this.ReturnPreserveSig(); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal_native__marshaller.OnInvoked(); + // Marshal - Convert managed data to native data. + __retVal_native__marshaller.FromManaged(__retVal); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __retVal_native = __retVal_native__marshaller.ToUnmanaged(); + } + catch (System.Exception __exception) + { + __retVal_native = System.Runtime.InteropServices.Marshalling.ExceptionAsDefaultMarshaller.ConvertToUnmanaged(__exception); + return __retVal_native; + } + + // Cleanup - Perform required cleanup. + __retVal_native__marshaller.Free(); + return __retVal_native; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IStatefulMarshalling), sizeof(void*) * 9); + { + 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; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodIn; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodOut; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodRef; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Return; + vtable[8] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_ReturnPreserveSig; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IStatefulMarshalling + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IStatefulMarshalling + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.cs new file mode 100644 index 0000000..5aac879 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.cs @@ -0,0 +1,435 @@ +// +#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.IStatelessCollectionBlittableElement +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.Method(global::SharedTypes.ComInterfaces.StatelessCollection p, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement)); + nint __p_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __p_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __p_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __p_native = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(p, out __p_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(p).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__p_native, __p_native__numElements)); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __p_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + ; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__p_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.MethodIn(in global::SharedTypes.ComInterfaces.StatelessCollection pIn, in int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement)); + nint __pIn_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __pIn_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pIn_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __pIn_native = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(pIn, out __pIn_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(pIn).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__pIn_native, __pIn_native__numElements)); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__pIn_native, __size_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + ; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pIn_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.MethodRef(ref global::SharedTypes.ComInterfaces.StatelessCollection pRef, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement)); + nint __pRef_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __pRef_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pRef_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __pRef_native = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(pRef, out __pRef_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(pRef).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__pRef_native, __pRef_native__numElements)); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__pRef_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __pRef_native__numElements = size; + pRef = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__pRef_native, __pRef_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__pRef_native, __pRef_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(pRef)); + } + finally + { + // Cleanup - Perform required cleanup. + __pRef_native__numElements = size; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pRef_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.MethodOut(out global::SharedTypes.ComInterfaces.StatelessCollection pOut, out int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out pOut); + System.Runtime.CompilerServices.Unsafe.SkipInit(out size); + nint __pOut_native; + int __invokeRetVal; + // Setup - Perform required setup. + int __pOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pOut_native__numElements); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__pOut_native, __size_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __pOut_native__numElements = size; + pOut = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__pOut_native, __pOut_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__pOut_native, __pOut_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(pOut)); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatelessCollection global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.Return(int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement)); + global::SharedTypes.ComInterfaces.StatelessCollection __retVal; + nint __retVal_native; + int __invokeRetVal; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, size, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal_native__numElements = size; + __retVal = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(__retVal)); + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatelessCollection global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.ReturnPreserveSig(int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement)); + global::SharedTypes.ComInterfaces.StatelessCollection __retVal = default; + nint __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + { + __retVal_native = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = size; + __retVal = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(__retVal)); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_native__numElements = size; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__retVal_native); + } + + 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, nint __p_native, int size) + { + global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement @this = default; + global::SharedTypes.ComInterfaces.StatelessCollection p = default; + int __retVal = default; + // Setup - Perform required setup. + int __p_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __p_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __p_native__numElements = size; + p = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__p_native, __p_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__p_native, __p_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(p)); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Method(p, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __pIn_native__param, int* __size_native__param) + { + global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement @this = default; + nint __pIn_native = *__pIn_native__param; + global::SharedTypes.ComInterfaces.StatelessCollection pIn = default; + int __size_native = *__size_native__param; + int size = default; + int __retVal = default; + // Setup - Perform required setup. + int __pIn_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pIn_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + size = __size_native; + __pIn_native__numElements = size; + pIn = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__pIn_native, __pIn_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__pIn_native, __pIn_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(pIn)); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodIn(in pIn, in size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __pRef_native__param, int size) + { + global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement @this = default; + nint __pRef_native__out = default; + nint __pRef_native = *__pRef_native__param; + global::SharedTypes.ComInterfaces.StatelessCollection pRef = default; + int __retVal = default; + // Setup - Perform required setup. + int __pRef_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pRef_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __pRef_native__numElements = size; + pRef = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__pRef_native, __pRef_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__pRef_native, __pRef_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(pRef)); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodRef(ref pRef, size); + // Marshal - Convert managed data to native data. + __pRef_native__out = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(pRef, out __pRef_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(pRef).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__pRef_native__out, __pRef_native__numElements)); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + __pRef_native__numElements = size; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pRef_native__out); + return __retVal; + } + + // AssignOut - Assign to parameters + *__pRef_native__param = __pRef_native__out; + // Cleanup - Perform required cleanup. + __pRef_native__numElements = size; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pRef_native); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __pOut_native__param, int* __size_native__param) + { + global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement @this = default; + nint __pOut_native__out = default; + global::SharedTypes.ComInterfaces.StatelessCollection pOut = default; + int __size_native__out = default; + int size = default; + int __retVal = default; + // Setup - Perform required setup. + int __pOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pOut_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodOut(out pOut, out size); + // Marshal - Convert managed data to native data. + __size_native__out = size; + __pOut_native__out = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(pOut, out __pOut_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(pOut).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__pOut_native__out, __pOut_native__numElements)); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + ; + return __retVal; + } + + // AssignOut - Assign to parameters + *__size_native__param = __size_native__out; + *__pOut_native__param = __pOut_native__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int size, nint* __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement @this = default; + nint __invokeRetValUnmanaged__out = default; + global::SharedTypes.ComInterfaces.StatelessCollection __invokeRetVal = default; + int __retVal = default; + // Setup - Perform required setup. + int __invokeRetValUnmanaged__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Return(size); + // Marshal - Convert managed data to native data. + __invokeRetValUnmanaged__out = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(__invokeRetVal).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements)); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + ; + 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 nint ABI_ReturnPreserveSig(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int size) + { + global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement @this = default; + global::SharedTypes.ComInterfaces.StatelessCollection __retVal = default; + nint __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __retVal = @this.ReturnPreserveSig(size); + // Marshal - Convert managed data to native data. + __retVal_native = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(__retVal, out __retVal_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(__retVal).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__retVal_native, __retVal_native__numElements)); + } + catch (System.Exception __exception) + { + __retVal_native = System.Runtime.InteropServices.Marshalling.ExceptionAsDefaultMarshaller.ConvertToUnmanaged(__exception); + return __retVal_native; + } + + return __retVal_native; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement), sizeof(void*) * 9); + { + 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; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodIn; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodRef; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodOut; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Return; + vtable[8] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_ReturnPreserveSig; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + partial interface IStatelessCollectionBlittableElement + { + } +} + +namespace SharedTypes.ComInterfaces +{ + partial interface IStatelessCollectionBlittableElement + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.cs new file mode 100644 index 0000000..0cd1e3d --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.cs @@ -0,0 +1,603 @@ +// +#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.IStatelessCollectionStatelessElement +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.Method(global::SharedTypes.ComInterfaces.StatelessCollection p, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement)); + nint __p_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __p_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __p_native__numElements); + int __p_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __p_native = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(p, out __p_native__numElements); + { + System.ReadOnlySpan __p_native__managedSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(p); + System.Span __p_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__p_native, __p_native__numElements); + for (int __i0 = 0; __i0 < __p_native__managedSpan.Length; ++__i0, ++__p_native__lastIndexMarshalled) + { + __p_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__p_native__managedSpan[__i0]); + } + } + + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __p_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __p_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__p_native, __p_native__numElements); + for (int __i0 = 0; __i0 < __p_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__p_native__nativeSpan[__i0]); + } + }; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__p_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.MethodIn(in global::SharedTypes.ComInterfaces.StatelessCollection pIn, in int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement)); + nint __pIn_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __pIn_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pIn_native__numElements); + int __pIn_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __pIn_native = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(pIn, out __pIn_native__numElements); + { + System.ReadOnlySpan __pIn_native__managedSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(pIn); + System.Span __pIn_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__pIn_native, __pIn_native__numElements); + for (int __i0 = 0; __i0 < __pIn_native__managedSpan.Length; ++__i0, ++__pIn_native__lastIndexMarshalled) + { + __pIn_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__pIn_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__pIn_native, __size_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __pIn_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__pIn_native, __pIn_native__numElements); + for (int __i0 = 0; __i0 < __pIn_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__pIn_native__nativeSpan[__i0]); + } + }; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pIn_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.MethodRef(ref global::SharedTypes.ComInterfaces.StatelessCollection pRef, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement)); + nint __pRef_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __pRef_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pRef_native__numElements); + int __pRef_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __pRef_native = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(pRef, out __pRef_native__numElements); + { + System.ReadOnlySpan __pRef_native__managedSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(pRef); + System.Span __pRef_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__pRef_native, __pRef_native__numElements); + for (int __i0 = 0; __i0 < __pRef_native__managedSpan.Length; ++__i0, ++__pRef_native__lastIndexMarshalled) + { + __pRef_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__pRef_native__managedSpan[__i0]); + } + } + + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__pRef_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __pRef_native__numElements = size; + pRef = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__pRef_native, __pRef_native__numElements); + { + System.ReadOnlySpan __pRef_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__pRef_native, __pRef_native__numElements); + System.Span __pRef_native__managedSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(pRef); + for (int __i0 = 0; __i0 < __pRef_native__numElements; ++__i0) + { + __pRef_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__pRef_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __pRef_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__pRef_native, __pRef_native__numElements); + for (int __i0 = 0; __i0 < __pRef_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__pRef_native__nativeSpan[__i0]); + } + } + + __pRef_native__numElements = size; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pRef_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.MethodOut(out global::SharedTypes.ComInterfaces.StatelessCollection pOut, out int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out pOut); + System.Runtime.CompilerServices.Unsafe.SkipInit(out size); + nint __pOut_native; + int __invokeRetVal; + // Setup - Perform required setup. + int __pOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pOut_native__numElements); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__pOut_native, __size_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __pOut_native__numElements = size; + pOut = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__pOut_native, __pOut_native__numElements); + { + System.ReadOnlySpan __pOut_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__pOut_native, __pOut_native__numElements); + System.Span __pOut_native__managedSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(pOut); + for (int __i0 = 0; __i0 < __pOut_native__numElements; ++__i0) + { + __pOut_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__pOut_native__nativeSpan[__i0]); + } + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatelessCollection global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.Return(int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement)); + global::SharedTypes.ComInterfaces.StatelessCollection __retVal; + nint __retVal_native; + int __invokeRetVal; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, size, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal_native__numElements = size; + __retVal = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + System.Span __retVal_native__managedSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(__retVal); + for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + { + __retVal_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__retVal_native__nativeSpan[__i0]); + } + } + + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatelessCollection global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.ReturnPreserveSig(int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement)); + global::SharedTypes.ComInterfaces.StatelessCollection __retVal = default; + nint __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + { + __retVal_native = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = size; + __retVal = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + System.Span __retVal_native__managedSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(__retVal); + for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + { + __retVal_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__retVal_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__retVal_native, __retVal_native__numElements); + for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__retVal_native__nativeSpan[__i0]); + } + } + + __retVal_native__numElements = size; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__retVal_native); + } + + 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, nint __p_native, int size) + { + global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement @this = default; + global::SharedTypes.ComInterfaces.StatelessCollection p = default; + int __retVal = default; + // Setup - Perform required setup. + int __p_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __p_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __p_native__numElements = size; + p = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__p_native, __p_native__numElements); + { + System.ReadOnlySpan __p_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__p_native, __p_native__numElements); + System.Span __p_native__managedSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(p); + for (int __i0 = 0; __i0 < __p_native__numElements; ++__i0) + { + __p_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__p_native__nativeSpan[__i0]); + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Method(p, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __pIn_native__param, int* __size_native__param) + { + global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement @this = default; + nint __pIn_native = *__pIn_native__param; + global::SharedTypes.ComInterfaces.StatelessCollection pIn = default; + int __size_native = *__size_native__param; + int size = default; + int __retVal = default; + // Setup - Perform required setup. + int __pIn_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pIn_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + size = __size_native; + __pIn_native__numElements = size; + pIn = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__pIn_native, __pIn_native__numElements); + { + System.ReadOnlySpan __pIn_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__pIn_native, __pIn_native__numElements); + System.Span __pIn_native__managedSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(pIn); + for (int __i0 = 0; __i0 < __pIn_native__numElements; ++__i0) + { + __pIn_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__pIn_native__nativeSpan[__i0]); + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodIn(in pIn, in size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __pRef_native__param, int size) + { + global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement @this = default; + nint __pRef_native__out = default; + nint __pRef_native = *__pRef_native__param; + global::SharedTypes.ComInterfaces.StatelessCollection pRef = default; + int __retVal = default; + // Setup - Perform required setup. + int __pRef_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pRef_native__numElements); + int __pRef_native__lastIndexMarshalled = 0; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __pRef_native__numElements = size; + pRef = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__pRef_native, __pRef_native__numElements); + { + System.ReadOnlySpan __pRef_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__pRef_native, __pRef_native__numElements); + System.Span __pRef_native__managedSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(pRef); + for (int __i0 = 0; __i0 < __pRef_native__numElements; ++__i0) + { + __pRef_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__pRef_native__nativeSpan[__i0]); + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodRef(ref pRef, size); + // Marshal - Convert managed data to native data. + __pRef_native__out = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(pRef, out __pRef_native__numElements); + { + System.ReadOnlySpan __pRef_native__managedSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(pRef); + System.Span __pRef_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__pRef_native__out, __pRef_native__numElements); + for (int __i0 = 0; __i0 < __pRef_native__managedSpan.Length; ++__i0, ++__pRef_native__lastIndexMarshalled) + { + __pRef_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__pRef_native__managedSpan[__i0]); + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + { + System.ReadOnlySpan __pRef_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__pRef_native__out, __pRef_native__numElements); + for (int __i0 = 0; __i0 < __pRef_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__pRef_native__nativeSpan[__i0]); + } + } + + __pRef_native__numElements = size; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pRef_native__out); + return __retVal; + } + + // AssignOut - Assign to parameters + *__pRef_native__param = __pRef_native__out; + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __pRef_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__pRef_native, __pRef_native__numElements); + for (int __i0 = 0; __i0 < __pRef_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__pRef_native__nativeSpan[__i0]); + } + } + + __pRef_native__numElements = size; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pRef_native); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __pOut_native__param, int* __size_native__param) + { + global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement @this = default; + nint __pOut_native__out = default; + global::SharedTypes.ComInterfaces.StatelessCollection pOut = default; + int __size_native__out = default; + int size = default; + int __retVal = default; + // Setup - Perform required setup. + int __pOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pOut_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodOut(out pOut, out size); + // Marshal - Convert managed data to native data. + __size_native__out = size; + __pOut_native__out = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(pOut, out __pOut_native__numElements); + { + System.ReadOnlySpan __pOut_native__managedSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(pOut); + System.Span __pOut_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__pOut_native__out, __pOut_native__numElements); + __pOut_native__nativeSpan.Clear(); + for (int __i0 = 0; __i0 < __pOut_native__managedSpan.Length; ++__i0) + { + __pOut_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__pOut_native__managedSpan[__i0]); + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + { + System.ReadOnlySpan __pOut_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__pOut_native__out, __pOut_native__numElements); + for (int __i0 = 0; __i0 < __pOut_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__pOut_native__nativeSpan[__i0]); + } + }; + return __retVal; + } + + // AssignOut - Assign to parameters + *__size_native__param = __size_native__out; + *__pOut_native__param = __pOut_native__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int size, nint* __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement @this = default; + nint __invokeRetValUnmanaged__out = default; + global::SharedTypes.ComInterfaces.StatelessCollection __invokeRetVal = default; + int __retVal = default; + // Setup - Perform required setup. + int __invokeRetValUnmanaged__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Return(size); + // Marshal - Convert managed data to native data. + __invokeRetValUnmanaged__out = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); + { + System.ReadOnlySpan __invokeRetValUnmanaged__managedSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(__invokeRetVal); + System.Span __invokeRetValUnmanaged__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements); + __invokeRetValUnmanaged__nativeSpan.Clear(); + for (int __i0 = 0; __i0 < __invokeRetValUnmanaged__managedSpan.Length; ++__i0) + { + __invokeRetValUnmanaged__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__invokeRetValUnmanaged__managedSpan[__i0]); + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + { + System.ReadOnlySpan __invokeRetValUnmanaged__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements); + for (int __i0 = 0; __i0 < __invokeRetValUnmanaged__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__invokeRetValUnmanaged__nativeSpan[__i0]); + } + }; + 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 nint ABI_ReturnPreserveSig(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int size) + { + global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement @this = default; + global::SharedTypes.ComInterfaces.StatelessCollection __retVal = default; + nint __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + int __retVal_native__lastIndexMarshalled = 0; + try + { + // Unmarshal - Convert native data to managed data. + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __retVal = @this.ReturnPreserveSig(size); + // Marshal - Convert managed data to native data. + __retVal_native = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(__retVal, out __retVal_native__numElements); + { + System.ReadOnlySpan __retVal_native__managedSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(__retVal); + System.Span __retVal_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__retVal_native, __retVal_native__numElements); + for (int __i0 = 0; __i0 < __retVal_native__managedSpan.Length; ++__i0, ++__retVal_native__lastIndexMarshalled) + { + __retVal_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__retVal_native__managedSpan[__i0]); + } + } + } + catch (System.Exception __exception) + { + __retVal_native = System.Runtime.InteropServices.Marshalling.ExceptionAsDefaultMarshaller.ConvertToUnmanaged(__exception); + return __retVal_native; + } + + return __retVal_native; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement), sizeof(void*) * 9); + { + 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; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodIn; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodRef; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodOut; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Return; + vtable[8] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_ReturnPreserveSig; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + partial interface IStatelessCollectionStatelessElement + { + } +} + +namespace SharedTypes.ComInterfaces +{ + partial interface IStatelessCollectionStatelessElement + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessMarshalling.cs new file mode 100644 index 0000000..a30655c --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessMarshalling.cs @@ -0,0 +1,356 @@ +// +#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[] { 93, 250, 50, 71, 5, 193, 35, 74, 135, 167, 88, 220, 237, 212, 169, 179 })); + + 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.IStatelessMarshalling +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessMarshalling.Method(global::SharedTypes.ComInterfaces.StatelessType param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessMarshalling)); + nint __param_native = default; + int __invokeRetVal = default; + try + { + // Marshal - Convert managed data to native data. + __param_native = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(param); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessMarshalling.MethodIn(in global::SharedTypes.ComInterfaces.StatelessType param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessMarshalling)); + nint __param_native = default; + int __invokeRetVal = default; + try + { + // Marshal - Convert managed data to native data. + __param_native = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(param); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessMarshalling.MethodOut(out global::SharedTypes.ComInterfaces.StatelessType param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessMarshalling)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out param); + nint __param_native; + int __invokeRetVal; + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + param = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessMarshalling.MethodRef(ref global::SharedTypes.ComInterfaces.StatelessType param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessMarshalling)); + nint __param_native = default; + int __invokeRetVal = default; + try + { + // Marshal - Convert managed data to native data. + __param_native = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(param); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + param = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatelessType global::SharedTypes.ComInterfaces.IStatelessMarshalling.Return() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessMarshalling)); + global::SharedTypes.ComInterfaces.StatelessType __retVal; + nint __retVal_native; + int __invokeRetVal; + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__retVal_native); + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatelessType global::SharedTypes.ComInterfaces.IStatelessMarshalling.ReturnPreserveSig() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessMarshalling)); + global::SharedTypes.ComInterfaces.StatelessType __retVal = default; + nint __retVal_native = default; + try + { + { + __retVal_native = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + __retVal = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__retVal_native); + } + + 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, nint __param_native, int size) + { + global::SharedTypes.ComInterfaces.IStatelessMarshalling @this = default; + global::SharedTypes.ComInterfaces.StatelessType param = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + param = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Method(param, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param, int size) + { + global::SharedTypes.ComInterfaces.IStatelessMarshalling @this = default; + nint __param_native = *__param_native__param; + global::SharedTypes.ComInterfaces.StatelessType param = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + param = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodIn(in param, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param, int size) + { + global::SharedTypes.ComInterfaces.IStatelessMarshalling @this = default; + nint __param_native__out = default; + global::SharedTypes.ComInterfaces.StatelessType param = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodOut(out param, size); + // Marshal - Convert managed data to native data. + __param_native__out = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(param); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param, int size) + { + global::SharedTypes.ComInterfaces.IStatelessMarshalling @this = default; + nint __param_native__out = default; + nint __param_native = *__param_native__param; + global::SharedTypes.ComInterfaces.StatelessType param = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + param = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodRef(ref param, size); + // Marshal - Convert managed data to native data. + __param_native__out = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(param); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__out); + return __retVal; + } + + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IStatelessMarshalling @this = default; + nint __invokeRetValUnmanaged__out = default; + global::SharedTypes.ComInterfaces.StatelessType __invokeRetVal = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Return(); + // Marshal - Convert managed data to native data. + __invokeRetValUnmanaged__out = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.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; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static nint ABI_ReturnPreserveSig(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native) + { + global::SharedTypes.ComInterfaces.IStatelessMarshalling @this = default; + global::SharedTypes.ComInterfaces.StatelessType __retVal = default; + nint __retVal_native = default; + try + { + // Unmarshal - Convert native data to managed data. + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __retVal = @this.ReturnPreserveSig(); + // Marshal - Convert managed data to native data. + __retVal_native = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__retVal); + } + catch (System.Exception __exception) + { + __retVal_native = System.Runtime.InteropServices.Marshalling.ExceptionAsDefaultMarshaller.ConvertToUnmanaged(__exception); + return __retVal_native; + } + + return __retVal_native; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IStatelessMarshalling), sizeof(void*) * 9); + { + 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; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodIn; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodOut; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodRef; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Return; + vtable[8] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_ReturnPreserveSig; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IStatelessMarshalling + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IStatelessMarshalling + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverride.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverride.cs new file mode 100644 index 0000000..fa244b8 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverride.cs @@ -0,0 +1,218 @@ +// +#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[] { 219, 183, 70, 81, 136, 5, 155, 70, 184, 229, 179, 128, 144, 162, 252, 21 })); + + 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.IStringMarshallingOverride +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + string global::SharedTypes.ComInterfaces.IStringMarshallingOverride.StringMarshallingUtf8(string input) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStringMarshallingOverride)); + byte* __input_native = default; + string __retVal = default; + byte* __retVal_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __input_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __input_native__marshaller.FromManaged(input, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __input_native = __input_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __input_native, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + __input_native__marshaller.Free(); + } + + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + string global::SharedTypes.ComInterfaces.IStringMarshallingOverride.MarshalAsLPWString(string input) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStringMarshallingOverride)); + string __retVal; + ushort* __retVal_native; + int __invokeRetVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __input_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(input)) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, (ushort*)__input_native, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + string global::SharedTypes.ComInterfaces.IStringMarshallingOverride.MarshalUsingUtf16(string input) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStringMarshallingOverride)); + string __retVal; + ushort* __retVal_native; + int __invokeRetVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __input_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(input)) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, (ushort*)__input_native, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + return __retVal; + } +} + +file unsafe partial interface InterfaceImplementation +{ + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_StringMarshallingUtf8(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, byte* __input_native, byte** __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IStringMarshallingOverride @this = default; + string input = default; + byte* __invokeRetValUnmanaged__out = default; + string __invokeRetVal = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + input = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__input_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.StringMarshallingUtf8(input); + // Marshal - Convert managed data to native data. + __invokeRetValUnmanaged__out = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.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; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MarshalAsLPWString(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, ushort* __input_native, ushort** __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IStringMarshallingOverride @this = default; + string input = default; + ushort* __invokeRetValUnmanaged__out = default; + string __invokeRetVal = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + input = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__input_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.MarshalAsLPWString(input); + // Marshal - Convert managed data to native data. + __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; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MarshalUsingUtf16(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, ushort* __input_native, ushort** __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IStringMarshallingOverride @this = default; + string input = default; + ushort* __invokeRetValUnmanaged__out = default; + string __invokeRetVal = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + input = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__input_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.MarshalUsingUtf16(input); + // Marshal - Convert managed data to native data. + __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; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IStringMarshallingOverride), sizeof(void*) * 6); + { + 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_StringMarshallingUtf8; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MarshalAsLPWString; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MarshalUsingUtf16; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IStringMarshallingOverride + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IStringMarshallingOverride + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.cs new file mode 100644 index 0000000..20621f8 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.cs @@ -0,0 +1,304 @@ +// +#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[] { 253, 227, 255, 58, 30, 209, 149, 65, 130, 80, 12, 115, 50, 25, 119, 160 })); + + 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.IStringMarshallingOverrideDerived +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + string global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.StringMarshallingUtf8_2(string input) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived)); + byte* __input_native = default; + string __retVal = default; + byte* __retVal_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __input_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __input_native__marshaller.FromManaged(input, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __input_native = __input_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, __input_native, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + __input_native__marshaller.Free(); + } + + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + string global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.MarshalAsLPWString_2(string input) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived)); + string __retVal; + ushort* __retVal_native; + int __invokeRetVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __input_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(input)) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, (ushort*)__input_native, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + string global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.MarshalUsingUtf16_2(string input) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived)); + string __retVal; + ushort* __retVal_native; + int __invokeRetVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __input_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(input)) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this, (ushort*)__input_native, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + string global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.StringMarshallingUtf8(string input) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived)); + byte* __input_native = default; + string __retVal = default; + byte* __retVal_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __input_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __input_native__marshaller.FromManaged(input, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __input_native = __input_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __input_native, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + __input_native__marshaller.Free(); + } + + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + string global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.MarshalAsLPWString(string input) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived)); + string __retVal; + ushort* __retVal_native; + int __invokeRetVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __input_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(input)) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, (ushort*)__input_native, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + string global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.MarshalUsingUtf16(string input) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived)); + string __retVal; + ushort* __retVal_native; + int __invokeRetVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __input_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(input)) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, (ushort*)__input_native, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + return __retVal; + } + + string global::SharedTypes.ComInterfaces.IStringMarshallingOverride.StringMarshallingUtf8(string input) => throw new System.Diagnostics.UnreachableException(); + string global::SharedTypes.ComInterfaces.IStringMarshallingOverride.MarshalAsLPWString(string input) => throw new System.Diagnostics.UnreachableException(); + string global::SharedTypes.ComInterfaces.IStringMarshallingOverride.MarshalUsingUtf16(string input) => throw new System.Diagnostics.UnreachableException(); +} + +file unsafe partial interface InterfaceImplementation +{ + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_StringMarshallingUtf8_2(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, byte* __input_native, byte** __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived @this = default; + string input = default; + byte* __invokeRetValUnmanaged__out = default; + string __invokeRetVal = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + input = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__input_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.StringMarshallingUtf8_2(input); + // Marshal - Convert managed data to native data. + __invokeRetValUnmanaged__out = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.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; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MarshalAsLPWString_2(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, ushort* __input_native, ushort** __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived @this = default; + string input = default; + ushort* __invokeRetValUnmanaged__out = default; + string __invokeRetVal = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + input = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__input_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.MarshalAsLPWString_2(input); + // Marshal - Convert managed data to native data. + __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; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MarshalUsingUtf16_2(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, ushort* __input_native, ushort** __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived @this = default; + string input = default; + ushort* __invokeRetValUnmanaged__out = default; + string __invokeRetVal = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + input = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__input_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.MarshalUsingUtf16_2(input); + // Marshal - Convert managed data to native data. + __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; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived), sizeof(void*) * 9); + { + System.Runtime.InteropServices.NativeMemory.Copy(System.Runtime.InteropServices.Marshalling.StrategyBasedComWrappers.DefaultIUnknownInterfaceDetailsStrategy.GetIUnknownDerivedDetails(typeof(global::SharedTypes.ComInterfaces.IStringMarshallingOverride).TypeHandle).ManagedVirtualMethodTable, vtable, (nuint)(sizeof(void*) * 6)); + } + + { + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_StringMarshallingUtf8_2; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MarshalAsLPWString_2; + vtable[8] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MarshalUsingUtf16_2; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IStringMarshallingOverrideDerived + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IStringMarshallingOverrideDerived + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + new string StringMarshallingUtf8(string input) => ((global::SharedTypes.ComInterfaces.IStringMarshallingOverride)this).StringMarshallingUtf8(input); + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + new string MarshalAsLPWString(string input) => ((global::SharedTypes.ComInterfaces.IStringMarshallingOverride)this).MarshalAsLPWString(input); + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + new string MarshalUsingUtf16(string input) => ((global::SharedTypes.ComInterfaces.IStringMarshallingOverride)this).MarshalUsingUtf16(input); + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF16Marshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF16Marshalling.cs new file mode 100644 index 0000000..986dc40 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF16Marshalling.cs @@ -0,0 +1,139 @@ +// +#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[] { 62, 95, 29, 225, 87, 221, 166, 65, 165, 158, 125, 17, 5, 81, 167, 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.IUTF16Marshalling +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + string global::SharedTypes.ComInterfaces.IUTF16Marshalling.GetString() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IUTF16Marshalling)); + string __retVal; + ushort* __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 = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IUTF16Marshalling.SetString(string value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IUTF16Marshalling)); + int __invokeRetVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __value_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(value)) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, (ushort*)__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_GetString(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, ushort** __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IUTF16Marshalling @this = default; + ushort* __invokeRetValUnmanaged__out = default; + string __invokeRetVal = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.GetString(); + // Marshal - Convert managed data to native data. + __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; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_SetString(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, ushort* __value_native) + { + global::SharedTypes.ComInterfaces.IUTF16Marshalling @this = default; + string value = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + value = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__value_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.SetString(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.IUTF16Marshalling), 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_GetString; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_SetString; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IUTF16Marshalling + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IUTF16Marshalling + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF8Marshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF8Marshalling.cs new file mode 100644 index 0000000..5ff08b5 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF8Marshalling.cs @@ -0,0 +1,152 @@ +// +#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[] { 62, 95, 29, 225, 87, 221, 166, 65, 165, 158, 125, 17, 5, 81, 167, 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.IUTF8Marshalling +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + string global::SharedTypes.ComInterfaces.IUTF8Marshalling.GetString() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IUTF8Marshalling)); + string __retVal; + byte* __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 = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__retVal_native); + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IUTF8Marshalling.SetString(string value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IUTF8Marshalling)); + byte* __value_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __value_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __value_native__marshaller.FromManaged(value, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __value_native = __value_native__marshaller.ToUnmanaged(); + __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); + } + finally + { + // Cleanup - Perform required cleanup. + __value_native__marshaller.Free(); + } + } +} + +file unsafe partial interface InterfaceImplementation +{ + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_GetString(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, byte** __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IUTF8Marshalling @this = default; + byte* __invokeRetValUnmanaged__out = default; + string __invokeRetVal = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.GetString(); + // Marshal - Convert managed data to native data. + __invokeRetValUnmanaged__out = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.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; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_SetString(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, byte* __value_native) + { + global::SharedTypes.ComInterfaces.IUTF8Marshalling @this = default; + string value = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + value = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__value_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.SetString(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.IUTF8Marshalling), 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_GetString; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_SetString; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IUTF8Marshalling + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IUTF8Marshalling + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.cs new file mode 100644 index 0000000..be3f6fb --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.cs @@ -0,0 +1,227 @@ +// +#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[] { 149, 115, 133, 164, 251, 6, 110, 74, 129, 219, 53, 70, 27, 233, 153, 197 })); + + 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.MarshallingFails.ICollectionMarshallingFails +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + int[] global::SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.Get(out int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out size); + int[] __retVal; + nint* __retVal_native; + int __invokeRetVal; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __size_native, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal_native__numElements = size; + __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + System.Span __retVal_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal); + for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + { + __retVal_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.ConvertToManaged(__retVal_native__nativeSpan[__i0]); + } + } + + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.Set(int[] value, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails)); + nint* __value_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __value_native__marshaller = new(); + int __value_native__numElements; + int __value_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __value_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __value_native__marshaller.FromManaged(value, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __value_native__managedSpan = __value_native__marshaller.GetManagedValuesSource(); + System.Span __value_native__nativeSpan = __value_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __value_native__managedSpan.Length; ++__i0, ++__value_native__lastIndexMarshalled) + { + __value_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.ConvertToUnmanaged(__value_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __value_native__unused = __value_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __value_native = __value_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, __value_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __value_native__nativeSpan = __value_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __value_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__value_native__nativeSpan[__i0]); + } + } + + __value_native__marshaller.Free(); + } + } +} + +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, int* __size_native__param, nint** __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails @this = default; + int __size_native__out = default; + int size = default; + nint* __invokeRetValUnmanaged__out = default; + int[] __invokeRetVal = default; + int __retVal = default; + // Setup - Perform required setup. + int __invokeRetValUnmanaged__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Get(out size); + // Marshal - Convert managed data to native data. + __size_native__out = size; + __invokeRetValUnmanaged__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); + { + System.ReadOnlySpan __invokeRetValUnmanaged__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__invokeRetVal); + System.Span __invokeRetValUnmanaged__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements); + __invokeRetValUnmanaged__nativeSpan.Clear(); + for (int __i0 = 0; __i0 < __invokeRetValUnmanaged__managedSpan.Length; ++__i0) + { + __invokeRetValUnmanaged__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.ConvertToUnmanaged(__invokeRetValUnmanaged__managedSpan[__i0]); + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + { + System.ReadOnlySpan __invokeRetValUnmanaged__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements); + for (int __i0 = 0; __i0 < __invokeRetValUnmanaged__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__invokeRetValUnmanaged__nativeSpan[__i0]); + } + }; + return __retVal; + } + + // AssignOut - Assign to parameters + *__size_native__param = __size_native__out; + *__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, nint* __value_native, int size) + { + global::SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails @this = default; + int[] value = default; + int __retVal = default; + // Setup - Perform required setup. + int __value_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __value_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __value_native__numElements = size; + value = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__value_native, __value_native__numElements); + { + System.ReadOnlySpan __value_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__value_native, __value_native__numElements); + System.Span __value_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(value); + for (int __i0 = 0; __i0 < __value_native__numElements; ++__i0) + { + __value_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.ConvertToManaged(__value_native__nativeSpan[__i0]); + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Set(value, size); + } + 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.MarshallingFails.ICollectionMarshallingFails), 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.MarshallingFails +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface ICollectionMarshallingFails + { + } +} + +namespace SharedTypes.ComInterfaces.MarshallingFails +{ + internal partial interface ICollectionMarshallingFails + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.cs new file mode 100644 index 0000000..e6577bc --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.cs @@ -0,0 +1,445 @@ +// +#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[] { 169, 168, 164, 159, 143, 61, 168, 72, 182, 251, 180, 91, 95, 27, 159, 182 })); + + 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.MarshallingFails.IJaggedIntArrayMarshallingFails +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + int[][] global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.Get(out int[] widths, out int length) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out widths); + System.Runtime.CompilerServices.Unsafe.SkipInit(out length); + int* __widths_native; + int[][] __retVal; + System.IntPtr* __retVal_native; + int __invokeRetVal; + // Setup - Perform required setup. + int __widths_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __length_native = &length) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, &__widths_native, __length_native, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __widths_native__numElements = length; + widths = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__widths_native, __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__widths_native, __widths_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(widths)); + __retVal_native__numElements = length; + __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + System.Span __retVal_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal); + for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + { + int __retVal_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__nativeSpan____i0__numElements); + __retVal_native__nativeSpan____i0__numElements = widths[__i0]; + __retVal_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((nint*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements); + { + System.ReadOnlySpan __retVal_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements); + System.Span __retVal_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal_native__managedSpan[__i0]); + for (int __i1 = 0; __i1 < __retVal_native__nativeSpan____i0__numElements; ++__i1) + { + __retVal_native__nativeSpan____i0__managedSpan[__i1] = global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.ConvertToManaged(__retVal_native__nativeSpan____i0__nativeSpan[__i1]); + } + } + } + } + + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + int global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.Get2(out int[][] array, out int[] widths) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out array); + System.Runtime.CompilerServices.Unsafe.SkipInit(out widths); + System.IntPtr* __array_native; + int* __widths_native; + int __retVal; + int __invokeRetVal; + // Setup - Perform required setup. + int __widths_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__array_native, &__widths_native, &__retVal); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __widths_native__numElements = __retVal; + widths = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__widths_native, __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__widths_native, __widths_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(widths)); + __array_native__numElements = __retVal; + array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); + { + System.ReadOnlySpan __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements); + System.Span __array_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array); + for (int __i0 = 0; __i0 < __array_native__numElements; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan____i0__numElements = widths[__i0]; + __array_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + { + System.ReadOnlySpan __array_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + System.Span __array_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__array_native__managedSpan[__i0]); + for (int __i1 = 0; __i1 < __array_native__nativeSpan____i0__numElements; ++__i1) + { + __array_native__nativeSpan____i0__managedSpan[__i1] = global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.ConvertToManaged(__array_native__nativeSpan____i0__nativeSpan[__i1]); + } + } + } + } + + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.Set(int[][] array, int[] widths, int length) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails)); + System.IntPtr* __array_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __array_native__marshaller = new(); + int __array_native__numElements; + int __array_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __array_native__marshaller.FromManaged(array, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __array_native__managedSpan = __array_native__marshaller.GetManagedValuesSource(); + System.Span __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __array_native__managedSpan.Length; ++__i0, ++__array_native__lastIndexMarshalled) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan[__i0] = (System.IntPtr)global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__array_native__managedSpan[__i0], out __array_native__nativeSpan____i0__numElements); + { + System.ReadOnlySpan __array_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__array_native__managedSpan[__i0]); + System.Span __array_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan____i0__nativeSpan.Clear(); + for (int __i1 = 0; __i1 < __array_native__nativeSpan____i0__managedSpan.Length; ++__i1) + { + __array_native__nativeSpan____i0__nativeSpan[__i1] = global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.ConvertToUnmanaged(__array_native__nativeSpan____i0__managedSpan[__i1]); + } + } + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __widths_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(widths)) + fixed (void* __array_native__unused = __array_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __array_native = __array_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, __array_native, (int*)__widths_native, length); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __array_native__lastIndexMarshalled; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan____i0__numElements = 0; + { + System.ReadOnlySpan __array_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + for (int __i1 = 0; __i1 < __array_native__nativeSpan____i0__nativeSpan.Length; ++__i1) + { + global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__array_native__nativeSpan____i0__nativeSpan[__i1]); + } + }; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__array_native__nativeSpan[__i0]); + } + } + + __array_native__marshaller.Free(); + } + } +} + +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, int** __widths_native__param, int* __length_native__param, System.IntPtr** __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails @this = default; + int* __widths_native__out = default; + int[] widths = default; + int __length_native__out = default; + int length = default; + System.IntPtr* __invokeRetValUnmanaged__out = default; + int[][] __invokeRetVal = default; + int __retVal = default; + // Setup - Perform required setup. + int __widths_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); + int __invokeRetValUnmanaged__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Get(out widths, out length); + // Marshal - Convert managed data to native data. + __length_native__out = length; + __widths_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(widths, out __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(widths).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__widths_native__out, __widths_native__numElements)); + __invokeRetValUnmanaged__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); + { + System.ReadOnlySpan __invokeRetValUnmanaged__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__invokeRetVal); + System.Span __invokeRetValUnmanaged__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements); + __invokeRetValUnmanaged__nativeSpan.Clear(); + for (int __i0 = 0; __i0 < __invokeRetValUnmanaged__managedSpan.Length; ++__i0) + { + int __invokeRetValUnmanaged__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__nativeSpan____i0__numElements); + __invokeRetValUnmanaged__nativeSpan[__i0] = (System.IntPtr)global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetValUnmanaged__managedSpan[__i0], out __invokeRetValUnmanaged__nativeSpan____i0__numElements); + { + System.ReadOnlySpan __invokeRetValUnmanaged__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__invokeRetValUnmanaged__managedSpan[__i0]); + System.Span __invokeRetValUnmanaged__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__invokeRetValUnmanaged__nativeSpan[__i0], __invokeRetValUnmanaged__nativeSpan____i0__numElements); + __invokeRetValUnmanaged__nativeSpan____i0__nativeSpan.Clear(); + for (int __i1 = 0; __i1 < __invokeRetValUnmanaged__nativeSpan____i0__managedSpan.Length; ++__i1) + { + __invokeRetValUnmanaged__nativeSpan____i0__nativeSpan[__i1] = global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.ConvertToUnmanaged(__invokeRetValUnmanaged__nativeSpan____i0__managedSpan[__i1]); + } + } + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + ; + { + System.ReadOnlySpan __invokeRetValUnmanaged__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements); + for (int __i0 = 0; __i0 < __invokeRetValUnmanaged__nativeSpan.Length; ++__i0) + { + int __invokeRetValUnmanaged__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__nativeSpan____i0__numElements); + __invokeRetValUnmanaged__nativeSpan____i0__numElements = 0; + { + System.ReadOnlySpan __invokeRetValUnmanaged__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__invokeRetValUnmanaged__nativeSpan[__i0], __invokeRetValUnmanaged__nativeSpan____i0__numElements); + for (int __i1 = 0; __i1 < __invokeRetValUnmanaged__nativeSpan____i0__nativeSpan.Length; ++__i1) + { + global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__invokeRetValUnmanaged__nativeSpan____i0__nativeSpan[__i1]); + } + }; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__invokeRetValUnmanaged__nativeSpan[__i0]); + } + }; + return __retVal; + } + + // AssignOut - Assign to parameters + *__length_native__param = __length_native__out; + *__widths_native__param = __widths_native__out; + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Get2(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, System.IntPtr** __array_native__param, int** __widths_native__param, int* __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails @this = default; + System.IntPtr* __array_native__out = default; + int[][] array = default; + int* __widths_native__out = default; + int[] widths = default; + int __invokeRetValUnmanaged__out = default; + int __invokeRetVal = default; + int __retVal = default; + // Setup - Perform required setup. + int __widths_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Get2(out array, out widths); + // Marshal - Convert managed data to native data. + __invokeRetValUnmanaged__out = __invokeRetVal; + __widths_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(widths, out __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(widths).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__widths_native__out, __widths_native__numElements)); + __array_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(array, out __array_native__numElements); + { + System.ReadOnlySpan __array_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(array); + System.Span __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__array_native__out, __array_native__numElements); + __array_native__nativeSpan.Clear(); + for (int __i0 = 0; __i0 < __array_native__managedSpan.Length; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan[__i0] = (System.IntPtr)global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__array_native__managedSpan[__i0], out __array_native__nativeSpan____i0__numElements); + { + System.ReadOnlySpan __array_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__array_native__managedSpan[__i0]); + System.Span __array_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan____i0__nativeSpan.Clear(); + for (int __i1 = 0; __i1 < __array_native__nativeSpan____i0__managedSpan.Length; ++__i1) + { + __array_native__nativeSpan____i0__nativeSpan[__i1] = global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.ConvertToUnmanaged(__array_native__nativeSpan____i0__managedSpan[__i1]); + } + } + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + ; + { + System.ReadOnlySpan __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native__out, __array_native__numElements); + for (int __i0 = 0; __i0 < __array_native__nativeSpan.Length; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan____i0__numElements = 0; + { + System.ReadOnlySpan __array_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + for (int __i1 = 0; __i1 < __array_native__nativeSpan____i0__nativeSpan.Length; ++__i1) + { + global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__array_native__nativeSpan____i0__nativeSpan[__i1]); + } + }; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__array_native__nativeSpan[__i0]); + } + }; + return __retVal; + } + + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + *__widths_native__param = __widths_native__out; + *__array_native__param = __array_native__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, System.IntPtr* __array_native, int* __widths_native, int length) + { + global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails @this = default; + int[][] array = default; + int[] widths = default; + int __retVal = default; + // Setup - Perform required setup. + int __widths_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __widths_native__numElements = length; + widths = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__widths_native, __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__widths_native, __widths_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(widths)); + __array_native__numElements = length; + array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); + { + System.ReadOnlySpan __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements); + System.Span __array_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array); + for (int __i0 = 0; __i0 < __array_native__numElements; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan____i0__numElements = widths[__i0]; + __array_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + { + System.ReadOnlySpan __array_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + System.Span __array_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__array_native__managedSpan[__i0]); + for (int __i1 = 0; __i1 < __array_native__nativeSpan____i0__numElements; ++__i1) + { + __array_native__nativeSpan____i0__managedSpan[__i1] = global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.ConvertToManaged(__array_native__nativeSpan____i0__nativeSpan[__i1]); + } + } + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Set(array, widths, length); + } + 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.MarshallingFails.IJaggedIntArrayMarshallingFails), sizeof(void*) * 6); + { + 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_Get2; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Set; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces.MarshallingFails +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IJaggedIntArrayMarshallingFails + { + } +} + +namespace SharedTypes.ComInterfaces.MarshallingFails +{ + internal partial interface IJaggedIntArrayMarshallingFails + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs new file mode 100644 index 0000000..9d956e9 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs @@ -0,0 +1,669 @@ +// +#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[] { 17, 194, 17, 190, 213, 118, 111, 73, 161, 23, 130, 245, 209, 50, 8, 247 })); + + 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.MarshallingFails.IStringArrayMarshallingFails +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.Param(string[] value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails)); + nint* __value_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __value_native__marshaller = new(); + int __value_native__numElements; + int __value_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __value_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __value_native__marshaller.FromManaged(value, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __value_native__managedSpan = __value_native__marshaller.GetManagedValuesSource(); + System.Span __value_native__nativeSpan = __value_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __value_native__managedSpan.Length; ++__i0, ++__value_native__lastIndexMarshalled) + { + __value_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToUnmanaged(__value_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __value_native__unused = __value_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __value_native = __value_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __value_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + _ = __value_native__lastIndexMarshalled; + __value_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.InParam(in string[] value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails)); + nint* __value_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __value_native__marshaller = new(); + int __value_native__numElements; + int __value_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __value_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __value_native__marshaller.FromManaged(value, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __value_native__managedSpan = __value_native__marshaller.GetManagedValuesSource(); + System.Span __value_native__nativeSpan = __value_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __value_native__managedSpan.Length; ++__i0, ++__value_native__lastIndexMarshalled) + { + __value_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToUnmanaged(__value_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __value_native__unused = __value_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __value_native = __value_native__marshaller.ToUnmanaged(); + __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); + } + finally + { + // Cleanup - Perform required cleanup. + _ = __value_native__lastIndexMarshalled; + __value_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.RefParam(ref string[] value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails)); + nint* __value_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __value_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __value_native__numElements); + int __value_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __value_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(value, out __value_native__numElements); + { + System.ReadOnlySpan __value_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(value); + System.Span __value_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__value_native, __value_native__numElements); + for (int __i0 = 0; __i0 < __value_native__managedSpan.Length; ++__i0, ++__value_native__lastIndexMarshalled) + { + __value_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToUnmanaged(__value_native__managedSpan[__i0]); + } + } + + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__value_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __value_native__numElements = 10; + value = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__value_native, __value_native__numElements); + { + System.ReadOnlySpan __value_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__value_native, __value_native__numElements); + System.Span __value_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(value); + for (int __i0 = 0; __i0 < __value_native__numElements; ++__i0) + { + __value_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToManaged(__value_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + _ = __value_native__lastIndexMarshalled; + __value_native__numElements = 10; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__value_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.OutParam(out string[] value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out value); + nint* __value_native; + int __invokeRetVal; + // Setup - Perform required setup. + int __value_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __value_native__numElements); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__value_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __value_native__numElements = 10; + value = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__value_native, __value_native__numElements); + { + System.ReadOnlySpan __value_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__value_native, __value_native__numElements); + System.Span __value_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(value); + for (int __i0 = 0; __i0 < __value_native__numElements; ++__i0) + { + __value_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToManaged(__value_native__nativeSpan[__i0]); + } + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.ByValueOutParam(string[] value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails)); + nint* __value_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __value_native__marshaller = new(); + int __value_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __value_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __value_native__marshaller.FromManaged(value, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + __value_native__marshaller.GetUnmanagedValuesDestination().Clear(); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __value_native__unused = __value_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __value_native = __value_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, __value_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + { + __value_native__numElements = __value_native__marshaller.GetManagedValuesSource().Length; + System.Span __value_native__managedSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __value_native__marshaller.GetManagedValuesSource().GetPinnableReference()), __value_native__numElements); + System.Span __value_native__nativeSpan = __value_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __value_native__numElements; ++__i0) + { + __value_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToManaged(__value_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + __value_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.ByValueInOutParam(string[] value) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails)); + nint* __value_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __value_native__marshaller = new(); + int __value_native__numElements; + int __value_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __value_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __value_native__marshaller.FromManaged(value, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __value_native__managedSpan = __value_native__marshaller.GetManagedValuesSource(); + System.Span __value_native__nativeSpan = __value_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __value_native__managedSpan.Length; ++__i0, ++__value_native__lastIndexMarshalled) + { + __value_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToUnmanaged(__value_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __value_native__unused = __value_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __value_native = __value_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this, __value_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + { + __value_native__numElements = __value_native__marshaller.GetManagedValuesSource().Length; + System.Span __value_native__managedSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __value_native__marshaller.GetManagedValuesSource().GetPinnableReference()), __value_native__numElements); + System.Span __value_native__nativeSpan = __value_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __value_native__numElements; ++__i0) + { + __value_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToManaged(__value_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + _ = __value_native__lastIndexMarshalled; + __value_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + string[] global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.ReturnValue() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails)); + string[] __retVal; + nint* __retVal_native; + int __invokeRetVal; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[9])(__this, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal_native__numElements = 10; + __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + System.Span __retVal_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal); + for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + { + __retVal_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToManaged(__retVal_native__nativeSpan[__i0]); + } + } + + return __retVal; + } +} + +file unsafe partial interface InterfaceImplementation +{ + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Param(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __value_native) + { + global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails @this = default; + string[] value = default; + int __retVal = default; + // Setup - Perform required setup. + int __value_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __value_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __value_native__numElements = 10; + value = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__value_native, __value_native__numElements); + { + System.ReadOnlySpan __value_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__value_native, __value_native__numElements); + System.Span __value_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(value); + for (int __i0 = 0; __i0 < __value_native__numElements; ++__i0) + { + __value_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToManaged(__value_native__nativeSpan[__i0]); + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Param(value); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_InParam(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint** __value_native__param) + { + global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails @this = default; + nint* __value_native = *__value_native__param; + string[] value = default; + int __retVal = default; + // Setup - Perform required setup. + int __value_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __value_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __value_native__numElements = 10; + value = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__value_native, __value_native__numElements); + { + System.ReadOnlySpan __value_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__value_native, __value_native__numElements); + System.Span __value_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(value); + for (int __i0 = 0; __i0 < __value_native__numElements; ++__i0) + { + __value_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToManaged(__value_native__nativeSpan[__i0]); + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.InParam(in value); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_RefParam(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint** __value_native__param) + { + global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails @this = default; + nint* __value_native__out = default; + nint* __value_native = *__value_native__param; + string[] value = default; + int __retVal = default; + // Setup - Perform required setup. + int __value_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __value_native__numElements); + int __value_native__lastIndexMarshalled = 0; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __value_native__numElements = 10; + value = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__value_native, __value_native__numElements); + { + System.ReadOnlySpan __value_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__value_native, __value_native__numElements); + System.Span __value_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(value); + for (int __i0 = 0; __i0 < __value_native__numElements; ++__i0) + { + __value_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToManaged(__value_native__nativeSpan[__i0]); + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.RefParam(ref value); + // Marshal - Convert managed data to native data. + __value_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(value, out __value_native__numElements); + { + System.ReadOnlySpan __value_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(value); + System.Span __value_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__value_native__out, __value_native__numElements); + for (int __i0 = 0; __i0 < __value_native__managedSpan.Length; ++__i0, ++__value_native__lastIndexMarshalled) + { + __value_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToUnmanaged(__value_native__managedSpan[__i0]); + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + _ = __value_native__lastIndexMarshalled; + __value_native__numElements = 10; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__value_native__out); + return __retVal; + } + + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; + // Cleanup - Perform required cleanup. + _ = __value_native__lastIndexMarshalled; + __value_native__numElements = 10; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__value_native); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_OutParam(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint** __value_native__param) + { + global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails @this = default; + nint* __value_native__out = default; + string[] value = default; + int __retVal = default; + // Setup - Perform required setup. + int __value_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __value_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.OutParam(out value); + // Marshal - Convert managed data to native data. + __value_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(value, out __value_native__numElements); + { + System.ReadOnlySpan __value_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(value); + System.Span __value_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__value_native__out, __value_native__numElements); + __value_native__nativeSpan.Clear(); + for (int __i0 = 0; __i0 < __value_native__managedSpan.Length; ++__i0) + { + __value_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToUnmanaged(__value_native__managedSpan[__i0]); + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + ; + return __retVal; + } + + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_ByValueOutParam(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __value_native) + { + global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails @this = default; + string[] value = default; + int __retVal = default; + // Setup - Perform required setup. + int __value_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __value_native__numElements); + System.Span __value_native__out; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(value).Clear(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.ByValueOutParam(value); + // Marshal - Convert managed data to native data. + { + __value_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(value).Length; +#pragma warning disable CS9081 + __value_native__out = stackalloc nint[__value_native__numElements]; +#pragma warning restore CS9081 + System.Span __value_native__nativeSpan = __value_native__out; + System.Span __value_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(value); + for (int __i0 = 0; __i0 < __value_native__numElements; ++__i0) + { + nint __value_native__nativeSpan____i0__original = __value_native__nativeSpan[__i0]; + __value_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToUnmanaged(__value_native__managedSpan[__i0]); + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + __value_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__value_native, __value_native__numElements).GetPinnableReference()), __value_native__numElements)); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_ByValueInOutParam(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __value_native) + { + global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails @this = default; + string[] value = default; + int __retVal = default; + // Setup - Perform required setup. + int __value_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __value_native__numElements); + System.Span __value_native__out; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __value_native__numElements = 10; + value = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__value_native, __value_native__numElements); + { + System.ReadOnlySpan __value_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__value_native, __value_native__numElements); + System.Span __value_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(value); + for (int __i0 = 0; __i0 < __value_native__numElements; ++__i0) + { + __value_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToManaged(__value_native__nativeSpan[__i0]); + } + } + + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.ByValueInOutParam(value); + // Marshal - Convert managed data to native data. + { + __value_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(value).Length; +#pragma warning disable CS9081 + __value_native__out = stackalloc nint[__value_native__numElements]; +#pragma warning restore CS9081 + System.Span __value_native__nativeSpan = __value_native__out; + System.Span __value_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(value); + for (int __i0 = 0; __i0 < __value_native__numElements; ++__i0) + { + nint __value_native__nativeSpan____i0__original = __value_native__nativeSpan[__i0]; + __value_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToUnmanaged(__value_native__managedSpan[__i0]); + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + // AssignOut - Assign to parameters + __value_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__value_native, __value_native__numElements).GetPinnableReference()), __value_native__numElements)); + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_ReturnValue(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint** __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails @this = default; + nint* __invokeRetValUnmanaged__out = default; + string[] __invokeRetVal = default; + int __retVal = default; + // Setup - Perform required setup. + int __invokeRetValUnmanaged__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.ReturnValue(); + // Marshal - Convert managed data to native data. + __invokeRetValUnmanaged__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); + { + System.ReadOnlySpan __invokeRetValUnmanaged__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__invokeRetVal); + System.Span __invokeRetValUnmanaged__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements); + __invokeRetValUnmanaged__nativeSpan.Clear(); + for (int __i0 = 0; __i0 < __invokeRetValUnmanaged__managedSpan.Length; ++__i0) + { + __invokeRetValUnmanaged__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToUnmanaged(__invokeRetValUnmanaged__managedSpan[__i0]); + } + } + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + ; + return __retVal; + } + + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + return __retVal; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails), sizeof(void*) * 10); + { + 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_Param; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_InParam; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_RefParam; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_OutParam; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_ByValueOutParam; + vtable[8] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_ByValueInOutParam; + vtable[9] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_ReturnValue; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces.MarshallingFails +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IStringArrayMarshallingFails + { + } +} + +namespace SharedTypes.ComInterfaces.MarshallingFails +{ + internal partial interface IStringArrayMarshallingFails + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/ManagedToNativeStubs.g.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/ManagedToNativeStubs.g.cs new file mode 100644 index 0000000..845a3ba --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/ManagedToNativeStubs.g.cs @@ -0,0 +1,575 @@ +// +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class ImplicitThis + { + internal unsafe partial interface INativeObject + { + internal unsafe partial interface Native + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + int global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject.GetData() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)); + int __retVal; + { + __retVal = ((delegate* unmanaged )__vtable_native[0])(__this); + } + + System.GC.KeepAlive(this); + return __retVal; + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class ImplicitThis + { + internal unsafe partial interface INativeObject + { + internal unsafe partial interface Native + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject.SetData(int x) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)); + { + ((delegate* unmanaged )__vtable_native[1])(__this, x); + } + + System.GC.KeepAlive(this); + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class ImplicitThis + { + internal unsafe partial interface INativeObject + { + internal unsafe partial interface Native + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject.ExchangeData(ref int x) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __x_native = &x) + { + ((delegate* unmanaged )__vtable_native[2])(__this, __x_native); + } + + System.GC.KeepAlive(this); + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class ImplicitThis + { + internal unsafe partial interface INativeObject + { + internal unsafe partial interface Native + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject.SumAndSetData(int[] values, int numValues, out int oldValue) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out oldValue); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __oldValue_native = &oldValue) + fixed (void* __values_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(values)) + { + ((delegate* unmanaged )__vtable_native[3])(__this, (int*)__values_native, numValues, __oldValue_native); + } + + System.GC.KeepAlive(this); + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class ImplicitThis + { + internal unsafe partial interface INativeObject + { + internal unsafe partial interface Native + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject.SumAndSetData(ref int[] values, int numValues, out int oldValue) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out oldValue); + int* __values_native = default; + // Setup - Perform required setup. + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(values).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __oldValue_native = &oldValue) + { + ((delegate* unmanaged )__vtable_native[4])(__this, &__values_native, numValues, __oldValue_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; + values = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values)); + } + finally + { + // Cleanup - Perform required cleanup. + __values_native__numElements = numValues; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values_native); + } + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class ImplicitThis + { + internal unsafe partial interface INativeObject + { + internal unsafe partial interface Native + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject.MultiplyWithData(int[] values, int numValues) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __values_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(values)) + { + ((delegate* unmanaged )__vtable_native[5])(__this, (int*)__values_native, numValues); + } + + System.GC.KeepAlive(this); + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class NoImplicitThis + { + internal unsafe partial interface IStaticMethodTable + { + internal unsafe partial interface Native + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + int global::ComInterfaceGenerator.Tests.NativeExportsNE.NoImplicitThis.IStaticMethodTable.Add(int x, int y) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::ComInterfaceGenerator.Tests.NativeExportsNE.NoImplicitThis.IStaticMethodTable)); + int __retVal; + { + __retVal = ((delegate* unmanaged )__vtable_native[0])(x, y); + } + + System.GC.KeepAlive(this); + return __retVal; + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class NoImplicitThis + { + internal unsafe partial interface IStaticMethodTable + { + internal unsafe partial interface Native + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + int global::ComInterfaceGenerator.Tests.NativeExportsNE.NoImplicitThis.IStaticMethodTable.Multiply(int x, int y) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::ComInterfaceGenerator.Tests.NativeExportsNE.NoImplicitThis.IStaticMethodTable)); + int __retVal; + { + __retVal = ((delegate* unmanaged )__vtable_native[1])(x, y); + } + + System.GC.KeepAlive(this); + return __retVal; + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class UnmanagedToManagedCustomMarshalling + { + internal unsafe partial interface INativeObject + { + internal unsafe partial interface Native + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.IntWrapper global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject.GetData() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)); + global::SharedTypes.IntWrapper __retVal = default; + int __retVal_native = default; + try + { + { + __retVal_native = ((delegate* unmanaged )__vtable_native[0])(__this); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + __retVal = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__retVal_native); + } + + return __retVal; + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class UnmanagedToManagedCustomMarshalling + { + internal unsafe partial interface INativeObject + { + internal unsafe partial interface Native + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject.SetData(global::SharedTypes.IntWrapper x) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)); + int __x_native = default; + try + { + // Marshal - Convert managed data to native data. + __x_native = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(x); + { + ((delegate* unmanaged )__vtable_native[1])(__this, __x_native); + } + + System.GC.KeepAlive(this); + } + finally + { + // Cleanup - Perform required cleanup. + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__x_native); + } + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class UnmanagedToManagedCustomMarshalling + { + internal unsafe partial interface INativeObject + { + internal unsafe partial interface Native + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject.ExchangeData(ref global::SharedTypes.IntWrapper data) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)); + int __data_native = default; + try + { + // Marshal - Convert managed data to native data. + __data_native = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(data); + { + ((delegate* unmanaged )__vtable_native[2])(__this, &__data_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + data = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__data_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__data_native); + } + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class UnmanagedToManagedCustomMarshalling + { + internal unsafe partial interface INativeObject + { + internal unsafe partial interface Native + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject.SumAndSetData(global::SharedTypes.IntWrapper[] values, int numValues, out global::SharedTypes.IntWrapper oldValue) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out oldValue); + int* __values_native = default; + int __oldValue_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __values_native__marshaller = new(); + int __values_native__numElements; + int __values_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native__marshaller.FromManaged(values, stackalloc int[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __values_native__managedSpan = __values_native__marshaller.GetManagedValuesSource(); + System.Span __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __values_native__managedSpan.Length; ++__i0, ++__values_native__lastIndexMarshalled) + { + __values_native__nativeSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(__values_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __values_native__unused = __values_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __values_native = __values_native__marshaller.ToUnmanaged(); + ((delegate* unmanaged )__vtable_native[3])(__this, __values_native, numValues, &__oldValue_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + oldValue = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__oldValue_native); + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __values_native__lastIndexMarshalled; ++__i0) + { + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values_native__nativeSpan[__i0]); + } + } + + __values_native__marshaller.Free(); + } + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class UnmanagedToManagedCustomMarshalling + { + internal unsafe partial interface INativeObject + { + internal unsafe partial interface Native + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject.SumAndSetData(ref global::SharedTypes.IntWrapper[] values, int numValues, out global::SharedTypes.IntWrapper oldValue) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out oldValue); + int* __values_native = default; + int __oldValue_native = default; + // Setup - Perform required setup. + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + int __values_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __values_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); + { + System.ReadOnlySpan __values_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(values); + System.Span __values_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements); + for (int __i0 = 0; __i0 < __values_native__managedSpan.Length; ++__i0, ++__values_native__lastIndexMarshalled) + { + __values_native__nativeSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(__values_native__managedSpan[__i0]); + } + } + + { + ((delegate* unmanaged )__vtable_native[4])(__this, &__values_native, numValues, &__oldValue_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + oldValue = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__oldValue_native); + __values_native__numElements = numValues; + values = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); + { + System.ReadOnlySpan __values_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements); + System.Span __values_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values); + for (int __i0 = 0; __i0 < __values_native__numElements; ++__i0) + { + __values_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __values_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements); + for (int __i0 = 0; __i0 < __values_native__lastIndexMarshalled; ++__i0) + { + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values_native__nativeSpan[__i0]); + } + } + + __values_native__numElements = numValues; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values_native); + } + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class UnmanagedToManagedCustomMarshalling + { + internal unsafe partial interface INativeObject + { + internal unsafe partial interface Native + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject.MultiplyWithData(global::SharedTypes.IntWrapper[] values123, int numValues) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)); + int* __values123_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __values123_native__marshaller = new(); + int __values123_native__numElements; + int __values123_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values123_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values123_native__marshaller.FromManaged(values123, stackalloc int[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __values123_native__managedSpan = __values123_native__marshaller.GetManagedValuesSource(); + System.Span __values123_native__nativeSpan = __values123_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __values123_native__managedSpan.Length; ++__i0, ++__values123_native__lastIndexMarshalled) + { + __values123_native__nativeSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(__values123_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __values123_native__unused = __values123_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __values123_native = __values123_native__marshaller.ToUnmanaged(); + ((delegate* unmanaged )__vtable_native[5])(__this, __values123_native, numValues); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + { + __values123_native__numElements = __values123_native__marshaller.GetManagedValuesSource().Length; + System.Span __values123_native__managedSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __values123_native__marshaller.GetManagedValuesSource().GetPinnableReference()), __values123_native__numElements); + System.Span __values123_native__nativeSpan = __values123_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __values123_native__numElements; ++__i0) + { + __values123_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values123_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __values123_native__nativeSpan = __values123_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __values123_native__lastIndexMarshalled; ++__i0) + { + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values123_native__nativeSpan[__i0]); + } + } + + __values123_native__marshaller.Free(); + } + } + } + } + } + } +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeInterfaces.g.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeInterfaces.g.cs new file mode 100644 index 0000000..16c3004 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeInterfaces.g.cs @@ -0,0 +1,65 @@ +// +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class ImplicitThis + { + internal unsafe partial interface INativeObject + { + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] + internal partial interface Native : INativeObject + { + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class NoImplicitThis + { + internal unsafe partial interface IStaticMethodTable + { + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] + internal partial interface Native : IStaticMethodTable + { + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class UnmanagedToManagedCustomMarshalling + { + internal unsafe partial interface INativeObject + { + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] + internal partial interface Native : INativeObject + { + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class UnmanagedToManagedCustomMarshalling + { + internal unsafe partial interface INativeObjectStateful + { + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] + internal partial interface Native : INativeObjectStateful + { + } + } + } + } +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeToManagedStubs.g.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeToManagedStubs.g.cs new file mode 100644 index 0000000..add8a5f --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeToManagedStubs.g.cs @@ -0,0 +1,630 @@ +// +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class ImplicitThis + { + internal unsafe partial interface INativeObject + { + internal unsafe partial interface Native + { + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] + internal static int ABI_GetData(void* __this_native) + { + global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject @this; + int __retVal = default; + // Unmarshal - Convert native data to managed data. + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + __retVal = @this.GetData(); + return __retVal; + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class ImplicitThis + { + internal unsafe partial interface INativeObject + { + internal unsafe partial interface Native + { + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] + internal static void ABI_SetData(void* __this_native, int x) + { + global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject @this; + // Unmarshal - Convert native data to managed data. + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.SetData(x); + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class ImplicitThis + { + internal unsafe partial interface INativeObject + { + internal unsafe partial interface Native + { + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] + internal static void ABI_ExchangeData(void* __this_native, int* __x_native__param) + { + global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject @this; + int __x_native__out = default; + int __x_native = *__x_native__param; + int x; + // Unmarshal - Convert native data to managed data. + x = __x_native; + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.ExchangeData(ref x); + // Marshal - Convert managed data to native data. + __x_native__out = x; + // AssignOut - Assign to parameters + *__x_native__param = __x_native__out; + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class ImplicitThis + { + internal unsafe partial interface INativeObject + { + internal unsafe partial interface Native + { + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] + internal static void ABI_SumAndSetData(void* __this_native, int* __values_native, int numValues, int* __oldValue_native__param) + { + global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject @this; + int[] values; + int __oldValue_native__out = default; + int oldValue; + // Setup - Perform required setup. + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; + values = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values)); + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.SumAndSetData(values, numValues, out oldValue); + // Marshal - Convert managed data to native data. + __oldValue_native__out = oldValue; + // AssignOut - Assign to parameters + *__oldValue_native__param = __oldValue_native__out; + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class ImplicitThis + { + internal unsafe partial interface INativeObject + { + internal unsafe partial interface Native + { + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] + internal static void ABI_SumAndSetData(void* __this_native, int** __values_native__param, int numValues, int* __oldValue_native__param) + { + global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject @this = default; + int* __values_native__out = default; + int* __values_native = *__values_native__param; + int[] values = default; + int __oldValue_native__out = default; + int oldValue = default; + // Setup - Perform required setup. + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; + values = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values)); + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.SumAndSetData(ref values, numValues, out oldValue); + // Marshal - Convert managed data to native data. + __oldValue_native__out = oldValue; + __values_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(values).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__values_native__out, __values_native__numElements)); + // AssignOut - Assign to parameters + *__oldValue_native__param = __oldValue_native__out; + *__values_native__param = __values_native__out; + // Cleanup - Perform required cleanup. + __values_native__numElements = numValues; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values_native); + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class ImplicitThis + { + internal unsafe partial interface INativeObject + { + internal unsafe partial interface Native + { + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] + internal static void ABI_MultiplyWithData(void* __this_native, int* __values_native, int numValues) + { + global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject @this; + int[] values; + // Setup - Perform required setup. + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; + values = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values)); + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.MultiplyWithData(values, numValues); + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class UnmanagedToManagedCustomMarshalling + { + internal unsafe partial interface INativeObject + { + internal unsafe partial interface Native + { + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] + internal static int ABI_GetData(void* __this_native) + { + global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject @this; + global::SharedTypes.IntWrapper __retVal; + int __retVal_native = default; + // Unmarshal - Convert native data to managed data. + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + __retVal = @this.GetData(); + // Marshal - Convert managed data to native data. + __retVal_native = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(__retVal); + return __retVal_native; + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class UnmanagedToManagedCustomMarshalling + { + internal unsafe partial interface INativeObject + { + internal unsafe partial interface Native + { + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] + internal static void ABI_SetData(void* __this_native, int __x_native) + { + global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject @this; + global::SharedTypes.IntWrapper x; + // Unmarshal - Convert native data to managed data. + x = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__x_native); + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.SetData(x); + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class UnmanagedToManagedCustomMarshalling + { + internal unsafe partial interface INativeObject + { + internal unsafe partial interface Native + { + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] + internal static void ABI_ExchangeData(void* __this_native, int* __data_native__param) + { + global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject @this = default; + int __data_native__out = default; + int __data_native = *__data_native__param; + global::SharedTypes.IntWrapper data = default; + // Unmarshal - Convert native data to managed data. + data = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__data_native); + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.ExchangeData(ref data); + // Marshal - Convert managed data to native data. + __data_native__out = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(data); + // AssignOut - Assign to parameters + *__data_native__param = __data_native__out; + // Cleanup - Perform required cleanup. + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__data_native); + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class UnmanagedToManagedCustomMarshalling + { + internal unsafe partial interface INativeObject + { + internal unsafe partial interface Native + { + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] + internal static void ABI_SumAndSetData(void* __this_native, int* __values_native, int numValues, int* __oldValue_native__param) + { + global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject @this; + global::SharedTypes.IntWrapper[] values; + int __oldValue_native__out = default; + global::SharedTypes.IntWrapper oldValue; + // Setup - Perform required setup. + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; + values = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); + { + System.ReadOnlySpan __values_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements); + System.Span __values_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values); + for (int __i0 = 0; __i0 < __values_native__numElements; ++__i0) + { + __values_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values_native__nativeSpan[__i0]); + } + } + + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.SumAndSetData(values, numValues, out oldValue); + // Marshal - Convert managed data to native data. + __oldValue_native__out = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(oldValue); + // AssignOut - Assign to parameters + *__oldValue_native__param = __oldValue_native__out; + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class UnmanagedToManagedCustomMarshalling + { + internal unsafe partial interface INativeObject + { + internal unsafe partial interface Native + { + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] + internal static void ABI_SumAndSetData(void* __this_native, int** __values_native__param, int numValues, int* __oldValue_native__param) + { + global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject @this = default; + int* __values_native__out = default; + int* __values_native = *__values_native__param; + global::SharedTypes.IntWrapper[] values = default; + int __oldValue_native__out = default; + global::SharedTypes.IntWrapper oldValue = default; + // Setup - Perform required setup. + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + int __values_native__lastIndexMarshalled = 0; + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; + values = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); + { + System.ReadOnlySpan __values_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements); + System.Span __values_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values); + for (int __i0 = 0; __i0 < __values_native__numElements; ++__i0) + { + __values_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values_native__nativeSpan[__i0]); + } + } + + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.SumAndSetData(ref values, numValues, out oldValue); + // Marshal - Convert managed data to native data. + __oldValue_native__out = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(oldValue); + __values_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); + { + System.ReadOnlySpan __values_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(values); + System.Span __values_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__values_native__out, __values_native__numElements); + for (int __i0 = 0; __i0 < __values_native__managedSpan.Length; ++__i0, ++__values_native__lastIndexMarshalled) + { + __values_native__nativeSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(__values_native__managedSpan[__i0]); + } + } + + // AssignOut - Assign to parameters + *__oldValue_native__param = __oldValue_native__out; + *__values_native__param = __values_native__out; + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __values_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements); + for (int __i0 = 0; __i0 < __values_native__lastIndexMarshalled; ++__i0) + { + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values_native__nativeSpan[__i0]); + } + } + + __values_native__numElements = numValues; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values_native); + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class UnmanagedToManagedCustomMarshalling + { + internal unsafe partial interface INativeObject + { + internal unsafe partial interface Native + { + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] + internal static void ABI_MultiplyWithData(void* __this_native, int* __values123_native, int numValues) + { + global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject @this; + global::SharedTypes.IntWrapper[] values123; + // Setup - Perform required setup. + int __values123_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values123_native__numElements); + System.Span __values123_native__out; + // Unmarshal - Convert native data to managed data. + __values123_native__numElements = numValues; + values123 = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values123_native, __values123_native__numElements); + { + System.ReadOnlySpan __values123_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values123_native, __values123_native__numElements); + System.Span __values123_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values123); + for (int __i0 = 0; __i0 < __values123_native__numElements; ++__i0) + { + __values123_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values123_native__nativeSpan[__i0]); + } + } + + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.MultiplyWithData(values123, numValues); + // Marshal - Convert managed data to native data. + { + __values123_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values123).Length; +#pragma warning disable CS9081 + __values123_native__out = stackalloc int[__values123_native__numElements]; +#pragma warning restore CS9081 + System.Span __values123_native__nativeSpan = __values123_native__out; + System.Span __values123_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values123); + for (int __i0 = 0; __i0 < __values123_native__numElements; ++__i0) + { + int __values123_native__nativeSpan____i0__original = __values123_native__nativeSpan[__i0]; + __values123_native__nativeSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(__values123_native__managedSpan[__i0]); + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values123_native__nativeSpan____i0__original); + } + } + + // AssignOut - Assign to parameters + __values123_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values123_native, __values123_native__numElements).GetPinnableReference()), __values123_native__numElements)); + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class UnmanagedToManagedCustomMarshalling + { + internal unsafe partial interface INativeObjectStateful + { + internal unsafe partial interface Native + { + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] + internal static void ABI_SumAndSetData(void* __this_native, int* __values_native, int numValues, int* __oldValue_native__param) + { + global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObjectStateful @this = default; + global::SharedTypes.IntWrapper[] values = default; + int __oldValue_native__out = default; + global::SharedTypes.IntWrapper oldValue = default; + // Setup - Perform required setup. + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.StatefulUnmanagedToManagedCollectionMarshaller.In __values_native__marshaller = new(); + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __values_native__marshaller.FromUnmanaged(__values_native); + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; + { + System.ReadOnlySpan __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesSource(__values_native__numElements); + System.Span __values_native__managedSpan = __values_native__marshaller.GetManagedValuesDestination(__values_native__numElements); + for (int __i0 = 0; __i0 < __values_native__numElements; ++__i0) + { + __values_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values_native__nativeSpan[__i0]); + } + } + + values = __values_native__marshaller.ToManaged(); + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObjectStateful)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.SumAndSetData(values, numValues, out oldValue); + // Marshal - Convert managed data to native data. + __oldValue_native__out = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(oldValue); + // AssignOut - Assign to parameters + *__oldValue_native__param = __oldValue_native__out; + // Cleanup - Perform required cleanup. + __values_native__marshaller.Free(); + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class UnmanagedToManagedCustomMarshalling + { + internal unsafe partial interface INativeObjectStateful + { + internal unsafe partial interface Native + { + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] + internal static void ABI_SumAndSetData(void* __this_native, int** __values_native__param, int numValues, int* __oldValue_native__param) + { + global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObjectStateful @this = default; + int* __values_native__out = default; + int* __values_native = *__values_native__param; + global::SharedTypes.IntWrapper[] values = default; + int __oldValue_native__out = default; + global::SharedTypes.IntWrapper oldValue = default; + // Setup - Perform required setup. + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.StatefulUnmanagedToManagedCollectionMarshaller.Ref __values_native__marshaller = new(); + int __values_native__numElements; + int __values_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __values_native__marshaller.FromUnmanaged(__values_native); + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; + { + System.ReadOnlySpan __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesSource(__values_native__numElements); + System.Span __values_native__managedSpan = __values_native__marshaller.GetManagedValuesDestination(__values_native__numElements); + for (int __i0 = 0; __i0 < __values_native__numElements; ++__i0) + { + __values_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values_native__nativeSpan[__i0]); + } + } + + values = __values_native__marshaller.ToManaged(); + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObjectStateful)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.SumAndSetData(ref values, numValues, out oldValue); + // Marshal - Convert managed data to native data. + __oldValue_native__out = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(oldValue); + __values_native__marshaller.FromManaged(values); + { + System.ReadOnlySpan __values_native__managedSpan = __values_native__marshaller.GetManagedValuesSource(); + System.Span __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __values_native__managedSpan.Length; ++__i0, ++__values_native__lastIndexMarshalled) + { + __values_native__nativeSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(__values_native__managedSpan[__i0]); + } + } + + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __values_native__out = __values_native__marshaller.ToUnmanaged(); + // AssignOut - Assign to parameters + *__oldValue_native__param = __oldValue_native__out; + *__values_native__param = __values_native__out; + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesSource(__values_native__numElements); + for (int __i0 = 0; __i0 < __values_native__lastIndexMarshalled; ++__i0) + { + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values_native__nativeSpan[__i0]); + } + } + + __values_native__marshaller.Free(); + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class UnmanagedToManagedCustomMarshalling + { + internal unsafe partial interface INativeObjectStateful + { + internal unsafe partial interface Native + { + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] + internal static void ABI_MultiplyWithData(void* __this_native, int* __values123_native, int numValues) + { + global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObjectStateful @this = default; + global::SharedTypes.IntWrapper[] values123 = default; + // Setup - Perform required setup. + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.StatefulUnmanagedToManagedCollectionMarshaller.In __values123_native__marshaller = new(); + int __values123_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values123_native__numElements); + System.Span __values123_native__out; + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __values123_native__marshaller.FromUnmanaged(__values123_native); + // Unmarshal - Convert native data to managed data. + __values123_native__numElements = numValues; + { + System.ReadOnlySpan __values123_native__nativeSpan = __values123_native__marshaller.GetUnmanagedValuesSource(__values123_native__numElements); + System.Span __values123_native__managedSpan = __values123_native__marshaller.GetManagedValuesDestination(__values123_native__numElements); + for (int __i0 = 0; __i0 < __values123_native__numElements; ++__i0) + { + __values123_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values123_native__nativeSpan[__i0]); + } + } + + values123 = __values123_native__marshaller.ToManaged(); + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObjectStateful)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.MultiplyWithData(values123, numValues); + // Marshal - Convert managed data to native data. + { + __values123_native__numElements = __values123_native__marshaller.GetManagedValuesDestination(__values123_native__numElements).Length; +#pragma warning disable CS9081 + __values123_native__out = stackalloc int[__values123_native__numElements]; +#pragma warning restore CS9081 + System.Span __values123_native__nativeSpan = __values123_native__out; + System.Span __values123_native__managedSpan = __values123_native__marshaller.GetManagedValuesDestination(__values123_native__numElements); + for (int __i0 = 0; __i0 < __values123_native__numElements; ++__i0) + { + int __values123_native__nativeSpan____i0__original = __values123_native__nativeSpan[__i0]; + __values123_native__nativeSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(__values123_native__managedSpan[__i0]); + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values123_native__nativeSpan____i0__original); + } + } + + // AssignOut - Assign to parameters + __values123_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __values123_native__marshaller.GetUnmanagedValuesSource(__values123_native__numElements).GetPinnableReference()), __values123_native__numElements)); + // Cleanup - Perform required cleanup. + __values123_native__marshaller.Free(); + } + } + } + } + } +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/PopulateVTable.g.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/PopulateVTable.g.cs new file mode 100644 index 0000000..90c87a9 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/PopulateVTable.g.cs @@ -0,0 +1,70 @@ +// +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class ImplicitThis + { + internal unsafe partial interface INativeObject + { + internal unsafe partial interface Native + { + internal static unsafe void PopulateUnmanagedVirtualMethodTable(void** vtable) + { + vtable[0] = (void*)(delegate* unmanaged )&ABI_GetData; + vtable[1] = (void*)(delegate* unmanaged )&ABI_SetData; + vtable[2] = (void*)(delegate* unmanaged )&ABI_ExchangeData; + vtable[3] = (void*)(delegate* unmanaged )&ABI_SumAndSetData; + vtable[4] = (void*)(delegate* unmanaged )&ABI_SumAndSetData; + vtable[5] = (void*)(delegate* unmanaged )&ABI_MultiplyWithData; + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class UnmanagedToManagedCustomMarshalling + { + internal unsafe partial interface INativeObject + { + internal unsafe partial interface Native + { + internal static unsafe void PopulateUnmanagedVirtualMethodTable(void** vtable) + { + vtable[0] = (void*)(delegate* unmanaged )&ABI_GetData; + vtable[1] = (void*)(delegate* unmanaged )&ABI_SetData; + vtable[2] = (void*)(delegate* unmanaged )&ABI_ExchangeData; + vtable[3] = (void*)(delegate* unmanaged )&ABI_SumAndSetData; + vtable[4] = (void*)(delegate* unmanaged )&ABI_SumAndSetData; + vtable[5] = (void*)(delegate* unmanaged )&ABI_MultiplyWithData; + } + } + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class UnmanagedToManagedCustomMarshalling + { + internal unsafe partial interface INativeObjectStateful + { + internal unsafe partial interface Native + { + internal static unsafe void PopulateUnmanagedVirtualMethodTable(void** vtable) + { + vtable[3] = (void*)(delegate* unmanaged )&ABI_SumAndSetData; + vtable[4] = (void*)(delegate* unmanaged )&ABI_SumAndSetData; + vtable[5] = (void*)(delegate* unmanaged )&ABI_MultiplyWithData; + } + } + } + } + } +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs new file mode 100644 index 0000000..fd35f4d --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs @@ -0,0 +1,460 @@ +// +namespace ComInterfaceGenerator.Tests +{ + unsafe partial class NativeExportsNE + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "set_com_object_data", ExactSpelling = true)] + public static extern partial void SetComObjectData(void* obj, int data); + } +} +namespace ComInterfaceGenerator.Tests +{ + unsafe partial class NativeExportsNE + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "get_com_object_data", ExactSpelling = true)] + public static extern partial int GetComObjectData(void* obj); + } +} +namespace ComInterfaceGenerator.Tests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void SetComObjectData(global::SharedTypes.ComInterfaces.IGetAndSetInt obj, int data) + { + void* __obj_native = default; + try + { + // Marshal - Convert managed data to native data. + __obj_native = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(obj); + { + __PInvoke(__obj_native, data); + } + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__obj_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "set_com_object_data", ExactSpelling = true)] + static extern unsafe void __PInvoke(void* __obj_native, int __data_native); + } + } +} +namespace ComInterfaceGenerator.Tests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int GetComObjectData(global::SharedTypes.ComInterfaces.IGetAndSetInt obj) + { + void* __obj_native = default; + int __retVal = default; + try + { + // Marshal - Convert managed data to native data. + __obj_native = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(obj); + { + __retVal = __PInvoke(__obj_native); + } + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__obj_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "get_com_object_data", ExactSpelling = true)] + static extern unsafe int __PInvoke(void* __obj_native); + } + } +} +namespace ComInterfaceGenerator.Tests +{ + public unsafe partial class GeneratedComInterfaceComImportInteropTests + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + private static partial global::SharedTypes.ComInterfaces.IGetAndSetInt NewNativeObject() + { + global::SharedTypes.ComInterfaces.IGetAndSetInt __retVal = default; + void* __retVal_native = default; + try + { + { + __retVal_native = __PInvoke(); + } + + // Unmarshal - Convert native data to managed data. + __retVal = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__retVal_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "new_get_and_set_int", ExactSpelling = true)] + static extern unsafe void* __PInvoke(); + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "get_com_object", ExactSpelling = true)] + public static extern partial void* NewNativeObject(); + } +} +namespace ComInterfaceGenerator.Tests +{ + public unsafe partial class IGetAndSetIntTests + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "new_get_and_set_int", ExactSpelling = true)] + public static extern partial void* NewNativeObject(); + } +} +namespace ComInterfaceGenerator.Tests +{ + public unsafe partial class IGetAndSetIntTests + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + internal static partial global::SharedTypes.ComInterfaces.IGetAndSetInt NewNativeObjectWithMarshaller() + { + global::SharedTypes.ComInterfaces.IGetAndSetInt __retVal = default; + void* __retVal_native = default; + try + { + { + __retVal_native = __PInvoke(); + } + + // Unmarshal - Convert native data to managed data. + __retVal = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__retVal_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "new_get_and_set_int", ExactSpelling = true)] + static extern unsafe void* __PInvoke(); + } + } +} +namespace ComInterfaceGenerator.Tests +{ + public unsafe partial class IGetAndSetIntTests + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + internal static partial global::SharedTypes.ComInterfaces.IGetAndSetInt NewNativeObjectWithUniqueMarshaller() + { + global::SharedTypes.ComInterfaces.IGetAndSetInt __retVal = default; + void* __retVal_native = default; + try + { + { + __retVal_native = __PInvoke(); + } + + // Unmarshal - Convert native data to managed data. + __retVal = global::System.Runtime.InteropServices.Marshalling.UniqueComInterfaceMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.UniqueComInterfaceMarshaller.Free(__retVal_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "new_get_and_set_int", ExactSpelling = true)] + static extern unsafe void* __PInvoke(); + } + } +} +namespace ComInterfaceGenerator.Tests +{ + public unsafe partial class IGetIntArrayTests + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "new_get_and_set_int_array", ExactSpelling = true)] + public static extern partial void* NewNativeObject(); + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class ImplicitThis + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.NativeObject NewNativeObject() + { + global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.NativeObject __retVal; + void* __retVal_native; + { + __retVal_native = __PInvoke(); + } + + // Unmarshal - Convert native data to managed data. + __retVal = global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.NativeObjectMarshaller.ConvertToManaged(__retVal_native); + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "new_native_object", ExactSpelling = true)] + static extern unsafe void* __PInvoke(); + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class ImplicitThis + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "delete_native_object", ExactSpelling = true)] + public static extern partial void DeleteNativeObject(void* obj); + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class ImplicitThis + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "set_native_object_data", ExactSpelling = true)] + public static extern partial void SetNativeObjectData(void* obj, int data); + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class ImplicitThis + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "get_native_object_data", ExactSpelling = true)] + public static extern partial int GetNativeObjectData(void* obj); + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class NoImplicitThis + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::ComInterfaceGenerator.Tests.NativeExportsNE.NoImplicitThis.StaticMethodTable GetStaticFunctionTable() + { + global::ComInterfaceGenerator.Tests.NativeExportsNE.NoImplicitThis.StaticMethodTable __retVal; + void* __retVal_native; + { + __retVal_native = __PInvoke(); + } + + // Unmarshal - Convert native data to managed data. + __retVal = global::ComInterfaceGenerator.Tests.NativeExportsNE.NoImplicitThis.StaticMethodTableMarshaller.ConvertToManaged(__retVal_native); + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "get_static_function_table", ExactSpelling = true)] + static extern unsafe void* __PInvoke(); + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + public unsafe partial class PreserveSigTests + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_point_provider", ExactSpelling = true)] + public static extern partial void* NewNativeObject(); + } +} +namespace ComInterfaceGenerator.Tests +{ + public unsafe partial class StringMarshallingTests + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "new_utf8_marshalling", ExactSpelling = true)] + public static extern partial void* NewIUtf8Marshalling(); + } +} +namespace ComInterfaceGenerator.Tests +{ + public unsafe partial class StringMarshallingTests + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "new_utf16_marshalling", ExactSpelling = true)] + public static extern partial void* NewIUtf16Marshalling(); + } +} +namespace ComInterfaceGenerator.Tests +{ + public unsafe partial class StringMarshallingTests + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "new_string_marshalling_override", ExactSpelling = true)] + public static extern partial void* NewStringMarshallingOverride(); + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class UnmanagedToManagedCustomMarshalling + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "set_native_object_data", ExactSpelling = true)] + public static extern partial void SetNativeObjectData(void* obj, int data); + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class UnmanagedToManagedCustomMarshalling + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "get_native_object_data", ExactSpelling = true)] + public static extern partial int GetNativeObjectData(void* obj); + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class UnmanagedToManagedCustomMarshalling + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ExchangeNativeObjectData(void* obj, ref int x) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __x_native = &x) + { + __retVal = __PInvoke(obj, __x_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "exchange_native_object_data", ExactSpelling = true)] + static extern unsafe int __PInvoke(void* __obj_native, int* __x_native); + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class UnmanagedToManagedCustomMarshalling + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int SumAndSetNativeObjectData(void* obj, int[] arr, int numValues, out int oldValue) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out oldValue); + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __oldValue_native = &oldValue) + fixed (void* __arr_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(arr)) + { + __retVal = __PInvoke(obj, (int*)__arr_native, numValues, __oldValue_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_and_set_native_object_data", ExactSpelling = true)] + static extern unsafe int __PInvoke(void* __obj_native, int* __arr_native, int __numValues_native, int* __oldValue_native); + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class UnmanagedToManagedCustomMarshalling + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int SumAndSetNativeObjectData(void* obj, ref int[] arr, int numValues, out int oldValue) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out oldValue); + int* __arr_native = default; + int __retVal = default; + // Setup - Perform required setup. + int __arr_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __arr_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __arr_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(arr, out __arr_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(arr).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__arr_native, __arr_native__numElements)); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __oldValue_native = &oldValue) + { + __retVal = __PInvoke(obj, &__arr_native, numValues, __oldValue_native); + } + + // Unmarshal - Convert native data to managed data. + __arr_native__numElements = numValues; + arr = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__arr_native, __arr_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__arr_native, __arr_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(arr)); + } + finally + { + // Cleanup - Perform required cleanup. + __arr_native__numElements = numValues; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__arr_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_and_set_native_object_data_with_ref", ExactSpelling = true)] + static extern unsafe int __PInvoke(void* __obj_native, int** __arr_native, int __numValues_native, int* __oldValue_native); + } + } + } +} +namespace ComInterfaceGenerator.Tests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class UnmanagedToManagedCustomMarshalling + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int MultiplyWithNativeObjectData(void* obj, int[] arr, int numValues) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __arr_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(arr)) + { + __retVal = __PInvoke(obj, (int*)__arr_native, numValues); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "multiply_with_native_object_data", ExactSpelling = true)] + static extern unsafe int __PInvoke(void* __obj_native, int* __arr_native, int __numValues_native); + } + } + } +} diff --git a/LibraryImportGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs b/LibraryImportGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs new file mode 100644 index 0000000..f647cd2 --- /dev/null +++ b/LibraryImportGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs @@ -0,0 +1,8225 @@ +// +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int Sum(int[] values, int numValues) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __values_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(values)) + { + __retVal = __PInvoke((int*)__values_native, numValues); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array", ExactSpelling = true)] + static extern unsafe int __PInvoke(int* __values_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int Sum(ref int values, int numValues) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __values_native = &values) + { + __retVal = __PInvoke(__values_native, numValues); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array", ExactSpelling = true)] + static extern unsafe int __PInvoke(int* __values_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int SumInArray(in int[] values, int numValues) + { + int* __values_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __values_native__marshaller = new(); + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native__marshaller.FromManaged(values, stackalloc int[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + __values_native__marshaller.GetManagedValuesSource().CopyTo(__values_native__marshaller.GetUnmanagedValuesDestination()); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __values_native__unused = __values_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __values_native = __values_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(&__values_native, numValues); + } + } + finally + { + // Cleanup - Perform required cleanup. + __values_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array_ref", ExactSpelling = true)] + static extern unsafe int __PInvoke(int** __values_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Duplicate(ref int[] values, int numValues) + { + int* __values_native = default; + // Setup - Perform required setup. + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(values).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); + { + __PInvoke(&__values_native, numValues); + } + + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; + values = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values)); + } + finally + { + // Cleanup - Perform required cleanup. + __values_native__numElements = numValues; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "duplicate_int_array", ExactSpelling = true)] + static extern unsafe void __PInvoke(int** __values_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int[] CreateRange(int start, int end, out int numValues) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); + int[] __retVal = default; + int* __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __numValues_native = &numValues) + { + __retVal_native = __PInvoke(start, end, __numValues_native); + } + + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = numValues; + __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal)); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_native__numElements = numValues; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array", ExactSpelling = true)] + static extern unsafe int* __PInvoke(int __start_native, int __end_native, int* __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void CreateRange_Out(int start, int end, out int numValues, out int[] res) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); + System.Runtime.CompilerServices.Unsafe.SkipInit(out res); + int* __res_native; + // Setup - Perform required setup. + int __res_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __res_native__numElements); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __numValues_native = &numValues) + { + __PInvoke(start, end, __numValues_native, &__res_native); + } + + // Unmarshal - Convert native data to managed data. + __res_native__numElements = numValues; + res = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__res_native, __res_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__res_native, __res_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(res)); + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array_out", ExactSpelling = true)] + static extern unsafe void __PInvoke(int __start_native, int __end_native, int* __numValues_native, int** __res_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int SumChars(char[] chars, int numElements) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __chars_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(chars)) + { + __retVal = __PInvoke((char*)__chars_native, numElements); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_char_array", ExactSpelling = true)] + static extern unsafe int __PInvoke(char* __chars_native, int __numElements_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void FillChars(char[] chars, int length, ushort start) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __chars_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(chars)) + { + __PInvoke((char*)__chars_native, length, start); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "fill_char_array", ExactSpelling = true)] + static extern unsafe void __PInvoke(char* __chars_native, int __length_native, ushort __start_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReverseChars(ref char[] chars, int numElements) + { + char* __chars_native = default; + // Setup - Perform required setup. + int __chars_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __chars_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __chars_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(chars, out __chars_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(chars).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__chars_native, __chars_native__numElements)); + { + __PInvoke(&__chars_native, numElements); + } + + // Unmarshal - Convert native data to managed data. + __chars_native__numElements = numElements; + chars = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__chars_native, __chars_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__chars_native, __chars_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(chars)); + } + finally + { + // Cleanup - Perform required cleanup. + __chars_native__numElements = numElements; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__chars_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_char_array", ExactSpelling = true)] + static extern unsafe void __PInvoke(char** __chars_native, int __numElements_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int SumStringLengths(string[] strArray) + { + System.IntPtr* __strArray_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __strArray_native__marshaller = new(); + int __strArray_native__numElements; + int __strArray_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __strArray_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __strArray_native__marshaller.FromManaged(strArray, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __strArray_native__managedSpan = __strArray_native__marshaller.GetManagedValuesSource(); + System.Span __strArray_native__nativeSpan = __strArray_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __strArray_native__managedSpan.Length; ++__i0, ++__strArray_native__lastIndexMarshalled) + { + __strArray_native__nativeSpan[__i0] = (System.IntPtr)(ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__strArray_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __strArray_native__unused = __strArray_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __strArray_native = __strArray_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(__strArray_native); + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __strArray_native__nativeSpan = __strArray_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __strArray_native__lastIndexMarshalled; ++__i0) + { + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free((ushort*)__strArray_native__nativeSpan[__i0]); + } + } + + __strArray_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_string_lengths", ExactSpelling = true)] + static extern unsafe int __PInvoke(System.IntPtr* __strArray_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReverseStrings_Ref(ref string[] strArray, out int numElements) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out numElements); + System.IntPtr* __strArray_native = default; + // Setup - Perform required setup. + int __strArray_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __strArray_native__numElements); + int __strArray_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __strArray_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(strArray, out __strArray_native__numElements); + { + System.ReadOnlySpan __strArray_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(strArray); + System.Span __strArray_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__strArray_native, __strArray_native__numElements); + for (int __i0 = 0; __i0 < __strArray_native__managedSpan.Length; ++__i0, ++__strArray_native__lastIndexMarshalled) + { + __strArray_native__nativeSpan[__i0] = (System.IntPtr)(ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__strArray_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __numElements_native = &numElements) + { + __PInvoke(&__strArray_native, __numElements_native); + } + + // Unmarshal - Convert native data to managed data. + __strArray_native__numElements = numElements; + strArray = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__strArray_native, __strArray_native__numElements); + { + System.ReadOnlySpan __strArray_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__strArray_native, __strArray_native__numElements); + System.Span __strArray_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(strArray); + for (int __i0 = 0; __i0 < __strArray_native__numElements; ++__i0) + { + __strArray_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged((ushort*)__strArray_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __strArray_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__strArray_native, __strArray_native__numElements); + for (int __i0 = 0; __i0 < __strArray_native__lastIndexMarshalled; ++__i0) + { + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free((ushort*)__strArray_native__nativeSpan[__i0]); + } + } + + __strArray_native__numElements = numElements; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__strArray_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_strings_replace", ExactSpelling = true)] + static extern unsafe void __PInvoke(System.IntPtr** __strArray_native, int* __numElements_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial string[] ReverseStrings_Return(string[] strArray, out int numElements) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out numElements); + System.IntPtr* __strArray_native = default; + string[] __retVal = default; + System.IntPtr* __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __strArray_native__marshaller = new(); + int __strArray_native__numElements; + int __strArray_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __strArray_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __strArray_native__marshaller.FromManaged(strArray, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __strArray_native__managedSpan = __strArray_native__marshaller.GetManagedValuesSource(); + System.Span __strArray_native__nativeSpan = __strArray_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __strArray_native__managedSpan.Length; ++__i0, ++__strArray_native__lastIndexMarshalled) + { + __strArray_native__nativeSpan[__i0] = (System.IntPtr)(ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__strArray_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __numElements_native = &numElements) + fixed (void* __strArray_native__unused = __strArray_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __strArray_native = __strArray_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__strArray_native, __numElements_native); + } + + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = numElements; + __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + System.Span __retVal_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal); + for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + { + __retVal_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged((ushort*)__retVal_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__retVal_native, __retVal_native__numElements); + for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + { + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free((ushort*)__retVal_native__nativeSpan[__i0]); + } + } + + __retVal_native__numElements = numElements; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + { + System.ReadOnlySpan __strArray_native__nativeSpan = __strArray_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __strArray_native__lastIndexMarshalled; ++__i0) + { + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free((ushort*)__strArray_native__nativeSpan[__i0]); + } + } + + __strArray_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_strings_return", ExactSpelling = true)] + static extern unsafe System.IntPtr* __PInvoke(System.IntPtr* __strArray_native, int* __numElements_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReverseStrings_Out(string[] strArray, out int numElements, out string[] res) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out numElements); + System.Runtime.CompilerServices.Unsafe.SkipInit(out res); + System.IntPtr* __strArray_native = default; + System.IntPtr* __res_native = default; + // Setup - Perform required setup. + int __res_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __res_native__numElements); + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __strArray_native__marshaller = new(); + int __strArray_native__numElements; + int __strArray_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __strArray_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __strArray_native__marshaller.FromManaged(strArray, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __strArray_native__managedSpan = __strArray_native__marshaller.GetManagedValuesSource(); + System.Span __strArray_native__nativeSpan = __strArray_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __strArray_native__managedSpan.Length; ++__i0, ++__strArray_native__lastIndexMarshalled) + { + __strArray_native__nativeSpan[__i0] = (System.IntPtr)(ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__strArray_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __numElements_native = &numElements) + fixed (void* __strArray_native__unused = __strArray_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __strArray_native = __strArray_native__marshaller.ToUnmanaged(); + __PInvoke(__strArray_native, __numElements_native, &__res_native); + } + + // Unmarshal - Convert native data to managed data. + __res_native__numElements = numElements; + res = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__res_native, __res_native__numElements); + { + System.ReadOnlySpan __res_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__res_native, __res_native__numElements); + System.Span __res_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(res); + for (int __i0 = 0; __i0 < __res_native__numElements; ++__i0) + { + __res_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged((ushort*)__res_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __strArray_native__nativeSpan = __strArray_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __strArray_native__lastIndexMarshalled; ++__i0) + { + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free((ushort*)__strArray_native__nativeSpan[__i0]); + } + } + + __strArray_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_strings_out", ExactSpelling = true)] + static extern unsafe void __PInvoke(System.IntPtr* __strArray_native, int* __numElements_native, System.IntPtr** __res_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial byte[] GetLongBytes(long l) + { + byte[] __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + { + __retVal_native = __PInvoke(l); + } + + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = 8; + __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal)); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_native__numElements = 8; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "get_long_bytes", ExactSpelling = true)] + static extern unsafe byte* __PInvoke(long __l_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Append(ref int[] values, int numOriginalValues, int newValue) + { + int* __values_native = default; + // Setup - Perform required setup. + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(values).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); + { + __PInvoke(&__values_native, numOriginalValues, newValue); + } + + // Unmarshal - Convert native data to managed data. + __values_native__numElements = checked(1 + numOriginalValues); + values = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values)); + } + finally + { + // Cleanup - Perform required cleanup. + __values_native__numElements = checked(1 + numOriginalValues); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "append_int_to_array", ExactSpelling = true)] + static extern unsafe void __PInvoke(int** __values_native, int __numOriginalValues_native, int __newValue_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool FillRangeArray(global::SharedTypes.IntStructWrapper[] array, int length, int start) + { + global::SharedTypes.IntStructWrapperNative* __array_native = default; + bool __retVal = default; + byte __retVal_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __array_native__marshaller = new(); + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __array_native__marshaller.FromManaged(array, stackalloc global::SharedTypes.IntStructWrapperNative[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + __array_native__marshaller.GetUnmanagedValuesDestination().Clear(); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __array_native__unused = __array_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __array_native = __array_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__array_native, length, start); + } + + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + { + __array_native__numElements = __array_native__marshaller.GetManagedValuesSource().Length; + System.Span __array_native__managedSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __array_native__marshaller.GetManagedValuesSource().GetPinnableReference()), __array_native__numElements); + System.Span __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __array_native__numElements; ++__i0) + { + __array_native__managedSpan[__i0] = global::SharedTypes.IntStructWrapperMarshaller.ConvertToManaged(__array_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + __array_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "fill_range_array", ExactSpelling = true)] + static extern unsafe byte __PInvoke(global::SharedTypes.IntStructWrapperNative* __array_native, int __length_native, int __start_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void DoubleValues(global::SharedTypes.IntStructWrapper[] array, int length) + { + global::SharedTypes.IntStructWrapperNative* __array_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __array_native__marshaller = new(); + int __array_native__numElements; + int __array_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __array_native__marshaller.FromManaged(array, stackalloc global::SharedTypes.IntStructWrapperNative[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __array_native__managedSpan = __array_native__marshaller.GetManagedValuesSource(); + System.Span __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __array_native__managedSpan.Length; ++__i0, ++__array_native__lastIndexMarshalled) + { + __array_native__nativeSpan[__i0] = global::SharedTypes.IntStructWrapperMarshaller.ConvertToUnmanaged(__array_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __array_native__unused = __array_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __array_native = __array_native__marshaller.ToUnmanaged(); + __PInvoke(__array_native, length); + } + + // Unmarshal - Convert native data to managed data. + { + __array_native__numElements = __array_native__marshaller.GetManagedValuesSource().Length; + System.Span __array_native__managedSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __array_native__marshaller.GetManagedValuesSource().GetPinnableReference()), __array_native__numElements); + System.Span __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __array_native__numElements; ++__i0) + { + __array_native__managedSpan[__i0] = global::SharedTypes.IntStructWrapperMarshaller.ConvertToManaged(__array_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + _ = __array_native__lastIndexMarshalled; + __array_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "double_values", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.IntStructWrapperNative* __array_native, int __length_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool AndAllMembers(global::SharedTypes.BoolStruct[] pArray, int length) + { + global::SharedTypes.BoolStructMarshaller.BoolStructNative* __pArray_native = default; + bool __retVal = default; + byte __retVal_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __pArray_native__marshaller = new(); + int __pArray_native__numElements; + int __pArray_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pArray_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __pArray_native__marshaller.FromManaged(pArray, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __pArray_native__managedSpan = __pArray_native__marshaller.GetManagedValuesSource(); + System.Span __pArray_native__nativeSpan = __pArray_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __pArray_native__managedSpan.Length; ++__i0, ++__pArray_native__lastIndexMarshalled) + { + __pArray_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__pArray_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __pArray_native__unused = __pArray_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pArray_native = __pArray_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__pArray_native, length); + } + + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + } + finally + { + // Cleanup - Perform required cleanup. + _ = __pArray_native__lastIndexMarshalled; + __pArray_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "and_bool_struct_array", ExactSpelling = true)] + static extern unsafe byte __PInvoke(global::SharedTypes.BoolStructMarshaller.BoolStructNative* __pArray_native, int __length_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool AndAllMembersIn(in global::SharedTypes.BoolStruct[] pArray, int length) + { + global::SharedTypes.BoolStructMarshaller.BoolStructNative* __pArray_native = default; + bool __retVal = default; + byte __retVal_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __pArray_native__marshaller = new(); + int __pArray_native__numElements; + int __pArray_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pArray_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __pArray_native__marshaller.FromManaged(pArray, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __pArray_native__managedSpan = __pArray_native__marshaller.GetManagedValuesSource(); + System.Span __pArray_native__nativeSpan = __pArray_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __pArray_native__managedSpan.Length; ++__i0, ++__pArray_native__lastIndexMarshalled) + { + __pArray_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__pArray_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __pArray_native__unused = __pArray_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pArray_native = __pArray_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(&__pArray_native, length); + } + + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + } + finally + { + // Cleanup - Perform required cleanup. + _ = __pArray_native__lastIndexMarshalled; + __pArray_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "and_bool_struct_array_in", ExactSpelling = true)] + static extern unsafe byte __PInvoke(global::SharedTypes.BoolStructMarshaller.BoolStructNative** __pArray_native, int __length_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void NegateBools(ref global::SharedTypes.BoolStruct[] boolStruct, int numValues) + { + global::SharedTypes.BoolStructMarshaller.BoolStructNative* __boolStruct_native = default; + // Setup - Perform required setup. + int __boolStruct_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + int __boolStruct_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(boolStruct, out __boolStruct_native__numElements); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(boolStruct); + System.Span __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); + } + } + + { + __PInvoke(&__boolStruct_native, numValues); + } + + // Unmarshal - Convert native data to managed data. + __boolStruct_native__numElements = numValues; + boolStruct = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__boolStruct_native, __boolStruct_native__numElements); + { + System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__boolStruct_native, __boolStruct_native__numElements); + System.Span __boolStruct_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(boolStruct); + for (int __i0 = 0; __i0 < __boolStruct_native__numElements; ++__i0) + { + __boolStruct_native__managedSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__boolStruct_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + _ = __boolStruct_native__lastIndexMarshalled; + __boolStruct_native__numElements = numValues; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__boolStruct_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_ref", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.BoolStructMarshaller.BoolStructNative** __boolStruct_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void NegateBools(global::SharedTypes.BoolStruct[] boolStruct, int numValues, out global::SharedTypes.BoolStruct[] pBoolStructOut) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out pBoolStructOut); + global::SharedTypes.BoolStructMarshaller.BoolStructNative* __boolStruct_native = default; + global::SharedTypes.BoolStructMarshaller.BoolStructNative* __pBoolStructOut_native = default; + // Setup - Perform required setup. + int __pBoolStructOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pBoolStructOut_native__numElements); + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __boolStruct_native__marshaller = new(); + int __boolStruct_native__numElements; + int __boolStruct_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native__marshaller.FromManaged(boolStruct, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = __boolStruct_native__marshaller.GetManagedValuesSource(); + System.Span __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __boolStruct_native__unused = __boolStruct_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __boolStruct_native = __boolStruct_native__marshaller.ToUnmanaged(); + __PInvoke(__boolStruct_native, numValues, &__pBoolStructOut_native); + } + + // Unmarshal - Convert native data to managed data. + __pBoolStructOut_native__numElements = numValues; + pBoolStructOut = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__pBoolStructOut_native, __pBoolStructOut_native__numElements); + { + System.ReadOnlySpan __pBoolStructOut_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__pBoolStructOut_native, __pBoolStructOut_native__numElements); + System.Span __pBoolStructOut_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(pBoolStructOut); + for (int __i0 = 0; __i0 < __pBoolStructOut_native__numElements; ++__i0) + { + __pBoolStructOut_native__managedSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__pBoolStructOut_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + _ = __boolStruct_native__lastIndexMarshalled; + __boolStruct_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_out", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.BoolStructMarshaller.BoolStructNative* __boolStruct_native, int __numValues_native, global::SharedTypes.BoolStructMarshaller.BoolStructNative** __pBoolStructOut_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::SharedTypes.BoolStruct[] NegateBools(global::SharedTypes.BoolStruct[] boolStruct, int numValues) + { + global::SharedTypes.BoolStructMarshaller.BoolStructNative* __boolStruct_native = default; + global::SharedTypes.BoolStruct[] __retVal = default; + global::SharedTypes.BoolStructMarshaller.BoolStructNative* __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __boolStruct_native__marshaller = new(); + int __boolStruct_native__numElements; + int __boolStruct_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native__marshaller.FromManaged(boolStruct, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = __boolStruct_native__marshaller.GetManagedValuesSource(); + System.Span __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __boolStruct_native__unused = __boolStruct_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __boolStruct_native = __boolStruct_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__boolStruct_native, numValues); + } + + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = numValues; + __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + System.Span __retVal_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal); + for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + { + __retVal_native__managedSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__retVal_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_native__numElements = numValues; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + _ = __boolStruct_native__lastIndexMarshalled; + __boolStruct_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_return", ExactSpelling = true)] + static extern unsafe global::SharedTypes.BoolStructMarshaller.BoolStructNative* __PInvoke(global::SharedTypes.BoolStructMarshaller.BoolStructNative* __boolStruct_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int[][] TransposeMatrix(int[][] matrix, int[] numRows, int numColumns) + { + System.IntPtr* __matrix_native = default; + int[][] __retVal = default; + System.IntPtr* __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __matrix_native__marshaller = new(); + int __matrix_native__numElements; + int __matrix_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __matrix_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __matrix_native__marshaller.FromManaged(matrix, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __matrix_native__managedSpan = __matrix_native__marshaller.GetManagedValuesSource(); + System.Span __matrix_native__nativeSpan = __matrix_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __matrix_native__managedSpan.Length; ++__i0, ++__matrix_native__lastIndexMarshalled) + { + int __matrix_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __matrix_native__nativeSpan____i0__numElements); + __matrix_native__nativeSpan[__i0] = (System.IntPtr)global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__matrix_native__managedSpan[__i0], out __matrix_native__nativeSpan____i0__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__matrix_native__managedSpan[__i0]).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((int*)__matrix_native__nativeSpan[__i0], __matrix_native__nativeSpan____i0__numElements)); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __numRows_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(numRows)) + fixed (void* __matrix_native__unused = __matrix_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __matrix_native = __matrix_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__matrix_native, (int*)__numRows_native, numColumns); + } + + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = numColumns; + __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + System.Span __retVal_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal); + for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + { + int __retVal_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__nativeSpan____i0__numElements); + __retVal_native__nativeSpan____i0__numElements = numRows[__i0]; + __retVal_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((int*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((int*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal_native__managedSpan[__i0])); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__retVal_native, __retVal_native__numElements); + for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + { + int __retVal_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__nativeSpan____i0__numElements); + __retVal_native__nativeSpan____i0__numElements = numRows[__i0]; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((int*)__retVal_native__nativeSpan[__i0]); + } + } + + __retVal_native__numElements = numColumns; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + { + System.ReadOnlySpan __matrix_native__nativeSpan = __matrix_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __matrix_native__lastIndexMarshalled; ++__i0) + { + int __matrix_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __matrix_native__nativeSpan____i0__numElements); + ; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((int*)__matrix_native__nativeSpan[__i0]); + } + } + + __matrix_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "transpose_matrix", ExactSpelling = true)] + static extern unsafe System.IntPtr* __PInvoke(System.IntPtr* __matrix_native, int* __numRows_native, int __numColumns_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static unsafe partial int Sum(int*[] values, int numValues) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __values_native = &global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(values)) + { + __retVal = __PInvoke((nint*)__values_native, numValues); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_ptr_array", ExactSpelling = true)] + static extern unsafe int __PInvoke(nint* __values_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static unsafe partial int SumInArray(in int*[] values, int numValues) + { + nint* __values_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.ManagedToUnmanagedIn __values_native__marshaller = new(); + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native__marshaller.FromManaged(values, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + __values_native__marshaller.GetManagedValuesSource().CopyTo(__values_native__marshaller.GetUnmanagedValuesDestination()); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __values_native__unused = __values_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __values_native = __values_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(&__values_native, numValues); + } + } + finally + { + // Cleanup - Perform required cleanup. + __values_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_ptr_array_ref", ExactSpelling = true)] + static extern unsafe int __PInvoke(nint** __values_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static unsafe partial void Duplicate(ref int*[] values, int numValues) + { + nint* __values_native = default; + // Setup - Perform required setup. + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native = global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.GetManagedValuesSource(values).CopyTo(global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); + { + __PInvoke(&__values_native, numValues); + } + + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; + values = global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.GetManagedValuesDestination(values)); + } + finally + { + // Cleanup - Perform required cleanup. + __values_native__numElements = numValues; + global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.Free(__values_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "duplicate_int_ptr_array", ExactSpelling = true)] + static extern unsafe void __PInvoke(nint** __values_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static unsafe partial int*[] ReturnDuplicate(int*[] values, int numValues) + { + int*[] __retVal = default; + nint* __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __values_native = &global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(values)) + { + __retVal_native = __PInvoke((nint*)__values_native, numValues); + } + + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = numValues; + __retVal = global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.GetManagedValuesDestination(__retVal)); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_native__numElements = numValues; + global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.Free(__retVal_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_duplicate_int_ptr_array", ExactSpelling = true)] + static extern unsafe nint* __PInvoke(nint* __values_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "blittablestructs_return_instance", ExactSpelling = true)] + public static extern partial global::SharedTypes.IntFields DoubleIntFields(global::SharedTypes.IntFields result); + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void DoubleIntFieldsByRef(ref global::SharedTypes.IntFields result) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (global::SharedTypes.IntFields* __result_native = &result) + { + __PInvoke(__result_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "blittablestructs_double_intfields_byref", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.IntFields* __result_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void DoubleIntFieldsByRefIn(in global::SharedTypes.IntFields result) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (global::SharedTypes.IntFields* __result_native = &result) + { + __PInvoke(__result_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "blittablestructs_double_intfields_byref", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.IntFields* __result_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void DoubleIntFieldsRefReturn(global::SharedTypes.IntFields input, ref global::SharedTypes.IntFields result) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (global::SharedTypes.IntFields* __result_native = &result) + { + __PInvoke(input, __result_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "blittablestructs_double_intfields_refreturn", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.IntFields __input_native, global::SharedTypes.IntFields* __result_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void DoubleIntFieldsOutReturn(global::SharedTypes.IntFields input, out global::SharedTypes.IntFields result) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out result); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (global::SharedTypes.IntFields* __result_native = &result) + { + __PInvoke(input, __result_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "blittablestructs_double_intfields_refreturn", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.IntFields __input_native, global::SharedTypes.IntFields* __result_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void IncrementInvertPointerFieldsByRef(ref global::SharedTypes.PointerFields result) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (global::SharedTypes.PointerFields* __result_native = &result) + { + __PInvoke(__result_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "blittablestructs_increment_invert_ptrfields_byref", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.PointerFields* __result_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void IncrementInvertPointerFieldsByRefIn(in global::SharedTypes.PointerFields result) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (global::SharedTypes.PointerFields* __result_native = &result) + { + __PInvoke(__result_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "blittablestructs_increment_invert_ptrfields_byref", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.PointerFields* __result_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void IncrementInvertPointerFieldsRefReturn(global::SharedTypes.PointerFields input, ref global::SharedTypes.PointerFields result) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (global::SharedTypes.PointerFields* __result_native = &result) + { + __PInvoke(input, __result_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "blittablestructs_increment_invert_ptrfields_refreturn", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.PointerFields __input_native, global::SharedTypes.PointerFields* __result_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial uint ReturnByteBoolAsUInt(bool input) + { + byte __input_native; + uint __retVal; + // Marshal - Convert managed data to native data. + __input_native = (byte)(input ? 1 : 0); + { + __retVal = __PInvoke(__input_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "bytebool_return_as_uint", ExactSpelling = true)] + static extern unsafe uint __PInvoke(byte __input_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial uint ReturnSByteBoolAsUInt(bool input) + { + sbyte __input_native; + uint __retVal; + // Marshal - Convert managed data to native data. + __input_native = (sbyte)(input ? 1 : 0); + { + __retVal = __PInvoke(__input_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "bytebool_return_as_uint", ExactSpelling = true)] + static extern unsafe uint __PInvoke(sbyte __input_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial uint ReturnVariantBoolAsUInt(bool input) + { + short __input_native; + uint __retVal; + // Marshal - Convert managed data to native data. + __input_native = (short)(input ? -1 : 0); + { + __retVal = __PInvoke(__input_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "variantbool_return_as_uint", ExactSpelling = true)] + static extern unsafe uint __PInvoke(short __input_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial uint ReturnIntBoolAsUInt(bool input) + { + int __input_native; + uint __retVal; + // Marshal - Convert managed data to native data. + __input_native = (int)(input ? 1 : 0); + { + __retVal = __PInvoke(__input_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "winbool_return_as_uint", ExactSpelling = true)] + static extern unsafe uint __PInvoke(int __input_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial uint ReturnUIntBoolAsUInt(bool input) + { + uint __input_native; + uint __retVal; + // Marshal - Convert managed data to native data. + __input_native = (uint)(input ? 1 : 0); + { + __retVal = __PInvoke(__input_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "winbool_return_as_uint", ExactSpelling = true)] + static extern unsafe uint __PInvoke(uint __input_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial uint ReturnWinBoolAsUInt(bool input) + { + int __input_native; + uint __retVal; + // Marshal - Convert managed data to native data. + __input_native = (int)(input ? 1 : 0); + { + __retVal = __PInvoke(__input_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "winbool_return_as_uint", ExactSpelling = true)] + static extern unsafe uint __PInvoke(int __input_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool ReturnUIntAsByteBool(uint input) + { + bool __retVal; + byte __retVal_native; + { + __retVal_native = __PInvoke(input); + } + + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "winbool_return_as_uint", ExactSpelling = true)] + static extern unsafe byte __PInvoke(uint __input_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool ReturnUIntAsVariantBool(uint input) + { + bool __retVal; + short __retVal_native; + { + __retVal_native = __PInvoke(input); + } + + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native == -1; + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "winbool_return_as_uint", ExactSpelling = true)] + static extern unsafe short __PInvoke(uint __input_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool ReturnUIntAsWinBool(uint input) + { + bool __retVal; + int __retVal_native; + { + __retVal_native = __PInvoke(input); + } + + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "winbool_return_as_uint", ExactSpelling = true)] + static extern unsafe int __PInvoke(uint __input_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReturnUIntAsByteBool_Ref(uint input, ref bool res) + { + byte __res_native; + // Marshal - Convert managed data to native data. + __res_native = (byte)(res ? 1 : 0); + { + __PInvoke(input, &__res_native); + } + + // Unmarshal - Convert native data to managed data. + res = __res_native != 0; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "uint_return_as_refbool", ExactSpelling = true)] + static extern unsafe void __PInvoke(uint __input_native, byte* __res_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReturnUIntAsByteBool_Out(uint input, out bool res) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out res); + byte __res_native; + { + __PInvoke(input, &__res_native); + } + + // Unmarshal - Convert native data to managed data. + res = __res_native != 0; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "uint_return_as_refbool", ExactSpelling = true)] + static extern unsafe void __PInvoke(uint __input_native, byte* __res_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReturnUIntAsByteBool_In(uint input, in bool res) + { + byte __res_native; + // Marshal - Convert managed data to native data. + __res_native = (byte)(res ? 1 : 0); + { + __PInvoke(input, &__res_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "uint_return_as_refbool", ExactSpelling = true)] + static extern unsafe void __PInvoke(uint __input_native, byte* __res_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReturnUIntAsVariantBool_Ref(uint input, ref bool res) + { + short __res_native; + // Marshal - Convert managed data to native data. + __res_native = (short)(res ? -1 : 0); + { + __PInvoke(input, &__res_native); + } + + // Unmarshal - Convert native data to managed data. + res = __res_native == -1; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "uint_return_as_refvariantbool", ExactSpelling = true)] + static extern unsafe void __PInvoke(uint __input_native, short* __res_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReturnUIntAsVariantBool_Out(uint input, out bool res) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out res); + short __res_native; + { + __PInvoke(input, &__res_native); + } + + // Unmarshal - Convert native data to managed data. + res = __res_native == -1; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "uint_return_as_refvariantbool", ExactSpelling = true)] + static extern unsafe void __PInvoke(uint __input_native, short* __res_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReturnUIntAsVariantBool_In(uint input, in bool res) + { + short __res_native; + // Marshal - Convert managed data to native data. + __res_native = (short)(res ? -1 : 0); + { + __PInvoke(input, &__res_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "uint_return_as_refvariantbool", ExactSpelling = true)] + static extern unsafe void __PInvoke(uint __input_native, short* __res_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReturnUIntAsWinBool_Ref(uint input, ref bool res) + { + int __res_native; + // Marshal - Convert managed data to native data. + __res_native = (int)(res ? 1 : 0); + { + __PInvoke(input, &__res_native); + } + + // Unmarshal - Convert native data to managed data. + res = __res_native != 0; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "uint_return_as_refwinbool", ExactSpelling = true)] + static extern unsafe void __PInvoke(uint __input_native, int* __res_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReturnUIntAsWinBool_Out(uint input, out bool res) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out res); + int __res_native; + { + __PInvoke(input, &__res_native); + } + + // Unmarshal - Convert native data to managed data. + res = __res_native != 0; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "uint_return_as_refwinbool", ExactSpelling = true)] + static extern unsafe void __PInvoke(uint __input_native, int* __res_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReturnUIntAsWinBool_In(uint input, in bool res) + { + int __res_native; + // Marshal - Convert managed data to native data. + __res_native = (int)(res ? 1 : 0); + { + __PInvoke(input, &__res_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "uint_return_as_refwinbool", ExactSpelling = true)] + static extern unsafe void __PInvoke(uint __input_native, int* __res_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class CallingConventions + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "add_integers_cdecl", ExactSpelling = true)] + public static extern partial long AddLongsCdecl(long i, long j, long k, long l, long m, long n, long o, long p, long q); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class CallingConventions + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "add_integers_stdcall", ExactSpelling = true)] + public static extern partial long AddLongsStdcall(long i, long j, long k, long l, long m, long n, long o, long p, long q); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "ushort_return_as_uint", ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Unicode)] + public static extern partial uint ReturnUnicodeAsUInt(char input); + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "char_return_as_uint", ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Unicode)] + public static extern partial char ReturnUIntAsUnicode(uint input); + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReturnUIntAsUnicode_Ref(uint input, ref char res) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (char* __res_native = &res) + { + __PInvoke(input, __res_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "char_return_as_refushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(uint __input_native, char* __res_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReturnUIntAsUnicode_Out(uint input, out char res) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out res); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (char* __res_native = &res) + { + __PInvoke(input, __res_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "char_return_as_refushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(uint __input_native, char* __res_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReturnUIntAsUnicode_In(uint input, in char res) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (char* __res_native = &res) + { + __PInvoke(input, __res_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "char_return_as_refushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(uint __input_native, char* __res_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "char_return_as_uint", ExactSpelling = true)] + public static extern partial char ReturnU2AsU2IgnoreCharSet(char input); + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "char_return_as_uint", ExactSpelling = true)] + public static extern partial char ReturnI2AsI2IgnoreCharSet(char input); + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReverseBuffer(ref char buffer, int len) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (char* __buffer_native = &buffer) + { + __PInvoke(__buffer_native, len); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "char_reverse_buffer_ref", ExactSpelling = true)] + static extern unsafe void __PInvoke(char* __buffer_native, int __len_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class MarshallingFails + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Utf8StringSpan(global::System.ReadOnlySpan s) + { + System.IntPtr* __s_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ReadOnlySpanMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + int __s_native__numElements; + int __s_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __s_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ReadOnlySpanMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __s_native__managedSpan = __s_native__marshaller.GetManagedValuesSource(); + System.Span __s_native__nativeSpan = __s_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __s_native__managedSpan.Length; ++__i0, ++__s_native__lastIndexMarshalled) + { + __s_native__nativeSpan[__i0] = (System.IntPtr)(byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(__s_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native__unused = __s_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __PInvoke(__s_native); + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __s_native__nativeSpan = __s_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __s_native__lastIndexMarshalled; ++__i0) + { + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free((byte*)__s_native__nativeSpan[__i0]); + } + } + + __s_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("DoesNotExist", EntryPoint = "Utf8StringSpan", ExactSpelling = true)] + static extern unsafe void __PInvoke(System.IntPtr* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class MarshallingFails + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Utf8StringArray(string[] s) + { + System.IntPtr* __s_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + int __s_native__numElements; + int __s_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __s_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __s_native__managedSpan = __s_native__marshaller.GetManagedValuesSource(); + System.Span __s_native__nativeSpan = __s_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __s_native__managedSpan.Length; ++__i0, ++__s_native__lastIndexMarshalled) + { + __s_native__nativeSpan[__i0] = (System.IntPtr)(byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(__s_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native__unused = __s_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __PInvoke(__s_native); + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __s_native__nativeSpan = __s_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __s_native__lastIndexMarshalled; ++__i0) + { + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free((byte*)__s_native__nativeSpan[__i0]); + } + } + + __s_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("DoesNotExist", EntryPoint = "Utf8StringArray", ExactSpelling = true)] + static extern unsafe void __PInvoke(System.IntPtr* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class MarshallingFails + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void MarshalSingleDimensionalArray(global::SharedTypes.BoolStruct[] c) + { + nint* __c_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __c_native__marshaller = new(); + int __c_native__numElements; + int __c_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __c_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __c_native__marshaller.FromManaged(c, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __c_native__managedSpan = __c_native__marshaller.GetManagedValuesSource(); + System.Span __c_native__nativeSpan = __c_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __c_native__managedSpan.Length; ++__i0, ++__c_native__lastIndexMarshalled) + { + __c_native__nativeSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStruct.ConvertToUnmanaged(__c_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __c_native__unused = __c_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __c_native = __c_native__marshaller.ToUnmanaged(); + __PInvoke(__c_native); + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __c_native__nativeSpan = __c_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __c_native__lastIndexMarshalled; ++__i0) + { + global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStruct.Free(__c_native__nativeSpan[__i0]); + } + } + + __c_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("DoesNotExist", EntryPoint = "MarshalSingleDimensionalArray", ExactSpelling = true)] + static extern unsafe void __PInvoke(nint* __c_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class MarshallingFails + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void MarshalMultidimensionalArray_CheckOuterArrayIsIndexTracked(global::SharedTypes.BoolStruct[][] c) + { + nint* __c_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __c_native__marshaller = new(); + int __c_native__numElements; + int __c_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __c_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __c_native__marshaller.FromManaged(c, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __c_native__managedSpan = __c_native__marshaller.GetManagedValuesSource(); + System.Span __c_native__nativeSpan = __c_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __c_native__managedSpan.Length; ++__i0, ++__c_native__lastIndexMarshalled) + { + __c_native__nativeSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStructArray.ConvertToUnmanaged(__c_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __c_native__unused = __c_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __c_native = __c_native__marshaller.ToUnmanaged(); + __PInvoke(__c_native); + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __c_native__nativeSpan = __c_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __c_native__lastIndexMarshalled; ++__i0) + { + global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStructArray.Free(__c_native__nativeSpan[__i0]); + } + } + + __c_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("DoesNotExist", EntryPoint = "MarshalMultidimensionalArray_CheckOuterArrayIsIndexTracked", ExactSpelling = true)] + static extern unsafe void __PInvoke(nint* __c_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class MarshallingFails + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void MarshalMultidimensionalArray_CheckInnerArraysAreCleared(global::SharedTypes.BoolStruct[][] c) + { + System.IntPtr* __c_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __c_native__marshaller = new(); + int __c_native__numElements; + int __c_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __c_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __c_native__marshaller.FromManaged(c, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __c_native__managedSpan = __c_native__marshaller.GetManagedValuesSource(); + System.Span __c_native__nativeSpan = __c_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __c_native__managedSpan.Length; ++__i0, ++__c_native__lastIndexMarshalled) + { + int __c_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __c_native__nativeSpan____i0__numElements); + __c_native__nativeSpan[__i0] = (System.IntPtr)global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__c_native__managedSpan[__i0], out __c_native__nativeSpan____i0__numElements); + { + System.ReadOnlySpan __c_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__c_native__managedSpan[__i0]); + System.Span __c_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__c_native__nativeSpan[__i0], __c_native__nativeSpan____i0__numElements); + __c_native__nativeSpan____i0__nativeSpan.Clear(); + for (int __i1 = 0; __i1 < __c_native__nativeSpan____i0__managedSpan.Length; ++__i1) + { + __c_native__nativeSpan____i0__nativeSpan[__i1] = global::LibraryImportGenerator.IntegrationTests.EnforceClearedMemoryCleanup.ConvertToUnmanaged(__c_native__nativeSpan____i0__managedSpan[__i1]); + } + } + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __c_native__unused = __c_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __c_native = __c_native__marshaller.ToUnmanaged(); + __PInvoke(__c_native); + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __c_native__nativeSpan = __c_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __c_native__lastIndexMarshalled; ++__i0) + { + int __c_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __c_native__nativeSpan____i0__numElements); + __c_native__nativeSpan____i0__numElements = 0; + { + System.ReadOnlySpan __c_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__c_native__nativeSpan[__i0], __c_native__nativeSpan____i0__numElements); + for (int __i1 = 0; __i1 < __c_native__nativeSpan____i0__nativeSpan.Length; ++__i1) + { + global::LibraryImportGenerator.IntegrationTests.EnforceClearedMemoryCleanup.Free(__c_native__nativeSpan____i0__nativeSpan[__i1]); + } + }; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__c_native__nativeSpan[__i0]); + } + } + + __c_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("DoesNotExist", EntryPoint = "MarshalMultidimensionalArray_CheckInnerArraysAreCleared", ExactSpelling = true)] + static extern unsafe void __PInvoke(System.IntPtr* __c_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class MarshallingFails + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void MarshalArray_Ref(ref global::SharedTypes.BoolStruct[] c) + { + nint* __c_native = default; + // Setup - Perform required setup. + int __c_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __c_native__numElements); + int __c_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __c_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(c, out __c_native__numElements); + { + System.ReadOnlySpan __c_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(c); + System.Span __c_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__c_native, __c_native__numElements); + for (int __i0 = 0; __i0 < __c_native__managedSpan.Length; ++__i0, ++__c_native__lastIndexMarshalled) + { + __c_native__nativeSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStruct.ConvertToUnmanaged(__c_native__managedSpan[__i0]); + } + } + + { + __PInvoke(&__c_native); + } + + // Unmarshal - Convert native data to managed data. + __c_native__numElements = 10; + c = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__c_native, __c_native__numElements); + { + System.ReadOnlySpan __c_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__c_native, __c_native__numElements); + System.Span __c_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(c); + for (int __i0 = 0; __i0 < __c_native__numElements; ++__i0) + { + __c_native__managedSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStruct.ConvertToManaged(__c_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __c_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__c_native, __c_native__numElements); + for (int __i0 = 0; __i0 < __c_native__lastIndexMarshalled; ++__i0) + { + global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStruct.Free(__c_native__nativeSpan[__i0]); + } + } + + __c_native__numElements = 10; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__c_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("DoesNotExist", EntryPoint = "MarshalArray_Ref", ExactSpelling = true)] + static extern unsafe void __PInvoke(nint** __c_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class MarshallingFails + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void NegateBoolsOut(global::SharedTypes.BoolStruct[] boolStruct, int numValues, out global::SharedTypes.BoolStruct[] pBoolStructOut) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out pBoolStructOut); + global::SharedTypes.BoolStructMarshaller.BoolStructNative* __boolStruct_native = default; + nint* __pBoolStructOut_native = default; + // Setup - Perform required setup. + int __pBoolStructOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pBoolStructOut_native__numElements); + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __boolStruct_native__marshaller = new(); + int __boolStruct_native__numElements; + int __boolStruct_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native__marshaller.FromManaged(boolStruct, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = __boolStruct_native__marshaller.GetManagedValuesSource(); + System.Span __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __boolStruct_native__unused = __boolStruct_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __boolStruct_native = __boolStruct_native__marshaller.ToUnmanaged(); + __PInvoke(__boolStruct_native, numValues, &__pBoolStructOut_native); + } + + // Unmarshal - Convert native data to managed data. + __pBoolStructOut_native__numElements = numValues; + pBoolStructOut = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__pBoolStructOut_native, __pBoolStructOut_native__numElements); + { + System.ReadOnlySpan __pBoolStructOut_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__pBoolStructOut_native, __pBoolStructOut_native__numElements); + System.Span __pBoolStructOut_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(pBoolStructOut); + for (int __i0 = 0; __i0 < __pBoolStructOut_native__numElements; ++__i0) + { + __pBoolStructOut_native__managedSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpBoolStruct.ConvertToManaged(__pBoolStructOut_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + _ = __boolStruct_native__lastIndexMarshalled; + __boolStruct_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_out", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.BoolStructMarshaller.BoolStructNative* __boolStruct_native, int __numValues_native, nint** __pBoolStructOut_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class MarshallingFails + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void NegateBoolsOut2D(global::SharedTypes.BoolStruct[][] boolStruct, int length, int[] widths, out global::SharedTypes.BoolStruct[][] pBoolStructOut) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out pBoolStructOut); + System.IntPtr* __boolStruct_native = default; + System.IntPtr* __pBoolStructOut_native = default; + // Setup - Perform required setup. + int __pBoolStructOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pBoolStructOut_native__numElements); + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __boolStruct_native__marshaller = new(); + int __boolStruct_native__numElements; + int __boolStruct_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native__marshaller.FromManaged(boolStruct, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = __boolStruct_native__marshaller.GetManagedValuesSource(); + System.Span __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + int __boolStruct_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__nativeSpan____i0__numElements); + __boolStruct_native__nativeSpan[__i0] = (System.IntPtr)global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__boolStruct_native__managedSpan[__i0], out __boolStruct_native__nativeSpan____i0__numElements); + { + System.ReadOnlySpan __boolStruct_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__boolStruct_native__managedSpan[__i0]); + System.Span __boolStruct_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((global::SharedTypes.BoolStructMarshaller.BoolStructNative*)__boolStruct_native__nativeSpan[__i0], __boolStruct_native__nativeSpan____i0__numElements); + __boolStruct_native__nativeSpan____i0__nativeSpan.Clear(); + for (int __i1 = 0; __i1 < __boolStruct_native__nativeSpan____i0__managedSpan.Length; ++__i1) + { + __boolStruct_native__nativeSpan____i0__nativeSpan[__i1] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__nativeSpan____i0__managedSpan[__i1]); + } + } + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __widths_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(widths)) + fixed (void* __boolStruct_native__unused = __boolStruct_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __boolStruct_native = __boolStruct_native__marshaller.ToUnmanaged(); + __PInvoke(__boolStruct_native, length, (int*)__widths_native, &__pBoolStructOut_native); + } + + // Unmarshal - Convert native data to managed data. + __pBoolStructOut_native__numElements = length; + pBoolStructOut = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__pBoolStructOut_native, __pBoolStructOut_native__numElements); + { + System.ReadOnlySpan __pBoolStructOut_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__pBoolStructOut_native, __pBoolStructOut_native__numElements); + System.Span __pBoolStructOut_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(pBoolStructOut); + for (int __i0 = 0; __i0 < __pBoolStructOut_native__numElements; ++__i0) + { + int __pBoolStructOut_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pBoolStructOut_native__nativeSpan____i0__numElements); + __pBoolStructOut_native__nativeSpan____i0__numElements = widths[__i0]; + __pBoolStructOut_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((nint*)__pBoolStructOut_native__nativeSpan[__i0], __pBoolStructOut_native__nativeSpan____i0__numElements); + { + System.ReadOnlySpan __pBoolStructOut_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__pBoolStructOut_native__nativeSpan[__i0], __pBoolStructOut_native__nativeSpan____i0__numElements); + System.Span __pBoolStructOut_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__pBoolStructOut_native__managedSpan[__i0]); + for (int __i1 = 0; __i1 < __pBoolStructOut_native__nativeSpan____i0__numElements; ++__i1) + { + __pBoolStructOut_native__nativeSpan____i0__managedSpan[__i1] = global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpBoolStruct.ConvertToManaged(__pBoolStructOut_native__nativeSpan____i0__nativeSpan[__i1]); + } + } + } + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __boolStruct_native__lastIndexMarshalled; ++__i0) + { + int __boolStruct_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__nativeSpan____i0__numElements); + ; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((global::SharedTypes.BoolStructMarshaller.BoolStructNative*)__boolStruct_native__nativeSpan[__i0]); + } + } + + __boolStruct_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_out_2d", ExactSpelling = true)] + static extern unsafe void __PInvoke(System.IntPtr* __boolStruct_native, int __length_native, int* __widths_native, System.IntPtr** __pBoolStructOut_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class MarshallingFails + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool FillRangeArray(global::SharedTypes.IntStructWrapper[] array, int length, int start) + { + nint* __array_native = default; + bool __retVal = default; + byte __retVal_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __array_native__marshaller = new(); + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __array_native__marshaller.FromManaged(array, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + __array_native__marshaller.GetUnmanagedValuesDestination().Clear(); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __array_native__unused = __array_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __array_native = __array_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__array_native, length, start); + } + + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + { + __array_native__numElements = __array_native__marshaller.GetManagedValuesSource().Length; + System.Span __array_native__managedSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __array_native__marshaller.GetManagedValuesSource().GetPinnableReference()), __array_native__numElements); + System.Span __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __array_native__numElements; ++__i0) + { + __array_native__managedSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpIntStruct.ConvertToManaged(__array_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + __array_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "fill_range_array", ExactSpelling = true)] + static extern unsafe byte __PInvoke(nint* __array_native, int __length_native, int __start_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class MarshallingFails + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool FillRangeArray2D(global::SharedTypes.IntStructWrapper[][] array, int length, int[] widths, int start) + { + System.IntPtr* __array_native = default; + bool __retVal = default; + byte __retVal_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __array_native__marshaller = new(); + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __array_native__marshaller.FromManaged(array, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + __array_native__marshaller.GetUnmanagedValuesDestination().Clear(); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __widths_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(widths)) + fixed (void* __array_native__unused = __array_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __array_native = __array_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__array_native, length, (int*)__widths_native, start); + } + + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + { + __array_native__numElements = __array_native__marshaller.GetManagedValuesSource().Length; + System.Span __array_native__managedSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __array_native__marshaller.GetManagedValuesSource().GetPinnableReference()), __array_native__numElements); + System.Span __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __array_native__numElements; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan____i0__numElements = widths[__i0]; + __array_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + { + System.ReadOnlySpan __array_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + System.Span __array_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__array_native__managedSpan[__i0]); + for (int __i1 = 0; __i1 < __array_native__nativeSpan____i0__numElements; ++__i1) + { + __array_native__nativeSpan____i0__managedSpan[__i1] = global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpIntStruct.ConvertToManaged(__array_native__nativeSpan____i0__nativeSpan[__i1]); + } + } + } + } + } + finally + { + // Cleanup - Perform required cleanup. + __array_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "fill_range_array_2d", ExactSpelling = true)] + static extern unsafe byte __PInvoke(System.IntPtr* __array_native, int __length_native, int* __widths_native, int __start_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class MarshallingFails + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void NegateBoolsRef(ref global::SharedTypes.BoolStruct[] boolStruct, int numValues) + { + nint* __boolStruct_native = default; + // Setup - Perform required setup. + int __boolStruct_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + int __boolStruct_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(boolStruct, out __boolStruct_native__numElements); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(boolStruct); + System.Span __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + __boolStruct_native__nativeSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStruct.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); + } + } + + { + __PInvoke(&__boolStruct_native, numValues); + } + + // Unmarshal - Convert native data to managed data. + __boolStruct_native__numElements = numValues; + boolStruct = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__boolStruct_native, __boolStruct_native__numElements); + { + System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__boolStruct_native, __boolStruct_native__numElements); + System.Span __boolStruct_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(boolStruct); + for (int __i0 = 0; __i0 < __boolStruct_native__numElements; ++__i0) + { + __boolStruct_native__managedSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStruct.ConvertToManaged(__boolStruct_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); + for (int __i0 = 0; __i0 < __boolStruct_native__lastIndexMarshalled; ++__i0) + { + global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStruct.Free(__boolStruct_native__nativeSpan[__i0]); + } + } + + __boolStruct_native__numElements = numValues; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__boolStruct_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_ref", ExactSpelling = true)] + static extern unsafe void __PInvoke(nint** __boolStruct_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class MarshallingFails + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void NegateBoolsRef2D_LastElementMarshalling(ref global::SharedTypes.BoolStruct[][] boolStruct, int length) + { + nint* __boolStruct_native = default; + // Setup - Perform required setup. + int __boolStruct_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + int __boolStruct_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(boolStruct, out __boolStruct_native__numElements); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(boolStruct); + System.Span __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + __boolStruct_native__nativeSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStructArray.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); + } + } + + { + __PInvoke(&__boolStruct_native, length); + } + + // Unmarshal - Convert native data to managed data. + __boolStruct_native__numElements = length; + boolStruct = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__boolStruct_native, __boolStruct_native__numElements); + { + System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__boolStruct_native, __boolStruct_native__numElements); + System.Span __boolStruct_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(boolStruct); + for (int __i0 = 0; __i0 < __boolStruct_native__numElements; ++__i0) + { + __boolStruct_native__managedSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStructArray.ConvertToManaged(__boolStruct_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); + for (int __i0 = 0; __i0 < __boolStruct_native__lastIndexMarshalled; ++__i0) + { + global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStructArray.Free(__boolStruct_native__nativeSpan[__i0]); + } + } + + __boolStruct_native__numElements = length; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__boolStruct_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("DoesNotExist", EntryPoint = "negate_bool_struct_array_ref_2d", ExactSpelling = true)] + static extern unsafe void __PInvoke(nint** __boolStruct_native, int __length_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class MarshallingFails + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void NegateBoolsRef2D_ClearMarshalling(ref global::SharedTypes.BoolStruct[][] boolStruct, int length, int[] widths) + { + System.IntPtr* __boolStruct_native = default; + // Setup - Perform required setup. + int __boolStruct_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + int __boolStruct_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(boolStruct, out __boolStruct_native__numElements); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(boolStruct); + System.Span __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + int __boolStruct_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__nativeSpan____i0__numElements); + __boolStruct_native__nativeSpan[__i0] = (System.IntPtr)global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__boolStruct_native__managedSpan[__i0], out __boolStruct_native__nativeSpan____i0__numElements); + { + System.ReadOnlySpan __boolStruct_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__boolStruct_native__managedSpan[__i0]); + System.Span __boolStruct_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__boolStruct_native__nativeSpan[__i0], __boolStruct_native__nativeSpan____i0__numElements); + __boolStruct_native__nativeSpan____i0__nativeSpan.Clear(); + for (int __i1 = 0; __i1 < __boolStruct_native__nativeSpan____i0__managedSpan.Length; ++__i1) + { + __boolStruct_native__nativeSpan____i0__nativeSpan[__i1] = global::LibraryImportGenerator.IntegrationTests.EnforceClearedMemoryCleanup.ConvertToUnmanaged(__boolStruct_native__nativeSpan____i0__managedSpan[__i1]); + } + } + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __widths_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(widths)) + { + __PInvoke(&__boolStruct_native, length, (int*)__widths_native); + } + + // Unmarshal - Convert native data to managed data. + __boolStruct_native__numElements = length; + boolStruct = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__boolStruct_native, __boolStruct_native__numElements); + { + System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__boolStruct_native, __boolStruct_native__numElements); + System.Span __boolStruct_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(boolStruct); + for (int __i0 = 0; __i0 < __boolStruct_native__numElements; ++__i0) + { + int __boolStruct_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__nativeSpan____i0__numElements); + __boolStruct_native__nativeSpan____i0__numElements = widths[__i0]; + __boolStruct_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((nint*)__boolStruct_native__nativeSpan[__i0], __boolStruct_native__nativeSpan____i0__numElements); + { + System.ReadOnlySpan __boolStruct_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__boolStruct_native__nativeSpan[__i0], __boolStruct_native__nativeSpan____i0__numElements); + System.Span __boolStruct_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__boolStruct_native__managedSpan[__i0]); + for (int __i1 = 0; __i1 < __boolStruct_native__nativeSpan____i0__numElements; ++__i1) + { + __boolStruct_native__nativeSpan____i0__managedSpan[__i1] = global::LibraryImportGenerator.IntegrationTests.EnforceClearedMemoryCleanup.ConvertToManaged(__boolStruct_native__nativeSpan____i0__nativeSpan[__i1]); + } + } + } + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); + for (int __i0 = 0; __i0 < __boolStruct_native__lastIndexMarshalled; ++__i0) + { + int __boolStruct_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__nativeSpan____i0__numElements); + __boolStruct_native__nativeSpan____i0__numElements = widths[__i0]; + { + System.ReadOnlySpan __boolStruct_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__boolStruct_native__nativeSpan[__i0], __boolStruct_native__nativeSpan____i0__numElements); + for (int __i1 = 0; __i1 < __boolStruct_native__nativeSpan____i0__nativeSpan.Length; ++__i1) + { + global::LibraryImportGenerator.IntegrationTests.EnforceClearedMemoryCleanup.Free(__boolStruct_native__nativeSpan____i0__nativeSpan[__i1]); + } + } + + __boolStruct_native__nativeSpan____i0__numElements = widths[__i0]; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__boolStruct_native__nativeSpan[__i0]); + } + } + + __boolStruct_native__numElements = length; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__boolStruct_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("DoesNotExist", EntryPoint = "negate_bool_struct_array_ref_2d", ExactSpelling = true)] + static extern unsafe void __PInvoke(System.IntPtr** __boolStruct_native, int __length_native, int* __widths_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int Sum(global::System.Collections.Generic.List values, int numValues) + { + byte* __values_native = default; + int __retVal = default; + // Setup - Perform required setup. + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native = global::SharedTypes.ListMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); + global::SharedTypes.ListMarshaller.GetManagedValuesSource(values).CopyTo(global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); + { + __retVal = __PInvoke(__values_native, numValues); + } + } + finally + { + // Cleanup - Perform required cleanup. + ; + global::SharedTypes.ListMarshaller.Free(__values_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte* __values_native, int __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int SumWithBuffer(global::System.Collections.Generic.List values, int numValues) + { + byte* __values_native = default; + int __retVal = default; + // Setup - Perform required setup. + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + System.Span __values_native__buffer = stackalloc byte[global::SharedTypes.ListMarshallerWithBuffer.BufferSize]; + __values_native = global::SharedTypes.ListMarshallerWithBuffer.AllocateContainerForUnmanagedElements(values, __values_native__buffer, out __values_native__numElements); + global::SharedTypes.ListMarshallerWithBuffer.GetManagedValuesSource(values).CopyTo(global::SharedTypes.ListMarshallerWithBuffer.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); + { + __retVal = __PInvoke(__values_native, numValues); + } + } + finally + { + // Cleanup - Perform required cleanup. + ; + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte* __values_native, int __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static unsafe partial int SumWithFreeTracking(global::System.Collections.Generic.List values, int numValues) + { + byte* __values_native = default; + int __retVal = default; + // Setup - Perform required setup. + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + int __values_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __values_native = global::SharedTypes.ListMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); + { + System.ReadOnlySpan __values_native__managedSpan = global::SharedTypes.ListMarshaller.GetManagedValuesSource(values); + System.Span __values_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements); + for (int __i0 = 0; __i0 < __values_native__managedSpan.Length; ++__i0, ++__values_native__lastIndexMarshalled) + { + __values_native__nativeSpan[__i0] = (System.IntPtr)(int*)global::SharedTypes.IntWrapperMarshallerWithFreeCounts.ConvertToUnmanaged(__values_native__managedSpan[__i0]); + } + } + + { + __retVal = __PInvoke(__values_native, numValues); + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __values_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements); + for (int __i0 = 0; __i0 < __values_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.IntWrapperMarshallerWithFreeCounts.Free((int*)__values_native__nativeSpan[__i0]); + } + }; + global::SharedTypes.ListMarshaller.Free(__values_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_ptr_array", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte* __values_native, int __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int DoubleValues(global::System.Collections.Generic.List values, int length) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __values_native = &global::SharedTypes.ListMarshallerWithPinning.GetPinnableReference(values)) + { + __retVal = __PInvoke((byte*)__values_native, length); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "double_values", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte* __values_native, int __length_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int SumInArray(in global::System.Collections.Generic.List values, int numValues) + { + byte* __values_native = default; + int __retVal = default; + // Setup - Perform required setup. + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native = global::SharedTypes.ListMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); + global::SharedTypes.ListMarshaller.GetManagedValuesSource(values).CopyTo(global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); + { + __retVal = __PInvoke(&__values_native, numValues); + } + } + finally + { + // Cleanup - Perform required cleanup. + ; + global::SharedTypes.ListMarshaller.Free(__values_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array_ref", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte** __values_native, int __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Duplicate(ref global::System.Collections.Generic.List values, int numValues) + { + byte* __values_native = default; + // Setup - Perform required setup. + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native = global::SharedTypes.ListMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); + global::SharedTypes.ListMarshaller.GetManagedValuesSource(values).CopyTo(global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); + { + __PInvoke(&__values_native, numValues); + } + + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; + values = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); + global::SharedTypes.ListMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements).CopyTo(global::SharedTypes.ListMarshaller.GetManagedValuesDestination(values)); + } + finally + { + // Cleanup - Perform required cleanup. + __values_native__numElements = numValues; + global::SharedTypes.ListMarshaller.Free(__values_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "duplicate_int_array", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __values_native, int __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::System.Collections.Generic.List CreateRange(int start, int end, out int numValues) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); + global::System.Collections.Generic.List __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __numValues_native = &numValues) + { + __retVal_native = __PInvoke(start, end, __numValues_native); + } + + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = numValues; + __retVal = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::SharedTypes.ListMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::SharedTypes.ListMarshaller.GetManagedValuesDestination(__retVal)); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_native__numElements = numValues; + global::SharedTypes.ListMarshaller.Free(__retVal_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array", ExactSpelling = true)] + static extern unsafe byte* __PInvoke(int __start_native, int __end_native, int* __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void CreateRange_Out(int start, int end, out int numValues, out global::System.Collections.Generic.List res) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); + System.Runtime.CompilerServices.Unsafe.SkipInit(out res); + byte* __res_native; + // Setup - Perform required setup. + int __res_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __res_native__numElements); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __numValues_native = &numValues) + { + __PInvoke(start, end, __numValues_native, &__res_native); + } + + // Unmarshal - Convert native data to managed data. + __res_native__numElements = numValues; + res = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__res_native, __res_native__numElements); + global::SharedTypes.ListMarshaller.GetUnmanagedValuesSource(__res_native, __res_native__numElements).CopyTo(global::SharedTypes.ListMarshaller.GetManagedValuesDestination(res)); + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array_out", ExactSpelling = true)] + static extern unsafe void __PInvoke(int __start_native, int __end_native, int* __numValues_native, byte** __res_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::System.Collections.Generic.List GetLongBytes(long l) + { + global::System.Collections.Generic.List __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + { + __retVal_native = __PInvoke(l); + } + + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = 8; + __retVal = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::SharedTypes.ListMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::SharedTypes.ListMarshaller.GetManagedValuesDestination(__retVal)); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_native__numElements = 8; + global::SharedTypes.ListMarshaller.Free(__retVal_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "get_long_bytes", ExactSpelling = true)] + static extern unsafe byte* __PInvoke(long __l_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool AndAllMembers(global::System.Collections.Generic.List pArray, int length) + { + byte* __pArray_native = default; + bool __retVal = default; + byte __retVal_native = default; + // Setup - Perform required setup. + int __pArray_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pArray_native__numElements); + int __pArray_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __pArray_native = global::SharedTypes.ListMarshaller.AllocateContainerForUnmanagedElements(pArray, out __pArray_native__numElements); + { + System.ReadOnlySpan __pArray_native__managedSpan = global::SharedTypes.ListMarshaller.GetManagedValuesSource(pArray); + System.Span __pArray_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__pArray_native, __pArray_native__numElements); + for (int __i0 = 0; __i0 < __pArray_native__managedSpan.Length; ++__i0, ++__pArray_native__lastIndexMarshalled) + { + __pArray_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__pArray_native__managedSpan[__i0]); + } + } + + { + __retVal_native = __PInvoke(__pArray_native, length); + } + + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + } + finally + { + // Cleanup - Perform required cleanup. + _ = __pArray_native__lastIndexMarshalled; + ; + global::SharedTypes.ListMarshaller.Free(__pArray_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "and_bool_struct_array", ExactSpelling = true)] + static extern unsafe byte __PInvoke(byte* __pArray_native, int __length_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool AndAllMembersIn(in global::System.Collections.Generic.List pArray, int length) + { + byte* __pArray_native = default; + bool __retVal = default; + byte __retVal_native = default; + // Setup - Perform required setup. + int __pArray_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pArray_native__numElements); + int __pArray_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __pArray_native = global::SharedTypes.ListMarshaller.AllocateContainerForUnmanagedElements(pArray, out __pArray_native__numElements); + { + System.ReadOnlySpan __pArray_native__managedSpan = global::SharedTypes.ListMarshaller.GetManagedValuesSource(pArray); + System.Span __pArray_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__pArray_native, __pArray_native__numElements); + for (int __i0 = 0; __i0 < __pArray_native__managedSpan.Length; ++__i0, ++__pArray_native__lastIndexMarshalled) + { + __pArray_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__pArray_native__managedSpan[__i0]); + } + } + + { + __retVal_native = __PInvoke(&__pArray_native, length); + } + + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + } + finally + { + // Cleanup - Perform required cleanup. + _ = __pArray_native__lastIndexMarshalled; + ; + global::SharedTypes.ListMarshaller.Free(__pArray_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "and_bool_struct_array_in", ExactSpelling = true)] + static extern unsafe byte __PInvoke(byte** __pArray_native, int __length_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void NegateBools(ref global::System.Collections.Generic.List boolStruct, int numValues) + { + byte* __boolStruct_native = default; + // Setup - Perform required setup. + int __boolStruct_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + int __boolStruct_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native = global::SharedTypes.ListMarshaller.AllocateContainerForUnmanagedElements(boolStruct, out __boolStruct_native__numElements); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = global::SharedTypes.ListMarshaller.GetManagedValuesSource(boolStruct); + System.Span __boolStruct_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); + } + } + + { + __PInvoke(&__boolStruct_native, numValues); + } + + // Unmarshal - Convert native data to managed data. + __boolStruct_native__numElements = numValues; + boolStruct = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__boolStruct_native, __boolStruct_native__numElements); + { + System.ReadOnlySpan __boolStruct_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesSource(__boolStruct_native, __boolStruct_native__numElements); + System.Span __boolStruct_native__managedSpan = global::SharedTypes.ListMarshaller.GetManagedValuesDestination(boolStruct); + for (int __i0 = 0; __i0 < __boolStruct_native__numElements; ++__i0) + { + __boolStruct_native__managedSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__boolStruct_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + _ = __boolStruct_native__lastIndexMarshalled; + __boolStruct_native__numElements = numValues; + global::SharedTypes.ListMarshaller.Free(__boolStruct_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_ref", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __boolStruct_native, int __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void NegateBools(global::System.Collections.Generic.List boolStruct, int numValues, out global::System.Collections.Generic.List pBoolStructOut) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out pBoolStructOut); + byte* __boolStruct_native = default; + byte* __pBoolStructOut_native = default; + // Setup - Perform required setup. + int __pBoolStructOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pBoolStructOut_native__numElements); + int __boolStruct_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + int __boolStruct_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native = global::SharedTypes.ListMarshaller.AllocateContainerForUnmanagedElements(boolStruct, out __boolStruct_native__numElements); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = global::SharedTypes.ListMarshaller.GetManagedValuesSource(boolStruct); + System.Span __boolStruct_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); + } + } + + { + __PInvoke(__boolStruct_native, numValues, &__pBoolStructOut_native); + } + + // Unmarshal - Convert native data to managed data. + __pBoolStructOut_native__numElements = numValues; + pBoolStructOut = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__pBoolStructOut_native, __pBoolStructOut_native__numElements); + { + System.ReadOnlySpan __pBoolStructOut_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesSource(__pBoolStructOut_native, __pBoolStructOut_native__numElements); + System.Span __pBoolStructOut_native__managedSpan = global::SharedTypes.ListMarshaller.GetManagedValuesDestination(pBoolStructOut); + for (int __i0 = 0; __i0 < __pBoolStructOut_native__numElements; ++__i0) + { + __pBoolStructOut_native__managedSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__pBoolStructOut_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + _ = __boolStruct_native__lastIndexMarshalled; + ; + global::SharedTypes.ListMarshaller.Free(__boolStruct_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_out", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte* __boolStruct_native, int __numValues_native, byte** __pBoolStructOut_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::System.Collections.Generic.List NegateBools(global::System.Collections.Generic.List boolStruct, int numValues) + { + byte* __boolStruct_native = default; + global::System.Collections.Generic.List __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + int __boolStruct_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + int __boolStruct_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native = global::SharedTypes.ListMarshaller.AllocateContainerForUnmanagedElements(boolStruct, out __boolStruct_native__numElements); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = global::SharedTypes.ListMarshaller.GetManagedValuesSource(boolStruct); + System.Span __boolStruct_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); + } + } + + { + __retVal_native = __PInvoke(__boolStruct_native, numValues); + } + + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = numValues; + __retVal = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + System.Span __retVal_native__managedSpan = global::SharedTypes.ListMarshaller.GetManagedValuesDestination(__retVal); + for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + { + __retVal_native__managedSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__retVal_native__nativeSpan[__i0]); + } + } + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_native__numElements = numValues; + global::SharedTypes.ListMarshaller.Free(__retVal_native); + _ = __boolStruct_native__lastIndexMarshalled; + ; + global::SharedTypes.ListMarshaller.Free(__boolStruct_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_return", ExactSpelling = true)] + static extern unsafe byte* __PInvoke(byte* __boolStruct_native, int __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int GuaranteedUnmarshal(out global::System.Collections.Generic.List ret) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + byte* __ret_native = default; + int __retVal = default; + int __retVal_native = default; + // Setup - Perform required setup. + int __ret_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __ret_native__numElements); + try + { + { + __retVal_native = __PInvoke(&__ret_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal = global::SharedTypes.ExceptionOnUnmarshal.ConvertToManaged(__retVal_native); + } + finally + { + if (__invokeSucceeded) + { + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + __ret_native__numElements = 1; + ret = global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.Collections.Stateless.ListGuaranteedUnmarshal.AllocateContainerForManagedElementsFinally(__ret_native, __ret_native__numElements); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_zero", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte** __ret_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int GuaranteedUnmarshal(out global::System.Collections.Generic.List ret) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + byte* __ret_native = default; + int __retVal = default; + int __retVal_native = default; + // Setup - Perform required setup. + int __ret_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __ret_native__numElements); + try + { + { + __retVal_native = __PInvoke(&__ret_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal = global::SharedTypes.ExceptionOnUnmarshal.ConvertToManaged(__retVal_native); + } + finally + { + if (__invokeSucceeded) + { + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + __ret_native__numElements = 1; + ret = global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.Collections.Stateless.ListGuaranteedUnmarshal.AllocateContainerForManagedElementsFinally(__ret_native, __ret_native__numElements); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_zero", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte** __ret_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int Sum(global::System.Collections.Generic.List values, int numValues) + { + byte* __values_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __values_native__marshaller = new(); + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native__marshaller.FromManaged(values, stackalloc int[global::SharedTypes.ListMarshallerStateful.Marshaller.BufferSize]); + __values_native__marshaller.GetManagedValuesSource().CopyTo(__values_native__marshaller.GetUnmanagedValuesDestination()); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __values_native__unused = __values_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __values_native = __values_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(__values_native, numValues); + } + } + finally + { + // Cleanup - Perform required cleanup. + __values_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte* __values_native, int __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static unsafe partial int SumWithFreeTracking(global::System.Collections.Generic.List values, int numValues) + { + byte* __values_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __values_native__marshaller = new(); + int __values_native__numElements; + int __values_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native__marshaller.FromManaged(values, stackalloc System.IntPtr[global::SharedTypes.ListMarshallerStateful.Marshaller.BufferSize]); + { + System.ReadOnlySpan __values_native__managedSpan = __values_native__marshaller.GetManagedValuesSource(); + System.Span __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __values_native__managedSpan.Length; ++__i0, ++__values_native__lastIndexMarshalled) + { + __values_native__nativeSpan[__i0] = (System.IntPtr)(int*)global::SharedTypes.IntWrapperMarshallerWithFreeCounts.ConvertToUnmanaged(__values_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __values_native__unused = __values_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __values_native = __values_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(__values_native, numValues); + } + } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __values_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.IntWrapperMarshallerWithFreeCounts.Free((int*)__values_native__nativeSpan[__i0]); + } + } + + __values_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_ptr_array", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte* __values_native, int __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int SumInArray(in global::System.Collections.Generic.List values, int numValues) + { + byte* __values_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __values_native__marshaller = new(); + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native__marshaller.FromManaged(values, stackalloc int[global::SharedTypes.ListMarshallerStateful.Marshaller.BufferSize]); + __values_native__marshaller.GetManagedValuesSource().CopyTo(__values_native__marshaller.GetUnmanagedValuesDestination()); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __values_native__unused = __values_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __values_native = __values_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(&__values_native, numValues); + } + } + finally + { + // Cleanup - Perform required cleanup. + __values_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array_ref", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte** __values_native, int __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Duplicate(ref global::System.Collections.Generic.List values, int numValues) + { + byte* __values_native = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __values_native__marshaller = new(); + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native__marshaller.FromManaged(values); + __values_native__marshaller.GetManagedValuesSource().CopyTo(__values_native__marshaller.GetUnmanagedValuesDestination()); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __values_native = __values_native__marshaller.ToUnmanaged(); + __PInvoke(&__values_native, numValues); + } + + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __values_native__marshaller.FromUnmanaged(__values_native); + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; + __values_native__marshaller.GetUnmanagedValuesSource(__values_native__numElements).CopyTo(__values_native__marshaller.GetManagedValuesDestination(__values_native__numElements)); + values = __values_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __values_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "duplicate_int_array", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __values_native, int __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::System.Collections.Generic.List CreateRange(int start, int end, out int numValues) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); + global::System.Collections.Generic.List __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __retVal_native__marshaller = new(); + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __numValues_native = &numValues) + { + __retVal_native = __PInvoke(start, end, __numValues_native); + } + + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __retVal_native__marshaller.FromUnmanaged(__retVal_native); + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = numValues; + __retVal_native__marshaller.GetUnmanagedValuesSource(__retVal_native__numElements).CopyTo(__retVal_native__marshaller.GetManagedValuesDestination(__retVal_native__numElements)); + __retVal = __retVal_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array", ExactSpelling = true)] + static extern unsafe byte* __PInvoke(int __start_native, int __end_native, int* __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void CreateRange_Out(int start, int end, out int numValues, out global::System.Collections.Generic.List res) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); + System.Runtime.CompilerServices.Unsafe.SkipInit(out res); + byte* __res_native; + // Setup - Perform required setup. + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __res_native__marshaller = new(); + int __res_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __res_native__numElements); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __numValues_native = &numValues) + { + __PInvoke(start, end, __numValues_native, &__res_native); + } + + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __res_native__marshaller.FromUnmanaged(__res_native); + // Unmarshal - Convert native data to managed data. + __res_native__numElements = numValues; + __res_native__marshaller.GetUnmanagedValuesSource(__res_native__numElements).CopyTo(__res_native__marshaller.GetManagedValuesDestination(__res_native__numElements)); + res = __res_native__marshaller.ToManaged(); + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array_out", ExactSpelling = true)] + static extern unsafe void __PInvoke(int __start_native, int __end_native, int* __numValues_native, byte** __res_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::System.Collections.Generic.List GetLongBytes(long l) + { + global::System.Collections.Generic.List __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __retVal_native__marshaller = new(); + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + { + __retVal_native = __PInvoke(l); + } + + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __retVal_native__marshaller.FromUnmanaged(__retVal_native); + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = 8; + __retVal_native__marshaller.GetUnmanagedValuesSource(__retVal_native__numElements).CopyTo(__retVal_native__marshaller.GetManagedValuesDestination(__retVal_native__numElements)); + __retVal = __retVal_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "get_long_bytes", ExactSpelling = true)] + static extern unsafe byte* __PInvoke(long __l_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool AndAllMembers(global::System.Collections.Generic.List pArray, int length) + { + byte* __pArray_native = default; + bool __retVal = default; + byte __retVal_native = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __pArray_native__marshaller = new(); + int __pArray_native__numElements; + int __pArray_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pArray_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __pArray_native__marshaller.FromManaged(pArray, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::SharedTypes.ListMarshallerStateful.Marshaller.BufferSize]); + { + System.ReadOnlySpan __pArray_native__managedSpan = __pArray_native__marshaller.GetManagedValuesSource(); + System.Span __pArray_native__nativeSpan = __pArray_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __pArray_native__managedSpan.Length; ++__i0, ++__pArray_native__lastIndexMarshalled) + { + __pArray_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__pArray_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __pArray_native__unused = __pArray_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pArray_native = __pArray_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__pArray_native, length); + } + + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + } + finally + { + // Cleanup - Perform required cleanup. + _ = __pArray_native__lastIndexMarshalled; + __pArray_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "and_bool_struct_array", ExactSpelling = true)] + static extern unsafe byte __PInvoke(byte* __pArray_native, int __length_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool AndAllMembersIn(in global::System.Collections.Generic.List pArray, int length) + { + byte* __pArray_native = default; + bool __retVal = default; + byte __retVal_native = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __pArray_native__marshaller = new(); + int __pArray_native__numElements; + int __pArray_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pArray_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __pArray_native__marshaller.FromManaged(pArray, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::SharedTypes.ListMarshallerStateful.Marshaller.BufferSize]); + { + System.ReadOnlySpan __pArray_native__managedSpan = __pArray_native__marshaller.GetManagedValuesSource(); + System.Span __pArray_native__nativeSpan = __pArray_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __pArray_native__managedSpan.Length; ++__i0, ++__pArray_native__lastIndexMarshalled) + { + __pArray_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__pArray_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __pArray_native__unused = __pArray_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pArray_native = __pArray_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(&__pArray_native, length); + } + + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + } + finally + { + // Cleanup - Perform required cleanup. + _ = __pArray_native__lastIndexMarshalled; + __pArray_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "and_bool_struct_array_in", ExactSpelling = true)] + static extern unsafe byte __PInvoke(byte** __pArray_native, int __length_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void NegateBools(ref global::System.Collections.Generic.List boolStruct, int numValues) + { + byte* __boolStruct_native = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __boolStruct_native__marshaller = new(); + int __boolStruct_native__numElements; + int __boolStruct_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native__marshaller.FromManaged(boolStruct); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = __boolStruct_native__marshaller.GetManagedValuesSource(); + System.Span __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); + } + } + + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __boolStruct_native = __boolStruct_native__marshaller.ToUnmanaged(); + __PInvoke(&__boolStruct_native, numValues); + } + + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __boolStruct_native__marshaller.FromUnmanaged(__boolStruct_native); + // Unmarshal - Convert native data to managed data. + __boolStruct_native__numElements = numValues; + { + System.ReadOnlySpan __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesSource(__boolStruct_native__numElements); + System.Span __boolStruct_native__managedSpan = __boolStruct_native__marshaller.GetManagedValuesDestination(__boolStruct_native__numElements); + for (int __i0 = 0; __i0 < __boolStruct_native__numElements; ++__i0) + { + __boolStruct_native__managedSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__boolStruct_native__nativeSpan[__i0]); + } + } + + boolStruct = __boolStruct_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + _ = __boolStruct_native__lastIndexMarshalled; + __boolStruct_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_ref", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __boolStruct_native, int __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void NegateBools(global::System.Collections.Generic.List boolStruct, int numValues, out global::System.Collections.Generic.List pBoolStructOut) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out pBoolStructOut); + byte* __boolStruct_native = default; + byte* __pBoolStructOut_native = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __pBoolStructOut_native__marshaller = new(); + int __pBoolStructOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pBoolStructOut_native__numElements); + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __boolStruct_native__marshaller = new(); + int __boolStruct_native__numElements; + int __boolStruct_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native__marshaller.FromManaged(boolStruct, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::SharedTypes.ListMarshallerStateful.Marshaller.BufferSize]); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = __boolStruct_native__marshaller.GetManagedValuesSource(); + System.Span __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __boolStruct_native__unused = __boolStruct_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __boolStruct_native = __boolStruct_native__marshaller.ToUnmanaged(); + __PInvoke(__boolStruct_native, numValues, &__pBoolStructOut_native); + } + + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __pBoolStructOut_native__marshaller.FromUnmanaged(__pBoolStructOut_native); + // Unmarshal - Convert native data to managed data. + __pBoolStructOut_native__numElements = numValues; + { + System.ReadOnlySpan __pBoolStructOut_native__nativeSpan = __pBoolStructOut_native__marshaller.GetUnmanagedValuesSource(__pBoolStructOut_native__numElements); + System.Span __pBoolStructOut_native__managedSpan = __pBoolStructOut_native__marshaller.GetManagedValuesDestination(__pBoolStructOut_native__numElements); + for (int __i0 = 0; __i0 < __pBoolStructOut_native__numElements; ++__i0) + { + __pBoolStructOut_native__managedSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__pBoolStructOut_native__nativeSpan[__i0]); + } + } + + pBoolStructOut = __pBoolStructOut_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + _ = __boolStruct_native__lastIndexMarshalled; + __boolStruct_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_out", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte* __boolStruct_native, int __numValues_native, byte** __pBoolStructOut_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::System.Collections.Generic.List NegateBools(global::System.Collections.Generic.List boolStruct, int numValues) + { + byte* __boolStruct_native = default; + global::System.Collections.Generic.List __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __retVal_native__marshaller = new(); + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __boolStruct_native__marshaller = new(); + int __boolStruct_native__numElements; + int __boolStruct_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native__marshaller.FromManaged(boolStruct, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::SharedTypes.ListMarshallerStateful.Marshaller.BufferSize]); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = __boolStruct_native__marshaller.GetManagedValuesSource(); + System.Span __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __boolStruct_native__unused = __boolStruct_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __boolStruct_native = __boolStruct_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__boolStruct_native, numValues); + } + + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __retVal_native__marshaller.FromUnmanaged(__retVal_native); + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = numValues; + { + 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.BoolStructMarshaller.ConvertToManaged(__retVal_native__nativeSpan[__i0]); + } + } + + __retVal = __retVal_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_native__marshaller.Free(); + _ = __boolStruct_native__lastIndexMarshalled; + __boolStruct_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_return", ExactSpelling = true)] + static extern unsafe byte* __PInvoke(byte* __boolStruct_native, int __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int GuaranteedUnmarshal(out global::System.Collections.Generic.List ret) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + byte* __ret_native = default; + int __retVal = default; + int __retVal_native = default; + // Setup - Perform required setup. + global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.Collections.Stateful.ListGuaranteedUnmarshal.Marshaller __ret_native__marshaller = new(); + int __ret_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __ret_native__numElements); + try + { + { + __retVal_native = __PInvoke(&__ret_native); + } + + __invokeSucceeded = true; + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __ret_native__marshaller.FromUnmanaged(__ret_native); + // Unmarshal - Convert native data to managed data. + __retVal = global::SharedTypes.ExceptionOnUnmarshal.ConvertToManaged(__retVal_native); + } + finally + { + if (__invokeSucceeded) + { + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + ret = __ret_native__marshaller.ToManagedFinally(); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_zero", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte** __ret_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int GuaranteedUnmarshal(out global::System.Collections.Generic.List ret) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + byte* __ret_native = default; + int __retVal = default; + int __retVal_native = default; + // Setup - Perform required setup. + global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.Collections.Stateful.ListGuaranteedUnmarshal.Marshaller __ret_native__marshaller = new(); + int __ret_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __ret_native__numElements); + try + { + { + __retVal_native = __PInvoke(&__ret_native); + } + + __invokeSucceeded = true; + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __ret_native__marshaller.FromUnmanaged(__ret_native); + // Unmarshal - Convert native data to managed data. + __retVal = global::SharedTypes.ExceptionOnUnmarshal.ConvertToManaged(__retVal_native); + } + finally + { + if (__invokeSucceeded) + { + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + ret = __ret_native__marshaller.ToManagedFinally(); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_zero", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte** __ret_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void DeepDuplicateStrings(global::SharedTypes.StringContainer strings, out global::SharedTypes.StringContainer pStringsOut) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out pStringsOut); + global::SharedTypes.StringContainerMarshaller.StringContainerNative __strings_native = default; + global::SharedTypes.StringContainerMarshaller.StringContainerNative __pStringsOut_native = default; + try + { + // Marshal - Convert managed data to native data. + __strings_native = global::SharedTypes.StringContainerMarshaller.In.ConvertToUnmanaged(strings); + { + __PInvoke(__strings_native, &__pStringsOut_native); + } + + // Unmarshal - Convert native data to managed data. + pStringsOut = global::SharedTypes.StringContainerMarshaller.Out.ConvertToManaged(__pStringsOut_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.StringContainerMarshaller.In.Free(__strings_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "stringcontainer_deepduplicate", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.StringContainerMarshaller.StringContainerNative __strings_native, global::SharedTypes.StringContainerMarshaller.StringContainerNative* __pStringsOut_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReverseStrings(ref global::SharedTypes.StringContainer strings) + { + global::SharedTypes.StringContainerMarshaller.StringContainerNative __strings_native = default; + try + { + // Marshal - Convert managed data to native data. + __strings_native = global::SharedTypes.StringContainerMarshaller.Ref.ConvertToUnmanaged(strings); + { + __PInvoke(&__strings_native); + } + + // Unmarshal - Convert native data to managed data. + strings = global::SharedTypes.StringContainerMarshaller.Ref.ConvertToManaged(__strings_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.StringContainerMarshaller.Ref.Free(__strings_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "stringcontainer_reverse_strings", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.StringContainerMarshaller.StringContainerNative* __strings_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial double GetLongBytesAsDouble(double d) + { + long __d_native; + double __retVal; + // Marshal - Convert managed data to native data. + __d_native = global::SharedTypes.DoubleToLongMarshaller.ConvertToUnmanaged(d); + { + __retVal = __PInvoke(__d_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "get_long_bytes_as_double", ExactSpelling = true)] + static extern unsafe double __PInvoke(long __d_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial double GetBytesAsDoubleBigEndian(double d) + { + byte* __d_native; + double __retVal; + // Marshal - Convert managed data to native data. + System.Span __d_native__buffer = stackalloc byte[global::SharedTypes.DoubleToBytesBigEndianMarshaller.BufferSize]; + __d_native = global::SharedTypes.DoubleToBytesBigEndianMarshaller.ConvertToUnmanaged(d, __d_native__buffer); + { + __retVal = __PInvoke(__d_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "get_bytes_as_double_big_endian", ExactSpelling = true)] + static extern unsafe double __PInvoke(byte* __d_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void NegateBools(global::SharedTypes.BoolStruct boolStruct, out global::SharedTypes.BoolStruct pBoolStructOut) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out pBoolStructOut); + global::SharedTypes.BoolStructMarshaller.BoolStructNative __boolStruct_native; + global::SharedTypes.BoolStructMarshaller.BoolStructNative __pBoolStructOut_native; + // Marshal - Convert managed data to native data. + __boolStruct_native = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(boolStruct); + { + __PInvoke(__boolStruct_native, &__pBoolStructOut_native); + } + + // Unmarshal - Convert native data to managed data. + pBoolStructOut = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__pBoolStructOut_native); + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bools", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.BoolStructMarshaller.BoolStructNative __boolStruct_native, global::SharedTypes.BoolStructMarshaller.BoolStructNative* __pBoolStructOut_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool AndBoolsRef(in global::SharedTypes.BoolStruct boolStruct) + { + global::SharedTypes.BoolStructMarshaller.BoolStructNative __boolStruct_native; + bool __retVal; + byte __retVal_native; + // Marshal - Convert managed data to native data. + __boolStruct_native = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(boolStruct); + { + __retVal_native = __PInvoke(&__boolStruct_native); + } + + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "and_bools_ref", ExactSpelling = true)] + static extern unsafe byte __PInvoke(global::SharedTypes.BoolStructMarshaller.BoolStructNative* __boolStruct_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::SharedTypes.IntWrapper DoubleIntRef(global::SharedTypes.IntWrapper pInt) + { + int* __pInt_native = default; + global::SharedTypes.IntWrapper __retVal = default; + int* __retVal_native = default; + try + { + // Marshal - Convert managed data to native data. + __pInt_native = (int*)global::SharedTypes.IntWrapperMarshaller.ConvertToUnmanaged(pInt); + { + __retVal_native = __PInvoke(__pInt_native); + } + + // Unmarshal - Convert native data to managed data. + __retVal = global::SharedTypes.IntWrapperMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.IntWrapperMarshaller.Free(__retVal_native); + global::SharedTypes.IntWrapperMarshaller.Free(__pInt_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "double_int_ref", ExactSpelling = true)] + static extern unsafe int* __PInvoke(int* __pInt_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::SharedTypes.IntWrapperWithoutGetPinnableReference DoubleIntRef(global::SharedTypes.IntWrapperWithoutGetPinnableReference pInt) + { + global::SharedTypes.IntWrapperWithoutGetPinnableReference __retVal = default; + int* __retVal_native = default; + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __pInt_native = &global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.GetPinnableReference(pInt)) + { + __retVal_native = __PInvoke((int*)__pInt_native); + } + + // Unmarshal - Convert native data to managed data. + __retVal = global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.Free(__retVal_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "double_int_ref", ExactSpelling = true)] + static extern unsafe int* __PInvoke(int* __pInt_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int GuaranteedUnmarshal(out int ret) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + int __ret_native = default; + int __retVal = default; + int __retVal_native = default; + try + { + { + __retVal_native = __PInvoke(&__ret_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + ret = global::SharedTypes.ExceptionOnUnmarshal.ConvertToManaged(__ret_native); + } + finally + { + if (__invokeSucceeded) + { + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + __retVal = global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.Stateless.IntGuaranteedUnmarshal.ConvertToManagedFinally(__retVal_native); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_zero", ExactSpelling = true)] + static extern unsafe int __PInvoke(int* __ret_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::SharedTypes.IntWrapperWithNotification SubtractInts(global::SharedTypes.IntWrapperWithNotification x, global::SharedTypes.IntWrapperWithNotification y) + { + int __x_native; + int __y_native; + global::SharedTypes.IntWrapperWithNotification __retVal; + int __retVal_native; + // Setup - Perform required setup. + global::SharedTypes.IntWrapperWithNotificationMarshaller.Marshaller __retVal_native__marshaller = new(); + global::SharedTypes.IntWrapperWithNotificationMarshaller.Marshaller __y_native__marshaller = new(); + global::SharedTypes.IntWrapperWithNotificationMarshaller.Marshaller __x_native__marshaller = new(); + // Marshal - Convert managed data to native data. + __y_native__marshaller.FromManaged(y); + __x_native__marshaller.FromManaged(x); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __y_native = __y_native__marshaller.ToUnmanaged(); + __x_native = __x_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__x_native, __y_native); + } + + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __y_native__marshaller.OnInvoked(); + __x_native__marshaller.OnInvoked(); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __retVal_native__marshaller.FromUnmanaged(__retVal_native); + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native__marshaller.ToManaged(); + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_return_int", ExactSpelling = true)] + static extern unsafe int __PInvoke(int __x_native, int __y_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void SubtractInts(global::SharedTypes.IntWrapperWithNotification x, global::SharedTypes.IntWrapperWithNotification y, out global::SharedTypes.IntWrapperWithNotification result) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out result); + int __x_native; + int __y_native; + int __result_native; + // Setup - Perform required setup. + global::SharedTypes.IntWrapperWithNotificationMarshaller.Marshaller __result_native__marshaller = new(); + global::SharedTypes.IntWrapperWithNotificationMarshaller.Marshaller __y_native__marshaller = new(); + global::SharedTypes.IntWrapperWithNotificationMarshaller.Marshaller __x_native__marshaller = new(); + // Marshal - Convert managed data to native data. + __y_native__marshaller.FromManaged(y); + __x_native__marshaller.FromManaged(x); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __y_native = __y_native__marshaller.ToUnmanaged(); + __x_native = __x_native__marshaller.ToUnmanaged(); + __PInvoke(__x_native, __y_native, &__result_native); + } + + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __y_native__marshaller.OnInvoked(); + __x_native__marshaller.OnInvoked(); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __result_native__marshaller.FromUnmanaged(__result_native); + // Unmarshal - Convert native data to managed data. + result = __result_native__marshaller.ToManaged(); + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_out_int", ExactSpelling = true)] + static extern unsafe void __PInvoke(int __x_native, int __y_native, int* __result_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void NegateBools(global::SharedTypes.BoolStruct boolStruct, out global::SharedTypes.BoolStruct pBoolStructOut) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out pBoolStructOut); + global::SharedTypes.BoolStructMarshallerStateful.BoolStructNative __boolStruct_native; + global::SharedTypes.BoolStructMarshallerStateful.BoolStructNative __pBoolStructOut_native; + // Setup - Perform required setup. + global::SharedTypes.BoolStructMarshallerStateful.Marshaller __pBoolStructOut_native__marshaller = new(); + global::SharedTypes.BoolStructMarshallerStateful.Marshaller __boolStruct_native__marshaller = new(); + // Marshal - Convert managed data to native data. + __boolStruct_native__marshaller.FromManaged(boolStruct); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __boolStruct_native = __boolStruct_native__marshaller.ToUnmanaged(); + __PInvoke(__boolStruct_native, &__pBoolStructOut_native); + } + + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __pBoolStructOut_native__marshaller.FromUnmanaged(__pBoolStructOut_native); + // Unmarshal - Convert native data to managed data. + pBoolStructOut = __pBoolStructOut_native__marshaller.ToManaged(); + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bools", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.BoolStructMarshallerStateful.BoolStructNative __boolStruct_native, global::SharedTypes.BoolStructMarshallerStateful.BoolStructNative* __pBoolStructOut_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool AndBoolsRef(in global::SharedTypes.BoolStruct boolStruct) + { + global::SharedTypes.BoolStructMarshallerStateful.BoolStructNative __boolStruct_native; + bool __retVal; + byte __retVal_native; + // Setup - Perform required setup. + global::SharedTypes.BoolStructMarshallerStateful.Marshaller __boolStruct_native__marshaller = new(); + // Marshal - Convert managed data to native data. + __boolStruct_native__marshaller.FromManaged(boolStruct); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __boolStruct_native = __boolStruct_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(&__boolStruct_native); + } + + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "and_bools_ref", ExactSpelling = true)] + static extern unsafe byte __PInvoke(global::SharedTypes.BoolStructMarshallerStateful.BoolStructNative* __boolStruct_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::SharedTypes.IntWrapperWithoutGetPinnableReference DoubleIntRef(global::SharedTypes.IntWrapperWithoutGetPinnableReference pInt) + { + global::SharedTypes.IntWrapperWithoutGetPinnableReference __retVal = default; + int* __retVal_native = default; + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __pInt_native = &global::SharedTypes.IntWrapperWithoutGetPinnableReferenceStatefulMarshaller.StatelessGetPinnableReference.GetPinnableReference(pInt)) + { + __retVal_native = __PInvoke((int*)__pInt_native); + } + + // Unmarshal - Convert native data to managed data. + __retVal = global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.Free(__retVal_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "double_int_ref", ExactSpelling = true)] + static extern unsafe int* __PInvoke(int* __pInt_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::SharedTypes.IntWrapperWithoutGetPinnableReference DoubleIntRefNoAlloc(global::SharedTypes.IntWrapperWithoutGetPinnableReference pInt) + { + int* __pInt_native = default; + global::SharedTypes.IntWrapperWithoutGetPinnableReference __retVal = default; + int* __retVal_native = default; + // Setup - Perform required setup. + global::SharedTypes.IntWrapperWithoutGetPinnableReferenceStatefulNoAllocMarshaller.StatefulGetPinnableReference __pInt_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __pInt_native__marshaller.FromManaged(pInt); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __pInt_native__unused = __pInt_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pInt_native = __pInt_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__pInt_native); + } + + // Unmarshal - Convert native data to managed data. + __retVal = global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.Free(__retVal_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "double_int_ref", ExactSpelling = true)] + static extern unsafe int* __PInvoke(int* __pInt_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::SharedTypes.IntWrapper DoubleIntRef(global::SharedTypes.IntWrapper pInt) + { + int* __pInt_native = default; + global::SharedTypes.IntWrapper __retVal = default; + int* __retVal_native = default; + // Setup - Perform required setup. + global::SharedTypes.IntWrapperMarshallerStateful.Marshaller __retVal_native__marshaller = new(); + global::SharedTypes.IntWrapperMarshallerStateful.Marshaller __pInt_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __pInt_native__marshaller.FromManaged(pInt); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pInt_native = __pInt_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__pInt_native); + } + + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __retVal_native__marshaller.FromUnmanaged(__retVal_native); + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_native__marshaller.Free(); + __pInt_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "double_int_ref", ExactSpelling = true)] + static extern unsafe int* __PInvoke(int* __pInt_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int GuaranteedUnmarshal(out int ret) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + int __ret_native = default; + int __retVal = default; + int __retVal_native = default; + // Setup - Perform required setup. + global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.Stateful.IntGuaranteedUnmarshal.Marshaller __retVal_native__marshaller = new(); + try + { + { + __retVal_native = __PInvoke(&__ret_native); + } + + __invokeSucceeded = true; + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __retVal_native__marshaller.FromUnmanaged(__retVal_native); + // Unmarshal - Convert native data to managed data. + ret = global::SharedTypes.ExceptionOnUnmarshal.ConvertToManaged(__ret_native); + } + finally + { + if (__invokeSucceeded) + { + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + __retVal = __retVal_native__marshaller.ToManagedFinally(); + } + + // Cleanup - Perform required cleanup. + __retVal_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_zero", ExactSpelling = true)] + static extern unsafe int __PInvoke(int* __ret_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReverseReplaceString(ref string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnStringLength(string s) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __retVal = __PInvoke((ushort*)__s_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_ushort", ExactSpelling = true)] + static extern unsafe int __PInvoke(ushort* __s_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void InvokeAfterGC(global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.VoidVoid cb) + { + System.IntPtr __cb_native; + // Marshal - Convert managed data to native data. + __cb_native = cb != null ? System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(cb) : default; + { + __PInvoke(__cb_native); + } + + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + global::System.GC.KeepAlive(cb); + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "invoke_callback_after_gc", ExactSpelling = true)] + static extern unsafe void __PInvoke(System.IntPtr __cb_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int InvokeWithBlittableArgument(global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.IntIntInt cb, int a, int b) + { + System.IntPtr __cb_native; + int __retVal; + // Marshal - Convert managed data to native data. + __cb_native = cb != null ? System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(cb) : default; + { + __retVal = __PInvoke(__cb_native, a, b); + } + + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + global::System.GC.KeepAlive(cb); + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "invoke_callback_blittable_args", ExactSpelling = true)] + static extern unsafe int __PInvoke(System.IntPtr __cb_native, int __a_native, int __b_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class IntEnum + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_return_int", ExactSpelling = true)] + public static extern partial global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum Subtract_Return(global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum a, global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum b); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class IntEnum + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Subtract_Out(global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum a, global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum b, out global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum c) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out c); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum* __c_native = &c) + { + __PInvoke(a, b, __c_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_out_int", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum __a_native, global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum __b_native, global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum* __c_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class IntEnum + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Subtract_Ref(global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum a, ref global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum b) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum* __b_native = &b) + { + __PInvoke(a, __b_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_ref_int", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum __a_native, global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum* __b_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class IntEnum + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Subtract_In(global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum a, in global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum b) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum* __b_native = &b) + { + __PInvoke(a, __b_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_ref_int", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum __a_native, global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum* __b_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class ByteEnum + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_return_byte", ExactSpelling = true)] + public static extern partial global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum Subtract_Return(global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum a, global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum b); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class ByteEnum + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Subtract_Out(global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum a, global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum b, out global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum c) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out c); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum* __c_native = &c) + { + __PInvoke(a, b, __c_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_out_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum __a_native, global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum __b_native, global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum* __c_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class ByteEnum + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Subtract_Ref(global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum a, ref global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum b) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum* __b_native = &b) + { + __PInvoke(a, __b_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum __a_native, global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum* __b_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class ByteEnum + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Subtract_In(global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum a, in global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum b) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum* __b_native = &b) + { + __PInvoke(a, __b_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum __a_native, global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum* __b_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class FunctionPointer + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "invoke_managed_callback_after_gc", ExactSpelling = true)] + public static unsafe extern partial void InvokeAfterGC(delegate* cb); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class FunctionPointer + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "invoke_callback_after_gc", ExactSpelling = true)] + public static unsafe extern partial void InvokeAfterGC(delegate* unmanaged cb); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class FunctionPointer + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "invoke_callback_after_gc", ExactSpelling = true)] + public static unsafe extern partial void InvokeAfterGC(delegate* unmanaged[Stdcall] cb); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class FunctionPointer + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "invoke_managed_callback_blittable_args", ExactSpelling = true)] + public static unsafe extern partial int InvokeWithBlittableArgument(delegate* cb, int a, int b); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class FunctionPointer + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "invoke_callback_blittable_args", ExactSpelling = true)] + public static unsafe extern partial int InvokeWithBlittableArgument(delegate* unmanaged cb, int a, int b); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class FunctionPointer + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "invoke_callback_blittable_args", ExactSpelling = true)] + public static unsafe extern partial int InvokeWithBlittableArgument(delegate* unmanaged[Stdcall] cb, int a, int b); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_ref_int", ExactSpelling = true)] + public static unsafe extern partial void Subtract_Int_Ptr(int a, int* b); + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_ref_byte", ExactSpelling = true)] + public static unsafe extern partial void Subtract_Byte_Ptr(byte a, byte* b); + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "blittablestructs_double_intfields_byref", ExactSpelling = true)] + public static unsafe extern partial void DoubleIntFields_Ptr(global::SharedTypes.IntFields* result); + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class NativeExportsSafeHandle + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + private static partial global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.NativeExportsSafeHandle AllocateHandle() + { + global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.NativeExportsSafeHandle __retVal = default; + nint __retVal_native = default; + // Setup - Perform required setup. + global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller.ManagedToUnmanagedOut __retVal_native__marshaller = new(); + try + { + { + __retVal_native = __PInvoke(); + } + + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __retVal_native__marshaller.FromUnmanaged(__retVal_native); + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "alloc_handle", ExactSpelling = true)] + static extern unsafe nint __PInvoke(); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.NativeExportsSafeHandle AllocateHandle() + { + global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.NativeExportsSafeHandle __retVal = default; + nint __retVal_native = default; + // Setup - Perform required setup. + global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller.ManagedToUnmanagedOut __retVal_native__marshaller = new(); + try + { + { + __retVal_native = __PInvoke(); + } + + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __retVal_native__marshaller.FromUnmanaged(__retVal_native); + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "alloc_handle", ExactSpelling = true)] + static extern unsafe nint __PInvoke(); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void AllocateHandle(out global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.NativeExportsSafeHandle handle) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out handle); + nint __handle_native; + // Setup - Perform required setup. + global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller.ManagedToUnmanagedOut __handle_native__marshaller = new(); + { + __PInvoke(&__handle_native); + } + + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __handle_native__marshaller.FromUnmanaged(__handle_native); + // Unmarshal - Convert native data to managed data. + handle = __handle_native__marshaller.ToManaged(); + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "alloc_handle_out", ExactSpelling = true)] + static extern unsafe void __PInvoke(nint* __handle_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + private static partial bool ReleaseHandle(nint handle) + { + bool __retVal; + sbyte __retVal_native; + { + __retVal_native = __PInvoke(handle); + } + + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "release_handle", ExactSpelling = true)] + static extern unsafe sbyte __PInvoke(nint __handle_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool IsHandleAlive(global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.NativeExportsSafeHandle handle) + { + nint __handle_native = default; + bool __retVal = default; + sbyte __retVal_native = default; + // Setup - Perform required setup. + global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller.ManagedToUnmanagedIn __handle_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __handle_native__marshaller.FromManaged(handle); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __handle_native = __handle_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__handle_native); + } + + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + } + finally + { + // Cleanup - Perform required cleanup. + __handle_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "is_handle_alive", ExactSpelling = true)] + static extern unsafe sbyte __PInvoke(nint __handle_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ModifyHandle(ref global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.NativeExportsSafeHandle handle, bool newHandle) + { + bool __invokeSucceeded = default; + nint __handle_native = default; + sbyte __newHandle_native = default; + // Setup - Perform required setup. + global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller.ManagedToUnmanagedRef __handle_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __newHandle_native = (sbyte)(newHandle ? 1 : 0); + __handle_native__marshaller.FromManaged(handle); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __handle_native = __handle_native__marshaller.ToUnmanaged(); + __PInvoke(&__handle_native, __newHandle_native); + } + + __invokeSucceeded = true; + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __handle_native__marshaller.OnInvoked(); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __handle_native__marshaller.FromUnmanaged(__handle_native); + } + finally + { + if (__invokeSucceeded) + { + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + handle = __handle_native__marshaller.ToManagedFinally(); + } + + // Cleanup - Perform required cleanup. + __handle_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "modify_handle", ExactSpelling = true)] + static extern unsafe void __PInvoke(nint* __handle_native, sbyte __newHandle_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class SetLastError + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int SetError(int error, byte shouldSetError) + { + int __lastError; + int __retVal; + { + System.Runtime.InteropServices.Marshal.SetLastSystemError(0); + __retVal = __PInvoke(error, shouldSetError); + __lastError = System.Runtime.InteropServices.Marshal.GetLastSystemError(); + } + + System.Runtime.InteropServices.Marshal.SetLastPInvokeError(__lastError); + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "set_error", ExactSpelling = true)] + static extern unsafe int __PInvoke(int __error_native, byte __shouldSetError_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class SetLastError + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int SetError_CustomMarshallingSetsError(int error, byte shouldSetError) + { + int __lastError; + int __retVal; + int __retVal_native; + { + System.Runtime.InteropServices.Marshal.SetLastSystemError(0); + __retVal_native = __PInvoke(error, shouldSetError); + __lastError = System.Runtime.InteropServices.Marshal.GetLastSystemError(); + } + + // Unmarshal - Convert native data to managed data. + __retVal = global::LibraryImportGenerator.IntegrationTests.SetLastErrorMarshaller.ConvertToManaged(__retVal_native); + System.Runtime.InteropServices.Marshal.SetLastPInvokeError(__lastError); + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "set_error", ExactSpelling = true)] + static extern unsafe int __PInvoke(int __error_native, byte __shouldSetError_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class SetLastError + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial string SetError_NonBlittableSignature(int error, bool shouldSetError, string errorString) + { + int __lastError; + byte __shouldSetError_native = default; + string __retVal = default; + ushort* __retVal_native = default; + try + { + // Marshal - Convert managed data to native data. + __shouldSetError_native = (byte)(shouldSetError ? 1 : 0); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __errorString_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(errorString)) + { + System.Runtime.InteropServices.Marshal.SetLastSystemError(0); + __retVal_native = __PInvoke(error, __shouldSetError_native, (ushort*)__errorString_native); + __lastError = System.Runtime.InteropServices.Marshal.GetLastSystemError(); + } + + // Unmarshal - Convert native data to managed data. + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + } + + System.Runtime.InteropServices.Marshal.SetLastPInvokeError(__lastError); + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "set_error_return_string", ExactSpelling = true)] + static extern unsafe ushort* __PInvoke(int __error_native, byte __shouldSetError_native, ushort* __errorString_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Span + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int Sum(global::System.Span values, int numValues) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __values_native = &global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.ManagedToUnmanagedIn.GetPinnableReference(values)) + { + __retVal = __PInvoke((int*)__values_native, numValues); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array", ExactSpelling = true)] + static extern unsafe int __PInvoke(int* __values_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Span + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int Sum(global::System.ReadOnlySpan values, int numValues) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __values_native = &global::System.Runtime.InteropServices.Marshalling.ReadOnlySpanMarshaller.ManagedToUnmanagedIn.GetPinnableReference(values)) + { + __retVal = __PInvoke((int*)__values_native, numValues); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array", ExactSpelling = true)] + static extern unsafe int __PInvoke(int* __values_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Span + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int SumInArray(in global::System.Span values, int numValues) + { + int* __values_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.ManagedToUnmanagedIn __values_native__marshaller = new(); + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native__marshaller.FromManaged(values, stackalloc int[global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.ManagedToUnmanagedIn.BufferSize]); + __values_native__marshaller.GetManagedValuesSource().CopyTo(__values_native__marshaller.GetUnmanagedValuesDestination()); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __values_native__unused = __values_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __values_native = __values_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(&__values_native, numValues); + } + } + finally + { + // Cleanup - Perform required cleanup. + __values_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array_ref", ExactSpelling = true)] + static extern unsafe int __PInvoke(int** __values_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Span + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Duplicate(ref global::System.Span values, int numValues) + { + int* __values_native = default; + // Setup - Perform required setup. + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native = global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetManagedValuesSource(values).CopyTo(global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); + { + __PInvoke(&__values_native, numValues); + } + + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; + values = global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetManagedValuesDestination(values)); + } + finally + { + // Cleanup - Perform required cleanup. + __values_native__numElements = numValues; + global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.Free(__values_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "duplicate_int_array", ExactSpelling = true)] + static extern unsafe void __PInvoke(int** __values_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Span + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::System.Span CreateRange(int start, int end, out int numValues) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); + global::System.Span __retVal = default; + int* __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __numValues_native = &numValues) + { + __retVal_native = __PInvoke(start, end, __numValues_native); + } + + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = numValues; + __retVal = global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetManagedValuesDestination(__retVal)); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_native__numElements = numValues; + global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.Free(__retVal_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array", ExactSpelling = true)] + static extern unsafe int* __PInvoke(int __start_native, int __end_native, int* __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Span + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void CreateRange_Out(int start, int end, out int numValues, out global::System.Span res) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); + res = default; + int* __res_native; + // Setup - Perform required setup. + int __res_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __res_native__numElements); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __numValues_native = &numValues) + { + __PInvoke(start, end, __numValues_native, &__res_native); + } + + // Unmarshal - Convert native data to managed data. + __res_native__numElements = numValues; + res = global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.AllocateContainerForManagedElements(__res_native, __res_native__numElements); + global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetUnmanagedValuesSource(__res_native, __res_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetManagedValuesDestination(res)); + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array_out", ExactSpelling = true)] + static extern unsafe void __PInvoke(int __start_native, int __end_native, int* __numValues_native, int** __res_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Span + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::System.Span GetLongBytes(long l) + { + global::System.Span __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + { + __retVal_native = __PInvoke(l); + } + + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = 8; + __retVal = global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetManagedValuesDestination(__retVal)); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_native__numElements = 8; + global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.Free(__retVal_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "get_long_bytes", ExactSpelling = true)] + static extern unsafe byte* __PInvoke(long __l_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Span + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool AndAllMembers(global::System.Span pArray, int length) + { + global::SharedTypes.BoolStructMarshaller.BoolStructNative* __pArray_native = default; + bool __retVal = default; + byte __retVal_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.ManagedToUnmanagedIn __pArray_native__marshaller = new(); + int __pArray_native__numElements; + int __pArray_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pArray_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __pArray_native__marshaller.FromManaged(pArray, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __pArray_native__managedSpan = __pArray_native__marshaller.GetManagedValuesSource(); + System.Span __pArray_native__nativeSpan = __pArray_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __pArray_native__managedSpan.Length; ++__i0, ++__pArray_native__lastIndexMarshalled) + { + __pArray_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__pArray_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __pArray_native__unused = __pArray_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pArray_native = __pArray_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__pArray_native, length); + } + + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + } + finally + { + // Cleanup - Perform required cleanup. + _ = __pArray_native__lastIndexMarshalled; + __pArray_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "and_bool_struct_array", ExactSpelling = true)] + static extern unsafe byte __PInvoke(global::SharedTypes.BoolStructMarshaller.BoolStructNative* __pArray_native, int __length_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Utf16 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength(string s) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __retVal = __PInvoke((ushort*)__s_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_ushort", ExactSpelling = true)] + static extern unsafe int __PInvoke(ushort* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Utf16 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial string Reverse_Return(string s) + { + string __retVal = default; + ushort* __retVal_native = default; + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __retVal_native = __PInvoke((ushort*)__s_native); + } + + // Unmarshal - Convert native data to managed data. + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_return_ushort", ExactSpelling = true)] + static extern unsafe ushort* __PInvoke(ushort* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Utf16 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Out(string s, out string ret) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + ushort* __ret_native; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __PInvoke((ushort*)__s_native, &__ret_native); + } + + // Unmarshal - Convert native data to managed data. + ret = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__ret_native); + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort* __s_native, ushort** __ret_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Utf16 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Ref(ref string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Utf16 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_In(in string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Utf16 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Replace_Ref(ref string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPTStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength(string s) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __retVal = __PInvoke((ushort*)__s_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_ushort", ExactSpelling = true)] + static extern unsafe int __PInvoke(ushort* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPTStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength_IgnoreStringMarshalling(string s) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __retVal = __PInvoke((ushort*)__s_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_ushort", ExactSpelling = true)] + static extern unsafe int __PInvoke(ushort* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPTStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial string Reverse_Return(string s) + { + string __retVal = default; + ushort* __retVal_native = default; + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __retVal_native = __PInvoke((ushort*)__s_native); + } + + // Unmarshal - Convert native data to managed data. + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_return_ushort", ExactSpelling = true)] + static extern unsafe ushort* __PInvoke(ushort* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPTStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Out(string s, out string ret) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + ushort* __ret_native; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __PInvoke((ushort*)__s_native, &__ret_native); + } + + // Unmarshal - Convert native data to managed data. + ret = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__ret_native); + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort* __s_native, ushort** __ret_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPTStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Ref(ref string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPTStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_In(in string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPTStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Replace_Ref(ref string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPWStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength(string s) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __retVal = __PInvoke((ushort*)__s_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_ushort", ExactSpelling = true)] + static extern unsafe int __PInvoke(ushort* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPWStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength_IgnoreStringMarshalling(string s) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __retVal = __PInvoke((ushort*)__s_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_ushort", ExactSpelling = true)] + static extern unsafe int __PInvoke(ushort* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPWStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial string Reverse_Return(string s) + { + string __retVal = default; + ushort* __retVal_native = default; + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __retVal_native = __PInvoke((ushort*)__s_native); + } + + // Unmarshal - Convert native data to managed data. + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_return_ushort", ExactSpelling = true)] + static extern unsafe ushort* __PInvoke(ushort* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPWStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Out(string s, out string ret) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + ushort* __ret_native; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __PInvoke((ushort*)__s_native, &__ret_native); + } + + // Unmarshal - Convert native data to managed data. + ret = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__ret_native); + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort* __s_native, ushort** __ret_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPWStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Ref(ref string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPWStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_In(in string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPWStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Replace_Ref(ref string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPUTF8Str + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength(string s) + { + byte* __s_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(__s_native); + } + } + finally + { + // Cleanup - Perform required cleanup. + __s_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_byte", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPUTF8Str + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength_IgnoreStringMarshalling(string s) + { + byte* __s_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(__s_native); + } + } + finally + { + // Cleanup - Perform required cleanup. + __s_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_byte", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPUTF8Str + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial string Reverse_Return(string s) + { + byte* __s_native = default; + string __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__s_native); + } + + // Unmarshal - Convert native data to managed data. + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); + __s_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_return_byte", ExactSpelling = true)] + static extern unsafe byte* __PInvoke(byte* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPUTF8Str + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Out(string s, out string ret) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + byte* __s_native = default; + byte* __ret_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __PInvoke(__s_native, &__ret_native); + } + + // Unmarshal - Convert native data to managed data. + ret = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__ret_native); + } + finally + { + // Cleanup - Perform required cleanup. + __s_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte* __s_native, byte** __ret_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPUTF8Str + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_In(in string s) + { + byte* __s_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __PInvoke(&__s_native); + } + } + finally + { + // Cleanup - Perform required cleanup. + __s_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPUTF8Str + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Ref(ref string s) + { + byte* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPUTF8Str + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Replace_Ref(ref string s) + { + byte* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Utf8 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength(string s) + { + byte* __s_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(__s_native); + } + } + finally + { + // Cleanup - Perform required cleanup. + __s_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_byte", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Utf8 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial string Reverse_Return(string s) + { + byte* __s_native = default; + string __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__s_native); + } + + // Unmarshal - Convert native data to managed data. + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); + __s_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_return_byte", ExactSpelling = true)] + static extern unsafe byte* __PInvoke(byte* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Utf8 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Out(string s, out string ret) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + byte* __s_native = default; + byte* __ret_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __PInvoke(__s_native, &__ret_native); + } + + // Unmarshal - Convert native data to managed data. + ret = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__ret_native); + } + finally + { + // Cleanup - Perform required cleanup. + __s_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte* __s_native, byte** __ret_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Utf8 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Ref(ref string s) + { + byte* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Utf8 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_In(in string s) + { + byte* __s_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __PInvoke(&__s_native); + } + } + finally + { + // Cleanup - Perform required cleanup. + __s_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Utf8 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Replace_Ref(ref string s) + { + byte* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength(string s) + { + byte* __s_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(__s_native); + } + } + finally + { + // Cleanup - Perform required cleanup. + __s_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_byte", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength_IgnoreStringMarshalling(string s) + { + byte* __s_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(__s_native); + } + } + finally + { + // Cleanup - Perform required cleanup. + __s_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_byte", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial string Reverse_Return(string s) + { + byte* __s_native = default; + string __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__s_native); + } + + // Unmarshal - Convert native data to managed data. + __retVal = global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.Free(__retVal_native); + __s_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_return_byte", ExactSpelling = true)] + static extern unsafe byte* __PInvoke(byte* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Out(string s, out string ret) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + byte* __s_native = default; + byte* __ret_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __PInvoke(__s_native, &__ret_native); + } + + // Unmarshal - Convert native data to managed data. + ret = global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ConvertToManaged(__ret_native); + } + finally + { + // Cleanup - Perform required cleanup. + __s_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte* __s_native, byte** __ret_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Ref(ref string s) + { + byte* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (byte*)global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_In(in string s) + { + byte* __s_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __PInvoke(&__s_native); + } + } + finally + { + // Cleanup - Perform required cleanup. + __s_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Replace_Ref(ref string s) + { + byte* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (byte*)global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class BStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength(string s) + { + ushort* __s_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(__s_native); + } + } + finally + { + // Cleanup - Perform required cleanup. + __s_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_bstr", ExactSpelling = true)] + static extern unsafe int __PInvoke(ushort* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class BStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength_IgnoreStringMarshalling(string s) + { + ushort* __s_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(__s_native); + } + } + finally + { + // Cleanup - Perform required cleanup. + __s_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_bstr", ExactSpelling = true)] + static extern unsafe int __PInvoke(ushort* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class BStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial string Reverse_Return(string s) + { + ushort* __s_native = default; + string __retVal = default; + ushort* __retVal_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__s_native); + } + + // Unmarshal - Convert native data to managed data. + __retVal = global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.Free(__retVal_native); + __s_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_return_bstr", ExactSpelling = true)] + static extern unsafe ushort* __PInvoke(ushort* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class BStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Out(string s, out string ret) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + ushort* __s_native = default; + ushort* __ret_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __PInvoke(__s_native, &__ret_native); + } + + // Unmarshal - Convert native data to managed data. + ret = global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ConvertToManaged(__ret_native); + } + finally + { + // Cleanup - Perform required cleanup. + __s_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_bstr", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort* __s_native, ushort** __ret_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class BStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Ref(ref string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_bstr", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class BStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_In(in string s) + { + ushort* __s_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __PInvoke(&__s_native); + } + } + finally + { + // Cleanup - Perform required cleanup. + __s_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_bstr", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class BStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Replace_Ref(ref string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_bstr", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class StringMarshallingCustomType + { + public unsafe partial class Utf16 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength(string s) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __retVal = __PInvoke((ushort*)__s_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_ushort", ExactSpelling = true)] + static extern unsafe int __PInvoke(ushort* __s_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class StringMarshallingCustomType + { + public unsafe partial class Utf16 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial string Reverse_Return(string s) + { + string __retVal = default; + ushort* __retVal_native = default; + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __retVal_native = __PInvoke((ushort*)__s_native); + } + + // Unmarshal - Convert native data to managed data. + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_return_ushort", ExactSpelling = true)] + static extern unsafe ushort* __PInvoke(ushort* __s_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class StringMarshallingCustomType + { + public unsafe partial class Utf16 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Out(string s, out string ret) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + ushort* __ret_native; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __PInvoke((ushort*)__s_native, &__ret_native); + } + + // Unmarshal - Convert native data to managed data. + ret = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__ret_native); + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort* __s_native, ushort** __ret_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class StringMarshallingCustomType + { + public unsafe partial class Utf16 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Ref(ref string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class StringMarshallingCustomType + { + public unsafe partial class Utf16 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_In(in string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class StringMarshallingCustomType + { + public unsafe partial class Utf16 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Replace_Ref(ref string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class StringMarshallingCustomType + { + public unsafe partial class Utf8 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength(string s) + { + byte* __s_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(__s_native); + } + } + finally + { + // Cleanup - Perform required cleanup. + __s_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_byte", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte* __s_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class StringMarshallingCustomType + { + public unsafe partial class Utf8 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial string Reverse_Return(string s) + { + byte* __s_native = default; + string __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__s_native); + } + + // Unmarshal - Convert native data to managed data. + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); + __s_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_return_byte", ExactSpelling = true)] + static extern unsafe byte* __PInvoke(byte* __s_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class StringMarshallingCustomType + { + public unsafe partial class Utf8 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Out(string s, out string ret) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + byte* __s_native = default; + byte* __ret_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __PInvoke(__s_native, &__ret_native); + } + + // Unmarshal - Convert native data to managed data. + ret = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__ret_native); + } + finally + { + // Cleanup - Perform required cleanup. + __s_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte* __s_native, byte** __ret_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class StringMarshallingCustomType + { + public unsafe partial class Utf8 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Ref(ref string s) + { + byte* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __s_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class StringMarshallingCustomType + { + public unsafe partial class Utf8 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_In(in string s) + { + byte* __s_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __PInvoke(&__s_native); + } + } + finally + { + // Cleanup - Perform required cleanup. + __s_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __s_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class StringMarshallingCustomType + { + public unsafe partial class Utf8 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Replace_Ref(ref string s) + { + byte* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __s_native); + } + } + } + } +} From 8d4127e20e51ef8c0915eefaa873bfd92a47c655 Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Thu, 27 Jul 2023 11:03:44 -0700 Subject: [PATCH 8/8] Make sure we cleanup right on stateless values --- ...atelessCallerAllocatedBufferMarshalling.cs | 31 + ...mInterfaces.StatelessFinallyMarshalling.cs | 31 + ...omInterfaces.StatelessPinnedMarshalling.cs | 31 + ...ComInterfaces.IArrayOfStatelessElements.cs | 138 ++-- .../SharedTypes.ComInterfaces.IBool.cs | 4 +- ...nterfaces.ICustomStringMarshallingUtf16.cs | 31 +- .../SharedTypes.ComInterfaces.IDerived.cs | 31 +- .../SharedTypes.ComInterfaces.IEnumUnknown.cs | 61 +- .../SharedTypes.ComInterfaces.IFloat.cs | 4 +- ...SharedTypes.ComInterfaces.IGetAndSetInt.cs | 4 +- .../SharedTypes.ComInterfaces.IGetIntArray.cs | 35 +- .../SharedTypes.ComInterfaces.IInt.cs | 12 +- .../SharedTypes.ComInterfaces.IIntArray.cs | 163 +++-- .../SharedTypes.ComInterfaces.IInterface.cs | 69 +- ...aredTypes.ComInterfaces.IJaggedIntArray.cs | 163 +++-- .../SharedTypes.ComInterfaces.IRefStrings.cs | 38 +- ...aredTypes.ComInterfaces.ISafeFileHandle.cs | 28 +- ...tatefulCallerAllocatedBufferMarshalling.cs | 425 ++++++++++++ ...ces.IStatefulCollectionBlittableElement.cs | 99 +-- ...ces.IStatefulCollectionStatelessElement.cs | 147 ++-- ...mInterfaces.IStatefulFinallyMarshalling.cs | 465 +++++++++++++ ...ypes.ComInterfaces.IStatefulMarshalling.cs | 85 ++- ...omInterfaces.IStatefulPinnedMarshalling.cs | 443 +++++++++++++ ...tatelessCallerAllocateBufferMarshalling.cs | 379 +++++++++++ ...es.IStatelessCollectionBlittableElement.cs | 89 +-- ...es.IStatelessCollectionStatelessElement.cs | 145 ++-- ...Interfaces.IStatelessFinallyMarshalling.cs | 407 ++++++++++++ ...pes.ComInterfaces.IStatelessMarshalling.cs | 83 ++- ...mInterfaces.IStatelessPinnedMarshalling.cs | 368 ++++++++++ ...omInterfaces.IStringMarshallingOverride.cs | 77 ++- ...faces.IStringMarshallingOverrideDerived.cs | 136 ++-- ...edTypes.ComInterfaces.IUTF16Marshalling.cs | 31 +- ...redTypes.ComInterfaces.IUTF8Marshalling.cs | 31 +- ...allingFails.ICollectionMarshallingFails.cs | 59 +- ...ngFails.IJaggedIntArrayMarshallingFails.cs | 199 ++++-- ...llingFails.IStringArrayMarshallingFails.cs | 128 ++-- .../ManagedToNativeStubs.g.cs | 4 +- .../NativeToManagedStubs.g.cs | 627 +++++++++++------- .../LibraryImports.g.cs | 1 - .../LibraryImports.g.cs | 351 ++++++---- 40 files changed, 4560 insertions(+), 1093 deletions(-) create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferMarshalling.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessFinallyMarshalling.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessPinnedMarshalling.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulFinallyMarshalling.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulPinnedMarshalling.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessFinallyMarshalling.cs create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessPinnedMarshalling.cs diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferMarshalling.cs new file mode 100644 index 0000000..cfdc220 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferMarshalling.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.IStatelessCallerAllocateBufferMarshalling).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 StatelessCallerAllocatedBufferMarshalling + { + } +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessFinallyMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessFinallyMarshalling.cs new file mode 100644 index 0000000..db62952 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessFinallyMarshalling.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.IStatelessFinallyMarshalling).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 StatelessFinallyMarshalling + { + } +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessPinnedMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessPinnedMarshalling.cs new file mode 100644 index 0000000..ab38470 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessPinnedMarshalling.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.IStatelessPinnedMarshalling).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 StatelessPinnedMarshalling + { + } +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IArrayOfStatelessElements.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IArrayOfStatelessElements.cs index c8eb16f..85ffe63 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IArrayOfStatelessElements.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IArrayOfStatelessElements.cs @@ -121,27 +121,43 @@ { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatelessElements)); System.Runtime.CompilerServices.Unsafe.SkipInit(out param); - nint* __param_native; - int __invokeRetVal; + nint* __param_native = default; + int __invokeRetVal = default; // Setup - Perform required setup. int __param_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__param_native, size); - } + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__param_native, size); + } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __param_native__numElements = size; - param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __param_native__numElements = size; + param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); + for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + { + __param_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native__nativeSpan[__i0]); + } + } + } + finally { - System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); - System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); - for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) + // Cleanup - Perform required cleanup. { - __param_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native__nativeSpan[__i0]); + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__param_native, __param_native__numElements); + for (int __i0 = 0; __i0 < __param_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan[__i0]); + } } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__param_native); } } @@ -198,7 +214,6 @@ } } - __param_native__numElements = size; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__param_native); } } @@ -295,6 +310,14 @@ finally { // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan[__i0]); + } + } + __param_native__marshaller.Free(); } } @@ -463,6 +486,9 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com __param_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__param_native__managedSpan[__i0]); } } + + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; } catch (System.Exception __exception) { @@ -474,12 +500,12 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com { global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan[__i0]); } - }; + } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__param_native__out); return __retVal; } - // AssignOut - Assign to parameters - *__param_native__param = __param_native__out; return __retVal; } @@ -522,6 +548,19 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com __param_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__param_native__managedSpan[__i0]); } } + + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan[__i0]); + } + } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__param_native); } catch (System.Exception __exception) { @@ -535,24 +574,10 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com } } - __param_native__numElements = size; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__param_native__out); return __retVal; } - // AssignOut - Assign to parameters - *__param_native__param = __param_native__out; - // Cleanup - Perform required cleanup. - { - System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); - for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) - { - global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan[__i0]); - } - } - - __param_native__numElements = size; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__param_native); return __retVal; } @@ -601,20 +626,20 @@ internal static int ABI_MethodContentsOut(System.Runtime.InteropServices.ComWrap // Setup - Perform required setup. int __param_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); - System.Span __param_native__out; + scoped System.Span __param_native__out = default; try { // Unmarshal - Convert native data to managed data. __retVal = 0; // S_OK global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param).Clear(); + __param_native__numElements = size; + param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodContentsOut(param, size); // Marshal - Convert managed data to native data. { __param_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param).Length; -#pragma warning disable CS9081 __param_native__out = stackalloc nint[__param_native__numElements]; -#pragma warning restore CS9081 System.Span __param_native__nativeSpan = __param_native__out; System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) @@ -623,15 +648,26 @@ internal static int ABI_MethodContentsOut(System.Runtime.InteropServices.ComWrap __param_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__param_native__managedSpan[__i0]); } } + + // AssignOut - Assign to parameters + __param_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements).GetPinnableReference()), __param_native__numElements)); } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = __param_native__out; + for (int __i0 = 0; __i0 < __param_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan[__i0]); + } + } + + __param_native__numElements = size; return __retVal; } - // AssignOut - Assign to parameters - __param_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements).GetPinnableReference()), __param_native__numElements)); return __retVal; } @@ -644,7 +680,7 @@ internal static int ABI_MethodContentsInOut(System.Runtime.InteropServices.ComWr // Setup - Perform required setup. int __param_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements); - System.Span __param_native__out; + scoped System.Span __param_native__out = default; try { // Unmarshal - Convert native data to managed data. @@ -665,27 +701,45 @@ internal static int ABI_MethodContentsInOut(System.Runtime.InteropServices.ComWr // Marshal - Convert managed data to native data. { __param_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param).Length; -#pragma warning disable CS9081 __param_native__out = stackalloc nint[__param_native__numElements]; -#pragma warning restore CS9081 System.Span __param_native__nativeSpan = __param_native__out; System.Span __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param); for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0) { nint __param_native__nativeSpan____i0__original = __param_native__nativeSpan[__i0]; __param_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__param_native__managedSpan[__i0]); - global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan____i0__original); } } + + // AssignOut - Assign to parameters + __param_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements).GetPinnableReference()), __param_native__numElements)); + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + for (int __i0 = 0; __i0 < __param_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan[__i0]); + } + } + + __param_native__numElements = size; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + { + System.ReadOnlySpan __param_native__nativeSpan = __param_native__out; + for (int __i0 = 0; __i0 < __param_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native__nativeSpan[__i0]); + } + } + + __param_native__numElements = size; return __retVal; } - // AssignOut - Assign to parameters - __param_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements).GetPinnableReference()), __param_native__numElements)); return __retVal; } } 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 index 9cdd50d..e41bf13 100644 --- 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 @@ -66,6 +66,8 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf __invokeRetVal = @this.Get(); // Marshal - Convert managed data to native data. __invokeRetValUnmanaged__out = (sbyte)(__invokeRetVal ? 1 : 0); + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; } catch (System.Exception __exception) { @@ -73,8 +75,6 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf 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.ICustomStringMarshallingUtf16.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.ICustomStringMarshallingUtf16.cs index 5468fb7..61bccd7 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 @@ -16,17 +16,26 @@ string global::SharedTypes.ComInterfaces.ICustomStringMarshallingUtf16.GetString() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.ICustomStringMarshallingUtf16)); - string __retVal; - ushort* __retVal_native; - int __invokeRetVal; + string __retVal = default; + ushort* __retVal_native = default; + int __invokeRetVal = default; + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, &__retVal_native); + { + __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 = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); return __retVal; } @@ -65,15 +74,17 @@ internal static int ABI_GetString(System.Runtime.InteropServices.ComWrappers.Com __invokeRetVal = @this.GetString(); // Marshal - Convert managed data to native data. __invokeRetValUnmanaged__out = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__invokeRetVal); + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__invokeRetValUnmanaged__out); 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.IDerived.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IDerived.cs index 31f6a4c..40a1478 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 @@ -33,17 +33,26 @@ string global::SharedTypes.ComInterfaces.IDerived.GetName() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IDerived)); - string __retVal; - ushort* __retVal_native; - int __invokeRetVal; + string __retVal = default; + ushort* __retVal_native = default; + int __invokeRetVal = default; + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__retVal_native); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); return __retVal; } @@ -123,15 +132,17 @@ internal static int ABI_GetName(System.Runtime.InteropServices.ComWrappers.ComIn __invokeRetVal = @this.GetName(); // Marshal - Convert managed data to native data. __invokeRetValUnmanaged__out = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__invokeRetVal); + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__invokeRetValUnmanaged__out); 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 eeb9813..10a9f34 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 @@ -53,6 +53,14 @@ finally { // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __rgelt_native__nativeSpan = __rgelt_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __rgelt_native__nativeSpan.Length; ++__i0) + { + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free((void*)__rgelt_native__nativeSpan[__i0]); + } + } + __rgelt_native__marshaller.Free(); } } @@ -93,16 +101,24 @@ { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IEnumUnknown)); System.Runtime.CompilerServices.Unsafe.SkipInit(out ppenum); - void* __ppenum_native; - int __invokeRetVal; + void* __ppenum_native = default; + int __invokeRetVal = default; + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__ppenum_native); - } + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__ppenum_native); + } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - ppenum = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__ppenum_native); + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + ppenum = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__ppenum_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__ppenum_native); + } } } @@ -119,21 +135,21 @@ internal static int ABI_Next(System.Runtime.InteropServices.ComWrappers.ComInter // Setup - Perform required setup. int __rgelt_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __rgelt_native__numElements); - System.Span __rgelt_native__out; + scoped System.Span __rgelt_native__out = default; try { // Unmarshal - Convert native data to managed data. __retVal = 0; // S_OK global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(rgelt).Clear(); + __rgelt_native__numElements = -1; + rgelt = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__rgelt_native, __rgelt_native__numElements); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Next(celt, rgelt, out pceltFetched); // Marshal - Convert managed data to native data. __pceltFetched_native__out = pceltFetched; { __rgelt_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(rgelt).Length; -#pragma warning disable CS9081 __rgelt_native__out = stackalloc System.IntPtr[__rgelt_native__numElements]; -#pragma warning restore CS9081 System.Span __rgelt_native__nativeSpan = __rgelt_native__out; System.Span __rgelt_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(rgelt); for (int __i0 = 0; __i0 < __rgelt_native__numElements; ++__i0) @@ -142,16 +158,27 @@ internal static int ABI_Next(System.Runtime.InteropServices.ComWrappers.ComInter __rgelt_native__nativeSpan[__i0] = (System.IntPtr)(void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(__rgelt_native__managedSpan[__i0]); } } + + // AssignOut - Assign to parameters + *__pceltFetched_native__param = __pceltFetched_native__out; + __rgelt_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__rgelt_native, __rgelt_native__numElements).GetPinnableReference()), __rgelt_native__numElements)); } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + { + System.ReadOnlySpan __rgelt_native__nativeSpan = __rgelt_native__out; + for (int __i0 = 0; __i0 < __rgelt_native__nativeSpan.Length; ++__i0) + { + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free((void*)__rgelt_native__nativeSpan[__i0]); + } + } + + __rgelt_native__numElements = -1; return __retVal; } - // AssignOut - Assign to parameters - *__pceltFetched_native__param = __pceltFetched_native__out; - __rgelt_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__rgelt_native, __rgelt_native__numElements).GetPinnableReference()), __rgelt_native__numElements)); return __retVal; } @@ -212,15 +239,17 @@ internal static int ABI_Clone(System.Runtime.InteropServices.ComWrappers.ComInte @this.Clone(out ppenum); // Marshal - Convert managed data to native data. __ppenum_native__out = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(ppenum); + // AssignOut - Assign to parameters + *__ppenum_native__param = __ppenum_native__out; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__ppenum_native__out); return __retVal; } - // AssignOut - Assign to parameters - *__ppenum_native__param = __ppenum_native__out; return __retVal; } } diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IFloat.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IFloat.cs index 12ba740..37f5d68 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IFloat.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IFloat.cs @@ -61,6 +61,8 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf __invokeRetVal = @this.Get(); // Marshal - Convert managed data to native data. __invokeRetValUnmanaged__out = __invokeRetVal; + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; } catch (System.Exception __exception) { @@ -68,8 +70,6 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf 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.IGetAndSetInt.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetAndSetInt.cs index 2e6729f..3675daa 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetAndSetInt.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetAndSetInt.cs @@ -61,6 +61,8 @@ internal static int ABI_GetInt(System.Runtime.InteropServices.ComWrappers.ComInt __invokeRetVal = @this.GetInt(); // Marshal - Convert managed data to native data. __invokeRetValUnmanaged__out = __invokeRetVal; + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; } catch (System.Exception __exception) { @@ -68,8 +70,6 @@ internal static int ABI_GetInt(System.Runtime.InteropServices.ComWrappers.ComInt 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.IGetIntArray.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetIntArray.cs index 24128be..e894238 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetIntArray.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetIntArray.cs @@ -16,22 +16,31 @@ int[] global::SharedTypes.ComInterfaces.IGetIntArray.GetInts() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IGetIntArray)); - int[] __retVal; - int* __retVal_native; - int __invokeRetVal; + int[] __retVal = default; + int* __retVal_native = default; + int __invokeRetVal = default; // Setup - Perform required setup. int __retVal_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + { + __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_native__numElements = 10; + __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal)); + } + finally { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, &__retVal_native); + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __retVal_native__numElements = 10; - __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal)); return __retVal; } } @@ -57,17 +66,17 @@ internal static int ABI_GetInts(System.Runtime.InteropServices.ComWrappers.ComIn // Marshal - Convert managed data to native data. __invokeRetValUnmanaged__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__invokeRetVal).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements)); + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); // CleanupFailure - Perform required cleanup. - ; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__invokeRetValUnmanaged__out); 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.IInt.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInt.cs index f723e50..c794008 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInt.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInt.cs @@ -113,6 +113,8 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf __invokeRetVal = @this.Get(); // Marshal - Convert managed data to native data. __invokeRetValUnmanaged__out = __invokeRetVal; + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; } catch (System.Exception __exception) { @@ -120,8 +122,6 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf return __retVal; } - // AssignOut - Assign to parameters - *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; return __retVal; } @@ -163,6 +163,8 @@ internal static int ABI_SwapRef(System.Runtime.InteropServices.ComWrappers.ComIn @this.SwapRef(ref value); // Marshal - Convert managed data to native data. __value_native__out = value; + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; } catch (System.Exception __exception) { @@ -170,8 +172,6 @@ internal static int ABI_SwapRef(System.Runtime.InteropServices.ComWrappers.ComIn return __retVal; } - // AssignOut - Assign to parameters - *__value_native__param = __value_native__out; return __retVal; } @@ -190,6 +190,8 @@ internal static int ABI_GetOut(System.Runtime.InteropServices.ComWrappers.ComInt @this.GetOut(out value); // Marshal - Convert managed data to native data. __value_native__out = value; + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; } catch (System.Exception __exception) { @@ -197,8 +199,6 @@ internal static int ABI_GetOut(System.Runtime.InteropServices.ComWrappers.ComInt return __retVal; } - // AssignOut - Assign to parameters - *__value_native__param = __value_native__out; return __retVal; } diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs index 79e5b82..7986287 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs @@ -17,24 +17,33 @@ { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IIntArray)); System.Runtime.CompilerServices.Unsafe.SkipInit(out size); - int[] __retVal; - int* __retVal_native; - int __invokeRetVal; + int[] __retVal = default; + int* __retVal_native = default; + int __invokeRetVal = default; // Setup - Perform required setup. int __retVal_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (int* __size_native = &size) + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __size_native, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal_native__numElements = size; + __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal)); + } + finally { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __size_native, &__retVal_native); + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __retVal_native__numElements = size; - __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal)); return __retVal; } @@ -44,22 +53,31 @@ { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IIntArray)); System.Runtime.CompilerServices.Unsafe.SkipInit(out array); - int* __array_native; - int __retVal; - int __invokeRetVal; + int* __array_native = default; + int __retVal = default; + int __invokeRetVal = default; // Setup - Perform required setup. int __array_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__array_native, &__retVal); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __array_native__numElements = __retVal; + array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array)); + } + finally { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__array_native, &__retVal); + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native); } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __array_native__numElements = __retVal; - array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array)); return __retVal; } @@ -97,6 +115,23 @@ System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IIntArray.Double(int[] array, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IIntArray)); + int __invokeRetVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __array_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(array)) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, (int*)__array_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] void global::SharedTypes.ComInterfaces.IIntArray.PassIn(in int[] array, int size) @@ -118,7 +153,7 @@ { // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __array_native = __array_native__marshaller.ToUnmanaged(); - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, &__array_native, size); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this, &__array_native, size); } System.GC.KeepAlive(this); @@ -148,7 +183,7 @@ __array_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(array, out __array_native__numElements); global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(array).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__array_native, __array_native__numElements)); { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this, &__array_native, size); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[9])(__this, &__array_native, size); } System.GC.KeepAlive(this); @@ -161,7 +196,6 @@ finally { // Cleanup - Perform required cleanup. - __array_native__numElements = size; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native); } } @@ -191,18 +225,18 @@ internal static int ABI_GetReturn(System.Runtime.InteropServices.ComWrappers.Com __size_native__out = size; __invokeRetValUnmanaged__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__invokeRetVal).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements)); + // AssignOut - Assign to parameters + *__size_native__param = __size_native__out; + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); // CleanupFailure - Perform required cleanup. - ; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__invokeRetValUnmanaged__out); return __retVal; } - // AssignOut - Assign to parameters - *__size_native__param = __size_native__out; - *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; return __retVal; } @@ -228,18 +262,18 @@ internal static int ABI_GetOut(System.Runtime.InteropServices.ComWrappers.ComInt __invokeRetValUnmanaged__out = __invokeRetVal; __array_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(array, out __array_native__numElements); global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(array).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__array_native__out, __array_native__numElements)); + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + *__array_native__param = __array_native__out; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); // CleanupFailure - Perform required cleanup. - ; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native__out); return __retVal; } - // AssignOut - Assign to parameters - *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; - *__array_native__param = __array_native__out; return __retVal; } @@ -280,12 +314,14 @@ internal static int ABI_FillAscending(System.Runtime.InteropServices.ComWrappers // Setup - Perform required setup. int __array_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); - System.Span __array_native__out; + scoped System.Span __array_native__out = default; try { // Unmarshal - Convert native data to managed data. __retVal = 0; // S_OK global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array).Clear(); + __array_native__numElements = size; + array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.FillAscending(array, size); // Marshal - Convert managed data to native data. @@ -296,15 +332,53 @@ internal static int ABI_FillAscending(System.Runtime.InteropServices.ComWrappers #pragma warning restore CS9081 global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array).CopyTo(__array_native__out); } + + // AssignOut - Assign to parameters + __array_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements).GetPinnableReference()), __array_native__numElements)); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + __array_native__numElements = size; + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Double(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int* __array_native, int size) + { + global::SharedTypes.ComInterfaces.IIntArray @this = default; + int[] array = default; + int __retVal = default; + // Setup - Perform required setup. + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + scoped System.Span __array_native__out = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + __array_native__numElements = size; + array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array)); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Double(array, size); + // AssignOut - Assign to parameters + __array_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements).GetPinnableReference()), __array_native__numElements)); + // Cleanup - Perform required cleanup. + __array_native__numElements = size; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + __array_native__numElements = size; return __retVal; } - // AssignOut - Assign to parameters - __array_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements).GetPinnableReference()), __array_native__numElements)); return __retVal; } @@ -360,21 +434,19 @@ internal static int ABI_SwapArray(System.Runtime.InteropServices.ComWrappers.Com // Marshal - Convert managed data to native data. __array_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(array, out __array_native__numElements); global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(array).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__array_native__out, __array_native__numElements)); + // AssignOut - Assign to parameters + *__array_native__param = __array_native__out; + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native); } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); // CleanupFailure - Perform required cleanup. - __array_native__numElements = size; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native__out); return __retVal; } - // AssignOut - Assign to parameters - *__array_native__param = __array_native__out; - // Cleanup - Perform required cleanup. - __array_native__numElements = size; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native); return __retVal; } } @@ -383,7 +455,7 @@ file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() { - void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IIntArray), sizeof(void*) * 9); + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IIntArray), sizeof(void*) * 10); { nint v0, v1, v2; System.Runtime.InteropServices.ComWrappers.GetIUnknownImpl(out v0, out v1, out v2); @@ -397,8 +469,9 @@ file unsafe partial interface InterfaceImplementation vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_GetOut; vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_SetContents; vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_FillAscending; - vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_PassIn; - vtable[8] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_SwapArray; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Double; + vtable[8] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_PassIn; + vtable[9] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_SwapArray; } return vtable; diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs index 48315bf..9ccea46 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs @@ -16,17 +16,26 @@ global::SharedTypes.ComInterfaces.IInt global::SharedTypes.ComInterfaces.IInterface.Get() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IInterface)); - global::SharedTypes.ComInterfaces.IInt __retVal; - void* __retVal_native; - int __invokeRetVal; + global::SharedTypes.ComInterfaces.IInt __retVal = default; + void* __retVal_native = default; + int __invokeRetVal = default; + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, &__retVal_native); + { + __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 = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__retVal_native); } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __retVal = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__retVal_native); return __retVal; } @@ -89,16 +98,24 @@ { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IInterface)); System.Runtime.CompilerServices.Unsafe.SkipInit(out value); - void* __value_native; - int __invokeRetVal; + void* __value_native = default; + int __invokeRetVal = default; + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__value_native); - } + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__value_native); + } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - value = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__value_native); + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + value = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__value_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__value_native); + } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] @@ -145,15 +162,17 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf __invokeRetVal = @this.Get(); // Marshal - Convert managed data to native data. __invokeRetValUnmanaged__out = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(__invokeRetVal); + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__invokeRetValUnmanaged__out); return __retVal; } - // AssignOut - Assign to parameters - *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; return __retVal; } @@ -197,6 +216,10 @@ internal static int ABI_SwapRef(System.Runtime.InteropServices.ComWrappers.ComIn @this.SwapRef(ref value); // Marshal - Convert managed data to native data. __value_native__out = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(value); + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__value_native); } catch (System.Exception __exception) { @@ -206,10 +229,6 @@ internal static int ABI_SwapRef(System.Runtime.InteropServices.ComWrappers.ComIn return __retVal; } - // AssignOut - Assign to parameters - *__value_native__param = __value_native__out; - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__value_native); return __retVal; } @@ -228,15 +247,17 @@ internal static int ABI_GetOut(System.Runtime.InteropServices.ComWrappers.ComInt @this.GetOut(out value); // Marshal - Convert managed data to native data. __value_native__out = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(value); + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__value_native__out); return __retVal; } - // AssignOut - Assign to parameters - *__value_native__param = __value_native__out; return __retVal; } diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IJaggedIntArray.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IJaggedIntArray.cs index 007a504..219fdbd 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IJaggedIntArray.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IJaggedIntArray.cs @@ -18,40 +18,59 @@ var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IJaggedIntArray)); System.Runtime.CompilerServices.Unsafe.SkipInit(out widths); System.Runtime.CompilerServices.Unsafe.SkipInit(out length); - int* __widths_native; - int[][] __retVal; - System.IntPtr* __retVal_native; - int __invokeRetVal; + int* __widths_native = default; + int[][] __retVal = default; + System.IntPtr* __retVal_native = default; + int __invokeRetVal = default; // Setup - Perform required setup. int __widths_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); int __retVal_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (int* __length_native = &length) + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, &__widths_native, __length_native, &__retVal_native); - } + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __length_native = &length) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, &__widths_native, __length_native, &__retVal_native); + } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __widths_native__numElements = length; - widths = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__widths_native, __widths_native__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__widths_native, __widths_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(widths)); - __retVal_native__numElements = length; - __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __widths_native__numElements = length; + widths = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__widths_native, __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__widths_native, __widths_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(widths)); + __retVal_native__numElements = length; + __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + System.Span __retVal_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal); + for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + { + int __retVal_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__nativeSpan____i0__numElements); + __retVal_native__nativeSpan____i0__numElements = widths[__i0]; + __retVal_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((int*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((int*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal_native__managedSpan[__i0])); + } + } + } + finally { - System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); - System.Span __retVal_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal); - for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__widths_native); { - int __retVal_native__nativeSpan____i0__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__nativeSpan____i0__numElements); - __retVal_native__nativeSpan____i0__numElements = widths[__i0]; - __retVal_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((int*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((int*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal_native__managedSpan[__i0])); + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__retVal_native, __retVal_native__numElements); + for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + { + int __retVal_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__nativeSpan____i0__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((int*)__retVal_native__nativeSpan[__i0]); + } } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); } return __retVal; @@ -64,38 +83,57 @@ var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IJaggedIntArray)); System.Runtime.CompilerServices.Unsafe.SkipInit(out array); System.Runtime.CompilerServices.Unsafe.SkipInit(out widths); - System.IntPtr* __array_native; - int* __widths_native; - int __retVal; - int __invokeRetVal; + System.IntPtr* __array_native = default; + int* __widths_native = default; + int __retVal = default; + int __invokeRetVal = default; // Setup - Perform required setup. int __widths_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); int __array_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__array_native, &__widths_native, &__retVal); - } + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__array_native, &__widths_native, &__retVal); + } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __widths_native__numElements = __retVal; - widths = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__widths_native, __widths_native__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__widths_native, __widths_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(widths)); - __array_native__numElements = __retVal; - array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __widths_native__numElements = __retVal; + widths = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__widths_native, __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__widths_native, __widths_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(widths)); + __array_native__numElements = __retVal; + array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); + { + System.ReadOnlySpan __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements); + System.Span __array_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array); + for (int __i0 = 0; __i0 < __array_native__numElements; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan____i0__numElements = widths[__i0]; + __array_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((int*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((int*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__array_native__managedSpan[__i0])); + } + } + } + finally { - System.ReadOnlySpan __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements); - System.Span __array_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array); - for (int __i0 = 0; __i0 < __array_native__numElements; ++__i0) + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__widths_native); { - int __array_native__nativeSpan____i0__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); - __array_native__nativeSpan____i0__numElements = widths[__i0]; - __array_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((int*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((int*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__array_native__managedSpan[__i0])); + System.ReadOnlySpan __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__array_native, __array_native__numElements); + for (int __i0 = 0; __i0 < __array_native__nativeSpan.Length; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((int*)__array_native__nativeSpan[__i0]); + } } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native); } return __retVal; @@ -151,7 +189,6 @@ { int __array_native__nativeSpan____i0__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); - ; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((int*)__array_native__nativeSpan[__i0]); } } @@ -202,29 +239,31 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__invokeRetValUnmanaged__managedSpan[__i0]).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((int*)__invokeRetValUnmanaged__nativeSpan[__i0], __invokeRetValUnmanaged__nativeSpan____i0__numElements)); } } + + // AssignOut - Assign to parameters + *__length_native__param = __length_native__out; + *__widths_native__param = __widths_native__out; + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); // CleanupFailure - Perform required cleanup. - ; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__widths_native__out); { System.ReadOnlySpan __invokeRetValUnmanaged__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements); for (int __i0 = 0; __i0 < __invokeRetValUnmanaged__nativeSpan.Length; ++__i0) { int __invokeRetValUnmanaged__nativeSpan____i0__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__nativeSpan____i0__numElements); - ; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((int*)__invokeRetValUnmanaged__nativeSpan[__i0]); } - }; + } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__invokeRetValUnmanaged__out); return __retVal; } - // AssignOut - Assign to parameters - *__length_native__param = __length_native__out; - *__widths_native__param = __widths_native__out; - *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; return __retVal; } @@ -267,29 +306,31 @@ internal static int ABI_Get2(System.Runtime.InteropServices.ComWrappers.ComInter global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__array_native__managedSpan[__i0]).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((int*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements)); } } + + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + *__widths_native__param = __widths_native__out; + *__array_native__param = __array_native__out; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); // CleanupFailure - Perform required cleanup. - ; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__widths_native__out); { System.ReadOnlySpan __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native__out, __array_native__numElements); for (int __i0 = 0; __i0 < __array_native__nativeSpan.Length; ++__i0) { int __array_native__nativeSpan____i0__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); - ; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((int*)__array_native__nativeSpan[__i0]); } - }; + } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native__out); return __retVal; } - // AssignOut - Assign to parameters - *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; - *__widths_native__param = __widths_native__out; - *__array_native__param = __array_native__out; return __retVal; } diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs index a95a0ae..1a78ec3 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs @@ -74,16 +74,24 @@ { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IRefStrings)); System.Runtime.CompilerServices.Unsafe.SkipInit(out value); - byte* __value_native; - int __invokeRetVal; + byte* __value_native = default; + int __invokeRetVal = default; + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__value_native); - } + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__value_native); + } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - value = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__value_native); + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + value = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__value_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__value_native); + } } } @@ -106,6 +114,10 @@ internal static int ABI_RefString(System.Runtime.InteropServices.ComWrappers.Com @this.RefString(ref value); // Marshal - Convert managed data to native data. __value_native__out = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(value); + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__value_native); } catch (System.Exception __exception) { @@ -115,10 +127,6 @@ internal static int ABI_RefString(System.Runtime.InteropServices.ComWrappers.Com return __retVal; } - // AssignOut - Assign to parameters - *__value_native__param = __value_native__out; - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__value_native); return __retVal; } @@ -161,15 +169,17 @@ internal static int ABI_OutString(System.Runtime.InteropServices.ComWrappers.Com @this.OutString(out value); // Marshal - Convert managed data to native data. __value_native__out = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(value); + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__value_native__out); return __retVal; } - // AssignOut - Assign to parameters - *__value_native__param = __value_native__out; return __retVal; } } diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.ISafeFileHandle.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.ISafeFileHandle.cs index 2aad297..6cf4ae5 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.ISafeFileHandle.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.ISafeFileHandle.cs @@ -75,20 +75,28 @@ { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.ISafeFileHandle)); System.Runtime.CompilerServices.Unsafe.SkipInit(out p); - nint __p_native; - int __invokeRetVal; + nint __p_native = default; + int __invokeRetVal = default; // Setup - Perform required setup. global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller.ManagedToUnmanagedOut __p_native__marshaller = new(); + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__p_native); - } + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__p_native); + } - System.GC.KeepAlive(this); - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __p_native__marshaller.FromUnmanaged(__p_native); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - p = __p_native__marshaller.ToManaged(); + System.GC.KeepAlive(this); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __p_native__marshaller.FromUnmanaged(__p_native); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + p = __p_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __p_native__marshaller.Free(); + } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling.cs new file mode 100644 index 0000000..7117542 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling.cs @@ -0,0 +1,425 @@ +// +#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[] { 93, 250, 49, 71, 3, 193, 34, 74, 135, 161, 88, 220, 237, 212, 169, 179 })); + + 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.IStatefulCallerAllocatedBufferMarshalling +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling.Method(global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferType param) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling)); + nint __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferTypeMarshaller __param_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param, stackalloc byte[global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferTypeMarshaller.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __param_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling.MethodIn(in global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferType param) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling)); + nint __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferTypeMarshaller __param_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param, stackalloc byte[global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferTypeMarshaller.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__param_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling.MethodOut(out global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferType param) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out param); + nint __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferTypeMarshaller __param_native__marshaller = new(); + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__param_native); + } + + System.GC.KeepAlive(this); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __param_native__marshaller.FromUnmanaged(__param_native); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + param = __param_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling.MethodRef(ref global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferType param) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling)); + nint __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferTypeMarshaller __param_native__marshaller = new(); + try + { + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__param_native); + } + + System.GC.KeepAlive(this); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __param_native__marshaller.FromUnmanaged(__param_native); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + param = __param_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferType global::SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling.Return() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling)); + global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferType __retVal = default; + nint __retVal_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferTypeMarshaller __retVal_native__marshaller = new(); + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, &__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); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal = __retVal_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_native__marshaller.Free(); + } + + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferType global::SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling.ReturnPreserveSig() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling)); + global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferType __retVal = default; + nint __retVal_native = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferTypeMarshaller __retVal_native__marshaller = new(); + try + { + { + __retVal_native = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this); + } + + 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); + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_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, nint __param_native) + { + global::SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling @this = default; + global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferType param = default; + int __retVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferTypeMarshaller __param_native__marshaller = new(); + try + { + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __param_native__marshaller.FromUnmanaged(__param_native); + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + param = __param_native__marshaller.ToManaged(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Method(param); + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param) + { + global::SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling @this = default; + nint __param_native = *__param_native__param; + global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferType param = default; + int __retVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferTypeMarshaller __param_native__marshaller = new(); + try + { + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __param_native__marshaller.FromUnmanaged(__param_native); + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + param = __param_native__marshaller.ToManaged(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodIn(in param); + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param) + { + global::SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling @this = default; + nint __param_native__out = default; + global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferType param = default; + int __retVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferTypeMarshaller __param_native__marshaller = new(); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodOut(out param); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native__out = __param_native__marshaller.ToUnmanaged(); + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + __param_native__marshaller.Free(); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param) + { + global::SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling @this = default; + nint __param_native__out = default; + nint __param_native = *__param_native__param; + global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferType param = default; + int __retVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferTypeMarshaller __param_native__marshaller = new(); + try + { + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __param_native__marshaller.FromUnmanaged(__param_native); + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + param = __param_native__marshaller.ToManaged(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodRef(ref param); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native__out = __param_native__marshaller.ToUnmanaged(); + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + __param_native__marshaller.Free(); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling @this = default; + nint __invokeRetValUnmanaged__out = default; + global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferType __invokeRetVal = default; + int __retVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferTypeMarshaller __invokeRetValUnmanaged__marshaller = new(); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Return(); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __invokeRetValUnmanaged__out = __invokeRetValUnmanaged__marshaller.ToUnmanaged(); + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + __invokeRetValUnmanaged__marshaller.Free(); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static nint ABI_ReturnPreserveSig(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native) + { + global::SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling @this = default; + global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferType __retVal = default; + nint __retVal_native = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferTypeMarshaller __retVal_native__marshaller = new(); + try + { + // Unmarshal - Convert native data to managed data. + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __retVal = @this.ReturnPreserveSig(); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __retVal_native = __retVal_native__marshaller.ToUnmanaged(); + // Cleanup - Perform required cleanup. + __retVal_native__marshaller.Free(); + } + catch (System.Exception __exception) + { + __retVal_native = System.Runtime.InteropServices.Marshalling.ExceptionAsDefaultMarshaller.ConvertToUnmanaged(__exception); + return __retVal_native; + } + + return __retVal_native; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling), sizeof(void*) * 9); + { + 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; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodIn; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodOut; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodRef; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Return; + vtable[8] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_ReturnPreserveSig; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IStatefulCallerAllocatedBufferMarshalling + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IStatefulCallerAllocatedBufferMarshalling + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.cs index b84d7a4..11b8616 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.cs @@ -124,26 +124,34 @@ var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement)); System.Runtime.CompilerServices.Unsafe.SkipInit(out pOut); System.Runtime.CompilerServices.Unsafe.SkipInit(out size); - byte* __pOut_native; - int __invokeRetVal; + byte* __pOut_native = default; + int __invokeRetVal = default; // Setup - Perform required setup. scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __pOut_native__marshaller = new(); int __pOut_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __pOut_native__numElements); - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (int* __size_native = &size) + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__pOut_native, __size_native); - } + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__pOut_native, __size_native); + } - System.GC.KeepAlive(this); - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __pOut_native__marshaller.FromUnmanaged(__pOut_native); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __pOut_native__numElements = size; - __pOut_native__marshaller.GetUnmanagedValuesSource(__pOut_native__numElements).CopyTo(__pOut_native__marshaller.GetManagedValuesDestination(__pOut_native__numElements)); - pOut = __pOut_native__marshaller.ToManaged(); + System.GC.KeepAlive(this); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __pOut_native__marshaller.FromUnmanaged(__pOut_native); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __pOut_native__numElements = size; + __pOut_native__marshaller.GetUnmanagedValuesSource(__pOut_native__numElements).CopyTo(__pOut_native__marshaller.GetManagedValuesDestination(__pOut_native__numElements)); + pOut = __pOut_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __pOut_native__marshaller.Free(); + } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] @@ -151,25 +159,34 @@ global::SharedTypes.ComInterfaces.StatefulCollection global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.Return(int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement)); - global::SharedTypes.ComInterfaces.StatefulCollection __retVal; - byte* __retVal_native; - int __invokeRetVal; + global::SharedTypes.ComInterfaces.StatefulCollection __retVal = default; + byte* __retVal_native = default; + int __invokeRetVal = default; // Setup - Perform required setup. scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __retVal_native__marshaller = new(); int __retVal_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, size, &__retVal_native); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, size, &__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); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal_native__numElements = size; + __retVal_native__marshaller.GetUnmanagedValuesSource(__retVal_native__numElements).CopyTo(__retVal_native__marshaller.GetManagedValuesDestination(__retVal_native__numElements)); + __retVal = __retVal_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_native__marshaller.Free(); } - 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); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __retVal_native__numElements = size; - __retVal_native__marshaller.GetUnmanagedValuesSource(__retVal_native__numElements).CopyTo(__retVal_native__marshaller.GetManagedValuesDestination(__retVal_native__numElements)); - __retVal = __retVal_native__marshaller.ToManaged(); return __retVal; } @@ -231,6 +248,8 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt p = __p_native__marshaller.ToManaged(); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Method(p, size); + // Cleanup - Perform required cleanup. + __p_native__marshaller.Free(); } catch (System.Exception __exception) { @@ -238,8 +257,6 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt return __retVal; } - // Cleanup - Perform required cleanup. - __p_native__marshaller.Free(); return __retVal; } @@ -268,6 +285,8 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI pIn = __pIn_native__marshaller.ToManaged(); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodIn(in pIn, in size); + // Cleanup - Perform required cleanup. + __pIn_native__marshaller.Free(); } catch (System.Exception __exception) { @@ -275,8 +294,6 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI return __retVal; } - // Cleanup - Perform required cleanup. - __pIn_native__marshaller.Free(); return __retVal; } @@ -308,6 +325,10 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com __pRef_native__marshaller.GetManagedValuesSource().CopyTo(__pRef_native__marshaller.GetUnmanagedValuesDestination()); // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __pRef_native__out = __pRef_native__marshaller.ToUnmanaged(); + // AssignOut - Assign to parameters + *__pRef_native__param = __pRef_native__out; + // Cleanup - Perform required cleanup. + __pRef_native__marshaller.Free(); } catch (System.Exception __exception) { @@ -317,10 +338,6 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com return __retVal; } - // AssignOut - Assign to parameters - *__pRef_native__param = __pRef_native__out; - // Cleanup - Perform required cleanup. - __pRef_native__marshaller.Free(); return __retVal; } @@ -349,6 +366,9 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com __pOut_native__marshaller.GetManagedValuesSource().CopyTo(__pOut_native__marshaller.GetUnmanagedValuesDestination()); // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __pOut_native__out = __pOut_native__marshaller.ToUnmanaged(); + // AssignOut - Assign to parameters + *__size_native__param = __size_native__out; + *__pOut_native__param = __pOut_native__out; } catch (System.Exception __exception) { @@ -358,9 +378,6 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com return __retVal; } - // AssignOut - Assign to parameters - *__size_native__param = __size_native__out; - *__pOut_native__param = __pOut_native__out; return __retVal; } @@ -386,6 +403,8 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt __invokeRetValUnmanaged__marshaller.GetManagedValuesSource().CopyTo(__invokeRetValUnmanaged__marshaller.GetUnmanagedValuesDestination()); // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __invokeRetValUnmanaged__out = __invokeRetValUnmanaged__marshaller.ToUnmanaged(); + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; } catch (System.Exception __exception) { @@ -395,8 +414,6 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt return __retVal; } - // AssignOut - Assign to parameters - *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; return __retVal; } @@ -420,6 +437,8 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt __retVal_native__marshaller.GetManagedValuesSource().CopyTo(__retVal_native__marshaller.GetUnmanagedValuesDestination()); // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __retVal_native = __retVal_native__marshaller.ToUnmanaged(); + // Cleanup - Perform required cleanup. + __retVal_native__marshaller.Free(); } catch (System.Exception __exception) { @@ -427,8 +446,6 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt return __retVal_native; } - // Cleanup - Perform required cleanup. - __retVal_native__marshaller.Free(); return __retVal_native; } } diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.cs index 350d241..11e8b3c 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.cs @@ -183,34 +183,50 @@ var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement)); System.Runtime.CompilerServices.Unsafe.SkipInit(out pOut); System.Runtime.CompilerServices.Unsafe.SkipInit(out size); - byte* __pOut_native; - int __invokeRetVal; + byte* __pOut_native = default; + int __invokeRetVal = default; // Setup - Perform required setup. scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __pOut_native__marshaller = new(); int __pOut_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __pOut_native__numElements); - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (int* __size_native = &size) + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__pOut_native, __size_native); - } + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__pOut_native, __size_native); + } - System.GC.KeepAlive(this); - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __pOut_native__marshaller.FromUnmanaged(__pOut_native); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __pOut_native__numElements = size; - { - 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) + System.GC.KeepAlive(this); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __pOut_native__marshaller.FromUnmanaged(__pOut_native); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __pOut_native__numElements = size; { - __pOut_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__pOut_native__nativeSpan[__i0]); + 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.StatelessTypeMarshaller.ConvertToManaged(__pOut_native__nativeSpan[__i0]); + } } + + pOut = __pOut_native__marshaller.ToManaged(); } + finally + { + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __pOut_native__nativeSpan = __pOut_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __pOut_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__pOut_native__nativeSpan[__i0]); + } + } - pOut = __pOut_native__marshaller.ToManaged(); + __pOut_native__marshaller.Free(); + } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] @@ -218,33 +234,50 @@ global::SharedTypes.ComInterfaces.StatefulCollection global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.Return(int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement)); - global::SharedTypes.ComInterfaces.StatefulCollection __retVal; - byte* __retVal_native; - int __invokeRetVal; + global::SharedTypes.ComInterfaces.StatefulCollection __retVal = default; + byte* __retVal_native = default; + int __invokeRetVal = default; // Setup - Perform required setup. scoped global::SharedTypes.ComInterfaces.StatefulCollectionMarshaller.Default __retVal_native__marshaller = new(); int __retVal_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, size, &__retVal_native); - } + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, size, &__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); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __retVal_native__numElements = size; + 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); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal_native__numElements = size; + { + 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.StatelessTypeMarshaller.ConvertToManaged(__retVal_native__nativeSpan[__i0]); + } + } + + __retVal = __retVal_native__marshaller.ToManaged(); + } + finally { - 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) + // Cleanup - Perform required cleanup. { - __retVal_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__retVal_native__nativeSpan[__i0]); + System.ReadOnlySpan __retVal_native__nativeSpan = __retVal_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__retVal_native__nativeSpan[__i0]); + } } + + __retVal_native__marshaller.Free(); } - __retVal = __retVal_native__marshaller.ToManaged(); return __retVal; } @@ -330,6 +363,8 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt p = __p_native__marshaller.ToManaged(); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Method(p, size); + // Cleanup - Perform required cleanup. + __p_native__marshaller.Free(); } catch (System.Exception __exception) { @@ -337,8 +372,6 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt return __retVal; } - // Cleanup - Perform required cleanup. - __p_native__marshaller.Free(); return __retVal; } @@ -375,6 +408,8 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI pIn = __pIn_native__marshaller.ToManaged(); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodIn(in pIn, in size); + // Cleanup - Perform required cleanup. + __pIn_native__marshaller.Free(); } catch (System.Exception __exception) { @@ -382,8 +417,6 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI return __retVal; } - // Cleanup - Perform required cleanup. - __pIn_native__marshaller.Free(); return __retVal; } @@ -432,6 +465,18 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __pRef_native__out = __pRef_native__marshaller.ToUnmanaged(); + // AssignOut - Assign to parameters + *__pRef_native__param = __pRef_native__out; + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __pRef_native__nativeSpan = __pRef_native__marshaller.GetUnmanagedValuesSource(__pRef_native__numElements); + for (int __i0 = 0; __i0 < __pRef_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__pRef_native__nativeSpan[__i0]); + } + } + + __pRef_native__marshaller.Free(); } catch (System.Exception __exception) { @@ -449,18 +494,6 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com return __retVal; } - // AssignOut - Assign to parameters - *__pRef_native__param = __pRef_native__out; - // Cleanup - Perform required cleanup. - { - System.ReadOnlySpan __pRef_native__nativeSpan = __pRef_native__marshaller.GetUnmanagedValuesSource(__pRef_native__numElements); - for (int __i0 = 0; __i0 < __pRef_native__lastIndexMarshalled; ++__i0) - { - global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__pRef_native__nativeSpan[__i0]); - } - } - - __pRef_native__marshaller.Free(); return __retVal; } @@ -498,6 +531,9 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __pOut_native__out = __pOut_native__marshaller.ToUnmanaged(); + // AssignOut - Assign to parameters + *__size_native__param = __size_native__out; + *__pOut_native__param = __pOut_native__out; } catch (System.Exception __exception) { @@ -515,9 +551,6 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com return __retVal; } - // AssignOut - Assign to parameters - *__size_native__param = __size_native__out; - *__pOut_native__param = __pOut_native__out; return __retVal; } @@ -552,6 +585,8 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __invokeRetValUnmanaged__out = __invokeRetValUnmanaged__marshaller.ToUnmanaged(); + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; } catch (System.Exception __exception) { @@ -569,8 +604,6 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt return __retVal; } - // AssignOut - Assign to parameters - *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; return __retVal; } @@ -603,6 +636,8 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __retVal_native = __retVal_native__marshaller.ToUnmanaged(); + // Cleanup - Perform required cleanup. + __retVal_native__marshaller.Free(); } catch (System.Exception __exception) { @@ -610,8 +645,6 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt return __retVal_native; } - // Cleanup - Perform required cleanup. - __retVal_native__marshaller.Free(); return __retVal_native; } } diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulFinallyMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulFinallyMarshalling.cs new file mode 100644 index 0000000..80633b3 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulFinallyMarshalling.cs @@ -0,0 +1,465 @@ +// +#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[] { 93, 250, 49, 71, 3, 193, 34, 74, 135, 161, 88, 220, 237, 212, 169, 179 })); + + 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.IStatefulFinallyMarshalling +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulFinallyMarshalling.Method(global::SharedTypes.ComInterfaces.StatefulFinallyType param) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulFinallyMarshalling)); + nint __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulFinallyTypeMarshaller __param_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __param_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulFinallyMarshalling.MethodIn(in global::SharedTypes.ComInterfaces.StatefulFinallyType param) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulFinallyMarshalling)); + nint __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulFinallyTypeMarshaller __param_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__param_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulFinallyMarshalling.MethodOut(out global::SharedTypes.ComInterfaces.StatefulFinallyType param) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulFinallyMarshalling)); + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out param); + nint __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulFinallyTypeMarshaller __param_native__marshaller = new(); + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__param_native); + } + + __invokeSucceeded = true; + System.GC.KeepAlive(this); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __param_native__marshaller.FromUnmanaged(__param_native); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + if (__invokeSucceeded) + { + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + param = __param_native__marshaller.ToManagedFinally(); + } + + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulFinallyMarshalling.MethodRef(ref global::SharedTypes.ComInterfaces.StatefulFinallyType param) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulFinallyMarshalling)); + bool __invokeSucceeded = default; + nint __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulFinallyTypeMarshaller __param_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__param_native); + } + + __invokeSucceeded = true; + System.GC.KeepAlive(this); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __param_native__marshaller.FromUnmanaged(__param_native); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + if (__invokeSucceeded) + { + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + param = __param_native__marshaller.ToManagedFinally(); + } + + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatefulFinallyType global::SharedTypes.ComInterfaces.IStatefulFinallyMarshalling.Return() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulFinallyMarshalling)); + bool __invokeSucceeded = default; + global::SharedTypes.ComInterfaces.StatefulFinallyType __retVal = default; + nint __retVal_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulFinallyTypeMarshaller __retVal_native__marshaller = new(); + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, &__retVal_native); + } + + __invokeSucceeded = true; + 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); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + if (__invokeSucceeded) + { + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + __retVal = __retVal_native__marshaller.ToManagedFinally(); + } + + // Cleanup - Perform required cleanup. + __retVal_native__marshaller.Free(); + } + + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatefulFinallyType global::SharedTypes.ComInterfaces.IStatefulFinallyMarshalling.ReturnPreserveSig() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulFinallyMarshalling)); + bool __invokeSucceeded = default; + global::SharedTypes.ComInterfaces.StatefulFinallyType __retVal = default; + nint __retVal_native = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulFinallyTypeMarshaller __retVal_native__marshaller = new(); + try + { + { + __retVal_native = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this); + } + + __invokeSucceeded = true; + 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); + } + finally + { + if (__invokeSucceeded) + { + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + __retVal = __retVal_native__marshaller.ToManagedFinally(); + } + + // Cleanup - Perform required cleanup. + __retVal_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, nint __param_native) + { + global::SharedTypes.ComInterfaces.IStatefulFinallyMarshalling @this = default; + global::SharedTypes.ComInterfaces.StatefulFinallyType param = default; + int __retVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulFinallyTypeMarshaller __param_native__marshaller = new(); + try + { + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __param_native__marshaller.FromUnmanaged(__param_native); + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + param = __param_native__marshaller.ToManagedFinally(); + @this.Method(param); + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param) + { + global::SharedTypes.ComInterfaces.IStatefulFinallyMarshalling @this = default; + nint __param_native = *__param_native__param; + global::SharedTypes.ComInterfaces.StatefulFinallyType param = default; + int __retVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulFinallyTypeMarshaller __param_native__marshaller = new(); + try + { + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __param_native__marshaller.FromUnmanaged(__param_native); + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + param = __param_native__marshaller.ToManagedFinally(); + @this.MethodIn(in param); + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param) + { + global::SharedTypes.ComInterfaces.IStatefulFinallyMarshalling @this = default; + nint __param_native__out = default; + global::SharedTypes.ComInterfaces.StatefulFinallyType param = default; + int __retVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulFinallyTypeMarshaller __param_native__marshaller = new(); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodOut(out param); + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native__out = __param_native__marshaller.ToUnmanaged(); + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + __param_native__marshaller.Free(); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param) + { + global::SharedTypes.ComInterfaces.IStatefulFinallyMarshalling @this = default; + nint __param_native__out = default; + nint __param_native = *__param_native__param; + global::SharedTypes.ComInterfaces.StatefulFinallyType param = default; + int __retVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulFinallyTypeMarshaller __param_native__marshaller = new(); + try + { + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __param_native__marshaller.FromUnmanaged(__param_native); + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + param = __param_native__marshaller.ToManagedFinally(); + @this.MethodRef(ref param); + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native__out = __param_native__marshaller.ToUnmanaged(); + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + __param_native__marshaller.Free(); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IStatefulFinallyMarshalling @this = default; + nint __invokeRetValUnmanaged__out = default; + global::SharedTypes.ComInterfaces.StatefulFinallyType __invokeRetVal = default; + int __retVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulFinallyTypeMarshaller __invokeRetValUnmanaged__marshaller = new(); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Return(); + // Marshal - Convert managed data to native data. + __invokeRetValUnmanaged__marshaller.FromManaged(__invokeRetVal); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __invokeRetValUnmanaged__out = __invokeRetValUnmanaged__marshaller.ToUnmanaged(); + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + __invokeRetValUnmanaged__marshaller.Free(); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static nint ABI_ReturnPreserveSig(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native) + { + global::SharedTypes.ComInterfaces.IStatefulFinallyMarshalling @this = default; + global::SharedTypes.ComInterfaces.StatefulFinallyType __retVal = default; + nint __retVal_native = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulFinallyTypeMarshaller __retVal_native__marshaller = new(); + try + { + // Unmarshal - Convert native data to managed data. + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __retVal = @this.ReturnPreserveSig(); + // Marshal - Convert managed data to native data. + __retVal_native__marshaller.FromManaged(__retVal); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __retVal_native = __retVal_native__marshaller.ToUnmanaged(); + // Cleanup - Perform required cleanup. + __retVal_native__marshaller.Free(); + } + catch (System.Exception __exception) + { + __retVal_native = System.Runtime.InteropServices.Marshalling.ExceptionAsDefaultMarshaller.ConvertToUnmanaged(__exception); + return __retVal_native; + } + + return __retVal_native; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IStatefulFinallyMarshalling), sizeof(void*) * 9); + { + 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; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodIn; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodOut; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodRef; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Return; + vtable[8] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_ReturnPreserveSig; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IStatefulFinallyMarshalling + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IStatefulFinallyMarshalling + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulMarshalling.cs index 60d9ef0..59d7d8a 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulMarshalling.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulMarshalling.cs @@ -81,20 +81,28 @@ { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulMarshalling)); System.Runtime.CompilerServices.Unsafe.SkipInit(out param); - nint __param_native; - int __invokeRetVal; + nint __param_native = default; + int __invokeRetVal = default; // Setup - Perform required setup. global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __param_native__marshaller = new(); + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__param_native); - } + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__param_native); + } - System.GC.KeepAlive(this); - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __param_native__marshaller.FromUnmanaged(__param_native); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - param = __param_native__marshaller.ToManaged(); + System.GC.KeepAlive(this); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __param_native__marshaller.FromUnmanaged(__param_native); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + param = __param_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] @@ -137,21 +145,30 @@ global::SharedTypes.ComInterfaces.StatefulType global::SharedTypes.ComInterfaces.IStatefulMarshalling.Return() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulMarshalling)); - global::SharedTypes.ComInterfaces.StatefulType __retVal; - nint __retVal_native; - int __invokeRetVal; + global::SharedTypes.ComInterfaces.StatefulType __retVal = default; + nint __retVal_native = default; + int __invokeRetVal = default; // Setup - Perform required setup. global::SharedTypes.ComInterfaces.StatefulTypeMarshaller __retVal_native__marshaller = new(); + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, &__retVal_native); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, &__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); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal = __retVal_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_native__marshaller.Free(); } - 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); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __retVal = __retVal_native__marshaller.ToManaged(); return __retVal; } @@ -205,6 +222,8 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt param = __param_native__marshaller.ToManaged(); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Method(param); + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); } catch (System.Exception __exception) { @@ -212,8 +231,6 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt return __retVal; } - // Cleanup - Perform required cleanup. - __param_native__marshaller.Free(); return __retVal; } @@ -235,6 +252,8 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI param = __param_native__marshaller.ToManaged(); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodIn(in param); + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); } catch (System.Exception __exception) { @@ -242,8 +261,6 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI return __retVal; } - // Cleanup - Perform required cleanup. - __param_native__marshaller.Free(); return __retVal; } @@ -268,6 +285,8 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com __param_native__marshaller.FromManaged(param); // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __param_native__out = __param_native__marshaller.ToUnmanaged(); + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; } catch (System.Exception __exception) { @@ -277,8 +296,6 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com return __retVal; } - // AssignOut - Assign to parameters - *__param_native__param = __param_native__out; return __retVal; } @@ -307,6 +324,10 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com __param_native__marshaller.FromManaged(param); // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __param_native__out = __param_native__marshaller.ToUnmanaged(); + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); } catch (System.Exception __exception) { @@ -316,10 +337,6 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com return __retVal; } - // AssignOut - Assign to parameters - *__param_native__param = __param_native__out; - // Cleanup - Perform required cleanup. - __param_native__marshaller.Free(); return __retVal; } @@ -344,6 +361,8 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt __invokeRetValUnmanaged__marshaller.FromManaged(__invokeRetVal); // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __invokeRetValUnmanaged__out = __invokeRetValUnmanaged__marshaller.ToUnmanaged(); + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; } catch (System.Exception __exception) { @@ -353,8 +372,6 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt return __retVal; } - // AssignOut - Assign to parameters - *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; return __retVal; } @@ -377,6 +394,8 @@ internal static nint ABI_ReturnPreserveSig(System.Runtime.InteropServices.ComWra __retVal_native__marshaller.FromManaged(__retVal); // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __retVal_native = __retVal_native__marshaller.ToUnmanaged(); + // Cleanup - Perform required cleanup. + __retVal_native__marshaller.Free(); } catch (System.Exception __exception) { @@ -384,8 +403,6 @@ internal static nint ABI_ReturnPreserveSig(System.Runtime.InteropServices.ComWra return __retVal_native; } - // Cleanup - Perform required cleanup. - __retVal_native__marshaller.Free(); return __retVal_native; } } diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulPinnedMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulPinnedMarshalling.cs new file mode 100644 index 0000000..04ea0db --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulPinnedMarshalling.cs @@ -0,0 +1,443 @@ +// +#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[] { 93, 250, 49, 71, 3, 193, 34, 74, 135, 161, 88, 220, 237, 212, 169, 179 })); + + 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.IStatefulPinnedMarshalling +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulPinnedMarshalling.Method(global::SharedTypes.ComInterfaces.StatefulPinnedType param) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulPinnedMarshalling)); + nint __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulPinnedTypeMarshaller __param_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param, stackalloc byte[global::SharedTypes.ComInterfaces.StatefulPinnedTypeMarshaller.BufferSize]); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __param_native__unused = __param_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __param_native); + } + + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __param_native__marshaller.OnInvoked(); + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulPinnedMarshalling.MethodIn(in global::SharedTypes.ComInterfaces.StatefulPinnedType param) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulPinnedMarshalling)); + nint __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulPinnedTypeMarshaller __param_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __param_native__marshaller.FromManaged(param, stackalloc byte[global::SharedTypes.ComInterfaces.StatefulPinnedTypeMarshaller.BufferSize]); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __param_native__unused = __param_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__param_native); + } + + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __param_native__marshaller.OnInvoked(); + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulPinnedMarshalling.MethodOut(out global::SharedTypes.ComInterfaces.StatefulPinnedType param) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulPinnedMarshalling)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out param); + nint __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulPinnedTypeMarshaller __param_native__marshaller = new(); + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__param_native); + } + + System.GC.KeepAlive(this); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __param_native__marshaller.FromUnmanaged(__param_native); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + param = __param_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatefulPinnedMarshalling.MethodRef(ref global::SharedTypes.ComInterfaces.StatefulPinnedType param) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulPinnedMarshalling)); + nint __param_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulPinnedTypeMarshaller __param_native__marshaller = new(); + try + { + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native = __param_native__marshaller.ToUnmanaged(); + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__param_native); + } + + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __param_native__marshaller.OnInvoked(); + System.GC.KeepAlive(this); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __param_native__marshaller.FromUnmanaged(__param_native); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + param = __param_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatefulPinnedType global::SharedTypes.ComInterfaces.IStatefulPinnedMarshalling.Return() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulPinnedMarshalling)); + global::SharedTypes.ComInterfaces.StatefulPinnedType __retVal = default; + nint __retVal_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulPinnedTypeMarshaller __retVal_native__marshaller = new(); + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, &__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); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal = __retVal_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_native__marshaller.Free(); + } + + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatefulPinnedType global::SharedTypes.ComInterfaces.IStatefulPinnedMarshalling.ReturnPreserveSig() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulPinnedMarshalling)); + global::SharedTypes.ComInterfaces.StatefulPinnedType __retVal = default; + nint __retVal_native = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulPinnedTypeMarshaller __retVal_native__marshaller = new(); + try + { + { + __retVal_native = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this); + } + + 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); + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __retVal_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, nint __param_native) + { + global::SharedTypes.ComInterfaces.IStatefulPinnedMarshalling @this = default; + global::SharedTypes.ComInterfaces.StatefulPinnedType param = default; + int __retVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulPinnedTypeMarshaller __param_native__marshaller = new(); + try + { + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __param_native__marshaller.FromUnmanaged(__param_native); + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + param = __param_native__marshaller.ToManaged(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Method(param); + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param) + { + global::SharedTypes.ComInterfaces.IStatefulPinnedMarshalling @this = default; + nint __param_native = *__param_native__param; + global::SharedTypes.ComInterfaces.StatefulPinnedType param = default; + int __retVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulPinnedTypeMarshaller __param_native__marshaller = new(); + try + { + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __param_native__marshaller.FromUnmanaged(__param_native); + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + param = __param_native__marshaller.ToManaged(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodIn(in param); + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param) + { + global::SharedTypes.ComInterfaces.IStatefulPinnedMarshalling @this = default; + nint __param_native__out = default; + global::SharedTypes.ComInterfaces.StatefulPinnedType param = default; + int __retVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulPinnedTypeMarshaller __param_native__marshaller = new(); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodOut(out param); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __param_native__marshaller.OnInvoked(); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native__out = __param_native__marshaller.ToUnmanaged(); + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + __param_native__marshaller.Free(); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param) + { + global::SharedTypes.ComInterfaces.IStatefulPinnedMarshalling @this = default; + nint __param_native__out = default; + nint __param_native = *__param_native__param; + global::SharedTypes.ComInterfaces.StatefulPinnedType param = default; + int __retVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulPinnedTypeMarshaller __param_native__marshaller = new(); + try + { + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __param_native__marshaller.FromUnmanaged(__param_native); + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + param = __param_native__marshaller.ToManaged(); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodRef(ref param); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __param_native__marshaller.OnInvoked(); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __param_native__out = __param_native__marshaller.ToUnmanaged(); + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + // Cleanup - Perform required cleanup. + __param_native__marshaller.Free(); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + __param_native__marshaller.Free(); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IStatefulPinnedMarshalling @this = default; + nint __invokeRetValUnmanaged__out = default; + global::SharedTypes.ComInterfaces.StatefulPinnedType __invokeRetVal = default; + int __retVal = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulPinnedTypeMarshaller __invokeRetValUnmanaged__marshaller = new(); + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Return(); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __invokeRetValUnmanaged__marshaller.OnInvoked(); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __invokeRetValUnmanaged__out = __invokeRetValUnmanaged__marshaller.ToUnmanaged(); + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + __invokeRetValUnmanaged__marshaller.Free(); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static nint ABI_ReturnPreserveSig(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native) + { + global::SharedTypes.ComInterfaces.IStatefulPinnedMarshalling @this = default; + global::SharedTypes.ComInterfaces.StatefulPinnedType __retVal = default; + nint __retVal_native = default; + // Setup - Perform required setup. + global::SharedTypes.ComInterfaces.StatefulPinnedTypeMarshaller __retVal_native__marshaller = new(); + try + { + // Unmarshal - Convert native data to managed data. + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __retVal = @this.ReturnPreserveSig(); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal_native__marshaller.OnInvoked(); + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __retVal_native = __retVal_native__marshaller.ToUnmanaged(); + // Cleanup - Perform required cleanup. + __retVal_native__marshaller.Free(); + } + catch (System.Exception __exception) + { + __retVal_native = System.Runtime.InteropServices.Marshalling.ExceptionAsDefaultMarshaller.ConvertToUnmanaged(__exception); + return __retVal_native; + } + + return __retVal_native; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IStatefulPinnedMarshalling), sizeof(void*) * 9); + { + 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; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodIn; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodOut; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodRef; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Return; + vtable[8] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_ReturnPreserveSig; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IStatefulPinnedMarshalling + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IStatefulPinnedMarshalling + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling.cs new file mode 100644 index 0000000..cfa2922 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling.cs @@ -0,0 +1,379 @@ +// +#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[] { 93, 250, 50, 71, 5, 193, 35, 74, 135, 167, 88, 220, 237, 212, 169, 179 })); + + 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.IStatelessCallerAllocateBufferMarshalling +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling.Method(global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferType param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling)); + nint __param_native = default; + int __invokeRetVal = default; + try + { + // Marshal - Convert managed data to native data. + System.Span __param_native__buffer = stackalloc byte[global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.BufferSize]; + __param_native = global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.ConvertToUnmanaged(param, __param_native__buffer); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.Free(__param_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling.MethodIn(in global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferType param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling)); + nint __param_native = default; + int __invokeRetVal = default; + try + { + // Marshal - Convert managed data to native data. + System.Span __param_native__buffer = stackalloc byte[global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.BufferSize]; + __param_native = global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.ConvertToUnmanaged(param, __param_native__buffer); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.Free(__param_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling.MethodOut(out global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferType param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out param); + nint __param_native = default; + int __invokeRetVal = default; + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + param = global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.ConvertToManaged(__param_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.Free(__param_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling.MethodRef(ref global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferType param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling)); + nint __param_native = default; + int __invokeRetVal = default; + try + { + // Marshal - Convert managed data to native data. + __param_native = global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.ConvertToUnmanaged(param); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + param = global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.ConvertToManaged(__param_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.Free(__param_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferType global::SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling.Return() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling)); + global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferType __retVal = default; + nint __retVal_native = default; + int __invokeRetVal = default; + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal = global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.Free(__retVal_native); + } + + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferType global::SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling.ReturnPreserveSig() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling)); + global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferType __retVal = default; + nint __retVal_native = default; + try + { + { + __retVal_native = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + __retVal = global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.Free(__retVal_native); + } + + 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, nint __param_native, int size) + { + global::SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling @this = default; + global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferType param = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + param = global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.ConvertToManaged(__param_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Method(param, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param, int size) + { + global::SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling @this = default; + nint __param_native = *__param_native__param; + global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferType param = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + param = global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.ConvertToManaged(__param_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodIn(in param, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param, int size) + { + global::SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling @this = default; + nint __param_native__out = default; + global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferType param = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodOut(out param, size); + // Marshal - Convert managed data to native data. + __param_native__out = global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.ConvertToUnmanaged(param); + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.Free(__param_native__out); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param, int size) + { + global::SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling @this = default; + nint __param_native__out = default; + nint __param_native = *__param_native__param; + global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferType param = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + param = global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.ConvertToManaged(__param_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodRef(ref param, size); + // Marshal - Convert managed data to native data. + __param_native__out = global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.ConvertToUnmanaged(param); + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.Free(__param_native); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.Free(__param_native__out); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling @this = default; + nint __invokeRetValUnmanaged__out = default; + global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferType __invokeRetVal = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Return(); + // Marshal - Convert managed data to native data. + __invokeRetValUnmanaged__out = global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.ConvertToUnmanaged(__invokeRetVal); + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.Free(__invokeRetValUnmanaged__out); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static nint ABI_ReturnPreserveSig(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native) + { + global::SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling @this = default; + global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferType __retVal = default; + nint __retVal_native = default; + try + { + // Unmarshal - Convert native data to managed data. + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __retVal = @this.ReturnPreserveSig(); + // Marshal - Convert managed data to native data. + __retVal_native = global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.ConvertToUnmanaged(__retVal); + } + catch (System.Exception __exception) + { + __retVal_native = System.Runtime.InteropServices.Marshalling.ExceptionAsDefaultMarshaller.ConvertToUnmanaged(__exception); + return __retVal_native; + } + + return __retVal_native; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling), sizeof(void*) * 9); + { + 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; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodIn; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodOut; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodRef; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Return; + vtable[8] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_ReturnPreserveSig; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IStatelessCallerAllocateBufferMarshalling + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IStatelessCallerAllocateBufferMarshalling + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.cs index 5aac879..0a4a445 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.cs @@ -37,7 +37,6 @@ finally { // Cleanup - Perform required cleanup. - ; global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__p_native); } } @@ -70,7 +69,6 @@ finally { // Cleanup - Perform required cleanup. - ; global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pIn_native); } } @@ -104,7 +102,6 @@ finally { // Cleanup - Perform required cleanup. - __pRef_native__numElements = size; global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pRef_native); } } @@ -116,23 +113,31 @@ var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement)); System.Runtime.CompilerServices.Unsafe.SkipInit(out pOut); System.Runtime.CompilerServices.Unsafe.SkipInit(out size); - nint __pOut_native; - int __invokeRetVal; + nint __pOut_native = default; + int __invokeRetVal = default; // Setup - Perform required setup. int __pOut_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __pOut_native__numElements); - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (int* __size_native = &size) + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__pOut_native, __size_native); - } + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__pOut_native, __size_native); + } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __pOut_native__numElements = size; - pOut = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__pOut_native, __pOut_native__numElements); - global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__pOut_native, __pOut_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(pOut)); + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __pOut_native__numElements = size; + pOut = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__pOut_native, __pOut_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__pOut_native, __pOut_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(pOut)); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pOut_native); + } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] @@ -140,22 +145,31 @@ global::SharedTypes.ComInterfaces.StatelessCollection global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.Return(int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement)); - global::SharedTypes.ComInterfaces.StatelessCollection __retVal; - nint __retVal_native; - int __invokeRetVal; + global::SharedTypes.ComInterfaces.StatelessCollection __retVal = default; + nint __retVal_native = default; + int __invokeRetVal = default; // Setup - Perform required setup. int __retVal_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, size, &__retVal_native); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, size, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal_native__numElements = size; + __retVal = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(__retVal)); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__retVal_native); } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __retVal_native__numElements = size; - __retVal = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); - global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(__retVal)); return __retVal; } @@ -184,7 +198,6 @@ finally { // Cleanup - Perform required cleanup. - __retVal_native__numElements = size; global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__retVal_native); } @@ -277,21 +290,19 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com // Marshal - Convert managed data to native data. __pRef_native__out = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(pRef, out __pRef_native__numElements); global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(pRef).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__pRef_native__out, __pRef_native__numElements)); + // AssignOut - Assign to parameters + *__pRef_native__param = __pRef_native__out; + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pRef_native); } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); // CleanupFailure - Perform required cleanup. - __pRef_native__numElements = size; global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pRef_native__out); return __retVal; } - // AssignOut - Assign to parameters - *__pRef_native__param = __pRef_native__out; - // Cleanup - Perform required cleanup. - __pRef_native__numElements = size; - global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pRef_native); return __retVal; } @@ -317,18 +328,18 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com __size_native__out = size; __pOut_native__out = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(pOut, out __pOut_native__numElements); global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(pOut).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__pOut_native__out, __pOut_native__numElements)); + // AssignOut - Assign to parameters + *__size_native__param = __size_native__out; + *__pOut_native__param = __pOut_native__out; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); // CleanupFailure - Perform required cleanup. - ; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pOut_native__out); return __retVal; } - // AssignOut - Assign to parameters - *__size_native__param = __size_native__out; - *__pOut_native__param = __pOut_native__out; return __retVal; } @@ -351,17 +362,17 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt // Marshal - Convert managed data to native data. __invokeRetValUnmanaged__out = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesSource(__invokeRetVal).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements)); + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); // CleanupFailure - Perform required cleanup. - ; + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__invokeRetValUnmanaged__out); 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.IStatelessCollectionStatelessElement.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.cs index 0cd1e3d..a61eae7 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.cs @@ -52,7 +52,8 @@ { global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__p_native__nativeSpan[__i0]); } - }; + } + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__p_native); } } @@ -100,7 +101,8 @@ { global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__pIn_native__nativeSpan[__i0]); } - }; + } + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pIn_native); } } @@ -158,7 +160,6 @@ } } - __pRef_native__numElements = size; global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pRef_native); } } @@ -170,29 +171,45 @@ var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement)); System.Runtime.CompilerServices.Unsafe.SkipInit(out pOut); System.Runtime.CompilerServices.Unsafe.SkipInit(out size); - nint __pOut_native; - int __invokeRetVal; + nint __pOut_native = default; + int __invokeRetVal = default; // Setup - Perform required setup. int __pOut_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __pOut_native__numElements); - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (int* __size_native = &size) + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__pOut_native, __size_native); - } + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__pOut_native, __size_native); + } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __pOut_native__numElements = size; - pOut = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__pOut_native, __pOut_native__numElements); + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __pOut_native__numElements = size; + pOut = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__pOut_native, __pOut_native__numElements); + { + System.ReadOnlySpan __pOut_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__pOut_native, __pOut_native__numElements); + System.Span __pOut_native__managedSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(pOut); + for (int __i0 = 0; __i0 < __pOut_native__numElements; ++__i0) + { + __pOut_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__pOut_native__nativeSpan[__i0]); + } + } + } + finally { - System.ReadOnlySpan __pOut_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__pOut_native, __pOut_native__numElements); - System.Span __pOut_native__managedSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(pOut); - for (int __i0 = 0; __i0 < __pOut_native__numElements; ++__i0) + // Cleanup - Perform required cleanup. { - __pOut_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__pOut_native__nativeSpan[__i0]); + System.ReadOnlySpan __pOut_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__pOut_native, __pOut_native__numElements); + for (int __i0 = 0; __i0 < __pOut_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__pOut_native__nativeSpan[__i0]); + } } + + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pOut_native); } } @@ -201,28 +218,44 @@ global::SharedTypes.ComInterfaces.StatelessCollection global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.Return(int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement)); - global::SharedTypes.ComInterfaces.StatelessCollection __retVal; - nint __retVal_native; - int __invokeRetVal; + global::SharedTypes.ComInterfaces.StatelessCollection __retVal = default; + nint __retVal_native = default; + int __invokeRetVal = default; // Setup - Perform required setup. int __retVal_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, size, &__retVal_native); - } + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, size, &__retVal_native); + } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __retVal_native__numElements = size; - __retVal = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal_native__numElements = size; + __retVal = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + System.Span __retVal_native__managedSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(__retVal); + for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + { + __retVal_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__retVal_native__nativeSpan[__i0]); + } + } + } + finally { - System.ReadOnlySpan __retVal_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); - System.Span __retVal_native__managedSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetManagedValuesDestination(__retVal); - for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + // Cleanup - Perform required cleanup. { - __retVal_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__retVal_native__nativeSpan[__i0]); + System.ReadOnlySpan __retVal_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesDestination(__retVal_native, __retVal_native__numElements); + for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__retVal_native__nativeSpan[__i0]); + } } + + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__retVal_native); } return __retVal; @@ -268,7 +301,6 @@ } } - __retVal_native__numElements = size; global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__retVal_native); } @@ -393,6 +425,19 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com __pRef_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__pRef_native__managedSpan[__i0]); } } + + // AssignOut - Assign to parameters + *__pRef_native__param = __pRef_native__out; + // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __pRef_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__pRef_native, __pRef_native__numElements); + for (int __i0 = 0; __i0 < __pRef_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__pRef_native__nativeSpan[__i0]); + } + } + + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pRef_native); } catch (System.Exception __exception) { @@ -406,24 +451,10 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com } } - __pRef_native__numElements = size; global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pRef_native__out); return __retVal; } - // AssignOut - Assign to parameters - *__pRef_native__param = __pRef_native__out; - // Cleanup - Perform required cleanup. - { - System.ReadOnlySpan __pRef_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.GetUnmanagedValuesSource(__pRef_native, __pRef_native__numElements); - for (int __i0 = 0; __i0 < __pRef_native__lastIndexMarshalled; ++__i0) - { - global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__pRef_native__nativeSpan[__i0]); - } - } - - __pRef_native__numElements = size; - global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pRef_native); return __retVal; } @@ -457,6 +488,10 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com __pOut_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__pOut_native__managedSpan[__i0]); } } + + // AssignOut - Assign to parameters + *__size_native__param = __size_native__out; + *__pOut_native__param = __pOut_native__out; } catch (System.Exception __exception) { @@ -468,13 +503,12 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com { global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__pOut_native__nativeSpan[__i0]); } - }; + } + + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__pOut_native__out); return __retVal; } - // AssignOut - Assign to parameters - *__size_native__param = __size_native__out; - *__pOut_native__param = __pOut_native__out; return __retVal; } @@ -505,6 +539,9 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt __invokeRetValUnmanaged__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__invokeRetValUnmanaged__managedSpan[__i0]); } } + + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; } catch (System.Exception __exception) { @@ -516,12 +553,12 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt { global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__invokeRetValUnmanaged__nativeSpan[__i0]); } - }; + } + + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Default.Free(__invokeRetValUnmanaged__out); 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.IStatelessFinallyMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessFinallyMarshalling.cs new file mode 100644 index 0000000..124aa6c --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessFinallyMarshalling.cs @@ -0,0 +1,407 @@ +// +#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[] { 93, 250, 50, 71, 5, 193, 38, 74, 135, 167, 88, 220, 237, 212, 169, 179 })); + + 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.IStatelessFinallyMarshalling +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessFinallyMarshalling.Method(global::SharedTypes.ComInterfaces.StatelessFinallyType param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessFinallyMarshalling)); + nint __param_native = default; + int __invokeRetVal = default; + try + { + // Marshal - Convert managed data to native data. + __param_native = global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.ConvertToUnmanaged(param); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.Free(__param_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessFinallyMarshalling.MethodIn(in global::SharedTypes.ComInterfaces.StatelessFinallyType param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessFinallyMarshalling)); + nint __param_native = default; + int __invokeRetVal = default; + try + { + // Marshal - Convert managed data to native data. + __param_native = global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.ConvertToUnmanaged(param); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.Free(__param_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessFinallyMarshalling.MethodOut(out global::SharedTypes.ComInterfaces.StatelessFinallyType param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessFinallyMarshalling)); + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out param); + nint __param_native = default; + int __invokeRetVal = default; + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__param_native, size); + } + + __invokeSucceeded = true; + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + if (__invokeSucceeded) + { + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + param = global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.ConvertToManagedFinally(__param_native); + } + + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.Free(__param_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessFinallyMarshalling.MethodRef(ref global::SharedTypes.ComInterfaces.StatelessFinallyType param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessFinallyMarshalling)); + bool __invokeSucceeded = default; + nint __param_native = default; + int __invokeRetVal = default; + try + { + // Marshal - Convert managed data to native data. + __param_native = global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.ConvertToUnmanaged(param); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__param_native, size); + } + + __invokeSucceeded = true; + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + if (__invokeSucceeded) + { + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + param = global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.ConvertToManagedFinally(__param_native); + } + + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.Free(__param_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatelessFinallyType global::SharedTypes.ComInterfaces.IStatelessFinallyMarshalling.Return() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessFinallyMarshalling)); + bool __invokeSucceeded = default; + global::SharedTypes.ComInterfaces.StatelessFinallyType __retVal = default; + nint __retVal_native = default; + int __invokeRetVal = default; + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, &__retVal_native); + } + + __invokeSucceeded = true; + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + if (__invokeSucceeded) + { + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + __retVal = global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.ConvertToManagedFinally(__retVal_native); + } + + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.Free(__retVal_native); + } + + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatelessFinallyType global::SharedTypes.ComInterfaces.IStatelessFinallyMarshalling.ReturnPreserveSig() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessFinallyMarshalling)); + bool __invokeSucceeded = default; + global::SharedTypes.ComInterfaces.StatelessFinallyType __retVal = default; + nint __retVal_native = default; + try + { + { + __retVal_native = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this); + } + + __invokeSucceeded = true; + System.GC.KeepAlive(this); + } + finally + { + if (__invokeSucceeded) + { + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + __retVal = global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.ConvertToManagedFinally(__retVal_native); + } + + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.Free(__retVal_native); + } + + 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, nint __param_native, int size) + { + global::SharedTypes.ComInterfaces.IStatelessFinallyMarshalling @this = default; + global::SharedTypes.ComInterfaces.StatelessFinallyType param = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + param = global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.ConvertToManagedFinally(__param_native); + @this.Method(param, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param, int size) + { + global::SharedTypes.ComInterfaces.IStatelessFinallyMarshalling @this = default; + nint __param_native = *__param_native__param; + global::SharedTypes.ComInterfaces.StatelessFinallyType param = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + param = global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.ConvertToManagedFinally(__param_native); + @this.MethodIn(in param, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param, int size) + { + global::SharedTypes.ComInterfaces.IStatelessFinallyMarshalling @this = default; + nint __param_native__out = default; + global::SharedTypes.ComInterfaces.StatelessFinallyType param = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodOut(out param, size); + // Marshal - Convert managed data to native data. + __param_native__out = global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.ConvertToUnmanaged(param); + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.Free(__param_native__out); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param, int size) + { + global::SharedTypes.ComInterfaces.IStatelessFinallyMarshalling @this = default; + nint __param_native__out = default; + nint __param_native = *__param_native__param; + global::SharedTypes.ComInterfaces.StatelessFinallyType param = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + param = global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.ConvertToManagedFinally(__param_native); + @this.MethodRef(ref param, size); + // Marshal - Convert managed data to native data. + __param_native__out = global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.ConvertToUnmanaged(param); + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.Free(__param_native); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.Free(__param_native__out); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IStatelessFinallyMarshalling @this = default; + nint __invokeRetValUnmanaged__out = default; + global::SharedTypes.ComInterfaces.StatelessFinallyType __invokeRetVal = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Return(); + // Marshal - Convert managed data to native data. + __invokeRetValUnmanaged__out = global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.ConvertToUnmanaged(__invokeRetVal); + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.Free(__invokeRetValUnmanaged__out); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static nint ABI_ReturnPreserveSig(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native) + { + global::SharedTypes.ComInterfaces.IStatelessFinallyMarshalling @this = default; + global::SharedTypes.ComInterfaces.StatelessFinallyType __retVal = default; + nint __retVal_native = default; + try + { + // Unmarshal - Convert native data to managed data. + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __retVal = @this.ReturnPreserveSig(); + // Marshal - Convert managed data to native data. + __retVal_native = global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.ConvertToUnmanaged(__retVal); + } + catch (System.Exception __exception) + { + __retVal_native = System.Runtime.InteropServices.Marshalling.ExceptionAsDefaultMarshaller.ConvertToUnmanaged(__exception); + return __retVal_native; + } + + return __retVal_native; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IStatelessFinallyMarshalling), sizeof(void*) * 9); + { + 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; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodIn; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodOut; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodRef; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Return; + vtable[8] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_ReturnPreserveSig; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IStatelessFinallyMarshalling + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IStatelessFinallyMarshalling + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessMarshalling.cs index a30655c..5a3045f 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessMarshalling.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessMarshalling.cs @@ -65,20 +65,28 @@ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - void global::SharedTypes.ComInterfaces.IStatelessMarshalling.MethodOut(out global::SharedTypes.ComInterfaces.StatelessType param, int size) + void global::SharedTypes.ComInterfaces.IStatelessMarshalling.MethodOut(out global::SharedTypes.ComInterfaces.StatelessType paramyBoi, int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessMarshalling)); - System.Runtime.CompilerServices.Unsafe.SkipInit(out param); - nint __param_native; - int __invokeRetVal; + System.Runtime.CompilerServices.Unsafe.SkipInit(out paramyBoi); + nint __paramyBoi_native = default; + int __invokeRetVal = default; + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__param_native, size); - } + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__paramyBoi_native, size); + } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - param = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__param_native); + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + paramyBoi = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__paramyBoi_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__paramyBoi_native); + } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] @@ -113,17 +121,26 @@ global::SharedTypes.ComInterfaces.StatelessType global::SharedTypes.ComInterfaces.IStatelessMarshalling.Return() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessMarshalling)); - global::SharedTypes.ComInterfaces.StatelessType __retVal; - nint __retVal_native; - int __invokeRetVal; + global::SharedTypes.ComInterfaces.StatelessType __retVal = default; + nint __retVal_native = default; + int __invokeRetVal = default; + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__retVal_native); + } + finally { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, &__retVal_native); + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__retVal_native); } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __retVal = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToManaged(__retVal_native); return __retVal; } @@ -204,29 +221,31 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI } [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] - internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param, int size) + internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __paramyBoi_native__param, int size) { global::SharedTypes.ComInterfaces.IStatelessMarshalling @this = default; - nint __param_native__out = default; - global::SharedTypes.ComInterfaces.StatelessType param = default; + nint __paramyBoi_native__out = default; + global::SharedTypes.ComInterfaces.StatelessType paramyBoi = default; int __retVal = default; try { // Unmarshal - Convert native data to managed data. __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); - @this.MethodOut(out param, size); + @this.MethodOut(out paramyBoi, size); // Marshal - Convert managed data to native data. - __param_native__out = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(param); + __paramyBoi_native__out = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(paramyBoi); + // AssignOut - Assign to parameters + *__paramyBoi_native__param = __paramyBoi_native__out; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__paramyBoi_native__out); return __retVal; } - // AssignOut - Assign to parameters - *__param_native__param = __param_native__out; return __retVal; } @@ -247,6 +266,10 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com @this.MethodRef(ref param, size); // Marshal - Convert managed data to native data. __param_native__out = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(param); + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native); } catch (System.Exception __exception) { @@ -256,10 +279,6 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com return __retVal; } - // AssignOut - Assign to parameters - *__param_native__param = __param_native__out; - // Cleanup - Perform required cleanup. - global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__param_native); return __retVal; } @@ -278,15 +297,17 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt __invokeRetVal = @this.Return(); // Marshal - Convert managed data to native data. __invokeRetValUnmanaged__out = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ConvertToUnmanaged(__invokeRetVal); + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Free(__invokeRetValUnmanaged__out); 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.IStatelessPinnedMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessPinnedMarshalling.cs new file mode 100644 index 0000000..a640544 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessPinnedMarshalling.cs @@ -0,0 +1,368 @@ +// +#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[] { 93, 250, 50, 71, 5, 193, 35, 74, 135, 167, 88, 220, 237, 212, 169, 179 })); + + 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.IStatelessPinnedMarshalling +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessPinnedMarshalling.Method(global::SharedTypes.ComInterfaces.StatelessPinnedType param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessPinnedMarshalling)); + int __invokeRetVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __param_native = &global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.GetPinnableReference(param)) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, (nint)__param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessPinnedMarshalling.MethodIn(in global::SharedTypes.ComInterfaces.StatelessPinnedType param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessPinnedMarshalling)); + nint __param_native = default; + int __invokeRetVal = default; + try + { + // Marshal - Convert managed data to native data. + __param_native = global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.ConvertToUnmanaged(param); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.Free(__param_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessPinnedMarshalling.MethodOut(out global::SharedTypes.ComInterfaces.StatelessPinnedType param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessPinnedMarshalling)); + System.Runtime.CompilerServices.Unsafe.SkipInit(out param); + nint __param_native = default; + int __invokeRetVal = default; + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, &__param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + param = global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.ConvertToManaged(__param_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.Free(__param_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessPinnedMarshalling.MethodRef(ref global::SharedTypes.ComInterfaces.StatelessPinnedType param, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessPinnedMarshalling)); + nint __param_native = default; + int __invokeRetVal = default; + try + { + // Marshal - Convert managed data to native data. + __param_native = global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.ConvertToUnmanaged(param); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__param_native, size); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + param = global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.ConvertToManaged(__param_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.Free(__param_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatelessPinnedType global::SharedTypes.ComInterfaces.IStatelessPinnedMarshalling.Return() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessPinnedMarshalling)); + global::SharedTypes.ComInterfaces.StatelessPinnedType __retVal = default; + nint __retVal_native = default; + int __invokeRetVal = default; + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal = global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.Free(__retVal_native); + } + + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatelessPinnedType global::SharedTypes.ComInterfaces.IStatelessPinnedMarshalling.ReturnPreserveSig() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessPinnedMarshalling)); + global::SharedTypes.ComInterfaces.StatelessPinnedType __retVal = default; + nint __retVal_native = default; + try + { + { + __retVal_native = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + __retVal = global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.Free(__retVal_native); + } + + 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, nint __param_native, int size) + { + global::SharedTypes.ComInterfaces.IStatelessPinnedMarshalling @this = default; + global::SharedTypes.ComInterfaces.StatelessPinnedType param = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + param = global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.ConvertToManaged(__param_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Method(param, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param, int size) + { + global::SharedTypes.ComInterfaces.IStatelessPinnedMarshalling @this = default; + nint __param_native = *__param_native__param; + global::SharedTypes.ComInterfaces.StatelessPinnedType param = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + param = global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.ConvertToManaged(__param_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodIn(in param, size); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param, int size) + { + global::SharedTypes.ComInterfaces.IStatelessPinnedMarshalling @this = default; + nint __param_native__out = default; + global::SharedTypes.ComInterfaces.StatelessPinnedType param = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodOut(out param, size); + // Marshal - Convert managed data to native data. + __param_native__out = global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.ConvertToUnmanaged(param); + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.Free(__param_native__out); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native__param, int size) + { + global::SharedTypes.ComInterfaces.IStatelessPinnedMarshalling @this = default; + nint __param_native__out = default; + nint __param_native = *__param_native__param; + global::SharedTypes.ComInterfaces.StatelessPinnedType param = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + param = global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.ConvertToManaged(__param_native); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodRef(ref param, size); + // Marshal - Convert managed data to native data. + __param_native__out = global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.ConvertToUnmanaged(param); + // AssignOut - Assign to parameters + *__param_native__param = __param_native__out; + // Cleanup - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.Free(__param_native); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.Free(__param_native__out); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IStatelessPinnedMarshalling @this = default; + nint __invokeRetValUnmanaged__out = default; + global::SharedTypes.ComInterfaces.StatelessPinnedType __invokeRetVal = default; + int __retVal = default; + try + { + // Unmarshal - Convert native data to managed data. + __retVal = 0; // S_OK + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Return(); + // Marshal - Convert managed data to native data. + __invokeRetValUnmanaged__out = global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.ConvertToUnmanaged(__invokeRetVal); + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.Free(__invokeRetValUnmanaged__out); + return __retVal; + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static nint ABI_ReturnPreserveSig(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native) + { + global::SharedTypes.ComInterfaces.IStatelessPinnedMarshalling @this = default; + global::SharedTypes.ComInterfaces.StatelessPinnedType __retVal = default; + nint __retVal_native = default; + try + { + // Unmarshal - Convert native data to managed data. + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __retVal = @this.ReturnPreserveSig(); + // Marshal - Convert managed data to native data. + __retVal_native = global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.ConvertToUnmanaged(__retVal); + } + catch (System.Exception __exception) + { + __retVal_native = System.Runtime.InteropServices.Marshalling.ExceptionAsDefaultMarshaller.ConvertToUnmanaged(__exception); + return __retVal_native; + } + + return __retVal_native; + } +} + +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IStatelessPinnedMarshalling), sizeof(void*) * 9); + { + 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; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodIn; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodOut; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_MethodRef; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_Return; + vtable[8] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_ReturnPreserveSig; + } + + return vtable; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IStatelessPinnedMarshalling + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IStatelessPinnedMarshalling + { + } +} \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverride.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverride.cs index fa244b8..606de1e 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverride.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverride.cs @@ -40,6 +40,7 @@ finally { // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); __input_native__marshaller.Free(); } @@ -51,19 +52,28 @@ string global::SharedTypes.ComInterfaces.IStringMarshallingOverride.MarshalAsLPWString(string input) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStringMarshallingOverride)); - string __retVal; - ushort* __retVal_native; - int __invokeRetVal; - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __input_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(input)) + string __retVal = default; + ushort* __retVal_native = default; + int __invokeRetVal = default; + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, (ushort*)__input_native, &__retVal_native); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __input_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(input)) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, (ushort*)__input_native, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); return __retVal; } @@ -72,19 +82,28 @@ string global::SharedTypes.ComInterfaces.IStringMarshallingOverride.MarshalUsingUtf16(string input) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStringMarshallingOverride)); - string __retVal; - ushort* __retVal_native; - int __invokeRetVal; - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __input_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(input)) + string __retVal = default; + ushort* __retVal_native = default; + int __invokeRetVal = default; + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, (ushort*)__input_native, &__retVal_native); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __input_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(input)) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, (ushort*)__input_native, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); return __retVal; } } @@ -108,15 +127,17 @@ internal static int ABI_StringMarshallingUtf8(System.Runtime.InteropServices.Com __invokeRetVal = @this.StringMarshallingUtf8(input); // Marshal - Convert managed data to native data. __invokeRetValUnmanaged__out = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(__invokeRetVal); + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__invokeRetValUnmanaged__out); return __retVal; } - // AssignOut - Assign to parameters - *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; return __retVal; } @@ -137,15 +158,17 @@ internal static int ABI_MarshalAsLPWString(System.Runtime.InteropServices.ComWra __invokeRetVal = @this.MarshalAsLPWString(input); // Marshal - Convert managed data to native data. __invokeRetValUnmanaged__out = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__invokeRetVal); + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__invokeRetValUnmanaged__out); return __retVal; } - // AssignOut - Assign to parameters - *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; return __retVal; } @@ -166,15 +189,17 @@ internal static int ABI_MarshalUsingUtf16(System.Runtime.InteropServices.ComWrap __invokeRetVal = @this.MarshalUsingUtf16(input); // Marshal - Convert managed data to native data. __invokeRetValUnmanaged__out = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__invokeRetVal); + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__invokeRetValUnmanaged__out); 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.IStringMarshallingOverrideDerived.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.cs index 20621f8..6de4963 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.cs @@ -40,6 +40,7 @@ finally { // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); __input_native__marshaller.Free(); } @@ -51,19 +52,28 @@ string global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.MarshalAsLPWString_2(string input) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived)); - string __retVal; - ushort* __retVal_native; - int __invokeRetVal; - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __input_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(input)) + string __retVal = default; + ushort* __retVal_native = default; + int __invokeRetVal = default; + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, (ushort*)__input_native, &__retVal_native); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __input_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(input)) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[7])(__this, (ushort*)__input_native, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); return __retVal; } @@ -72,19 +82,28 @@ string global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.MarshalUsingUtf16_2(string input) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived)); - string __retVal; - ushort* __retVal_native; - int __invokeRetVal; - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __input_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(input)) + string __retVal = default; + ushort* __retVal_native = default; + int __invokeRetVal = default; + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this, (ushort*)__input_native, &__retVal_native); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __input_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(input)) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this, (ushort*)__input_native, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); return __retVal; } @@ -117,6 +136,7 @@ finally { // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); __input_native__marshaller.Free(); } @@ -128,19 +148,28 @@ string global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.MarshalAsLPWString(string input) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived)); - string __retVal; - ushort* __retVal_native; - int __invokeRetVal; - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __input_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(input)) + string __retVal = default; + ushort* __retVal_native = default; + int __invokeRetVal = default; + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, (ushort*)__input_native, &__retVal_native); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __input_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(input)) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, (ushort*)__input_native, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); return __retVal; } @@ -149,19 +178,28 @@ string global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.MarshalUsingUtf16(string input) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived)); - string __retVal; - ushort* __retVal_native; - int __invokeRetVal; - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __input_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(input)) + string __retVal = default; + ushort* __retVal_native = default; + int __invokeRetVal = default; + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, (ushort*)__input_native, &__retVal_native); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __input_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(input)) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[5])(__this, (ushort*)__input_native, &__retVal_native); + } + + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); return __retVal; } @@ -189,15 +227,17 @@ internal static int ABI_StringMarshallingUtf8_2(System.Runtime.InteropServices.C __invokeRetVal = @this.StringMarshallingUtf8_2(input); // Marshal - Convert managed data to native data. __invokeRetValUnmanaged__out = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(__invokeRetVal); + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__invokeRetValUnmanaged__out); return __retVal; } - // AssignOut - Assign to parameters - *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; return __retVal; } @@ -218,15 +258,17 @@ internal static int ABI_MarshalAsLPWString_2(System.Runtime.InteropServices.ComW __invokeRetVal = @this.MarshalAsLPWString_2(input); // Marshal - Convert managed data to native data. __invokeRetValUnmanaged__out = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__invokeRetVal); + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__invokeRetValUnmanaged__out); return __retVal; } - // AssignOut - Assign to parameters - *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; return __retVal; } @@ -247,15 +289,17 @@ internal static int ABI_MarshalUsingUtf16_2(System.Runtime.InteropServices.ComWr __invokeRetVal = @this.MarshalUsingUtf16_2(input); // Marshal - Convert managed data to native data. __invokeRetValUnmanaged__out = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__invokeRetVal); + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__invokeRetValUnmanaged__out); 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.IUTF16Marshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF16Marshalling.cs index 986dc40..d82d3eb 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF16Marshalling.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF16Marshalling.cs @@ -16,17 +16,26 @@ string global::SharedTypes.ComInterfaces.IUTF16Marshalling.GetString() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IUTF16Marshalling)); - string __retVal; - ushort* __retVal_native; - int __invokeRetVal; + string __retVal = default; + ushort* __retVal_native = default; + int __invokeRetVal = default; + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, &__retVal_native); + { + __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 = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); return __retVal; } @@ -65,15 +74,17 @@ internal static int ABI_GetString(System.Runtime.InteropServices.ComWrappers.Com __invokeRetVal = @this.GetString(); // Marshal - Convert managed data to native data. __invokeRetValUnmanaged__out = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__invokeRetVal); + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__invokeRetValUnmanaged__out); 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.IUTF8Marshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF8Marshalling.cs index 5ff08b5..14023af 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF8Marshalling.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF8Marshalling.cs @@ -16,17 +16,26 @@ string global::SharedTypes.ComInterfaces.IUTF8Marshalling.GetString() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IUTF8Marshalling)); - string __retVal; - byte* __retVal_native; - int __invokeRetVal; + string __retVal = default; + byte* __retVal_native = default; + int __invokeRetVal = default; + try + { + { + __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 = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__retVal_native); + } + finally { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, &__retVal_native); + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __retVal = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__retVal_native); return __retVal; } @@ -78,15 +87,17 @@ internal static int ABI_GetString(System.Runtime.InteropServices.ComWrappers.Com __invokeRetVal = @this.GetString(); // Marshal - Convert managed data to native data. __invokeRetValUnmanaged__out = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(__invokeRetVal); + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__invokeRetValUnmanaged__out); 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.MarshallingFails.ICollectionMarshallingFails.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.cs index be3f6fb..2f8e763 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.cs @@ -17,30 +17,46 @@ { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails)); System.Runtime.CompilerServices.Unsafe.SkipInit(out size); - int[] __retVal; - nint* __retVal_native; - int __invokeRetVal; + int[] __retVal = default; + nint* __retVal_native = default; + int __invokeRetVal = default; // Setup - Perform required setup. int __retVal_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (int* __size_native = &size) + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __size_native, &__retVal_native); - } + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, __size_native, &__retVal_native); + } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __retVal_native__numElements = size; - __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal_native__numElements = size; + __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + System.Span __retVal_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal); + for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + { + __retVal_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.ConvertToManaged(__retVal_native__nativeSpan[__i0]); + } + } + } + finally { - System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); - System.Span __retVal_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal); - for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + // Cleanup - Perform required cleanup. { - __retVal_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.ConvertToManaged(__retVal_native__nativeSpan[__i0]); + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__retVal_native, __retVal_native__numElements); + for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__retVal_native__nativeSpan[__i0]); + } } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); } return __retVal; @@ -131,6 +147,10 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf __invokeRetValUnmanaged__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.ConvertToUnmanaged(__invokeRetValUnmanaged__managedSpan[__i0]); } } + + // AssignOut - Assign to parameters + *__size_native__param = __size_native__out; + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; } catch (System.Exception __exception) { @@ -142,13 +162,12 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf { global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__invokeRetValUnmanaged__nativeSpan[__i0]); } - }; + } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__invokeRetValUnmanaged__out); return __retVal; } - // AssignOut - Assign to parameters - *__size_native__param = __size_native__out; - *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; return __retVal; } diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.cs index e6577bc..e3a8da4 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.cs @@ -18,47 +18,75 @@ var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails)); System.Runtime.CompilerServices.Unsafe.SkipInit(out widths); System.Runtime.CompilerServices.Unsafe.SkipInit(out length); - int* __widths_native; - int[][] __retVal; - System.IntPtr* __retVal_native; - int __invokeRetVal; + int* __widths_native = default; + int[][] __retVal = default; + System.IntPtr* __retVal_native = default; + int __invokeRetVal = default; // Setup - Perform required setup. int __widths_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); int __retVal_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (int* __length_native = &length) + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, &__widths_native, __length_native, &__retVal_native); - } + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __length_native = &length) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this, &__widths_native, __length_native, &__retVal_native); + } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __widths_native__numElements = length; - widths = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__widths_native, __widths_native__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__widths_native, __widths_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(widths)); - __retVal_native__numElements = length; - __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __widths_native__numElements = length; + widths = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__widths_native, __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__widths_native, __widths_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(widths)); + __retVal_native__numElements = length; + __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + System.Span __retVal_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal); + for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + { + int __retVal_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__nativeSpan____i0__numElements); + __retVal_native__nativeSpan____i0__numElements = widths[__i0]; + __retVal_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((nint*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements); + { + System.ReadOnlySpan __retVal_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements); + System.Span __retVal_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal_native__managedSpan[__i0]); + for (int __i1 = 0; __i1 < __retVal_native__nativeSpan____i0__numElements; ++__i1) + { + __retVal_native__nativeSpan____i0__managedSpan[__i1] = global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.ConvertToManaged(__retVal_native__nativeSpan____i0__nativeSpan[__i1]); + } + } + } + } + } + finally { - System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); - System.Span __retVal_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal); - for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__widths_native); { - int __retVal_native__nativeSpan____i0__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__nativeSpan____i0__numElements); - __retVal_native__nativeSpan____i0__numElements = widths[__i0]; - __retVal_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((nint*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements); + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__retVal_native, __retVal_native__numElements); + for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) { - System.ReadOnlySpan __retVal_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements); - System.Span __retVal_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal_native__managedSpan[__i0]); - for (int __i1 = 0; __i1 < __retVal_native__nativeSpan____i0__numElements; ++__i1) + int __retVal_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__nativeSpan____i0__numElements); + __retVal_native__nativeSpan____i0__numElements = widths[__i0]; { - __retVal_native__nativeSpan____i0__managedSpan[__i1] = global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.ConvertToManaged(__retVal_native__nativeSpan____i0__nativeSpan[__i1]); + System.ReadOnlySpan __retVal_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements); + for (int __i1 = 0; __i1 < __retVal_native__nativeSpan____i0__nativeSpan.Length; ++__i1) + { + global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__retVal_native__nativeSpan____i0__nativeSpan[__i1]); + } } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__retVal_native__nativeSpan[__i0]); } } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); } return __retVal; @@ -71,45 +99,73 @@ var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails)); System.Runtime.CompilerServices.Unsafe.SkipInit(out array); System.Runtime.CompilerServices.Unsafe.SkipInit(out widths); - System.IntPtr* __array_native; - int* __widths_native; - int __retVal; - int __invokeRetVal; + System.IntPtr* __array_native = default; + int* __widths_native = default; + int __retVal = default; + int __invokeRetVal = default; // Setup - Perform required setup. int __widths_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __widths_native__numElements); int __array_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__array_native, &__widths_native, &__retVal); - } + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[4])(__this, &__array_native, &__widths_native, &__retVal); + } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __widths_native__numElements = __retVal; - widths = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__widths_native, __widths_native__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__widths_native, __widths_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(widths)); - __array_native__numElements = __retVal; - array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __widths_native__numElements = __retVal; + widths = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__widths_native, __widths_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__widths_native, __widths_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(widths)); + __array_native__numElements = __retVal; + array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); + { + System.ReadOnlySpan __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements); + System.Span __array_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array); + for (int __i0 = 0; __i0 < __array_native__numElements; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan____i0__numElements = widths[__i0]; + __array_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + { + System.ReadOnlySpan __array_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + System.Span __array_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__array_native__managedSpan[__i0]); + for (int __i1 = 0; __i1 < __array_native__nativeSpan____i0__numElements; ++__i1) + { + __array_native__nativeSpan____i0__managedSpan[__i1] = global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.ConvertToManaged(__array_native__nativeSpan____i0__nativeSpan[__i1]); + } + } + } + } + } + finally { - System.ReadOnlySpan __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements); - System.Span __array_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array); - for (int __i0 = 0; __i0 < __array_native__numElements; ++__i0) + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__widths_native); { - int __array_native__nativeSpan____i0__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); - __array_native__nativeSpan____i0__numElements = widths[__i0]; - __array_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + System.ReadOnlySpan __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__array_native, __array_native__numElements); + for (int __i0 = 0; __i0 < __array_native__nativeSpan.Length; ++__i0) { - System.ReadOnlySpan __array_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); - System.Span __array_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__array_native__managedSpan[__i0]); - for (int __i1 = 0; __i1 < __array_native__nativeSpan____i0__numElements; ++__i1) + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan____i0__numElements = widths[__i0]; { - __array_native__nativeSpan____i0__managedSpan[__i1] = global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.ConvertToManaged(__array_native__nativeSpan____i0__nativeSpan[__i1]); + System.ReadOnlySpan __array_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + for (int __i1 = 0; __i1 < __array_native__nativeSpan____i0__nativeSpan.Length; ++__i1) + { + global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__array_native__nativeSpan____i0__nativeSpan[__i1]); + } } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__array_native__nativeSpan[__i0]); } } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native); } return __retVal; @@ -180,7 +236,8 @@ { global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__array_native__nativeSpan____i0__nativeSpan[__i1]); } - }; + } + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__array_native__nativeSpan[__i0]); } } @@ -239,12 +296,17 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf } } } + + // AssignOut - Assign to parameters + *__length_native__param = __length_native__out; + *__widths_native__param = __widths_native__out; + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); // CleanupFailure - Perform required cleanup. - ; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__widths_native__out); { System.ReadOnlySpan __invokeRetValUnmanaged__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__invokeRetValUnmanaged__out, __invokeRetValUnmanaged__numElements); for (int __i0 = 0; __i0 < __invokeRetValUnmanaged__nativeSpan.Length; ++__i0) @@ -258,17 +320,16 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf { global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__invokeRetValUnmanaged__nativeSpan____i0__nativeSpan[__i1]); } - }; + } + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__invokeRetValUnmanaged__nativeSpan[__i0]); } - }; + } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__invokeRetValUnmanaged__out); return __retVal; } - // AssignOut - Assign to parameters - *__length_native__param = __length_native__out; - *__widths_native__param = __widths_native__out; - *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; return __retVal; } @@ -319,12 +380,17 @@ internal static int ABI_Get2(System.Runtime.InteropServices.ComWrappers.ComInter } } } + + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; + *__widths_native__param = __widths_native__out; + *__array_native__param = __array_native__out; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); // CleanupFailure - Perform required cleanup. - ; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__widths_native__out); { System.ReadOnlySpan __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native__out, __array_native__numElements); for (int __i0 = 0; __i0 < __array_native__nativeSpan.Length; ++__i0) @@ -338,17 +404,16 @@ internal static int ABI_Get2(System.Runtime.InteropServices.ComWrappers.ComInter { global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__array_native__nativeSpan____i0__nativeSpan[__i1]); } - }; + } + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__array_native__nativeSpan[__i0]); } - }; + } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native__out); return __retVal; } - // AssignOut - Assign to parameters - *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; - *__widths_native__param = __widths_native__out; - *__array_native__param = __array_native__out; return __retVal; } diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs index 9d956e9..c054851 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs @@ -147,7 +147,6 @@ { // Cleanup - Perform required cleanup. _ = __value_native__lastIndexMarshalled; - __value_native__numElements = 10; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__value_native); } } @@ -158,28 +157,36 @@ { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails)); System.Runtime.CompilerServices.Unsafe.SkipInit(out value); - nint* __value_native; - int __invokeRetVal; + nint* __value_native = default; + int __invokeRetVal = default; // Setup - Perform required setup. int __value_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __value_native__numElements); + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__value_native); - } + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[6])(__this, &__value_native); + } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __value_native__numElements = 10; - value = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__value_native, __value_native__numElements); - { - System.ReadOnlySpan __value_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__value_native, __value_native__numElements); - System.Span __value_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(value); - for (int __i0 = 0; __i0 < __value_native__numElements; ++__i0) + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __value_native__numElements = 10; + value = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__value_native, __value_native__numElements); { - __value_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToManaged(__value_native__nativeSpan[__i0]); + System.ReadOnlySpan __value_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__value_native, __value_native__numElements); + System.Span __value_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(value); + for (int __i0 = 0; __i0 < __value_native__numElements; ++__i0) + { + __value_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToManaged(__value_native__nativeSpan[__i0]); + } } } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__value_native); + } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] @@ -285,29 +292,37 @@ string[] global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.ReturnValue() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails)); - string[] __retVal; - nint* __retVal_native; - int __invokeRetVal; + string[] __retVal = default; + nint* __retVal_native = default; + int __invokeRetVal = default; // Setup - Perform required setup. int __retVal_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try { - __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[9])(__this, &__retVal_native); - } + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[9])(__this, &__retVal_native); + } - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - __retVal_native__numElements = 10; - __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); - { - System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); - System.Span __retVal_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal); - for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __retVal_native__numElements = 10; + __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); { - __retVal_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToManaged(__retVal_native__nativeSpan[__i0]); + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + System.Span __retVal_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal); + for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + { + __retVal_native__managedSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToManaged(__retVal_native__nativeSpan[__i0]); + } } } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + } return __retVal; } @@ -427,23 +442,22 @@ internal static int ABI_RefParam(System.Runtime.InteropServices.ComWrappers.ComI __value_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToUnmanaged(__value_native__managedSpan[__i0]); } } + + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; + // Cleanup - Perform required cleanup. + _ = __value_native__lastIndexMarshalled; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__value_native); } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); // CleanupFailure - Perform required cleanup. _ = __value_native__lastIndexMarshalled; - __value_native__numElements = 10; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__value_native__out); return __retVal; } - // AssignOut - Assign to parameters - *__value_native__param = __value_native__out; - // Cleanup - Perform required cleanup. - _ = __value_native__lastIndexMarshalled; - __value_native__numElements = 10; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__value_native); return __retVal; } @@ -474,17 +488,18 @@ internal static int ABI_OutParam(System.Runtime.InteropServices.ComWrappers.ComI __value_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToUnmanaged(__value_native__managedSpan[__i0]); } } + + // AssignOut - Assign to parameters + *__value_native__param = __value_native__out; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); // CleanupFailure - Perform required cleanup. - ; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__value_native__out); return __retVal; } - // AssignOut - Assign to parameters - *__value_native__param = __value_native__out; return __retVal; } @@ -497,20 +512,20 @@ internal static int ABI_ByValueOutParam(System.Runtime.InteropServices.ComWrappe // Setup - Perform required setup. int __value_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __value_native__numElements); - System.Span __value_native__out; + scoped System.Span __value_native__out = default; try { // Unmarshal - Convert native data to managed data. __retVal = 0; // S_OK global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(value).Clear(); + __value_native__numElements = 10; + value = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__value_native, __value_native__numElements); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.ByValueOutParam(value); // Marshal - Convert managed data to native data. { __value_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(value).Length; -#pragma warning disable CS9081 __value_native__out = stackalloc nint[__value_native__numElements]; -#pragma warning restore CS9081 System.Span __value_native__nativeSpan = __value_native__out; System.Span __value_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(value); for (int __i0 = 0; __i0 < __value_native__numElements; ++__i0) @@ -519,15 +534,18 @@ internal static int ABI_ByValueOutParam(System.Runtime.InteropServices.ComWrappe __value_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToUnmanaged(__value_native__managedSpan[__i0]); } } + + // AssignOut - Assign to parameters + __value_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__value_native, __value_native__numElements).GetPinnableReference()), __value_native__numElements)); } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + __value_native__numElements = 10; return __retVal; } - // AssignOut - Assign to parameters - __value_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__value_native, __value_native__numElements).GetPinnableReference()), __value_native__numElements)); return __retVal; } @@ -540,7 +558,7 @@ internal static int ABI_ByValueInOutParam(System.Runtime.InteropServices.ComWrap // Setup - Perform required setup. int __value_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __value_native__numElements); - System.Span __value_native__out; + scoped System.Span __value_native__out = default; try { // Unmarshal - Convert native data to managed data. @@ -561,9 +579,7 @@ internal static int ABI_ByValueInOutParam(System.Runtime.InteropServices.ComWrap // Marshal - Convert managed data to native data. { __value_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(value).Length; -#pragma warning disable CS9081 __value_native__out = stackalloc nint[__value_native__numElements]; -#pragma warning restore CS9081 System.Span __value_native__nativeSpan = __value_native__out; System.Span __value_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(value); for (int __i0 = 0; __i0 < __value_native__numElements; ++__i0) @@ -572,15 +588,20 @@ internal static int ABI_ByValueInOutParam(System.Runtime.InteropServices.ComWrap __value_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToUnmanaged(__value_native__managedSpan[__i0]); } } + + // AssignOut - Assign to parameters + __value_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__value_native, __value_native__numElements).GetPinnableReference()), __value_native__numElements)); + // Cleanup - Perform required cleanup. + __value_native__numElements = 10; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + // CleanupFailure - Perform required cleanup. + __value_native__numElements = 10; return __retVal; } - // AssignOut - Assign to parameters - __value_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__value_native, __value_native__numElements).GetPinnableReference()), __value_native__numElements)); return __retVal; } @@ -611,17 +632,18 @@ internal static int ABI_ReturnValue(System.Runtime.InteropServices.ComWrappers.C __invokeRetValUnmanaged__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToUnmanaged(__invokeRetValUnmanaged__managedSpan[__i0]); } } + + // AssignOut - Assign to parameters + *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; } catch (System.Exception __exception) { __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); // CleanupFailure - Perform required cleanup. - ; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__invokeRetValUnmanaged__out); return __retVal; } - // AssignOut - Assign to parameters - *__invokeRetValUnmanaged__param = __invokeRetValUnmanaged__out; return __retVal; } } diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/ManagedToNativeStubs.g.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/ManagedToNativeStubs.g.cs index 845a3ba..8e86040 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/ManagedToNativeStubs.g.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/ManagedToNativeStubs.g.cs @@ -151,7 +151,6 @@ internal unsafe partial interface Native finally { // Cleanup - Perform required cleanup. - __values_native__numElements = numValues; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values_native); } } @@ -411,6 +410,7 @@ internal unsafe partial interface Native finally { // Cleanup - Perform required cleanup. + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__oldValue_native); { System.ReadOnlySpan __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesDestination(); for (int __i0 = 0; __i0 < __values_native__lastIndexMarshalled; ++__i0) @@ -483,6 +483,7 @@ internal unsafe partial interface Native finally { // Cleanup - Perform required cleanup. + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__oldValue_native); { System.ReadOnlySpan __values_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements); for (int __i0 = 0; __i0 < __values_native__lastIndexMarshalled; ++__i0) @@ -491,7 +492,6 @@ internal unsafe partial interface Native } } - __values_native__numElements = numValues; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values_native); } } diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeToManagedStubs.g.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeToManagedStubs.g.cs index add8a5f..ba9a1ef 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeToManagedStubs.g.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeToManagedStubs.g.cs @@ -12,11 +12,19 @@ internal unsafe partial interface Native [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] internal static int ABI_GetData(void* __this_native) { - global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject @this; + global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject @this = default; int __retVal = default; - // Unmarshal - Convert native data to managed data. - @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); - __retVal = @this.GetData(); + try + { + // Unmarshal - Convert native data to managed data. + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + __retVal = @this.GetData(); + } + catch (System.Exception) + { + return __retVal; + } + return __retVal; } } @@ -37,10 +45,17 @@ internal unsafe partial interface Native [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] internal static void ABI_SetData(void* __this_native, int x) { - global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject @this; - // Unmarshal - Convert native data to managed data. - @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); - @this.SetData(x); + global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject @this = default; + try + { + // Unmarshal - Convert native data to managed data. + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.SetData(x); + } + catch (System.Exception) + { + return; + } } } } @@ -60,18 +75,25 @@ internal unsafe partial interface Native [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] internal static void ABI_ExchangeData(void* __this_native, int* __x_native__param) { - global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject @this; + global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject @this = default; int __x_native__out = default; int __x_native = *__x_native__param; - int x; - // Unmarshal - Convert native data to managed data. - x = __x_native; - @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); - @this.ExchangeData(ref x); - // Marshal - Convert managed data to native data. - __x_native__out = x; - // AssignOut - Assign to parameters - *__x_native__param = __x_native__out; + int x = default; + try + { + // Unmarshal - Convert native data to managed data. + x = __x_native; + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.ExchangeData(ref x); + // Marshal - Convert managed data to native data. + __x_native__out = x; + // AssignOut - Assign to parameters + *__x_native__param = __x_native__out; + } + catch (System.Exception) + { + return; + } } } } @@ -91,23 +113,30 @@ internal unsafe partial interface Native [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] internal static void ABI_SumAndSetData(void* __this_native, int* __values_native, int numValues, int* __oldValue_native__param) { - global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject @this; - int[] values; + global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject @this = default; + int[] values = default; int __oldValue_native__out = default; - int oldValue; + int oldValue = default; // Setup - Perform required setup. int __values_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); - // Unmarshal - Convert native data to managed data. - __values_native__numElements = numValues; - values = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values)); - @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); - @this.SumAndSetData(values, numValues, out oldValue); - // Marshal - Convert managed data to native data. - __oldValue_native__out = oldValue; - // AssignOut - Assign to parameters - *__oldValue_native__param = __oldValue_native__out; + try + { + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; + values = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values)); + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.SumAndSetData(values, numValues, out oldValue); + // Marshal - Convert managed data to native data. + __oldValue_native__out = oldValue; + // AssignOut - Assign to parameters + *__oldValue_native__param = __oldValue_native__out; + } + catch (System.Exception) + { + return; + } } } } @@ -136,22 +165,30 @@ internal static void ABI_SumAndSetData(void* __this_native, int** __values_nativ // Setup - Perform required setup. int __values_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); - // Unmarshal - Convert native data to managed data. - __values_native__numElements = numValues; - values = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values)); - @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); - @this.SumAndSetData(ref values, numValues, out oldValue); - // Marshal - Convert managed data to native data. - __oldValue_native__out = oldValue; - __values_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(values).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__values_native__out, __values_native__numElements)); - // AssignOut - Assign to parameters - *__oldValue_native__param = __oldValue_native__out; - *__values_native__param = __values_native__out; - // Cleanup - Perform required cleanup. - __values_native__numElements = numValues; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values_native); + try + { + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; + values = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values)); + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.SumAndSetData(ref values, numValues, out oldValue); + // Marshal - Convert managed data to native data. + __oldValue_native__out = oldValue; + __values_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(values).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__values_native__out, __values_native__numElements)); + // AssignOut - Assign to parameters + *__oldValue_native__param = __oldValue_native__out; + *__values_native__param = __values_native__out; + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values_native); + } + catch (System.Exception) + { + // CleanupFailure - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values_native__out); + return; + } } } } @@ -171,17 +208,24 @@ internal unsafe partial interface Native [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] internal static void ABI_MultiplyWithData(void* __this_native, int* __values_native, int numValues) { - global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject @this; - int[] values; + global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject @this = default; + int[] values = default; // Setup - Perform required setup. int __values_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); - // Unmarshal - Convert native data to managed data. - __values_native__numElements = numValues; - values = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values)); - @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); - @this.MultiplyWithData(values, numValues); + try + { + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; + values = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values)); + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.MultiplyWithData(values, numValues); + } + catch (System.Exception) + { + return; + } } } } @@ -201,14 +245,22 @@ internal unsafe partial interface Native [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] internal static int ABI_GetData(void* __this_native) { - global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject @this; - global::SharedTypes.IntWrapper __retVal; + global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject @this = default; + global::SharedTypes.IntWrapper __retVal = default; int __retVal_native = default; - // Unmarshal - Convert native data to managed data. - @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); - __retVal = @this.GetData(); - // Marshal - Convert managed data to native data. - __retVal_native = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(__retVal); + try + { + // Unmarshal - Convert native data to managed data. + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + __retVal = @this.GetData(); + // Marshal - Convert managed data to native data. + __retVal_native = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(__retVal); + } + catch (System.Exception) + { + return __retVal_native; + } + return __retVal_native; } } @@ -229,12 +281,19 @@ internal unsafe partial interface Native [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] internal static void ABI_SetData(void* __this_native, int __x_native) { - global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject @this; - global::SharedTypes.IntWrapper x; - // Unmarshal - Convert native data to managed data. - x = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__x_native); - @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); - @this.SetData(x); + global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject @this = default; + global::SharedTypes.IntWrapper x = default; + try + { + // Unmarshal - Convert native data to managed data. + x = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__x_native); + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.SetData(x); + } + catch (System.Exception) + { + return; + } } } } @@ -258,16 +317,25 @@ internal static void ABI_ExchangeData(void* __this_native, int* __data_native__p int __data_native__out = default; int __data_native = *__data_native__param; global::SharedTypes.IntWrapper data = default; - // Unmarshal - Convert native data to managed data. - data = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__data_native); - @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); - @this.ExchangeData(ref data); - // Marshal - Convert managed data to native data. - __data_native__out = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(data); - // AssignOut - Assign to parameters - *__data_native__param = __data_native__out; - // Cleanup - Perform required cleanup. - global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__data_native); + try + { + // Unmarshal - Convert native data to managed data. + data = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__data_native); + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.ExchangeData(ref data); + // Marshal - Convert managed data to native data. + __data_native__out = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(data); + // AssignOut - Assign to parameters + *__data_native__param = __data_native__out; + // Cleanup - Perform required cleanup. + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__data_native); + } + catch (System.Exception) + { + // CleanupFailure - Perform required cleanup. + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__data_native__out); + return; + } } } } @@ -287,31 +355,40 @@ internal unsafe partial interface Native [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] internal static void ABI_SumAndSetData(void* __this_native, int* __values_native, int numValues, int* __oldValue_native__param) { - global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject @this; - global::SharedTypes.IntWrapper[] values; + global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject @this = default; + global::SharedTypes.IntWrapper[] values = default; int __oldValue_native__out = default; - global::SharedTypes.IntWrapper oldValue; + global::SharedTypes.IntWrapper oldValue = default; // Setup - Perform required setup. int __values_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); - // Unmarshal - Convert native data to managed data. - __values_native__numElements = numValues; - values = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); + try { - System.ReadOnlySpan __values_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements); - System.Span __values_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values); - for (int __i0 = 0; __i0 < __values_native__numElements; ++__i0) + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; + values = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); { - __values_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values_native__nativeSpan[__i0]); + System.ReadOnlySpan __values_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements); + System.Span __values_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values); + for (int __i0 = 0; __i0 < __values_native__numElements; ++__i0) + { + __values_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values_native__nativeSpan[__i0]); + } } - } - @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); - @this.SumAndSetData(values, numValues, out oldValue); - // Marshal - Convert managed data to native data. - __oldValue_native__out = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(oldValue); - // AssignOut - Assign to parameters - *__oldValue_native__param = __oldValue_native__out; + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.SumAndSetData(values, numValues, out oldValue); + // Marshal - Convert managed data to native data. + __oldValue_native__out = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(oldValue); + // AssignOut - Assign to parameters + *__oldValue_native__param = __oldValue_native__out; + } + catch (System.Exception) + { + // CleanupFailure - Perform required cleanup. + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__oldValue_native__out); + return; + } } } } @@ -341,46 +418,63 @@ internal static void ABI_SumAndSetData(void* __this_native, int** __values_nativ int __values_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); int __values_native__lastIndexMarshalled = 0; - // Unmarshal - Convert native data to managed data. - __values_native__numElements = numValues; - values = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); + try { - System.ReadOnlySpan __values_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements); - System.Span __values_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values); - for (int __i0 = 0; __i0 < __values_native__numElements; ++__i0) + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; + values = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); { - __values_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values_native__nativeSpan[__i0]); + System.ReadOnlySpan __values_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements); + System.Span __values_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values); + for (int __i0 = 0; __i0 < __values_native__numElements; ++__i0) + { + __values_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values_native__nativeSpan[__i0]); + } } - } - @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); - @this.SumAndSetData(ref values, numValues, out oldValue); - // Marshal - Convert managed data to native data. - __oldValue_native__out = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(oldValue); - __values_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); - { - System.ReadOnlySpan __values_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(values); - System.Span __values_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__values_native__out, __values_native__numElements); - for (int __i0 = 0; __i0 < __values_native__managedSpan.Length; ++__i0, ++__values_native__lastIndexMarshalled) + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.SumAndSetData(ref values, numValues, out oldValue); + // Marshal - Convert managed data to native data. + __oldValue_native__out = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(oldValue); + __values_native__out = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); { - __values_native__nativeSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(__values_native__managedSpan[__i0]); + System.ReadOnlySpan __values_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(values); + System.Span __values_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__values_native__out, __values_native__numElements); + for (int __i0 = 0; __i0 < __values_native__managedSpan.Length; ++__i0, ++__values_native__lastIndexMarshalled) + { + __values_native__nativeSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(__values_native__managedSpan[__i0]); + } } - } - // AssignOut - Assign to parameters - *__oldValue_native__param = __oldValue_native__out; - *__values_native__param = __values_native__out; - // Cleanup - Perform required cleanup. - { - System.ReadOnlySpan __values_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements); - for (int __i0 = 0; __i0 < __values_native__lastIndexMarshalled; ++__i0) + // AssignOut - Assign to parameters + *__oldValue_native__param = __oldValue_native__out; + *__values_native__param = __values_native__out; + // Cleanup - Perform required cleanup. { - global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values_native__nativeSpan[__i0]); + System.ReadOnlySpan __values_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements); + for (int __i0 = 0; __i0 < __values_native__lastIndexMarshalled; ++__i0) + { + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values_native__nativeSpan[__i0]); + } } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values_native); } + catch (System.Exception) + { + // CleanupFailure - Perform required cleanup. + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__oldValue_native__out); + { + System.ReadOnlySpan __values_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native__out, __values_native__numElements); + for (int __i0 = 0; __i0 < __values_native__lastIndexMarshalled; ++__i0) + { + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values_native__nativeSpan[__i0]); + } + } - __values_native__numElements = numValues; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values_native); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values_native__out); + return; + } } } } @@ -400,44 +494,68 @@ internal unsafe partial interface Native [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] internal static void ABI_MultiplyWithData(void* __this_native, int* __values123_native, int numValues) { - global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject @this; - global::SharedTypes.IntWrapper[] values123; + global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject @this = default; + global::SharedTypes.IntWrapper[] values123 = default; // Setup - Perform required setup. int __values123_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __values123_native__numElements); - System.Span __values123_native__out; - // Unmarshal - Convert native data to managed data. - __values123_native__numElements = numValues; - values123 = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values123_native, __values123_native__numElements); + scoped System.Span __values123_native__out = default; + try { - System.ReadOnlySpan __values123_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values123_native, __values123_native__numElements); - System.Span __values123_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values123); - for (int __i0 = 0; __i0 < __values123_native__numElements; ++__i0) + // Unmarshal - Convert native data to managed data. + __values123_native__numElements = numValues; + values123 = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values123_native, __values123_native__numElements); { - __values123_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values123_native__nativeSpan[__i0]); + System.ReadOnlySpan __values123_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values123_native, __values123_native__numElements); + System.Span __values123_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values123); + for (int __i0 = 0; __i0 < __values123_native__numElements; ++__i0) + { + __values123_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values123_native__nativeSpan[__i0]); + } } - } - @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); - @this.MultiplyWithData(values123, numValues); - // Marshal - Convert managed data to native data. - { - __values123_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values123).Length; -#pragma warning disable CS9081 - __values123_native__out = stackalloc int[__values123_native__numElements]; -#pragma warning restore CS9081 - System.Span __values123_native__nativeSpan = __values123_native__out; - System.Span __values123_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values123); - for (int __i0 = 0; __i0 < __values123_native__numElements; ++__i0) + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.MultiplyWithData(values123, numValues); + // Marshal - Convert managed data to native data. + { + __values123_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values123).Length; + __values123_native__out = stackalloc int[__values123_native__numElements]; + System.Span __values123_native__nativeSpan = __values123_native__out; + System.Span __values123_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values123); + for (int __i0 = 0; __i0 < __values123_native__numElements; ++__i0) + { + int __values123_native__nativeSpan____i0__original = __values123_native__nativeSpan[__i0]; + __values123_native__nativeSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(__values123_native__managedSpan[__i0]); + } + } + + // AssignOut - Assign to parameters + __values123_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values123_native, __values123_native__numElements).GetPinnableReference()), __values123_native__numElements)); + // Cleanup - Perform required cleanup. { - int __values123_native__nativeSpan____i0__original = __values123_native__nativeSpan[__i0]; - __values123_native__nativeSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(__values123_native__managedSpan[__i0]); - global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values123_native__nativeSpan____i0__original); + System.ReadOnlySpan __values123_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values123_native, __values123_native__numElements); + for (int __i0 = 0; __i0 < __values123_native__nativeSpan.Length; ++__i0) + { + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values123_native__nativeSpan[__i0]); + } } + + __values123_native__numElements = numValues; } + catch (System.Exception) + { + // CleanupFailure - Perform required cleanup. + { + System.ReadOnlySpan __values123_native__nativeSpan = __values123_native__out; + for (int __i0 = 0; __i0 < __values123_native__nativeSpan.Length; ++__i0) + { + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values123_native__nativeSpan[__i0]); + } + } - // AssignOut - Assign to parameters - __values123_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values123_native, __values123_native__numElements).GetPinnableReference()), __values123_native__numElements)); + __values123_native__numElements = numValues; + return; + } } } } @@ -465,28 +583,37 @@ internal static void ABI_SumAndSetData(void* __this_native, int* __values_native global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.StatefulUnmanagedToManagedCollectionMarshaller.In __values_native__marshaller = new(); int __values_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __values_native__marshaller.FromUnmanaged(__values_native); - // Unmarshal - Convert native data to managed data. - __values_native__numElements = numValues; + try { - System.ReadOnlySpan __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesSource(__values_native__numElements); - System.Span __values_native__managedSpan = __values_native__marshaller.GetManagedValuesDestination(__values_native__numElements); - for (int __i0 = 0; __i0 < __values_native__numElements; ++__i0) + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __values_native__marshaller.FromUnmanaged(__values_native); + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; { - __values_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values_native__nativeSpan[__i0]); + System.ReadOnlySpan __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesSource(__values_native__numElements); + System.Span __values_native__managedSpan = __values_native__marshaller.GetManagedValuesDestination(__values_native__numElements); + for (int __i0 = 0; __i0 < __values_native__numElements; ++__i0) + { + __values_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values_native__nativeSpan[__i0]); + } } - } - values = __values_native__marshaller.ToManaged(); - @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObjectStateful)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); - @this.SumAndSetData(values, numValues, out oldValue); - // Marshal - Convert managed data to native data. - __oldValue_native__out = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(oldValue); - // AssignOut - Assign to parameters - *__oldValue_native__param = __oldValue_native__out; - // Cleanup - Perform required cleanup. - __values_native__marshaller.Free(); + values = __values_native__marshaller.ToManaged(); + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObjectStateful)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.SumAndSetData(values, numValues, out oldValue); + // Marshal - Convert managed data to native data. + __oldValue_native__out = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(oldValue); + // AssignOut - Assign to parameters + *__oldValue_native__param = __oldValue_native__out; + // Cleanup - Perform required cleanup. + __values_native__marshaller.Free(); + } + catch (System.Exception) + { + // CleanupFailure - Perform required cleanup. + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__oldValue_native__out); + return; + } } } } @@ -517,49 +644,67 @@ internal static void ABI_SumAndSetData(void* __this_native, int** __values_nativ int __values_native__numElements; int __values_native__lastIndexMarshalled = 0; System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __values_native__marshaller.FromUnmanaged(__values_native); - // Unmarshal - Convert native data to managed data. - __values_native__numElements = numValues; + try { - System.ReadOnlySpan __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesSource(__values_native__numElements); - System.Span __values_native__managedSpan = __values_native__marshaller.GetManagedValuesDestination(__values_native__numElements); - for (int __i0 = 0; __i0 < __values_native__numElements; ++__i0) + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __values_native__marshaller.FromUnmanaged(__values_native); + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; { - __values_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values_native__nativeSpan[__i0]); + System.ReadOnlySpan __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesSource(__values_native__numElements); + System.Span __values_native__managedSpan = __values_native__marshaller.GetManagedValuesDestination(__values_native__numElements); + for (int __i0 = 0; __i0 < __values_native__numElements; ++__i0) + { + __values_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values_native__nativeSpan[__i0]); + } } - } - values = __values_native__marshaller.ToManaged(); - @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObjectStateful)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); - @this.SumAndSetData(ref values, numValues, out oldValue); - // Marshal - Convert managed data to native data. - __oldValue_native__out = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(oldValue); - __values_native__marshaller.FromManaged(values); - { - System.ReadOnlySpan __values_native__managedSpan = __values_native__marshaller.GetManagedValuesSource(); - System.Span __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __values_native__managedSpan.Length; ++__i0, ++__values_native__lastIndexMarshalled) + values = __values_native__marshaller.ToManaged(); + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObjectStateful)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.SumAndSetData(ref values, numValues, out oldValue); + // Marshal - Convert managed data to native data. + __oldValue_native__out = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(oldValue); + __values_native__marshaller.FromManaged(values); { - __values_native__nativeSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(__values_native__managedSpan[__i0]); + System.ReadOnlySpan __values_native__managedSpan = __values_native__marshaller.GetManagedValuesSource(); + System.Span __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __values_native__managedSpan.Length; ++__i0, ++__values_native__lastIndexMarshalled) + { + __values_native__nativeSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(__values_native__managedSpan[__i0]); + } } - } - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __values_native__out = __values_native__marshaller.ToUnmanaged(); - // AssignOut - Assign to parameters - *__oldValue_native__param = __oldValue_native__out; - *__values_native__param = __values_native__out; - // Cleanup - Perform required cleanup. - { - System.ReadOnlySpan __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesSource(__values_native__numElements); - for (int __i0 = 0; __i0 < __values_native__lastIndexMarshalled; ++__i0) + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __values_native__out = __values_native__marshaller.ToUnmanaged(); + // AssignOut - Assign to parameters + *__oldValue_native__param = __oldValue_native__out; + *__values_native__param = __values_native__out; + // Cleanup - Perform required cleanup. { - global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values_native__nativeSpan[__i0]); + System.ReadOnlySpan __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesSource(__values_native__numElements); + for (int __i0 = 0; __i0 < __values_native__lastIndexMarshalled; ++__i0) + { + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values_native__nativeSpan[__i0]); + } } + + __values_native__marshaller.Free(); } + catch (System.Exception) + { + // CleanupFailure - Perform required cleanup. + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__oldValue_native__out); + { + System.ReadOnlySpan __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesSource(__values_native__numElements); + for (int __i0 = 0; __i0 < __values_native__lastIndexMarshalled; ++__i0) + { + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values_native__nativeSpan[__i0]); + } + } - __values_native__marshaller.Free(); + __values_native__marshaller.Free(); + return; + } } } } @@ -585,43 +730,65 @@ internal static void ABI_MultiplyWithData(void* __this_native, int* __values123_ global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.StatefulUnmanagedToManagedCollectionMarshaller.In __values123_native__marshaller = new(); int __values123_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __values123_native__numElements); - System.Span __values123_native__out; - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __values123_native__marshaller.FromUnmanaged(__values123_native); - // Unmarshal - Convert native data to managed data. - __values123_native__numElements = numValues; + scoped System.Span __values123_native__out = default; + try { - System.ReadOnlySpan __values123_native__nativeSpan = __values123_native__marshaller.GetUnmanagedValuesSource(__values123_native__numElements); - System.Span __values123_native__managedSpan = __values123_native__marshaller.GetManagedValuesDestination(__values123_native__numElements); - for (int __i0 = 0; __i0 < __values123_native__numElements; ++__i0) + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __values123_native__marshaller.FromUnmanaged(__values123_native); + // Unmarshal - Convert native data to managed data. + __values123_native__numElements = numValues; { - __values123_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values123_native__nativeSpan[__i0]); + System.ReadOnlySpan __values123_native__nativeSpan = __values123_native__marshaller.GetUnmanagedValuesSource(__values123_native__numElements); + System.Span __values123_native__managedSpan = __values123_native__marshaller.GetManagedValuesDestination(__values123_native__numElements); + for (int __i0 = 0; __i0 < __values123_native__numElements; ++__i0) + { + __values123_native__managedSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__values123_native__nativeSpan[__i0]); + } } - } - values123 = __values123_native__marshaller.ToManaged(); - @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObjectStateful)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); - @this.MultiplyWithData(values123, numValues); - // Marshal - Convert managed data to native data. - { - __values123_native__numElements = __values123_native__marshaller.GetManagedValuesDestination(__values123_native__numElements).Length; -#pragma warning disable CS9081 - __values123_native__out = stackalloc int[__values123_native__numElements]; -#pragma warning restore CS9081 - System.Span __values123_native__nativeSpan = __values123_native__out; - System.Span __values123_native__managedSpan = __values123_native__marshaller.GetManagedValuesDestination(__values123_native__numElements); - for (int __i0 = 0; __i0 < __values123_native__numElements; ++__i0) + values123 = __values123_native__marshaller.ToManaged(); + @this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObjectStateful)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper>(__this_native); + @this.MultiplyWithData(values123, numValues); + // Marshal - Convert managed data to native data. + { + __values123_native__numElements = __values123_native__marshaller.GetManagedValuesDestination(__values123_native__numElements).Length; + __values123_native__out = stackalloc int[__values123_native__numElements]; + System.Span __values123_native__nativeSpan = __values123_native__out; + System.Span __values123_native__managedSpan = __values123_native__marshaller.GetManagedValuesDestination(__values123_native__numElements); + for (int __i0 = 0; __i0 < __values123_native__numElements; ++__i0) + { + int __values123_native__nativeSpan____i0__original = __values123_native__nativeSpan[__i0]; + __values123_native__nativeSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(__values123_native__managedSpan[__i0]); + } + } + + // AssignOut - Assign to parameters + __values123_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __values123_native__marshaller.GetUnmanagedValuesSource(__values123_native__numElements).GetPinnableReference()), __values123_native__numElements)); + // Cleanup - Perform required cleanup. { - int __values123_native__nativeSpan____i0__original = __values123_native__nativeSpan[__i0]; - __values123_native__nativeSpan[__i0] = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToUnmanaged(__values123_native__managedSpan[__i0]); - global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values123_native__nativeSpan____i0__original); + System.ReadOnlySpan __values123_native__nativeSpan = __values123_native__marshaller.GetUnmanagedValuesSource(__values123_native__numElements); + for (int __i0 = 0; __i0 < __values123_native__nativeSpan.Length; ++__i0) + { + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values123_native__nativeSpan[__i0]); + } } + + __values123_native__marshaller.Free(); } + catch (System.Exception) + { + // CleanupFailure - Perform required cleanup. + { + System.ReadOnlySpan __values123_native__nativeSpan = __values123_native__out; + for (int __i0 = 0; __i0 < __values123_native__nativeSpan.Length; ++__i0) + { + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__values123_native__nativeSpan[__i0]); + } + } - // AssignOut - Assign to parameters - __values123_native__out.CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __values123_native__marshaller.GetUnmanagedValuesSource(__values123_native__numElements).GetPinnableReference()), __values123_native__numElements)); - // Cleanup - Perform required cleanup. - __values123_native__marshaller.Free(); + __values123_native__marshaller.Free(); + return; + } } } } diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs index fd35f4d..d4a8a61 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs @@ -421,7 +421,6 @@ public static partial int SumAndSetNativeObjectData(void* obj, ref int[] arr, in finally { // Cleanup - Perform required cleanup. - __arr_native__numElements = numValues; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__arr_native); } diff --git a/LibraryImportGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs b/LibraryImportGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs index f647cd2..f9e0690 100644 --- a/LibraryImportGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs +++ b/LibraryImportGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs @@ -123,7 +123,6 @@ public static partial void Duplicate(ref int[] values, int numValues) finally { // Cleanup - Perform required cleanup. - __values_native__numElements = numValues; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values_native); } @@ -166,7 +165,6 @@ public static partial int[] CreateRange(int start, int end, out int numValues) finally { // Cleanup - Perform required cleanup. - __retVal_native__numElements = numValues; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); } @@ -190,20 +188,29 @@ public static partial void CreateRange_Out(int start, int end, out int numValues { System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); System.Runtime.CompilerServices.Unsafe.SkipInit(out res); - int* __res_native; + int* __res_native = default; // Setup - Perform required setup. int __res_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __res_native__numElements); - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (int* __numValues_native = &numValues) + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __numValues_native = &numValues) + { + __PInvoke(start, end, __numValues_native, &__res_native); + } + + // Unmarshal - Convert native data to managed data. + __res_native__numElements = numValues; + res = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__res_native, __res_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__res_native, __res_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(res)); + } + finally { - __PInvoke(start, end, __numValues_native, &__res_native); + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__res_native); } - // Unmarshal - Convert native data to managed data. - __res_native__numElements = numValues; - res = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__res_native, __res_native__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__res_native, __res_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(res)); // Local P/Invoke [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array_out", ExactSpelling = true)] static extern unsafe void __PInvoke(int __start_native, int __end_native, int* __numValues_native, int** __res_native); @@ -290,7 +297,6 @@ public static partial void ReverseChars(ref char[] chars, int numElements) finally { // Cleanup - Perform required cleanup. - __chars_native__numElements = numElements; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__chars_native); } @@ -419,7 +425,6 @@ public static partial void ReverseStrings_Ref(ref string[] strArray, out int num } } - __strArray_native__numElements = numElements; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__strArray_native); } @@ -496,7 +501,6 @@ public static partial string[] ReverseStrings_Return(string[] strArray, out int } } - __retVal_native__numElements = numElements; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); { System.ReadOnlySpan __strArray_native__nativeSpan = __strArray_native__marshaller.GetUnmanagedValuesDestination(); @@ -575,6 +579,15 @@ public static partial void ReverseStrings_Out(string[] strArray, out int numElem finally { // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __res_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__res_native, __res_native__numElements); + for (int __i0 = 0; __i0 < __res_native__nativeSpan.Length; ++__i0) + { + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free((ushort*)__res_native__nativeSpan[__i0]); + } + } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__res_native); { System.ReadOnlySpan __strArray_native__nativeSpan = __strArray_native__marshaller.GetUnmanagedValuesDestination(); for (int __i0 = 0; __i0 < __strArray_native__lastIndexMarshalled; ++__i0) @@ -622,7 +635,6 @@ public static partial byte[] GetLongBytes(long l) finally { // Cleanup - Perform required cleanup. - __retVal_native__numElements = 8; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); } @@ -665,7 +677,6 @@ public static partial void Append(ref int[] values, int numOriginalValues, int n finally { // Cleanup - Perform required cleanup. - __values_native__numElements = checked(1 + numOriginalValues); global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values_native); } @@ -956,7 +967,6 @@ public static partial void NegateBools(ref global::SharedTypes.BoolStruct[] bool { // Cleanup - Perform required cleanup. _ = __boolStruct_native__lastIndexMarshalled; - __boolStruct_native__numElements = numValues; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__boolStruct_native); } @@ -1023,6 +1033,7 @@ public static partial void NegateBools(global::SharedTypes.BoolStruct[] boolStru finally { // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__pBoolStructOut_native); _ = __boolStruct_native__lastIndexMarshalled; __boolStruct_native__marshaller.Free(); } @@ -1090,7 +1101,6 @@ public unsafe partial class Arrays finally { // Cleanup - Perform required cleanup. - __retVal_native__numElements = numValues; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); _ = __boolStruct_native__lastIndexMarshalled; __boolStruct_native__marshaller.Free(); @@ -1174,12 +1184,10 @@ public static partial int[][] TransposeMatrix(int[][] matrix, int[] numRows, int { int __retVal_native__nativeSpan____i0__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__nativeSpan____i0__numElements); - __retVal_native__nativeSpan____i0__numElements = numRows[__i0]; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((int*)__retVal_native__nativeSpan[__i0]); } } - __retVal_native__numElements = numColumns; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); { System.ReadOnlySpan __matrix_native__nativeSpan = __matrix_native__marshaller.GetUnmanagedValuesDestination(); @@ -1187,7 +1195,6 @@ public static partial int[][] TransposeMatrix(int[][] matrix, int[] numRows, int { int __matrix_native__nativeSpan____i0__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __matrix_native__nativeSpan____i0__numElements); - ; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((int*)__matrix_native__nativeSpan[__i0]); } } @@ -1302,7 +1309,6 @@ public static unsafe partial void Duplicate(ref int*[] values, int numValues) finally { // Cleanup - Perform required cleanup. - __values_native__numElements = numValues; global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.Free(__values_native); } @@ -1344,7 +1350,6 @@ public unsafe partial class Arrays finally { // Cleanup - Perform required cleanup. - __retVal_native__numElements = numValues; global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.Free(__retVal_native); } @@ -2341,7 +2346,8 @@ public static partial void MarshalMultidimensionalArray_CheckInnerArraysAreClear { global::LibraryImportGenerator.IntegrationTests.EnforceClearedMemoryCleanup.Free(__c_native__nativeSpan____i0__nativeSpan[__i1]); } - }; + } + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__c_native__nativeSpan[__i0]); } } @@ -2411,7 +2417,6 @@ public static partial void MarshalArray_Ref(ref global::SharedTypes.BoolStruct[] } } - __c_native__numElements = 10; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__c_native); } @@ -2478,6 +2483,15 @@ public static partial void NegateBoolsOut(global::SharedTypes.BoolStruct[] boolS finally { // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __pBoolStructOut_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__pBoolStructOut_native, __pBoolStructOut_native__numElements); + for (int __i0 = 0; __i0 < __pBoolStructOut_native__nativeSpan.Length; ++__i0) + { + global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpBoolStruct.Free(__pBoolStructOut_native__nativeSpan[__i0]); + } + } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__pBoolStructOut_native); _ = __boolStruct_native__lastIndexMarshalled; __boolStruct_native__marshaller.Free(); } @@ -2568,13 +2582,32 @@ public static partial void NegateBoolsOut2D(global::SharedTypes.BoolStruct[][] b finally { // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __pBoolStructOut_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__pBoolStructOut_native, __pBoolStructOut_native__numElements); + for (int __i0 = 0; __i0 < __pBoolStructOut_native__nativeSpan.Length; ++__i0) + { + int __pBoolStructOut_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pBoolStructOut_native__nativeSpan____i0__numElements); + __pBoolStructOut_native__nativeSpan____i0__numElements = widths[__i0]; + { + System.ReadOnlySpan __pBoolStructOut_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__pBoolStructOut_native__nativeSpan[__i0], __pBoolStructOut_native__nativeSpan____i0__numElements); + for (int __i1 = 0; __i1 < __pBoolStructOut_native__nativeSpan____i0__nativeSpan.Length; ++__i1) + { + global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpBoolStruct.Free(__pBoolStructOut_native__nativeSpan____i0__nativeSpan[__i1]); + } + } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__pBoolStructOut_native__nativeSpan[__i0]); + } + } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__pBoolStructOut_native); { System.ReadOnlySpan __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesDestination(); for (int __i0 = 0; __i0 < __boolStruct_native__lastIndexMarshalled; ++__i0) { int __boolStruct_native__nativeSpan____i0__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__nativeSpan____i0__numElements); - ; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((global::SharedTypes.BoolStructMarshaller.BoolStructNative*)__boolStruct_native__nativeSpan[__i0]); } } @@ -2634,6 +2667,14 @@ public static partial bool FillRangeArray(global::SharedTypes.IntStructWrapper[] finally { // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __array_native__nativeSpan.Length; ++__i0) + { + global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpIntStruct.Free(__array_native__nativeSpan[__i0]); + } + } + __array_native__marshaller.Free(); } @@ -2702,6 +2743,25 @@ public static partial bool FillRangeArray2D(global::SharedTypes.IntStructWrapper finally { // Cleanup - Perform required cleanup. + { + System.ReadOnlySpan __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __array_native__nativeSpan.Length; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan____i0__numElements = widths[__i0]; + { + System.ReadOnlySpan __array_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + for (int __i1 = 0; __i1 < __array_native__nativeSpan____i0__nativeSpan.Length; ++__i1) + { + global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpIntStruct.Free(__array_native__nativeSpan____i0__nativeSpan[__i1]); + } + } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__array_native__nativeSpan[__i0]); + } + } + __array_native__marshaller.Free(); } @@ -2768,7 +2828,6 @@ public static partial void NegateBoolsRef(ref global::SharedTypes.BoolStruct[] b } } - __boolStruct_native__numElements = numValues; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__boolStruct_native); } @@ -2834,7 +2893,6 @@ public static partial void NegateBoolsRef2D_LastElementMarshalling(ref global::S } } - __boolStruct_native__numElements = length; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__boolStruct_native); } @@ -2931,12 +2989,10 @@ public static partial void NegateBoolsRef2D_ClearMarshalling(ref global::SharedT } } - __boolStruct_native__nativeSpan____i0__numElements = widths[__i0]; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__boolStruct_native__nativeSpan[__i0]); } } - __boolStruct_native__numElements = length; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__boolStruct_native); } @@ -2976,7 +3032,6 @@ public static partial int Sum(global::System.Collections.Generic.List value finally { // Cleanup - Perform required cleanup. - ; global::SharedTypes.ListMarshaller.Free(__values_native); } @@ -3001,25 +3056,17 @@ public unsafe partial class Stateless [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial int SumWithBuffer(global::System.Collections.Generic.List values, int numValues) { - byte* __values_native = default; - int __retVal = default; + byte* __values_native; + int __retVal; // Setup - Perform required setup. int __values_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); - try - { - // Marshal - Convert managed data to native data. - System.Span __values_native__buffer = stackalloc byte[global::SharedTypes.ListMarshallerWithBuffer.BufferSize]; - __values_native = global::SharedTypes.ListMarshallerWithBuffer.AllocateContainerForUnmanagedElements(values, __values_native__buffer, out __values_native__numElements); - global::SharedTypes.ListMarshallerWithBuffer.GetManagedValuesSource(values).CopyTo(global::SharedTypes.ListMarshallerWithBuffer.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); - { - __retVal = __PInvoke(__values_native, numValues); - } - } - finally + // Marshal - Convert managed data to native data. + System.Span __values_native__buffer = stackalloc byte[global::SharedTypes.ListMarshallerWithBuffer.BufferSize]; + __values_native = global::SharedTypes.ListMarshallerWithBuffer.AllocateContainerForUnmanagedElements(values, __values_native__buffer, out __values_native__numElements); + global::SharedTypes.ListMarshallerWithBuffer.GetManagedValuesSource(values).CopyTo(global::SharedTypes.ListMarshallerWithBuffer.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); { - // Cleanup - Perform required cleanup. - ; + __retVal = __PInvoke(__values_native, numValues); } return __retVal; @@ -3075,7 +3122,8 @@ public static unsafe partial int SumWithFreeTracking(global::System.Collections. { global::SharedTypes.IntWrapperMarshallerWithFreeCounts.Free((int*)__values_native__nativeSpan[__i0]); } - }; + } + global::SharedTypes.ListMarshaller.Free(__values_native); } @@ -3145,7 +3193,6 @@ public static partial int SumInArray(in global::System.Collections.Generic.List< finally { // Cleanup - Perform required cleanup. - ; global::SharedTypes.ListMarshaller.Free(__values_native); } @@ -3191,7 +3238,6 @@ public static partial void Duplicate(ref global::System.Collections.Generic.List finally { // Cleanup - Perform required cleanup. - __values_native__numElements = numValues; global::SharedTypes.ListMarshaller.Free(__values_native); } @@ -3237,7 +3283,6 @@ public unsafe partial class Stateless finally { // Cleanup - Perform required cleanup. - __retVal_native__numElements = numValues; global::SharedTypes.ListMarshaller.Free(__retVal_native); } @@ -3264,20 +3309,29 @@ public static partial void CreateRange_Out(int start, int end, out int numValues { System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); System.Runtime.CompilerServices.Unsafe.SkipInit(out res); - byte* __res_native; + byte* __res_native = default; // Setup - Perform required setup. int __res_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __res_native__numElements); - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (int* __numValues_native = &numValues) + try { - __PInvoke(start, end, __numValues_native, &__res_native); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __numValues_native = &numValues) + { + __PInvoke(start, end, __numValues_native, &__res_native); + } + + // Unmarshal - Convert native data to managed data. + __res_native__numElements = numValues; + res = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__res_native, __res_native__numElements); + global::SharedTypes.ListMarshaller.GetUnmanagedValuesSource(__res_native, __res_native__numElements).CopyTo(global::SharedTypes.ListMarshaller.GetManagedValuesDestination(res)); + } + finally + { + // Cleanup - Perform required cleanup. + global::SharedTypes.ListMarshaller.Free(__res_native); } - // Unmarshal - Convert native data to managed data. - __res_native__numElements = numValues; - res = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__res_native, __res_native__numElements); - global::SharedTypes.ListMarshaller.GetUnmanagedValuesSource(__res_native, __res_native__numElements).CopyTo(global::SharedTypes.ListMarshaller.GetManagedValuesDestination(res)); // Local P/Invoke [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array_out", ExactSpelling = true)] static extern unsafe void __PInvoke(int __start_native, int __end_native, int* __numValues_native, byte** __res_native); @@ -3317,7 +3371,6 @@ public unsafe partial class Stateless finally { // Cleanup - Perform required cleanup. - __retVal_native__numElements = 8; global::SharedTypes.ListMarshaller.Free(__retVal_native); } @@ -3373,7 +3426,6 @@ public static partial bool AndAllMembers(global::System.Collections.Generic.List { // Cleanup - Perform required cleanup. _ = __pArray_native__lastIndexMarshalled; - ; global::SharedTypes.ListMarshaller.Free(__pArray_native); } @@ -3429,7 +3481,6 @@ public static partial bool AndAllMembersIn(in global::System.Collections.Generic { // Cleanup - Perform required cleanup. _ = __pArray_native__lastIndexMarshalled; - ; global::SharedTypes.ListMarshaller.Free(__pArray_native); } @@ -3492,7 +3543,6 @@ public static partial void NegateBools(ref global::System.Collections.Generic.Li { // Cleanup - Perform required cleanup. _ = __boolStruct_native__lastIndexMarshalled; - __boolStruct_native__numElements = numValues; global::SharedTypes.ListMarshaller.Free(__boolStruct_native); } @@ -3557,8 +3607,8 @@ public static partial void NegateBools(global::System.Collections.Generic.List.Free(__pBoolStructOut_native); _ = __boolStruct_native__lastIndexMarshalled; - ; global::SharedTypes.ListMarshaller.Free(__boolStruct_native); } @@ -3623,10 +3673,8 @@ public unsafe partial class Stateless finally { // Cleanup - Perform required cleanup. - __retVal_native__numElements = numValues; global::SharedTypes.ListMarshaller.Free(__retVal_native); _ = __boolStruct_native__lastIndexMarshalled; - ; global::SharedTypes.ListMarshaller.Free(__boolStruct_native); } @@ -4004,23 +4052,32 @@ public static partial void CreateRange_Out(int start, int end, out int numValues { System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); System.Runtime.CompilerServices.Unsafe.SkipInit(out res); - byte* __res_native; + byte* __res_native = default; // Setup - Perform required setup. scoped global::SharedTypes.ListMarshallerStateful.Marshaller __res_native__marshaller = new(); int __res_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __res_native__numElements); - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (int* __numValues_native = &numValues) + try { - __PInvoke(start, end, __numValues_native, &__res_native); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __numValues_native = &numValues) + { + __PInvoke(start, end, __numValues_native, &__res_native); + } + + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __res_native__marshaller.FromUnmanaged(__res_native); + // Unmarshal - Convert native data to managed data. + __res_native__numElements = numValues; + __res_native__marshaller.GetUnmanagedValuesSource(__res_native__numElements).CopyTo(__res_native__marshaller.GetManagedValuesDestination(__res_native__numElements)); + res = __res_native__marshaller.ToManaged(); + } + finally + { + // Cleanup - Perform required cleanup. + __res_native__marshaller.Free(); } - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __res_native__marshaller.FromUnmanaged(__res_native); - // Unmarshal - Convert native data to managed data. - __res_native__numElements = numValues; - __res_native__marshaller.GetUnmanagedValuesSource(__res_native__numElements).CopyTo(__res_native__marshaller.GetManagedValuesDestination(__res_native__numElements)); - res = __res_native__marshaller.ToManaged(); // Local P/Invoke [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array_out", ExactSpelling = true)] static extern unsafe void __PInvoke(int __start_native, int __end_native, int* __numValues_native, byte** __res_native); @@ -4324,6 +4381,7 @@ public static partial void NegateBools(global::System.Collections.Generic.List.ManagedToUnmanagedOut __handle_native__marshaller = new(); + try + { + { + __PInvoke(&__handle_native); + } + + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __handle_native__marshaller.FromUnmanaged(__handle_native); + // Unmarshal - Convert native data to managed data. + handle = __handle_native__marshaller.ToManaged(); + } + finally { - __PInvoke(&__handle_native); + // Cleanup - Perform required cleanup. + __handle_native__marshaller.Free(); } - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __handle_native__marshaller.FromUnmanaged(__handle_native); - // Unmarshal - Convert native data to managed data. - handle = __handle_native__marshaller.ToManaged(); // Local P/Invoke [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "alloc_handle_out", ExactSpelling = true)] static extern unsafe void __PInvoke(nint* __handle_native); @@ -5933,7 +6007,6 @@ public static partial void Duplicate(ref global::System.Span values, int nu finally { // Cleanup - Perform required cleanup. - __values_native__numElements = numValues; global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.Free(__values_native); } @@ -5976,7 +6049,6 @@ public unsafe partial class Span finally { // Cleanup - Perform required cleanup. - __retVal_native__numElements = numValues; global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.Free(__retVal_native); } @@ -6000,20 +6072,29 @@ public static partial void CreateRange_Out(int start, int end, out int numValues { System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); res = default; - int* __res_native; + int* __res_native = default; // Setup - Perform required setup. int __res_native__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __res_native__numElements); - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (int* __numValues_native = &numValues) + try { - __PInvoke(start, end, __numValues_native, &__res_native); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __numValues_native = &numValues) + { + __PInvoke(start, end, __numValues_native, &__res_native); + } + + // Unmarshal - Convert native data to managed data. + __res_native__numElements = numValues; + res = global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.AllocateContainerForManagedElements(__res_native, __res_native__numElements); + global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetUnmanagedValuesSource(__res_native, __res_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetManagedValuesDestination(res)); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.Free(__res_native); } - // Unmarshal - Convert native data to managed data. - __res_native__numElements = numValues; - res = global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.AllocateContainerForManagedElements(__res_native, __res_native__numElements); - global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetUnmanagedValuesSource(__res_native, __res_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetManagedValuesDestination(res)); // Local P/Invoke [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array_out", ExactSpelling = true)] static extern unsafe void __PInvoke(int __start_native, int __end_native, int* __numValues_native, int** __res_native); @@ -6050,7 +6131,6 @@ public unsafe partial class Span finally { // Cleanup - Perform required cleanup. - __retVal_native__numElements = 8; global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.Free(__retVal_native); } @@ -6192,15 +6272,24 @@ public unsafe partial class Utf16 public static partial void Reverse_Out(string s, out string ret) { System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); - ushort* __ret_native; - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + ushort* __ret_native = default; + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __PInvoke((ushort*)__s_native, &__ret_native); + } + + // Unmarshal - Convert native data to managed data. + ret = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__ret_native); + } + finally { - __PInvoke((ushort*)__s_native, &__ret_native); + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__ret_native); } - // Unmarshal - Convert native data to managed data. - ret = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__ret_native); // Local P/Invoke [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_ushort", ExactSpelling = true)] static extern unsafe void __PInvoke(ushort* __s_native, ushort** __ret_native); @@ -6408,15 +6497,24 @@ public unsafe partial class LPTStr public static partial void Reverse_Out(string s, out string ret) { System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); - ushort* __ret_native; - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + ushort* __ret_native = default; + try { - __PInvoke((ushort*)__s_native, &__ret_native); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __PInvoke((ushort*)__s_native, &__ret_native); + } + + // Unmarshal - Convert native data to managed data. + ret = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__ret_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__ret_native); } - // Unmarshal - Convert native data to managed data. - ret = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__ret_native); // Local P/Invoke [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_ushort", ExactSpelling = true)] static extern unsafe void __PInvoke(ushort* __s_native, ushort** __ret_native); @@ -6624,15 +6722,24 @@ public unsafe partial class LPWStr public static partial void Reverse_Out(string s, out string ret) { System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); - ushort* __ret_native; - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + ushort* __ret_native = default; + try { - __PInvoke((ushort*)__s_native, &__ret_native); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __PInvoke((ushort*)__s_native, &__ret_native); + } + + // Unmarshal - Convert native data to managed data. + ret = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__ret_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__ret_native); } - // Unmarshal - Convert native data to managed data. - ret = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__ret_native); // Local P/Invoke [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_ushort", ExactSpelling = true)] static extern unsafe void __PInvoke(ushort* __s_native, ushort** __ret_native); @@ -6892,6 +6999,7 @@ public static partial void Reverse_Out(string s, out string ret) finally { // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__ret_native); __s_native__marshaller.Free(); } @@ -7120,6 +7228,7 @@ public static partial void Reverse_Out(string s, out string ret) finally { // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__ret_native); __s_native__marshaller.Free(); } @@ -7386,6 +7495,7 @@ public static partial void Reverse_Out(string s, out string ret) finally { // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.Free(__ret_native); __s_native__marshaller.Free(); } @@ -7652,6 +7762,7 @@ public static partial void Reverse_Out(string s, out string ret) finally { // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.Free(__ret_native); __s_native__marshaller.Free(); } @@ -7849,15 +7960,24 @@ public unsafe partial class Utf16 public static partial void Reverse_Out(string s, out string ret) { System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); - ushort* __ret_native; - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + ushort* __ret_native = default; + try { - __PInvoke((ushort*)__s_native, &__ret_native); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __PInvoke((ushort*)__s_native, &__ret_native); + } + + // Unmarshal - Convert native data to managed data. + ret = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__ret_native); + } + finally + { + // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__ret_native); } - // Unmarshal - Convert native data to managed data. - ret = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__ret_native); // Local P/Invoke [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_ushort", ExactSpelling = true)] static extern unsafe void __PInvoke(ushort* __s_native, ushort** __ret_native); @@ -8097,6 +8217,7 @@ public static partial void Reverse_Out(string s, out string ret) finally { // Cleanup - Perform required cleanup. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__ret_native); __s_native__marshaller.Free(); }