Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Gavia

Win32 app with console output

This topic is 5384 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

Hello All, I was just wondering what the best way to get some debugging output is in a win32 app using VC++ .net. I just want to use some printf''s etc so I don''t have to step through and inspect whenever I want to see values. Ideally I''d just like to see the output in the standard debug console. If there is a resource that has this information or any place else I can look, I''d be grateful for the help. Thanks! -Michael

Share this post


Link to post
Share on other sites
Advertisement
You can use the function OutputDebugString, but you will have to do your own formatting. What I mean is that OutputDebugString only takes (const char*), unlike printf which takes (const char*, ...)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I use the following:


namespace DebugConsole
{
void print(char*, ...);
};

void DebugConsole:rint(char* format, ...)
{
static bool first = true;

if (first) {
first = false;
FreeConsole();
AllocConsole();
}

va_list args;
va_start(args, format);
static char buffer[1024];
vsprintf(buffer, format, args);
unsigned long numch;
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), buffer,
strlen(buffer), &numch, NULL);
va_end(args);
}



Then I just call DebugConsole:rint("Pointer is: 0x%x\n", ptr);

There are a ton of other things you can do, but this is the very basic way of doing things. (Search for AllocConsole on msdn.microsoft.com)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Heh, doh. ":" produces a weird smiley...

Share this post


Link to post
Share on other sites
Here''s how I do it:

I have a DebugLog class. If the DEBUG flag is set in the ini file then all debug messages get written to a file, as well as output to the debugger. All my Log.Write() calls are wrapped in an if(DEBUGLOG). I imagine the hundreds of ''if'' statements might be slowing things down a bit by this point, but most of them are in error cases anyway.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!