From: dmitrykos Date: Wed, 10 Mar 2010 21:47:01 +0000 (+0000) Subject: implemented optional log output to Visual Studio Output window if PA_ENABLE_MSVC_DEBU... X-Git-Tag: pa_stable_v19_20110326_r1647~152 X-Git-Url: https://andrewgundersen.net/repos?a=commitdiff_plain;h=e4c126aab11d455212669998ed69be568eb0de59;p=portaudio implemented optional log output to Visual Studio Output window if PA_ENABLE_MSVC_DEBUG_OUTPUT is defined, this simplifies debugging of external process if Visual Studio is attached to process --- diff --git a/src/common/pa_debugprint.c b/src/common/pa_debugprint.c index f05f40e..7ee8f7f 100644 --- a/src/common/pa_debugprint.c +++ b/src/common/pa_debugprint.c @@ -53,17 +53,21 @@ @todo Consider reentrancy and possibly corrupted strdump buffer. */ - #include #include #include "pa_debugprint.h" +// for OutputDebugStringA +#if defined(_MSC_VER) && defined(PA_ENABLE_MSVC_DEBUG_OUTPUT) + #define WIN32_LEAN_AND_MEAN // exclude rare headers + #include "windows.h" +#endif +// User callback +static PaUtilLogCallback userCB = NULL; -static PaUtilLogCallback userCB=0; - - +// Sets user callback void PaUtil_SetDebugPrintFunction(PaUtilLogCallback cb) { userCB = cb; @@ -72,41 +76,51 @@ void PaUtil_SetDebugPrintFunction(PaUtilLogCallback cb) /* If your platform doesn’t have vsnprintf, you are stuck with a VERY dangerous alternative, vsprintf (with no n) - */ - -#if _MSC_VER -/* Some Windows Mobile SDKs don't define vsnprintf but all define _vsnprintf (hopefully). - According to MSDN "vsnprintf is identical to _vsnprintf". So we use _vsnprintf with MSC. */ -#define VSNPRINTF _vsnprintf +#if _MSC_VER + /* Some Windows Mobile SDKs don't define vsnprintf but all define _vsnprintf (hopefully). + According to MSDN "vsnprintf is identical to _vsnprintf". So we use _vsnprintf with MSC. + */ + #define VSNPRINTF _vsnprintf #else -#define VSNPRINTF vsnprintf + #define VSNPRINTF vsnprintf #endif -#define SIZEDUMP 1024 - +#define PA_LOG_BUF_SIZE 2048 void PaUtil_DebugPrint( const char *format, ... ) { + // Optional logging into Output console of Visual Studio +#if defined(_MSC_VER) && defined(PA_ENABLE_MSVC_DEBUG_OUTPUT) + { + char buf[PA_LOG_BUF_SIZE]; + va_list ap; + va_start(ap, format); + VSNPRINTF(buf, sizeof(buf), format, ap); + buf[sizeof(buf)-1] = 0; + OutputDebugStringA(buf); + va_end(ap); + } +#endif - if (userCB) + // Output to User-Callback + if (userCB != NULL) { - char strdump[SIZEDUMP]; - + char strdump[PA_LOG_BUF_SIZE]; va_list ap; - va_start( ap, format ); - VSNPRINTF( strdump, SIZEDUMP, format, ap ); - strdump[SIZEDUMP-1] = 0; + va_start(ap, format); + VSNPRINTF(strdump, sizeof(strdump), format, ap); + strdump[sizeof(strdump)-1] = 0; userCB(strdump); - va_end( ap ); + va_end(ap); } else + // Standard output to stderr { va_list ap; - va_start( ap, format ); - vfprintf( stderr, format, ap ); - va_end( ap ); - fflush( stderr ); + va_start(ap, format); + vfprintf(stderr, format, ap); + va_end(ap); + fflush(stderr); } - }