Last modified: July 23, 2011

Applies to: Outlook

Closes the form.

HRESULT ShutdownForm(
  ULONG ulSaveOptions


[in] A value that controls how or whether data in the form is saved before the form is closed. One of the following flags can be set:


Form data should not be saved.


The user should be prompted to save any changed data in the form.


Form data should be saved if it has changed since the last save. If no user interface is being displayed, the form can optionally switch to using the functionality for the SAVEOPTS_NOSAVE option.


The form was closed.


The form was already closed by a prior call to ShutdownForm.

Form viewers call the IMAPIForm::ShutdownForm method to close a form.

Perform the following tasks in your implementation of ShutdownForm:

  1. Check that a viewer has not already called ShutdownForm, and return E_UNEXPECTED if it has. Although this is unlikely, you should check.

  2. Call your form's IUnknown::AddRef method so that storage for the form and any internal data structures remain available until processing is finished.

  3. Determine whether there are any unsaved changes to the form's data. Save unsaved data according to how the ulSaveOptions parameter is set by calling your viewer's IMAPIMessageSite::SaveMessage method.

  4. Destroy your form's user interface window.

  5. Release your form's message and message site objects by calling their IUnknown::Release methods.

  6. Notify all registered viewers of the pending shutdown by calling their IMAPIViewAdviseSink::OnShutdown methods.

  7. Call the IMAPIViewContext::SetAdviseSink method to cancel your form's registration for notification by setting the advise sink pointer to null.

  8. Call the MAPIFreeBuffer function to free the memory for your form's properties.

  9. Call your form's IUnknown::Release method, matching the AddRef call made in step 2.

  10. Return S_OK.

Note Note

After these actions have been completed, the only valid methods on the form object that may be called are those from the IUnknown interface.

When ShutdownForm returns, regardless of whether it returns an error, release the form by calling its IUnknown::Release method. You can safely ignore any errors returned by ShutdownForm.