Example #1
0
        private static int Main(string[] args)
        {
            // from http://blogs.msdn.com/b/microsoft_press/archive/2010/02/03/jeffrey-richter-excerpt-2-from-clr-via-c-third-edition.aspx
            AppDomain.CurrentDomain.AssemblyResolve += ResolveEventHandler;

            if (args.Length != 0)
            {
                //Get a pointer to the forground window.  The idea here is that
                //IF the user is starting our application from an existing console
                //shell, that shell will be the uppermost window.  We'll get it
                //and attach to it

                /*
                 *              IntPtr ptr = GetForegroundWindow();
                 *
                 *              int u;
                 *
                 *              GetWindowThreadProcessId(ptr, out u);
                 *
                 *              Process process = Process.GetProcessById(u);
                 *
                 *              if (process.ProcessName == "cmd") //Is the uppermost window a cmd process?
                 *              {
                 *                  AttachConsole(process.Id);
                 *              }
                 *              else
                 *              {
                 *                  //no console AND we're in console mode ... create a new console.
                 *
                 *                  AllocConsole();
                 *              }
                 */

                var clRunner      = new CommandLineRunner();
                int dosErrorLevel = clRunner.Run(args);

                return(dosErrorLevel);
            }
            else
            {
                FreeConsole();
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new MainForm());

                return(0);
            }
        }
Example #2
0
        private static int Main(string[] args)
        {
            // from http://blogs.msdn.com/b/microsoft_press/archive/2010/02/03/jeffrey-richter-excerpt-2-from-clr-via-c-third-edition.aspx
            AppDomain.CurrentDomain.AssemblyResolve += ResolveEventHandler;

            if (args.Length != 0 && args.Contains("--cl"))
            {
                //Get a parent procss for see where send the output.
                Process process = Process.GetProcessById(Process.GetCurrentProcess().Id).Parent();

                if (process.ProcessName == "cmd") //Is the uppermost window a cmd process?
                {
                    AttachConsole(process.Id);
                }
                else
                {
                    //no console AND we're in console mode ... create a new console.

                    AllocConsole();
                }

                var clRunner      = new CommandLineRunner();
                int dosErrorLevel = clRunner.Run(args);

                FreeConsole();
                return(dosErrorLevel);
            }
            else
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new MainForm());

                return(0);
            }
        }