Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize


Indicates whether the application can terminate.

BOOL AFXAPI AfxOleCanExitApp( );

Return Value

Nonzero if the application can exit; otherwise 0.


An application should not terminate if there are outstanding references to its objects. The global functions AfxOleLockApp and AfxOleUnlockApp increment and decrement, respectively, a counter of references to the application's objects. The application should not terminate when this counter is nonzero. If the counter is nonzero, the application's main window is hidden (not destroyed) when the user chooses Close from the system menu or Exit from the File menu. The framework calls this function in CFrameWnd::OnClose.


// Helper exit function for automation server
BOOL CDlgautoDlg::CanExit()
   if (AfxOleCanExitApp())
      // No outstanding object counts - go ahead and exit
      return TRUE;
   } else
      // There are outstanding OLE object counts...
      // hide app to give user impression that application has exited.
      // take user out of control of the app
      return FALSE;


Header: <afxdisp.h>

See Also

MFC Macros and Globals | AfxOleLockApp | AfxOleUnlockApp

© 2015 Microsoft