Associates a handler method with an event.
long __hook( &SourceClass::EventMethod, source, &ReceiverClass::HandlerMethod [, receiver = this] ); long __hook( interface, source );
Use the intrinsic function __hook in an event receiver to associate or hook a handler method with an event method. The specified handler is then called when the source raises the specified event. You can hook several handlers to a single event or hook several events to a single handler.
There are two forms of __hook. You can use the first (four-argument) form in most cases, specifically, for COM event receivers in which the layout_dependent parameter of the event_receiver attribute is false.
In these cases you do not need to hook all methods in an interface before firing an event on one of the methods; only the method handling the event needs to be hooked. You can use the second (two-argument) form of __hook only for a COM event receiver in which layout_dependent=true.
__hook returns a long value. A nonzero return value indicates that an error has occurred (managed events throw an exception).
The compiler checks for the existence of an event and that the event signature agrees with the delegate signature.
With the exception of COM events, __hook and __unhook can be called outside the event receiver.
An alternative to using __hook is to use the += operator.
For information on coding managed events in the new syntax, see event (Visual C++).
A templated class or struct cannot contain events.