--------------------- DisplayError Displays the last error in the winApi. lpszFunction is just an argument that enhances the debug output
| 20 | // Displays the last error in the winApi. lpszFunction is just an argument that enhances the debug output |
| 21 | // |
| 22 | void DisplayError(LPTSTR lpszFunction) |
| 23 | { |
| 24 | LPVOID lpMsgBuf; |
| 25 | LPVOID lpDisplayBuf; |
| 26 | DWORD dw = GetLastError(); |
| 27 | |
| 28 | FormatMessage( |
| 29 | FORMAT_MESSAGE_ALLOCATE_BUFFER | |
| 30 | FORMAT_MESSAGE_FROM_SYSTEM | |
| 31 | FORMAT_MESSAGE_IGNORE_INSERTS, |
| 32 | NULL, |
| 33 | dw, |
| 34 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
| 35 | (LPTSTR)&lpMsgBuf, |
| 36 | 0, |
| 37 | NULL); |
| 38 | |
| 39 | lpDisplayBuf = |
| 40 | (LPVOID)LocalAlloc(LMEM_ZEROINIT, |
| 41 | (lstrlen((LPCTSTR)lpMsgBuf) |
| 42 | + lstrlen((LPCTSTR)lpszFunction) |
| 43 | + 40) // account for format string |
| 44 | * sizeof(TCHAR)); |
| 45 | |
| 46 | if (FAILED(StringCchPrintf((LPTSTR)lpDisplayBuf, |
| 47 | LocalSize(lpDisplayBuf) / sizeof(TCHAR), |
| 48 | TEXT("%s failed with error code %d as follows:\n%s"), |
| 49 | lpszFunction, |
| 50 | dw, |
| 51 | lpMsgBuf))) |
| 52 | { |
| 53 | LOG("FATAL: Unable to output error code", Error); |
| 54 | } |
| 55 | |
| 56 | LOG((LPCTSTR)lpDisplayBuf, Error); |
| 57 | |
| 58 | LocalFree(lpMsgBuf); |
| 59 | LocalFree(lpDisplayBuf); |
| 60 | } |
| 61 | |
| 62 | //--------------------- |
| 63 | // GetExecutablePathName |
no outgoing calls
no test coverage detected