Painless Debug Console

I have had the pleasure of writing a pretty large number of apps for Windows. There are a few things that I have learned, over time, that have really helped to improve my productivity. One of those things is a basic debug console.

Typically, a debug console is handy – go figure – while you’re debugging. Once you have a release quality build, you won’t want the debug console hanging around anymore.

This is one of those snippets of code that, while brutally simple, is rather non-obvious and most people don’t know of.

    freopen("CONOUT$", "wt", stdout);

    SetConsoleTitle(L"MyApp : Debug Console");


    printf(" MyApp Debug Consolen");

Basically this code, if debug trace preprocessor is set (add MYAPP_DEBUG_TRACE to your preprocessor settings), will allocate a nice little debug console window, change the title, set the font colors, and redirect standard output to the console.

This snippet of code can be added to any Win32 application, and gives you the instant capability to spit out oodles of delicious debugging data. Typically, I combine this method with something along these lines:

#ifdef __cplusplus
inline void null_func(char *format, ...) { }
#define DbgEmpty null_func
#define DbgEmpty { }
/* Debug Trace Enabled */
#define DbgPrintf printf
/* Debug Trace Disabled */
#define DbgPrintf DbgEmpty

Now, you can use the function “DbgPrintf” just as if it was “printf” – and it will compile away to nothing in a release mode build!

Bacon McFlurry

McDonalds officially unveiled yet another new flavor of McFlurry this weekend. The latest addition to the McDonalds menu combines the popular McFlurry dessert with the salted and smoked meat from the back and sides of a pig.

Executive Vice President Claire Babrowski says “We were just looking for something new. We wanted to combine dessert and breakfast, and I think we accomplished that.”