Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR 85117 #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<ComClassInformation>]
partial class DerivedImpl
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType
{
public static System.Guid Iid { get; } = new(new System.ReadOnlySpan<byte>(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<InterfaceInformation, InterfaceImplementation>]
internal partial interface Empty
{
}
}

namespace SharedTypes.ComInterfaces
{
internal partial interface Empty
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<void*, ushort*, int> )__vtable_native[5])(__this, (ushort*)__name_native);
__invokeRetVal = ((delegate* unmanaged[MemberFunction]<void*, ushort*, int> )__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<void*, ushort**, int> )__vtable_native[6])(__this, &__retVal_native);
__invokeRetVal = ((delegate* unmanaged[MemberFunction]<void*, ushort**, int> )__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);
Expand All @@ -51,22 +53,57 @@

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]<void*, int*, int> )__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]<void*, int, int> )__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
{
// 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<global::ComInterfaceGenerator.Tests.IDerivedComInterface>(__this_native);
@this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance<global::SharedTypes.ComInterfaces.IDerivedComInterface>(__this_native);
@this.SetName(name);
}
catch (System.Exception __exception)
Expand All @@ -82,18 +119,18 @@ 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;
try
{
// Unmarshal - Convert native data to managed data.
__retVal = 0; // S_OK
@this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance<global::ComInterfaceGenerator.Tests.IDerivedComInterface>(__this_native);
@this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance<global::SharedTypes.ComInterfaces.IDerivedComInterface>(__this_native);
__invokeRetVal = @this.GetName();
// Marshal - Convert managed data to native data.
__invokeRetValUnmanaged = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__invokeRetVal);
Expand All @@ -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<System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch*, ushort*, int> )&ABI_SetName;
vtable[6] = (void*)(delegate* unmanaged<System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch*, ushort**, int> )&ABI_GetName;
vtable[5] = (void*)(delegate* unmanaged[MemberFunction]<System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch*, ushort*, int> )&ABI_SetName;
vtable[6] = (void*)(delegate* unmanaged[MemberFunction]<System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch*, ushort**, int> )&ABI_GetName;
}

return vtable;
}
}

namespace ComInterfaceGenerator.Tests
namespace SharedTypes.ComInterfaces
{
[System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute<InterfaceInformation, InterfaceImplementation>]
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
int __retVal;
int __invokeRetVal;
{
__invokeRetVal = ((delegate* unmanaged<void*, int*, int> )__vtable_native[3])(__this, &__retVal);
__invokeRetVal = ((delegate* unmanaged[MemberFunction]<void*, int*, int> )__vtable_native[3])(__this, &__retVal);
}

System.GC.KeepAlive(this);
// Unmarshal - Convert native data to managed data.
System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal);
return __retVal;
Expand All @@ -32,17 +33,18 @@
var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IGetAndSetInt));
int __invokeRetVal;
{
__invokeRetVal = ((delegate* unmanaged<void*, int, int> )__vtable_native[4])(__this, x);
__invokeRetVal = ((delegate* unmanaged[MemberFunction]<void*, int, int> )__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]
[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;
Expand All @@ -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;
Expand Down Expand Up @@ -101,8 +103,8 @@ file unsafe partial interface InterfaceImplementation
}

{
vtable[3] = (void*)(delegate* unmanaged<System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch*, int*, int> )&ABI_GetInt;
vtable[4] = (void*)(delegate* unmanaged<System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch*, int, int> )&ABI_SetInt;
vtable[3] = (void*)(delegate* unmanaged[MemberFunction]<System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch*, int*, int> )&ABI_GetInt;
vtable[4] = (void*)(delegate* unmanaged[MemberFunction]<System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch*, int, int> )&ABI_SetInt;
}

return vtable;
Expand All @@ -112,7 +114,14 @@ file unsafe partial interface InterfaceImplementation
namespace SharedTypes.ComInterfaces
{
[System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute<InterfaceInformation, InterfaceImplementation>]
partial interface IGetAndSetInt
internal partial interface IGetAndSetInt
{
}
}

namespace SharedTypes.ComInterfaces
{
internal partial interface IGetAndSetInt
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
try
{
{
__invokeRetVal = ((delegate* unmanaged<void*, int**, int> )__vtable_native[3])(__this, &__retVal_native);
__invokeRetVal = ((delegate* unmanaged[MemberFunction]<void*, int**, int> )__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;
Expand All @@ -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;
Expand Down Expand Up @@ -92,7 +93,7 @@ file unsafe partial interface InterfaceImplementation
}

{
vtable[3] = (void*)(delegate* unmanaged<System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch*, int**, int> )&ABI_GetInts;
vtable[3] = (void*)(delegate* unmanaged[MemberFunction]<System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch*, int**, int> )&ABI_GetInts;
}

return vtable;
Expand All @@ -102,7 +103,14 @@ file unsafe partial interface InterfaceImplementation
namespace SharedTypes.ComInterfaces
{
[System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute<InterfaceInformation, InterfaceImplementation>]
partial interface IGetIntArray
internal partial interface IGetIntArray
{
}
}

namespace SharedTypes.ComInterfaces
{
internal partial interface IGetIntArray
{
}
}
Loading