Solved

what is the equivalent win32 function for MFC TRACE?

Posted on 2000-02-28
12
333 Views
Last Modified: 2013-12-03
Hi,

In MFC, we can use TRACE as printf to output some varialbles or objects.  Then, what are the similar functions in SDK?  

Thanks,

tao_shaobin
0
Comment
Question by:tao_shaobin
  • 4
  • 3
  • 3
  • +2
12 Comments
 
LVL 5

Expert Comment

by:laeuchli
ID: 2565592
Yes, see the macros (_RPT# and family) in crtdbg.h.
0
 
LVL 2

Expert Comment

by:bbousquet
ID: 2565611
I'm pretty sure you can also use OutputDebugString, although there are no 'printf-style' parameters to it.
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2565618
OutputDebugString()
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2565628
Oops ,
Don't read the comment because the 1 minute in between.
0
 
LVL 1

Expert Comment

by:JMu
ID: 2565657
Well, I had to change my propesed answer to a comment because I was slow (no answers when I started writing my answer). Too long answer or am I a slow writer?

--------------

Is there any? Don't know. Anyway here's my TRACE.

// in header

#ifdef _DEBUG
      void TRACE( LPCTSTR format, ... );
#else
      #define TRACE
#endif

#define __countof(array) (sizeof(array)/sizeof(array[0]))

// in source code
#ifdef _DEBUG
void TRACE( LPCTSTR format, ... )
{
      va_list args;
      va_start( args, format );

      int length;
      TCHAR buffer[ 512 ];

      length = _vsntprintf( buffer, __countof(buffer), format, args );

      // was there an error? was the expanded string too long?
      ASSERT( length >= 0 );

      if ( length > 0 )
      {
            //printf( buffer );
            OutputDebugString( buffer );
      }

      va_end( args );
}
#endif

JMu
0
 
LVL 2

Expert Comment

by:bbousquet
ID: 2567120
Wyn, I think JMu's answer is way better than yours. I suggest you retract your answer. [I had written it as a comment because OutputDebugString does not do what the TRACEx macro series do]

JMu's answer is a complete one.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 5

Expert Comment

by:Wyn
ID: 2577391
o,okay...
Btw:
JMu,are you clear with AM.PM ?
Regards
W.Yinan
0
 
LVL 1

Expert Comment

by:JMu
ID: 2577706
AM is Above Moon and PM is Post Millennium, right?
0
 
LVL 1

Author Comment

by:tao_shaobin
ID: 2587526
Thanks for your advices.  Whom should I give credit to?

0
 
LVL 1

Accepted Solution

by:
JMu earned 50 total points
ID: 2587627
Me.
0
 
LVL 2

Expert Comment

by:bbousquet
ID: 2588039
Yep, JMu definitely deserves the points.
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2595308
->AM is Above Moon and PM is Post Millennium, right?
========================
Why are you so funny ?
very funny you are,hahaha...
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video discusses moving either the default database or any database to a new volume.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now