Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot open resource file in VS 2015: Can't open include file afxres.h

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?

like image 236
Amiad Avatar asked Feb 16 '16 15:02

Amiad


3 Answers

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.

like image 98
Werner Henze Avatar answered Nov 04 '22 06:11

Werner Henze


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

like image 3
displayName Avatar answered Nov 04 '22 07:11

displayName


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.

like image 2
James Wilkins Avatar answered Nov 04 '22 07:11

James Wilkins