定义 WIN32_LEAN_AND_MEAN 的作用

这个宏的主要作用是减少编译时间和避免命名空间污染。不过你的程序需要使用被WIN32_LEAN_AND_MEAN排除的API,你则不能定义这个宏,或者需要单独包含那些特定的头文件。

简洁的来说,定义WIN32_LEAN_AND_MEAN以排除加密、DDE、RPC、Shell 和Windows套接字等 API,官方文档在这

这个宏在源码中是这样的:

#ifndef WIN32_LEAN_AND_MEAN
#include <cderr.h>      // 提供公共对话框错误代码。
#include <dde.h>        // 动态数据交换(DDE)管理库的定义。
#include <ddeml.h>      // DDE管理库的高级接口。
#include <dlgs.h>       // 标准对话框的资源标识符。
#ifndef _MAC
    #include <lzexpand.h>   // LZ扩展库函数,用于处理LZ压缩文件。
    #include <mmsystem.h>   // 多媒体API,如声音播放和录制。
    #include <nb30.h>       // NetBIOS 3.0接口,用于网络通信。
    #include <rpc.h>        // 远程过程调用API。
#endif
#include <shellapi.h>    // 提供对Shell函数和接口的访问,如拖放和程序启动。
#ifndef _MAC
    #include <winperf.h>    // 性能监视器的API。
    #include <winsock.h>    // Windows Sockets API,用于网络通信。
#endif
#ifndef NOCRYPT
    #include <wincrypt.h>   // 加密API。
    #include <winefs.h>     // 加密文件系统(EFS)相关API。
    #include <winscard.h>   // 智能卡API。
#endif
#ifndef NOGDI
    #ifndef _MAC
        #include <winspool.h>   // 打印机和打印作业管理函数。
        #ifdef INC_OLE1
            #include <ole.h>        // 旧的对象链接和嵌入接口。
        #else
            #include <ole2.h>       // OLE接口。
        #endif /* !INC_OLE1 */
    #endif /* !MAC */
    #include <commdlg.h>    // 公共对话框函数,如文件打开、保存、打印等。
#endif /* !NOGDI */
#endif /* WIN32_LEAN_AND_MEAN */
创建时间:2020-04-21
最后修改:2020-04-21

反馈