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. 🙂
4 replies on “C++ OutputDebugString()”
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.
LikeLike
Another way to output debug information is using marco TRACE
TRY that.
LikeLike
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.
LikeLike
sounds like you should blog about it.
LikeLike