MFC框架的程序有入口函数吗?

MFC框架的程序有入口函数吗?,第1张

extern "C" int WINAPI

_tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,

LPTSTR lpCmdLine, int nCmdShow)

{

// call shared/exported WinMain

return AfxWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)

}

这个是MFC已经准备好直接由链接器加到应用程序中的,注:这里的_tWinMain是为了兼容Unicode制作的

#ifdef _UNICODE

#define _tWinMain wWinMain

#else

#define _tWinMain WinMain

#endif

而AfxWinMain

int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,

LPTSTR lpCmdLine, int nCmdShow)

{

ASSERT(hPrevInstance == NULL)

int nReturnCode = -1

CWinThread* pThread = AfxGetThread()

CWinApp* pApp = AfxGetApp()

// AFX internal initialization

if (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow))

goto InitFailure

// App global initializations (rare)

if (pApp != NULL &&!pApp->InitApplication())

goto InitFailure

// Perform specific initializations

if (!pThread->InitInstance())

{

if (pThread->m_pMainWnd != NULL)

{

TRACE0("Warning: Destroying non-NULL m_pMainWnd\n")

pThread->m_pMainWnd->DestroyWindow()

}

nReturnCode = pThread->ExitInstance()

goto InitFailure

}

nReturnCode = pThread->Run()

InitFailure:

#ifdef _DEBUG

// Check for missing AfxLockTempMap calls

if (AfxGetModuleThreadState()->m_nTempMapLock != 0)

{

TRACE1("Warning: Temp map lock count non-zero (%ld).\n",

AfxGetModuleThreadState()->m_nTempMapLock)

}

AfxLockTempMaps()

AfxUnlockTempMaps(-1)

#endif

AfxWinTerm()

return nReturnCode

}

你可以自己看源码,在vc安装目录的MFC源文件里,以上两个函数分别在APPMODUL.cpp和WINMAIN.cpp

里面。

MFC中程序的入口是WinMain函数,这是一个WINAPI函数,是在APPMODUL.CPP中定义的,这个文件在VC6.0的安装目录下。

你调试MFC程序时,点击Restart按钮(Ctrl+Shift+F5),就会进入该函数。

/////////////////////////////////////////////////////////////////////////////

//

export

WinMain

to

force

linkage

to

this

module

extern

int

AFXAPI

AfxWinMain(HINSTANCE

hInstance

,

HINSTANCE

hPrevInstance,

LPTSTR

lpCmdLine,

int

nCmdShow)

extern

"C"

int

WINAPI

_tWinMain(HINSTANCE

hInstance,

HINSTANCE

hPrevInstance,

LPTSTR

lpCmdLine,

int

nCmdShow)

{

//

call

shared/exported

WinMain

return

AfxWinMain(hInstance,

hPrevInstance,

lpCmdLine,

nCmdShow)

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12075996.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-20
下一篇 2023-05-20

发表评论

登录后才能评论

评论列表(0条)

保存