0

I have a .idl file with some extended non-ASCII characters in the comments using Windows-1252 encoding. When I open it in the IDE editor I get an error message:

Some bytes have been replaced with the Unicode substitution character while loading file xxx.idl with Unicode (UTF-8) encoding. Saving the file will not preserve the original file contents.

Sure enough, the special characters have been replaced with the question mark in a black diamond.

When I do a compile, the file is automatically resaved with the garbage characters in it. The characters are only in comments, so everything compiles just fine, but the comments are ruined. The source control system notices the change and helpfully offers to check in the bad file, which would make the damage permanent.

I've tried to find a way to get Visual Studio to open the file with the proper encoding but haven't found a suitable setting anywhere. I found this Microsoft documentation /source-charset (Set Source Character Set) but apparently it only affects the compiler, not the editor.

Is there a setting, hopefully file-by-file but more globally would be OK too, where I can specify the character encoding?

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
  • @RichardCritten I didn't find any options specific to the MIDL compiler, only general C++ ones. But it's not the compiler I worry about, it's the editor. – Mark Ransom Sep 15 '20 at 19:37
  • Take a look at [this page](https://learn.microsoft.com/en-us/visualstudio/ide/how-to-save-and-open-files-with-encoding?view=vs-2019) from Microsoft. – jkb Sep 15 '20 at 19:42
  • @jkb I don't consider needing "Open With" every time I open a file to be an acceptable solution. For example, if I get a compile error I should be able to double-click on the error to open the file to the line causing the error. – Mark Ransom Sep 15 '20 at 19:48
  • You can try EditorConfig https://stackoverflow.com/a/49643621/84507 – Sergey Vlasov Sep 16 '20 at 03:43
  • @SergeyVlasov thanks for the suggestion. It looks like it would work, but I haven't managed to create a file that makes any difference. – Mark Ransom Sep 16 '20 at 15:14
  • I am afraid there is no setting to set encoding file-by-file. – Barrnet Chou Sep 17 '20 at 08:44
  • @BarrnetChou that was my conclusion too, but I was hoping there was someone out there who knows better than either of us. I can't even find a global setting. – Mark Ransom Sep 17 '20 at 13:51

0 Answers0