This documentation is archived and is not being maintained.


Windows allows several copies of the same program to run at the same time.

virtual BOOL InitInstance( );

Return Value

Nonzero if initialization is successful; otherwise 0.


Application initialization is conceptually divided into two sections: one-time application initialization that is done the first time the program runs, and instance initialization that runs each time a copy of the program runs, including the first time. The framework's implementation of WinMain calls this function.

Override InitInstance to initialize each new instance of your application running under Windows. Typically, you override InitInstance to construct your main window object and set the CWinThread::m_pMainWnd data member to point to that window. For more information on overriding this member function, see CWinApp: The Application Class.


// AppWizard implements the InitInstance overridable function 
// according to options you select.  For example, the single document
// interface (SDI) option was chosen for the AppWizard code created
// below. You can add other per-instance initializations to the code
// created by AppWizard.

BOOL CMyApp::InitInstance()
   // Standard initialization
   // If you are not using these features and wish to reduce the size
   //  of your final executable, you should remove from the following
   //  the specific initialization routines you do not need.

   LoadStdProfileSettings();  // Load standard INI file options (including MRU)

   // Register the application's document templates.  Document templates
   //  serve as the connection between documents, frame windows and views.

   CSingleDocTemplate* pDocTemplate;
   pDocTemplate = new CSingleDocTemplate(
      RUNTIME_CLASS(CMainFrame),     // main SDI frame window

   // create a new (empty) document

   if (m_lpCmdLine[0] != '\0')
      // TODO: add command line processing here

   return TRUE;

See Also

CWinApp Overview | Class Members | Hierarchy Chart