Announcements and discussion for PInvoke


Postby patrickinminneapolis » Fri Jul 27, 2007 3:13 am

I am using AttachConsole to grab a .Net Console App in C# which is working - I can send it a Ctrl-C or print to its console which is very neat. I am really getting hung up on sending input into the Console App however.

I have been trying to use WriteConsoleInput, but getting stuck in various ways.

//here are my declarations
static extern bool WriteConsoleInput(IntPtr hConsoleInput, INPUT_RECORD[] lpBuffer, uint nLength, out uint lpNumberOfEventsWritten);

[DllImport("kernel32.dll", EntryPoint = "GetStdHandle", SetLastError = True, CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
private static extern int GetStdHandle(int nStdHandle);

//I want to do this
rHnd = GetStdHandle(STD_INPUT_HANDLE);

//but I don't know how to access the definition of HANDLE, or the definition of STD_INPUT_HANDLE, I tried using (IntPtr)0xFFFFFFF6 for STD_INPUT_HANDLE but got an int overflow

//Then once I have the handle I would like to plug it into WriteConsoleInput, which I think I can figure out, but any examples would be appreciated, I basically just want to send it a few characters and {enter}

Really do appreciate any help.
Posts: 1
Joined: Fri Jul 27, 2007 3:01 am

Return to PInvoke.Net

Who is online

Users browsing this forum: No registered users and 0 guests