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
21 * a pidl == NULL means desktop and is legal
26 #include "wine/port.h"
34 #define NONAMELESSUNION
35 #define NONAMELESSSTRUCT
44 #include "undocshell.h"
45 #include "shell32_main.h"
49 #include "wine/debug.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(pidl
);
52 WINE_DECLARE_DEBUG_CHANNEL(shell
);
54 /* from comctl32.dll */
55 extern LPVOID WINAPI
Alloc(INT
);
56 extern BOOL WINAPI
Free(LPVOID
);
58 static LPSTR
_ILGetSTextPointer(LPCITEMIDLIST pidl
);
59 static LPWSTR
_ILGetTextPointerW(LPCITEMIDLIST pidl
);
61 /*************************************************************************
62 * ILGetDisplayNameEx [SHELL32.186]
64 * Retrieves the display name of an ItemIDList
67 * psf [I] Shell Folder to start with, if NULL the desktop is used
68 * pidl [I] ItemIDList relative to the psf to get the display name for
69 * path [O] Filled in with the display name, assumed to be at least MAX_PATH long
70 * type [I] Type of display name to retrieve
71 * 0 = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR uses always the desktop as root
72 * 1 = SHGDN_NORMAL relative to the root folder
73 * 2 = SHGDN_INFOLDER relative to the root folder, only the last name
76 * True if the display name could be retrieved successfully, False otherwise
78 BOOL WINAPI
ILGetDisplayNameExA(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPSTR path
, DWORD type
)
81 WCHAR wPath
[MAX_PATH
];
83 TRACE("%p %p %p %d\n", psf
, pidl
, path
, type
);
88 ret
= ILGetDisplayNameExW(psf
, pidl
, wPath
, type
);
89 WideCharToMultiByte(CP_ACP
, 0, wPath
, -1, path
, MAX_PATH
, NULL
, NULL
);
90 TRACE("%p %p %s\n", psf
, pidl
, debugstr_a(path
));
95 BOOL WINAPI
ILGetDisplayNameExW(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPWSTR path
, DWORD type
)
97 LPSHELLFOLDER psfParent
, lsf
= psf
;
98 HRESULT ret
= NO_ERROR
;
99 LPCITEMIDLIST pidllast
;
103 TRACE("%p %p %p %x\n", psf
, pidl
, path
, type
);
110 ret
= SHGetDesktopFolder(&lsf
);
117 case ILGDN_FORPARSING
:
118 flag
= SHGDN_FORPARSING
| SHGDN_FORADDRESSBAR
;
124 flag
= SHGDN_INFOLDER
;
127 FIXME("Unknown type parameter = %x\n", type
);
128 flag
= SHGDN_FORPARSING
| SHGDN_FORADDRESSBAR
;
132 if (!*(const WORD
*)pidl
|| type
== ILGDN_FORPARSING
)
134 ret
= IShellFolder_GetDisplayNameOf(lsf
, pidl
, flag
, &strret
);
137 if(!StrRetToStrNW(path
, MAX_PATH
, &strret
, pidl
))
143 ret
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psfParent
, &pidllast
);
146 ret
= IShellFolder_GetDisplayNameOf(psfParent
, pidllast
, flag
, &strret
);
149 if(!StrRetToStrNW(path
, MAX_PATH
, &strret
, pidllast
))
152 IShellFolder_Release(psfParent
);
156 TRACE("%p %p %s\n", psf
, pidl
, debugstr_w(path
));
159 IShellFolder_Release(lsf
);
160 return SUCCEEDED(ret
);
163 BOOL WINAPI
ILGetDisplayNameEx(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPVOID path
, DWORD type
)
165 TRACE_(shell
)("%p %p %p %d\n", psf
, pidl
, path
, type
);
167 if (SHELL_OsIsUnicode())
168 return ILGetDisplayNameExW(psf
, pidl
, path
, type
);
169 return ILGetDisplayNameExA(psf
, pidl
, path
, type
);
172 /*************************************************************************
173 * ILGetDisplayName [SHELL32.15]
175 BOOL WINAPI
ILGetDisplayName(LPCITEMIDLIST pidl
, LPVOID path
)
177 TRACE_(shell
)("%p %p\n", pidl
, path
);
179 if (SHELL_OsIsUnicode())
180 return ILGetDisplayNameExW(NULL
, pidl
, path
, ILGDN_FORPARSING
);
181 return ILGetDisplayNameExA(NULL
, pidl
, path
, ILGDN_FORPARSING
);
184 /*************************************************************************
185 * ILFindLastID [SHELL32.16]
188 * observed: pidl=Desktop return=pidl
190 LPITEMIDLIST WINAPI
ILFindLastID(LPCITEMIDLIST pidl
)
192 LPCITEMIDLIST pidlLast
= pidl
;
194 TRACE("(pidl=%p)\n",pidl
);
199 while (pidl
->mkid
.cb
)
202 pidl
= ILGetNext(pidl
);
204 return (LPITEMIDLIST
)pidlLast
;
207 /*************************************************************************
208 * ILRemoveLastID [SHELL32.17]
211 * when pidl=Desktop return=FALSE
213 BOOL WINAPI
ILRemoveLastID(LPITEMIDLIST pidl
)
215 TRACE_(shell
)("pidl=%p\n",pidl
);
217 if (!pidl
|| !pidl
->mkid
.cb
)
219 ILFindLastID(pidl
)->mkid
.cb
= 0;
223 /*************************************************************************
224 * ILClone [SHELL32.18]
227 * duplicate an idlist
229 LPITEMIDLIST WINAPI
ILClone (LPCITEMIDLIST pidl
)
232 LPITEMIDLIST newpidl
;
237 len
= ILGetSize(pidl
);
238 newpidl
= SHAlloc(len
);
240 memcpy(newpidl
,pidl
,len
);
242 TRACE("pidl=%p newpidl=%p\n",pidl
, newpidl
);
248 /*************************************************************************
249 * ILCloneFirst [SHELL32.19]
252 * duplicates the first idlist of a complex pidl
254 LPITEMIDLIST WINAPI
ILCloneFirst(LPCITEMIDLIST pidl
)
257 LPITEMIDLIST pidlNew
= NULL
;
259 TRACE("pidl=%p\n", pidl
);
265 pidlNew
= SHAlloc(len
+2);
268 memcpy(pidlNew
,pidl
,len
+2); /* 2 -> mind a desktop pidl */
271 ILGetNext(pidlNew
)->mkid
.cb
= 0x00;
274 TRACE("-- newpidl=%p\n",pidlNew
);
279 /*************************************************************************
280 * ILLoadFromStream (SHELL32.26)
283 * the first two bytes are the len, the pidl is following then
285 HRESULT WINAPI
ILLoadFromStream (IStream
* pStream
, LPITEMIDLIST
* ppPidl
)
289 HRESULT ret
= E_FAIL
;
292 TRACE_(shell
)("%p %p\n", pStream
, ppPidl
);
297 IStream_AddRef (pStream
);
299 if (SUCCEEDED(IStream_Read(pStream
, (LPVOID
)&wLen
, 2, &dwBytesRead
)))
301 TRACE("PIDL length is %d\n", wLen
);
304 *ppPidl
= SHAlloc (wLen
);
305 if (SUCCEEDED(IStream_Read(pStream
, *ppPidl
, wLen
, &dwBytesRead
)))
307 TRACE("Stream read OK\n");
312 WARN("reading pidl failed\n");
324 /* we are not yet fully compatible */
325 if (*ppPidl
&& !pcheck(*ppPidl
))
327 WARN("Check failed\n");
332 IStream_Release (pStream
);
337 /*************************************************************************
338 * ILSaveToStream (SHELL32.27)
341 * the first two bytes are the len, the pidl is following then
343 HRESULT WINAPI
ILSaveToStream (IStream
* pStream
, LPCITEMIDLIST pPidl
)
346 HRESULT ret
= E_FAIL
;
348 TRACE_(shell
)("%p %p\n", pStream
, pPidl
);
350 IStream_AddRef (pStream
);
352 wLen
= ILGetSize(pPidl
);
354 if (SUCCEEDED(IStream_Write(pStream
, (LPVOID
)&wLen
, 2, NULL
)))
356 if (SUCCEEDED(IStream_Write(pStream
, pPidl
, wLen
, NULL
)))
359 IStream_Release (pStream
);
364 /*************************************************************************
365 * SHILCreateFromPath [SHELL32.28]
367 * Create an ItemIDList from a path
372 * attributes [I/O] requested attributes on call and actual attributes when
373 * the function returns
376 * NO_ERROR if successful, or an OLE errer code otherwise
379 * Wrapper for IShellFolder_ParseDisplayName().
381 HRESULT WINAPI
SHILCreateFromPathA(LPCSTR path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
383 WCHAR lpszDisplayName
[MAX_PATH
];
385 TRACE_(shell
)("%s %p 0x%08x\n", path
, ppidl
, attributes
? *attributes
: 0);
387 if (!MultiByteToWideChar(CP_ACP
, 0, path
, -1, lpszDisplayName
, MAX_PATH
))
388 lpszDisplayName
[MAX_PATH
-1] = 0;
390 return SHILCreateFromPathW(lpszDisplayName
, ppidl
, attributes
);
393 HRESULT WINAPI
SHILCreateFromPathW(LPCWSTR path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
397 HRESULT ret
= E_FAIL
;
399 TRACE_(shell
)("%s %p 0x%08x\n", debugstr_w(path
), ppidl
, attributes
? *attributes
: 0);
401 if (SUCCEEDED (SHGetDesktopFolder(&sf
)))
403 ret
= IShellFolder_ParseDisplayName(sf
, 0, NULL
, (LPWSTR
)path
, &pchEaten
, ppidl
, attributes
);
404 IShellFolder_Release(sf
);
409 HRESULT WINAPI
SHILCreateFromPathAW (LPCVOID path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
411 if ( SHELL_OsIsUnicode())
412 return SHILCreateFromPathW (path
, ppidl
, attributes
);
413 return SHILCreateFromPathA (path
, ppidl
, attributes
);
416 /*************************************************************************
417 * SHCloneSpecialIDList [SHELL32.89]
419 * Create an ItemIDList to one of the special folders.
423 * nFolder [in] CSIDL_xxxxx
424 * fCreate [in] Create folder if it does not exist
427 * Success: The newly created pidl
428 * Failure: NULL, if inputs are invalid.
431 * exported by ordinal.
432 * Caller is responsible for deallocating the returned ItemIDList with the
433 * shells IMalloc interface, aka ILFree.
435 LPITEMIDLIST WINAPI
SHCloneSpecialIDList(HWND hwndOwner
, DWORD nFolder
, BOOL fCreate
)
438 TRACE_(shell
)("(hwnd=%p,csidl=0x%x,%s).\n", hwndOwner
, nFolder
, fCreate
? "T" : "F");
441 nFolder
|= CSIDL_FLAG_CREATE
;
443 SHGetSpecialFolderLocation(hwndOwner
, nFolder
, &ppidl
);
447 /*************************************************************************
448 * ILGlobalClone [SHELL32.20]
450 * Clones an ItemIDList using Alloc.
453 * pidl [I] ItemIDList to clone
456 * Newly allocated ItemIDList.
459 * exported by ordinal.
461 LPITEMIDLIST WINAPI
ILGlobalClone(LPCITEMIDLIST pidl
)
464 LPITEMIDLIST newpidl
;
469 len
= ILGetSize(pidl
);
470 newpidl
= Alloc(len
);
472 memcpy(newpidl
,pidl
,len
);
474 TRACE("pidl=%p newpidl=%p\n",pidl
, newpidl
);
480 /*************************************************************************
481 * ILIsEqual [SHELL32.21]
484 BOOL WINAPI
ILIsEqual(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
486 char szData1
[MAX_PATH
];
487 char szData2
[MAX_PATH
];
489 LPCITEMIDLIST pidltemp1
= pidl1
;
490 LPCITEMIDLIST pidltemp2
= pidl2
;
492 TRACE("pidl1=%p pidl2=%p\n",pidl1
, pidl2
);
495 * Explorer reads from registry directly (StreamMRU),
496 * so we can only check here
498 if (!pcheck(pidl1
) || !pcheck (pidl2
))
504 if (!pidl1
|| !pidl2
)
507 while (pidltemp1
->mkid
.cb
&& pidltemp2
->mkid
.cb
)
509 _ILSimpleGetText(pidltemp1
, szData1
, MAX_PATH
);
510 _ILSimpleGetText(pidltemp2
, szData2
, MAX_PATH
);
512 if (strcasecmp( szData1
, szData2
))
515 pidltemp1
= ILGetNext(pidltemp1
);
516 pidltemp2
= ILGetNext(pidltemp2
);
519 if (!pidltemp1
->mkid
.cb
&& !pidltemp2
->mkid
.cb
)
525 /*************************************************************************
526 * ILIsParent [SHELL32.23]
528 * Verifies that pidlParent is indeed the (immediate) parent of pidlChild.
533 * bImmediate [I] only return true if the parent is the direct parent
537 * True if the parent ItemIDlist is a complete part of the child ItemIdList,
541 * parent = a/b, child = a/b/c -> true, c is in folder a/b
542 * child = a/b/c/d -> false if bImmediate is true, d is not in folder a/b
543 * child = a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
545 BOOL WINAPI
ILIsParent(LPCITEMIDLIST pidlParent
, LPCITEMIDLIST pidlChild
, BOOL bImmediate
)
547 char szData1
[MAX_PATH
];
548 char szData2
[MAX_PATH
];
549 LPCITEMIDLIST pParent
= pidlParent
;
550 LPCITEMIDLIST pChild
= pidlChild
;
552 TRACE("%p %p %x\n", pidlParent
, pidlChild
, bImmediate
);
554 if (!pParent
|| !pChild
)
557 while (pParent
->mkid
.cb
&& pChild
->mkid
.cb
)
559 _ILSimpleGetText(pParent
, szData1
, MAX_PATH
);
560 _ILSimpleGetText(pChild
, szData2
, MAX_PATH
);
562 if (strcasecmp( szData1
, szData2
))
565 pParent
= ILGetNext(pParent
);
566 pChild
= ILGetNext(pChild
);
569 /* child shorter or has equal length to parent */
570 if (pParent
->mkid
.cb
|| !pChild
->mkid
.cb
)
573 /* not immediate descent */
574 if ( ILGetNext(pChild
)->mkid
.cb
&& bImmediate
)
580 /*************************************************************************
581 * ILFindChild [SHELL32.24]
583 * Compares elements from pidl1 and pidl2.
590 * pidl1 is desktop pidl2
591 * pidl1 shorter pidl2 pointer to first different element of pidl2
592 * if there was at least one equal element
593 * pidl2 shorter pidl1 0
594 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
597 * exported by ordinal.
599 LPITEMIDLIST WINAPI
ILFindChild(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
601 char szData1
[MAX_PATH
];
602 char szData2
[MAX_PATH
];
604 LPCITEMIDLIST pidltemp1
= pidl1
;
605 LPCITEMIDLIST pidltemp2
= pidl2
;
606 LPCITEMIDLIST ret
=NULL
;
608 TRACE("pidl1=%p pidl2=%p\n",pidl1
, pidl2
);
610 /* explorer reads from registry directly (StreamMRU),
611 so we can only check here */
612 if ((!pcheck (pidl1
)) || (!pcheck (pidl2
)))
618 if (_ILIsDesktop(pidl1
))
624 while (pidltemp1
->mkid
.cb
&& pidltemp2
->mkid
.cb
)
626 _ILSimpleGetText(pidltemp1
, szData1
, MAX_PATH
);
627 _ILSimpleGetText(pidltemp2
, szData2
, MAX_PATH
);
629 if (strcasecmp(szData1
,szData2
))
632 pidltemp1
= ILGetNext(pidltemp1
);
633 pidltemp2
= ILGetNext(pidltemp2
);
637 if (pidltemp1
->mkid
.cb
)
638 ret
= NULL
; /* elements of pidl1 left*/
640 TRACE_(shell
)("--- %p\n", ret
);
641 return (LPITEMIDLIST
)ret
; /* pidl 1 is shorter */
644 /*************************************************************************
645 * ILCombine [SHELL32.25]
647 * Concatenates two complex ItemIDLists.
650 * pidl1 [I] first complex ItemIDLists
651 * pidl2 [I] complex ItemIDLists to append
654 * if both pidl's == NULL NULL
655 * if pidl1 == NULL cloned pidl2
656 * if pidl2 == NULL cloned pidl1
657 * otherwise new pidl with pidl2 appended to pidl1
660 * exported by ordinal.
661 * Does not destroy the passed in ItemIDLists!
663 LPITEMIDLIST WINAPI
ILCombine(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
666 LPITEMIDLIST pidlNew
;
668 TRACE("pidl=%p pidl=%p\n",pidl1
,pidl2
);
670 if (!pidl1
&& !pidl2
) return NULL
;
677 pidlNew
= ILClone(pidl2
);
683 pidlNew
= ILClone(pidl1
);
687 len1
= ILGetSize(pidl1
)-2;
688 len2
= ILGetSize(pidl2
);
689 pidlNew
= SHAlloc(len1
+len2
);
693 memcpy(pidlNew
,pidl1
,len1
);
694 memcpy(((BYTE
*)pidlNew
)+len1
,pidl2
,len2
);
697 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
701 /*************************************************************************
702 * SHGetRealIDL [SHELL32.98]
706 HRESULT WINAPI
SHGetRealIDL(LPSHELLFOLDER lpsf
, LPCITEMIDLIST pidlSimple
, LPITEMIDLIST
*pidlReal
)
708 IDataObject
* pDataObj
;
711 hr
= IShellFolder_GetUIObjectOf(lpsf
, 0, 1, &pidlSimple
,
712 &IID_IDataObject
, 0, (LPVOID
*)&pDataObj
);
718 fmt
.cfFormat
= RegisterClipboardFormatW(CFSTR_SHELLIDLISTW
);
720 fmt
.dwAspect
= DVASPECT_CONTENT
;
722 fmt
.tymed
= TYMED_HGLOBAL
;
724 hr
= IDataObject_GetData(pDataObj
, &fmt
, &medium
);
726 IDataObject_Release(pDataObj
);
730 /*assert(pida->cidl==1);*/
731 LPIDA pida
= GlobalLock(medium
.u
.hGlobal
);
733 LPCITEMIDLIST pidl_folder
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[0]);
734 LPCITEMIDLIST pidl_child
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[1]);
736 *pidlReal
= ILCombine(pidl_folder
, pidl_child
);
741 GlobalUnlock(medium
.u
.hGlobal
);
742 GlobalFree(medium
.u
.hGlobal
);
749 /*************************************************************************
750 * SHLogILFromFSIL [SHELL32.95]
753 * pild = CSIDL_DESKTOP ret = 0
754 * pild = CSIDL_DRIVES ret = 0
756 LPITEMIDLIST WINAPI
SHLogILFromFSIL(LPITEMIDLIST pidl
)
758 FIXME("(pidl=%p)\n",pidl
);
765 /*************************************************************************
766 * ILGetSize [SHELL32.152]
768 * Gets the byte size of an ItemIDList including zero terminator
771 * pidl [I] ItemIDList
774 * size of pidl in bytes
777 * exported by ordinal
779 UINT WINAPI
ILGetSize(LPCITEMIDLIST pidl
)
781 LPCSHITEMID si
= &(pidl
->mkid
);
789 si
= (LPCSHITEMID
)(((const BYTE
*)si
)+si
->cb
);
793 TRACE("pidl=%p size=%u\n",pidl
, len
);
797 /*************************************************************************
798 * ILGetNext [SHELL32.153]
800 * Gets the next ItemID of an ItemIDList
803 * pidl [I] ItemIDList
808 * simple pidl -> pointer to 0x0000 element
811 * exported by ordinal.
813 LPITEMIDLIST WINAPI
ILGetNext(LPCITEMIDLIST pidl
)
824 pidl
= (LPCITEMIDLIST
) (((const BYTE
*)pidl
)+len
);
825 TRACE("-- %p\n", pidl
);
826 return (LPITEMIDLIST
)pidl
;
832 /*************************************************************************
833 * ILAppend [SHELL32.154]
835 * Adds the single ItemID item to the ItemIDList indicated by pidl.
836 * If bEnd is FALSE, inserts the item in the front of the list,
837 * otherwise it adds the item to the end. (???)
840 * pidl [I] ItemIDList to extend
841 * item [I] ItemID to prepend/append
842 * bEnd [I] Indicates if the item should be appended
845 * Destroys the passed in idlist! (???)
847 LPITEMIDLIST WINAPI
ILAppend(LPITEMIDLIST pidl
, LPCITEMIDLIST item
, BOOL bEnd
)
851 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl
,item
,bEnd
);
856 if (_ILIsDesktop(pidl
))
858 idlRet
= ILClone(item
);
864 idlRet
= ILCombine(pidl
, item
);
866 idlRet
= ILCombine(item
, pidl
);
872 /*************************************************************************
873 * ILFree [SHELL32.155]
875 * Frees memory (if not NULL) allocated by SHMalloc allocator
884 * exported by ordinal
886 void WINAPI
ILFree(LPITEMIDLIST pidl
)
888 TRACE("(pidl=%p)\n",pidl
);
892 /*************************************************************************
893 * ILGlobalFree [SHELL32.156]
895 * Frees memory (if not NULL) allocated by Alloc allocator
904 * exported by ordinal.
906 void WINAPI
ILGlobalFree( LPITEMIDLIST pidl
)
913 /*************************************************************************
914 * ILCreateFromPathA [SHELL32.189]
916 * Creates a complex ItemIDList from a path and returns it.
922 * the newly created complex ItemIDList or NULL if failed
925 * exported by ordinal.
927 LPITEMIDLIST WINAPI
ILCreateFromPathA (LPCSTR path
)
929 LPITEMIDLIST pidlnew
= NULL
;
931 TRACE_(shell
)("%s\n", debugstr_a(path
));
933 if (SUCCEEDED(SHILCreateFromPathA(path
, &pidlnew
, NULL
)))
938 /*************************************************************************
939 * ILCreateFromPathW [SHELL32.190]
941 * See ILCreateFromPathA.
943 LPITEMIDLIST WINAPI
ILCreateFromPathW (LPCWSTR path
)
945 LPITEMIDLIST pidlnew
= NULL
;
947 TRACE_(shell
)("%s\n", debugstr_w(path
));
949 if (SUCCEEDED(SHILCreateFromPathW(path
, &pidlnew
, NULL
)))
954 /*************************************************************************
955 * ILCreateFromPath [SHELL32.157]
957 LPITEMIDLIST WINAPI
ILCreateFromPathAW (LPCVOID path
)
959 if ( SHELL_OsIsUnicode())
960 return ILCreateFromPathW (path
);
961 return ILCreateFromPathA (path
);
964 /*************************************************************************
965 * _ILParsePathW [internal]
967 * Creates an ItemIDList from a path and returns it.
970 * path [I] path to parse and convert into an ItemIDList
971 * lpFindFile [I] pointer to buffer to initialize the FileSystem
972 * Bind Data object with
973 * bBindCtx [I] indicates to create a BindContext and assign a
974 * FileSystem Bind Data object
975 * ppidl [O] the newly create ItemIDList
976 * prgfInOut [I/O] requested attributes on input and actual
977 * attributes on return
980 * NO_ERROR on success or an OLE error code
983 * If either lpFindFile is non-NULL or bBindCtx is TRUE, this function
984 * creates a BindContext object and assigns a FileSystem Bind Data object
985 * to it, passing the BindContext to IShellFolder_ParseDisplayName. Each
986 * IShellFolder uses that FileSystem Bind Data object of the BindContext
987 * to pass data about the current path element to the next object. This
988 * is used to avoid having to verify the current path element on disk, so
989 * that creating an ItemIDList from a nonexistent path still can work.
991 static HRESULT
_ILParsePathW(LPCWSTR path
, LPWIN32_FIND_DATAW lpFindFile
,
992 BOOL bBindCtx
, LPITEMIDLIST
*ppidl
, LPDWORD prgfInOut
)
994 LPSHELLFOLDER pSF
= NULL
;
998 TRACE("%s %p %d (%p)->%p (%p)->0x%x\n", debugstr_w(path
), lpFindFile
, bBindCtx
,
999 ppidl
, ppidl
? *ppidl
: NULL
,
1000 prgfInOut
, prgfInOut
? *prgfInOut
: 0);
1002 ret
= SHGetDesktopFolder(&pSF
);
1006 if (lpFindFile
|| bBindCtx
)
1007 ret
= IFileSystemBindData_Constructor(lpFindFile
, &pBC
);
1011 ret
= IShellFolder_ParseDisplayName(pSF
, 0, pBC
, (LPOLESTR
)path
, NULL
, ppidl
, prgfInOut
);
1016 IBindCtx_Release(pBC
);
1020 IShellFolder_Release(pSF
);
1022 if (FAILED(ret
) && ppidl
)
1025 TRACE("%s %p 0x%x\n", debugstr_w(path
), ppidl
? *ppidl
: NULL
, prgfInOut
? *prgfInOut
: 0);
1030 /*************************************************************************
1031 * SHSimpleIDListFromPath [SHELL32.162]
1033 * Creates a simple ItemIDList from a path and returns it. This function
1034 * does not fail on nonexistent paths.
1037 * path [I] path to parse and convert into an ItemIDList
1040 * the newly created simple ItemIDList
1043 * Simple in the name does not mean a relative ItemIDList but rather a
1044 * fully qualified list, where only the file name is filled in and the
1045 * directory flag for those ItemID elements this is known about, eg.
1046 * it is not the last element in the ItemIDList or the actual directory
1048 * exported by ordinal.
1050 LPITEMIDLIST WINAPI
SHSimpleIDListFromPathA(LPCSTR lpszPath
)
1052 LPITEMIDLIST pidl
= NULL
;
1053 LPWSTR wPath
= NULL
;
1056 TRACE("%s\n", debugstr_a(lpszPath
));
1060 len
= MultiByteToWideChar(CP_ACP
, 0, lpszPath
, -1, NULL
, 0);
1061 wPath
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1062 MultiByteToWideChar(CP_ACP
, 0, lpszPath
, -1, wPath
, len
);
1065 _ILParsePathW(wPath
, NULL
, TRUE
, &pidl
, NULL
);
1067 HeapFree(GetProcessHeap(), 0, wPath
);
1068 TRACE("%s %p\n", debugstr_a(lpszPath
), pidl
);
1072 LPITEMIDLIST WINAPI
SHSimpleIDListFromPathW(LPCWSTR lpszPath
)
1074 LPITEMIDLIST pidl
= NULL
;
1076 TRACE("%s\n", debugstr_w(lpszPath
));
1078 _ILParsePathW(lpszPath
, NULL
, TRUE
, &pidl
, NULL
);
1079 TRACE("%s %p\n", debugstr_w(lpszPath
), pidl
);
1083 LPITEMIDLIST WINAPI
SHSimpleIDListFromPathAW(LPCVOID lpszPath
)
1085 if ( SHELL_OsIsUnicode())
1086 return SHSimpleIDListFromPathW (lpszPath
);
1087 return SHSimpleIDListFromPathA (lpszPath
);
1090 /*************************************************************************
1091 * SHGetDataFromIDListA [SHELL32.247]
1094 * the pidl can be a simple one. since we can't get the path out of the pidl
1095 * we have to take all data from the pidl
1097 HRESULT WINAPI
SHGetDataFromIDListA(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
,
1098 int nFormat
, LPVOID dest
, int len
)
1100 LPSTR filename
, shortname
;
1101 WIN32_FIND_DATAA
* pfd
;
1103 TRACE_(shell
)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf
,pidl
,nFormat
,dest
,len
);
1107 return E_INVALIDARG
;
1111 case SHGDFIL_FINDDATA
:
1114 if (_ILIsDrive(pidl
) || _ILIsSpecialFolder(pidl
))
1115 return E_INVALIDARG
;
1117 if (len
< sizeof(WIN32_FIND_DATAA
))
1118 return E_INVALIDARG
;
1120 ZeroMemory(pfd
, sizeof (WIN32_FIND_DATAA
));
1121 _ILGetFileDateTime( pidl
, &(pfd
->ftLastWriteTime
));
1122 pfd
->dwFileAttributes
= _ILGetFileAttributes(pidl
, NULL
, 0);
1123 pfd
->nFileSizeLow
= _ILGetFileSize ( pidl
, NULL
, 0);
1125 filename
= _ILGetTextPointer(pidl
);
1126 shortname
= _ILGetSTextPointer(pidl
);
1129 lstrcpynA(pfd
->cFileName
, filename
, sizeof(pfd
->cFileName
));
1131 pfd
->cFileName
[0] = '\0';
1134 lstrcpynA(pfd
->cAlternateFileName
, shortname
, sizeof(pfd
->cAlternateFileName
));
1136 pfd
->cAlternateFileName
[0] = '\0';
1139 case SHGDFIL_NETRESOURCE
:
1140 case SHGDFIL_DESCRIPTIONID
:
1141 FIXME_(shell
)("SHGDFIL %i stub\n", nFormat
);
1145 ERR_(shell
)("Unknown SHGDFIL %i, please report\n", nFormat
);
1148 return E_INVALIDARG
;
1151 /*************************************************************************
1152 * SHGetDataFromIDListW [SHELL32.248]
1155 HRESULT WINAPI
SHGetDataFromIDListW(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
,
1156 int nFormat
, LPVOID dest
, int len
)
1158 LPSTR filename
, shortname
;
1159 WIN32_FIND_DATAW
* pfd
= dest
;
1161 TRACE_(shell
)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf
,pidl
,nFormat
,dest
,len
);
1166 return E_INVALIDARG
;
1170 case SHGDFIL_FINDDATA
:
1173 if (_ILIsDrive(pidl
))
1174 return E_INVALIDARG
;
1176 if (len
< sizeof(WIN32_FIND_DATAW
))
1177 return E_INVALIDARG
;
1179 ZeroMemory(pfd
, sizeof (WIN32_FIND_DATAA
));
1180 _ILGetFileDateTime( pidl
, &(pfd
->ftLastWriteTime
));
1181 pfd
->dwFileAttributes
= _ILGetFileAttributes(pidl
, NULL
, 0);
1182 pfd
->nFileSizeLow
= _ILGetFileSize ( pidl
, NULL
, 0);
1184 filename
= _ILGetTextPointer(pidl
);
1185 shortname
= _ILGetSTextPointer(pidl
);
1188 pfd
->cFileName
[0] = '\0';
1189 else if (!MultiByteToWideChar(CP_ACP
, 0, filename
, -1, pfd
->cFileName
, MAX_PATH
))
1190 pfd
->cFileName
[MAX_PATH
-1] = 0;
1193 pfd
->cAlternateFileName
[0] = '\0';
1194 else if (!MultiByteToWideChar(CP_ACP
, 0, shortname
, -1, pfd
->cAlternateFileName
, 14))
1195 pfd
->cAlternateFileName
[13] = 0;
1198 case SHGDFIL_NETRESOURCE
:
1199 case SHGDFIL_DESCRIPTIONID
:
1200 FIXME_(shell
)("SHGDFIL %i stub\n", nFormat
);
1204 ERR_(shell
)("Unknown SHGDFIL %i, please report\n", nFormat
);
1207 return E_INVALIDARG
;
1210 /*************************************************************************
1211 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
1215 * pszPath [OUT] path
1218 * path from a passed PIDL.
1221 * NULL returns FALSE
1222 * desktop pidl gives path to desktop directory back
1223 * special pidls returning FALSE
1225 BOOL WINAPI
SHGetPathFromIDListA(LPCITEMIDLIST pidl
, LPSTR pszPath
)
1227 WCHAR wszPath
[MAX_PATH
];
1230 bSuccess
= SHGetPathFromIDListW(pidl
, wszPath
);
1231 WideCharToMultiByte(CP_ACP
, 0, wszPath
, -1, pszPath
, MAX_PATH
, NULL
, NULL
);
1236 /*************************************************************************
1237 * SHGetPathFromIDListW [SHELL32.@]
1239 * See SHGetPathFromIDListA.
1241 BOOL WINAPI
SHGetPathFromIDListW(LPCITEMIDLIST pidl
, LPWSTR pszPath
)
1244 LPCITEMIDLIST pidlLast
;
1245 LPSHELLFOLDER psfFolder
;
1249 TRACE_(shell
)("(pidl=%p,%p)\n", pidl
, pszPath
);
1256 hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (VOID
**)&psfFolder
, &pidlLast
);
1257 if (FAILED(hr
)) return FALSE
;
1259 dwAttributes
= SFGAO_FILESYSTEM
;
1260 hr
= IShellFolder_GetAttributesOf(psfFolder
, 1, &pidlLast
, &dwAttributes
);
1261 if (FAILED(hr
) || !(dwAttributes
& SFGAO_FILESYSTEM
)) {
1262 IShellFolder_Release(psfFolder
);
1266 hr
= IShellFolder_GetDisplayNameOf(psfFolder
, pidlLast
, SHGDN_FORPARSING
, &strret
);
1267 IShellFolder_Release(psfFolder
);
1268 if (FAILED(hr
)) return FALSE
;
1270 hr
= StrRetToBufW(&strret
, pidlLast
, pszPath
, MAX_PATH
);
1272 TRACE_(shell
)("-- %s, 0x%08x\n",debugstr_w(pszPath
), hr
);
1273 return SUCCEEDED(hr
);
1276 /*************************************************************************
1277 * SHBindToParent [shell version 5.0]
1279 HRESULT WINAPI
SHBindToParent(LPCITEMIDLIST pidl
, REFIID riid
, LPVOID
*ppv
, LPCITEMIDLIST
*ppidlLast
)
1281 IShellFolder
* psfDesktop
;
1284 TRACE_(shell
)("pidl=%p\n", pidl
);
1288 return E_INVALIDARG
;
1294 hr
= SHGetDesktopFolder(&psfDesktop
);
1298 if (_ILIsPidlSimple(pidl
))
1300 /* we are on desktop level */
1301 hr
= IShellFolder_QueryInterface(psfDesktop
, riid
, ppv
);
1305 LPITEMIDLIST pidlParent
= ILClone(pidl
);
1306 ILRemoveLastID(pidlParent
);
1307 hr
= IShellFolder_BindToObject(psfDesktop
, pidlParent
, NULL
, riid
, ppv
);
1308 SHFree (pidlParent
);
1311 IShellFolder_Release(psfDesktop
);
1313 if (SUCCEEDED(hr
) && ppidlLast
)
1314 *ppidlLast
= ILFindLastID(pidl
);
1316 TRACE_(shell
)("-- psf=%p pidl=%p ret=0x%08x\n", *ppv
, (ppidlLast
)?*ppidlLast
:NULL
, hr
);
1320 /**************************************************************************
1322 * internal functions
1324 * ### 1. section creating pidls ###
1326 *************************************************************************
1329 /* Basic PIDL constructor. Allocates size + 5 bytes, where:
1330 * - two bytes are SHITEMID.cb
1331 * - one byte is PIDLDATA.type
1332 * - two bytes are the NULL PIDL terminator
1333 * Sets type of the returned PIDL to type.
1335 static LPITEMIDLIST
_ILAlloc(PIDLTYPE type
, unsigned int size
)
1337 LPITEMIDLIST pidlOut
= NULL
;
1339 pidlOut
= SHAlloc(size
+ 5);
1343 LPITEMIDLIST pidlNext
;
1345 ZeroMemory(pidlOut
, size
+ 5);
1346 pidlOut
->mkid
.cb
= size
+ 3;
1348 pData
= _ILGetDataPointer(pidlOut
);
1352 pidlNext
= ILGetNext(pidlOut
);
1354 pidlNext
->mkid
.cb
= 0x00;
1355 TRACE("-- (pidl=%p, size=%u)\n", pidlOut
, size
);
1361 LPITEMIDLIST
_ILCreateDesktop(void)
1372 LPITEMIDLIST
_ILCreateMyComputer(void)
1375 return _ILCreateGuid(PT_GUID
, &CLSID_MyComputer
);
1378 LPITEMIDLIST
_ILCreateMyDocuments(void)
1381 return _ILCreateGuid(PT_GUID
, &CLSID_MyDocuments
);
1384 LPITEMIDLIST
_ILCreateIExplore(void)
1387 return _ILCreateGuid(PT_GUID
, &CLSID_Internet
);
1390 LPITEMIDLIST
_ILCreateControlPanel(void)
1392 LPITEMIDLIST parent
= _ILCreateGuid(PT_GUID
, &CLSID_MyComputer
), ret
= NULL
;
1397 LPITEMIDLIST cpl
= _ILCreateGuid(PT_SHELLEXT
, &CLSID_ControlPanel
);
1401 ret
= ILCombine(parent
, cpl
);
1409 LPITEMIDLIST
_ILCreatePrinters(void)
1411 LPITEMIDLIST parent
= _ILCreateGuid(PT_GUID
, &CLSID_MyComputer
), ret
= NULL
;
1416 LPITEMIDLIST printers
= _ILCreateGuid(PT_YAGUID
, &CLSID_Printers
);
1420 ret
= ILCombine(parent
, printers
);
1428 LPITEMIDLIST
_ILCreateNetwork(void)
1431 return _ILCreateGuid(PT_GUID
, &CLSID_NetworkPlaces
);
1434 LPITEMIDLIST
_ILCreateBitBucket(void)
1437 return _ILCreateGuid(PT_GUID
, &CLSID_RecycleBin
);
1440 LPITEMIDLIST
_ILCreateNetHood(void)
1443 return _ILCreateGuid(PT_GUID
, &CLSID_NetworkPlaces
);
1446 LPITEMIDLIST
_ILCreateGuid(PIDLTYPE type
, REFIID guid
)
1448 LPITEMIDLIST pidlOut
;
1450 if (type
== PT_SHELLEXT
|| type
== PT_GUID
|| type
== PT_YAGUID
)
1452 pidlOut
= _ILAlloc(type
, sizeof(GUIDStruct
));
1455 LPPIDLDATA pData
= _ILGetDataPointer(pidlOut
);
1457 pData
->u
.guid
.guid
= *guid
;
1458 TRACE("-- create GUID-pidl %s\n",
1459 debugstr_guid(&(pData
->u
.guid
.guid
)));
1464 WARN("%d: invalid type for GUID\n", type
);
1470 LPITEMIDLIST
_ILCreateGuidFromStrA(LPCSTR szGUID
)
1474 if (FAILED(SHCLSIDFromStringA(szGUID
, &iid
)))
1476 ERR("%s is not a GUID\n", szGUID
);
1479 return _ILCreateGuid(PT_GUID
, &iid
);
1482 LPITEMIDLIST
_ILCreateGuidFromStrW(LPCWSTR szGUID
)
1486 if (FAILED(SHCLSIDFromStringW(szGUID
, &iid
)))
1488 ERR("%s is not a GUID\n", debugstr_w(szGUID
));
1491 return _ILCreateGuid(PT_GUID
, &iid
);
1494 LPITEMIDLIST
_ILCreateFromFindDataW( const WIN32_FIND_DATAW
*wfd
)
1496 char buff
[MAX_PATH
+ 14 +1]; /* see WIN32_FIND_DATA */
1497 DWORD len
, len1
, wlen
, alen
;
1504 TRACE("(%s, %s)\n",debugstr_w(wfd
->cAlternateFileName
), debugstr_w(wfd
->cFileName
));
1506 /* prepare buffer with both names */
1507 len
= WideCharToMultiByte(CP_ACP
,0,wfd
->cFileName
,-1,buff
,MAX_PATH
,NULL
,NULL
);
1508 len1
= WideCharToMultiByte(CP_ACP
,0,wfd
->cAlternateFileName
,-1, buff
+len
, sizeof(buff
)-len
, NULL
, NULL
);
1511 type
= (wfd
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ? PT_FOLDER
: PT_VALUE
;
1513 wlen
= lstrlenW(wfd
->cFileName
) + 1;
1514 pidl
= _ILAlloc(type
, FIELD_OFFSET(FileStruct
, szNames
[alen
+ (alen
& 1)]) +
1515 FIELD_OFFSET(FileStructW
, wszName
[wlen
]) + sizeof(WORD
));
1518 LPPIDLDATA pData
= _ILGetDataPointer(pidl
);
1519 FileStruct
*fs
= &pData
->u
.file
;
1523 FileTimeToDosDateTime( &wfd
->ftLastWriteTime
, &fs
->uFileDate
, &fs
->uFileTime
);
1524 fs
->dwFileSize
= wfd
->nFileSizeLow
;
1525 fs
->uFileAttribs
= wfd
->dwFileAttributes
;
1526 memcpy(fs
->szNames
, buff
, alen
);
1528 fsw
= (FileStructW
*)(pData
->u
.file
.szNames
+ alen
+ (alen
& 0x1));
1529 fsw
->cbLen
= FIELD_OFFSET(FileStructW
, wszName
[wlen
]) + sizeof(WORD
);
1530 FileTimeToDosDateTime( &wfd
->ftCreationTime
, &fsw
->uCreationDate
, &fsw
->uCreationTime
);
1531 FileTimeToDosDateTime( &wfd
->ftLastAccessTime
, &fsw
->uLastAccessDate
, &fsw
->uLastAccessTime
);
1532 memcpy(fsw
->wszName
, wfd
->cFileName
, wlen
* sizeof(WCHAR
));
1534 pOffsetW
= (WORD
*)((LPBYTE
)pidl
+ pidl
->mkid
.cb
- sizeof(WORD
));
1535 *pOffsetW
= (LPBYTE
)fsw
- (LPBYTE
)pidl
;
1536 TRACE("-- Set Value: %s\n",debugstr_w(fsw
->wszName
));
1542 HRESULT
_ILCreateFromPathW(LPCWSTR szPath
, LPITEMIDLIST
* ppidl
)
1545 WIN32_FIND_DATAW stffile
;
1548 return E_INVALIDARG
;
1550 hFile
= FindFirstFileW(szPath
, &stffile
);
1551 if (hFile
== INVALID_HANDLE_VALUE
)
1552 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
1556 *ppidl
= _ILCreateFromFindDataW(&stffile
);
1558 return *ppidl
? S_OK
: E_OUTOFMEMORY
;
1561 LPITEMIDLIST
_ILCreateDrive(LPCWSTR lpszNew
)
1563 LPITEMIDLIST pidlOut
;
1565 TRACE("(%s)\n",debugstr_w(lpszNew
));
1567 pidlOut
= _ILAlloc(PT_DRIVE
, sizeof(DriveStruct
));
1572 pszDest
= _ILGetTextPointer(pidlOut
);
1575 strcpy(pszDest
, "x:\\");
1576 pszDest
[0]=toupperW(lpszNew
[0]);
1577 TRACE("-- create Drive: %s\n", debugstr_a(pszDest
));
1583 LPITEMIDLIST
_ILCreateEntireNetwork(void)
1585 LPITEMIDLIST pidlOut
;
1589 pidlOut
= _ILAlloc(PT_NETWORK
, FIELD_OFFSET(PIDLDATA
, u
.network
.szNames
[sizeof("Entire Network")]));
1592 LPPIDLDATA pData
= _ILGetDataPointer(pidlOut
);
1594 pData
->u
.network
.dummy
= 0;
1595 strcpy(pData
->u
.network
.szNames
, "Entire Network");
1600 /**************************************************************************
1603 * Gets the text for the drive eg. 'c:\'
1608 DWORD
_ILGetDrive(LPCITEMIDLIST pidl
,LPSTR pOut
, UINT uSize
)
1610 TRACE("(%p,%p,%u)\n",pidl
,pOut
,uSize
);
1612 if(_ILIsMyComputer(pidl
))
1613 pidl
= ILGetNext(pidl
);
1615 if (pidl
&& _ILIsDrive(pidl
))
1616 return _ILSimpleGetText(pidl
, pOut
, uSize
);
1621 /**************************************************************************
1623 * ### 2. section testing pidls ###
1625 **************************************************************************
1629 * _ILIsSpecialFolder()
1635 BOOL
_ILIsUnicode(LPCITEMIDLIST pidl
)
1637 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1639 TRACE("(%p)\n",pidl
);
1641 return (pidl
&& lpPData
&& PT_VALUEW
== lpPData
->type
);
1644 BOOL
_ILIsDesktop(LPCITEMIDLIST pidl
)
1646 TRACE("(%p)\n",pidl
);
1648 return pidl
&& pidl
->mkid
.cb
? 0 : 1;
1651 BOOL
_ILIsMyComputer(LPCITEMIDLIST pidl
)
1653 REFIID iid
= _ILGetGUIDPointer(pidl
);
1655 TRACE("(%p)\n",pidl
);
1658 return IsEqualIID(iid
, &CLSID_MyComputer
);
1662 BOOL
_ILIsSpecialFolder (LPCITEMIDLIST pidl
)
1664 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1666 TRACE("(%p)\n",pidl
);
1668 return (pidl
&& ( (lpPData
&& (PT_GUID
== lpPData
->type
|| PT_SHELLEXT
== lpPData
->type
|| PT_YAGUID
== lpPData
->type
)) ||
1669 (pidl
&& pidl
->mkid
.cb
== 0x00)
1673 BOOL
_ILIsDrive(LPCITEMIDLIST pidl
)
1675 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1677 TRACE("(%p)\n",pidl
);
1679 return (pidl
&& lpPData
&& (PT_DRIVE
== lpPData
->type
||
1680 PT_DRIVE1
== lpPData
->type
||
1681 PT_DRIVE2
== lpPData
->type
||
1682 PT_DRIVE3
== lpPData
->type
));
1685 BOOL
_ILIsFolder(LPCITEMIDLIST pidl
)
1687 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1689 TRACE("(%p)\n",pidl
);
1691 return (pidl
&& lpPData
&& (PT_FOLDER
== lpPData
->type
|| PT_FOLDER1
== lpPData
->type
));
1694 BOOL
_ILIsValue(LPCITEMIDLIST pidl
)
1696 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1698 TRACE("(%p)\n",pidl
);
1700 return (pidl
&& lpPData
&& PT_VALUE
== lpPData
->type
);
1703 BOOL
_ILIsCPanelStruct(LPCITEMIDLIST pidl
)
1705 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1707 TRACE("(%p)\n",pidl
);
1709 return (pidl
&& lpPData
&& (lpPData
->type
== 0));
1712 /**************************************************************************
1715 BOOL
_ILIsPidlSimple(LPCITEMIDLIST pidl
)
1719 if(! _ILIsDesktop(pidl
)) /* pidl=NULL or mkid.cb=0 */
1721 WORD len
= pidl
->mkid
.cb
;
1722 LPCITEMIDLIST pidlnext
= (LPCITEMIDLIST
) (((const BYTE
*)pidl
) + len
);
1724 if (pidlnext
->mkid
.cb
)
1728 TRACE("%s\n", ret
? "Yes" : "No");
1732 /**************************************************************************
1734 * ### 3. section getting values from pidls ###
1737 /**************************************************************************
1740 * gets the text for the first item in the pidl (eg. simple pidl)
1742 * returns the length of the string
1744 DWORD
_ILSimpleGetText (LPCITEMIDLIST pidl
, LPSTR szOut
, UINT uOutSize
)
1750 char szTemp
[MAX_PATH
];
1752 TRACE("(%p %p %x)\n",pidl
,szOut
,uOutSize
);
1760 if (_ILIsDesktop(pidl
))
1763 if (HCR_GetClassNameA(&CLSID_ShellDesktop
, szTemp
, MAX_PATH
))
1766 lstrcpynA(szOut
, szTemp
, uOutSize
);
1768 dwReturn
= strlen (szTemp
);
1771 else if (( szSrc
= _ILGetTextPointer(pidl
) ))
1775 lstrcpynA(szOut
, szSrc
, uOutSize
);
1777 dwReturn
= strlen(szSrc
);
1779 else if (( szSrcW
= _ILGetTextPointerW(pidl
) ))
1781 /* unicode filesystem */
1782 WideCharToMultiByte(CP_ACP
,0,szSrcW
, -1, szTemp
, MAX_PATH
, NULL
, NULL
);
1785 lstrcpynA(szOut
, szTemp
, uOutSize
);
1787 dwReturn
= strlen (szTemp
);
1789 else if (( riid
= _ILGetGUIDPointer(pidl
) ))
1791 /* special folder */
1792 if ( HCR_GetClassNameA(riid
, szTemp
, MAX_PATH
) )
1795 lstrcpynA(szOut
, szTemp
, uOutSize
);
1797 dwReturn
= strlen (szTemp
);
1802 ERR("-- no text\n");
1805 TRACE("-- (%p=%s 0x%08x)\n",szOut
,debugstr_a(szOut
),dwReturn
);
1809 /**************************************************************************
1812 * gets the text for the first item in the pidl (eg. simple pidl)
1814 * returns the length of the string
1816 DWORD
_ILSimpleGetTextW (LPCITEMIDLIST pidl
, LPWSTR szOut
, UINT uOutSize
)
1819 FileStructW
*pFileStructW
= _ILGetFileStructW(pidl
);
1821 TRACE("(%p %p %x)\n",pidl
,szOut
,uOutSize
);
1824 lstrcpynW(szOut
, pFileStructW
->wszName
, uOutSize
);
1825 dwReturn
= lstrlenW(pFileStructW
->wszName
);
1828 WCHAR szTemp
[MAX_PATH
];
1839 if (_ILIsDesktop(pidl
))
1842 if (HCR_GetClassNameW(&CLSID_ShellDesktop
, szTemp
, MAX_PATH
))
1845 lstrcpynW(szOut
, szTemp
, uOutSize
);
1847 dwReturn
= lstrlenW (szTemp
);
1850 else if (( szSrcW
= _ILGetTextPointerW(pidl
) ))
1852 /* unicode filesystem */
1854 lstrcpynW(szOut
, szSrcW
, uOutSize
);
1856 dwReturn
= lstrlenW(szSrcW
);
1858 else if (( szSrc
= _ILGetTextPointer(pidl
) ))
1861 MultiByteToWideChar(CP_ACP
, 0, szSrc
, -1, szTemp
, MAX_PATH
);
1864 lstrcpynW(szOut
, szTemp
, uOutSize
);
1866 dwReturn
= lstrlenW (szTemp
);
1868 else if (( riid
= _ILGetGUIDPointer(pidl
) ))
1870 /* special folder */
1871 if ( HCR_GetClassNameW(riid
, szTemp
, MAX_PATH
) )
1874 lstrcpynW(szOut
, szTemp
, uOutSize
);
1876 dwReturn
= lstrlenW (szTemp
);
1881 ERR("-- no text\n");
1885 TRACE("-- (%p=%s 0x%08x)\n",szOut
,debugstr_w(szOut
),dwReturn
);
1889 /**************************************************************************
1891 * ### 4. getting pointers to parts of pidls ###
1893 **************************************************************************
1894 * _ILGetDataPointer()
1896 LPPIDLDATA
_ILGetDataPointer(LPCITEMIDLIST pidl
)
1898 if(pidl
&& pidl
->mkid
.cb
!= 0x00)
1899 return (LPPIDLDATA
)pidl
->mkid
.abID
;
1903 /**************************************************************************
1904 * _ILGetTextPointerW()
1905 * gets a pointer to the unicode long filename string stored in the pidl
1907 static LPWSTR
_ILGetTextPointerW(LPCITEMIDLIST pidl
)
1909 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
1911 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
1916 switch (pdata
->type
)
1927 /*return (LPSTR)&(pdata->u.drive.szDriveName);*/
1935 /*return (LPSTR)&(pdata->u.file.szNames);*/
1941 case PT_NETPROVIDER
:
1943 /*return (LPSTR)&(pdata->u.network.szNames);*/
1947 return (LPWSTR
)pdata
->u
.file
.szNames
;
1953 /**************************************************************************
1954 * _ILGetTextPointer()
1955 * gets a pointer to the long filename string stored in the pidl
1957 LPSTR
_ILGetTextPointer(LPCITEMIDLIST pidl
)
1959 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
1961 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
1966 switch (pdata
->type
)
1977 return (LPSTR
)pdata
->u
.drive
.szDriveName
;
1984 return (LPSTR
)pdata
->u
.file
.szNames
;
1989 case PT_NETPROVIDER
:
1991 return (LPSTR
)pdata
->u
.network
.szNames
;
1996 /**************************************************************************
1997 * _ILGetSTextPointer()
1998 * gets a pointer to the short filename string stored in the pidl
2000 static LPSTR
_ILGetSTextPointer(LPCITEMIDLIST pidl
)
2002 /* TRACE(pidl,"(pidl%p)\n", pidl); */
2004 LPPIDLDATA pdata
=_ILGetDataPointer(pidl
);
2009 switch (pdata
->type
)
2015 return (LPSTR
)(pdata
->u
.file
.szNames
+ strlen (pdata
->u
.file
.szNames
) + 1);
2018 return (LPSTR
)(pdata
->u
.network
.szNames
+ strlen (pdata
->u
.network
.szNames
) + 1);
2023 /**************************************************************************
2024 * _ILGetGUIDPointer()
2026 * returns reference to guid stored in some pidls
2028 IID
* _ILGetGUIDPointer(LPCITEMIDLIST pidl
)
2030 LPPIDLDATA pdata
=_ILGetDataPointer(pidl
);
2032 TRACE("%p\n", pidl
);
2037 TRACE("pdata->type 0x%04x\n", pdata
->type
);
2038 switch (pdata
->type
)
2043 return &(pdata
->u
.guid
.guid
);
2046 TRACE("Unknown pidl type 0x%04x\n", pdata
->type
);
2052 /******************************************************************************
2053 * _ILGetFileStructW [Internal]
2055 * Get pointer the a SHITEMID's FileStructW field if present
2058 * pidl [I] The SHITEMID
2061 * Success: Pointer to pidl's FileStructW field.
2064 FileStructW
* _ILGetFileStructW(LPCITEMIDLIST pidl
) {
2065 FileStructW
*pFileStructW
;
2068 if (!(_ILIsValue(pidl
) || _ILIsFolder(pidl
)))
2071 cbOffset
= *(const WORD
*)((const BYTE
*)pidl
+ pidl
->mkid
.cb
- sizeof(WORD
));
2072 pFileStructW
= (FileStructW
*)((LPBYTE
)pidl
+ cbOffset
);
2074 /* Currently I don't see a fool prove way to figure out if a pidl is for sure of WinXP
2075 * style with a FileStructW member. If we switch all our shellfolder-implementations to
2076 * the new format, this won't be a problem. For now, we do as many sanity checks as possible. */
2077 if (cbOffset
& 0x1 || /* FileStructW member is word aligned in the pidl */
2078 /* FileStructW is positioned after FileStruct */
2079 cbOffset
< sizeof(pidl
->mkid
.cb
) + sizeof(PIDLTYPE
) + sizeof(FileStruct
) ||
2080 /* There has to be enough space at cbOffset in the pidl to hold FileStructW and cbOffset */
2081 cbOffset
> pidl
->mkid
.cb
- sizeof(cbOffset
) - sizeof(FileStructW
) ||
2082 pidl
->mkid
.cb
!= cbOffset
+ pFileStructW
->cbLen
)
2084 WARN("Invalid pidl format (cbOffset = %d)!\n", cbOffset
);
2088 return pFileStructW
;
2091 /*************************************************************************
2092 * _ILGetFileDateTime
2094 * Given the ItemIdList, get the FileTime
2097 * pidl [I] The ItemIDList
2098 * pFt [I] the resulted FILETIME of the file
2101 * True if Successful
2106 BOOL
_ILGetFileDateTime(LPCITEMIDLIST pidl
, FILETIME
*pFt
)
2108 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2113 switch (pdata
->type
)
2117 DosDateTimeToFileTime(pdata
->u
.file
.uFileDate
, pdata
->u
.file
.uFileTime
, pFt
);
2125 BOOL
_ILGetFileDate (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2131 if (_ILGetFileDateTime( pidl
, &ft
))
2133 FileTimeToLocalFileTime(&ft
, &lft
);
2134 FileTimeToSystemTime (&lft
, &time
);
2136 ret
= GetDateFormatA(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&time
, NULL
, pOut
, uOutSize
);
2139 /* Append space + time without seconds */
2141 GetTimeFormatA(LOCALE_USER_DEFAULT
, TIME_NOSECONDS
, &time
, NULL
, &pOut
[ret
], uOutSize
- ret
);
2152 /*************************************************************************
2155 * Given the ItemIdList, get the FileSize
2158 * pidl [I] The ItemIDList
2159 * pOut [I] The buffer to save the result
2160 * uOutsize [I] The size of the buffer
2166 * pOut can be null when no string is needed
2169 DWORD
_ILGetFileSize (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2171 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2177 switch (pdata
->type
)
2180 dwSize
= pdata
->u
.file
.dwFileSize
;
2182 StrFormatKBSizeA(dwSize
, pOut
, uOutSize
);
2190 BOOL
_ILGetExtension (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2192 char szTemp
[MAX_PATH
];
2193 const char * pPoint
;
2194 LPCITEMIDLIST pidlTemp
=pidl
;
2196 TRACE("pidl=%p\n",pidl
);
2201 pidlTemp
= ILFindLastID(pidl
);
2203 if (!_ILIsValue(pidlTemp
))
2205 if (!_ILSimpleGetText(pidlTemp
, szTemp
, MAX_PATH
))
2208 pPoint
= PathFindExtensionA(szTemp
);
2214 lstrcpynA(pOut
, pPoint
, uOutSize
);
2220 /*************************************************************************
2223 * Given the ItemIdList, get the file type description
2226 * pidl [I] The ItemIDList (simple)
2227 * pOut [I] The buffer to save the result
2228 * uOutsize [I] The size of the buffer
2234 * This function copies as much as possible into the buffer.
2236 void _ILGetFileType(LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2238 if(_ILIsValue(pidl
))
2244 if (_ILGetExtension (pidl
, sTemp
, 64))
2246 if (!( HCR_MapTypeToValueA(sTemp
, sTemp
, 64, TRUE
)
2247 && HCR_MapTypeToValueA(sTemp
, pOut
, uOutSize
, FALSE
)))
2249 lstrcpynA (pOut
, sTemp
, uOutSize
- 6);
2250 strcat (pOut
, "-file");
2255 lstrcpynA(pOut
, "Folder", uOutSize
);
2258 /*************************************************************************
2259 * _ILGetFileAttributes
2261 * Given the ItemIdList, get the Attrib string format
2264 * pidl [I] The ItemIDList
2265 * pOut [I] The buffer to save the result
2266 * uOutsize [I] The size of the Buffer
2272 * return value 0 in case of error is a valid return value
2275 DWORD
_ILGetFileAttributes(LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2277 LPPIDLDATA pData
= _ILGetDataPointer(pidl
);
2288 wAttrib
= pData
->u
.file
.uFileAttribs
;
2295 if(wAttrib
& FILE_ATTRIBUTE_READONLY
)
2297 if(wAttrib
& FILE_ATTRIBUTE_HIDDEN
)
2299 if(wAttrib
& FILE_ATTRIBUTE_SYSTEM
)
2301 if(wAttrib
& FILE_ATTRIBUTE_ARCHIVE
)
2303 if(wAttrib
& FILE_ATTRIBUTE_COMPRESSED
)
2310 /*************************************************************************
2313 * free a aPidl struct
2315 void _ILFreeaPidl(LPITEMIDLIST
* apidl
, UINT cidl
)
2321 for (i
= 0; i
< cidl
; i
++)
2327 /*************************************************************************
2330 * copies an aPidl struct
2332 LPITEMIDLIST
* _ILCopyaPidl(const LPCITEMIDLIST
* apidlsrc
, UINT cidl
)
2335 LPITEMIDLIST
*apidldest
;
2337 apidldest
= SHAlloc(cidl
* sizeof(LPITEMIDLIST
));
2341 for (i
= 0; i
< cidl
; i
++)
2342 apidldest
[i
] = ILClone(apidlsrc
[i
]);
2347 /*************************************************************************
2348 * _ILCopyCidaToaPidl
2350 * creates aPidl from CIDA
2352 LPITEMIDLIST
* _ILCopyCidaToaPidl(LPITEMIDLIST
* pidl
, const CIDA
* cida
)
2357 dst
= SHAlloc(cida
->cidl
* sizeof(LPITEMIDLIST
));
2362 *pidl
= ILClone((LPCITEMIDLIST
)(&((const BYTE
*)cida
)[cida
->aoffset
[0]]));
2364 for (i
= 0; i
< cida
->cidl
; i
++)
2365 dst
[i
] = ILClone((LPCITEMIDLIST
)(&((const BYTE
*)cida
)[cida
->aoffset
[i
+ 1]]));
2370 HRESULT WINAPI
SHCreateShellItem(LPCITEMIDLIST pidlParent
,
2371 IShellFolder
*psfParent
, LPCITEMIDLIST pidl
, void **ppsi
)
2373 FIXME("STUB: %p %p %p %p\n",pidlParent
, psfParent
, pidl
, ppsi
);
2374 return E_NOINTERFACE
;