Thoughts From My Life
May
01

Win32 Application and Logging To The Console

Written by Neil Galloway
 

I have been writing demo applications using OpenGL recently in C++. I documented how to set up the environment and create a project in my article OpenGL and Visual Studio Express 2008. I started out by writing the application as a Win32 application. This was a problem though.

When you are doing it in a Win32 project instead of a Win32 Console project it makes it very hard to do simple debugging using print statements. If you are like me, I like to scatter prinf or cout statements through different parts of my code so I can trace the progress and examine variables during development. It makes it very easy.

If you use these statements in a Win32 project however, this output does not get printed out to the console or anywhere for that matter. It is just eaten and no errors are incurred.

My Solution to Logging On Win32 Projects

The correct solution, which I didn't do, is to create a logging interface. Either create a separate dialog window that you can write your statements to or have it write to a file. This way, you might be able to cover off your logging system at the same time (if your application needs it).

What I actually did was another story. I switched my project to a Win32 console application. This gives you just the regular main method for your application and dumbs it down a bit. You also don't need to include the windows.h header file. The catch is that you must use the OpenGL Utility Toolkit ... glut to create your windows for drawing your OpenGL demos in. I wrote about it in my OpenGL and Visual Studio Express 2008 tutorial.

If you enjoyed this post, then make sure you subscribe to my RSS feed or subscribe for email updates. Only one email a day and only if there was a new post.

Virus and Spyware Removal Service

Digg!

Related Posts

Getting Frets On Fire Working On Vista
OpenGL and Visual Studio Express 2008
Patching NDS Homebrew With DLDI
Getting A Chinese Travel Visa in Canada
Flashback On The Nintendo DS

Email this article

Category: Computers


4 Comments

James Birchall Says:
2008-05-01 09:52:43
It actually doesn't get eaten...it's just that stdout and stderr don't get displayed in the window context because, by default in windows, there's no renderer hooked up to do that. After all, which text area should be "default stdout/stderr displayer"?

When you create a Win32 project, as different from a Console project, you're telling Visual Studio to compile the application as a windows forms based application (complete with Message Pump and NULL stdout/stderr) instead of a console based one (where stdout is rendered on the command line).

You can, however, have your cake and eat it too...

Just implement a secondary stdout/stderr reader that hooks up to your winforms process and pipes stdout/stderr into some text renderer (a text box or whatever).

Jay Kint Says:
2008-05-19 23:59:08
You might want to check out the AllocConsole Win32 API. Using it you can compile as a Windows application (using WinMain) and still have a console that you can output to. In your case, making a console one of the logging option is a good alternative, so that way logging output could go to the console and/or a file.

Graham Says:
2008-09-26 11:42:17
Or use OutputDebugString and visual studio will pick it up.

anand Says:
2008-10-02 21:17:57
hi

Add a Comment

Note: Comments will be visible after they have been moderated.
Name:

Email: (Never made public)

Web Page:
(include http:// or https://)
Comment:


Verification: