I am trying to write a program that works in console or GUI mode, depending on the execution options. I was able to write the following code example:
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using System.Runtime.InteropServices; namespace wfSketchbook { static class Program { [DllImport("Kernel32.dll")] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool AttachConsole(int processId); [DllImport("Kernel32.dll")] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool AllocConsole(); [DllImport("Kernel32.dll")] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool FreeConsole(); private const int ATTACH_PARENT_PROCESS = -1;
It usually works, however, when the program is called from the command line of the system, cmd does not seem to know that this program works in console mode and immediately exits:
d:\Dokumenty\Dev\C
I would prefer the following output:
d:\Dokumenty\Dev\C
How can I fix this problem?
Spook source share