FormatMessage 将 ErrorCode 转化成字符串

   
  FormatMessage 将 GetLastError得到的错误信息(这个错误信息是数字代号)转化成字符串信息的函数。
   http://baike.baidu.com/view/1340740.htm



void CmessageboxDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
DWORD dwError = GetDlgItemInt(IDC_EDT_ERRORCODE, NULL, FALSE);


HLOCAL hlocal = NULL;


DWORD systemLocale = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL);


BOOL fOk = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_ALLOCATE_BUFFER,
NULL, dwError, systemLocale,
(PTSTR)&hlocal, 0, NULL);

if (fOk && (hlocal != NULL))
{
SetDlgItemText(IDC_EDT_ERRORTEXT, (PCTSTR)LocalLock(hlocal));
LocalFree(hlocal);
}
else
{
SetDlgItemText(IDC_EDT_ERRORTEXT, TEXT("No Text"));
}
}

你可能感兴趣的:(null,System,buffer)