In MFC, why do I need to create a global instance of CWinApp?

Why should the constructor of my derived CWinApp be called before the main function starts?
Why can't it be something like:

int WinMain()
{
   CMainFrame* pMainFrame = new CMainFrame;
   // etc ...
}

I am looking for a technical reason that forces this behavior.
Edit:
To make it clearer - if I use the win32 API without MFC, the main window is created inside WinMain, so what's the difference?

+5
source share
1 answer

Basically, because the MFC designers decided to provide the entry point of the application ( WinMain () , not main()) in the library itself, so users would not have to write one.

InitInstance() ExitInstance() CWinApp - . WinMain(), ( Run() ) (, nCmdShow, ).

CWinApp -derived - WinMain().

, MFC.

+3

All Articles