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?

3
  • 1
    afxRes.h is an MFC header. Does your VS 2015 installation include MFC?
    – dxiv
    Commented Feb 16, 2016 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. Commented Aug 5, 2016 at 8:45
  • Take a look at: stackoverflow.com/questions/3566018/…
    – Matthias
    Commented May 19, 2017 at 12:06

3 Answers 3

27

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.

1
  • 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. Commented May 15, 2017 at 5: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

1
  • Fixed the error for me in my VS2019 C++ project on new machine!
    – PJRobot
    Commented Jun 9, 2020 at 10:32
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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.