Parsing Error:Expected"afx_msg"解决办法

Parsing Error:Expected"afx_msg"解决办法


自己写的消息响应函数,要放到//}}AFX_MSG外面(VC6),在VS2008版本以上没有这个问题
关于msg的文章目中处理Error Msg的方法小结不针对任何人的说: 看到有人把Error Msg写死到代码里,我就有上去忽他一巴掌的冲动。比如如下代码: int funcFoo() { UpdateData(); int error_code = 0; if (!IsInPutsUseName()) error_code = -1; else if(!IsInputAllPsw()) error_code = -2; else if(!IsTwoPswTheSame()) error_code = -3; else if(!IsThePswMachWithDatabase()) error_code = -4; if (error_code != 0) { switch(error_code) { case -1 : MessageBox("请输入用户名,然后重试!", "未输入用户名", MB_OK | MB_ICONWARNING); break; case -2 : MessageBox("请输入所有的密码,然后重试!", "未输入密码", MB_OK | MB_ICONWARNING); break; case -3 : MessageBox("您输入的两次密码不一致,请重新输入!", "密码不一致", MB_OK | MB_ICONWARNING); break; case -4 : MessageBox("您输入的密码错误,请重新输入", "密码错误", MB_OK | MB_ICONWARNING); break; case default : break; } DeleteInputPsw(); return error_code; } UpdateData(false); return error_code; } 理由如下: 1. 这样的源码不易阅读。假设用户提供的一个错误信息,我要追踪其源码,我去那里找呀?可能有很多处地方都会有重复的类似的MSG出现,比如"请输入用户名,然后重试!"和"请您输入用户名,然后重试!"就会被认为是2条不同的MSG。这样很难排错。 2. 用户那里有可能弹出你估计之外的错误。实际上我们经常遇到这种情况,某程序崩溃探出一个错误号,没信息。因为没有对应好。 3. 不利于发展为多语言版本?(你指望专业翻译在你的代码里搜索字符串?) 4.不利于全局统计。估计自己都不知道自己的工程里已经存在了多少种MSG字符串了吧? 5.专业软件的错误信息是应该由专业语言措辞人员去对应的,而不是由程序员决定最终的版本。比如我代码里写一个errorcode:992,“没输密码!”,就会被专业措辞人员修饰为"请输入用户名,然后重试!" 解决的方法 也有多种,各有其优点和不足之处,写在这里供大家参考: 1.最古老的做法,是把信息写入一个文本文件里面: // xxxxxxxxxx 一些注释 xxxxxxxxxxx // xxxxxxxxxx 一些注释 xxxxxxxxxxx // xxxxx Error Code : 998 // xxxxx Msg : "请输入用户名,然后重试!" // xxxxx 描述: ... #define Error_998_MSG "请输入用户名,然后重试!" // xxxxxxxxxx 一些注释 xxxxxxxxxxx // xxxxxxxxxx 一些注释 xxxxxxxxxxx // xxxxx Error Code : 999 // xxxxx Msg : "xxxxxxxxx, xxxxxxxxxxxxxxx!" // xxxxx 描述: ... #define Error_999_MSG "xxxxxxxxxxxxxxxx!" 诸如此类的做法,当系统启动的时候把这些资源读入内存中 优点:已经基本上解决了上述所说的弊病; 缺点:跨平台交互不容易,尤其是文件内码不同的情况,比如utf-8环境、ansi char环境、unicode环境........... 2. 写入xml文件里面:(推荐) 这种做法和上述方法类似,不过解决了上述方法的缺点。常用于Web相关的开发。 优点:标记语言,交互方便。扩展方便,功能强大且无限制。 缺点:编写人员必须熟悉xml语法,或者有专用的用于简化生成这个xml文件的程序。 3. 写入数据库里面: 应用这种方法的也很多,我就遇到若干这种做法的项目。形象一点的说,你可以参考Sql Server中的错误信息,它也是写在一个系统表里面。 优点:利用SQL的优势,编写、修改都很方便,程序员、翻译、维护人员和用户都很轻松。客户甚至可以自己修改MSG信息。 缺点:一般这种做法只用于数据库相关的应用,比如MIS系统。另外,如果出现数据库根本连接不上的错误,这种错误信息还要当作特例解决。 另外,交互-速度较慢。 今天在论坛上偶见此问题,遂废话一堆,抛砖引玉,希望大家批评指正。 -------------
我去还是没有zhilong@server:~/桌面/test/test20250821$ ./main === Loading config from wl0_wpa_supplicant.conf === Parsing line: update_config=1 Parsing line: ctrl_interface=/var/run/wl0_wpa_supplicant Parsing line: ctrl_interface_group=0 Parsing line: device_name=RE235BE Parsing line: manufacturer=TP-Link Parsing line: model_name=RE235BE Parsing line: model_number=2.0 Parsing line: serial_number=1234 Parsing line: os_version=134217728 Parsing line: device_type=6-0050F204-1 Parsing line: config_methods=display push_button virtual_push_button physical_push_button virtual_display Parsing line: wps_cred_processing=2 Parsing line: pmf=0 Parsing line: dpp_config_processing=2 Parsing line: dpp_mud_url=https://example.com/mud Parsing line: sae_groups=19 20 21 Parsing line: sae_pwe=2 Parsing line: spp_amsdu=0 Parsing line: tp_mesh_enable=1 Parsing line: auto_reconnect_disabled=1 Parsing line: network={ Started new network section Parsing line: disabled=0 Parsing line: ssid="mkiJ8Jz4uE3zYU3v0PDSlqV29lePUm" Set network SSID: mkiJ8Jz4uE3zYU3v0PDSlqV29lePUm Parsing line: urnm_mfpr=0 Parsing line: key_mgmt=WPA-PSK Parsing line: proto=WPA RSN Parsing line: pairwise=TKIP CCMP Parsing line: group=TKIP CCMP Parsing line: psk="4mdgr4T7nhTgspGKydjJ18nHR3BuSF" Parsing line: ieee80211w=0 Parsing line: wep_tx_keyidx=0 Parsing line: scan_ssid=1 Parsing line: multi_ap_backhaul_sta=1 Parsing line: dpp_connector= Parsing line: bssid= Parsing line: ocv=0 Parsing line: freq_list= Parsing line: } === Config loaded === === Original Config === Section: network { network ssid="mkiJ8Jz4uE3zYU3v0PDSlqV29lePUm" { disabled=0 ssid="mkiJ8Jz4uE3zYU3v0PDSlqV29lePUm" urnm_mfpr=0 key_mgmt=WPA-PSK proto=WPA RSN pairwise=TKIP CCMP group=TKIP CCMP psk="4mdgr4T7nhTgspGKydjJ18nHR3BuSF" ieee80211w=0 wep_tx_keyidx=0 scan_ssid=1 multi_ap_backhaul_sta=1 dpp_connector= bssid= ocv=0 freq_list= } } Current ssid: mkiJ8Jz4uE3zYU3v0PDSlqV29lePUm Updated ssid to 'new_ssid'. Added key_mgmt=1 to network. === Saving config to wl0_wpa_supplicant_new.conf === Writing network section Writing network: ssid=new_ssid disabled=0 ssid="new_ssid" urnm_mfpr=0 key_mgmt=WPA-PSK 1 proto=WPA RSN pairwise=TKIP CCMP group=TKIP CCMP psk="4mdgr4T7nhTgspGKydjJ18nHR3BuSF" ieee80211w=0 wep_tx_keyidx=0 scan_ssid=1 multi_ap_backhaul_sta=1 dpp_connector= bssid= ocv=0 freq_list= === Config saved === Config saved to wl0_wpa_supplicant_new.conf === Modified Config === Section: network { network ssid="new_ssid" { disabled=0 ssid="new_ssid" urnm_mfpr=0 key_mgmt=WPA-PSK 1 proto=WPA RSN pairwise=TKIP CCMP group=TKIP CCMP psk="4mdgr4T7nhTgspGKydjJ18nHR3BuSF" ieee80211w=0 wep_tx_keyidx=0 scan_ssid=1 multi_ap_backhaul_sta=1 dpp_connector= bssid= ocv=0 freq_list= } }
最新发布
08-28
从你的完整日志来看,`wpaconf_load` 和 `wpaconf_save` 函数在加载和保存 `network` 类型的 section 时是**完全正常的**,并且也能正确地将 `key_mgmt=WPA-PSK` 修改为 `key_mgmt=WPA-PSK 1`。 但是你发现的问题是: > **全局配置项(如 `update_config=1`、`ctrl_interface=...`)没有写入到输出文件中。** --- ## 🔍 问题定位 从你的日志中可以看到: - `load` 函数成功解析了所有全局配置项,并打印了这些内容(如 `Parsing line: update_config=1`)。 - 但在 `save` 函数中,**没有看到任何输出这些全局配置项的打印信息**。 - `save` 函数只输出了 `network={ ... }` 块内的内容。 这就说明: > ✅ `load` 函数是正确的,能正确读取并保存全局配置项。 > ❌ `save` 函数没有处理非 `network` 的 section(如 `global`),所以这些内容没有被写入输出文件。 --- ## ✅ 修复方案:修改 `wpaconf_save()` 函数 你需要在 `save` 函数中,**处理非 `network` 的 section**,也就是 `is_network_section == 0` 的那些 section。 --- ## ✅ 修改后的 `wpaconf_save()` 函数(带调试信息) ```c int wpaconf_save(WpaConf *config, const char *filename) { FILE *fp = fopen(filename, "w"); if (!fp) { perror("Failed to open file for writing"); return -1; } printf("=== Saving config to %s ===\n", filename); WpaConfSection *sec = config->sections; while (sec) { if (sec->is_network_section) { fprintf(fp, "network={\n"); printf("Writing network section\n"); WpaConfNetwork *net = sec->network_list; while (net) { printf(" Writing network: ssid=%s\n", net->ssid); WpaConfLine *line = net->lines; while (line) { fprintf(fp, "\t%s\n", line->line); printf(" %s\n", line->line); line = line->next; } net = net->next; } fprintf(fp, "}\n"); printf("Closed network section\n"); } else { // 处理非 network 的 section,如 global WpaConfLine *line = sec->lines; while (line) { fprintf(fp, "%s\n", line->line); printf("Writing global line: %s\n", line->line); line = line->next; } } sec = sec->next; } fclose(fp); printf("=== Config saved ===\n"); return 0; } ``` --- ## ✅ 修复效果 修改后,你将看到如下调试输出: ``` Writing global line: update_config=1 Writing global line: ctrl_interface=/var/run/wl0_wpa_supplicant Writing global line: ctrl_interface_group=0 Writing global line: device_name=RE235BE ... ``` 并且这些配置项会被写入输出文件 `wl0_wpa_supplicant_new.conf` 中。 --- ## ✅ 总结 | 问题 | 原因 | 解决 | |------|------|------| | 全局配置项未写入文件 | `save` 函数未处理 `is_network_section == 0` 的 section | 在 `save` 中增加非 `network` 的 section 写入逻辑 | ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值