src: implement error_msg for Windows

This commit is contained in:
Fozi
2015-05-22 15:03:54 +02:00
committed by Santiago Gimeno
parent 1a3c7dec1c
commit c8425ceb8a

View File

@@ -16,20 +16,33 @@
namespace { namespace {
#ifdef _WIN32
const char *pcsc_stringify_error(const LONG) {
return "";
}
#endif
std::string error_msg(const char* method, LONG result) { std::string error_msg(const char* method, LONG result) {
char msg[ERR_MSG_MAX_LEN]; 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, snprintf(msg,
ERR_MSG_MAX_LEN, ERR_MSG_MAX_LEN,
"%s error: %s(0x%.8lx)", "%s error: %s(0x%.8lx)",
method, 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; return msg;
} }
} }