src: implement error_msg for Windows
This commit is contained in:
29
src/common.h
29
src/common.h
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user