Skip to content

[API Proposal]: Provide an IUnknown IID constant #91150

@AaronRobinsonMSFT

Description

@AaronRobinsonMSFT

Background and motivation

The IUnknown interface ID (IID) is a well known constant that has been set since the early 90's. This IID can be used in a myriad of cases, particularly with the new COM source generator. This constant should be defined in a way that can be used both as a declaration on an interface definition and as a way to easily implement QueryInterface().

Additional IIDs that could also be considered:

  • IID_IClassFactory
  • IID_IClassFactory2

API Proposal

The suggestion is a Guid member, but this could be a string, ReadOnlySpan<byte> or another type the Guid constructor can take. Another consideration is the constructor for GuidAttribute, which takes a string.

namespace System.Runtime.InteropServices;

public abstract class ComWrappers
{
+    public static readonly Guid IID_IUnknown;
}

API Usage

Used as a constant when implementing QueryInterface().

Alternative Designs

Define an IUnknown interface type in C# and define the value using the GuidAttribute. This approach is unfortunately not AOT compatible.

Risks

None. This is a well known value and one that should be available.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions