473,387 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

trying to WriteConsoleInput

Hi I'm tring to WriteConsoleInput to a Console app after I use
AttachConsole. I don't know where to get the HANDLE definition -- I
tried "using System;,System.Runtime.InteropServices,
System.Diagnostics,,using System.IO, Microsoft.Win32,
Microsoft.Internal" but I cannot find the definition of HANDLE, "The
type or namespace name 'HANDLE' could not be found (are you missing a
using directive or an assembly reference?)" I also can't find the
definitions of GENERIC_READ and OPEN_EXISTING, for example.

I need the definition of HANDLE to do something like this:
HANDLE rHnd;
rHnd = GetStdHandle(STD_INPUT_HANDLE);
and then WriteConsoleInput(rHnd, ...);

I would just like to write some characters to the console input
buffer, but this is proving difficult, if you have any direction,
definitions, examples, et cetera, I would appreciate it very much.
Thanks, Patrick

Jul 26 '07 #1
1 4249
Patrick Burke wrote:
Hi I'm tring to WriteConsoleInput to a Console app after I use
AttachConsole. I don't know where to get the HANDLE definition -- I
tried "using System;,System.Runtime.InteropServices,
System.Diagnostics,,using System.IO, Microsoft.Win32,
Microsoft.Internal" but I cannot find the definition of HANDLE, "The
type or namespace name 'HANDLE' could not be found (are you missing a
using directive or an assembly reference?)" I also can't find the
definitions of GENERIC_READ and OPEN_EXISTING, for example.

I need the definition of HANDLE to do something like this:
HANDLE rHnd;
rHnd = GetStdHandle(STD_INPUT_HANDLE);
and then WriteConsoleInput(rHnd, ...);

I would just like to write some characters to the console input
buffer, but this is proving difficult, if you have any direction,
definitions, examples, et cetera, I would appreciate it very much.
uint or int works fine.

Code below.

Arne

=============================================

public class MyConsole : IDisposable
{
private const uint STD_INPUT_HANDLE = 0xfffffff6;
private const uint STD_OUTPUT_HANDLE = 0xfffffff5;
private const uint STD_ERROR_HANDLE = 0xfffffff4;
private const uint ATTACH_PARENT_PROCESS = 0xffffffff;
[DllImport("kernel32.dll")]
public static extern bool AttachConsole(uint dwProcessId);
[DllImport("kernel32.dll")]
public static extern bool AllocConsole();
[DllImport("kernel32.dll")]
public static extern bool FreeConsole();
[DllImport("kernel32.dll")]
public static extern int GetStdHandle(uint nStdHandle);
[DllImport("kernel32.dll")]
public static extern bool WriteConsole(int hConsoleOutput,
string lpBuffer,
int nNumberOfCharsToWrite,
ref int
lpNumberOfCharsWritten,
int lpReserved);
[DllImport("kernel32.dll")]
public static extern bool ReadConsole(int hConsoleInput,
StringBuilder lpBuffer,
int nNumberOfCharsToRead,
ref int lpNumberOfCharsRead,
int lpReserved);
private int stdin;
private int stdout;
public MyConsole()
{
AllocConsole();
stdin = GetStdHandle(STD_INPUT_HANDLE);
stdout = GetStdHandle(STD_OUTPUT_HANDLE);
}
public void WriteLine(string s)
{
int len = 0;
WriteConsole(stdout, s + "\r\n", s.Length + 2, ref len, 0);
}
public string ReadLine()
{
int len = 0;
StringBuilder sb = new StringBuilder();
ReadConsole(stdin, sb, 256, ref len, 0);
return sb.ToString(0, sb.Length - 2);
}
public void Dispose()
{
FreeConsole();
}
}
Aug 20 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Garry Freemyer | last post by:
I'm trying to convert this macro to a c# function but I have a big problem. It's on the LEFT side of an assignment statement and I am extremely flustered over this one because I'm a little rusty...
7
by: Kris Desmadryl | last post by:
Hi all, I create a new asp project, with just one button on the startup form but when I run I always get a messagebox with the error : "Error while trying to run project." That's all what I see...
5
by: tshad | last post by:
I am trying to access my log files and am running into a permissions problem. I am doing the following: ****************************************************************** private void...
10
by: Doug Perkes | last post by:
Does anyone have an example of declaring and using the WriteConsoleOutput Win32 API function? I'm having a little bit of trouble understanding how to translate all the structures to VB.NET....
3
by: David Thielen | last post by:
Hi; I created a virtual directory in IIS 6.0 and my asp.net app runs fine. But when it tries to write a file I get: Access to the path is denied. - C:\Inetpub\wwwroot\RunReportASP\images ...
4
by: 28tommy | last post by:
Hi, I'm trying to find scripts in html source of a page retrieved from the web. I'm trying to use the following rule: match = re.compile('<script + src=+>') I'm testing it on a page that...
5
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As...
17
by: Sam Malone | last post by:
I am trying to get details from a database. I really want to use only native VS.NET managed code "stuff" (just cuz I want to) and avoid any interop stuff. So, I'm trying to do this without using...
0
by: cwho.work | last post by:
Hi! We are using apache ibatis with our MySQL 5.0 database (using innodb tables), in our web application running on Tomcat 5. Recently we started getting a number of errors relating to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.