VC8下多线程环境中AfxGetMainWnd()返回空指针问题及解决方法

一个vc6的项目放到vc8下重新编译 这里死活过不去 查了些资料无果 后来翻到一句老外的回答

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()返回的是和当前线程相关联的窗体句柄而不是当前程序的主窗体句柄。不知道这是不是vc8的一个改变,也没时间去细查。

解决方法1:
CWnd* m_pCWnd = NULL;
在OnInitDialog里 m_pCWnd = AfxGetMainWnd();

解决方法2:
调用AfxGetMainWnd()的地方替换成AfxGetApp()->m_pMainWnd

编译后运行问题解决

 

 

转自: http://www.freshbug.com/archives/84

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值