TRACE-messages how ?
i would like to show simple trace messages in VC++6,
like printf("trace1"); in the output window on bottom.
how can it be done?
Karl - Blueskied Games | my german site: Gratis Spiele
In general, just use OutputDebugMessage(), it will send all messages to the connected debugger, in case of VC, the Debug window on the bottom of the screen.
But be warned that this only works when running the program inside the IDE using the debugger (F5; not ctrl-f5).
I''d recommend you to also use a log file, that will allow you to get access to debugging messages if people not having VC++ test your program.
For myself, I''ve written a little debugging library which has printf() like commands that will automatically written into a log file and the debugger. If used in C++ (works also in C), it contains a general exception class from which custom exceptions can be derived, allowing complete logging of exceptions, but also handling them in a single catch().
www.LunaticSystems.de/tfxdebug.zip
-Markus-
But be warned that this only works when running the program inside the IDE using the debugger (F5; not ctrl-f5).
I''d recommend you to also use a log file, that will allow you to get access to debugging messages if people not having VC++ test your program.
For myself, I''ve written a little debugging library which has printf() like commands that will automatically written into a log file and the debugger. If used in C++ (works also in C), it contains a general exception class from which custom exceptions can be derived, allowing complete logging of exceptions, but also handling them in a single catch().
www.LunaticSystems.de/tfxdebug.zip
-Markus-
Professional C++ and .NET developer trying to break into indie game development.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
there are some codes,which use TRACE0("tracemsg");
how can i use this too ?
how can i use this too ?
Karl - Blueskied Games | my german site: Gratis Spiele
September 26, 2000 11:17 AM
I believe the TRACEx macros are for use when you have an application that has MFC support. You can build your own however, like Cygon pointed out and call it whatever you like.
September 26, 2000 12:53 PM
The TRACEn() macro is a legacy version of TRACE that allows you to specify the number of extra parameters supplied. It''s usually better to use the TRACE() macro nowadays.
If you''d like your own TRACE replacement outside of MFC try something like the following:
debug.h
#include stdarg.h // Need to put in angled brackets
extern void __DebugTraceString( const char *pszFormat, ... );
#ifdef _DEBUG
#define TRACE __DebugTraceString
#else
#define TRACE TRUE ? ( void )0 : __DebugTraceString
#endif //def _DEBUG
Inside debug.cpp implement the following code...
void __DebugTraceString( const char *pszFormat, ... )
{
char szBuffer[ 1024 ];
va_list args;
va_start( args, pszFormat );
vsprintf( szBuffer, pszFormat, args );
OutputDebugString( szBuffer );
va_end( args );
}
This will only be active during debug builds, and will be ignored during release builds.
Hope that helps you some...
n!
If you''d like your own TRACE replacement outside of MFC try something like the following:
debug.h
#include stdarg.h // Need to put in angled brackets
extern void __DebugTraceString( const char *pszFormat, ... );
#ifdef _DEBUG
#define TRACE __DebugTraceString
#else
#define TRACE TRUE ? ( void )0 : __DebugTraceString
#endif //def _DEBUG
Inside debug.cpp implement the following code...
void __DebugTraceString( const char *pszFormat, ... )
{
char szBuffer[ 1024 ];
va_list args;
va_start( args, pszFormat );
vsprintf( szBuffer, pszFormat, args );
OutputDebugString( szBuffer );
va_end( args );
}
This will only be active during debug builds, and will be ignored during release builds.
Hope that helps you some...
n!
And don''t forget about double clicking on messages and you can get sent to the whichever file/line you wish in your code. You need to follow the template you see for compile errors for this to work. This code here demonstrates
That will print out a message and if you double click on it, it will take you to the file/line where the message was executed. This is perfect for error messages. I''d recommend writing a macro that calls your message function (like the post above) but places __FILE__ and __LINE__ automatically.
- Houdini
void DebugMessage(char *message, char *file, int line){ char buffer[1024]; sprintf(buffer, "%s(%d): %s\n", file, line, message); OutputDebugString(buffer);}void somefunc(){ DebugMessage("Here is a message", __FILE__, __LINE__);}
That will print out a message and if you double click on it, it will take you to the file/line where the message was executed. This is perfect for error messages. I''d recommend writing a macro that calls your message function (like the post above) but places __FILE__ and __LINE__ automatically.
- Houdini
- Houdini
September 26, 2000 03:08 PM
Yup thats a handy one
I usually use a macro for that though...
#ifdef _DEBUG
#define DEBUG_MSG( message ) DebugMessage( message, __FILE__, __LINE__ )
#else
#define DEBUG_MSG( message ) {}
#endif //def _DEBUG
So you can just use DEBUG_MSG( "A debug message." );
n!
I usually use a macro for that though...
#ifdef _DEBUG
#define DEBUG_MSG( message ) DebugMessage( message, __FILE__, __LINE__ )
#else
#define DEBUG_MSG( message ) {}
#endif //def _DEBUG
So you can just use DEBUG_MSG( "A debug message." );
n!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement