Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/hakchi2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2017-06-22 21:03:28 +0300
committerAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2017-06-22 21:03:28 +0300
commit55471b07fcff8cc258dd54491373e0a3fcb07f05 (patch)
treefe2c943eda75f88dae5daa98da8344b0a0491402 /Program.cs
parent7a573ed12837553af63467b4aaba6f402bc54193 (diff)
Debugging console output fix for VS2017
Diffstat (limited to 'Program.cs')
-rw-r--r--Program.cs16
1 files changed, 16 insertions, 0 deletions
diff --git a/Program.cs b/Program.cs
index 364c7cab..8ae34e00 100644
--- a/Program.cs
+++ b/Program.cs
@@ -1,5 +1,6 @@
#pragma warning disable 0618
using com.clusterrr.hakchi_gui.Properties;
+using Microsoft.Win32.SafeHandles;
using System;
using System.Deployment.Application;
using System.Diagnostics;
@@ -8,6 +9,7 @@ using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Principal;
+using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
@@ -28,6 +30,13 @@ namespace com.clusterrr.hakchi_gui
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool AllocConsole();
+ [DllImport("kernel32.dll", SetLastError = true)]
+ private static extern IntPtr CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, uint lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, uint hTemplateFile);
+
+ private const int MY_CODE_PAGE = 437;
+ private const uint GENERIC_WRITE = 0x40000000;
+ private const uint FILE_SHARE_WRITE = 0x2;
+ private const uint OPEN_EXISTING = 0x3;
public static string BaseDirectoryInternal, BaseDirectoryExternal;
/// <summary>
@@ -40,6 +49,13 @@ namespace com.clusterrr.hakchi_gui
try
{
AllocConsole();
+ IntPtr stdHandle = CreateFile("CONOUT$", GENERIC_WRITE, FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
+ SafeFileHandle safeFileHandle = new SafeFileHandle(stdHandle, true);
+ FileStream fileStream = new FileStream(safeFileHandle, FileAccess.Write);
+ Encoding encoding = System.Text.Encoding.GetEncoding(MY_CODE_PAGE);
+ StreamWriter standardOutput = new StreamWriter(fileStream, encoding);
+ standardOutput.AutoFlush = true;
+ Console.SetOut(standardOutput);
Debug.Listeners.Add(new TextWriterTraceListener(System.Console.Out));
}
catch { }