Jump to content
  • Advertisement
Sign in to follow this  
PfhorSlayer

Win32 app with an output console?

This topic is 5142 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
Advertisement
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
Just put a


while (Escape is not pressed)
{
}


in the DebugConsole destructor before the console is destroyed. I'll leave the actual implementation up to you and google :)

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
Quote:
Original post by PfhorSlayer
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 :(


Then check this out Console in System Tray

With it after your app closes the messages will still be there.

Helps?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!