comctl32: Register all the controls in DllMain.
[wine/wine64.git] / dlls / urlmon / format.c
blob0a0a97d5cf0709d3e80d46be3a436377e8b05e8b
1 /*
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 <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
27 #include "urlmon.h"
28 #include "urlmon_main.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
34 static WCHAR wszEnumFORMATETC[] = {'_','E','n','u','m','F','O','R','M','A','T','E','T','C','_',0};
36 typedef struct {
37 const IEnumFORMATETCVtbl *lpEnumFORMATETCVtbl;
39 FORMATETC *fetc;
40 UINT fetc_cnt;
41 UINT it;
43 LONG ref;
44 } EnumFORMATETC;
46 static IEnumFORMATETC *EnumFORMATETC_Create(UINT cfmtetc, FORMATETC *rgfmtetc, UINT it);
48 #define ENUMF_THIS(iface) ICOM_THIS_MULTI(EnumFORMATETC, lpEnumFORMATETCVtbl, iface)
50 static HRESULT WINAPI EnumFORMATETC_QueryInterface(IEnumFORMATETC *iface, REFIID riid, void **ppv)
52 TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
54 *ppv = NULL;
56 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IEnumFORMATETC, riid)) {
57 *ppv = iface;
58 return S_OK;
61 WARN("not supported interface %s\n", debugstr_guid(riid));
62 return E_NOINTERFACE;
65 static ULONG WINAPI EnumFORMATETC_AddRef(IEnumFORMATETC *iface)
67 ENUMF_THIS(iface);
68 LONG ref = InterlockedIncrement(&This->ref);
69 TRACE("(%p) ref=%d\n", This, ref);
70 return ref;
73 static ULONG WINAPI EnumFORMATETC_Release(IEnumFORMATETC *iface)
75 ENUMF_THIS(iface);
76 LONG ref = InterlockedDecrement(&This->ref);
78 TRACE("(%p) ref=%d\n", This, ref);
80 if(!ref) {
81 HeapFree(GetProcessHeap(), 0, This->fetc);
82 HeapFree(GetProcessHeap(), 0, This);
84 URLMON_UnlockModule();
87 return ref;
90 static HRESULT WINAPI EnumFORMATETC_Next(IEnumFORMATETC *iface, ULONG celt,
91 FORMATETC *rgelt, ULONG *pceltFetched)
93 ENUMF_THIS(iface);
94 ULONG cnt;
96 TRACE("(%p)->(%d %p %p)\n", This, celt, rgelt, pceltFetched);
98 if(!rgelt)
99 return E_INVALIDARG;
101 if(This->it >= This->fetc_cnt || !celt) {
102 if(pceltFetched)
103 *pceltFetched = 0;
104 return celt ? S_FALSE : S_OK;
107 cnt = This->fetc_cnt-This->it > celt ? celt : This->fetc_cnt-This->it;
109 memcpy(rgelt, This->fetc+This->it, cnt*sizeof(FORMATETC));
110 This->it += cnt;
112 if(pceltFetched)
113 *pceltFetched = cnt;
115 return cnt == celt ? S_OK : S_FALSE;
118 static HRESULT WINAPI EnumFORMATETC_Skip(IEnumFORMATETC *iface, ULONG celt)
120 ENUMF_THIS(iface);
122 TRACE("(%p)->(%d)\n", This, celt);
124 This->it += celt;
125 return This->it > This->fetc_cnt ? S_FALSE : S_OK;
128 static HRESULT WINAPI EnumFORMATETC_Reset(IEnumFORMATETC *iface)
130 ENUMF_THIS(iface);
132 TRACE("(%p)\n", This);
134 This->it = 0;
135 return S_OK;
138 static HRESULT WINAPI EnumFORMATETC_Clone(IEnumFORMATETC *iface, IEnumFORMATETC **ppenum)
140 ENUMF_THIS(iface);
142 TRACE("(%p)->(%p)\n", This, ppenum);
144 if(!ppenum)
145 return E_INVALIDARG;
147 *ppenum = EnumFORMATETC_Create(This->fetc_cnt, This->fetc, This->it);
148 return S_OK;
151 static const IEnumFORMATETCVtbl EnumFORMATETCVtbl = {
152 EnumFORMATETC_QueryInterface,
153 EnumFORMATETC_AddRef,
154 EnumFORMATETC_Release,
155 EnumFORMATETC_Next,
156 EnumFORMATETC_Skip,
157 EnumFORMATETC_Reset,
158 EnumFORMATETC_Clone
161 static IEnumFORMATETC *EnumFORMATETC_Create(UINT cfmtetc, FORMATETC *rgfmtetc, UINT it)
163 EnumFORMATETC *ret = HeapAlloc(GetProcessHeap(), 0, sizeof(EnumFORMATETC));
165 URLMON_LockModule();
167 ret->lpEnumFORMATETCVtbl = &EnumFORMATETCVtbl;
168 ret->ref = 1;
169 ret->it = it;
170 ret->fetc_cnt = cfmtetc;
172 ret->fetc = HeapAlloc(GetProcessHeap(), 0, cfmtetc*sizeof(FORMATETC));
173 memcpy(ret->fetc, rgfmtetc, cfmtetc*sizeof(FORMATETC));
175 return (IEnumFORMATETC*)ret;
178 /**********************************************************
179 * CreateFormatEnumerator (urlmon.@)
181 HRESULT WINAPI CreateFormatEnumerator(UINT cfmtetc, FORMATETC *rgfmtetc,
182 IEnumFORMATETC** ppenumfmtetc)
184 TRACE("(%d %p %p)\n", cfmtetc, rgfmtetc, ppenumfmtetc);
186 if(!ppenumfmtetc)
187 return E_INVALIDARG;
188 if(!cfmtetc)
189 return E_FAIL;
191 *ppenumfmtetc = EnumFORMATETC_Create(cfmtetc, rgfmtetc, 0);
192 return S_OK;
195 /**********************************************************
196 * RegisterFormatEnumerator (urlmon.@)
198 HRESULT WINAPI RegisterFormatEnumerator(LPBC pBC, IEnumFORMATETC *pEFetc, DWORD reserved)
200 TRACE("(%p %p %d)\n", pBC, pEFetc, reserved);
202 if(reserved)
203 WARN("reserved != 0\n");
205 if(!pBC || !pEFetc)
206 return E_INVALIDARG;
208 return IBindCtx_RegisterObjectParam(pBC, wszEnumFORMATETC, (IUnknown*)pEFetc);
211 /**********************************************************
212 * RevokeFormatEnumerator (urlmon.@)
214 HRESULT WINAPI RevokeFormatEnumerator(LPBC pbc, IEnumFORMATETC *pEFetc)
216 TRACE("(%p %p)\n", pbc, pEFetc);
218 if(!pbc)
219 return E_INVALIDARG;
221 return IBindCtx_RevokeObjectParam(pbc, wszEnumFORMATETC);