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"
23 #include "wine/unicode.h"
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
29 typedef struct IEnumRegFiltersImpl
31 IEnumRegFilters IEnumRegFilters_iface;
34 REGFILTER* RegFilters;
36 } IEnumRegFiltersImpl;
38 static inline IEnumRegFiltersImpl *impl_from_IEnumRegFilters(IEnumRegFilters *iface)
40 return CONTAINING_RECORD(iface, IEnumRegFiltersImpl, IEnumRegFilters_iface);
43 static const struct IEnumRegFiltersVtbl IEnumRegFiltersImpl_Vtbl;
45 HRESULT IEnumRegFiltersImpl_Construct(REGFILTER* pInRegFilters, const ULONG size, IEnumRegFilters ** ppEnum)
47 IEnumRegFiltersImpl* pEnumRegFilters;
48 REGFILTER* pRegFilters = NULL;
51 TRACE("(%p, %d, %p)\n", pInRegFilters, size, ppEnum);
53 pEnumRegFilters = CoTaskMemAlloc(sizeof(IEnumRegFiltersImpl));
60 /* Accept size of 0 */
63 pRegFilters = CoTaskMemAlloc(sizeof(REGFILTER)*size);
66 CoTaskMemFree(pEnumRegFilters);
72 for(i = 0; i < size; i++)
74 pRegFilters[i].Clsid = pInRegFilters[i].Clsid;
75 pRegFilters[i].Name = CoTaskMemAlloc((strlenW(pInRegFilters[i].Name)+1)*sizeof(WCHAR));
76 if (!pRegFilters[i].Name)
79 CoTaskMemFree(pRegFilters[--i].Name);
80 CoTaskMemFree(pRegFilters);
81 CoTaskMemFree(pEnumRegFilters);
84 CopyMemory(pRegFilters[i].Name, pInRegFilters[i].Name, (strlenW(pInRegFilters[i].Name)+1)*sizeof(WCHAR));
87 pEnumRegFilters->IEnumRegFilters_iface.lpVtbl = &IEnumRegFiltersImpl_Vtbl;
88 pEnumRegFilters->refCount = 1;
89 pEnumRegFilters->uIndex = 0;
90 pEnumRegFilters->RegFilters = pRegFilters;
91 pEnumRegFilters->size = size;
93 *ppEnum = &pEnumRegFilters->IEnumRegFilters_iface;
98 static HRESULT WINAPI IEnumRegFiltersImpl_QueryInterface(IEnumRegFilters * iface, REFIID riid, LPVOID * ppv)
100 TRACE("(%p)->(%s, %p)\n", iface, qzdebugstr_guid(riid), ppv);
104 if (IsEqualIID(riid, &IID_IUnknown))
106 else if (IsEqualIID(riid, &IID_IEnumRegFilters))
111 IUnknown_AddRef((IUnknown *)(*ppv));
115 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
117 return E_NOINTERFACE;
120 static ULONG WINAPI IEnumRegFiltersImpl_AddRef(IEnumRegFilters * iface)
122 IEnumRegFiltersImpl *This = impl_from_IEnumRegFilters(iface);
123 ULONG refCount = InterlockedIncrement(&This->refCount);
125 TRACE("(%p)\n", iface);
130 static ULONG WINAPI IEnumRegFiltersImpl_Release(IEnumRegFilters * iface)
132 IEnumRegFiltersImpl *This = impl_from_IEnumRegFilters(iface);
133 ULONG refCount = InterlockedDecrement(&This->refCount);
135 TRACE("(%p)\n", iface);
141 for(i = 0; i < This->size; i++)
143 CoTaskMemFree(This->RegFilters[i].Name);
145 CoTaskMemFree(This->RegFilters);
152 static HRESULT WINAPI IEnumRegFiltersImpl_Next(IEnumRegFilters * iface, ULONG cFilters, REGFILTER ** ppRegFilter, ULONG * pcFetched)
155 IEnumRegFiltersImpl *This = impl_from_IEnumRegFilters(iface);
158 cFetched = min(This->size, This->uIndex + cFilters) - This->uIndex;
160 TRACE("(%p)->(%u, %p, %p)\n", iface, cFilters, ppRegFilter, pcFetched);
164 for(i = 0; i < cFetched; i++)
166 /* The string in the REGFILTER structure must be allocated in the same block as the REGFILTER structure itself */
167 ppRegFilter[i] = CoTaskMemAlloc(sizeof(REGFILTER)+(strlenW(This->RegFilters[This->uIndex + i].Name)+1)*sizeof(WCHAR));
172 CoTaskMemFree(ppRegFilter[--i]);
173 ppRegFilter[i] = NULL;
175 return E_OUTOFMEMORY;
177 ppRegFilter[i]->Clsid = This->RegFilters[This->uIndex + i].Clsid;
178 ppRegFilter[i]->Name = (WCHAR*)((char*)ppRegFilter[i]+sizeof(REGFILTER));
179 CopyMemory(ppRegFilter[i]->Name, This->RegFilters[This->uIndex + i].Name,
180 (strlenW(This->RegFilters[This->uIndex + i].Name)+1)*sizeof(WCHAR));
183 This->uIndex += cFetched;
185 *pcFetched = cFetched;
192 static HRESULT WINAPI IEnumRegFiltersImpl_Skip(IEnumRegFilters * iface, ULONG n)
194 TRACE("(%p)->(%u)\n", iface, n);
199 static HRESULT WINAPI IEnumRegFiltersImpl_Reset(IEnumRegFilters * iface)
201 IEnumRegFiltersImpl *This = impl_from_IEnumRegFilters(iface);
203 TRACE("(%p)\n", iface);
209 static HRESULT WINAPI IEnumRegFiltersImpl_Clone(IEnumRegFilters * iface, IEnumRegFilters ** ppEnum)
211 TRACE("(%p)->(%p)\n", iface, ppEnum);
216 static const IEnumRegFiltersVtbl IEnumRegFiltersImpl_Vtbl =
218 IEnumRegFiltersImpl_QueryInterface,
219 IEnumRegFiltersImpl_AddRef,
220 IEnumRegFiltersImpl_Release,
221 IEnumRegFiltersImpl_Next,
222 IEnumRegFiltersImpl_Skip,
223 IEnumRegFiltersImpl_Reset,
224 IEnumRegFiltersImpl_Clone