Skip to main content
GameDev.net gamedev.net
🔒 Locked

What does define WIN32_LEAN_AND_MEAN Actually do?

Started by JamesCobras Aug 15, 2009 at 7:39 AM 8 replies 17.9k views
Original Post
JamesCobras
JamesCobras
Hi guys, just wondering, what exactly does: define WIN32_LEAN_AND_MEAN Actually, it's a macro so i know it probably does a load of stuff, but can you give me a brief summary on what it does?? Thanks JamesCobras
Nik02
Nik02
Windows.h uses the macro to exclude various headers. You can see these by searching for "#ifndef WIN32_LEAN_AND_MEAN".

Niko Suni
Anon Mike
Anon Mike
It's purpose is to speed up compiles. Including windows.h causes virtually every windows related header in the world to come along with it by default. Using WIN32_LEAN_AND_MEAN cuts that down.

It's probably not as relevant today as it used to be since machines are faster and more people use pre-compiled headers.
-Mike
BitMaster
BitMaster
There are other reasons to still define WIN32_LEAN_AND_MEAN. For example Winsock will not be included (bad if you intend to use Winsock2) and neither will those horrible min/max macros be defined.
swiftcoder
swiftcoder
Quote:
Original post by BitMaster
There are other reasons to still define WIN32_LEAN_AND_MEAN... and neither will those horrible min/max macros be defined.
This. The reason why every C++ application should define WIN32_LEAN_AND_MEAN - otherwise you have no std::min/std::max, which ruins portability.

There is supposed to be a separate macro, NOMINMAX, which takes care of this problem, but I haven't been able to get it to work reliably across Visual Studio versions.
Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]
dmatter
dmatter
Quote:
Original post by swiftcoder
every C++ application should define WIN32_LEAN_AND_MEAN
I had a look back at some old C++ projects where I #include "windows.h" in more than one file and it looks like I made a header to wrap it:

// windows_lean_and_mean.h

#define WIN32_LEAN_AND_MEAN
#include "windows.h"


Is there a better way? I know there alternatives like the /D option.
swiftcoder
swiftcoder
Quote:
Original post by dmatter
Is there a better way? I know there alternatives like the /D option.
That is the approach I take - my CMake build system is set to define several of those type of macros when it detects the compiler to be MSVC.
Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]
Washu
Washu
Quote:
Original post by BitMaster
...and neither will those horrible min/max macros be defined.

#define NOMINMAX

Note that defining NOMINMAX can break some windows headers that use it (mainly ATL).
In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
hiigara
hiigara
If using gdiplus you cannot define WIN32_LEAN_AND_MEAN. Gdiplus needs some type definitions that are excluded by this macro.
yewbie
yewbie
I think it doesn't load alot of the MFC stuff if you use it

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.