Article ID: 132750
Article Last Modified on 7/11/2005
LPITEMIDLIST pidl;
LPSHELLFOLDER pDesktopFolder;
char szPath[MAX_PATH];
OLECHAR olePath[MAX_PATH];
ULONG chEaten;
ULONG dwAttributes;
HRESULT hr;
//
// Get the path to the file we need to convert.
//
GetCurrentDirectory(MAX_PATH, szPath);
lstrcat(szPath, "\\readme.txt");
//
// Get a pointer to the Desktop's IShellFolder interface.
//
if (SUCCEEDED(SHGetDesktopFolder(&pDesktopFolder)))
{
//
// IShellFolder::ParseDisplayName requires the file name be in
// Unicode.
//
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szPath, -1,
olePath, MAX_PATH);
//
// Convert the path to an ITEMIDLIST.
//
hr = pDesktopFolder->lpVtbl->ParseDisplayName(pDesktopFolder,
NULL,
NULL,
olePath,
&chEaten,
&pidl,
&dwAttributes);
if (FAILED(hr))
{
// Handle error.
}
//
// pidl now contains a pointer to an ITEMIDLIST for .\readme.txt.
// This ITEMIDLIST needs to be freed using the IMalloc allocator
// returned from SHGetMalloc().
//
//release the desktop folder object
pDesktopFolder->lpVtbl->Release();
}
Additional query words: PIDL path file
Keywords: kbhowto KB132750