What does #defining WIN32_LEAN_AND_MEAN exclude exactly? What does #defining WIN32_LEAN_AND_MEAN exclude exactly? windows windows

What does #defining WIN32_LEAN_AND_MEAN exclude exactly?


Directly from the Windows.h header file:

#ifndef WIN32_LEAN_AND_MEAN    #include <cderr.h>    #include <dde.h>    #include <ddeml.h>    #include <dlgs.h>    #ifndef _MAC        #include <lzexpand.h>        #include <mmsystem.h>        #include <nb30.h>        #include <rpc.h>    #endif    #include <shellapi.h>    #ifndef _MAC        #include <winperf.h>        #include <winsock.h>    #endif    #ifndef NOCRYPT        #include <wincrypt.h>        #include <winefs.h>        #include <winscard.h>    #endif    #ifndef NOGDI        #ifndef _MAC            #include <winspool.h>            #ifdef INC_OLE1                #include <ole.h>            #else                #include <ole2.h>            #endif /* !INC_OLE1 */        #endif /* !MAC */        #include <commdlg.h>    #endif /* !NOGDI */#endif /* WIN32_LEAN_AND_MEAN */

If you want to know what each of the headers actually do, typing the header names into the search in the MSDN library will usually produce a list of the functions in that header file.

Also, from Microsoft's support page:

To speed the build process, Visual C++ and the Windows Headers providethe following new defines:

VC_EXTRALEANWIN32_LEAN_AND_MEAN

You can use them to reduce the size of the Win32 header files.

Finally, if you choose to use either of these preprocessor defines, and something you need is missing, you can just include that specific header file yourself. Typing the name of the function you're after into MSDN will usually produce an entry which will tell you which header to include if you want to use it, at the bottom of the page.


According the to Windows Dev Center WIN32_LEAN_AND_MEAN excludes APIs such as Cryptography, DDE, RPC, Shell, and Windows Sockets.


Complementing the above answers and also "Parroting" from the Windows Dev Center documentation,

The Winsock2.h header file internally includes core elements from the Windows.h header file, so there is not usually an #include line for the Windows.h header file in Winsock applications. If an #include line is needed for the Windows.h header file, this should be preceded with the #define WIN32_LEAN_AND_MEAN macro. For historical reasons, the Windows.h header defaults to including the Winsock.h header file for Windows Sockets 1.1. The declarations in the Winsock.h header file will conflict with the declarations in the Winsock2.h header file required by Windows Sockets 2.0. The WIN32_LEAN_AND_MEAN macro prevents the Winsock.h from being included by the Windows.h header ..