Aracılığıyla paylaş


Applying the custom Attribute to Overwrite the Default COM Dispatch Identifier (DISPID)

Dispatch interfaces in unmanaged COM have a default member (DISPID_VALUE, or 0) that is called in the absence of a specified DISPID. The .NET Framework cannot reference a default method or property; thus, you can use this custom attribute to specify any DISPID as the default member upon import. The syntax of this custom attribute is as follows:

GUID = CD2BC5C9-F452-4326-B714-F9C539D4DA58
Value = number indicating the default DISPID

Example

The following example, written in the Interface Definition language (IDL), shows the use of the custom DISPID attribute to specify, upon import, that the member method1, with a DISPID of 2, is to be used as the default member.

[
   object,
   uuid(5EA05866-2E49-421C-BE47-FF62C5B9504E),
   dual,
   helpstring("IMyClass Interface"),
   pointer_default(unique)
]
interface IMyClass : IDispatch
{
   // Use the default dispID.
   [custom(CD2BC5C9-F452-4326-B714-F9C539D4DA58, 0), id(2), helpstring("method method1")] HRESULT method1();
};
[
   uuid(186D98EE-6750-42B9-947D-B82CF4A94600),
   helpstring("MyClass Class")
]
coclass MyClass
{
   [default] interface IMyClass;
};

The resulting MSIL after importing the type library would look similar to the following:

.method public hidebysig newslot abstract virtual 
instance void  method1() runtime managed internalcall
{
.custom instance void [mscorlib]System.Runtime.InteropServices.DispIdAttribute::.ctor(int32) = ( 01 00 03 00 00 00 00 00 ) 
} // This is the end of method IMyClass::method1.

See Also

Reference

TypeLibConverter

ITypeLibConverter

Tlbimp.exe (Type Library Importer)

Concepts

Applying the custom Attribute to Implement IEnumerable

Applying the custom Attribute to Tag Unmanaged COM Get/Set Properties

Importing a Type Library as an Assembly