Fix LOG_SYSRESULT
author <shinichiro.hamaji@gmail.com> <>
Tue, 3 Jul 2012 05:25:54 +0000 (05:25 +0000)
committer <shinichiro.hamaji@gmail.com> <>
Tue, 3 Jul 2012 05:25:54 +0000 (05:25 +0000)
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

src/glog/logging.h.in
src/windows/glog/logging.h

index 71859a9..4799ea8 100644 (file)
@@ -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); \
     } \
   }
index 76c38cd..25b42c1 100755 (executable)
@@ -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); \
     } \
   }