C++ OutputDebugString()

I have programmed in many different languages, and as much as I can remember, one of the best things you can do is write debug ouput to an output window

VB 6.0 – Debug.Print “Debug Output”

.NET – System.Diagnostics.Debug.WriteLine(“Debug Output”);

and recently I have been doing some VC++ programming, and I didn’t know how to output to the output window, so I decided to figure that one out. Came across OutputDebugString();

Now I can stop throwing MessageBox’s all over the place when trying to debug something. What is cool to is that there are utlities that will read the messages from a debug output, like SysInternals Microsoft’s DebugView

One thing that is kind of weird, is that even if you build in Release mode, debug messages still come out. You could and probably should I am guessing wrap then OutputDebugString() in a DEBUG define, or even better IsDebuggerPresent()

Anyways, I’m glad to have taken 2 minutes out of my coding to find this instead of going along thinking there aren’t easier ways. :)

Advertisements

4 thoughts on “C++ OutputDebugString()”

  1. Another bonus to using OutputDebugString is that it doesn’t change the state of your application like message boxes do. When you start throwing message boxes around, you monkey with all sorts of things (focus, timing, etc) that can have a major effect on what it is you’re trying to debug. But when you’re just writing out to the debug logger, there’s such a minimal impact that it’s generally safe.

    Like

  2. What is the point of this “article”? You don’t give any examples of how to use OutputDebugString. Have you tried it? It’s a giant pain in the ass, because it doesn’t handle formatting strings and it insists on wide characters. You can’t use regular C strings, so sprintf isn’t an option. You have to find some way of getting your message into a LPCWSTR, which so far even wsprintf isn’t viable for. Inexcusable.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s