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 /*************************************************************************
59 * ILGetDisplayNameEx [SHELL32.186]
61 * Retrieves the display name of an ItemIDList
64 * psf [I] Shell Folder to start with, if NULL the desktop is used
65 * pidl [I] ItemIDList relativ to the psf to get the display name for
66 * path [O] Filled in with the display name, assumed to be at least MAX_PATH long
67 * type [I] Type of display name to retrieve
68 * 0 = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR uses always the desktop as root
69 * 1 = SHGDN_NORMAL relative to the root folder
70 * 2 = SHGDN_INFOLDER relative to the root folder, only the last name
73 * True if the display name could be retrieved successfully, False otherwise
75 BOOL WINAPI ILGetDisplayNameExA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPSTR path, DWORD type)
78 WCHAR wPath[MAX_PATH];
80 TRACE("%p %p %p %d\n", psf, pidl, path, type);
85 ret = ILGetDisplayNameExW(psf, pidl, wPath, type);
86 WideCharToMultiByte(CP_ACP, 0, wPath, -1, path, MAX_PATH, NULL, NULL);
87 TRACE("%p %p %s\n", psf, pidl, debugstr_a(path));
92 BOOL WINAPI ILGetDisplayNameExW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPWSTR path, DWORD type)
94 LPSHELLFOLDER psfParent, lsf = psf;
95 HRESULT ret = NO_ERROR;
96 LPCITEMIDLIST pidllast;
100 TRACE("%p %p %p %d\n", psf, pidl, path, type);
107 ret = SHGetDesktopFolder(&lsf);
112 if (type >= 0 && type <= 2)
116 case ILGDN_FORPARSING:
117 flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
123 flag = SHGDN_INFOLDER;
126 FIXME("Unknown type parameter = %x\n", type);
127 flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
130 if (!*(const WORD*)pidl || type == ILGDN_FORPARSING)
132 ret = IShellFolder_GetDisplayNameOf(lsf, pidl, flag, &strret);
135 if(!StrRetToStrNW(path, MAX_PATH, &strret, pidl))
141 ret = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psfParent, &pidllast);
144 ret = IShellFolder_GetDisplayNameOf(psfParent, pidllast, flag, &strret);
147 if(!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 %d\n", psf, pidl, path, type);
166 if (SHELL_OsIsUnicode())
167 return ILGetDisplayNameExW(psf, pidl, path, type);
168 return ILGetDisplayNameExA(psf, pidl, path, type);
171 /*************************************************************************
172 * ILGetDisplayName [SHELL32.15]
174 BOOL WINAPI ILGetDisplayName(LPCITEMIDLIST pidl, LPVOID path)
176 TRACE_(shell)("%p %p\n", pidl, path);
178 if (SHELL_OsIsUnicode())
179 return ILGetDisplayNameExW(NULL, pidl, path, ILGDN_FORPARSING);
180 return ILGetDisplayNameExA(NULL, pidl, path, ILGDN_FORPARSING);
183 /*************************************************************************
184 * ILFindLastID [SHELL32.16]
187 * observed: pidl=Desktop return=pidl
189 LPITEMIDLIST WINAPI ILFindLastID(LPCITEMIDLIST pidl)
191 LPCITEMIDLIST pidlLast = pidl;
193 TRACE("(pidl=%p)\n",pidl);
198 while (pidl->mkid.cb)
201 pidl = ILGetNext(pidl);
203 return (LPITEMIDLIST)pidlLast;
206 /*************************************************************************
207 * ILRemoveLastID [SHELL32.17]
210 * when pidl=Desktop return=FALSE
212 BOOL WINAPI ILRemoveLastID(LPITEMIDLIST pidl)
214 TRACE_(shell)("pidl=%p\n",pidl);
216 if (!pidl || !pidl->mkid.cb)
218 ILFindLastID(pidl)->mkid.cb = 0;
222 /*************************************************************************
223 * ILClone [SHELL32.18]
226 * duplicate an idlist
228 LPITEMIDLIST WINAPI ILClone (LPCITEMIDLIST pidl)
231 LPITEMIDLIST newpidl;
236 len = ILGetSize(pidl);
237 newpidl = (LPITEMIDLIST)SHAlloc(len);
239 memcpy(newpidl,pidl,len);
241 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
247 /*************************************************************************
248 * ILCloneFirst [SHELL32.19]
251 * duplicates the first idlist of a complex pidl
253 LPITEMIDLIST WINAPI ILCloneFirst(LPCITEMIDLIST pidl)
256 LPITEMIDLIST pidlNew = NULL;
258 TRACE("pidl=%p\n", pidl);
264 pidlNew = (LPITEMIDLIST) SHAlloc (len+2);
267 memcpy(pidlNew,pidl,len+2); /* 2 -> mind a desktop pidl */
270 ILGetNext(pidlNew)->mkid.cb = 0x00;
273 TRACE("-- newpidl=%p\n",pidlNew);
278 /*************************************************************************
279 * ILLoadFromStream (SHELL32.26)
282 * the first two bytes are the len, the pidl is following then
284 HRESULT WINAPI ILLoadFromStream (IStream * pStream, LPITEMIDLIST * ppPidl)
288 HRESULT ret = E_FAIL;
291 TRACE_(shell)("%p %p\n", pStream , ppPidl);
296 IStream_AddRef (pStream);
298 if (SUCCEEDED(IStream_Read(pStream, (LPVOID)&wLen, 2, &dwBytesRead)))
300 TRACE("PIDL length is %d\n", wLen);
303 *ppPidl = SHAlloc (wLen);
304 if (SUCCEEDED(IStream_Read(pStream, *ppPidl , wLen, &dwBytesRead)))
306 TRACE("Stream read OK\n");
311 WARN("reading pidl failed\n");
323 /* we are not yet fully compatible */
324 if (*ppPidl && !pcheck(*ppPidl))
326 WARN("Check failed\n");
331 IStream_Release (pStream);
336 /*************************************************************************
337 * ILSaveToStream (SHELL32.27)
340 * the first two bytes are the len, the pidl is following then
342 HRESULT WINAPI ILSaveToStream (IStream * pStream, LPCITEMIDLIST pPidl)
345 HRESULT ret = E_FAIL;
347 TRACE_(shell)("%p %p\n", pStream, pPidl);
349 IStream_AddRef (pStream);
351 wLen = ILGetSize(pPidl);
353 if (SUCCEEDED(IStream_Write(pStream, (LPVOID)&wLen, 2, NULL)))
355 if (SUCCEEDED(IStream_Write(pStream, pPidl, wLen, NULL)))
358 IStream_Release (pStream);
363 /*************************************************************************
364 * SHILCreateFromPath [SHELL32.28]
366 * Create an ItemIDList from a path
371 * attributes [I/O] requested attributes on call and actual attributes when
372 * the function returns
375 * NO_ERROR if successful, or an OLE errer code otherwise
378 * Wrapper for IShellFolder_ParseDisplayName().
380 HRESULT WINAPI SHILCreateFromPathA(LPCSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
382 WCHAR lpszDisplayName[MAX_PATH];
384 TRACE_(shell)("%s %p 0x%08x\n", path, ppidl, attributes ? *attributes : 0);
386 if (!MultiByteToWideChar(CP_ACP, 0, path, -1, lpszDisplayName, MAX_PATH))
387 lpszDisplayName[MAX_PATH-1] = 0;
389 return SHILCreateFromPathW(lpszDisplayName, ppidl, attributes);
392 HRESULT WINAPI SHILCreateFromPathW(LPCWSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
396 HRESULT ret = E_FAIL;
398 TRACE_(shell)("%s %p 0x%08x\n", debugstr_w(path), ppidl, attributes ? *attributes : 0);
400 if (SUCCEEDED (SHGetDesktopFolder(&sf)))
402 ret = IShellFolder_ParseDisplayName(sf, 0, NULL, (LPWSTR)path, &pchEaten, ppidl, attributes);
403 IShellFolder_Release(sf);
408 HRESULT WINAPI SHILCreateFromPathAW (LPCVOID path, LPITEMIDLIST * ppidl, DWORD * attributes)
410 if ( SHELL_OsIsUnicode())
411 return SHILCreateFromPathW (path, ppidl, attributes);
412 return SHILCreateFromPathA (path, ppidl, attributes);
415 /*************************************************************************
416 * SHCloneSpecialIDList [SHELL32.89]
418 * Create an ItemIDList to one of the special folders.
422 * nFolder [in] CSIDL_xxxxx
423 * fCreate [in] Create folder if it does not exist
426 * Success: The newly created pidl
427 * Failure: NULL, if inputs are invalid.
430 * exported by ordinal.
431 * Caller is responsible for deallocating the returned ItemIDList with the
432 * shells IMalloc interface, aka ILFree.
434 LPITEMIDLIST WINAPI SHCloneSpecialIDList(HWND hwndOwner, DWORD nFolder, BOOL fCreate)
437 TRACE_(shell)("(hwnd=%p,csidl=0x%x,%s).\n", hwndOwner, nFolder, fCreate ? "T" : "F");
440 nFolder |= CSIDL_FLAG_CREATE;
442 SHGetSpecialFolderLocation(hwndOwner, nFolder, &ppidl);
446 /*************************************************************************
447 * ILGlobalClone [SHELL32.20]
449 * Clones an ItemIDList using Alloc.
452 * pidl [I] ItemIDList to clone
455 * Newly allocated ItemIDList.
458 * exported by ordinal.
460 LPITEMIDLIST WINAPI ILGlobalClone(LPCITEMIDLIST pidl)
463 LPITEMIDLIST newpidl;
468 len = ILGetSize(pidl);
469 newpidl = (LPITEMIDLIST)Alloc(len);
471 memcpy(newpidl,pidl,len);
473 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
479 /*************************************************************************
480 * ILIsEqual [SHELL32.21]
483 BOOL WINAPI ILIsEqual(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
485 char szData1[MAX_PATH];
486 char szData2[MAX_PATH];
488 LPCITEMIDLIST pidltemp1 = pidl1;
489 LPCITEMIDLIST pidltemp2 = pidl2;
491 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
494 * Explorer reads from registry directly (StreamMRU),
495 * so we can only check here
497 if (!pcheck(pidl1) || !pcheck (pidl2))
503 if (!pidl1 || !pidl2)
506 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
508 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
509 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
511 if (strcasecmp( szData1, szData2 ))
514 pidltemp1 = ILGetNext(pidltemp1);
515 pidltemp2 = ILGetNext(pidltemp2);
518 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];
548 LPCITEMIDLIST pParent = pidlParent;
549 LPCITEMIDLIST pChild = pidlChild;
551 TRACE("%p %p %x\n", pidlParent, pidlChild, bImmediate);
553 if (!pParent || !pChild)
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 ))
564 pParent = ILGetNext(pParent);
565 pChild = ILGetNext(pChild);
568 /* child shorter or has equal length to parent */
569 if (pParent->mkid.cb || !pChild->mkid.cb)
572 /* not immediate descent */
573 if ( ILGetNext(pChild)->mkid.cb && bImmediate)
579 /*************************************************************************
580 * ILFindChild [SHELL32.24]
582 * Compares elements from pidl1 and pidl2.
589 * pidl1 is desktop pidl2
590 * pidl1 shorter pidl2 pointer to first different element of pidl2
591 * if there was at least one equal element
592 * pidl2 shorter pidl1 0
593 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
596 * exported by ordinal.
598 LPITEMIDLIST WINAPI ILFindChild(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
600 char szData1[MAX_PATH];
601 char szData2[MAX_PATH];
603 LPCITEMIDLIST pidltemp1 = pidl1;
604 LPCITEMIDLIST pidltemp2 = pidl2;
605 LPCITEMIDLIST ret=NULL;
607 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
609 /* explorer reads from registry directly (StreamMRU),
610 so we can only check here */
611 if ((!pcheck (pidl1)) || (!pcheck (pidl2)))
617 if (_ILIsDesktop(pidl1))
623 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
625 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
626 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
628 if (strcasecmp(szData1,szData2))
631 pidltemp1 = ILGetNext(pidltemp1);
632 pidltemp2 = ILGetNext(pidltemp2);
636 if (pidltemp1->mkid.cb)
637 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;
710 hr = IShellFolder_GetUIObjectOf(lpsf, 0, 1, &pidlSimple,
711 &IID_IDataObject, 0, (LPVOID*)&pDataObj);
717 fmt.cfFormat = RegisterClipboardFormatA(CFSTR_SHELLIDLIST);
719 fmt.dwAspect = DVASPECT_CONTENT;
721 fmt.tymed = TYMED_HGLOBAL;
723 hr = IDataObject_GetData(pDataObj, &fmt, &medium);
725 IDataObject_Release(pDataObj);
729 /*assert(pida->cidl==1);*/
730 LPIDA pida = (LPIDA)GlobalLock(medium.u.hGlobal);
732 LPCITEMIDLIST pidl_folder = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[0]);
733 LPCITEMIDLIST pidl_child = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[1]);
735 *pidlReal = ILCombine(pidl_folder, pidl_child);
740 GlobalUnlock(medium.u.hGlobal);
741 GlobalFree(medium.u.hGlobal);
748 /*************************************************************************
749 * SHLogILFromFSIL [SHELL32.95]
752 * pild = CSIDL_DESKTOP ret = 0
753 * pild = CSIDL_DRIVES ret = 0
755 LPITEMIDLIST WINAPI SHLogILFromFSIL(LPITEMIDLIST pidl)
757 FIXME("(pidl=%p)\n",pidl);
764 /*************************************************************************
765 * ILGetSize [SHELL32.152]
767 * Gets the byte size of an ItemIDList including zero terminator
770 * pidl [I] ItemIDList
773 * size of pidl in bytes
776 * exported by ordinal
778 UINT WINAPI ILGetSize(LPCITEMIDLIST pidl)
780 LPCSHITEMID si = &(pidl->mkid);
788 si = (LPCSHITEMID)(((const BYTE*)si)+si->cb);
792 TRACE("pidl=%p size=%u\n",pidl, len);
796 /*************************************************************************
797 * ILGetNext [SHELL32.153]
799 * Gets the next ItemID of an ItemIDList
802 * pidl [I] ItemIDList
807 * simple pidl -> pointer to 0x0000 element
810 * exported by ordinal.
812 LPITEMIDLIST WINAPI ILGetNext(LPCITEMIDLIST pidl)
823 pidl = (LPCITEMIDLIST) (((const BYTE*)pidl)+len);
824 TRACE("-- %p\n", pidl);
825 return (LPITEMIDLIST)pidl;
831 /*************************************************************************
832 * ILAppend [SHELL32.154]
834 * Adds the single ItemID item to the ItemIDList indicated by pidl.
835 * If bEnd is FALSE, inserts the item in the front of the list,
836 * otherwise it adds the item to the end. (???)
839 * pidl [I] ItemIDList to extend
840 * item [I] ItemID to prepend/append
841 * bEnd [I] Indicates if the item should be appended
844 * Destroys the passed in idlist! (???)
846 LPITEMIDLIST WINAPI ILAppend(LPITEMIDLIST pidl, LPCITEMIDLIST item, BOOL bEnd)
850 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl,item,bEnd);
855 if (_ILIsDesktop(pidl))
857 idlRet = ILClone(item);
863 idlRet = ILCombine(pidl, item);
865 idlRet = ILCombine(item, pidl);
871 /*************************************************************************
872 * ILFree [SHELL32.155]
874 * Frees memory (if not NULL) allocated by SHMalloc allocator
883 * exported by ordinal
885 void WINAPI ILFree(LPITEMIDLIST pidl)
887 TRACE("(pidl=%p)\n",pidl);
891 /*************************************************************************
892 * ILGlobalFree [SHELL32.156]
894 * Frees memory (if not NULL) allocated by Alloc allocator
903 * exported by ordinal.
905 void WINAPI ILGlobalFree( LPITEMIDLIST pidl)
912 /*************************************************************************
913 * ILCreateFromPathA [SHELL32.189]
915 * Creates a complex ItemIDList from a path and returns it.
921 * the newly created complex ItemIDList or NULL if failed
924 * exported by ordinal.
926 LPITEMIDLIST WINAPI ILCreateFromPathA (LPCSTR path)
928 LPITEMIDLIST pidlnew = NULL;
930 TRACE_(shell)("%s\n", debugstr_a(path));
932 if (SUCCEEDED(SHILCreateFromPathA(path, &pidlnew, NULL)))
937 /*************************************************************************
938 * ILCreateFromPathW [SHELL32.190]
940 * See ILCreateFromPathA.
942 LPITEMIDLIST WINAPI ILCreateFromPathW (LPCWSTR path)
944 LPITEMIDLIST pidlnew = NULL;
946 TRACE_(shell)("%s\n", debugstr_w(path));
948 if (SUCCEEDED(SHILCreateFromPathW(path, &pidlnew, NULL)))
953 /*************************************************************************
954 * ILCreateFromPath [SHELL32.157]
956 LPITEMIDLIST WINAPI ILCreateFromPathAW (LPCVOID path)
958 if ( SHELL_OsIsUnicode())
959 return ILCreateFromPathW (path);
960 return ILCreateFromPathA (path);
963 /*************************************************************************
964 * _ILParsePathW [internal]
966 * Creates an ItemIDList from a path and returns it.
969 * path [I] path to parse and convert into an ItemIDList
970 * lpFindFile [I] pointer to buffer to initialize the FileSystem
971 * Bind Data object with
972 * bBindCtx [I] indicates to create a BindContext and assign a
973 * FileSystem Bind Data object
974 * ppidl [O] the newly create ItemIDList
975 * prgfInOut [I/O] requested attributes on input and actual
976 * attributes on return
979 * NO_ERROR on success or an OLE error code
982 * If either lpFindFile is non-NULL or bBindCtx is TRUE, this function
983 * creates a BindContext object and assigns a FileSystem Bind Data object
984 * to it, passing the BindContext to IShellFolder_ParseDisplayName. Each
985 * IShellFolder uses that FileSystem Bind Data object of the BindContext
986 * to pass data about the current path element to the next object. This
987 * is used to avoid having to verify the current path element on disk, so
988 * that creating an ItemIDList from a nonexistent path still can work.
990 static HRESULT WINAPI _ILParsePathW(LPCWSTR path, LPWIN32_FIND_DATAW lpFindFile,
991 BOOL bBindCtx, LPITEMIDLIST *ppidl, LPDWORD prgfInOut)
993 LPSHELLFOLDER pSF = NULL;
997 TRACE("%s %p %d (%p)->%p (%p)->0x%x\n", debugstr_w(path), lpFindFile, bBindCtx,
998 ppidl, ppidl ? *ppidl : NULL,
999 prgfInOut, prgfInOut ? *prgfInOut : 0);
1001 ret = SHGetDesktopFolder(&pSF);
1005 if (lpFindFile || bBindCtx)
1006 ret = IFileSystemBindData_Constructor(lpFindFile, &pBC);
1010 ret = IShellFolder_ParseDisplayName(pSF, 0, pBC, (LPOLESTR)path, NULL, ppidl, prgfInOut);
1015 IBindCtx_Release(pBC);
1019 IShellFolder_Release(pSF);
1021 if (!SUCCEEDED(ret) && ppidl)
1024 TRACE("%s %p 0x%x\n", debugstr_w(path), ppidl ? *ppidl : NULL, prgfInOut ? *prgfInOut : 0);
1029 /*************************************************************************
1030 * SHSimpleIDListFromPath [SHELL32.162]
1032 * Creates a simple ItemIDList from a path and returns it. This function
1033 * does not fail on nonexistent paths.
1036 * path [I] path to parse and convert into an ItemIDList
1039 * the newly created simple ItemIDList
1042 * Simple in the name does not mean a relative ItemIDList but rather a
1043 * fully qualified list, where only the file name is filled in and the
1044 * directory flag for those ItemID elements this is known about, eg.
1045 * it is not the last element in the ItemIDList or the actual directory
1047 * exported by ordinal.
1049 LPITEMIDLIST WINAPI SHSimpleIDListFromPathA(LPCSTR lpszPath)
1051 LPITEMIDLIST pidl = NULL;
1052 LPWSTR wPath = NULL;
1055 TRACE("%s\n", debugstr_a(lpszPath));
1059 len = MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, NULL, 0);
1060 wPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1061 MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, wPath, len);
1064 _ILParsePathW(wPath, NULL, TRUE, &pidl, NULL);
1066 HeapFree(GetProcessHeap(), 0, wPath);
1067 TRACE("%s %p\n", debugstr_a(lpszPath), pidl);
1071 LPITEMIDLIST WINAPI SHSimpleIDListFromPathW(LPCWSTR lpszPath)
1073 LPITEMIDLIST pidl = NULL;
1075 TRACE("%s\n", debugstr_w(lpszPath));
1077 _ILParsePathW(lpszPath, NULL, TRUE, &pidl, NULL);
1078 TRACE("%s %p\n", debugstr_w(lpszPath), pidl);
1082 LPITEMIDLIST WINAPI SHSimpleIDListFromPathAW(LPCVOID lpszPath)
1084 if ( SHELL_OsIsUnicode())
1085 return SHSimpleIDListFromPathW (lpszPath);
1086 return SHSimpleIDListFromPathA (lpszPath);
1089 /*************************************************************************
1090 * SHGetDataFromIDListA [SHELL32.247]
1093 * the pidl can be a simple one. since we can't get the path out of the pidl
1094 * we have to take all data from the pidl
1096 HRESULT WINAPI SHGetDataFromIDListA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl,
1097 int nFormat, LPVOID dest, int len)
1099 LPSTR filename, shortname;
1100 WIN32_FIND_DATAA * pfd;
1102 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
1106 return E_INVALIDARG;
1110 case SHGDFIL_FINDDATA:
1113 if (_ILIsDrive(pidl) || _ILIsSpecialFolder(pidl))
1114 return E_INVALIDARG;
1116 if (len < sizeof(WIN32_FIND_DATAA))
1117 return E_INVALIDARG;
1119 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1120 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1121 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1122 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1124 filename = _ILGetTextPointer(pidl);
1125 shortname = _ILGetSTextPointer(pidl);
1128 lstrcpynA(pfd->cFileName, filename, MAX_PATH);
1130 pfd->cFileName[0] = '\0';
1133 lstrcpynA(pfd->cAlternateFileName, shortname, MAX_PATH);
1135 pfd->cAlternateFileName[0] = '\0';
1138 case SHGDFIL_NETRESOURCE:
1139 case SHGDFIL_DESCRIPTIONID:
1140 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1144 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1147 return E_INVALIDARG;
1150 /*************************************************************************
1151 * SHGetDataFromIDListW [SHELL32.248]
1154 HRESULT WINAPI SHGetDataFromIDListW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl,
1155 int nFormat, LPVOID dest, int len)
1157 LPSTR filename, shortname;
1158 WIN32_FIND_DATAW * pfd = dest;
1160 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
1165 return E_INVALIDARG;
1169 case SHGDFIL_FINDDATA:
1172 if (_ILIsDrive(pidl))
1173 return E_INVALIDARG;
1175 if (len < sizeof(WIN32_FIND_DATAW))
1176 return E_INVALIDARG;
1178 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1179 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1180 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1181 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1183 filename = _ILGetTextPointer(pidl);
1184 shortname = _ILGetSTextPointer(pidl);
1187 pfd->cFileName[0] = '\0';
1188 else if (!MultiByteToWideChar(CP_ACP, 0, filename, -1, pfd->cFileName, MAX_PATH))
1189 pfd->cFileName[MAX_PATH-1] = 0;
1192 pfd->cAlternateFileName[0] = '\0';
1193 else if (!MultiByteToWideChar(CP_ACP, 0, shortname, -1, pfd->cAlternateFileName, 14))
1194 pfd->cAlternateFileName[13] = 0;
1197 case SHGDFIL_NETRESOURCE:
1198 case SHGDFIL_DESCRIPTIONID:
1199 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1203 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1206 return E_INVALIDARG;
1209 /*************************************************************************
1210 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
1214 * pszPath [OUT] path
1217 * path from a passed PIDL.
1220 * NULL returns FALSE
1221 * desktop pidl gives path to desktop directory back
1222 * special pidls returning FALSE
1224 BOOL WINAPI SHGetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath)
1226 WCHAR wszPath[MAX_PATH];
1229 bSuccess = SHGetPathFromIDListW(pidl, wszPath);
1230 WideCharToMultiByte(CP_ACP, 0, wszPath, -1, pszPath, MAX_PATH, NULL, NULL);
1235 /*************************************************************************
1236 * SHGetPathFromIDListW [SHELL32.@]
1238 * See SHGetPathFromIDListA.
1240 BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
1243 LPCITEMIDLIST pidlLast;
1244 LPSHELLFOLDER psfFolder;
1248 TRACE_(shell)("(pidl=%p,%p)\n", pidl, pszPath);
1255 hr = SHBindToParent(pidl, &IID_IShellFolder, (VOID**)&psfFolder, &pidlLast);
1256 if (FAILED(hr)) return FALSE;
1258 dwAttributes = SFGAO_FILESYSTEM;
1259 hr = IShellFolder_GetAttributesOf(psfFolder, 1, &pidlLast, &dwAttributes);
1260 if (FAILED(hr) || !(dwAttributes & SFGAO_FILESYSTEM)) {
1261 IShellFolder_Release(psfFolder);
1265 hr = IShellFolder_GetDisplayNameOf(psfFolder, pidlLast, SHGDN_FORPARSING, &strret);
1266 IShellFolder_Release(psfFolder);
1267 if (FAILED(hr)) return FALSE;
1269 hr = StrRetToBufW(&strret, pidlLast, pszPath, MAX_PATH);
1271 TRACE_(shell)("-- %s, 0x%08x\n",debugstr_w(pszPath), hr);
1272 return SUCCEEDED(hr);
1275 /*************************************************************************
1276 * SHBindToParent [shell version 5.0]
1278 HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
1280 IShellFolder * psfDesktop;
1283 TRACE_(shell)("pidl=%p\n", pidl);
1287 return E_INVALIDARG;
1293 hr = SHGetDesktopFolder(&psfDesktop);
1297 if (_ILIsPidlSimple(pidl))
1299 /* we are on desktop level */
1300 hr = IShellFolder_QueryInterface(psfDesktop, riid, ppv);
1304 LPITEMIDLIST pidlParent = ILClone(pidl);
1305 ILRemoveLastID(pidlParent);
1306 hr = IShellFolder_BindToObject(psfDesktop, pidlParent, NULL, riid, ppv);
1307 SHFree (pidlParent);
1310 IShellFolder_Release(psfDesktop);
1312 if (SUCCEEDED(hr) && ppidlLast)
1313 *ppidlLast = ILFindLastID(pidl);
1315 TRACE_(shell)("-- psf=%p pidl=%p ret=0x%08x\n", *ppv, (ppidlLast)?*ppidlLast:NULL, hr);
1319 /**************************************************************************
1321 * internal functions
1323 * ### 1. section creating pidls ###
1325 *************************************************************************
1327 LPITEMIDLIST _ILAlloc(PIDLTYPE type, unsigned int size)
1329 LPITEMIDLIST pidlOut = NULL;
1331 pidlOut = SHAlloc(size + 5);
1335 LPITEMIDLIST pidlNext;
1337 ZeroMemory(pidlOut, size + 5);
1338 pidlOut->mkid.cb = size + 3;
1340 pData = _ILGetDataPointer(pidlOut);
1344 pidlNext = ILGetNext(pidlOut);
1346 pidlNext->mkid.cb = 0x00;
1347 TRACE("-- (pidl=%p, size=%u)\n", pidlOut, size);
1353 LPITEMIDLIST _ILCreateDesktop(void)
1364 LPITEMIDLIST _ILCreateMyComputer(void)
1367 return _ILCreateGuid(PT_GUID, &CLSID_MyComputer);
1370 LPITEMIDLIST _ILCreateMyDocuments(void)
1373 return _ILCreateGuid(PT_GUID, &CLSID_MyDocuments);
1376 LPITEMIDLIST _ILCreateIExplore(void)
1379 return _ILCreateGuid(PT_GUID, &CLSID_Internet);
1382 LPITEMIDLIST _ILCreateControlPanel(void)
1384 LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL;
1389 LPITEMIDLIST cpl = _ILCreateGuid(PT_SHELLEXT, &CLSID_ControlPanel);
1393 ret = ILCombine(parent, cpl);
1401 LPITEMIDLIST _ILCreatePrinters(void)
1403 LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL;
1408 LPITEMIDLIST printers = _ILCreateGuid(PT_YAGUID, &CLSID_Printers);
1412 ret = ILCombine(parent, printers);
1420 LPITEMIDLIST _ILCreateNetwork(void)
1423 return _ILCreateGuid(PT_GUID, &CLSID_NetworkPlaces);
1426 LPITEMIDLIST _ILCreateBitBucket(void)
1429 return _ILCreateGuid(PT_GUID, &CLSID_RecycleBin);
1432 LPITEMIDLIST _ILCreateNetHood(void)
1435 return _ILCreateGuid(PT_GUID, &CLSID_NetworkPlaces);
1438 LPITEMIDLIST _ILCreateGuid(PIDLTYPE type, REFIID guid)
1440 LPITEMIDLIST pidlOut;
1442 if (type == PT_SHELLEXT || type == PT_GUID || type == PT_YAGUID)
1444 pidlOut = _ILAlloc(type, sizeof(GUIDStruct));
1447 LPPIDLDATA pData = _ILGetDataPointer(pidlOut);
1449 memcpy(&(pData->u.guid.guid), guid, sizeof(GUID));
1450 TRACE("-- create GUID-pidl %s\n",
1451 debugstr_guid(&(pData->u.guid.guid)));
1456 WARN("%d: invalid type for GUID\n", type);
1462 LPITEMIDLIST _ILCreateGuidFromStrA(LPCSTR szGUID)
1466 if (!SUCCEEDED(SHCLSIDFromStringA(szGUID, &iid)))
1468 ERR("%s is not a GUID\n", szGUID);
1471 return _ILCreateGuid(PT_GUID, &iid);
1474 LPITEMIDLIST _ILCreateGuidFromStrW(LPCWSTR szGUID)
1478 if (!SUCCEEDED(SHCLSIDFromStringW(szGUID, &iid)))
1480 ERR("%s is not a GUID\n", debugstr_w(szGUID));
1483 return _ILCreateGuid(PT_GUID, &iid);
1486 LPITEMIDLIST _ILCreateFromFindDataW( const WIN32_FIND_DATAW *wfd )
1488 char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1489 DWORD len, len1, wlen, alen;
1496 TRACE("(%s, %s)\n",debugstr_w(wfd->cAlternateFileName), debugstr_w(wfd->cFileName));
1498 /* prepare buffer with both names */
1499 len = WideCharToMultiByte(CP_ACP,0,wfd->cFileName,-1,buff,MAX_PATH,NULL,NULL);
1500 len1 = WideCharToMultiByte(CP_ACP,0,wfd->cAlternateFileName,-1, buff+len, sizeof(buff)-len, NULL, NULL);
1503 type = (wfd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? PT_FOLDER : PT_VALUE;
1505 wlen = lstrlenW(wfd->cFileName) + 1;
1506 pidl = _ILAlloc(type, FIELD_OFFSET(FileStruct, szNames[alen + (alen & 1)]) +
1507 FIELD_OFFSET(FileStructW, wszName[wlen]) + sizeof(WORD));
1510 LPPIDLDATA pData = _ILGetDataPointer(pidl);
1511 FileStruct *fs = &pData->u.file;
1515 FileTimeToDosDateTime( &wfd->ftLastWriteTime, &fs->uFileDate, &fs->uFileTime);
1516 fs->dwFileSize = wfd->nFileSizeLow;
1517 fs->uFileAttribs = wfd->dwFileAttributes;
1518 memcpy(fs->szNames, buff, alen);
1520 fsw = (FileStructW*)(pData->u.file.szNames + alen + (alen & 0x1));
1521 fsw->cbLen = FIELD_OFFSET(FileStructW, wszName[wlen]) + sizeof(WORD);
1522 FileTimeToDosDateTime( &wfd->ftCreationTime, &fsw->uCreationDate, &fsw->uCreationTime);
1523 FileTimeToDosDateTime( &wfd->ftLastAccessTime, &fsw->uLastAccessDate, &fsw->uLastAccessTime);
1524 memcpy(fsw->wszName, wfd->cFileName, wlen * sizeof(WCHAR));
1526 pOffsetW = (WORD*)((LPBYTE)pidl + pidl->mkid.cb - sizeof(WORD));
1527 *pOffsetW = (LPBYTE)fsw - (LPBYTE)pidl;
1528 TRACE("-- Set Value: %s\n",debugstr_w(fsw->wszName));
1534 HRESULT _ILCreateFromPathW(LPCWSTR szPath, LPITEMIDLIST* ppidl)
1537 WIN32_FIND_DATAW stffile;
1540 return E_INVALIDARG;
1542 hFile = FindFirstFileW(szPath, &stffile);
1543 if (hFile == INVALID_HANDLE_VALUE)
1544 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
1548 *ppidl = _ILCreateFromFindDataW(&stffile);
1550 return *ppidl ? S_OK : E_OUTOFMEMORY;
1553 LPITEMIDLIST _ILCreateDrive(LPCWSTR lpszNew)
1555 LPITEMIDLIST pidlOut;
1557 TRACE("(%s)\n",debugstr_w(lpszNew));
1559 pidlOut = _ILAlloc(PT_DRIVE, sizeof(DriveStruct));
1564 pszDest = _ILGetTextPointer(pidlOut);
1567 strcpy(pszDest, "x:\\");
1568 pszDest[0]=toupperW(lpszNew[0]);
1569 TRACE("-- create Drive: %s\n", debugstr_a(pszDest));
1575 /**************************************************************************
1578 * Gets the text for the drive eg. 'c:\'
1583 DWORD _ILGetDrive(LPCITEMIDLIST pidl,LPSTR pOut, UINT uSize)
1585 TRACE("(%p,%p,%u)\n",pidl,pOut,uSize);
1587 if(_ILIsMyComputer(pidl))
1588 pidl = ILGetNext(pidl);
1590 if (pidl && _ILIsDrive(pidl))
1591 return _ILSimpleGetText(pidl, pOut, uSize);
1596 /**************************************************************************
1598 * ### 2. section testing pidls ###
1600 **************************************************************************
1604 * _ILIsSpecialFolder()
1610 BOOL _ILIsUnicode(LPCITEMIDLIST pidl)
1612 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1614 TRACE("(%p)\n",pidl);
1616 return (pidl && lpPData && PT_VALUEW == lpPData->type);
1619 BOOL _ILIsDesktop(LPCITEMIDLIST pidl)
1621 TRACE("(%p)\n",pidl);
1623 return pidl && pidl->mkid.cb ? 0 : 1;
1626 BOOL _ILIsMyComputer(LPCITEMIDLIST pidl)
1628 REFIID iid = _ILGetGUIDPointer(pidl);
1630 TRACE("(%p)\n",pidl);
1633 return IsEqualIID(iid, &CLSID_MyComputer);
1637 BOOL _ILIsSpecialFolder (LPCITEMIDLIST pidl)
1639 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1641 TRACE("(%p)\n",pidl);
1643 return (pidl && ( (lpPData && (PT_GUID== lpPData->type || PT_SHELLEXT== lpPData->type || PT_YAGUID == lpPData->type)) ||
1644 (pidl && pidl->mkid.cb == 0x00)
1648 BOOL _ILIsDrive(LPCITEMIDLIST pidl)
1650 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1652 TRACE("(%p)\n",pidl);
1654 return (pidl && lpPData && (PT_DRIVE == lpPData->type ||
1655 PT_DRIVE1 == lpPData->type ||
1656 PT_DRIVE2 == lpPData->type ||
1657 PT_DRIVE3 == lpPData->type));
1660 BOOL _ILIsFolder(LPCITEMIDLIST pidl)
1662 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1664 TRACE("(%p)\n",pidl);
1666 return (pidl && lpPData && (PT_FOLDER == lpPData->type || PT_FOLDER1 == lpPData->type));
1669 BOOL _ILIsValue(LPCITEMIDLIST pidl)
1671 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1673 TRACE("(%p)\n",pidl);
1675 return (pidl && lpPData && PT_VALUE == lpPData->type);
1678 BOOL _ILIsCPanelStruct(LPCITEMIDLIST pidl)
1680 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1682 TRACE("(%p)\n",pidl);
1684 return (pidl && lpPData && (lpPData->type == 0));
1687 /**************************************************************************
1690 BOOL _ILIsPidlSimple(LPCITEMIDLIST pidl)
1694 if(! _ILIsDesktop(pidl)) /* pidl=NULL or mkid.cb=0 */
1696 WORD len = pidl->mkid.cb;
1697 LPCITEMIDLIST pidlnext = (LPCITEMIDLIST) (((const BYTE*)pidl) + len );
1699 if (pidlnext->mkid.cb)
1703 TRACE("%s\n", ret ? "Yes" : "No");
1707 /**************************************************************************
1709 * ### 3. section getting values from pidls ###
1712 /**************************************************************************
1715 * gets the text for the first item in the pidl (eg. simple pidl)
1717 * returns the length of the string
1719 DWORD _ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
1725 char szTemp[MAX_PATH];
1727 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1735 if (_ILIsDesktop(pidl))
1738 if (HCR_GetClassNameA(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1741 lstrcpynA(szOut, szTemp, uOutSize);
1743 dwReturn = strlen (szTemp);
1746 else if (( szSrc = _ILGetTextPointer(pidl) ))
1750 lstrcpynA(szOut, szSrc, uOutSize);
1752 dwReturn = strlen(szSrc);
1754 else if (( szSrcW = _ILGetTextPointerW(pidl) ))
1756 /* unicode filesystem */
1757 WideCharToMultiByte(CP_ACP,0,szSrcW, -1, szTemp, MAX_PATH, NULL, NULL);
1760 lstrcpynA(szOut, szTemp, uOutSize);
1762 dwReturn = strlen (szTemp);
1764 else if (( riid = _ILGetGUIDPointer(pidl) ))
1766 /* special folder */
1767 if ( HCR_GetClassNameA(riid, szTemp, MAX_PATH) )
1770 lstrcpynA(szOut, szTemp, uOutSize);
1772 dwReturn = strlen (szTemp);
1777 ERR("-- no text\n");
1780 TRACE("-- (%p=%s 0x%08x)\n",szOut,debugstr_a(szOut),dwReturn);
1784 /**************************************************************************
1787 * gets the text for the first item in the pidl (eg. simple pidl)
1789 * returns the length of the string
1791 DWORD _ILSimpleGetTextW (LPCITEMIDLIST pidl, LPWSTR szOut, UINT uOutSize)
1794 FileStructW *pFileStructW = _ILGetFileStructW(pidl);
1796 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1799 lstrcpynW(szOut, pFileStructW->wszName, uOutSize);
1800 dwReturn = lstrlenW(pFileStructW->wszName);
1803 WCHAR szTemp[MAX_PATH];
1814 if (_ILIsDesktop(pidl))
1817 if (HCR_GetClassNameW(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1820 lstrcpynW(szOut, szTemp, uOutSize);
1822 dwReturn = lstrlenW (szTemp);
1825 else if (( szSrcW = _ILGetTextPointerW(pidl) ))
1827 /* unicode filesystem */
1829 lstrcpynW(szOut, szSrcW, uOutSize);
1831 dwReturn = lstrlenW(szSrcW);
1833 else if (( szSrc = _ILGetTextPointer(pidl) ))
1836 MultiByteToWideChar(CP_ACP, 0, szSrc, -1, szTemp, MAX_PATH);
1839 lstrcpynW(szOut, szTemp, uOutSize);
1841 dwReturn = lstrlenW (szTemp);
1843 else if (( riid = _ILGetGUIDPointer(pidl) ))
1845 /* special folder */
1846 if ( HCR_GetClassNameW(riid, szTemp, MAX_PATH) )
1849 lstrcpynW(szOut, szTemp, uOutSize);
1851 dwReturn = lstrlenW (szTemp);
1856 ERR("-- no text\n");
1860 TRACE("-- (%p=%s 0x%08x)\n",szOut,debugstr_w(szOut),dwReturn);
1864 /**************************************************************************
1866 * ### 4. getting pointers to parts of pidls ###
1868 **************************************************************************
1869 * _ILGetDataPointer()
1871 LPPIDLDATA _ILGetDataPointer(LPCITEMIDLIST pidl)
1873 if(pidl && pidl->mkid.cb != 0x00)
1874 return (LPPIDLDATA) &(pidl->mkid.abID);
1878 /**************************************************************************
1879 * _ILGetTextPointerW()
1880 * gets a pointer to the unicode long filename string stored in the pidl
1882 LPWSTR _ILGetTextPointerW(LPCITEMIDLIST pidl)
1884 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
1886 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
1891 switch (pdata->type)
1902 /*return (LPSTR)&(pdata->u.drive.szDriveName);*/
1910 /*return (LPSTR)&(pdata->u.file.szNames);*/
1916 case PT_NETPROVIDER:
1918 /*return (LPSTR)&(pdata->u.network.szNames);*/
1922 return (LPWSTR)&(pdata->u.file.szNames);
1928 /**************************************************************************
1929 * _ILGetTextPointer()
1930 * gets a pointer to the long filename string stored in the pidl
1932 LPSTR _ILGetTextPointer(LPCITEMIDLIST pidl)
1934 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
1936 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
1941 switch (pdata->type)
1952 return (LPSTR)&(pdata->u.drive.szDriveName);
1959 return (LPSTR)&(pdata->u.file.szNames);
1964 case PT_NETPROVIDER:
1966 return (LPSTR)&(pdata->u.network.szNames);
1971 /**************************************************************************
1972 * _ILGetSTextPointer()
1973 * gets a pointer to the short filename string stored in the pidl
1975 LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl)
1977 /* TRACE(pidl,"(pidl%p)\n", pidl); */
1979 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1984 switch (pdata->type)
1990 return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1);
1993 return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1);
1998 /**************************************************************************
1999 * _ILGetGUIDPointer()
2001 * returns reference to guid stored in some pidls
2003 IID* _ILGetGUIDPointer(LPCITEMIDLIST pidl)
2005 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
2007 TRACE("%p\n", pidl);
2012 TRACE("pdata->type 0x%04x\n", pdata->type);
2013 switch (pdata->type)
2018 return &(pdata->u.guid.guid);
2021 TRACE("Unknown pidl type 0x%04x\n", pdata->type);
2027 /******************************************************************************
2028 * _ILGetFileStructW [Internal]
2030 * Get pointer the a SHITEMID's FileStructW field if present
2033 * pidl [I] The SHITEMID
2036 * Success: Pointer to pidl's FileStructW field.
2039 FileStructW* _ILGetFileStructW(LPCITEMIDLIST pidl) {
2040 FileStructW *pFileStructW;
2043 if (!(_ILIsValue(pidl) || _ILIsFolder(pidl)))
2046 cbOffset = *(const WORD *)((const BYTE *)pidl + pidl->mkid.cb - sizeof(WORD));
2047 pFileStructW = (FileStructW*)((LPBYTE)pidl + cbOffset);
2049 /* Currently I don't see a fool prove way to figure out if a pidl is for sure of WinXP
2050 * style with a FileStructW member. If we switch all our shellfolder-implementations to
2051 * the new format, this won't be a problem. For now, we do as many sanity checks as possible. */
2052 if (cbOffset & 0x1 || /* FileStructW member is word aligned in the pidl */
2053 /* FileStructW is positioned after FileStruct */
2054 cbOffset < sizeof(pidl->mkid.cb) + sizeof(PIDLTYPE) + sizeof(FileStruct) ||
2055 /* There has to be enough space at cbOffset in the pidl to hold FileStructW and cbOffset */
2056 cbOffset > pidl->mkid.cb - sizeof(cbOffset) - sizeof(FileStructW) ||
2057 pidl->mkid.cb != cbOffset + pFileStructW->cbLen)
2059 WARN("Invalid pidl format (cbOffset = %d)!\n", cbOffset);
2063 return pFileStructW;
2066 /*************************************************************************
2067 * _ILGetFileDateTime
2069 * Given the ItemIdList, get the FileTime
2072 * pidl [I] The ItemIDList
2073 * pFt [I] the resulted FILETIME of the file
2076 * True if Successful
2081 BOOL _ILGetFileDateTime(LPCITEMIDLIST pidl, FILETIME *pFt)
2083 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2088 switch (pdata->type)
2092 DosDateTimeToFileTime(pdata->u.file.uFileDate, pdata->u.file.uFileTime, pFt);
2100 BOOL _ILGetFileDate (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2106 if (_ILGetFileDateTime( pidl, &ft ))
2108 FileTimeToLocalFileTime(&ft, &lft);
2109 FileTimeToSystemTime (&lft, &time);
2111 ret = GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&time, NULL, pOut, uOutSize);
2114 /* Append space + time without seconds */
2116 GetTimeFormatA(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &time, NULL, &pOut[ret], uOutSize - ret);
2127 /*************************************************************************
2130 * Given the ItemIdList, get the FileSize
2133 * pidl [I] The ItemIDList
2134 * pOut [I] The buffer to save the result
2135 * uOutsize [I] The size of the buffer
2141 * pOut can be null when no string is needed
2144 DWORD _ILGetFileSize (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2146 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2152 switch (pdata->type)
2155 dwSize = pdata->u.file.dwFileSize;
2157 StrFormatKBSizeA(dwSize, pOut, uOutSize);
2165 BOOL _ILGetExtension (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2167 char szTemp[MAX_PATH];
2168 const char * pPoint;
2169 LPCITEMIDLIST pidlTemp=pidl;
2171 TRACE("pidl=%p\n",pidl);
2176 pidlTemp = ILFindLastID(pidl);
2178 if (!_ILIsValue(pidlTemp))
2180 if (!_ILSimpleGetText(pidlTemp, szTemp, MAX_PATH))
2183 pPoint = PathFindExtensionA(szTemp);
2189 lstrcpynA(pOut, pPoint, uOutSize);
2195 /*************************************************************************
2198 * Given the ItemIdList, get the file type description
2201 * pidl [I] The ItemIDList (simple)
2202 * pOut [I] The buffer to save the result
2203 * uOutsize [I] The size of the buffer
2209 * This function copies as much as possible into the buffer.
2211 void _ILGetFileType(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2213 if(_ILIsValue(pidl))
2219 if (_ILGetExtension (pidl, sTemp, 64))
2221 if (!( HCR_MapTypeToValueA(sTemp, sTemp, 64, TRUE)
2222 && HCR_MapTypeToValueA(sTemp, pOut, uOutSize, FALSE )))
2224 lstrcpynA (pOut, sTemp, uOutSize - 6);
2225 strcat (pOut, "-file");
2230 lstrcpynA(pOut, "Folder", uOutSize);
2233 /*************************************************************************
2234 * _ILGetFileAttributes
2236 * Given the ItemIdList, get the Attrib string format
2239 * pidl [I] The ItemIDList
2240 * pOut [I] The buffer to save the result
2241 * uOutsize [I] The size of the Buffer
2247 * return value 0 in case of error is a valid return value
2250 DWORD _ILGetFileAttributes(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2252 LPPIDLDATA pData = _ILGetDataPointer(pidl);
2263 wAttrib = pData->u.file.uFileAttribs;
2270 if(wAttrib & FILE_ATTRIBUTE_READONLY)
2272 if(wAttrib & FILE_ATTRIBUTE_HIDDEN)
2274 if(wAttrib & FILE_ATTRIBUTE_SYSTEM)
2276 if(wAttrib & FILE_ATTRIBUTE_ARCHIVE)
2278 if(wAttrib & FILE_ATTRIBUTE_COMPRESSED)
2285 /*************************************************************************
2288 * free a aPidl struct
2290 void _ILFreeaPidl(LPITEMIDLIST * apidl, UINT cidl)
2296 for (i = 0; i < cidl; i++)
2302 /*************************************************************************
2305 * copies an aPidl struct
2307 LPITEMIDLIST* _ILCopyaPidl(const LPCITEMIDLIST * apidlsrc, UINT cidl)
2310 LPITEMIDLIST *apidldest;
2312 apidldest = SHAlloc(cidl * sizeof(LPITEMIDLIST));
2316 for (i = 0; i < cidl; i++)
2317 apidldest[i] = ILClone(apidlsrc[i]);
2322 /*************************************************************************
2323 * _ILCopyCidaToaPidl
2325 * creates aPidl from CIDA
2327 LPITEMIDLIST* _ILCopyCidaToaPidl(LPITEMIDLIST* pidl, const CIDA * cida)
2332 dst = SHAlloc(cida->cidl * sizeof(LPITEMIDLIST));
2337 *pidl = ILClone((LPCITEMIDLIST)(&((const BYTE*)cida)[cida->aoffset[0]]));
2339 for (i = 0; i < cida->cidl; i++)
2340 dst[i] = ILClone((LPCITEMIDLIST)(&((const BYTE*)cida)[cida->aoffset[i + 1]]));