[DllImport("kernel32.dll")]
static extern bool ReadConsoleOutputCharacter(IntPtr hConsoleOutput,
[Out] StringBuilder lpCharacter, uint nLength, COORD dwReadCoord,
out uint lpNumberOfCharsRead);
None.
None.
Please add some!
[StructLayout(LayoutKind.Sequential)]
private struct COORD
{
public short X;
public short Y;
}
// Before reading from the console, allocate the console using AllocConsole(), or attach to an existing console using AttachConsole().
// Then call GetStdHandle() to get an IntPtr for the stdout handle. Then call ReadConsoleOutputCharacter() as shown in this example.
private string ReadFromConsole(IntPtr stdout)
{
uint nLength = 80;
StringBuilder lpCharacter = new StringBuilder((int)nLength);
// read from the first character of the first line (0, 0)
COORD dwReadCoord;
dwReadCoord.X = 0;
dwReadCoord.Y = 0;
uint lpNumberOfCharsRead = 0;
if ( !ReadConsoleOutputCharacter(stdout, lpCharacter, nLength, dwReadCoord, out lpNumberOfCharsRead) )
throw new Win32Exception();
return lpCharacter.ToString();
}
Do you know one? Please contribute it!