Microsoft KB Archive/252625

= PRB: Custom MAPI Form Closes Unexpectedly =

Article ID: 252625

Article Last Modified on 3/4/2004

-

APPLIES TO


 * Microsoft Outlook 2000 Standard Edition
 * Microsoft Outlook 98 Standard Edition
 * Microsoft Outlook 97 Service Pack 1
 * Microsoft Outlook 97 Service Pack 1
 * Microsoft Outlook 97 Service Pack 1
 * Microsoft Outlook 97 Standard Edition

-



This article was previously published under Q252625



SYMPTOMS
When you use Outlook, Outlook may open messages without displaying them. This may cause behaviors with custom MAPI forms that do not take this action into account. Forms that implement Custom Verbs through the DoVerb mechanism are especially affected. Refer to the "References" section for more details on Custom Verbs.

This behavior may occur with a MAPI form that has Custom Verbs, and whose response to a IMAPIForm::ShutdownForm is to close the user interface, release itself, and disappear.

Steps to Reproduce Behavior

 * 1) Open a message that uses a form (such as described above) and has an attachment.
 * 2) From the folder list in Outlook, right-click the message and select a custom verb. The verb executes and the message you had opened closes.



CAUSE
This behavior can occur because Outlook has to load the message in it's form to determine what to place in the context menu. After the verb is executed, Outlook calls ShutdownForm, which is required by MAPI. This is what causes the behavior, and because a client should not open more than one copy of a message, all of this actually happens to the form that is currently being displayed.



RESOLUTION
To avoid the behavior, you can do a conditional check when ShutdownForm is called. For example, in your application you can implement a pair of flags that indicate when it is safe to close. Assuming that the first flag is called m_bFormDisplayed and the second one is called m_bOkToQuit, set both of the flags to FALSE by default. Toggle m_bFormDisplayed to True when the form is displayed on the screen. Set m_bOkToQuit to TRUE only when the user requests the form to close (by using Microsoft Foundation Classes, this might be in response to an OnOK or OnCancel call).

If these flags are maintained properly, the following code, placed at the top of ShutdownForm, prevents the form from shutting down prematurely:

if (m_bFormDisplayed && !m_bOkToQuit) //Don't go through with the shutdown return hRes;



STATUS
This behavior is by design.

