In MFC, how can WinMain function find user application object's address value?

Viewed 1545

Greeting, I'm novice in MFC area.

I have a question about process of starting MFC application.

I learned that unlike SDK program, I don't have to write WinMain. Because It is supplied by the class library and is called when the application starts up.* (See reference here : https://msdn.microsoft.com/en-us/library/akdx0603.aspx)

And my curious part is here: *Then CWinApp calls member functions of the application object to initialize and run the application.

That sentence indicates that CWinApp already know address value of application object which is made by a programmer.

However, even though application object is defined as global variable, how can WinMain function find application object's address value?

I couldn't find any connection or declaration in my sample MFC code which brings address value to the WinMain function.

#include <afxwin.h>

class CHelloApp : public CWinApp
{
public:
virtual BOOL InitInstance();
};

class CMainFrame : public CFrameWnd
{
public:
CMainFrame();
protected:
afx_msg void OnPaint();
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
DECLARE_MESSAGE_MAP()
};
CHelloApp theApp;

BOOL CHelloApp::InitInstance()
{
m_pMainWnd = new CMainFrame;
m_pMainWnd->ShowWindow(m_nCmdShow);
return TRUE;
}

CMainFrame::CMainFrame()
{
Create(NULL, "HelloMFC Application");
}


BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
1 Answers
Related