我已经学习 Java 编程大约 7 个月了,并且对 c++ 产生了兴趣。我目前也在读一本 c++ 书。
我正在使用 eclipse c++,因为我对 eclipse 非常熟悉。
我用 C++ 制作了 6 个项目(小项目),到目前为止一切正常。
我的问题是我无法让 SHGetKnownFolderPath 方法工作。完整的行是 red ,尽管我已经导入了所有内容,构建它,尝试运行它。我检查了互联网站点,并且使用了与其他人相同的代码,但仍然不适合我。
它说:函数 SHGetKnownFolderPath 无法解析
我在 64 位 Windows 8 计算机上。这是代码: 更新
#define WINVER 0x0600 // 0x06020000 0x06030000
#include <shlobj.h>
#include <windows.h>
#include <combaseapi.h>
#include <comutil.h> //for _bstr_t (used in the string conversion)
#include <knownfolders.h>
#include <winerror.h> //for HRESULT
#include <winnt.h>
#include <iostream>
#include <string>
using namespace std;
int main(){
LPWSTR wszPath = NULL;
HRESULT hr;
hr = SHGetKnownFolderPath(FOLDERID_Documents, 0, NULL, &wszPath);// THIS LINE IS COMPLETELY RED
if (SUCCEEDED(hr)){
_bstr_t bstrPath(wszPath);
std::string strPath((char*)bstrPath);
std::cout << strPath;
}
CoTaskMemFree(wszPath);
return 0;
}
这是日志:
#pragma comment(lib, "comsuppw")
^
..\src\HelloWorld.cpp: In function 'int main()':
..\src\HelloWorld.cpp:21:64: error: 'SHGetKnownFolderPath' was not declared in this scope
hr = SHGetKnownFolderPath(FOLDERID_Documents, 0, NULL, &wszPath);
&wszPath 下的最后一个括号有一个小箭头)
什么可能是错的?我将不胜感激所有我能得到的答案或提示。