AfxGetThread()函数返回空指针是怎么回事?
疯癫小程序 2012-06-23 08:32:34 我写的是一个简单的MFC Dialog程序,编译没有错误,然后在调试启动窗口的时候,运行到下面大号字体的时候就出现了未处理的异常,查了下原因是应为pThread这个指针为空,看看下面的红色代码CWinThread* pThread = AfxGetThread();知道了AfxGetThread函数居然返回的是空指针,请教各位英雄,这究竟是怎么回事啊,希望指点下,不胜感激。
int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
_In_ 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)
{
TRACE(traceAppMsg, 0, "Warning: Destroying non-NULL m_pMainWnd\n");
pThread->m_pMainWnd->DestroyWindow();
}
nReturnCode = pThread->ExitInstance();
goto InitFailure;
}
nReturnCode = pThread->Run();