How To Convert a File Path to an ITEMIDLIST
Article ID | : | 132750 |
Last Review | : | July 11, 2005 |
Revision | : | 1.3 |
This article was previously published under Q132750
SUMMARY
When developing an application that interacts with the Windows Explorer shell, you may need to convert an arbitrary path to a file to an ITEMIDLIST. You can do this using the IShellFolder::ParseDisplayName API.
MORE INFORMATION
Following is an example of how to use the IShellFolder interface to convert the path to the file Readme.txt in the current directory to an ITEMIDLIST. The example is written in C. If the program is written using Visual C++, accessing member functions through the lpVtbl variable is unnecessary.
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();
}
APPLIES TO
• | Microsoft Platform Software Development Kit-January 2000 Edition |
'Windows' 카테고리의 다른 글
Windows Fundamentals for Legacy PCs v2006 SP2 설치 실패기 (0) | 2007.02.20 |
---|---|
Microsoft TechNet Offline Seminar, Feb. 15th 2007 정리 (0) | 2007.02.16 |
Windows 2003에서 Visual Studio 2005 서비스팩 1(SP1)이 설치가 안되요. ;ㅁ; (0) | 2007.02.14 |
Using COM to explore the namespace (0) | 2007.02.08 |
ITEMIDLIST management library (0) | 2007.02.06 |