On Mon, 20 Mar 2000 [EMAIL PROTECTED] wrote:
> On 17 Mar, Chad Loder wrote:
> > How about a TRACE macro that compiles out in release builds? I have
> > a decent debugging framework for Windows that I could check in. I don't
> > know what the Linux equivalent is to the Win32 OutputDebugString().
>
> Sure, can we check it out??
>
> The linux eq of OutputDebugString() is printf(). :-)
Yuck! I can imagine me trying to use gdb while all this crap is going
to the screen. :)
Here it is (an unabashedly Win32 specific implementation, but it would
be trivial to add other operating systems):
#ifdef _DEBUG
#ifdef UNICODE
# define DebugOut DebugOutW
# define DebugOutBytes DebugOutBytesW
#else
# define DebugOut DebugOutA
# define DebugOutBytes DebugOutBytesA
#endif
__inline void DebugOutW (LPCWSTR lpszFmt, ...)
{
WCHAR szBuff[1024];
va_list vargs;
va_start (vargs,lpszFmt);
wvsprintf (szBuff, lpszFmt, vargs);
va_end (vargs);
OutputDebugStringW (szBuff);
}
__inline void DebugOutA (LPCSTR lpszFmt, ...)
{
// non-wide string, so convert it, then output it
CHAR szBuff[1024];
va_list vargs;
int len = 0;
WCHAR* wideBuff = 0;
va_start (vargs,lpszFmt);
len = vsprintf (szBuff, lpszFmt, vargs);
va_end (vargs);
OutputDebugStringA(wideBuff);
}
__inline void DebugOutErrorMsg(LPCTSTR msg, DWORD dwSysErr)
{
LPVOID lpMsgBuf = 0;
DWORD fmtResult = FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
dwSysErr,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
// if we could not figure out a windows string, then we
// use generic text
if (0 == fmtResult)
{
if (lpMsgBuf != 0)
LocalFree( lpMsgBuf );
lpMsgBuf = _T("Unkown error");
}
// Display the string.
DebugOut(_T("%s : %u: %s)"), msg, dwSysErr, lpMsgBuf);
// Free the buffer.
if (0 != fmtResult)
LocalFree( lpMsgBuf );
}
// print out the standard message for the given error code to the
// debug stream
__inline void DebugErrorString(DWORD dwSysErr)
{
DebugOutErrorMsg(_T(""), dwSysErr);
}
#else
// let these macros compile out in release builds
#define DebugOut
#define DebugOutA
#define DebugOutW
#define DebugErrorString(dwSysErr)
#define DebugOutErrorMsg(msg, dwSysErr)
#endif
_______________________________________________
[EMAIL PROTECTED]
http://www.freeamp.org/mailman/listinfo/freeamp-dev