__unhook
Dissociates a handler method from an event.
long __unhook( &SourceClass::EventMethod, source, &ReceiverClass::HandlerMethod [, receiver = this] ); long __unhook( interface, source ); long __unhook( source );
Use the intrinsic function __unhook in an event receiver to dissociate or "unhook" a handler method from an event method.
There are three forms of __unhook. You can use the first (four-argument) form in most cases. You can use the second (two-argument) form of __unhook only for a COM event receiver; this unhooks the entire event interface. You can use the third (one-argument) form to unhook all delegates from the specified source.
A nonzero return value indicates that an error has occurred (managed events will throw an exception).
If you call __unhook on an event and event handler that are not already hooked, it will have no effect.
At compile time, the compiler verifies that the event exists and does parameter type checking with the specified handler.
With the exception of COM events, __hook and __unhook can be called outside the event receiver.
An alternative to using __unhook is to use the -= operator.
For information on coding managed events in the new syntax, see event (Visual C++).
Note
|
|---|
|
A templated class or struct cannot contain events. |
See Event Handling in Native C++ and Event Handling in COM for samples.
Note