-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNativeConsole.cs
More file actions
91 lines (75 loc) · 2.89 KB
/
NativeConsole.cs
File metadata and controls
91 lines (75 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System.Runtime.InteropServices;
namespace VTTest;
/// <summary>
/// Win32 Console P/Invoke declarations.
/// </summary>
internal static class NativeConsole
{
// Console input mode flags (from wincon.h)
internal const uint ENABLE_PROCESSED_INPUT = 0x0001;
internal const uint ENABLE_LINE_INPUT = 0x0002;
internal const uint ENABLE_ECHO_INPUT = 0x0004;
internal const uint ENABLE_WINDOW_INPUT = 0x0008;
internal const uint ENABLE_MOUSE_INPUT = 0x0010;
internal const uint ENABLE_INSERT_MODE = 0x0020;
internal const uint ENABLE_QUICK_EDIT_MODE = 0x0040;
internal const uint ENABLE_EXTENDED_FLAGS = 0x0080;
internal const uint ENABLE_AUTO_POSITION = 0x0100;
internal const uint ENABLE_VIRTUAL_TERMINAL_INPUT = 0x0200;
// Console output mode flags
internal const uint ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004;
internal const int STD_INPUT_HANDLE = -10;
internal const int STD_OUTPUT_HANDLE = -11;
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern IntPtr GetStdHandle(int nStdHandle);
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode);
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode);
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool ReadFile(
IntPtr hFile,
byte[] lpBuffer,
uint nNumberOfBytesToRead,
out uint lpNumberOfBytesRead,
IntPtr lpOverlapped);
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool WriteFile(
IntPtr hFile,
byte[] lpBuffer,
uint nNumberOfBytesToWrite,
out uint lpNumberOfBytesWritten,
IntPtr lpOverlapped);
[StructLayout(LayoutKind.Sequential)]
internal struct CONSOLE_SCREEN_BUFFER_INFO
{
public COORD dwSize;
public COORD dwCursorPosition;
public short wAttributes;
public SMALL_RECT srWindow;
public COORD dwMaximumWindowSize;
}
[StructLayout(LayoutKind.Sequential)]
internal struct COORD
{
public short X;
public short Y;
}
[StructLayout(LayoutKind.Sequential)]
internal struct SMALL_RECT
{
public short Left;
public short Top;
public short Right;
public short Bottom;
}
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool GetConsoleScreenBufferInfo(
IntPtr hConsoleOutput,
out CONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo);
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool SetConsoleOutputCP(uint wCodePageID);
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern uint GetConsoleOutputCP();
internal const uint CP_UTF8 = 65001;
}