widl: Always write out pointers if the structure is a pointer structure. Pointer...
[wine/multimedia.git] / dlls / shell32 / pidl.c
blobef249273c49e49a98875a4193655034ca8853598
1 /*
2 * pidl Handling
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
20 * NOTES
21 * a pidl == NULL means desktop and is legal
25 #include "config.h"
26 #include "wine/port.h"
28 #include <ctype.h>
29 #include <stdarg.h>
30 #include <stdlib.h>
31 #include <string.h>
33 #define COBJMACROS
34 #define NONAMELESSUNION
35 #define NONAMELESSSTRUCT
37 #include "windef.h"
38 #include "winbase.h"
39 #include "winreg.h"
40 #include "objbase.h"
41 #include "shlguid.h"
42 #include "winerror.h"
43 #include "winnls.h"
44 #include "undocshell.h"
45 #include "shell32_main.h"
46 #include "shlwapi.h"
48 #include "pidl.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
63 * PARAMS
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
72 * RETURNS
73 * True if the display name could be retrieved successfully, False otherwise
75 BOOL WINAPI ILGetDisplayNameExA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPSTR path, DWORD type)
77 BOOL ret = FALSE;
78 WCHAR wPath[MAX_PATH];
80 TRACE("%p %p %p %d\n", psf, pidl, path, type);
82 if (!pidl || !path)
83 return FALSE;
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));
89 return ret;
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;
97 STRRET strret;
98 DWORD flag;
100 TRACE("%p %p %p %d\n", psf, pidl, path, type);
102 if (!pidl || !path)
103 return FALSE;
105 if (!lsf)
107 ret = SHGetDesktopFolder(&lsf);
108 if (FAILED(ret))
109 return FALSE;
112 if (type >= 0 && type <= 2)
114 switch (type)
116 case ILGDN_FORPARSING:
117 flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
118 break;
119 case ILGDN_NORMAL:
120 flag = SHGDN_NORMAL;
121 break;
122 case ILGDN_INFOLDER:
123 flag = SHGDN_INFOLDER;
124 break;
125 default:
126 FIXME("Unknown type parameter = %x\n", type);
127 flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
128 break;
130 if (!*(const WORD*)pidl || type == ILGDN_FORPARSING)
132 ret = IShellFolder_GetDisplayNameOf(lsf, pidl, flag, &strret);
133 if (SUCCEEDED(ret))
135 if(!StrRetToStrNW(path, MAX_PATH, &strret, pidl))
136 ret = E_FAIL;
139 else
141 ret = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psfParent, &pidllast);
142 if (SUCCEEDED(ret))
144 ret = IShellFolder_GetDisplayNameOf(psfParent, pidllast, flag, &strret);
145 if (SUCCEEDED(ret))
147 if(!StrRetToStrNW(path, MAX_PATH, &strret, pidllast))
148 ret = E_FAIL;
150 IShellFolder_Release(psfParent);
155 TRACE("%p %p %s\n", psf, pidl, debugstr_w(path));
157 if (!psf)
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]
186 * NOTES
187 * observed: pidl=Desktop return=pidl
189 LPITEMIDLIST WINAPI ILFindLastID(LPCITEMIDLIST pidl)
191 LPCITEMIDLIST pidlLast = pidl;
193 TRACE("(pidl=%p)\n",pidl);
195 if (!pidl)
196 return NULL;
198 while (pidl->mkid.cb)
200 pidlLast = pidl;
201 pidl = ILGetNext(pidl);
203 return (LPITEMIDLIST)pidlLast;
206 /*************************************************************************
207 * ILRemoveLastID [SHELL32.17]
209 * NOTES
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)
217 return 0;
218 ILFindLastID(pidl)->mkid.cb = 0;
219 return 1;
222 /*************************************************************************
223 * ILClone [SHELL32.18]
225 * NOTES
226 * duplicate an idlist
228 LPITEMIDLIST WINAPI ILClone (LPCITEMIDLIST pidl)
230 DWORD len;
231 LPITEMIDLIST newpidl;
233 if (!pidl)
234 return NULL;
236 len = ILGetSize(pidl);
237 newpidl = (LPITEMIDLIST)SHAlloc(len);
238 if (newpidl)
239 memcpy(newpidl,pidl,len);
241 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
242 pdump(pidl);
244 return newpidl;
247 /*************************************************************************
248 * ILCloneFirst [SHELL32.19]
250 * NOTES
251 * duplicates the first idlist of a complex pidl
253 LPITEMIDLIST WINAPI ILCloneFirst(LPCITEMIDLIST pidl)
255 DWORD len;
256 LPITEMIDLIST pidlNew = NULL;
258 TRACE("pidl=%p\n", pidl);
259 pdump(pidl);
261 if (pidl)
263 len = pidl->mkid.cb;
264 pidlNew = (LPITEMIDLIST) SHAlloc (len+2);
265 if (pidlNew)
267 memcpy(pidlNew,pidl,len+2); /* 2 -> mind a desktop pidl */
269 if (len)
270 ILGetNext(pidlNew)->mkid.cb = 0x00;
273 TRACE("-- newpidl=%p\n",pidlNew);
275 return pidlNew;
278 /*************************************************************************
279 * ILLoadFromStream (SHELL32.26)
281 * NOTES
282 * the first two bytes are the len, the pidl is following then
284 HRESULT WINAPI ILLoadFromStream (IStream * pStream, LPITEMIDLIST * ppPidl)
286 WORD wLen = 0;
287 DWORD dwBytesRead;
288 HRESULT ret = E_FAIL;
291 TRACE_(shell)("%p %p\n", pStream , ppPidl);
293 SHFree(*ppPidl);
294 *ppPidl = NULL;
296 IStream_AddRef (pStream);
298 if (SUCCEEDED(IStream_Read(pStream, (LPVOID)&wLen, 2, &dwBytesRead)))
300 TRACE("PIDL length is %d\n", wLen);
301 if (wLen != 0)
303 *ppPidl = SHAlloc (wLen);
304 if (SUCCEEDED(IStream_Read(pStream, *ppPidl , wLen, &dwBytesRead)))
306 TRACE("Stream read OK\n");
307 ret = S_OK;
309 else
311 WARN("reading pidl failed\n");
312 SHFree(*ppPidl);
313 *ppPidl = NULL;
316 else
318 *ppPidl = NULL;
319 ret = S_OK;
323 /* we are not yet fully compatible */
324 if (*ppPidl && !pcheck(*ppPidl))
326 WARN("Check failed\n");
327 SHFree(*ppPidl);
328 *ppPidl = NULL;
331 IStream_Release (pStream);
332 TRACE("done\n");
333 return ret;
336 /*************************************************************************
337 * ILSaveToStream (SHELL32.27)
339 * NOTES
340 * the first two bytes are the len, the pidl is following then
342 HRESULT WINAPI ILSaveToStream (IStream * pStream, LPCITEMIDLIST pPidl)
344 LPCITEMIDLIST pidl;
345 WORD wLen = 0;
346 HRESULT ret = E_FAIL;
348 TRACE_(shell)("%p %p\n", pStream, pPidl);
350 IStream_AddRef (pStream);
352 pidl = pPidl;
353 while (pidl->mkid.cb)
355 wLen += sizeof(WORD) + pidl->mkid.cb;
356 pidl = ILGetNext(pidl);
359 if (SUCCEEDED(IStream_Write(pStream, (LPVOID)&wLen, 2, NULL)))
361 if (SUCCEEDED(IStream_Write(pStream, pPidl, wLen, NULL)))
362 ret = S_OK;
364 IStream_Release (pStream);
366 return ret;
369 /*************************************************************************
370 * SHILCreateFromPath [SHELL32.28]
372 * Create an ItemIDList from a path
374 * PARAMS
375 * path [I]
376 * ppidl [O]
377 * attributes [I/O] requested attributes on call and actual attributes when
378 * the function returns
380 * RETURNS
381 * NO_ERROR if successful, or an OLE errer code otherwise
383 * NOTES
384 * Wrapper for IShellFolder_ParseDisplayName().
386 HRESULT WINAPI SHILCreateFromPathA(LPCSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
388 WCHAR lpszDisplayName[MAX_PATH];
390 TRACE_(shell)("%s %p 0x%08x\n", path, ppidl, attributes ? *attributes : 0);
392 if (!MultiByteToWideChar(CP_ACP, 0, path, -1, lpszDisplayName, MAX_PATH))
393 lpszDisplayName[MAX_PATH-1] = 0;
395 return SHILCreateFromPathW(lpszDisplayName, ppidl, attributes);
398 HRESULT WINAPI SHILCreateFromPathW(LPCWSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
400 LPSHELLFOLDER sf;
401 DWORD pchEaten;
402 HRESULT ret = E_FAIL;
404 TRACE_(shell)("%s %p 0x%08x\n", debugstr_w(path), ppidl, attributes ? *attributes : 0);
406 if (SUCCEEDED (SHGetDesktopFolder(&sf)))
408 ret = IShellFolder_ParseDisplayName(sf, 0, NULL, (LPWSTR)path, &pchEaten, ppidl, attributes);
409 IShellFolder_Release(sf);
411 return ret;
414 HRESULT WINAPI SHILCreateFromPathAW (LPCVOID path, LPITEMIDLIST * ppidl, DWORD * attributes)
416 if ( SHELL_OsIsUnicode())
417 return SHILCreateFromPathW (path, ppidl, attributes);
418 return SHILCreateFromPathA (path, ppidl, attributes);
421 /*************************************************************************
422 * SHCloneSpecialIDList [SHELL32.89]
424 * Create an ItemIDList to one of the special folders.
426 * PARAMS
427 * hwndOwner [in]
428 * nFolder [in] CSIDL_xxxxx
429 * fCreate [in] Create folder if it does not exist
431 * RETURNS
432 * Success: The newly created pidl
433 * Failure: NULL, if inputs are invalid.
435 * NOTES
436 * exported by ordinal.
437 * Caller is responsible for deallocating the returned ItemIDList with the
438 * shells IMalloc interface, aka ILFree.
440 LPITEMIDLIST WINAPI SHCloneSpecialIDList(HWND hwndOwner, DWORD nFolder, BOOL fCreate)
442 LPITEMIDLIST ppidl;
443 TRACE_(shell)("(hwnd=%p,csidl=0x%x,%s).\n", hwndOwner, nFolder, fCreate ? "T" : "F");
445 if (fCreate)
446 nFolder |= CSIDL_FLAG_CREATE;
448 SHGetSpecialFolderLocation(hwndOwner, nFolder, &ppidl);
449 return ppidl;
452 /*************************************************************************
453 * ILGlobalClone [SHELL32.20]
455 * Clones an ItemIDList using Alloc.
457 * PARAMS
458 * pidl [I] ItemIDList to clone
460 * RETURNS
461 * Newly allocated ItemIDList.
463 * NOTES
464 * exported by ordinal.
466 LPITEMIDLIST WINAPI ILGlobalClone(LPCITEMIDLIST pidl)
468 DWORD len;
469 LPITEMIDLIST newpidl;
471 if (!pidl)
472 return NULL;
474 len = ILGetSize(pidl);
475 newpidl = (LPITEMIDLIST)Alloc(len);
476 if (newpidl)
477 memcpy(newpidl,pidl,len);
479 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
480 pdump(pidl);
482 return newpidl;
485 /*************************************************************************
486 * ILIsEqual [SHELL32.21]
489 BOOL WINAPI ILIsEqual(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
491 char szData1[MAX_PATH];
492 char szData2[MAX_PATH];
494 LPCITEMIDLIST pidltemp1 = pidl1;
495 LPCITEMIDLIST pidltemp2 = pidl2;
497 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
500 * Explorer reads from registry directly (StreamMRU),
501 * so we can only check here
503 if (!pcheck(pidl1) || !pcheck (pidl2))
504 return FALSE;
506 pdump (pidl1);
507 pdump (pidl2);
509 if (!pidl1 || !pidl2)
510 return FALSE;
512 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
514 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
515 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
517 if (strcasecmp( szData1, szData2 ))
518 return FALSE;
520 pidltemp1 = ILGetNext(pidltemp1);
521 pidltemp2 = ILGetNext(pidltemp2);
524 if (!pidltemp1->mkid.cb && !pidltemp2->mkid.cb)
525 return TRUE;
527 return FALSE;
530 /*************************************************************************
531 * ILIsParent [SHELL32.23]
533 * Verifies that pidlParent is indeed the (immediate) parent of pidlChild.
535 * PARAMS
536 * pidlParent [I]
537 * pidlChild [I]
538 * bImmediate [I] only return true if the parent is the direct parent
539 * of the child
541 * RETURNS
542 * True if the parent ItemIDlist is a complete part of the child ItemIdList,
543 * False otherwise.
545 * NOTES
546 * parent = a/b, child = a/b/c -> true, c is in folder a/b
547 * child = a/b/c/d -> false if bImmediate is true, d is not in folder a/b
548 * child = a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
550 BOOL WINAPI ILIsParent(LPCITEMIDLIST pidlParent, LPCITEMIDLIST pidlChild, BOOL bImmediate)
552 char szData1[MAX_PATH];
553 char szData2[MAX_PATH];
554 LPCITEMIDLIST pParent = pidlParent;
555 LPCITEMIDLIST pChild = pidlChild;
557 TRACE("%p %p %x\n", pidlParent, pidlChild, bImmediate);
559 if (!pParent || !pChild)
560 return FALSE;
562 while (pParent->mkid.cb && pChild->mkid.cb)
564 _ILSimpleGetText(pParent, szData1, MAX_PATH);
565 _ILSimpleGetText(pChild, szData2, MAX_PATH);
567 if (strcasecmp( szData1, szData2 ))
568 return FALSE;
570 pParent = ILGetNext(pParent);
571 pChild = ILGetNext(pChild);
574 /* child shorter or has equal length to parent */
575 if (pParent->mkid.cb || !pChild->mkid.cb)
576 return FALSE;
578 /* not immediate descent */
579 if ( ILGetNext(pChild)->mkid.cb && bImmediate)
580 return FALSE;
582 return TRUE;
585 /*************************************************************************
586 * ILFindChild [SHELL32.24]
588 * Compares elements from pidl1 and pidl2.
590 * PARAMS
591 * pidl1 [I]
592 * pidl2 [I]
594 * RETURNS
595 * pidl1 is desktop pidl2
596 * pidl1 shorter pidl2 pointer to first different element of pidl2
597 * if there was at least one equal element
598 * pidl2 shorter pidl1 0
599 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
601 * NOTES
602 * exported by ordinal.
604 LPITEMIDLIST WINAPI ILFindChild(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
606 char szData1[MAX_PATH];
607 char szData2[MAX_PATH];
609 LPCITEMIDLIST pidltemp1 = pidl1;
610 LPCITEMIDLIST pidltemp2 = pidl2;
611 LPCITEMIDLIST ret=NULL;
613 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
615 /* explorer reads from registry directly (StreamMRU),
616 so we can only check here */
617 if ((!pcheck (pidl1)) || (!pcheck (pidl2)))
618 return FALSE;
620 pdump (pidl1);
621 pdump (pidl2);
623 if (_ILIsDesktop(pidl1))
625 ret = pidl2;
627 else
629 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
631 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
632 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
634 if (strcasecmp(szData1,szData2))
635 break;
637 pidltemp1 = ILGetNext(pidltemp1);
638 pidltemp2 = ILGetNext(pidltemp2);
639 ret = pidltemp2;
642 if (pidltemp1->mkid.cb)
643 ret = NULL; /* elements of pidl1 left*/
645 TRACE_(shell)("--- %p\n", ret);
646 return (LPITEMIDLIST)ret; /* pidl 1 is shorter */
649 /*************************************************************************
650 * ILCombine [SHELL32.25]
652 * Concatenates two complex ItemIDLists.
654 * PARAMS
655 * pidl1 [I] first complex ItemIDLists
656 * pidl2 [I] complex ItemIDLists to append
658 * RETURNS
659 * if both pidl's == NULL NULL
660 * if pidl1 == NULL cloned pidl2
661 * if pidl2 == NULL cloned pidl1
662 * otherwise new pidl with pidl2 appended to pidl1
664 * NOTES
665 * exported by ordinal.
666 * Does not destroy the passed in ItemIDLists!
668 LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
670 DWORD len1,len2;
671 LPITEMIDLIST pidlNew;
673 TRACE("pidl=%p pidl=%p\n",pidl1,pidl2);
675 if (!pidl1 && !pidl2) return NULL;
677 pdump (pidl1);
678 pdump (pidl2);
680 if (!pidl1)
682 pidlNew = ILClone(pidl2);
683 return pidlNew;
686 if (!pidl2)
688 pidlNew = ILClone(pidl1);
689 return pidlNew;
692 len1 = ILGetSize(pidl1)-2;
693 len2 = ILGetSize(pidl2);
694 pidlNew = SHAlloc(len1+len2);
696 if (pidlNew)
698 memcpy(pidlNew,pidl1,len1);
699 memcpy(((BYTE *)pidlNew)+len1,pidl2,len2);
702 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
703 return pidlNew;
706 /*************************************************************************
707 * SHGetRealIDL [SHELL32.98]
709 * NOTES
711 HRESULT WINAPI SHGetRealIDL(LPSHELLFOLDER lpsf, LPCITEMIDLIST pidlSimple, LPITEMIDLIST *pidlReal)
713 IDataObject* pDataObj;
714 HRESULT hr;
716 hr = IShellFolder_GetUIObjectOf(lpsf, 0, 1, &pidlSimple,
717 &IID_IDataObject, 0, (LPVOID*)&pDataObj);
718 if (SUCCEEDED(hr))
720 STGMEDIUM medium;
721 FORMATETC fmt;
723 fmt.cfFormat = RegisterClipboardFormatA(CFSTR_SHELLIDLIST);
724 fmt.ptd = NULL;
725 fmt.dwAspect = DVASPECT_CONTENT;
726 fmt.lindex = -1;
727 fmt.tymed = TYMED_HGLOBAL;
729 hr = IDataObject_GetData(pDataObj, &fmt, &medium);
731 IDataObject_Release(pDataObj);
733 if (SUCCEEDED(hr))
735 /*assert(pida->cidl==1);*/
736 LPIDA pida = (LPIDA)GlobalLock(medium.u.hGlobal);
738 LPCITEMIDLIST pidl_folder = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[0]);
739 LPCITEMIDLIST pidl_child = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[1]);
741 *pidlReal = ILCombine(pidl_folder, pidl_child);
743 if (!*pidlReal)
744 hr = E_OUTOFMEMORY;
746 GlobalUnlock(medium.u.hGlobal);
747 GlobalFree(medium.u.hGlobal);
751 return hr;
754 /*************************************************************************
755 * SHLogILFromFSIL [SHELL32.95]
757 * NOTES
758 * pild = CSIDL_DESKTOP ret = 0
759 * pild = CSIDL_DRIVES ret = 0
761 LPITEMIDLIST WINAPI SHLogILFromFSIL(LPITEMIDLIST pidl)
763 FIXME("(pidl=%p)\n",pidl);
765 pdump(pidl);
767 return 0;
770 /*************************************************************************
771 * ILGetSize [SHELL32.152]
773 * Gets the byte size of an ItemIDList including zero terminator
775 * PARAMS
776 * pidl [I] ItemIDList
778 * RETURNS
779 * size of pidl in bytes
781 * NOTES
782 * exported by ordinal
784 UINT WINAPI ILGetSize(LPCITEMIDLIST pidl)
786 LPCSHITEMID si = &(pidl->mkid);
787 UINT len=0;
789 if (pidl)
791 while (si->cb)
793 len += si->cb;
794 si = (LPCSHITEMID)(((const BYTE*)si)+si->cb);
796 len += 2;
798 TRACE("pidl=%p size=%u\n",pidl, len);
799 return len;
802 /*************************************************************************
803 * ILGetNext [SHELL32.153]
805 * Gets the next ItemID of an ItemIDList
807 * PARAMS
808 * pidl [I] ItemIDList
810 * RETURNS
811 * null -> null
812 * desktop -> null
813 * simple pidl -> pointer to 0x0000 element
815 * NOTES
816 * exported by ordinal.
818 LPITEMIDLIST WINAPI ILGetNext(LPCITEMIDLIST pidl)
820 WORD len;
822 TRACE("%p\n", pidl);
824 if (pidl)
826 len = pidl->mkid.cb;
827 if (len)
829 pidl = (LPCITEMIDLIST) (((const BYTE*)pidl)+len);
830 TRACE("-- %p\n", pidl);
831 return (LPITEMIDLIST)pidl;
834 return NULL;
837 /*************************************************************************
838 * ILAppend [SHELL32.154]
840 * Adds the single ItemID item to the ItemIDList indicated by pidl.
841 * If bEnd is FALSE, inserts the item in the front of the list,
842 * otherwise it adds the item to the end. (???)
844 * PARAMS
845 * pidl [I] ItemIDList to extend
846 * item [I] ItemID to prepend/append
847 * bEnd [I] Indicates if the item should be appended
849 * NOTES
850 * Destroys the passed in idlist! (???)
852 LPITEMIDLIST WINAPI ILAppend(LPITEMIDLIST pidl, LPCITEMIDLIST item, BOOL bEnd)
854 LPITEMIDLIST idlRet;
856 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl,item,bEnd);
858 pdump (pidl);
859 pdump (item);
861 if (_ILIsDesktop(pidl))
863 idlRet = ILClone(item);
864 SHFree (pidl);
865 return idlRet;
868 if (bEnd)
869 idlRet = ILCombine(pidl, item);
870 else
871 idlRet = ILCombine(item, pidl);
873 SHFree(pidl);
874 return idlRet;
877 /*************************************************************************
878 * ILFree [SHELL32.155]
880 * Frees memory (if not NULL) allocated by SHMalloc allocator
882 * PARAMS
883 * pidl [I]
885 * RETURNS
886 * Nothing
888 * NOTES
889 * exported by ordinal
891 void WINAPI ILFree(LPITEMIDLIST pidl)
893 TRACE("(pidl=%p)\n",pidl);
894 SHFree(pidl);
897 /*************************************************************************
898 * ILGlobalFree [SHELL32.156]
900 * Frees memory (if not NULL) allocated by Alloc allocator
902 * PARAMS
903 * pidl [I]
905 * RETURNS
906 * Nothing
908 * NOTES
909 * exported by ordinal.
911 void WINAPI ILGlobalFree( LPITEMIDLIST pidl)
913 TRACE("%p\n", pidl);
915 Free(pidl);
918 /*************************************************************************
919 * ILCreateFromPathA [SHELL32.189]
921 * Creates a complex ItemIDList from a path and returns it.
923 * PARAMS
924 * path [I]
926 * RETURNS
927 * the newly created complex ItemIDList or NULL if failed
929 * NOTES
930 * exported by ordinal.
932 LPITEMIDLIST WINAPI ILCreateFromPathA (LPCSTR path)
934 LPITEMIDLIST pidlnew = NULL;
936 TRACE_(shell)("%s\n", debugstr_a(path));
938 if (SUCCEEDED(SHILCreateFromPathA(path, &pidlnew, NULL)))
939 return pidlnew;
940 return NULL;
943 /*************************************************************************
944 * ILCreateFromPathW [SHELL32.190]
946 * See ILCreateFromPathA.
948 LPITEMIDLIST WINAPI ILCreateFromPathW (LPCWSTR path)
950 LPITEMIDLIST pidlnew = NULL;
952 TRACE_(shell)("%s\n", debugstr_w(path));
954 if (SUCCEEDED(SHILCreateFromPathW(path, &pidlnew, NULL)))
955 return pidlnew;
956 return NULL;
959 /*************************************************************************
960 * ILCreateFromPath [SHELL32.157]
962 LPITEMIDLIST WINAPI ILCreateFromPathAW (LPCVOID path)
964 if ( SHELL_OsIsUnicode())
965 return ILCreateFromPathW (path);
966 return ILCreateFromPathA (path);
969 /*************************************************************************
970 * _ILParsePathW [internal]
972 * Creates an ItemIDList from a path and returns it.
974 * PARAMS
975 * path [I] path to parse and convert into an ItemIDList
976 * lpFindFile [I] pointer to buffer to initialize the FileSystem
977 * Bind Data object with
978 * bBindCtx [I] indicates to create a BindContext and assign a
979 * FileSystem Bind Data object
980 * ppidl [O] the newly create ItemIDList
981 * prgfInOut [I/O] requested attributes on input and actual
982 * attributes on return
984 * RETURNS
985 * NO_ERROR on success or an OLE error code
987 * NOTES
988 * If either lpFindFile is non-NULL or bBindCtx is TRUE, this function
989 * creates a BindContext object and assigns a FileSystem Bind Data object
990 * to it, passing the BindContext to IShellFolder_ParseDisplayName. Each
991 * IShellFolder uses that FileSystem Bind Data object of the BindContext
992 * to pass data about the current path element to the next object. This
993 * is used to avoid having to verify the current path element on disk, so
994 * that creating an ItemIDList from a nonexistent path still can work.
996 static HRESULT WINAPI _ILParsePathW(LPCWSTR path, LPWIN32_FIND_DATAW lpFindFile,
997 BOOL bBindCtx, LPITEMIDLIST *ppidl, LPDWORD prgfInOut)
999 LPSHELLFOLDER pSF = NULL;
1000 LPBC pBC = NULL;
1001 HRESULT ret;
1003 TRACE("%s %p %d (%p)->%p (%p)->0x%x\n", debugstr_w(path), lpFindFile, bBindCtx,
1004 ppidl, ppidl ? *ppidl : NULL,
1005 prgfInOut, prgfInOut ? *prgfInOut : 0);
1007 ret = SHGetDesktopFolder(&pSF);
1008 if (FAILED(ret))
1009 return ret;
1011 if (lpFindFile || bBindCtx)
1012 ret = IFileSystemBindData_Constructor(lpFindFile, &pBC);
1014 if (SUCCEEDED(ret))
1016 ret = IShellFolder_ParseDisplayName(pSF, 0, pBC, (LPOLESTR)path, NULL, ppidl, prgfInOut);
1019 if (pBC)
1021 IBindCtx_Release(pBC);
1022 pBC = NULL;
1025 IShellFolder_Release(pSF);
1027 if (!SUCCEEDED(ret) && ppidl)
1028 *ppidl = NULL;
1030 TRACE("%s %p 0x%x\n", debugstr_w(path), ppidl ? *ppidl : NULL, prgfInOut ? *prgfInOut : 0);
1032 return ret;
1035 /*************************************************************************
1036 * SHSimpleIDListFromPath [SHELL32.162]
1038 * Creates a simple ItemIDList from a path and returns it. This function
1039 * does not fail on nonexistent paths.
1041 * PARAMS
1042 * path [I] path to parse and convert into an ItemIDList
1044 * RETURNS
1045 * the newly created simple ItemIDList
1047 * NOTES
1048 * Simple in the name does not mean a relative ItemIDList but rather a
1049 * fully qualified list, where only the file name is filled in and the
1050 * directory flag for those ItemID elements this is known about, eg.
1051 * it is not the last element in the ItemIDList or the actual directory
1052 * exists on disk.
1053 * exported by ordinal.
1055 LPITEMIDLIST WINAPI SHSimpleIDListFromPathA(LPCSTR lpszPath)
1057 LPITEMIDLIST pidl = NULL;
1058 LPWSTR wPath = NULL;
1059 int len;
1061 TRACE("%s\n", debugstr_a(lpszPath));
1063 if (lpszPath)
1065 len = MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, NULL, 0);
1066 wPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1067 MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, wPath, len);
1070 _ILParsePathW(wPath, NULL, TRUE, &pidl, NULL);
1072 HeapFree(GetProcessHeap(), 0, wPath);
1073 TRACE("%s %p\n", debugstr_a(lpszPath), pidl);
1074 return pidl;
1077 LPITEMIDLIST WINAPI SHSimpleIDListFromPathW(LPCWSTR lpszPath)
1079 LPITEMIDLIST pidl = NULL;
1081 TRACE("%s\n", debugstr_w(lpszPath));
1083 _ILParsePathW(lpszPath, NULL, TRUE, &pidl, NULL);
1084 TRACE("%s %p\n", debugstr_w(lpszPath), pidl);
1085 return pidl;
1088 LPITEMIDLIST WINAPI SHSimpleIDListFromPathAW(LPCVOID lpszPath)
1090 if ( SHELL_OsIsUnicode())
1091 return SHSimpleIDListFromPathW (lpszPath);
1092 return SHSimpleIDListFromPathA (lpszPath);
1095 /*************************************************************************
1096 * SHGetDataFromIDListA [SHELL32.247]
1098 * NOTES
1099 * the pidl can be a simple one. since we can't get the path out of the pidl
1100 * we have to take all data from the pidl
1102 HRESULT WINAPI SHGetDataFromIDListA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl,
1103 int nFormat, LPVOID dest, int len)
1105 LPSTR filename, shortname;
1106 WIN32_FIND_DATAA * pfd;
1108 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
1110 pdump(pidl);
1111 if (!psf || !dest)
1112 return E_INVALIDARG;
1114 switch (nFormat)
1116 case SHGDFIL_FINDDATA:
1117 pfd = dest;
1119 if (_ILIsDrive(pidl) || _ILIsSpecialFolder(pidl))
1120 return E_INVALIDARG;
1122 if (len < sizeof(WIN32_FIND_DATAA))
1123 return E_INVALIDARG;
1125 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1126 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1127 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1128 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1130 filename = _ILGetTextPointer(pidl);
1131 shortname = _ILGetSTextPointer(pidl);
1133 if (filename)
1134 lstrcpynA(pfd->cFileName, filename, MAX_PATH);
1135 else
1136 pfd->cFileName[0] = '\0';
1138 if (shortname)
1139 lstrcpynA(pfd->cAlternateFileName, shortname, MAX_PATH);
1140 else
1141 pfd->cAlternateFileName[0] = '\0';
1142 return NOERROR;
1144 case SHGDFIL_NETRESOURCE:
1145 case SHGDFIL_DESCRIPTIONID:
1146 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1147 break;
1149 default:
1150 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1153 return E_INVALIDARG;
1156 /*************************************************************************
1157 * SHGetDataFromIDListW [SHELL32.248]
1160 HRESULT WINAPI SHGetDataFromIDListW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl,
1161 int nFormat, LPVOID dest, int len)
1163 LPSTR filename, shortname;
1164 WIN32_FIND_DATAW * pfd = dest;
1166 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
1168 pdump(pidl);
1170 if (!psf || !dest)
1171 return E_INVALIDARG;
1173 switch (nFormat)
1175 case SHGDFIL_FINDDATA:
1176 pfd = dest;
1178 if (_ILIsDrive(pidl))
1179 return E_INVALIDARG;
1181 if (len < sizeof(WIN32_FIND_DATAW))
1182 return E_INVALIDARG;
1184 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1185 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1186 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1187 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1189 filename = _ILGetTextPointer(pidl);
1190 shortname = _ILGetSTextPointer(pidl);
1192 if (!filename)
1193 pfd->cFileName[0] = '\0';
1194 else if (!MultiByteToWideChar(CP_ACP, 0, filename, -1, pfd->cFileName, MAX_PATH))
1195 pfd->cFileName[MAX_PATH-1] = 0;
1197 if (!shortname)
1198 pfd->cAlternateFileName[0] = '\0';
1199 else if (!MultiByteToWideChar(CP_ACP, 0, shortname, -1, pfd->cAlternateFileName, 14))
1200 pfd->cAlternateFileName[13] = 0;
1201 return NOERROR;
1203 case SHGDFIL_NETRESOURCE:
1204 case SHGDFIL_DESCRIPTIONID:
1205 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1206 break;
1208 default:
1209 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1212 return E_INVALIDARG;
1215 /*************************************************************************
1216 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
1218 * PARAMETERS
1219 * pidl, [IN] pidl
1220 * pszPath [OUT] path
1222 * RETURNS
1223 * path from a passed PIDL.
1225 * NOTES
1226 * NULL returns FALSE
1227 * desktop pidl gives path to desktop directory back
1228 * special pidls returning FALSE
1230 BOOL WINAPI SHGetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath)
1232 WCHAR wszPath[MAX_PATH];
1233 BOOL bSuccess;
1235 bSuccess = SHGetPathFromIDListW(pidl, wszPath);
1236 WideCharToMultiByte(CP_ACP, 0, wszPath, -1, pszPath, MAX_PATH, NULL, NULL);
1238 return bSuccess;
1241 /*************************************************************************
1242 * SHGetPathFromIDListW [SHELL32.@]
1244 * See SHGetPathFromIDListA.
1246 BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
1248 HRESULT hr;
1249 LPCITEMIDLIST pidlLast;
1250 LPSHELLFOLDER psfFolder;
1251 DWORD dwAttributes;
1252 STRRET strret;
1254 TRACE_(shell)("(pidl=%p,%p)\n", pidl, pszPath);
1255 pdump(pidl);
1257 *pszPath = '\0';
1258 if (!pidl)
1259 return FALSE;
1261 hr = SHBindToParent(pidl, &IID_IShellFolder, (VOID**)&psfFolder, &pidlLast);
1262 if (FAILED(hr)) return FALSE;
1264 dwAttributes = SFGAO_FILESYSTEM;
1265 hr = IShellFolder_GetAttributesOf(psfFolder, 1, &pidlLast, &dwAttributes);
1266 if (FAILED(hr) || !(dwAttributes & SFGAO_FILESYSTEM)) {
1267 IShellFolder_Release(psfFolder);
1268 return FALSE;
1271 hr = IShellFolder_GetDisplayNameOf(psfFolder, pidlLast, SHGDN_FORPARSING, &strret);
1272 IShellFolder_Release(psfFolder);
1273 if (FAILED(hr)) return FALSE;
1275 hr = StrRetToBufW(&strret, pidlLast, pszPath, MAX_PATH);
1277 TRACE_(shell)("-- %s, 0x%08x\n",debugstr_w(pszPath), hr);
1278 return SUCCEEDED(hr);
1281 /*************************************************************************
1282 * SHBindToParent [shell version 5.0]
1284 HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
1286 IShellFolder * psfDesktop;
1287 HRESULT hr=E_FAIL;
1289 TRACE_(shell)("pidl=%p\n", pidl);
1290 pdump(pidl);
1292 if (!pidl || !ppv)
1293 return E_INVALIDARG;
1295 *ppv = NULL;
1296 if (ppidlLast)
1297 *ppidlLast = NULL;
1299 hr = SHGetDesktopFolder(&psfDesktop);
1300 if (FAILED(hr))
1301 return hr;
1303 if (_ILIsPidlSimple(pidl))
1305 /* we are on desktop level */
1306 hr = IShellFolder_QueryInterface(psfDesktop, riid, ppv);
1308 else
1310 LPITEMIDLIST pidlParent = ILClone(pidl);
1311 ILRemoveLastID(pidlParent);
1312 hr = IShellFolder_BindToObject(psfDesktop, pidlParent, NULL, riid, ppv);
1313 SHFree (pidlParent);
1316 IShellFolder_Release(psfDesktop);
1318 if (SUCCEEDED(hr) && ppidlLast)
1319 *ppidlLast = ILFindLastID(pidl);
1321 TRACE_(shell)("-- psf=%p pidl=%p ret=0x%08x\n", *ppv, (ppidlLast)?*ppidlLast:NULL, hr);
1322 return hr;
1325 /**************************************************************************
1327 * internal functions
1329 * ### 1. section creating pidls ###
1331 *************************************************************************
1333 LPITEMIDLIST _ILAlloc(PIDLTYPE type, unsigned int size)
1335 LPITEMIDLIST pidlOut = NULL;
1337 pidlOut = SHAlloc(size + 5);
1338 if(pidlOut)
1340 LPPIDLDATA pData;
1341 LPITEMIDLIST pidlNext;
1343 ZeroMemory(pidlOut, size + 5);
1344 pidlOut->mkid.cb = size + 3;
1346 pData = _ILGetDataPointer(pidlOut);
1347 if (pData)
1348 pData->type = type;
1350 pidlNext = ILGetNext(pidlOut);
1351 if (pidlNext)
1352 pidlNext->mkid.cb = 0x00;
1353 TRACE("-- (pidl=%p, size=%u)\n", pidlOut, size);
1356 return pidlOut;
1359 LPITEMIDLIST _ILCreateDesktop(void)
1361 LPITEMIDLIST ret;
1363 TRACE("()\n");
1364 ret = SHAlloc(2);
1365 if (ret)
1366 ret->mkid.cb = 0;
1367 return ret;
1370 LPITEMIDLIST _ILCreateMyComputer(void)
1372 TRACE("()\n");
1373 return _ILCreateGuid(PT_GUID, &CLSID_MyComputer);
1376 LPITEMIDLIST _ILCreateMyDocuments(void)
1378 TRACE("()\n");
1379 return _ILCreateGuid(PT_GUID, &CLSID_MyDocuments);
1382 LPITEMIDLIST _ILCreateIExplore(void)
1384 TRACE("()\n");
1385 return _ILCreateGuid(PT_GUID, &CLSID_Internet);
1388 LPITEMIDLIST _ILCreateControlPanel(void)
1390 LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL;
1392 TRACE("()\n");
1393 if (parent)
1395 LPITEMIDLIST cpl = _ILCreateGuid(PT_SHELLEXT, &CLSID_ControlPanel);
1397 if (cpl)
1399 ret = ILCombine(parent, cpl);
1400 SHFree(cpl);
1402 SHFree(parent);
1404 return ret;
1407 LPITEMIDLIST _ILCreatePrinters(void)
1409 LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL;
1411 TRACE("()\n");
1412 if (parent)
1414 LPITEMIDLIST printers = _ILCreateGuid(PT_YAGUID, &CLSID_Printers);
1416 if (printers)
1418 ret = ILCombine(parent, printers);
1419 SHFree(printers);
1421 SHFree(parent);
1423 return ret;
1426 LPITEMIDLIST _ILCreateNetwork(void)
1428 TRACE("()\n");
1429 return _ILCreateGuid(PT_GUID, &CLSID_NetworkPlaces);
1432 LPITEMIDLIST _ILCreateBitBucket(void)
1434 TRACE("()\n");
1435 return _ILCreateGuid(PT_GUID, &CLSID_RecycleBin);
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));
1445 if (pidlOut)
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)));
1454 else
1456 WARN("%d: invalid type for GUID\n", type);
1457 pidlOut = NULL;
1459 return pidlOut;
1462 LPITEMIDLIST _ILCreateGuidFromStrA(LPCSTR szGUID)
1464 IID iid;
1466 if (!SUCCEEDED(SHCLSIDFromStringA(szGUID, &iid)))
1468 ERR("%s is not a GUID\n", szGUID);
1469 return NULL;
1471 return _ILCreateGuid(PT_GUID, &iid);
1474 LPITEMIDLIST _ILCreateGuidFromStrW(LPCWSTR szGUID)
1476 IID iid;
1478 if (!SUCCEEDED(SHCLSIDFromStringW(szGUID, &iid)))
1480 ERR("%s is not a GUID\n", debugstr_w(szGUID));
1481 return NULL;
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;
1490 LPITEMIDLIST pidl;
1491 PIDLTYPE type;
1493 if (!wfd)
1494 return NULL;
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);
1501 alen = len + len1;
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));
1508 if (pidl)
1510 LPPIDLDATA pData = _ILGetDataPointer(pidl);
1511 FileStruct *fs = &pData->u.file;
1512 FileStructW *fsw;
1513 WORD *pOffsetW;
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));
1530 return pidl;
1534 HRESULT _ILCreateFromPathW(LPCWSTR szPath, LPITEMIDLIST* ppidl)
1536 HANDLE hFile;
1537 WIN32_FIND_DATAW stffile;
1539 if (!ppidl)
1540 return E_INVALIDARG;
1542 hFile = FindFirstFileW(szPath, &stffile);
1543 if (hFile == INVALID_HANDLE_VALUE)
1544 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
1546 FindClose(hFile);
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));
1560 if (pidlOut)
1562 LPSTR pszDest;
1564 pszDest = _ILGetTextPointer(pidlOut);
1565 if (pszDest)
1567 strcpy(pszDest, "x:\\");
1568 pszDest[0]=toupperW(lpszNew[0]);
1569 TRACE("-- create Drive: %s\n", debugstr_a(pszDest));
1572 return pidlOut;
1575 /**************************************************************************
1576 * _ILGetDrive()
1578 * Gets the text for the drive eg. 'c:\'
1580 * RETURNS
1581 * strlen (lpszText)
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);
1593 return 0;
1596 /**************************************************************************
1598 * ### 2. section testing pidls ###
1600 **************************************************************************
1601 * _ILIsUnicode()
1602 * _ILIsDesktop()
1603 * _ILIsMyComputer()
1604 * _ILIsSpecialFolder()
1605 * _ILIsDrive()
1606 * _ILIsFolder()
1607 * _ILIsValue()
1608 * _ILIsPidlSimple()
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);
1632 if (iid)
1633 return IsEqualIID(iid, &CLSID_MyComputer);
1634 return FALSE;
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 /**************************************************************************
1688 * _ILIsPidlSimple
1690 BOOL _ILIsPidlSimple(LPCITEMIDLIST pidl)
1692 BOOL ret = TRUE;
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)
1700 ret = FALSE;
1703 TRACE("%s\n", ret ? "Yes" : "No");
1704 return ret;
1707 /**************************************************************************
1709 * ### 3. section getting values from pidls ###
1712 /**************************************************************************
1713 * _ILSimpleGetText
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)
1721 DWORD dwReturn=0;
1722 LPSTR szSrc;
1723 LPWSTR szSrcW;
1724 GUID const * riid;
1725 char szTemp[MAX_PATH];
1727 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1729 if (!pidl)
1730 return 0;
1732 if (szOut)
1733 *szOut = 0;
1735 if (_ILIsDesktop(pidl))
1737 /* desktop */
1738 if (HCR_GetClassNameA(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1740 if (szOut)
1741 lstrcpynA(szOut, szTemp, uOutSize);
1743 dwReturn = strlen (szTemp);
1746 else if (( szSrc = _ILGetTextPointer(pidl) ))
1748 /* filesystem */
1749 if (szOut)
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);
1759 if (szOut)
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) )
1769 if (szOut)
1770 lstrcpynA(szOut, szTemp, uOutSize);
1772 dwReturn = strlen (szTemp);
1775 else
1777 ERR("-- no text\n");
1780 TRACE("-- (%p=%s 0x%08x)\n",szOut,debugstr_a(szOut),dwReturn);
1781 return dwReturn;
1784 /**************************************************************************
1785 * _ILSimpleGetTextW
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)
1793 DWORD dwReturn;
1794 FileStructW *pFileStructW = _ILGetFileStructW(pidl);
1796 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1798 if (pFileStructW) {
1799 lstrcpynW(szOut, pFileStructW->wszName, uOutSize);
1800 dwReturn = lstrlenW(pFileStructW->wszName);
1801 } else {
1802 GUID const * riid;
1803 WCHAR szTemp[MAX_PATH];
1804 LPSTR szSrc;
1805 LPWSTR szSrcW;
1806 dwReturn=0;
1808 if (!pidl)
1809 return 0;
1811 if (szOut)
1812 *szOut = 0;
1814 if (_ILIsDesktop(pidl))
1816 /* desktop */
1817 if (HCR_GetClassNameW(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1819 if (szOut)
1820 lstrcpynW(szOut, szTemp, uOutSize);
1822 dwReturn = lstrlenW (szTemp);
1825 else if (( szSrcW = _ILGetTextPointerW(pidl) ))
1827 /* unicode filesystem */
1828 if (szOut)
1829 lstrcpynW(szOut, szSrcW, uOutSize);
1831 dwReturn = lstrlenW(szSrcW);
1833 else if (( szSrc = _ILGetTextPointer(pidl) ))
1835 /* filesystem */
1836 MultiByteToWideChar(CP_ACP, 0, szSrc, -1, szTemp, MAX_PATH);
1838 if (szOut)
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) )
1848 if (szOut)
1849 lstrcpynW(szOut, szTemp, uOutSize);
1851 dwReturn = lstrlenW (szTemp);
1854 else
1856 ERR("-- no text\n");
1860 TRACE("-- (%p=%s 0x%08x)\n",szOut,debugstr_w(szOut),dwReturn);
1861 return 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);
1875 return NULL;
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);
1888 if (!pdata)
1889 return NULL;
1891 switch (pdata->type)
1893 case PT_GUID:
1894 case PT_SHELLEXT:
1895 case PT_YAGUID:
1896 return NULL;
1898 case PT_DRIVE:
1899 case PT_DRIVE1:
1900 case PT_DRIVE2:
1901 case PT_DRIVE3:
1902 /*return (LPSTR)&(pdata->u.drive.szDriveName);*/
1903 return NULL;
1905 case PT_FOLDER:
1906 case PT_FOLDER1:
1907 case PT_VALUE:
1908 case PT_IESPECIAL1:
1909 case PT_IESPECIAL2:
1910 /*return (LPSTR)&(pdata->u.file.szNames);*/
1911 return NULL;
1913 case PT_WORKGRP:
1914 case PT_COMP:
1915 case PT_NETWORK:
1916 case PT_NETPROVIDER:
1917 case PT_SHARE:
1918 /*return (LPSTR)&(pdata->u.network.szNames);*/
1919 return NULL;
1921 case PT_VALUEW:
1922 return (LPWSTR)&(pdata->u.file.szNames);
1924 return NULL;
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);
1938 if (!pdata)
1939 return NULL;
1941 switch (pdata->type)
1943 case PT_GUID:
1944 case PT_SHELLEXT:
1945 case PT_YAGUID:
1946 return NULL;
1948 case PT_DRIVE:
1949 case PT_DRIVE1:
1950 case PT_DRIVE2:
1951 case PT_DRIVE3:
1952 return (LPSTR)&(pdata->u.drive.szDriveName);
1954 case PT_FOLDER:
1955 case PT_FOLDER1:
1956 case PT_VALUE:
1957 case PT_IESPECIAL1:
1958 case PT_IESPECIAL2:
1959 return (LPSTR)&(pdata->u.file.szNames);
1961 case PT_WORKGRP:
1962 case PT_COMP:
1963 case PT_NETWORK:
1964 case PT_NETPROVIDER:
1965 case PT_SHARE:
1966 return (LPSTR)&(pdata->u.network.szNames);
1968 return NULL;
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);
1981 if (!pdata)
1982 return NULL;
1984 switch (pdata->type)
1986 case PT_FOLDER:
1987 case PT_VALUE:
1988 case PT_IESPECIAL1:
1989 case PT_IESPECIAL2:
1990 return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1);
1992 case PT_WORKGRP:
1993 return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1);
1995 return NULL;
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);
2009 if (!pdata)
2010 return NULL;
2012 TRACE("pdata->type 0x%04x\n", pdata->type);
2013 switch (pdata->type)
2015 case PT_SHELLEXT:
2016 case PT_GUID:
2017 case PT_YAGUID:
2018 return &(pdata->u.guid.guid);
2020 default:
2021 TRACE("Unknown pidl type 0x%04x\n", pdata->type);
2022 break;
2024 return NULL;
2027 /******************************************************************************
2028 * _ILGetFileStructW [Internal]
2030 * Get pointer the a SHITEMID's FileStructW field if present
2032 * PARAMS
2033 * pidl [I] The SHITEMID
2035 * RETURNS
2036 * Success: Pointer to pidl's FileStructW field.
2037 * Failure: NULL
2039 FileStructW* _ILGetFileStructW(LPCITEMIDLIST pidl) {
2040 FileStructW *pFileStructW;
2041 WORD cbOffset;
2043 if (!(_ILIsValue(pidl) || _ILIsFolder(pidl)))
2044 return NULL;
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);
2060 return NULL;
2063 return pFileStructW;
2066 /*************************************************************************
2067 * _ILGetFileDateTime
2069 * Given the ItemIdList, get the FileTime
2071 * PARAMS
2072 * pidl [I] The ItemIDList
2073 * pFt [I] the resulted FILETIME of the file
2075 * RETURNS
2076 * True if Successful
2078 * NOTES
2081 BOOL _ILGetFileDateTime(LPCITEMIDLIST pidl, FILETIME *pFt)
2083 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2085 if (!pdata)
2086 return FALSE;
2088 switch (pdata->type)
2090 case PT_FOLDER:
2091 case PT_VALUE:
2092 DosDateTimeToFileTime(pdata->u.file.uFileDate, pdata->u.file.uFileTime, pFt);
2093 break;
2094 default:
2095 return FALSE;
2097 return TRUE;
2100 BOOL _ILGetFileDate (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2102 FILETIME ft,lft;
2103 SYSTEMTIME time;
2104 BOOL ret;
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);
2112 if (ret)
2114 /* Append space + time without seconds */
2115 pOut[ret-1] = ' ';
2116 GetTimeFormatA(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &time, NULL, &pOut[ret], uOutSize - ret);
2119 else
2121 pOut[0] = '\0';
2122 ret = FALSE;
2124 return ret;
2127 /*************************************************************************
2128 * _ILGetFileSize
2130 * Given the ItemIdList, get the FileSize
2132 * PARAMS
2133 * pidl [I] The ItemIDList
2134 * pOut [I] The buffer to save the result
2135 * uOutsize [I] The size of the buffer
2137 * RETURNS
2138 * The FileSize
2140 * NOTES
2141 * pOut can be null when no string is needed
2144 DWORD _ILGetFileSize (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2146 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2147 DWORD dwSize;
2149 if (!pdata)
2150 return 0;
2152 switch (pdata->type)
2154 case PT_VALUE:
2155 dwSize = pdata->u.file.dwFileSize;
2156 if (pOut)
2157 StrFormatKBSizeA(dwSize, pOut, uOutSize);
2158 return dwSize;
2160 if (pOut)
2161 *pOut = 0x00;
2162 return 0;
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);
2173 if (!pidl)
2174 return FALSE;
2176 pidlTemp = ILFindLastID(pidl);
2178 if (!_ILIsValue(pidlTemp))
2179 return FALSE;
2180 if (!_ILSimpleGetText(pidlTemp, szTemp, MAX_PATH))
2181 return FALSE;
2183 pPoint = PathFindExtensionA(szTemp);
2185 if (!*pPoint)
2186 return FALSE;
2188 pPoint++;
2189 lstrcpynA(pOut, pPoint, uOutSize);
2190 TRACE("%s\n",pOut);
2192 return TRUE;
2195 /*************************************************************************
2196 * _ILGetFileType
2198 * Given the ItemIdList, get the file type description
2200 * PARAMS
2201 * pidl [I] The ItemIDList (simple)
2202 * pOut [I] The buffer to save the result
2203 * uOutsize [I] The size of the buffer
2205 * RETURNS
2206 * nothing
2208 * NOTES
2209 * This function copies as much as possible into the buffer.
2211 void _ILGetFileType(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2213 if(_ILIsValue(pidl))
2215 char sTemp[64];
2217 if(uOutSize > 0)
2218 pOut[0] = 0;
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");
2229 else
2230 lstrcpynA(pOut, "Folder", uOutSize);
2233 /*************************************************************************
2234 * _ILGetFileAttributes
2236 * Given the ItemIdList, get the Attrib string format
2238 * PARAMS
2239 * pidl [I] The ItemIDList
2240 * pOut [I] The buffer to save the result
2241 * uOutsize [I] The size of the Buffer
2243 * RETURNS
2244 * Attributes
2246 * FIXME
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);
2253 WORD wAttrib = 0;
2254 int i;
2256 if (!pData)
2257 return 0;
2259 switch(pData->type)
2261 case PT_FOLDER:
2262 case PT_VALUE:
2263 wAttrib = pData->u.file.uFileAttribs;
2264 break;
2267 if(uOutSize >= 6)
2269 i=0;
2270 if(wAttrib & FILE_ATTRIBUTE_READONLY)
2271 pOut[i++] = 'R';
2272 if(wAttrib & FILE_ATTRIBUTE_HIDDEN)
2273 pOut[i++] = 'H';
2274 if(wAttrib & FILE_ATTRIBUTE_SYSTEM)
2275 pOut[i++] = 'S';
2276 if(wAttrib & FILE_ATTRIBUTE_ARCHIVE)
2277 pOut[i++] = 'A';
2278 if(wAttrib & FILE_ATTRIBUTE_COMPRESSED)
2279 pOut[i++] = 'C';
2280 pOut[i] = 0x00;
2282 return wAttrib;
2285 /*************************************************************************
2286 * ILFreeaPidl
2288 * free a aPidl struct
2290 void _ILFreeaPidl(LPITEMIDLIST * apidl, UINT cidl)
2292 UINT i;
2294 if (apidl)
2296 for (i = 0; i < cidl; i++)
2297 SHFree(apidl[i]);
2298 SHFree(apidl);
2302 /*************************************************************************
2303 * ILCopyaPidl
2305 * copies an aPidl struct
2307 LPITEMIDLIST* _ILCopyaPidl(LPCITEMIDLIST * apidlsrc, UINT cidl)
2309 UINT i;
2310 LPITEMIDLIST *apidldest;
2312 apidldest = SHAlloc(cidl * sizeof(LPITEMIDLIST));
2313 if (!apidlsrc)
2314 return NULL;
2316 for (i = 0; i < cidl; i++)
2317 apidldest[i] = ILClone(apidlsrc[i]);
2319 return apidldest;
2322 /*************************************************************************
2323 * _ILCopyCidaToaPidl
2325 * creates aPidl from CIDA
2327 LPITEMIDLIST* _ILCopyCidaToaPidl(LPITEMIDLIST* pidl, LPIDA cida)
2329 UINT i;
2330 LPITEMIDLIST *dst;
2332 dst = SHAlloc(cida->cidl * sizeof(LPITEMIDLIST));
2333 if (!dst)
2334 return NULL;
2336 if (pidl)
2337 *pidl = ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[0]]));
2339 for (i = 0; i < cida->cidl; i++)
2340 dst[i] = ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[i + 1]]));
2342 return dst;