AfxWinMain中pThread->InitInstance()出错的解决方法
2014-05-10 10:00
429 查看
最近在写程序时,在Debug下能正常运行,但是换到Release下就报一个中断错误:“0x71ea1cbc(mfc100.dll) 处未处理的异常: 0xC0000005: 读取位置 0x00000000 时发生访问冲突”,并且,错误箭头指到了winmain.cpp文件中AfxWinMain函数内的if (!pThread->InitInstance())语句,经过分析是pThread为NULL,这就让我搞不清楚了,都没有进入我程序中的main函数,怎么会报这个错误呢。而且,我发现导致这个错误的原因是我加入了一个头文件#include<afx.h>导致的。就在网上找资料,还是stackoverflow比较牛叉啊,通过【http://stackoverflow.com/questions/20242974/mfc-application-crash-immediately-after-start】,内容如下:
If I understand the question correctly, you've created an empty project and just added these lines of code to a new cpp file.
If you want to use Afx support, or MFC, you need to state that when you create the project. I suggest you let the IDE create a non-empty project, check that builds
and runs, then start adding code to it.
be initialised by the framework for you - if you allow it to automatically generate the supoorting code for you. From memory, at very least it creates a global (arggg) variable called
type
which will initialise things it needs, like threads.
Go back through (the sample of) the book very carefully and follow all the instructions. If that doesn't work, get a better book. Or buy the whole book. Or work through the tutorials on
the msdn.
看过以后,发现是我建的工程不适合用#include<afx.h>,因为我建的Qt的工程(控制台程序也是如此),没有在建工程时没有设置为MFC类型,就没有提前初始化pThread(它是在建project时自动初始化的)。
另外,类似的错误及解决方法可参考:
http://bbs.csdn.net/topics/390349358
由于本人对MFC不熟悉,就不想再重新建一个MFC工程了,想继续在Qt工程中运行,怎么办呢?因为我用到了CString,所以才引入了头文件#include<afx.h>,后来在网上看到,可以用 ATL,#inlcude <atlstr.h>,就可以用CString了。(Win32 Application不能包含MFC,如果要用CString,也可以这么做)
另外,TRACE在MFC支持程序里用,不能在WIN32 Application程序里用;TRACE使用的是AfxTrace对象,这个对象只有在支持MFC的程序才有;
OutputDebugString("这个好用啊");TRACE是MFC中的定义,在win32代码中可以直接用OutputDebugString来达到相同效果。
OK,问题到此就解决了。我觉得能不用#include<afx.h>的时候,尽量别用。用了以后,会带来很多问题。
==================================================
另外,VC中Debug正常,Release异常的解决方法可参考:
http://blog.csdn.net/Tony_Jas/article/details/5875083 http://blog.csdn.net/frankiewang008/article/details/8021411
If I understand the question correctly, you've created an empty project and just added these lines of code to a new cpp file.
If you want to use Afx support, or MFC, you need to state that when you create the project. I suggest you let the IDE create a non-empty project, check that builds
and runs, then start adding code to it.
pthreadshould
be initialised by the framework for you - if you allow it to automatically generate the supoorting code for you. From memory, at very least it creates a global (arggg) variable called
theAppof
type
CWinApp,
which will initialise things it needs, like threads.
Go back through (the sample of) the book very carefully and follow all the instructions. If that doesn't work, get a better book. Or buy the whole book. Or work through the tutorials on
the msdn.
看过以后,发现是我建的工程不适合用#include<afx.h>,因为我建的Qt的工程(控制台程序也是如此),没有在建工程时没有设置为MFC类型,就没有提前初始化pThread(它是在建project时自动初始化的)。
另外,类似的错误及解决方法可参考:
http://bbs.csdn.net/topics/390349358
由于本人对MFC不熟悉,就不想再重新建一个MFC工程了,想继续在Qt工程中运行,怎么办呢?因为我用到了CString,所以才引入了头文件#include<afx.h>,后来在网上看到,可以用 ATL,#inlcude <atlstr.h>,就可以用CString了。(Win32 Application不能包含MFC,如果要用CString,也可以这么做)
另外,TRACE在MFC支持程序里用,不能在WIN32 Application程序里用;TRACE使用的是AfxTrace对象,这个对象只有在支持MFC的程序才有;
OutputDebugString("这个好用啊");TRACE是MFC中的定义,在win32代码中可以直接用OutputDebugString来达到相同效果。
OK,问题到此就解决了。我觉得能不用#include<afx.h>的时候,尽量别用。用了以后,会带来很多问题。
==================================================
另外,VC中Debug正常,Release异常的解决方法可参考:
http://blog.csdn.net/Tony_Jas/article/details/5875083 http://blog.csdn.net/frankiewang008/article/details/8021411
相关文章推荐
- 使用jmail的时候避免无法发送的方法
- Failed to install helloworld.apk on device '????????????': adb rejected instal
- TGraphiControl响应WM_MOUSEMOVE的过程(以TPaintBox为例)
- oc 利用retain关键字自动管理内存
- UVA Matrix Chain Multiplication
- sleep和wait的区别
- HDU 4819 —— Mosaic(二维线段树)
- @property详解:nonatomic,retain
- apache-tomcat-7.0.53-windows-x86或者x64:出现错误提示:(Unable to open the service 'tomcat7)或者(Failed installing 'Tomcat7' service) tomcat7 %1 不是有效的 Win32 应用程序。
- no ip domain-lookup
- NewMail 对象(CDONTS 库)发送邮件
- SSH中“Host key verification failed.“的解决方案
- http://blog.csdn.net/hhhccckkk/article/details/9313999
- 'release' is unavailable: not available in automat
- 位图缩放和旋转main26
- Cairo-dock
- 今后这个博客不再更新,迁移至http://liujiacai.net/
- baiduK站的主要特征
- 关于通达Oa的一些问题,raid,论坛
- WARNING: Re-reading the partition table failed with error 16: Device or resource busy.