Skip to content

Conversation

@CraftedCart
Copy link

Avoid defining min/max macros from winmindef.h/minmax.h, since I was bitten by this trying to use std::numeric_limits<T>::max() in a mod I've been tinkering with. :P

  • Everywhere we used to use min/max macros now uses std::min/std::max functions from <algorithm>
  • Headers that include winmindef.h (eg: by including Windows.h directly, or through DirectX headers) now define both WIN32_LEAN_AND_MEAN and NOMINMAX if they weren't already defined, both to avoid the min/max macro pollution, and cut down on how much un-needed stuff from Windows.h gets included
  • Source files that use the windows headers just define WIN32_LEAN_AND_MEAN and NOMINMAX directly at the top too now

@OrfeasZ
Copy link
Owner

OrfeasZ commented Jan 11, 2026

Thanks for this! Instead of defining WIN32_LEAN_AND_MEAN and NOMINMAX in multiple places, you could instead apply them for the entire project by using add_compile_definitions() in the root CMakeLists.txt

You can leave the definition in Common.h so mods get it too, since that should be included in most places.

@CraftedCart
Copy link
Author

Yeah that makes sense heh - though I do wonder if it might still be an issue if say, a mod includes Hooks.h before other things (which seems to include Windows.h* before* Common.h) :P

Maybe we consider that as a non-issue, since arguably a mod could define NOMINMAX itself if it wants to opt-out of that macro pollution? Not sure heh.

Anyway, I'll mark this PR as a draft then until I get round to that.

@CraftedCart CraftedCart marked this pull request as draft January 11, 2026 23:03
… WIN32_LEAN_AND_MEAN everywhere else windows.h is included.
…s.txt, shuffle some includes around to avoid try min/max macros pollution in mods too
@CraftedCart
Copy link
Author

Okie, moved the defines to CMakeLists.txt, shuffled around includes a bit in Hooks.h to make sure Common.h is included before Windows.h.

Also re-wrote the first commit to get rid of the the odd removed newline at EOF changes :P

@CraftedCart CraftedCart marked this pull request as ready for review January 20, 2026 00:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants