无法在 VC2010 Express 中打开包含文件‘ afxres.h’

我正在尝试使用 VS Express 2010编译一个旧项目,但是我得到了这个错误:

致命错误 RC1015: 无法从此代码打开包含文件‘ afxres.h’

/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

我已经安装了 WindowsSDK,但没有任何成功。

谢谢!

133712 次浏览

此标头是 MFC 库的一部分。VS Express 版本不包含 MFC。如果您的项目不使用 MFC,您可以安全地将 afxres.h替换为 terrain2.rc中的 windows.h

您还可以尝试用 WinResrc.h 替换 afxres.h

就连我也面临过类似的问题,

致命错误 RC1015: 无法从此代码打开包含文件‘ afxres.h’

将 afxres.h 替换为 Winresrc.h 并将 IDC _ STATIC 声明为 -1对我来说很有用。 (使用视觉工作室溢价2012)

//#include "afxres.h"
#include "WinResrc.h"
#define IDC_STATIC  -1

遇到了同样的问题。通过安装用于 C + + 的 Microsoft 基础类修复了这个问题。

  1. 开始
  2. 更改或删除程序(类型)
  3. MicrosoftVisualStudio
  4. 修改
  5. 选择“用于 C + + 的 Microsoft 基础类”
  6. 更新

enter image description here

或者,您可以创建自己的 afxres.h:

#ifndef _AFXRES_H
#define _AFXRES_H
#if __GNUC__ >= 3
#pragma GCC system_header
#endif


#ifdef __cplusplus
extern "C" {
#endif


#ifndef _WINDOWS_H
#include <windows.h>
#endif


/* IDC_STATIC is documented in winuser.h, but not defined. */
#ifndef IDC_STATIC
#define IDC_STATIC (-1)
#endif


#ifdef __cplusplus
}
#endif
#endif

通过从另一个 VisualStudio 设置(非快速设置)复制下面的文件夹来修复此问题

来自 C: Program Files (x86) Microsoft Visual Studio 12.0 VC atlmfc

到 C: Program Files (x86) Microsoft Visual Studio 11.0 VC atlmfc

Visual Studio 2015 RC 也有类似的问题。 有时它失去了打开 RC 的能力: 你双击,但编辑器没有一个菜单和对话框。

右键点击文件 * . rc,它会打开:

enter image description here

改变如下:

enter image description here

有类似的问题,但消息显示时,我试图打开一个项目解决方案。对我起作用的是:

工具-> 导入和导出设置...-> 重置所有设置

我在 VS 2019上也遇到过同样的问题。我的解决方案是从“个人组件”选项卡安装 C + + MFC 库。打开 VisualStudio 时,转到 Tools-> GetToolsAndFeatures-> PersonualComponent

选择并安装:

  • MSVC v142-VS 2019 C + + x64/x86构建工具(最新版本)
  • 用于最新的 v142构建工具(x86 & x64)的 C + + ATL
  • 用于最新的 v142构建工具(x86 & x64)的 C + + MFC