SHGetFolderPath不推荐:什么是替代方法来检索Windows文件夹的路径? [英] SHGetFolderPath Deprecated: What is alternative to retrieve path for Windows folders?
问题描述
从Windows Vista开始, SHGetFolderPath()
功能已弃用: http://msdn.microsoft.com/en-us/library/bb762181%28v=VS.85%29.aspx p>
在Windows中检索应用程序文件夹的路径的另一种方法是什么?
SHGetFolderPath(NULL,CSIDL_COMMON_APPDATA,NULL,0,szPath)
使用此函数时出现错误:
错误1错误C2065:'CSIDL_COMMON_APPDATA':未声明的标识符
错误2错误C3861:'SHGetFolderPath':未找到标识符
替代方法在您链接的文档中描述。也就是 SHGetKnownFolderPath
。 p>
但是, SHGetKnownFolderPath
仅适用于Vista或更高版本。所以如果你使用加载时间链接,并运行一个程序调用 SHGetKnownFolderPath
在XP上,那么该程序将无法启动。这显然是一个问题,如果你想支持XP。
现在,你可以切换到运行时链接 SHGetKnownFolderPath
。在调用它之前进行版本检查,如果函数不可用,那么可以回到 SHGetFolderPath
。
个人而言,我不会让这种过时的担心你。 Microsoft为维持向后兼容性而闻名。不要期望 SHGetFolderPath
即将消失。你会发现在Windows 8中存在 SHGetFolderPath
,我希望它仍然存在于任何Windows是当前10年后。我的建议是坚持加载时间链接,只有当你放弃支持XP时,切换到 SHGetKnownFolderPath
。
你的另一个问题,你在编辑中询问,是如何调用 SHGetFolderPath
。您需要遵守在您的问题中链接的MSDN文档主题底部列出的要求。具体来说,包括 Shlobj.h
,并将 Shlobj.lib
传递给链接器。
The SHGetFolderPath()
function is deprecated beginning with Windows Vista: http://msdn.microsoft.com/en-us/library/bb762181%28v=VS.85%29.aspx
What is the alternative way to retrieve the path to the Application Folder in Windows?
SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, 0, szPath)
Aside from that, why do I get those errors when using this function:
Error 1 error C2065: 'CSIDL_COMMON_APPDATA' : undeclared identifier
Error 2 error C3861: 'SHGetFolderPath': identifier not found
The alternative is described in the documentation to which you link. Namely it is SHGetKnownFolderPath
.
However, SHGetKnownFolderPath
is only available on Vista or later. So if you use load time linking, and run a program that calls SHGetKnownFolderPath
on XP, then that program will fail to start. This is clearly a problem if you wish to support XP.
Now, you could switch to run time linking of SHGetKnownFolderPath
. Carry out a version check before you call it, and if the function is not available, then fall back to SHGetFolderPath
.
Personally, I would not let this deprecation worry you excessively. Microsoft are renowned for maintaining backwards compatibility. Don't expect SHGetFolderPath
to disappear any time soon. You will find that SHGetFolderPath
exists in Windows 8 and I would expect it still to be present in whatever Windows is current 10 years from now. My advice is to stick to load time linking, and only switch to SHGetKnownFolderPath
when you give up supporting XP.
Your other question, that you ask in an edit, is how to call SHGetFolderPath
. You need to respect the requirements which are laid out at the bottom of the MSDN documentation topic which you linked to in your question. Specifically, include Shlobj.h
and pass Shlobj.lib
to the linker.
这篇关于SHGetFolderPath不推荐:什么是替代方法来检索Windows文件夹的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!