event_receiver
attribute
Creates an event receiver (sink).
Note
Event attributes in native C++ are incompatible with Standard C++. They don't compile when you specify /permissive-
conformance mode.
Syntax
[ event_receiver(type
[, layout_dependent=false]) ]
Parameters
type
An enumeration of one of the following values:
native
for unmanaged C/C++ code (default for native classes).com
for COM code. This value requires that you include these header files:#define _ATL_ATTRIBUTES #include <atlbase.h> #include <atlcom.h>
layout_dependent
Specify layout_dependent
only if type
=com. layout_dependent
is a Boolean:
true
means that the signature of the delegates in the event receiver must exactly match the ones they're hooked to in the event source. The event receiver handler names must match the names specified in the relevant event source interface. Usecoclass
whenlayout_dependent
istrue
. It's slightly more efficient to specifytrue
.false
(default) means that the calling convention and storage class (virtual
,static
, and others) don't have to match the event method and the handlers. The handler names also don't need to match the event source interface method names.
Remarks
The event_receiver
C++ attribute specifies that the class or structure to which it's applied will be an event receiver, using the Microsoft C++ unified event model.
event_receiver
is used with the event_source
attribute and the __hook
and __unhook
keywords. Use event_source
to create event sources. Use __hook
within an event receiver's methods to associate ("hook") event receiver methods to the events of an event source. Use __unhook
to disassociate them.
layout_dependent
is only specified for COM event receivers (type
=com
). The default for layout_dependent
is false
.
Note
A templated class or struct cannot contain events.
Requirements
Attribute context | Value |
---|---|
Applies to | class , struct |
Repeatable | No |
Required attributes | coclass when layout_dependent =true |
Invalid attributes | None |
For more information, see Attribute contexts.
See also
Compiler attributes
event_source
__event
__hook
__unhook
Class attributes