ProcessErrorMessage(char* ErrorText)

来源:互联网 发布:东升博展集团 知乎 编辑:程序博客网 时间:2024/06/10 00:12
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());====================================================


原创粉丝点击