HOWTO: Convert a File Path to an ITEMIDLISTLast reviewed: January 5, 1998Article ID: Q132750 |
The information in this article applies to:
SUMMARYWhen developing an application that interacts with the Windows 95 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 INFORMATIONFollowing 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(); } |
Additional query words: 4.00 PIDL path file
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |