新建一个基于对话框的MFC程序,对话框上添加了RichEdit控件,编译成功后无法运行起来,Debug版本与Release版本均不行!
Windbg分析结果:
WARNING: Stack unwind information not available. Following frames may be wrong.
00 003df80c 76447a25 00000000 77e8f3b0 ffffffff ntdll!ZwTerminateProcess+0x12
*** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\Windows\WinSxS\x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.30729.1_none_bb1f6aa1308c35eb\MSVCR90D.dll -
01 003df820 6d40bf2b 00000000 003df87c 6d40bdb1 kernel32!ExitProcess+0x15
02 003df82c 6d40bdb1 00000000 b3cad0fa 00000000 MSVCR90D!amsg_exit+0x4db
03 003df87c 6d40b9e2 00000000 00000000 00000000 MSVCR90D!amsg_exit+0x361
*** WARNING: Unable to verify checksum for MfcRTLogMonitor.exe
04 003df890 002a3b26 00000000 b3c2e0a7 00000000 MSVCR90D!exit+0x12
05 003df934 002a386f 003df948 764433ca 7efde000 MfcRTLogMonitor!__tmainCRTStartup+0x2a6 [f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c @ 599]
06 003df93c 764433ca 7efde000 003df988 77b99ed2 MfcRTLogMonitor!wWinMainCRTStartup+0xf [f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c @ 403]
07 003df948 77b99ed2 7efde000 77fa2cb3 00000000 kernel32!BaseThreadInitThunk+0x12
08 003df988 77b99ea5 002a17fd 7efde000 00000000 ntdll!RtlInitializeExceptionChain+0x63
09 003df9a0 00000000 002a17fd 7efde000 00000000 ntdll!RtlInitializeExceptionChain+0x36
解决办法:
在应用程序类(App类)中的InitInstance函数体内添加以下语句:
AfxInitRichEdit(); 对应1.0版本
如果有2.0版本需要添加如下
AfxInitRichEdit2(); 对应2.0 版本
说明:
添加RichEdit控件后,在调用对话框函数DoModal()之前需要调用AfxInitRichEdit( )函数,对于一个工程中,只需要调用一次AfxInitRichEdit( )函数就可以初始化所有的RichEdit控件的基本信息,实际上只要在工程的初始化中调用一次就可以了。
参考:http://blog.csdn.net/qq_28098067/article/details/52253620