2 * Copyright 2005 Jacek Caban
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "urlmon_main.h"
20 #include "wine/debug.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(urlmon
);
24 static WCHAR wszEnumFORMATETC
[] = L
"_EnumFORMATETC_";
27 IEnumFORMATETC IEnumFORMATETC_iface
;
36 static inline EnumFORMATETC
*impl_from_IEnumFORMATETC(IEnumFORMATETC
*iface
)
38 return CONTAINING_RECORD(iface
, EnumFORMATETC
, IEnumFORMATETC_iface
);
41 static IEnumFORMATETC
*EnumFORMATETC_Create(UINT cfmtetc
, const FORMATETC
*rgfmtetc
, UINT it
);
43 static HRESULT WINAPI
EnumFORMATETC_QueryInterface(IEnumFORMATETC
*iface
, REFIID riid
, void **ppv
)
45 EnumFORMATETC
*This
= impl_from_IEnumFORMATETC(iface
);
47 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
51 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IEnumFORMATETC
, riid
)) {
52 IEnumFORMATETC_AddRef(iface
);
57 WARN("not supported interface %s\n", debugstr_guid(riid
));
61 static ULONG WINAPI
EnumFORMATETC_AddRef(IEnumFORMATETC
*iface
)
63 EnumFORMATETC
*This
= impl_from_IEnumFORMATETC(iface
);
64 LONG ref
= InterlockedIncrement(&This
->ref
);
65 TRACE("(%p) ref=%ld\n", This
, ref
);
69 static ULONG WINAPI
EnumFORMATETC_Release(IEnumFORMATETC
*iface
)
71 EnumFORMATETC
*This
= impl_from_IEnumFORMATETC(iface
);
72 LONG ref
= InterlockedDecrement(&This
->ref
);
74 TRACE("(%p) ref=%ld\n", This
, ref
);
80 URLMON_UnlockModule();
86 static HRESULT WINAPI
EnumFORMATETC_Next(IEnumFORMATETC
*iface
, ULONG celt
,
87 FORMATETC
*rgelt
, ULONG
*pceltFetched
)
89 EnumFORMATETC
*This
= impl_from_IEnumFORMATETC(iface
);
92 TRACE("(%p)->(%ld %p %p)\n", This
, celt
, rgelt
, pceltFetched
);
97 if(This
->it
>= This
->fetc_cnt
|| !celt
) {
100 return celt
? S_FALSE
: S_OK
;
103 cnt
= This
->fetc_cnt
-This
->it
> celt
? celt
: This
->fetc_cnt
-This
->it
;
105 memcpy(rgelt
, This
->fetc
+This
->it
, cnt
*sizeof(FORMATETC
));
111 return cnt
== celt
? S_OK
: S_FALSE
;
114 static HRESULT WINAPI
EnumFORMATETC_Skip(IEnumFORMATETC
*iface
, ULONG celt
)
116 EnumFORMATETC
*This
= impl_from_IEnumFORMATETC(iface
);
118 TRACE("(%p)->(%ld)\n", This
, celt
);
121 return This
->it
> This
->fetc_cnt
? S_FALSE
: S_OK
;
124 static HRESULT WINAPI
EnumFORMATETC_Reset(IEnumFORMATETC
*iface
)
126 EnumFORMATETC
*This
= impl_from_IEnumFORMATETC(iface
);
128 TRACE("(%p)\n", This
);
134 static HRESULT WINAPI
EnumFORMATETC_Clone(IEnumFORMATETC
*iface
, IEnumFORMATETC
**ppenum
)
136 EnumFORMATETC
*This
= impl_from_IEnumFORMATETC(iface
);
138 TRACE("(%p)->(%p)\n", This
, ppenum
);
143 *ppenum
= EnumFORMATETC_Create(This
->fetc_cnt
, This
->fetc
, This
->it
);
147 static const IEnumFORMATETCVtbl EnumFORMATETCVtbl
= {
148 EnumFORMATETC_QueryInterface
,
149 EnumFORMATETC_AddRef
,
150 EnumFORMATETC_Release
,
157 static IEnumFORMATETC
*EnumFORMATETC_Create(UINT cfmtetc
, const FORMATETC
*rgfmtetc
, UINT it
)
159 EnumFORMATETC
*ret
= malloc(sizeof(EnumFORMATETC
));
163 ret
->IEnumFORMATETC_iface
.lpVtbl
= &EnumFORMATETCVtbl
;
166 ret
->fetc_cnt
= cfmtetc
;
168 ret
->fetc
= malloc(cfmtetc
* sizeof(FORMATETC
));
169 memcpy(ret
->fetc
, rgfmtetc
, cfmtetc
*sizeof(FORMATETC
));
171 return &ret
->IEnumFORMATETC_iface
;
174 /**********************************************************
175 * CreateFormatEnumerator (urlmon.@)
177 HRESULT WINAPI
CreateFormatEnumerator(UINT cfmtetc
, FORMATETC
*rgfmtetc
,
178 IEnumFORMATETC
** ppenumfmtetc
)
180 TRACE("(%d %p %p)\n", cfmtetc
, rgfmtetc
, ppenumfmtetc
);
187 *ppenumfmtetc
= EnumFORMATETC_Create(cfmtetc
, rgfmtetc
, 0);
191 /**********************************************************
192 * RegisterFormatEnumerator (urlmon.@)
194 HRESULT WINAPI
RegisterFormatEnumerator(LPBC pBC
, IEnumFORMATETC
*pEFetc
, DWORD reserved
)
196 TRACE("(%p %p %ld)\n", pBC
, pEFetc
, reserved
);
199 WARN("reserved != 0\n");
204 return IBindCtx_RegisterObjectParam(pBC
, wszEnumFORMATETC
, (IUnknown
*)pEFetc
);
207 /**********************************************************
208 * RevokeFormatEnumerator (urlmon.@)
210 HRESULT WINAPI
RevokeFormatEnumerator(LPBC pbc
, IEnumFORMATETC
*pEFetc
)
212 TRACE("(%p %p)\n", pbc
, pEFetc
);
217 return IBindCtx_RevokeObjectParam(pbc
, wszEnumFORMATETC
);