从 C 代码调用 SHGetKnownFolderPath
我正在尝试使用 Visual Studio 2008 从 C 调用 Vista 函数 SHGetKnownFolderPath()
。该代码可以像 C++ 一样正常工作,但拒绝使用以下输出编译为 C 代码:
xyz\indexwiki.cpp(316):错误 C2440: 'function':无法转换自 'const GUID' 到 'const KNOWNFOLDERID *const ' xyz\indexwiki.cpp(316) : 警告 C4024: 'SHGetKnownFolderPath' :不同类型的正式和 实际参数1
代码非常多:
PWSTR path;
HRESULT hr = SHGetKnownFolderPath(
FOLDERID_Profile,
0,
NULL,
&path
);
如果可以的话,我更愿意将其保留为 C 并将项目保留为单个源文件。这是较新的 Windows API 的已知问题吗?我通过谷歌找不到太多信息。我错过了什么吗?或者是否有一个涉及铸造或预处理器定义的简单解决方法?
I'm trying to call the Vista function SHGetKnownFolderPath()
from C using Visual Studio 2008. The code works fine as C++ but refuses to compile as C code with this output:
xyz\indexwiki.cpp(316) : error C2440:
'function' : cannot convert from
'const GUID' to 'const KNOWNFOLDERID
*const ' xyz\indexwiki.cpp(316) : warning C4024: 'SHGetKnownFolderPath'
: different types for formal and
actual parameter 1
The code is pretty much:
PWSTR path;
HRESULT hr = SHGetKnownFolderPath(
FOLDERID_Profile,
0,
NULL,
&path
);
I'd prefer to keep it as C and keep the project as a single source file if I can. Is this a known problem with newer Windows APIs? I couldn't find much via Google. Am I missing something? Or is there perhaps a simple workaround involving casting or preprocessor defines?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
下面的怎么样?
How about the following?
即使你在 C 中传入一个指针,智能感知仍然会抱怨找不到构造函数。我认为这是一个错误,因为我无法摆脱它。我的解决方案是将文件重命名为 .cpp。
Even if you pass in a pointer in C, the intellisense will still complain about not finding a constructor. I think this is a bug, because I couldn't get rid of it. My solution was to just rename the file to .cpp.
从错误消息中可以看出,您传递的是 const GUID,而 SHGetKnownFolderPath 需要 REFKNOWNFOLDERID。尝试使用这个:
As you can see from the error message, you are passing a const GUID, while the SHGetKnownFolderPath wants a REFKNOWNFOLDERID. Try using this: