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.
4/8/2010

When users have finished performing messaging tasks, there is no further need to consume valuable system resources with the messaging subsystem. At that point, it is a good idea to free resources by ending the MAPI session.

To end the MAPI session

  1. End the MAPI session with the IMAPISession::Logoffmethod, as follows:

    Copy Code
    hr = pSession->Logoff(0, 0, 0);
    
  2. Decrement the MAPI session reference count by calling MAPI IUnknown::Releaseon the MAPI session object:

    Copy Code
    pSession->Release();
    
  3. Decrement the MAPI subsystem reference count, and delete any per-instance global data for the MAPI DLL with the MAPIUninitializeglobal MAPI function:

    Copy Code
    MAPIUninitialize();
    

Example

The following code example demonstrates how to end a MAPI session.

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;

hr = MAPIInitialize(NULL);
hr = MAPILogonEx(0, NULL, NULL, 0, (LPMAPISESSION *)&pSession);

hr = pSession->Logoff(0, 0, 0);

pSession->Release();
pSession = NULL;

MAPIUninitialize();

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.

    Copy Code
    #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 Pagesdialog box appears.

    2. In the dialog box, navigate to the Inputproperty page for the Linker(navigate to Configuration Properties> Linker> Input).

    3. In Additional Dependencies, type Cemapi.lib, and then click OK.

See Also