CString转换成pidl路径

来源:互联网 发布:软件通用质量特性 编辑:程序博客网 时间:2024/04/30 23:38
从MFC的CShellManager类中找到的一个方法:
HRESULT CShellManager::ItemFromPath(LPCTSTR lpszPath, LPITEMIDLIST& pidl){ENSURE(lpszPath != NULL);LPSHELLFOLDER pDesktopFolder;HRESULT hr = SHGetDesktopFolder(&pDesktopFolder);if (FAILED(hr)){return hr;}OLECHAR olePath [MAX_PATH];// IShellFolder::ParseDisplayName requires the file name be in// Unicode.#ifdef _UNICODElstrcpy(olePath, lpszPath);#elseMultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpszPath, -1, olePath, MAX_PATH);#endif// Convert the path to an ITEMIDLIST.ULONG chEaten;ULONG dwAttributes;hr = pDesktopFolder->ParseDisplayName(NULL, NULL, olePath, &chEaten, &pidl, &dwAttributes);pDesktopFolder->Release();return hr;}