从 C++ 开始,至于写这篇文章的那一刻,微软鼓励使用SHGetKnownFolderPath
所需的KNOWNFOLDERID
枚举值。您需要使用的值为FOLDERID_CommonStartMenu
. 在您的情况下,代码如下所示:
wchar_t * path = nullptr;
const auto result = SHGetKnownFolderPath(FOLDERID_CommonStartMenu, 0, NULL, &path);
if (S_OK == result)
{
// do what you want with path, f.ex. create string from it
std::wstring pathAsString(path);
// according to documentation, calling process is responsible for freeing this resource
CoTaskMemFree(path);
}
有参考SHGetKnownFolderPath
:
https ://msdn.microsoft.com/en-us/library/windows/desktop/bb762188(v=vs.85).aspx
枚举的所有可用值的参考都KNOWNFOLDERID
在那里:
https ://msdn.microsoft.com/en-us/library/windows/desktop/dd378457(v=vs.85).aspx
调用进程负责释放资源的信息可以SHGetKnownFolderPath
在部分文档ppszPath
参数的文档中找到。
请注意,从服务执行时,某些值不可用(例如与用户数据相关的 f.ex. FOLDERID_Documents
)。此外,如果您使用不同的体系结构,某些值不可用(与FOLDERID_ProgramFilesX64
32 位操作系统相关的 f.ex. 值不可用)。
如果有人愿意知道 Microsoft 鼓励在哪里使用SHGetKnownFolderPath
而不是其他可用功能,请阅读 deprecated 文档的顶部SHGetFolderPath
。