Home > Uncategorized > C#: Creating a hybrid CLI and GUI app

C#: Creating a hybrid CLI and GUI app

Note that you’re probably better off dealing with a CLI app that in turn creates a Windows.Form object. The project I had was already written templated out to Windows.Form, so this is a bit hacky.

Use the following

class ClassyTheClass
{

[DllImport("kernel32.dll", SetLastError = true)]
static extern bool AttachConsole(uint dwProcessId);

[DllImport("kernel32.dll", SetLastError = true, ExactSpelling =
true)]
static extern bool FreeConsole();

method()
{

AttachConsole(0x0ffffffff);

Console.WriteLine("I'm writing to your parent process, the host of your console.");

SendKeys.SendWait("{ENTER}"); //hackalicious <a href="http://stackoverflow.com/questions/1305257/using-attachconsole-user-must-hit-enter-to-get-regular-command-line/2463039#2463039">http://stackoverflow.com/questions/1305257/using-attachconsole-user-must-hit-enter-to-get- regular-command-line/2463039#2463039</a>

FreeConsole();

System.Environment.Exit(0);
}

}
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: