mshtml: Check for null pointers in IHTMLLocation_get*.
[wine/hramrach.git] / dlls / shell32 / cpanelfolder.c
blobcd2f3b81d667671536a08f68b37defafc34114b2
1 /*
2 * Control panel folder
4 * Copyright 2003 Martin Fuchs
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <stdlib.h>
25 #include <string.h>
26 #include <stdarg.h>
27 #include <stdio.h>
29 #define COBJMACROS
30 #define NONAMELESSUNION
31 #define NONAMELESSSTRUCT
33 #include "winerror.h"
34 #include "windef.h"
35 #include "winbase.h"
36 #include "winreg.h"
37 #include "wingdi.h"
38 #include "winuser.h"
40 #include "ole2.h"
41 #include "shlguid.h"
43 #include "commctrl.h"
44 #include "cpanel.h"
45 #include "enumidlist.h"
46 #include "pidl.h"
47 #include "undocshell.h"
48 #include "shell32_main.h"
49 #include "shresdef.h"
50 #include "shlwapi.h"
51 #include "wine/debug.h"
52 #include "debughlp.h"
53 #include "shfldr.h"
55 WINE_DEFAULT_DEBUG_CHANNEL(shell);
57 /***********************************************************************
58 * control panel implementation in shell namespace
61 typedef struct {
62 const IShellFolder2Vtbl *lpVtbl;
63 LONG ref;
64 const IPersistFolder2Vtbl *lpVtblPersistFolder2;
65 const IShellExecuteHookWVtbl *lpVtblShellExecuteHookW;
66 const IShellExecuteHookAVtbl *lpVtblShellExecuteHookA;
68 IUnknown *pUnkOuter; /* used for aggregation */
70 /* both paths are parsible from the desktop */
71 LPITEMIDLIST pidlRoot; /* absolute pidl */
72 int dwAttributes; /* attributes returned by GetAttributesOf FIXME: use it */
73 } ICPanelImpl;
75 static const IShellFolder2Vtbl vt_ShellFolder2;
76 static const IPersistFolder2Vtbl vt_PersistFolder2;
77 static const IShellExecuteHookWVtbl vt_ShellExecuteHookW;
78 static const IShellExecuteHookAVtbl vt_ShellExecuteHookA;
80 static inline ICPanelImpl *impl_from_IPersistFolder2( IPersistFolder2 *iface )
82 return (ICPanelImpl *)((char*)iface - FIELD_OFFSET(ICPanelImpl, lpVtblPersistFolder2));
85 static inline ICPanelImpl *impl_from_IShellExecuteHookW( IShellExecuteHookW *iface )
87 return (ICPanelImpl *)((char*)iface - FIELD_OFFSET(ICPanelImpl, lpVtblShellExecuteHookW));
90 static inline ICPanelImpl *impl_from_IShellExecuteHookA( IShellExecuteHookA *iface )
92 return (ICPanelImpl *)((char*)iface - FIELD_OFFSET(ICPanelImpl, lpVtblShellExecuteHookA));
97 converts This to an interface pointer
99 #define _IUnknown_(This) ((IUnknown*)&(This)->lpVtbl)
100 #define _IShellFolder_(This) ((IShellFolder*)&(This)->lpVtbl)
101 #define _IShellFolder2_(This) (&(This)->lpVtbl)
103 #define _IPersist_(This) (&(This)->lpVtblPersistFolder2)
104 #define _IPersistFolder_(This) (&(This)->lpVtblPersistFolder2)
105 #define _IPersistFolder2_(This) (&(This)->lpVtblPersistFolder2)
106 #define _IShellExecuteHookW_(This) (&(This)->lpVtblShellExecuteHookW)
107 #define _IShellExecuteHookA_(This) (&(This)->lpVtblShellExecuteHookA)
109 /***********************************************************************
110 * IShellFolder [ControlPanel] implementation
113 static const shvheader ControlPanelSFHeader[] = {
114 {IDS_SHV_COLUMN8, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},/*FIXME*/
115 {IDS_SHV_COLUMN9, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_LEFT, 80},/*FIXME*/
118 #define CONROLPANELSHELLVIEWCOLUMNS 2
120 /**************************************************************************
121 * IControlPanel_Constructor
123 HRESULT WINAPI IControlPanel_Constructor(IUnknown* pUnkOuter, REFIID riid, LPVOID * ppv)
125 ICPanelImpl *sf;
127 TRACE("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid(riid));
129 if (!ppv)
130 return E_POINTER;
131 if (pUnkOuter && !IsEqualIID (riid, &IID_IUnknown))
132 return CLASS_E_NOAGGREGATION;
134 sf = LocalAlloc(LMEM_ZEROINIT, sizeof(ICPanelImpl));
135 if (!sf)
136 return E_OUTOFMEMORY;
138 sf->ref = 0;
139 sf->lpVtbl = &vt_ShellFolder2;
140 sf->lpVtblPersistFolder2 = &vt_PersistFolder2;
141 sf->lpVtblShellExecuteHookW = &vt_ShellExecuteHookW;
142 sf->lpVtblShellExecuteHookA = &vt_ShellExecuteHookA;
143 sf->pidlRoot = _ILCreateControlPanel(); /* my qualified pidl */
144 sf->pUnkOuter = pUnkOuter ? pUnkOuter : _IUnknown_ (sf);
146 if (FAILED(IUnknown_QueryInterface(_IUnknown_(sf), riid, ppv))) {
147 IUnknown_Release(_IUnknown_(sf));
148 return E_NOINTERFACE;
151 TRACE("--(%p)\n", sf);
152 return S_OK;
155 /**************************************************************************
156 * ISF_ControlPanel_fnQueryInterface
158 * NOTES supports not IPersist/IPersistFolder
160 static HRESULT WINAPI ISF_ControlPanel_fnQueryInterface(IShellFolder2 * iface, REFIID riid, LPVOID * ppvObject)
162 ICPanelImpl *This = (ICPanelImpl *)iface;
164 TRACE("(%p)->(%s,%p)\n", This, shdebugstr_guid(riid), ppvObject);
166 *ppvObject = NULL;
168 if (IsEqualIID(riid, &IID_IUnknown) ||
169 IsEqualIID(riid, &IID_IShellFolder) || IsEqualIID(riid, &IID_IShellFolder2))
170 *ppvObject = This;
171 else if (IsEqualIID(riid, &IID_IPersist) ||
172 IsEqualIID(riid, &IID_IPersistFolder) || IsEqualIID(riid, &IID_IPersistFolder2))
173 *ppvObject = _IPersistFolder2_(This);
174 else if (IsEqualIID(riid, &IID_IShellExecuteHookW))
175 *ppvObject = _IShellExecuteHookW_(This);
176 else if (IsEqualIID(riid, &IID_IShellExecuteHookA))
177 *ppvObject = _IShellExecuteHookA_(This);
179 if (*ppvObject) {
180 IUnknown_AddRef((IUnknown *)(*ppvObject));
181 TRACE("-- Interface:(%p)->(%p)\n", ppvObject, *ppvObject);
182 return S_OK;
184 TRACE("-- Interface: E_NOINTERFACE\n");
185 return E_NOINTERFACE;
188 static ULONG WINAPI ISF_ControlPanel_fnAddRef(IShellFolder2 * iface)
190 ICPanelImpl *This = (ICPanelImpl *)iface;
191 ULONG refCount = InterlockedIncrement(&This->ref);
193 TRACE("(%p)->(count=%u)\n", This, refCount - 1);
195 return refCount;
198 static ULONG WINAPI ISF_ControlPanel_fnRelease(IShellFolder2 * iface)
200 ICPanelImpl *This = (ICPanelImpl *)iface;
201 ULONG refCount = InterlockedDecrement(&This->ref);
203 TRACE("(%p)->(count=%u)\n", This, refCount + 1);
205 if (!refCount) {
206 TRACE("-- destroying IShellFolder(%p)\n", This);
207 SHFree(This->pidlRoot);
208 LocalFree(This);
210 return refCount;
213 /**************************************************************************
214 * ISF_ControlPanel_fnParseDisplayName
216 static HRESULT WINAPI
217 ISF_ControlPanel_fnParseDisplayName(IShellFolder2 * iface,
218 HWND hwndOwner,
219 LPBC pbc,
220 LPOLESTR lpszDisplayName,
221 DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
223 ICPanelImpl *This = (ICPanelImpl *)iface;
225 HRESULT hr = E_INVALIDARG;
227 FIXME("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
228 This, hwndOwner, pbc, lpszDisplayName, debugstr_w(lpszDisplayName), pchEaten, ppidl, pdwAttributes);
230 *ppidl = 0;
231 if (pchEaten)
232 *pchEaten = 0;
234 TRACE("(%p)->(-- ret=0x%08x)\n", This, hr);
236 return hr;
239 static LPITEMIDLIST _ILCreateCPanelApplet(LPCSTR name, LPCSTR displayName,
240 LPCSTR comment, int iconIdx)
242 PIDLCPanelStruct *p;
243 LPITEMIDLIST pidl;
244 PIDLDATA tmp;
245 int size0 = (char*)tmp.u.cpanel.szName-(char*)&tmp.u.cpanel;
246 int size = size0;
247 int l;
249 tmp.type = PT_CPLAPPLET;
250 tmp.u.cpanel.dummy = 0;
251 tmp.u.cpanel.iconIdx = iconIdx;
253 l = strlen(name);
254 size += l+1;
256 tmp.u.cpanel.offsDispName = l+1;
257 l = strlen(displayName);
258 size += l+1;
260 tmp.u.cpanel.offsComment = tmp.u.cpanel.offsDispName+1+l;
261 l = strlen(comment);
262 size += l+1;
264 pidl = SHAlloc(size+4);
265 if (!pidl)
266 return NULL;
268 pidl->mkid.cb = size+2;
269 memcpy(pidl->mkid.abID, &tmp, 2+size0);
271 p = &((PIDLDATA*)pidl->mkid.abID)->u.cpanel;
272 strcpy(p->szName, name);
273 strcpy(p->szName+tmp.u.cpanel.offsDispName, displayName);
274 strcpy(p->szName+tmp.u.cpanel.offsComment, comment);
276 *(WORD*)((char*)pidl+(size+2)) = 0;
278 pcheck(pidl);
280 return pidl;
283 /**************************************************************************
284 * _ILGetCPanelPointer()
285 * gets a pointer to the control panel struct stored in the pidl
287 static PIDLCPanelStruct* _ILGetCPanelPointer(LPCITEMIDLIST pidl)
289 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
291 if (pdata && pdata->type==PT_CPLAPPLET)
292 return &pdata->u.cpanel;
294 return NULL;
297 /**************************************************************************
298 * ISF_ControlPanel_fnEnumObjects
300 static BOOL SHELL_RegisterCPanelApp(IEnumIDList* list, LPCSTR path)
302 LPITEMIDLIST pidl;
303 CPlApplet* applet;
304 CPanel panel;
305 CPLINFO info;
306 unsigned i;
307 int iconIdx;
309 char displayName[MAX_PATH];
310 char comment[MAX_PATH];
312 WCHAR wpath[MAX_PATH];
314 MultiByteToWideChar(CP_ACP, 0, path, -1, wpath, MAX_PATH);
316 panel.first = NULL;
317 applet = Control_LoadApplet(0, wpath, &panel);
319 if (applet)
321 for(i=0; i<applet->count; ++i)
323 WideCharToMultiByte(CP_ACP, 0, applet->info[i].szName, -1, displayName, MAX_PATH, 0, 0);
324 WideCharToMultiByte(CP_ACP, 0, applet->info[i].szInfo, -1, comment, MAX_PATH, 0, 0);
326 applet->proc(0, CPL_INQUIRE, i, (LPARAM)&info);
328 if (info.idIcon > 0)
329 iconIdx = -info.idIcon; /* negative icon index instead of icon number */
330 else
331 iconIdx = 0;
333 pidl = _ILCreateCPanelApplet(path, displayName, comment, iconIdx);
335 if (pidl)
336 AddToEnumList(list, pidl);
338 Control_UnloadApplet(applet);
340 return TRUE;
343 static int SHELL_RegisterRegistryCPanelApps(IEnumIDList* list, HKEY hkey_root, LPCSTR szRepPath)
345 char name[MAX_PATH];
346 char value[MAX_PATH];
347 HKEY hkey;
349 int cnt = 0;
351 if (RegOpenKeyA(hkey_root, szRepPath, &hkey) == ERROR_SUCCESS)
353 int idx = 0;
355 for(;; ++idx)
357 DWORD nameLen = MAX_PATH;
358 DWORD valueLen = MAX_PATH;
360 if (RegEnumValueA(hkey, idx, name, &nameLen, NULL, NULL, (LPBYTE)value, &valueLen) != ERROR_SUCCESS)
361 break;
363 if (SHELL_RegisterCPanelApp(list, value))
364 ++cnt;
366 RegCloseKey(hkey);
369 return cnt;
372 static int SHELL_RegisterCPanelFolders(IEnumIDList* list, HKEY hkey_root, LPCSTR szRepPath)
374 char name[MAX_PATH];
375 HKEY hkey;
377 int cnt = 0;
379 if (RegOpenKeyA(hkey_root, szRepPath, &hkey) == ERROR_SUCCESS)
381 int idx = 0;
382 for(;; ++idx)
384 if (RegEnumKeyA(hkey, idx, name, MAX_PATH) != ERROR_SUCCESS)
385 break;
387 if (*name == '{')
389 LPITEMIDLIST pidl = _ILCreateGuidFromStrA(name);
391 if (pidl && AddToEnumList(list, pidl))
392 ++cnt;
396 RegCloseKey(hkey);
399 return cnt;
402 /**************************************************************************
403 * CreateCPanelEnumList()
405 static BOOL CreateCPanelEnumList(
406 IEnumIDList * iface,
407 DWORD dwFlags)
409 CHAR szPath[MAX_PATH];
410 WIN32_FIND_DATAA wfd;
411 HANDLE hFile;
413 TRACE("(%p)->(flags=0x%08x)\n", iface, dwFlags);
415 /* enumerate control panel folders */
416 if (dwFlags & SHCONTF_FOLDERS)
417 SHELL_RegisterCPanelFolders(iface, HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ControlPanel\\NameSpace");
419 /* enumerate the control panel applets */
420 if (dwFlags & SHCONTF_NONFOLDERS)
422 LPSTR p;
424 GetSystemDirectoryA(szPath, MAX_PATH);
425 p = PathAddBackslashA(szPath);
426 strcpy(p, "*.cpl");
428 TRACE("-- (%p)-> enumerate SHCONTF_NONFOLDERS of %s\n",iface,debugstr_a(szPath));
429 hFile = FindFirstFileA(szPath, &wfd);
431 if (hFile != INVALID_HANDLE_VALUE)
435 if (!(dwFlags & SHCONTF_INCLUDEHIDDEN) && (wfd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN))
436 continue;
438 if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
439 strcpy(p, wfd.cFileName);
440 SHELL_RegisterCPanelApp(iface, szPath);
442 } while(FindNextFileA(hFile, &wfd));
443 FindClose(hFile);
446 SHELL_RegisterRegistryCPanelApps(iface, HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Control Panel\\Cpls");
447 SHELL_RegisterRegistryCPanelApps(iface, HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Control Panel\\Cpls");
449 return TRUE;
452 /**************************************************************************
453 * ISF_ControlPanel_fnEnumObjects
455 static HRESULT WINAPI
456 ISF_ControlPanel_fnEnumObjects(IShellFolder2 * iface, HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
458 ICPanelImpl *This = (ICPanelImpl *)iface;
460 TRACE("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n", This, hwndOwner, dwFlags, ppEnumIDList);
462 *ppEnumIDList = IEnumIDList_Constructor();
463 if (*ppEnumIDList)
464 CreateCPanelEnumList(*ppEnumIDList, dwFlags);
466 TRACE("--(%p)->(new ID List: %p)\n", This, *ppEnumIDList);
468 return(*ppEnumIDList) ? S_OK : E_OUTOFMEMORY;
471 /**************************************************************************
472 * ISF_ControlPanel_fnBindToObject
474 static HRESULT WINAPI
475 ISF_ControlPanel_fnBindToObject(IShellFolder2 * iface, LPCITEMIDLIST pidl,
476 LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
478 ICPanelImpl *This = (ICPanelImpl *)iface;
480 TRACE("(%p)->(pidl=%p,%p,%s,%p)\n", This, pidl, pbcReserved, shdebugstr_guid(riid), ppvOut);
482 return SHELL32_BindToChild(This->pidlRoot, NULL, pidl, riid, ppvOut);
485 /**************************************************************************
486 * ISF_ControlPanel_fnBindToStorage
488 static HRESULT WINAPI
489 ISF_ControlPanel_fnBindToStorage(IShellFolder2 * iface,
490 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
492 ICPanelImpl *This = (ICPanelImpl *)iface;
494 FIXME("(%p)->(pidl=%p,%p,%s,%p) stub\n", This, pidl, pbcReserved, shdebugstr_guid(riid), ppvOut);
496 *ppvOut = NULL;
497 return E_NOTIMPL;
500 /**************************************************************************
501 * ISF_ControlPanel_fnCompareIDs
504 static HRESULT WINAPI
505 ISF_ControlPanel_fnCompareIDs(IShellFolder2 * iface, LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
507 ICPanelImpl *This = (ICPanelImpl *)iface;
509 int nReturn;
511 TRACE("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
512 nReturn = SHELL32_CompareIDs(_IShellFolder_(This), lParam, pidl1, pidl2);
513 TRACE("-- %i\n", nReturn);
514 return nReturn;
517 /**************************************************************************
518 * ISF_ControlPanel_fnCreateViewObject
520 static HRESULT WINAPI
521 ISF_ControlPanel_fnCreateViewObject(IShellFolder2 * iface, HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
523 ICPanelImpl *This = (ICPanelImpl *)iface;
525 LPSHELLVIEW pShellView;
526 HRESULT hr = E_INVALIDARG;
528 TRACE("(%p)->(hwnd=%p,%s,%p)\n", This, hwndOwner, shdebugstr_guid(riid), ppvOut);
530 if (ppvOut) {
531 *ppvOut = NULL;
533 if (IsEqualIID(riid, &IID_IDropTarget)) {
534 WARN("IDropTarget not implemented\n");
535 hr = E_NOTIMPL;
536 } else if (IsEqualIID(riid, &IID_IContextMenu)) {
537 WARN("IContextMenu not implemented\n");
538 hr = E_NOTIMPL;
539 } else if (IsEqualIID(riid, &IID_IShellView)) {
540 pShellView = IShellView_Constructor((IShellFolder *) iface);
541 if (pShellView) {
542 hr = IShellView_QueryInterface(pShellView, riid, ppvOut);
543 IShellView_Release(pShellView);
547 TRACE("--(%p)->(interface=%p)\n", This, ppvOut);
548 return hr;
551 /**************************************************************************
552 * ISF_ControlPanel_fnGetAttributesOf
554 static HRESULT WINAPI
555 ISF_ControlPanel_fnGetAttributesOf(IShellFolder2 * iface, UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
557 ICPanelImpl *This = (ICPanelImpl *)iface;
559 HRESULT hr = S_OK;
561 TRACE("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n",
562 This, cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0);
564 if (!rgfInOut)
565 return E_INVALIDARG;
566 if (cidl && !apidl)
567 return E_INVALIDARG;
569 if (*rgfInOut == 0)
570 *rgfInOut = ~0;
572 while(cidl > 0 && *apidl) {
573 pdump(*apidl);
574 SHELL32_GetItemAttributes(_IShellFolder_(This), *apidl, rgfInOut);
575 apidl++;
576 cidl--;
578 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
579 *rgfInOut &= ~SFGAO_VALIDATE;
581 TRACE("-- result=0x%08x\n", *rgfInOut);
582 return hr;
585 /**************************************************************************
586 * ISF_ControlPanel_fnGetUIObjectOf
588 * PARAMETERS
589 * HWND hwndOwner, //[in ] Parent window for any output
590 * UINT cidl, //[in ] array size
591 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
592 * REFIID riid, //[in ] Requested Interface
593 * UINT* prgfInOut, //[ ] reserved
594 * LPVOID* ppvObject) //[out] Resulting Interface
597 static HRESULT WINAPI
598 ISF_ControlPanel_fnGetUIObjectOf(IShellFolder2 * iface,
599 HWND hwndOwner,
600 UINT cidl, LPCITEMIDLIST * apidl, REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
602 ICPanelImpl *This = (ICPanelImpl *)iface;
604 LPITEMIDLIST pidl;
605 IUnknown *pObj = NULL;
606 HRESULT hr = E_INVALIDARG;
608 TRACE("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
609 This, hwndOwner, cidl, apidl, shdebugstr_guid(riid), prgfInOut, ppvOut);
611 if (ppvOut) {
612 *ppvOut = NULL;
614 if (IsEqualIID(riid, &IID_IContextMenu) &&(cidl >= 1)) {
615 pObj = (LPUNKNOWN) ISvItemCm_Constructor((IShellFolder *) iface, This->pidlRoot, apidl, cidl);
616 hr = S_OK;
617 } else if (IsEqualIID(riid, &IID_IDataObject) &&(cidl >= 1)) {
618 pObj = (LPUNKNOWN) IDataObject_Constructor(hwndOwner, This->pidlRoot, apidl, cidl);
619 hr = S_OK;
620 } else if (IsEqualIID(riid, &IID_IExtractIconA) &&(cidl == 1)) {
621 pidl = ILCombine(This->pidlRoot, apidl[0]);
622 pObj = (LPUNKNOWN) IExtractIconA_Constructor(pidl);
623 SHFree(pidl);
624 hr = S_OK;
625 } else if (IsEqualIID(riid, &IID_IExtractIconW) &&(cidl == 1)) {
626 pidl = ILCombine(This->pidlRoot, apidl[0]);
627 pObj = (LPUNKNOWN) IExtractIconW_Constructor(pidl);
628 SHFree(pidl);
629 hr = S_OK;
630 } else if ((IsEqualIID(riid,&IID_IShellLinkW) || IsEqualIID(riid,&IID_IShellLinkA))
631 && (cidl == 1)) {
632 pidl = ILCombine(This->pidlRoot, apidl[0]);
633 hr = IShellLink_ConstructFromFile(NULL, riid, pidl,(LPVOID*)&pObj);
634 SHFree(pidl);
635 } else {
636 hr = E_NOINTERFACE;
639 if (SUCCEEDED(hr) && !pObj)
640 hr = E_OUTOFMEMORY;
642 *ppvOut = pObj;
644 TRACE("(%p)->hr=0x%08x\n", This, hr);
645 return hr;
648 /**************************************************************************
649 * ISF_ControlPanel_fnGetDisplayNameOf
651 static HRESULT WINAPI ISF_ControlPanel_fnGetDisplayNameOf(IShellFolder2 * iface, LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
653 ICPanelImpl *This = (ICPanelImpl *)iface;
655 CHAR szPath[MAX_PATH];
656 WCHAR wszPath[MAX_PATH+1]; /* +1 for potential backslash */
657 PIDLCPanelStruct* pcpanel;
659 *szPath = '\0';
661 TRACE("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet);
662 pdump(pidl);
664 if (!pidl || !strRet)
665 return E_INVALIDARG;
667 pcpanel = _ILGetCPanelPointer(pidl);
669 if (pcpanel) {
670 lstrcpyA(szPath, pcpanel->szName+pcpanel->offsDispName);
672 if (!(dwFlags & SHGDN_FORPARSING))
673 FIXME("retrieve display name from control panel app\n");
675 /* take names of special folders only if it's only this folder */
676 else if (_ILIsSpecialFolder(pidl)) {
677 BOOL bSimplePidl = _ILIsPidlSimple(pidl);
679 if (bSimplePidl) {
680 _ILSimpleGetTextW(pidl, wszPath, MAX_PATH); /* append my own path */
681 } else {
682 FIXME("special pidl\n");
685 if ((dwFlags & SHGDN_FORPARSING) && !bSimplePidl) { /* go deeper if needed */
686 int len = 0;
688 PathAddBackslashW(wszPath);
689 len = lstrlenW(wszPath);
691 if (FAILED(SHELL32_GetDisplayNameOfChild(iface, pidl, dwFlags | SHGDN_INFOLDER, wszPath + len, MAX_PATH + 1 - len)))
692 return E_OUTOFMEMORY;
693 if (!WideCharToMultiByte(CP_ACP, 0, wszPath, -1, szPath, MAX_PATH, NULL, NULL))
694 wszPath[0] = '\0';
698 strRet->uType = STRRET_CSTR;
699 lstrcpynA(strRet->u.cStr, szPath, MAX_PATH);
701 TRACE("--(%p)->(%s)\n", This, szPath);
702 return S_OK;
705 /**************************************************************************
706 * ISF_ControlPanel_fnSetNameOf
707 * Changes the name of a file object or subfolder, possibly changing its item
708 * identifier in the process.
710 * PARAMETERS
711 * HWND hwndOwner, //[in ] Owner window for output
712 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
713 * LPCOLESTR lpszName, //[in ] the items new display name
714 * DWORD dwFlags, //[in ] SHGNO formatting flags
715 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
717 static HRESULT WINAPI ISF_ControlPanel_fnSetNameOf(IShellFolder2 * iface, HWND hwndOwner, LPCITEMIDLIST pidl, /*simple pidl */
718 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
720 ICPanelImpl *This = (ICPanelImpl *)iface;
721 FIXME("(%p)->(%p,pidl=%p,%s,%u,%p)\n", This, hwndOwner, pidl, debugstr_w(lpName), dwFlags, pPidlOut);
722 return E_FAIL;
725 static HRESULT WINAPI ISF_ControlPanel_fnGetDefaultSearchGUID(IShellFolder2 * iface, GUID * pguid)
727 ICPanelImpl *This = (ICPanelImpl *)iface;
728 FIXME("(%p)\n", This);
729 return E_NOTIMPL;
731 static HRESULT WINAPI ISF_ControlPanel_fnEnumSearches(IShellFolder2 * iface, IEnumExtraSearch ** ppenum)
733 ICPanelImpl *This = (ICPanelImpl *)iface;
734 FIXME("(%p)\n", This);
735 return E_NOTIMPL;
737 static HRESULT WINAPI ISF_ControlPanel_fnGetDefaultColumn(IShellFolder2 * iface, DWORD dwRes, ULONG * pSort, ULONG * pDisplay)
739 ICPanelImpl *This = (ICPanelImpl *)iface;
741 TRACE("(%p)\n", This);
743 if (pSort) *pSort = 0;
744 if (pDisplay) *pDisplay = 0;
745 return S_OK;
747 static HRESULT WINAPI ISF_ControlPanel_fnGetDefaultColumnState(IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
749 ICPanelImpl *This = (ICPanelImpl *)iface;
751 TRACE("(%p)\n", This);
753 if (!pcsFlags || iColumn >= CONROLPANELSHELLVIEWCOLUMNS) return E_INVALIDARG;
754 *pcsFlags = ControlPanelSFHeader[iColumn].pcsFlags;
755 return S_OK;
757 static HRESULT WINAPI ISF_ControlPanel_fnGetDetailsEx(IShellFolder2 * iface, LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
759 ICPanelImpl *This = (ICPanelImpl *)iface;
760 FIXME("(%p)\n", This);
761 return E_NOTIMPL;
764 static HRESULT WINAPI ISF_ControlPanel_fnGetDetailsOf(IShellFolder2 * iface, LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
766 ICPanelImpl *This = (ICPanelImpl *)iface;
767 PIDLCPanelStruct* pcpanel;
768 HRESULT hr;
770 TRACE("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
772 if (!psd || iColumn >= CONROLPANELSHELLVIEWCOLUMNS)
773 return E_INVALIDARG;
775 if (!pidl) {
776 psd->fmt = ControlPanelSFHeader[iColumn].fmt;
777 psd->cxChar = ControlPanelSFHeader[iColumn].cxChar;
778 psd->str.uType = STRRET_CSTR;
779 LoadStringA(shell32_hInstance, ControlPanelSFHeader[iColumn].colnameid, psd->str.u.cStr, MAX_PATH);
780 return S_OK;
781 } else {
782 psd->str.u.cStr[0] = 0x00;
783 psd->str.uType = STRRET_CSTR;
784 switch(iColumn) {
785 case 0: /* name */
786 hr = IShellFolder_GetDisplayNameOf(iface, pidl, SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
787 break;
788 case 1: /* comment */
789 pcpanel = _ILGetCPanelPointer(pidl);
791 if (pcpanel)
792 lstrcpyA(psd->str.u.cStr, pcpanel->szName+pcpanel->offsComment);
793 else
794 _ILGetFileType(pidl, psd->str.u.cStr, MAX_PATH);
796 break;
798 hr = S_OK;
801 return hr;
803 static HRESULT WINAPI ISF_ControlPanel_fnMapColumnToSCID(IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
805 ICPanelImpl *This = (ICPanelImpl *)iface;
806 FIXME("(%p)\n", This);
807 return E_NOTIMPL;
810 static const IShellFolder2Vtbl vt_ShellFolder2 =
813 ISF_ControlPanel_fnQueryInterface,
814 ISF_ControlPanel_fnAddRef,
815 ISF_ControlPanel_fnRelease,
816 ISF_ControlPanel_fnParseDisplayName,
817 ISF_ControlPanel_fnEnumObjects,
818 ISF_ControlPanel_fnBindToObject,
819 ISF_ControlPanel_fnBindToStorage,
820 ISF_ControlPanel_fnCompareIDs,
821 ISF_ControlPanel_fnCreateViewObject,
822 ISF_ControlPanel_fnGetAttributesOf,
823 ISF_ControlPanel_fnGetUIObjectOf,
824 ISF_ControlPanel_fnGetDisplayNameOf,
825 ISF_ControlPanel_fnSetNameOf,
827 /* ShellFolder2 */
828 ISF_ControlPanel_fnGetDefaultSearchGUID,
829 ISF_ControlPanel_fnEnumSearches,
830 ISF_ControlPanel_fnGetDefaultColumn,
831 ISF_ControlPanel_fnGetDefaultColumnState,
832 ISF_ControlPanel_fnGetDetailsEx,
833 ISF_ControlPanel_fnGetDetailsOf,
834 ISF_ControlPanel_fnMapColumnToSCID
837 /************************************************************************
838 * ICPanel_PersistFolder2_QueryInterface
840 static HRESULT WINAPI ICPanel_PersistFolder2_QueryInterface(IPersistFolder2 * iface, REFIID iid, LPVOID * ppvObject)
842 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
844 TRACE("(%p)\n", This);
846 return IUnknown_QueryInterface(_IUnknown_(This), iid, ppvObject);
849 /************************************************************************
850 * ICPanel_PersistFolder2_AddRef
852 static ULONG WINAPI ICPanel_PersistFolder2_AddRef(IPersistFolder2 * iface)
854 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
856 TRACE("(%p)->(count=%u)\n", This, This->ref);
858 return IUnknown_AddRef(_IUnknown_(This));
861 /************************************************************************
862 * ISFPersistFolder_Release
864 static ULONG WINAPI ICPanel_PersistFolder2_Release(IPersistFolder2 * iface)
866 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
868 TRACE("(%p)->(count=%u)\n", This, This->ref);
870 return IUnknown_Release(_IUnknown_(This));
873 /************************************************************************
874 * ICPanel_PersistFolder2_GetClassID
876 static HRESULT WINAPI ICPanel_PersistFolder2_GetClassID(IPersistFolder2 * iface, CLSID * lpClassId)
878 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
880 TRACE("(%p)\n", This);
882 if (!lpClassId)
883 return E_POINTER;
884 *lpClassId = CLSID_ControlPanel;
886 return S_OK;
889 /************************************************************************
890 * ICPanel_PersistFolder2_Initialize
892 * NOTES: it makes no sense to change the pidl
894 static HRESULT WINAPI ICPanel_PersistFolder2_Initialize(IPersistFolder2 * iface, LPCITEMIDLIST pidl)
896 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
897 TRACE("(%p)->(%p)\n", This, pidl);
898 return E_NOTIMPL;
901 /**************************************************************************
902 * IPersistFolder2_fnGetCurFolder
904 static HRESULT WINAPI ICPanel_PersistFolder2_GetCurFolder(IPersistFolder2 * iface, LPITEMIDLIST * pidl)
906 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
908 TRACE("(%p)->(%p)\n", This, pidl);
910 if (!pidl)
911 return E_POINTER;
912 *pidl = ILClone(This->pidlRoot);
913 return S_OK;
916 static const IPersistFolder2Vtbl vt_PersistFolder2 =
919 ICPanel_PersistFolder2_QueryInterface,
920 ICPanel_PersistFolder2_AddRef,
921 ICPanel_PersistFolder2_Release,
922 ICPanel_PersistFolder2_GetClassID,
923 ICPanel_PersistFolder2_Initialize,
924 ICPanel_PersistFolder2_GetCurFolder
927 HRESULT CPanel_GetIconLocationW(LPCITEMIDLIST pidl,
928 LPWSTR szIconFile, UINT cchMax, int* piIndex)
930 PIDLCPanelStruct* pcpanel = _ILGetCPanelPointer(pidl);
932 if (!pcpanel)
933 return E_INVALIDARG;
935 MultiByteToWideChar(CP_ACP, 0, pcpanel->szName, -1, szIconFile, cchMax);
936 *piIndex = pcpanel->iconIdx!=-1? pcpanel->iconIdx: 0;
938 return S_OK;
942 /**************************************************************************
943 * IShellExecuteHookW Implementation
946 static HRESULT WINAPI IShellExecuteHookW_fnQueryInterface(
947 IShellExecuteHookW* iface, REFIID riid, void** ppvObject)
949 ICPanelImpl *This = impl_from_IShellExecuteHookW(iface);
951 TRACE("(%p)->(count=%u)\n", This, This->ref);
953 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObject);
956 static ULONG STDMETHODCALLTYPE IShellExecuteHookW_fnAddRef(IShellExecuteHookW* iface)
958 ICPanelImpl *This = impl_from_IShellExecuteHookW(iface);
960 TRACE("(%p)->(count=%u)\n", This, This->ref);
962 return IUnknown_AddRef(This->pUnkOuter);
965 static ULONG STDMETHODCALLTYPE IShellExecuteHookW_fnRelease(IShellExecuteHookW* iface)
967 ICPanelImpl *This = impl_from_IShellExecuteHookW(iface);
969 TRACE("(%p)\n", This);
971 return IUnknown_Release(This->pUnkOuter);
974 static HRESULT WINAPI IShellExecuteHookW_fnExecute(IShellExecuteHookW* iface, LPSHELLEXECUTEINFOW psei)
976 static const WCHAR wCplopen[] = {'c','p','l','o','p','e','n','\0'};
977 ICPanelImpl *This = (ICPanelImpl *)iface;
979 SHELLEXECUTEINFOW sei_tmp;
980 PIDLCPanelStruct* pcpanel;
981 WCHAR path[MAX_PATH];
982 WCHAR params[MAX_PATH];
983 BOOL ret;
984 int l;
986 TRACE("(%p)->execute(%p)\n", This, psei);
988 if (!psei)
989 return E_INVALIDARG;
991 pcpanel = _ILGetCPanelPointer(ILFindLastID(psei->lpIDList));
993 if (!pcpanel)
994 return E_INVALIDARG;
996 path[0] = '\"';
997 /* Return value from MultiByteToWideChar includes terminating NUL, which
998 * compensates for the starting double quote we just put in */
999 l = MultiByteToWideChar(CP_ACP, 0, pcpanel->szName, -1, path+1, MAX_PATH-1);
1001 /* pass applet name to Control_RunDLL to distinguish between applets in one .cpl file */
1002 path[l++] = '"';
1003 path[l] = '\0';
1005 MultiByteToWideChar(CP_ACP, 0, pcpanel->szName+pcpanel->offsDispName, -1, params, MAX_PATH);
1007 sei_tmp = *psei;
1008 sei_tmp.lpFile = path;
1009 sei_tmp.lpParameters = params;
1010 sei_tmp.fMask &= ~SEE_MASK_INVOKEIDLIST;
1011 sei_tmp.lpVerb = wCplopen;
1013 ret = ShellExecuteExW(&sei_tmp);
1014 if (ret)
1015 return S_OK;
1016 else
1017 return S_FALSE;
1020 static const IShellExecuteHookWVtbl vt_ShellExecuteHookW =
1023 IShellExecuteHookW_fnQueryInterface,
1024 IShellExecuteHookW_fnAddRef,
1025 IShellExecuteHookW_fnRelease,
1027 IShellExecuteHookW_fnExecute
1031 /**************************************************************************
1032 * IShellExecuteHookA Implementation
1035 static HRESULT WINAPI IShellExecuteHookA_fnQueryInterface(IShellExecuteHookA* iface, REFIID riid, void** ppvObject)
1037 ICPanelImpl *This = impl_from_IShellExecuteHookA(iface);
1039 TRACE("(%p)->(count=%u)\n", This, This->ref);
1041 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObject);
1044 static ULONG STDMETHODCALLTYPE IShellExecuteHookA_fnAddRef(IShellExecuteHookA* iface)
1046 ICPanelImpl *This = impl_from_IShellExecuteHookA(iface);
1048 TRACE("(%p)->(count=%u)\n", This, This->ref);
1050 return IUnknown_AddRef(This->pUnkOuter);
1053 static ULONG STDMETHODCALLTYPE IShellExecuteHookA_fnRelease(IShellExecuteHookA* iface)
1055 ICPanelImpl *This = impl_from_IShellExecuteHookA(iface);
1057 TRACE("(%p)\n", This);
1059 return IUnknown_Release(This->pUnkOuter);
1062 static HRESULT WINAPI IShellExecuteHookA_fnExecute(IShellExecuteHookA* iface, LPSHELLEXECUTEINFOA psei)
1064 ICPanelImpl *This = (ICPanelImpl *)iface;
1066 SHELLEXECUTEINFOA sei_tmp;
1067 PIDLCPanelStruct* pcpanel;
1068 char path[MAX_PATH];
1069 BOOL ret;
1071 TRACE("(%p)->execute(%p)\n", This, psei);
1073 if (!psei)
1074 return E_INVALIDARG;
1076 pcpanel = _ILGetCPanelPointer(ILFindLastID(psei->lpIDList));
1078 if (!pcpanel)
1079 return E_INVALIDARG;
1081 path[0] = '\"';
1082 lstrcpyA(path+1, pcpanel->szName);
1084 /* pass applet name to Control_RunDLL to distinguish between applets in one .cpl file */
1085 lstrcatA(path, "\" ");
1086 lstrcatA(path, pcpanel->szName+pcpanel->offsDispName);
1088 sei_tmp = *psei;
1089 sei_tmp.lpFile = path;
1090 sei_tmp.fMask &= ~SEE_MASK_INVOKEIDLIST;
1092 ret = ShellExecuteExA(&sei_tmp);
1093 if (ret)
1094 return S_OK;
1095 else
1096 return S_FALSE;
1099 static const IShellExecuteHookAVtbl vt_ShellExecuteHookA =
1101 IShellExecuteHookA_fnQueryInterface,
1102 IShellExecuteHookA_fnAddRef,
1103 IShellExecuteHookA_fnRelease,
1104 IShellExecuteHookA_fnExecute