Friday, April 5, 2013

如何獲得GetLastError()的文字訊息

[Reference] http://ascii-iicsa.blogspot.ca/2010/09/getlasterror.html

int main()
{
  CString strMsg;

  LPVOID lpMsgBuf;

  FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
                 FORMAT_MESSAGE_FROM_SYSTEM |
                 FORMAT_MESSAGE_IGNORE_INSERTS,
                 NULL,
                 GetLastError(), // 這裡也可以改成你想看的代碼值,例如直接打8L可得"空間不足"
                 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
                 (LPTSTR) &lpMsgBuf,
                 0,
                 NULL);

  strMsg.Format( _T("錯誤訊息:%s\n錯誤代碼:0x%x"), 
                 lpMsgBuf,     
                 GetLastError());

  LocalFree(lpMsgBuf); // 記得free掉空間

  return TRUE;
}


1 comment:

phpMyAdmin 無法存取 MariaDB 10 的解決方法

 [Reference]  https://www.qnap.com/zh-tw/how-to/faq/article/%E7%82%BA%E4%BB%80%E9%BA%BC%E7%84%A1%E6%B3%95%E5%9C%A8-phpmyadmin-%E5%AD%98%E5%8...