IOleObject::Close

Windows Mobile 6.5
A version of this page is also available for
4/8/2010

This method changes an embedded object from the running to the loaded state. It also disconnects a linked object from its link source.


HRESULT Close( 
  DWORD dwSaveOption
);

dwSaveOption

[in] Specifies whether the object is to be saved as part of the transition to the loaded state.

Valid values are taken from the enumeration OLECLOSE.

If the object closed successfully, the return value is S_OK.

If the user was prompted to save but chose the Cancel button from the prompt message box, the return value is OLE_E_PROMPTSAVECANCELLED.

The OLE 2 user model recommends that object applications do not prompt users before saving linked or embedded objects, including those activated in place.

This policy represents a change from the OLE 1 user model, in which object applications always prompt the user to decide whether to save changes.

To determine whether the platform supports this interface, see Determining Supported COM APIs.

A container application calls Close when it wants to move the object from a running to a loaded state. Following such a call, the object appears in its container but is not open for editing. Calling Close on an object that is loaded but not running has no effect. Closing a linked object simply means disconnecting it.

Upon receiving a call to Close, a running object should do the following:

  • If the object has been changed since it was last opened for editing, it should request to be saved, or not, according to instructions specified in dwSaveOption. If the option is to save the object, it should call its container's IOleClientSite::SaveObject interface.
  • If the object has IDataObject::DAdvise connections with ADVF_DATAONSTOP flags, it should send an OnDataChange notification.
  • If the object owns the Clipboard, it should empty it by calling OleFlushClipboard.
  • If the object is visible, notify its container by calling IOleClientSite::OnShowWindow with the fshow parameter set to FALSE.
  • Send IAdviseSink::OnClose notifications to appropriate advise sinks.
  • Forcibly cut off all remote clients by calling CoDisconnectObject.

If the object application is a local server (an EXE rather than a DLL), closing the object should also shut down the object application unless the latter is supporting other running objects or has another reason to remain in the running state. Such reasons might include the following:

  • The presence of IClassFactory::LockServer locks
  • User control of the application
  • The existence of other open documents requiring access to the application

Calling Close on a linked object disconnects it from, but does not shut down, its source application.

A source application that is visible to the user when the object is closed remains visible and running after the disconnection and does not send an OnClose notification to the link container.

HeaderOleidl.h, oleidl.idl
Libraryoleaut32.lib, uuid.lib
Windows Embedded CEWindows CE 2.0 and later
Windows MobileWindows Mobile Version 5.0 and later

Community Additions

Show: