winedbg: Don't dereference possibly NULL thread pointer.
[wine/zf.git] / dlls / shell32 / shfldr_printers.c
blob8e25e58857bb94788ce8b41deb2e4d56e0c5c01d
1 /*
2 * Virtual Printers folder
4 * Copyright 2010 Nikolay Sivov for CodeWeavers
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 <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include "winerror.h"
27 #include "windef.h"
28 #include "winbase.h"
30 #include "shell32_main.h"
31 #include "wine/debug.h"
32 #include "debughlp.h"
34 #include "shresdef.h"
35 #include "shfldr.h"
37 WINE_DEFAULT_DEBUG_CHANNEL (shell);
39 typedef struct {
40 IShellFolder2 IShellFolder2_iface;
41 IPersistFolder2 IPersistFolder2_iface;
42 LONG ref;
44 LPITEMIDLIST pidl;
45 } IPrintersFolderImpl;
47 static inline IPrintersFolderImpl *impl_from_IShellFolder2(IShellFolder2 *iface)
49 return CONTAINING_RECORD(iface, IPrintersFolderImpl, IShellFolder2_iface);
52 static inline IPrintersFolderImpl *impl_from_IPersistFolder2(IPersistFolder2 *iface)
54 return CONTAINING_RECORD(iface, IPrintersFolderImpl, IPersistFolder2_iface);
57 static const shvheader printers_header[] = {
58 { &FMTID_Storage, PID_STG_NAME, IDS_SHV_COLUMN8, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_LEFT, 20 },
59 { NULL, 0, IDS_SHV_COL_DOCS, SHCOLSTATE_TYPE_INT | SHCOLSTATE_ONBYDEFAULT, LVCFMT_LEFT, 12 },
60 { NULL, 0, IDS_SHV_COL_STATUS, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_LEFT, 12 },
61 { &FMTID_SummaryInformation, PIDSI_COMMENTS, IDS_SHV_COLUMN9, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_LEFT, 30 },
62 { NULL, 0, IDS_SHV_COL_LOCATION, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_LEFT, 20 },
63 { NULL, 0, IDS_SHV_COL_MODEL, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_LEFT, 20 }
66 static HRESULT WINAPI IShellFolder_Printers_fnQueryInterface(IShellFolder2 *iface,
67 REFIID riid, LPVOID *ppvObj)
69 IPrintersFolderImpl *This = impl_from_IShellFolder2(iface);
71 TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
73 *ppvObj = NULL;
75 if (IsEqualIID (riid, &IID_IUnknown) ||
76 IsEqualIID (riid, &IID_IShellFolder) ||
77 IsEqualIID (riid, &IID_IShellFolder2))
79 *ppvObj = &This->IShellFolder2_iface;
81 else if (IsEqualIID (riid, &IID_IPersist) ||
82 IsEqualIID (riid, &IID_IPersistFolder) ||
83 IsEqualIID (riid, &IID_IPersistFolder2))
85 *ppvObj = &This->IPersistFolder2_iface;
88 if (*ppvObj)
90 IUnknown_AddRef ((IUnknown *) (*ppvObj));
91 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
92 return S_OK;
95 ERR ("-- interface %s not supported\n", shdebugstr_guid (riid));
96 return E_NOINTERFACE;
99 static ULONG WINAPI IShellFolder_Printers_fnAddRef (IShellFolder2 * iface)
101 IPrintersFolderImpl *This = impl_from_IShellFolder2(iface);
102 ULONG refCount = InterlockedIncrement(&This->ref);
103 TRACE ("(%p)->(count=%u)\n", This, refCount - 1);
104 return refCount;
107 static ULONG WINAPI IShellFolder_Printers_fnRelease (IShellFolder2 * iface)
109 IPrintersFolderImpl *This = impl_from_IShellFolder2(iface);
110 ULONG refCount = InterlockedDecrement(&This->ref);
112 TRACE ("(%p)->(count=%u)\n", This, refCount + 1);
114 if (!refCount)
116 TRACE ("-- destroying IShellFolder(%p)\n", This);
117 SHFree(This->pidl);
118 LocalFree (This);
120 return refCount;
123 static HRESULT WINAPI IShellFolder_Printers_fnParseDisplayName (IShellFolder2 *iface,
124 HWND hwndOwner, LPBC pbc, LPOLESTR lpszDisplayName,
125 DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
127 IPrintersFolderImpl *This = impl_from_IShellFolder2(iface);
129 FIXME("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p) stub\n", This,
130 hwndOwner, pbc, lpszDisplayName, debugstr_w (lpszDisplayName),
131 pchEaten, ppidl, pdwAttributes);
133 return E_NOTIMPL;
136 static HRESULT WINAPI IShellFolder_Printers_fnEnumObjects (IShellFolder2 *iface,
137 HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST *ppEnumIDList)
139 IPrintersFolderImpl *This = impl_from_IShellFolder2(iface);
140 FIXME("(%p)->(HWND=%p flags=0x%08x pplist=%p) stub\n", This,
141 hwndOwner, dwFlags, ppEnumIDList);
142 return E_NOTIMPL;
145 static HRESULT WINAPI IShellFolder_Printers_fnBindToObject (IShellFolder2 *iface,
146 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
148 IPrintersFolderImpl *This = impl_from_IShellFolder2(iface);
149 FIXME("(%p)->(pidl=%p,%p,%s,%p) stub\n", This,
150 pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
151 return E_NOTIMPL;
154 static HRESULT WINAPI IShellFolder_Printers_fnBindToStorage (IShellFolder2 * iface,
155 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
157 IPrintersFolderImpl *This = impl_from_IShellFolder2(iface);
159 FIXME("(%p)->(pidl=%p,%p,%s,%p) stub\n", This,
160 pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
162 *ppvOut = NULL;
163 return E_NOTIMPL;
166 static HRESULT WINAPI IShellFolder_Printers_fnCompareIDs(IShellFolder2 *iface,
167 LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
169 IPrintersFolderImpl *This = impl_from_IShellFolder2(iface);
170 FIXME("(%p)->(0x%08lx,pidl1=%p,pidl2=%p) stub\n", This, lParam, pidl1, pidl2);
171 return E_NOTIMPL;
174 static HRESULT WINAPI IShellFolder_Printers_fnCreateViewObject(IShellFolder2 *iface,
175 HWND hwndOwner, REFIID riid, LPVOID *ppvOut)
177 IPrintersFolderImpl *This = impl_from_IShellFolder2(iface);
178 HRESULT hr = E_NOTIMPL;
180 TRACE("(%p)->(hwnd=%p,%s,%p)\n", This,
181 hwndOwner, shdebugstr_guid (riid), ppvOut);
183 if (!ppvOut)
184 return E_INVALIDARG;
186 *ppvOut = NULL;
188 if (IsEqualIID (riid, &IID_IShellView))
190 IShellView *pShellView = IShellView_Constructor ((IShellFolder *) iface);
191 if (pShellView)
193 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
194 IShellView_Release (pShellView);
197 else
198 WARN("unsupported interface %s\n", shdebugstr_guid (riid));
200 return hr;
203 static HRESULT WINAPI IShellFolder_Printers_fnGetAttributesOf (IShellFolder2 * iface,
204 UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
206 IPrintersFolderImpl *This = impl_from_IShellFolder2(iface);
207 FIXME("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x)) stub\n",
208 This, cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0);
209 return E_NOTIMPL;
212 static HRESULT WINAPI IShellFolder_Printers_fnGetUIObjectOf (IShellFolder2 * iface,
213 HWND hwndOwner, UINT cidl, LPCITEMIDLIST * apidl, REFIID riid,
214 UINT * prgfInOut, LPVOID * ppvOut)
216 IPrintersFolderImpl *This = impl_from_IShellFolder2(iface);
218 FIXME("(%p)->(%p,%u,apidl=%p,%s,%p,%p) stub\n", This,
219 hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
221 if (!ppvOut)
222 return E_INVALIDARG;
224 *ppvOut = NULL;
226 return E_NOTIMPL;
229 static HRESULT WINAPI IShellFolder_Printers_fnGetDisplayNameOf (IShellFolder2 *iface,
230 LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
232 IPrintersFolderImpl *This = impl_from_IShellFolder2(iface);
234 FIXME("(%p)->(pidl=%p,0x%08x,%p) stub\n", This, pidl, dwFlags, strRet);
236 if (!strRet)
237 return E_INVALIDARG;
239 return E_NOTIMPL;
242 static HRESULT WINAPI IShellFolder_Printers_fnSetNameOf (
243 IShellFolder2 * iface, HWND hwndOwner, LPCITEMIDLIST pidl,
244 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
246 IPrintersFolderImpl *This = impl_from_IShellFolder2(iface);
247 FIXME ("(%p)->(%p,pidl=%p,%s,%u,%p) stub\n", This,
248 hwndOwner, pidl, debugstr_w (lpName), dwFlags, pPidlOut);
249 return E_FAIL;
252 static HRESULT WINAPI IShellFolder_Printers_fnGetDefaultSearchGUID(IShellFolder2 *iface, GUID *guid)
254 IPrintersFolderImpl *This = impl_from_IShellFolder2(iface);
255 TRACE("(%p)->(%p)\n", This, guid);
256 return E_NOTIMPL;
259 static HRESULT WINAPI IShellFolder_Printers_fnEnumSearches (
260 IShellFolder2 * iface, IEnumExtraSearch ** ppenum)
262 IPrintersFolderImpl *This = impl_from_IShellFolder2(iface);
263 FIXME ("(%p) stub\n", This);
264 return E_NOTIMPL;
267 static HRESULT WINAPI IShellFolder_Printers_fnGetDefaultColumn(IShellFolder2 *iface, DWORD reserved,
268 ULONG *sort, ULONG *display)
270 IPrintersFolderImpl *This = impl_from_IShellFolder2(iface);
272 TRACE("(%p)->(%#x, %p, %p)\n", This, reserved, sort, display);
274 return E_NOTIMPL;
277 static HRESULT WINAPI IShellFolder_Printers_fnGetDefaultColumnState (
278 IShellFolder2 *iface, UINT iColumn, DWORD *pcsFlags)
280 IPrintersFolderImpl *This = impl_from_IShellFolder2(iface);
282 TRACE("(%p)->(%d %p)\n", This, iColumn, pcsFlags);
284 if (iColumn >= ARRAY_SIZE(printers_header))
285 return E_INVALIDARG;
287 *pcsFlags = printers_header[iColumn].pcsFlags;
289 return S_OK;
292 static HRESULT WINAPI IShellFolder_Printers_fnGetDetailsEx (IShellFolder2 * iface,
293 LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
295 IPrintersFolderImpl *This = impl_from_IShellFolder2(iface);
296 FIXME ("(%p) stub\n", This);
297 return E_NOTIMPL;
300 static HRESULT WINAPI IShellFolder_Printers_fnGetDetailsOf (IShellFolder2 *iface,
301 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS *psd)
303 IPrintersFolderImpl *This = impl_from_IShellFolder2(iface);
305 TRACE("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
307 if (iColumn >= ARRAY_SIZE(printers_header))
308 return E_NOTIMPL;
310 if (!pidl)
311 return SHELL32_GetColumnDetails(printers_header, iColumn, psd);
313 FIXME("unimplemented for supplied pidl\n");
315 return E_NOTIMPL;
318 static HRESULT WINAPI IShellFolder_Printers_fnMapColumnToSCID (IShellFolder2 *iface, UINT column, SHCOLUMNID *scid)
320 IPrintersFolderImpl *This = impl_from_IShellFolder2(iface);
322 TRACE("(%p)->(%u %p)\n", This, column, scid);
324 if (column >= ARRAY_SIZE(printers_header))
325 return E_INVALIDARG;
327 return shellfolder_map_column_to_scid(printers_header, column, scid);
330 static const IShellFolder2Vtbl vtbl_ShellFolder2 =
332 /* IUnknown */
333 IShellFolder_Printers_fnQueryInterface,
334 IShellFolder_Printers_fnAddRef,
335 IShellFolder_Printers_fnRelease,
336 /* IShellFolder */
337 IShellFolder_Printers_fnParseDisplayName,
338 IShellFolder_Printers_fnEnumObjects,
339 IShellFolder_Printers_fnBindToObject,
340 IShellFolder_Printers_fnBindToStorage,
341 IShellFolder_Printers_fnCompareIDs,
342 IShellFolder_Printers_fnCreateViewObject,
343 IShellFolder_Printers_fnGetAttributesOf,
344 IShellFolder_Printers_fnGetUIObjectOf,
345 IShellFolder_Printers_fnGetDisplayNameOf,
346 IShellFolder_Printers_fnSetNameOf,
347 /* IShellFolder2 */
348 IShellFolder_Printers_fnGetDefaultSearchGUID,
349 IShellFolder_Printers_fnEnumSearches,
350 IShellFolder_Printers_fnGetDefaultColumn,
351 IShellFolder_Printers_fnGetDefaultColumnState,
352 IShellFolder_Printers_fnGetDetailsEx,
353 IShellFolder_Printers_fnGetDetailsOf,
354 IShellFolder_Printers_fnMapColumnToSCID
357 /*** IPersistFolder2 ***/
358 static HRESULT WINAPI IPersistFolder2_Printers_fnQueryInterface(IPersistFolder2 * iface,
359 REFIID iid, LPVOID * ppvObj)
361 IPrintersFolderImpl *This = impl_from_IPersistFolder2(iface);
362 return IShellFolder2_QueryInterface(&This->IShellFolder2_iface, iid, ppvObj);
365 static ULONG WINAPI IPersistFolder2_Printers_fnAddRef(IPersistFolder2 *iface)
367 IPrintersFolderImpl *This = impl_from_IPersistFolder2(iface);
368 return IShellFolder2_AddRef(&This->IShellFolder2_iface);
371 static ULONG WINAPI IPersistFolder2_Printers_fnRelease(IPersistFolder2 *iface)
373 IPrintersFolderImpl *This = impl_from_IPersistFolder2(iface);
374 return IShellFolder2_Release(&This->IShellFolder2_iface);
377 static HRESULT WINAPI IPersistFolder2_Printers_fnGetClassID(IPersistFolder2 *iface, CLSID *classId)
379 IPrintersFolderImpl *This = impl_from_IPersistFolder2(iface);
381 FIXME("(%p) stub\n", This);
383 if (!classId)
384 return E_POINTER;
386 return E_NOTIMPL;
389 static HRESULT WINAPI IPersistFolder2_Printers_fnInitialize(IPersistFolder2 *iface, LPCITEMIDLIST pidl)
391 IPrintersFolderImpl *This = impl_from_IPersistFolder2(iface);
393 TRACE("(%p)->(%p)\n", This, pidl);
395 SHFree(This->pidl);
396 This->pidl = ILClone(pidl);
398 return S_OK;
401 static HRESULT WINAPI IPersistFolder2_Printers_fnGetCurFolder(IPersistFolder2 *iface, LPITEMIDLIST *pidl)
403 IPrintersFolderImpl *This = impl_from_IPersistFolder2(iface);
405 TRACE("(%p)->(%p)\n", This, pidl);
407 *pidl = ILClone(This->pidl);
409 return *pidl ? S_OK : S_FALSE;
412 static const IPersistFolder2Vtbl vtbl_PersistFolder2 =
414 IPersistFolder2_Printers_fnQueryInterface,
415 IPersistFolder2_Printers_fnAddRef,
416 IPersistFolder2_Printers_fnRelease,
417 IPersistFolder2_Printers_fnGetClassID,
418 IPersistFolder2_Printers_fnInitialize,
419 IPersistFolder2_Printers_fnGetCurFolder
422 HRESULT WINAPI Printers_Constructor(IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
424 IPrintersFolderImpl *sf;
426 TRACE("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
428 if (!ppv)
429 return E_POINTER;
430 if (pUnkOuter)
431 return CLASS_E_NOAGGREGATION;
433 sf = LocalAlloc(LMEM_FIXED, sizeof(IPrintersFolderImpl));
434 if (!sf)
435 return E_OUTOFMEMORY;
437 sf->ref = 0;
438 sf->pidl = NULL;
439 sf->IShellFolder2_iface.lpVtbl = &vtbl_ShellFolder2;
440 sf->IPersistFolder2_iface.lpVtbl = &vtbl_PersistFolder2;
442 if (IShellFolder2_QueryInterface(&sf->IShellFolder2_iface, riid, ppv) != S_OK)
444 IShellFolder2_Release(&sf->IShellFolder2_iface);
445 return E_NOINTERFACE;
448 TRACE("--(%p)\n", sf);
449 return S_OK;