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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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"
49 #include "wine/debug.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(pidl);
52 WINE_DECLARE_DEBUG_CHANNEL(shell);
54 /* from comctl32.dll */
55 extern LPVOID WINAPI Alloc(INT);
56 extern BOOL WINAPI Free(LPVOID);
58 static LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl);
59 static LPWSTR _ILGetTextPointerW(LPCITEMIDLIST pidl);
61 /*************************************************************************
64 * Retrieves the display name of an ItemIDList
67 * psf [I] Shell Folder to start with, if NULL the desktop is used
68 * pidl [I] ItemIDList relative to the psf to get the display name for
69 * path [O] Filled in with the display name, assumed to be at least MAX_PATH long
70 * type [I] Type of display name to retrieve
71 * 0 = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR uses always the desktop as root
72 * 1 = SHGDN_NORMAL relative to the root folder
73 * 2 = SHGDN_INFOLDER relative to the root folder, only the last name
76 * True if the display name could be retrieved successfully, False otherwise
78 static BOOL ILGetDisplayNameExA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPSTR path, DWORD type)
81 WCHAR wPath[MAX_PATH];
83 TRACE("%p %p %p %d\n", psf, pidl, path, type);
88 ret = ILGetDisplayNameExW(psf, pidl, wPath, type);
89 WideCharToMultiByte(CP_ACP, 0, wPath, -1, path, MAX_PATH, NULL, NULL);
90 TRACE("%p %p %s\n", psf, pidl, debugstr_a(path));
95 BOOL WINAPI ILGetDisplayNameExW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPWSTR path, DWORD type)
97 LPSHELLFOLDER psfParent, lsf = psf;
98 HRESULT ret = NO_ERROR;
99 LPCITEMIDLIST pidllast;
103 TRACE("%p %p %p %x\n", psf, pidl, path, type);
110 ret = SHGetDesktopFolder(&lsf);
117 case ILGDN_FORPARSING:
118 flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
124 flag = SHGDN_INFOLDER;
127 FIXME("Unknown type parameter = %x\n", type);
128 flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
132 if (!*(const WORD*)pidl || type == ILGDN_FORPARSING)
134 ret = IShellFolder_GetDisplayNameOf(lsf, pidl, flag, &strret);
137 if(!StrRetToStrNW(path, MAX_PATH, &strret, pidl))
143 ret = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psfParent, &pidllast);
146 ret = IShellFolder_GetDisplayNameOf(psfParent, pidllast, flag, &strret);
149 if(!StrRetToStrNW(path, MAX_PATH, &strret, pidllast))
152 IShellFolder_Release(psfParent);
156 TRACE("%p %p %s\n", psf, pidl, debugstr_w(path));
159 IShellFolder_Release(lsf);
160 return SUCCEEDED(ret);
163 /*************************************************************************
164 * ILGetDisplayNameEx [SHELL32.186]
166 BOOL WINAPI ILGetDisplayNameEx(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPVOID path, DWORD type)
168 TRACE_(shell)("%p %p %p %d\n", psf, pidl, path, type);
170 if (SHELL_OsIsUnicode())
171 return ILGetDisplayNameExW(psf, pidl, path, type);
172 return ILGetDisplayNameExA(psf, pidl, path, type);
175 /*************************************************************************
176 * ILGetDisplayName [SHELL32.15]
178 BOOL WINAPI ILGetDisplayName(LPCITEMIDLIST pidl, LPVOID path)
180 TRACE_(shell)("%p %p\n", pidl, path);
182 if (SHELL_OsIsUnicode())
183 return ILGetDisplayNameExW(NULL, pidl, path, ILGDN_FORPARSING);
184 return ILGetDisplayNameExA(NULL, pidl, path, ILGDN_FORPARSING);
187 /*************************************************************************
188 * ILFindLastID [SHELL32.16]
191 * observed: pidl=Desktop return=pidl
193 LPITEMIDLIST WINAPI ILFindLastID(LPCITEMIDLIST pidl)
195 LPCITEMIDLIST pidlLast = pidl;
197 TRACE("(pidl=%p)\n",pidl);
202 while (pidl->mkid.cb)
205 pidl = ILGetNext(pidl);
207 return (LPITEMIDLIST)pidlLast;
210 /*************************************************************************
211 * ILRemoveLastID [SHELL32.17]
214 * when pidl=Desktop return=FALSE
216 BOOL WINAPI ILRemoveLastID(LPITEMIDLIST pidl)
218 TRACE_(shell)("pidl=%p\n",pidl);
220 if (!pidl || !pidl->mkid.cb)
222 ILFindLastID(pidl)->mkid.cb = 0;
226 /*************************************************************************
227 * ILClone [SHELL32.18]
230 * duplicate an idlist
232 LPITEMIDLIST WINAPI ILClone (LPCITEMIDLIST pidl)
235 LPITEMIDLIST newpidl;
240 len = ILGetSize(pidl);
241 newpidl = SHAlloc(len);
243 memcpy(newpidl,pidl,len);
245 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
251 /*************************************************************************
252 * ILCloneFirst [SHELL32.19]
255 * duplicates the first idlist of a complex pidl
257 LPITEMIDLIST WINAPI ILCloneFirst(LPCITEMIDLIST pidl)
260 LPITEMIDLIST pidlNew = NULL;
262 TRACE("pidl=%p\n", pidl);
268 pidlNew = SHAlloc(len+2);
271 memcpy(pidlNew,pidl,len+2); /* 2 -> mind a desktop pidl */
274 ILGetNext(pidlNew)->mkid.cb = 0x00;
277 TRACE("-- newpidl=%p\n",pidlNew);
282 /*************************************************************************
283 * ILLoadFromStream (SHELL32.26)
286 * the first two bytes are the len, the pidl is following then
288 HRESULT WINAPI ILLoadFromStream (IStream * pStream, LPITEMIDLIST * ppPidl)
292 HRESULT ret = E_FAIL;
295 TRACE_(shell)("%p %p\n", pStream , ppPidl);
300 IStream_AddRef (pStream);
302 if (SUCCEEDED(IStream_Read(pStream, &wLen, 2, &dwBytesRead)))
304 TRACE("PIDL length is %d\n", wLen);
307 *ppPidl = SHAlloc (wLen);
308 if (SUCCEEDED(IStream_Read(pStream, *ppPidl , wLen, &dwBytesRead)))
310 TRACE("Stream read OK\n");
315 WARN("reading pidl failed\n");
327 /* we are not yet fully compatible */
328 if (*ppPidl && !pcheck(*ppPidl))
330 WARN("Check failed\n");
335 IStream_Release (pStream);
340 /*************************************************************************
341 * ILSaveToStream (SHELL32.27)
344 * the first two bytes are the len, the pidl is following then
346 HRESULT WINAPI ILSaveToStream (IStream * pStream, LPCITEMIDLIST pPidl)
349 HRESULT ret = E_FAIL;
351 TRACE_(shell)("%p %p\n", pStream, pPidl);
353 IStream_AddRef (pStream);
355 wLen = ILGetSize(pPidl);
357 if (SUCCEEDED(IStream_Write(pStream, &wLen, 2, NULL)))
359 if (SUCCEEDED(IStream_Write(pStream, pPidl, wLen, NULL)))
362 IStream_Release (pStream);
367 /*************************************************************************
368 * SHILCreateFromPath [SHELL32.28]
370 * Create an ItemIDList from a path
375 * attributes [I/O] requested attributes on call and actual attributes when
376 * the function returns
379 * NO_ERROR if successful, or an OLE errer code otherwise
382 * Wrapper for IShellFolder_ParseDisplayName().
384 static HRESULT SHILCreateFromPathA(LPCSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
386 WCHAR lpszDisplayName[MAX_PATH];
388 TRACE_(shell)("%s %p 0x%08x\n", path, ppidl, attributes ? *attributes : 0);
390 if (!MultiByteToWideChar(CP_ACP, 0, path, -1, lpszDisplayName, MAX_PATH))
391 lpszDisplayName[MAX_PATH-1] = 0;
393 return SHILCreateFromPathW(lpszDisplayName, ppidl, attributes);
396 HRESULT WINAPI SHILCreateFromPathW(LPCWSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
400 HRESULT ret = E_FAIL;
402 TRACE_(shell)("%s %p 0x%08x\n", debugstr_w(path), ppidl, attributes ? *attributes : 0);
404 if (SUCCEEDED (SHGetDesktopFolder(&sf)))
406 ret = IShellFolder_ParseDisplayName(sf, 0, NULL, (LPWSTR)path, &pchEaten, ppidl, attributes);
407 IShellFolder_Release(sf);
412 HRESULT WINAPI SHILCreateFromPathAW (LPCVOID path, LPITEMIDLIST * ppidl, DWORD * attributes)
414 if ( SHELL_OsIsUnicode())
415 return SHILCreateFromPathW (path, ppidl, attributes);
416 return SHILCreateFromPathA (path, ppidl, attributes);
419 /*************************************************************************
420 * SHCloneSpecialIDList [SHELL32.89]
422 * Create an ItemIDList to one of the special folders.
426 * nFolder [in] CSIDL_xxxxx
427 * fCreate [in] Create folder if it does not exist
430 * Success: The newly created pidl
431 * Failure: NULL, if inputs are invalid.
434 * exported by ordinal.
435 * Caller is responsible for deallocating the returned ItemIDList with the
436 * shells IMalloc interface, aka ILFree.
438 LPITEMIDLIST WINAPI SHCloneSpecialIDList(HWND hwndOwner, DWORD nFolder, BOOL fCreate)
441 TRACE_(shell)("(hwnd=%p,csidl=0x%x,%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)
467 LPITEMIDLIST newpidl;
472 len = ILGetSize(pidl);
473 newpidl = Alloc(len);
475 memcpy(newpidl,pidl,len);
477 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
483 /*************************************************************************
484 * ILIsEqual [SHELL32.21]
487 BOOL WINAPI ILIsEqual(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
489 char szData1[MAX_PATH];
490 char szData2[MAX_PATH];
492 LPCITEMIDLIST pidltemp1 = pidl1;
493 LPCITEMIDLIST pidltemp2 = pidl2;
495 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
498 * Explorer reads from registry directly (StreamMRU),
499 * so we can only check here
501 if (!pcheck(pidl1) || !pcheck (pidl2))
507 if (!pidl1 || !pidl2)
510 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
512 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
513 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
515 if (strcasecmp( szData1, szData2 ))
518 pidltemp1 = ILGetNext(pidltemp1);
519 pidltemp2 = ILGetNext(pidltemp2);
522 if (!pidltemp1->mkid.cb && !pidltemp2->mkid.cb)
528 /*************************************************************************
529 * ILIsParent [SHELL32.23]
531 * Verifies that pidlParent is indeed the (immediate) parent of pidlChild.
536 * bImmediate [I] only return true if the parent is the direct parent
540 * True if the parent ItemIDlist is a complete part of the child ItemIdList,
544 * parent = a/b, child = a/b/c -> true, c is in folder a/b
545 * child = a/b/c/d -> false if bImmediate is true, d is not in folder a/b
546 * child = a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
548 BOOL WINAPI ILIsParent(LPCITEMIDLIST pidlParent, LPCITEMIDLIST pidlChild, BOOL bImmediate)
550 char szData1[MAX_PATH];
551 char szData2[MAX_PATH];
552 LPCITEMIDLIST pParent = pidlParent;
553 LPCITEMIDLIST pChild = pidlChild;
555 TRACE("%p %p %x\n", pidlParent, pidlChild, bImmediate);
557 if (!pParent || !pChild)
560 while (pParent->mkid.cb && pChild->mkid.cb)
562 _ILSimpleGetText(pParent, szData1, MAX_PATH);
563 _ILSimpleGetText(pChild, szData2, MAX_PATH);
565 if (strcasecmp( szData1, szData2 ))
568 pParent = ILGetNext(pParent);
569 pChild = ILGetNext(pChild);
572 /* child shorter or has equal length to parent */
573 if (pParent->mkid.cb || !pChild->mkid.cb)
576 /* not immediate descent */
577 if ( ILGetNext(pChild)->mkid.cb && bImmediate)
583 /*************************************************************************
584 * ILFindChild [SHELL32.24]
586 * Compares elements from pidl1 and pidl2.
593 * pidl1 is desktop pidl2
594 * pidl1 shorter pidl2 pointer to first different element of pidl2
595 * if there was at least one equal element
596 * pidl2 shorter pidl1 0
597 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
600 * exported by ordinal.
602 LPITEMIDLIST WINAPI ILFindChild(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
604 char szData1[MAX_PATH];
605 char szData2[MAX_PATH];
607 LPCITEMIDLIST pidltemp1 = pidl1;
608 LPCITEMIDLIST pidltemp2 = pidl2;
609 LPCITEMIDLIST ret=NULL;
611 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
613 /* explorer reads from registry directly (StreamMRU),
614 so we can only check here */
615 if ((!pcheck (pidl1)) || (!pcheck (pidl2)))
621 if (_ILIsDesktop(pidl1))
627 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
629 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
630 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
632 if (strcasecmp(szData1,szData2))
635 pidltemp1 = ILGetNext(pidltemp1);
636 pidltemp2 = ILGetNext(pidltemp2);
640 if (pidltemp1->mkid.cb)
641 ret = NULL; /* elements of pidl1 left*/
643 TRACE_(shell)("--- %p\n", ret);
644 return (LPITEMIDLIST)ret; /* pidl 1 is shorter */
647 /*************************************************************************
648 * ILCombine [SHELL32.25]
650 * Concatenates two complex ItemIDLists.
653 * pidl1 [I] first complex ItemIDLists
654 * pidl2 [I] complex ItemIDLists to append
657 * if both pidl's == NULL NULL
658 * if pidl1 == NULL cloned pidl2
659 * if pidl2 == NULL cloned pidl1
660 * otherwise new pidl with pidl2 appended to pidl1
663 * exported by ordinal.
664 * Does not destroy the passed in ItemIDLists!
666 LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
669 LPITEMIDLIST pidlNew;
671 TRACE("pidl=%p pidl=%p\n",pidl1,pidl2);
673 if (!pidl1 && !pidl2) return NULL;
680 pidlNew = ILClone(pidl2);
686 pidlNew = ILClone(pidl1);
690 len1 = ILGetSize(pidl1)-2;
691 len2 = ILGetSize(pidl2);
692 pidlNew = SHAlloc(len1+len2);
696 memcpy(pidlNew,pidl1,len1);
697 memcpy(((BYTE *)pidlNew)+len1,pidl2,len2);
700 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
704 /*************************************************************************
705 * SHGetRealIDL [SHELL32.98]
709 HRESULT WINAPI SHGetRealIDL(LPSHELLFOLDER lpsf, LPCITEMIDLIST pidlSimple, LPITEMIDLIST *pidlReal)
711 IDataObject* pDataObj;
714 hr = IShellFolder_GetUIObjectOf(lpsf, 0, 1, &pidlSimple,
715 &IID_IDataObject, 0, (LPVOID*)&pDataObj);
721 fmt.cfFormat = RegisterClipboardFormatW(CFSTR_SHELLIDLISTW);
723 fmt.dwAspect = DVASPECT_CONTENT;
725 fmt.tymed = TYMED_HGLOBAL;
727 hr = IDataObject_GetData(pDataObj, &fmt, &medium);
729 IDataObject_Release(pDataObj);
733 /*assert(pida->cidl==1);*/
734 LPIDA pida = GlobalLock(medium.u.hGlobal);
736 LPCITEMIDLIST pidl_folder = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[0]);
737 LPCITEMIDLIST pidl_child = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[1]);
739 *pidlReal = ILCombine(pidl_folder, pidl_child);
744 GlobalUnlock(medium.u.hGlobal);
745 GlobalFree(medium.u.hGlobal);
752 /*************************************************************************
753 * SHLogILFromFSIL [SHELL32.95]
756 * pild = CSIDL_DESKTOP ret = 0
757 * pild = CSIDL_DRIVES ret = 0
759 LPITEMIDLIST WINAPI SHLogILFromFSIL(LPITEMIDLIST pidl)
761 FIXME("(pidl=%p)\n",pidl);
768 /*************************************************************************
769 * ILGetSize [SHELL32.152]
771 * Gets the byte size of an ItemIDList including zero terminator
774 * pidl [I] ItemIDList
777 * size of pidl in bytes
780 * exported by ordinal
782 UINT WINAPI ILGetSize(LPCITEMIDLIST pidl)
784 LPCSHITEMID si = &(pidl->mkid);
792 si = (LPCSHITEMID)(((const BYTE*)si)+si->cb);
796 TRACE("pidl=%p size=%u\n",pidl, len);
800 /*************************************************************************
801 * ILGetNext [SHELL32.153]
803 * Gets the next ItemID of an ItemIDList
806 * pidl [I] ItemIDList
811 * simple pidl -> pointer to 0x0000 element
814 * exported by ordinal.
816 LPITEMIDLIST WINAPI ILGetNext(LPCITEMIDLIST pidl)
827 pidl = (LPCITEMIDLIST) (((const BYTE*)pidl)+len);
828 TRACE("-- %p\n", pidl);
829 return (LPITEMIDLIST)pidl;
835 /*************************************************************************
836 * ILAppend [SHELL32.154]
838 * Adds the single ItemID item to the ItemIDList indicated by pidl.
839 * If bEnd is FALSE, inserts the item in the front of the list,
840 * otherwise it adds the item to the end. (???)
843 * pidl [I] ItemIDList to extend
844 * item [I] ItemID to prepend/append
845 * bEnd [I] Indicates if the item should be appended
848 * Destroys the passed in idlist! (???)
850 LPITEMIDLIST WINAPI ILAppend(LPITEMIDLIST pidl, LPCITEMIDLIST item, BOOL bEnd)
854 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl,item,bEnd);
859 if (_ILIsDesktop(pidl))
861 idlRet = ILClone(item);
867 idlRet = ILCombine(pidl, item);
869 idlRet = ILCombine(item, pidl);
875 /*************************************************************************
876 * ILFree [SHELL32.155]
878 * Frees memory (if not NULL) allocated by SHMalloc allocator
887 * exported by ordinal
889 void WINAPI ILFree(LPITEMIDLIST pidl)
891 TRACE("(pidl=%p)\n",pidl);
895 /*************************************************************************
896 * ILGlobalFree [SHELL32.156]
898 * Frees memory (if not NULL) allocated by Alloc allocator
907 * exported by ordinal.
909 void WINAPI ILGlobalFree( LPITEMIDLIST pidl)
916 /*************************************************************************
917 * ILCreateFromPathA [SHELL32.189]
919 * Creates a complex ItemIDList from a path and returns it.
925 * the newly created complex ItemIDList or NULL if failed
928 * exported by ordinal.
930 LPITEMIDLIST WINAPI ILCreateFromPathA (LPCSTR path)
932 LPITEMIDLIST pidlnew = NULL;
934 TRACE_(shell)("%s\n", debugstr_a(path));
936 if (SUCCEEDED(SHILCreateFromPathA(path, &pidlnew, NULL)))
941 /*************************************************************************
942 * ILCreateFromPathW [SHELL32.190]
944 * See ILCreateFromPathA.
946 LPITEMIDLIST WINAPI ILCreateFromPathW (LPCWSTR path)
948 LPITEMIDLIST pidlnew = NULL;
950 TRACE_(shell)("%s\n", debugstr_w(path));
952 if (SUCCEEDED(SHILCreateFromPathW(path, &pidlnew, NULL)))
957 /*************************************************************************
958 * ILCreateFromPath [SHELL32.157]
960 LPITEMIDLIST WINAPI ILCreateFromPathAW (LPCVOID path)
962 if ( SHELL_OsIsUnicode())
963 return ILCreateFromPathW (path);
964 return ILCreateFromPathA (path);
967 /*************************************************************************
968 * _ILParsePathW [internal]
970 * Creates an ItemIDList from a path and returns it.
973 * path [I] path to parse and convert into an ItemIDList
974 * lpFindFile [I] pointer to buffer to initialize the FileSystem
975 * Bind Data object with
976 * bBindCtx [I] indicates to create a BindContext and assign a
977 * FileSystem Bind Data object
978 * ppidl [O] the newly create ItemIDList
979 * prgfInOut [I/O] requested attributes on input and actual
980 * attributes on return
983 * NO_ERROR on success or an OLE error code
986 * If either lpFindFile is non-NULL or bBindCtx is TRUE, this function
987 * creates a BindContext object and assigns a FileSystem Bind Data object
988 * to it, passing the BindContext to IShellFolder_ParseDisplayName. Each
989 * IShellFolder uses that FileSystem Bind Data object of the BindContext
990 * to pass data about the current path element to the next object. This
991 * is used to avoid having to verify the current path element on disk, so
992 * that creating an ItemIDList from a nonexistent path still can work.
994 static HRESULT _ILParsePathW(LPCWSTR path, LPWIN32_FIND_DATAW lpFindFile,
995 BOOL bBindCtx, LPITEMIDLIST *ppidl, LPDWORD prgfInOut)
997 LPSHELLFOLDER pSF = NULL;
1001 TRACE("%s %p %d (%p)->%p (%p)->0x%x\n", debugstr_w(path), lpFindFile, bBindCtx,
1002 ppidl, ppidl ? *ppidl : NULL,
1003 prgfInOut, prgfInOut ? *prgfInOut : 0);
1005 ret = SHGetDesktopFolder(&pSF);
1009 if (lpFindFile || bBindCtx)
1010 ret = IFileSystemBindData_Constructor(lpFindFile, &pBC);
1014 ret = IShellFolder_ParseDisplayName(pSF, 0, pBC, (LPOLESTR)path, NULL, ppidl, prgfInOut);
1019 IBindCtx_Release(pBC);
1023 IShellFolder_Release(pSF);
1025 if (FAILED(ret) && ppidl)
1028 TRACE("%s %p 0x%x\n", debugstr_w(path), ppidl ? *ppidl : NULL, prgfInOut ? *prgfInOut : 0);
1033 /*************************************************************************
1034 * SHSimpleIDListFromPath [SHELL32.162]
1036 * Creates a simple ItemIDList from a path and returns it. This function
1037 * does not fail on nonexistent paths.
1040 * path [I] path to parse and convert into an ItemIDList
1043 * the newly created simple ItemIDList
1046 * Simple in the name does not mean a relative ItemIDList but rather a
1047 * fully qualified list, where only the file name is filled in and the
1048 * directory flag for those ItemID elements this is known about, eg.
1049 * it is not the last element in the ItemIDList or the actual directory
1051 * exported by ordinal.
1053 LPITEMIDLIST WINAPI SHSimpleIDListFromPathA(LPCSTR lpszPath)
1055 LPITEMIDLIST pidl = NULL;
1056 LPWSTR wPath = NULL;
1059 TRACE("%s\n", debugstr_a(lpszPath));
1063 len = MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, NULL, 0);
1064 wPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1065 MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, wPath, len);
1068 _ILParsePathW(wPath, NULL, TRUE, &pidl, NULL);
1070 HeapFree(GetProcessHeap(), 0, wPath);
1071 TRACE("%s %p\n", debugstr_a(lpszPath), pidl);
1075 LPITEMIDLIST WINAPI SHSimpleIDListFromPathW(LPCWSTR lpszPath)
1077 LPITEMIDLIST pidl = NULL;
1079 TRACE("%s\n", debugstr_w(lpszPath));
1081 _ILParsePathW(lpszPath, NULL, TRUE, &pidl, NULL);
1082 TRACE("%s %p\n", debugstr_w(lpszPath), pidl);
1086 LPITEMIDLIST WINAPI SHSimpleIDListFromPathAW(LPCVOID lpszPath)
1088 if ( SHELL_OsIsUnicode())
1089 return SHSimpleIDListFromPathW (lpszPath);
1090 return SHSimpleIDListFromPathA (lpszPath);
1093 /*************************************************************************
1094 * SHGetDataFromIDListA [SHELL32.247]
1097 * the pidl can be a simple one. since we can't get the path out of the pidl
1098 * we have to take all data from the pidl
1100 HRESULT WINAPI SHGetDataFromIDListA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl,
1101 int nFormat, LPVOID dest, int len)
1103 LPSTR filename, shortname;
1104 WIN32_FIND_DATAA * pfd;
1106 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
1110 return E_INVALIDARG;
1114 case SHGDFIL_FINDDATA:
1117 if (_ILIsDrive(pidl) || _ILIsSpecialFolder(pidl))
1118 return E_INVALIDARG;
1120 if (len < sizeof(WIN32_FIND_DATAA))
1121 return E_INVALIDARG;
1123 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1124 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1125 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1126 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1128 filename = _ILGetTextPointer(pidl);
1129 shortname = _ILGetSTextPointer(pidl);
1132 lstrcpynA(pfd->cFileName, filename, sizeof(pfd->cFileName));
1134 pfd->cFileName[0] = '\0';
1137 lstrcpynA(pfd->cAlternateFileName, shortname, sizeof(pfd->cAlternateFileName));
1139 pfd->cAlternateFileName[0] = '\0';
1142 case SHGDFIL_NETRESOURCE:
1143 case SHGDFIL_DESCRIPTIONID:
1144 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1148 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1151 return E_INVALIDARG;
1154 /*************************************************************************
1155 * SHGetDataFromIDListW [SHELL32.248]
1158 HRESULT WINAPI SHGetDataFromIDListW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl,
1159 int nFormat, LPVOID dest, int len)
1161 LPSTR filename, shortname;
1162 WIN32_FIND_DATAW * pfd = dest;
1164 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
1169 return E_INVALIDARG;
1173 case SHGDFIL_FINDDATA:
1176 if (_ILIsDrive(pidl))
1177 return E_INVALIDARG;
1179 if (len < sizeof(WIN32_FIND_DATAW))
1180 return E_INVALIDARG;
1182 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1183 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1184 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1185 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1187 filename = _ILGetTextPointer(pidl);
1188 shortname = _ILGetSTextPointer(pidl);
1191 pfd->cFileName[0] = '\0';
1192 else if (!MultiByteToWideChar(CP_ACP, 0, filename, -1, pfd->cFileName, MAX_PATH))
1193 pfd->cFileName[MAX_PATH-1] = 0;
1196 pfd->cAlternateFileName[0] = '\0';
1197 else if (!MultiByteToWideChar(CP_ACP, 0, shortname, -1, pfd->cAlternateFileName, 14))
1198 pfd->cAlternateFileName[13] = 0;
1201 case SHGDFIL_NETRESOURCE:
1202 case SHGDFIL_DESCRIPTIONID:
1203 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1207 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1210 return E_INVALIDARG;
1213 /*************************************************************************
1214 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
1218 * pszPath [OUT] path
1221 * path from a passed PIDL.
1224 * NULL returns FALSE
1225 * desktop pidl gives path to desktop directory back
1226 * special pidls returning FALSE
1228 BOOL WINAPI SHGetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath)
1230 WCHAR wszPath[MAX_PATH];
1233 bSuccess = SHGetPathFromIDListW(pidl, wszPath);
1234 WideCharToMultiByte(CP_ACP, 0, wszPath, -1, pszPath, MAX_PATH, NULL, NULL);
1239 /*************************************************************************
1240 * SHGetPathFromIDListW [SHELL32.@]
1242 * See SHGetPathFromIDListA.
1244 BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
1247 LPCITEMIDLIST pidlLast;
1248 LPSHELLFOLDER psfFolder;
1252 TRACE_(shell)("(pidl=%p,%p)\n", pidl, pszPath);
1259 hr = SHBindToParent(pidl, &IID_IShellFolder, (VOID**)&psfFolder, &pidlLast);
1260 if (FAILED(hr)) return FALSE;
1262 dwAttributes = SFGAO_FILESYSTEM;
1263 hr = IShellFolder_GetAttributesOf(psfFolder, 1, &pidlLast, &dwAttributes);
1264 if (FAILED(hr) || !(dwAttributes & SFGAO_FILESYSTEM)) {
1265 IShellFolder_Release(psfFolder);
1269 hr = IShellFolder_GetDisplayNameOf(psfFolder, pidlLast, SHGDN_FORPARSING, &strret);
1270 IShellFolder_Release(psfFolder);
1271 if (FAILED(hr)) return FALSE;
1273 hr = StrRetToBufW(&strret, pidlLast, pszPath, MAX_PATH);
1275 TRACE_(shell)("-- %s, 0x%08x\n",debugstr_w(pszPath), hr);
1276 return SUCCEEDED(hr);
1279 /*************************************************************************
1280 * SHBindToParent [shell version 5.0]
1282 HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
1284 IShellFolder * psfDesktop;
1287 TRACE_(shell)("pidl=%p\n", pidl);
1291 return E_INVALIDARG;
1297 hr = SHGetDesktopFolder(&psfDesktop);
1301 if (_ILIsPidlSimple(pidl))
1303 /* we are on desktop level */
1304 hr = IShellFolder_QueryInterface(psfDesktop, riid, ppv);
1308 LPITEMIDLIST pidlParent = ILClone(pidl);
1309 ILRemoveLastID(pidlParent);
1310 hr = IShellFolder_BindToObject(psfDesktop, pidlParent, NULL, riid, ppv);
1311 SHFree (pidlParent);
1314 IShellFolder_Release(psfDesktop);
1316 if (SUCCEEDED(hr) && ppidlLast)
1317 *ppidlLast = ILFindLastID(pidl);
1319 TRACE_(shell)("-- psf=%p pidl=%p ret=0x%08x\n", *ppv, (ppidlLast)?*ppidlLast:NULL, hr);
1323 /**************************************************************************
1325 * internal functions
1327 * ### 1. section creating pidls ###
1329 *************************************************************************
1332 /* Basic PIDL constructor. Allocates size + 5 bytes, where:
1333 * - two bytes are SHITEMID.cb
1334 * - one byte is PIDLDATA.type
1335 * - two bytes are the NULL PIDL terminator
1336 * Sets type of the returned PIDL to type.
1338 static LPITEMIDLIST _ILAlloc(PIDLTYPE type, unsigned int size)
1340 LPITEMIDLIST pidlOut = NULL;
1342 pidlOut = SHAlloc(size + 5);
1346 LPITEMIDLIST pidlNext;
1348 ZeroMemory(pidlOut, size + 5);
1349 pidlOut->mkid.cb = size + 3;
1351 pData = _ILGetDataPointer(pidlOut);
1355 pidlNext = ILGetNext(pidlOut);
1357 pidlNext->mkid.cb = 0x00;
1358 TRACE("-- (pidl=%p, size=%u)\n", pidlOut, size);
1364 LPITEMIDLIST _ILCreateDesktop(void)
1375 LPITEMIDLIST _ILCreateMyComputer(void)
1378 return _ILCreateGuid(PT_GUID, &CLSID_MyComputer);
1381 LPITEMIDLIST _ILCreateMyDocuments(void)
1384 return _ILCreateGuid(PT_GUID, &CLSID_MyDocuments);
1387 LPITEMIDLIST _ILCreateIExplore(void)
1390 return _ILCreateGuid(PT_GUID, &CLSID_Internet);
1393 LPITEMIDLIST _ILCreateControlPanel(void)
1395 LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL;
1400 LPITEMIDLIST cpl = _ILCreateGuid(PT_SHELLEXT, &CLSID_ControlPanel);
1404 ret = ILCombine(parent, cpl);
1412 LPITEMIDLIST _ILCreatePrinters(void)
1414 LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL;
1419 LPITEMIDLIST printers = _ILCreateGuid(PT_YAGUID, &CLSID_Printers);
1423 ret = ILCombine(parent, printers);
1431 LPITEMIDLIST _ILCreateNetwork(void)
1434 return _ILCreateGuid(PT_GUID, &CLSID_NetworkPlaces);
1437 LPITEMIDLIST _ILCreateBitBucket(void)
1440 return _ILCreateGuid(PT_GUID, &CLSID_RecycleBin);
1443 LPITEMIDLIST _ILCreateNetHood(void)
1446 return _ILCreateGuid(PT_GUID, &CLSID_NetworkPlaces);
1449 LPITEMIDLIST _ILCreateGuid(PIDLTYPE type, REFIID guid)
1451 LPITEMIDLIST pidlOut;
1453 if (type == PT_SHELLEXT || type == PT_GUID || type == PT_YAGUID)
1455 pidlOut = _ILAlloc(type, sizeof(GUIDStruct));
1458 LPPIDLDATA pData = _ILGetDataPointer(pidlOut);
1460 pData->u.guid.guid = *guid;
1461 TRACE("-- create GUID-pidl %s\n",
1462 debugstr_guid(&(pData->u.guid.guid)));
1467 WARN("%d: invalid type for GUID\n", type);
1473 LPITEMIDLIST _ILCreateGuidFromStrA(LPCSTR szGUID)
1477 if (FAILED(SHCLSIDFromStringA(szGUID, &iid)))
1479 ERR("%s is not a GUID\n", szGUID);
1482 return _ILCreateGuid(PT_GUID, &iid);
1485 LPITEMIDLIST _ILCreateGuidFromStrW(LPCWSTR szGUID)
1489 if (FAILED(SHCLSIDFromStringW(szGUID, &iid)))
1491 ERR("%s is not a GUID\n", debugstr_w(szGUID));
1494 return _ILCreateGuid(PT_GUID, &iid);
1497 LPITEMIDLIST _ILCreateFromFindDataW( const WIN32_FIND_DATAW *wfd )
1499 char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1500 DWORD len, len1, wlen, alen;
1507 TRACE("(%s, %s)\n",debugstr_w(wfd->cAlternateFileName), debugstr_w(wfd->cFileName));
1509 /* prepare buffer with both names */
1510 len = WideCharToMultiByte(CP_ACP,0,wfd->cFileName,-1,buff,MAX_PATH,NULL,NULL);
1511 len1 = WideCharToMultiByte(CP_ACP,0,wfd->cAlternateFileName,-1, buff+len, sizeof(buff)-len, NULL, NULL);
1514 type = (wfd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? PT_FOLDER : PT_VALUE;
1516 wlen = lstrlenW(wfd->cFileName) + 1;
1517 pidl = _ILAlloc(type, FIELD_OFFSET(FileStruct, szNames[alen + (alen & 1)]) +
1518 FIELD_OFFSET(FileStructW, wszName[wlen]) + sizeof(WORD));
1521 LPPIDLDATA pData = _ILGetDataPointer(pidl);
1522 FileStruct *fs = &pData->u.file;
1526 FileTimeToDosDateTime( &wfd->ftLastWriteTime, &fs->uFileDate, &fs->uFileTime);
1527 fs->dwFileSize = wfd->nFileSizeLow;
1528 fs->uFileAttribs = wfd->dwFileAttributes;
1529 memcpy(fs->szNames, buff, alen);
1531 fsw = (FileStructW*)(pData->u.file.szNames + alen + (alen & 0x1));
1532 fsw->cbLen = FIELD_OFFSET(FileStructW, wszName[wlen]) + sizeof(WORD);
1533 FileTimeToDosDateTime( &wfd->ftCreationTime, &fsw->uCreationDate, &fsw->uCreationTime);
1534 FileTimeToDosDateTime( &wfd->ftLastAccessTime, &fsw->uLastAccessDate, &fsw->uLastAccessTime);
1535 memcpy(fsw->wszName, wfd->cFileName, wlen * sizeof(WCHAR));
1537 pOffsetW = (WORD*)((LPBYTE)pidl + pidl->mkid.cb - sizeof(WORD));
1538 *pOffsetW = (LPBYTE)fsw - (LPBYTE)pidl;
1539 TRACE("-- Set Value: %s\n",debugstr_w(fsw->wszName));
1545 HRESULT _ILCreateFromPathW(LPCWSTR szPath, LPITEMIDLIST* ppidl)
1548 WIN32_FIND_DATAW stffile;
1551 return E_INVALIDARG;
1553 hFile = FindFirstFileW(szPath, &stffile);
1554 if (hFile == INVALID_HANDLE_VALUE)
1555 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
1559 *ppidl = _ILCreateFromFindDataW(&stffile);
1561 return *ppidl ? S_OK : E_OUTOFMEMORY;
1564 LPITEMIDLIST _ILCreateDrive(LPCWSTR lpszNew)
1566 LPITEMIDLIST pidlOut;
1568 TRACE("(%s)\n",debugstr_w(lpszNew));
1570 pidlOut = _ILAlloc(PT_DRIVE, sizeof(DriveStruct));
1575 pszDest = _ILGetTextPointer(pidlOut);
1578 strcpy(pszDest, "x:\\");
1579 pszDest[0]=toupperW(lpszNew[0]);
1580 TRACE("-- create Drive: %s\n", debugstr_a(pszDest));
1586 LPITEMIDLIST _ILCreateEntireNetwork(void)
1588 LPITEMIDLIST pidlOut;
1592 pidlOut = _ILAlloc(PT_NETWORK, FIELD_OFFSET(PIDLDATA, u.network.szNames[sizeof("Entire Network")]));
1595 LPPIDLDATA pData = _ILGetDataPointer(pidlOut);
1597 pData->u.network.dummy = 0;
1598 strcpy(pData->u.network.szNames, "Entire Network");
1603 /**************************************************************************
1606 * Gets the text for the drive eg. 'c:\'
1611 DWORD _ILGetDrive(LPCITEMIDLIST pidl,LPSTR pOut, UINT uSize)
1613 TRACE("(%p,%p,%u)\n",pidl,pOut,uSize);
1615 if(_ILIsMyComputer(pidl))
1616 pidl = ILGetNext(pidl);
1618 if (pidl && _ILIsDrive(pidl))
1619 return _ILSimpleGetText(pidl, pOut, uSize);
1624 /**************************************************************************
1626 * ### 2. section testing pidls ###
1628 **************************************************************************
1632 * _ILIsSpecialFolder()
1638 BOOL _ILIsUnicode(LPCITEMIDLIST pidl)
1640 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1642 TRACE("(%p)\n",pidl);
1644 return (pidl && lpPData && PT_VALUEW == lpPData->type);
1647 BOOL _ILIsDesktop(LPCITEMIDLIST pidl)
1649 TRACE("(%p)\n",pidl);
1651 return pidl && pidl->mkid.cb ? 0 : 1;
1654 BOOL _ILIsMyComputer(LPCITEMIDLIST pidl)
1656 REFIID iid = _ILGetGUIDPointer(pidl);
1658 TRACE("(%p)\n",pidl);
1661 return IsEqualIID(iid, &CLSID_MyComputer);
1665 BOOL _ILIsSpecialFolder (LPCITEMIDLIST pidl)
1667 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1669 TRACE("(%p)\n",pidl);
1671 return (pidl && ( (lpPData && (PT_GUID== lpPData->type || PT_SHELLEXT== lpPData->type || PT_YAGUID == lpPData->type)) ||
1672 (pidl && pidl->mkid.cb == 0x00)
1676 BOOL _ILIsDrive(LPCITEMIDLIST pidl)
1678 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1680 TRACE("(%p)\n",pidl);
1682 return (pidl && lpPData && (PT_DRIVE == lpPData->type ||
1683 PT_DRIVE1 == lpPData->type ||
1684 PT_DRIVE2 == lpPData->type ||
1685 PT_DRIVE3 == lpPData->type));
1688 BOOL _ILIsFolder(LPCITEMIDLIST pidl)
1690 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1692 TRACE("(%p)\n",pidl);
1694 return (pidl && lpPData && (PT_FOLDER == lpPData->type || PT_FOLDER1 == lpPData->type));
1697 BOOL _ILIsValue(LPCITEMIDLIST pidl)
1699 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1701 TRACE("(%p)\n",pidl);
1703 return (pidl && lpPData && PT_VALUE == lpPData->type);
1706 BOOL _ILIsCPanelStruct(LPCITEMIDLIST pidl)
1708 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1710 TRACE("(%p)\n",pidl);
1712 return (pidl && lpPData && (lpPData->type == 0));
1715 /**************************************************************************
1718 BOOL _ILIsPidlSimple(LPCITEMIDLIST pidl)
1722 if(! _ILIsDesktop(pidl)) /* pidl=NULL or mkid.cb=0 */
1724 WORD len = pidl->mkid.cb;
1725 LPCITEMIDLIST pidlnext = (LPCITEMIDLIST) (((const BYTE*)pidl) + len );
1727 if (pidlnext->mkid.cb)
1731 TRACE("%s\n", ret ? "Yes" : "No");
1735 /**************************************************************************
1737 * ### 3. section getting values from pidls ###
1740 /**************************************************************************
1743 * gets the text for the first item in the pidl (eg. simple pidl)
1745 * returns the length of the string
1747 DWORD _ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
1753 char szTemp[MAX_PATH];
1755 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1763 if (_ILIsDesktop(pidl))
1766 if (HCR_GetClassNameA(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1769 lstrcpynA(szOut, szTemp, uOutSize);
1771 dwReturn = strlen (szTemp);
1774 else if (( szSrc = _ILGetTextPointer(pidl) ))
1778 lstrcpynA(szOut, szSrc, uOutSize);
1780 dwReturn = strlen(szSrc);
1782 else if (( szSrcW = _ILGetTextPointerW(pidl) ))
1784 /* unicode filesystem */
1785 WideCharToMultiByte(CP_ACP,0,szSrcW, -1, szTemp, MAX_PATH, NULL, NULL);
1788 lstrcpynA(szOut, szTemp, uOutSize);
1790 dwReturn = strlen (szTemp);
1792 else if (( riid = _ILGetGUIDPointer(pidl) ))
1794 /* special folder */
1795 if ( HCR_GetClassNameA(riid, szTemp, MAX_PATH) )
1798 lstrcpynA(szOut, szTemp, uOutSize);
1800 dwReturn = strlen (szTemp);
1805 ERR("-- no text\n");
1808 TRACE("-- (%p=%s 0x%08x)\n",szOut,debugstr_a(szOut),dwReturn);
1812 /**************************************************************************
1815 * gets the text for the first item in the pidl (eg. simple pidl)
1817 * returns the length of the string
1819 DWORD _ILSimpleGetTextW (LPCITEMIDLIST pidl, LPWSTR szOut, UINT uOutSize)
1822 FileStructW *pFileStructW = _ILGetFileStructW(pidl);
1824 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1827 lstrcpynW(szOut, pFileStructW->wszName, uOutSize);
1828 dwReturn = lstrlenW(pFileStructW->wszName);
1831 WCHAR szTemp[MAX_PATH];
1842 if (_ILIsDesktop(pidl))
1845 if (HCR_GetClassNameW(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1848 lstrcpynW(szOut, szTemp, uOutSize);
1850 dwReturn = lstrlenW (szTemp);
1853 else if (( szSrcW = _ILGetTextPointerW(pidl) ))
1855 /* unicode filesystem */
1857 lstrcpynW(szOut, szSrcW, uOutSize);
1859 dwReturn = lstrlenW(szSrcW);
1861 else if (( szSrc = _ILGetTextPointer(pidl) ))
1864 MultiByteToWideChar(CP_ACP, 0, szSrc, -1, szTemp, MAX_PATH);
1867 lstrcpynW(szOut, szTemp, uOutSize);
1869 dwReturn = lstrlenW (szTemp);
1871 else if (( riid = _ILGetGUIDPointer(pidl) ))
1873 /* special folder */
1874 if ( HCR_GetClassNameW(riid, szTemp, MAX_PATH) )
1877 lstrcpynW(szOut, szTemp, uOutSize);
1879 dwReturn = lstrlenW (szTemp);
1884 ERR("-- no text\n");
1888 TRACE("-- (%p=%s 0x%08x)\n",szOut,debugstr_w(szOut),dwReturn);
1892 /**************************************************************************
1894 * ### 4. getting pointers to parts of pidls ###
1896 **************************************************************************
1897 * _ILGetDataPointer()
1899 LPPIDLDATA _ILGetDataPointer(LPCITEMIDLIST pidl)
1901 if(pidl && pidl->mkid.cb != 0x00)
1902 return (LPPIDLDATA)pidl->mkid.abID;
1906 /**************************************************************************
1907 * _ILGetTextPointerW()
1908 * gets a pointer to the unicode long filename string stored in the pidl
1910 static LPWSTR _ILGetTextPointerW(LPCITEMIDLIST pidl)
1912 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
1914 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
1919 switch (pdata->type)
1930 /*return (LPSTR)&(pdata->u.drive.szDriveName);*/
1938 /*return (LPSTR)&(pdata->u.file.szNames);*/
1944 case PT_NETPROVIDER:
1946 /*return (LPSTR)&(pdata->u.network.szNames);*/
1950 return (LPWSTR)pdata->u.file.szNames;
1956 /**************************************************************************
1957 * _ILGetTextPointer()
1958 * gets a pointer to the long filename string stored in the pidl
1960 LPSTR _ILGetTextPointer(LPCITEMIDLIST pidl)
1962 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
1964 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
1969 switch (pdata->type)
1980 return pdata->u.drive.szDriveName;
1987 return pdata->u.file.szNames;
1992 case PT_NETPROVIDER:
1994 return pdata->u.network.szNames;
1999 /**************************************************************************
2000 * _ILGetSTextPointer()
2001 * gets a pointer to the short filename string stored in the pidl
2003 static LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl)
2005 /* TRACE(pidl,"(pidl%p)\n", pidl); */
2007 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
2012 switch (pdata->type)
2018 return pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1;
2021 return pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1;
2026 /**************************************************************************
2027 * _ILGetGUIDPointer()
2029 * returns reference to guid stored in some pidls
2031 IID* _ILGetGUIDPointer(LPCITEMIDLIST pidl)
2033 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
2035 TRACE("%p\n", pidl);
2040 TRACE("pdata->type 0x%04x\n", pdata->type);
2041 switch (pdata->type)
2046 return &(pdata->u.guid.guid);
2049 TRACE("Unknown pidl type 0x%04x\n", pdata->type);
2055 /******************************************************************************
2056 * _ILGetFileStructW [Internal]
2058 * Get pointer the a SHITEMID's FileStructW field if present
2061 * pidl [I] The SHITEMID
2064 * Success: Pointer to pidl's FileStructW field.
2067 FileStructW* _ILGetFileStructW(LPCITEMIDLIST pidl) {
2068 FileStructW *pFileStructW;
2071 if (!(_ILIsValue(pidl) || _ILIsFolder(pidl)))
2074 cbOffset = *(const WORD *)((const BYTE *)pidl + pidl->mkid.cb - sizeof(WORD));
2075 pFileStructW = (FileStructW*)((LPBYTE)pidl + cbOffset);
2077 /* Currently I don't see a fool prove way to figure out if a pidl is for sure of WinXP
2078 * style with a FileStructW member. If we switch all our shellfolder-implementations to
2079 * the new format, this won't be a problem. For now, we do as many sanity checks as possible. */
2080 if (cbOffset & 0x1 || /* FileStructW member is word aligned in the pidl */
2081 /* FileStructW is positioned after FileStruct */
2082 cbOffset < sizeof(pidl->mkid.cb) + sizeof(PIDLTYPE) + sizeof(FileStruct) ||
2083 /* There has to be enough space at cbOffset in the pidl to hold FileStructW and cbOffset */
2084 cbOffset > pidl->mkid.cb - sizeof(cbOffset) - sizeof(FileStructW) ||
2085 pidl->mkid.cb != cbOffset + pFileStructW->cbLen)
2087 WARN("Invalid pidl format (cbOffset = %d)!\n", cbOffset);
2091 return pFileStructW;
2094 /*************************************************************************
2095 * _ILGetFileDateTime
2097 * Given the ItemIdList, get the FileTime
2100 * pidl [I] The ItemIDList
2101 * pFt [I] the resulted FILETIME of the file
2104 * True if Successful
2109 BOOL _ILGetFileDateTime(LPCITEMIDLIST pidl, FILETIME *pFt)
2111 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2116 switch (pdata->type)
2120 DosDateTimeToFileTime(pdata->u.file.uFileDate, pdata->u.file.uFileTime, pFt);
2128 BOOL _ILGetFileDate (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2134 if (_ILGetFileDateTime( pidl, &ft ))
2136 FileTimeToLocalFileTime(&ft, &lft);
2137 FileTimeToSystemTime (&lft, &time);
2139 ret = GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&time, NULL, pOut, uOutSize);
2142 /* Append space + time without seconds */
2144 GetTimeFormatA(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &time, NULL, &pOut[ret], uOutSize - ret);
2155 /*************************************************************************
2158 * Given the ItemIdList, get the FileSize
2161 * pidl [I] The ItemIDList
2162 * pOut [I] The buffer to save the result
2163 * uOutsize [I] The size of the buffer
2169 * pOut can be null when no string is needed
2172 DWORD _ILGetFileSize (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2174 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2180 switch (pdata->type)
2183 dwSize = pdata->u.file.dwFileSize;
2185 StrFormatKBSizeA(dwSize, pOut, uOutSize);
2193 BOOL _ILGetExtension (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2195 char szTemp[MAX_PATH];
2196 const char * pPoint;
2197 LPCITEMIDLIST pidlTemp=pidl;
2199 TRACE("pidl=%p\n",pidl);
2204 pidlTemp = ILFindLastID(pidl);
2206 if (!_ILIsValue(pidlTemp))
2208 if (!_ILSimpleGetText(pidlTemp, szTemp, MAX_PATH))
2211 pPoint = PathFindExtensionA(szTemp);
2217 lstrcpynA(pOut, pPoint, uOutSize);
2223 /*************************************************************************
2226 * Given the ItemIdList, get the file type description
2229 * pidl [I] The ItemIDList (simple)
2230 * pOut [I] The buffer to save the result
2231 * uOutsize [I] The size of the buffer
2237 * This function copies as much as possible into the buffer.
2239 void _ILGetFileType(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2241 if(_ILIsValue(pidl))
2247 if (_ILGetExtension (pidl, sTemp, 64))
2249 if (!( HCR_MapTypeToValueA(sTemp, sTemp, 64, TRUE)
2250 && HCR_MapTypeToValueA(sTemp, pOut, uOutSize, FALSE )))
2252 lstrcpynA (pOut, sTemp, uOutSize - 6);
2253 strcat (pOut, "-file");
2258 lstrcpynA(pOut, "Folder", uOutSize);
2261 /*************************************************************************
2262 * _ILGetFileAttributes
2264 * Given the ItemIdList, get the Attrib string format
2267 * pidl [I] The ItemIDList
2268 * pOut [I] The buffer to save the result
2269 * uOutsize [I] The size of the Buffer
2275 * return value 0 in case of error is a valid return value
2278 DWORD _ILGetFileAttributes(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2280 LPPIDLDATA pData = _ILGetDataPointer(pidl);
2291 wAttrib = pData->u.file.uFileAttribs;
2298 if(wAttrib & FILE_ATTRIBUTE_READONLY)
2300 if(wAttrib & FILE_ATTRIBUTE_HIDDEN)
2302 if(wAttrib & FILE_ATTRIBUTE_SYSTEM)
2304 if(wAttrib & FILE_ATTRIBUTE_ARCHIVE)
2306 if(wAttrib & FILE_ATTRIBUTE_COMPRESSED)
2313 /*************************************************************************
2316 * free a aPidl struct
2318 void _ILFreeaPidl(LPITEMIDLIST * apidl, UINT cidl)
2324 for (i = 0; i < cidl; i++)
2330 /*************************************************************************
2333 * copies an aPidl struct
2335 LPITEMIDLIST* _ILCopyaPidl(const LPCITEMIDLIST * apidlsrc, UINT cidl)
2338 LPITEMIDLIST *apidldest;
2340 apidldest = SHAlloc(cidl * sizeof(LPITEMIDLIST));
2344 for (i = 0; i < cidl; i++)
2345 apidldest[i] = ILClone(apidlsrc[i]);
2350 /*************************************************************************
2351 * _ILCopyCidaToaPidl
2353 * creates aPidl from CIDA
2355 LPITEMIDLIST* _ILCopyCidaToaPidl(LPITEMIDLIST* pidl, const CIDA * cida)
2360 dst = SHAlloc(cida->cidl * sizeof(LPITEMIDLIST));
2365 *pidl = ILClone((LPCITEMIDLIST)(&((const BYTE*)cida)[cida->aoffset[0]]));
2367 for (i = 0; i < cida->cidl; i++)
2368 dst[i] = ILClone((LPCITEMIDLIST)(&((const BYTE*)cida)[cida->aoffset[i + 1]]));