diff --git a/README.md b/README.md deleted file mode 100644 index daa29e5..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -# GeneratedCode diff --git a/main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.GeneratedComInterfaceTests.DerivedImpl.cs b/main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.GeneratedComInterfaceTests.DerivedImpl.cs new file mode 100644 index 0000000..198dff9 --- /dev/null +++ b/main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.GeneratedComInterfaceTests.DerivedImpl.cs @@ -0,0 +1,39 @@ +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.IDerivedComInterface).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 GeneratedComInterfaceTests + { + [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute] + partial class DerivedImpl + { + } + } +} diff --git a/main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.Empty.cs b/main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.Empty.cs new file mode 100644 index 0000000..50b93e0 --- /dev/null +++ b/main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.Empty.cs @@ -0,0 +1,51 @@ +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.Empty +{ +} + +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.Empty), 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 Empty + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface Empty + { + } +} \ No newline at end of file diff --git a/main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/ComInterfaceGenerator.Tests.IDerivedComInterface.cs b/main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IDerivedComInterface.cs similarity index 55% rename from main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/ComInterfaceGenerator.Tests.IDerivedComInterface.cs rename to main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IDerivedComInterface.cs index 0f90d2c..865c8e3 100644 --- a/main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/ComInterfaceGenerator.Tests.IDerivedComInterface.cs +++ b/main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IDerivedComInterface.cs @@ -7,38 +7,40 @@ } [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] -file unsafe partial interface InterfaceImplementation : global::ComInterfaceGenerator.Tests.IDerivedComInterface +file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IDerivedComInterface { [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] [System.Runtime.CompilerServices.SkipLocalsInitAttribute] - void global::ComInterfaceGenerator.Tests.IDerivedComInterface.SetName(string name) + void global::SharedTypes.ComInterfaces.IDerivedComInterface.SetName(string name) { - var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::ComInterfaceGenerator.Tests.IDerivedComInterface)); + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IDerivedComInterface)); 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 )__vtable_native[5])(__this, (ushort*)__name_native); + __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); } [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] [System.Runtime.CompilerServices.SkipLocalsInitAttribute] - string global::ComInterfaceGenerator.Tests.IDerivedComInterface.GetName() + string global::SharedTypes.ComInterfaces.IDerivedComInterface.GetName() { - var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::ComInterfaceGenerator.Tests.IDerivedComInterface)); + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IDerivedComInterface)); string __retVal; ushort* __retVal_native = default; int __invokeRetVal; try { { - __invokeRetVal = ((delegate* unmanaged )__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); @@ -51,14 +53,49 @@ return __retVal; } + + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [System.Runtime.CompilerServices.SkipLocalsInitAttribute] + int global::SharedTypes.ComInterfaces.IDerivedComInterface.GetInt() + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IDerivedComInterface)); + 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; + } + + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IDerivedComInterface.SetInt(int x) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IDerivedComInterface)); + 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] + [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::ComInterfaceGenerator.Tests.IDerivedComInterface @this = default; + global::SharedTypes.ComInterfaces.IDerivedComInterface @this = default; string name = default; int __retVal = default; try @@ -66,7 +103,7 @@ internal static int ABI_SetName(System.Runtime.InteropServices.ComWrappers.ComIn // 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 = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.SetName(name); } catch (System.Exception __exception) @@ -82,10 +119,10 @@ internal static int ABI_SetName(System.Runtime.InteropServices.ComWrappers.ComIn return __retVal; } - [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] + [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::ComInterfaceGenerator.Tests.IDerivedComInterface @this = default; + global::SharedTypes.ComInterfaces.IDerivedComInterface @this = default; ref ushort* __invokeRetValUnmanaged = ref *__invokeRetValUnmanaged__param; string __invokeRetVal = default; int __retVal = default; @@ -93,7 +130,7 @@ internal static int ABI_GetName(System.Runtime.InteropServices.ComWrappers.ComIn { // Unmarshal - Convert native data to managed data. __retVal = 0; // S_OK - @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @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); @@ -116,24 +153,33 @@ file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() { - void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::ComInterfaceGenerator.Tests.IDerivedComInterface), sizeof(void*) * 7); + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IDerivedComInterface), sizeof(void*) * 7); { - System.Runtime.InteropServices.NativeMemory.Copy(System.Runtime.InteropServices.Marshalling.StrategyBasedComWrappers.DefaultIUnknownInterfaceDetailsStrategy.GetIUnknownDerivedDetails(typeof(global::ComInterfaceGenerator.Tests.IComInterface1).TypeHandle).ManagedVirtualMethodTable, vtable, (nuint)(sizeof(void*) * 5)); + 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 )&ABI_SetName; - vtable[6] = (void*)(delegate* unmanaged )&ABI_GetName; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_SetName; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_GetName; } return vtable; } } -namespace ComInterfaceGenerator.Tests +namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] - public partial interface IDerivedComInterface + internal partial interface IDerivedComInterface + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IDerivedComInterface { + new int GetInt() => ((global::SharedTypes.ComInterfaces.IGetAndSetInt)this).GetInt(); + new void SetInt(int x) => ((global::SharedTypes.ComInterfaces.IGetAndSetInt)this).SetInt(x); } } \ No newline at end of file diff --git a/main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetAndSetInt.cs b/main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetAndSetInt.cs index b7ec442..a5092aa 100644 --- a/main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetAndSetInt.cs +++ b/main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetAndSetInt.cs @@ -17,9 +17,10 @@ int __retVal; int __invokeRetVal; { - __invokeRetVal = ((delegate* unmanaged )__vtable_native[3])(__this, &__retVal); + __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; @@ -32,9 +33,10 @@ var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IGetAndSetInt)); int __invokeRetVal; { - __invokeRetVal = ((delegate* unmanaged )__vtable_native[4])(__this, x); + __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); } @@ -42,7 +44,7 @@ file unsafe partial interface InterfaceImplementation { - [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] + [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; @@ -66,7 +68,7 @@ internal static int ABI_GetInt(System.Runtime.InteropServices.ComWrappers.ComInt return __retVal; } - [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] + [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; @@ -101,8 +103,8 @@ file unsafe partial interface InterfaceImplementation } { - vtable[3] = (void*)(delegate* unmanaged )&ABI_GetInt; - vtable[4] = (void*)(delegate* unmanaged )&ABI_SetInt; + vtable[3] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_GetInt; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_SetInt; } return vtable; @@ -112,7 +114,14 @@ file unsafe partial interface InterfaceImplementation namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] - partial interface IGetAndSetInt + internal partial interface IGetAndSetInt + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IGetAndSetInt { } } \ No newline at end of file diff --git a/main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetIntArray.cs b/main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetIntArray.cs index f17fa80..5e11504 100644 --- a/main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetIntArray.cs +++ b/main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetIntArray.cs @@ -23,9 +23,10 @@ try { { - __invokeRetVal = ((delegate* unmanaged )__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_native__numElements = 10; @@ -44,7 +45,7 @@ file unsafe partial interface InterfaceImplementation { - [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] + [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; @@ -92,7 +93,7 @@ file unsafe partial interface InterfaceImplementation } { - vtable[3] = (void*)(delegate* unmanaged )&ABI_GetInts; + vtable[3] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_GetInts; } return vtable; @@ -102,7 +103,14 @@ file unsafe partial interface InterfaceImplementation namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] - partial interface IGetIntArray + internal partial interface IGetIntArray + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IGetIntArray { } } \ No newline at end of file diff --git a/main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/ComInterfaceGenerator.Tests.IComInterface1.cs b/main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IPointProvider.cs similarity index 53% rename from main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/ComInterfaceGenerator.Tests.IComInterface1.cs rename to main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IPointProvider.cs index a583864..69093ae 100644 --- a/main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/ComInterfaceGenerator.Tests.IComInterface1.cs +++ b/main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IPointProvider.cs @@ -1,40 +1,39 @@ 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 })); + 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::ComInterfaceGenerator.Tests.IComInterface1 +file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IPointProvider { [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] [System.Runtime.CompilerServices.SkipLocalsInitAttribute] - int global::ComInterfaceGenerator.Tests.IComInterface1.GetData() + global::System.Drawing.Point global::SharedTypes.ComInterfaces.IPointProvider.GetPoint() { - var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::ComInterfaceGenerator.Tests.IComInterface1)); - int __retVal; - int __invokeRetVal; + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IPointProvider)); + global::System.Drawing.Point __retVal; { - __invokeRetVal = ((delegate* unmanaged )__vtable_native[3])(__this, &__retVal); + __retVal = ((delegate* unmanaged[MemberFunction] )__vtable_native[3])(__this); } - // Unmarshal - Convert native data to managed data. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + System.GC.KeepAlive(this); return __retVal; } [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] [System.Runtime.CompilerServices.SkipLocalsInitAttribute] - void global::ComInterfaceGenerator.Tests.IComInterface1.SetData(int n) + void global::SharedTypes.ComInterfaces.IPointProvider.SetPoint(global::System.Drawing.Point point) { - var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::ComInterfaceGenerator.Tests.IComInterface1)); + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IPointProvider)); int __invokeRetVal; { - __invokeRetVal = ((delegate* unmanaged )__vtable_native[4])(__this, n); + __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); } @@ -42,41 +41,36 @@ file unsafe partial interface InterfaceImplementation { - [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] - internal static int ABI_GetData(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int* __invokeRetValUnmanaged__param) + [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::ComInterfaceGenerator.Tests.IComInterface1 @this = default; - ref int __invokeRetValUnmanaged = ref *__invokeRetValUnmanaged__param; - int __invokeRetVal = default; - int __retVal = default; + global::SharedTypes.ComInterfaces.IPointProvider @this = default; + global::System.Drawing.Point __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.GetData(); - // Marshal - Convert managed data to native data. - __invokeRetValUnmanaged = __invokeRetVal; + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __retVal = @this.GetPoint(); } catch (System.Exception __exception) { - __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsDefaultMarshaller.ConvertToUnmanaged(__exception); } return __retVal; } - [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute] - internal static int ABI_SetData(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int n) + [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::ComInterfaceGenerator.Tests.IComInterface1 @this = default; + 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.SetData(n); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.SetPoint(point); } catch (System.Exception __exception) { @@ -91,7 +85,7 @@ file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() { - void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::ComInterfaceGenerator.Tests.IComInterface1), sizeof(void*) * 5); + 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); @@ -101,18 +95,25 @@ file unsafe partial interface InterfaceImplementation } { - vtable[3] = (void*)(delegate* unmanaged )&ABI_GetData; - vtable[4] = (void*)(delegate* unmanaged )&ABI_SetData; + vtable[3] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_GetPoint; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction] )&ABI_SetPoint; } return vtable; } } -namespace ComInterfaceGenerator.Tests +namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] - public partial interface IComInterface1 + internal partial interface IPointProvider + { + } +} + +namespace SharedTypes.ComInterfaces +{ + internal partial interface IPointProvider { } } \ No newline at end of file diff --git a/main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/ManagedToNativeStubs.g.cs b/main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/ManagedToNativeStubs.g.cs index 7eb9069..3a07cec 100644 --- a/main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/ManagedToNativeStubs.g.cs +++ b/main/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/ManagedToNativeStubs.g.cs @@ -19,6 +19,7 @@ internal unsafe partial interface Native __retVal = ((delegate* unmanaged )__vtable_native[0])(__this); } + System.GC.KeepAlive(this); return __retVal; } } @@ -44,6 +45,8 @@ internal unsafe partial interface Native { ((delegate* unmanaged )__vtable_native[1])(__this, x); } + + System.GC.KeepAlive(this); } } } @@ -70,6 +73,7 @@ internal unsafe partial interface Native __retVal = ((delegate* unmanaged )__vtable_native[0])(x, y); } + System.GC.KeepAlive(this); return __retVal; } } @@ -97,6 +101,7 @@ internal unsafe partial interface Native __retVal = ((delegate* unmanaged )__vtable_native[1])(x, y); } + System.GC.KeepAlive(this); return __retVal; } } diff --git a/main/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs b/main/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs deleted file mode 100644 index 8e1783f..0000000 --- a/main/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs +++ /dev/null @@ -1,126 +0,0 @@ -// -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 -{ - 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 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 - { - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [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 - { - [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [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(); - } - } - } -}