Important: |
---|
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
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
-
Initialize the MAPI subsystem, and log onto a MAPI session. For more information, see Beginning a MAPI Session.
-
Declare a NULL IMAPITableinterface object, and get the message stores table by using IMAPISession::GetMsgStoresTable, as follows:
Copy Code hr = pSession->GetMsgStoresTable(0, &pTable);
-
Declare a NULL SRowSetstructure, 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:
Copy Code hr = pTable->QueryRows(1, 0, &pSRowSet);
-
Declare a NULL IMsgStoreinterface object, and open the message store by using IMAPISession::OpenMsgStore—making use of the SRowSetstructure:
Copy Code hr = pSession->OpenMsgStore(0, pSRowSet->aRow[0].lpProps[0].Value.bin.cb, (ENTRYID *)pSRowSet->aRow[0].lpProps[0].Value.bin.lpb, NULL, 0, &pStore);
-
If no longer needed, release the message stores table by calling IUnknown::Releaseon the table object, and free the memory allocated for the row set structure by calling FreeProws:
Copy Code 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. |
Copy Code | |
---|---|
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.
- 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.
Copy Code #include <cemapi.h> #include <mapidefs.h> #include <mapiutil.h> #include <mapix.h>
- Specify a linker dependency to the CE MAPI type library as a
project property.
- Press
Alt+F7, and the
Project Property Pagesdialog box appears.
- In the dialog box, navigate to the
Inputproperty page for the
Linker(navigate to
Configuration Properties>
Linker>
Input).
- In
Additional Dependencies, type cemapi.lib, and then click
OK.
- Press
Alt+F7, and the
Project Property Pagesdialog box appears.
See Also
Tasks
Beginning a MAPI SessionCreating a Message
Sending a Message
Ending a MAPI Session
Reference
FreeProwsConcepts
Messaging SamplesOther Resources
Messaging Common TasksMessaging Application Development
Messaging