Visual Studio .Net 2003 C++ / Console
-
Hallo zusammen, ich hab gerade mal angefagen in VC++ .Net2003 zu programmieren.
Hab leider nicht viel erfahrung mit VC++ und net mit der MS - Umgebung und vielleicht könnt ihr mir ja helfen.Also ich hab mal angefangen und mir ein Windows Forms Projekt zusammengestellt.
Mit C++. Jetzt hätte ich aber gerne so etwas wie consolen ausgaben, aber wenn ichConsole::WriteLine("Test");
mache kommt bei mir nichts.
Wie oder was muss ich machen um soetwas wie consolen ausgaben zu erhalten, debugtechnisch gesehen ist das einfach eine feine sache.
-
In den Projekteigenschaften den OutputType auf "Console Application" setzen.
-
Thx a lot
-
Kann man auch irgendwie programmatisch eine Konsole öffnen?
-
wenn du folgendes als winexe compilierst, öffnet sich nur das fenster.
wenn du folgendes als exe compilierst, wie noodle es sagt, öffnet sich beides: konsole und fenster.
//eine konsole herstellen als fenster ist wohl nicht vorgesehen. (?)using System; using System.Windows.Forms; namespace MyForm { public class CreatedForm : System.Windows.Forms.Form { public CreatedForm() { InitializeComponents(); } void InitializeComponents() { System.Console.WriteLine("Console"); } } }
-
Bashar schrieb:
Kann man auch irgendwie programmatisch eine Konsole öffnen?
Wie meinste das?
Ne Konsole für Debugausgaben oder die Standardkonsole?System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("cmd"); psi.WorkingDirectory = "C:\\"; System.Diagnostics.Process.Start(psi);
-
Noodles schrieb:
Wie meinste das?
Ne Konsole für Debugausgaben oder die Standardkonsole?Ist die Frage dein Ernst? Ich hoffe nicht.
-
Nein, natürlich nicht, Entschuldige es kommt nicht wieder vor.
-
das ist es nicht... , aber mit IntPtr kommt man runter.
using System; using System.IO; using System.Diagnostics; using System.Runtime.InteropServices; using System.Windows.Forms; namespace WindowsConsole { public class WinConsole { [DllImport("kernel32.dll")] [return: MarshalAs(UnmanagedType.Bool)] static extern bool AllocConsole(); [DllImport("kernel32.dll")] [return: MarshalAs(UnmanagedType.Bool)] static extern bool FreeConsole(); [DllImport("kernel32.dll")] [return: MarshalAs(UnmanagedType.Bool)] static extern bool AttachConsole( int processId ); [DllImport("kernel32.dll")] static extern int GetCurrentProcessId(); [DllImport("kernel32.dll")] static extern IntPtr GetStdHandle( int nStdHandle ); [DllImport("kernel32.dll")] static extern int WaitForSingleObject( IntPtr handle, int timeout ); [DllImport("kernel32.dll")] static extern bool FlushConsoleInputBuffer( IntPtr handle ); const int STD_INPUT_HANDLE = -10; const int STD_OUTPUT_HANDLE = -11; const int STD_ERROR_HANDLE = -12; [STAThread] static void Main( string[] args ) { Process myProcess = Process.GetCurrentProcess(); AllocConsole(); IntPtr inHandle = GetStdHandle( STD_INPUT_HANDLE ); IntPtr outHandle = GetStdHandle( STD_OUTPUT_HANDLE ); FileStream outStream = new FileStream( outHandle, FileAccess.Write ); StreamWriter writer = new StreamWriter( outStream ); Console.SetOut( writer ); writer.AutoFlush = true; Console.WriteLine("Hello Console!"); FlushConsoleInputBuffer( inHandle ); int result = WaitForSingleObject( inHandle, 0xffffff ); } } }