ComAwareEventInfo.AddEventHandler(Object, Delegate) Método

Definição

Anexa um manipulador de eventos a um objeto COM.Attaches an event handler to a COM object.

public:
 override void AddEventHandler(System::Object ^ target, Delegate ^ handler);
public override void AddEventHandler (object target, Delegate handler);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public override void AddEventHandler (object target, Delegate handler);
override this.AddEventHandler : obj * Delegate -> unit
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
override this.AddEventHandler : obj * Delegate -> unit
Public Overrides Sub AddEventHandler (target As Object, handler As Delegate)

Parâmetros

target
Object

O objeto de destino ao qual o delegado de evento deve ser associado.The target object that the event delegate should bind to.

handler
Delegate

O delegado do evento.The event delegate.

Atributos

Comentários

Esse método é semelhante ao EventInfo.AddEventHandler(Object, Delegate) método, exceto pelo fato de que ele permite anexar eventos a objetos com.This method is similar to the EventInfo.AddEventHandler(Object, Delegate) method except that it allows you to attach events to COM objects.

Se target for um objeto com, esse método adicionará um delegado a um evento usando o ComEventsHelper.Combine(Object, Guid, Int32, Delegate) método.If target is a COM object, this method adds a delegate to an event by using the ComEventsHelper.Combine(Object, Guid, Int32, Delegate) method.

AddEventHandler facilita o registro de coletores de eventos COM que encaminham chamadas para delegados gerenciados correspondentes.AddEventHandler facilitates registering COM event sinks that forward calls to corresponding managed delegates. Ele requer as seguintes informações:It requires the following information:

  • O próprio objeto de destino ( target ).The target object itself (target).

  • O GUID da interface de origem.The GUID of the source interface.

  • O DispID do método na interface COM que corresponde ao evento especificado.The DispID of the method on the COM interface that corresponds to the specified event.

  • O delegado que seria invocado quando o objeto COM disparar o evento correspondente ( handler ).The delegate that would be invoked when the COM object triggers the corresponding event (handler).

AddEventHandler pesquisa a interface de origem COM correspondente (especificada como o primeiro parâmetro do ComEventInterfaceAttribute.ComEventInterfaceAttribute(Type, Type) Construtor).AddEventHandler looks up the corresponding COM source interface (specified as the first parameter of the ComEventInterfaceAttribute.ComEventInterfaceAttribute(Type, Type) constructor). Em seguida, ele pesquisa um método na interface de origem cujo nome é idêntico ao nome do evento.It then looks up a method on the source interface whose name is identical to the event name. O valor de GuidAttribute na interface de origem é o GUID que é passado para ComEventsHelper.Combine(Object, Guid, Int32, Delegate) ; o valor de DispIDAttribute no método é o valor de DISPID que é passado para ComEventsHelper.Combine(Object, Guid, Int32, Delegate) .The value of GuidAttribute on the source interface is the GUID that is passed to ComEventsHelper.Combine(Object, Guid, Int32, Delegate); the value of DispIDAttribute on the method is the DispID value that is passed to ComEventsHelper.Combine(Object, Guid, Int32, Delegate).

Aplica-se a