Skip to content

Conversation

@jtschuster
Copy link
Member

Includes #82657, so wait until that's merged to look.

Adds GenerateIIUnknownInterfaceTypeImplementation method to generate the implementation of IIUnknownInterfaceType for the Com interface shown below. It always uses a guid of all 0's.

static Guid IIUnknownInterfaceType.Iid => new Guid("00000000-0000-0000-0000-000000000000");

private static readonly void** m_vtable = (void**)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(<InterfaceType>), sizeof(void*) * <numberOfInterfaceMethods + 3>);

static void** IIUnknownInterfaceType.ManagedVirtualMethodTable
{
    get
    {
        if (m_vtable[0] == null)
        {
            nint v0, v1, v2;
            ComWrappers.GetIUnknownImpl(out v0, out v1, out v2);
            m_vtable[0] = (void*)v0;
            m_vtable[1] = (void*)v1;
            m_vtable[2] = (void*)v2;
            Native.PopulateManagedVirtualMethodTable(m_vtable);
        }
         return m_vtable;
    }
}

Also adds a definition of an interface with [GeneratedComInterface] to easily view the output of the generator in VS, and as a basis for functionality tests.

@ghost
Copy link

ghost commented Mar 6, 2023

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

Issue Details

Includes #82657, so wait until that's merged to look.

Adds GenerateIIUnknownInterfaceTypeImplementation method to generate the implementation of IIUnknownInterfaceType for the Com interface shown below. It always uses a guid of all 0's.

static Guid IIUnknownInterfaceType.Iid => new Guid("00000000-0000-0000-0000-000000000000");

private static readonly void** m_vtable = (void**)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(<InterfaceType>), sizeof(void*) * <numberOfInterfaceMethods + 3>);

static void** IIUnknownInterfaceType.ManagedVirtualMethodTable
{
    get
    {
        if (m_vtable[0] == null)
        {
            nint v0, v1, v2;
            ComWrappers.GetIUnknownImpl(out v0, out v1, out v2);
            m_vtable[0] = (void*)v0;
            m_vtable[1] = (void*)v1;
            m_vtable[2] = (void*)v2;
            Native.PopulateManagedVirtualMethodTable(m_vtable);
        }
         return m_vtable;
    }
}

Also adds a definition of an interface with [GeneratedComInterface] to easily view the output of the generator in VS, and as a basis for functionality tests.

Author: jtschuster
Assignees: jtschuster
Labels:

area-System.Runtime.InteropServices

Milestone: -

@AaronRobinsonMSFT
Copy link
Member

It always uses a guid of all 0's.

@jtschuster This is fine for a draft PR but all 0's represents GUID_NULL which is an invalid interface ID. I would hardcode a few GUID values and then also have at least a test that uses a randomly generated one.

jkoritzinsky added a commit to jkoritzinsky/runtime that referenced this pull request Mar 7, 2023
@jtschuster
Copy link
Member Author

This is mostly a subset of #83055

@jtschuster jtschuster closed this Mar 7, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Apr 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants