shell32/tests: Avoid testing that only certain services are requested by IObjectWithS...
[wine.git] / dlls / quartz / enumregfilters.c
blob42dccf3b625fd107c114183c8527c972084c0d03
1 /*
2 * Implementation of IEnumRegFilters Interface
4 * Copyright 2004 Christian Costa
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 "quartz_private.h"
24 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
28 typedef struct IEnumRegFiltersImpl
30 IEnumRegFilters IEnumRegFilters_iface;
31 LONG refCount;
32 ULONG size;
33 REGFILTER* RegFilters;
34 ULONG uIndex;
35 } IEnumRegFiltersImpl;
37 static inline IEnumRegFiltersImpl *impl_from_IEnumRegFilters(IEnumRegFilters *iface)
39 return CONTAINING_RECORD(iface, IEnumRegFiltersImpl, IEnumRegFilters_iface);
42 static const struct IEnumRegFiltersVtbl IEnumRegFiltersImpl_Vtbl;
44 HRESULT IEnumRegFiltersImpl_Construct(REGFILTER* pInRegFilters, const ULONG size, IEnumRegFilters ** ppEnum)
46 IEnumRegFiltersImpl* pEnumRegFilters;
47 REGFILTER* pRegFilters = NULL;
48 unsigned int i;
50 TRACE("(%p, %d, %p)\n", pInRegFilters, size, ppEnum);
52 pEnumRegFilters = CoTaskMemAlloc(sizeof(IEnumRegFiltersImpl));
53 if (!pEnumRegFilters)
55 *ppEnum = NULL;
56 return E_OUTOFMEMORY;
59 /* Accept size of 0 */
60 if (size)
62 pRegFilters = CoTaskMemAlloc(sizeof(REGFILTER)*size);
63 if (!pRegFilters)
65 CoTaskMemFree(pEnumRegFilters);
66 *ppEnum = NULL;
67 return E_OUTOFMEMORY;
71 for(i = 0; i < size; i++)
73 pRegFilters[i].Clsid = pInRegFilters[i].Clsid;
74 pRegFilters[i].Name = CoTaskMemAlloc((lstrlenW(pInRegFilters[i].Name)+1)*sizeof(WCHAR));
75 if (!pRegFilters[i].Name)
77 while(i)
78 CoTaskMemFree(pRegFilters[--i].Name);
79 CoTaskMemFree(pRegFilters);
80 CoTaskMemFree(pEnumRegFilters);
81 return E_OUTOFMEMORY;
83 CopyMemory(pRegFilters[i].Name, pInRegFilters[i].Name, (lstrlenW(pInRegFilters[i].Name)+1)*sizeof(WCHAR));
86 pEnumRegFilters->IEnumRegFilters_iface.lpVtbl = &IEnumRegFiltersImpl_Vtbl;
87 pEnumRegFilters->refCount = 1;
88 pEnumRegFilters->uIndex = 0;
89 pEnumRegFilters->RegFilters = pRegFilters;
90 pEnumRegFilters->size = size;
92 *ppEnum = &pEnumRegFilters->IEnumRegFilters_iface;
94 return S_OK;
97 static HRESULT WINAPI IEnumRegFiltersImpl_QueryInterface(IEnumRegFilters * iface, REFIID riid, LPVOID * ppv)
99 TRACE("(%p)->(%s, %p)\n", iface, qzdebugstr_guid(riid), ppv);
101 *ppv = NULL;
103 if (IsEqualIID(riid, &IID_IUnknown))
104 *ppv = iface;
105 else if (IsEqualIID(riid, &IID_IEnumRegFilters))
106 *ppv = iface;
108 if (*ppv)
110 IUnknown_AddRef((IUnknown *)(*ppv));
111 return S_OK;
114 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
116 return E_NOINTERFACE;
119 static ULONG WINAPI IEnumRegFiltersImpl_AddRef(IEnumRegFilters * iface)
121 IEnumRegFiltersImpl *This = impl_from_IEnumRegFilters(iface);
122 ULONG refCount = InterlockedIncrement(&This->refCount);
124 TRACE("(%p)\n", iface);
126 return refCount;
129 static ULONG WINAPI IEnumRegFiltersImpl_Release(IEnumRegFilters * iface)
131 IEnumRegFiltersImpl *This = impl_from_IEnumRegFilters(iface);
132 ULONG refCount = InterlockedDecrement(&This->refCount);
134 TRACE("(%p)\n", iface);
136 if (!refCount)
138 ULONG i;
140 for(i = 0; i < This->size; i++)
142 CoTaskMemFree(This->RegFilters[i].Name);
144 CoTaskMemFree(This->RegFilters);
145 CoTaskMemFree(This);
146 return 0;
147 } else
148 return refCount;
151 static HRESULT WINAPI IEnumRegFiltersImpl_Next(IEnumRegFilters * iface, ULONG cFilters, REGFILTER ** ppRegFilter, ULONG * pcFetched)
153 ULONG cFetched;
154 IEnumRegFiltersImpl *This = impl_from_IEnumRegFilters(iface);
155 unsigned int i;
157 cFetched = min(This->size, This->uIndex + cFilters) - This->uIndex;
159 TRACE("(%p)->(%u, %p, %p)\n", iface, cFilters, ppRegFilter, pcFetched);
161 if (cFetched > 0)
163 for(i = 0; i < cFetched; i++)
165 /* The string in the REGFILTER structure must be allocated in the same block as the REGFILTER structure itself */
166 ppRegFilter[i] = CoTaskMemAlloc(sizeof(REGFILTER)+(lstrlenW(This->RegFilters[This->uIndex + i].Name)+1)*sizeof(WCHAR));
167 if (!ppRegFilter[i])
169 while(i)
171 CoTaskMemFree(ppRegFilter[--i]);
172 ppRegFilter[i] = NULL;
174 return E_OUTOFMEMORY;
176 ppRegFilter[i]->Clsid = This->RegFilters[This->uIndex + i].Clsid;
177 ppRegFilter[i]->Name = (WCHAR*)((char*)ppRegFilter[i]+sizeof(REGFILTER));
178 CopyMemory(ppRegFilter[i]->Name, This->RegFilters[This->uIndex + i].Name,
179 (lstrlenW(This->RegFilters[This->uIndex + i].Name)+1)*sizeof(WCHAR));
182 This->uIndex += cFetched;
183 if (pcFetched)
184 *pcFetched = cFetched;
185 return S_OK;
188 return S_FALSE;
191 static HRESULT WINAPI IEnumRegFiltersImpl_Skip(IEnumRegFilters * iface, ULONG n)
193 TRACE("(%p)->(%u)\n", iface, n);
195 return E_NOTIMPL;
198 static HRESULT WINAPI IEnumRegFiltersImpl_Reset(IEnumRegFilters * iface)
200 IEnumRegFiltersImpl *This = impl_from_IEnumRegFilters(iface);
202 TRACE("(%p)\n", iface);
204 This->uIndex = 0;
205 return S_OK;
208 static HRESULT WINAPI IEnumRegFiltersImpl_Clone(IEnumRegFilters * iface, IEnumRegFilters ** ppEnum)
210 TRACE("(%p)->(%p)\n", iface, ppEnum);
212 return E_NOTIMPL;
215 static const IEnumRegFiltersVtbl IEnumRegFiltersImpl_Vtbl =
217 IEnumRegFiltersImpl_QueryInterface,
218 IEnumRegFiltersImpl_AddRef,
219 IEnumRegFiltersImpl_Release,
220 IEnumRegFiltersImpl_Next,
221 IEnumRegFiltersImpl_Skip,
222 IEnumRegFiltersImpl_Reset,
223 IEnumRegFiltersImpl_Clone