Advertisement
chino

Translate error code into string

Aug 18th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void LErr(TCHAR szFunc[] = NULL, DWORD dwErr = 0)
  2. {
  3.     /*
  4.         szFunc ... Function Name
  5.         dwErr ... Error Code (it ccan be obtained by GetLastError() or sth)
  6.     */
  7.  
  8.     LPVOID lpMsgBuf;
  9.     TCHAR szMsg[4096] = { '\0' };
  10.  
  11.     FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
  12.         FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dwErr,
  13.         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  14.         (LPTSTR)&lpMsgBuf, 0, NULL);
  15.  
  16.     swprintf_s(szMsg, 4096, _T("%s\r\n0x%08X (Dec:%u)"), lpMsgBuf, dwErr, dwErr);
  17.    
  18.     //MessageBox(NULL, szMsg, NULL, MB_OK);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement