Error RC2135 in C++ project due to UTF-8 encoding of RC file

可紊 提交于 2019-12-04 06:32:00

As part of the switch to Visual Studio 2012 I had also updated the program version number in the .rc file using a home-made program that processed all of my AssemblyInfo.cs and .rc files, and it had changed the encoding of the .rc file from ANSI to UTF-8. And the Microsoft Resource Compiler can't read UTF-8 files properly! http://social.msdn.microsoft.com/Forums/hu-HU/vcgeneral/thread/e212069d-678e-4ac8-957f-7d60d3e1c89f

So the solution is to re-encode the .rc file as ANSI or UTF-16.

If you promise to always hand-edit the .rc file, you could put this at beginning of it and the resource compiler will compile utf-8 like an angel,

#pragma code_page(65001)

But once the VS resource editor gets to regenerate the .rc file, it will be all messed up.

You can also use Pre-build event command line to convert your UTF-8 source file before compiling.

Sample steps:

  1. exclude your UTF-8 file from compiling.

  2. make a copy of your UTF-8 file, rename it

  3. add an entry in the Pre-build event command line, converting the original UTF-8 file to the renamed file as UNICODE. This tool may help you.

    $(ProjectDir)\tools\uniconv.exe UTF8 $(ProjectDir)\DocumentBrowserUTF8.rc UCS2 $(ProjectDir)\DocumentBrowser.rc

  4. in your build scripts (in many cases, Visual Studio .vcxproj file), make it to compile the converted file instead of the original UTF-8 file.

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