push 378fe7a60681a28e8b22f62dcfe122d585b92570
[wine/hacks.git] / dlls / shell32 / pidl.c
blob5dc07a1e4ebfcdc44adf3a9dcb7e706d9c06c291
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 static LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl);
59 static LPWSTR _ILGetTextPointerW(LPCITEMIDLIST pidl);
61 /*************************************************************************
62 * ILGetDisplayNameEx [SHELL32.186]
64 * Retrieves the display name of an ItemIDList
66 * PARAMS
67 * psf [I] Shell Folder to start with, if NULL the desktop is used
68 * pidl [I] ItemIDList relative to the psf to get the display name for
69 * path [O] Filled in with the display name, assumed to be at least MAX_PATH long
70 * type [I] Type of display name to retrieve
71 * 0 = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR uses always the desktop as root
72 * 1 = SHGDN_NORMAL relative to the root folder
73 * 2 = SHGDN_INFOLDER relative to the root folder, only the last name
75 * RETURNS
76 * True if the display name could be retrieved successfully, False otherwise
78 BOOL WINAPI ILGetDisplayNameExA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPSTR path, DWORD type)
80 BOOL ret = FALSE;
81 WCHAR wPath[MAX_PATH];
83 TRACE("%p %p %p %d\n", psf, pidl, path, type);
85 if (!pidl || !path)
86 return FALSE;
88 ret = ILGetDisplayNameExW(psf, pidl, wPath, type);
89 WideCharToMultiByte(CP_ACP, 0, wPath, -1, path, MAX_PATH, NULL, NULL);
90 TRACE("%p %p %s\n", psf, pidl, debugstr_a(path));
92 return ret;
95 BOOL WINAPI ILGetDisplayNameExW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPWSTR path, DWORD type)
97 LPSHELLFOLDER psfParent, lsf = psf;
98 HRESULT ret = NO_ERROR;
99 LPCITEMIDLIST pidllast;
100 STRRET strret;
101 DWORD flag;
103 TRACE("%p %p %p %x\n", psf, pidl, path, type);
105 if (!pidl || !path)
106 return FALSE;
108 if (!lsf)
110 ret = SHGetDesktopFolder(&lsf);
111 if (FAILED(ret))
112 return FALSE;
115 switch (type)
117 case ILGDN_FORPARSING:
118 flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
119 break;
120 case ILGDN_NORMAL:
121 flag = SHGDN_NORMAL;
122 break;
123 case ILGDN_INFOLDER:
124 flag = SHGDN_INFOLDER;
125 break;
126 default:
127 FIXME("Unknown type parameter = %x\n", type);
128 flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
129 break;
132 if (!*(const WORD*)pidl || type == ILGDN_FORPARSING)
134 ret = IShellFolder_GetDisplayNameOf(lsf, pidl, flag, &strret);
135 if (SUCCEEDED(ret))
137 if(!StrRetToStrNW(path, MAX_PATH, &strret, pidl))
138 ret = E_FAIL;
141 else
143 ret = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psfParent, &pidllast);
144 if (SUCCEEDED(ret))
146 ret = IShellFolder_GetDisplayNameOf(psfParent, pidllast, flag, &strret);
147 if (SUCCEEDED(ret))
149 if(!StrRetToStrNW(path, MAX_PATH, &strret, pidllast))
150 ret = E_FAIL;
152 IShellFolder_Release(psfParent);
156 TRACE("%p %p %s\n", psf, pidl, debugstr_w(path));
158 if (!psf)
159 IShellFolder_Release(lsf);
160 return SUCCEEDED(ret);
163 BOOL WINAPI ILGetDisplayNameEx(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPVOID path, DWORD type)
165 TRACE_(shell)("%p %p %p %d\n", psf, pidl, path, type);
167 if (SHELL_OsIsUnicode())
168 return ILGetDisplayNameExW(psf, pidl, path, type);
169 return ILGetDisplayNameExA(psf, pidl, path, type);
172 /*************************************************************************
173 * ILGetDisplayName [SHELL32.15]
175 BOOL WINAPI ILGetDisplayName(LPCITEMIDLIST pidl, LPVOID path)
177 TRACE_(shell)("%p %p\n", pidl, path);
179 if (SHELL_OsIsUnicode())
180 return ILGetDisplayNameExW(NULL, pidl, path, ILGDN_FORPARSING);
181 return ILGetDisplayNameExA(NULL, pidl, path, ILGDN_FORPARSING);
184 /*************************************************************************
185 * ILFindLastID [SHELL32.16]
187 * NOTES
188 * observed: pidl=Desktop return=pidl
190 LPITEMIDLIST WINAPI ILFindLastID(LPCITEMIDLIST pidl)
192 LPCITEMIDLIST pidlLast = pidl;
194 TRACE("(pidl=%p)\n",pidl);
196 if (!pidl)
197 return NULL;
199 while (pidl->mkid.cb)
201 pidlLast = pidl;
202 pidl = ILGetNext(pidl);
204 return (LPITEMIDLIST)pidlLast;
207 /*************************************************************************
208 * ILRemoveLastID [SHELL32.17]
210 * NOTES
211 * when pidl=Desktop return=FALSE
213 BOOL WINAPI ILRemoveLastID(LPITEMIDLIST pidl)
215 TRACE_(shell)("pidl=%p\n",pidl);
217 if (!pidl || !pidl->mkid.cb)
218 return 0;
219 ILFindLastID(pidl)->mkid.cb = 0;
220 return 1;
223 /*************************************************************************
224 * ILClone [SHELL32.18]
226 * NOTES
227 * duplicate an idlist
229 LPITEMIDLIST WINAPI ILClone (LPCITEMIDLIST pidl)
231 DWORD len;
232 LPITEMIDLIST newpidl;
234 if (!pidl)
235 return NULL;
237 len = ILGetSize(pidl);
238 newpidl = SHAlloc(len);
239 if (newpidl)
240 memcpy(newpidl,pidl,len);
242 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
243 pdump(pidl);
245 return newpidl;
248 /*************************************************************************
249 * ILCloneFirst [SHELL32.19]
251 * NOTES
252 * duplicates the first idlist of a complex pidl
254 LPITEMIDLIST WINAPI ILCloneFirst(LPCITEMIDLIST pidl)
256 DWORD len;
257 LPITEMIDLIST pidlNew = NULL;
259 TRACE("pidl=%p\n", pidl);
260 pdump(pidl);
262 if (pidl)
264 len = pidl->mkid.cb;
265 pidlNew = SHAlloc(len+2);
266 if (pidlNew)
268 memcpy(pidlNew,pidl,len+2); /* 2 -> mind a desktop pidl */
270 if (len)
271 ILGetNext(pidlNew)->mkid.cb = 0x00;
274 TRACE("-- newpidl=%p\n",pidlNew);
276 return pidlNew;
279 /*************************************************************************
280 * ILLoadFromStream (SHELL32.26)
282 * NOTES
283 * the first two bytes are the len, the pidl is following then
285 HRESULT WINAPI ILLoadFromStream (IStream * pStream, LPITEMIDLIST * ppPidl)
287 WORD wLen = 0;
288 DWORD dwBytesRead;
289 HRESULT ret = E_FAIL;
292 TRACE_(shell)("%p %p\n", pStream , ppPidl);
294 SHFree(*ppPidl);
295 *ppPidl = NULL;
297 IStream_AddRef (pStream);
299 if (SUCCEEDED(IStream_Read(pStream, (LPVOID)&wLen, 2, &dwBytesRead)))
301 TRACE("PIDL length is %d\n", wLen);
302 if (wLen != 0)
304 *ppPidl = SHAlloc (wLen);
305 if (SUCCEEDED(IStream_Read(pStream, *ppPidl , wLen, &dwBytesRead)))
307 TRACE("Stream read OK\n");
308 ret = S_OK;
310 else
312 WARN("reading pidl failed\n");
313 SHFree(*ppPidl);
314 *ppPidl = NULL;
317 else
319 *ppPidl = NULL;
320 ret = S_OK;
324 /* we are not yet fully compatible */
325 if (*ppPidl && !pcheck(*ppPidl))
327 WARN("Check failed\n");
328 SHFree(*ppPidl);
329 *ppPidl = NULL;
332 IStream_Release (pStream);
333 TRACE("done\n");
334 return ret;
337 /*************************************************************************
338 * ILSaveToStream (SHELL32.27)
340 * NOTES
341 * the first two bytes are the len, the pidl is following then
343 HRESULT WINAPI ILSaveToStream (IStream * pStream, LPCITEMIDLIST pPidl)
345 WORD wLen = 0;
346 HRESULT ret = E_FAIL;
348 TRACE_(shell)("%p %p\n", pStream, pPidl);
350 IStream_AddRef (pStream);
352 wLen = ILGetSize(pPidl);
354 if (SUCCEEDED(IStream_Write(pStream, (LPVOID)&wLen, 2, NULL)))
356 if (SUCCEEDED(IStream_Write(pStream, pPidl, wLen, NULL)))
357 ret = S_OK;
359 IStream_Release (pStream);
361 return ret;
364 /*************************************************************************
365 * SHILCreateFromPath [SHELL32.28]
367 * Create an ItemIDList from a path
369 * PARAMS
370 * path [I]
371 * ppidl [O]
372 * attributes [I/O] requested attributes on call and actual attributes when
373 * the function returns
375 * RETURNS
376 * NO_ERROR if successful, or an OLE errer code otherwise
378 * NOTES
379 * Wrapper for IShellFolder_ParseDisplayName().
381 HRESULT WINAPI SHILCreateFromPathA(LPCSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
383 WCHAR lpszDisplayName[MAX_PATH];
385 TRACE_(shell)("%s %p 0x%08x\n", path, ppidl, attributes ? *attributes : 0);
387 if (!MultiByteToWideChar(CP_ACP, 0, path, -1, lpszDisplayName, MAX_PATH))
388 lpszDisplayName[MAX_PATH-1] = 0;
390 return SHILCreateFromPathW(lpszDisplayName, ppidl, attributes);
393 HRESULT WINAPI SHILCreateFromPathW(LPCWSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
395 LPSHELLFOLDER sf;
396 DWORD pchEaten;
397 HRESULT ret = E_FAIL;
399 TRACE_(shell)("%s %p 0x%08x\n", debugstr_w(path), ppidl, attributes ? *attributes : 0);
401 if (SUCCEEDED (SHGetDesktopFolder(&sf)))
403 ret = IShellFolder_ParseDisplayName(sf, 0, NULL, (LPWSTR)path, &pchEaten, ppidl, attributes);
404 IShellFolder_Release(sf);
406 return ret;
409 HRESULT WINAPI SHILCreateFromPathAW (LPCVOID path, LPITEMIDLIST * ppidl, DWORD * attributes)
411 if ( SHELL_OsIsUnicode())
412 return SHILCreateFromPathW (path, ppidl, attributes);
413 return SHILCreateFromPathA (path, ppidl, attributes);
416 /*************************************************************************
417 * SHCloneSpecialIDList [SHELL32.89]
419 * Create an ItemIDList to one of the special folders.
421 * PARAMS
422 * hwndOwner [in]
423 * nFolder [in] CSIDL_xxxxx
424 * fCreate [in] Create folder if it does not exist
426 * RETURNS
427 * Success: The newly created pidl
428 * Failure: NULL, if inputs are invalid.
430 * NOTES
431 * exported by ordinal.
432 * Caller is responsible for deallocating the returned ItemIDList with the
433 * shells IMalloc interface, aka ILFree.
435 LPITEMIDLIST WINAPI SHCloneSpecialIDList(HWND hwndOwner, DWORD nFolder, BOOL fCreate)
437 LPITEMIDLIST ppidl;
438 TRACE_(shell)("(hwnd=%p,csidl=0x%x,%s).\n", hwndOwner, nFolder, fCreate ? "T" : "F");
440 if (fCreate)
441 nFolder |= CSIDL_FLAG_CREATE;
443 SHGetSpecialFolderLocation(hwndOwner, nFolder, &ppidl);
444 return ppidl;
447 /*************************************************************************
448 * ILGlobalClone [SHELL32.20]
450 * Clones an ItemIDList using Alloc.
452 * PARAMS
453 * pidl [I] ItemIDList to clone
455 * RETURNS
456 * Newly allocated ItemIDList.
458 * NOTES
459 * exported by ordinal.
461 LPITEMIDLIST WINAPI ILGlobalClone(LPCITEMIDLIST pidl)
463 DWORD len;
464 LPITEMIDLIST newpidl;
466 if (!pidl)
467 return NULL;
469 len = ILGetSize(pidl);
470 newpidl = Alloc(len);
471 if (newpidl)
472 memcpy(newpidl,pidl,len);
474 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
475 pdump(pidl);
477 return newpidl;
480 /*************************************************************************
481 * ILIsEqual [SHELL32.21]
484 BOOL WINAPI ILIsEqual(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
486 char szData1[MAX_PATH];
487 char szData2[MAX_PATH];
489 LPCITEMIDLIST pidltemp1 = pidl1;
490 LPCITEMIDLIST pidltemp2 = pidl2;
492 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
495 * Explorer reads from registry directly (StreamMRU),
496 * so we can only check here
498 if (!pcheck(pidl1) || !pcheck (pidl2))
499 return FALSE;
501 pdump (pidl1);
502 pdump (pidl2);
504 if (!pidl1 || !pidl2)
505 return FALSE;
507 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
509 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
510 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
512 if (strcasecmp( szData1, szData2 ))
513 return FALSE;
515 pidltemp1 = ILGetNext(pidltemp1);
516 pidltemp2 = ILGetNext(pidltemp2);
519 if (!pidltemp1->mkid.cb && !pidltemp2->mkid.cb)
520 return TRUE;
522 return FALSE;
525 /*************************************************************************
526 * ILIsParent [SHELL32.23]
528 * Verifies that pidlParent is indeed the (immediate) parent of pidlChild.
530 * PARAMS
531 * pidlParent [I]
532 * pidlChild [I]
533 * bImmediate [I] only return true if the parent is the direct parent
534 * of the child
536 * RETURNS
537 * True if the parent ItemIDlist is a complete part of the child ItemIdList,
538 * False otherwise.
540 * NOTES
541 * parent = a/b, child = a/b/c -> true, c is in folder a/b
542 * child = a/b/c/d -> false if bImmediate is true, d is not in folder a/b
543 * child = a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
545 BOOL WINAPI ILIsParent(LPCITEMIDLIST pidlParent, LPCITEMIDLIST pidlChild, BOOL bImmediate)
547 char szData1[MAX_PATH];
548 char szData2[MAX_PATH];
549 LPCITEMIDLIST pParent = pidlParent;
550 LPCITEMIDLIST pChild = pidlChild;
552 TRACE("%p %p %x\n", pidlParent, pidlChild, bImmediate);
554 if (!pParent || !pChild)
555 return FALSE;
557 while (pParent->mkid.cb && pChild->mkid.cb)
559 _ILSimpleGetText(pParent, szData1, MAX_PATH);
560 _ILSimpleGetText(pChild, szData2, MAX_PATH);
562 if (strcasecmp( szData1, szData2 ))
563 return FALSE;
565 pParent = ILGetNext(pParent);
566 pChild = ILGetNext(pChild);
569 /* child shorter or has equal length to parent */
570 if (pParent->mkid.cb || !pChild->mkid.cb)
571 return FALSE;
573 /* not immediate descent */
574 if ( ILGetNext(pChild)->mkid.cb && bImmediate)
575 return FALSE;
577 return TRUE;
580 /*************************************************************************
581 * ILFindChild [SHELL32.24]
583 * Compares elements from pidl1 and pidl2.
585 * PARAMS
586 * pidl1 [I]
587 * pidl2 [I]
589 * RETURNS
590 * pidl1 is desktop pidl2
591 * pidl1 shorter pidl2 pointer to first different element of pidl2
592 * if there was at least one equal element
593 * pidl2 shorter pidl1 0
594 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
596 * NOTES
597 * exported by ordinal.
599 LPITEMIDLIST WINAPI ILFindChild(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
601 char szData1[MAX_PATH];
602 char szData2[MAX_PATH];
604 LPCITEMIDLIST pidltemp1 = pidl1;
605 LPCITEMIDLIST pidltemp2 = pidl2;
606 LPCITEMIDLIST ret=NULL;
608 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
610 /* explorer reads from registry directly (StreamMRU),
611 so we can only check here */
612 if ((!pcheck (pidl1)) || (!pcheck (pidl2)))
613 return FALSE;
615 pdump (pidl1);
616 pdump (pidl2);
618 if (_ILIsDesktop(pidl1))
620 ret = pidl2;
622 else
624 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
626 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
627 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
629 if (strcasecmp(szData1,szData2))
630 break;
632 pidltemp1 = ILGetNext(pidltemp1);
633 pidltemp2 = ILGetNext(pidltemp2);
634 ret = pidltemp2;
637 if (pidltemp1->mkid.cb)
638 ret = NULL; /* elements of pidl1 left*/
640 TRACE_(shell)("--- %p\n", ret);
641 return (LPITEMIDLIST)ret; /* pidl 1 is shorter */
644 /*************************************************************************
645 * ILCombine [SHELL32.25]
647 * Concatenates two complex ItemIDLists.
649 * PARAMS
650 * pidl1 [I] first complex ItemIDLists
651 * pidl2 [I] complex ItemIDLists to append
653 * RETURNS
654 * if both pidl's == NULL NULL
655 * if pidl1 == NULL cloned pidl2
656 * if pidl2 == NULL cloned pidl1
657 * otherwise new pidl with pidl2 appended to pidl1
659 * NOTES
660 * exported by ordinal.
661 * Does not destroy the passed in ItemIDLists!
663 LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
665 DWORD len1,len2;
666 LPITEMIDLIST pidlNew;
668 TRACE("pidl=%p pidl=%p\n",pidl1,pidl2);
670 if (!pidl1 && !pidl2) return NULL;
672 pdump (pidl1);
673 pdump (pidl2);
675 if (!pidl1)
677 pidlNew = ILClone(pidl2);
678 return pidlNew;
681 if (!pidl2)
683 pidlNew = ILClone(pidl1);
684 return pidlNew;
687 len1 = ILGetSize(pidl1)-2;
688 len2 = ILGetSize(pidl2);
689 pidlNew = SHAlloc(len1+len2);
691 if (pidlNew)
693 memcpy(pidlNew,pidl1,len1);
694 memcpy(((BYTE *)pidlNew)+len1,pidl2,len2);
697 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
698 return pidlNew;
701 /*************************************************************************
702 * SHGetRealIDL [SHELL32.98]
704 * NOTES
706 HRESULT WINAPI SHGetRealIDL(LPSHELLFOLDER lpsf, LPCITEMIDLIST pidlSimple, LPITEMIDLIST *pidlReal)
708 IDataObject* pDataObj;
709 HRESULT hr;
711 hr = IShellFolder_GetUIObjectOf(lpsf, 0, 1, &pidlSimple,
712 &IID_IDataObject, 0, (LPVOID*)&pDataObj);
713 if (SUCCEEDED(hr))
715 STGMEDIUM medium;
716 FORMATETC fmt;
718 fmt.cfFormat = RegisterClipboardFormatW(CFSTR_SHELLIDLISTW);
719 fmt.ptd = NULL;
720 fmt.dwAspect = DVASPECT_CONTENT;
721 fmt.lindex = -1;
722 fmt.tymed = TYMED_HGLOBAL;
724 hr = IDataObject_GetData(pDataObj, &fmt, &medium);
726 IDataObject_Release(pDataObj);
728 if (SUCCEEDED(hr))
730 /*assert(pida->cidl==1);*/
731 LPIDA pida = GlobalLock(medium.u.hGlobal);
733 LPCITEMIDLIST pidl_folder = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[0]);
734 LPCITEMIDLIST pidl_child = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[1]);
736 *pidlReal = ILCombine(pidl_folder, pidl_child);
738 if (!*pidlReal)
739 hr = E_OUTOFMEMORY;
741 GlobalUnlock(medium.u.hGlobal);
742 GlobalFree(medium.u.hGlobal);
746 return hr;
749 /*************************************************************************
750 * SHLogILFromFSIL [SHELL32.95]
752 * NOTES
753 * pild = CSIDL_DESKTOP ret = 0
754 * pild = CSIDL_DRIVES ret = 0
756 LPITEMIDLIST WINAPI SHLogILFromFSIL(LPITEMIDLIST pidl)
758 FIXME("(pidl=%p)\n",pidl);
760 pdump(pidl);
762 return 0;
765 /*************************************************************************
766 * ILGetSize [SHELL32.152]
768 * Gets the byte size of an ItemIDList including zero terminator
770 * PARAMS
771 * pidl [I] ItemIDList
773 * RETURNS
774 * size of pidl in bytes
776 * NOTES
777 * exported by ordinal
779 UINT WINAPI ILGetSize(LPCITEMIDLIST pidl)
781 LPCSHITEMID si = &(pidl->mkid);
782 UINT len=0;
784 if (pidl)
786 while (si->cb)
788 len += si->cb;
789 si = (LPCSHITEMID)(((const BYTE*)si)+si->cb);
791 len += 2;
793 TRACE("pidl=%p size=%u\n",pidl, len);
794 return len;
797 /*************************************************************************
798 * ILGetNext [SHELL32.153]
800 * Gets the next ItemID of an ItemIDList
802 * PARAMS
803 * pidl [I] ItemIDList
805 * RETURNS
806 * null -> null
807 * desktop -> null
808 * simple pidl -> pointer to 0x0000 element
810 * NOTES
811 * exported by ordinal.
813 LPITEMIDLIST WINAPI ILGetNext(LPCITEMIDLIST pidl)
815 WORD len;
817 TRACE("%p\n", pidl);
819 if (pidl)
821 len = pidl->mkid.cb;
822 if (len)
824 pidl = (LPCITEMIDLIST) (((const BYTE*)pidl)+len);
825 TRACE("-- %p\n", pidl);
826 return (LPITEMIDLIST)pidl;
829 return NULL;
832 /*************************************************************************
833 * ILAppend [SHELL32.154]
835 * Adds the single ItemID item to the ItemIDList indicated by pidl.
836 * If bEnd is FALSE, inserts the item in the front of the list,
837 * otherwise it adds the item to the end. (???)
839 * PARAMS
840 * pidl [I] ItemIDList to extend
841 * item [I] ItemID to prepend/append
842 * bEnd [I] Indicates if the item should be appended
844 * NOTES
845 * Destroys the passed in idlist! (???)
847 LPITEMIDLIST WINAPI ILAppend(LPITEMIDLIST pidl, LPCITEMIDLIST item, BOOL bEnd)
849 LPITEMIDLIST idlRet;
851 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl,item,bEnd);
853 pdump (pidl);
854 pdump (item);
856 if (_ILIsDesktop(pidl))
858 idlRet = ILClone(item);
859 SHFree (pidl);
860 return idlRet;
863 if (bEnd)
864 idlRet = ILCombine(pidl, item);
865 else
866 idlRet = ILCombine(item, pidl);
868 SHFree(pidl);
869 return idlRet;
872 /*************************************************************************
873 * ILFree [SHELL32.155]
875 * Frees memory (if not NULL) allocated by SHMalloc allocator
877 * PARAMS
878 * pidl [I]
880 * RETURNS
881 * Nothing
883 * NOTES
884 * exported by ordinal
886 void WINAPI ILFree(LPITEMIDLIST pidl)
888 TRACE("(pidl=%p)\n",pidl);
889 SHFree(pidl);
892 /*************************************************************************
893 * ILGlobalFree [SHELL32.156]
895 * Frees memory (if not NULL) allocated by Alloc allocator
897 * PARAMS
898 * pidl [I]
900 * RETURNS
901 * Nothing
903 * NOTES
904 * exported by ordinal.
906 void WINAPI ILGlobalFree( LPITEMIDLIST pidl)
908 TRACE("%p\n", pidl);
910 Free(pidl);
913 /*************************************************************************
914 * ILCreateFromPathA [SHELL32.189]
916 * Creates a complex ItemIDList from a path and returns it.
918 * PARAMS
919 * path [I]
921 * RETURNS
922 * the newly created complex ItemIDList or NULL if failed
924 * NOTES
925 * exported by ordinal.
927 LPITEMIDLIST WINAPI ILCreateFromPathA (LPCSTR path)
929 LPITEMIDLIST pidlnew = NULL;
931 TRACE_(shell)("%s\n", debugstr_a(path));
933 if (SUCCEEDED(SHILCreateFromPathA(path, &pidlnew, NULL)))
934 return pidlnew;
935 return NULL;
938 /*************************************************************************
939 * ILCreateFromPathW [SHELL32.190]
941 * See ILCreateFromPathA.
943 LPITEMIDLIST WINAPI ILCreateFromPathW (LPCWSTR path)
945 LPITEMIDLIST pidlnew = NULL;
947 TRACE_(shell)("%s\n", debugstr_w(path));
949 if (SUCCEEDED(SHILCreateFromPathW(path, &pidlnew, NULL)))
950 return pidlnew;
951 return NULL;
954 /*************************************************************************
955 * ILCreateFromPath [SHELL32.157]
957 LPITEMIDLIST WINAPI ILCreateFromPathAW (LPCVOID path)
959 if ( SHELL_OsIsUnicode())
960 return ILCreateFromPathW (path);
961 return ILCreateFromPathA (path);
964 /*************************************************************************
965 * _ILParsePathW [internal]
967 * Creates an ItemIDList from a path and returns it.
969 * PARAMS
970 * path [I] path to parse and convert into an ItemIDList
971 * lpFindFile [I] pointer to buffer to initialize the FileSystem
972 * Bind Data object with
973 * bBindCtx [I] indicates to create a BindContext and assign a
974 * FileSystem Bind Data object
975 * ppidl [O] the newly create ItemIDList
976 * prgfInOut [I/O] requested attributes on input and actual
977 * attributes on return
979 * RETURNS
980 * NO_ERROR on success or an OLE error code
982 * NOTES
983 * If either lpFindFile is non-NULL or bBindCtx is TRUE, this function
984 * creates a BindContext object and assigns a FileSystem Bind Data object
985 * to it, passing the BindContext to IShellFolder_ParseDisplayName. Each
986 * IShellFolder uses that FileSystem Bind Data object of the BindContext
987 * to pass data about the current path element to the next object. This
988 * is used to avoid having to verify the current path element on disk, so
989 * that creating an ItemIDList from a nonexistent path still can work.
991 static HRESULT _ILParsePathW(LPCWSTR path, LPWIN32_FIND_DATAW lpFindFile,
992 BOOL bBindCtx, LPITEMIDLIST *ppidl, LPDWORD prgfInOut)
994 LPSHELLFOLDER pSF = NULL;
995 LPBC pBC = NULL;
996 HRESULT ret;
998 TRACE("%s %p %d (%p)->%p (%p)->0x%x\n", debugstr_w(path), lpFindFile, bBindCtx,
999 ppidl, ppidl ? *ppidl : NULL,
1000 prgfInOut, prgfInOut ? *prgfInOut : 0);
1002 ret = SHGetDesktopFolder(&pSF);
1003 if (FAILED(ret))
1004 return ret;
1006 if (lpFindFile || bBindCtx)
1007 ret = IFileSystemBindData_Constructor(lpFindFile, &pBC);
1009 if (SUCCEEDED(ret))
1011 ret = IShellFolder_ParseDisplayName(pSF, 0, pBC, (LPOLESTR)path, NULL, ppidl, prgfInOut);
1014 if (pBC)
1016 IBindCtx_Release(pBC);
1017 pBC = NULL;
1020 IShellFolder_Release(pSF);
1022 if (FAILED(ret) && ppidl)
1023 *ppidl = NULL;
1025 TRACE("%s %p 0x%x\n", debugstr_w(path), ppidl ? *ppidl : NULL, prgfInOut ? *prgfInOut : 0);
1027 return ret;
1030 /*************************************************************************
1031 * SHSimpleIDListFromPath [SHELL32.162]
1033 * Creates a simple ItemIDList from a path and returns it. This function
1034 * does not fail on nonexistent paths.
1036 * PARAMS
1037 * path [I] path to parse and convert into an ItemIDList
1039 * RETURNS
1040 * the newly created simple ItemIDList
1042 * NOTES
1043 * Simple in the name does not mean a relative ItemIDList but rather a
1044 * fully qualified list, where only the file name is filled in and the
1045 * directory flag for those ItemID elements this is known about, eg.
1046 * it is not the last element in the ItemIDList or the actual directory
1047 * exists on disk.
1048 * exported by ordinal.
1050 LPITEMIDLIST WINAPI SHSimpleIDListFromPathA(LPCSTR lpszPath)
1052 LPITEMIDLIST pidl = NULL;
1053 LPWSTR wPath = NULL;
1054 int len;
1056 TRACE("%s\n", debugstr_a(lpszPath));
1058 if (lpszPath)
1060 len = MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, NULL, 0);
1061 wPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1062 MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, wPath, len);
1065 _ILParsePathW(wPath, NULL, TRUE, &pidl, NULL);
1067 HeapFree(GetProcessHeap(), 0, wPath);
1068 TRACE("%s %p\n", debugstr_a(lpszPath), pidl);
1069 return pidl;
1072 LPITEMIDLIST WINAPI SHSimpleIDListFromPathW(LPCWSTR lpszPath)
1074 LPITEMIDLIST pidl = NULL;
1076 TRACE("%s\n", debugstr_w(lpszPath));
1078 _ILParsePathW(lpszPath, NULL, TRUE, &pidl, NULL);
1079 TRACE("%s %p\n", debugstr_w(lpszPath), pidl);
1080 return pidl;
1083 LPITEMIDLIST WINAPI SHSimpleIDListFromPathAW(LPCVOID lpszPath)
1085 if ( SHELL_OsIsUnicode())
1086 return SHSimpleIDListFromPathW (lpszPath);
1087 return SHSimpleIDListFromPathA (lpszPath);
1090 /*************************************************************************
1091 * SHGetDataFromIDListA [SHELL32.247]
1093 * NOTES
1094 * the pidl can be a simple one. since we can't get the path out of the pidl
1095 * we have to take all data from the pidl
1097 HRESULT WINAPI SHGetDataFromIDListA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl,
1098 int nFormat, LPVOID dest, int len)
1100 LPSTR filename, shortname;
1101 WIN32_FIND_DATAA * pfd;
1103 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
1105 pdump(pidl);
1106 if (!psf || !dest)
1107 return E_INVALIDARG;
1109 switch (nFormat)
1111 case SHGDFIL_FINDDATA:
1112 pfd = dest;
1114 if (_ILIsDrive(pidl) || _ILIsSpecialFolder(pidl))
1115 return E_INVALIDARG;
1117 if (len < sizeof(WIN32_FIND_DATAA))
1118 return E_INVALIDARG;
1120 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1121 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1122 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1123 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1125 filename = _ILGetTextPointer(pidl);
1126 shortname = _ILGetSTextPointer(pidl);
1128 if (filename)
1129 lstrcpynA(pfd->cFileName, filename, sizeof(pfd->cFileName));
1130 else
1131 pfd->cFileName[0] = '\0';
1133 if (shortname)
1134 lstrcpynA(pfd->cAlternateFileName, shortname, sizeof(pfd->cAlternateFileName));
1135 else
1136 pfd->cAlternateFileName[0] = '\0';
1137 return NOERROR;
1139 case SHGDFIL_NETRESOURCE:
1140 case SHGDFIL_DESCRIPTIONID:
1141 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1142 break;
1144 default:
1145 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1148 return E_INVALIDARG;
1151 /*************************************************************************
1152 * SHGetDataFromIDListW [SHELL32.248]
1155 HRESULT WINAPI SHGetDataFromIDListW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl,
1156 int nFormat, LPVOID dest, int len)
1158 LPSTR filename, shortname;
1159 WIN32_FIND_DATAW * pfd = dest;
1161 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
1163 pdump(pidl);
1165 if (!psf || !dest)
1166 return E_INVALIDARG;
1168 switch (nFormat)
1170 case SHGDFIL_FINDDATA:
1171 pfd = dest;
1173 if (_ILIsDrive(pidl))
1174 return E_INVALIDARG;
1176 if (len < sizeof(WIN32_FIND_DATAW))
1177 return E_INVALIDARG;
1179 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1180 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1181 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1182 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1184 filename = _ILGetTextPointer(pidl);
1185 shortname = _ILGetSTextPointer(pidl);
1187 if (!filename)
1188 pfd->cFileName[0] = '\0';
1189 else if (!MultiByteToWideChar(CP_ACP, 0, filename, -1, pfd->cFileName, MAX_PATH))
1190 pfd->cFileName[MAX_PATH-1] = 0;
1192 if (!shortname)
1193 pfd->cAlternateFileName[0] = '\0';
1194 else if (!MultiByteToWideChar(CP_ACP, 0, shortname, -1, pfd->cAlternateFileName, 14))
1195 pfd->cAlternateFileName[13] = 0;
1196 return NOERROR;
1198 case SHGDFIL_NETRESOURCE:
1199 case SHGDFIL_DESCRIPTIONID:
1200 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1201 break;
1203 default:
1204 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1207 return E_INVALIDARG;
1210 /*************************************************************************
1211 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
1213 * PARAMETERS
1214 * pidl, [IN] pidl
1215 * pszPath [OUT] path
1217 * RETURNS
1218 * path from a passed PIDL.
1220 * NOTES
1221 * NULL returns FALSE
1222 * desktop pidl gives path to desktop directory back
1223 * special pidls returning FALSE
1225 BOOL WINAPI SHGetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath)
1227 WCHAR wszPath[MAX_PATH];
1228 BOOL bSuccess;
1230 bSuccess = SHGetPathFromIDListW(pidl, wszPath);
1231 WideCharToMultiByte(CP_ACP, 0, wszPath, -1, pszPath, MAX_PATH, NULL, NULL);
1233 return bSuccess;
1236 /*************************************************************************
1237 * SHGetPathFromIDListW [SHELL32.@]
1239 * See SHGetPathFromIDListA.
1241 BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
1243 HRESULT hr;
1244 LPCITEMIDLIST pidlLast;
1245 LPSHELLFOLDER psfFolder;
1246 DWORD dwAttributes;
1247 STRRET strret;
1249 TRACE_(shell)("(pidl=%p,%p)\n", pidl, pszPath);
1250 pdump(pidl);
1252 *pszPath = '\0';
1253 if (!pidl)
1254 return FALSE;
1256 hr = SHBindToParent(pidl, &IID_IShellFolder, (VOID**)&psfFolder, &pidlLast);
1257 if (FAILED(hr)) return FALSE;
1259 dwAttributes = SFGAO_FILESYSTEM;
1260 hr = IShellFolder_GetAttributesOf(psfFolder, 1, &pidlLast, &dwAttributes);
1261 if (FAILED(hr) || !(dwAttributes & SFGAO_FILESYSTEM)) {
1262 IShellFolder_Release(psfFolder);
1263 return FALSE;
1266 hr = IShellFolder_GetDisplayNameOf(psfFolder, pidlLast, SHGDN_FORPARSING, &strret);
1267 IShellFolder_Release(psfFolder);
1268 if (FAILED(hr)) return FALSE;
1270 hr = StrRetToBufW(&strret, pidlLast, pszPath, MAX_PATH);
1272 TRACE_(shell)("-- %s, 0x%08x\n",debugstr_w(pszPath), hr);
1273 return SUCCEEDED(hr);
1276 /*************************************************************************
1277 * SHBindToParent [shell version 5.0]
1279 HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
1281 IShellFolder * psfDesktop;
1282 HRESULT hr=E_FAIL;
1284 TRACE_(shell)("pidl=%p\n", pidl);
1285 pdump(pidl);
1287 if (!pidl || !ppv)
1288 return E_INVALIDARG;
1290 *ppv = NULL;
1291 if (ppidlLast)
1292 *ppidlLast = NULL;
1294 hr = SHGetDesktopFolder(&psfDesktop);
1295 if (FAILED(hr))
1296 return hr;
1298 if (_ILIsPidlSimple(pidl))
1300 /* we are on desktop level */
1301 hr = IShellFolder_QueryInterface(psfDesktop, riid, ppv);
1303 else
1305 LPITEMIDLIST pidlParent = ILClone(pidl);
1306 ILRemoveLastID(pidlParent);
1307 hr = IShellFolder_BindToObject(psfDesktop, pidlParent, NULL, riid, ppv);
1308 SHFree (pidlParent);
1311 IShellFolder_Release(psfDesktop);
1313 if (SUCCEEDED(hr) && ppidlLast)
1314 *ppidlLast = ILFindLastID(pidl);
1316 TRACE_(shell)("-- psf=%p pidl=%p ret=0x%08x\n", *ppv, (ppidlLast)?*ppidlLast:NULL, hr);
1317 return hr;
1320 /**************************************************************************
1322 * internal functions
1324 * ### 1. section creating pidls ###
1326 *************************************************************************
1329 /* Basic PIDL constructor. Allocates size + 5 bytes, where:
1330 * - two bytes are SHITEMID.cb
1331 * - one byte is PIDLDATA.type
1332 * - two bytes are the NULL PIDL terminator
1333 * Sets type of the returned PIDL to type.
1335 static LPITEMIDLIST _ILAlloc(PIDLTYPE type, unsigned int size)
1337 LPITEMIDLIST pidlOut = NULL;
1339 pidlOut = SHAlloc(size + 5);
1340 if(pidlOut)
1342 LPPIDLDATA pData;
1343 LPITEMIDLIST pidlNext;
1345 ZeroMemory(pidlOut, size + 5);
1346 pidlOut->mkid.cb = size + 3;
1348 pData = _ILGetDataPointer(pidlOut);
1349 if (pData)
1350 pData->type = type;
1352 pidlNext = ILGetNext(pidlOut);
1353 if (pidlNext)
1354 pidlNext->mkid.cb = 0x00;
1355 TRACE("-- (pidl=%p, size=%u)\n", pidlOut, size);
1358 return pidlOut;
1361 LPITEMIDLIST _ILCreateDesktop(void)
1363 LPITEMIDLIST ret;
1365 TRACE("()\n");
1366 ret = SHAlloc(2);
1367 if (ret)
1368 ret->mkid.cb = 0;
1369 return ret;
1372 LPITEMIDLIST _ILCreateMyComputer(void)
1374 TRACE("()\n");
1375 return _ILCreateGuid(PT_GUID, &CLSID_MyComputer);
1378 LPITEMIDLIST _ILCreateMyDocuments(void)
1380 TRACE("()\n");
1381 return _ILCreateGuid(PT_GUID, &CLSID_MyDocuments);
1384 LPITEMIDLIST _ILCreateIExplore(void)
1386 TRACE("()\n");
1387 return _ILCreateGuid(PT_GUID, &CLSID_Internet);
1390 LPITEMIDLIST _ILCreateControlPanel(void)
1392 LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL;
1394 TRACE("()\n");
1395 if (parent)
1397 LPITEMIDLIST cpl = _ILCreateGuid(PT_SHELLEXT, &CLSID_ControlPanel);
1399 if (cpl)
1401 ret = ILCombine(parent, cpl);
1402 SHFree(cpl);
1404 SHFree(parent);
1406 return ret;
1409 LPITEMIDLIST _ILCreatePrinters(void)
1411 LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL;
1413 TRACE("()\n");
1414 if (parent)
1416 LPITEMIDLIST printers = _ILCreateGuid(PT_YAGUID, &CLSID_Printers);
1418 if (printers)
1420 ret = ILCombine(parent, printers);
1421 SHFree(printers);
1423 SHFree(parent);
1425 return ret;
1428 LPITEMIDLIST _ILCreateNetwork(void)
1430 TRACE("()\n");
1431 return _ILCreateGuid(PT_GUID, &CLSID_NetworkPlaces);
1434 LPITEMIDLIST _ILCreateBitBucket(void)
1436 TRACE("()\n");
1437 return _ILCreateGuid(PT_GUID, &CLSID_RecycleBin);
1440 LPITEMIDLIST _ILCreateNetHood(void)
1442 TRACE("()\n");
1443 return _ILCreateGuid(PT_GUID, &CLSID_NetworkPlaces);
1446 LPITEMIDLIST _ILCreateGuid(PIDLTYPE type, REFIID guid)
1448 LPITEMIDLIST pidlOut;
1450 if (type == PT_SHELLEXT || type == PT_GUID || type == PT_YAGUID)
1452 pidlOut = _ILAlloc(type, sizeof(GUIDStruct));
1453 if (pidlOut)
1455 LPPIDLDATA pData = _ILGetDataPointer(pidlOut);
1457 pData->u.guid.guid = *guid;
1458 TRACE("-- create GUID-pidl %s\n",
1459 debugstr_guid(&(pData->u.guid.guid)));
1462 else
1464 WARN("%d: invalid type for GUID\n", type);
1465 pidlOut = NULL;
1467 return pidlOut;
1470 LPITEMIDLIST _ILCreateGuidFromStrA(LPCSTR szGUID)
1472 IID iid;
1474 if (FAILED(SHCLSIDFromStringA(szGUID, &iid)))
1476 ERR("%s is not a GUID\n", szGUID);
1477 return NULL;
1479 return _ILCreateGuid(PT_GUID, &iid);
1482 LPITEMIDLIST _ILCreateGuidFromStrW(LPCWSTR szGUID)
1484 IID iid;
1486 if (FAILED(SHCLSIDFromStringW(szGUID, &iid)))
1488 ERR("%s is not a GUID\n", debugstr_w(szGUID));
1489 return NULL;
1491 return _ILCreateGuid(PT_GUID, &iid);
1494 LPITEMIDLIST _ILCreateFromFindDataW( const WIN32_FIND_DATAW *wfd )
1496 char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1497 DWORD len, len1, wlen, alen;
1498 LPITEMIDLIST pidl;
1499 PIDLTYPE type;
1501 if (!wfd)
1502 return NULL;
1504 TRACE("(%s, %s)\n",debugstr_w(wfd->cAlternateFileName), debugstr_w(wfd->cFileName));
1506 /* prepare buffer with both names */
1507 len = WideCharToMultiByte(CP_ACP,0,wfd->cFileName,-1,buff,MAX_PATH,NULL,NULL);
1508 len1 = WideCharToMultiByte(CP_ACP,0,wfd->cAlternateFileName,-1, buff+len, sizeof(buff)-len, NULL, NULL);
1509 alen = len + len1;
1511 type = (wfd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? PT_FOLDER : PT_VALUE;
1513 wlen = lstrlenW(wfd->cFileName) + 1;
1514 pidl = _ILAlloc(type, FIELD_OFFSET(FileStruct, szNames[alen + (alen & 1)]) +
1515 FIELD_OFFSET(FileStructW, wszName[wlen]) + sizeof(WORD));
1516 if (pidl)
1518 LPPIDLDATA pData = _ILGetDataPointer(pidl);
1519 FileStruct *fs = &pData->u.file;
1520 FileStructW *fsw;
1521 WORD *pOffsetW;
1523 FileTimeToDosDateTime( &wfd->ftLastWriteTime, &fs->uFileDate, &fs->uFileTime);
1524 fs->dwFileSize = wfd->nFileSizeLow;
1525 fs->uFileAttribs = wfd->dwFileAttributes;
1526 memcpy(fs->szNames, buff, alen);
1528 fsw = (FileStructW*)(pData->u.file.szNames + alen + (alen & 0x1));
1529 fsw->cbLen = FIELD_OFFSET(FileStructW, wszName[wlen]) + sizeof(WORD);
1530 FileTimeToDosDateTime( &wfd->ftCreationTime, &fsw->uCreationDate, &fsw->uCreationTime);
1531 FileTimeToDosDateTime( &wfd->ftLastAccessTime, &fsw->uLastAccessDate, &fsw->uLastAccessTime);
1532 memcpy(fsw->wszName, wfd->cFileName, wlen * sizeof(WCHAR));
1534 pOffsetW = (WORD*)((LPBYTE)pidl + pidl->mkid.cb - sizeof(WORD));
1535 *pOffsetW = (LPBYTE)fsw - (LPBYTE)pidl;
1536 TRACE("-- Set Value: %s\n",debugstr_w(fsw->wszName));
1538 return pidl;
1542 HRESULT _ILCreateFromPathW(LPCWSTR szPath, LPITEMIDLIST* ppidl)
1544 HANDLE hFile;
1545 WIN32_FIND_DATAW stffile;
1547 if (!ppidl)
1548 return E_INVALIDARG;
1550 hFile = FindFirstFileW(szPath, &stffile);
1551 if (hFile == INVALID_HANDLE_VALUE)
1552 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
1554 FindClose(hFile);
1556 *ppidl = _ILCreateFromFindDataW(&stffile);
1558 return *ppidl ? S_OK : E_OUTOFMEMORY;
1561 LPITEMIDLIST _ILCreateDrive(LPCWSTR lpszNew)
1563 LPITEMIDLIST pidlOut;
1565 TRACE("(%s)\n",debugstr_w(lpszNew));
1567 pidlOut = _ILAlloc(PT_DRIVE, sizeof(DriveStruct));
1568 if (pidlOut)
1570 LPSTR pszDest;
1572 pszDest = _ILGetTextPointer(pidlOut);
1573 if (pszDest)
1575 strcpy(pszDest, "x:\\");
1576 pszDest[0]=toupperW(lpszNew[0]);
1577 TRACE("-- create Drive: %s\n", debugstr_a(pszDest));
1580 return pidlOut;
1583 LPITEMIDLIST _ILCreateEntireNetwork(void)
1585 LPITEMIDLIST pidlOut;
1587 TRACE("\n");
1589 pidlOut = _ILAlloc(PT_NETWORK, FIELD_OFFSET(PIDLDATA, u.network.szNames[sizeof("Entire Network")]));
1590 if (pidlOut)
1592 LPPIDLDATA pData = _ILGetDataPointer(pidlOut);
1594 pData->u.network.dummy = 0;
1595 strcpy(pData->u.network.szNames, "Entire Network");
1597 return pidlOut;
1600 /**************************************************************************
1601 * _ILGetDrive()
1603 * Gets the text for the drive eg. 'c:\'
1605 * RETURNS
1606 * strlen (lpszText)
1608 DWORD _ILGetDrive(LPCITEMIDLIST pidl,LPSTR pOut, UINT uSize)
1610 TRACE("(%p,%p,%u)\n",pidl,pOut,uSize);
1612 if(_ILIsMyComputer(pidl))
1613 pidl = ILGetNext(pidl);
1615 if (pidl && _ILIsDrive(pidl))
1616 return _ILSimpleGetText(pidl, pOut, uSize);
1618 return 0;
1621 /**************************************************************************
1623 * ### 2. section testing pidls ###
1625 **************************************************************************
1626 * _ILIsUnicode()
1627 * _ILIsDesktop()
1628 * _ILIsMyComputer()
1629 * _ILIsSpecialFolder()
1630 * _ILIsDrive()
1631 * _ILIsFolder()
1632 * _ILIsValue()
1633 * _ILIsPidlSimple()
1635 BOOL _ILIsUnicode(LPCITEMIDLIST pidl)
1637 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1639 TRACE("(%p)\n",pidl);
1641 return (pidl && lpPData && PT_VALUEW == lpPData->type);
1644 BOOL _ILIsDesktop(LPCITEMIDLIST pidl)
1646 TRACE("(%p)\n",pidl);
1648 return pidl && pidl->mkid.cb ? 0 : 1;
1651 BOOL _ILIsMyComputer(LPCITEMIDLIST pidl)
1653 REFIID iid = _ILGetGUIDPointer(pidl);
1655 TRACE("(%p)\n",pidl);
1657 if (iid)
1658 return IsEqualIID(iid, &CLSID_MyComputer);
1659 return FALSE;
1662 BOOL _ILIsSpecialFolder (LPCITEMIDLIST pidl)
1664 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1666 TRACE("(%p)\n",pidl);
1668 return (pidl && ( (lpPData && (PT_GUID== lpPData->type || PT_SHELLEXT== lpPData->type || PT_YAGUID == lpPData->type)) ||
1669 (pidl && pidl->mkid.cb == 0x00)
1673 BOOL _ILIsDrive(LPCITEMIDLIST pidl)
1675 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1677 TRACE("(%p)\n",pidl);
1679 return (pidl && lpPData && (PT_DRIVE == lpPData->type ||
1680 PT_DRIVE1 == lpPData->type ||
1681 PT_DRIVE2 == lpPData->type ||
1682 PT_DRIVE3 == lpPData->type));
1685 BOOL _ILIsFolder(LPCITEMIDLIST pidl)
1687 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1689 TRACE("(%p)\n",pidl);
1691 return (pidl && lpPData && (PT_FOLDER == lpPData->type || PT_FOLDER1 == lpPData->type));
1694 BOOL _ILIsValue(LPCITEMIDLIST pidl)
1696 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1698 TRACE("(%p)\n",pidl);
1700 return (pidl && lpPData && PT_VALUE == lpPData->type);
1703 BOOL _ILIsCPanelStruct(LPCITEMIDLIST pidl)
1705 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1707 TRACE("(%p)\n",pidl);
1709 return (pidl && lpPData && (lpPData->type == 0));
1712 /**************************************************************************
1713 * _ILIsPidlSimple
1715 BOOL _ILIsPidlSimple(LPCITEMIDLIST pidl)
1717 BOOL ret = TRUE;
1719 if(! _ILIsDesktop(pidl)) /* pidl=NULL or mkid.cb=0 */
1721 WORD len = pidl->mkid.cb;
1722 LPCITEMIDLIST pidlnext = (LPCITEMIDLIST) (((const BYTE*)pidl) + len );
1724 if (pidlnext->mkid.cb)
1725 ret = FALSE;
1728 TRACE("%s\n", ret ? "Yes" : "No");
1729 return ret;
1732 /**************************************************************************
1734 * ### 3. section getting values from pidls ###
1737 /**************************************************************************
1738 * _ILSimpleGetText
1740 * gets the text for the first item in the pidl (eg. simple pidl)
1742 * returns the length of the string
1744 DWORD _ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
1746 DWORD dwReturn=0;
1747 LPSTR szSrc;
1748 LPWSTR szSrcW;
1749 GUID const * riid;
1750 char szTemp[MAX_PATH];
1752 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1754 if (!pidl)
1755 return 0;
1757 if (szOut)
1758 *szOut = 0;
1760 if (_ILIsDesktop(pidl))
1762 /* desktop */
1763 if (HCR_GetClassNameA(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1765 if (szOut)
1766 lstrcpynA(szOut, szTemp, uOutSize);
1768 dwReturn = strlen (szTemp);
1771 else if (( szSrc = _ILGetTextPointer(pidl) ))
1773 /* filesystem */
1774 if (szOut)
1775 lstrcpynA(szOut, szSrc, uOutSize);
1777 dwReturn = strlen(szSrc);
1779 else if (( szSrcW = _ILGetTextPointerW(pidl) ))
1781 /* unicode filesystem */
1782 WideCharToMultiByte(CP_ACP,0,szSrcW, -1, szTemp, MAX_PATH, NULL, NULL);
1784 if (szOut)
1785 lstrcpynA(szOut, szTemp, uOutSize);
1787 dwReturn = strlen (szTemp);
1789 else if (( riid = _ILGetGUIDPointer(pidl) ))
1791 /* special folder */
1792 if ( HCR_GetClassNameA(riid, szTemp, MAX_PATH) )
1794 if (szOut)
1795 lstrcpynA(szOut, szTemp, uOutSize);
1797 dwReturn = strlen (szTemp);
1800 else
1802 ERR("-- no text\n");
1805 TRACE("-- (%p=%s 0x%08x)\n",szOut,debugstr_a(szOut),dwReturn);
1806 return dwReturn;
1809 /**************************************************************************
1810 * _ILSimpleGetTextW
1812 * gets the text for the first item in the pidl (eg. simple pidl)
1814 * returns the length of the string
1816 DWORD _ILSimpleGetTextW (LPCITEMIDLIST pidl, LPWSTR szOut, UINT uOutSize)
1818 DWORD dwReturn;
1819 FileStructW *pFileStructW = _ILGetFileStructW(pidl);
1821 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1823 if (pFileStructW) {
1824 lstrcpynW(szOut, pFileStructW->wszName, uOutSize);
1825 dwReturn = lstrlenW(pFileStructW->wszName);
1826 } else {
1827 GUID const * riid;
1828 WCHAR szTemp[MAX_PATH];
1829 LPSTR szSrc;
1830 LPWSTR szSrcW;
1831 dwReturn=0;
1833 if (!pidl)
1834 return 0;
1836 if (szOut)
1837 *szOut = 0;
1839 if (_ILIsDesktop(pidl))
1841 /* desktop */
1842 if (HCR_GetClassNameW(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1844 if (szOut)
1845 lstrcpynW(szOut, szTemp, uOutSize);
1847 dwReturn = lstrlenW (szTemp);
1850 else if (( szSrcW = _ILGetTextPointerW(pidl) ))
1852 /* unicode filesystem */
1853 if (szOut)
1854 lstrcpynW(szOut, szSrcW, uOutSize);
1856 dwReturn = lstrlenW(szSrcW);
1858 else if (( szSrc = _ILGetTextPointer(pidl) ))
1860 /* filesystem */
1861 MultiByteToWideChar(CP_ACP, 0, szSrc, -1, szTemp, MAX_PATH);
1863 if (szOut)
1864 lstrcpynW(szOut, szTemp, uOutSize);
1866 dwReturn = lstrlenW (szTemp);
1868 else if (( riid = _ILGetGUIDPointer(pidl) ))
1870 /* special folder */
1871 if ( HCR_GetClassNameW(riid, szTemp, MAX_PATH) )
1873 if (szOut)
1874 lstrcpynW(szOut, szTemp, uOutSize);
1876 dwReturn = lstrlenW (szTemp);
1879 else
1881 ERR("-- no text\n");
1885 TRACE("-- (%p=%s 0x%08x)\n",szOut,debugstr_w(szOut),dwReturn);
1886 return dwReturn;
1889 /**************************************************************************
1891 * ### 4. getting pointers to parts of pidls ###
1893 **************************************************************************
1894 * _ILGetDataPointer()
1896 LPPIDLDATA _ILGetDataPointer(LPCITEMIDLIST pidl)
1898 if(pidl && pidl->mkid.cb != 0x00)
1899 return (LPPIDLDATA)pidl->mkid.abID;
1900 return NULL;
1903 /**************************************************************************
1904 * _ILGetTextPointerW()
1905 * gets a pointer to the unicode long filename string stored in the pidl
1907 static LPWSTR _ILGetTextPointerW(LPCITEMIDLIST pidl)
1909 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
1911 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
1913 if (!pdata)
1914 return NULL;
1916 switch (pdata->type)
1918 case PT_GUID:
1919 case PT_SHELLEXT:
1920 case PT_YAGUID:
1921 return NULL;
1923 case PT_DRIVE:
1924 case PT_DRIVE1:
1925 case PT_DRIVE2:
1926 case PT_DRIVE3:
1927 /*return (LPSTR)&(pdata->u.drive.szDriveName);*/
1928 return NULL;
1930 case PT_FOLDER:
1931 case PT_FOLDER1:
1932 case PT_VALUE:
1933 case PT_IESPECIAL1:
1934 case PT_IESPECIAL2:
1935 /*return (LPSTR)&(pdata->u.file.szNames);*/
1936 return NULL;
1938 case PT_WORKGRP:
1939 case PT_COMP:
1940 case PT_NETWORK:
1941 case PT_NETPROVIDER:
1942 case PT_SHARE:
1943 /*return (LPSTR)&(pdata->u.network.szNames);*/
1944 return NULL;
1946 case PT_VALUEW:
1947 return (LPWSTR)pdata->u.file.szNames;
1949 return NULL;
1953 /**************************************************************************
1954 * _ILGetTextPointer()
1955 * gets a pointer to the long filename string stored in the pidl
1957 LPSTR _ILGetTextPointer(LPCITEMIDLIST pidl)
1959 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
1961 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
1963 if (!pdata)
1964 return NULL;
1966 switch (pdata->type)
1968 case PT_GUID:
1969 case PT_SHELLEXT:
1970 case PT_YAGUID:
1971 return NULL;
1973 case PT_DRIVE:
1974 case PT_DRIVE1:
1975 case PT_DRIVE2:
1976 case PT_DRIVE3:
1977 return (LPSTR)pdata->u.drive.szDriveName;
1979 case PT_FOLDER:
1980 case PT_FOLDER1:
1981 case PT_VALUE:
1982 case PT_IESPECIAL1:
1983 case PT_IESPECIAL2:
1984 return (LPSTR)pdata->u.file.szNames;
1986 case PT_WORKGRP:
1987 case PT_COMP:
1988 case PT_NETWORK:
1989 case PT_NETPROVIDER:
1990 case PT_SHARE:
1991 return (LPSTR)pdata->u.network.szNames;
1993 return NULL;
1996 /**************************************************************************
1997 * _ILGetSTextPointer()
1998 * gets a pointer to the short filename string stored in the pidl
2000 static LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl)
2002 /* TRACE(pidl,"(pidl%p)\n", pidl); */
2004 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
2006 if (!pdata)
2007 return NULL;
2009 switch (pdata->type)
2011 case PT_FOLDER:
2012 case PT_VALUE:
2013 case PT_IESPECIAL1:
2014 case PT_IESPECIAL2:
2015 return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1);
2017 case PT_WORKGRP:
2018 return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1);
2020 return NULL;
2023 /**************************************************************************
2024 * _ILGetGUIDPointer()
2026 * returns reference to guid stored in some pidls
2028 IID* _ILGetGUIDPointer(LPCITEMIDLIST pidl)
2030 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
2032 TRACE("%p\n", pidl);
2034 if (!pdata)
2035 return NULL;
2037 TRACE("pdata->type 0x%04x\n", pdata->type);
2038 switch (pdata->type)
2040 case PT_SHELLEXT:
2041 case PT_GUID:
2042 case PT_YAGUID:
2043 return &(pdata->u.guid.guid);
2045 default:
2046 TRACE("Unknown pidl type 0x%04x\n", pdata->type);
2047 break;
2049 return NULL;
2052 /******************************************************************************
2053 * _ILGetFileStructW [Internal]
2055 * Get pointer the a SHITEMID's FileStructW field if present
2057 * PARAMS
2058 * pidl [I] The SHITEMID
2060 * RETURNS
2061 * Success: Pointer to pidl's FileStructW field.
2062 * Failure: NULL
2064 FileStructW* _ILGetFileStructW(LPCITEMIDLIST pidl) {
2065 FileStructW *pFileStructW;
2066 WORD cbOffset;
2068 if (!(_ILIsValue(pidl) || _ILIsFolder(pidl)))
2069 return NULL;
2071 cbOffset = *(const WORD *)((const BYTE *)pidl + pidl->mkid.cb - sizeof(WORD));
2072 pFileStructW = (FileStructW*)((LPBYTE)pidl + cbOffset);
2074 /* Currently I don't see a fool prove way to figure out if a pidl is for sure of WinXP
2075 * style with a FileStructW member. If we switch all our shellfolder-implementations to
2076 * the new format, this won't be a problem. For now, we do as many sanity checks as possible. */
2077 if (cbOffset & 0x1 || /* FileStructW member is word aligned in the pidl */
2078 /* FileStructW is positioned after FileStruct */
2079 cbOffset < sizeof(pidl->mkid.cb) + sizeof(PIDLTYPE) + sizeof(FileStruct) ||
2080 /* There has to be enough space at cbOffset in the pidl to hold FileStructW and cbOffset */
2081 cbOffset > pidl->mkid.cb - sizeof(cbOffset) - sizeof(FileStructW) ||
2082 pidl->mkid.cb != cbOffset + pFileStructW->cbLen)
2084 WARN("Invalid pidl format (cbOffset = %d)!\n", cbOffset);
2085 return NULL;
2088 return pFileStructW;
2091 /*************************************************************************
2092 * _ILGetFileDateTime
2094 * Given the ItemIdList, get the FileTime
2096 * PARAMS
2097 * pidl [I] The ItemIDList
2098 * pFt [I] the resulted FILETIME of the file
2100 * RETURNS
2101 * True if Successful
2103 * NOTES
2106 BOOL _ILGetFileDateTime(LPCITEMIDLIST pidl, FILETIME *pFt)
2108 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2110 if (!pdata)
2111 return FALSE;
2113 switch (pdata->type)
2115 case PT_FOLDER:
2116 case PT_VALUE:
2117 DosDateTimeToFileTime(pdata->u.file.uFileDate, pdata->u.file.uFileTime, pFt);
2118 break;
2119 default:
2120 return FALSE;
2122 return TRUE;
2125 BOOL _ILGetFileDate (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2127 FILETIME ft,lft;
2128 SYSTEMTIME time;
2129 BOOL ret;
2131 if (_ILGetFileDateTime( pidl, &ft ))
2133 FileTimeToLocalFileTime(&ft, &lft);
2134 FileTimeToSystemTime (&lft, &time);
2136 ret = GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&time, NULL, pOut, uOutSize);
2137 if (ret)
2139 /* Append space + time without seconds */
2140 pOut[ret-1] = ' ';
2141 GetTimeFormatA(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &time, NULL, &pOut[ret], uOutSize - ret);
2144 else
2146 pOut[0] = '\0';
2147 ret = FALSE;
2149 return ret;
2152 /*************************************************************************
2153 * _ILGetFileSize
2155 * Given the ItemIdList, get the FileSize
2157 * PARAMS
2158 * pidl [I] The ItemIDList
2159 * pOut [I] The buffer to save the result
2160 * uOutsize [I] The size of the buffer
2162 * RETURNS
2163 * The FileSize
2165 * NOTES
2166 * pOut can be null when no string is needed
2169 DWORD _ILGetFileSize (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2171 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2172 DWORD dwSize;
2174 if (!pdata)
2175 return 0;
2177 switch (pdata->type)
2179 case PT_VALUE:
2180 dwSize = pdata->u.file.dwFileSize;
2181 if (pOut)
2182 StrFormatKBSizeA(dwSize, pOut, uOutSize);
2183 return dwSize;
2185 if (pOut)
2186 *pOut = 0x00;
2187 return 0;
2190 BOOL _ILGetExtension (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2192 char szTemp[MAX_PATH];
2193 const char * pPoint;
2194 LPCITEMIDLIST pidlTemp=pidl;
2196 TRACE("pidl=%p\n",pidl);
2198 if (!pidl)
2199 return FALSE;
2201 pidlTemp = ILFindLastID(pidl);
2203 if (!_ILIsValue(pidlTemp))
2204 return FALSE;
2205 if (!_ILSimpleGetText(pidlTemp, szTemp, MAX_PATH))
2206 return FALSE;
2208 pPoint = PathFindExtensionA(szTemp);
2210 if (!*pPoint)
2211 return FALSE;
2213 pPoint++;
2214 lstrcpynA(pOut, pPoint, uOutSize);
2215 TRACE("%s\n",pOut);
2217 return TRUE;
2220 /*************************************************************************
2221 * _ILGetFileType
2223 * Given the ItemIdList, get the file type description
2225 * PARAMS
2226 * pidl [I] The ItemIDList (simple)
2227 * pOut [I] The buffer to save the result
2228 * uOutsize [I] The size of the buffer
2230 * RETURNS
2231 * nothing
2233 * NOTES
2234 * This function copies as much as possible into the buffer.
2236 void _ILGetFileType(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2238 if(_ILIsValue(pidl))
2240 char sTemp[64];
2242 if(uOutSize > 0)
2243 pOut[0] = 0;
2244 if (_ILGetExtension (pidl, sTemp, 64))
2246 if (!( HCR_MapTypeToValueA(sTemp, sTemp, 64, TRUE)
2247 && HCR_MapTypeToValueA(sTemp, pOut, uOutSize, FALSE )))
2249 lstrcpynA (pOut, sTemp, uOutSize - 6);
2250 strcat (pOut, "-file");
2254 else
2255 lstrcpynA(pOut, "Folder", uOutSize);
2258 /*************************************************************************
2259 * _ILGetFileAttributes
2261 * Given the ItemIdList, get the Attrib string format
2263 * PARAMS
2264 * pidl [I] The ItemIDList
2265 * pOut [I] The buffer to save the result
2266 * uOutsize [I] The size of the Buffer
2268 * RETURNS
2269 * Attributes
2271 * FIXME
2272 * return value 0 in case of error is a valid return value
2275 DWORD _ILGetFileAttributes(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2277 LPPIDLDATA pData = _ILGetDataPointer(pidl);
2278 WORD wAttrib = 0;
2279 int i;
2281 if (!pData)
2282 return 0;
2284 switch(pData->type)
2286 case PT_FOLDER:
2287 case PT_VALUE:
2288 wAttrib = pData->u.file.uFileAttribs;
2289 break;
2292 if(uOutSize >= 6)
2294 i=0;
2295 if(wAttrib & FILE_ATTRIBUTE_READONLY)
2296 pOut[i++] = 'R';
2297 if(wAttrib & FILE_ATTRIBUTE_HIDDEN)
2298 pOut[i++] = 'H';
2299 if(wAttrib & FILE_ATTRIBUTE_SYSTEM)
2300 pOut[i++] = 'S';
2301 if(wAttrib & FILE_ATTRIBUTE_ARCHIVE)
2302 pOut[i++] = 'A';
2303 if(wAttrib & FILE_ATTRIBUTE_COMPRESSED)
2304 pOut[i++] = 'C';
2305 pOut[i] = 0x00;
2307 return wAttrib;
2310 /*************************************************************************
2311 * ILFreeaPidl
2313 * free a aPidl struct
2315 void _ILFreeaPidl(LPITEMIDLIST * apidl, UINT cidl)
2317 UINT i;
2319 if (apidl)
2321 for (i = 0; i < cidl; i++)
2322 SHFree(apidl[i]);
2323 SHFree(apidl);
2327 /*************************************************************************
2328 * ILCopyaPidl
2330 * copies an aPidl struct
2332 LPITEMIDLIST* _ILCopyaPidl(const LPCITEMIDLIST * apidlsrc, UINT cidl)
2334 UINT i;
2335 LPITEMIDLIST *apidldest;
2337 apidldest = SHAlloc(cidl * sizeof(LPITEMIDLIST));
2338 if (!apidlsrc)
2339 return NULL;
2341 for (i = 0; i < cidl; i++)
2342 apidldest[i] = ILClone(apidlsrc[i]);
2344 return apidldest;
2347 /*************************************************************************
2348 * _ILCopyCidaToaPidl
2350 * creates aPidl from CIDA
2352 LPITEMIDLIST* _ILCopyCidaToaPidl(LPITEMIDLIST* pidl, const CIDA * cida)
2354 UINT i;
2355 LPITEMIDLIST *dst;
2357 dst = SHAlloc(cida->cidl * sizeof(LPITEMIDLIST));
2358 if (!dst)
2359 return NULL;
2361 if (pidl)
2362 *pidl = ILClone((LPCITEMIDLIST)(&((const BYTE*)cida)[cida->aoffset[0]]));
2364 for (i = 0; i < cida->cidl; i++)
2365 dst[i] = ILClone((LPCITEMIDLIST)(&((const BYTE*)cida)[cida->aoffset[i + 1]]));
2367 return dst;
2370 HRESULT WINAPI SHCreateShellItem(LPCITEMIDLIST pidlParent,
2371 IShellFolder *psfParent, LPCITEMIDLIST pidl, void **ppsi)
2373 FIXME("STUB: %p %p %p %p\n",pidlParent, psfParent, pidl, ppsi);
2374 return E_NOINTERFACE;