【发布时间】:2013-06-24 15:02:41
【问题描述】:
为什么 GetPath 在查询 FOLDERID_ControlPanelFolder 时总是返回 E_FAIL?其他 FOLDERID 确实有效:
HRESULT hr = S_OK;
*path = '\0';
LPWSTR pwcPath = NULL;
CoInitialize(NULL);
IKnownFolderManager *pFolderManager = NULL;
if ((hr = CoCreateInstance(__uuidof(KnownFolderManager), NULL, CLSCTX_INPROC_SERVER, __uuidof(IKnownFolderManager), (LPVOID *)&pFolderManager)) == S_OK)
{
IKnownFolder *pControlPanelFolder = NULL;
if ((hr = pFolderManager->GetFolder(FOLDERID_ControlPanelFolder, &pControlPanelFolder)) == S_OK)
{
hr = pControlPanelFolder->GetPath(0, &pwcPath);
if (hr == S_OK && pwcPath)
{
int nSize = wcslen(pwcPath);
WideCharToMultiByte(CP_ACP, 0, pwcPath, nSize, path, nSize+2, NULL, NULL);
path[nSize] = '\0';
CoTaskMemFree(pwcPath);
}
pControlPanelFolder->Release();
pControlPanelFolder = NULL;
}
pFolderManager->Release();
pFolderManager = NULL;
}
CoUninitialize();
(是的,我偶然发现了this question,但我不需要所有枚举的东西。)
【问题讨论】:
-
可能是因为控制面板是一个虚拟文件夹,因此它没有实际路径?
-
Getting PIDL of Control Panel:
string ControlPanelGUID = "::{26EE0668-A00A-44D7-9371-BEB064C98683}";