Platform SDK: MAPI |
The IMAPISession::Advise method registers to receive notification of specified events affecting the session.
HRESULT Advise( ULONG cbEntryID, LPENTRYID lpEntryID, ULONG ulEventMask, LPMAPIADVISESINK lpAdviseSink, ULONG FAR * lpulConnection );
When lpEntryID points to an entry identifier, the following values are valid for the ulEventMask parameter:
The IMAPISession::Advise method establishes a connection between the caller's advise sink object, the session, and, as an option, a service provider. This connection is used to send notifications to the advise sink when one or more events as specified in the ulEventMask parameter occur to the object pointed to by lpEntryID. When lpEntryID is NULL, the target object is the session and notifications are sent for critical error and extended events only.
When lpEntryID points to a valid entry identifier, MAPI calls the Advise method of the logon object belonging to the responsible service provider. For example, if lpEntryID points to the entry identifier of a distribution list, MAPI calls the appropriate address book provider's IABLogon::Advise method.
To send a notification, either the service provider or MAPI calls the registered advise sink's IMAPIAdviseSink::OnNotify method. One of the parameters to OnNotify, a notification structure, contains information that describes the specific event.
On systems that support multiple threads of execution, the call to OnNotify can also occur on any thread at any time. If you must be assured that notifications only occur at a particular time on a particular thread, call HrThisThreadAdviseSink to generate the advise sink object that you pass to Advise.
To determine when a client has logged off, register for notifications in your service provider by calling Advise with lpEntryID set to NULL and cbEntryID set to zero. When the logoff occurs, you'll receive an fnevExtended notification.
After a call to Advise has succeeded and before Unadvise has been called to cancel the registration, be prepared for the advise sink object to be released. You should release your advise sink object after Advise returns unless you have a specific long-term use for it.
For an overview of the notification process, see Event Notification in MAPI.
For more information on handling notifications, see Handling Notifications.
NOTIFICATION, HrThisThreadAdviseSink, IMAPIAdviseSink::OnNotify, IMAPISession::Unadvise