VC2008中AfxGetMainWnd函数的变化

今天把一个VC6的旧项目转为VC2008项目,运行后程序挂掉。中断后发现程序挂在工作线程中调用AfxGetMainWnd后,因为AfxGetMainWnd返回了NULL指针,随后导致非法访问。

 

查看MSDN,发现如下描述:

 

If AfxGetMainWnd is called from the application's primary thread, it returns the application's main window according to the above rules. If the function is called from a secondary thread in the application, the function returns the main window associated with the thread that made the call.

 

 

AfxGetMainWnd函数在主线程下,返回主窗口指针。在其它线程下,返回当前线程的窗口指针。因为我是在工作线程下调用的AfxGetMainWnd函数,该线程没有创建窗口,所以使该函数返回空指针。

 

之前使用VC6的时候,在不管在任何线程下AfxGetMainWnd都是返回主窗口的指针。因为一直使用VC6,不知道微软什么时候更改了这个函数的实现。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值