VC 根据错误码获取错误信息

01.CString GetErrorString(int nErrCode)  
02.{  
03.    CString csErrorInfo;  
04.    LPVOID lpMsgBuf;  
05.    FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,  
06.        NULL, nErrCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&lpMsgBuf, 0, NULL);  
07.    if (lpMsgBuf) {  
08.        csErrorInfo.Format("错误码%d:%s",errCode, lpMsgBuf);  
09.        LocalFree(lpMsgBuf);  
10.    } else {  
11.        ret.Format(L"错误码%d:invalid input errorcode",nErrCode);  
12.    }  
13.    return csErrorInfo;  
14.}  

你可能感兴趣的:(VC++,MFC)