Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(native): windows.h brings min/max as macros, and Types.hpp says ::max()

yhhcff3d866ebb3
diff --git a/native/host/Bench.cpp b/native/host/Bench.cpp
index 3c5851a90..a6d4dd629 100644
--- a/native/host/Bench.cpp
+++ b/native/host/Bench.cpp
@@ -19,6 +19,15 @@
#include <vector>
#if defined(_WIN32)
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+// windows.h defines min/max as MACROS, and Types.hpp says
+// numeric_limits<u32>::max() -- which then reads as ::(), and the compiler
+// blames that line rather than this include. NOMINMAX is what turns them off.
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
#include <windows.h>
#else
#include <ctime>
diff --git a/native/host/platform/windows_common.cpp b/native/host/platform/windows_common.cpp
index b73c5dc75..e7f46747d 100644
--- a/native/host/platform/windows_common.cpp
+++ b/native/host/platform/windows_common.cpp
@@ -12,6 +12,15 @@
*/
#include "platform/windows_common.hpp"
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+// windows.h defines min/max as MACROS, and Types.hpp says
+// numeric_limits<u32>::max() -- which then reads as ::(), and the compiler
+// blames that line rather than this include. NOMINMAX is what turns them off.
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
#include <windows.h>
#include <dwrite.h>
#include <winhttp.h>
diff --git a/src/esengine/core/DynamicLibrary.hpp b/src/esengine/core/DynamicLibrary.hpp
index 2012881db..dbfaecaa4 100644
--- a/src/esengine/core/DynamicLibrary.hpp
+++ b/src/esengine/core/DynamicLibrary.hpp
@@ -23,6 +23,12 @@
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
+// min/max arrive as MACROS otherwise, and the next numeric_limits<T>::max()
+// in any translation unit that included this reads as ::() -- reported
+// against that line, never against this one.
+# ifndef NOMINMAX
+# define NOMINMAX
+# endif
# include <windows.h>
#else
# include <dlfcn.h>