(Original) Ce mapi instance description-how to get all messages in inbox (1)

Source: Internet
Author: User

The first time I wrote this stuff, it was quite awkward. However, when I thought about the previous problems, I also got a lot of help from the network. At the same time, I also got a lot of help in csdn, I also saw some netizens asking questions about mapi. Although I am not very good at writing, I think it is necessary to share my accumulated things with everyone over the past few years, I hope to help you. My writing skills are not good, so I will try to use code to express my meaning. I have a superficial understanding of some theoretical knowledge, I hope you can correct the error. Thank you!
I will not talk much about the significance of mapi. You can go to msdn to find out why my English is poor and misleading. In the following example, all error handling will be omitted to Reduce the length, but during normal use, we hope that the user can add detailed error handling, which will make our program more robust.
Let's take a look at the first example, how to get messages in each message box in tmail (the inbox program we call it well-known.
Step 1: Initialize mapi:
// Session variable. Do not release it before you stop using mapi.
Imapisession * m_psession = NULL;

// COM Initialization
Coinitializeex (null, coinit_multithreaded );
Mapiinitialize (null );
Mapilogonex (null, & m_psession );

Exit mapi
 If (m_psession)
{
M_psession-> logoff (0, 0, 0 );
M_psession-> release ();
M_psession = NULL;
}
Mapiuninitialize ();
Couninitialize ();


Step 2: Get the message store. For the message store, I think it is a collection of message and folder management. It corresponds to each account in the inbox and each account has a store, we can use session to traverse all message stores. Each store has a display name, through which we can get the specified store. The following shows how to get the SMS store:
// Imapitable, through which we can access data, such as store, folder, and message. The methods are similar. Next we will introduce
Lpmapitable ptable = NULL;
Ulong lcount = 0;
Hresult hR = 0;
Lpsrowset prows = NULL;
Imsgstore * pmsgstore = NULL;
// How many attributes do you want to obtain? Here we only need to obtain two attributes
Ulong ulnumcols = 2;
// The following definition tells the system that we need to obtain the following two attributes: Entry ID, store object, and display name, we use it to compare whether it is the store we need
Sizedsproptagarray (ulnumcols, columns) =
{
Ulnumcols,
Pr_entryid, // entry ID of the store
Pr_display_name // display name of store
};

Psession-> getmsgstorestable (mapi_unicode, & ptable );
Ptable-> setcolumns (lpsproptagarray) & columns, 0 );

While (succeeded (ptable-> queryrows (1, 0, & prows )))
{

If(Null = prows | prows-> crows! = 1)

{

Break;

}
// Start querying records, prows-> Arow [0]. lpprops [0] indicates the first query attribute, that is, entry ID, prows-> Arow [0]. lpprops [1] indicates the display name.
If (_ tcsicmp (prows-> Arow [0]. lpprops [1]. value. lpszw, _ T ("SMS") = 0)
{
Ulong ulmesagetype;
// If it is SMS, obtain the store object
Psession-> openentry (prows-> Arow [0]. lpprops [0]. value. bin. CB,
(Lpentryid) prows-> Arow [0]. lpprops [0]. value. bin. LPB,
Null,
Mapi_best_access,
& Ulmesagetype,
(Lpunknown *) & pmsgstore );
Break;
}

Freeprows (prows );
Prows = NULL;
}
If (prows)
{
Freeprows (prows );
Prows = NULL;
}

At this point, we got the message store of SMS, exhausted. Take a break and let's continue to get the folder. Here, I would like to remind you that objects such as imsgstore obtained earlier and imapifolder to be discussed later must be release () when not in use. Never forget it.

Bored customers
2005.8.11
Yzx0023@gmail.com

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.