1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| string get_sys_error_msg(unsigned long err) { char _inner_msg[10240] = { 0 }; memset(_inner_msg, 0, sizeof(_inner_msg));
if (err == 0) err = GetLastError(); LPSTR buf = NULL; if (::FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), (LPSTR)&buf, 0, NULL)) {
sprintf_s(_inner_msg, sizeof(_inner_msg),"[%d]%s", err, buf); ::LocalFree(buf); } else { snprintf(_inner_msg, sizeof(_inner_msg), " [0x%x]Unknown error", err); } string str_error_msg(_inner_msg); return str_error_msg; }
|