void AFXAPI AfxOleLockApp( );
#include <afxdisp.h>
Remarks
Increments the framework’s global count of the number of active objects in the application.
The framework keeps a count of the number of objects active in an application. The AfxOleLockApp and AfxOleUnlockApp functions, respectively, increment and decrement this count.
When the user attempts to close an application that has active objects — an application for which the count of active objects is nonzero — the framework hides the application from the user’s view instead of completely shutting it down. The AfxOleCanExitApp function indicates whether the application can terminate.
Call AfxOleLockApp from any object that exposes OLE interfaces, if it would be undesirable for that object to be destroyed while still being used by a client application. Also call AfxOleUnlockApp in the destructor of any object that calls AfxOleLockApp in the constructor. By default, COleDocument (and derived classes) automatically lock and unlock the application.
Example
// Below is a code sample from an AppWizard-generated SDI Application
// with Automation support. The AppWizard adds a dispatch
// interface to the document class. AfxOleLockApp() and
// AfxOleUnlockApp() respectively increment and decrement the
// application's object count. When the object count is equal to
// zero and if the user has not taken control of the application,
// the server is terminated.
CTestDoc::CTestDoc()
{
EnableAutomation();
AfxOleLockApp();
}
CTestDoc::~CTestDoc()
{
AfxOleUnlockApp();
}
See Also AfxOleUnlockApp, AfxOleCanExitApp, COleDocument