ReadConsoleOutputCharacter (kernel32)
Last changed: -24.87.64.223

.
Summary

C# Signature:

[DllImport("kernel32.dll")]
static extern bool ReadConsoleOutputCharacter(IntPtr hConsoleOutput,
   [Out] StringBuilder lpCharacter, uint nLength, COORD dwReadCoord,
   out uint lpNumberOfCharsRead);

User-Defined Types:

None.

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

[StructLayout(LayoutKind.Sequential)]

private struct COORD

{

    public short X;
    public short Y;

}

private void ReadFromConsole(IntPtr stdout)

{

    // first allocate the console using AllocConsole(), or attach to an existing console using AttachConsole().
    // then call GetStdHandle() to get an IntPtr for the stdout handle.

    uint nLength = 80;
    StringBuilder lpCharacter = new StringBuilder((int)nLength);

    COORD dwReadCoord;
    dwReadCoord.X = 0;
    dwReadCoord.Y = 0;

    uint lpNumberOfCharsRead = 0;

    if ( !ReadConsoleOutputCharacter(stdout, lpCharacter, nLength, dwReadCoord, out lpNumberOfCharsRead) )
    throw new Win32Exception();

    MessageBox.Show(lpCharacter.ToString());

}

Alternative Managed API:

Do you know one? Please contribute it!

Documentation