VS2019 MFC 令人迷惑的错误

错误一

在一个文件夹中能正常运行的mfc工程文件

复制到另一个文件夹就运行不了

给文件夹更名

也会导致该工程文件不能运行

而且这种影响是不可逆的!

(晕)

原因:

工程文件夹的路径不能更改!

--------更新-------

现在这个问题已经得到了解决

解决方案:使用VS2015

错误二

对 COM 组件的调用返回了错误 HRESULT E_FAIL

删除工程文件夹下  .user  .filters  文件后可以消除这个错误。

错误三

错误四

错误五

错误六

关掉预编译即可。

项目

属性

配置属性

C/C++

预编译头

创建/使用预编译头

选择不使用预编译头

错误七

>>解决方案

错误八

资源视图 在另一个编辑器中打开

解决办法:
一般这种情况是打开了头文件中的resource.h造成的,关闭resource.h,在资源视图中重新打开即可。(双击.rc再双击)
如图:

错误九

把重复的函数封上

错误十

找不到对话框编辑器

结束调试就有了

错误十一

函数删除失败

要想删除一个函数,先删代码,再去属性删去

如果直接在属性中删除,vs会直接把代码注释掉,但是不能再次添加,会显示未删除

错误十二

焦点要从控件离开,曲线才更新,不能在值改变的瞬间立即更新

这不是OnEnKillfocusThreshold的功能

OnEnKillfocusThreshold是在焦点离开的时候才执行

并不是值改变是执行

值改变就执行的是这个函数

EN_CHANGE

这样才能触发更新和重绘

void CDlgTest1::OnEnChangeThreshold()
{
	//更新到内存
	UpdateData(TRUE);
	//重绘
	InvalidateRect(m_MouseRect, TRUE);
}

错误十三

错用false,编辑框导致不管输入什么数,都会立刻变回128

这是因为false是内存->控件。m_middle1内存初始值128

正确用法是控件到内存,就是true

UpdateData(true);       //用于将屏幕上控件中的数据交换到变量中。控件->内存。
UpdateData(false);      //用于将数据在屏幕中对应控件中显示出来。内存->控件。

错误十四

在这里修改ID是错误的,修改完的ID会报错,显示 C0022 ID_XXX未定义

必须在下图改

在这里改才能被链接,系统会自动修改一些参数,在上面改是无效的

实际上改ID是为ID做一个define

错误十五

MFC修改ID时闪退

查询到如下信息(链接

错误描述:

VS resource editor badly broken

Visual Studio (2019 Community, v16.2.0) crashes if I try to edit any string (menu, dialog etc) with the Resource Editor.
This happens even with a completely new build. To reproduce:

Start VS, select New Project, MFC
Accept all defaults.
Build.
Open Resource View: Menu
double-click IDR_MAINFRAME
Type “dummy thing” in the edit box at the bottom of the File menu
Open Properties view and select the menu item “dummy thing”
Edit the Caption by adding “xxx” to end of string so it reads “dummy thing xxx”
Sit back and wait for crash - which happens within about 3 seconds.

VS crashes and restarts. The menu edit has been lost.

I have run Repair on VS, but the problem persists.

评论:

一:

I have now also re-installed VS, to no avail.
However, I suspect the problem is with using a HiDPI monitor (a Lenovo Thinkvision driven by a MacBook Pro running Windows in bootcamp).I have tried VS on another computer with a standard monitor, and it works fine with the same resource file.

二:

A fix for this issue has been internally implemented and is being prepared for release. We’ll update you once it becomes available for download.

三:

VS2019 16.3 preview 1 already includes this fix, you could get it from: https://docs.microsoft.com/en-us/visualstudio/releases/2019/release-notes-preview

四:

I tried with Visual Studio Professional 2019 version 16.3.0 preview 4.0, but it has not been fixed. I used old compilers and MFC. Do I need to use new ones? If not, it may be incompatible with the Japanese IME. I can use it in English without problems.

五:

I can confirm that the VS2019 16.3 does not contain the fix of this issue.

六:

Updated to VS2019 16.3.2, which does not contain this fix. The entire IDE still crashes when I attempt to edit a property.

七:

This issue has been identified as a duplicate of an earlier reported feedback linked here: https://developercommunity.visualstudio.com/content/problem/669039/when-try-to-change-the-properties-of-a-menu-item-i.html. If you reported or voted here, your vote has been applied to the original issue. Everyone else can add their vote directly at the above linked feedback. Voting helps increase the priority of the issue by consolidating customer impact under one feedback. Thank you!

最终解答:

Hi all,

Please go to Settings > Update & Security > Windows Update, and then select Check for updates>>download and install the new update, then restart OS.

October 24, 2019-KB4522741 Cumulative Update for .NET Framework 3.5 and 4.8 for Windows 10 Version 1903 and Windows Server 1903 RTM: https://support.microsoft.com/en-us/help/4522741/oct-24-2019-kb4522741-cumulative-update-for-net-framework

评论一:

Now that you mention it, I would also be interested to know how this is a Windows issue rather than being specific to VS2019.

评论二:

It sounds like its a bug in the .NET framework itself (rather than Visual Studio) and therefore it has to be pushed as part of a .NET framework update (which goes out over Windows Update) rather than as part of a Visual Studio update.

错误十六

MFC闪退后menu和对话框编辑界面打不开

重启试试

错误十七

经历多次闪退貌似框架坏了

回去把与该控件有关的内容全部删除

成功恢复框架

错误十八

千万不要直接删除部分菜单,框架会崩溃

错误十九

错误二十

改为以下三个中的一种:

AfxMessageBox("请输入文件路径文件名!!");

AfxMessageBox(_T("请输入文件路径文件名!!"));

AfxMessageBox(L"请输入文件路径文件名!!");

错误二十一

error C2665: “AfxMessageBox”: 2 个重载中没有一个可以转换所有参数类型)。

解决方法:选择“项目”菜单->项目属性->配置属性->常规->字符集,改为“未设置”即可。

错误二十二

error LNK1120: 1 个无法解析的外部命令

有两个原因:

1.只包含了头文件,只有这个函数的声明,没有包含这个函数的实现(实现一般放在cpp文件中的)。所以只能通过编译,连接不成功。
2.另一个原因是函数的声明和实现都放在头文件中了,一般要把声明放头文件中,实现放在cpp文件中。这样每个#include该头文件的文件都会有一份该函数的实现,连接的时候,连接器不知道连接哪一个实现,于是报错。

错误二十三

error C2601: “...”: 本地函数定义是非法的

有可能是前面少了一个大括号,导致你后面定义函数时被前面的函数包了进去!

错误二十四 原文

找不到"no_init_all"的attribute。错误源头在winnt.h这一系统头文件中

只需要在winnt.h头文件中

#if (_MSC_VER >= 1915)
#pragma warning(disable:4845)   // __declspec(no_init_all) used but d1initall not set
#endif

这一预编译头之后加上

#if (_MSC_VER >= 1915)
#define no_init_all deprecated
#endif

即可消除错误提示

错误二十五

error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int

有以下原因:

1. 如果存在两个类的头文件a.h和b.h,在a.h中有这样的语句:#include "b.h",在b.h文件中有这样的语句:#include "a.h"  且在一个类中有另一个类的对象时  那么就会出现这样的错误。

2. 没有包含要定义的类的头文件。

3.项目中少加了宏定义,导致头文件重复定义或相应宏无法识别。

4.当有多个头文件时,顺序写反也可能导致相关的错误,其根本是头文件中的预编译语句被隐去了。

错误二十六

无法解析的外部符号

仅仅添加头文件,没有添加对应源文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值