| 95 | |
| 96 | # define PATH_SEPARATOR "\\" |
| 97 | static std::string |
| 98 | get_error_str() |
| 99 | { |
| 100 | // Retrieve the system error message for the last-error code |
| 101 | LPVOID lpMsgBuf; |
| 102 | DWORD dw = GetLastError(); |
| 103 | std::string errMsg; |
| 104 | DWORD rc |
| 105 | = FormatMessageA((FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS), |
| 106 | NULL, |
| 107 | dw, |
| 108 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
| 109 | reinterpret_cast<LPSTR>(&lpMsgBuf), |
| 110 | 0, |
| 111 | NULL); |
| 112 | // If FormatMessage fails using FORMAT_MESSAGE_ALLOCATE_BUFFER |
| 113 | // it means that the size of the error message exceeds an internal |
| 114 | // buffer limit (128 kb according to MSDN) and lpMsgBuf will be |
| 115 | // uninitialized. |
| 116 | // Inform the caller that the error message couldn't be retrieved. |
| 117 | if (rc == 0) |
| 118 | { |
| 119 | errMsg = "Failed to retrieve error message."; |
| 120 | } |
| 121 | else |
| 122 | { |
| 123 | errMsg = reinterpret_cast<LPSTR>(lpMsgBuf); |
| 124 | LocalFree(lpMsgBuf); |
| 125 | } |
| 126 | return errMsg; |
| 127 | } |
| 128 | |
| 129 | std::string |
| 130 | us_tempfile() |