NotSoSmartGuy Posted May 26, 2010 Share Posted May 26, 2010 Basically I have a windows app and would like to add a console window where I can output Console.WriteLine("SSSSSSSSSSSSSSSS"); Link to comment https://www.neowin.net/forum/topic/904788-c-adding-a-console-window-in-a-windows-app/ Share on other sites More sharing options...
0 still1 Posted May 26, 2010 Share Posted May 26, 2010 Basically I have a windows app and would like to add a console window where I can output Console.WriteLine("SSSSSSSSSSSSSSSS"); embedding a console in windows app or opening a new console windows from windows app? Link to comment https://www.neowin.net/forum/topic/904788-c-adding-a-console-window-in-a-windows-app/#findComment-592671978 Share on other sites More sharing options...
0 NotSoSmartGuy Posted May 26, 2010 Author Share Posted May 26, 2010 opening a new console window, so I can check what I am doing Link to comment https://www.neowin.net/forum/topic/904788-c-adding-a-console-window-in-a-windows-app/#findComment-592672000 Share on other sites More sharing options...
0 hdood Posted May 26, 2010 Share Posted May 26, 2010 I don't think there is any .NET call for that, but the native function is AllocConsole and you could call that with interop: [DllImport("kernel32")] static extern int AllocConsole(); static void Main() { AllocConsole(); } If you call AllocConsole before calling any console functions, that should be all you need. Otherwise you need to also manually set up stdout and friends. FreeConsole is the opposite of AllocConsole, and is used to get rid of the console. Link to comment https://www.neowin.net/forum/topic/904788-c-adding-a-console-window-in-a-windows-app/#findComment-592672054 Share on other sites More sharing options...
0 still1 Posted May 26, 2010 Share Posted May 26, 2010 using System.Runtime.InteropServices; [DllImport("kernel32.dll", EntryPoint = "AllocConsole", SetLastError = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] private static extern int AllocConsole(); AllocConsole(); Console.WriteLine("Hello World!"); // outputs to console window Link to comment https://www.neowin.net/forum/topic/904788-c-adding-a-console-window-in-a-windows-app/#findComment-592672090 Share on other sites More sharing options...
0 boogerjones Posted May 26, 2010 Share Posted May 26, 2010 Wouldn't it make more sense for a GUI app to have a dialog/form/whatever with a textbox that you write to instead? Is there something about the console that you specifically need? If you're just trying to "check what you're doing," I think allocating a console is inappropriate. Especially since the Windows console hasn't changed since Windows 98 It's usually better to tell us what goal you're trying to achieve. Lots of people use the wrong tool for the job. Link to comment https://www.neowin.net/forum/topic/904788-c-adding-a-console-window-in-a-windows-app/#findComment-592672442 Share on other sites More sharing options...
0 hdood Posted May 26, 2010 Share Posted May 26, 2010 The console is a quick and useful way of outputting debug messages. Link to comment https://www.neowin.net/forum/topic/904788-c-adding-a-console-window-in-a-windows-app/#findComment-592672852 Share on other sites More sharing options...
0 the_architect Posted May 26, 2010 Share Posted May 26, 2010 The console is a quick and useful way of outputting debug messages. Check out the Debug.Writeline method if you are using Visual Studio, this is an easy way of outputting debug messages http://msdn.microsoft.com/en-us/library/system.diagnostics.debug.writeline.aspx Link to comment https://www.neowin.net/forum/topic/904788-c-adding-a-console-window-in-a-windows-app/#findComment-592672980 Share on other sites More sharing options...
0 hdood Posted May 27, 2010 Share Posted May 27, 2010 Check out the Debug.Writeline method if you are using Visual Studio, this is an easy way of outputting debug messages http://msdn.microsoft.com/en-us/library/system.diagnostics.debug.writeline.aspx I do not write managed code, but presumably it is equivalent to the native debugging functions, which means you actually have to have a debugger attached in order to see the output. Sometimes you just want to display debug messages without the need for that. Link to comment https://www.neowin.net/forum/topic/904788-c-adding-a-console-window-in-a-windows-app/#findComment-592673186 Share on other sites More sharing options...
0 ReDwAvE Posted May 27, 2010 Share Posted May 27, 2010 Easy, Just go to the property of the project and make the Application Type : Console Application and Writes Console.WriteLine() :) Link to comment https://www.neowin.net/forum/topic/904788-c-adding-a-console-window-in-a-windows-app/#findComment-592674266 Share on other sites More sharing options...
0 Rudy Posted May 27, 2010 Share Posted May 27, 2010 Easy, Just go to the property of the project and make the Application Type : Console Application and Writes Console.WriteLine() :) That's not what he wants. His application is NOT a console application but he still wants to send text to a console. A solution has already been posting anyway Link to comment https://www.neowin.net/forum/topic/904788-c-adding-a-console-window-in-a-windows-app/#findComment-592675822 Share on other sites More sharing options...
0 klay Posted May 28, 2010 Share Posted May 28, 2010 That's not what he wants. His application is NOT a console application but he still wants to send text to a console. A solution has already been posting anyway From the smiley face above you should have realized he was joking. Link to comment https://www.neowin.net/forum/topic/904788-c-adding-a-console-window-in-a-windows-app/#findComment-592677728 Share on other sites More sharing options...
0 Rudy Posted May 28, 2010 Share Posted May 28, 2010 From the smiley face above you should have realized he was joking. Even with the smiley face it doesn't seem like he's joking... Link to comment https://www.neowin.net/forum/topic/904788-c-adding-a-console-window-in-a-windows-app/#findComment-592679760 Share on other sites More sharing options...
0 Joddie Posted May 29, 2010 Share Posted May 29, 2010 Check out the Debug.Writeline method if you are using Visual Studio, this is an easy way of outputting debug messages http://msdn.microsoft.com/en-us/library/system.diagnostics.debug.writeline.aspx Use this instead of console, visual studio will then output this for you internally instead of having one extra window spawning for your console, that also goes away if your program crashes. If you need to read debug-output from deployed applications or similar have a look on Log4Net(http://logging.apache.org/log4net/index.html) that allows you to configure exactly how you want your debug lines to be output (console/debug, file, to server etc) Link to comment https://www.neowin.net/forum/topic/904788-c-adding-a-console-window-in-a-windows-app/#findComment-592682990 Share on other sites More sharing options...
0 +Matthew S. Subscriber² Posted May 30, 2010 Subscriber² Share Posted May 30, 2010 Your not writing managed code but you are using C# :/ Link to comment https://www.neowin.net/forum/topic/904788-c-adding-a-console-window-in-a-windows-app/#findComment-592685102 Share on other sites More sharing options...
0 Rudy Posted May 31, 2010 Share Posted May 31, 2010 Your not writing managed code but you are using C# :/ He might not understand what "managed" code is Link to comment https://www.neowin.net/forum/topic/904788-c-adding-a-console-window-in-a-windows-app/#findComment-592687420 Share on other sites More sharing options...
0 hdood Posted May 31, 2010 Share Posted May 31, 2010 Your not writing managed code but you are using C# :/ Are you talking to me? I do not write managed code in C# or any other language, but I can still guess the answer to simpler questions. I said this to make it clear that I had no expertise and was guessing that it was equivalent to certain native APIs. I was saying that a console can be useful because you sometimes want to output certain information to something other than a debugger. The two complement each other, it's not one or the other. Link to comment https://www.neowin.net/forum/topic/904788-c-adding-a-console-window-in-a-windows-app/#findComment-592688010 Share on other sites More sharing options...
0 +Matthew S. Subscriber² Posted May 31, 2010 Subscriber² Share Posted May 31, 2010 Are you talking to me? I do not write managed code in C# or any other language, but I can still guess the answer to simpler questions. I said this to make it clear that I had no expertise and was guessing that it was equivalent to certain native APIs. I was saying that a console can be useful because you sometimes want to output certain information to something other than a debugger. The two complement each other, it's not one or the other. Ah was somehow confusing you with the OP :p :whistle: *sneaks out the back door* Link to comment https://www.neowin.net/forum/topic/904788-c-adding-a-console-window-in-a-windows-app/#findComment-592688130 Share on other sites More sharing options...
Question
NotSoSmartGuy
Basically I have a windows app and would like to add a console window where I can output Console.WriteLine("SSSSSSSSSSSSSSSS");
Link to comment
https://www.neowin.net/forum/topic/904788-c-adding-a-console-window-in-a-windows-app/Share on other sites
17 answers to this question
Recommended Posts