Sign in to follow this  

Win32 app with an output console?

This topic is 4837 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I very recently got a PC and VC++, and have been porting my engine from Mac OS X to Win32. As a debug feature, I do lots of printfing and cout <<ing to stdout, which on the Mac in Xcode shows up in the program's run log (very convenient!). On the win32 side, I see no such feature, and printfing and cout << both do nothing that I can see. :( The project I created in VC++ was a "Win32 Application," and not a "Win32 Console Application," as I didn't realize that the Win32 app one would have NO console whatsoever, as opposed to it just not being console-based. How can I get an output console that stdout will go to? Thanks, Dylan

Share this post


Link to post
Share on other sites
Try this:

Write debug messages to a console

Alternatively, if you want to still use cout, use that and place freopen("CONOUT$","r+",stdout) in the init code, or similar. Google will help.

I've done it before, so it's completely possible :)

[EDIT]
A simple example:



DebugConsole::DebugConsole()
{
if (AllocConsole()!=TRUE)
{
//Throw exception
}else{
//Redirect standard output to console
freopen("CONOUT$","w",stdout);
freopen("CONOUT$","w",stderr);
freopen("CONIN$","w",stdin);
std::cout<<"Console opened correctly, awaiting debug messages"<<std::endl;
}
}

DebugConsole::~DebugConsole()
{
if (FreeConsole()!=TRUE)
{
//Throw exception
}
}



Simple as that. Place a global DebugConsole somewhere (bad practice, but only use std::cout outside of contructors/destructors anyhow).
[/EDIT]

Share this post


Link to post
Share on other sites
Excellient, thank you very much.

All is right with the world now, except that the console goes away when the app exits, so it's hard to see what was there :(

But nevertheless, it works and that is good :D

Share this post


Link to post
Share on other sites
Damnit! That is so cool! I want to do this now with the console! Better yet, I should add a command line argument that enables this console to be show and puts the program in debug mode.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
running the program from within a console would work right? wouldn't it just write to the console?

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
running the program from within a console would work right? wouldn't it just write to the console?


Unfortunately, no. :
Thanks a TON, CloudNine. I got it all working now :)

Share this post


Link to post
Share on other sites

This topic is 4837 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this