How to write to a console window from a windows application?

To do this programmatically, you can PInvoke the appropriate Win32 console functions (e.g. AllocConsole to create your own or AttachConsole to use another process’s) from within your own code. This way you have the best control over what actually happens.

If you are OK with having a console window open alongside your other UI for the full lifetime of your process, you can simply change the project properties from within Visual Studio and choose “Console Application”, simple as that:

VS Project settings

Leave a Comment