OutputDebugString导致不一致的错误
OutputDebugString causing inconsistent errors
我有一个问题,由于神秘的原因出现和消失。不久前,当我开始这个项目时,我发现了一个相当方便的函数,它允许在VS2010中调试窗口输出。有一段时间效果很好。
现在它不一致地显示错误。这意味着有时代码会编译,有时不会,我不知道下面的代码为什么会导致错误。这看起来几乎是随机的。按compile,error,再按compile而不更改任何内容有时出错有时还好。
这就是错误的样子:
http://clip2net.com/clip/m0/1332710747-clip-29kb.png
无
http://clip2net.com/clip/m0/1332737362-clip-40kb.png
罪魁祸首是OutputDebugString(buf);注释掉该行时没有出现错误。
我想解决这个问题,我只需要一种将文本输出到调试窗口(输出)的方法,并且正在寻找一个简单、稳定的解决方案。或者,也许有一种方法可以让这个功能发挥作用。我有点被卡住了。
如果你能分享你的做法,我将不胜感激。
代码为:
#pragma once
#ifndef _XDEBUG_H_
#define _XDEBUG_H_
#include <stdio.h>
#include <stdarg.h>
#include <ctype.h>
class XDebug
{
public:
static void __cdecl odprintf(const wchar_t *format, ...){
wchar_t buf[4096], *p = buf;
va_list args;
int n;
va_start(args, format);
n = _vsnwprintf(p, sizeof buf - 3, format, args); // buf-3 is room for CR/LF/NUL
va_end(args);
p += (n < 0) ? sizeof buf - 3 : n;
while ( p > buf && isspace(p[-1]) )
*--p = ' ';
*p++ = 'r';
*p++ = 'n';
*p = ' ';
OutputDebugString(buf);
}
};
#endif
OutputDebugString
是在Windows.h中定义的。您需要包含该标头才能使用该函数。
看起来你还没有完成:
#include <windows.h>
OutputDebugString
函数是Windows API的一部分。
相关文章:
- 大于65535的C++数组[size]引发不一致的溢出
- 在 C++(和 C)中进行类型转换时明显不一致
- 填充上编译器生成的复制构造函数之间的不一致
- 犰狳的 print() 方法和 cout 在从 Rcpp 调用时顺序不一致
- CreateDIBSection为同一图像返回不一致的位图位值
- 在 Qml 中从 QSqlTableModel 中删除单行时视图不一致
- 模板参数推导不一致
- 试图修复一个错误,该错误不会让我开始编程其余部分
- 声明中不一致的no是否违反ODR?
- DLL 注入不断失败,出现不一致的错误
- 元数据操作失败LNK2022错误 (8013118D):重复类型中的布局信息不一致 (选择设备参数):(0x020002
- C++的 istream::eof() 的不一致是规范中的错误还是实现中的错误?
- C++ 对指针的引用:不一致的段错误
- 形成两组的并集似乎给出了错误且不一致的答案
- OutputDebugString导致不一致的错误
- 字符串流错误不一致
- c++字符串操作给我奇怪的/不一致的/错误的结果
- 如何纠正不一致的未解决外部错误
- 运行时出现不一致的分段错误
- 收到错误:将我的 c++ 代码从 Linux 移植到 android 时'asm'中的操作数约束不一致