winecfg: Renamed 'Shell Folder' to 'Folder'.
[wine/multimedia.git] / dlls / shell32 / shlfsbind.c
blobaa4ce97d82a23f2517a95ca982fc9c80489d6329
1 /*
2 * File System Bind Data object to use as parameter for the bind context to
3 * IShellFolder_ParseDisplayName
5 * Copyright 2003 Rolf Kalbermatter
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <stdarg.h>
27 #define COBJMACROS
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winuser.h"
32 #include "shlobj.h"
33 #include "shell32_main.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(pidl);
39 /***********************************************************************
40 * IFileSystemBindData implementation
42 typedef struct
44 const IFileSystemBindDataVtbl *lpVtbl;
45 LONG ref;
46 WIN32_FIND_DATAW findFile;
47 } IFileSystemBindDataImpl;
49 static HRESULT WINAPI IFileSystemBindData_fnQueryInterface(IFileSystemBindData *, REFIID, LPVOID*);
50 static ULONG WINAPI IFileSystemBindData_fnAddRef(IFileSystemBindData *);
51 static ULONG WINAPI IFileSystemBindData_fnRelease(IFileSystemBindData *);
52 static HRESULT WINAPI IFileSystemBindData_fnGetFindData(IFileSystemBindData *, WIN32_FIND_DATAW *);
53 static HRESULT WINAPI IFileSystemBindData_fnSetFindData(IFileSystemBindData *, const WIN32_FIND_DATAW *);
55 static const IFileSystemBindDataVtbl sbvt =
57 IFileSystemBindData_fnQueryInterface,
58 IFileSystemBindData_fnAddRef,
59 IFileSystemBindData_fnRelease,
60 IFileSystemBindData_fnSetFindData,
61 IFileSystemBindData_fnGetFindData,
64 static const WCHAR wFileSystemBindData[] = {
65 'F','i','l','e',' ','S','y','s','t','e','m',' ','B','i','n','d','D','a','t','a',0};
67 HRESULT WINAPI IFileSystemBindData_Constructor(const WIN32_FIND_DATAW *pfd, LPBC *ppV)
69 IFileSystemBindDataImpl *sb;
70 HRESULT ret = E_OUTOFMEMORY;
72 TRACE("%p, %p\n", pfd, ppV);
74 if (!ppV)
75 return E_INVALIDARG;
77 *ppV = NULL;
79 sb = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IFileSystemBindDataImpl));
80 if (!sb)
81 return ret;
83 sb->lpVtbl = &sbvt;
84 sb->ref = 1;
85 IFileSystemBindData_fnSetFindData((IFileSystemBindData*)sb, pfd);
87 ret = CreateBindCtx(0, ppV);
88 if (SUCCEEDED(ret))
90 BIND_OPTS bindOpts;
92 bindOpts.cbStruct = sizeof(BIND_OPTS);
93 bindOpts.grfFlags = 0;
94 bindOpts.grfMode = STGM_CREATE;
95 bindOpts.dwTickCountDeadline = 0;
96 IBindCtx_SetBindOptions(*ppV, &bindOpts);
97 IBindCtx_RegisterObjectParam(*ppV, (LPOLESTR)wFileSystemBindData, (LPUNKNOWN)sb);
99 IFileSystemBindData_Release((IFileSystemBindData*)sb);
101 else
102 HeapFree(GetProcessHeap(), 0, sb);
103 return ret;
106 HRESULT WINAPI FileSystemBindData_GetFindData(LPBC pbc, WIN32_FIND_DATAW *pfd)
108 LPUNKNOWN pUnk;
109 IFileSystemBindData *pfsbd = NULL;
110 HRESULT ret;
112 TRACE("%p, %p\n", pbc, pfd);
114 if (!pfd)
115 return E_INVALIDARG;
117 ret = IBindCtx_GetObjectParam(pbc, (LPOLESTR)wFileSystemBindData, &pUnk);
118 if (SUCCEEDED(ret))
120 ret = IUnknown_QueryInterface(pUnk, &IID_IFileSystemBindData, (LPVOID *)&pfsbd);
121 if (SUCCEEDED(ret))
123 ret = IFileSystemBindData_GetFindData(pfsbd, pfd);
124 IFileSystemBindData_Release(pfsbd);
126 IUnknown_Release(pUnk);
128 return ret;
131 HRESULT WINAPI FileSystemBindData_SetFindData(LPBC pbc, const WIN32_FIND_DATAW *pfd)
133 LPUNKNOWN pUnk;
134 IFileSystemBindData *pfsbd = NULL;
135 HRESULT ret;
137 TRACE("%p, %p\n", pbc, pfd);
139 ret = IBindCtx_GetObjectParam(pbc, (LPOLESTR)wFileSystemBindData, &pUnk);
140 if (SUCCEEDED(ret))
142 ret = IUnknown_QueryInterface(pUnk, &IID_IFileSystemBindData, (LPVOID *)&pfsbd);
143 if (SUCCEEDED(ret))
145 ret = IFileSystemBindData_SetFindData(pfsbd, pfd);
146 IFileSystemBindData_Release(pfsbd);
148 IUnknown_Release(pUnk);
150 return ret;
153 static HRESULT WINAPI IFileSystemBindData_fnQueryInterface(
154 IFileSystemBindData *iface, REFIID riid, LPVOID *ppV)
156 IFileSystemBindDataImpl *This = (IFileSystemBindDataImpl *)iface;
157 TRACE("(%p)->(\n\tIID:\t%s, %p)\n", This, debugstr_guid(riid), ppV);
159 *ppV = NULL;
161 if (IsEqualIID(riid, &IID_IUnknown))
162 *ppV = This;
163 else if (IsEqualIID(riid, &IID_IFileSystemBindData))
164 *ppV = (IFileSystemBindData*)This;
166 if (*ppV)
168 IUnknown_AddRef((IUnknown*)(*ppV));
169 TRACE("-- Interface: (%p)->(%p)\n", ppV, *ppV);
170 return S_OK;
172 TRACE("-- Interface: E_NOINTERFACE\n");
173 return E_NOINTERFACE;
176 static ULONG WINAPI IFileSystemBindData_fnAddRef(IFileSystemBindData *iface)
178 IFileSystemBindDataImpl *This = (IFileSystemBindDataImpl *)iface;
179 ULONG refCount = InterlockedIncrement(&This->ref);
181 TRACE("(%p)->(count=%i)\n", This, refCount - 1);
183 return refCount;
186 static ULONG WINAPI IFileSystemBindData_fnRelease(IFileSystemBindData *iface)
188 IFileSystemBindDataImpl *This = (IFileSystemBindDataImpl *)iface;
189 ULONG refCount = InterlockedDecrement(&This->ref);
191 TRACE("(%p)->(count=%i)\n", This, refCount + 1);
193 if (!refCount)
195 TRACE(" destroying ISFBindPidl(%p)\n",This);
196 HeapFree(GetProcessHeap(), 0, This);
198 return refCount;
201 static HRESULT WINAPI IFileSystemBindData_fnGetFindData(
202 IFileSystemBindData *iface, WIN32_FIND_DATAW *pfd)
204 IFileSystemBindDataImpl *This = (IFileSystemBindDataImpl *)iface;
205 TRACE("(%p), %p\n", This, pfd);
207 if (!pfd)
208 return E_INVALIDARG;
210 *pfd = This->findFile;
211 return NOERROR;
214 static HRESULT WINAPI IFileSystemBindData_fnSetFindData(
215 IFileSystemBindData *iface, const WIN32_FIND_DATAW *pfd)
217 IFileSystemBindDataImpl *This = (IFileSystemBindDataImpl *)iface;
218 TRACE("(%p), %p\n", This, pfd);
220 if (pfd)
221 This->findFile = *pfd;
222 else
223 memset(&This->findFile, 0, sizeof(WIN32_FIND_DATAW));
224 return NOERROR;