This topic has not yet been rated - Rate this topic

ComAwareEventInfo.AddEventHandler Method

Attaches an event handler to a COM object.

Namespace:  System.Runtime.InteropServices
Assembly:  System.Core (in System.Core.dll)
public override void AddEventHandler(
	Object target,
	Delegate handler
)

Parameters

target
Type: System.Object

The target object that the event delegate should bind to.

handler
Type: System.Delegate

The event delegate.

Implements

_EventInfo.AddEventHandler(Object, Delegate)

This method is similar to the EventInfo.AddEventHandler(Object, Delegate) method except that it allows you to attach events to COM objects.

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 facilitates registering COM event sinks that forward calls to corresponding managed delegates. It requires the following information:

  • The target object itself (target).

  • The GUID of the source interface.

  • The DispID of the method on the COM interface that corresponds to the specified event.

  • The delegate that would be invoked when the COM object triggers the corresponding event (handler).

AddEventHandler looks up the corresponding COM source interface (specified as the first parameter of the ComEventInterfaceAttribute.ComEventInterfaceAttribute(Type, Type) constructor). It then looks up a method on the source interface whose name is identical to the event name. 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).

.NET Framework

Supported in: 4.5.1, 4.5, 4

.NET Framework Client Profile

Supported in: 4

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.