PRB: Custom MAPI Form Closes Unexpectedly (252625)



The information in this article applies to:

  • Microsoft Outlook 2000
  • Microsoft Outlook 98
  • Microsoft Outlook 97 8.0
  • Microsoft Outlook 97 8.01
  • Microsoft Outlook 97 8.02
  • Microsoft Outlook 97 8.03

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.

REFERENCES

Please see the Platform SDK section of MSDN for detailed description of MAPI Forms and the Custom Verb mechanisms. For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

246524 SAMPLE: FormServer Implements a C++ MAPI Form with IDispatch


Modification Type:MinorLast Reviewed:3/4/2004
Keywords:kbMsg kbprb KB252625