Get rid of the non-standard ICOM_VFIELD macro.
[wine/multimedia.git] / dlls / quartz / enummoniker.c
blobec3fbe73315011a25063f83ea08ee0fa85d4b1e5
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 #define COM_NO_WINDOWS_H
25 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "ole2.h"
31 #include "strmif.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
37 typedef struct EnumMonikerImpl
39 IEnumMonikerVtbl *lpVtbl;
40 ULONG ref;
41 IMoniker ** ppMoniker;
42 ULONG nMonikerCount;
43 ULONG index;
44 } EnumMonikerImpl;
46 static struct ICOM_VTABLE(IEnumMoniker) EnumMonikerImpl_Vtbl;
48 static ULONG WINAPI EnumMonikerImpl_AddRef(LPENUMMONIKER iface);
50 HRESULT EnumMonikerImpl_Create(IMoniker ** ppMoniker, ULONG nMonikerCount, IEnumMoniker ** ppEnum)
52 /* NOTE: assumes that array of IMonikers has already been AddRef'd
53 * I.e. this function does not AddRef the array of incoming
54 * IMonikers */
55 EnumMonikerImpl * pemi = CoTaskMemAlloc(sizeof(EnumMonikerImpl));
57 TRACE("(%p, %ld, %p)\n", ppMoniker, nMonikerCount, ppEnum);
59 *ppEnum = NULL;
61 if (!pemi)
62 return E_OUTOFMEMORY;
64 pemi->lpVtbl = &EnumMonikerImpl_Vtbl;
65 pemi->ref = 1;
66 pemi->ppMoniker = CoTaskMemAlloc(nMonikerCount * sizeof(IMoniker*));
67 memcpy(pemi->ppMoniker, ppMoniker, nMonikerCount*sizeof(IMoniker*));
68 pemi->nMonikerCount = nMonikerCount;
69 pemi->index = 0;
71 *ppEnum = (IEnumMoniker *)pemi;
73 return S_OK;
76 /**********************************************************************
77 * IEnumMoniker_QueryInterface (also IUnknown)
79 static HRESULT WINAPI EnumMonikerImpl_QueryInterface(
80 LPENUMMONIKER iface,
81 REFIID riid,
82 LPVOID *ppvObj)
84 ICOM_THIS(EnumMonikerImpl, iface);
85 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
87 if (This == NULL || ppvObj == NULL) return E_POINTER;
89 if (IsEqualGUID(riid, &IID_IUnknown) ||
90 IsEqualGUID(riid, &IID_IEnumMoniker))
92 *ppvObj = (LPVOID)iface;
93 EnumMonikerImpl_AddRef(iface);
94 return S_OK;
97 FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
98 return E_NOINTERFACE;
101 /**********************************************************************
102 * IEnumMoniker_AddRef (also IUnknown)
104 static ULONG WINAPI EnumMonikerImpl_AddRef(LPENUMMONIKER iface)
106 ICOM_THIS(EnumMonikerImpl, iface);
108 TRACE("\n");
110 if (This == NULL) return E_POINTER;
112 return InterlockedIncrement(&This->ref);
115 /**********************************************************************
116 * IEnumMoniker_Release (also IUnknown)
118 static ULONG WINAPI EnumMonikerImpl_Release(LPENUMMONIKER iface)
120 ICOM_THIS(EnumMonikerImpl, iface);
122 TRACE("\n");
124 if (!InterlockedDecrement(&This->ref))
126 CoTaskMemFree(This->ppMoniker);
127 This->ppMoniker = NULL;
128 CoTaskMemFree(This);
129 return 0;
131 return This->ref;
134 static HRESULT WINAPI EnumMonikerImpl_Next(LPENUMMONIKER iface, ULONG celt, IMoniker ** rgelt, ULONG * pceltFetched)
136 ULONG fetched;
137 ICOM_THIS(EnumMonikerImpl, iface);
139 TRACE("(%ld, %p, %p)\n", celt, rgelt, pceltFetched);
141 for (fetched = 0; (This->index + fetched < This->nMonikerCount) && (fetched < celt); fetched++)
143 rgelt[fetched] = This->ppMoniker[This->index + fetched];
144 IMoniker_AddRef(rgelt[fetched]);
147 This->index += fetched;
149 if (pceltFetched)
150 *pceltFetched = fetched;
152 if (fetched != celt)
153 return S_FALSE;
154 else
155 return S_OK;
158 static HRESULT WINAPI EnumMonikerImpl_Skip(LPENUMMONIKER iface, ULONG celt)
160 ICOM_THIS(EnumMonikerImpl, iface);
162 TRACE("(%ld)\n", celt);
164 This->index += celt;
166 return S_OK;
169 static HRESULT WINAPI EnumMonikerImpl_Reset(LPENUMMONIKER iface)
171 ICOM_THIS(EnumMonikerImpl, iface);
173 TRACE("()\n");
175 This->index = 0;
177 return S_OK;
180 static HRESULT WINAPI EnumMonikerImpl_Clone(LPENUMMONIKER iface, IEnumMoniker ** ppenum)
182 FIXME("(%p): stub\n", ppenum);
184 return E_NOTIMPL;
187 /**********************************************************************
188 * IEnumMoniker_Vtbl
190 static ICOM_VTABLE(IEnumMoniker) EnumMonikerImpl_Vtbl =
192 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
193 EnumMonikerImpl_QueryInterface,
194 EnumMonikerImpl_AddRef,
195 EnumMonikerImpl_Release,
196 EnumMonikerImpl_Next,
197 EnumMonikerImpl_Skip,
198 EnumMonikerImpl_Reset,
199 EnumMonikerImpl_Clone