That's what I want to do with C#. I have two buttons and two textboxes, and first I want to write something in textbox1, and this message is redirected to the console, and at this time, when something new appears in my console, textbox2 needs to read it, and the process should continue and continue. I want to use my simple DLL library, which works in this scenario. I know how to write messages to the console, but I can not read every new one from the console and write it to textbox2.
This is my redirecting from textbox into console, now i need to read anything new appearing in the console to my textbox2.
public partial class NativeMethods
{
public static Int32 STD_OUTPUT_HANDLE = -11;
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
public static extern System.IntPtr GetStdHandle(Int32 nStdHandle);
[System.Runtime.InteropServices.DllImport("kernel32.dll", EntryPoint = "AllocConsole")]
[return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)]
public static extern bool AllocConsole();
}
And somewhere else....
public void console()
{
if(NativeMethods.AllocConsole())
{
IntPtr handle = NativeMethods.GetStdHandle(NativeMethods.STD_OUTPUT_HANDLE);
Console.WriteLine("type: ");
}
else
{
Console.WriteLine("Waiting...");
}
}
Using these when a button is clicked.