Dump HeapWalk entries.
[wine/multimedia.git] / dlls / quartz / enummoniker.c
blob879d80a68bde5167ef4dd83b33a7e4675daece78
1 /*
2 * IEnumMoniker implementation
4 * Copyright 2003 Robert Shearman
6 * This file contains the (internal) driver registration functions,
7 * driver enumeration APIs and DirectDraw creation functions.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <stdarg.h>
26 #define COBJMACROS
27 #define COM_NO_WINDOWS_H
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winuser.h"
32 #include "ole2.h"
33 #include "strmif.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
39 typedef struct EnumMonikerImpl
41 IEnumMonikerVtbl *lpVtbl;
42 ULONG ref;
43 IMoniker ** ppMoniker;
44 ULONG nMonikerCount;
45 ULONG index;
46 } EnumMonikerImpl;
48 static struct IEnumMonikerVtbl EnumMonikerImpl_Vtbl;
50 static ULONG WINAPI EnumMonikerImpl_AddRef(LPENUMMONIKER iface);
52 HRESULT EnumMonikerImpl_Create(IMoniker ** ppMoniker, ULONG nMonikerCount, IEnumMoniker ** ppEnum)
54 /* NOTE: assumes that array of IMonikers has already been AddRef'd
55 * I.e. this function does not AddRef the array of incoming
56 * IMonikers */
57 EnumMonikerImpl * pemi = CoTaskMemAlloc(sizeof(EnumMonikerImpl));
59 TRACE("(%p, %ld, %p)\n", ppMoniker, nMonikerCount, ppEnum);
61 *ppEnum = NULL;
63 if (!pemi)
64 return E_OUTOFMEMORY;
66 pemi->lpVtbl = &EnumMonikerImpl_Vtbl;
67 pemi->ref = 1;
68 pemi->ppMoniker = CoTaskMemAlloc(nMonikerCount * sizeof(IMoniker*));
69 memcpy(pemi->ppMoniker, ppMoniker, nMonikerCount*sizeof(IMoniker*));
70 pemi->nMonikerCount = nMonikerCount;
71 pemi->index = 0;
73 *ppEnum = (IEnumMoniker *)pemi;
75 return S_OK;
78 /**********************************************************************
79 * IEnumMoniker_QueryInterface (also IUnknown)
81 static HRESULT WINAPI EnumMonikerImpl_QueryInterface(
82 LPENUMMONIKER iface,
83 REFIID riid,
84 LPVOID *ppvObj)
86 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
87 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
89 if (This == NULL || ppvObj == NULL) return E_POINTER;
91 if (IsEqualGUID(riid, &IID_IUnknown) ||
92 IsEqualGUID(riid, &IID_IEnumMoniker))
94 *ppvObj = (LPVOID)iface;
95 EnumMonikerImpl_AddRef(iface);
96 return S_OK;
99 FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
100 return E_NOINTERFACE;
103 /**********************************************************************
104 * IEnumMoniker_AddRef (also IUnknown)
106 static ULONG WINAPI EnumMonikerImpl_AddRef(LPENUMMONIKER iface)
108 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
109 ULONG ref;
111 if (This == NULL) return E_POINTER;
113 ref = InterlockedIncrement(&This->ref);
115 TRACE("(%p)->() AddRef from %ld\n", iface, ref - 1);
117 return ref;
120 /**********************************************************************
121 * IEnumMoniker_Release (also IUnknown)
123 static ULONG WINAPI EnumMonikerImpl_Release(LPENUMMONIKER iface)
125 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
126 ULONG ref = InterlockedDecrement(&This->ref);
128 TRACE("(%p)->() Release from %ld\n", iface, ref + 1);
130 if (!ref)
132 CoTaskMemFree(This->ppMoniker);
133 This->ppMoniker = NULL;
134 CoTaskMemFree(This);
135 return 0;
137 return ref;
140 static HRESULT WINAPI EnumMonikerImpl_Next(LPENUMMONIKER iface, ULONG celt, IMoniker ** rgelt, ULONG * pceltFetched)
142 ULONG fetched;
143 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
145 TRACE("(%p)->(%ld, %p, %p)\n", iface, celt, rgelt, pceltFetched);
147 for (fetched = 0; (This->index + fetched < This->nMonikerCount) && (fetched < celt); fetched++)
149 rgelt[fetched] = This->ppMoniker[This->index + fetched];
150 IMoniker_AddRef(rgelt[fetched]);
153 This->index += fetched;
155 TRACE("-- fetched %ld\n", fetched);
157 if (pceltFetched)
158 *pceltFetched = fetched;
160 if (fetched != celt)
161 return S_FALSE;
162 else
163 return S_OK;
166 static HRESULT WINAPI EnumMonikerImpl_Skip(LPENUMMONIKER iface, ULONG celt)
168 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
170 TRACE("(%p)->(%ld)\n", iface, celt);
172 This->index += celt;
174 return S_OK;
177 static HRESULT WINAPI EnumMonikerImpl_Reset(LPENUMMONIKER iface)
179 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
181 TRACE("(%p)->()\n", iface);
183 This->index = 0;
185 return S_OK;
188 static HRESULT WINAPI EnumMonikerImpl_Clone(LPENUMMONIKER iface, IEnumMoniker ** ppenum)
190 FIXME("(%p)->(%p): stub\n", iface, ppenum);
192 return E_NOTIMPL;
195 /**********************************************************************
196 * IEnumMoniker_Vtbl
198 static IEnumMonikerVtbl EnumMonikerImpl_Vtbl =
200 EnumMonikerImpl_QueryInterface,
201 EnumMonikerImpl_AddRef,
202 EnumMonikerImpl_Release,
203 EnumMonikerImpl_Next,
204 EnumMonikerImpl_Skip,
205 EnumMonikerImpl_Reset,
206 EnumMonikerImpl_Clone