Cannot open include file 'afxres.h' in VC2010 Express

C++Visual StudioWinapiVisual C++

C++ Problem Overview


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!

C++ Solutions


Solution 1 - C++

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.

Solution 2 - C++

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

Solution 3 - C++

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

Solution 4 - C++

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   

Solution 5 - C++

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

Solution 6 - C++

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

Solution 7 - C++

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

Solution 8 - C++

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionclampView Question on Stackoverflow
Solution 1 - C++Kirill V. LyadvinskyView Answer on Stackoverflow
Solution 2 - C++Colonel PanicView Answer on Stackoverflow
Solution 3 - C++ravi.zombieView Answer on Stackoverflow
Solution 4 - C++GerbenView Answer on Stackoverflow
Solution 5 - C++IrbisView Answer on Stackoverflow
Solution 6 - C++Tiago DuarteView Answer on Stackoverflow
Solution 7 - C++ingcontiView Answer on Stackoverflow
Solution 8 - C++OlppahView Answer on Stackoverflow