2

使用 Visual Studio 2008,我一直在输出窗口中看到此错误:

_CrtDbgReport:字符串太长或 IO 错误

我有很多TRACE宏分散在我的代码中,用于转储有关错误条件的信息:文件路径、行号、错误等。我需要追踪此错误的来源,因为它可能是它试图转储到的信息输出窗口太长。TRACE宏可以接受的字符串的最大长度是多少?这是我通常如何使用此宏的示例:

TRACE(_T("CreateNotifyWindow : Failed to create handle for notify window thread.\r\n\tError: %d\r\n\tFile: %s\r\n\tLine: %d\r\n"), ::GetLastError(), _T(__FILE__), __LINE__);

任何想法将不胜感激。谢谢。

4

2 回答 2

4

最终我敢打赌,问题是将对象字符串而不是 string.c_str() 传递给宏。TRACE 使用可变参数传递给最终调用 vsnprintf() 家族中的某些东西进行%s处理的东西。它不能处理对象,因为C不能。

由于实现,OutputDebugString 的最大长度为4K 字节减去一个分数

于 2011-04-11T20:52:08.027 回答
2

你遇到了和我一样的麻烦。我在网上得到了这个问题的答案,我查了一下,效果很好。

// Inside your main header like stdafx.h, add the following include directive

#include <locale.h>


// And inside your main implementation such as InitInstance()
// of your CWinApp derived application class,
// you can put the following locale designation function.

#ifdef _DEBUG
_tsetlocale(LC_ALL, _T("korean")); // you should set the country code of yours
#endif // _DEBUG

现在,您可以在调试输出窗口中看到正确的宽字符串。祝你好运!

于 2011-08-28T11:23:54.313 回答