Fix segmentation fault caused by incorrect referencing of client audio
[wine] / dlls / shell32 / shfldr_mycomp.c
1 /*
2  *    Virtual Workplace folder
3  *
4  *    Copyright 1997            Marcus Meissner
5  *    Copyright 1998, 1999, 2002    Juergen Schmied
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include "config.h"
23 #include "wine/port.h"
24
25 #include <stdlib.h>
26 #include <string.h>
27 #include <stdarg.h>
28 #include <stdio.h>
29
30 #define COBJMACROS
31 #define NONAMELESSUNION
32 #define NONAMELESSSTRUCT
33
34 #include "winerror.h"
35 #include "windef.h"
36 #include "winbase.h"
37 #include "winreg.h"
38
39 #include "wingdi.h"
40 #include "pidl.h"
41 #include "shlguid.h"
42 #include "enumidlist.h"
43 #include "undocshell.h"
44 #include "shell32_main.h"
45 #include "shresdef.h"
46 #include "shlwapi.h"
47 #include "wine/debug.h"
48 #include "debughlp.h"
49 #include "shfldr.h"
50
51 WINE_DEFAULT_DEBUG_CHANNEL (shell);
52
53 /***********************************************************************
54 *   IShellFolder implementation
55 */
56
57 typedef struct {
58     IShellFolder2Vtbl   *lpVtbl;
59     DWORD                ref;
60     IPersistFolder2Vtbl *lpVtblPersistFolder2;
61
62     /* both paths are parsible from the desktop */
63     LPITEMIDLIST pidlRoot;    /* absolute pidl */
64     int dwAttributes;        /* attributes returned by GetAttributesOf FIXME: use it */
65 } IGenericSFImpl;
66
67 static struct IShellFolder2Vtbl vt_ShellFolder2;
68 static struct IPersistFolder2Vtbl vt_PersistFolder2;
69
70 #define _IPersistFolder2_Offset ((int)(&(((IGenericSFImpl*)0)->lpVtblPersistFolder2)))
71 #define _ICOM_THIS_From_IPersistFolder2(class, name) class* This = (class*)(((char*)name)-_IPersistFolder2_Offset);
72
73 /*
74   converts This to an interface pointer
75 */
76 #define _IUnknown_(This)    (IUnknown*)&(This->lpVtbl)
77 #define _IShellFolder_(This)    (IShellFolder*)&(This->lpVtbl)
78 #define _IShellFolder2_(This)    (IShellFolder2*)&(This->lpVtbl)
79
80 #define _IPersist_(This)    (IPersist*)&(This->lpVtblPersistFolder2)
81 #define _IPersistFolder_(This)    (IPersistFolder*)&(This->lpVtblPersistFolder2)
82 #define _IPersistFolder2_(This)    (IPersistFolder2*)&(This->lpVtblPersistFolder2)
83
84 /***********************************************************************
85 *   IShellFolder [MyComputer] implementation
86 */
87
88 static shvheader MyComputerSFHeader[] = {
89     {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
90     {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
91     {IDS_SHV_COLUMN6, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
92     {IDS_SHV_COLUMN7, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
93 };
94
95 #define MYCOMPUTERSHELLVIEWCOLUMNS 4
96
97 /**************************************************************************
98 *    ISF_MyComputer_Constructor
99 */
100 HRESULT WINAPI ISF_MyComputer_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
101 {
102     IGenericSFImpl *sf;
103
104     TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
105
106     if (!ppv)
107         return E_POINTER;
108     if (pUnkOuter)
109         return CLASS_E_NOAGGREGATION;
110
111     sf = LocalAlloc (LMEM_ZEROINIT, sizeof (IGenericSFImpl));
112     if (!sf)
113         return E_OUTOFMEMORY;
114
115     sf->ref = 0;
116     sf->lpVtbl = &vt_ShellFolder2;
117     sf->lpVtblPersistFolder2 = &vt_PersistFolder2;
118     sf->pidlRoot = _ILCreateMyComputer ();    /* my qualified pidl */
119
120     if (!SUCCEEDED (IUnknown_QueryInterface (_IUnknown_ (sf), riid, ppv)))
121     {
122         IUnknown_Release (_IUnknown_ (sf));
123         return E_NOINTERFACE;
124     }
125
126     TRACE ("--(%p)\n", sf);
127     return S_OK;
128 }
129
130 /**************************************************************************
131  *    ISF_MyComputer_fnQueryInterface
132  *
133  * NOTES supports not IPersist/IPersistFolder
134  */
135 static HRESULT WINAPI ISF_MyComputer_fnQueryInterface (IShellFolder2 *iface,
136                REFIID riid, LPVOID *ppvObj)
137 {
138     IGenericSFImpl *This = (IGenericSFImpl *)iface;
139
140     TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
141
142     *ppvObj = NULL;
143
144     if (IsEqualIID (riid, &IID_IUnknown) ||
145         IsEqualIID (riid, &IID_IShellFolder) ||
146         IsEqualIID (riid, &IID_IShellFolder2))
147     {
148         *ppvObj = This;
149     }
150     else if (IsEqualIID (riid, &IID_IPersist) ||
151              IsEqualIID (riid, &IID_IPersistFolder) ||
152              IsEqualIID (riid, &IID_IPersistFolder2))
153     {
154         *ppvObj = _IPersistFolder2_ (This);
155     }
156
157     if (*ppvObj)
158     {
159         IUnknown_AddRef ((IUnknown *) (*ppvObj));
160         TRACE ("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
161         return S_OK;
162     }
163     TRACE ("-- Interface: E_NOINTERFACE\n");
164     return E_NOINTERFACE;
165 }
166
167 static ULONG WINAPI ISF_MyComputer_fnAddRef (IShellFolder2 * iface)
168 {
169     IGenericSFImpl *This = (IGenericSFImpl *)iface;
170     ULONG refCount = InterlockedIncrement(&This->ref);
171
172     TRACE ("(%p)->(count=%lu)\n", This, refCount - 1);
173
174     return refCount;
175 }
176
177 static ULONG WINAPI ISF_MyComputer_fnRelease (IShellFolder2 * iface)
178 {
179     IGenericSFImpl *This = (IGenericSFImpl *)iface;
180     ULONG refCount = InterlockedDecrement(&This->ref);
181
182     TRACE ("(%p)->(count=%lu)\n", This, refCount + 1);
183
184     if (!refCount)
185     {
186         TRACE ("-- destroying IShellFolder(%p)\n", This);
187         if (This->pidlRoot)
188             SHFree (This->pidlRoot);
189         LocalFree ((HLOCAL) This);
190     }
191     return refCount;
192 }
193
194 /**************************************************************************
195 *    ISF_MyComputer_fnParseDisplayName
196 */
197 static HRESULT WINAPI ISF_MyComputer_fnParseDisplayName (IShellFolder2 *iface,
198                HWND hwndOwner, LPBC pbc, LPOLESTR lpszDisplayName,
199                DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
200 {
201     IGenericSFImpl *This = (IGenericSFImpl *)iface;
202     HRESULT hr = E_INVALIDARG;
203     LPCWSTR szNext = NULL;
204     WCHAR szElement[MAX_PATH];
205     LPITEMIDLIST pidlTemp = NULL;
206     CLSID clsid;
207
208     TRACE("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n", This,
209           hwndOwner, pbc, lpszDisplayName, debugstr_w (lpszDisplayName),
210           pchEaten, ppidl, pdwAttributes);
211
212     *ppidl = 0;
213     if (pchEaten)
214         *pchEaten = 0;        /* strange but like the original */
215
216     /* handle CLSID paths */
217     if (lpszDisplayName[0] == ':' && lpszDisplayName[1] == ':')
218     {
219         szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
220         TRACE ("-- element: %s\n", debugstr_w (szElement));
221         SHCLSIDFromStringW (szElement + 2, &clsid);
222         pidlTemp = _ILCreateGuid (PT_GUID, &clsid);
223     }
224     /* do we have an absolute path name ? */
225     else if (PathGetDriveNumberW (lpszDisplayName) >= 0 &&
226               lpszDisplayName[2] == (WCHAR) '\\')
227     {
228         szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
229         /* make drive letter uppercase to enable PIDL comparison */
230         szElement[0] = toupper(szElement[0]);
231         pidlTemp = _ILCreateDrive (szElement);
232     }
233
234     if (szNext && *szNext)
235     {
236         hr = SHELL32_ParseNextElement (iface, hwndOwner, pbc, &pidlTemp,
237                               (LPOLESTR) szNext, pchEaten, pdwAttributes);
238     }
239     else
240     {
241         if (pdwAttributes && *pdwAttributes)
242             SHELL32_GetItemAttributes (_IShellFolder_ (This),
243                                        pidlTemp, pdwAttributes);
244         hr = S_OK;
245     }
246
247     *ppidl = pidlTemp;
248
249     TRACE ("(%p)->(-- ret=0x%08lx)\n", This, hr);
250
251     return hr;
252 }
253
254 /**************************************************************************
255  *  CreateMyCompEnumList()
256  */
257 static const WCHAR MyComputer_NameSpaceW[] = { 'S','O','F','T','W','A','R','E',
258  '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
259  'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
260  'o','r','e','r','\\','M','y','C','o','m','p','u','t','e','r','\\','N','a','m',
261  'e','s','p','a','c','e','\0' };
262
263 static BOOL CreateMyCompEnumList(IEnumIDList *list, DWORD dwFlags)
264 {
265     BOOL ret = TRUE;
266
267     TRACE("(%p)->(flags=0x%08lx) \n",list,dwFlags);
268
269     /* enumerate the folders */
270     if (dwFlags & SHCONTF_FOLDERS)
271     {
272         WCHAR wszDriveName[] = {'A', ':', '\\', '\0'};
273         DWORD dwDrivemap = GetLogicalDrives();
274         HKEY hkey;
275
276         while (ret && wszDriveName[0]<='Z')
277         {
278             if(dwDrivemap & 0x00000001L)
279                 ret = AddToEnumList(list, _ILCreateDrive(wszDriveName));
280             wszDriveName[0]++;
281             dwDrivemap = dwDrivemap >> 1;
282         }
283
284         TRACE("-- (%p)-> enumerate (mycomputer shell extensions)\n",list);
285         if (ret && !RegOpenKeyExW(HKEY_LOCAL_MACHINE, MyComputer_NameSpaceW,
286          0, KEY_READ, &hkey))
287         {
288             WCHAR iid[50];
289             int i=0;
290
291             while (ret)
292             {
293                 DWORD size;
294                 LONG r;
295
296                 size = sizeof(iid) / sizeof(iid[0]);
297                 r = RegEnumKeyExW(hkey, i, iid, &size, 0, NULL, NULL, NULL);
298                 if (ERROR_SUCCESS == r)
299                 {
300                     /* FIXME: shell extensions, shouldn't the type be
301                      * PT_SHELLEXT? */
302                     ret = AddToEnumList(list, _ILCreateGuidFromStrW(iid));
303                     i++;
304                 }
305                 else if (ERROR_NO_MORE_ITEMS == r)
306                     break;
307                 else
308                     ret = FALSE;
309             }
310             RegCloseKey(hkey);
311         }
312     }
313     return ret;
314 }
315
316 /**************************************************************************
317 *        ISF_MyComputer_fnEnumObjects
318 */
319 static HRESULT WINAPI ISF_MyComputer_fnEnumObjects (IShellFolder2 *iface,
320                HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST *ppEnumIDList)
321 {
322     IGenericSFImpl *This = (IGenericSFImpl *)iface;
323
324     TRACE("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n", This,
325           hwndOwner, dwFlags, ppEnumIDList);
326
327     *ppEnumIDList = IEnumIDList_Constructor();
328     if (*ppEnumIDList)
329         CreateMyCompEnumList(*ppEnumIDList, dwFlags);
330
331     TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
332
333     return (*ppEnumIDList) ? S_OK : E_OUTOFMEMORY;
334 }
335
336 /**************************************************************************
337 *        ISF_MyComputer_fnBindToObject
338 */
339 static HRESULT WINAPI ISF_MyComputer_fnBindToObject (IShellFolder2 *iface,
340                LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
341 {
342     IGenericSFImpl *This = (IGenericSFImpl *)iface;
343
344     TRACE("(%p)->(pidl=%p,%p,%s,%p)\n", This,
345           pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
346
347     return SHELL32_BindToChild (This->pidlRoot, NULL, pidl, riid, ppvOut);
348 }
349
350 /**************************************************************************
351 *    ISF_MyComputer_fnBindToStorage
352 */
353 static HRESULT WINAPI ISF_MyComputer_fnBindToStorage (IShellFolder2 * iface,
354                LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
355 {
356     IGenericSFImpl *This = (IGenericSFImpl *)iface;
357
358     FIXME("(%p)->(pidl=%p,%p,%s,%p) stub\n", This,
359           pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
360
361     *ppvOut = NULL;
362     return E_NOTIMPL;
363 }
364
365 /**************************************************************************
366 *     ISF_MyComputer_fnCompareIDs
367 */
368
369 static HRESULT WINAPI ISF_MyComputer_fnCompareIDs (IShellFolder2 *iface,
370                LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
371 {
372     IGenericSFImpl *This = (IGenericSFImpl *)iface;
373     int nReturn;
374
375     TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
376     nReturn = SHELL32_CompareIDs (_IShellFolder_ (This), lParam, pidl1, pidl2);
377     TRACE ("-- %i\n", nReturn);
378     return nReturn;
379 }
380
381 /**************************************************************************
382 *    ISF_MyComputer_fnCreateViewObject
383 */
384 static HRESULT WINAPI ISF_MyComputer_fnCreateViewObject (IShellFolder2 *iface,
385                HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
386 {
387     IGenericSFImpl *This = (IGenericSFImpl *)iface;
388     LPSHELLVIEW pShellView;
389     HRESULT hr = E_INVALIDARG;
390
391     TRACE("(%p)->(hwnd=%p,%s,%p)\n", This,
392           hwndOwner, shdebugstr_guid (riid), ppvOut);
393
394     if (!ppvOut)
395         return hr;
396
397     *ppvOut = NULL;
398
399     if (IsEqualIID (riid, &IID_IDropTarget))
400     {
401         WARN ("IDropTarget not implemented\n");
402         hr = E_NOTIMPL;
403     }
404     else if (IsEqualIID (riid, &IID_IContextMenu))
405     {
406         WARN ("IContextMenu not implemented\n");
407         hr = E_NOTIMPL;
408     }
409     else if (IsEqualIID (riid, &IID_IShellView))
410     {
411         pShellView = IShellView_Constructor ((IShellFolder *) iface);
412         if (pShellView)
413         {
414             hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
415             IShellView_Release (pShellView);
416         }
417     }
418     TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
419     return hr;
420 }
421
422 /**************************************************************************
423 *  ISF_MyComputer_fnGetAttributesOf
424 */
425 static HRESULT WINAPI ISF_MyComputer_fnGetAttributesOf (IShellFolder2 * iface,
426                 UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
427 {
428     IGenericSFImpl *This = (IGenericSFImpl *)iface;
429     HRESULT hr = S_OK;
430
431     TRACE ("(%p)->(cidl=%d apidl=%p mask=0x%08lx)\n", This, cidl, apidl, *rgfInOut);
432
433     if (!cidl || !apidl || !rgfInOut)
434         return E_INVALIDARG;
435
436     if (*rgfInOut == 0)
437         *rgfInOut = ~0;
438
439     while (cidl > 0 && *apidl)
440     {
441         pdump (*apidl);
442         SHELL32_GetItemAttributes (_IShellFolder_ (This), *apidl, rgfInOut);
443         apidl++;
444         cidl--;
445     }
446
447     TRACE ("-- result=0x%08lx\n", *rgfInOut);
448     return hr;
449 }
450
451 /**************************************************************************
452 *    ISF_MyComputer_fnGetUIObjectOf
453 *
454 * PARAMETERS
455 *  hwndOwner [in]  Parent window for any output
456 *  cidl      [in]  array size
457 *  apidl     [in]  simple pidl array
458 *  riid      [in]  Requested Interface
459 *  prgfInOut [   ] reserved
460 *  ppvObject [out] Resulting Interface
461 *
462 */
463 static HRESULT WINAPI ISF_MyComputer_fnGetUIObjectOf (IShellFolder2 * iface,
464                 HWND hwndOwner, UINT cidl, LPCITEMIDLIST * apidl, REFIID riid,
465                 UINT * prgfInOut, LPVOID * ppvOut)
466 {
467     IGenericSFImpl *This = (IGenericSFImpl *)iface;
468
469     LPITEMIDLIST pidl;
470     IUnknown *pObj = NULL;
471     HRESULT hr = E_INVALIDARG;
472
473     TRACE("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n", This,
474           hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
475
476     if (!ppvOut)
477         return hr;
478
479     *ppvOut = NULL;
480
481     if (IsEqualIID (riid, &IID_IContextMenu) && (cidl >= 1))
482     {
483         pObj = (LPUNKNOWN) ISvItemCm_Constructor ((IShellFolder *) iface,
484                                               This->pidlRoot, apidl, cidl);
485         hr = S_OK;
486     }
487     else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1))
488     {
489         pObj = (LPUNKNOWN) IDataObject_Constructor (hwndOwner,
490                                               This->pidlRoot, apidl, cidl);
491         hr = S_OK;
492     }
493     else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1))
494     {
495         pidl = ILCombine (This->pidlRoot, apidl[0]);
496         pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
497         SHFree (pidl);
498         hr = S_OK;
499     }
500     else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1))
501     {
502         pidl = ILCombine (This->pidlRoot, apidl[0]);
503         pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
504         SHFree (pidl);
505         hr = S_OK;
506     }
507     else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1))
508     {
509         hr = IShellFolder_QueryInterface (iface, &IID_IDropTarget,
510                                           (LPVOID *) &pObj);
511     }
512     else if ((IsEqualIID(riid,&IID_IShellLinkW) ||
513               IsEqualIID(riid,&IID_IShellLinkA)) && (cidl == 1))
514     {
515         pidl = ILCombine (This->pidlRoot, apidl[0]);
516         hr = IShellLink_ConstructFromFile(NULL, riid, pidl, (LPVOID*) &pObj);
517         SHFree (pidl);
518     }
519     else 
520         hr = E_NOINTERFACE;
521
522     if (SUCCEEDED(hr) && !pObj)
523         hr = E_OUTOFMEMORY;
524
525     *ppvOut = pObj;
526     TRACE ("(%p)->hr=0x%08lx\n", This, hr);
527     return hr;
528 }
529
530 /**************************************************************************
531 *    ISF_MyComputer_fnGetDisplayNameOf
532 */
533 static HRESULT WINAPI ISF_MyComputer_fnGetDisplayNameOf (IShellFolder2 *iface,
534                LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
535 {
536     IGenericSFImpl *This = (IGenericSFImpl *)iface;
537
538     char szPath[MAX_PATH];
539     HRESULT hr = S_OK;
540
541     TRACE ("(%p)->(pidl=%p,0x%08lx,%p)\n", This, pidl, dwFlags, strRet);
542     pdump (pidl);
543
544     if (!strRet)
545         return E_INVALIDARG;
546
547     szPath[0] = 0x00;
548
549     if (!pidl->mkid.cb)
550     {
551         /* parsing name like ::{...} */
552         lstrcpyA (szPath, "::");
553         SHELL32_GUIDToStringA(&CLSID_MyComputer, &szPath[2]);
554     }
555     else if (_ILIsPidlSimple(pidl))    
556     {
557         /* take names of special folders only if its only this folder */
558         if (_ILIsSpecialFolder(pidl))
559         {
560             GUID const *clsid;
561
562             clsid = _ILGetGUIDPointer (pidl);
563             if (clsid)
564             {
565                 if (GET_SHGDN_FOR (dwFlags) == SHGDN_FORPARSING)
566                 {
567                     static const WCHAR clsidW[] =
568                      { 'C','L','S','I','D','\\',0 };
569                     static const WCHAR shellfolderW[] =
570                      { '\\','s','h','e','l','l','f','o','l','d','e','r',0 };
571                     static const WCHAR wantsForParsingW[] =
572                      { 'W','a','n','t','s','F','o','r','P','a','r','s','i','n',
573                      'g',0 };
574                     int bWantsForParsing = FALSE;
575                     WCHAR szRegPath[100];
576                     LONG r;
577
578                     /*
579                      * We can only get a filesystem path from a shellfolder
580                      * if the value WantsFORPARSING exists in
581                      *      CLSID\\{...}\\shellfolder 
582                      * exception: the MyComputer folder has this keys not
583                      *            but like any filesystem backed
584                      *            folder it needs these behaviour
585                      *
586                      * Get the "WantsFORPARSING" flag from the registry
587                      */
588
589                     lstrcpyW (szRegPath, clsidW);
590                     SHELL32_GUIDToStringW (clsid, &szRegPath[6]);
591                     lstrcatW (szRegPath, shellfolderW);
592                     r = SHGetValueW (HKEY_CLASSES_ROOT, szRegPath, 
593                                      wantsForParsingW, NULL, NULL, NULL);
594                     if (r == ERROR_SUCCESS)
595                         bWantsForParsing = TRUE;
596
597                     if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
598                         bWantsForParsing)
599                     {
600                         /*
601                          * We need the filesystem path to the destination folder
602                          * Only the folder itself can know it
603                          */
604                         hr = SHELL32_GetDisplayNameOfChild (iface, pidl,
605                                                 dwFlags, szPath, MAX_PATH);
606                     }
607                     else
608                     {
609                         LPSTR p;
610
611                         /* parsing name like ::{...} */
612                         p = lstrcpyA(szPath, "::") + 2;
613                         p += SHELL32_GUIDToStringA(&CLSID_MyComputer, p);
614
615                         lstrcatA(p, "\\::");
616                         p += 3;
617                         SHELL32_GUIDToStringA(clsid, p);
618                     }
619                 }
620                 else
621                 {
622                     /* user friendly name */
623                     HCR_GetClassNameA (clsid, szPath, MAX_PATH);
624                 }
625             }
626             else
627             {
628                 /* append my own path */
629                 _ILSimpleGetText (pidl, szPath, MAX_PATH);
630             }
631         }
632         else if (_ILIsDrive(pidl))
633         {        
634             _ILSimpleGetText (pidl, szPath, MAX_PATH);    /* append my own path */
635
636             /* long view "lw_name (C:)" */
637             if (!(dwFlags & SHGDN_FORPARSING))
638             {
639                 DWORD dwVolumeSerialNumber, dwMaximumComponetLength, dwFileSystemFlags;
640                 char szDrive[18] = "";
641
642                 GetVolumeInformationA (szPath, szDrive, sizeof (szDrive) - 6,
643                            &dwVolumeSerialNumber,
644                            &dwMaximumComponetLength, &dwFileSystemFlags, NULL, 0);
645                 strcat (szDrive, " (");
646                 strncat (szDrive, szPath, 2);
647                 strcat (szDrive, ")");
648                 strcpy (szPath, szDrive);
649             }
650         }
651         else 
652         {
653             /* Neither a shell namespace extension nor a drive letter. */
654             ERR("Wrong pidl type\n");
655             return E_INVALIDARG;
656         }
657     }
658     else
659     {
660         /* Complex pidl. Let the child folder do the work */
661         strRet->uType = STRRET_CSTR;
662         hr = SHELL32_GetDisplayNameOfChild(iface, pidl, dwFlags, szPath, MAX_PATH);
663     }
664
665     if (SUCCEEDED (hr))
666     {
667         strRet->uType = STRRET_CSTR;
668         lstrcpynA (strRet->u.cStr, szPath, MAX_PATH);
669     }
670
671     TRACE ("-- (%p)->(%s)\n", This, szPath);
672     return hr;
673 }
674
675 /**************************************************************************
676 *  ISF_MyComputer_fnSetNameOf
677 *  Changes the name of a file object or subfolder, possibly changing its item
678 *  identifier in the process.
679 *
680 * PARAMETERS
681 *  hwndOwner  [in]   Owner window for output
682 *  pidl       [in]   simple pidl of item to change
683 *  lpszName   [in]   the items new display name
684 *  dwFlags    [in]   SHGNO formatting flags
685 *  ppidlOut   [out]  simple pidl returned
686 */
687 static HRESULT WINAPI ISF_MyComputer_fnSetNameOf (
688                IShellFolder2 * iface, HWND hwndOwner, LPCITEMIDLIST pidl,
689                LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
690 {
691     IGenericSFImpl *This = (IGenericSFImpl *)iface;
692     FIXME ("(%p)->(%p,pidl=%p,%s,%lu,%p)\n", This,
693            hwndOwner, pidl, debugstr_w (lpName), dwFlags, pPidlOut);
694     return E_FAIL;
695 }
696
697 static HRESULT WINAPI ISF_MyComputer_fnGetDefaultSearchGUID (
698                IShellFolder2 * iface, GUID * pguid)
699 {
700     IGenericSFImpl *This = (IGenericSFImpl *)iface;
701     FIXME ("(%p)\n", This);
702     return E_NOTIMPL;
703 }
704 static HRESULT WINAPI ISF_MyComputer_fnEnumSearches (
705                IShellFolder2 * iface, IEnumExtraSearch ** ppenum)
706 {
707     IGenericSFImpl *This = (IGenericSFImpl *)iface;
708     FIXME ("(%p)\n", This);
709     return E_NOTIMPL;
710 }
711 static HRESULT WINAPI ISF_MyComputer_fnGetDefaultColumn (
712                IShellFolder2 *iface, DWORD dwRes, ULONG *pSort, ULONG *pDisplay)
713 {
714     IGenericSFImpl *This = (IGenericSFImpl *)iface;
715
716     TRACE ("(%p)\n", This);
717
718     if (pSort)
719          *pSort = 0;
720     if (pDisplay)
721         *pDisplay = 0;
722     return S_OK;
723 }
724 static HRESULT WINAPI ISF_MyComputer_fnGetDefaultColumnState (
725                IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
726 {
727     IGenericSFImpl *This = (IGenericSFImpl *)iface;
728
729     TRACE ("(%p)\n", This);
730
731     if (!pcsFlags || iColumn >= MYCOMPUTERSHELLVIEWCOLUMNS)
732         return E_INVALIDARG;
733     *pcsFlags = MyComputerSFHeader[iColumn].pcsFlags;
734     return S_OK;
735 }
736
737 static HRESULT WINAPI ISF_MyComputer_fnGetDetailsEx (IShellFolder2 * iface,
738                LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
739 {
740     IGenericSFImpl *This = (IGenericSFImpl *)iface;
741     FIXME ("(%p)\n", This);
742     return E_NOTIMPL;
743 }
744
745 /* FIXME: drive size >4GB is rolling over */
746 static HRESULT WINAPI ISF_MyComputer_fnGetDetailsOf (IShellFolder2 * iface,
747                LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
748 {
749     IGenericSFImpl *This = (IGenericSFImpl *)iface;
750     HRESULT hr;
751
752     TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
753
754     if (!psd || iColumn >= MYCOMPUTERSHELLVIEWCOLUMNS)
755         return E_INVALIDARG;
756
757     if (!pidl)
758     {
759         psd->fmt = MyComputerSFHeader[iColumn].fmt;
760         psd->cxChar = MyComputerSFHeader[iColumn].cxChar;
761         psd->str.uType = STRRET_CSTR;
762         LoadStringA (shell32_hInstance, MyComputerSFHeader[iColumn].colnameid,
763                      psd->str.u.cStr, MAX_PATH);
764         return S_OK;
765     }
766     else
767     {
768         char szPath[MAX_PATH];
769         ULARGE_INTEGER ulBytes;
770
771         psd->str.u.cStr[0] = 0x00;
772         psd->str.uType = STRRET_CSTR;
773         switch (iColumn)
774         {
775         case 0:        /* name */
776             hr = IShellFolder_GetDisplayNameOf (iface, pidl,
777                        SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
778             break;
779         case 1:        /* type */
780             _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
781             break;
782         case 2:        /* total size */
783             if (_ILIsDrive (pidl))
784             {
785                 _ILSimpleGetText (pidl, szPath, MAX_PATH);
786                 GetDiskFreeSpaceExA (szPath, NULL, &ulBytes, NULL);
787                 StrFormatByteSizeA (ulBytes.u.LowPart, psd->str.u.cStr, MAX_PATH);
788             }
789             break;
790         case 3:        /* free size */
791             if (_ILIsDrive (pidl))
792             {
793                 _ILSimpleGetText (pidl, szPath, MAX_PATH);
794                 GetDiskFreeSpaceExA (szPath, &ulBytes, NULL, NULL);
795                 StrFormatByteSizeA (ulBytes.u.LowPart, psd->str.u.cStr, MAX_PATH);
796             }
797             break;
798         }
799         hr = S_OK;
800     }
801
802     return hr;
803 }
804
805 static HRESULT WINAPI ISF_MyComputer_fnMapColumnToSCID (
806                IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
807 {
808     IGenericSFImpl *This = (IGenericSFImpl *)iface;
809     FIXME ("(%p)\n", This);
810     return E_NOTIMPL;
811 }
812
813 static IShellFolder2Vtbl vt_ShellFolder2 =
814 {
815     ISF_MyComputer_fnQueryInterface,
816     ISF_MyComputer_fnAddRef,
817     ISF_MyComputer_fnRelease,
818     ISF_MyComputer_fnParseDisplayName,
819     ISF_MyComputer_fnEnumObjects,
820     ISF_MyComputer_fnBindToObject,
821     ISF_MyComputer_fnBindToStorage,
822     ISF_MyComputer_fnCompareIDs,
823     ISF_MyComputer_fnCreateViewObject,
824     ISF_MyComputer_fnGetAttributesOf,
825     ISF_MyComputer_fnGetUIObjectOf,
826     ISF_MyComputer_fnGetDisplayNameOf,
827     ISF_MyComputer_fnSetNameOf,
828     /* ShellFolder2 */
829     ISF_MyComputer_fnGetDefaultSearchGUID,
830     ISF_MyComputer_fnEnumSearches,
831     ISF_MyComputer_fnGetDefaultColumn,
832     ISF_MyComputer_fnGetDefaultColumnState,
833     ISF_MyComputer_fnGetDetailsEx,
834     ISF_MyComputer_fnGetDetailsOf,
835     ISF_MyComputer_fnMapColumnToSCID
836 };
837
838 /************************************************************************
839  *    IMCFldr_PersistFolder2_QueryInterface
840  */
841 static HRESULT WINAPI IMCFldr_PersistFolder2_QueryInterface (
842                IPersistFolder2 * iface, REFIID iid, LPVOID * ppvObj)
843 {
844     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
845
846     TRACE ("(%p)\n", This);
847
848     return IUnknown_QueryInterface (_IUnknown_ (This), iid, ppvObj);
849 }
850
851 /************************************************************************
852  *    IMCFldr_PersistFolder2_AddRef
853  */
854 static ULONG WINAPI IMCFldr_PersistFolder2_AddRef (IPersistFolder2 * iface)
855 {
856     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
857
858     TRACE ("(%p)->(count=%lu)\n", This, This->ref);
859
860     return IUnknown_AddRef (_IUnknown_ (This));
861 }
862
863 /************************************************************************
864  *    ISFPersistFolder_Release
865  */
866 static ULONG WINAPI IMCFldr_PersistFolder2_Release (IPersistFolder2 * iface)
867 {
868     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
869
870     TRACE ("(%p)->(count=%lu)\n", This, This->ref);
871
872     return IUnknown_Release (_IUnknown_ (This));
873 }
874
875 /************************************************************************
876  *    IMCFldr_PersistFolder2_GetClassID
877  */
878 static HRESULT WINAPI IMCFldr_PersistFolder2_GetClassID (
879                IPersistFolder2 * iface, CLSID * lpClassId)
880 {
881     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
882
883     TRACE ("(%p)\n", This);
884
885     if (!lpClassId)
886     return E_POINTER;
887     *lpClassId = CLSID_MyComputer;
888
889     return S_OK;
890 }
891
892 /************************************************************************
893  *    IMCFldr_PersistFolder2_Initialize
894  *
895  * NOTES: it makes no sense to change the pidl
896  */
897 static HRESULT WINAPI IMCFldr_PersistFolder2_Initialize (
898                IPersistFolder2 * iface, LPCITEMIDLIST pidl)
899 {
900     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
901     TRACE ("(%p)->(%p)\n", This, pidl);
902     return E_NOTIMPL;
903 }
904
905 /**************************************************************************
906  *    IPersistFolder2_fnGetCurFolder
907  */
908 static HRESULT WINAPI IMCFldr_PersistFolder2_GetCurFolder (
909                IPersistFolder2 * iface, LPITEMIDLIST * pidl)
910 {
911     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
912
913     TRACE ("(%p)->(%p)\n", This, pidl);
914
915     if (!pidl)
916         return E_POINTER;
917     *pidl = ILClone (This->pidlRoot);
918     return S_OK;
919 }
920
921 static IPersistFolder2Vtbl vt_PersistFolder2 =
922 {
923     IMCFldr_PersistFolder2_QueryInterface,
924     IMCFldr_PersistFolder2_AddRef,
925     IMCFldr_PersistFolder2_Release,
926     IMCFldr_PersistFolder2_GetClassID,
927     IMCFldr_PersistFolder2_Initialize,
928     IMCFldr_PersistFolder2_GetCurFolder
929 };