| 365 | } |
| 366 | |
| 367 | inline std::string get_last_error(DWORD errorMessageID) |
| 368 | { |
| 369 | if (errorMessageID == 0) |
| 370 | return std::string(); |
| 371 | |
| 372 | LPSTR messageBuffer = nullptr; |
| 373 | size_t size = FormatMessageA( |
| 374 | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | |
| 375 | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK, |
| 376 | NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
| 377 | (LPSTR)&messageBuffer, 0, NULL); |
| 378 | |
| 379 | std::string message(messageBuffer, size); |
| 380 | |
| 381 | LocalFree(messageBuffer); |
| 382 | |
| 383 | return message; |
| 384 | } |
| 385 | |
| 386 | inline FILE *file_from_handle(HANDLE h, const char *mode) |
| 387 | { |