Freigeben über


Connecting to a Message Store

4/8/2010

Before you can create and manipulate message folders and message items, you must establish a connection to a message store.

To open a connection to a message store

  1. Initialize the MAPI subsystem, and log onto a MAPI session. For more information, see Beginning a MAPI Session.

  2. Declare a NULL IMAPITable interface object, and get the message stores table by using IMAPISession::GetMsgStoresTable, as follows:

    hr = pSession->GetMsgStoresTable(0, &pTable);
    
  3. Declare a NULL SRowSet structure, and populate it with property values from one of the message stores by using IMAPITable::QueryRows. The following code retrieves the first (default) message store:

    hr = pTable->QueryRows(1, 0, &pSRowSet);
    
  4. Declare a NULL IMsgStore interface object, and open the message store by using IMAPISession::OpenMsgStore—making use of the SRowSet structure:

    hr = pSession->OpenMsgStore(0,
                                pSRowSet->aRow[0].lpProps[0].Value.bin.cb,
                                (ENTRYID *)pSRowSet->aRow[0].lpProps[0].Value.bin.lpb,
                                NULL, 0, &pStore);
    
  5. If no longer needed, release the message stores table by calling IUnknown::Release on the table object, and free the memory allocated for the row set structure by calling FreeProws:

    pTable->Release();
    FreeProws(pSRowSet);
    

Example

The following code example demonstrates how to connect to the local message store on a Windows Mobile device.

Note

To make the following code example easier to read, security checking and error handling are not included. This code example should not be used in a release configuration unless it has been modified to include them.

HRESULT hr;

ICEMAPISession * pSession = NULL;
IMAPITable     * pTable   = NULL;
SRowSet        * pSRowSet = NULL;
IMsgStore      * pStore   = NULL;

hr = pSession->GetMsgStoresTable(0, &pTable);

hr = pTable->QueryRows(1, 0, &pSRowSet);

hr = pSession->OpenMsgStore(0,
                            pSRowSet->aRow[0].lpProps[0].Value.bin.cb,
                            (ENTRYID *)pSRowSet->aRow[0].lpProps[0].Value.bin.lpb,
                            NULL, 0, &pStore);

pTable->Release();
FreeProws(pSRowSet);

pTable   = NULL;
pSRowSet = NULL;

Both the Windows Mobile Professional SDK and the Windows Mobile Standard SDK ship with a code sample called Sending E-mail, which you can build and run to gain a better understanding of the fundamental messaging concepts. The default location for the sample:

C:\Program Files\Windows Mobile 6.5.3 DTK\Samples\Common\CPP\Win32\SendMail\SendMail.sln

Compiling the Code

To compile the code sample, you must add references to the CE MAPI type library and the CE MAPI header files, to your project.

  1. Add preprocessor directives that include the header files in with the rest of your project files when you build your project. You do this by typing the following statements at the top of either your main C++ source file or your header file.

    #include <cemapi.h>
    #include <mapidefs.h>
    #include <mapiutil.h>
    #include <mapix.h>
    
  2. Specify a linker dependency to the CE MAPI type library as a project property.

    1. Press Alt+F7, and the Project Property Pages dialog box appears.
    2. In the dialog box, navigate to the Input property page for the Linker (navigate to Configuration Properties > Linker > Input).
    3. In Additional Dependencies, type cemapi.lib, and then click OK.

See Also

Tasks

Beginning a MAPI Session
Creating a Message
Sending a Message
Ending a MAPI Session

Reference

FreeProws

Concepts

Messaging Samples

Other Resources

Messaging Common Tasks
Messaging Application Development
Messaging