server: Send WM_WINE_SETCURSOR with the thread input cursor handle.
[wine.git] / dlls / shell32 / pidl.c
blob668a5bc583aa250ef0989760396f7525500d127a
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 <ctype.h>
26 #include <stdarg.h>
27 #include <stdlib.h>
28 #include <string.h>
30 #define COBJMACROS
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winreg.h"
34 #include "objbase.h"
35 #include "shlguid.h"
36 #include "winerror.h"
37 #include "winnls.h"
38 #include "shell32_main.h"
39 #include "shlwapi.h"
41 #include "pidl.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(pidl);
45 WINE_DECLARE_DEBUG_CHANNEL(shell);
47 /* from comctl32.dll */
48 extern LPVOID WINAPI Alloc(INT);
49 extern BOOL WINAPI Free(LPVOID);
51 static LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl);
52 static LPWSTR _ILGetTextPointerW(LPCITEMIDLIST pidl);
54 /*************************************************************************
55 * ILGetDisplayNameExA
57 * Retrieves the display name of an ItemIDList
59 * PARAMS
60 * psf [I] Shell Folder to start with, if NULL the desktop is used
61 * pidl [I] ItemIDList relative to the psf to get the display name for
62 * path [O] Filled in with the display name, assumed to be at least MAX_PATH long
63 * type [I] Type of display name to retrieve
64 * 0 = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR uses always the desktop as root
65 * 1 = SHGDN_NORMAL relative to the root folder
66 * 2 = SHGDN_INFOLDER relative to the root folder, only the last name
68 * RETURNS
69 * True if the display name could be retrieved successfully, False otherwise
71 static BOOL ILGetDisplayNameExA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPSTR path, DWORD type)
73 BOOL ret = FALSE;
74 WCHAR wPath[MAX_PATH];
76 TRACE("%p %p %p %ld\n", psf, pidl, path, type);
78 if (!pidl || !path)
79 return FALSE;
81 ret = ILGetDisplayNameExW(psf, pidl, wPath, type);
82 WideCharToMultiByte(CP_ACP, 0, wPath, -1, path, MAX_PATH, NULL, NULL);
83 TRACE("%p %p %s\n", psf, pidl, debugstr_a(path));
85 return ret;
88 BOOL ILGetDisplayNameExW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPWSTR path, DWORD type)
90 LPSHELLFOLDER psfParent, lsf = psf;
91 HRESULT ret = NO_ERROR;
92 LPCITEMIDLIST pidllast;
93 STRRET strret;
94 DWORD flag;
96 TRACE("%p %p %p %lx\n", psf, pidl, path, type);
98 if (!pidl || !path)
99 return FALSE;
101 if (!lsf)
103 ret = SHGetDesktopFolder(&lsf);
104 if (FAILED(ret))
105 return FALSE;
108 switch (type)
110 case ILGDN_FORPARSING:
111 flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
112 break;
113 case ILGDN_NORMAL:
114 flag = SHGDN_NORMAL;
115 break;
116 case ILGDN_INFOLDER:
117 flag = SHGDN_INFOLDER;
118 break;
119 default:
120 FIXME("Unknown type parameter = %lx\n", type);
121 flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
122 break;
125 if (!*(const WORD*)pidl || type == ILGDN_FORPARSING)
127 ret = IShellFolder_GetDisplayNameOf(lsf, pidl, flag, &strret);
128 if (SUCCEEDED(ret))
130 if(!StrRetToStrNW(path, MAX_PATH, &strret, pidl))
131 ret = E_FAIL;
134 else
136 ret = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psfParent, &pidllast);
137 if (SUCCEEDED(ret))
139 ret = IShellFolder_GetDisplayNameOf(psfParent, pidllast, flag, &strret);
140 if (SUCCEEDED(ret))
142 if(!StrRetToStrNW(path, MAX_PATH, &strret, pidllast))
143 ret = E_FAIL;
145 IShellFolder_Release(psfParent);
149 TRACE("%p %p %s\n", psf, pidl, debugstr_w(path));
151 if (!psf)
152 IShellFolder_Release(lsf);
153 return SUCCEEDED(ret);
156 /*************************************************************************
157 * ILGetDisplayNameEx [SHELL32.186]
159 BOOL WINAPI ILGetDisplayNameEx(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPVOID path, DWORD type)
161 TRACE_(shell)("%p %p %p %ld\n", psf, pidl, path, type);
163 if (SHELL_OsIsUnicode())
164 return ILGetDisplayNameExW(psf, pidl, path, type);
165 return ILGetDisplayNameExA(psf, pidl, path, type);
168 /*************************************************************************
169 * ILGetDisplayName [SHELL32.15]
171 BOOL WINAPI ILGetDisplayName(LPCITEMIDLIST pidl, LPVOID path)
173 TRACE_(shell)("%p %p\n", pidl, path);
175 if (SHELL_OsIsUnicode())
176 return ILGetDisplayNameExW(NULL, pidl, path, ILGDN_FORPARSING);
177 return ILGetDisplayNameExA(NULL, pidl, path, ILGDN_FORPARSING);
180 /*************************************************************************
181 * ILFindLastID [SHELL32.16]
183 * NOTES
184 * observed: pidl=Desktop return=pidl
186 LPITEMIDLIST WINAPI ILFindLastID(LPCITEMIDLIST pidl)
188 LPCITEMIDLIST pidlLast = pidl;
190 TRACE("(pidl=%p)\n",pidl);
192 if (!pidl)
193 return NULL;
195 while (pidl->mkid.cb)
197 pidlLast = pidl;
198 pidl = ILGetNext(pidl);
200 return (LPITEMIDLIST)pidlLast;
203 /*************************************************************************
204 * ILRemoveLastID [SHELL32.17]
206 * NOTES
207 * when pidl=Desktop return=FALSE
209 BOOL WINAPI ILRemoveLastID(LPITEMIDLIST pidl)
211 TRACE_(shell)("pidl=%p\n",pidl);
213 if (_ILIsEmpty(pidl))
214 return FALSE;
215 ILFindLastID(pidl)->mkid.cb = 0;
216 return TRUE;
219 /*************************************************************************
220 * ILClone [SHELL32.18]
222 * NOTES
223 * duplicate an idlist
225 LPITEMIDLIST WINAPI ILClone (LPCITEMIDLIST pidl)
227 DWORD len;
228 LPITEMIDLIST newpidl;
230 if (!pidl)
231 return NULL;
233 len = ILGetSize(pidl);
234 newpidl = SHAlloc(len);
235 if (newpidl)
236 memcpy(newpidl,pidl,len);
238 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
239 pdump(pidl);
241 return newpidl;
244 /*************************************************************************
245 * ILCloneFirst [SHELL32.19]
247 * NOTES
248 * duplicates the first idlist of a complex pidl
250 LPITEMIDLIST WINAPI ILCloneFirst(LPCITEMIDLIST pidl)
252 DWORD len;
253 LPITEMIDLIST pidlNew = NULL;
255 TRACE("pidl=%p\n", pidl);
256 pdump(pidl);
258 if (pidl)
260 len = pidl->mkid.cb;
261 pidlNew = SHAlloc(len+2);
262 if (pidlNew)
264 memcpy(pidlNew,pidl,len+2); /* 2 -> mind a desktop pidl */
266 if (len)
267 ILGetNext(pidlNew)->mkid.cb = 0x00;
270 TRACE("-- newpidl=%p\n",pidlNew);
272 return pidlNew;
275 /*************************************************************************
276 * ILLoadFromStream (SHELL32.26)
278 * NOTES
279 * the first two bytes are the len, the pidl is following then
281 HRESULT WINAPI ILLoadFromStream (IStream * pStream, LPITEMIDLIST * ppPidl)
283 WORD wLen = 0;
284 DWORD dwBytesRead;
285 HRESULT ret = E_FAIL;
288 TRACE_(shell)("%p %p\n", pStream , ppPidl);
290 SHFree(*ppPidl);
291 *ppPidl = NULL;
293 IStream_AddRef (pStream);
295 if (SUCCEEDED(IStream_Read(pStream, &wLen, 2, &dwBytesRead)))
297 TRACE("PIDL length is %d\n", wLen);
298 if (wLen != 0)
300 *ppPidl = SHAlloc (wLen);
301 if (SUCCEEDED(IStream_Read(pStream, *ppPidl , wLen, &dwBytesRead)))
303 TRACE("Stream read OK\n");
304 ret = S_OK;
306 else
308 WARN("reading pidl failed\n");
309 SHFree(*ppPidl);
310 *ppPidl = NULL;
313 else
315 *ppPidl = NULL;
316 ret = S_OK;
320 /* we are not yet fully compatible */
321 if (*ppPidl && !pcheck(*ppPidl))
323 WARN("Check failed\n");
324 SHFree(*ppPidl);
325 *ppPidl = NULL;
328 IStream_Release (pStream);
329 TRACE("done\n");
330 return ret;
333 /*************************************************************************
334 * ILSaveToStream (SHELL32.27)
336 * NOTES
337 * the first two bytes are the len, the pidl is following then
339 HRESULT WINAPI ILSaveToStream (IStream * pStream, LPCITEMIDLIST pPidl)
341 WORD wLen = 0;
342 HRESULT ret = E_FAIL;
344 TRACE_(shell)("%p %p\n", pStream, pPidl);
346 IStream_AddRef (pStream);
348 wLen = ILGetSize(pPidl);
350 if (SUCCEEDED(IStream_Write(pStream, &wLen, 2, NULL)))
352 if (SUCCEEDED(IStream_Write(pStream, pPidl, wLen, NULL)))
353 ret = S_OK;
355 IStream_Release (pStream);
357 return ret;
360 /*************************************************************************
361 * SHILCreateFromPath [SHELL32.28]
363 * Create an ItemIDList from a path
365 * PARAMS
366 * path [I]
367 * ppidl [O]
368 * attributes [I/O] requested attributes on call and actual attributes when
369 * the function returns
371 * RETURNS
372 * NO_ERROR if successful, or an OLE errer code otherwise
374 * NOTES
375 * Wrapper for IShellFolder_ParseDisplayName().
377 static HRESULT SHILCreateFromPathA(LPCSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
379 WCHAR lpszDisplayName[MAX_PATH];
381 TRACE_(shell)("%s %p 0x%08lx\n", path, ppidl, attributes ? *attributes : 0);
383 if (!MultiByteToWideChar(CP_ACP, 0, path, -1, lpszDisplayName, MAX_PATH))
384 lpszDisplayName[MAX_PATH-1] = 0;
386 return SHILCreateFromPathW(lpszDisplayName, ppidl, attributes);
389 HRESULT SHILCreateFromPathW(LPCWSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
391 LPSHELLFOLDER sf;
392 DWORD pchEaten;
393 HRESULT ret = E_FAIL;
395 TRACE_(shell)("%s %p 0x%08lx\n", debugstr_w(path), ppidl, attributes ? *attributes : 0);
397 if (SUCCEEDED (SHGetDesktopFolder(&sf)))
399 ret = IShellFolder_ParseDisplayName(sf, 0, NULL, (LPWSTR)path, &pchEaten, ppidl, attributes);
400 IShellFolder_Release(sf);
402 return ret;
405 HRESULT WINAPI SHILCreateFromPathAW (LPCVOID path, LPITEMIDLIST * ppidl, DWORD * attributes)
407 if ( SHELL_OsIsUnicode())
408 return SHILCreateFromPathW (path, ppidl, attributes);
409 return SHILCreateFromPathA (path, ppidl, attributes);
412 /*************************************************************************
413 * SHCloneSpecialIDList [SHELL32.89]
415 * Create an ItemIDList to one of the special folders.
417 * PARAMS
418 * hwndOwner [in]
419 * nFolder [in] CSIDL_xxxxx
420 * fCreate [in] Create folder if it does not exist
422 * RETURNS
423 * Success: The newly created pidl
424 * Failure: NULL, if inputs are invalid.
426 * NOTES
427 * exported by ordinal.
428 * Caller is responsible for deallocating the returned ItemIDList with the
429 * shells IMalloc interface, aka ILFree.
431 LPITEMIDLIST WINAPI SHCloneSpecialIDList(HWND hwndOwner, DWORD nFolder, BOOL fCreate)
433 LPITEMIDLIST ppidl;
434 TRACE_(shell)("(hwnd=%p,csidl=0x%lx,%s).\n", hwndOwner, nFolder, fCreate ? "T" : "F");
436 if (fCreate)
437 nFolder |= CSIDL_FLAG_CREATE;
439 SHGetSpecialFolderLocation(hwndOwner, nFolder, &ppidl);
440 return ppidl;
443 /*************************************************************************
444 * ILGlobalClone [SHELL32.20]
446 * Clones an ItemIDList using Alloc.
448 * PARAMS
449 * pidl [I] ItemIDList to clone
451 * RETURNS
452 * Newly allocated ItemIDList.
454 * NOTES
455 * exported by ordinal.
457 LPITEMIDLIST WINAPI ILGlobalClone(LPCITEMIDLIST pidl)
459 DWORD len;
460 LPITEMIDLIST newpidl;
462 if (!pidl)
463 return NULL;
465 len = ILGetSize(pidl);
466 newpidl = Alloc(len);
467 if (newpidl)
468 memcpy(newpidl,pidl,len);
470 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
471 pdump(pidl);
473 return newpidl;
476 /*************************************************************************
477 * ILIsEqual [SHELL32.21]
480 BOOL WINAPI ILIsEqual(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
482 char szData1[MAX_PATH];
483 char szData2[MAX_PATH];
485 LPCITEMIDLIST pidltemp1 = pidl1;
486 LPCITEMIDLIST pidltemp2 = pidl2;
488 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
491 * Explorer reads from registry directly (StreamMRU),
492 * so we can only check here
494 if (!pcheck(pidl1) || !pcheck (pidl2))
495 return FALSE;
497 pdump (pidl1);
498 pdump (pidl2);
500 if (!pidl1 || !pidl2)
501 return FALSE;
503 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
505 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
506 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
508 if (lstrcmpiA( szData1, szData2 ))
509 return FALSE;
511 pidltemp1 = ILGetNext(pidltemp1);
512 pidltemp2 = ILGetNext(pidltemp2);
515 if (!pidltemp1->mkid.cb && !pidltemp2->mkid.cb)
516 return TRUE;
518 return FALSE;
521 /*************************************************************************
522 * ILIsParent [SHELL32.23]
524 * Verifies that pidlParent is indeed the (immediate) parent of pidlChild.
526 * PARAMS
527 * pidlParent [I]
528 * pidlChild [I]
529 * bImmediate [I] only return true if the parent is the direct parent
530 * of the child
532 * RETURNS
533 * True if the parent ItemIDlist is a complete part of the child ItemIdList,
534 * False otherwise.
536 * NOTES
537 * parent = a/b, child = a/b/c -> true, c is in folder a/b
538 * child = a/b/c/d -> false if bImmediate is true, d is not in folder a/b
539 * child = a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
540 * child = a/b -> false if bImmediate is true
541 * child = a/b -> true if bImmediate is false
543 BOOL WINAPI ILIsParent(LPCITEMIDLIST pidlParent, LPCITEMIDLIST pidlChild, BOOL bImmediate)
545 char szData1[MAX_PATH];
546 char szData2[MAX_PATH];
547 LPCITEMIDLIST pParent = pidlParent;
548 LPCITEMIDLIST pChild = pidlChild;
550 TRACE("%p %p %x\n", pidlParent, pidlChild, bImmediate);
552 if (!pParent || !pChild)
553 return FALSE;
555 while (pParent->mkid.cb && pChild->mkid.cb)
557 _ILSimpleGetText(pParent, szData1, MAX_PATH);
558 _ILSimpleGetText(pChild, szData2, MAX_PATH);
560 if (lstrcmpiA( szData1, szData2 ))
561 return FALSE;
563 pParent = ILGetNext(pParent);
564 pChild = ILGetNext(pChild);
567 /* child has shorter name than parent */
568 if (pParent->mkid.cb)
569 return FALSE;
571 /* not immediate descent */
572 if ((!pChild->mkid.cb || ILGetNext(pChild)->mkid.cb) && bImmediate)
573 return FALSE;
575 return TRUE;
578 /*************************************************************************
579 * ILFindChild [SHELL32.24]
581 * Compares elements from pidl1 and pidl2.
583 * PARAMS
584 * pidl1 [I]
585 * pidl2 [I]
587 * RETURNS
588 * pidl1 is desktop pidl2
589 * pidl1 shorter pidl2 pointer to first different element of pidl2
590 * if there was at least one equal element
591 * pidl2 shorter pidl1 0
592 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
594 * NOTES
595 * exported by ordinal.
597 LPITEMIDLIST WINAPI ILFindChild(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
599 char szData1[MAX_PATH];
600 char szData2[MAX_PATH];
602 LPCITEMIDLIST pidltemp1 = pidl1;
603 LPCITEMIDLIST pidltemp2 = pidl2;
604 LPCITEMIDLIST ret=NULL;
606 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
608 /* explorer reads from registry directly (StreamMRU),
609 so we can only check here */
610 if ((!pcheck (pidl1)) || (!pcheck (pidl2)))
611 return FALSE;
613 pdump (pidl1);
614 pdump (pidl2);
616 if (_ILIsDesktop(pidl1))
618 ret = pidl2;
620 else
622 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
624 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
625 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
627 if (lstrcmpiA(szData1,szData2))
628 break;
630 pidltemp1 = ILGetNext(pidltemp1);
631 pidltemp2 = ILGetNext(pidltemp2);
632 ret = pidltemp2;
635 if (pidltemp1->mkid.cb)
636 ret = NULL; /* elements of pidl1 left*/
638 TRACE_(shell)("--- %p\n", ret);
639 return (LPITEMIDLIST)ret; /* pidl 1 is shorter */
642 /*************************************************************************
643 * ILCombine [SHELL32.25]
645 * Concatenates two complex ItemIDLists.
647 * PARAMS
648 * pidl1 [I] first complex ItemIDLists
649 * pidl2 [I] complex ItemIDLists to append
651 * RETURNS
652 * if both pidl's == NULL NULL
653 * if pidl1 == NULL cloned pidl2
654 * if pidl2 == NULL cloned pidl1
655 * otherwise new pidl with pidl2 appended to pidl1
657 * NOTES
658 * exported by ordinal.
659 * Does not destroy the passed in ItemIDLists!
661 LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
663 DWORD len1,len2;
664 LPITEMIDLIST pidlNew;
666 TRACE("pidl=%p pidl=%p\n",pidl1,pidl2);
668 if (!pidl1 && !pidl2) return NULL;
670 pdump (pidl1);
671 pdump (pidl2);
673 if (!pidl1)
675 pidlNew = ILClone(pidl2);
676 return pidlNew;
679 if (!pidl2)
681 pidlNew = ILClone(pidl1);
682 return pidlNew;
685 len1 = ILGetSize(pidl1)-2;
686 len2 = ILGetSize(pidl2);
687 pidlNew = SHAlloc(len1+len2);
689 if (pidlNew)
691 memcpy(pidlNew,pidl1,len1);
692 memcpy(((BYTE *)pidlNew)+len1,pidl2,len2);
695 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
696 return pidlNew;
699 /*************************************************************************
700 * SHGetRealIDL [SHELL32.98]
702 * NOTES
704 HRESULT WINAPI SHGetRealIDL(LPSHELLFOLDER lpsf, LPCITEMIDLIST pidlSimple, LPITEMIDLIST *pidlReal)
706 IDataObject* pDataObj;
707 HRESULT hr;
709 hr = IShellFolder_GetUIObjectOf(lpsf, 0, 1, &pidlSimple,
710 &IID_IDataObject, 0, (LPVOID*)&pDataObj);
711 if (SUCCEEDED(hr))
713 STGMEDIUM medium;
714 FORMATETC fmt;
716 fmt.cfFormat = RegisterClipboardFormatW(CFSTR_SHELLIDLISTW);
717 fmt.ptd = NULL;
718 fmt.dwAspect = DVASPECT_CONTENT;
719 fmt.lindex = -1;
720 fmt.tymed = TYMED_HGLOBAL;
722 hr = IDataObject_GetData(pDataObj, &fmt, &medium);
724 IDataObject_Release(pDataObj);
726 if (SUCCEEDED(hr))
728 /*assert(pida->cidl==1);*/
729 LPIDA pida = GlobalLock(medium.hGlobal);
731 LPCITEMIDLIST pidl_folder = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[0]);
732 LPCITEMIDLIST pidl_child = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[1]);
734 *pidlReal = ILCombine(pidl_folder, pidl_child);
736 if (!*pidlReal)
737 hr = E_OUTOFMEMORY;
739 GlobalUnlock(medium.hGlobal);
740 GlobalFree(medium.hGlobal);
744 return hr;
747 /*************************************************************************
748 * SHLogILFromFSIL [SHELL32.95]
750 * NOTES
751 * pild = CSIDL_DESKTOP ret = 0
752 * pild = CSIDL_DRIVES ret = 0
754 LPITEMIDLIST WINAPI SHLogILFromFSIL(LPITEMIDLIST pidl)
756 FIXME("(pidl=%p)\n",pidl);
758 pdump(pidl);
760 return 0;
763 /*************************************************************************
764 * ILGetSize [SHELL32.152]
766 * Gets the byte size of an ItemIDList including zero terminator
768 * PARAMS
769 * pidl [I] ItemIDList
771 * RETURNS
772 * size of pidl in bytes
774 * NOTES
775 * exported by ordinal
777 UINT WINAPI ILGetSize(LPCITEMIDLIST pidl)
779 LPCSHITEMID si = &(pidl->mkid);
780 UINT len=0;
782 if (pidl)
784 while (si->cb)
786 len += si->cb;
787 si = (LPCSHITEMID)(((const BYTE*)si)+si->cb);
789 len += 2;
791 TRACE("pidl=%p size=%u\n",pidl, len);
792 return len;
795 /*************************************************************************
796 * ILGetNext [SHELL32.153]
798 * Gets the next ItemID of an ItemIDList
800 * PARAMS
801 * pidl [I] ItemIDList
803 * RETURNS
804 * null -> null
805 * desktop -> null
806 * simple pidl -> pointer to 0x0000 element
808 * NOTES
809 * exported by ordinal.
811 LPITEMIDLIST WINAPI ILGetNext(LPCITEMIDLIST pidl)
813 WORD len;
815 TRACE("%p\n", pidl);
817 if (pidl)
819 len = pidl->mkid.cb;
820 if (len)
822 pidl = (LPCITEMIDLIST) (((const BYTE*)pidl)+len);
823 TRACE("-- %p\n", pidl);
824 return (LPITEMIDLIST)pidl;
827 return NULL;
830 /*************************************************************************
831 * ILAppendID [SHELL32.154]
833 * Adds the single ItemID item to the ItemIDList indicated by pidl.
834 * If bEnd is FALSE, inserts the item in the front of the list,
835 * otherwise it adds the item to the end. (???)
837 * PARAMS
838 * pidl [I] ItemIDList to extend
839 * item [I] ItemID to prepend/append
840 * bEnd [I] Indicates if the item should be appended
842 * NOTES
843 * Destroys the passed in idlist! (???)
845 LPITEMIDLIST WINAPI ILAppendID(LPITEMIDLIST pidl, LPCSHITEMID item, BOOL bEnd)
847 LPITEMIDLIST idlRet;
848 LPCITEMIDLIST itemid = (LPCITEMIDLIST)item;
850 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl,item,bEnd);
852 pdump (pidl);
853 pdump (itemid);
855 if (_ILIsDesktop(pidl))
857 idlRet = ILClone(itemid);
858 SHFree (pidl);
859 return idlRet;
862 if (bEnd)
863 idlRet = ILCombine(pidl, itemid);
864 else
865 idlRet = ILCombine(itemid, pidl);
867 SHFree(pidl);
868 return idlRet;
871 /*************************************************************************
872 * ILFree [SHELL32.155]
874 * Frees memory (if not NULL) allocated by SHMalloc allocator
876 * PARAMS
877 * pidl [I]
879 * RETURNS
880 * Nothing
882 * NOTES
883 * exported by ordinal
885 void WINAPI ILFree(LPITEMIDLIST pidl)
887 TRACE("(pidl=%p)\n",pidl);
888 SHFree(pidl);
891 /*************************************************************************
892 * ILGlobalFree [SHELL32.156]
894 * Frees memory (if not NULL) allocated by Alloc allocator
896 * PARAMS
897 * pidl [I]
899 * RETURNS
900 * Nothing
902 * NOTES
903 * exported by ordinal.
905 void WINAPI ILGlobalFree( LPITEMIDLIST pidl)
907 TRACE("%p\n", pidl);
909 Free(pidl);
912 /*************************************************************************
913 * ILCreateFromPathA [SHELL32.189]
915 * Creates a complex ItemIDList from a path and returns it.
917 * PARAMS
918 * path [I]
920 * RETURNS
921 * the newly created complex ItemIDList or NULL if failed
923 * NOTES
924 * exported by ordinal.
926 LPITEMIDLIST WINAPI ILCreateFromPathA (LPCSTR path)
928 LPITEMIDLIST pidlnew = NULL;
930 TRACE_(shell)("%s\n", debugstr_a(path));
932 if (SUCCEEDED(SHILCreateFromPathA(path, &pidlnew, NULL)))
933 return pidlnew;
934 return NULL;
937 /*************************************************************************
938 * ILCreateFromPathW [SHELL32.190]
940 * See ILCreateFromPathA.
942 LPITEMIDLIST WINAPI ILCreateFromPathW (LPCWSTR path)
944 LPITEMIDLIST pidlnew = NULL;
946 TRACE_(shell)("%s\n", debugstr_w(path));
948 if (SUCCEEDED(SHILCreateFromPathW(path, &pidlnew, NULL)))
949 return pidlnew;
950 return NULL;
953 /*************************************************************************
954 * ILCreateFromPath [SHELL32.157]
956 LPITEMIDLIST WINAPI ILCreateFromPathAW (LPCVOID path)
958 if ( SHELL_OsIsUnicode())
959 return ILCreateFromPathW (path);
960 return ILCreateFromPathA (path);
963 /*************************************************************************
964 * _ILParsePathW [internal]
966 * Creates an ItemIDList from a path and returns it.
968 * PARAMS
969 * path [I] path to parse and convert into an ItemIDList
970 * lpFindFile [I] pointer to buffer to initialize the FileSystem
971 * Bind Data object with
972 * bBindCtx [I] indicates to create a BindContext and assign a
973 * FileSystem Bind Data object
974 * ppidl [O] the newly create ItemIDList
975 * prgfInOut [I/O] requested attributes on input and actual
976 * attributes on return
978 * RETURNS
979 * NO_ERROR on success or an OLE error code
981 * NOTES
982 * If either lpFindFile is non-NULL or bBindCtx is TRUE, this function
983 * creates a BindContext object and assigns a FileSystem Bind Data object
984 * to it, passing the BindContext to IShellFolder_ParseDisplayName. Each
985 * IShellFolder uses that FileSystem Bind Data object of the BindContext
986 * to pass data about the current path element to the next object. This
987 * is used to avoid having to verify the current path element on disk, so
988 * that creating an ItemIDList from a nonexistent path still can work.
990 static HRESULT _ILParsePathW(LPCWSTR path, LPWIN32_FIND_DATAW lpFindFile,
991 BOOL bBindCtx, LPITEMIDLIST *ppidl, LPDWORD prgfInOut)
993 LPSHELLFOLDER pSF = NULL;
994 LPBC pBC = NULL;
995 HRESULT ret;
997 TRACE("%s %p %d (%p)->%p (%p)->0x%lx\n", debugstr_w(path), lpFindFile, bBindCtx,
998 ppidl, ppidl ? *ppidl : NULL,
999 prgfInOut, prgfInOut ? *prgfInOut : 0);
1001 ret = SHGetDesktopFolder(&pSF);
1002 if (FAILED(ret))
1003 return ret;
1005 if (lpFindFile || bBindCtx)
1006 ret = IFileSystemBindData_Constructor(lpFindFile, &pBC);
1008 if (SUCCEEDED(ret))
1010 ret = IShellFolder_ParseDisplayName(pSF, 0, pBC, (LPOLESTR)path, NULL, ppidl, prgfInOut);
1013 if (pBC)
1015 IBindCtx_Release(pBC);
1016 pBC = NULL;
1019 IShellFolder_Release(pSF);
1021 if (FAILED(ret) && ppidl)
1022 *ppidl = NULL;
1024 TRACE("%s %p 0x%lx\n", debugstr_w(path), ppidl ? *ppidl : NULL, prgfInOut ? *prgfInOut : 0);
1026 return ret;
1029 /*************************************************************************
1030 * SHSimpleIDListFromPath [SHELL32.162]
1032 * Creates a simple ItemIDList from a path and returns it. This function
1033 * does not fail on nonexistent paths.
1035 * PARAMS
1036 * path [I] path to parse and convert into an ItemIDList
1038 * RETURNS
1039 * the newly created simple ItemIDList
1041 * NOTES
1042 * Simple in the name does not mean a relative ItemIDList but rather a
1043 * fully qualified list, where only the file name is filled in and the
1044 * directory flag for those ItemID elements this is known about, eg.
1045 * it is not the last element in the ItemIDList or the actual directory
1046 * exists on disk.
1047 * exported by ordinal.
1049 LPITEMIDLIST SHSimpleIDListFromPathA(LPCSTR lpszPath)
1051 LPITEMIDLIST pidl = NULL;
1052 LPWSTR wPath = NULL;
1053 int len;
1055 TRACE("%s\n", debugstr_a(lpszPath));
1057 if (lpszPath)
1059 len = MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, NULL, 0);
1060 wPath = malloc(len * sizeof(WCHAR));
1061 MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, wPath, len);
1064 _ILParsePathW(wPath, NULL, TRUE, &pidl, NULL);
1066 free(wPath);
1067 TRACE("%s %p\n", debugstr_a(lpszPath), pidl);
1068 return pidl;
1071 LPITEMIDLIST SHSimpleIDListFromPathW(LPCWSTR lpszPath)
1073 LPITEMIDLIST pidl = NULL;
1075 TRACE("%s\n", debugstr_w(lpszPath));
1077 _ILParsePathW(lpszPath, NULL, TRUE, &pidl, NULL);
1078 TRACE("%s %p\n", debugstr_w(lpszPath), pidl);
1079 return pidl;
1082 LPITEMIDLIST WINAPI SHSimpleIDListFromPathAW(LPCVOID lpszPath)
1084 if ( SHELL_OsIsUnicode())
1085 return SHSimpleIDListFromPathW (lpszPath);
1086 return SHSimpleIDListFromPathA (lpszPath);
1089 /*************************************************************************
1090 * SHGetDataFromIDListA [SHELL32.247]
1092 * NOTES
1093 * the pidl can be a simple one. since we can't get the path out of the pidl
1094 * we have to take all data from the pidl
1096 HRESULT WINAPI SHGetDataFromIDListA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl,
1097 int nFormat, LPVOID dest, int len)
1099 LPSTR filename, shortname;
1100 WIN32_FIND_DATAA * pfd;
1102 TRACE_(shell)("%p, %p, %d, %p, %d.\n", psf, pidl, nFormat, dest, len);
1104 pdump(pidl);
1105 if (!psf || !dest)
1106 return E_INVALIDARG;
1108 switch (nFormat)
1110 case SHGDFIL_FINDDATA:
1111 pfd = dest;
1113 if (_ILIsDrive(pidl) || _ILIsSpecialFolder(pidl))
1114 return E_INVALIDARG;
1116 if (len < sizeof(WIN32_FIND_DATAA))
1117 return E_INVALIDARG;
1119 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1120 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1121 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1122 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1124 filename = _ILGetTextPointer(pidl);
1125 shortname = _ILGetSTextPointer(pidl);
1127 if (filename)
1128 lstrcpynA(pfd->cFileName, filename, sizeof(pfd->cFileName));
1129 else
1130 pfd->cFileName[0] = '\0';
1132 if (shortname)
1133 lstrcpynA(pfd->cAlternateFileName, shortname, sizeof(pfd->cAlternateFileName));
1134 else
1135 pfd->cAlternateFileName[0] = '\0';
1136 return S_OK;
1138 case SHGDFIL_NETRESOURCE:
1139 case SHGDFIL_DESCRIPTIONID:
1140 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1141 break;
1143 default:
1144 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1147 return E_INVALIDARG;
1150 /*************************************************************************
1151 * SHGetDataFromIDListW [SHELL32.248]
1154 HRESULT WINAPI SHGetDataFromIDListW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl,
1155 int nFormat, LPVOID dest, int len)
1157 LPSTR filename, shortname;
1158 WIN32_FIND_DATAW * pfd = dest;
1160 TRACE_(shell)("%p, %p, %d, %p, %d.\n", psf, pidl, nFormat, dest, len);
1162 pdump(pidl);
1164 if (!psf || !dest)
1165 return E_INVALIDARG;
1167 switch (nFormat)
1169 case SHGDFIL_FINDDATA:
1170 pfd = dest;
1172 if (_ILIsDrive(pidl))
1173 return E_INVALIDARG;
1175 if (len < sizeof(WIN32_FIND_DATAW))
1176 return E_INVALIDARG;
1178 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAW));
1179 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1180 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1181 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1183 filename = _ILGetTextPointer(pidl);
1184 shortname = _ILGetSTextPointer(pidl);
1186 if (!filename)
1187 pfd->cFileName[0] = '\0';
1188 else if (!MultiByteToWideChar(CP_ACP, 0, filename, -1, pfd->cFileName, MAX_PATH))
1189 pfd->cFileName[MAX_PATH-1] = 0;
1191 if (!shortname)
1192 pfd->cAlternateFileName[0] = '\0';
1193 else if (!MultiByteToWideChar(CP_ACP, 0, shortname, -1, pfd->cAlternateFileName, 14))
1194 pfd->cAlternateFileName[13] = 0;
1195 return S_OK;
1197 case SHGDFIL_NETRESOURCE:
1198 case SHGDFIL_DESCRIPTIONID:
1199 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1200 break;
1202 default:
1203 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1206 return E_INVALIDARG;
1209 /*************************************************************************
1210 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
1212 * PARAMETERS
1213 * pidl, [IN] pidl
1214 * pszPath [OUT] path
1216 * RETURNS
1217 * path from a passed PIDL.
1219 * NOTES
1220 * NULL returns FALSE
1221 * desktop pidl gives path to desktop directory back
1222 * special pidls returning FALSE
1224 BOOL WINAPI SHGetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath)
1226 WCHAR wszPath[MAX_PATH];
1227 BOOL bSuccess;
1229 bSuccess = SHGetPathFromIDListW(pidl, wszPath);
1230 WideCharToMultiByte(CP_ACP, 0, wszPath, -1, pszPath, MAX_PATH, NULL, NULL);
1232 return bSuccess;
1235 /*************************************************************************
1236 * SHGetPathFromIDListW [SHELL32.@]
1238 * See SHGetPathFromIDListA.
1240 BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
1242 return SHGetPathFromIDListEx(pidl, pszPath, MAX_PATH, 0);
1245 /*************************************************************************
1246 * SHGetPathFromIDListEx [SHELL32.@]
1248 BOOL WINAPI SHGetPathFromIDListEx(LPCITEMIDLIST pidl, WCHAR *path, DWORD path_size, GPFIDL_FLAGS flags)
1250 HRESULT hr;
1251 LPCITEMIDLIST pidlLast;
1252 LPSHELLFOLDER psfFolder;
1253 DWORD dwAttributes;
1254 STRRET strret;
1256 TRACE_(shell)("(pidl=%p,%p,%lu,%x)\n", pidl, path, path_size, flags);
1257 pdump(pidl);
1259 if (flags != GPFIDL_DEFAULT)
1260 FIXME("Unsupported flags %x\n", flags);
1262 *path = '\0';
1263 if (!pidl)
1264 return FALSE;
1266 hr = SHBindToParent(pidl, &IID_IShellFolder, (VOID**)&psfFolder, &pidlLast);
1267 if (FAILED(hr)) return FALSE;
1269 dwAttributes = SFGAO_FILESYSTEM;
1270 hr = IShellFolder_GetAttributesOf(psfFolder, 1, &pidlLast, &dwAttributes);
1271 if (FAILED(hr) || !(dwAttributes & SFGAO_FILESYSTEM)) {
1272 IShellFolder_Release(psfFolder);
1273 return FALSE;
1276 hr = IShellFolder_GetDisplayNameOf(psfFolder, pidlLast, SHGDN_FORPARSING, &strret);
1277 IShellFolder_Release(psfFolder);
1278 if (FAILED(hr)) return FALSE;
1280 hr = StrRetToBufW(&strret, pidlLast, path, path_size);
1282 TRACE_(shell)("-- %s, 0x%08lx\n",debugstr_w(path), hr);
1283 return SUCCEEDED(hr);
1286 /*************************************************************************
1287 * SHBindToParent [shell version 5.0]
1289 HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
1291 return SHBindToFolderIDListParent(NULL, pidl, riid, ppv, ppidlLast);
1294 /*************************************************************************
1295 * SHBindToFolderIDListParent [SHELL32.@]
1297 HRESULT WINAPI SHBindToFolderIDListParent(IShellFolder *psf, LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
1299 IShellFolder *psfDesktop = NULL;
1300 HRESULT hr;
1302 TRACE_(shell)("%p,%p,%s\n", psf, pidl, debugstr_guid(riid));
1303 pdump(pidl);
1305 if (ppidlLast)
1306 *ppidlLast = NULL;
1308 if (!pidl || !ppv)
1309 return E_INVALIDARG;
1311 *ppv = NULL;
1313 if (!psf)
1315 hr = SHGetDesktopFolder(&psfDesktop);
1316 if (FAILED(hr))
1317 return hr;
1318 psf = psfDesktop;
1321 if (_ILIsPidlSimple(pidl))
1323 /* we are on desktop level */
1324 hr = IShellFolder_QueryInterface(psf, riid, ppv);
1326 else
1328 LPITEMIDLIST pidlParent = ILClone(pidl);
1329 ILRemoveLastID(pidlParent);
1330 hr = IShellFolder_BindToObject(psf, pidlParent, NULL, riid, ppv);
1331 ILFree(pidlParent);
1334 if (psfDesktop)
1335 IShellFolder_Release(psfDesktop);
1337 if (SUCCEEDED(hr) && ppidlLast)
1338 *ppidlLast = ILFindLastID(pidl);
1340 TRACE_(shell)("-- ppv=%p pidl=%p ret=0x%08lx\n", *ppv, (ppidlLast)?*ppidlLast:NULL, hr);
1341 return hr;
1344 HRESULT WINAPI SHBindToObject(IShellFolder *psf, LPCITEMIDLIST pidl, IBindCtx *pbc, REFIID riid, void **ppv)
1346 IShellFolder *psfDesktop = NULL;
1347 HRESULT hr;
1349 TRACE_(shell)("%p,%p,%p,%s,%p\n", psf, pidl, pbc, debugstr_guid(riid), ppv);
1350 pdump(pidl);
1352 if (!ppv)
1353 return E_INVALIDARG;
1355 *ppv = NULL;
1357 if (!psf)
1359 hr = SHGetDesktopFolder(&psfDesktop);
1360 if (FAILED(hr))
1361 return hr;
1362 psf = psfDesktop;
1365 if (_ILIsPidlSimple(pidl))
1366 /* we are on desktop level */
1367 hr = IShellFolder_QueryInterface(psf, riid, ppv);
1368 else
1369 hr = IShellFolder_BindToObject(psf, pidl, pbc, riid, ppv);
1371 if (psfDesktop)
1372 IShellFolder_Release(psfDesktop);
1374 TRACE_(shell)("-- ppv=%p ret=0x%08lx\n", *ppv, hr);
1375 return hr;
1379 /*************************************************************************
1380 * SHParseDisplayName [SHELL32.@]
1382 HRESULT WINAPI SHParseDisplayName(LPCWSTR name, IBindCtx *bindctx, LPITEMIDLIST *pidlist,
1383 SFGAOF attr_in, SFGAOF *attr_out)
1385 IShellFolder *desktop;
1386 HRESULT hr;
1388 TRACE("%s %p %p %ld %p\n", debugstr_w(name), bindctx, pidlist, attr_in, attr_out);
1390 *pidlist = NULL;
1392 if (!name) return E_INVALIDARG;
1394 hr = SHGetDesktopFolder(&desktop);
1395 if (hr != S_OK) return hr;
1397 hr = IShellFolder_ParseDisplayName(desktop, NULL, bindctx, (LPWSTR)name, NULL, pidlist, &attr_in);
1398 if (attr_out) *attr_out = attr_in;
1400 IShellFolder_Release(desktop);
1402 return hr;
1405 /*************************************************************************
1406 * SHGetNameFromIDList [SHELL32.@]
1408 HRESULT WINAPI SHGetNameFromIDList(PCIDLIST_ABSOLUTE pidl, SIGDN sigdnName, PWSTR *ppszName)
1410 IShellFolder *psfparent;
1411 LPCITEMIDLIST child_pidl;
1412 STRRET disp_name;
1413 HRESULT ret;
1415 TRACE("%p 0x%08x %p\n", pidl, sigdnName, ppszName);
1417 *ppszName = NULL;
1418 ret = SHBindToParent(pidl, &IID_IShellFolder, (void**)&psfparent, &child_pidl);
1419 if(SUCCEEDED(ret))
1421 switch(sigdnName)
1423 /* sigdnName & 0xffff */
1424 case SIGDN_NORMALDISPLAY: /* SHGDN_NORMAL */
1425 case SIGDN_PARENTRELATIVEPARSING: /* SHGDN_INFOLDER | SHGDN_FORPARSING */
1426 case SIGDN_PARENTRELATIVEEDITING: /* SHGDN_INFOLDER | SHGDN_FOREDITING */
1427 case SIGDN_DESKTOPABSOLUTEPARSING: /* SHGDN_FORPARSING */
1428 case SIGDN_DESKTOPABSOLUTEEDITING: /* SHGDN_FOREDITING | SHGDN_FORADDRESSBAR*/
1429 case SIGDN_PARENTRELATIVEFORADDRESSBAR: /* SIGDN_INFOLDER | SHGDN_FORADDRESSBAR */
1430 case SIGDN_PARENTRELATIVE: /* SIGDN_INFOLDER */
1432 disp_name.uType = STRRET_WSTR;
1433 ret = IShellFolder_GetDisplayNameOf(psfparent, child_pidl,
1434 sigdnName & 0xffff,
1435 &disp_name);
1436 if(SUCCEEDED(ret))
1437 ret = StrRetToStrW(&disp_name, pidl, ppszName);
1439 break;
1441 case SIGDN_FILESYSPATH:
1442 *ppszName = CoTaskMemAlloc(sizeof(WCHAR)*MAX_PATH);
1443 if(SHGetPathFromIDListW(pidl, *ppszName))
1445 TRACE("Got string %s\n", debugstr_w(*ppszName));
1446 ret = S_OK;
1448 else
1450 CoTaskMemFree(*ppszName);
1451 ret = E_INVALIDARG;
1453 break;
1455 case SIGDN_URL:
1456 default:
1457 FIXME("Unsupported SIGDN %x\n", sigdnName);
1458 ret = E_FAIL;
1461 IShellFolder_Release(psfparent);
1463 return ret;
1466 /*************************************************************************
1467 * SHGetIDListFromObject [SHELL32.@]
1469 HRESULT WINAPI SHGetIDListFromObject(IUnknown *punk, PIDLIST_ABSOLUTE *ppidl)
1471 IPersistIDList *ppersidl;
1472 IPersistFolder2 *ppf2;
1473 IDataObject *pdo;
1474 IFolderView *pfv;
1475 HRESULT ret;
1477 if(!punk)
1478 return E_NOINTERFACE;
1480 *ppidl = NULL;
1482 /* Try IPersistIDList */
1483 ret = IUnknown_QueryInterface(punk, &IID_IPersistIDList, (void**)&ppersidl);
1484 if(SUCCEEDED(ret))
1486 TRACE("IPersistIDList (%p)\n", ppersidl);
1487 ret = IPersistIDList_GetIDList(ppersidl, ppidl);
1488 IPersistIDList_Release(ppersidl);
1489 if(SUCCEEDED(ret))
1490 return ret;
1493 /* Try IPersistFolder2 */
1494 ret = IUnknown_QueryInterface(punk, &IID_IPersistFolder2, (void**)&ppf2);
1495 if(SUCCEEDED(ret))
1497 TRACE("IPersistFolder2 (%p)\n", ppf2);
1498 ret = IPersistFolder2_GetCurFolder(ppf2, ppidl);
1499 IPersistFolder2_Release(ppf2);
1500 if(SUCCEEDED(ret))
1501 return ret;
1504 /* Try IDataObject */
1505 ret = IUnknown_QueryInterface(punk, &IID_IDataObject, (void**)&pdo);
1506 if(SUCCEEDED(ret))
1508 IShellItem *psi;
1509 TRACE("IDataObject (%p)\n", pdo);
1510 ret = SHGetItemFromDataObject(pdo, DOGIF_ONLY_IF_ONE,
1511 &IID_IShellItem, (void**)&psi);
1512 if(SUCCEEDED(ret))
1514 ret = SHGetIDListFromObject((IUnknown*)psi, ppidl);
1515 IShellItem_Release(psi);
1517 IDataObject_Release(pdo);
1519 if(SUCCEEDED(ret))
1520 return ret;
1523 /* Try IFolderView */
1524 ret = IUnknown_QueryInterface(punk, &IID_IFolderView, (void**)&pfv);
1525 if(SUCCEEDED(ret))
1527 IShellFolder *psf;
1528 TRACE("IFolderView (%p)\n", pfv);
1529 ret = IFolderView_GetFolder(pfv, &IID_IShellFolder, (void**)&psf);
1530 if(SUCCEEDED(ret))
1532 /* We might be able to get IPersistFolder2 from a shellfolder. */
1533 ret = SHGetIDListFromObject((IUnknown*)psf, ppidl);
1534 IShellFolder_Release(psf);
1536 IFolderView_Release(pfv);
1537 return ret;
1540 return ret;
1543 /**************************************************************************
1545 * internal functions
1547 * ### 1. section creating pidls ###
1549 *************************************************************************
1552 /* Basic PIDL constructor. Allocates size + 5 bytes, where:
1553 * - two bytes are SHITEMID.cb
1554 * - one byte is PIDLDATA.type
1555 * - two bytes are the NULL PIDL terminator
1556 * Sets type of the returned PIDL to type.
1558 static LPITEMIDLIST _ILAlloc(PIDLTYPE type, unsigned int size)
1560 LPITEMIDLIST pidlOut = NULL;
1562 pidlOut = SHAlloc(size + 5);
1563 if(pidlOut)
1565 LPPIDLDATA pData;
1566 LPITEMIDLIST pidlNext;
1568 ZeroMemory(pidlOut, size + 5);
1569 pidlOut->mkid.cb = size + 3;
1571 pData = _ILGetDataPointer(pidlOut);
1572 if (pData)
1573 pData->type = type;
1575 pidlNext = ILGetNext(pidlOut);
1576 if (pidlNext)
1577 pidlNext->mkid.cb = 0x00;
1578 TRACE("-- (pidl=%p, size=%u)\n", pidlOut, size);
1581 return pidlOut;
1584 LPITEMIDLIST _ILCreateDesktop(void)
1586 LPITEMIDLIST ret;
1588 TRACE("()\n");
1589 ret = SHAlloc(sizeof(*ret));
1590 if (ret)
1591 ret->mkid.cb = 0;
1592 return ret;
1595 LPITEMIDLIST _ILCreateMyComputer(void)
1597 TRACE("()\n");
1598 return _ILCreateGuid(PT_GUID, &CLSID_MyComputer);
1601 LPITEMIDLIST _ILCreateMyDocuments(void)
1603 TRACE("()\n");
1604 return _ILCreateGuid(PT_GUID, &CLSID_MyDocuments);
1607 LPITEMIDLIST _ILCreateIExplore(void)
1609 TRACE("()\n");
1610 return _ILCreateGuid(PT_GUID, &CLSID_Internet);
1613 LPITEMIDLIST _ILCreateControlPanel(void)
1615 LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL;
1617 TRACE("()\n");
1618 if (parent)
1620 LPITEMIDLIST cpl = _ILCreateGuid(PT_SHELLEXT, &CLSID_ControlPanel);
1622 if (cpl)
1624 ret = ILCombine(parent, cpl);
1625 SHFree(cpl);
1627 SHFree(parent);
1629 return ret;
1632 LPITEMIDLIST _ILCreatePrinters(void)
1634 LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL;
1636 TRACE("()\n");
1637 if (parent)
1639 LPITEMIDLIST printers = _ILCreateGuid(PT_YAGUID, &CLSID_Printers);
1641 if (printers)
1643 ret = ILCombine(parent, printers);
1644 SHFree(printers);
1646 SHFree(parent);
1648 return ret;
1651 LPITEMIDLIST _ILCreateNetwork(void)
1653 TRACE("()\n");
1654 return _ILCreateGuid(PT_GUID, &CLSID_NetworkPlaces);
1657 LPITEMIDLIST _ILCreateBitBucket(void)
1659 TRACE("()\n");
1660 return _ILCreateGuid(PT_GUID, &CLSID_RecycleBin);
1663 LPITEMIDLIST _ILCreateNetHood(void)
1665 TRACE("()\n");
1666 return _ILCreateGuid(PT_GUID, &CLSID_NetworkPlaces);
1669 LPITEMIDLIST _ILCreateGuid(PIDLTYPE type, REFIID guid)
1671 LPITEMIDLIST pidlOut;
1673 if (type == PT_SHELLEXT || type == PT_GUID || type == PT_YAGUID)
1675 pidlOut = _ILAlloc(type, sizeof(GUIDStruct));
1676 if (pidlOut)
1678 LPPIDLDATA pData = _ILGetDataPointer(pidlOut);
1680 pData->u.guid.guid = *guid;
1681 TRACE("-- create GUID-pidl %s\n",
1682 debugstr_guid(&(pData->u.guid.guid)));
1685 else
1687 WARN("%d: invalid type for GUID\n", type);
1688 pidlOut = NULL;
1690 return pidlOut;
1693 LPITEMIDLIST _ILCreateGuidFromStrA(LPCSTR szGUID)
1695 IID iid;
1697 if (FAILED(SHCLSIDFromStringA(szGUID, &iid)))
1699 ERR("%s is not a GUID\n", szGUID);
1700 return NULL;
1702 return _ILCreateGuid(PT_GUID, &iid);
1705 LPITEMIDLIST _ILCreateGuidFromStrW(LPCWSTR szGUID)
1707 IID iid;
1709 if (FAILED(SHCLSIDFromStringW(szGUID, &iid)))
1711 ERR("%s is not a GUID\n", debugstr_w(szGUID));
1712 return NULL;
1714 return _ILCreateGuid(PT_GUID, &iid);
1717 LPITEMIDLIST _ILCreateFromFindDataW( const WIN32_FIND_DATAW *wfd )
1719 DWORD wlen, alen;
1720 LPITEMIDLIST pidl;
1721 PIDLTYPE type;
1723 if (!wfd)
1724 return NULL;
1726 TRACE("(%s, %s)\n",debugstr_w(wfd->cAlternateFileName), debugstr_w(wfd->cFileName));
1728 type = (wfd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? PT_FOLDER : PT_VALUE;
1730 alen = WideCharToMultiByte( CP_ACP, 0, wfd->cFileName, -1, NULL, 0, NULL, NULL );
1731 wlen = lstrlenW(wfd->cFileName) + 1;
1732 pidl = _ILAlloc(type, FIELD_OFFSET(FileStruct, szNames[alen + (alen & 1)]) +
1733 FIELD_OFFSET(FileStructW, wszName[wlen]) + sizeof(WORD));
1734 if (pidl)
1736 LPPIDLDATA pData = _ILGetDataPointer(pidl);
1737 FileStruct *fs = &pData->u.file;
1738 FileStructW *fsw;
1739 WORD *pOffsetW;
1741 FileTimeToDosDateTime( &wfd->ftLastWriteTime, &fs->uFileDate, &fs->uFileTime);
1742 fs->dwFileSize = wfd->nFileSizeLow;
1743 fs->uFileAttribs = wfd->dwFileAttributes;
1744 WideCharToMultiByte( CP_ACP, 0, wfd->cFileName, -1, fs->szNames, alen, NULL, NULL );
1746 fsw = (FileStructW*)(pData->u.file.szNames + alen + (alen & 0x1));
1747 fsw->cbLen = FIELD_OFFSET(FileStructW, wszName[wlen]) + sizeof(WORD);
1748 FileTimeToDosDateTime( &wfd->ftCreationTime, &fsw->uCreationDate, &fsw->uCreationTime);
1749 FileTimeToDosDateTime( &wfd->ftLastAccessTime, &fsw->uLastAccessDate, &fsw->uLastAccessTime);
1750 memcpy(fsw->wszName, wfd->cFileName, wlen * sizeof(WCHAR));
1752 pOffsetW = (WORD*)((LPBYTE)pidl + pidl->mkid.cb - sizeof(WORD));
1753 *pOffsetW = (LPBYTE)fsw - (LPBYTE)pidl;
1754 TRACE("-- Set Value: %s\n",debugstr_w(fsw->wszName));
1756 return pidl;
1760 HRESULT _ILCreateFromPathW(LPCWSTR szPath, LPITEMIDLIST* ppidl)
1762 HANDLE hFile;
1763 WIN32_FIND_DATAW stffile;
1765 if (!ppidl)
1766 return E_INVALIDARG;
1768 hFile = FindFirstFileW(szPath, &stffile);
1769 if (hFile == INVALID_HANDLE_VALUE)
1770 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
1772 FindClose(hFile);
1774 *ppidl = _ILCreateFromFindDataW(&stffile);
1776 return *ppidl ? S_OK : E_OUTOFMEMORY;
1779 LPITEMIDLIST _ILCreateDrive(LPCWSTR lpszNew)
1781 LPITEMIDLIST pidlOut;
1783 TRACE("(%s)\n",debugstr_w(lpszNew));
1785 pidlOut = _ILAlloc(PT_DRIVE, sizeof(DriveStruct));
1786 if (pidlOut)
1788 LPSTR pszDest;
1790 pszDest = _ILGetTextPointer(pidlOut);
1791 if (pszDest)
1793 strcpy(pszDest, "x:\\");
1794 pszDest[0]=towupper(lpszNew[0]);
1795 TRACE("-- create Drive: %s\n", debugstr_a(pszDest));
1798 return pidlOut;
1801 LPITEMIDLIST _ILCreateEntireNetwork(void)
1803 LPITEMIDLIST pidlOut;
1805 TRACE("\n");
1807 pidlOut = _ILAlloc(PT_NETWORK, FIELD_OFFSET(PIDLDATA, u.network.szNames[sizeof("Entire Network")]));
1808 if (pidlOut)
1810 LPPIDLDATA pData = _ILGetDataPointer(pidlOut);
1812 pData->u.network.dummy = 0;
1813 strcpy(pData->u.network.szNames, "Entire Network");
1815 return pidlOut;
1818 /**************************************************************************
1819 * _ILGetDrive()
1821 * Gets the text for the drive eg. 'c:\'
1823 * RETURNS
1824 * strlen (lpszText)
1826 DWORD _ILGetDrive(LPCITEMIDLIST pidl,LPSTR pOut, UINT uSize)
1828 TRACE("(%p,%p,%u)\n",pidl,pOut,uSize);
1830 if(_ILIsMyComputer(pidl))
1831 pidl = ILGetNext(pidl);
1833 if (pidl && _ILIsDrive(pidl))
1834 return _ILSimpleGetText(pidl, pOut, uSize);
1836 return 0;
1839 /**************************************************************************
1841 * ### 2. section testing pidls ###
1843 **************************************************************************
1844 * _ILIsUnicode()
1845 * _ILIsDesktop()
1846 * _ILIsMyComputer()
1847 * _ILIsSpecialFolder()
1848 * _ILIsDrive()
1849 * _ILIsFolder()
1850 * _ILIsValue()
1851 * _ILIsPidlSimple()
1853 BOOL _ILIsUnicode(LPCITEMIDLIST pidl)
1855 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1857 TRACE("(%p)\n",pidl);
1859 return (pidl && lpPData && PT_VALUEW == lpPData->type);
1862 BOOL _ILIsDesktop(LPCITEMIDLIST pidl)
1864 TRACE("(%p)\n",pidl);
1866 return !pidl || !pidl->mkid.cb;
1869 BOOL _ILIsMyComputer(LPCITEMIDLIST pidl)
1871 REFIID iid = _ILGetGUIDPointer(pidl);
1873 TRACE("(%p)\n",pidl);
1875 if (iid)
1876 return IsEqualIID(iid, &CLSID_MyComputer);
1877 return FALSE;
1880 BOOL _ILIsSpecialFolder (LPCITEMIDLIST pidl)
1882 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1884 TRACE("(%p)\n",pidl);
1886 return (pidl && ( (lpPData && (PT_GUID== lpPData->type || PT_SHELLEXT== lpPData->type || PT_YAGUID == lpPData->type)) ||
1887 (pidl && pidl->mkid.cb == 0x00)
1891 BOOL _ILIsDrive(LPCITEMIDLIST pidl)
1893 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1895 TRACE("(%p)\n",pidl);
1897 return (pidl && lpPData && (PT_DRIVE == lpPData->type ||
1898 PT_DRIVE1 == lpPData->type ||
1899 PT_DRIVE2 == lpPData->type ||
1900 PT_DRIVE3 == lpPData->type));
1903 BOOL _ILIsFolder(LPCITEMIDLIST pidl)
1905 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1907 TRACE("(%p)\n",pidl);
1909 return (pidl && lpPData && (PT_FOLDER == lpPData->type || PT_FOLDER1 == lpPData->type));
1912 BOOL _ILIsValue(LPCITEMIDLIST pidl)
1914 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1916 TRACE("(%p)\n",pidl);
1918 return (pidl && lpPData && PT_VALUE == lpPData->type);
1921 BOOL _ILIsCPanelStruct(LPCITEMIDLIST pidl)
1923 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1925 TRACE("(%p)\n",pidl);
1927 return (pidl && lpPData && (lpPData->type == 0));
1930 /**************************************************************************
1931 * _ILIsPidlSimple
1933 BOOL _ILIsPidlSimple(LPCITEMIDLIST pidl)
1935 BOOL ret = TRUE;
1937 if(! _ILIsDesktop(pidl)) /* pidl=NULL or mkid.cb=0 */
1939 WORD len = pidl->mkid.cb;
1940 LPCITEMIDLIST pidlnext = (LPCITEMIDLIST) (((const BYTE*)pidl) + len );
1942 if (pidlnext->mkid.cb)
1943 ret = FALSE;
1946 TRACE("%s\n", ret ? "Yes" : "No");
1947 return ret;
1950 /**************************************************************************
1952 * ### 3. section getting values from pidls ###
1955 /**************************************************************************
1956 * _ILSimpleGetText
1958 * gets the text for the first item in the pidl (eg. simple pidl)
1960 * returns the length of the string
1962 DWORD _ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
1964 DWORD dwReturn=0;
1965 LPSTR szSrc;
1966 LPWSTR szSrcW;
1967 GUID const * riid;
1968 char szTemp[MAX_PATH];
1970 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1972 if (!pidl)
1973 return 0;
1975 if (szOut)
1976 *szOut = 0;
1978 if (_ILIsDesktop(pidl))
1980 /* desktop */
1981 if (HCR_GetClassNameA(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1983 if (szOut)
1984 lstrcpynA(szOut, szTemp, uOutSize);
1986 dwReturn = strlen (szTemp);
1989 else if (( szSrc = _ILGetTextPointer(pidl) ))
1991 /* filesystem */
1992 if (szOut)
1993 lstrcpynA(szOut, szSrc, uOutSize);
1995 dwReturn = strlen(szSrc);
1997 else if (( szSrcW = _ILGetTextPointerW(pidl) ))
1999 /* unicode filesystem */
2000 WideCharToMultiByte(CP_ACP,0,szSrcW, -1, szTemp, MAX_PATH, NULL, NULL);
2002 if (szOut)
2003 lstrcpynA(szOut, szTemp, uOutSize);
2005 dwReturn = strlen (szTemp);
2007 else if (( riid = _ILGetGUIDPointer(pidl) ))
2009 /* special folder */
2010 if ( HCR_GetClassNameA(riid, szTemp, MAX_PATH) )
2012 if (szOut)
2013 lstrcpynA(szOut, szTemp, uOutSize);
2015 dwReturn = strlen (szTemp);
2018 else
2020 ERR("-- no text\n");
2023 TRACE("-- (%p=%s 0x%08lx)\n",szOut,debugstr_a(szOut),dwReturn);
2024 return dwReturn;
2027 /**************************************************************************
2028 * _ILSimpleGetTextW
2030 * gets the text for the first item in the pidl (eg. simple pidl)
2032 * returns the length of the string
2034 DWORD _ILSimpleGetTextW (LPCITEMIDLIST pidl, LPWSTR szOut, UINT uOutSize)
2036 DWORD dwReturn;
2037 FileStructW *pFileStructW = _ILGetFileStructW(pidl);
2039 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
2041 if (pFileStructW) {
2042 lstrcpynW(szOut, pFileStructW->wszName, uOutSize);
2043 dwReturn = lstrlenW(pFileStructW->wszName);
2044 } else {
2045 GUID const * riid;
2046 WCHAR szTemp[MAX_PATH];
2047 LPSTR szSrc;
2048 LPWSTR szSrcW;
2049 dwReturn=0;
2051 if (!pidl)
2052 return 0;
2054 if (szOut)
2055 *szOut = 0;
2057 if (_ILIsDesktop(pidl))
2059 /* desktop */
2060 if (HCR_GetClassNameW(&CLSID_ShellDesktop, szTemp, MAX_PATH))
2062 if (szOut)
2063 lstrcpynW(szOut, szTemp, uOutSize);
2065 dwReturn = lstrlenW (szTemp);
2068 else if (( szSrcW = _ILGetTextPointerW(pidl) ))
2070 /* unicode filesystem */
2071 if (szOut)
2072 lstrcpynW(szOut, szSrcW, uOutSize);
2074 dwReturn = lstrlenW(szSrcW);
2076 else if (( szSrc = _ILGetTextPointer(pidl) ))
2078 /* filesystem */
2079 MultiByteToWideChar(CP_ACP, 0, szSrc, -1, szTemp, MAX_PATH);
2081 if (szOut)
2082 lstrcpynW(szOut, szTemp, uOutSize);
2084 dwReturn = lstrlenW (szTemp);
2086 else if (( riid = _ILGetGUIDPointer(pidl) ))
2088 /* special folder */
2089 if ( HCR_GetClassNameW(riid, szTemp, MAX_PATH) )
2091 if (szOut)
2092 lstrcpynW(szOut, szTemp, uOutSize);
2094 dwReturn = lstrlenW (szTemp);
2097 else
2099 ERR("-- no text\n");
2103 TRACE("-- (%p=%s 0x%08lx)\n",szOut,debugstr_w(szOut),dwReturn);
2104 return dwReturn;
2107 /**************************************************************************
2109 * ### 4. getting pointers to parts of pidls ###
2111 **************************************************************************
2112 * _ILGetDataPointer()
2114 LPPIDLDATA _ILGetDataPointer(LPCITEMIDLIST pidl)
2116 if(!_ILIsEmpty(pidl))
2117 return (LPPIDLDATA)pidl->mkid.abID;
2118 return NULL;
2121 /**************************************************************************
2122 * _ILGetTextPointerW()
2123 * gets a pointer to the unicode long filename string stored in the pidl
2125 static LPWSTR _ILGetTextPointerW(LPCITEMIDLIST pidl)
2127 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
2129 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2131 if (!pdata)
2132 return NULL;
2134 switch (pdata->type)
2136 case PT_GUID:
2137 case PT_SHELLEXT:
2138 case PT_YAGUID:
2139 return NULL;
2141 case PT_DRIVE:
2142 case PT_DRIVE1:
2143 case PT_DRIVE2:
2144 case PT_DRIVE3:
2145 /*return (LPSTR)&(pdata->u.drive.szDriveName);*/
2146 return NULL;
2148 case PT_FOLDER:
2149 case PT_FOLDER1:
2150 case PT_VALUE:
2151 case PT_IESPECIAL1:
2152 case PT_IESPECIAL2:
2153 /*return (LPSTR)&(pdata->u.file.szNames);*/
2154 return NULL;
2156 case PT_WORKGRP:
2157 case PT_COMP:
2158 case PT_NETWORK:
2159 case PT_NETPROVIDER:
2160 case PT_SHARE:
2161 /*return (LPSTR)&(pdata->u.network.szNames);*/
2162 return NULL;
2164 case PT_VALUEW:
2165 return (LPWSTR)pdata->u.file.szNames;
2167 return NULL;
2171 /**************************************************************************
2172 * _ILGetTextPointer()
2173 * gets a pointer to the long filename string stored in the pidl
2175 LPSTR _ILGetTextPointer(LPCITEMIDLIST pidl)
2177 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
2179 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2181 if (!pdata)
2182 return NULL;
2184 switch (pdata->type)
2186 case PT_GUID:
2187 case PT_SHELLEXT:
2188 case PT_YAGUID:
2189 return NULL;
2191 case PT_DRIVE:
2192 case PT_DRIVE1:
2193 case PT_DRIVE2:
2194 case PT_DRIVE3:
2195 return pdata->u.drive.szDriveName;
2197 case PT_FOLDER:
2198 case PT_FOLDER1:
2199 case PT_VALUE:
2200 case PT_IESPECIAL1:
2201 case PT_IESPECIAL2:
2202 return pdata->u.file.szNames;
2204 case PT_WORKGRP:
2205 case PT_COMP:
2206 case PT_NETWORK:
2207 case PT_NETPROVIDER:
2208 case PT_SHARE:
2209 return pdata->u.network.szNames;
2211 return NULL;
2214 /**************************************************************************
2215 * _ILGetSTextPointer()
2216 * gets a pointer to the short filename string stored in the pidl
2218 static LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl)
2220 /* TRACE(pidl,"(pidl%p)\n", pidl); */
2222 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
2224 if (!pdata)
2225 return NULL;
2227 switch (pdata->type)
2229 case PT_FOLDER:
2230 case PT_VALUE:
2231 case PT_IESPECIAL1:
2232 case PT_IESPECIAL2:
2233 return pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1;
2235 case PT_WORKGRP:
2236 return pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1;
2238 return NULL;
2241 /**************************************************************************
2242 * _ILGetGUIDPointer()
2244 * returns reference to guid stored in some pidls
2246 IID* _ILGetGUIDPointer(LPCITEMIDLIST pidl)
2248 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
2250 TRACE("%p\n", pidl);
2252 if (!pdata)
2253 return NULL;
2255 TRACE("pdata->type 0x%04x\n", pdata->type);
2256 switch (pdata->type)
2258 case PT_SHELLEXT:
2259 case PT_GUID:
2260 case PT_YAGUID:
2261 return &(pdata->u.guid.guid);
2263 default:
2264 TRACE("Unknown pidl type 0x%04x\n", pdata->type);
2265 break;
2267 return NULL;
2270 /******************************************************************************
2271 * _ILGetFileStructW [Internal]
2273 * Get pointer the a SHITEMID's FileStructW field if present
2275 * PARAMS
2276 * pidl [I] The SHITEMID
2278 * RETURNS
2279 * Success: Pointer to pidl's FileStructW field.
2280 * Failure: NULL
2282 FileStructW* _ILGetFileStructW(LPCITEMIDLIST pidl) {
2283 FileStructW *pFileStructW;
2284 WORD cbOffset;
2286 if (!(_ILIsValue(pidl) || _ILIsFolder(pidl)))
2287 return NULL;
2289 cbOffset = *(const WORD *)((const BYTE *)pidl + pidl->mkid.cb - sizeof(WORD));
2290 pFileStructW = (FileStructW*)((LPBYTE)pidl + cbOffset);
2292 /* Currently I don't see a fool prove way to figure out if a pidl is for sure of WinXP
2293 * style with a FileStructW member. If we switch all our shellfolder-implementations to
2294 * the new format, this won't be a problem. For now, we do as many sanity checks as possible. */
2295 if ((cbOffset & 0x1) || /* FileStructW member is word aligned in the pidl */
2296 /* FileStructW is positioned after FileStruct */
2297 cbOffset < sizeof(pidl->mkid.cb) + sizeof(PIDLTYPE) + sizeof(FileStruct) ||
2298 /* There has to be enough space at cbOffset in the pidl to hold FileStructW and cbOffset */
2299 cbOffset > pidl->mkid.cb - sizeof(cbOffset) - sizeof(FileStructW) ||
2300 pidl->mkid.cb != cbOffset + pFileStructW->cbLen)
2302 WARN("Invalid pidl format (cbOffset = %d)!\n", cbOffset);
2303 return NULL;
2306 return pFileStructW;
2309 /*************************************************************************
2310 * _ILGetFileDateTime
2312 * Given the ItemIdList, get the FileTime
2314 * PARAMS
2315 * pidl [I] The ItemIDList
2316 * pFt [I] the resulted FILETIME of the file
2318 * RETURNS
2319 * True if Successful
2321 * NOTES
2324 BOOL _ILGetFileDateTime(LPCITEMIDLIST pidl, FILETIME *pFt)
2326 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2328 if (!pdata)
2329 return FALSE;
2331 switch (pdata->type)
2333 case PT_FOLDER:
2334 case PT_VALUE:
2335 DosDateTimeToFileTime(pdata->u.file.uFileDate, pdata->u.file.uFileTime, pFt);
2336 break;
2337 default:
2338 return FALSE;
2340 return TRUE;
2343 BOOL _ILGetFileDate (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2345 FILETIME ft,lft;
2346 SYSTEMTIME time;
2347 BOOL ret;
2349 if (_ILGetFileDateTime( pidl, &ft ))
2351 FileTimeToLocalFileTime(&ft, &lft);
2352 FileTimeToSystemTime (&lft, &time);
2354 ret = GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&time, NULL, pOut, uOutSize);
2355 if (ret)
2357 /* Append space + time without seconds */
2358 pOut[ret-1] = ' ';
2359 GetTimeFormatA(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &time, NULL, &pOut[ret], uOutSize - ret);
2362 else
2364 pOut[0] = '\0';
2365 ret = FALSE;
2367 return ret;
2370 /*************************************************************************
2371 * _ILGetFileSize
2373 * Given the ItemIdList, get the FileSize
2375 * PARAMS
2376 * pidl [I] The ItemIDList
2377 * pOut [I] The buffer to save the result
2378 * uOutsize [I] The size of the buffer
2380 * RETURNS
2381 * The FileSize
2383 * NOTES
2384 * pOut can be null when no string is needed
2387 DWORD _ILGetFileSize (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2389 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2390 DWORD dwSize;
2392 if (!pdata)
2393 return 0;
2395 switch (pdata->type)
2397 case PT_VALUE:
2398 dwSize = pdata->u.file.dwFileSize;
2399 if (pOut)
2400 StrFormatKBSizeA(dwSize, pOut, uOutSize);
2401 return dwSize;
2403 if (pOut)
2404 *pOut = 0x00;
2405 return 0;
2408 BOOL _ILGetExtension (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2410 char szTemp[MAX_PATH];
2411 const char * pPoint;
2412 LPCITEMIDLIST pidlTemp=pidl;
2414 TRACE("pidl=%p\n",pidl);
2416 if (!pidl)
2417 return FALSE;
2419 pidlTemp = ILFindLastID(pidl);
2421 if (!_ILIsValue(pidlTemp))
2422 return FALSE;
2423 if (!_ILSimpleGetText(pidlTemp, szTemp, MAX_PATH))
2424 return FALSE;
2426 pPoint = PathFindExtensionA(szTemp);
2428 if (!*pPoint)
2429 return FALSE;
2431 pPoint++;
2432 lstrcpynA(pOut, pPoint, uOutSize);
2433 TRACE("%s\n",pOut);
2435 return TRUE;
2438 /*************************************************************************
2439 * _ILGetFileType
2441 * Given the ItemIdList, get the file type description
2443 * PARAMS
2444 * pidl [I] The ItemIDList (simple)
2445 * pOut [I] The buffer to save the result
2446 * uOutsize [I] The size of the buffer
2448 * RETURNS
2449 * nothing
2451 * NOTES
2452 * This function copies as much as possible into the buffer.
2454 void _ILGetFileType(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2456 if(_ILIsValue(pidl))
2458 char sTemp[64];
2460 /* "name" or "name." or any unhandled => "File" */
2461 lstrcpynA (pOut, "File", uOutSize);
2463 /* If there's space for more, try to get a better description. */
2464 if (uOutSize > 6 && _ILGetExtension (pidl, sTemp, 64))
2466 if (!( HCR_MapTypeToValueA(sTemp, sTemp, 64, TRUE)
2467 && HCR_MapTypeToValueA(sTemp, pOut, uOutSize, FALSE ))
2468 && sTemp[0])
2470 lstrcpynA (pOut, sTemp, uOutSize - 6);
2471 strcat (pOut, " file");
2475 else
2476 lstrcpynA(pOut, "Folder", uOutSize);
2479 /*************************************************************************
2480 * _ILGetFileAttributes
2482 * Given the ItemIdList, get the Attrib string format
2484 * PARAMS
2485 * pidl [I] The ItemIDList
2486 * pOut [I] The buffer to save the result
2487 * uOutsize [I] The size of the Buffer
2489 * RETURNS
2490 * Attributes
2492 * FIXME
2493 * return value 0 in case of error is a valid return value
2496 DWORD _ILGetFileAttributes(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2498 LPPIDLDATA pData = _ILGetDataPointer(pidl);
2499 WORD wAttrib = 0;
2500 int i;
2502 if (!pData)
2503 return 0;
2505 switch(pData->type)
2507 case PT_FOLDER:
2508 case PT_VALUE:
2509 wAttrib = pData->u.file.uFileAttribs;
2510 break;
2513 if(uOutSize >= 6)
2515 i=0;
2516 if(wAttrib & FILE_ATTRIBUTE_READONLY)
2517 pOut[i++] = 'R';
2518 if(wAttrib & FILE_ATTRIBUTE_HIDDEN)
2519 pOut[i++] = 'H';
2520 if(wAttrib & FILE_ATTRIBUTE_SYSTEM)
2521 pOut[i++] = 'S';
2522 if(wAttrib & FILE_ATTRIBUTE_ARCHIVE)
2523 pOut[i++] = 'A';
2524 if(wAttrib & FILE_ATTRIBUTE_COMPRESSED)
2525 pOut[i++] = 'C';
2526 pOut[i] = 0x00;
2528 return wAttrib;
2531 /*************************************************************************
2532 * ILFreeaPidl
2534 * frees an aPidl struct
2536 void _ILFreeaPidl(LPITEMIDLIST * apidl, UINT cidl)
2538 UINT i;
2540 if (apidl)
2542 for (i = 0; i < cidl; i++)
2543 SHFree(apidl[i]);
2544 SHFree(apidl);
2548 /*************************************************************************
2549 * ILCopyaPidl
2551 * copies an aPidl struct
2553 LPITEMIDLIST* _ILCopyaPidl(const LPCITEMIDLIST * apidlsrc, UINT cidl)
2555 UINT i;
2556 LPITEMIDLIST *apidldest;
2558 if (!apidlsrc)
2559 return NULL;
2561 apidldest = SHAlloc(cidl * sizeof(LPITEMIDLIST));
2563 for (i = 0; i < cidl; i++)
2564 apidldest[i] = ILClone(apidlsrc[i]);
2566 return apidldest;
2569 /*************************************************************************
2570 * _ILCopyCidaToaPidl
2572 * creates aPidl from CIDA
2574 LPITEMIDLIST* _ILCopyCidaToaPidl(LPITEMIDLIST* pidl, const CIDA * cida)
2576 UINT i;
2577 LPITEMIDLIST *dst;
2579 dst = SHAlloc(cida->cidl * sizeof(LPITEMIDLIST));
2580 if (!dst)
2581 return NULL;
2583 if (pidl)
2584 *pidl = ILClone((LPCITEMIDLIST)(&((const BYTE*)cida)[cida->aoffset[0]]));
2586 for (i = 0; i < cida->cidl; i++)
2587 dst[i] = ILClone((LPCITEMIDLIST)(&((const BYTE*)cida)[cida->aoffset[i + 1]]));
2589 return dst;