Share via


Ending a MAPI Session

Send Feedback

When the user is done performing messaging tasks, there is no further need to consume valuable system resources with the messaging subsystem. At this 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::Logoff method, as follows:

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

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

    MAPIUninitialize();
    

Code 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.

hr = pSession->Logoff(0, 0, 0);
if (hr != S_OK) {
    // Logoff failed.
    MessageBox(NULL, 
               _T("Logoff failed."),
               _T("Warning"), 
               MB_OK);
    exit(0);  // Replace with specific error handling.
}

pSession->Release();
pSession = NULL;
MAPIUninitialize();

See Also

How to Create a Messaging Application | Messaging Application Development for Windows Mobile-based Devices | Messaging | How to: Begin a MAPI Session | How to: Connect to a Message Store | How to: Create a Message | How to: Send a Message | Messaging Sample Code

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.