153

I'm trying to compile an old project using VS express 2010 but I get this error:

fatal error RC1015: cannot open include file 'afxres.h'. from this code

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

I have installed Windows SDK already, but without any success.

thanks!

Mathieu Renda
  • 14,069
  • 2
  • 35
  • 33
clamp
  • 33,000
  • 75
  • 203
  • 299

9 Answers9

211

This header is a part of the MFC Library. VS Express edition doesn't contain MFC. If your project doesn't use MFC you can safely replace afxres.h with windows.h in your terrain2.rc.

Kirill V. Lyadvinsky
  • 97,037
  • 24
  • 136
  • 212
  • 4
    thanks, then i get the error: error RC2104: undefined keyword or key name: IDC_STATIC – clamp Aug 25 '10 at 13:16
  • @clamp: that sounds like a Common Control definition. try adding #include as well (and link your program to Comctl32.lib) – default Aug 25 '10 at 13:28
  • 3
    Otherwise IDC_STATIC is defined as -1, so define it yourself if that's the only problem remaining. – erikH Jun 26 '12 at 11:46
  • 40
    winres.h defines IDC_STATIC so you can likely just #include rather than afxres.h or windows.h. – Conrad Poelman Oct 20 '12 at 05:51
142

Had the same problem . Fixed it by installing Microsoft Foundation Classes for C++.

  1. Start
  2. Change or remove program (type)
  3. Microsoft Visual Studio
  4. Modify
  5. Select 'Microsoft Foundation Classes for C++'
  6. Update

enter image description here

In in the Visual Studio Installer for VS 2022 this may be listed as an individual component: "C++ MFC for latest v143 build Tools (x86 & x64)", but you may need to adapt this for your platform and latest version available.

Stephen Turner
  • 7,125
  • 4
  • 51
  • 68
Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
42

Even I too faced similar issue,

fatal error RC1015: cannot open include file 'afxres.h'. from this code

Replacing afxres.h with Winresrc.h and declaring IDC_STATIC as -1 worked for me. (Using visual studio Premium 2012)

//#include "afxres.h"
#include "WinResrc.h"
#define IDC_STATIC  -1
ravi.zombie
  • 1,482
  • 1
  • 20
  • 23
  • I _have_ MFC installed. The above hack just tells me that WinResrc.h is not found (I am using VS 2019 Community Edition) – flounder Jan 04 '23 at 06:27
16

Alternatively you can create your own 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   
Gerben
  • 161
  • 1
  • 2
8

You can also try replace afxres.h with WinResrc.h

Irbis
  • 11,537
  • 6
  • 39
  • 68
  • I changed the file to windows.h and WinResrc.h and the message has changed in both cases to another messgaes stating : error RC2104: undefined keyword or key name: IDC_STATIC .. I am just guessing that this IDC_static is defined within th original afxres.h file, but how to resolve this new error ? – hashDefine Jun 27 '13 at 10:50
6

managed to fix this by copying the below folder from another Visual Studio setup (non-express)

from C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc

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

Tiago Duarte
  • 3,244
  • 3
  • 23
  • 29
2

a similar issue is for Visual studio 2015 RC. Sometimes it loses the ability to open RC: you double click but editor do not one menus and dialogs.

Right click on the file *.rc, it will open:

enter image description here

And change as following:

enter image description here

ingconti
  • 10,876
  • 3
  • 61
  • 48
2

I faced same issue on VS 2019. My solution was to install C++ MFC library from Individual Components tab. When you open Visual Studio go to Tools->GetToolsAndFeatures->IndividualComponents

Select and install:

  • MSVC v142 - VS 2019 C++ x64/x86 build tools (Latest)
  • C++ ATL for latest v142 build tools (x86 & x64)
  • C++ MFC for latest v142 build tools (x86 & x64)
Darko V
  • 49
  • 1
  • 5
-1

Had similar issue but the message was shown when I tried to open a project solution. What worked for me was:

TOOLS -> Import and Export Settings...-> Reset all settings

Olppah
  • 790
  • 1
  • 10
  • 21