2

Currently it defaults to my system locale, which is 932 (Japanese Shift-JIS) in my case, but I want it to be 65001 (UTF-8) by default.

I can change the default for a given program by inserting a SetConsoleOutputCP line somewhere in the code and then removing it, but doing it for every program is pretty annoying.

Any suggestions?

Nikolai
  • 3,053
  • 3
  • 24
  • 33
  • Well, you shouldn't. The output of console mode apps can be redirected. Whatever program reads the output is going to be clueless about the utf-8 encoding. If the 8-bit codepage requirement for console apps starts to become a problem then you need to start thinking about writing native Windows programs. – Hans Passant Sep 17 '11 at 12:24
  • The Windows console does not work work with utf-8. Not even SetConsoleOutputCP will help. – Mihai Nita Oct 07 '11 at 23:45

1 Answers1

1

This could be done with the standard approach: by composing the registry settings for the executable being debugged. My template dbg_console.reg:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Console\<encoded_path_to_executable>]
"ScreenBufferSize"=dword:1388012c
"WindowSize"=dword:00340096
"FontSize"=dword:00100000
"FontFamily"=dword:00000036
"FontWeight"=dword:00000190
"FaceName"="Lucida Console"
"HistoryNoDup"=dword:00000000
"QuickEdit"=dword:00000001
"CodePage"=dword:000004e3

<encoded_path_to_executable> is the string where \ is replaced with _. E.g.: Z:\prj\prj_name\out\debug\bin\program.exe is transformed to Z:_prj_prj_name_out_debug_bin_program.exe.

"CodePage"=dword:000004e3 sets the desired code page. It is important to choose a proper font.

Due to debug mode, the standard settings dialog called on the window header of a program console cannot function properly. However, you can get the desired settings via Windows cmd started with Win+R shortcut. They appear under the folder %SystemRoot%_system32_cmd.exe or alike.

Thus, you exactly get the desired code page in the debug console of your executable without the need to setup code page conditionally at run time. The support of the 65001 code page can be determined from the keys in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage: if there is the key 65001 having appropriate *.nls file, this page is supported.

Aleksey F.
  • 751
  • 7
  • 19