24

I converted my VS 2012 projects to VS 2015 by using the automatic conversion tool. When I try to load a resource file (.rc) it fails with this error:

fatal error RC1015: cannot open include file afxres.h

Any idea?

Étienne
  • 4,773
  • 2
  • 33
  • 58
Amiad
  • 361
  • 1
  • 2
  • 7
  • 1
    `afxRes.h` is an MFC header. Does your VS 2015 installation include MFC? – dxiv Feb 16 '16 at 18:31
  • 1
    @fxiv You are right, but unfortunately at least VS2010 has put "#include afxres.h" also into rc files for non-MFC console applications, so this dependance comes a bit surprising. – Werner Henze Aug 05 '16 at 08:45
  • Take a look at: http://stackoverflow.com/questions/3566018/cannot-open-include-file-afxres-h-in-vc2010-express – Matthias May 19 '17 at 12:06

3 Answers3

26

I have seen the same problem with console applications without MFC that where generated with Visual Studio 2010.

One solution is to modify the installation of Visual Studio 2015 to include MFC. MFC is not installed by default because of it's size. But in my opinion this should only be applied if you have applications that use MFC.

If you only need MFC for afxres.h you can replace

#include "afxres.h"
[...]
"#include ""afxres.h""\r\n"

with

#include "WinResrc.h"
[...]
"#include ""WinResrc.h""\r\n"

You might need to add (but you will see that when compiling the resources).

#define IDC_STATIC -1
[...]
"#define IDC_STATIC -1""\r\n"

As you can see in the rc file one of the sections is TEXTINCLUDE. When Visual Studio's resource editor opens the rc file and saves it back to disc it takes this section and puts the text into the section marked with "Generated from the TEXTINCLUDE [...]". So take care to change both places of at least the TEXTINCLUDE section so that resource editor can do the rest.

Werner Henze
  • 16,404
  • 12
  • 44
  • 69
  • 3
    Great solution! I just falled on the same problem when moving an old VS2013 project to a brand new VS2017 installation without MFC. Replacing afxres with WinResrc unlocked my build. – Francis Pierot May 15 '17 at 05:27
3

This answer on Thomson Reuters website worked for me. Adding for other users:

You probably need to modify the Visual Studio 2015 setup and add the MFC .

Please close VS2015 and go to Control Panel -> Programs and Features -> Microsoft Visual Studio -> Change -> Modify -> Add Microsoft Foundation Classes

See the figure below:

enter image description here

displayName
  • 13,888
  • 8
  • 60
  • 75
2

I'm using VS 2017 and I didn't need to install MFC. You can change the header to #include "winres.h" instead. There are other minor changes with the #if defines, so I strongly suggest you create a new .rc resource file and do an A/B compare to see the differences (it is not much). I just compared the old with the new and migrated the differences.

James Wilkins
  • 6,836
  • 3
  • 48
  • 73