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
;
33 REGFILTER
* RegFilters
;
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
;
50 TRACE("(%p, %d, %p)\n", pInRegFilters
, size
, ppEnum
);
52 pEnumRegFilters
= CoTaskMemAlloc(sizeof(IEnumRegFiltersImpl
));
59 /* Accept size of 0 */
62 pRegFilters
= CoTaskMemAlloc(sizeof(REGFILTER
)*size
);
65 CoTaskMemFree(pEnumRegFilters
);
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
)
78 CoTaskMemFree(pRegFilters
[--i
].Name
);
79 CoTaskMemFree(pRegFilters
);
80 CoTaskMemFree(pEnumRegFilters
);
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
;
97 static HRESULT WINAPI
IEnumRegFiltersImpl_QueryInterface(IEnumRegFilters
* iface
, REFIID riid
, LPVOID
* ppv
)
99 TRACE("(%p)->(%s, %p)\n", iface
, qzdebugstr_guid(riid
), ppv
);
103 if (IsEqualIID(riid
, &IID_IUnknown
))
105 else if (IsEqualIID(riid
, &IID_IEnumRegFilters
))
110 IUnknown_AddRef((IUnknown
*)(*ppv
));
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
);
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
);
140 for(i
= 0; i
< This
->size
; i
++)
142 CoTaskMemFree(This
->RegFilters
[i
].Name
);
144 CoTaskMemFree(This
->RegFilters
);
151 static HRESULT WINAPI
IEnumRegFiltersImpl_Next(IEnumRegFilters
* iface
, ULONG cFilters
, REGFILTER
** ppRegFilter
, ULONG
* pcFetched
)
154 IEnumRegFiltersImpl
*This
= impl_from_IEnumRegFilters(iface
);
157 cFetched
= min(This
->size
, This
->uIndex
+ cFilters
) - This
->uIndex
;
159 TRACE("(%p)->(%u, %p, %p)\n", iface
, cFilters
, ppRegFilter
, pcFetched
);
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
));
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
;
184 *pcFetched
= cFetched
;
191 static HRESULT WINAPI
IEnumRegFiltersImpl_Skip(IEnumRegFilters
* iface
, ULONG n
)
193 TRACE("(%p)->(%u)\n", iface
, n
);
198 static HRESULT WINAPI
IEnumRegFiltersImpl_Reset(IEnumRegFilters
* iface
)
200 IEnumRegFiltersImpl
*This
= impl_from_IEnumRegFilters(iface
);
202 TRACE("(%p)\n", iface
);
208 static HRESULT WINAPI
IEnumRegFiltersImpl_Clone(IEnumRegFilters
* iface
, IEnumRegFilters
** ppEnum
)
210 TRACE("(%p)->(%p)\n", iface
, ppEnum
);
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