CXX.CWINAPP.INIT

Incorrect or missing InitInstance override for class derived from CWinApp.

When deriving an application class from CWinApp, one should override the InitInstance member function to create the application's main window object.

Vulnerability and risk

This will cause the following types of exceptions and not just EXE applications but also for regular DLLs dynamically linked to MFC:

Error code: (NTSTATUS) 0xc015000f (3222601743) - The activation context being deactivated is not the most recently activated one.

Error code: (NTSTATUS) 0xc0150010 (3222601744) - The activation context being deactivated is not active for the current thread of execution.

Error code: (NTSTATUS) 0xc0150014 (3222601748) - The activation context activation stack for the running thread of execution is corrupt.

Mitigation and prevention

Within the InitInstance function, you must disable the ambient activation context by invoking AfxSetAmbientActCtx(FALSE), or afxAmbientActCtx = FALSE, or AfxGetModuleState()->m_bSetAmbientActCtx = FALSE and this should be the first function invoked within InitInstance() to ensure it is done before initialization.

For any intermediate base classes, this rule can be safely ignored, but you should declare InitInstance() as a pure virtual or abstract method so that method then needs to be defined by any derived classes.

Example

Copy
class CMMF_ImageCaptureApp : public CWinApp;
               
CMMF_ImageCaptureApp theApp;

BOOL CMMF_ImageCaptureApp::InitInstance()
{
  BOOL stat = i18nSetResourceHandle();
  AfxSetAmbientActCtx(FALSE);
  return CWinApp::InitInstance();
}

Object initialization occurs before AfxSetAmbientActCtx set to false.