5.9 Closing a Client Application

Before a client application closes a document and terminates itself, it should:

Call OleQueryOpen to see if any of the document's objects are open in the server application.

Call OleUpdate once for each opened object. OleUpdate obtains the current presentation format for the opened object.

Call OleRelease once for each object. OleRelease closes the object if it is open, and tells the library to release any memory associated with the object. Closing an object terminates all DDE conversations with the object's server. OleRelease must be called for all objects, since it tells the library to release memory. Conveniently, OleRelease will also close an object if it is currently open in the server application.

Call OleRevokeClientDoc to notify the client and server DLLs that the document is closed and no longer available. OleRevokeClientDoc takes as its parameter the handle to the document provided by a call to OleRegisterClientDoc.

A client application should call the OleRelease function for each object in the document to remove all objects from memory when it shuts down. If the client DLL returns OLE_WAIT_FOR_RELEASE instead of OLE_OK, the client application should not quit. While waiting for the OLE_RELEASE notification, the client can perform many cleanup tasks —for example, it can close files, free memory, and hide windows.

The OLE_RELEASE notification to the client application's callback function indicates that an operation has finished in a server application, but it does not identify the operation or indicate whether the operation was successful. A client application can call the OleQueryReleaseStatus function to determine whether an operation has been completed for a specified object. The OleQueryRelease function indicates the nature of the operation that has finished for a specified object. To discover the error value for the operation, the client application can call the OleQueryReleaseError function.

If a client application owns the clipboard when it quits, it should make sure that the data on the clipboard is complete and in the correct order.