What does #defining WIN32_LEAN_AND_MEAN exclude exactly?

WindowsVisual C++

Windows Problem Overview


I found the explanation defining WIN32_LEAN_AND_MEAN "reduces the size of the Win32 header files by excluding some of the less frequently used APIs". Somewhere else I read that it speeds up the build process.

So what does WIN32_LEAN_AND_MEAN exclude exactly? Should I care about this pre-processor directive? Does it speed up the build process?

I've also seen a pre-processor directive in projects named something along the lines of extra lean. Is this another esoteric pre-processor incantation I should know about?

Windows Solutions


Solution 1 - Windows

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

Solution 2 - Windows

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 provide > the following new defines: > > VC_EXTRALEAN > WIN32_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.

Solution 3 - Windows

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionfishfoodView Question on Stackoverflow
Solution 1 - WindowsChris911View Answer on Stackoverflow
Solution 2 - WindowsCuriousGeorgeView Answer on Stackoverflow
Solution 3 - Windows0xsteveView Answer on Stackoverflow