From 7c613d6190d1a112a1943aa9f6526f070bc555b5 Mon Sep 17 00:00:00 2001 From: Date: Tue, 3 Jul 2012 05:25:54 +0000 Subject: [PATCH] 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 --- src/glog/logging.h.in | 11 ++++++----- src/windows/glog/logging.h | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/glog/logging.h.in b/src/glog/logging.h.in index 71859a9..4799ea8 100644 --- a/src/glog/logging.h.in +++ b/src/glog/logging.h.in @@ -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(&message); \ - DWORD message_length = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | \ + if (FAILED(HRESULT_FROM_WIN32(result))) { \ + LPSTR message = NULL; \ + LPSTR msg = reinterpret_cast(&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(message); \ LocalFree(message); \ } \ } diff --git a/src/windows/glog/logging.h b/src/windows/glog/logging.h index 76c38cd..25b42c1 100755 --- a/src/windows/glog/logging.h +++ b/src/windows/glog/logging.h @@ -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(&message); \ - DWORD message_length = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | \ + if (FAILED(HRESULT_FROM_WIN32(result))) { \ + LPSTR message = NULL; \ + LPSTR msg = reinterpret_cast(&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(message); \ LocalFree(message); \ } \ } -- 2.7.4