Link to home
Start Free TrialLog in
Avatar of tao_shaobin
tao_shaobin

asked on

what is the equivalent win32 function for MFC TRACE?

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
Avatar of laeuchli
laeuchli

Yes, see the macros (_RPT# and family) in crtdbg.h.
I'm pretty sure you can also use OutputDebugString, although there are no 'printf-style' parameters to it.
OutputDebugString()
Oops ,
Don't read the comment because the 1 minute in between.
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
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.
o,okay...
Btw:
JMu,are you clear with AM.PM ?
Regards
W.Yinan
AM is Above Moon and PM is Post Millennium, right?
Avatar of tao_shaobin

ASKER

Thanks for your advices.  Whom should I give credit to?

ASKER CERTIFIED SOLUTION
Avatar of JMu
JMu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yep, JMu definitely deserves the points.
->AM is Above Moon and PM is Post Millennium, right?
========================
Why are you so funny ?
very funny you are,hahaha...