【发布时间】:2022-08-02 16:52:28
【问题描述】:
我是winAPI的新手,我正在学习如何编写具有一些特殊功能等的代码程序,所以我下载了Windows的SDK。
问题是,GCC 决定戴上盲眼镜并说:
Documents_path.c:6:25: fatal error: KnownFolders.h: No such file or directory
#include<KnownFolders.h>
^
compilation terminated.
我说“好的,然后下一个”,还有另一个标题有同样的问题:
thread.c:3:30: fatal error: processthreadsapi.h: No such file or directory
#include<processthreadsapi.h>
^
compilation terminated.
我检查了这些标题是否甚至在我的 PC 中,并且在这里它们使用 windows.h 进行设置,当我尝试使用它的基本功能时它正在工作。
我搜索了这个问题的答案,但没有找到任何问题,要么是外部\\二进制库问题,要么是本地问题,要么是宏修复(它不起作用)。
我该如何解决这个问题?
编辑: 我正在使用 VS 代码
编辑2:
这是 \"Documents_path.c\" 示例的代码:
#include<stdio.h>
#include<stdlib.h>
#include<Windows.h>
#include<ShlObj.h>
#include<initguid.h>
#include<KnownFolders.h>
#pragma comment(lib, \"user32.lib\")
int main(){
int a;
PWSTR path = NULL;
HRESULT hr = SHGetKnownFolderPath(&FOLDERID_Documents, 0, NULL, &path);
if(SUCCEEDED(hr)){
printf(\"path for Documents is: %ls\", path);
}
scanf(\"%d\",&a);
CoTaskMemFree(path);
return 0;
}
我正在从这个网站阅读 winAPI 的基础知识: https://zetcode.com/gui/winapi/
至于项目文件夹的结构: C:\\Users\\%USER%\\Documents\\C\\dawd
-
你为什么不只包括
windows.h? -
与 MinGW-W64 8.1.0 一起为我工作。 (\"KnownFolders.h\" 给出了很多其他错误,因为我之前没有包含 \"windows.h\"。)您可能想要edit 您的问题并显示minimal reproducible example。
-
@gost1212 你确定
windows.hgcc 找到的是 Windows SDK 文件夹中的windows.h吗?我很确定windows.hgcc 找到的是 gcc 附带的,而不是 Windows SDK 文件夹中的那个。您可以通过暂时删除 Windows SDK 文件夹中的windows.h来轻松检查。 -
Mingw 应该有它自己的头文件和库。
-
stackoverflow.com/questions/1549123/… misc #define 可能需要 shlobj.h 等。
标签: c windows visual-studio-code winapi gcc