Fucked MFC RichEdit In Visual c++2010!

文章详细描述了在使用MFC进行编程时遇到的问题,特别是RichEdit控件未正确初始化导致的内存泄漏和程序崩溃。通过调整初始化函数的位置,最终解决了问题。同时讨论了微软产品在自动化支持方面的不足。

不知为何,个人感觉微软的东西越来越不好用了,今天用Visual 2010 开始写一个MFC程序,结果几乎是什么事情也没干,就花费掉了一个晚上去解决一个令人生烦、内心已经燃烧起了队MS产品的怒火发火……

是这样的,编写了一个MFC程序,才拖了几个控件到界面,然后就运行程序,结果发现编译、生成均没有报任何错,但是,运行是就出问题了,具体是,ctrl+F5运行的话,程序界面没有出来,什么反应也没有;如果F5调试运行的话,同样运行失败,提示信息如下:

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
“TempCtrl.exe”: 已加载“F:\TempCtrl_0\Debug\TempCtrl.exe”,已加载符号。
“TempCtrl.exe”: 已加载“C:\Windows\System32\ntdll.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Windows\System32\kernel32.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Windows\System32\KernelBase.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Windows\System32\user32.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Windows\System32\gdi32.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Windows\System32\lpk.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Windows\System32\usp10.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Windows\System32\msvcrt.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Windows\System32\msimg32.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Windows\System32\comdlg32.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Windows\System32\shlwapi.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7600.16661_none_420fe3fa2b8113bd\comctl32.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Windows\System32\shell32.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Windows\System32\winspool.drv”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Windows\System32\advapi32.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Windows\System32\sechost.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Windows\System32\rpcrt4.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Windows\System32\ole32.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Windows\System32\oleaut32.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Windows\System32\oledlg.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Windows\winsxs\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.7600.16385_none_72fc7cbf861225ca\GdiPlus.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Windows\System32\oleacc.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Windows\System32\imm32.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Windows\System32\msctf.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Windows\System32\winmm.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Program Files\Kaspersky Lab\Kaspersky Anti-Virus 6.0 for Windows Workstations MP4\adialhk.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Program Files\Kaspersky Lab\Kaspersky Anti-Virus 6.0 for Windows Workstations MP4\kloehk.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Windows\System32\uxtheme.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Windows\System32\dwmapi.dll”,Cannot find or open the PDB file
“TempCtrl.exe”: 已加载“C:\Windows\System32\cryptbase.dll”,Cannot find or open the PDB file
Detected memory leaks!
Dumping objects ->
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\occmgr.cpp(195) : {251} normal block at 0x022C7FF8, 192 bytes long.
 Data: <                > 02 00 00 00 00 00 00 00 FF FF FF FF 00 00 00 00 
{250} normal block at 0x022C7D50, 100 bytes long.
 Data: <                > FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 
Object dump complete.
线程 'Win32 线程' (0x594) 已退出,返回值为 0 (0x0)。
线程 'Win32 线程' (0x564) 已退出,返回值为 0 (0x0)。
程序“[4920] TempCtrl.exe: 本机”已退出,返回值为 0 (0x0)。
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------



感觉莫名奇妙,我的程序什么事情也没做(除了画界面,几乎就没遍码),怎么可能内存泄露,而且编译,生成都没提示错误!这就是visual studio垃圾的地方!

经过一晚上的折腾,后来知道错误在了,我的界面中用到了RichEdit2,使用RichEdit控件时,必须手工在初始化函数中加入对其的初始化函数:AfxInitRichEdit()或AfxInitRichEdit2();否则也会出现我上面说的同样的错误,而我当时把这个AfxInitRichEdit2()函数放在了界面窗口的初始化函数<CTempCtrlDlg::OnInitDialog()>中了,而不是放在整个程序的初始化函数<CTempCtrlApp::InitInstance()>中。结果就导致这样的悲剧了尴尬!!!

不知微软是怎么想的,既然用RichEdit2必须要初始化,为何不由MS MFC自动完成?还用用户自己去添加<这一问题,网络已牛人回答是:MFC向导不对你在创建项目之后增加的内容负责。程序员需要为自己增加的内容添加完整的支持,例如在使用richedit之前调用MFC的richedit初始化函数AfxInitRichEdit>
更要命的是,既然你都要求用RichEdit2必须要初始化,为何用户没有初始化,编译器检测不出? 这个检查应该不难吧?

关于这个问题,可能是我自己对MFC理解的很浅,但我个人总体感觉微软的东西越来越不好用!


解析代码: void avahi_server_generate_response(AvahiServer *s, AvahiInterface *i, AvahiDnsPacket *p, const AvahiAddress *a, uint16_t port, int legacy_unicast, int immediately) { assert(s); assert(i); assert(!legacy_unicast || (a && port > 0 && p)); if (legacy_unicast) { AvahiDnsPacket *reply; AvahiRecord *r; if (!(reply = avahi_dns_packet_new_reply(p, 512 + AVAHI_DNS_PACKET_EXTRA_SIZE /* unicast DNS maximum packet size is 512 */ , 1, 1))) return; /* OOM */ while ((r = avahi_record_list_next(s->record_list, NULL, NULL, NULL))) { append_aux_records_to_list(s, i, r, 0); if (avahi_dns_packet_append_record(reply, r, 0, 10)) avahi_dns_packet_inc_field(reply, AVAHI_DNS_FIELD_ANCOUNT); else { char *t = avahi_record_to_string(r); avahi_log_warn("Record [%s] not fitting in legacy unicast packet, dropping.", t); avahi_free(t); } avahi_record_unref(r); } if (avahi_dns_packet_get_field(reply, AVAHI_DNS_FIELD_ANCOUNT) != 0) avahi_interface_send_packet_unicast(i, reply, a, port); avahi_dns_packet_free(reply); } else { int unicast_response, flush_cache, auxiliary; AvahiDnsPacket *reply = NULL; AvahiRecord *r; /* In case the query packet was truncated never respond immediately, because known answer suppression records might be contained in later packets */ int tc = p && !!(avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_FLAGS) & AVAHI_DNS_FLAG_TC); while ((r = avahi_record_list_next(s->record_list, &flush_cache, &unicast_response, &auxiliary))) { int im = immediately; /* Only send the response immediately if it contains a * unique entry AND it is not in reply to a truncated * packet AND it is not an auxiliary record AND all other * responses for this record are unique too. */ if (flush_cache && !tc && !auxiliary && avahi_record_list_all_flush_cache(s->record_list)) im = 1; if (!avahi_interface_post_response(i, r, flush_cache, a, im) && unicast_response) { /* Due to some reasons the record has not been scheduled. * The client requested an unicast response in that * case. Therefore we prepare such a response */ append_aux_records_to_list(s, i, r, unicast_response); for (;;) { if (!reply) { assert(p); if (!(reply = avahi_dns_packet_new_reply(p, i->hardware->mtu, 0, 0))) break; /* OOM */ } if (avahi_dns_packet_append_record(reply, r, flush_cache, 0)) { /* Appending this record succeeded, so incremeant * the specific header field, and return to the caller */ avahi_dns_packet_inc_field(reply, AVAHI_DNS_FIELD_ANCOUNT); break; } if (avahi_dns_packet_get_field(reply, AVAHI_DNS_FIELD_ANCOUNT) == 0) { size_t size; /* The record is too large for one packet, so create a larger packet */ avahi_dns_packet_free(reply); size = avahi_record_get_estimate_size(r) + AVAHI_DNS_PACKET_HEADER_SIZE; if (!(reply = avahi_dns_packet_new_reply(p, size + AVAHI_DNS_PACKET_EXTRA_SIZE, 0, 1))) break; /* OOM */ if (avahi_dns_packet_append_record(reply, r, flush_cache, 0)) { /* Appending this record succeeded, so incremeant * the specific header field, and return to the caller */ avahi_dns_packet_inc_field(reply, AVAHI_DNS_FIELD_ANCOUNT); break; } else { /* We completely fucked up, there's * nothing we can do. The RR just doesn't * fit in. Let's ignore it. */ char *t; avahi_dns_packet_free(reply); reply = NULL; t = avahi_record_to_string(r); avahi_log_warn("Record [%s] too large, doesn't fit in any packet!", t); avahi_free(t); break; } } /* Appending the record didn't succeeed, so let's send this packet, and create a new one */ avahi_interface_send_packet_unicast(i, reply, a, port); avahi_dns_packet_free(reply); reply = NULL; } } avahi_record_unref(r); } if (reply) { if (avahi_dns_packet_get_field(reply, AVAHI_DNS_FIELD_ANCOUNT) != 0) avahi_interface_send_packet_unicast(i, reply, a, port); avahi_dns_packet_free(reply); } } avahi_record_list_flush(s->record_list); }
最新发布
09-20
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值