//------------------------------------------------------------------------ // ShowErrorMsg() // - 获取对应Windows错误码的详细中文解释 // dwErrCode - 错误码 // pszBuf - 获取到的中文解释 // iBufLen - pszBuf的长度 //------------------------------------------------------------------------ int ShowErrorMsg(DWORD dwErrCode, char* pszBuf, int& iBufLen) { DWORD dwFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS; HMODULE hModule = NULL; if ( dwErrCode>=12001 && dwErrCode<=12156 ) { hModule = LoadLibraryEx(TEXT("wininet.dll"), NULL, LOAD_LIBRARY_AS_DATAFILE); if ( hModule != NULL ) { dwFlags |= FORMAT_MESSAGE_FROM_HMODULE; } } DWORD dwRet = -1; LPVOID lpMsgBuf = NULL; if ( 0 != FormatMessage(dwFlags, hModule, dwErrCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, NULL) ) { if ( iBufLen > (int)strlen((LPCTSTR)lpMsgBuf) ) { strcpy(pszBuf, (LPCTSTR)lpMsgBuf); dwRet = 0; } else { iBufLen = (int)strlen((LPCTSTR)lpMsgBuf); } } if ( lpMsgBuf != NULL ) { LocalFree(lpMsgBuf); lpMsgBuf = NULL; } if ( hModule != NULL ) { FreeLibrary(hModule); hModule = NULL; } return dwRet; }