Set console output code page to UTF-8 (#753)

This commit is contained in:
Next Turn
2020-12-26 08:27:45 +08:00
committed by NextTurn
parent 4f7e623602
commit 16c6aa9c08
2 changed files with 7 additions and 0 deletions

View File

@@ -8,6 +8,8 @@ namespace WinSW.Native
{
internal const int ATTACH_PARENT_PROCESS = -1;
internal const uint CP_UTF8 = 65001;
[DllImport(Libraries.Kernel32, SetLastError = true)]
internal static extern bool AttachConsole(int processId);
@@ -20,6 +22,9 @@ namespace WinSW.Native
[DllImport(Libraries.Kernel32)]
internal static extern bool SetConsoleCtrlHandler(ConsoleCtrlHandlerRoutine? handlerRoutine, bool add);
[DllImport(Libraries.Kernel32)]
internal static extern bool SetConsoleOutputCP(uint codePageID);
internal delegate bool ConsoleCtrlHandlerRoutine(CtrlEvents ctrlType);
internal enum CtrlEvents : uint

View File

@@ -219,6 +219,8 @@ namespace WinSW.Util
bool succeeded = SetConsoleCtrlHandler(null, false); // inherited
Debug.Assert(succeeded);
succeeded = ConsoleApis.SetConsoleOutputCP(ConsoleApis.CP_UTF8);
Debug.Assert(succeeded);
try
{