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.
Background and motivation
The
IUnknowninterface 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 implementQueryInterface().Additional IIDs that could also be considered:
IID_IClassFactoryIID_IClassFactory2API Proposal
The suggestion is a
Guidmember, but this could be astring,ReadOnlySpan<byte>or another type theGuidconstructor can take. Another consideration is the constructor forGuidAttribute, which takes astring.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
IUnknowninterface type in C# and define the value using theGuidAttribute. This approach is unfortunately not AOT compatible.Risks
None. This is a well known value and one that should be available.