You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Code::Blocks 20.03 64位编译WinAPI代码报错:未定义引用IID_IShellFolder

解决undefined reference to 'IID_IShellFolder'错误的方案

1. 链接必要的系统库

IID_IShellFolder属于Shell COM接口相关定义,编译时需要链接Shell32库:

  • 打开Code::Blocks的项目Build options
  • 切换到Linker settings标签
  • 在Other linker options中添加 -lshell32(适用于GCC/MinGW环境);或者在Link libraries列表里添加shell32

2. 定义INITGUID宏生成GUID实例

在包含相关头文件前定义INITGUID,让编译器生成IID_IShellFolder的具体实现:

#define INITGUID
#include <windows.h>
#include <tchar.h>
#include <commctrl.h>
#include <shlobj.h>
#include <shlwapi.h>
#include <objidl.h>

注意:INITGUID必须在所有相关头文件之前定义,且整个项目中仅定义一次,避免重复定义错误。

3. 手动初始化IID_IShellFolder(备选方案)

如果上述方法无效,可以直接在代码中手动定义这个GUID的常量:

const IID IID_IShellFolder = {0x000214E6, 0x0000, 0x0000, {0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}};

4. 调整头文件包含顺序

确保windows.h在其他WinAPI头文件之前包含,避免宏定义冲突:

#include <windows.h>
#include <tchar.h>
#include <commctrl.h>
#include <shlobj.h>
#include <shlwapi.h>
#include <objidl.h>

内容的提问来源于stack exchange,提问作者Niteya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 15:22:11