ProcessErrorMessage(char* ErrorText)


CString strTemp;
char szTemp[128];


strTemp = _T("abckdkfei");
memset( szTemp, 0, sizeof(szTemp) );
strcpy( szTemp, strTemp.GetBuffer(strTemp.GetLength()) );
//===================================================
//
void ProcessErrorMessage(char* ErrorText)
{
	char *Temp = new char[200];
	
	LPVOID lpMsgBuf;
    DWORD ErrCode= GetLastError();
	FormatMessage( 
		FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
		NULL,
		ErrCode,
		MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
		(LPTSTR) &lpMsgBuf,
		0,
		NULL 
		);
	
	sprintf(Temp, "WARNING:  %s Failed with the following error: \n%s\n ErrCode: %d\n", (char*)ErrorText, lpMsgBuf, ErrCode); 
	MessageBox(NULL, Temp, "Application Error", MB_ICONSTOP);
	
	LocalFree(lpMsgBuf);
	delete [] Temp;
}


#include <stdio.h>
#include <stdarg.h>
#include <ctype.h>
void __cdecl ODPrintf(const char *format, ...)
{
	char buf[4096], *p = buf;
	va_list args;
	va_start(args, format);
	p += _vsnprintf(p, sizeof buf - 1, format, args);
	va_end(args);
//	while ( p > buf && isspace(p[-1]) )
//	{
//		*--p = '\0';
		*p++ = '\r';
		*p++ = '\n';
		*p = '\0';
//	}
	OutputDebugString(buf);
}
//在代码中使用它就很简单:  
//odprintf("Cannot open file %s [err=%ld]", fname, GetLastError());


====================================================


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值