Re: [unclassified] Re: NULL Device ?

"Byron Guernsey" <byron-s/[email protected]> Tue, 25 Oct 2005 20:16:24 -0400
Newsgroups gmane.comp.windows.ce.freeware
Message-ID <001501c5d9c2$80202400$0a00a8c0@antigravity>
I typically write my own method or use one I found in some free source 
dxutil (wish I remembered the author of that or could give a reference to 
where I found the original code) that takes variable arguments and formats a 
string and writes it to the debug console using OutputDebugString().  Here 
is one that I'm using currently:

VOID    DXUtil_Trace( TCHAR* strMsg, ... );

#if defined(DEBUG) | defined(_DEBUG)
    #define DXTRACE           DXUtil_Trace
#else
    #define DXTRACE           sizeof
#endif

#ifdef TRACE_ODS
VOID DXUtil_Trace( TCHAR* strMsg, ... )
{
#if defined(DEBUG) | defined(_DEBUG)
    TCHAR strBuffer[512];

    va_list args;
    va_start(args, strMsg);
    _vsntprintf( strBuffer, 512, strMsg, args );
    va_end(args);

    OutputDebugString( strBuffer );
#else
    UNREFERENCED_PARAMETER(strMsg);
#endif
}
#else
VOID DXUtil_Trace( TCHAR* strMsg, ... )
{
#if defined(DEBUG) | defined(_DEBUG)
    TCHAR strBuffer[512];

    va_list args;
    va_start(args, strMsg);
    _vsntprintf( strBuffer, 512, strMsg, args );
    va_end(args);

 FILE *fptr = fopen("\\dxtrace.log", "a");
 if(fptr != NULL) {
  fwprintf(fptr, (TCHAR *) strBuffer);
  fclose(fptr);
 }
#else
    UNREFERENCED_PARAMETER(strMsg);
#endif
}
#endif


Then you define DEBUG or _DEBUG to turn on tracing during compilation 
(disabling all the logging code).  You can define TRACE_ODS to have the 
tracing go through OutputDebugString (which should display it in an attached 
debugger), or don't define it to have it saved to a file, right now 
\dxtrace.log

You use the macro:  DXTRACE(_T("Log your values and other stuff here 
%s(%d)"), strValue, iValue);

If you wanted, you could easily redefine this code to switch between 
OutputDebugString and a file at runtime by using a function pointer. 
OutputDebugString() has little overhead when a debugger isn't capturing its 
output.

Byron

----- Original Message ----- 
From: ""Thilo Köhler"" <[email protected]>
To: <[email protected]>
Sent: Tuesday, October 25, 2005 9:46 AM
Subject: [unclassified] Re: [wince-devel] NULL Device ?


I need it for the following:

I have a program that does a lot of debug output to stdout.
Because some versions of WinCE have no console,
some have, I wrote a little function that opens a file and
defines "stdout" and "stderr" as the file handle variable.
So I have all debug output in a text file.

Now I want to compile a version of this program, that does
no output at all, because the device does not like file access
(it slows down a lot when there are many programs write
to files).

Greetings,

Thilo


-- 
Lust, ein paar Euro nebenbei zu verdienen? Ohne Kosten, ohne Risiko!
Satte Provisionen für GMX Partner: http://www.gmx.net/de/go/partner

[Non-text portions of this message have been removed]





Yahoo! Groups Links










------------------------ Yahoo! Groups Sponsor --------------------~--> 
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/W4wwlB/TM
--------------------------------------------------------------------~->