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

夙愿已清 提交于 2020-03-18 03:26:06

问题


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: Can't open include file afxres.h

Any idea?


回答1:


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.




回答2:


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:




回答3:


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.



来源:https://stackoverflow.com/questions/35436654/cant-open-resource-file-in-vs-2015-cant-open-include-file-afxres-h

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!