logging debug messages

B

byaarov

How do I display debug messages from a Win32 application project
(visual studio c++). I'd like to print the messages in the output
window of visual studio
 
P

Peter Duniho

How do I display debug messages from a Win32 application project
(visual studio c++). I'd like to print the messages in the output
window of visual studio

Just add a new TraceListener to the Debug.Listeners collection. You can
then write the output of the Debug class wherever you like.
 
B

byaarov

Just add a new TraceListener to the Debug.Listeners collection. You can
then write the output of the Debug class wherever you like.

I just have a simple console application written in C... is there a
simpler way to do this? I remember a while back there was a simple
function like DebugMessage or LogMessage or something like that, which
just wrote the input to the console window of the visual C debugger...
is there still something like that available?
 
D

David Lowndes

I just have a simple console application written in C... is there a
simpler way to do this? I remember a while back there was a simple
function like DebugMessage or LogMessage or something like that, which
just wrote the input to the console window of the visual C debugger...
is there still something like that available?

It sounds like you're looking for OutputDebugString()

Dave
 
P

Peter Duniho

I just have a simple console application written in C... is there a
simpler way to do this? I remember a while back there was a simple
function like DebugMessage or LogMessage or something like that, which
just wrote the input to the console window of the visual C debugger...
is there still something like that available?

I don't understand your question. Your original post, to me, implied that
you had debug messages already in the Output window, and you wanted to
display them somewhere else (like print them, for example).

While OutputDebugString() works in some contexts, it's not the .NET way to
do things. There is a perfectly good, just-as-easy-to-use Debug class
that is available in .NET. If you are simply trying to find out how to
get messages to the Output window in the first place, then Debug.Write()
and Debug.WriteLine() are what you want.

I cannot imagine anything being simpler. OutputDebugString() certainly is
no simpler (though it's not much more complicated either).

If you then also want those messages logged elsewhere somehow, you can add
a TraceListener to the Debug.Listeners collection. Perhaps you don't need
this, but if you do it's simple to add. Assuming you are using the .NET
Debug class in the first place, of course.

Pete
 
D

David Ching

Peter Duniho said:
While OutputDebugString() works in some contexts, it's not the .NET way to
do things. There is a perfectly good, just-as-easy-to-use Debug class
that is available in .NET. If you are simply trying to find out how to
get messages to the Output window in the first place, then Debug.Write()
and Debug.WriteLine() are what you want.

But there is no .NET Debug class available to an MFC program!

-- David
 
P

Peter Duniho

But there is no .NET Debug class available to an MFC program!

So? The OP never said anything about MFC, and this is a .NET Framework
programming newsgroup.

You are grossly mistaken if you are reading this newsgroup for information
about MFC programming topics.

Pete
 
D

David Ching

Peter Duniho said:
So? The OP never said anything about MFC, and this is a .NET Framework
programming newsgroup.

You are grossly mistaken if you are reading this newsgroup for information
about MFC programming topics.

Look at the newsgroups that the thread is posted to.

-- David
 
H

Hans-J. Ude

Peter Duniho said:
So? The OP never said anything about MFC, and this is a .NET Framework
programming newsgroup.

You are grossly mistaken if you are reading this newsgroup for information
about MFC programming topics.

No he isn't. The OP did a crosspost without follow-up.

Hans
 
P

Peter Duniho

Look at the newsgroups that the thread is posted to.

Yes? You'll note that one of them is the
microsoft.public.dotnet.framework newsgroup. Just because someone can't
be bothered to not cross-pollute newsgroups, I'm expected to only answer
if my answer pertains to the *other* newsgroup(s) in the list?

I don't think so.
 
D

David Ching

Peter Duniho said:
Yes? You'll note that one of them is the
microsoft.public.dotnet.framework newsgroup. Just because someone can't
be bothered to not cross-pollute newsgroups, I'm expected to only answer
if my answer pertains to the *other* newsgroup(s) in the list?

I don't think so.

Your other recent posts make you seem like a decent guy, so I'll cut you a
break. I've removed the MFC newsgroup from this answer as you should have
done in yours.

-- David
 
D

David Wilkinson

Peter said:
Yes? You'll note that one of them is the
microsoft.public.dotnet.framework newsgroup. Just because someone can't
be bothered to not cross-pollute newsgroups, I'm expected to only answer
if my answer pertains to the *other* newsgroup(s) in the list?

I don't think so.

Just another example of why cross-posting is almost always a bad idea.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top