How to: Use the MAPI Crash Recovery API
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

How to: Use the MAPI Crash Recovery API

Last modified: November 03, 2010

Applies to: Office 2010 | Outlook 2010 | Visual Studio

This topic contains a code sample in C++ that shows how to call the MAPICrashRecovery function from the UnhandledExceptionFilter function. The MAPICrashRecovery function checks the state of the Personal Folders file (PST) or Offline Folders file (OST) shared memory. If the memory is in a consistent state, the MAPICrashRecovery function moves the data to disk and prevents further read or write access until the process is terminated. By ensuring that the PSTs or OSTs are in a consistent state before the process is terminated, you can prevent Microsoft Outlook 2010 from displaying the following error message and avoid performance problems.

A data file did not close properly the last time it was used and is being checked for problems. Performance might be affected while the check is in progress.

LONG WINAPI UnhandledExceptionFilter(__in EXCEPTION_POINTERS* pep) 
    // Let the OS terminate the process upon return. 
    switch (pep->ExceptionRecord->ExceptionCode) 
            // Ignore debugging exceptions. 
            retval = EXCEPTION_CONTINUE_SEARCH; 
            // The process is going to be terminated, so disconnect the MAPI database. 
            // Optionally, you can display a crash reporting dialog box here. 
            // If the user chooses to debug,  
            // call MAPICrashRecovery(MAPICRASH_CONTINUE). 
    return retval; 
© 2016 Microsoft