ComAwareEventInfo.AddEventHandler Method (Object, Delegate)

.NET Framework (current version)
 

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.

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

SecurityPermission

for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Universal Windows Platform
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Windows Phone
Available since 8.1
Return to top
Show: