|
在MFC程序中有TRACE等一系列的宏可以輸出調(diào)試信息, 但是其他的地方不能用了, 下面這個小程序測試了怎么輸出調(diào)試信息,
// Test_ErrorCode.cpp : 定義控制臺應用程序的入口點。
//
#include "stdafx.h"
#include <Windows.h>
#include <stdio.h>
#include <stdarg.h>
#include <ctype.h>
void __cdecl odprintf(const char* fmt, ...)
{
char buf[4096], *p = buf;
va_list args;
va_start(args, fmt);
p += vsnprintf_s(p, sizeof(buf), _TRUNCATE, fmt, args);
va_end(args);
while ( p > buf && isspace(p[-1]) )
*--p = '\0';
*p++ = '\r';
*p++ = '\n';
*p = '\0';
OutputDebugStringA(buf); //OutputDebugString
}
int _tmain(int argc, _TCHAR* argv[])
{
odprintf("Testing...");
HANDLE hFile = CreateFile(_T("c://a.txt"), 0, 0, NULL, OPEN_EXISTING,0,NULL);
odprintf("Retrieve last error code = %ld", ::GetLastError());
return 0;
}
|
|