What does define WIN32_LEAN_AND_MEAN Actually do?

Started by
8 comments, last by yewbie 14 years, 8 months ago
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
Advertisement
Windows.h uses the macro to exclude various headers. You can see these by searching for "#ifndef WIN32_LEAN_AND_MEAN".

Niko Suni

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
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.
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]

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.
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]

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.

If using gdiplus you cannot define WIN32_LEAN_AND_MEAN. Gdiplus needs some type definitions that are excluded by this macro.
I think it doesn't load alot of the MFC stuff if you use it

This topic is closed to new replies.

Advertisement