Match class name used by Windows.
[wine] / dlls / shell32 / shlfsbind.c
1 /*
2  * File System Bind Data object to use as parameter for the bind context to
3  * IShellFolder_ParseDisplayName
4  *
5  * Copyright 2003 Rolf Kalbermatter
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 <stdarg.h>
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winreg.h"
30 #include "winuser.h"
31 #include "shlobj.h"
32 #include "shell32_main.h"
33
34 #include "debughlp.h"
35 #include "wine/debug.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(pidl);
38
39 /***********************************************************************
40  * IFileSystemBindData implementation
41  */
42 typedef struct
43 {
44         IFileSystemBindDataVtbl *lpVtbl;
45         DWORD              ref;
46         WIN32_FIND_DATAW findFile;
47 } IFileSystemBindDataImpl;
48
49 static HRESULT WINAPI IFileSystemBindData_fnQueryInterface(IFileSystemBindData *iface, REFIID riid, LPVOID* ppvObj);
50 static ULONG WINAPI IFileSystemBindData_fnAddRef(IFileSystemBindData *iface);
51 static ULONG WINAPI IFileSystemBindData_fnRelease(IFileSystemBindData *iface);
52 static HRESULT WINAPI IFileSystemBindData_fnGetFindData(IFileSystemBindData *iface, WIN32_FIND_DATAW *pfd);
53 static HRESULT WINAPI IFileSystemBindData_fnSetFindData(IFileSystemBindData *iface, const WIN32_FIND_DATAW *pfd);
54
55 static struct IFileSystemBindDataVtbl sbvt =
56 {
57     IFileSystemBindData_fnQueryInterface,
58     IFileSystemBindData_fnAddRef,
59     IFileSystemBindData_fnRelease,
60     IFileSystemBindData_fnSetFindData,
61     IFileSystemBindData_fnGetFindData,
62 };
63
64 static const WCHAR wFileSystemBindData[] = {'F','i','l','e',' ','S','y','s','t','e','m',' ','B','i','n','d','D','a','t','a',0};
65
66 HRESULT WINAPI IFileSystemBindData_Constructor(const WIN32_FIND_DATAW *pfd, LPBC *ppV)
67 {
68         IFileSystemBindDataImpl *sb;
69         HRESULT ret = E_OUTOFMEMORY;
70
71         TRACE("%p, %p\n", pfd, ppV);
72
73         if (!ppV)
74           return E_INVALIDARG;
75
76         *ppV = NULL;
77
78         sb = (IFileSystemBindDataImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IFileSystemBindDataImpl));
79         if (!sb)
80           return ret;
81
82         sb->lpVtbl = &sbvt;
83         sb->ref = 1;
84         IFileSystemBindData_fnSetFindData((IFileSystemBindData*)sb, pfd);
85
86         ret = CreateBindCtx(0, ppV);
87         if (SUCCEEDED(ret))
88         {
89           BIND_OPTS bindOpts;
90           bindOpts.cbStruct = sizeof(BIND_OPTS);
91           bindOpts.grfFlags = 0;
92           bindOpts.grfMode = STGM_CREATE;
93           bindOpts.dwTickCountDeadline = 0;
94           IBindCtx_SetBindOptions(*ppV, &bindOpts);
95           IBindCtx_RegisterObjectParam(*ppV, (LPOLESTR)wFileSystemBindData, (LPUNKNOWN)sb);
96
97           IFileSystemBindData_Release((IFileSystemBindData*)sb);
98         }
99         else
100           HeapFree(GetProcessHeap(), 0, sb);
101         return ret;
102 }
103
104 HRESULT WINAPI FileSystemBindData_GetFindData(LPBC pbc, WIN32_FIND_DATAW *pfd)
105 {
106         LPUNKNOWN pUnk;
107         IFileSystemBindData *pfsbd = NULL;
108         HRESULT ret;
109
110         TRACE("%p, %p\n", pbc, pfd);
111
112         if (!pfd)
113           return E_INVALIDARG;
114
115         ret = IBindCtx_GetObjectParam(pbc, (LPOLESTR)wFileSystemBindData, &pUnk);
116         if (SUCCEEDED(ret))
117         {
118           ret = IUnknown_QueryInterface(pUnk, &IID_IFileSystemBindData, (LPVOID *)&pfsbd);
119           if (SUCCEEDED(ret))
120           {
121             ret = IFileSystemBindData_GetFindData(pfsbd, pfd);
122             IFileSystemBindData_Release(pfsbd);
123           }
124           IUnknown_Release(pUnk);
125         }
126         return ret;
127 }
128
129 HRESULT WINAPI FileSystemBindData_SetFindData(LPBC pbc, const WIN32_FIND_DATAW *pfd)
130 {
131         LPUNKNOWN pUnk;
132         IFileSystemBindData *pfsbd = NULL;
133         HRESULT ret;
134         
135         TRACE("%p, %p\n", pbc, pfd);
136
137         ret = IBindCtx_GetObjectParam(pbc, (LPOLESTR)wFileSystemBindData, &pUnk);
138         if (SUCCEEDED(ret))
139         {
140           ret = IUnknown_QueryInterface(pUnk, &IID_IFileSystemBindData, (LPVOID *)&pfsbd);
141           if (SUCCEEDED(ret))
142           {
143             ret = IFileSystemBindData_SetFindData(pfsbd, pfd);
144             IFileSystemBindData_Release(pfsbd);
145           }
146           IUnknown_Release(pUnk);
147         }
148         return ret;}
149
150
151
152 static HRESULT WINAPI IFileSystemBindData_fnQueryInterface(IFileSystemBindData *iface, REFIID riid, LPVOID *ppV)
153 {
154         IFileSystemBindDataImpl *This = (IFileSystemBindDataImpl *)iface;
155         TRACE("(%p)->(\n\tIID:\t%s, %p)\n", This, debugstr_guid(riid), ppV);
156
157         *ppV = NULL;
158
159         if (IsEqualIID(riid, &IID_IUnknown))
160         {
161           *ppV = This;
162         }
163         else if (IsEqualIID(riid, &IID_IFileSystemBindData))
164         {
165           *ppV = (IFileSystemBindData*)This;
166         }
167
168         if (*ppV)
169         {
170           IUnknown_AddRef((IUnknown*)(*ppV));
171           TRACE("-- Interface: (%p)->(%p)\n", ppV, *ppV);
172           return S_OK;
173         }
174         TRACE("-- Interface: E_NOINTERFACE\n");
175         return E_NOINTERFACE;
176 }
177
178 static ULONG WINAPI IFileSystemBindData_fnAddRef(IFileSystemBindData *iface)
179 {
180         IFileSystemBindDataImpl *This = (IFileSystemBindDataImpl *)iface;
181         TRACE("(%p)\n", This);
182         return InterlockedIncrement(&This->ref);
183 }
184
185 static ULONG WINAPI IFileSystemBindData_fnRelease(IFileSystemBindData *iface)
186 {
187         IFileSystemBindDataImpl *This = (IFileSystemBindDataImpl *)iface;
188         TRACE("(%p)\n", This);
189
190         if (!InterlockedDecrement(&This->ref))
191         {
192           TRACE(" destroying ISFBindPidl(%p)\n",This);
193           HeapFree(GetProcessHeap(), 0, This);
194           return 0;
195         }
196         return This->ref;
197 }
198
199 static HRESULT WINAPI IFileSystemBindData_fnGetFindData(IFileSystemBindData *iface, WIN32_FIND_DATAW *pfd)
200 {
201         IFileSystemBindDataImpl *This = (IFileSystemBindDataImpl *)iface;
202         TRACE("(%p), %p\n", This, pfd);
203
204         if (!pfd)
205           return E_INVALIDARG;
206
207         memcpy(pfd, &This->findFile, sizeof(WIN32_FIND_DATAW));
208         return NOERROR;
209 }
210
211 static HRESULT WINAPI IFileSystemBindData_fnSetFindData(IFileSystemBindData *iface, const WIN32_FIND_DATAW *pfd)
212 {
213         IFileSystemBindDataImpl *This = (IFileSystemBindDataImpl *)iface;
214         TRACE("(%p), %p\n", This, pfd);
215
216         if (pfd)
217           memcpy(&This->findFile, pfd, sizeof(WIN32_FIND_DATAW));
218         else
219           memset(&This->findFile, 0, sizeof(WIN32_FIND_DATAW));
220         return NOERROR;
221 }