Ce mapi example (3)

Source: Internet
Author: User
Sometimes, we need to care about the change of a message and make a timely response. Of course, we cannot actively query the status of the message. Fortunately, the system provides imapiadvisesink, we can get notifications such as message moving, changing, and deleting. First, we need to implement our own imapiadvisesink interface. The prototype is: Class Cadvisesink:PublicImapiadvisesink { Public : Cadvisesink (); ~ Cadvisesink (); Mapimethod _ (ulong, onnotify) (ulong cnotif, lpnotification lpnotifications ); Mapimethod (QueryInterface) (refiid IID,Void** Ppvobject ); Mapimethod _ (ulong, addref )(); Mapimethod _ (ulong, release )();   Private : Ulong m_cref; }; Our main concern is Onnotify Other functions can be implemented according to the standard. Let's take a look at a simple implementation of onnotify. The key point is that I added a comment: Ulong cadvisesink: onnotify (ulong cnotif, lpnotification lpnotifications) { // Cnotif: Number of notification notifications // Lpnotifications: Notification Array, number of cnotif For(IntI = 0; I <(Int) Cnotif; ++ I) { // There are many types of Processing Based on Different notification types. Here are just a few simple lists. To obtain these notifications, it is closely related to registering advisesink. You need to tell the system, if you care about messages, such as message moving and deletion, the system will send these notifications to you. Other messages you don't care about will not be notified to you, we will talk about these in the subsequent registration section. Switch(Lpnotifications [I]. uleventtype) { CaseFnevobjectmoved: Break; CaseFnevobjectmodified: Break; CaseFnevobjectdeleted: Break; Default: Break; } } Return0; } Next, register advisesink, which corresponds to the store of each account, such as SMS and outlook. Follow these steps: A. Obtain the message store object to be monitored.ArticleWe already know how to obtain the specified message store. Here we take the SMS store as an example. B. Create our own cadvisesink object C. Call Imsgstore: advise Register The following is an example of RegistrationCode: Imsgstore * pmsgstore = ...... // Get SMS message store Cadvisesink * g_padvisesink = new cadvisesink (); Ulong m_uladvisesink = 0 ;// Used to identify advisesink. We need to use it when canceling registration. // Ueventmask: Its function is to tell the system what aspects of notification we care about, and events that are not listed will not respond in cadvisesink: onnotify. Ulong ueventmask = fnevcriticalerror | fnevnewmail | fnevobjectcreated | fnevobjectdeleted | Fnevobjectmodified | fnevobjectmoved | fnevobjectcopied | fnevsearchcomplete | fnevtablemodified | Fnevstatusobjectmodified | fnevreservedformapi | fnevextended; Pmsgstore-> advise (0, null, ueventmask, g_padvisesink, & m_uladvisesink ); In this way, the registration is successful.   The following is a sample code for canceling registration: If (m_uladvisesink) { Pmsgstore-> unadvise (m_uladvisesink ); } // Release object If (g_padvisesink) { Delete g_padvisesink; G_padvisesink = NULL; }   The previous section briefly introduces the usage of advisesink. In the next article, I will use a specific example to describe the use of advisesink in normal development. Bored customers Yzx0023@gmail.com 2006.4.25

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.