in

DavidJBerman.com

An online community of advocacy and support of entrepreneurial ventures

C sharp (C#)

How to create a console window for a Windows Forms application

Suppose you are writing a GUI application for Windows and you want to be able to debug your applicaiton by sending console output to a console window that opens only if you pass a certain command line argument or are compiled in debug mode.  Console.WriteLine sends your output to nowhere very fast.  If you want to have a console window, here is how you do it:

 

Inside one of your classes insert this reference to the AllocConsole method in kernel32.dll:

[DllImport("kernel32.dll")]
public static extern Int32 AllocConsole();

Now just call MyClass.AllocConsole() if you want a console for output and voila, there you go!  All output to Console now appears in your console window.

 

 

Published Aug 06 2007, 03:38 PM by Dave
Filed under:

Comments

No Comments

Leave a Comment

(required)  
(optional)
(required)  
Add

About Dave

David Berman is an Entrepreneur and Business Systems Analyst Consultant. Through leadership, business process reengineering and strategic planning David transforms companies, enabling them to become more profitable, respond faster to changes in any industry, and become more competitive. David also manages inhouse or internationally outsourced software development projects when custom solutions are needed.
Copyright 2006 David J. Berman, all rights reserved.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems