Set console output code page to UTF-8

pull/754/head
NextTurn 2020-04-02 00:00:00 +08:00 committed by Next Turn
parent 932807529a
commit 7b23c949c4
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 AllocConsole();
@ -23,6 +25,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

@ -568,6 +568,8 @@ namespace WinSW
Debug.Assert(succeeded);
succeeded = ConsoleApis.SetConsoleCtrlHandler(null, false); // inherited
Debug.Assert(succeeded);
succeeded = ConsoleApis.SetConsoleOutputCP(ConsoleApis.CP_UTF8);
Debug.Assert(succeeded);
Process process;
try