Sign in to follow this  

What does define WIN32_LEAN_AND_MEAN Actually do?

This topic is 3044 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites

This topic is 3044 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this