advapi32: Make rpcrt4 a delayed import to work around circular dependencies with...
[wine/testsucceed.git] / dlls / quartz / enumregfilters.c
blobcadeba5e02fa63cb75c47320c27dbcb269e78cd5
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"
23 #include "wine/unicode.h"
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
29 typedef struct IEnumRegFiltersImpl
31 const IEnumRegFiltersVtbl * lpVtbl;
32 LONG refCount;
33 ULONG size;
34 REGFILTER* RegFilters;
35 ULONG uIndex;
36 } IEnumRegFiltersImpl;
38 static const struct IEnumRegFiltersVtbl IEnumRegFiltersImpl_Vtbl;
40 HRESULT IEnumRegFiltersImpl_Construct(REGFILTER* pInRegFilters, const ULONG size, IEnumRegFilters ** ppEnum)
42 IEnumRegFiltersImpl* pEnumRegFilters;
43 REGFILTER* pRegFilters = NULL;
44 unsigned int i;
46 TRACE("(%p, %d, %p)\n", pInRegFilters, size, ppEnum);
48 pEnumRegFilters = CoTaskMemAlloc(sizeof(IEnumRegFiltersImpl));
49 if (!pEnumRegFilters)
51 *ppEnum = NULL;
52 return E_OUTOFMEMORY;
55 /* Accept size of 0 */
56 if (size)
58 pRegFilters = CoTaskMemAlloc(sizeof(REGFILTER)*size);
59 if (!pRegFilters)
61 CoTaskMemFree(pEnumRegFilters);
62 *ppEnum = NULL;
63 return E_OUTOFMEMORY;
67 for(i = 0; i < size; i++)
69 pRegFilters[i].Clsid = pInRegFilters[i].Clsid;
70 pRegFilters[i].Name = CoTaskMemAlloc((strlenW(pInRegFilters[i].Name)+1)*sizeof(WCHAR));
71 if (!pRegFilters[i].Name)
73 while(i)
74 CoTaskMemFree(pRegFilters[--i].Name);
75 CoTaskMemFree(pRegFilters);
76 CoTaskMemFree(pEnumRegFilters);
77 return E_OUTOFMEMORY;
79 CopyMemory(pRegFilters[i].Name, pInRegFilters[i].Name, (strlenW(pInRegFilters[i].Name)+1)*sizeof(WCHAR));
82 pEnumRegFilters->lpVtbl = &IEnumRegFiltersImpl_Vtbl;
83 pEnumRegFilters->refCount = 1;
84 pEnumRegFilters->uIndex = 0;
85 pEnumRegFilters->RegFilters = pRegFilters;
86 pEnumRegFilters->size = size;
88 *ppEnum = (IEnumRegFilters *)(&pEnumRegFilters->lpVtbl);
90 return S_OK;
93 static HRESULT WINAPI IEnumRegFiltersImpl_QueryInterface(IEnumRegFilters * iface, REFIID riid, LPVOID * ppv)
95 TRACE("(%p)->(%s, %p)\n", iface, qzdebugstr_guid(riid), ppv);
97 *ppv = NULL;
99 if (IsEqualIID(riid, &IID_IUnknown))
100 *ppv = iface;
101 else if (IsEqualIID(riid, &IID_IEnumRegFilters))
102 *ppv = iface;
104 if (*ppv)
106 IUnknown_AddRef((IUnknown *)(*ppv));
107 return S_OK;
110 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
112 return E_NOINTERFACE;
115 static ULONG WINAPI IEnumRegFiltersImpl_AddRef(IEnumRegFilters * iface)
117 IEnumRegFiltersImpl *This = (IEnumRegFiltersImpl *)iface;
118 ULONG refCount = InterlockedIncrement(&This->refCount);
120 TRACE("(%p)\n", iface);
122 return refCount;
125 static ULONG WINAPI IEnumRegFiltersImpl_Release(IEnumRegFilters * iface)
127 IEnumRegFiltersImpl *This = (IEnumRegFiltersImpl *)iface;
128 ULONG refCount = InterlockedDecrement(&This->refCount);
130 TRACE("(%p)\n", iface);
132 if (!refCount)
134 ULONG i;
136 for(i = 0; i < This->size; i++)
138 CoTaskMemFree(This->RegFilters[i].Name);
140 CoTaskMemFree(This->RegFilters);
141 CoTaskMemFree(This);
142 return 0;
143 } else
144 return refCount;
147 static HRESULT WINAPI IEnumRegFiltersImpl_Next(IEnumRegFilters * iface, ULONG cFilters, REGFILTER ** ppRegFilter, ULONG * pcFetched)
149 ULONG cFetched;
150 IEnumRegFiltersImpl *This = (IEnumRegFiltersImpl *)iface;
151 unsigned int i;
153 cFetched = min(This->size, This->uIndex + cFilters) - This->uIndex;
155 TRACE("(%p)->(%u, %p, %p)\n", iface, cFilters, ppRegFilter, pcFetched);
157 if (cFetched > 0)
159 for(i = 0; i < cFetched; i++)
161 /* The string in the REGFILTER structure must be allocated in the same block as the REGFILTER structure itself */
162 ppRegFilter[i] = CoTaskMemAlloc(sizeof(REGFILTER)+(strlenW(This->RegFilters[This->uIndex + i].Name)+1)*sizeof(WCHAR));
163 if (!ppRegFilter[i])
165 while(i)
167 CoTaskMemFree(ppRegFilter[--i]);
168 ppRegFilter[i] = NULL;
170 return E_OUTOFMEMORY;
172 ppRegFilter[i]->Clsid = This->RegFilters[This->uIndex + i].Clsid;
173 ppRegFilter[i]->Name = (WCHAR*)((char*)ppRegFilter[i]+sizeof(REGFILTER));
174 CopyMemory(ppRegFilter[i]->Name, This->RegFilters[This->uIndex + i].Name,
175 (strlenW(This->RegFilters[This->uIndex + i].Name)+1)*sizeof(WCHAR));
178 This->uIndex += cFetched;
179 if (pcFetched)
180 *pcFetched = cFetched;
181 return S_OK;
184 return S_FALSE;
187 static HRESULT WINAPI IEnumRegFiltersImpl_Skip(IEnumRegFilters * iface, ULONG n)
189 TRACE("(%p)->(%u)\n", iface, n);
191 return E_NOTIMPL;
194 static HRESULT WINAPI IEnumRegFiltersImpl_Reset(IEnumRegFilters * iface)
196 IEnumRegFiltersImpl *This = (IEnumRegFiltersImpl *)iface;
198 TRACE("(%p)\n", iface);
200 This->uIndex = 0;
201 return S_OK;
204 static HRESULT WINAPI IEnumRegFiltersImpl_Clone(IEnumRegFilters * iface, IEnumRegFilters ** ppEnum)
206 TRACE("(%p)->(%p)\n", iface, ppEnum);
208 return E_NOTIMPL;
211 static const IEnumRegFiltersVtbl IEnumRegFiltersImpl_Vtbl =
213 IEnumRegFiltersImpl_QueryInterface,
214 IEnumRegFiltersImpl_AddRef,
215 IEnumRegFiltersImpl_Release,
216 IEnumRegFiltersImpl_Next,
217 IEnumRegFiltersImpl_Skip,
218 IEnumRegFiltersImpl_Reset,
219 IEnumRegFiltersImpl_Clone