浏览代码

Work around windows.h #defining GetMessage().

kenton@google.com 16 年之前
父节点
当前提交
709ea28f32
共有 3 个文件被更改,包括 25 次插入0 次删除
  1. 18 0
      src/google/protobuf/message.h
  2. 6 0
      src/google/protobuf/test_util.cc
  3. 1 0
      src/google/protobuf/testing/googletest.h

+ 18 - 0
src/google/protobuf/message.h

@@ -117,6 +117,24 @@
 #else
 #else
 #include <iosfwd>
 #include <iosfwd>
 #endif
 #endif
+
+#if defined(_WIN32) && defined(GetMessage)
+// windows.h defines GetMessage() as a macro.  Let's re-define it as an inline
+// function.  This is necessary because Reflection has a method called
+// GetMessage() which we don't want overridden.  The inline function should be
+// equivalent for C++ users.
+inline BOOL GetMessage_Win32(
+    LPMSG lpMsg, HWND hWnd,
+    UINT wMsgFilterMin, UINT wMsgFilterMax) {
+  return GetMessage(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax);
+}
+#undef GetMessage
+inline BOOL GetMessage(
+    LPMSG lpMsg, HWND hWnd,
+    UINT wMsgFilterMin, UINT wMsgFilterMax) {
+  return GetMessage_Win32(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax);
+}
+#endif
 
 
 #include <google/protobuf/stubs/common.h>
 #include <google/protobuf/stubs/common.h>
 
 

+ 6 - 0
src/google/protobuf/test_util.cc

@@ -32,6 +32,12 @@
 //  Based on original Protocol Buffers design by
 //  Based on original Protocol Buffers design by
 //  Sanjay Ghemawat, Jeff Dean, and others.
 //  Sanjay Ghemawat, Jeff Dean, and others.
 
 
+#ifdef _WIN32
+// Verify that #icnluding windows.h does not break anything (e.g. because
+// windows.h #defines GetMessage() as a macro).
+#include <windows.h>
+#endif
+
 #include <google/protobuf/test_util.h>
 #include <google/protobuf/test_util.h>
 #include <google/protobuf/descriptor.h>
 #include <google/protobuf/descriptor.h>
 #include <google/protobuf/message.h>
 #include <google/protobuf/message.h>

+ 1 - 0
src/google/protobuf/testing/googletest.h

@@ -58,6 +58,7 @@ string GetCapturedTestStderr();
 // For use with ScopedMemoryLog::GetMessages().  Inside Google the LogLevel
 // For use with ScopedMemoryLog::GetMessages().  Inside Google the LogLevel
 // constants don't have the LOGLEVEL_ prefix, so the code that used
 // constants don't have the LOGLEVEL_ prefix, so the code that used
 // ScopedMemoryLog refers to LOGLEVEL_ERROR as just ERROR.
 // ScopedMemoryLog refers to LOGLEVEL_ERROR as just ERROR.
+#undef ERROR  // defend against promiscuous windows.h
 static const LogLevel ERROR = LOGLEVEL_ERROR;
 static const LogLevel ERROR = LOGLEVEL_ERROR;
 
 
 // Receives copies of all LOG(ERROR) messages while in scope.  Sample usage:
 // Receives copies of all LOG(ERROR) messages while in scope.  Sample usage: