|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
Last modified: October 12, 2010
Applies to: Office 2010 | Outlook 2010 | Visual Studio
Registers to receive notification of specified events that affect the message store.
The IMsgStore::Advise method establishes a connection between the caller's advise sink object and either the message store or an object in the message store. 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 advise source object. When the lpEntryID parameter points to a valid entry identifier, the advise source is the object identified by this entry identifier. When lpEntryID is NULL, the advise source is the message store.
To send a notification, either the message store 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.
You can support notification with or without help from MAPI. MAPI has three support object methods for helping service providers implement notification: IMAPISupport::Subscribe, IMAPISupport::Unsubscribe, and IMAPISupport::Notify. If you elect to use the MAPI support methods, call Subscribe when your Advise method is called and release the lpAdviseSink pointer.
If you elect to support notification yourself, call the IUnknown::AddRef method of the advise sink represented by the lpAdviseSink parameter to keep a copy of this pointer. Maintain this copy until your IMsgStore::Unadvise method is called to cancel the registration.
Regardless of how you support notification, assign a nonzero connection number to the notification registration and return it in the lpulConnection parameter. Do not release this connection number until Unadvise has been called and has completed.
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 occur only at a particular time on a particular thread, call the HrThisThreadAdviseSink function to generate the advise sink object that you pass to Advise.
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 more information about the notification process, see Event Notification in MAPI.
For more information about handling notifications, see Handling Notifications.