Return OLE automation build value as win2k by default.
[wine] / dlls / shell32 / pidl.c
1 /*
2  *      pidl Handling
3  *
4  *      Copyright 1998  Juergen Schmied
5  *
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.
10  *
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.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  * NOTES
21  *  a pidl == NULL means desktop and is legal
22  *
23  */
24
25 #include "config.h"
26 #include "wine/port.h"
27
28 #include <ctype.h>
29 #include <stdarg.h>
30 #include <stdlib.h>
31 #include <string.h>
32
33 #define COBJMACROS
34 #define NONAMELESSUNION
35 #define NONAMELESSSTRUCT
36
37 #include "windef.h"
38 #include "winbase.h"
39 #include "winreg.h"
40 #include "objbase.h"
41 #include "shlguid.h"
42 #include "winerror.h"
43 #include "winnls.h"
44 #include "undocshell.h"
45 #include "shell32_main.h"
46 #include "shellapi.h"
47 #include "shlwapi.h"
48
49 #include "pidl.h"
50 #include "wine/debug.h"
51
52 WINE_DEFAULT_DEBUG_CHANNEL(pidl);
53 WINE_DECLARE_DEBUG_CHANNEL(shell);
54
55 /* from comctl32.dll */
56 extern LPVOID WINAPI Alloc(INT);
57 extern BOOL WINAPI Free(LPVOID);
58
59 /*************************************************************************
60  * ILGetDisplayNameEx           [SHELL32.186]
61  *
62  * Retrieves the display name of an ItemIDList
63  *
64  * PARAMS
65  *  psf        [I]   Shell Folder to start with, if NULL the desktop is used
66  *  pidl       [I]   ItemIDList relativ to the psf to get the display name for
67  *  path       [O]   Filled in with the display name, assumed to be at least MAX_PATH long
68  *  type       [I]   Type of display name to retrieve
69  *                    0 = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR uses always the desktop as root
70  *                    1 = SHGDN_NORMAL relative to the root folder
71  *                    2 = SHGDN_INFOLDER relative to the root folder, only the last name
72  *
73  * RETURNS
74  *  True if the display name could be retrieved successfully, False otherwise
75  */
76 BOOL WINAPI ILGetDisplayNameExA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPSTR path, DWORD type)
77 {
78         BOOL ret = FALSE;
79         WCHAR wPath[MAX_PATH];
80
81         TRACE("%p %p %p %ld\n", psf, pidl, path, type);
82
83         if (!pidl || !path)
84           return FALSE;
85
86         ret = ILGetDisplayNameExW(psf, pidl, wPath, type);
87         WideCharToMultiByte(CP_ACP, 0, wPath, -1, path, MAX_PATH, NULL, NULL);
88         TRACE("%p %p %s\n", psf, pidl, debugstr_a(path));
89
90         return ret;
91 }
92
93 BOOL WINAPI ILGetDisplayNameExW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPWSTR path, DWORD type)
94 {
95         LPSHELLFOLDER psfParent, lsf = psf;
96         HRESULT ret = NO_ERROR;
97         LPCITEMIDLIST pidllast;
98         STRRET strret;
99         DWORD flag;
100
101         TRACE("%p %p %p %ld\n", psf, pidl, path, type);
102
103         if (!pidl || !path)
104           return FALSE;
105
106         if (!lsf)
107         {
108           ret = SHGetDesktopFolder(&lsf);
109           if (FAILED(ret))
110             return FALSE;
111         }
112
113         if (type >= 0 && type <= 2)
114         {
115           switch (type)
116           {
117             case ILGDN_FORPARSING:
118               flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
119               break;
120             case ILGDN_NORMAL:
121               flag = SHGDN_NORMAL;
122               break;
123             case ILGDN_INFOLDER:
124               flag = SHGDN_INFOLDER;
125               break;
126             default:
127               FIXME("Unknown type parameter = %lx\n", type);
128               flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
129               break;
130           }
131           if (!*(const WORD*)pidl || type == ILGDN_FORPARSING)
132           {
133             ret = IShellFolder_GetDisplayNameOf(lsf, pidl, flag, &strret);
134             if (SUCCEEDED(ret))
135             {
136               ret = StrRetToStrNW(path, MAX_PATH, &strret, pidl);
137             }
138           }
139           else
140           {
141             ret = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psfParent, &pidllast);
142             if (SUCCEEDED(ret))
143             {
144               ret = IShellFolder_GetDisplayNameOf(psfParent, pidllast, flag, &strret);
145               if (SUCCEEDED(ret))
146               {
147                 ret = StrRetToStrNW(path, MAX_PATH, &strret, pidllast);
148               }
149               IShellFolder_Release(psfParent);
150             }
151           }
152         }
153
154         TRACE("%p %p %s\n", psf, pidl, debugstr_w(path));
155
156         if (!psf)
157           IShellFolder_Release(lsf);
158         return SUCCEEDED(ret);
159 }
160
161 BOOL WINAPI ILGetDisplayNameEx(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPVOID path, DWORD type)
162 {
163         TRACE_(shell)("%p %p %p %ld\n", psf, pidl, path, type);
164         if (SHELL_OsIsUnicode())
165           return ILGetDisplayNameExW(psf, pidl, path, type);
166         return ILGetDisplayNameExA(psf, pidl, path, type);
167 }
168
169 /*************************************************************************
170  * ILGetDisplayName                     [SHELL32.15]
171  */
172 BOOL WINAPI ILGetDisplayName(LPCITEMIDLIST pidl, LPVOID path)
173 {
174         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);
178 }
179
180 /*************************************************************************
181  * ILFindLastID [SHELL32.16]
182  *
183  * NOTES
184  *   observed: pidl=Desktop return=pidl
185  */
186 LPITEMIDLIST WINAPI ILFindLastID(LPCITEMIDLIST pidl)
187 {
188         LPCITEMIDLIST   pidlLast = pidl;
189
190         TRACE("(pidl=%p)\n",pidl);
191
192         if (!pidl)
193           return NULL;
194
195         while (pidl->mkid.cb)
196         {
197           pidlLast = pidl;
198           pidl = ILGetNext(pidl);
199         }
200         return (LPITEMIDLIST)pidlLast;
201 }
202 /*************************************************************************
203  * ILRemoveLastID [SHELL32.17]
204  *
205  * NOTES
206  *   when pidl=Desktop return=FALSE
207  */
208 BOOL WINAPI ILRemoveLastID(LPITEMIDLIST pidl)
209 {
210         TRACE_(shell)("pidl=%p\n",pidl);
211
212         if (!pidl || !pidl->mkid.cb)
213           return 0;
214         ILFindLastID(pidl)->mkid.cb = 0;
215         return 1;
216 }
217
218 /*************************************************************************
219  * ILClone [SHELL32.18]
220  *
221  * NOTES
222  *    duplicate an idlist
223  */
224 LPITEMIDLIST WINAPI ILClone (LPCITEMIDLIST pidl)
225 { DWORD    len;
226   LPITEMIDLIST  newpidl;
227
228   if (!pidl)
229     return NULL;
230
231   len = ILGetSize(pidl);
232   newpidl = (LPITEMIDLIST)SHAlloc(len);
233   if (newpidl)
234     memcpy(newpidl,pidl,len);
235
236   TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
237   pdump(pidl);
238
239   return newpidl;
240 }
241 /*************************************************************************
242  * ILCloneFirst [SHELL32.19]
243  *
244  * NOTES
245  *  duplicates the first idlist of a complex pidl
246  */
247 LPITEMIDLIST WINAPI ILCloneFirst(LPCITEMIDLIST pidl)
248 {       DWORD len;
249         LPITEMIDLIST pidlNew = NULL;
250
251         TRACE("pidl=%p \n",pidl);
252         pdump(pidl);
253
254         if (pidl)
255         {
256           len = pidl->mkid.cb;
257           pidlNew = (LPITEMIDLIST) SHAlloc (len+2);
258           if (pidlNew)
259           {
260             memcpy(pidlNew,pidl,len+2);         /* 2 -> mind a desktop pidl */
261
262             if (len)
263               ILGetNext(pidlNew)->mkid.cb = 0x00;
264           }
265         }
266         TRACE("-- newpidl=%p\n",pidlNew);
267
268         return pidlNew;
269 }
270
271 /*************************************************************************
272  * ILLoadFromStream (SHELL32.26)
273  *
274  * NOTES
275  *   the first two bytes are the len, the pidl is following then
276  */
277 HRESULT WINAPI ILLoadFromStream (IStream * pStream, LPITEMIDLIST * ppPidl)
278 {       WORD            wLen = 0;
279         DWORD           dwBytesRead;
280         HRESULT         ret = E_FAIL;
281
282
283         TRACE_(shell)("%p %p\n", pStream ,  ppPidl);
284
285         if (*ppPidl)
286         { SHFree(*ppPidl);
287           *ppPidl = NULL;
288         }
289
290         IStream_AddRef (pStream);
291
292         if (SUCCEEDED(IStream_Read(pStream, (LPVOID)&wLen, 2, &dwBytesRead)))
293         {
294           TRACE("PIDL length is %d\n", wLen);
295           if (wLen != 0) {
296             *ppPidl = SHAlloc (wLen);
297             if (SUCCEEDED(IStream_Read(pStream, *ppPidl , wLen, &dwBytesRead))) {
298                 TRACE("Stream read OK\n");
299                 ret = S_OK;
300             } else {
301                 WARN("reading pidl failed\n");
302                 SHFree(*ppPidl);
303                 *ppPidl = NULL;
304             }
305           } else {
306             *ppPidl = NULL;
307             ret = S_OK;
308           }
309         }
310
311         /* we are not yet fully compatible */
312         if (*ppPidl && !pcheck(*ppPidl))
313         {
314           WARN("Check failed\n");
315           SHFree(*ppPidl);
316           *ppPidl = NULL;
317         }
318
319         
320         IStream_Release (pStream);
321         TRACE("done\n");
322         return ret;
323 }
324
325 /*************************************************************************
326  * ILSaveToStream (SHELL32.27)
327  *
328  * NOTES
329  *   the first two bytes are the len, the pidl is following then
330  */
331 HRESULT WINAPI ILSaveToStream (IStream * pStream, LPCITEMIDLIST pPidl)
332 {
333         LPCITEMIDLIST   pidl;
334         WORD            wLen = 0;
335         HRESULT         ret = E_FAIL;
336
337         TRACE_(shell)("%p %p\n", pStream, pPidl);
338
339         IStream_AddRef (pStream);
340
341         pidl = pPidl;
342         while (pidl->mkid.cb)
343         {
344           wLen += sizeof(WORD) + pidl->mkid.cb;
345           pidl = ILGetNext(pidl);
346         }
347
348         if (SUCCEEDED(IStream_Write(pStream, (LPVOID)&wLen, 2, NULL)))
349         {
350           if (SUCCEEDED(IStream_Write(pStream, pPidl, wLen, NULL)))
351           { ret = S_OK;
352           }
353         }
354         IStream_Release (pStream);
355
356         return ret;
357 }
358
359 /*************************************************************************
360  * SHILCreateFromPath        [SHELL32.28]
361  *
362  * Create an ItemIDList from a path
363  *
364  * PARAMS
365  *  path       [I]
366  *  ppidl      [O]
367  *  attributes [I/O] requested attributes on call and actual attributes when
368  *                   the function returns
369  *
370  * RETURNS
371  *  NO_ERROR if successful, or an OLE errer code otherwise
372  *
373  * NOTES
374  *  Wrapper for IShellFolder_ParseDisplayName().
375  */
376 HRESULT WINAPI SHILCreateFromPathA(LPCSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
377 {
378         LPSHELLFOLDER sf;
379         WCHAR lpszDisplayName[MAX_PATH];
380         DWORD pchEaten;
381         HRESULT ret = E_FAIL;
382
383         TRACE_(shell)("%s %p 0x%08lx\n", path, ppidl, attributes ? *attributes : 0);
384
385         if (!MultiByteToWideChar(CP_ACP, 0, path, -1, lpszDisplayName, MAX_PATH))
386           lpszDisplayName[MAX_PATH-1] = 0;
387
388         if (SUCCEEDED (SHGetDesktopFolder(&sf)))
389         {
390           ret = IShellFolder_ParseDisplayName(sf, 0, NULL, lpszDisplayName, &pchEaten, ppidl, attributes);
391           IShellFolder_Release(sf);
392         }
393         return ret;
394 }
395
396 HRESULT WINAPI SHILCreateFromPathW(LPCWSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
397 {
398         LPSHELLFOLDER sf;
399         DWORD pchEaten;
400         HRESULT ret = E_FAIL;
401
402         TRACE_(shell)("%s %p 0x%08lx\n", debugstr_w(path), ppidl, attributes ? *attributes : 0);
403
404         if (SUCCEEDED (SHGetDesktopFolder(&sf)))
405         {
406           ret = IShellFolder_ParseDisplayName(sf, 0, NULL, (LPWSTR)path, &pchEaten, ppidl, attributes);
407           IShellFolder_Release(sf);
408         }
409         return ret;
410 }
411
412 HRESULT WINAPI SHILCreateFromPathAW (LPCVOID path, LPITEMIDLIST * ppidl, DWORD * attributes)
413 {
414         if ( SHELL_OsIsUnicode())
415           return SHILCreateFromPathW (path, ppidl, attributes);
416         return SHILCreateFromPathA (path, ppidl, attributes);
417 }
418
419 /*************************************************************************
420  * SHCloneSpecialIDList      [SHELL32.89]
421  *
422  * Create an ItemIDList to one of the special folders.
423
424  * PARAMS
425  *  hwndOwner   [in]
426  *  nFolder             [in]    CSIDL_xxxxx
427  *  fCreate             [in]    Create folder if it does not exist
428  *
429  * RETURNS
430  *  Success: The newly created pidl
431  *  Failure: NULL, if inputs are invalid.
432  *
433  * NOTES
434  *  exported by ordinal.
435  *  Caller is responsible for deallocating the returned ItemIDList with the
436  *  shells IMalloc interface, aka ILFree.
437  */
438 LPITEMIDLIST WINAPI SHCloneSpecialIDList(HWND hwndOwner, DWORD nFolder, BOOL fCreate)
439 {       LPITEMIDLIST ppidl;
440         TRACE_(shell)("(hwnd=%p,csidl=0x%lx,%s).\n", hwndOwner, nFolder, fCreate ? "T" : "F");
441
442         if (fCreate)
443           nFolder |= CSIDL_FLAG_CREATE;
444
445         SHGetSpecialFolderLocation(hwndOwner, nFolder, &ppidl);
446         return ppidl;
447 }
448
449 /*************************************************************************
450  * ILGlobalClone             [SHELL32.20]
451  *
452  * Clones an ItemIDList using Alloc.
453  *
454  * PARAMS
455  *  pidl       [I]   ItemIDList to clone
456  *
457  * RETURNS
458  *  Newly allocated ItemIDList.
459  *
460  * NOTES
461  *  exported by ordinal.
462  */
463 LPITEMIDLIST WINAPI ILGlobalClone(LPCITEMIDLIST pidl)
464 {       DWORD    len;
465         LPITEMIDLIST  newpidl;
466
467         if (!pidl)
468           return NULL;
469
470         len = ILGetSize(pidl);
471         newpidl = (LPITEMIDLIST)Alloc(len);
472         if (newpidl)
473           memcpy(newpidl,pidl,len);
474
475         TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
476         pdump(pidl);
477
478         return newpidl;
479 }
480
481 /*************************************************************************
482  * ILIsEqual [SHELL32.21]
483  *
484  */
485 BOOL WINAPI ILIsEqual(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
486 {
487         char    szData1[MAX_PATH];
488         char    szData2[MAX_PATH];
489
490         LPCITEMIDLIST pidltemp1 = pidl1;
491         LPCITEMIDLIST pidltemp2 = pidl2;
492
493         TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
494
495         /* explorer reads from registry directly (StreamMRU),
496            so we can only check here */
497         if ((!pcheck (pidl1)) || (!pcheck (pidl2))) return FALSE;
498
499         pdump (pidl1);
500         pdump (pidl2);
501
502         if ( (!pidl1) || (!pidl2) ) return FALSE;
503
504         while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
505         {
506             _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
507             _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
508
509             if (strcasecmp ( szData1, szData2 )!=0 )
510               return FALSE;
511
512             pidltemp1 = ILGetNext(pidltemp1);
513             pidltemp2 = ILGetNext(pidltemp2);
514         }
515
516         if (!pidltemp1->mkid.cb && !pidltemp2->mkid.cb)
517         {
518           return TRUE;
519         }
520
521         return FALSE;
522 }
523 /*************************************************************************
524  * ILIsParent                [SHELL32.23]
525  *
526  * Verifies that pidlParent is indeed the (immediate) parent of pidlChild.
527  *
528  * PARAMS
529  *  pidlParent [I]
530  *  pidlChild  [I]
531  *  bImmediate [I]   only return true if the parent is the direct parent
532  *                   of the child
533  *
534  * RETURNS
535  *  True if the parent ItemIDlist is a complete part of the child ItemIdList,
536  *  False otherwise.
537  *
538  * NOTES
539  *  parent = a/b, child = a/b/c -> true, c is in folder a/b
540  *  child = a/b/c/d -> false if bImmediate is true, d is not in folder a/b
541  *  child = a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
542  */
543 BOOL WINAPI ILIsParent(LPCITEMIDLIST pidlParent, LPCITEMIDLIST pidlChild, BOOL bImmediate)
544 {
545         char    szData1[MAX_PATH];
546         char    szData2[MAX_PATH];
547
548         LPCITEMIDLIST pParent = pidlParent;
549         LPCITEMIDLIST pChild = pidlChild;
550
551         TRACE("%p %p %x\n", pidlParent, pidlChild, bImmediate);
552
553         if (!pParent || !pChild) return FALSE;
554
555         while (pParent->mkid.cb && pChild->mkid.cb)
556         {
557           _ILSimpleGetText(pParent, szData1, MAX_PATH);
558           _ILSimpleGetText(pChild, szData2, MAX_PATH);
559
560           if (strcasecmp ( szData1, szData2 )!=0 )
561             return FALSE;
562
563           pParent = ILGetNext(pParent);
564           pChild = ILGetNext(pChild);
565         }
566
567         if ( pParent->mkid.cb || ! pChild->mkid.cb) /* child shorter or has equal length to parent */
568           return FALSE;
569
570         if ( ILGetNext(pChild)->mkid.cb && bImmediate) /* not immediate descent */
571           return FALSE;
572
573         return TRUE;
574 }
575
576 /*************************************************************************
577  * ILFindChild               [SHELL32.24]
578  *
579  *  Compares elements from pidl1 and pidl2.
580  *
581  * PARAMS
582  *  pidl1      [I]
583  *  pidl2      [I]
584  *
585  * RETURNS
586  *  pidl1 is desktop      pidl2
587  *  pidl1 shorter pidl2   pointer to first different element of pidl2
588  *                        if there was at least one equal element
589  *  pidl2 shorter pidl1   0
590  *  pidl2 equal pidl1     pointer to last 0x00-element of pidl2
591  *
592  * NOTES
593  *  exported by ordinal.
594  */
595 LPITEMIDLIST WINAPI ILFindChild(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
596 {
597         char    szData1[MAX_PATH];
598         char    szData2[MAX_PATH];
599
600         LPCITEMIDLIST pidltemp1 = pidl1;
601         LPCITEMIDLIST pidltemp2 = pidl2;
602         LPCITEMIDLIST ret=NULL;
603
604         TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
605
606         /* explorer reads from registry directly (StreamMRU),
607            so we can only check here */
608         if ((!pcheck (pidl1)) || (!pcheck (pidl2)))
609           return FALSE;
610
611         pdump (pidl1);
612         pdump (pidl2);
613
614         if ( _ILIsDesktop(pidl1) )
615         {
616           ret = pidl2;
617         }
618         else
619         {
620           while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
621           {
622             _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
623             _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
624
625             if (strcasecmp(szData1,szData2))
626               break;
627
628             pidltemp1 = ILGetNext(pidltemp1);
629             pidltemp2 = ILGetNext(pidltemp2);
630             ret = pidltemp2;
631           }
632
633           if (pidltemp1->mkid.cb)
634           {
635             ret = NULL; /* elements of pidl1 left*/
636           }
637         }
638         TRACE_(shell)("--- %p\n", ret);
639         return (LPITEMIDLIST)ret; /* pidl 1 is shorter */
640 }
641
642 /*************************************************************************
643  * ILCombine                 [SHELL32.25]
644  *
645  * Concatenates two complex ItemIDLists.
646  *
647  * PARAMS
648  *  pidl1      [I]   first complex ItemIDLists
649  *  pidl2      [I]   complex ItemIDLists to append
650  *
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
656  *
657  * NOTES
658  *  exported by ordinal.
659  *  Does not destroy the passed in ItemIDLists!
660  */
661 LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
662 {
663         DWORD    len1,len2;
664         LPITEMIDLIST  pidlNew;
665
666         TRACE("pidl=%p pidl=%p\n",pidl1,pidl2);
667
668         if(!pidl1 && !pidl2) return NULL;
669
670         pdump (pidl1);
671         pdump (pidl2);
672
673         if(!pidl1)
674         {
675           pidlNew = ILClone(pidl2);
676           return pidlNew;
677         }
678
679         if(!pidl2)
680         {
681           pidlNew = ILClone(pidl1);
682           return pidlNew;
683         }
684
685         len1  = ILGetSize(pidl1)-2;
686         len2  = ILGetSize(pidl2);
687         pidlNew  = SHAlloc(len1+len2);
688
689         if (pidlNew)
690         {
691           memcpy(pidlNew,pidl1,len1);
692           memcpy(((BYTE *)pidlNew)+len1,pidl2,len2);
693         }
694
695         /*  TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
696         return pidlNew;
697 }
698
699 /*************************************************************************
700  *  SHGetRealIDL [SHELL32.98]
701  *
702  * NOTES
703  */
704 HRESULT WINAPI SHGetRealIDL(LPSHELLFOLDER lpsf, LPCITEMIDLIST pidlSimple, LPITEMIDLIST *pidlReal)
705 {
706         IDataObject* pDataObj;
707         HRESULT hr = IShellFolder_GetUIObjectOf(lpsf, 0, 1, &pidlSimple, &IID_IDataObject, 0, (LPVOID*)&pDataObj);
708
709         if (SUCCEEDED(hr)) {
710             STGMEDIUM medium;
711             FORMATETC fmt;
712
713             fmt.cfFormat = RegisterClipboardFormatA(CFSTR_SHELLIDLIST);
714             fmt.ptd = NULL;
715             fmt.dwAspect = DVASPECT_CONTENT;
716             fmt.lindex = -1;
717             fmt.tymed = TYMED_HGLOBAL;
718
719             hr = IDataObject_GetData(pDataObj, &fmt, &medium);
720
721             IDataObject_Release(pDataObj);
722
723             if (SUCCEEDED(hr)) {
724                 /*assert(pida->cidl==1);*/
725                 LPIDA pida = (LPIDA)GlobalLock(medium.u.hGlobal);
726
727                 LPCITEMIDLIST pidl_folder = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[0]);
728                 LPCITEMIDLIST pidl_child = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[1]);
729
730                 *pidlReal = ILCombine(pidl_folder, pidl_child);
731
732                 if (!*pidlReal)
733                         hr = E_OUTOFMEMORY;
734
735                 GlobalUnlock(medium.u.hGlobal);
736                 GlobalFree(medium.u.hGlobal);
737             }
738         }
739
740         return hr;
741 }
742
743 /*************************************************************************
744  *  SHLogILFromFSIL [SHELL32.95]
745  *
746  * NOTES
747  *  pild = CSIDL_DESKTOP        ret = 0
748  *  pild = CSIDL_DRIVES         ret = 0
749  */
750 LPITEMIDLIST WINAPI SHLogILFromFSIL(LPITEMIDLIST pidl)
751 {
752         FIXME("(pidl=%p)\n",pidl);
753
754         pdump(pidl);
755
756         return 0;
757 }
758
759 /*************************************************************************
760  * ILGetSize                 [SHELL32.152]
761  *
762  * Gets the byte size of an ItemIDList including zero terminator
763  *
764  * PARAMS
765  *  pidl       [I]   ItemIDList
766  *
767  * RETURNS
768  *  size of pidl in bytes
769  *
770  * NOTES
771  *  exported by ordinal
772  */
773 UINT WINAPI ILGetSize(LPCITEMIDLIST pidl)
774 {
775         LPCSHITEMID si = &(pidl->mkid);
776         UINT len=0;
777
778         if (pidl)
779         { while (si->cb)
780           { len += si->cb;
781             si  = (LPCSHITEMID)(((const BYTE*)si)+si->cb);
782           }
783           len += 2;
784         }
785         TRACE("pidl=%p size=%u\n",pidl, len);
786         return len;
787 }
788
789 /*************************************************************************
790  * ILGetNext                 [SHELL32.153]
791  *
792  * Gets the next ItemID of an ItemIDList
793  *
794  * PARAMS
795  *  pidl       [I]   ItemIDList
796  *
797  * RETURNS
798  *  null -> null
799  *  desktop -> null
800  *  simple pidl -> pointer to 0x0000 element
801  *
802  * NOTES
803  *  exported by ordinal.
804  */
805 LPITEMIDLIST WINAPI ILGetNext(LPCITEMIDLIST pidl)
806 {
807         WORD len;
808
809         TRACE("%p\n", pidl);
810
811         if(pidl)
812         {
813           len =  pidl->mkid.cb;
814           if (len)
815           {
816             pidl = (LPCITEMIDLIST) (((const BYTE*)pidl)+len);
817             TRACE("-- %p\n", pidl);
818             return (LPITEMIDLIST)pidl;
819           }
820         }
821         return NULL;
822 }
823
824 /*************************************************************************
825  * ILAppend                  [SHELL32.154]
826  *
827  * Adds the single ItemID item to the ItemIDList indicated by pidl.
828  * If bEnd is FALSE, inserts the item in the front of the list,
829  * otherwise it adds the item to the end. (???)
830  *
831  * PARAMS
832  *  pidl       [I]   ItemIDList to extend
833  *  item       [I]   ItemID to prepend/append
834  *  bEnd       [I]   Indicates if the item should be appended
835  *
836  * NOTES
837  *  Destroys the passed in idlist! (???)
838  */
839 LPITEMIDLIST WINAPI ILAppend(LPITEMIDLIST pidl, LPCITEMIDLIST item, BOOL bEnd)
840 {
841         LPITEMIDLIST idlRet;
842
843         WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl,item,bEnd);
844
845         pdump (pidl);
846         pdump (item);
847
848         if (_ILIsDesktop(pidl))
849         {
850            idlRet = ILClone(item);
851            if (pidl)
852              SHFree (pidl);
853            return idlRet;
854         }
855
856         if (bEnd)
857         {
858           idlRet = ILCombine(pidl, item);
859         }
860         else
861         {
862           idlRet = ILCombine(item, pidl);
863         }
864
865         SHFree(pidl);
866         return idlRet;
867 }
868
869 /*************************************************************************
870  * ILFree                    [SHELL32.155]
871  *
872  * Frees memory (if not NULL) allocated by SHMalloc allocator
873  *
874  * PARAMS
875  *  pidl         [I]
876  *
877  * NOTES
878  *  exported by ordinal
879  */
880 void WINAPI ILFree(LPITEMIDLIST pidl)
881 {
882         TRACE("(pidl=%p)\n",pidl);
883         if(pidl) SHFree(pidl);
884 }
885
886 /*************************************************************************
887  * ILGlobalFree              [SHELL32.156]
888  *
889  * Frees memory (if not NULL) allocated by Alloc allocator
890  *
891  * PARAMS
892  *  pidl         [I]
893  *
894  * NOTES
895  *  exported by ordinal.
896  */
897 void WINAPI ILGlobalFree( LPITEMIDLIST pidl)
898 {
899         TRACE("%p\n", pidl);
900
901         if(!pidl) return;
902         Free(pidl);
903 }
904
905 /*************************************************************************
906  * ILCreateFromPathA         [SHELL32.189]
907  *
908  * Creates a complex ItemIDList from a path and returns it.
909  *
910  * PARAMS
911  *  path         [I]
912  *
913  * RETURNS
914  *  the newly created complex ItemIDList or NULL if failed
915  *
916  * NOTES
917  *  exported by ordinal.
918  */
919
920 LPITEMIDLIST WINAPI ILCreateFromPathA (LPCSTR path)
921 {
922         LPITEMIDLIST pidlnew = NULL;
923
924         TRACE_(shell)("%s\n", debugstr_a(path));
925
926         if (SUCCEEDED(SHILCreateFromPathA(path, &pidlnew, NULL)))
927           return pidlnew;
928         return NULL;
929 }
930
931 /*************************************************************************
932  * ILCreateFromPathW         [SHELL32.190]
933  */
934 LPITEMIDLIST WINAPI ILCreateFromPathW (LPCWSTR path)
935 {
936         LPITEMIDLIST pidlnew = NULL;
937
938         TRACE_(shell)("%s\n", debugstr_w(path));
939
940         if (SUCCEEDED(SHILCreateFromPathW(path, &pidlnew, NULL)))
941           return pidlnew;
942         return NULL;
943 }
944
945 /*************************************************************************
946  * ILCreateFromPath          [SHELL32.157]
947  */
948 LPITEMIDLIST WINAPI ILCreateFromPathAW (LPCVOID path)
949 {
950         if ( SHELL_OsIsUnicode())
951           return ILCreateFromPathW (path);
952         return ILCreateFromPathA (path);
953 }
954
955 /*************************************************************************
956  * _ILParsePathW             [internal]
957  *
958  * Creates an ItemIDList from a path and returns it.
959  *
960  * PARAMS
961  *  path         [I]   path to parse and convert into an ItemIDList
962  *  lpFindFile   [I]   pointer to buffer to initialize the FileSystem
963  *                     Bind Data object with
964  *  bBindCtx     [I]   indicates to create a BindContext and assign a
965  *                     FileSystem Bind Data object
966  *  ppidl        [O]   the newly create ItemIDList
967  *  prgfInOut    [I/O] requested attributes on input and actual
968  *                     attributes on return
969  *
970  * RETURNS
971  *  NO_ERROR on success or an OLE error code
972  *
973  * NOTES
974  *  If either lpFindFile is non-NULL or bBindCtx is TRUE, this function
975  *  creates a BindContext object and assigns a FileSystem Bind Data object
976  *  to it, passing the BindContext to IShellFolder_ParseDisplayName. Each
977  *  IShellFolder uses that FileSystem Bind Data object of the BindContext
978  *  to pass data about the current path element to the next object. This
979  *  is used to avoid having to verify the current path element on disk, so
980  *  that creating an ItemIDList from a non-existent path still can work.
981  */
982 static HRESULT WINAPI _ILParsePathW(LPCWSTR path, LPWIN32_FIND_DATAW lpFindFile,
983                              BOOL bBindCtx, LPITEMIDLIST *ppidl, LPDWORD prgfInOut)
984 {
985         LPSHELLFOLDER pSF = NULL;
986         LPBC pBC = NULL;
987         HRESULT ret;
988
989         TRACE("%s %p %d (%p)->%p (%p)->0x%lx\n", debugstr_w(path), lpFindFile, bBindCtx,
990                                                  ppidl, ppidl ? *ppidl : NULL,
991                                                  prgfInOut, prgfInOut ? *prgfInOut : 0);
992
993         ret = SHGetDesktopFolder(&pSF);
994         if (FAILED(ret))
995         {
996           return ret;
997         }
998
999         if (lpFindFile || bBindCtx)
1000           ret = IFileSystemBindData_Constructor(lpFindFile, &pBC);
1001
1002         if (SUCCEEDED(ret))
1003         {
1004           ret = IShellFolder_ParseDisplayName(pSF, 0, pBC, (LPOLESTR)path, NULL, ppidl, prgfInOut);
1005         }
1006
1007         if (pBC)
1008         {
1009           IBindCtx_Release(pBC);
1010           pBC = NULL;
1011         }
1012
1013         IShellFolder_Release(pSF);
1014
1015         if (!SUCCEEDED(ret) && ppidl)
1016           *ppidl = NULL;
1017
1018         TRACE("%s %p 0x%lx\n", debugstr_w(path), ppidl ? *ppidl : NULL, prgfInOut ? *prgfInOut : 0);
1019
1020         return ret;
1021 }
1022
1023 /*************************************************************************
1024  * SHSimpleIDListFromPath    [SHELL32.162]
1025  *
1026  * Creates a simple ItemIDList from a path and returns it. This function
1027  * does not fail on non-existent paths.
1028  *
1029  * PARAMS
1030  *  path         [I]   path to parse and convert into an ItemIDList
1031  *
1032  * RETURNS
1033  *  the newly created simple ItemIDList
1034  *
1035  * NOTES
1036  *  Simple in the name does not mean a relative ItemIDList but rather a
1037  *  fully qualified list, where only the file name is filled in and the
1038  *  directory flag for those ItemID elements this is known about, eg.
1039  *  it is not the last element in the ItemIDList or the actual directory
1040  *  exists on disk.
1041  *  exported by ordinal.
1042  */
1043 LPITEMIDLIST WINAPI SHSimpleIDListFromPathA(LPCSTR lpszPath)
1044 {
1045     LPITEMIDLIST pidl = NULL;
1046     LPWSTR wPath = NULL;
1047     int len;
1048
1049     TRACE("%s\n", debugstr_a(lpszPath));
1050
1051     if (lpszPath)
1052     {
1053         len = MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, NULL, 0);
1054         wPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1055         MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, wPath, len);
1056     }
1057
1058     _ILParsePathW(wPath, NULL, TRUE, &pidl, NULL);
1059
1060     HeapFree(GetProcessHeap(), 0, wPath);
1061     TRACE("%s %p\n", debugstr_a(lpszPath), pidl);
1062     return pidl;
1063 }
1064
1065 LPITEMIDLIST WINAPI SHSimpleIDListFromPathW(LPCWSTR lpszPath)
1066 {
1067         LPITEMIDLIST pidl = NULL;
1068
1069         TRACE("%s\n", debugstr_w(lpszPath));
1070
1071         _ILParsePathW(lpszPath, NULL, TRUE, &pidl, NULL);
1072         TRACE("%s %p\n", debugstr_w(lpszPath), pidl);
1073         return pidl;
1074 }
1075
1076 LPITEMIDLIST WINAPI SHSimpleIDListFromPathAW(LPCVOID lpszPath)
1077 {
1078         if ( SHELL_OsIsUnicode())
1079           return SHSimpleIDListFromPathW (lpszPath);
1080         return SHSimpleIDListFromPathA (lpszPath);
1081 }
1082
1083 /*************************************************************************
1084  * SHGetDataFromIDListA [SHELL32.247]
1085  *
1086  * NOTES
1087  *  the pidl can be a simple one. since we can't get the path out of the pidl
1088  *  we have to take all data from the pidl
1089  */
1090 HRESULT WINAPI SHGetDataFromIDListA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, int nFormat, LPVOID dest, int len)
1091 {
1092         TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
1093
1094         pdump(pidl);
1095         if (!psf || !dest )  return E_INVALIDARG;
1096
1097         switch (nFormat)
1098         {
1099           case SHGDFIL_FINDDATA:
1100             {
1101                LPSTR filename, shortname;
1102                WIN32_FIND_DATAA * pfd = dest;
1103
1104                if (_ILIsDrive(pidl))
1105                    return E_INVALIDARG;
1106
1107                if (len < (int)sizeof(WIN32_FIND_DATAA)) return E_INVALIDARG;
1108
1109                ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1110                _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1111                pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1112                pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1113
1114                filename = _ILGetTextPointer(pidl);
1115                shortname = _ILGetSTextPointer(pidl);
1116
1117                if (filename)
1118                    lstrcpynA(pfd->cFileName, filename, MAX_PATH);
1119                else
1120                    pfd->cFileName[0] = '\0';
1121
1122                if (shortname)
1123                    lstrcpynA(pfd->cAlternateFileName, shortname, MAX_PATH);
1124                else
1125                    pfd->cAlternateFileName[0] = '\0';
1126             }
1127             return NOERROR;
1128
1129           case SHGDFIL_NETRESOURCE:
1130           case SHGDFIL_DESCRIPTIONID:
1131             FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1132             break;
1133
1134           default:
1135             ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1136         }
1137
1138         return E_INVALIDARG;
1139 }
1140
1141 /*************************************************************************
1142  * SHGetDataFromIDListW [SHELL32.248]
1143  *
1144  */
1145 HRESULT WINAPI SHGetDataFromIDListW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, int nFormat, LPVOID dest, int len)
1146 {
1147         TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
1148
1149         pdump(pidl);
1150
1151         if (! psf || !dest )  return E_INVALIDARG;
1152
1153         switch (nFormat)
1154         {
1155           case SHGDFIL_FINDDATA:
1156             {
1157                LPSTR filename, shortname;
1158                WIN32_FIND_DATAW * pfd = dest;
1159
1160                if (_ILIsDrive(pidl))
1161                    return E_INVALIDARG;
1162
1163                if (len < (int)sizeof(WIN32_FIND_DATAW)) return E_INVALIDARG;
1164
1165                ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1166                _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1167                pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1168                pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1169
1170                filename = _ILGetTextPointer(pidl);
1171                shortname = _ILGetSTextPointer(pidl);
1172
1173                if (!filename)
1174                    pfd->cFileName[0] = '\0';
1175                else if (!MultiByteToWideChar(CP_ACP, 0, filename, -1, pfd->cFileName, MAX_PATH))
1176                    pfd->cFileName[MAX_PATH-1] = 0;
1177
1178                if (!shortname)
1179                    pfd->cAlternateFileName[0] = '\0';
1180                else if (!MultiByteToWideChar(CP_ACP, 0, shortname, -1, pfd->cAlternateFileName, 14))
1181                    pfd->cAlternateFileName[13] = 0;
1182             }
1183             return NOERROR;
1184           case SHGDFIL_NETRESOURCE:
1185           case SHGDFIL_DESCRIPTIONID:
1186             FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1187             break;
1188
1189           default:
1190             ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1191         }
1192
1193         return E_INVALIDARG;
1194 }
1195
1196 /*************************************************************************
1197  * SHELL_GetPathFromIDListA
1198  */
1199 HRESULT SHELL_GetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath, UINT uOutSize)
1200 {
1201         HRESULT hr = S_OK;
1202
1203         pszPath[0]=0;
1204
1205         /* One case is a PIDL rooted at desktop level */
1206         if (_ILIsValue(pidl) || _ILIsFolder(pidl)) {
1207             hr = SHGetSpecialFolderPathA(0, pszPath, CSIDL_DESKTOP, FALSE);
1208
1209             if (SUCCEEDED(hr))
1210                 PathAddBackslashA(pszPath);
1211         }
1212         /* The only other valid case is a item ID list beginning at "My Computer" */
1213         else if (_ILIsMyComputer(pidl))
1214             pidl = ILGetNext(pidl);
1215
1216         if (SUCCEEDED(hr)) {
1217             LPSTR txt;
1218
1219             while(pidl && pidl->mkid.cb) {
1220                 if (_ILIsSpecialFolder(pidl))
1221                     {hr = E_INVALIDARG; break;}
1222
1223                 txt = _ILGetTextPointer(pidl);
1224                 if (!txt)
1225                     {hr = E_INVALIDARG; break;}
1226
1227                 if (lstrlenA(txt) > pidl->mkid.cb)
1228                     ERR("pidl %p is borked\n",pidl);
1229
1230                 /* make sure there's enough space for the next segment */
1231                 if ( (lstrlenA(txt) + lstrlenA(pszPath)) > uOutSize)
1232                     {hr = E_INVALIDARG; break;}
1233                 lstrcatA( pszPath, txt );
1234
1235                 pidl = ILGetNext(pidl);
1236                 if (!pidl)
1237                     {hr = E_INVALIDARG; break;}
1238
1239                 if (!pidl->mkid.cb) {
1240                     /* We are at the end and successfully converted the complete PIDL. */
1241                     break;
1242                 }
1243
1244                 if( (lstrlenA(pszPath) + 1) > uOutSize)
1245                     {hr = E_INVALIDARG; break;}
1246                 if (!PathAddBackslashA(pszPath))
1247                     {hr = E_INVALIDARG; break;}
1248             }
1249         } else
1250             hr = E_INVALIDARG;
1251
1252         TRACE_(shell)("-- %s, 0x%08lx\n", pszPath, hr);
1253         return hr;
1254 }
1255
1256 /*************************************************************************
1257  * SHGetPathFromIDListA         [SHELL32.@][NT 4.0: SHELL32.220]
1258  *
1259  * PARAMETERS
1260  *  pidl,   [IN] pidl
1261  *  pszPath [OUT] path
1262  *
1263  * RETURNS
1264  *  path from a passed PIDL.
1265  *
1266  * NOTES
1267  *      NULL returns FALSE
1268  *      desktop pidl gives path to desktop directory back
1269  *      special pidls returning FALSE
1270  */
1271 BOOL WINAPI SHGetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath)
1272 {
1273         HRESULT hr;
1274
1275         TRACE_(shell)("(pidl=%p,%p)\n",pidl,pszPath);
1276         pdump(pidl);
1277
1278         if (!pidl)
1279             return FALSE;
1280
1281         hr = SHELL_GetPathFromIDListA(pidl, pszPath, MAX_PATH);
1282
1283         return SUCCEEDED(hr);
1284 }
1285
1286 /*************************************************************************
1287  * SHELL_GetPathFromIDListW
1288  */
1289 HRESULT SHELL_GetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath, UINT uOutSize)
1290 {
1291         HRESULT hr = S_OK;
1292         UINT len;
1293
1294         pszPath[0]=0;
1295
1296         /* One case is a PIDL rooted at desktop level */
1297         if (_ILIsValue(pidl) || _ILIsFolder(pidl)) {
1298             hr = SHGetSpecialFolderPathW(0, pszPath, CSIDL_DESKTOP, FALSE);
1299
1300             if (SUCCEEDED(hr))
1301                 PathAddBackslashW(pszPath);
1302         }
1303         /* The only other valid case is a item ID list beginning at "My Computer" */
1304         else if (_ILIsMyComputer(pidl))
1305             pidl = ILGetNext(pidl);
1306
1307         if (SUCCEEDED(hr)) {
1308             LPSTR txt;
1309
1310             while(pidl && pidl->mkid.cb) {
1311                 if (_ILIsSpecialFolder(pidl))
1312                     {hr = E_INVALIDARG; break;}
1313
1314                 txt = _ILGetTextPointer(pidl);
1315                 if (!txt)
1316                     {hr = E_INVALIDARG; break;}
1317
1318                 if (lstrlenA(txt) > pidl->mkid.cb)
1319                     ERR("pidl %p is borked\n",pidl);
1320                 len = MultiByteToWideChar(CP_ACP, 0, txt, -1, NULL, 0);
1321                 if ( (lstrlenW(pszPath) + len) > uOutSize )
1322                     {hr = E_INVALIDARG; break;}
1323
1324                 MultiByteToWideChar(CP_ACP, 0, txt, -1, 
1325                                     &pszPath[lstrlenW(pszPath)], len);
1326
1327                 pidl = ILGetNext(pidl);
1328                 if (!pidl)
1329                     {hr = E_INVALIDARG; break;}
1330
1331                 if (!pidl->mkid.cb) {
1332                     /* We are at the end and successfully converted the complete PIDL. */
1333                     break;
1334                 }
1335
1336                 if ( (lstrlenW(pszPath) + 1) > uOutSize )
1337                     {hr = E_INVALIDARG; break;}
1338                 if (!PathAddBackslashW(pszPath))
1339                     {hr = E_INVALIDARG; break;}
1340             }
1341         } else
1342             hr = E_INVALIDARG;
1343
1344     TRACE_(shell)("-- %s, 0x%08lx\n", debugstr_w(pszPath), hr);
1345     return hr;
1346 }
1347
1348 /*************************************************************************
1349  * SHGetPathFromIDListW                         [SHELL32.@]
1350  */
1351 BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
1352 {
1353         HRESULT hr;
1354
1355         TRACE_(shell)("(pidl=%p,%p)\n", pidl, debugstr_w(pszPath));
1356         pdump(pidl);
1357
1358         if (!pidl)
1359             return FALSE;
1360
1361         hr = SHELL_GetPathFromIDListW(pidl, pszPath, MAX_PATH);
1362
1363         TRACE_(shell)("-- %s, 0x%08lx\n",debugstr_w(pszPath), hr);
1364         return SUCCEEDED(hr);
1365 }
1366
1367 /*************************************************************************
1368  *      SHBindToParent          [shell version 5.0]
1369  */
1370 HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
1371 {
1372         IShellFolder    * psf;
1373         LPITEMIDLIST    pidlChild, pidlParent;
1374         HRESULT         hr=E_FAIL;
1375
1376         TRACE_(shell)("pidl=%p\n", pidl);
1377         pdump(pidl);
1378
1379         *ppv = NULL;
1380         if (ppidlLast) *ppidlLast = NULL;
1381
1382         if (_ILIsPidlSimple(pidl))
1383         {
1384           IShellFolder* desktop;
1385
1386           /* we are on desktop level */
1387           hr = SHGetDesktopFolder(&desktop);
1388
1389           if (SUCCEEDED(hr))
1390           {
1391             hr = IShellFolder_QueryInterface(desktop, riid, ppv);
1392
1393             if (SUCCEEDED(hr) && ppidlLast)
1394               *ppidlLast = ILClone(pidl);
1395
1396             IShellFolder_Release(desktop);
1397           }
1398         }
1399         else
1400         {
1401           pidlChild =  ILClone(ILFindLastID(pidl));
1402           pidlParent = ILClone(pidl);
1403           ILRemoveLastID(pidlParent);
1404
1405           hr = SHGetDesktopFolder(&psf);
1406
1407           if (SUCCEEDED(hr))
1408             hr = IShellFolder_BindToObject(psf, pidlParent, NULL, riid, ppv);
1409
1410           if (SUCCEEDED(hr) && ppidlLast)
1411             *ppidlLast = pidlChild;
1412           else
1413             ILFree (pidlChild);
1414
1415           SHFree (pidlParent);
1416           if (psf) IShellFolder_Release(psf);
1417         }
1418
1419
1420         TRACE_(shell)("-- psf=%p pidl=%p ret=0x%08lx\n", *ppv, (ppidlLast)?*ppidlLast:NULL, hr);
1421         return hr;
1422 }
1423
1424 /**************************************************************************
1425  *
1426  *              internal functions
1427  *
1428  *      ### 1. section creating pidls ###
1429  *
1430  *************************************************************************
1431  */
1432 LPITEMIDLIST _ILAlloc(PIDLTYPE type, size_t size)
1433 {
1434     LPITEMIDLIST pidlOut = NULL;
1435
1436     if((pidlOut = SHAlloc(size + 5)))
1437     {
1438         LPPIDLDATA pData;
1439         LPITEMIDLIST pidlNext;
1440
1441         ZeroMemory(pidlOut, size + 5);
1442         pidlOut->mkid.cb = size + 3;
1443
1444         if ((pData = _ILGetDataPointer(pidlOut)))
1445             pData->type = type;
1446
1447         if ((pidlNext = ILGetNext(pidlOut)))
1448             pidlNext->mkid.cb = 0x00;
1449         TRACE("-- (pidl=%p, size=%u)\n", pidlOut, size);
1450     }
1451
1452     return pidlOut;
1453 }
1454
1455 LPITEMIDLIST _ILCreateDesktop()
1456 {
1457     LPITEMIDLIST ret;
1458
1459     TRACE("()\n");
1460     ret = SHAlloc(2);
1461     if (ret)
1462         ret->mkid.cb = 0;
1463     return ret;
1464 }
1465
1466 LPITEMIDLIST _ILCreateMyComputer()
1467 {       TRACE("()\n");
1468         return _ILCreateGuid(PT_GUID, &CLSID_MyComputer);
1469 }
1470
1471 LPITEMIDLIST _ILCreateIExplore()
1472 {       TRACE("()\n");
1473         return _ILCreateGuid(PT_GUID, &CLSID_Internet);
1474 }
1475
1476 LPITEMIDLIST _ILCreateControlPanel()
1477 {
1478     LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL;
1479
1480     TRACE("()\n");
1481     if (parent)
1482     {
1483         LPITEMIDLIST cpl = _ILCreateGuid(PT_SHELLEXT, &CLSID_ControlPanel);
1484
1485         if (cpl)
1486         {
1487             ret = ILCombine(parent, cpl);
1488             SHFree(cpl);
1489         }
1490         SHFree(parent);
1491     }
1492     return ret;
1493 }
1494
1495 LPITEMIDLIST _ILCreatePrinters()
1496 {
1497     LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL;
1498
1499     TRACE("()\n");
1500     if (parent)
1501     {
1502         LPITEMIDLIST printers = _ILCreateGuid(PT_YAGUID, &CLSID_Printers);
1503
1504         if (printers)
1505         {
1506             ret = ILCombine(parent, printers);
1507             SHFree(printers);
1508         }
1509         SHFree(parent);
1510     }
1511     return ret;
1512 }
1513
1514 LPITEMIDLIST _ILCreateNetwork()
1515 {       TRACE("()\n");
1516         return _ILCreateGuid(PT_GUID, &CLSID_NetworkPlaces);
1517 }
1518
1519 LPITEMIDLIST _ILCreateBitBucket()
1520 {       TRACE("()\n");
1521         return _ILCreateGuid(PT_GUID, &CLSID_RecycleBin);
1522 }
1523
1524 LPITEMIDLIST _ILCreateGuid(PIDLTYPE type, REFIID guid)
1525 {
1526     LPITEMIDLIST pidlOut;
1527
1528     if (type == PT_SHELLEXT || type == PT_GUID || type == PT_YAGUID)
1529     {
1530         pidlOut = _ILAlloc(type, sizeof(GUIDStruct));
1531         if (pidlOut)
1532         {
1533             LPPIDLDATA pData = _ILGetDataPointer(pidlOut);
1534
1535             memcpy(&(pData->u.guid.guid), guid, sizeof(GUID));
1536             TRACE("-- create GUID-pidl %s\n",
1537              debugstr_guid(&(pData->u.guid.guid)));
1538         }
1539     }
1540     else
1541     {
1542         WARN("%d: invalid type for GUID\n", type);
1543         pidlOut = NULL;
1544     }
1545     return pidlOut;
1546 }
1547
1548 LPITEMIDLIST _ILCreateGuidFromStrA(LPCSTR szGUID)
1549 {
1550         IID iid;
1551
1552         if (!SUCCEEDED(SHCLSIDFromStringA(szGUID, &iid)))
1553         {
1554           ERR("%s is not a GUID\n", szGUID);
1555           return NULL;
1556         }
1557         return _ILCreateGuid(PT_GUID, &iid);
1558 }
1559
1560 LPITEMIDLIST _ILCreateFromFindDataA(WIN32_FIND_DATAA * stffile )
1561 {
1562     char        buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1563     char *      pbuff = buff;
1564     size_t      len, len1;
1565     LPITEMIDLIST pidl;
1566     PIDLTYPE type;
1567
1568     if (!stffile)
1569         return NULL;
1570
1571     TRACE("(%s, %s)\n",stffile->cAlternateFileName, stffile->cFileName);
1572
1573     /* prepare buffer with both names */
1574     len = strlen (stffile->cFileName) + 1;
1575     memcpy (pbuff, stffile->cFileName, len);
1576     pbuff += len;
1577
1578     len1 = strlen (stffile->cAlternateFileName)+1;
1579     memcpy (pbuff, stffile->cAlternateFileName, len1);
1580
1581     type = (stffile->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? PT_FOLDER : 
1582      PT_VALUE;
1583     /* FileStruct already has one byte for the first name, so use len - 1 in
1584      * size calculation
1585      */
1586     if ((pidl = _ILAlloc(type, sizeof(FileStruct) + (len - 1) + len1)))
1587     {
1588         LPPIDLDATA pData;
1589         LPSTR pszDest;
1590
1591         /* set attributes */
1592         if ((pData = _ILGetDataPointer(pidl)))
1593         {
1594             pData->type = type;
1595             FileTimeToDosDateTime(&(stffile->ftLastWriteTime),&pData->u.file.uFileDate,&pData->u.file.uFileTime);
1596             pData->u.file.dwFileSize = stffile->nFileSizeLow;
1597             pData->u.file.uFileAttribs = (WORD)stffile->dwFileAttributes;
1598         }
1599         if ((pszDest = _ILGetTextPointer(pidl)))
1600         {
1601             memcpy(pszDest, buff, len + len1);
1602             TRACE("-- create Value: %s\n",debugstr_a(pszDest));
1603         }
1604     }
1605     return pidl;
1606 }
1607
1608 HRESULT _ILCreateFromPathA(LPCSTR szPath, LPITEMIDLIST* ppidl)
1609 {
1610         HANDLE hFile;
1611         WIN32_FIND_DATAA stffile;
1612
1613     if (!ppidl)
1614         return E_INVALIDARG;
1615
1616         hFile = FindFirstFileA(szPath, &stffile);
1617
1618         if (hFile == INVALID_HANDLE_VALUE)
1619                 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
1620
1621         FindClose(hFile);
1622
1623         *ppidl = _ILCreateFromFindDataA(&stffile);
1624
1625         return *ppidl ? S_OK : E_OUTOFMEMORY;
1626 }
1627
1628 LPITEMIDLIST _ILCreateDrive(LPCWSTR lpszNew)
1629 {
1630     WCHAR sTemp[4];
1631     LPITEMIDLIST pidlOut;
1632
1633     sTemp[0]=toupperW(lpszNew[0]);
1634     sTemp[1]=':';
1635     sTemp[2]='\\';
1636     sTemp[3]=0x00;
1637     TRACE("(%s)\n",debugstr_w(sTemp));
1638
1639     if ((pidlOut = _ILAlloc(PT_DRIVE, sizeof(DriveStruct))))
1640     {
1641         LPSTR pszDest;
1642
1643         if ((pszDest = _ILGetTextPointer(pidlOut)))
1644         {
1645             WideCharToMultiByte(CP_ACP, 0, sTemp, sizeof(sTemp)/sizeof(WCHAR), pszDest, sizeof(sTemp)/sizeof(WCHAR), NULL, NULL);
1646             TRACE("-- create Drive: %s\n", debugstr_a(pszDest));
1647         }
1648     }
1649     return pidlOut;
1650 }
1651
1652 /**************************************************************************
1653  *  _ILGetDrive()
1654  *
1655  *  Gets the text for the drive eg. 'c:\'
1656  *
1657  * RETURNS
1658  *  strlen (lpszText)
1659  */
1660 DWORD _ILGetDrive(LPCITEMIDLIST pidl,LPSTR pOut, UINT uSize)
1661 {       TRACE("(%p,%p,%u)\n",pidl,pOut,uSize);
1662
1663         if(_ILIsMyComputer(pidl))
1664           pidl = ILGetNext(pidl);
1665
1666         if (pidl && _ILIsDrive(pidl))
1667           return _ILSimpleGetText(pidl, pOut, uSize);
1668
1669         return 0;
1670 }
1671
1672 /**************************************************************************
1673  *
1674  *      ### 2. section testing pidls ###
1675  *
1676  **************************************************************************
1677  *  _ILIsDesktop()
1678  *  _ILIsMyComputer()
1679  *  _ILIsSpecialFolder()
1680  *  _ILIsDrive()
1681  *  _ILIsFolder()
1682  *  _ILIsValue()
1683  *  _ILIsPidlSimple()
1684  */
1685 BOOL _ILIsDesktop(LPCITEMIDLIST pidl)
1686 {       TRACE("(%p)\n",pidl);
1687         return pidl && pidl->mkid.cb  ? 0 : 1;
1688 }
1689
1690 BOOL _ILIsMyComputer(LPCITEMIDLIST pidl)
1691 {
1692         REFIID iid = _ILGetGUIDPointer(pidl);
1693
1694         TRACE("(%p)\n",pidl);
1695
1696         if (iid)
1697           return IsEqualIID(iid, &CLSID_MyComputer);
1698         return FALSE;
1699 }
1700
1701 BOOL _ILIsSpecialFolder (LPCITEMIDLIST pidl)
1702 {
1703         LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1704         TRACE("(%p)\n",pidl);
1705         return (pidl && ( (lpPData && (PT_GUID== lpPData->type || PT_SHELLEXT== lpPData->type)) ||
1706                           (pidl && pidl->mkid.cb == 0x00)
1707                         ));
1708 }
1709
1710 BOOL _ILIsDrive(LPCITEMIDLIST pidl)
1711 {       LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1712         TRACE("(%p)\n",pidl);
1713         return (pidl && lpPData && (PT_DRIVE == lpPData->type ||
1714                                     PT_DRIVE1 == lpPData->type ||
1715                                     PT_DRIVE2 == lpPData->type ||
1716                                     PT_DRIVE3 == lpPData->type));
1717 }
1718
1719 BOOL _ILIsFolder(LPCITEMIDLIST pidl)
1720 {       LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1721         TRACE("(%p)\n",pidl);
1722         return (pidl && lpPData && (PT_FOLDER == lpPData->type || PT_FOLDER1 == lpPData->type));
1723 }
1724
1725 BOOL _ILIsValue(LPCITEMIDLIST pidl)
1726 {       LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1727         TRACE("(%p)\n",pidl);
1728         return (pidl && lpPData && PT_VALUE == lpPData->type);
1729 }
1730
1731 BOOL _ILIsCPanelStruct(LPCITEMIDLIST pidl)
1732 {       LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1733         TRACE("(%p)\n",pidl);
1734         return (pidl && lpPData && (lpPData->type == 0));
1735 }
1736
1737 /**************************************************************************
1738  *      _ILIsPidlSimple
1739  */
1740 BOOL _ILIsPidlSimple ( LPCITEMIDLIST pidl)
1741 {
1742         BOOL ret = TRUE;
1743
1744         if(! _ILIsDesktop(pidl))        /* pidl=NULL or mkid.cb=0 */
1745         {
1746           WORD len = pidl->mkid.cb;
1747           LPCITEMIDLIST pidlnext = (LPCITEMIDLIST) (((const BYTE*)pidl) + len );
1748           if (pidlnext->mkid.cb)
1749             ret = FALSE;
1750         }
1751
1752         TRACE("%s\n", ret ? "Yes" : "No");
1753         return ret;
1754 }
1755
1756 /**************************************************************************
1757  *
1758  *      ### 3. section getting values from pidls ###
1759  */
1760
1761  /**************************************************************************
1762  *  _ILSimpleGetText
1763  *
1764  * gets the text for the first item in the pidl (eg. simple pidl)
1765  *
1766  * returns the length of the string
1767  */
1768 DWORD _ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
1769 {
1770         DWORD           dwReturn=0;
1771         LPSTR           szSrc;
1772         GUID const *    riid;
1773         char szTemp[MAX_PATH];
1774
1775         TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1776
1777         if (!pidl) return 0;
1778
1779         if (szOut)
1780           *szOut = 0;
1781
1782         if (_ILIsDesktop(pidl))
1783         {
1784          /* desktop */
1785           if (HCR_GetClassNameA(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1786           {
1787             if (szOut)
1788               lstrcpynA(szOut, szTemp, uOutSize);
1789
1790             dwReturn = strlen (szTemp);
1791           }
1792         }
1793         else if (( szSrc = _ILGetTextPointer(pidl) ))
1794         {
1795           /* filesystem */
1796           if (szOut)
1797             lstrcpynA(szOut, szSrc, uOutSize);
1798
1799           dwReturn = strlen(szSrc);
1800         }
1801         else if (( riid = _ILGetGUIDPointer(pidl) ))
1802         {
1803           /* special folder */
1804           if ( HCR_GetClassNameA(riid, szTemp, MAX_PATH) )
1805           {
1806             if (szOut)
1807               lstrcpynA(szOut, szTemp, uOutSize);
1808
1809             dwReturn = strlen (szTemp);
1810           }
1811         }
1812         else
1813         {
1814           ERR("-- no text\n");
1815         }
1816
1817         TRACE("-- (%p=%s 0x%08lx)\n",szOut,debugstr_a(szOut),dwReturn);
1818         return dwReturn;
1819 }
1820
1821  /**************************************************************************
1822  *  _ILSimpleGetTextW
1823  *
1824  * gets the text for the first item in the pidl (eg. simple pidl)
1825  *
1826  * returns the length of the string
1827  */
1828 DWORD _ILSimpleGetTextW (LPCITEMIDLIST pidl, LPWSTR szOut, UINT uOutSize)
1829 {
1830         DWORD   dwReturn;
1831         char    szTemp[MAX_PATH];
1832
1833         TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1834
1835         dwReturn = _ILSimpleGetText(pidl, szTemp, uOutSize);
1836
1837         if (!MultiByteToWideChar(CP_ACP, 0, szTemp, -1, szOut, MAX_PATH))
1838                 *szOut = 0;
1839
1840         TRACE("-- (%p=%s 0x%08lx)\n",szOut,debugstr_w(szOut),dwReturn);
1841         return dwReturn;
1842 }
1843
1844 /**************************************************************************
1845  *
1846  *      ### 4. getting pointers to parts of pidls ###
1847  *
1848  **************************************************************************
1849  *  _ILGetDataPointer()
1850  */
1851 LPPIDLDATA _ILGetDataPointer(LPCITEMIDLIST pidl)
1852 {
1853         if(pidl && pidl->mkid.cb != 0x00)
1854           return (LPPIDLDATA) &(pidl->mkid.abID);
1855         return NULL;
1856 }
1857
1858 /**************************************************************************
1859  *  _ILGetTextPointer()
1860  * gets a pointer to the long filename string stored in the pidl
1861  */
1862 LPSTR _ILGetTextPointer(LPCITEMIDLIST pidl)
1863 {/*     TRACE(pidl,"(pidl%p)\n", pidl);*/
1864
1865         LPPIDLDATA pdata = _ILGetDataPointer(pidl);
1866
1867         if (pdata)
1868         {
1869           switch (pdata->type)
1870           {
1871             case PT_GUID:
1872             case PT_SHELLEXT:
1873             case PT_YAGUID:
1874               return NULL;
1875
1876             case PT_DRIVE:
1877             case PT_DRIVE1:
1878             case PT_DRIVE2:
1879             case PT_DRIVE3:
1880               return (LPSTR)&(pdata->u.drive.szDriveName);
1881
1882             case PT_FOLDER:
1883             case PT_FOLDER1:
1884             case PT_VALUE:
1885             case PT_IESPECIAL1:
1886             case PT_IESPECIAL2:
1887               return (LPSTR)&(pdata->u.file.szNames);
1888
1889             case PT_WORKGRP:
1890             case PT_COMP:
1891             case PT_NETWORK:
1892             case PT_NETPROVIDER:
1893             case PT_SHARE:
1894               return (LPSTR)&(pdata->u.network.szNames);
1895           }
1896         }
1897         return NULL;
1898 }
1899
1900 /**************************************************************************
1901  *  _ILGetSTextPointer()
1902  * gets a pointer to the short filename string stored in the pidl
1903  */
1904 LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl)
1905 {/*     TRACE(pidl,"(pidl%p)\n", pidl);*/
1906
1907         LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1908
1909         if (pdata)
1910         {
1911           switch (pdata->type)
1912           {
1913             case PT_FOLDER:
1914             case PT_VALUE:
1915             case PT_IESPECIAL1:
1916             case PT_IESPECIAL2:
1917               return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1);
1918
1919             case PT_WORKGRP:
1920               return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1);
1921           }
1922         }
1923         return NULL;
1924 }
1925
1926 /**************************************************************************
1927  * _ILGetGUIDPointer()
1928  *
1929  * returns reference to guid stored in some pidls
1930  */
1931 IID* _ILGetGUIDPointer(LPCITEMIDLIST pidl)
1932 {
1933         LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1934
1935         TRACE("%p\n", pidl);
1936
1937         if (pdata)
1938         {
1939           TRACE("pdata->type 0x%04x\n", pdata->type);
1940           switch (pdata->type)
1941           {
1942             case PT_SHELLEXT:
1943             case PT_GUID:
1944               return &(pdata->u.guid.guid);
1945
1946             default:
1947                 TRACE("Unknown pidl type 0x%04x\n", pdata->type);
1948                 break;
1949           }
1950         }
1951         return NULL;
1952 }
1953
1954 /*************************************************************************
1955  * _ILGetFileDateTime
1956  *
1957  * Given the ItemIdList, get the FileTime
1958  *
1959  * PARAMS
1960  *      pidl        [I] The ItemIDList
1961  *      pFt         [I] the resulted FILETIME of the file
1962  *
1963  * RETURNS
1964  *     True if Successful
1965  *
1966  * NOTES
1967  *
1968  */
1969 BOOL _ILGetFileDateTime(LPCITEMIDLIST pidl, FILETIME *pFt)
1970 {
1971     LPPIDLDATA pdata = _ILGetDataPointer(pidl);
1972
1973     if(! pdata) return FALSE;
1974
1975     switch (pdata->type)
1976     {
1977         case PT_FOLDER:
1978         case PT_VALUE:
1979             DosDateTimeToFileTime(pdata->u.file.uFileDate, pdata->u.file.uFileTime, pFt);
1980             break;
1981         default:
1982             return FALSE;
1983     }
1984     return TRUE;
1985 }
1986
1987 BOOL _ILGetFileDate (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1988 {
1989         FILETIME ft,lft;
1990         SYSTEMTIME time;
1991         BOOL ret;
1992
1993         if (_ILGetFileDateTime( pidl, &ft )) {
1994             FileTimeToLocalFileTime(&ft, &lft);
1995             FileTimeToSystemTime (&lft, &time);
1996             ret = GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&time, NULL,  pOut, uOutSize);
1997         } else {
1998             pOut[0] = '\0';
1999             ret = FALSE;
2000         }
2001         return ret;
2002
2003 }
2004
2005 /*************************************************************************
2006  * _ILGetFileSize
2007  *
2008  * Given the ItemIdList, get the FileSize
2009  *
2010  * PARAMS
2011  *      pidl    [I] The ItemIDList
2012  *      pOut    [I] The buffer to save the result
2013  *      uOutsize [I] The size of the buffer
2014  *
2015  * RETURNS
2016  *     The FileSize
2017  *
2018  * NOTES
2019  *      pOut can be null when no string is needed
2020  *
2021  */
2022 DWORD _ILGetFileSize (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2023 {
2024         LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2025         DWORD dwSize;
2026
2027         if(! pdata) return 0;
2028
2029         switch (pdata->type)
2030         {
2031           case PT_VALUE:
2032             dwSize = pdata->u.file.dwFileSize;
2033             if (pOut) StrFormatByteSizeA(dwSize, pOut, uOutSize);
2034             return dwSize;
2035         }
2036         if (pOut) *pOut = 0x00;
2037         return 0;
2038 }
2039
2040 BOOL _ILGetExtension (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2041 {
2042         char szTemp[MAX_PATH];
2043         const char * pPoint;
2044         LPCITEMIDLIST  pidlTemp=pidl;
2045
2046         TRACE("pidl=%p\n",pidl);
2047
2048         if (!pidl) return FALSE;
2049
2050         pidlTemp = ILFindLastID(pidl);
2051
2052         if (!_ILIsValue(pidlTemp)) return FALSE;
2053         if (!_ILSimpleGetText(pidlTemp, szTemp, MAX_PATH)) return FALSE;
2054
2055         pPoint = PathFindExtensionA(szTemp);
2056
2057         if (! *pPoint) return FALSE;
2058
2059         pPoint++;
2060         lstrcpynA(pOut, pPoint, uOutSize);
2061         TRACE("%s\n",pOut);
2062
2063         return TRUE;
2064 }
2065
2066 /*************************************************************************
2067  * _ILGetFileType
2068  *
2069  * Given the ItemIdList, get the file type description
2070  *
2071  * PARAMS
2072  *      pidl        [I] The ItemIDList (simple)
2073  *      pOut        [I] The buffer to save the result
2074  *      uOutsize    [I] The size of the buffer
2075  *
2076  * RETURNS
2077  *      nothing
2078  *
2079  * NOTES
2080  *      This function copies as much as possible into the buffer.
2081  */
2082 void _ILGetFileType(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2083 {
2084         if(_ILIsValue(pidl))
2085         {
2086           char sTemp[64];
2087           if(uOutSize > 0)
2088           {
2089             pOut[0] = 0;
2090           }
2091           if (_ILGetExtension (pidl, sTemp, 64))
2092           {
2093             if (!( HCR_MapTypeToValueA(sTemp, sTemp, 64, TRUE)
2094                 && HCR_MapTypeToValueA(sTemp, pOut, uOutSize, FALSE )))
2095             {
2096               lstrcpynA (pOut, sTemp, uOutSize - 6);
2097               strcat (pOut, "-file");
2098             }
2099           }
2100         }
2101         else
2102         {
2103           lstrcpynA(pOut, "Folder", uOutSize);
2104         }
2105 }
2106
2107 /*************************************************************************
2108  * _ILGetFileAttributes
2109  *
2110  * Given the ItemIdList, get the Attrib string format
2111  *
2112  * PARAMS
2113  *      pidl        [I] The ItemIDList
2114  *      pOut        [I] The buffer to save the result
2115  *      uOutsize    [I] The size of the Buffer
2116  *
2117  * RETURNS
2118  *     Attributes
2119  *
2120  * FIXME
2121  *  return value 0 in case of error is a valid return value
2122  *
2123  */
2124 DWORD _ILGetFileAttributes(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2125 {
2126         LPPIDLDATA pData = _ILGetDataPointer(pidl);
2127         WORD wAttrib = 0;
2128         int i;
2129
2130         if(! pData) return 0;
2131
2132         switch(pData->type)
2133         {
2134           case PT_FOLDER:
2135           case PT_VALUE:
2136             wAttrib = pData->u.file.uFileAttribs;
2137             break;
2138         }
2139
2140         if(uOutSize >= 6)
2141         {
2142           i=0;
2143           if(wAttrib & FILE_ATTRIBUTE_READONLY)
2144           {
2145             pOut[i++] = 'R';
2146           }
2147           if(wAttrib & FILE_ATTRIBUTE_HIDDEN)
2148           {
2149             pOut[i++] = 'H';
2150           }
2151           if(wAttrib & FILE_ATTRIBUTE_SYSTEM)
2152           {
2153             pOut[i++] = 'S';
2154           }
2155           if(wAttrib & FILE_ATTRIBUTE_ARCHIVE)
2156           {
2157             pOut[i++] = 'A';
2158           }
2159           if(wAttrib & FILE_ATTRIBUTE_COMPRESSED)
2160           {
2161             pOut[i++] = 'C';
2162           }
2163           pOut[i] = 0x00;
2164         }
2165         return wAttrib;
2166 }
2167
2168 /*************************************************************************
2169 * ILFreeaPidl
2170 *
2171 * free a aPidl struct
2172 */
2173 void _ILFreeaPidl(LPITEMIDLIST * apidl, UINT cidl)
2174 {
2175         UINT   i;
2176
2177         if (apidl)
2178         {
2179           for (i = 0; i < cidl; i++) SHFree(apidl[i]);
2180           SHFree(apidl);
2181         }
2182 }
2183
2184 /*************************************************************************
2185 * ILCopyaPidl
2186 *
2187 * copies an aPidl struct
2188 */
2189 LPITEMIDLIST* _ILCopyaPidl(LPCITEMIDLIST * apidlsrc, UINT cidl)
2190 {
2191         UINT i;
2192         LPITEMIDLIST * apidldest = (LPITEMIDLIST*)SHAlloc(cidl * sizeof(LPITEMIDLIST));
2193         if(!apidlsrc) return NULL;
2194
2195         for (i = 0; i < cidl; i++)
2196           apidldest[i] = ILClone(apidlsrc[i]);
2197
2198         return apidldest;
2199 }
2200
2201 /*************************************************************************
2202 * _ILCopyCidaToaPidl
2203 *
2204 * creates aPidl from CIDA
2205 */
2206 LPITEMIDLIST* _ILCopyCidaToaPidl(LPITEMIDLIST* pidl, LPIDA cida)
2207 {
2208         UINT i;
2209         LPITEMIDLIST * dst = (LPITEMIDLIST*)SHAlloc(cida->cidl * sizeof(LPITEMIDLIST));
2210
2211         if(!dst) return NULL;
2212
2213         if (pidl)
2214           *pidl = ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[0]]));
2215
2216         for (i = 0; i < cida->cidl; i++)
2217           dst[i] = ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[i + 1]]));
2218
2219         return dst;
2220 }