Platform SDK: MAPI

IMAPISession::Advise

The IMAPISession::Advise method registers to receive notification of specified events affecting the session.

Quick Info

See IMAPISession : IUnknown.

HRESULT Advise(
  ULONG cbEntryID,                 
  LPENTRYID lpEntryID,             
  ULONG ulEventMask,               
  LPMAPIADVISESINK lpAdviseSink,   
  ULONG FAR * lpulConnection       
);
 

Parameters

cbEntryID
[in] Count of bytes in the entry identifier pointed to by the lpEntryID parameter.
lpEntryID
[in] Pointer to the entry identifier of the address book or message store object about which notifications should be generated, or NULL, indicating that the client is registering to receive notifications about events that affect only the session.
ulEventMask
[in] A mask of values indicating the types of notification events that the client is interested in and should be included in the registration. If lpEntryID is NULL, MAPI automatically registers the client for critical error events for the session — the only type of event supported by the session.

When lpEntryID points to an entry identifier, the following values are valid for the ulEventMask parameter:

fnevCriticalError
Registers for notifications about severe errors, such as insufficient memory.
fnevExtended
Registers for notifications about events specific to a particular address book or message store provider and about session shut down.
fnevNewMail
Registers for notifications about the arrival of new messages.
fnevObjectCreated
Registers for notifications about the creation of a new object.
fnevObjectCopied
Registers for notifications about an object being copied.
fnevObjectDeleted
Registers for notifications about an object being deleted.
fnevObjectModified
Registers for notifications about an object being modified.
fnevObjectMoved
Registers for notifications about an object being moved.
fnevSearchComplete
Registers for notifications about the completion of a search operation.
lpAdviseSink
[in] Pointer to an advise sink object to receive the subsequent notifications. This advise sink object must have already been allocated.
lpulConnection
[out] Pointer to a nonzero number that represents the connection between the caller's advise sink object and the session.

Return Values

S_OK
The registration was successful.
MAPI_E_INVALID_ENTRYID
The entry identifier pointed to by lpEntryID does not represent a valid entry identifier.
MAPI_E_NO_SUPPORT
The service provider responsible for the entry identifier pointed to by lpEntryID either does not support the type of events specified in the ulEventMask parameter or does not support notification.
MAPI_E_UNKNOWN_ENTRYID
The entry identifier pointed to by lpEntryID cannot be handled by any of the service providers in the profile.

Remarks

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.

Notes to Callers

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.

See Also

NOTIFICATION, HrThisThreadAdviseSink, IMAPIAdviseSink::OnNotify, IMAPISession::Unadvise