From c8425ceb8a3f4ee2c43414abfaa642618a3ded19 Mon Sep 17 00:00:00 2001 From: Fozi Date: Fri, 22 May 2015 15:03:54 +0200 Subject: [PATCH] src: implement error_msg for Windows --- src/common.h | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/common.h b/src/common.h index 3666aa9..b6c90c0 100644 --- a/src/common.h +++ b/src/common.h @@ -16,20 +16,33 @@ namespace { -#ifdef _WIN32 - - const char *pcsc_stringify_error(const LONG) { - return ""; - } -#endif - std::string error_msg(const char* method, LONG result) { char msg[ERR_MSG_MAX_LEN]; +#ifdef _WIN32 + LPVOID lpMsgBuf; + FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + result, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR) &lpMsgBuf, + NULL); snprintf(msg, ERR_MSG_MAX_LEN, "%s error: %s(0x%.8lx)", method, - pcsc_stringify_error(result), result); + lpMsgBuf, + result); +#else + snprintf(msg, + ERR_MSG_MAX_LEN, + "%s error: %s(0x%.8lx)", + method, + pcsc_stringify_error(result), + result); +#endif + return msg; } }