天天看点

Window GetLastErrorInfo()输出错误查找的文本

std::string GetErrInfo(int wsaErrCode)
{
  std::string ret;
  LPVOID lpMsgBuf = NULL;
  FormatMessage(//将错误码转中文说明
    FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
    NULL,
    wsaErrCode,
    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
    (LPTSTR)&lpMsgBuf, 0, NULL);
  ret = (LPTSTR)lpMsgBuf;
  LocalFree(lpMsgBuf);
  return ret;
}

int main(){
  GetErrInfo(GetLastError);
}