다음을 통해 공유


AfxOleLockApp

Increments the framework's global count of the number of active objects in the application.

void AFXAPI AfxOleLockApp( );

Remarks

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  Application Wizard-generated SDI 
// Application with Automation support. The Application Wizard 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.

CCMFCAutomationDoc::CCMFCAutomationDoc()
{
    EnableAutomation();
    AfxOleLockApp();
}

CCMFCAutomationDoc::~CCMFCAutomationDoc()
{
    AfxOleUnlockApp();
}

Requirements

Header: <afxdisp.h>

See Also

Concepts

MFC Macros and Globals

AfxOleUnlockApp

AfxOleCanExitApp

COleDocument Class