0
#include <Windows.h>
#define WIN32_LEAN_AND_MEAN

Why the above code statement has mistake? Is the order wrong or others?

RichieHindle
  • 272,464
  • 47
  • 358
  • 399
zzz
  • 161
  • 4
  • 12

2 Answers2

6

In the Windows.h header, if WIN32_LEAN_AND_MEAN is not defined, the preprocessor will includes other headers. So if you want to not include theses headers, you must define WIN32_LEAN_AND_MEAN before #include , else it won't have any effects

#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 */

Directly from Windows.h

Nic007
  • 634
  • 5
  • 13
  • How should I write if I just want the header files below be excluded? #include #include #include #include – zzz Jun 05 '13 at 13:25
  • define WIN32_LEAN_AND_MEAN before Windows.h and add what you wants to include manually (don't forget Windows.h). – Nic007 Jun 05 '13 at 13:32
  • So, by using #define WIN32_LEAN_AND_MEAN, all the above header files will exclude. If you want some header files back, just #include back before #include . Am I right? – zzz Jun 05 '13 at 13:37
4

The order is wrong. WIN32_LEAN_AND_MEAN affects what windows.h declares, so it needs to be defined before windows.h is included:

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
RichieHindle
  • 272,464
  • 47
  • 358
  • 399
  • Good answer, just for future [reference](http://stackoverflow.com/questions/11040133/what-does-defining-win32-lean-and-mean-exclude-exactly) – dowhilefor Jun 05 '13 at 13:05