使用ShellAPI.h引发问题

dirent.h casuing problems with ShellAPI.h

本文关键字:问题 ShellAPI 使用      更新时间:2023-10-16

我有一个函数:

SHFileOperationFunc(string item1, string item2, int operation, CuTest *tc)

它用于执行操作(移动、删除或复制)目录。它运行良好。但我现在正在尝试使用dirent.h中的东西。当我包含该文件时,它会导致我在SHFileOperationFunc中使用的ShellAPI.h中的内容出现巨大问题。我得到了dirent.hhttp://www.softagalleria.net/dirent.php.

在我包含该文件后,我会收到错误,如:

error C2065: 'FO_DELETE' : undeclared identifier
error C2065: 'FO_COPY' : undeclared identifier
error C2065: 'FO_DELETE' : undeclared identifier
error C2065: 'FO_DELETE' : undeclared identifier

这些是在ShellAPI.h中定义的。当我在VS中将鼠标悬停在它们上面时,它会显示它们的值,所以它会看到它们。有人知道为什么包含此文件会产生这种效果吗?

在Windows机器上使用dirent.h是不可取的,因为它是Unix头。您下载的文件破坏了#包含的其余部分。将if放在#include <windows.h>之后,或者编辑文件并删除WIN32_LEAN_and_MEAN的#define。把它放在一个标题里,嗯,很刻薄。它会导致在Windows标头中跳过大量声明。