push 2f3ca95c4974ba229fa47d638b3044f50788f3bd
[wine/hacks.git] / dlls / shell32 / pidl.c
blobbee716641445fb40a9cc2fbcec7a4ddbe8d455db
1 /*
2 * pidl Handling
4 * Copyright 1998 Juergen Schmied
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * NOTES
21 * a pidl == NULL means desktop and is legal
25 #include "config.h"
26 #include "wine/port.h"
28 #include <ctype.h>
29 #include <stdarg.h>
30 #include <stdlib.h>
31 #include <string.h>
33 #define COBJMACROS
34 #define NONAMELESSUNION
35 #define NONAMELESSSTRUCT
37 #include "windef.h"
38 #include "winbase.h"
39 #include "winreg.h"
40 #include "objbase.h"
41 #include "shlguid.h"
42 #include "winerror.h"
43 #include "winnls.h"
44 #include "undocshell.h"
45 #include "shell32_main.h"
46 #include "shlwapi.h"
48 #include "pidl.h"
49 #include "wine/debug.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(pidl);
52 WINE_DECLARE_DEBUG_CHANNEL(shell);
54 /* from comctl32.dll */
55 extern LPVOID WINAPI Alloc(INT);
56 extern BOOL WINAPI Free(LPVOID);
58 /*************************************************************************
59 * ILGetDisplayNameEx [SHELL32.186]
61 * Retrieves the display name of an ItemIDList
63 * PARAMS
64 * psf [I] Shell Folder to start with, if NULL the desktop is used
65 * pidl [I] ItemIDList relative to the psf to get the display name for
66 * path [O] Filled in with the display name, assumed to be at least MAX_PATH long
67 * type [I] Type of display name to retrieve
68 * 0 = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR uses always the desktop as root
69 * 1 = SHGDN_NORMAL relative to the root folder
70 * 2 = SHGDN_INFOLDER relative to the root folder, only the last name
72 * RETURNS
73 * True if the display name could be retrieved successfully, False otherwise
75 BOOL WINAPI ILGetDisplayNameExA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPSTR path, DWORD type)
77 BOOL ret = FALSE;
78 WCHAR wPath[MAX_PATH];
80 TRACE("%p %p %p %d\n", psf, pidl, path, type);
82 if (!pidl || !path)
83 return FALSE;
85 ret = ILGetDisplayNameExW(psf, pidl, wPath, type);
86 WideCharToMultiByte(CP_ACP, 0, wPath, -1, path, MAX_PATH, NULL, NULL);
87 TRACE("%p %p %s\n", psf, pidl, debugstr_a(path));
89 return ret;
92 BOOL WINAPI ILGetDisplayNameExW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPWSTR path, DWORD type)
94 LPSHELLFOLDER psfParent, lsf = psf;
95 HRESULT ret = NO_ERROR;
96 LPCITEMIDLIST pidllast;
97 STRRET strret;
98 DWORD flag;
100 TRACE("%p %p %p %x\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 switch (type)
114 case ILGDN_FORPARSING:
115 flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
116 break;
117 case ILGDN_NORMAL:
118 flag = SHGDN_NORMAL;
119 break;
120 case ILGDN_INFOLDER:
121 flag = SHGDN_INFOLDER;
122 break;
123 default:
124 FIXME("Unknown type parameter = %x\n", type);
125 flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
126 break;
129 if (!*(const WORD*)pidl || type == ILGDN_FORPARSING)
131 ret = IShellFolder_GetDisplayNameOf(lsf, pidl, flag, &strret);
132 if (SUCCEEDED(ret))
134 if(!StrRetToStrNW(path, MAX_PATH, &strret, pidl))
135 ret = E_FAIL;
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 if(!StrRetToStrNW(path, MAX_PATH, &strret, pidllast))
147 ret = E_FAIL;
149 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 %d\n", psf, pidl, path, type);
164 if (SHELL_OsIsUnicode())
165 return ILGetDisplayNameExW(psf, pidl, path, type);
166 return ILGetDisplayNameExA(psf, pidl, path, type);
169 /*************************************************************************
170 * ILGetDisplayName [SHELL32.15]
172 BOOL WINAPI ILGetDisplayName(LPCITEMIDLIST pidl, LPVOID path)
174 TRACE_(shell)("%p %p\n", pidl, path);
176 if (SHELL_OsIsUnicode())
177 return ILGetDisplayNameExW(NULL, pidl, path, ILGDN_FORPARSING);
178 return ILGetDisplayNameExA(NULL, pidl, path, ILGDN_FORPARSING);
181 /*************************************************************************
182 * ILFindLastID [SHELL32.16]
184 * NOTES
185 * observed: pidl=Desktop return=pidl
187 LPITEMIDLIST WINAPI ILFindLastID(LPCITEMIDLIST pidl)
189 LPCITEMIDLIST pidlLast = pidl;
191 TRACE("(pidl=%p)\n",pidl);
193 if (!pidl)
194 return NULL;
196 while (pidl->mkid.cb)
198 pidlLast = pidl;
199 pidl = ILGetNext(pidl);
201 return (LPITEMIDLIST)pidlLast;
204 /*************************************************************************
205 * ILRemoveLastID [SHELL32.17]
207 * NOTES
208 * when pidl=Desktop return=FALSE
210 BOOL WINAPI ILRemoveLastID(LPITEMIDLIST pidl)
212 TRACE_(shell)("pidl=%p\n",pidl);
214 if (!pidl || !pidl->mkid.cb)
215 return 0;
216 ILFindLastID(pidl)->mkid.cb = 0;
217 return 1;
220 /*************************************************************************
221 * ILClone [SHELL32.18]
223 * NOTES
224 * duplicate an idlist
226 LPITEMIDLIST WINAPI ILClone (LPCITEMIDLIST pidl)
228 DWORD len;
229 LPITEMIDLIST newpidl;
231 if (!pidl)
232 return NULL;
234 len = ILGetSize(pidl);
235 newpidl = SHAlloc(len);
236 if (newpidl)
237 memcpy(newpidl,pidl,len);
239 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
240 pdump(pidl);
242 return newpidl;
245 /*************************************************************************
246 * ILCloneFirst [SHELL32.19]
248 * NOTES
249 * duplicates the first idlist of a complex pidl
251 LPITEMIDLIST WINAPI ILCloneFirst(LPCITEMIDLIST pidl)
253 DWORD len;
254 LPITEMIDLIST pidlNew = NULL;
256 TRACE("pidl=%p\n", pidl);
257 pdump(pidl);
259 if (pidl)
261 len = pidl->mkid.cb;
262 pidlNew = SHAlloc(len+2);
263 if (pidlNew)
265 memcpy(pidlNew,pidl,len+2); /* 2 -> mind a desktop pidl */
267 if (len)
268 ILGetNext(pidlNew)->mkid.cb = 0x00;
271 TRACE("-- newpidl=%p\n",pidlNew);
273 return pidlNew;
276 /*************************************************************************
277 * ILLoadFromStream (SHELL32.26)
279 * NOTES
280 * the first two bytes are the len, the pidl is following then
282 HRESULT WINAPI ILLoadFromStream (IStream * pStream, LPITEMIDLIST * ppPidl)
284 WORD wLen = 0;
285 DWORD dwBytesRead;
286 HRESULT ret = E_FAIL;
289 TRACE_(shell)("%p %p\n", pStream , ppPidl);
291 SHFree(*ppPidl);
292 *ppPidl = NULL;
294 IStream_AddRef (pStream);
296 if (SUCCEEDED(IStream_Read(pStream, (LPVOID)&wLen, 2, &dwBytesRead)))
298 TRACE("PIDL length is %d\n", wLen);
299 if (wLen != 0)
301 *ppPidl = SHAlloc (wLen);
302 if (SUCCEEDED(IStream_Read(pStream, *ppPidl , wLen, &dwBytesRead)))
304 TRACE("Stream read OK\n");
305 ret = S_OK;
307 else
309 WARN("reading pidl failed\n");
310 SHFree(*ppPidl);
311 *ppPidl = NULL;
314 else
316 *ppPidl = NULL;
317 ret = S_OK;
321 /* we are not yet fully compatible */
322 if (*ppPidl && !pcheck(*ppPidl))
324 WARN("Check failed\n");
325 SHFree(*ppPidl);
326 *ppPidl = NULL;
329 IStream_Release (pStream);
330 TRACE("done\n");
331 return ret;
334 /*************************************************************************
335 * ILSaveToStream (SHELL32.27)
337 * NOTES
338 * the first two bytes are the len, the pidl is following then
340 HRESULT WINAPI ILSaveToStream (IStream * pStream, LPCITEMIDLIST pPidl)
342 WORD wLen = 0;
343 HRESULT ret = E_FAIL;
345 TRACE_(shell)("%p %p\n", pStream, pPidl);
347 IStream_AddRef (pStream);
349 wLen = ILGetSize(pPidl);
351 if (SUCCEEDED(IStream_Write(pStream, (LPVOID)&wLen, 2, NULL)))
353 if (SUCCEEDED(IStream_Write(pStream, pPidl, wLen, NULL)))
354 ret = S_OK;
356 IStream_Release (pStream);
358 return ret;
361 /*************************************************************************
362 * SHILCreateFromPath [SHELL32.28]
364 * Create an ItemIDList from a path
366 * PARAMS
367 * path [I]
368 * ppidl [O]
369 * attributes [I/O] requested attributes on call and actual attributes when
370 * the function returns
372 * RETURNS
373 * NO_ERROR if successful, or an OLE errer code otherwise
375 * NOTES
376 * Wrapper for IShellFolder_ParseDisplayName().
378 HRESULT WINAPI SHILCreateFromPathA(LPCSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
380 WCHAR lpszDisplayName[MAX_PATH];
382 TRACE_(shell)("%s %p 0x%08x\n", path, ppidl, attributes ? *attributes : 0);
384 if (!MultiByteToWideChar(CP_ACP, 0, path, -1, lpszDisplayName, MAX_PATH))
385 lpszDisplayName[MAX_PATH-1] = 0;
387 return SHILCreateFromPathW(lpszDisplayName, ppidl, attributes);
390 HRESULT WINAPI SHILCreateFromPathW(LPCWSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
392 LPSHELLFOLDER sf;
393 DWORD pchEaten;
394 HRESULT ret = E_FAIL;
396 TRACE_(shell)("%s %p 0x%08x\n", debugstr_w(path), ppidl, attributes ? *attributes : 0);
398 if (SUCCEEDED (SHGetDesktopFolder(&sf)))
400 ret = IShellFolder_ParseDisplayName(sf, 0, NULL, (LPWSTR)path, &pchEaten, ppidl, attributes);
401 IShellFolder_Release(sf);
403 return ret;
406 HRESULT WINAPI SHILCreateFromPathAW (LPCVOID path, LPITEMIDLIST * ppidl, DWORD * attributes)
408 if ( SHELL_OsIsUnicode())
409 return SHILCreateFromPathW (path, ppidl, attributes);
410 return SHILCreateFromPathA (path, ppidl, attributes);
413 /*************************************************************************
414 * SHCloneSpecialIDList [SHELL32.89]
416 * Create an ItemIDList to one of the special folders.
418 * PARAMS
419 * hwndOwner [in]
420 * nFolder [in] CSIDL_xxxxx
421 * fCreate [in] Create folder if it does not exist
423 * RETURNS
424 * Success: The newly created pidl
425 * Failure: NULL, if inputs are invalid.
427 * NOTES
428 * exported by ordinal.
429 * Caller is responsible for deallocating the returned ItemIDList with the
430 * shells IMalloc interface, aka ILFree.
432 LPITEMIDLIST WINAPI SHCloneSpecialIDList(HWND hwndOwner, DWORD nFolder, BOOL fCreate)
434 LPITEMIDLIST ppidl;
435 TRACE_(shell)("(hwnd=%p,csidl=0x%x,%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)
460 DWORD len;
461 LPITEMIDLIST newpidl;
463 if (!pidl)
464 return NULL;
466 len = ILGetSize(pidl);
467 newpidl = Alloc(len);
468 if (newpidl)
469 memcpy(newpidl,pidl,len);
471 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
472 pdump(pidl);
474 return newpidl;
477 /*************************************************************************
478 * ILIsEqual [SHELL32.21]
481 BOOL WINAPI ILIsEqual(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
483 char szData1[MAX_PATH];
484 char szData2[MAX_PATH];
486 LPCITEMIDLIST pidltemp1 = pidl1;
487 LPCITEMIDLIST pidltemp2 = pidl2;
489 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
492 * Explorer reads from registry directly (StreamMRU),
493 * so we can only check here
495 if (!pcheck(pidl1) || !pcheck (pidl2))
496 return FALSE;
498 pdump (pidl1);
499 pdump (pidl2);
501 if (!pidl1 || !pidl2)
502 return FALSE;
504 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
506 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
507 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
509 if (strcasecmp( szData1, szData2 ))
510 return FALSE;
512 pidltemp1 = ILGetNext(pidltemp1);
513 pidltemp2 = ILGetNext(pidltemp2);
516 if (!pidltemp1->mkid.cb && !pidltemp2->mkid.cb)
517 return TRUE;
519 return FALSE;
522 /*************************************************************************
523 * ILIsParent [SHELL32.23]
525 * Verifies that pidlParent is indeed the (immediate) parent of pidlChild.
527 * PARAMS
528 * pidlParent [I]
529 * pidlChild [I]
530 * bImmediate [I] only return true if the parent is the direct parent
531 * of the child
533 * RETURNS
534 * True if the parent ItemIDlist is a complete part of the child ItemIdList,
535 * False otherwise.
537 * NOTES
538 * parent = a/b, child = a/b/c -> true, c is in folder a/b
539 * child = a/b/c/d -> false if bImmediate is true, d is not in folder a/b
540 * child = a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
542 BOOL WINAPI ILIsParent(LPCITEMIDLIST pidlParent, LPCITEMIDLIST pidlChild, BOOL bImmediate)
544 char szData1[MAX_PATH];
545 char szData2[MAX_PATH];
546 LPCITEMIDLIST pParent = pidlParent;
547 LPCITEMIDLIST pChild = pidlChild;
549 TRACE("%p %p %x\n", pidlParent, pidlChild, bImmediate);
551 if (!pParent || !pChild)
552 return FALSE;
554 while (pParent->mkid.cb && pChild->mkid.cb)
556 _ILSimpleGetText(pParent, szData1, MAX_PATH);
557 _ILSimpleGetText(pChild, szData2, MAX_PATH);
559 if (strcasecmp( szData1, szData2 ))
560 return FALSE;
562 pParent = ILGetNext(pParent);
563 pChild = ILGetNext(pChild);
566 /* child shorter or has equal length to parent */
567 if (pParent->mkid.cb || !pChild->mkid.cb)
568 return FALSE;
570 /* not immediate descent */
571 if ( ILGetNext(pChild)->mkid.cb && bImmediate)
572 return FALSE;
574 return TRUE;
577 /*************************************************************************
578 * ILFindChild [SHELL32.24]
580 * Compares elements from pidl1 and pidl2.
582 * PARAMS
583 * pidl1 [I]
584 * pidl2 [I]
586 * RETURNS
587 * pidl1 is desktop pidl2
588 * pidl1 shorter pidl2 pointer to first different element of pidl2
589 * if there was at least one equal element
590 * pidl2 shorter pidl1 0
591 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
593 * NOTES
594 * exported by ordinal.
596 LPITEMIDLIST WINAPI ILFindChild(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
598 char szData1[MAX_PATH];
599 char szData2[MAX_PATH];
601 LPCITEMIDLIST pidltemp1 = pidl1;
602 LPCITEMIDLIST pidltemp2 = pidl2;
603 LPCITEMIDLIST ret=NULL;
605 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
607 /* explorer reads from registry directly (StreamMRU),
608 so we can only check here */
609 if ((!pcheck (pidl1)) || (!pcheck (pidl2)))
610 return FALSE;
612 pdump (pidl1);
613 pdump (pidl2);
615 if (_ILIsDesktop(pidl1))
617 ret = pidl2;
619 else
621 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
623 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
624 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
626 if (strcasecmp(szData1,szData2))
627 break;
629 pidltemp1 = ILGetNext(pidltemp1);
630 pidltemp2 = ILGetNext(pidltemp2);
631 ret = pidltemp2;
634 if (pidltemp1->mkid.cb)
635 ret = NULL; /* elements of pidl1 left*/
637 TRACE_(shell)("--- %p\n", ret);
638 return (LPITEMIDLIST)ret; /* pidl 1 is shorter */
641 /*************************************************************************
642 * ILCombine [SHELL32.25]
644 * Concatenates two complex ItemIDLists.
646 * PARAMS
647 * pidl1 [I] first complex ItemIDLists
648 * pidl2 [I] complex ItemIDLists to append
650 * RETURNS
651 * if both pidl's == NULL NULL
652 * if pidl1 == NULL cloned pidl2
653 * if pidl2 == NULL cloned pidl1
654 * otherwise new pidl with pidl2 appended to pidl1
656 * NOTES
657 * exported by ordinal.
658 * Does not destroy the passed in ItemIDLists!
660 LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
662 DWORD len1,len2;
663 LPITEMIDLIST pidlNew;
665 TRACE("pidl=%p pidl=%p\n",pidl1,pidl2);
667 if (!pidl1 && !pidl2) return NULL;
669 pdump (pidl1);
670 pdump (pidl2);
672 if (!pidl1)
674 pidlNew = ILClone(pidl2);
675 return pidlNew;
678 if (!pidl2)
680 pidlNew = ILClone(pidl1);
681 return pidlNew;
684 len1 = ILGetSize(pidl1)-2;
685 len2 = ILGetSize(pidl2);
686 pidlNew = SHAlloc(len1+len2);
688 if (pidlNew)
690 memcpy(pidlNew,pidl1,len1);
691 memcpy(((BYTE *)pidlNew)+len1,pidl2,len2);
694 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
695 return pidlNew;
698 /*************************************************************************
699 * SHGetRealIDL [SHELL32.98]
701 * NOTES
703 HRESULT WINAPI SHGetRealIDL(LPSHELLFOLDER lpsf, LPCITEMIDLIST pidlSimple, LPITEMIDLIST *pidlReal)
705 IDataObject* pDataObj;
706 HRESULT hr;
708 hr = IShellFolder_GetUIObjectOf(lpsf, 0, 1, &pidlSimple,
709 &IID_IDataObject, 0, (LPVOID*)&pDataObj);
710 if (SUCCEEDED(hr))
712 STGMEDIUM medium;
713 FORMATETC fmt;
715 fmt.cfFormat = RegisterClipboardFormatW(CFSTR_SHELLIDLISTW);
716 fmt.ptd = NULL;
717 fmt.dwAspect = DVASPECT_CONTENT;
718 fmt.lindex = -1;
719 fmt.tymed = TYMED_HGLOBAL;
721 hr = IDataObject_GetData(pDataObj, &fmt, &medium);
723 IDataObject_Release(pDataObj);
725 if (SUCCEEDED(hr))
727 /*assert(pida->cidl==1);*/
728 LPIDA pida = GlobalLock(medium.u.hGlobal);
730 LPCITEMIDLIST pidl_folder = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[0]);
731 LPCITEMIDLIST pidl_child = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[1]);
733 *pidlReal = ILCombine(pidl_folder, pidl_child);
735 if (!*pidlReal)
736 hr = E_OUTOFMEMORY;
738 GlobalUnlock(medium.u.hGlobal);
739 GlobalFree(medium.u.hGlobal);
743 return hr;
746 /*************************************************************************
747 * SHLogILFromFSIL [SHELL32.95]
749 * NOTES
750 * pild = CSIDL_DESKTOP ret = 0
751 * pild = CSIDL_DRIVES ret = 0
753 LPITEMIDLIST WINAPI SHLogILFromFSIL(LPITEMIDLIST pidl)
755 FIXME("(pidl=%p)\n",pidl);
757 pdump(pidl);
759 return 0;
762 /*************************************************************************
763 * ILGetSize [SHELL32.152]
765 * Gets the byte size of an ItemIDList including zero terminator
767 * PARAMS
768 * pidl [I] ItemIDList
770 * RETURNS
771 * size of pidl in bytes
773 * NOTES
774 * exported by ordinal
776 UINT WINAPI ILGetSize(LPCITEMIDLIST pidl)
778 LPCSHITEMID si = &(pidl->mkid);
779 UINT len=0;
781 if (pidl)
783 while (si->cb)
785 len += si->cb;
786 si = (LPCSHITEMID)(((const BYTE*)si)+si->cb);
788 len += 2;
790 TRACE("pidl=%p size=%u\n",pidl, len);
791 return len;
794 /*************************************************************************
795 * ILGetNext [SHELL32.153]
797 * Gets the next ItemID of an ItemIDList
799 * PARAMS
800 * pidl [I] ItemIDList
802 * RETURNS
803 * null -> null
804 * desktop -> null
805 * simple pidl -> pointer to 0x0000 element
807 * NOTES
808 * exported by ordinal.
810 LPITEMIDLIST WINAPI ILGetNext(LPCITEMIDLIST pidl)
812 WORD len;
814 TRACE("%p\n", pidl);
816 if (pidl)
818 len = pidl->mkid.cb;
819 if (len)
821 pidl = (LPCITEMIDLIST) (((const BYTE*)pidl)+len);
822 TRACE("-- %p\n", pidl);
823 return (LPITEMIDLIST)pidl;
826 return NULL;
829 /*************************************************************************
830 * ILAppend [SHELL32.154]
832 * Adds the single ItemID item to the ItemIDList indicated by pidl.
833 * If bEnd is FALSE, inserts the item in the front of the list,
834 * otherwise it adds the item to the end. (???)
836 * PARAMS
837 * pidl [I] ItemIDList to extend
838 * item [I] ItemID to prepend/append
839 * bEnd [I] Indicates if the item should be appended
841 * NOTES
842 * Destroys the passed in idlist! (???)
844 LPITEMIDLIST WINAPI ILAppend(LPITEMIDLIST pidl, LPCITEMIDLIST item, BOOL bEnd)
846 LPITEMIDLIST idlRet;
848 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl,item,bEnd);
850 pdump (pidl);
851 pdump (item);
853 if (_ILIsDesktop(pidl))
855 idlRet = ILClone(item);
856 SHFree (pidl);
857 return idlRet;
860 if (bEnd)
861 idlRet = ILCombine(pidl, item);
862 else
863 idlRet = ILCombine(item, pidl);
865 SHFree(pidl);
866 return idlRet;
869 /*************************************************************************
870 * ILFree [SHELL32.155]
872 * Frees memory (if not NULL) allocated by SHMalloc allocator
874 * PARAMS
875 * pidl [I]
877 * RETURNS
878 * Nothing
880 * NOTES
881 * exported by ordinal
883 void WINAPI ILFree(LPITEMIDLIST pidl)
885 TRACE("(pidl=%p)\n",pidl);
886 SHFree(pidl);
889 /*************************************************************************
890 * ILGlobalFree [SHELL32.156]
892 * Frees memory (if not NULL) allocated by Alloc allocator
894 * PARAMS
895 * pidl [I]
897 * RETURNS
898 * Nothing
900 * NOTES
901 * exported by ordinal.
903 void WINAPI ILGlobalFree( LPITEMIDLIST pidl)
905 TRACE("%p\n", pidl);
907 Free(pidl);
910 /*************************************************************************
911 * ILCreateFromPathA [SHELL32.189]
913 * Creates a complex ItemIDList from a path and returns it.
915 * PARAMS
916 * path [I]
918 * RETURNS
919 * the newly created complex ItemIDList or NULL if failed
921 * NOTES
922 * exported by ordinal.
924 LPITEMIDLIST WINAPI ILCreateFromPathA (LPCSTR path)
926 LPITEMIDLIST pidlnew = NULL;
928 TRACE_(shell)("%s\n", debugstr_a(path));
930 if (SUCCEEDED(SHILCreateFromPathA(path, &pidlnew, NULL)))
931 return pidlnew;
932 return NULL;
935 /*************************************************************************
936 * ILCreateFromPathW [SHELL32.190]
938 * See ILCreateFromPathA.
940 LPITEMIDLIST WINAPI ILCreateFromPathW (LPCWSTR path)
942 LPITEMIDLIST pidlnew = NULL;
944 TRACE_(shell)("%s\n", debugstr_w(path));
946 if (SUCCEEDED(SHILCreateFromPathW(path, &pidlnew, NULL)))
947 return pidlnew;
948 return NULL;
951 /*************************************************************************
952 * ILCreateFromPath [SHELL32.157]
954 LPITEMIDLIST WINAPI ILCreateFromPathAW (LPCVOID path)
956 if ( SHELL_OsIsUnicode())
957 return ILCreateFromPathW (path);
958 return ILCreateFromPathA (path);
961 /*************************************************************************
962 * _ILParsePathW [internal]
964 * Creates an ItemIDList from a path and returns it.
966 * PARAMS
967 * path [I] path to parse and convert into an ItemIDList
968 * lpFindFile [I] pointer to buffer to initialize the FileSystem
969 * Bind Data object with
970 * bBindCtx [I] indicates to create a BindContext and assign a
971 * FileSystem Bind Data object
972 * ppidl [O] the newly create ItemIDList
973 * prgfInOut [I/O] requested attributes on input and actual
974 * attributes on return
976 * RETURNS
977 * NO_ERROR on success or an OLE error code
979 * NOTES
980 * If either lpFindFile is non-NULL or bBindCtx is TRUE, this function
981 * creates a BindContext object and assigns a FileSystem Bind Data object
982 * to it, passing the BindContext to IShellFolder_ParseDisplayName. Each
983 * IShellFolder uses that FileSystem Bind Data object of the BindContext
984 * to pass data about the current path element to the next object. This
985 * is used to avoid having to verify the current path element on disk, so
986 * that creating an ItemIDList from a nonexistent path still can work.
988 static HRESULT _ILParsePathW(LPCWSTR path, LPWIN32_FIND_DATAW lpFindFile,
989 BOOL bBindCtx, LPITEMIDLIST *ppidl, LPDWORD prgfInOut)
991 LPSHELLFOLDER pSF = NULL;
992 LPBC pBC = NULL;
993 HRESULT ret;
995 TRACE("%s %p %d (%p)->%p (%p)->0x%x\n", debugstr_w(path), lpFindFile, bBindCtx,
996 ppidl, ppidl ? *ppidl : NULL,
997 prgfInOut, prgfInOut ? *prgfInOut : 0);
999 ret = SHGetDesktopFolder(&pSF);
1000 if (FAILED(ret))
1001 return ret;
1003 if (lpFindFile || bBindCtx)
1004 ret = IFileSystemBindData_Constructor(lpFindFile, &pBC);
1006 if (SUCCEEDED(ret))
1008 ret = IShellFolder_ParseDisplayName(pSF, 0, pBC, (LPOLESTR)path, NULL, ppidl, prgfInOut);
1011 if (pBC)
1013 IBindCtx_Release(pBC);
1014 pBC = NULL;
1017 IShellFolder_Release(pSF);
1019 if (FAILED(ret) && ppidl)
1020 *ppidl = NULL;
1022 TRACE("%s %p 0x%x\n", debugstr_w(path), ppidl ? *ppidl : NULL, prgfInOut ? *prgfInOut : 0);
1024 return ret;
1027 /*************************************************************************
1028 * SHSimpleIDListFromPath [SHELL32.162]
1030 * Creates a simple ItemIDList from a path and returns it. This function
1031 * does not fail on nonexistent paths.
1033 * PARAMS
1034 * path [I] path to parse and convert into an ItemIDList
1036 * RETURNS
1037 * the newly created simple ItemIDList
1039 * NOTES
1040 * Simple in the name does not mean a relative ItemIDList but rather a
1041 * fully qualified list, where only the file name is filled in and the
1042 * directory flag for those ItemID elements this is known about, eg.
1043 * it is not the last element in the ItemIDList or the actual directory
1044 * exists on disk.
1045 * exported by ordinal.
1047 LPITEMIDLIST WINAPI SHSimpleIDListFromPathA(LPCSTR lpszPath)
1049 LPITEMIDLIST pidl = NULL;
1050 LPWSTR wPath = NULL;
1051 int len;
1053 TRACE("%s\n", debugstr_a(lpszPath));
1055 if (lpszPath)
1057 len = MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, NULL, 0);
1058 wPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1059 MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, wPath, len);
1062 _ILParsePathW(wPath, NULL, TRUE, &pidl, NULL);
1064 HeapFree(GetProcessHeap(), 0, wPath);
1065 TRACE("%s %p\n", debugstr_a(lpszPath), pidl);
1066 return pidl;
1069 LPITEMIDLIST WINAPI SHSimpleIDListFromPathW(LPCWSTR lpszPath)
1071 LPITEMIDLIST pidl = NULL;
1073 TRACE("%s\n", debugstr_w(lpszPath));
1075 _ILParsePathW(lpszPath, NULL, TRUE, &pidl, NULL);
1076 TRACE("%s %p\n", debugstr_w(lpszPath), pidl);
1077 return pidl;
1080 LPITEMIDLIST WINAPI SHSimpleIDListFromPathAW(LPCVOID lpszPath)
1082 if ( SHELL_OsIsUnicode())
1083 return SHSimpleIDListFromPathW (lpszPath);
1084 return SHSimpleIDListFromPathA (lpszPath);
1087 /*************************************************************************
1088 * SHGetDataFromIDListA [SHELL32.247]
1090 * NOTES
1091 * the pidl can be a simple one. since we can't get the path out of the pidl
1092 * we have to take all data from the pidl
1094 HRESULT WINAPI SHGetDataFromIDListA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl,
1095 int nFormat, LPVOID dest, int len)
1097 LPSTR filename, shortname;
1098 WIN32_FIND_DATAA * pfd;
1100 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
1102 pdump(pidl);
1103 if (!psf || !dest)
1104 return E_INVALIDARG;
1106 switch (nFormat)
1108 case SHGDFIL_FINDDATA:
1109 pfd = dest;
1111 if (_ILIsDrive(pidl) || _ILIsSpecialFolder(pidl))
1112 return E_INVALIDARG;
1114 if (len < sizeof(WIN32_FIND_DATAA))
1115 return E_INVALIDARG;
1117 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1118 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1119 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1120 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1122 filename = _ILGetTextPointer(pidl);
1123 shortname = _ILGetSTextPointer(pidl);
1125 if (filename)
1126 lstrcpynA(pfd->cFileName, filename, sizeof(pfd->cFileName));
1127 else
1128 pfd->cFileName[0] = '\0';
1130 if (shortname)
1131 lstrcpynA(pfd->cAlternateFileName, shortname, sizeof(pfd->cAlternateFileName));
1132 else
1133 pfd->cAlternateFileName[0] = '\0';
1134 return NOERROR;
1136 case SHGDFIL_NETRESOURCE:
1137 case SHGDFIL_DESCRIPTIONID:
1138 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1139 break;
1141 default:
1142 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1145 return E_INVALIDARG;
1148 /*************************************************************************
1149 * SHGetDataFromIDListW [SHELL32.248]
1152 HRESULT WINAPI SHGetDataFromIDListW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl,
1153 int nFormat, LPVOID dest, int len)
1155 LPSTR filename, shortname;
1156 WIN32_FIND_DATAW * pfd = dest;
1158 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
1160 pdump(pidl);
1162 if (!psf || !dest)
1163 return E_INVALIDARG;
1165 switch (nFormat)
1167 case SHGDFIL_FINDDATA:
1168 pfd = dest;
1170 if (_ILIsDrive(pidl))
1171 return E_INVALIDARG;
1173 if (len < sizeof(WIN32_FIND_DATAW))
1174 return E_INVALIDARG;
1176 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1177 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1178 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1179 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1181 filename = _ILGetTextPointer(pidl);
1182 shortname = _ILGetSTextPointer(pidl);
1184 if (!filename)
1185 pfd->cFileName[0] = '\0';
1186 else if (!MultiByteToWideChar(CP_ACP, 0, filename, -1, pfd->cFileName, MAX_PATH))
1187 pfd->cFileName[MAX_PATH-1] = 0;
1189 if (!shortname)
1190 pfd->cAlternateFileName[0] = '\0';
1191 else if (!MultiByteToWideChar(CP_ACP, 0, shortname, -1, pfd->cAlternateFileName, 14))
1192 pfd->cAlternateFileName[13] = 0;
1193 return NOERROR;
1195 case SHGDFIL_NETRESOURCE:
1196 case SHGDFIL_DESCRIPTIONID:
1197 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1198 break;
1200 default:
1201 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1204 return E_INVALIDARG;
1207 /*************************************************************************
1208 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
1210 * PARAMETERS
1211 * pidl, [IN] pidl
1212 * pszPath [OUT] path
1214 * RETURNS
1215 * path from a passed PIDL.
1217 * NOTES
1218 * NULL returns FALSE
1219 * desktop pidl gives path to desktop directory back
1220 * special pidls returning FALSE
1222 BOOL WINAPI SHGetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath)
1224 WCHAR wszPath[MAX_PATH];
1225 BOOL bSuccess;
1227 bSuccess = SHGetPathFromIDListW(pidl, wszPath);
1228 WideCharToMultiByte(CP_ACP, 0, wszPath, -1, pszPath, MAX_PATH, NULL, NULL);
1230 return bSuccess;
1233 /*************************************************************************
1234 * SHGetPathFromIDListW [SHELL32.@]
1236 * See SHGetPathFromIDListA.
1238 BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
1240 HRESULT hr;
1241 LPCITEMIDLIST pidlLast;
1242 LPSHELLFOLDER psfFolder;
1243 DWORD dwAttributes;
1244 STRRET strret;
1246 TRACE_(shell)("(pidl=%p,%p)\n", pidl, pszPath);
1247 pdump(pidl);
1249 *pszPath = '\0';
1250 if (!pidl)
1251 return FALSE;
1253 hr = SHBindToParent(pidl, &IID_IShellFolder, (VOID**)&psfFolder, &pidlLast);
1254 if (FAILED(hr)) return FALSE;
1256 dwAttributes = SFGAO_FILESYSTEM;
1257 hr = IShellFolder_GetAttributesOf(psfFolder, 1, &pidlLast, &dwAttributes);
1258 if (FAILED(hr) || !(dwAttributes & SFGAO_FILESYSTEM)) {
1259 IShellFolder_Release(psfFolder);
1260 return FALSE;
1263 hr = IShellFolder_GetDisplayNameOf(psfFolder, pidlLast, SHGDN_FORPARSING, &strret);
1264 IShellFolder_Release(psfFolder);
1265 if (FAILED(hr)) return FALSE;
1267 hr = StrRetToBufW(&strret, pidlLast, pszPath, MAX_PATH);
1269 TRACE_(shell)("-- %s, 0x%08x\n",debugstr_w(pszPath), hr);
1270 return SUCCEEDED(hr);
1273 /*************************************************************************
1274 * SHBindToParent [shell version 5.0]
1276 HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
1278 IShellFolder * psfDesktop;
1279 HRESULT hr=E_FAIL;
1281 TRACE_(shell)("pidl=%p\n", pidl);
1282 pdump(pidl);
1284 if (!pidl || !ppv)
1285 return E_INVALIDARG;
1287 *ppv = NULL;
1288 if (ppidlLast)
1289 *ppidlLast = NULL;
1291 hr = SHGetDesktopFolder(&psfDesktop);
1292 if (FAILED(hr))
1293 return hr;
1295 if (_ILIsPidlSimple(pidl))
1297 /* we are on desktop level */
1298 hr = IShellFolder_QueryInterface(psfDesktop, riid, ppv);
1300 else
1302 LPITEMIDLIST pidlParent = ILClone(pidl);
1303 ILRemoveLastID(pidlParent);
1304 hr = IShellFolder_BindToObject(psfDesktop, pidlParent, NULL, riid, ppv);
1305 SHFree (pidlParent);
1308 IShellFolder_Release(psfDesktop);
1310 if (SUCCEEDED(hr) && ppidlLast)
1311 *ppidlLast = ILFindLastID(pidl);
1313 TRACE_(shell)("-- psf=%p pidl=%p ret=0x%08x\n", *ppv, (ppidlLast)?*ppidlLast:NULL, hr);
1314 return hr;
1317 /**************************************************************************
1319 * internal functions
1321 * ### 1. section creating pidls ###
1323 *************************************************************************
1326 /* Basic PIDL constructor. Allocates size + 5 bytes, where:
1327 * - two bytes are SHITEMID.cb
1328 * - one byte is PIDLDATA.type
1329 * - two bytes are the NULL PIDL terminator
1330 * Sets type of the returned PIDL to type.
1332 static LPITEMIDLIST _ILAlloc(PIDLTYPE type, unsigned int size)
1334 LPITEMIDLIST pidlOut = NULL;
1336 pidlOut = SHAlloc(size + 5);
1337 if(pidlOut)
1339 LPPIDLDATA pData;
1340 LPITEMIDLIST pidlNext;
1342 ZeroMemory(pidlOut, size + 5);
1343 pidlOut->mkid.cb = size + 3;
1345 pData = _ILGetDataPointer(pidlOut);
1346 if (pData)
1347 pData->type = type;
1349 pidlNext = ILGetNext(pidlOut);
1350 if (pidlNext)
1351 pidlNext->mkid.cb = 0x00;
1352 TRACE("-- (pidl=%p, size=%u)\n", pidlOut, size);
1355 return pidlOut;
1358 LPITEMIDLIST _ILCreateDesktop(void)
1360 LPITEMIDLIST ret;
1362 TRACE("()\n");
1363 ret = SHAlloc(2);
1364 if (ret)
1365 ret->mkid.cb = 0;
1366 return ret;
1369 LPITEMIDLIST _ILCreateMyComputer(void)
1371 TRACE("()\n");
1372 return _ILCreateGuid(PT_GUID, &CLSID_MyComputer);
1375 LPITEMIDLIST _ILCreateMyDocuments(void)
1377 TRACE("()\n");
1378 return _ILCreateGuid(PT_GUID, &CLSID_MyDocuments);
1381 LPITEMIDLIST _ILCreateIExplore(void)
1383 TRACE("()\n");
1384 return _ILCreateGuid(PT_GUID, &CLSID_Internet);
1387 LPITEMIDLIST _ILCreateControlPanel(void)
1389 LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL;
1391 TRACE("()\n");
1392 if (parent)
1394 LPITEMIDLIST cpl = _ILCreateGuid(PT_SHELLEXT, &CLSID_ControlPanel);
1396 if (cpl)
1398 ret = ILCombine(parent, cpl);
1399 SHFree(cpl);
1401 SHFree(parent);
1403 return ret;
1406 LPITEMIDLIST _ILCreatePrinters(void)
1408 LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL;
1410 TRACE("()\n");
1411 if (parent)
1413 LPITEMIDLIST printers = _ILCreateGuid(PT_YAGUID, &CLSID_Printers);
1415 if (printers)
1417 ret = ILCombine(parent, printers);
1418 SHFree(printers);
1420 SHFree(parent);
1422 return ret;
1425 LPITEMIDLIST _ILCreateNetwork(void)
1427 TRACE("()\n");
1428 return _ILCreateGuid(PT_GUID, &CLSID_NetworkPlaces);
1431 LPITEMIDLIST _ILCreateBitBucket(void)
1433 TRACE("()\n");
1434 return _ILCreateGuid(PT_GUID, &CLSID_RecycleBin);
1437 LPITEMIDLIST _ILCreateNetHood(void)
1439 TRACE("()\n");
1440 return _ILCreateGuid(PT_GUID, &CLSID_NetworkPlaces);
1443 LPITEMIDLIST _ILCreateGuid(PIDLTYPE type, REFIID guid)
1445 LPITEMIDLIST pidlOut;
1447 if (type == PT_SHELLEXT || type == PT_GUID || type == PT_YAGUID)
1449 pidlOut = _ILAlloc(type, sizeof(GUIDStruct));
1450 if (pidlOut)
1452 LPPIDLDATA pData = _ILGetDataPointer(pidlOut);
1454 pData->u.guid.guid = *guid;
1455 TRACE("-- create GUID-pidl %s\n",
1456 debugstr_guid(&(pData->u.guid.guid)));
1459 else
1461 WARN("%d: invalid type for GUID\n", type);
1462 pidlOut = NULL;
1464 return pidlOut;
1467 LPITEMIDLIST _ILCreateGuidFromStrA(LPCSTR szGUID)
1469 IID iid;
1471 if (FAILED(SHCLSIDFromStringA(szGUID, &iid)))
1473 ERR("%s is not a GUID\n", szGUID);
1474 return NULL;
1476 return _ILCreateGuid(PT_GUID, &iid);
1479 LPITEMIDLIST _ILCreateGuidFromStrW(LPCWSTR szGUID)
1481 IID iid;
1483 if (FAILED(SHCLSIDFromStringW(szGUID, &iid)))
1485 ERR("%s is not a GUID\n", debugstr_w(szGUID));
1486 return NULL;
1488 return _ILCreateGuid(PT_GUID, &iid);
1491 LPITEMIDLIST _ILCreateFromFindDataW( const WIN32_FIND_DATAW *wfd )
1493 char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1494 DWORD len, len1, wlen, alen;
1495 LPITEMIDLIST pidl;
1496 PIDLTYPE type;
1498 if (!wfd)
1499 return NULL;
1501 TRACE("(%s, %s)\n",debugstr_w(wfd->cAlternateFileName), debugstr_w(wfd->cFileName));
1503 /* prepare buffer with both names */
1504 len = WideCharToMultiByte(CP_ACP,0,wfd->cFileName,-1,buff,MAX_PATH,NULL,NULL);
1505 len1 = WideCharToMultiByte(CP_ACP,0,wfd->cAlternateFileName,-1, buff+len, sizeof(buff)-len, NULL, NULL);
1506 alen = len + len1;
1508 type = (wfd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? PT_FOLDER : PT_VALUE;
1510 wlen = lstrlenW(wfd->cFileName) + 1;
1511 pidl = _ILAlloc(type, FIELD_OFFSET(FileStruct, szNames[alen + (alen & 1)]) +
1512 FIELD_OFFSET(FileStructW, wszName[wlen]) + sizeof(WORD));
1513 if (pidl)
1515 LPPIDLDATA pData = _ILGetDataPointer(pidl);
1516 FileStruct *fs = &pData->u.file;
1517 FileStructW *fsw;
1518 WORD *pOffsetW;
1520 FileTimeToDosDateTime( &wfd->ftLastWriteTime, &fs->uFileDate, &fs->uFileTime);
1521 fs->dwFileSize = wfd->nFileSizeLow;
1522 fs->uFileAttribs = wfd->dwFileAttributes;
1523 memcpy(fs->szNames, buff, alen);
1525 fsw = (FileStructW*)(pData->u.file.szNames + alen + (alen & 0x1));
1526 fsw->cbLen = FIELD_OFFSET(FileStructW, wszName[wlen]) + sizeof(WORD);
1527 FileTimeToDosDateTime( &wfd->ftCreationTime, &fsw->uCreationDate, &fsw->uCreationTime);
1528 FileTimeToDosDateTime( &wfd->ftLastAccessTime, &fsw->uLastAccessDate, &fsw->uLastAccessTime);
1529 memcpy(fsw->wszName, wfd->cFileName, wlen * sizeof(WCHAR));
1531 pOffsetW = (WORD*)((LPBYTE)pidl + pidl->mkid.cb - sizeof(WORD));
1532 *pOffsetW = (LPBYTE)fsw - (LPBYTE)pidl;
1533 TRACE("-- Set Value: %s\n",debugstr_w(fsw->wszName));
1535 return pidl;
1539 HRESULT _ILCreateFromPathW(LPCWSTR szPath, LPITEMIDLIST* ppidl)
1541 HANDLE hFile;
1542 WIN32_FIND_DATAW stffile;
1544 if (!ppidl)
1545 return E_INVALIDARG;
1547 hFile = FindFirstFileW(szPath, &stffile);
1548 if (hFile == INVALID_HANDLE_VALUE)
1549 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
1551 FindClose(hFile);
1553 *ppidl = _ILCreateFromFindDataW(&stffile);
1555 return *ppidl ? S_OK : E_OUTOFMEMORY;
1558 LPITEMIDLIST _ILCreateDrive(LPCWSTR lpszNew)
1560 LPITEMIDLIST pidlOut;
1562 TRACE("(%s)\n",debugstr_w(lpszNew));
1564 pidlOut = _ILAlloc(PT_DRIVE, sizeof(DriveStruct));
1565 if (pidlOut)
1567 LPSTR pszDest;
1569 pszDest = _ILGetTextPointer(pidlOut);
1570 if (pszDest)
1572 strcpy(pszDest, "x:\\");
1573 pszDest[0]=toupperW(lpszNew[0]);
1574 TRACE("-- create Drive: %s\n", debugstr_a(pszDest));
1577 return pidlOut;
1580 LPITEMIDLIST _ILCreateEntireNetwork(void)
1582 LPITEMIDLIST pidlOut;
1584 TRACE("\n");
1586 pidlOut = _ILAlloc(PT_NETWORK, FIELD_OFFSET(PIDLDATA, u.network.szNames[sizeof("Entire Network")]));
1587 if (pidlOut)
1589 LPPIDLDATA pData = _ILGetDataPointer(pidlOut);
1591 pData->u.network.dummy = 0;
1592 strcpy(pData->u.network.szNames, "Entire Network");
1594 return pidlOut;
1597 /**************************************************************************
1598 * _ILGetDrive()
1600 * Gets the text for the drive eg. 'c:\'
1602 * RETURNS
1603 * strlen (lpszText)
1605 DWORD _ILGetDrive(LPCITEMIDLIST pidl,LPSTR pOut, UINT uSize)
1607 TRACE("(%p,%p,%u)\n",pidl,pOut,uSize);
1609 if(_ILIsMyComputer(pidl))
1610 pidl = ILGetNext(pidl);
1612 if (pidl && _ILIsDrive(pidl))
1613 return _ILSimpleGetText(pidl, pOut, uSize);
1615 return 0;
1618 /**************************************************************************
1620 * ### 2. section testing pidls ###
1622 **************************************************************************
1623 * _ILIsUnicode()
1624 * _ILIsDesktop()
1625 * _ILIsMyComputer()
1626 * _ILIsSpecialFolder()
1627 * _ILIsDrive()
1628 * _ILIsFolder()
1629 * _ILIsValue()
1630 * _ILIsPidlSimple()
1632 BOOL _ILIsUnicode(LPCITEMIDLIST pidl)
1634 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1636 TRACE("(%p)\n",pidl);
1638 return (pidl && lpPData && PT_VALUEW == lpPData->type);
1641 BOOL _ILIsDesktop(LPCITEMIDLIST pidl)
1643 TRACE("(%p)\n",pidl);
1645 return pidl && pidl->mkid.cb ? 0 : 1;
1648 BOOL _ILIsMyComputer(LPCITEMIDLIST pidl)
1650 REFIID iid = _ILGetGUIDPointer(pidl);
1652 TRACE("(%p)\n",pidl);
1654 if (iid)
1655 return IsEqualIID(iid, &CLSID_MyComputer);
1656 return FALSE;
1659 BOOL _ILIsSpecialFolder (LPCITEMIDLIST pidl)
1661 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1663 TRACE("(%p)\n",pidl);
1665 return (pidl && ( (lpPData && (PT_GUID== lpPData->type || PT_SHELLEXT== lpPData->type || PT_YAGUID == lpPData->type)) ||
1666 (pidl && pidl->mkid.cb == 0x00)
1670 BOOL _ILIsDrive(LPCITEMIDLIST pidl)
1672 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1674 TRACE("(%p)\n",pidl);
1676 return (pidl && lpPData && (PT_DRIVE == lpPData->type ||
1677 PT_DRIVE1 == lpPData->type ||
1678 PT_DRIVE2 == lpPData->type ||
1679 PT_DRIVE3 == lpPData->type));
1682 BOOL _ILIsFolder(LPCITEMIDLIST pidl)
1684 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1686 TRACE("(%p)\n",pidl);
1688 return (pidl && lpPData && (PT_FOLDER == lpPData->type || PT_FOLDER1 == lpPData->type));
1691 BOOL _ILIsValue(LPCITEMIDLIST pidl)
1693 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1695 TRACE("(%p)\n",pidl);
1697 return (pidl && lpPData && PT_VALUE == lpPData->type);
1700 BOOL _ILIsCPanelStruct(LPCITEMIDLIST pidl)
1702 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1704 TRACE("(%p)\n",pidl);
1706 return (pidl && lpPData && (lpPData->type == 0));
1709 /**************************************************************************
1710 * _ILIsPidlSimple
1712 BOOL _ILIsPidlSimple(LPCITEMIDLIST pidl)
1714 BOOL ret = TRUE;
1716 if(! _ILIsDesktop(pidl)) /* pidl=NULL or mkid.cb=0 */
1718 WORD len = pidl->mkid.cb;
1719 LPCITEMIDLIST pidlnext = (LPCITEMIDLIST) (((const BYTE*)pidl) + len );
1721 if (pidlnext->mkid.cb)
1722 ret = FALSE;
1725 TRACE("%s\n", ret ? "Yes" : "No");
1726 return ret;
1729 /**************************************************************************
1731 * ### 3. section getting values from pidls ###
1734 /**************************************************************************
1735 * _ILSimpleGetText
1737 * gets the text for the first item in the pidl (eg. simple pidl)
1739 * returns the length of the string
1741 DWORD _ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
1743 DWORD dwReturn=0;
1744 LPSTR szSrc;
1745 LPWSTR szSrcW;
1746 GUID const * riid;
1747 char szTemp[MAX_PATH];
1749 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1751 if (!pidl)
1752 return 0;
1754 if (szOut)
1755 *szOut = 0;
1757 if (_ILIsDesktop(pidl))
1759 /* desktop */
1760 if (HCR_GetClassNameA(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1762 if (szOut)
1763 lstrcpynA(szOut, szTemp, uOutSize);
1765 dwReturn = strlen (szTemp);
1768 else if (( szSrc = _ILGetTextPointer(pidl) ))
1770 /* filesystem */
1771 if (szOut)
1772 lstrcpynA(szOut, szSrc, uOutSize);
1774 dwReturn = strlen(szSrc);
1776 else if (( szSrcW = _ILGetTextPointerW(pidl) ))
1778 /* unicode filesystem */
1779 WideCharToMultiByte(CP_ACP,0,szSrcW, -1, szTemp, MAX_PATH, NULL, NULL);
1781 if (szOut)
1782 lstrcpynA(szOut, szTemp, uOutSize);
1784 dwReturn = strlen (szTemp);
1786 else if (( riid = _ILGetGUIDPointer(pidl) ))
1788 /* special folder */
1789 if ( HCR_GetClassNameA(riid, szTemp, MAX_PATH) )
1791 if (szOut)
1792 lstrcpynA(szOut, szTemp, uOutSize);
1794 dwReturn = strlen (szTemp);
1797 else
1799 ERR("-- no text\n");
1802 TRACE("-- (%p=%s 0x%08x)\n",szOut,debugstr_a(szOut),dwReturn);
1803 return dwReturn;
1806 /**************************************************************************
1807 * _ILSimpleGetTextW
1809 * gets the text for the first item in the pidl (eg. simple pidl)
1811 * returns the length of the string
1813 DWORD _ILSimpleGetTextW (LPCITEMIDLIST pidl, LPWSTR szOut, UINT uOutSize)
1815 DWORD dwReturn;
1816 FileStructW *pFileStructW = _ILGetFileStructW(pidl);
1818 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1820 if (pFileStructW) {
1821 lstrcpynW(szOut, pFileStructW->wszName, uOutSize);
1822 dwReturn = lstrlenW(pFileStructW->wszName);
1823 } else {
1824 GUID const * riid;
1825 WCHAR szTemp[MAX_PATH];
1826 LPSTR szSrc;
1827 LPWSTR szSrcW;
1828 dwReturn=0;
1830 if (!pidl)
1831 return 0;
1833 if (szOut)
1834 *szOut = 0;
1836 if (_ILIsDesktop(pidl))
1838 /* desktop */
1839 if (HCR_GetClassNameW(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1841 if (szOut)
1842 lstrcpynW(szOut, szTemp, uOutSize);
1844 dwReturn = lstrlenW (szTemp);
1847 else if (( szSrcW = _ILGetTextPointerW(pidl) ))
1849 /* unicode filesystem */
1850 if (szOut)
1851 lstrcpynW(szOut, szSrcW, uOutSize);
1853 dwReturn = lstrlenW(szSrcW);
1855 else if (( szSrc = _ILGetTextPointer(pidl) ))
1857 /* filesystem */
1858 MultiByteToWideChar(CP_ACP, 0, szSrc, -1, szTemp, MAX_PATH);
1860 if (szOut)
1861 lstrcpynW(szOut, szTemp, uOutSize);
1863 dwReturn = lstrlenW (szTemp);
1865 else if (( riid = _ILGetGUIDPointer(pidl) ))
1867 /* special folder */
1868 if ( HCR_GetClassNameW(riid, szTemp, MAX_PATH) )
1870 if (szOut)
1871 lstrcpynW(szOut, szTemp, uOutSize);
1873 dwReturn = lstrlenW (szTemp);
1876 else
1878 ERR("-- no text\n");
1882 TRACE("-- (%p=%s 0x%08x)\n",szOut,debugstr_w(szOut),dwReturn);
1883 return dwReturn;
1886 /**************************************************************************
1888 * ### 4. getting pointers to parts of pidls ###
1890 **************************************************************************
1891 * _ILGetDataPointer()
1893 LPPIDLDATA _ILGetDataPointer(LPCITEMIDLIST pidl)
1895 if(pidl && pidl->mkid.cb != 0x00)
1896 return (LPPIDLDATA)pidl->mkid.abID;
1897 return NULL;
1900 /**************************************************************************
1901 * _ILGetTextPointerW()
1902 * gets a pointer to the unicode long filename string stored in the pidl
1904 LPWSTR _ILGetTextPointerW(LPCITEMIDLIST pidl)
1906 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
1908 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
1910 if (!pdata)
1911 return NULL;
1913 switch (pdata->type)
1915 case PT_GUID:
1916 case PT_SHELLEXT:
1917 case PT_YAGUID:
1918 return NULL;
1920 case PT_DRIVE:
1921 case PT_DRIVE1:
1922 case PT_DRIVE2:
1923 case PT_DRIVE3:
1924 /*return (LPSTR)&(pdata->u.drive.szDriveName);*/
1925 return NULL;
1927 case PT_FOLDER:
1928 case PT_FOLDER1:
1929 case PT_VALUE:
1930 case PT_IESPECIAL1:
1931 case PT_IESPECIAL2:
1932 /*return (LPSTR)&(pdata->u.file.szNames);*/
1933 return NULL;
1935 case PT_WORKGRP:
1936 case PT_COMP:
1937 case PT_NETWORK:
1938 case PT_NETPROVIDER:
1939 case PT_SHARE:
1940 /*return (LPSTR)&(pdata->u.network.szNames);*/
1941 return NULL;
1943 case PT_VALUEW:
1944 return (LPWSTR)pdata->u.file.szNames;
1946 return NULL;
1950 /**************************************************************************
1951 * _ILGetTextPointer()
1952 * gets a pointer to the long filename string stored in the pidl
1954 LPSTR _ILGetTextPointer(LPCITEMIDLIST pidl)
1956 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
1958 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
1960 if (!pdata)
1961 return NULL;
1963 switch (pdata->type)
1965 case PT_GUID:
1966 case PT_SHELLEXT:
1967 case PT_YAGUID:
1968 return NULL;
1970 case PT_DRIVE:
1971 case PT_DRIVE1:
1972 case PT_DRIVE2:
1973 case PT_DRIVE3:
1974 return (LPSTR)pdata->u.drive.szDriveName;
1976 case PT_FOLDER:
1977 case PT_FOLDER1:
1978 case PT_VALUE:
1979 case PT_IESPECIAL1:
1980 case PT_IESPECIAL2:
1981 return (LPSTR)pdata->u.file.szNames;
1983 case PT_WORKGRP:
1984 case PT_COMP:
1985 case PT_NETWORK:
1986 case PT_NETPROVIDER:
1987 case PT_SHARE:
1988 return (LPSTR)pdata->u.network.szNames;
1990 return NULL;
1993 /**************************************************************************
1994 * _ILGetSTextPointer()
1995 * gets a pointer to the short filename string stored in the pidl
1997 LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl)
1999 /* TRACE(pidl,"(pidl%p)\n", pidl); */
2001 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
2003 if (!pdata)
2004 return NULL;
2006 switch (pdata->type)
2008 case PT_FOLDER:
2009 case PT_VALUE:
2010 case PT_IESPECIAL1:
2011 case PT_IESPECIAL2:
2012 return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1);
2014 case PT_WORKGRP:
2015 return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1);
2017 return NULL;
2020 /**************************************************************************
2021 * _ILGetGUIDPointer()
2023 * returns reference to guid stored in some pidls
2025 IID* _ILGetGUIDPointer(LPCITEMIDLIST pidl)
2027 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
2029 TRACE("%p\n", pidl);
2031 if (!pdata)
2032 return NULL;
2034 TRACE("pdata->type 0x%04x\n", pdata->type);
2035 switch (pdata->type)
2037 case PT_SHELLEXT:
2038 case PT_GUID:
2039 case PT_YAGUID:
2040 return &(pdata->u.guid.guid);
2042 default:
2043 TRACE("Unknown pidl type 0x%04x\n", pdata->type);
2044 break;
2046 return NULL;
2049 /******************************************************************************
2050 * _ILGetFileStructW [Internal]
2052 * Get pointer the a SHITEMID's FileStructW field if present
2054 * PARAMS
2055 * pidl [I] The SHITEMID
2057 * RETURNS
2058 * Success: Pointer to pidl's FileStructW field.
2059 * Failure: NULL
2061 FileStructW* _ILGetFileStructW(LPCITEMIDLIST pidl) {
2062 FileStructW *pFileStructW;
2063 WORD cbOffset;
2065 if (!(_ILIsValue(pidl) || _ILIsFolder(pidl)))
2066 return NULL;
2068 cbOffset = *(const WORD *)((const BYTE *)pidl + pidl->mkid.cb - sizeof(WORD));
2069 pFileStructW = (FileStructW*)((LPBYTE)pidl + cbOffset);
2071 /* Currently I don't see a fool prove way to figure out if a pidl is for sure of WinXP
2072 * style with a FileStructW member. If we switch all our shellfolder-implementations to
2073 * the new format, this won't be a problem. For now, we do as many sanity checks as possible. */
2074 if (cbOffset & 0x1 || /* FileStructW member is word aligned in the pidl */
2075 /* FileStructW is positioned after FileStruct */
2076 cbOffset < sizeof(pidl->mkid.cb) + sizeof(PIDLTYPE) + sizeof(FileStruct) ||
2077 /* There has to be enough space at cbOffset in the pidl to hold FileStructW and cbOffset */
2078 cbOffset > pidl->mkid.cb - sizeof(cbOffset) - sizeof(FileStructW) ||
2079 pidl->mkid.cb != cbOffset + pFileStructW->cbLen)
2081 WARN("Invalid pidl format (cbOffset = %d)!\n", cbOffset);
2082 return NULL;
2085 return pFileStructW;
2088 /*************************************************************************
2089 * _ILGetFileDateTime
2091 * Given the ItemIdList, get the FileTime
2093 * PARAMS
2094 * pidl [I] The ItemIDList
2095 * pFt [I] the resulted FILETIME of the file
2097 * RETURNS
2098 * True if Successful
2100 * NOTES
2103 BOOL _ILGetFileDateTime(LPCITEMIDLIST pidl, FILETIME *pFt)
2105 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2107 if (!pdata)
2108 return FALSE;
2110 switch (pdata->type)
2112 case PT_FOLDER:
2113 case PT_VALUE:
2114 DosDateTimeToFileTime(pdata->u.file.uFileDate, pdata->u.file.uFileTime, pFt);
2115 break;
2116 default:
2117 return FALSE;
2119 return TRUE;
2122 BOOL _ILGetFileDate (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2124 FILETIME ft,lft;
2125 SYSTEMTIME time;
2126 BOOL ret;
2128 if (_ILGetFileDateTime( pidl, &ft ))
2130 FileTimeToLocalFileTime(&ft, &lft);
2131 FileTimeToSystemTime (&lft, &time);
2133 ret = GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&time, NULL, pOut, uOutSize);
2134 if (ret)
2136 /* Append space + time without seconds */
2137 pOut[ret-1] = ' ';
2138 GetTimeFormatA(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &time, NULL, &pOut[ret], uOutSize - ret);
2141 else
2143 pOut[0] = '\0';
2144 ret = FALSE;
2146 return ret;
2149 /*************************************************************************
2150 * _ILGetFileSize
2152 * Given the ItemIdList, get the FileSize
2154 * PARAMS
2155 * pidl [I] The ItemIDList
2156 * pOut [I] The buffer to save the result
2157 * uOutsize [I] The size of the buffer
2159 * RETURNS
2160 * The FileSize
2162 * NOTES
2163 * pOut can be null when no string is needed
2166 DWORD _ILGetFileSize (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2168 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2169 DWORD dwSize;
2171 if (!pdata)
2172 return 0;
2174 switch (pdata->type)
2176 case PT_VALUE:
2177 dwSize = pdata->u.file.dwFileSize;
2178 if (pOut)
2179 StrFormatKBSizeA(dwSize, pOut, uOutSize);
2180 return dwSize;
2182 if (pOut)
2183 *pOut = 0x00;
2184 return 0;
2187 BOOL _ILGetExtension (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2189 char szTemp[MAX_PATH];
2190 const char * pPoint;
2191 LPCITEMIDLIST pidlTemp=pidl;
2193 TRACE("pidl=%p\n",pidl);
2195 if (!pidl)
2196 return FALSE;
2198 pidlTemp = ILFindLastID(pidl);
2200 if (!_ILIsValue(pidlTemp))
2201 return FALSE;
2202 if (!_ILSimpleGetText(pidlTemp, szTemp, MAX_PATH))
2203 return FALSE;
2205 pPoint = PathFindExtensionA(szTemp);
2207 if (!*pPoint)
2208 return FALSE;
2210 pPoint++;
2211 lstrcpynA(pOut, pPoint, uOutSize);
2212 TRACE("%s\n",pOut);
2214 return TRUE;
2217 /*************************************************************************
2218 * _ILGetFileType
2220 * Given the ItemIdList, get the file type description
2222 * PARAMS
2223 * pidl [I] The ItemIDList (simple)
2224 * pOut [I] The buffer to save the result
2225 * uOutsize [I] The size of the buffer
2227 * RETURNS
2228 * nothing
2230 * NOTES
2231 * This function copies as much as possible into the buffer.
2233 void _ILGetFileType(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2235 if(_ILIsValue(pidl))
2237 char sTemp[64];
2239 if(uOutSize > 0)
2240 pOut[0] = 0;
2241 if (_ILGetExtension (pidl, sTemp, 64))
2243 if (!( HCR_MapTypeToValueA(sTemp, sTemp, 64, TRUE)
2244 && HCR_MapTypeToValueA(sTemp, pOut, uOutSize, FALSE )))
2246 lstrcpynA (pOut, sTemp, uOutSize - 6);
2247 strcat (pOut, "-file");
2251 else
2252 lstrcpynA(pOut, "Folder", uOutSize);
2255 /*************************************************************************
2256 * _ILGetFileAttributes
2258 * Given the ItemIdList, get the Attrib string format
2260 * PARAMS
2261 * pidl [I] The ItemIDList
2262 * pOut [I] The buffer to save the result
2263 * uOutsize [I] The size of the Buffer
2265 * RETURNS
2266 * Attributes
2268 * FIXME
2269 * return value 0 in case of error is a valid return value
2272 DWORD _ILGetFileAttributes(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2274 LPPIDLDATA pData = _ILGetDataPointer(pidl);
2275 WORD wAttrib = 0;
2276 int i;
2278 if (!pData)
2279 return 0;
2281 switch(pData->type)
2283 case PT_FOLDER:
2284 case PT_VALUE:
2285 wAttrib = pData->u.file.uFileAttribs;
2286 break;
2289 if(uOutSize >= 6)
2291 i=0;
2292 if(wAttrib & FILE_ATTRIBUTE_READONLY)
2293 pOut[i++] = 'R';
2294 if(wAttrib & FILE_ATTRIBUTE_HIDDEN)
2295 pOut[i++] = 'H';
2296 if(wAttrib & FILE_ATTRIBUTE_SYSTEM)
2297 pOut[i++] = 'S';
2298 if(wAttrib & FILE_ATTRIBUTE_ARCHIVE)
2299 pOut[i++] = 'A';
2300 if(wAttrib & FILE_ATTRIBUTE_COMPRESSED)
2301 pOut[i++] = 'C';
2302 pOut[i] = 0x00;
2304 return wAttrib;
2307 /*************************************************************************
2308 * ILFreeaPidl
2310 * free a aPidl struct
2312 void _ILFreeaPidl(LPITEMIDLIST * apidl, UINT cidl)
2314 UINT i;
2316 if (apidl)
2318 for (i = 0; i < cidl; i++)
2319 SHFree(apidl[i]);
2320 SHFree(apidl);
2324 /*************************************************************************
2325 * ILCopyaPidl
2327 * copies an aPidl struct
2329 LPITEMIDLIST* _ILCopyaPidl(const LPCITEMIDLIST * apidlsrc, UINT cidl)
2331 UINT i;
2332 LPITEMIDLIST *apidldest;
2334 apidldest = SHAlloc(cidl * sizeof(LPITEMIDLIST));
2335 if (!apidlsrc)
2336 return NULL;
2338 for (i = 0; i < cidl; i++)
2339 apidldest[i] = ILClone(apidlsrc[i]);
2341 return apidldest;
2344 /*************************************************************************
2345 * _ILCopyCidaToaPidl
2347 * creates aPidl from CIDA
2349 LPITEMIDLIST* _ILCopyCidaToaPidl(LPITEMIDLIST* pidl, const CIDA * cida)
2351 UINT i;
2352 LPITEMIDLIST *dst;
2354 dst = SHAlloc(cida->cidl * sizeof(LPITEMIDLIST));
2355 if (!dst)
2356 return NULL;
2358 if (pidl)
2359 *pidl = ILClone((LPCITEMIDLIST)(&((const BYTE*)cida)[cida->aoffset[0]]));
2361 for (i = 0; i < cida->cidl; i++)
2362 dst[i] = ILClone((LPCITEMIDLIST)(&((const BYTE*)cida)[cida->aoffset[i + 1]]));
2364 return dst;
2367 HRESULT WINAPI SHCreateShellItem(LPCITEMIDLIST pidlParent,
2368 IShellFolder *psfParent, LPCITEMIDLIST pidl, void **ppsi)
2370 FIXME("STUB: %p %p %p %p\n",pidlParent, psfParent, pidl, ppsi);
2371 return E_NOINTERFACE;