Commit 7c613d61 authored by 's avatar

Fix LOG_SYSRESULT

result is expected to be GetLastError() or WSAGetLastError(), so
we have to convert it to HRESULT by HRESULT_FROM_WIN32 for FAILED()
macro.
Use FormatMesssageA (ANSI version). since glog may not work with
Unicode string.

Contributed by ukai@



git-svn-id: https://google-glog.googlecode.com/svn/trunk@113 eb4d4688-79bd-11dd-afb4-1d65580434c0
parent 6d425367
......@@ -447,15 +447,16 @@ DECLARE_bool(stop_logging_if_full_disk);
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) || defined(__CYGWIN32__)
// A very useful logging macro to log windows errors:
#define LOG_SYSRESULT(result) \
if (FAILED(result)) { \
LPTSTR message = NULL; \
LPTSTR msg = reinterpret_cast<LPTSTR>(&message); \
DWORD message_length = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | \
if (FAILED(HRESULT_FROM_WIN32(result))) { \
LPSTR message = NULL; \
LPSTR msg = reinterpret_cast<LPSTR>(&message); \
DWORD message_length = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | \
FORMAT_MESSAGE_FROM_SYSTEM, \
0, result, 0, msg, 100, NULL); \
if (message_length > 0) { \
@ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::GLOG_ERROR, 0, \
&@ac_google_namespace@::LogMessage::SendToLog).stream() << message; \
&@ac_google_namespace@::LogMessage::SendToLog).stream() \
<< reinterpret_cast<const char*>(message); \
LocalFree(message); \
} \
}
......
......@@ -451,15 +451,16 @@ DECLARE_bool(stop_logging_if_full_disk);
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) || defined(__CYGWIN32__)
// A very useful logging macro to log windows errors:
#define LOG_SYSRESULT(result) \
if (FAILED(result)) { \
LPTSTR message = NULL; \
LPTSTR msg = reinterpret_cast<LPTSTR>(&message); \
DWORD message_length = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | \
if (FAILED(HRESULT_FROM_WIN32(result))) { \
LPSTR message = NULL; \
LPSTR msg = reinterpret_cast<LPSTR>(&message); \
DWORD message_length = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | \
FORMAT_MESSAGE_FROM_SYSTEM, \
0, result, 0, msg, 100, NULL); \
if (message_length > 0) { \
google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, 0, \
&google::LogMessage::SendToLog).stream() << message; \
&google::LogMessage::SendToLog).stream() \
<< reinterpret_cast<const char*>(message); \
LocalFree(message); \
} \
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment