spoolss/tests: Change skip() to win_skip().
[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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  *
21  */
22 #include "config.h"
23 #include "wine/port.h"
24
25 #include <stdarg.h>
26
27 #define COBJMACROS
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winuser.h"
32 #include "shlobj.h"
33 #include "shell32_main.h"
34
35 #include "wine/debug.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(pidl);
38
39 /***********************************************************************
40  * IFileSystemBindData implementation
41  */
42 typedef struct
43 {
44     IFileSystemBindData IFileSystemBindData_iface;
45     LONG ref;
46     WIN32_FIND_DATAW findFile;
47 } IFileSystemBindDataImpl;
48
49 static inline IFileSystemBindDataImpl *impl_from_IFileSystemBindData(IFileSystemBindData *iface)
50 {
51     return CONTAINING_RECORD(iface, IFileSystemBindDataImpl, IFileSystemBindData_iface);
52 }
53
54 static HRESULT WINAPI IFileSystemBindData_fnQueryInterface(IFileSystemBindData *, REFIID, LPVOID*);
55 static ULONG WINAPI IFileSystemBindData_fnAddRef(IFileSystemBindData *);
56 static ULONG WINAPI IFileSystemBindData_fnRelease(IFileSystemBindData *);
57 static HRESULT WINAPI IFileSystemBindData_fnGetFindData(IFileSystemBindData *, WIN32_FIND_DATAW *);
58 static HRESULT WINAPI IFileSystemBindData_fnSetFindData(IFileSystemBindData *, const WIN32_FIND_DATAW *);
59
60 static const IFileSystemBindDataVtbl sbvt =
61 {
62     IFileSystemBindData_fnQueryInterface,
63     IFileSystemBindData_fnAddRef,
64     IFileSystemBindData_fnRelease,
65     IFileSystemBindData_fnSetFindData,
66     IFileSystemBindData_fnGetFindData,
67 };
68
69 static const WCHAR wFileSystemBindData[] = {
70     'F','i','l','e',' ','S','y','s','t','e','m',' ','B','i','n','d',' ','D','a','t','a',0};
71
72 HRESULT WINAPI IFileSystemBindData_Constructor(const WIN32_FIND_DATAW *pfd, LPBC *ppV)
73 {
74     IFileSystemBindDataImpl *sb;
75     HRESULT ret = E_OUTOFMEMORY;
76
77     TRACE("%p, %p\n", pfd, ppV);
78
79     if (!ppV)
80        return E_INVALIDARG;
81
82     *ppV = NULL;
83
84     sb = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IFileSystemBindDataImpl));
85     if (!sb)
86         return ret;
87
88     sb->IFileSystemBindData_iface.lpVtbl = &sbvt;
89     sb->ref = 1;
90     IFileSystemBindData_fnSetFindData(&sb->IFileSystemBindData_iface, pfd);
91
92     ret = CreateBindCtx(0, ppV);
93     if (SUCCEEDED(ret))
94     {
95         BIND_OPTS bindOpts;
96
97         bindOpts.cbStruct = sizeof(BIND_OPTS);
98         bindOpts.grfFlags = 0;
99         bindOpts.grfMode = STGM_CREATE;
100         bindOpts.dwTickCountDeadline = 0;
101         IBindCtx_SetBindOptions(*ppV, &bindOpts);
102         IBindCtx_RegisterObjectParam(*ppV, (LPOLESTR)wFileSystemBindData, (LPUNKNOWN)sb);
103
104         IFileSystemBindData_Release(&sb->IFileSystemBindData_iface);
105     }
106     else
107         HeapFree(GetProcessHeap(), 0, sb);
108     return ret;
109 }
110
111 static HRESULT WINAPI IFileSystemBindData_fnQueryInterface(
112                 IFileSystemBindData *iface, REFIID riid, LPVOID *ppV)
113 {
114     IFileSystemBindDataImpl *This = impl_from_IFileSystemBindData(iface);
115     TRACE("(%p)->(\n\tIID:\t%s, %p)\n", This, debugstr_guid(riid), ppV);
116
117     *ppV = NULL;
118
119     if (IsEqualIID(riid, &IID_IUnknown))
120         *ppV = This;
121     else if (IsEqualIID(riid, &IID_IFileSystemBindData))
122         *ppV = This;
123
124     if (*ppV)
125     {
126         IUnknown_AddRef((IUnknown*)(*ppV));
127         TRACE("-- Interface: (%p)->(%p)\n", ppV, *ppV);
128         return S_OK;
129     }
130     TRACE("-- Interface: E_NOINTERFACE\n");
131     return E_NOINTERFACE;
132 }
133
134 static ULONG WINAPI IFileSystemBindData_fnAddRef(IFileSystemBindData *iface)
135 {
136     IFileSystemBindDataImpl *This = impl_from_IFileSystemBindData(iface);
137     ULONG refCount = InterlockedIncrement(&This->ref);
138
139     TRACE("(%p)->(count=%i)\n", This, refCount - 1);
140
141     return refCount;
142 }
143
144 static ULONG WINAPI IFileSystemBindData_fnRelease(IFileSystemBindData *iface)
145 {
146     IFileSystemBindDataImpl *This = impl_from_IFileSystemBindData(iface);
147     ULONG refCount = InterlockedDecrement(&This->ref);
148
149     TRACE("(%p)->(count=%i)\n", This, refCount + 1);
150
151     if (!refCount)
152     {
153         TRACE(" destroying ISFBindPidl(%p)\n",This);
154         HeapFree(GetProcessHeap(), 0, This);
155     }
156     return refCount;
157 }
158
159 static HRESULT WINAPI IFileSystemBindData_fnGetFindData(
160                IFileSystemBindData *iface, WIN32_FIND_DATAW *pfd)
161 {
162     IFileSystemBindDataImpl *This = impl_from_IFileSystemBindData(iface);
163     TRACE("(%p), %p\n", This, pfd);
164
165     if (!pfd)
166         return E_INVALIDARG;
167
168     *pfd = This->findFile;
169     return NOERROR;
170 }
171
172 static HRESULT WINAPI IFileSystemBindData_fnSetFindData(
173                IFileSystemBindData *iface, const WIN32_FIND_DATAW *pfd)
174 {
175     IFileSystemBindDataImpl *This = impl_from_IFileSystemBindData(iface);
176     TRACE("(%p), %p\n", This, pfd);
177
178     if (pfd)
179         This->findFile = *pfd;
180     else
181         memset(&This->findFile, 0, sizeof(WIN32_FIND_DATAW));
182     return NOERROR;
183 }