Export (0) Print
Expand All
TRY
Expand Minimize
This topic has not yet been rated - Rate this topic

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.

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

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

Requirements

Header: <afxdisp.h>

See Also

MFC Macros and Globals | AfxOleUnlockApp | AfxOleCanExitApp | COleDocument

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.