2

Visual Studio 2019 and 2022 Resource Editor is able to correctly read and display .rc file in UTF-8 encoding if .rc file is saved without UTF-8 BOM. The main requirements for it, .rc file must contain valid #pragma code_page.
Example:

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEUD)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(65001)

But if you did some changes in textual resource and saves result back to .rc file, it will be corrupted:

  • all #pragma code_page(65001) will be replaced by your default ANSI code page (e.g. #pragma code_page(1252))
  • all non ANSI symbol will be replaced by ?.

Is there some way how to work with UTF-8 c++ resource in Visual Studio 2019\2022 Resource Editor without this bug.

P.S.:

  • I don't use Unicode (UTF-16 LE) encoding due to problems in git with it.
  • Using UTF-8 without BOM is single way how to compile UTF-8 .rc file in Visual Studio, see link.
23W
  • 1,413
  • 18
  • 37
  • And what did you do for `#pragma code_page` that were around special parts like includes? I guess this pragma have to match the included files encoding... ? – Sandburg Feb 28 '23 at 14:42

1 Answers1

2

Microsoft knows about this bug and they decided not to fix it:

Thank you very much for your feedback. We've decided to take no action on this feedback at the time.
When working with Resource Compiler (.rc) source files, our suggestion has always been to use UTF-16 whenever resources contain strings that cannot be encoded as ASCII. Based on your replies, it looks like switching back to UTF-16 would unblock your experience with Resource Editor, with the caveat that GitHub won't treat .rc files as text.
While eventually we want to support UTF-8 text encodings for .rc files, we currently do not have plans for this work; and for this reason we're closing this issue as Won't Fix.

See https://developercommunity.visualstudio.com/t/visualstudio-v1590-resource-editor-using-utf-8-bom/384705

23W
  • 1,413
  • 18
  • 37
  • That's strange, Raymond Chen himself suggest to switch rc files to utf-8 https://devblogs.microsoft.com/oldnewthing/20190607-00/?p=102569 – Sandburg Feb 28 '23 at 14:44
  • The best advantage I see with `code_page(1200)` utf-16 is that more than being Unicode and 100% functional, it's also optional. Once converted, you can remove all the code_page entries. 1200 is the natural Visual encoding. Much better than 65001 utf-8. Plus, Visual will certainly remove them for you if you edit/save the resources. – Sandburg Feb 28 '23 at 17:09
  • @Sandburg, You will have problems in git with utff-16. – 23W Mar 01 '23 at 20:12
  • I will have more problems in Visual RC files with utf-8 (I tried). Until now, looks OK with utf-16LE in git. – Sandburg Mar 02 '23 at 17:47
  • @Sandburg, git treats utff-16 as binary file by default. it needs tuning to work with such files correctly. – 23W Mar 02 '23 at 18:32
  • This answer is wrong since in the very same Developer Community entry it is stated that the UTF-8 compatibility issues with the resource compiler are fixed with Windows SDK Version 10.0.20348.0 (rcdll.dll v10.0.19505.1001). – sigy Aug 25 '23 at 12:05