다음을 통해 공유


사용자 지정 특성을 적용하여 기본 COM DISPID(디스패치 식별자) 덮어쓰기

관리되지 않는 COM의 디스패치 인터페이스에는 지정된 DISPID가 없을 때 호출되는 기본 멤버((DISPID_VALUE 또는 0)가 있습니다. .NET Framework에서는 기본 메서드나 속성을 참조할 수 없으므로 이 custom 특성을 사용하면 가져오기를 할 때 원하는 DISPID를 기본 멤버로 지정할 수 있습니다. 이 custom 특성의 구문은 다음과 같습니다.

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

예제

IDL(Interface Definition language)로 작성된 다음 예제에서는 custom DISPID 특성을 사용하여, 가져오기를 할 때 DISPID가 2인 method1 멤버를 기본 멤버로 사용하도록 지정하는 방법을 보여 줍니다.

[
   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;
};

형식 라이브러리를 가져온 후의 MSIL은 다음과 같습니다.

.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.

참고 항목

참조

TypeLibConverter

ITypeLibConverter

Tlbimp.exe(형식 라이브러리 가져오기)

개념

사용자 지정 특성을 적용하여 IEnumerable 구현

사용자 지정 특성을 적용하여 관리되지 않는 COM Get/Set 속성에 태그 지정

형식 라이브러리를 어셈블리로 가져오기