4 * Copyright 1998 Juergen Schmied
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * a pidl == NULL means desktop and is legal
26 #include "wine/port.h"
34 #define NONAMELESSUNION
35 #define NONAMELESSSTRUCT
44 #include "undocshell.h"
45 #include "shell32_main.h"
51 #include "wine/debug.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(pidl);
54 WINE_DECLARE_DEBUG_CHANNEL(shell);
56 /* from comctl32.dll */
57 extern LPVOID WINAPI Alloc(INT);
58 extern BOOL WINAPI Free(LPVOID);
60 /*************************************************************************
61 * ILGetDisplayNameEx [SHELL32.186]
63 * Retrieves the display name of an ItemIDList
66 * psf [I] Shell Folder to start with, if NULL the desktop is used
67 * pidl [I] ItemIDList relativ to the psf to get the display name for
68 * path [O] Filled in with the display name, assumed to be at least MAX_PATH long
69 * type [I] Type of display name to retrieve
70 * 0 = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR uses always the desktop as root
71 * 1 = SHGDN_NORMAL relative to the root folder
72 * 2 = SHGDN_INFOLDER relative to the root folder, only the last name
75 * True if the display name could be retrieved successfully, False otherwise
77 BOOL WINAPI ILGetDisplayNameExA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPSTR path, DWORD type)
80 WCHAR wPath[MAX_PATH];
82 TRACE("%p %p %p %ld\n", psf, pidl, path, type);
87 ret = ILGetDisplayNameExW(psf, pidl, wPath, type);
88 WideCharToMultiByte(CP_ACP, 0, wPath, -1, path, MAX_PATH, NULL, NULL);
89 TRACE("%p %p %s\n", psf, pidl, debugstr_a(path));
94 BOOL WINAPI ILGetDisplayNameExW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPWSTR path, DWORD type)
96 LPSHELLFOLDER psfParent, lsf = psf;
97 HRESULT ret = NO_ERROR;
98 LPCITEMIDLIST pidllast;
102 TRACE("%p %p %p %ld\n", psf, pidl, path, type);
109 ret = SHGetDesktopFolder(&lsf);
114 if (type >= 0 && type <= 2)
118 case ILGDN_FORPARSING:
119 flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
125 flag = SHGDN_INFOLDER;
128 FIXME("Unknown type parameter = %lx\n", type);
129 flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
132 if (!*(const WORD*)pidl || type == ILGDN_FORPARSING)
134 ret = IShellFolder_GetDisplayNameOf(lsf, pidl, flag, &strret);
137 ret = StrRetToStrNW(path, MAX_PATH, &strret, pidl);
142 ret = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psfParent, &pidllast);
145 ret = IShellFolder_GetDisplayNameOf(psfParent, pidllast, flag, &strret);
148 ret = StrRetToStrNW(path, MAX_PATH, &strret, pidllast);
150 IShellFolder_Release(psfParent);
155 TRACE("%p %p %s\n", psf, pidl, debugstr_w(path));
158 IShellFolder_Release(lsf);
159 return SUCCEEDED(ret);
162 BOOL WINAPI ILGetDisplayNameEx(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPVOID path, DWORD type)
164 TRACE_(shell)("%p %p %p %ld\n", psf, pidl, path, type);
165 if (SHELL_OsIsUnicode())
166 return ILGetDisplayNameExW(psf, pidl, path, type);
167 return ILGetDisplayNameExA(psf, pidl, path, type);
170 /*************************************************************************
171 * ILGetDisplayName [SHELL32.15]
173 BOOL WINAPI ILGetDisplayName(LPCITEMIDLIST pidl, LPVOID path)
175 TRACE_(shell)("%p %p\n", pidl, path);
176 if (SHELL_OsIsUnicode())
177 return ILGetDisplayNameExW(NULL, pidl, path, ILGDN_FORPARSING);
178 return ILGetDisplayNameExA(NULL, pidl, path, ILGDN_FORPARSING);
181 /*************************************************************************
182 * ILFindLastID [SHELL32.16]
185 * observed: pidl=Desktop return=pidl
187 LPITEMIDLIST WINAPI ILFindLastID(LPCITEMIDLIST pidl)
189 LPCITEMIDLIST pidlLast = pidl;
191 TRACE("(pidl=%p)\n",pidl);
196 while (pidl->mkid.cb)
199 pidl = ILGetNext(pidl);
201 return (LPITEMIDLIST)pidlLast;
203 /*************************************************************************
204 * ILRemoveLastID [SHELL32.17]
207 * when pidl=Desktop return=FALSE
209 BOOL WINAPI ILRemoveLastID(LPITEMIDLIST pidl)
211 TRACE_(shell)("pidl=%p\n",pidl);
213 if (!pidl || !pidl->mkid.cb)
215 ILFindLastID(pidl)->mkid.cb = 0;
219 /*************************************************************************
220 * ILClone [SHELL32.18]
223 * duplicate an idlist
225 LPITEMIDLIST WINAPI ILClone (LPCITEMIDLIST pidl)
227 LPITEMIDLIST newpidl;
232 len = ILGetSize(pidl);
233 newpidl = (LPITEMIDLIST)SHAlloc(len);
235 memcpy(newpidl,pidl,len);
237 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
242 /*************************************************************************
243 * ILCloneFirst [SHELL32.19]
246 * duplicates the first idlist of a complex pidl
248 LPITEMIDLIST WINAPI ILCloneFirst(LPCITEMIDLIST pidl)
250 LPITEMIDLIST pidlNew = NULL;
252 TRACE("pidl=%p \n",pidl);
258 pidlNew = (LPITEMIDLIST) SHAlloc (len+2);
261 memcpy(pidlNew,pidl,len+2); /* 2 -> mind a desktop pidl */
264 ILGetNext(pidlNew)->mkid.cb = 0x00;
267 TRACE("-- newpidl=%p\n",pidlNew);
272 /*************************************************************************
273 * ILLoadFromStream (SHELL32.26)
276 * the first two bytes are the len, the pidl is following then
278 HRESULT WINAPI ILLoadFromStream (IStream * pStream, LPITEMIDLIST * ppPidl)
281 HRESULT ret = E_FAIL;
284 TRACE_(shell)("%p %p\n", pStream , ppPidl);
291 IStream_AddRef (pStream);
293 if (SUCCEEDED(IStream_Read(pStream, (LPVOID)&wLen, 2, &dwBytesRead)))
295 TRACE("PIDL length is %d\n", wLen);
297 *ppPidl = SHAlloc (wLen);
298 if (SUCCEEDED(IStream_Read(pStream, *ppPidl , wLen, &dwBytesRead))) {
299 TRACE("Stream read OK\n");
302 WARN("reading pidl failed\n");
312 /* we are not yet fully compatible */
313 if (*ppPidl && !pcheck(*ppPidl))
315 WARN("Check failed\n");
321 IStream_Release (pStream);
326 /*************************************************************************
327 * ILSaveToStream (SHELL32.27)
330 * the first two bytes are the len, the pidl is following then
332 HRESULT WINAPI ILSaveToStream (IStream * pStream, LPCITEMIDLIST pPidl)
336 HRESULT ret = E_FAIL;
338 TRACE_(shell)("%p %p\n", pStream, pPidl);
340 IStream_AddRef (pStream);
343 while (pidl->mkid.cb)
345 wLen += sizeof(WORD) + pidl->mkid.cb;
346 pidl = ILGetNext(pidl);
349 if (SUCCEEDED(IStream_Write(pStream, (LPVOID)&wLen, 2, NULL)))
351 if (SUCCEEDED(IStream_Write(pStream, pPidl, wLen, NULL)))
355 IStream_Release (pStream);
360 /*************************************************************************
361 * SHILCreateFromPath [SHELL32.28]
363 * Create an ItemIDList from a path
368 * attributes [I/O] requested attributes on call and actual attributes when
369 * the function returns
372 * NO_ERROR if successful, or an OLE errer code otherwise
375 * Wrapper for IShellFolder_ParseDisplayName().
377 HRESULT WINAPI SHILCreateFromPathA(LPCSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
380 WCHAR lpszDisplayName[MAX_PATH];
382 HRESULT ret = E_FAIL;
384 TRACE_(shell)("%s %p 0x%08lx\n", path, ppidl, attributes ? *attributes : 0);
386 if (!MultiByteToWideChar(CP_ACP, 0, path, -1, lpszDisplayName, MAX_PATH))
387 lpszDisplayName[MAX_PATH-1] = 0;
389 if (SUCCEEDED (SHGetDesktopFolder(&sf)))
391 ret = IShellFolder_ParseDisplayName(sf, 0, NULL, lpszDisplayName, &pchEaten, ppidl, attributes);
392 IShellFolder_Release(sf);
397 HRESULT WINAPI SHILCreateFromPathW(LPCWSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
401 HRESULT ret = E_FAIL;
403 TRACE_(shell)("%s %p 0x%08lx\n", debugstr_w(path), ppidl, attributes ? *attributes : 0);
405 if (SUCCEEDED (SHGetDesktopFolder(&sf)))
407 ret = IShellFolder_ParseDisplayName(sf, 0, NULL, (LPWSTR)path, &pchEaten, ppidl, attributes);
408 IShellFolder_Release(sf);
413 HRESULT WINAPI SHILCreateFromPathAW (LPCVOID path, LPITEMIDLIST * ppidl, DWORD * attributes)
415 if ( SHELL_OsIsUnicode())
416 return SHILCreateFromPathW (path, ppidl, attributes);
417 return SHILCreateFromPathA (path, ppidl, attributes);
420 /*************************************************************************
421 * SHCloneSpecialIDList [SHELL32.89]
423 * Create an ItemIDList to one of the special folders.
427 * nFolder [in] CSIDL_xxxxx
428 * fCreate [in] Create folder if it does not exist
431 * Success: The newly created pidl
432 * Failure: NULL, if inputs are invalid.
435 * exported by ordinal.
436 * Caller is responsible for deallocating the returned ItemIDList with the
437 * shells IMalloc interface, aka ILFree.
439 LPITEMIDLIST WINAPI SHCloneSpecialIDList(HWND hwndOwner, DWORD nFolder, BOOL fCreate)
440 { LPITEMIDLIST ppidl;
441 TRACE_(shell)("(hwnd=%p,csidl=0x%lx,%s).\n", hwndOwner, nFolder, fCreate ? "T" : "F");
444 nFolder |= CSIDL_FLAG_CREATE;
446 SHGetSpecialFolderLocation(hwndOwner, nFolder, &ppidl);
450 /*************************************************************************
451 * ILGlobalClone [SHELL32.20]
453 * Clones an ItemIDList using Alloc.
456 * pidl [I] ItemIDList to clone
459 * Newly allocated ItemIDList.
462 * exported by ordinal.
464 LPITEMIDLIST WINAPI ILGlobalClone(LPCITEMIDLIST pidl)
466 LPITEMIDLIST newpidl;
471 len = ILGetSize(pidl);
472 newpidl = (LPITEMIDLIST)Alloc(len);
474 memcpy(newpidl,pidl,len);
476 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
482 /*************************************************************************
483 * ILIsEqual [SHELL32.21]
486 BOOL WINAPI ILIsEqual(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
488 char szData1[MAX_PATH];
489 char szData2[MAX_PATH];
491 LPCITEMIDLIST pidltemp1 = pidl1;
492 LPCITEMIDLIST pidltemp2 = pidl2;
494 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
496 /* explorer reads from registry directly (StreamMRU),
497 so we can only check here */
498 if ((!pcheck (pidl1)) || (!pcheck (pidl2))) return FALSE;
503 if ( (!pidl1) || (!pidl2) ) return FALSE;
505 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
507 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
508 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
510 if (strcasecmp ( szData1, szData2 )!=0 )
513 pidltemp1 = ILGetNext(pidltemp1);
514 pidltemp2 = ILGetNext(pidltemp2);
517 if (!pidltemp1->mkid.cb && !pidltemp2->mkid.cb)
524 /*************************************************************************
525 * ILIsParent [SHELL32.23]
527 * Verifies that pidlParent is indeed the (immediate) parent of pidlChild.
532 * bImmediate [I] only return true if the parent is the direct parent
536 * True if the parent ItemIDlist is a complete part of the child ItemIdList,
540 * parent = a/b, child = a/b/c -> true, c is in folder a/b
541 * child = a/b/c/d -> false if bImmediate is true, d is not in folder a/b
542 * child = a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
544 BOOL WINAPI ILIsParent(LPCITEMIDLIST pidlParent, LPCITEMIDLIST pidlChild, BOOL bImmediate)
546 char szData1[MAX_PATH];
547 char szData2[MAX_PATH];
549 LPCITEMIDLIST pParent = pidlParent;
550 LPCITEMIDLIST pChild = pidlChild;
552 TRACE("%p %p %x\n", pidlParent, pidlChild, bImmediate);
554 if (!pParent || !pChild) return FALSE;
556 while (pParent->mkid.cb && pChild->mkid.cb)
558 _ILSimpleGetText(pParent, szData1, MAX_PATH);
559 _ILSimpleGetText(pChild, szData2, MAX_PATH);
561 if (strcasecmp ( szData1, szData2 )!=0 )
564 pParent = ILGetNext(pParent);
565 pChild = ILGetNext(pChild);
568 if ( pParent->mkid.cb || ! pChild->mkid.cb) /* child shorter or has equal length to parent */
571 if ( ILGetNext(pChild)->mkid.cb && bImmediate) /* not immediate descent */
577 /*************************************************************************
578 * ILFindChild [SHELL32.24]
580 * Compares elements from pidl1 and pidl2.
587 * pidl1 is desktop pidl2
588 * pidl1 shorter pidl2 pointer to first different element of pidl2
589 * if there was at least one equal element
590 * pidl2 shorter pidl1 0
591 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
594 * exported by ordinal.
596 LPITEMIDLIST WINAPI ILFindChild(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
598 char szData1[MAX_PATH];
599 char szData2[MAX_PATH];
601 LPCITEMIDLIST pidltemp1 = pidl1;
602 LPCITEMIDLIST pidltemp2 = pidl2;
603 LPCITEMIDLIST ret=NULL;
605 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
607 /* explorer reads from registry directly (StreamMRU),
608 so we can only check here */
609 if ((!pcheck (pidl1)) || (!pcheck (pidl2)))
615 if ( _ILIsDesktop(pidl1) )
621 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
623 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
624 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
626 if (strcasecmp(szData1,szData2))
629 pidltemp1 = ILGetNext(pidltemp1);
630 pidltemp2 = ILGetNext(pidltemp2);
634 if (pidltemp1->mkid.cb)
636 ret = NULL; /* elements of pidl1 left*/
639 TRACE_(shell)("--- %p\n", ret);
640 return (LPITEMIDLIST)ret; /* pidl 1 is shorter */
643 /*************************************************************************
644 * ILCombine [SHELL32.25]
646 * Concatenates two complex ItemIDLists.
649 * pidl1 [I] first complex ItemIDLists
650 * pidl2 [I] complex ItemIDLists to append
653 * if both pidl's == NULL NULL
654 * if pidl1 == NULL cloned pidl2
655 * if pidl2 == NULL cloned pidl1
656 * otherwise new pidl with pidl2 appended to pidl1
659 * exported by ordinal.
660 * Does not destroy the passed in ItemIDLists!
662 LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
665 LPITEMIDLIST pidlNew;
667 TRACE("pidl=%p pidl=%p\n",pidl1,pidl2);
669 if(!pidl1 && !pidl2) return NULL;
676 pidlNew = ILClone(pidl2);
682 pidlNew = ILClone(pidl1);
686 len1 = ILGetSize(pidl1)-2;
687 len2 = ILGetSize(pidl2);
688 pidlNew = SHAlloc(len1+len2);
692 memcpy(pidlNew,pidl1,len1);
693 memcpy(((BYTE *)pidlNew)+len1,pidl2,len2);
696 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
700 /*************************************************************************
701 * SHGetRealIDL [SHELL32.98]
705 HRESULT WINAPI SHGetRealIDL(LPSHELLFOLDER lpsf, LPCITEMIDLIST pidlSimple, LPITEMIDLIST *pidlReal)
707 IDataObject* pDataObj;
708 HRESULT hr = IShellFolder_GetUIObjectOf(lpsf, 0, 1, &pidlSimple, &IID_IDataObject, 0, (LPVOID*)&pDataObj);
714 fmt.cfFormat = RegisterClipboardFormatA(CFSTR_SHELLIDLIST);
716 fmt.dwAspect = DVASPECT_CONTENT;
718 fmt.tymed = TYMED_HGLOBAL;
720 hr = IDataObject_GetData(pDataObj, &fmt, &medium);
722 IDataObject_Release(pDataObj);
725 /*assert(pida->cidl==1);*/
726 LPIDA pida = (LPIDA)GlobalLock(medium.u.hGlobal);
728 LPCITEMIDLIST pidl_folder = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[0]);
729 LPCITEMIDLIST pidl_child = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[1]);
731 *pidlReal = ILCombine(pidl_folder, pidl_child);
736 GlobalUnlock(medium.u.hGlobal);
737 GlobalFree(medium.u.hGlobal);
744 /*************************************************************************
745 * SHLogILFromFSIL [SHELL32.95]
748 * pild = CSIDL_DESKTOP ret = 0
749 * pild = CSIDL_DRIVES ret = 0
751 LPITEMIDLIST WINAPI SHLogILFromFSIL(LPITEMIDLIST pidl)
753 FIXME("(pidl=%p)\n",pidl);
760 /*************************************************************************
761 * ILGetSize [SHELL32.152]
763 * Gets the byte size of an ItemIDList including zero terminator
766 * pidl [I] ItemIDList
769 * size of pidl in bytes
772 * exported by ordinal
774 UINT WINAPI ILGetSize(LPCITEMIDLIST pidl)
776 LPCSHITEMID si = &(pidl->mkid);
782 si = (LPCSHITEMID)(((const BYTE*)si)+si->cb);
786 TRACE("pidl=%p size=%u\n",pidl, len);
790 /*************************************************************************
791 * ILGetNext [SHELL32.153]
793 * Gets the next ItemID of an ItemIDList
796 * pidl [I] ItemIDList
801 * simple pidl -> pointer to 0x0000 element
804 * exported by ordinal.
806 LPITEMIDLIST WINAPI ILGetNext(LPCITEMIDLIST pidl)
817 pidl = (LPCITEMIDLIST) (((const BYTE*)pidl)+len);
818 TRACE("-- %p\n", pidl);
819 return (LPITEMIDLIST)pidl;
825 /*************************************************************************
826 * ILAppend [SHELL32.154]
828 * Adds the single ItemID item to the ItemIDList indicated by pidl.
829 * If bEnd is FALSE, inserts the item in the front of the list,
830 * otherwise it adds the item to the end. (???)
833 * pidl [I] ItemIDList to extend
834 * item [I] ItemID to prepend/append
835 * bEnd [I] Indicates if the item should be appended
838 * Destroys the passed in idlist! (???)
840 LPITEMIDLIST WINAPI ILAppend(LPITEMIDLIST pidl, LPCITEMIDLIST item, BOOL bEnd)
844 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl,item,bEnd);
849 if (_ILIsDesktop(pidl))
851 idlRet = ILClone(item);
859 idlRet = ILCombine(pidl, item);
863 idlRet = ILCombine(item, pidl);
870 /*************************************************************************
871 * ILFree [SHELL32.155]
873 * Frees memory (if not NULL) allocated by SHMalloc allocator
879 * exported by ordinal
881 void WINAPI ILFree(LPITEMIDLIST pidl)
883 TRACE("(pidl=%p)\n",pidl);
884 if(pidl) SHFree(pidl);
887 /*************************************************************************
888 * ILGlobalFree [SHELL32.156]
890 * Frees memory (if not NULL) allocated by Alloc allocator
896 * exported by ordinal.
898 void WINAPI ILGlobalFree( LPITEMIDLIST pidl)
906 /*************************************************************************
907 * ILCreateFromPathA [SHELL32.189]
909 * Creates a complex ItemIDList from a path and returns it.
915 * the newly created complex ItemIDList or NULL if failed
918 * exported by ordinal.
921 LPITEMIDLIST WINAPI ILCreateFromPathA (LPCSTR path)
923 LPITEMIDLIST pidlnew = NULL;
925 TRACE_(shell)("%s\n", debugstr_a(path));
927 if (SUCCEEDED(SHILCreateFromPathA(path, &pidlnew, NULL)))
932 /*************************************************************************
933 * ILCreateFromPathW [SHELL32.190]
935 LPITEMIDLIST WINAPI ILCreateFromPathW (LPCWSTR path)
937 LPITEMIDLIST pidlnew = NULL;
939 TRACE_(shell)("%s\n", debugstr_w(path));
941 if (SUCCEEDED(SHILCreateFromPathW(path, &pidlnew, NULL)))
946 /*************************************************************************
947 * ILCreateFromPath [SHELL32.157]
949 LPITEMIDLIST WINAPI ILCreateFromPathAW (LPCVOID path)
951 if ( SHELL_OsIsUnicode())
952 return ILCreateFromPathW (path);
953 return ILCreateFromPathA (path);
956 /*************************************************************************
957 * _ILParsePathW [internal]
959 * Creates an ItemIDList from a path and returns it.
962 * path [I] path to parse and convert into an ItemIDList
963 * lpFindFile [I] pointer to buffer to initialize the FileSystem
964 * Bind Data object with
965 * bBindCtx [I] indicates to create a BindContext and assign a
966 * FileSystem Bind Data object
967 * ppidl [O] the newly create ItemIDList
968 * prgfInOut [I/O] requested attributes on input and actual
969 * attributes on return
972 * NO_ERROR on success or an OLE error code
975 * If either lpFindFile is non-NULL or bBindCtx is TRUE, this function
976 * creates a BindContext object and assigns a FileSystem Bind Data object
977 * to it, passing the BindContext to IShellFolder_ParseDisplayName. Each
978 * IShellFolder uses that FileSystem Bind Data object of the BindContext
979 * to pass data about the current path element to the next object. This
980 * is used to avoid having to verify the current path element on disk, so
981 * that creating an ItemIDList from a non-existent path still can work.
983 static HRESULT WINAPI _ILParsePathW(LPCWSTR path, LPWIN32_FIND_DATAW lpFindFile,
984 BOOL bBindCtx, LPITEMIDLIST *ppidl, LPDWORD prgfInOut)
986 LPSHELLFOLDER pSF = NULL;
990 TRACE("%s %p %d (%p)->%p (%p)->0x%lx\n", debugstr_w(path), lpFindFile, bBindCtx,
991 ppidl, ppidl ? *ppidl : NULL,
992 prgfInOut, prgfInOut ? *prgfInOut : 0);
994 ret = SHGetDesktopFolder(&pSF);
1000 if (lpFindFile || bBindCtx)
1001 ret = IFileSystemBindData_Constructor(lpFindFile, &pBC);
1005 ret = IShellFolder_ParseDisplayName(pSF, 0, pBC, (LPOLESTR)path, NULL, ppidl, prgfInOut);
1010 IBindCtx_Release(pBC);
1014 IShellFolder_Release(pSF);
1016 if (!SUCCEEDED(ret) && ppidl)
1019 TRACE("%s %p 0x%lx\n", debugstr_w(path), ppidl ? *ppidl : NULL, prgfInOut ? *prgfInOut : 0);
1024 /*************************************************************************
1025 * SHSimpleIDListFromPath [SHELL32.162]
1027 * Creates a simple ItemIDList from a path and returns it. This function
1028 * does not fail on non-existent paths.
1031 * path [I] path to parse and convert into an ItemIDList
1034 * the newly created simple ItemIDList
1037 * Simple in the name does not mean a relative ItemIDList but rather a
1038 * fully qualified list, where only the file name is filled in and the
1039 * directory flag for those ItemID elements this is known about, eg.
1040 * it is not the last element in the ItemIDList or the actual directory
1042 * exported by ordinal.
1044 LPITEMIDLIST WINAPI SHSimpleIDListFromPathA(LPCSTR lpszPath)
1046 LPITEMIDLIST pidl = NULL;
1047 LPWSTR wPath = NULL;
1050 TRACE("%s\n", debugstr_a(lpszPath));
1054 len = MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, NULL, 0);
1055 wPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1056 MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, wPath, len);
1059 _ILParsePathW(wPath, NULL, TRUE, &pidl, NULL);
1061 if (wPath) HeapFree(GetProcessHeap(), 0, wPath);
1062 TRACE("%s %p\n", debugstr_a(lpszPath), pidl);
1066 LPITEMIDLIST WINAPI SHSimpleIDListFromPathW(LPCWSTR lpszPath)
1068 LPITEMIDLIST pidl = NULL;
1070 TRACE("%s\n", debugstr_w(lpszPath));
1072 _ILParsePathW(lpszPath, NULL, TRUE, &pidl, NULL);
1073 TRACE("%s %p\n", debugstr_w(lpszPath), pidl);
1077 LPITEMIDLIST WINAPI SHSimpleIDListFromPathAW(LPCVOID lpszPath)
1079 if ( SHELL_OsIsUnicode())
1080 return SHSimpleIDListFromPathW (lpszPath);
1081 return SHSimpleIDListFromPathA (lpszPath);
1084 /*************************************************************************
1085 * SHGetDataFromIDListA [SHELL32.247]
1088 * the pidl can be a simple one. since we can't get the path out of the pidl
1089 * we have to take all data from the pidl
1091 HRESULT WINAPI SHGetDataFromIDListA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, int nFormat, LPVOID dest, int len)
1093 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
1096 if (!psf || !dest ) return E_INVALIDARG;
1100 case SHGDFIL_FINDDATA:
1102 LPSTR filename, shortname;
1103 WIN32_FIND_DATAA * pfd = dest;
1105 if (_ILIsDrive(pidl))
1106 return E_INVALIDARG;
1108 if (len < (int)sizeof(WIN32_FIND_DATAA)) return E_INVALIDARG;
1110 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1111 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1112 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1113 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1115 filename = _ILGetTextPointer(pidl);
1116 shortname = _ILGetSTextPointer(pidl);
1119 lstrcpynA(pfd->cFileName, filename, MAX_PATH);
1121 pfd->cFileName[0] = '\0';
1124 lstrcpynA(pfd->cAlternateFileName, shortname, MAX_PATH);
1126 pfd->cAlternateFileName[0] = '\0';
1130 case SHGDFIL_NETRESOURCE:
1131 case SHGDFIL_DESCRIPTIONID:
1132 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1136 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1139 return E_INVALIDARG;
1142 /*************************************************************************
1143 * SHGetDataFromIDListW [SHELL32.248]
1146 HRESULT WINAPI SHGetDataFromIDListW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, int nFormat, LPVOID dest, int len)
1148 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
1152 if (! psf || !dest ) return E_INVALIDARG;
1156 case SHGDFIL_FINDDATA:
1158 LPSTR filename, shortname;
1159 WIN32_FIND_DATAW * pfd = dest;
1161 if (_ILIsDrive(pidl))
1162 return E_INVALIDARG;
1164 if (len < (int)sizeof(WIN32_FIND_DATAW)) return E_INVALIDARG;
1166 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1167 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1168 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1169 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1171 filename = _ILGetTextPointer(pidl);
1172 shortname = _ILGetSTextPointer(pidl);
1175 pfd->cFileName[0] = '\0';
1176 else if (!MultiByteToWideChar(CP_ACP, 0, filename, -1, pfd->cFileName, MAX_PATH))
1177 pfd->cFileName[MAX_PATH-1] = 0;
1180 pfd->cAlternateFileName[0] = '\0';
1181 else if (!MultiByteToWideChar(CP_ACP, 0, shortname, -1, pfd->cAlternateFileName, 14))
1182 pfd->cAlternateFileName[13] = 0;
1185 case SHGDFIL_NETRESOURCE:
1186 case SHGDFIL_DESCRIPTIONID:
1187 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1191 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1194 return E_INVALIDARG;
1197 /*************************************************************************
1198 * SHELL_GetPathFromIDListA
1200 HRESULT SHELL_GetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath, UINT uOutSize)
1206 /* One case is a PIDL rooted at desktop level */
1207 if (_ILIsValue(pidl) || _ILIsFolder(pidl)) {
1208 hr = SHGetSpecialFolderPathA(0, pszPath, CSIDL_DESKTOP, FALSE);
1211 PathAddBackslashA(pszPath);
1213 /* The only other valid case is a item ID list beginning at "My Computer" */
1214 else if (_ILIsMyComputer(pidl))
1215 pidl = ILGetNext(pidl);
1217 if (SUCCEEDED(hr)) {
1220 while(pidl && pidl->mkid.cb) {
1221 if (_ILIsSpecialFolder(pidl))
1222 {hr = E_INVALIDARG; break;}
1224 txt = _ILGetTextPointer(pidl);
1226 {hr = E_INVALIDARG; break;}
1228 if (lstrlenA(txt) > pidl->mkid.cb)
1229 ERR("pidl %p is borked\n",pidl);
1231 /* make sure there's enough space for the next segment */
1232 if ( (lstrlenA(txt) + lstrlenA(pszPath)) > uOutSize)
1233 {hr = E_INVALIDARG; break;}
1234 lstrcatA( pszPath, txt );
1236 pidl = ILGetNext(pidl);
1238 {hr = E_INVALIDARG; break;}
1240 if (!pidl->mkid.cb) {
1241 /* We are at the end and successfully converted the complete PIDL. */
1245 if( (lstrlenA(pszPath) + 1) > uOutSize)
1246 {hr = E_INVALIDARG; break;}
1247 if (!PathAddBackslashA(pszPath))
1248 {hr = E_INVALIDARG; break;}
1253 TRACE_(shell)("-- %s, 0x%08lx\n", pszPath, hr);
1257 /*************************************************************************
1258 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
1262 * pszPath [OUT] path
1265 * path from a passed PIDL.
1268 * NULL returns FALSE
1269 * desktop pidl gives path to desktop directory back
1270 * special pidls returning FALSE
1272 BOOL WINAPI SHGetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath)
1276 TRACE_(shell)("(pidl=%p,%p)\n",pidl,pszPath);
1282 hr = SHELL_GetPathFromIDListA(pidl, pszPath, MAX_PATH);
1284 return SUCCEEDED(hr);
1287 /*************************************************************************
1288 * SHELL_GetPathFromIDListW
1290 HRESULT SHELL_GetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath, UINT uOutSize)
1297 /* One case is a PIDL rooted at desktop level */
1298 if (_ILIsValue(pidl) || _ILIsFolder(pidl)) {
1299 hr = SHGetSpecialFolderPathW(0, pszPath, CSIDL_DESKTOP, FALSE);
1302 PathAddBackslashW(pszPath);
1304 /* The only other valid case is a item ID list beginning at "My Computer" */
1305 else if (_ILIsMyComputer(pidl))
1306 pidl = ILGetNext(pidl);
1308 if (SUCCEEDED(hr)) {
1311 while(pidl && pidl->mkid.cb) {
1312 if (_ILIsSpecialFolder(pidl))
1313 {hr = E_INVALIDARG; break;}
1315 txt = _ILGetTextPointer(pidl);
1317 {hr = E_INVALIDARG; break;}
1319 if (lstrlenA(txt) > pidl->mkid.cb)
1320 ERR("pidl %p is borked\n",pidl);
1321 len = MultiByteToWideChar(CP_ACP, 0, txt, -1, NULL, 0);
1322 if ( (lstrlenW(pszPath) + len) > uOutSize )
1323 {hr = E_INVALIDARG; break;}
1325 MultiByteToWideChar(CP_ACP, 0, txt, -1,
1326 &pszPath[lstrlenW(pszPath)], len);
1328 pidl = ILGetNext(pidl);
1330 {hr = E_INVALIDARG; break;}
1332 if (!pidl->mkid.cb) {
1333 /* We are at the end and successfully converted the complete PIDL. */
1337 if ( (lstrlenW(pszPath) + 1) > uOutSize )
1338 {hr = E_INVALIDARG; break;}
1339 if (!PathAddBackslashW(pszPath))
1340 {hr = E_INVALIDARG; break;}
1345 TRACE_(shell)("-- %s, 0x%08lx\n", debugstr_w(pszPath), hr);
1349 /*************************************************************************
1350 * SHGetPathFromIDListW [SHELL32.@]
1352 BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
1356 TRACE_(shell)("(pidl=%p,%p)\n", pidl, debugstr_w(pszPath));
1362 hr = SHELL_GetPathFromIDListW(pidl, pszPath, MAX_PATH);
1364 TRACE_(shell)("-- %s, 0x%08lx\n",debugstr_w(pszPath), hr);
1365 return SUCCEEDED(hr);
1368 /*************************************************************************
1369 * SHGetPathFromIDList [SHELL32.@][NT 4.0: SHELL32.219]
1371 BOOL WINAPI SHGetPathFromIDListAW(LPCITEMIDLIST pidl,LPVOID pszPath)
1373 TRACE_(shell)("(pidl=%p,%p)\n",pidl,pszPath);
1375 if (SHELL_OsIsUnicode())
1376 return SHGetPathFromIDListW(pidl,pszPath);
1377 return SHGetPathFromIDListA(pidl,pszPath);
1380 /*************************************************************************
1381 * SHBindToParent [shell version 5.0]
1383 HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
1386 LPITEMIDLIST pidlChild, pidlParent;
1389 TRACE_(shell)("pidl=%p\n", pidl);
1393 if (ppidlLast) *ppidlLast = NULL;
1395 if (_ILIsPidlSimple(pidl))
1397 IShellFolder* desktop;
1399 /* we are on desktop level */
1400 hr = SHGetDesktopFolder(&desktop);
1404 hr = IShellFolder_QueryInterface(desktop, riid, ppv);
1406 if (SUCCEEDED(hr) && ppidlLast)
1407 *ppidlLast = ILClone(pidl);
1409 IShellFolder_Release(desktop);
1414 pidlChild = ILClone(ILFindLastID(pidl));
1415 pidlParent = ILClone(pidl);
1416 ILRemoveLastID(pidlParent);
1418 hr = SHGetDesktopFolder(&psf);
1421 hr = IShellFolder_BindToObject(psf, pidlParent, NULL, riid, ppv);
1423 if (SUCCEEDED(hr) && ppidlLast)
1424 *ppidlLast = pidlChild;
1428 SHFree (pidlParent);
1429 if (psf) IShellFolder_Release(psf);
1433 TRACE_(shell)("-- psf=%p pidl=%p ret=0x%08lx\n", *ppv, (ppidlLast)?*ppidlLast:NULL, hr);
1437 /**************************************************************************
1439 * internal functions
1441 * ### 1. section creating pidls ###
1443 *************************************************************************
1445 LPITEMIDLIST _ILAlloc(PIDLTYPE type, size_t size)
1447 LPITEMIDLIST pidlOut = NULL;
1449 if((pidlOut = SHAlloc(size + 5)))
1452 LPITEMIDLIST pidlNext;
1454 ZeroMemory(pidlOut, size + 5);
1455 pidlOut->mkid.cb = size + 3;
1457 if ((pData = _ILGetDataPointer(pidlOut)))
1460 if ((pidlNext = ILGetNext(pidlOut)))
1461 pidlNext->mkid.cb = 0x00;
1462 TRACE("-- (pidl=%p, size=%u)\n", pidlOut, size);
1468 LPITEMIDLIST _ILCreateDesktop()
1479 LPITEMIDLIST _ILCreateMyComputer()
1481 return _ILCreateGuid(PT_GUID, &CLSID_MyComputer);
1484 LPITEMIDLIST _ILCreateIExplore()
1486 return _ILCreateGuid(PT_GUID, &CLSID_Internet);
1489 LPITEMIDLIST _ILCreateControlPanel()
1491 LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL;
1496 LPITEMIDLIST cpl = _ILCreateGuid(PT_SHELLEXT, &CLSID_ControlPanel);
1500 ret = ILCombine(parent, cpl);
1508 LPITEMIDLIST _ILCreatePrinters()
1510 LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL;
1515 LPITEMIDLIST printers = _ILCreateGuid(PT_YAGUID, &CLSID_Printers);
1519 ret = ILCombine(parent, printers);
1527 LPITEMIDLIST _ILCreateNetwork()
1529 return _ILCreateGuid(PT_GUID, &CLSID_NetworkPlaces);
1532 LPITEMIDLIST _ILCreateBitBucket()
1534 return _ILCreateGuid(PT_GUID, &CLSID_RecycleBin);
1537 LPITEMIDLIST _ILCreateGuid(PIDLTYPE type, REFIID guid)
1539 LPITEMIDLIST pidlOut;
1541 if (type == PT_SHELLEXT || type == PT_GUID || type == PT_YAGUID)
1543 pidlOut = _ILAlloc(type, sizeof(GUIDStruct));
1546 LPPIDLDATA pData = _ILGetDataPointer(pidlOut);
1548 memcpy(&(pData->u.guid.guid), guid, sizeof(GUID));
1549 TRACE("-- create GUID-pidl %s\n",
1550 debugstr_guid(&(pData->u.guid.guid)));
1555 WARN("%d: invalid type for GUID\n", type);
1561 LPITEMIDLIST _ILCreateGuidFromStrA(LPCSTR szGUID)
1565 if (!SUCCEEDED(SHCLSIDFromStringA(szGUID, &iid)))
1567 ERR("%s is not a GUID\n", szGUID);
1570 return _ILCreateGuid(PT_GUID, &iid);
1573 LPITEMIDLIST _ILCreateFromFindDataA(WIN32_FIND_DATAA * stffile )
1575 char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1576 char * pbuff = buff;
1584 TRACE("(%s, %s)\n",stffile->cAlternateFileName, stffile->cFileName);
1586 /* prepare buffer with both names */
1587 len = strlen (stffile->cFileName) + 1;
1588 memcpy (pbuff, stffile->cFileName, len);
1591 len1 = strlen (stffile->cAlternateFileName)+1;
1592 memcpy (pbuff, stffile->cAlternateFileName, len1);
1594 type = (stffile->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? PT_FOLDER :
1596 /* FileStruct already has one byte for the first name, so use len - 1 in
1599 if ((pidl = _ILAlloc(type, sizeof(FileStruct) + (len - 1) + len1)))
1604 /* set attributes */
1605 if ((pData = _ILGetDataPointer(pidl)))
1608 FileTimeToDosDateTime(&(stffile->ftLastWriteTime),&pData->u.file.uFileDate,&pData->u.file.uFileTime);
1609 pData->u.file.dwFileSize = stffile->nFileSizeLow;
1610 pData->u.file.uFileAttribs = (WORD)stffile->dwFileAttributes;
1612 if ((pszDest = _ILGetTextPointer(pidl)))
1614 memcpy(pszDest, buff, len + len1);
1615 TRACE("-- create Value: %s\n",debugstr_a(pszDest));
1621 HRESULT _ILCreateFromPathA(LPCSTR szPath, LPITEMIDLIST* ppidl)
1624 WIN32_FIND_DATAA stffile;
1627 return E_INVALIDARG;
1629 hFile = FindFirstFileA(szPath, &stffile);
1631 if (hFile == INVALID_HANDLE_VALUE)
1632 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
1636 *ppidl = _ILCreateFromFindDataA(&stffile);
1638 return *ppidl ? S_OK : E_OUTOFMEMORY;
1641 LPITEMIDLIST _ILCreateDrive(LPCWSTR lpszNew)
1644 LPITEMIDLIST pidlOut;
1646 sTemp[0]=toupperW(lpszNew[0]);
1650 TRACE("(%s)\n",debugstr_w(sTemp));
1652 if ((pidlOut = _ILAlloc(PT_DRIVE, sizeof(DriveStruct))))
1656 if ((pszDest = _ILGetTextPointer(pidlOut)))
1658 WideCharToMultiByte(CP_ACP, 0, sTemp, sizeof(sTemp)/sizeof(WCHAR), pszDest, sizeof(sTemp)/sizeof(WCHAR), NULL, NULL);
1659 TRACE("-- create Drive: %s\n", debugstr_a(pszDest));
1665 /**************************************************************************
1668 * Gets the text for the drive eg. 'c:\'
1673 DWORD _ILGetDrive(LPCITEMIDLIST pidl,LPSTR pOut, UINT uSize)
1674 { TRACE("(%p,%p,%u)\n",pidl,pOut,uSize);
1676 if(_ILIsMyComputer(pidl))
1677 pidl = ILGetNext(pidl);
1679 if (pidl && _ILIsDrive(pidl))
1680 return _ILSimpleGetText(pidl, pOut, uSize);
1685 /**************************************************************************
1687 * ### 2. section testing pidls ###
1689 **************************************************************************
1692 * _ILIsSpecialFolder()
1698 BOOL _ILIsDesktop(LPCITEMIDLIST pidl)
1699 { TRACE("(%p)\n",pidl);
1700 return pidl && pidl->mkid.cb ? 0 : 1;
1703 BOOL _ILIsMyComputer(LPCITEMIDLIST pidl)
1705 REFIID iid = _ILGetGUIDPointer(pidl);
1707 TRACE("(%p)\n",pidl);
1710 return IsEqualIID(iid, &CLSID_MyComputer);
1714 BOOL _ILIsSpecialFolder (LPCITEMIDLIST pidl)
1716 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1717 TRACE("(%p)\n",pidl);
1718 return (pidl && ( (lpPData && (PT_GUID== lpPData->type || PT_SHELLEXT== lpPData->type)) ||
1719 (pidl && pidl->mkid.cb == 0x00)
1723 BOOL _ILIsDrive(LPCITEMIDLIST pidl)
1724 { LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1725 TRACE("(%p)\n",pidl);
1726 return (pidl && lpPData && (PT_DRIVE == lpPData->type ||
1727 PT_DRIVE1 == lpPData->type ||
1728 PT_DRIVE2 == lpPData->type ||
1729 PT_DRIVE3 == lpPData->type));
1732 BOOL _ILIsFolder(LPCITEMIDLIST pidl)
1733 { LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1734 TRACE("(%p)\n",pidl);
1735 return (pidl && lpPData && (PT_FOLDER == lpPData->type || PT_FOLDER1 == lpPData->type));
1738 BOOL _ILIsValue(LPCITEMIDLIST pidl)
1739 { LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1740 TRACE("(%p)\n",pidl);
1741 return (pidl && lpPData && PT_VALUE == lpPData->type);
1744 BOOL _ILIsCPanelStruct(LPCITEMIDLIST pidl)
1745 { LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1746 TRACE("(%p)\n",pidl);
1747 return (pidl && lpPData && (lpPData->type == 0));
1750 /**************************************************************************
1753 BOOL _ILIsPidlSimple ( LPCITEMIDLIST pidl)
1757 if(! _ILIsDesktop(pidl)) /* pidl=NULL or mkid.cb=0 */
1759 WORD len = pidl->mkid.cb;
1760 LPCITEMIDLIST pidlnext = (LPCITEMIDLIST) (((const BYTE*)pidl) + len );
1761 if (pidlnext->mkid.cb)
1765 TRACE("%s\n", ret ? "Yes" : "No");
1769 /**************************************************************************
1771 * ### 3. section getting values from pidls ###
1774 /**************************************************************************
1777 * gets the text for the first item in the pidl (eg. simple pidl)
1779 * returns the length of the string
1781 DWORD _ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
1786 char szTemp[MAX_PATH];
1788 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1790 if (!pidl) return 0;
1795 if (_ILIsDesktop(pidl))
1798 if (HCR_GetClassNameA(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1801 lstrcpynA(szOut, szTemp, uOutSize);
1803 dwReturn = strlen (szTemp);
1806 else if (( szSrc = _ILGetTextPointer(pidl) ))
1810 lstrcpynA(szOut, szSrc, uOutSize);
1812 dwReturn = strlen(szSrc);
1814 else if (( riid = _ILGetGUIDPointer(pidl) ))
1816 /* special folder */
1817 if ( HCR_GetClassNameA(riid, szTemp, MAX_PATH) )
1820 lstrcpynA(szOut, szTemp, uOutSize);
1822 dwReturn = strlen (szTemp);
1827 ERR("-- no text\n");
1830 TRACE("-- (%p=%s 0x%08lx)\n",szOut,debugstr_a(szOut),dwReturn);
1834 /**************************************************************************
1837 * gets the text for the first item in the pidl (eg. simple pidl)
1839 * returns the length of the string
1841 DWORD _ILSimpleGetTextW (LPCITEMIDLIST pidl, LPWSTR szOut, UINT uOutSize)
1844 char szTemp[MAX_PATH];
1846 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1848 dwReturn = _ILSimpleGetText(pidl, szTemp, uOutSize);
1850 if (!MultiByteToWideChar(CP_ACP, 0, szTemp, -1, szOut, MAX_PATH))
1853 TRACE("-- (%p=%s 0x%08lx)\n",szOut,debugstr_w(szOut),dwReturn);
1857 /**************************************************************************
1859 * ### 4. getting pointers to parts of pidls ###
1861 **************************************************************************
1862 * _ILGetDataPointer()
1864 LPPIDLDATA _ILGetDataPointer(LPCITEMIDLIST pidl)
1866 if(pidl && pidl->mkid.cb != 0x00)
1867 return (LPPIDLDATA) &(pidl->mkid.abID);
1871 /**************************************************************************
1872 * _ILGetTextPointer()
1873 * gets a pointer to the long filename string stored in the pidl
1875 LPSTR _ILGetTextPointer(LPCITEMIDLIST pidl)
1876 {/* TRACE(pidl,"(pidl%p)\n", pidl);*/
1878 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
1882 switch (pdata->type)
1893 return (LPSTR)&(pdata->u.drive.szDriveName);
1900 return (LPSTR)&(pdata->u.file.szNames);
1905 case PT_NETPROVIDER:
1907 return (LPSTR)&(pdata->u.network.szNames);
1913 /**************************************************************************
1914 * _ILGetSTextPointer()
1915 * gets a pointer to the short filename string stored in the pidl
1917 LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl)
1918 {/* TRACE(pidl,"(pidl%p)\n", pidl);*/
1920 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1924 switch (pdata->type)
1930 return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1);
1933 return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1);
1939 /**************************************************************************
1940 * _ILGetGUIDPointer()
1942 * returns reference to guid stored in some pidls
1944 IID* _ILGetGUIDPointer(LPCITEMIDLIST pidl)
1946 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1948 TRACE("%p\n", pidl);
1952 TRACE("pdata->type 0x%04x\n", pdata->type);
1953 switch (pdata->type)
1957 return &(pdata->u.guid.guid);
1960 TRACE("Unknown pidl type 0x%04x\n", pdata->type);
1967 /*************************************************************************
1968 * _ILGetFileDateTime
1970 * Given the ItemIdList, get the FileTime
1973 * pidl [I] The ItemIDList
1974 * pFt [I] the resulted FILETIME of the file
1977 * True if Successful
1982 BOOL _ILGetFileDateTime(LPCITEMIDLIST pidl, FILETIME *pFt)
1984 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
1986 if(! pdata) return FALSE;
1988 switch (pdata->type)
1992 DosDateTimeToFileTime(pdata->u.file.uFileDate, pdata->u.file.uFileTime, pFt);
2000 BOOL _ILGetFileDate (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2006 if (_ILGetFileDateTime( pidl, &ft )) {
2007 FileTimeToLocalFileTime(&ft, &lft);
2008 FileTimeToSystemTime (&lft, &time);
2009 ret = GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&time, NULL, pOut, uOutSize);
2018 /*************************************************************************
2021 * Given the ItemIdList, get the FileSize
2024 * pidl [I] The ItemIDList
2025 * pOut [I] The buffer to save the result
2026 * uOutsize [I] The size of the buffer
2032 * pOut can be null when no string is needed
2035 DWORD _ILGetFileSize (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2037 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2040 if(! pdata) return 0;
2042 switch (pdata->type)
2045 dwSize = pdata->u.file.dwFileSize;
2046 if (pOut) StrFormatByteSizeA(dwSize, pOut, uOutSize);
2049 if (pOut) *pOut = 0x00;
2053 BOOL _ILGetExtension (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2055 char szTemp[MAX_PATH];
2056 const char * pPoint;
2057 LPCITEMIDLIST pidlTemp=pidl;
2059 TRACE("pidl=%p\n",pidl);
2061 if (!pidl) return FALSE;
2063 pidlTemp = ILFindLastID(pidl);
2065 if (!_ILIsValue(pidlTemp)) return FALSE;
2066 if (!_ILSimpleGetText(pidlTemp, szTemp, MAX_PATH)) return FALSE;
2068 pPoint = PathFindExtensionA(szTemp);
2070 if (! *pPoint) return FALSE;
2073 lstrcpynA(pOut, pPoint, uOutSize);
2079 /*************************************************************************
2082 * Given the ItemIdList, get the file type description
2085 * pidl [I] The ItemIDList (simple)
2086 * pOut [I] The buffer to save the result
2087 * uOutsize [I] The size of the buffer
2093 * This function copies as much as possible into the buffer.
2095 void _ILGetFileType(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2097 if(_ILIsValue(pidl))
2104 if (_ILGetExtension (pidl, sTemp, 64))
2106 if (!( HCR_MapTypeToValueA(sTemp, sTemp, 64, TRUE)
2107 && HCR_MapTypeToValueA(sTemp, pOut, uOutSize, FALSE )))
2109 lstrcpynA (pOut, sTemp, uOutSize - 6);
2110 strcat (pOut, "-file");
2116 lstrcpynA(pOut, "Folder", uOutSize);
2120 /*************************************************************************
2121 * _ILGetFileAttributes
2123 * Given the ItemIdList, get the Attrib string format
2126 * pidl [I] The ItemIDList
2127 * pOut [I] The buffer to save the result
2128 * uOutsize [I] The size of the Buffer
2134 * return value 0 in case of error is a valid return value
2137 DWORD _ILGetFileAttributes(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2139 LPPIDLDATA pData = _ILGetDataPointer(pidl);
2143 if(! pData) return 0;
2149 wAttrib = pData->u.file.uFileAttribs;
2156 if(wAttrib & FILE_ATTRIBUTE_READONLY)
2160 if(wAttrib & FILE_ATTRIBUTE_HIDDEN)
2164 if(wAttrib & FILE_ATTRIBUTE_SYSTEM)
2168 if(wAttrib & FILE_ATTRIBUTE_ARCHIVE)
2172 if(wAttrib & FILE_ATTRIBUTE_COMPRESSED)
2181 /*************************************************************************
2184 * free a aPidl struct
2186 void _ILFreeaPidl(LPITEMIDLIST * apidl, UINT cidl)
2192 for (i = 0; i < cidl; i++) SHFree(apidl[i]);
2197 /*************************************************************************
2200 * copies an aPidl struct
2202 LPITEMIDLIST* _ILCopyaPidl(LPCITEMIDLIST * apidlsrc, UINT cidl)
2205 LPITEMIDLIST * apidldest = (LPITEMIDLIST*)SHAlloc(cidl * sizeof(LPITEMIDLIST));
2206 if(!apidlsrc) return NULL;
2208 for (i = 0; i < cidl; i++)
2209 apidldest[i] = ILClone(apidlsrc[i]);
2214 /*************************************************************************
2215 * _ILCopyCidaToaPidl
2217 * creates aPidl from CIDA
2219 LPITEMIDLIST* _ILCopyCidaToaPidl(LPITEMIDLIST* pidl, LPIDA cida)
2222 LPITEMIDLIST * dst = (LPITEMIDLIST*)SHAlloc(cida->cidl * sizeof(LPITEMIDLIST));
2224 if(!dst) return NULL;
2227 *pidl = ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[0]]));
2229 for (i = 0; i < cida->cidl; i++)
2230 dst[i] = ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[i + 1]]));