Reduce the usage of Windows.h, and add macros to slim Windows.h
diff --git a/lib/cpp/src/thrift/transport/TPipeServer.cpp b/lib/cpp/src/thrift/transport/TPipeServer.cpp
index 1d7577f..e4234b1 100644
--- a/lib/cpp/src/thrift/transport/TPipeServer.cpp
+++ b/lib/cpp/src/thrift/transport/TPipeServer.cpp
@@ -26,6 +26,7 @@
#ifdef _WIN32
#include <thrift/windows/OverlappedSubmissionThread.h>
+#include <thrift/windows/Sync.h>
#include <AccCtrl.h>
#include <Aclapi.h>
#include <sddl.h>
diff --git a/lib/cpp/src/thrift/transport/TPipeServer.h b/lib/cpp/src/thrift/transport/TPipeServer.h
index 67c5d51..249591e 100644
--- a/lib/cpp/src/thrift/transport/TPipeServer.h
+++ b/lib/cpp/src/thrift/transport/TPipeServer.h
@@ -25,9 +25,6 @@
#ifndef _WIN32
#include <thrift/transport/TServerSocket.h>
#endif
-#ifdef _WIN32
-#include <thrift/windows/Sync.h>
-#endif
#define TPIPE_SERVER_MAX_CONNS_DEFAULT PIPE_UNLIMITED_INSTANCES
diff --git a/lib/cpp/src/thrift/windows/OverlappedSubmissionThread.h b/lib/cpp/src/thrift/windows/OverlappedSubmissionThread.h
index 6cecfc3..057f623 100644
--- a/lib/cpp/src/thrift/windows/OverlappedSubmissionThread.h
+++ b/lib/cpp/src/thrift/windows/OverlappedSubmissionThread.h
@@ -26,7 +26,6 @@
#include <thrift/windows/Sync.h>
#include <thrift/TNonCopyable.h>
-#include <Windows.h>
/*
*** Why does this class exist?
diff --git a/lib/cpp/src/thrift/windows/Sync.h b/lib/cpp/src/thrift/windows/Sync.h
index b1c83ee..f5b8a05 100644
--- a/lib/cpp/src/thrift/windows/Sync.h
+++ b/lib/cpp/src/thrift/windows/Sync.h
@@ -27,7 +27,13 @@
#include <thrift/concurrency/Exception.h>
#include <thrift/TNonCopyable.h>
+// Including Windows.h can conflict with Winsock2 usage, and also
+// adds problematic macros like min() and max(). Try to work around:
+#define NOMINMAX
+#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
+#undef NOMINMAX
+#undef WIN32_LEAN_AND_MEAN
/*
Lightweight synchronization objects that only make sense on Windows. For cross-platform