- move some PIDL function declarations from undocshell.h into public
[wine.git] / dlls / shell32 / pidl.c
blob545e238fe1d71f6df74f28e931c706c9e41ea611
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 NONAMELESSUNION
34 #define NONAMELESSSTRUCT
35 #include "windef.h"
36 #include "winbase.h"
37 #include "winreg.h"
38 #include "objbase.h"
39 #include "shlguid.h"
40 #include "winerror.h"
41 #include "winnls.h"
42 #include "undocshell.h"
43 #include "shell32_main.h"
44 #include "shellapi.h"
45 #include "shlwapi.h"
47 #include "pidl.h"
48 #include "debughlp.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 %ld\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 %ld\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 = %lx\n", type);
127 flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
128 break;
130 if (!*(LPWORD)pidl || type == ILGDN_FORPARSING)
132 ret = IShellFolder_GetDisplayNameOf(lsf, pidl, flag, &strret);
133 if (SUCCEEDED(ret))
135 ret = StrRetToStrNW(path, MAX_PATH, &strret, pidl);
138 else
140 ret = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psfParent, &pidllast);
141 if (SUCCEEDED(ret))
143 ret = IShellFolder_GetDisplayNameOf(psfParent, pidllast, flag, &strret);
144 if (SUCCEEDED(ret))
146 ret = StrRetToStrNW(path, MAX_PATH, &strret, pidllast);
148 IShellFolder_Release(psfParent);
153 TRACE("%p %p %s\n", psf, pidl, debugstr_w(path));
155 if (!psf)
156 IShellFolder_Release(lsf);
157 return SUCCEEDED(ret);
160 BOOL WINAPI ILGetDisplayNameEx(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPVOID path, DWORD type)
162 TRACE_(shell)("%p %p %p %ld\n", psf, pidl, path, type);
163 if (SHELL_OsIsUnicode())
164 return ILGetDisplayNameExW(psf, pidl, path, type);
165 return ILGetDisplayNameExA(psf, pidl, path, type);
168 /*************************************************************************
169 * ILGetDisplayName [SHELL32.15]
171 BOOL WINAPI ILGetDisplayName(LPCITEMIDLIST pidl, LPVOID path)
173 TRACE_(shell)("%p %p\n", pidl, path);
174 if (SHELL_OsIsUnicode())
175 return ILGetDisplayNameExW(NULL, pidl, path, ILGDN_FORPARSING);
176 return ILGetDisplayNameExA(NULL, pidl, path, ILGDN_FORPARSING);
179 /*************************************************************************
180 * ILFindLastID [SHELL32.16]
182 * NOTES
183 * observed: pidl=Desktop return=pidl
185 LPITEMIDLIST WINAPI ILFindLastID(LPCITEMIDLIST pidl)
186 { LPCITEMIDLIST pidlLast = pidl;
188 TRACE("(pidl=%p)\n",pidl);
190 while (pidl->mkid.cb)
192 pidlLast = pidl;
193 pidl = ILGetNext(pidl);
195 return (LPITEMIDLIST)pidlLast;
197 /*************************************************************************
198 * ILRemoveLastID [SHELL32.17]
200 * NOTES
201 * when pidl=Desktop return=FALSE
203 BOOL WINAPI ILRemoveLastID(LPCITEMIDLIST pidl)
205 TRACE_(shell)("pidl=%p\n",pidl);
207 if (!pidl || !pidl->mkid.cb)
208 return 0;
209 ILFindLastID(pidl)->mkid.cb = 0;
210 return 1;
213 /*************************************************************************
214 * ILClone [SHELL32.18]
216 * NOTES
217 * duplicate an idlist
219 LPITEMIDLIST WINAPI ILClone (LPCITEMIDLIST pidl)
220 { DWORD len;
221 LPITEMIDLIST newpidl;
223 if (!pidl)
224 return NULL;
226 len = ILGetSize(pidl);
227 newpidl = (LPITEMIDLIST)SHAlloc(len);
228 if (newpidl)
229 memcpy(newpidl,pidl,len);
231 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
232 pdump(pidl);
234 return newpidl;
236 /*************************************************************************
237 * ILCloneFirst [SHELL32.19]
239 * NOTES
240 * duplicates the first idlist of a complex pidl
242 LPITEMIDLIST WINAPI ILCloneFirst(LPCITEMIDLIST pidl)
243 { DWORD len;
244 LPITEMIDLIST pidlNew = NULL;
246 TRACE("pidl=%p \n",pidl);
247 pdump(pidl);
249 if (pidl)
251 len = pidl->mkid.cb;
252 pidlNew = (LPITEMIDLIST) SHAlloc (len+2);
253 if (pidlNew)
255 memcpy(pidlNew,pidl,len+2); /* 2 -> mind a desktop pidl */
257 if (len)
258 ILGetNext(pidlNew)->mkid.cb = 0x00;
261 TRACE("-- newpidl=%p\n",pidlNew);
263 return pidlNew;
266 /*************************************************************************
267 * ILLoadFromStream (SHELL32.26)
269 * NOTES
270 * the first two bytes are the len, the pidl is following then
272 HRESULT WINAPI ILLoadFromStream (IStream * pStream, LPITEMIDLIST * ppPidl)
273 { WORD wLen = 0;
274 DWORD dwBytesRead;
275 HRESULT ret = E_FAIL;
278 TRACE_(shell)("%p %p\n", pStream , ppPidl);
280 if (*ppPidl)
281 { SHFree(*ppPidl);
282 *ppPidl = NULL;
285 IStream_AddRef (pStream);
287 if (SUCCEEDED(IStream_Read(pStream, (LPVOID)&wLen, 2, &dwBytesRead)))
289 TRACE("PIDL length is %d\n", wLen);
290 if (wLen != 0) {
291 *ppPidl = SHAlloc (wLen);
292 if (SUCCEEDED(IStream_Read(pStream, *ppPidl , wLen, &dwBytesRead))) {
293 TRACE("Stream read OK\n");
294 ret = S_OK;
295 } else {
296 WARN("reading pidl failed\n");
297 SHFree(*ppPidl);
298 *ppPidl = NULL;
300 } else {
301 *ppPidl = NULL;
302 ret = S_OK;
306 /* we are not yet fully compatible */
307 if (*ppPidl && !pcheck(*ppPidl))
309 WARN("Check failed\n");
310 SHFree(*ppPidl);
311 *ppPidl = NULL;
315 IStream_Release (pStream);
316 TRACE("done\n");
317 return ret;
320 /*************************************************************************
321 * ILSaveToStream (SHELL32.27)
323 * NOTES
324 * the first two bytes are the len, the pidl is following then
326 HRESULT WINAPI ILSaveToStream (IStream * pStream, LPCITEMIDLIST pPidl)
328 LPCITEMIDLIST pidl;
329 WORD wLen = 0;
330 HRESULT ret = E_FAIL;
332 TRACE_(shell)("%p %p\n", pStream, pPidl);
334 IStream_AddRef (pStream);
336 pidl = pPidl;
337 while (pidl->mkid.cb)
339 wLen += sizeof(WORD) + pidl->mkid.cb;
340 pidl = ILGetNext(pidl);
343 if (SUCCEEDED(IStream_Write(pStream, (LPVOID)&wLen, 2, NULL)))
345 if (SUCCEEDED(IStream_Write(pStream, pPidl, wLen, NULL)))
346 { ret = S_OK;
349 IStream_Release (pStream);
351 return ret;
354 /*************************************************************************
355 * SHILCreateFromPath [SHELL32.28]
357 * Create an ItemIDList from a path
359 * PARAMS
360 * path [I]
361 * ppidl [O]
362 * attributes [I/O] requested attributes on call and actual attributes when
363 * the function returns
365 * RETURNS
366 * NO_ERROR if successful, or an OLE errer code otherwise
368 * NOTES
369 * Wrapper for IShellFolder_ParseDisplayName().
371 HRESULT WINAPI SHILCreateFromPathA(LPCSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
373 LPSHELLFOLDER sf;
374 WCHAR lpszDisplayName[MAX_PATH];
375 DWORD pchEaten;
376 HRESULT ret = E_FAIL;
378 TRACE_(shell)("%s %p 0x%08lx\n", path, ppidl, attributes ? *attributes : 0);
380 if (!MultiByteToWideChar(CP_ACP, 0, path, -1, lpszDisplayName, MAX_PATH))
381 lpszDisplayName[MAX_PATH-1] = 0;
383 if (SUCCEEDED (SHGetDesktopFolder(&sf)))
385 ret = IShellFolder_ParseDisplayName(sf, 0, NULL, lpszDisplayName, &pchEaten, ppidl, attributes);
386 IShellFolder_Release(sf);
388 return ret;
391 HRESULT WINAPI SHILCreateFromPathW(LPCWSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
393 LPSHELLFOLDER sf;
394 DWORD pchEaten;
395 HRESULT ret = E_FAIL;
397 TRACE_(shell)("%s %p 0x%08lx\n", debugstr_w(path), ppidl, attributes ? *attributes : 0);
399 if (SUCCEEDED (SHGetDesktopFolder(&sf)))
401 ret = IShellFolder_ParseDisplayName(sf, 0, NULL, (LPWSTR)path, &pchEaten, ppidl, attributes);
402 IShellFolder_Release(sf);
404 return ret;
407 HRESULT WINAPI SHILCreateFromPathAW (LPCVOID path, LPITEMIDLIST * ppidl, DWORD * attributes)
409 if ( SHELL_OsIsUnicode())
410 return SHILCreateFromPathW (path, ppidl, attributes);
411 return SHILCreateFromPathA (path, ppidl, attributes);
414 /*************************************************************************
415 * SHCloneSpecialIDList [SHELL32.89]
417 * Create an ItemIDList to one of the special folders.
419 * PARAMS
420 * hwndOwner [in]
421 * nFolder [in] CSIDL_xxxxx
422 * fCreate [in] Create folder if it does not exist
424 * RETURNS
425 * Success: The newly created pidl
426 * Failure: NULL, if inputs are invalid.
428 * NOTES
429 * exported by ordinal.
430 * Caller is responsible for deallocating the returned ItemIDList with the
431 * shells IMalloc interface, aka ILFree.
433 LPITEMIDLIST WINAPI SHCloneSpecialIDList(HWND hwndOwner, DWORD nFolder, BOOL fCreate)
434 { LPITEMIDLIST ppidl;
435 TRACE_(shell)("(hwnd=%p,csidl=0x%lx,%s).\n", hwndOwner, nFolder, fCreate ? "T" : "F");
437 if (fCreate)
438 nFolder |= CSIDL_FLAG_CREATE;
440 SHGetSpecialFolderLocation(hwndOwner, nFolder, &ppidl);
441 return ppidl;
444 /*************************************************************************
445 * ILGlobalClone [SHELL32.20]
447 * Clones an ItemIDList using Alloc.
449 * PARAMS
450 * pidl [I] ItemIDList to clone
452 * RETURNS
453 * Newly allocated ItemIDList.
455 * NOTES
456 * exported by ordinal.
458 LPITEMIDLIST WINAPI ILGlobalClone(LPCITEMIDLIST pidl)
459 { DWORD len;
460 LPITEMIDLIST newpidl;
462 if (!pidl)
463 return NULL;
465 len = ILGetSize(pidl);
466 newpidl = (LPITEMIDLIST)Alloc(len);
467 if (newpidl)
468 memcpy(newpidl,pidl,len);
470 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
471 pdump(pidl);
473 return newpidl;
476 /*************************************************************************
477 * ILIsEqual [SHELL32.21]
480 BOOL WINAPI ILIsEqual(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
482 char szData1[MAX_PATH];
483 char szData2[MAX_PATH];
485 LPCITEMIDLIST pidltemp1 = pidl1;
486 LPCITEMIDLIST pidltemp2 = pidl2;
488 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
490 /* explorer reads from registry directly (StreamMRU),
491 so we can only check here */
492 if ((!pcheck (pidl1)) || (!pcheck (pidl2))) return FALSE;
494 pdump (pidl1);
495 pdump (pidl2);
497 if ( (!pidl1) || (!pidl2) ) return FALSE;
499 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
501 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
502 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
504 if (strcasecmp ( szData1, szData2 )!=0 )
505 return FALSE;
507 pidltemp1 = ILGetNext(pidltemp1);
508 pidltemp2 = ILGetNext(pidltemp2);
511 if (!pidltemp1->mkid.cb && !pidltemp2->mkid.cb)
513 return TRUE;
516 return FALSE;
518 /*************************************************************************
519 * ILIsParent [SHELL32.23]
521 * Verifies that pidlParent is indeed the (immediate) parent of pidlChild.
523 * PARAMS
524 * pidlParent [I]
525 * pidlChild [I]
526 * bImmediate [I] only return true if the parent is the direct parent
527 * of the child
529 * RETURNS
530 * True if the parent ItemIDlist is a complete part of the child ItemIdList,
531 * False otherwise.
533 * NOTES
534 * parent = a/b, child = a/b/c -> true, c is in folder a/b
535 * child = a/b/c/d -> false if bImmediate is true, d is not in folder a/b
536 * child = a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
538 BOOL WINAPI ILIsParent(LPCITEMIDLIST pidlParent, LPCITEMIDLIST pidlChild, BOOL bImmediate)
540 char szData1[MAX_PATH];
541 char szData2[MAX_PATH];
543 LPCITEMIDLIST pParent = pidlParent;
544 LPCITEMIDLIST pChild = pidlChild;
546 TRACE("%p %p %x\n", pidlParent, pidlChild, bImmediate);
548 if (!pParent || !pChild) return FALSE;
550 while (pParent->mkid.cb && pChild->mkid.cb)
552 _ILSimpleGetText(pParent, szData1, MAX_PATH);
553 _ILSimpleGetText(pChild, szData2, MAX_PATH);
555 if (strcasecmp ( szData1, szData2 )!=0 )
556 return FALSE;
558 pParent = ILGetNext(pParent);
559 pChild = ILGetNext(pChild);
562 if ( pParent->mkid.cb || ! pChild->mkid.cb) /* child shorter or has equal length to parent */
563 return FALSE;
565 if ( ILGetNext(pChild)->mkid.cb && bImmediate) /* not immediate descent */
566 return FALSE;
568 return TRUE;
571 /*************************************************************************
572 * ILFindChild [SHELL32.24]
574 * Compares elements from pidl1 and pidl2.
576 * PARAMS
577 * pidl1 [I]
578 * pidl2 [I]
580 * RETURNS
581 * pidl1 is desktop pidl2
582 * pidl1 shorter pidl2 pointer to first different element of pidl2
583 * if there was at least one equal element
584 * pidl2 shorter pidl1 0
585 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
587 * NOTES
588 * exported by ordinal.
590 LPITEMIDLIST WINAPI ILFindChild(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
592 char szData1[MAX_PATH];
593 char szData2[MAX_PATH];
595 LPCITEMIDLIST pidltemp1 = pidl1;
596 LPCITEMIDLIST pidltemp2 = pidl2;
597 LPCITEMIDLIST ret=NULL;
599 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
601 /* explorer reads from registry directly (StreamMRU),
602 so we can only check here */
603 if ((!pcheck (pidl1)) || (!pcheck (pidl2)))
604 return FALSE;
606 pdump (pidl1);
607 pdump (pidl2);
609 if ( _ILIsDesktop(pidl1) )
611 ret = pidl2;
613 else
615 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
617 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
618 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
620 if (strcasecmp(szData1,szData2))
621 break;
623 pidltemp1 = ILGetNext(pidltemp1);
624 pidltemp2 = ILGetNext(pidltemp2);
625 ret = pidltemp2;
628 if (pidltemp1->mkid.cb)
630 ret = NULL; /* elements of pidl1 left*/
633 TRACE_(shell)("--- %p\n", ret);
634 return (LPITEMIDLIST)ret; /* pidl 1 is shorter */
637 /*************************************************************************
638 * ILCombine [SHELL32.25]
640 * Concatenates two complex ItemIDLists.
642 * PARAMS
643 * pidl1 [I] first complex ItemIDLists
644 * pidl2 [I] complex ItemIDLists to append
646 * RETURNS
647 * if both pidl's == NULL NULL
648 * if pidl1 == NULL cloned pidl2
649 * if pidl2 == NULL cloned pidl1
650 * otherwise new pidl with pidl2 appended to pidl1
652 * NOTES
653 * exported by ordinal.
654 * Does not destroy the passed in ItemIDLists!
656 LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
658 DWORD len1,len2;
659 LPITEMIDLIST pidlNew;
661 TRACE("pidl=%p pidl=%p\n",pidl1,pidl2);
663 if(!pidl1 && !pidl2) return NULL;
665 pdump (pidl1);
666 pdump (pidl2);
668 if(!pidl1)
670 pidlNew = ILClone(pidl2);
671 return pidlNew;
674 if(!pidl2)
676 pidlNew = ILClone(pidl1);
677 return pidlNew;
680 len1 = ILGetSize(pidl1)-2;
681 len2 = ILGetSize(pidl2);
682 pidlNew = SHAlloc(len1+len2);
684 if (pidlNew)
686 memcpy(pidlNew,pidl1,len1);
687 memcpy(((BYTE *)pidlNew)+len1,pidl2,len2);
690 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
691 return pidlNew;
694 /*************************************************************************
695 * SHGetRealIDL [SHELL32.98]
697 * NOTES
699 HRESULT WINAPI SHGetRealIDL(LPSHELLFOLDER lpsf, LPCITEMIDLIST pidlSimple, LPITEMIDLIST *pidlReal)
701 IDataObject* pDataObj;
702 HRESULT hr = IShellFolder_GetUIObjectOf(lpsf, 0, 1, &pidlSimple, &IID_IDataObject, 0, (LPVOID*)&pDataObj);
704 if (SUCCEEDED(hr)) {
705 STGMEDIUM medium;
706 FORMATETC fmt;
708 fmt.cfFormat = RegisterClipboardFormatA(CFSTR_SHELLIDLIST);
709 fmt.ptd = NULL;
710 fmt.dwAspect = DVASPECT_CONTENT;
711 fmt.lindex = -1;
712 fmt.tymed = TYMED_HGLOBAL;
714 hr = IDataObject_GetData(pDataObj, &fmt, &medium);
716 IDataObject_Release(pDataObj);
718 if (SUCCEEDED(hr)) {
719 /*assert(pida->cidl==1);*/
720 LPIDA pida = (LPIDA)GlobalLock(medium.u.hGlobal);
722 LPCITEMIDLIST pidl_folder = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[0]);
723 LPCITEMIDLIST pidl_child = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[1]);
725 *pidlReal = ILCombine(pidl_folder, pidl_child);
727 if (!*pidlReal)
728 hr = E_OUTOFMEMORY;
730 GlobalUnlock(medium.u.hGlobal);
731 GlobalFree(medium.u.hGlobal);
735 return hr;
738 /*************************************************************************
739 * SHLogILFromFSIL [SHELL32.95]
741 * NOTES
742 * pild = CSIDL_DESKTOP ret = 0
743 * pild = CSIDL_DRIVES ret = 0
745 LPITEMIDLIST WINAPI SHLogILFromFSIL(LPITEMIDLIST pidl)
747 FIXME("(pidl=%p)\n",pidl);
749 pdump(pidl);
751 return 0;
754 /*************************************************************************
755 * ILGetSize [SHELL32.152]
757 * Gets the byte size of an ItemIDList including zero terminator
759 * PARAMS
760 * pidl [I] ItemIDList
762 * RETURNS
763 * size of pidl in bytes
765 * NOTES
766 * exported by ordinal
768 UINT WINAPI ILGetSize(LPCITEMIDLIST pidl)
770 LPCSHITEMID si = &(pidl->mkid);
771 UINT len=0;
773 if (pidl)
774 { while (si->cb)
775 { len += si->cb;
776 si = (LPSHITEMID)(((LPBYTE)si)+si->cb);
778 len += 2;
780 TRACE("pidl=%p size=%u\n",pidl, len);
781 return len;
784 /*************************************************************************
785 * ILGetNext [SHELL32.153]
787 * Gets the next ItemID of an ItemIDList
789 * PARAMS
790 * pidl [I] ItemIDList
792 * RETURNS
793 * null -> null
794 * desktop -> null
795 * simple pidl -> pointer to 0x0000 element
797 * NOTES
798 * exported by ordinal.
800 LPITEMIDLIST WINAPI ILGetNext(LPCITEMIDLIST pidl)
802 WORD len;
804 TRACE("%p\n", pidl);
806 if(pidl)
808 len = pidl->mkid.cb;
809 if (len)
811 pidl = (LPITEMIDLIST) (((LPBYTE)pidl)+len);
812 TRACE("-- %p\n", pidl);
813 return (LPITEMIDLIST)pidl;
816 return NULL;
819 /*************************************************************************
820 * ILAppend [SHELL32.154]
822 * Adds the single ItemID item to the ItemIDList indicated by pidl.
823 * If bEnd is FALSE, inserts the item in the front of the list,
824 * otherwise it adds the item to the end. (???)
826 * PARAMS
827 * pidl [I] ItemIDList to extend
828 * item [I] ItemID to prepend/append
829 * bEnd [I] Indicates if the item should be appended
831 * NOTES
832 * Destroys the passed in idlist! (???)
834 LPITEMIDLIST WINAPI ILAppend(LPITEMIDLIST pidl, LPCITEMIDLIST item, BOOL bEnd)
836 LPITEMIDLIST idlRet;
838 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl,item,bEnd);
840 pdump (pidl);
841 pdump (item);
843 if (_ILIsDesktop(pidl))
845 idlRet = ILClone(item);
846 if (pidl)
847 SHFree (pidl);
848 return idlRet;
851 if (bEnd)
853 idlRet = ILCombine(pidl, item);
855 else
857 idlRet = ILCombine(item, pidl);
860 SHFree(pidl);
861 return idlRet;
864 /*************************************************************************
865 * ILFree [SHELL32.155]
867 * Frees memory (if not NULL) allocated by SHMalloc allocator
869 * PARAMS
870 * pidl [I]
872 * NOTES
873 * exported by ordinal
875 void WINAPI ILFree(LPITEMIDLIST pidl)
877 TRACE("(pidl=%p)\n",pidl);
878 if(pidl) SHFree(pidl);
881 /*************************************************************************
882 * ILGlobalFree [SHELL32.156]
884 * Frees memory (if not NULL) allocated by Alloc allocator
886 * PARAMS
887 * pidl [I]
889 * NOTES
890 * exported by ordinal.
892 void WINAPI ILGlobalFree( LPITEMIDLIST pidl)
894 TRACE("%p\n", pidl);
896 if(!pidl) return;
897 Free(pidl);
900 /*************************************************************************
901 * ILCreateFromPathA [SHELL32.189]
903 * Creates a complex ItemIDList from a path and returns it.
905 * PARAMS
906 * path [I]
908 * RETURNS
909 * the newly created complex ItemIDList or NULL if failed
911 * NOTES
912 * exported by ordinal.
915 LPITEMIDLIST WINAPI ILCreateFromPathA (LPCSTR path)
917 LPITEMIDLIST pidlnew = NULL;
919 TRACE_(shell)("%s\n", debugstr_a(path));
921 if (SUCCEEDED(SHILCreateFromPathA(path, &pidlnew, NULL)))
922 return pidlnew;
923 return NULL;
926 /*************************************************************************
927 * ILCreateFromPathW [SHELL32.190]
929 LPITEMIDLIST WINAPI ILCreateFromPathW (LPCWSTR path)
931 LPITEMIDLIST pidlnew = NULL;
933 TRACE_(shell)("%s\n", debugstr_w(path));
935 if (SUCCEEDED(SHILCreateFromPathW(path, &pidlnew, NULL)))
936 return pidlnew;
937 return NULL;
940 /*************************************************************************
941 * ILCreateFromPath [SHELL32.157]
943 LPITEMIDLIST WINAPI ILCreateFromPathAW (LPCVOID path)
945 if ( SHELL_OsIsUnicode())
946 return ILCreateFromPathW (path);
947 return ILCreateFromPathA (path);
950 /*************************************************************************
951 * _ILParsePathW [internal]
953 * Creates an ItemIDList from a path and returns it.
955 * PARAMS
956 * path [I] path to parse and convert into an ItemIDList
957 * lpFindFile [I] pointer to buffer to initialize the FileSystem
958 * Bind Data object with
959 * bBindCtx [I] indicates to create a BindContext and assign a
960 * FileSystem Bind Data object
961 * ppidl [O] the newly create ItemIDList
962 * prgfInOut [I/O] requested attributes on input and actual
963 * attributes on return
965 * RETURNS
966 * NO_ERROR on success or an OLE error code
968 * NOTES
969 * If either lpFindFile is non-NULL or bBindCtx is TRUE, this function
970 * creates a BindContext object and assigns a FileSystem Bind Data object
971 * to it, passing the BindContext to IShellFolder_ParseDisplayName. Each
972 * IShellFolder uses that FileSystem Bind Data object of the BindContext
973 * to pass data about the current path element to the next object. This
974 * is used to avoid having to verify the current path element on disk, so
975 * that creating an ItemIDList from a non-existent path still can work.
977 static HRESULT WINAPI _ILParsePathW(LPCWSTR path, LPWIN32_FIND_DATAW lpFindFile,
978 BOOL bBindCtx, LPITEMIDLIST *ppidl, LPDWORD prgfInOut)
980 LPSHELLFOLDER pSF = NULL;
981 LPBC pBC = NULL;
982 HRESULT ret;
984 TRACE("%s %p %d (%p)->%p (%p)->0x%lx\n", debugstr_w(path), lpFindFile, bBindCtx,
985 ppidl, ppidl ? *ppidl : NULL,
986 prgfInOut, prgfInOut ? *prgfInOut : 0);
988 ret = SHGetDesktopFolder(&pSF);
989 if (FAILED(ret))
991 return ret;
994 if (lpFindFile || bBindCtx)
995 ret = IFileSystemBindData_Constructor(lpFindFile, &pBC);
997 if (SUCCEEDED(ret))
999 ret = IShellFolder_ParseDisplayName(pSF, 0, pBC, (LPOLESTR)path, NULL, ppidl, prgfInOut);
1002 if (pBC)
1004 IBindCtx_Release(pBC);
1005 pBC = NULL;
1008 IShellFolder_Release(pSF);
1010 if (!SUCCEEDED(ret) && ppidl)
1011 *ppidl = NULL;
1013 TRACE("%s %p 0x%lx\n", debugstr_w(path), ppidl ? *ppidl : NULL, prgfInOut ? *prgfInOut : 0);
1015 return ret;
1018 /*************************************************************************
1019 * SHSimpleIDListFromPath [SHELL32.162]
1021 * Creates a simple ItemIDList from a path and returns it. This function
1022 * does not fail on non-existent paths.
1024 * PARAMS
1025 * path [I] path to parse and convert into an ItemIDList
1027 * RETURNS
1028 * the newly created simple ItemIDList
1030 * NOTES
1031 * Simple in the name does not mean a relative ItemIDList but rather a
1032 * fully qualified list, where only the file name is filled in and the
1033 * directory flag for those ItemID elements this is known about, eg.
1034 * it is not the last element in the ItemIDList or the actual directory
1035 * exists on disk.
1036 * exported by ordinal.
1038 LPITEMIDLIST WINAPI SHSimpleIDListFromPathA(LPCSTR lpszPath)
1040 LPITEMIDLIST pidl = NULL;
1041 LPWSTR wPath = NULL;
1042 int len;
1044 TRACE("%s\n", debugstr_a(lpszPath));
1046 if (lpszPath)
1048 len = MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, NULL, 0);
1049 wPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1050 MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, wPath, len);
1053 _ILParsePathW(wPath, NULL, TRUE, &pidl, NULL);
1055 if (wPath) HeapFree(GetProcessHeap(), 0, wPath);
1056 TRACE("%s %p\n", debugstr_a(lpszPath), pidl);
1057 return pidl;
1060 LPITEMIDLIST WINAPI SHSimpleIDListFromPathW(LPCWSTR lpszPath)
1062 LPITEMIDLIST pidl = NULL;
1064 TRACE("%s\n", debugstr_w(lpszPath));
1066 _ILParsePathW(lpszPath, NULL, TRUE, &pidl, NULL);
1067 TRACE("%s %p\n", debugstr_w(lpszPath), pidl);
1068 return pidl;
1071 LPITEMIDLIST WINAPI SHSimpleIDListFromPathAW(LPCVOID lpszPath)
1073 if ( SHELL_OsIsUnicode())
1074 return SHSimpleIDListFromPathW (lpszPath);
1075 return SHSimpleIDListFromPathA (lpszPath);
1078 /*************************************************************************
1079 * SHGetSpecialFolderLocation [SHELL32.@]
1081 * gets the folder locations from the registry and creates a pidl
1082 * creates missing reg keys and directories
1084 * PARAMS
1085 * hwndOwner [I]
1086 * nFolder [I] CSIDL_xxxxx
1087 * ppidl [O] PIDL of a special folder
1089 * NOTES
1090 * In NT5, SHGetSpecialFolderLocation needs the <winntdir>/Recent
1091 * directory. If the directory is missing it returns a x80070002.
1093 HRESULT WINAPI SHGetSpecialFolderLocation(
1094 HWND hwndOwner,
1095 INT nFolder,
1096 LPITEMIDLIST * ppidl)
1098 CHAR szPath[MAX_PATH];
1099 HRESULT hr = E_INVALIDARG;
1101 TRACE_(shell)("(%p,0x%x,%p)\n", hwndOwner,nFolder,ppidl);
1103 if (ppidl)
1105 *ppidl = NULL;
1106 switch (nFolder)
1108 case CSIDL_DESKTOP:
1109 *ppidl = _ILCreateDesktop();
1110 break;
1112 case CSIDL_DRIVES:
1113 *ppidl = _ILCreateMyComputer();
1114 break;
1116 case CSIDL_NETWORK:
1117 *ppidl = _ILCreateNetwork ();
1118 break;
1120 case CSIDL_CONTROLS:
1121 *ppidl = _ILCreateControl ();
1122 break;
1124 case CSIDL_PRINTERS:
1125 *ppidl = _ILCreatePrinter ();
1126 break;
1128 case CSIDL_BITBUCKET:
1129 *ppidl = _ILCreateBitBucket ();
1130 break;
1132 default:
1133 if (SHGetSpecialFolderPathA(hwndOwner, szPath, nFolder, TRUE))
1135 DWORD attributes=0;
1136 TRACE_(shell)("Value=%s\n",szPath);
1137 hr = SHILCreateFromPathA(szPath, ppidl, &attributes);
1140 if(*ppidl) hr = NOERROR;
1143 TRACE_(shell)("-- (new pidl %p)\n",*ppidl);
1144 return hr;
1147 /*************************************************************************
1148 * SHGetFolderLocation [SHELL32.@]
1150 * NOTES
1151 * the pidl can be a simple one. since we cant get the path out of the pidl
1152 * we have to take all data from the pidl
1154 HRESULT WINAPI SHGetFolderLocation(
1155 HWND hwnd,
1156 int csidl,
1157 HANDLE hToken,
1158 DWORD dwFlags,
1159 LPITEMIDLIST *ppidl)
1161 FIXME("%p 0x%08x %p 0x%08lx %p\n",
1162 hwnd, csidl, hToken, dwFlags, ppidl);
1163 return SHGetSpecialFolderLocation(hwnd, csidl, ppidl);
1166 /*************************************************************************
1167 * SHGetDataFromIDListA [SHELL32.247]
1169 * NOTES
1170 * the pidl can be a simple one. since we cant get the path out of the pidl
1171 * we have to take all data from the pidl
1173 HRESULT WINAPI SHGetDataFromIDListA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, int nFormat, LPVOID dest, int len)
1175 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
1177 pdump(pidl);
1178 if (!psf || !dest ) return E_INVALIDARG;
1180 switch (nFormat)
1182 case SHGDFIL_FINDDATA:
1184 LPSTR filename, shortname;
1185 WIN32_FIND_DATAA * pfd = dest;
1187 if (_ILIsDrive(pidl))
1188 return E_INVALIDARG;
1190 if (len < (int)sizeof(WIN32_FIND_DATAA)) return E_INVALIDARG;
1192 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1193 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1194 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1195 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1197 filename = _ILGetTextPointer(pidl);
1198 shortname = _ILGetSTextPointer(pidl);
1200 if (filename)
1201 lstrcpynA(pfd->cFileName, filename, MAX_PATH);
1202 else
1203 pfd->cFileName[0] = '\0';
1205 if (shortname)
1206 lstrcpynA(pfd->cAlternateFileName, shortname, MAX_PATH);
1207 else
1208 pfd->cAlternateFileName[0] = '\0';
1210 return NOERROR;
1212 case SHGDFIL_NETRESOURCE:
1213 case SHGDFIL_DESCRIPTIONID:
1214 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1215 break;
1217 default:
1218 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1221 return E_INVALIDARG;
1224 /*************************************************************************
1225 * SHGetDataFromIDListW [SHELL32.248]
1228 HRESULT WINAPI SHGetDataFromIDListW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, int nFormat, LPVOID dest, int len)
1230 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
1232 pdump(pidl);
1234 if (! psf || !dest ) return E_INVALIDARG;
1236 switch (nFormat)
1238 case SHGDFIL_FINDDATA:
1240 LPSTR filename, shortname;
1241 WIN32_FIND_DATAW * pfd = dest;
1243 if (_ILIsDrive(pidl))
1244 return E_INVALIDARG;
1246 if (len < (int)sizeof(WIN32_FIND_DATAW)) return E_INVALIDARG;
1248 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1249 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1250 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1251 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1253 filename = _ILGetTextPointer(pidl);
1254 shortname = _ILGetSTextPointer(pidl);
1256 if (!filename)
1257 pfd->cFileName[0] = '\0';
1258 else if (!MultiByteToWideChar(CP_ACP, 0, filename, -1, pfd->cFileName, MAX_PATH))
1259 pfd->cFileName[MAX_PATH-1] = 0;
1261 if (!shortname)
1262 pfd->cAlternateFileName[0] = '\0';
1263 else if (!MultiByteToWideChar(CP_ACP, 0, shortname, -1, pfd->cAlternateFileName, 14))
1264 pfd->cAlternateFileName[13] = 0;
1266 return NOERROR;
1267 case SHGDFIL_NETRESOURCE:
1268 case SHGDFIL_DESCRIPTIONID:
1269 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1270 break;
1272 default:
1273 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1276 return E_INVALIDARG;
1279 /*************************************************************************
1280 * SHELL_GetPathFromIDListA
1282 HRESULT SHELL_GetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath, UINT uOutSize)
1284 HRESULT hr = S_OK;
1286 pszPath[0]=0;
1288 /* One case is a PIDL rooted at desktop level */
1289 if (_ILIsValue(pidl) || _ILIsFolder(pidl)) {
1290 hr = SHGetSpecialFolderPathA(0, pszPath, CSIDL_DESKTOP, FALSE);
1292 if (SUCCEEDED(hr))
1293 PathAddBackslashA(pszPath);
1295 /* The only other valid case is a item ID list beginning at "My Computer" */
1296 else if (_ILIsMyComputer(pidl))
1297 pidl = ILGetNext(pidl);
1299 if (SUCCEEDED(hr)) {
1300 LPSTR txt;
1302 while(pidl && pidl->mkid.cb) {
1303 if (_ILIsSpecialFolder(pidl))
1304 {hr = E_INVALIDARG; break;}
1306 txt = _ILGetTextPointer(pidl);
1307 if (!txt)
1308 {hr = E_INVALIDARG; break;}
1310 if (lstrlenA(txt) > pidl->mkid.cb)
1311 ERR("pidl %p is borked\n",pidl);
1313 /* make sure there's enough space for the next segment */
1314 if ( (lstrlenA(txt) + lstrlenA(pszPath)) > uOutSize)
1315 {hr = E_INVALIDARG; break;}
1316 lstrcatA( pszPath, txt );
1318 pidl = ILGetNext(pidl);
1319 if (!pidl)
1320 {hr = E_INVALIDARG; break;}
1322 if (!pidl->mkid.cb) {
1323 /* We are at the end and successfully converted the complete PIDL. */
1324 break;
1327 if( (lstrlenA(pszPath) + 1) > uOutSize)
1328 {hr = E_INVALIDARG; break;}
1329 if (!PathAddBackslashA(pszPath))
1330 {hr = E_INVALIDARG; break;}
1332 } else
1333 hr = E_INVALIDARG;
1335 TRACE_(shell)("-- %s, 0x%08lx\n", pszPath, hr);
1336 return hr;
1339 /*************************************************************************
1340 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
1342 * PARAMETERS
1343 * pidl, [IN] pidl
1344 * pszPath [OUT] path
1346 * RETURNS
1347 * path from a passed PIDL.
1349 * NOTES
1350 * NULL returns FALSE
1351 * desktop pidl gives path to desktop directory back
1352 * special pidls returning FALSE
1354 BOOL WINAPI SHGetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath)
1356 HRESULT hr;
1358 TRACE_(shell)("(pidl=%p,%p)\n",pidl,pszPath);
1359 pdump(pidl);
1361 if (!pidl)
1362 return FALSE;
1364 hr = SHELL_GetPathFromIDListA(pidl, pszPath, MAX_PATH);
1366 return SUCCEEDED(hr);
1369 /*************************************************************************
1370 * SHELL_GetPathFromIDListW
1372 HRESULT SHELL_GetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath, UINT uOutSize)
1374 HRESULT hr = S_OK;
1375 UINT len;
1377 pszPath[0]=0;
1379 /* One case is a PIDL rooted at desktop level */
1380 if (_ILIsValue(pidl) || _ILIsFolder(pidl)) {
1381 hr = SHGetSpecialFolderPathW(0, pszPath, CSIDL_DESKTOP, FALSE);
1383 if (SUCCEEDED(hr))
1384 PathAddBackslashW(pszPath);
1386 /* The only other valid case is a item ID list beginning at "My Computer" */
1387 else if (_ILIsMyComputer(pidl))
1388 pidl = ILGetNext(pidl);
1390 if (SUCCEEDED(hr)) {
1391 LPSTR txt;
1393 while(pidl && pidl->mkid.cb) {
1394 if (_ILIsSpecialFolder(pidl))
1395 {hr = E_INVALIDARG; break;}
1397 txt = _ILGetTextPointer(pidl);
1398 if (!txt)
1399 {hr = E_INVALIDARG; break;}
1401 if (lstrlenA(txt) > pidl->mkid.cb)
1402 ERR("pidl %p is borked\n",pidl);
1403 len = MultiByteToWideChar(CP_ACP, 0, txt, -1, NULL, 0);
1404 if ( (lstrlenW(pszPath) + len) > uOutSize )
1405 {hr = E_INVALIDARG; break;}
1407 MultiByteToWideChar(CP_ACP, 0, txt, -1,
1408 &pszPath[lstrlenW(pszPath)], len);
1410 pidl = ILGetNext(pidl);
1411 if (!pidl)
1412 {hr = E_INVALIDARG; break;}
1414 if (!pidl->mkid.cb) {
1415 /* We are at the end and successfully converted the complete PIDL. */
1416 break;
1419 if ( (lstrlenW(pszPath) + 1) > uOutSize )
1420 {hr = E_INVALIDARG; break;}
1421 if (!PathAddBackslashW(pszPath))
1422 {hr = E_INVALIDARG; break;}
1424 } else
1425 hr = E_INVALIDARG;
1427 TRACE_(shell)("-- %s, 0x%08lx\n", debugstr_w(pszPath), hr);
1428 return hr;
1431 /*************************************************************************
1432 * SHGetPathFromIDListW [SHELL32.@]
1434 BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
1436 HRESULT hr;
1438 TRACE_(shell)("(pidl=%p,%p)\n", pidl, debugstr_w(pszPath));
1439 pdump(pidl);
1441 if (!pidl)
1442 return FALSE;
1444 hr = SHELL_GetPathFromIDListW(pidl, pszPath, MAX_PATH);
1446 TRACE_(shell)("-- %s, 0x%08lx\n",debugstr_w(pszPath), hr);
1447 return SUCCEEDED(hr);
1450 /*************************************************************************
1451 * SHGetPathFromIDList [SHELL32.@][NT 4.0: SHELL32.219]
1453 BOOL WINAPI SHGetPathFromIDListAW(LPCITEMIDLIST pidl,LPVOID pszPath)
1455 TRACE_(shell)("(pidl=%p,%p)\n",pidl,pszPath);
1457 if (SHELL_OsIsUnicode())
1458 return SHGetPathFromIDListW(pidl,pszPath);
1459 return SHGetPathFromIDListA(pidl,pszPath);
1462 /*************************************************************************
1463 * SHBindToParent [shell version 5.0]
1465 HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
1467 IShellFolder * psf;
1468 LPITEMIDLIST pidlChild, pidlParent;
1469 HRESULT hr=E_FAIL;
1471 TRACE_(shell)("pidl=%p\n", pidl);
1472 pdump(pidl);
1474 *ppv = NULL;
1475 if (ppidlLast) *ppidlLast = NULL;
1477 if (_ILIsPidlSimple(pidl))
1479 /* we are on desktop level */
1480 if (ppidlLast)
1481 *ppidlLast = ILClone(pidl);
1482 hr = SHGetDesktopFolder((IShellFolder**)ppv);
1484 else
1486 pidlChild = ILClone(ILFindLastID(pidl));
1487 pidlParent = ILClone(pidl);
1488 ILRemoveLastID(pidlParent);
1490 hr = SHGetDesktopFolder(&psf);
1492 if (SUCCEEDED(hr))
1493 hr = IShellFolder_BindToObject(psf, pidlParent, NULL, riid, ppv);
1495 if (SUCCEEDED(hr) && ppidlLast)
1496 *ppidlLast = pidlChild;
1497 else
1498 ILFree (pidlChild);
1500 SHFree (pidlParent);
1501 if (psf) IShellFolder_Release(psf);
1505 TRACE_(shell)("-- psf=%p pidl=%p ret=0x%08lx\n", *ppv, (ppidlLast)?*ppidlLast:NULL, hr);
1506 return hr;
1509 /**************************************************************************
1511 * internal functions
1513 * ### 1. section creating pidls ###
1515 *************************************************************************
1516 * _ILCreateDesktop()
1517 * _ILCreateIExplore()
1518 * _ILCreateMyComputer()
1519 * _ILCreateDrive()
1520 * _ILCreateFolder()
1521 * _ILCreateValue()
1523 LPITEMIDLIST _ILCreateDesktop()
1524 { TRACE("()\n");
1525 return _ILCreate(PT_DESKTOP, NULL, 0);
1528 LPITEMIDLIST _ILCreateMyComputer()
1529 { TRACE("()\n");
1530 return _ILCreate(PT_MYCOMP, &CLSID_MyComputer, sizeof(GUID));
1533 LPITEMIDLIST _ILCreateIExplore()
1534 { TRACE("()\n");
1535 return _ILCreate(PT_MYCOMP, &CLSID_Internet, sizeof(GUID));
1538 LPITEMIDLIST _ILCreateControl()
1539 { TRACE("()\n");
1540 return _ILCreate(PT_SPECIAL, &CLSID_ControlPanel, sizeof(GUID));
1543 LPITEMIDLIST _ILCreatePrinter()
1544 { TRACE("()\n");
1545 return _ILCreate(PT_SPECIAL, &CLSID_Printers, sizeof(GUID));
1548 LPITEMIDLIST _ILCreateNetwork()
1549 { TRACE("()\n");
1550 return _ILCreate(PT_MYCOMP, &CLSID_NetworkPlaces, sizeof(GUID));
1553 LPITEMIDLIST _ILCreateBitBucket()
1554 { TRACE("()\n");
1555 return _ILCreate(PT_MYCOMP, &CLSID_RecycleBin, sizeof(GUID));
1558 LPITEMIDLIST _ILCreateDrive( LPCSTR lpszNew)
1559 { char sTemp[4];
1560 lstrcpynA (sTemp,lpszNew,4);
1561 sTemp[2]='\\';
1562 sTemp[3]=0x00;
1563 TRACE("(%s)\n",sTemp);
1564 return _ILCreate(PT_DRIVE,(LPVOID)&sTemp[0],4);
1567 LPITEMIDLIST _ILCreateFolder( WIN32_FIND_DATAA * stffile )
1569 char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1570 char * pbuff = buff;
1571 ULONG len, len1;
1572 LPITEMIDLIST pidl;
1574 TRACE("(%s, %s)\n",stffile->cAlternateFileName, stffile->cFileName);
1576 /* prepare buffer with both names */
1577 len = strlen (stffile->cFileName) + 1;
1578 memcpy (pbuff, stffile->cFileName, len);
1579 pbuff += len;
1581 if (stffile->cAlternateFileName)
1583 len1 = strlen (stffile->cAlternateFileName)+1;
1584 memcpy (pbuff, stffile->cAlternateFileName, len1);
1586 else
1588 len1 = 1;
1589 *pbuff = 0x00;
1592 pidl = _ILCreate(PT_FOLDER, (LPVOID)buff, len + len1);
1594 /* set attributes */
1595 if (pidl)
1597 LPPIDLDATA pData;
1598 pData = _ILGetDataPointer(pidl);
1599 FileTimeToDosDateTime(&(stffile->ftLastWriteTime),&pData->u.folder.uFileDate,&pData->u.folder.uFileTime);
1600 pData->u.folder.dwFileSize = stffile->nFileSizeLow;
1601 pData->u.folder.uFileAttribs = stffile->dwFileAttributes;
1604 return pidl;
1607 LPITEMIDLIST _ILCreateValue(WIN32_FIND_DATAA * stffile)
1609 char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1610 char * pbuff = buff;
1611 ULONG len, len1;
1612 LPITEMIDLIST pidl;
1614 TRACE("(%s, %s)\n",stffile->cAlternateFileName, stffile->cFileName);
1616 /* prepare buffer with both names */
1617 len = strlen (stffile->cFileName) + 1;
1618 memcpy (pbuff, stffile->cFileName, len);
1619 pbuff += len;
1621 if (stffile->cAlternateFileName)
1623 len1 = strlen (stffile->cAlternateFileName)+1;
1624 memcpy (pbuff, stffile->cAlternateFileName, len1);
1626 else
1628 len1 = 1;
1629 *pbuff = 0x00;
1632 pidl = _ILCreate(PT_VALUE, (LPVOID)buff, len + len1);
1634 /* set attributes */
1635 if (pidl)
1637 LPPIDLDATA pData;
1638 pData = _ILGetDataPointer(pidl);
1639 FileTimeToDosDateTime(&(stffile->ftLastWriteTime),&pData->u.folder.uFileDate,&pData->u.folder.uFileTime);
1640 pData->u.folder.dwFileSize = stffile->nFileSizeLow;
1641 pData->u.folder.uFileAttribs=stffile->dwFileAttributes;
1644 return pidl;
1647 LPITEMIDLIST _ILCreateFromPathA(LPCSTR szPath)
1649 HANDLE hFile;
1650 WIN32_FIND_DATAA stffile;
1651 LPITEMIDLIST pidl = NULL;
1653 hFile = FindFirstFileA(szPath, &stffile);
1654 if (hFile != INVALID_HANDLE_VALUE)
1656 if (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1657 pidl = _ILCreateFolder(&stffile);
1658 else
1659 pidl = _ILCreateValue(&stffile);
1660 FindClose(hFile);
1662 return pidl;
1665 LPITEMIDLIST _ILCreateSpecial(LPCSTR szGUID)
1667 IID iid;
1669 if (!SUCCEEDED(SHCLSIDFromStringA(szGUID, &iid)))
1671 ERR("%s is not a GUID\n", szGUID);
1672 return NULL;
1674 return _ILCreate(PT_MYCOMP, &iid, sizeof(IID));
1677 /**************************************************************************
1678 * _ILCreate()
1679 * Creates a new PIDL
1680 * type = PT_DESKTOP | PT_DRIVE | PT_FOLDER | PT_VALUE
1681 * pIn = data
1682 * uInSize = size of data (raw)
1685 LPITEMIDLIST _ILCreate(PIDLTYPE type, LPCVOID pIn, UINT uInSize)
1687 LPITEMIDLIST pidlOut = NULL, pidlTemp = NULL;
1688 LPPIDLDATA pData;
1689 UINT uSize = 0;
1690 LPSTR pszDest;
1692 TRACE("(0x%02x %p %i)\n",type,pIn,uInSize);
1694 switch (type)
1696 case PT_DESKTOP:
1697 uSize = 0;
1698 break;
1699 case PT_SPECIAL:
1700 case PT_MYCOMP:
1701 uSize = 2 + 2 + sizeof(GUID);
1702 break;
1703 case PT_DRIVE:
1704 uSize = 2 + 23;
1705 break;
1706 case PT_FOLDER:
1707 case PT_VALUE:
1708 uSize = 2 + 12 + uInSize;
1709 break;
1710 default:
1711 FIXME("can't create type: 0x%08x\n",type);
1712 return NULL;
1715 if(!(pidlOut = SHAlloc(uSize + 2))) return NULL;
1716 ZeroMemory(pidlOut, uSize + 2);
1717 pidlOut->mkid.cb = uSize;
1719 switch (type)
1721 case PT_DESKTOP:
1722 TRACE("- create Desktop\n");
1723 break;
1725 case PT_SPECIAL:
1726 case PT_MYCOMP:
1727 pData = _ILGetDataPointer(pidlOut);
1728 pData->type = type;
1729 memcpy(&(pData->u.mycomp.guid), pIn, uInSize);
1730 TRACE("-- create GUID-pidl %s\n", debugstr_guid(&(pData->u.mycomp.guid)));
1731 break;
1733 case PT_DRIVE:
1734 pData = _ILGetDataPointer(pidlOut);
1735 pData->type = type;
1736 pszDest = _ILGetTextPointer(pidlOut);
1737 memcpy(pszDest, pIn, uInSize);
1738 TRACE("-- create Drive: %s\n",debugstr_a(pszDest));
1739 break;
1741 case PT_FOLDER:
1742 case PT_VALUE:
1743 pData = _ILGetDataPointer(pidlOut);
1744 pData->type = type;
1745 pszDest = _ILGetTextPointer(pidlOut);
1746 memcpy(pszDest, pIn, uInSize);
1747 TRACE("-- create Value: %s\n",debugstr_a(pszDest));
1748 break;
1751 pidlTemp = ILGetNext(pidlOut);
1752 if (pidlTemp)
1753 pidlTemp->mkid.cb = 0x00;
1755 TRACE("-- (pidl=%p, size=%u)\n", pidlOut, uSize);
1756 return pidlOut;
1759 /**************************************************************************
1760 * _ILGetDrive()
1762 * Gets the text for the drive eg. 'c:\'
1764 * RETURNS
1765 * strlen (lpszText)
1767 DWORD _ILGetDrive(LPCITEMIDLIST pidl,LPSTR pOut, UINT uSize)
1768 { TRACE("(%p,%p,%u)\n",pidl,pOut,uSize);
1770 if(_ILIsMyComputer(pidl))
1771 pidl = ILGetNext(pidl);
1773 if (pidl && _ILIsDrive(pidl))
1774 return _ILSimpleGetText(pidl, pOut, uSize);
1776 return 0;
1779 /**************************************************************************
1781 * ### 2. section testing pidls ###
1783 **************************************************************************
1784 * _ILIsDesktop()
1785 * _ILIsMyComputer()
1786 * _ILIsSpecialFolder()
1787 * _ILIsDrive()
1788 * _ILIsFolder()
1789 * _ILIsValue()
1790 * _ILIsPidlSimple()
1792 BOOL _ILIsDesktop(LPCITEMIDLIST pidl)
1793 { TRACE("(%p)\n",pidl);
1794 return pidl && pidl->mkid.cb ? 0 : 1;
1797 BOOL _ILIsMyComputer(LPCITEMIDLIST pidl)
1799 REFIID iid = _ILGetGUIDPointer(pidl);
1801 TRACE("(%p)\n",pidl);
1803 if (iid)
1804 return IsEqualIID(iid, &CLSID_MyComputer);
1805 return FALSE;
1808 BOOL _ILIsSpecialFolder (LPCITEMIDLIST pidl)
1810 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1811 TRACE("(%p)\n",pidl);
1812 return (pidl && ( (lpPData && (PT_MYCOMP== lpPData->type || PT_SPECIAL== lpPData->type)) ||
1813 (pidl && pidl->mkid.cb == 0x00)
1817 BOOL _ILIsDrive(LPCITEMIDLIST pidl)
1818 { LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1819 TRACE("(%p)\n",pidl);
1820 return (pidl && lpPData && (PT_DRIVE == lpPData->type ||
1821 PT_DRIVE1 == lpPData->type ||
1822 PT_DRIVE2 == lpPData->type ||
1823 PT_DRIVE3 == lpPData->type));
1826 BOOL _ILIsFolder(LPCITEMIDLIST pidl)
1827 { LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1828 TRACE("(%p)\n",pidl);
1829 return (pidl && lpPData && (PT_FOLDER == lpPData->type || PT_FOLDER1 == lpPData->type));
1832 BOOL _ILIsValue(LPCITEMIDLIST pidl)
1833 { LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1834 TRACE("(%p)\n",pidl);
1835 return (pidl && lpPData && PT_VALUE == lpPData->type);
1838 /**************************************************************************
1839 * _ILIsPidlSimple
1841 BOOL _ILIsPidlSimple ( LPCITEMIDLIST pidl)
1843 BOOL ret = TRUE;
1845 if(! _ILIsDesktop(pidl)) /* pidl=NULL or mkid.cb=0 */
1847 WORD len = pidl->mkid.cb;
1848 LPCITEMIDLIST pidlnext = (LPCITEMIDLIST) (((LPBYTE)pidl) + len );
1849 if (pidlnext->mkid.cb)
1850 ret = FALSE;
1853 TRACE("%s\n", ret ? "Yes" : "No");
1854 return ret;
1857 /**************************************************************************
1859 * ### 3. section getting values from pidls ###
1862 /**************************************************************************
1863 * _ILSimpleGetText
1865 * gets the text for the first item in the pidl (eg. simple pidl)
1867 * returns the length of the string
1869 DWORD _ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
1871 DWORD dwReturn=0;
1872 LPSTR szSrc;
1873 GUID const * riid;
1874 char szTemp[MAX_PATH];
1876 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1878 if (!pidl) return 0;
1880 if (szOut)
1881 *szOut = 0;
1883 if (_ILIsDesktop(pidl))
1885 /* desktop */
1886 if (HCR_GetClassNameA(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1888 if (szOut)
1889 lstrcpynA(szOut, szTemp, uOutSize);
1891 dwReturn = strlen (szTemp);
1894 else if (( szSrc = _ILGetTextPointer(pidl) ))
1896 /* filesystem */
1897 if (szOut)
1898 lstrcpynA(szOut, szSrc, uOutSize);
1900 dwReturn = strlen(szSrc);
1902 else if (( riid = _ILGetGUIDPointer(pidl) ))
1904 /* special folder */
1905 if ( HCR_GetClassNameA(riid, szTemp, MAX_PATH) )
1907 if (szOut)
1908 lstrcpynA(szOut, szTemp, uOutSize);
1910 dwReturn = strlen (szTemp);
1913 else
1915 ERR("-- no text\n");
1918 TRACE("-- (%p=%s 0x%08lx)\n",szOut,debugstr_a(szOut),dwReturn);
1919 return dwReturn;
1922 /**************************************************************************
1923 * _ILSimpleGetTextW
1925 * gets the text for the first item in the pidl (eg. simple pidl)
1927 * returns the length of the string
1929 DWORD _ILSimpleGetTextW (LPCITEMIDLIST pidl, LPWSTR szOut, UINT uOutSize)
1931 DWORD dwReturn;
1932 char szTemp[MAX_PATH];
1934 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1936 dwReturn = _ILSimpleGetText(pidl, szTemp, uOutSize);
1938 if (!MultiByteToWideChar(CP_ACP, 0, szTemp, -1, szOut, MAX_PATH))
1939 *szOut = 0;
1941 TRACE("-- (%p=%s 0x%08lx)\n",szOut,debugstr_w(szOut),dwReturn);
1942 return dwReturn;
1945 /**************************************************************************
1947 * ### 4. getting pointers to parts of pidls ###
1949 **************************************************************************
1950 * _ILGetDataPointer()
1952 LPPIDLDATA _ILGetDataPointer(LPCITEMIDLIST pidl)
1954 if(pidl && pidl->mkid.cb != 0x00)
1955 return (LPPIDLDATA) &(pidl->mkid.abID);
1956 return NULL;
1959 /**************************************************************************
1960 * _ILGetTextPointer()
1961 * gets a pointer to the long filename string stored in the pidl
1963 LPSTR _ILGetTextPointer(LPCITEMIDLIST pidl)
1964 {/* TRACE(pidl,"(pidl%p)\n", pidl);*/
1966 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
1968 if (pdata)
1970 switch (pdata->type)
1972 case PT_MYCOMP:
1973 case PT_SPECIAL:
1974 return NULL;
1976 case PT_DRIVE:
1977 case PT_DRIVE1:
1978 case PT_DRIVE2:
1979 case PT_DRIVE3:
1980 return (LPSTR)&(pdata->u.drive.szDriveName);
1982 case PT_FOLDER:
1983 case PT_FOLDER1:
1984 case PT_VALUE:
1985 case PT_IESPECIAL1:
1986 case PT_RAS_FOLDER:
1987 case PT_IESPECIAL2:
1988 return (LPSTR)&(pdata->u.file.szNames);
1990 case PT_WORKGRP:
1991 case PT_COMP:
1992 case PT_NETWORK:
1993 case PT_NETPROVIDER:
1994 case PT_SHARE:
1995 return (LPSTR)&(pdata->u.network.szNames);
1998 return NULL;
2001 /**************************************************************************
2002 * _ILGetSTextPointer()
2003 * gets a pointer to the short filename string stored in the pidl
2005 LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl)
2006 {/* TRACE(pidl,"(pidl%p)\n", pidl);*/
2008 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
2010 if (pdata)
2012 switch (pdata->type)
2014 case PT_FOLDER:
2015 case PT_VALUE:
2016 case PT_IESPECIAL1:
2017 case PT_RAS_FOLDER:
2018 case PT_IESPECIAL2:
2019 return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1);
2021 case PT_WORKGRP:
2022 return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1);
2025 return NULL;
2028 /**************************************************************************
2029 * _ILGetGUIDPointer()
2031 * returns reference to guid stored in some pidls
2033 REFIID _ILGetGUIDPointer(LPCITEMIDLIST pidl)
2035 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
2037 TRACE("%p\n", pidl);
2039 if (pdata)
2041 TRACE("pdata->type 0x%04x\n", pdata->type);
2042 switch (pdata->type)
2044 case PT_SPECIAL:
2045 case PT_MYCOMP:
2046 return (REFIID) &(pdata->u.mycomp.guid);
2048 default:
2049 TRACE("Unknown pidl type 0x%04x\n", pdata->type);
2050 break;
2053 return NULL;
2056 /*************************************************************************
2057 * _ILGetFileDateTime
2059 * Given the ItemIdList, get the FileTime
2061 * PARAMS
2062 * pidl [I] The ItemIDList
2063 * pFt [I] the resulted FILETIME of the file
2065 * RETURNS
2066 * True if Successful
2068 * NOTES
2071 BOOL _ILGetFileDateTime(LPCITEMIDLIST pidl, FILETIME *pFt)
2073 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2075 if(! pdata) return FALSE;
2077 switch (pdata->type)
2079 case PT_FOLDER:
2080 DosDateTimeToFileTime(pdata->u.folder.uFileDate, pdata->u.folder.uFileTime, pFt);
2081 break;
2082 case PT_VALUE:
2083 DosDateTimeToFileTime(pdata->u.file.uFileDate, pdata->u.file.uFileTime, pFt);
2084 break;
2085 default:
2086 return FALSE;
2088 return TRUE;
2091 BOOL _ILGetFileDate (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2093 FILETIME ft,lft;
2094 SYSTEMTIME time;
2095 BOOL ret;
2097 if (_ILGetFileDateTime( pidl, &ft )) {
2098 FileTimeToLocalFileTime(&ft, &lft);
2099 FileTimeToSystemTime (&lft, &time);
2100 ret = GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&time, NULL, pOut, uOutSize);
2101 } else {
2102 pOut[0] = '\0';
2103 ret = FALSE;
2105 return ret;
2109 /*************************************************************************
2110 * _ILGetFileSize
2112 * Given the ItemIdList, get the FileSize
2114 * PARAMS
2115 * pidl [I] The ItemIDList
2116 * pOut [I] The buffer to save the result
2117 * uOutsize [I] The size of the buffer
2119 * RETURNS
2120 * The FileSize
2122 * NOTES
2123 * pOut can be null when no string is needed
2126 DWORD _ILGetFileSize (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2128 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2129 DWORD dwSize;
2131 if(! pdata) return 0;
2133 switch (pdata->type)
2135 case PT_VALUE:
2136 dwSize = pdata->u.file.dwFileSize;
2137 if (pOut) StrFormatByteSizeA(dwSize, pOut, uOutSize);
2138 return dwSize;
2140 if (pOut) *pOut = 0x00;
2141 return 0;
2144 BOOL _ILGetExtension (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2146 char szTemp[MAX_PATH];
2147 const char * pPoint;
2148 LPCITEMIDLIST pidlTemp=pidl;
2150 TRACE("pidl=%p\n",pidl);
2152 if (!pidl) return FALSE;
2154 pidlTemp = ILFindLastID(pidl);
2156 if (!_ILIsValue(pidlTemp)) return FALSE;
2157 if (!_ILSimpleGetText(pidlTemp, szTemp, MAX_PATH)) return FALSE;
2159 pPoint = PathFindExtensionA(szTemp);
2161 if (! *pPoint) return FALSE;
2163 pPoint++;
2164 lstrcpynA(pOut, pPoint, uOutSize);
2165 TRACE("%s\n",pOut);
2167 return TRUE;
2170 /*************************************************************************
2171 * _ILGetFileType
2173 * Given the ItemIdList, get the file type description
2175 * PARAMS
2176 * pidl [I] The ItemIDList (simple)
2177 * pOut [I] The buffer to save the result
2178 * uOutsize [I] The size of the buffer
2180 * RETURNS
2181 * nothing
2183 * NOTES
2184 * This function copies as much as possible into the buffer.
2186 void _ILGetFileType(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2188 if(_ILIsValue(pidl))
2190 char sTemp[64];
2191 if(uOutSize > 0)
2193 pOut[0] = 0;
2195 if (_ILGetExtension (pidl, sTemp, 64))
2197 if (!( HCR_MapTypeToValueA(sTemp, sTemp, 64, TRUE)
2198 && HCR_MapTypeToValueA(sTemp, pOut, uOutSize, FALSE )))
2200 lstrcpynA (pOut, sTemp, uOutSize - 6);
2201 strcat (pOut, "-file");
2205 else
2207 lstrcpynA(pOut, "Folder", uOutSize);
2211 /*************************************************************************
2212 * _ILGetFileAttributes
2214 * Given the ItemIdList, get the Attrib string format
2216 * PARAMS
2217 * pidl [I] The ItemIDList
2218 * pOut [I] The buffer to save the result
2219 * uOutsize [I] The size of the Buffer
2221 * RETURNS
2222 * Attributes
2224 * FIXME
2225 * return value 0 in case of error is a valid return value
2228 DWORD _ILGetFileAttributes(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2230 LPPIDLDATA pData = _ILGetDataPointer(pidl);
2231 WORD wAttrib = 0;
2232 int i;
2234 if(! pData) return 0;
2236 switch(pData->type)
2238 case PT_FOLDER:
2239 wAttrib = pData->u.folder.uFileAttribs;
2240 break;
2241 case PT_VALUE:
2242 wAttrib = pData->u.file.uFileAttribs;
2243 break;
2246 if(uOutSize >= 6)
2248 i=0;
2249 if(wAttrib & FILE_ATTRIBUTE_READONLY)
2251 pOut[i++] = 'R';
2253 if(wAttrib & FILE_ATTRIBUTE_HIDDEN)
2255 pOut[i++] = 'H';
2257 if(wAttrib & FILE_ATTRIBUTE_SYSTEM)
2259 pOut[i++] = 'S';
2261 if(wAttrib & FILE_ATTRIBUTE_ARCHIVE)
2263 pOut[i++] = 'A';
2265 if(wAttrib & FILE_ATTRIBUTE_COMPRESSED)
2267 pOut[i++] = 'C';
2269 pOut[i] = 0x00;
2271 return wAttrib;
2274 /*************************************************************************
2275 * ILFreeaPidl
2277 * free a aPidl struct
2279 void _ILFreeaPidl(LPITEMIDLIST * apidl, UINT cidl)
2281 UINT i;
2283 if (apidl)
2285 for (i = 0; i < cidl; i++) SHFree(apidl[i]);
2286 SHFree(apidl);
2290 /*************************************************************************
2291 * ILCopyaPidl
2293 * copies an aPidl struct
2295 LPITEMIDLIST* _ILCopyaPidl(LPCITEMIDLIST * apidlsrc, UINT cidl)
2297 UINT i;
2298 LPITEMIDLIST * apidldest = (LPITEMIDLIST*)SHAlloc(cidl * sizeof(LPITEMIDLIST));
2299 if(!apidlsrc) return NULL;
2301 for (i = 0; i < cidl; i++)
2302 apidldest[i] = ILClone(apidlsrc[i]);
2304 return apidldest;
2307 /*************************************************************************
2308 * _ILCopyCidaToaPidl
2310 * creates aPidl from CIDA
2312 LPITEMIDLIST* _ILCopyCidaToaPidl(LPITEMIDLIST* pidl, LPIDA cida)
2314 UINT i;
2315 LPITEMIDLIST * dst = (LPITEMIDLIST*)SHAlloc(cida->cidl * sizeof(LPITEMIDLIST));
2317 if(!dst) return NULL;
2319 if (pidl)
2320 *pidl = ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[0]]));
2322 for (i = 0; i < cida->cidl; i++)
2323 dst[i] = ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[i + 1]]));
2325 return dst;