#include <Windows.h>
#define WIN32_LEAN_AND_MEAN
为什么上面的代码语句有错误?是顺序错误还是其他?
在 Windows.h 标头中,如果未定义 WIN32_LEAN_AND_MEAN,则预处理器将包含其他标头。所以如果你不想包含这些头文件,你必须在 #include 之前定义 WIN32_LEAN_AND_MEAN ,否则它不会有任何影响
#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 */
直接从 Windows.h
顺序是错误的。 WIN32_LEAN_AND_MEAN
影响windows.h
声明的内容,因此需要在windows.h
包含之前定义:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>