Skip to content

Instantly share code, notes, and snippets.

@treytomes
Created January 18, 2016 19:22
Show Gist options
  • Save treytomes/95666e4b966464b4cf00 to your computer and use it in GitHub Desktop.
Save treytomes/95666e4b966464b4cf00 to your computer and use it in GitHub Desktop.
Dump the Extended ASCII character set to the console window using DllImport.
using System;
using System.Runtime.InteropServices;
namespace ConsoleTest
{
class Program
{
public const int STD_OUTPUT_HANDLE = -11;
public struct COORD
{
public short X;
public short Y;
}
[DllImport("kernel32.dll")]
public static extern IntPtr GetStdHandle(int nStdHandle);
[DllImport("kernel32.dll")]
public static extern bool WriteConsole(IntPtr hConsoleOutput, string lpBuffer,
uint nNumberOfCharsToWrite, out uint lpNumberOfCharsWritten,
IntPtr lpReserved);
[DllImport("kernel32.dll")]
public static extern bool WriteConsoleOutputCharacter(IntPtr hConsoleOutput,
string lpCharacter, uint nLength, COORD dwWriteCoord,
out uint lpNumberOfCharsWritten);
static void Main(string[] args)
{
IntPtr hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
COORD p = new COORD();
uint num;
for (int index = 0; index < 256; index++)
{
WriteConsoleOutputCharacter(hOutput, new string((char)index, 1), 1, p, out num);
p.X++;
if (p.X > 40)
{
p.X = 0;
p.Y++;
}
}
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment