Visual Studio 输出窗口错误 - C++

发布于 2024-10-31 19:17:40 字数 483 浏览 9 评论 0原文

使用 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__);

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

Using Visual Studio 2008, I keep seeing this error in the output window:

_CrtDbgReport: String too long or IO Error

I have a lot of TRACE macros scattered throughout my code used to dump information about error conditions: file path, line number, error, etc. I need to trace down the source of this error because it may be that information it is trying to dump to the output window is too long. What is the maximum length of the string the TRACE macro can accept? Here is an example of how I typically use this macro:

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__);

Any thoughts would be appreciated. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遇见了你 2024-11-07 19:17:40

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

由于实现原因,OutputDebugString 的最大长度为 4K 字节减去小数

Ultimately I'll bet the problem is passing an object string instead of string.c_str() to the Macro. TRACE uses variadic argument passing to, ultimately, something that calls something in the vsnprintf() family for %s processing. It cannot deal with objects because C can not.

The maximum length for OutputDebugString is 4K bytes minus a fraction, due to the implementation.

浅紫色的梦幻 2024-11-07 19:17:40

你和我遇到了同样的麻烦。
我在网上找到了这个问题的答案
我检查了一下,效果非常好。

// 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

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

You've got in the same trouble as I did.
I got the answer to this question on the web, and
I checked it out, which worked very well.

// 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

Now, you can see the correct wide character string on your debug output window.
Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文