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();
...全文
924 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
QSDWHD 2014-03-11
  • 打赏
  • 举报
回复
楼主,我和你碰到一样的问题了,这个theApp的定义文件你有吗,可以发给我吗,这个theApp定义文件加在什么地方?谢谢
疯癫小程序 2012-06-25
  • 打赏
  • 举报
回复
找到原因了,是因为我不小心删除了 theAPP定义的文件,加上就好了。。。谢谢各位,结贴了。。。
hurryboylqs 2012-06-23
  • 打赏
  • 举报
回复
看调用栈,这个崩溃之前执行什么代码了
ningto.com 2012-06-23
  • 打赏
  • 举报
回复
AfxGetThread returns NULL if no thread was found. If you want the application thread, you must call AfxGetApp.
疯癫小程序 2012-06-23
  • 打赏
  • 举报
回复
英雄都睡觉去了么?

15,980

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧