#include <windows.h>
#include <strsafe.h>
#include <comdef.h>
#define _DEBUG_BUF_SIZE_ 1048
static char _buf_[_DEBUG_BUF_SIZE_];
class trace_impl
{
public:
trace_impl(const char* file,size_t line):file_(file),line_(line)
{
}
inline void operator() (const wchar_t* format,...) const
{
char msg[_DEBUG_BUF_SIZE_];
wchar_t buf[_DEBUG_BUF_SIZE_*2];
va_list args;
va_start(args, format);
StringCbVPrintfW(buf,_DEBUG_BUF_SIZE_, format, args);
//OutputDebugStringW(buf);
va_end(args);
StringCbPrintfA(msg,_DEBUG_BUF_SIZE_," in %s(%d)",file_,line_);
//StringCchPrintfW
_bstr_t t;
t = buf;
t += msg;
OutputDebugStringW((const wchar_t*)t);
}
private:
const char* file_;
size_t line_;
};
#ifdef _DEBUG
#define LogView trace_impl(__FILE__,__LINE__)
#else
#define LogView //
#endif
int main(int argc, char* argv[])
{
LogView(L"%s",L"safedebug");
return 0;
}vc6 调试输出行号加强版
最新推荐文章于 2025-09-15 11:46:17 发布
本文介绍了一个在Windows环境下用于输出调试信息的C++实现方案。该方案利用宏定义及模板类实现文件名和行号的自动填充,并通过`OutputDebugStringW`函数将调试信息输出到Windows调试环境中。此外,还提供了如何根据不同编译配置调整输出行为的方法。

774

被折叠的 条评论
为什么被折叠?



