ReactOS 0.4.16-dev-91-g764881a
format.c
Go to the documentation of this file.
1/*
2 * Copyright 2005 Jacek Caban
3 *
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.
8 *
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.
13 *
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
17 */
18
19#include "urlmon_main.h"
20#include "wine/debug.h"
21
23
24static WCHAR wszEnumFORMATETC[] = {'_','E','n','u','m','F','O','R','M','A','T','E','T','C','_',0};
25
26typedef struct {
28
29 FORMATETC *fetc;
32
35
37{
38 return CONTAINING_RECORD(iface, EnumFORMATETC, IEnumFORMATETC_iface);
39}
40
41static IEnumFORMATETC *EnumFORMATETC_Create(UINT cfmtetc, const FORMATETC *rgfmtetc, UINT it);
42
44{
46
47 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
48
49 *ppv = NULL;
50
52 IEnumFORMATETC_AddRef(iface);
53 *ppv = iface;
54 return S_OK;
55 }
56
57 WARN("not supported interface %s\n", debugstr_guid(riid));
58 return E_NOINTERFACE;
59}
60
62{
65 TRACE("(%p) ref=%d\n", This, ref);
66 return ref;
67}
68
70{
73
74 TRACE("(%p) ref=%d\n", This, ref);
75
76 if(!ref) {
77 heap_free(This->fetc);
79
81 }
82
83 return ref;
84}
85
87 FORMATETC *rgelt, ULONG *pceltFetched)
88{
90 ULONG cnt;
91
92 TRACE("(%p)->(%d %p %p)\n", This, celt, rgelt, pceltFetched);
93
94 if(!rgelt)
95 return E_INVALIDARG;
96
97 if(This->it >= This->fetc_cnt || !celt) {
98 if(pceltFetched)
99 *pceltFetched = 0;
100 return celt ? S_FALSE : S_OK;
101 }
102
103 cnt = This->fetc_cnt-This->it > celt ? celt : This->fetc_cnt-This->it;
104
105 memcpy(rgelt, This->fetc+This->it, cnt*sizeof(FORMATETC));
106 This->it += cnt;
107
108 if(pceltFetched)
109 *pceltFetched = cnt;
110
111 return cnt == celt ? S_OK : S_FALSE;
112}
113
115{
117
118 TRACE("(%p)->(%d)\n", This, celt);
119
120 This->it += celt;
121 return This->it > This->fetc_cnt ? S_FALSE : S_OK;
122}
123
125{
127
128 TRACE("(%p)\n", This);
129
130 This->it = 0;
131 return S_OK;
132}
133
135{
137
138 TRACE("(%p)->(%p)\n", This, ppenum);
139
140 if(!ppenum)
141 return E_INVALIDARG;
142
143 *ppenum = EnumFORMATETC_Create(This->fetc_cnt, This->fetc, This->it);
144 return S_OK;
145}
146
147static const IEnumFORMATETCVtbl EnumFORMATETCVtbl = {
155};
156
157static IEnumFORMATETC *EnumFORMATETC_Create(UINT cfmtetc, const FORMATETC *rgfmtetc, UINT it)
158{
160
162
163 ret->IEnumFORMATETC_iface.lpVtbl = &EnumFORMATETCVtbl;
164 ret->ref = 1;
165 ret->it = it;
166 ret->fetc_cnt = cfmtetc;
167
168 ret->fetc = heap_alloc(cfmtetc*sizeof(FORMATETC));
169 memcpy(ret->fetc, rgfmtetc, cfmtetc*sizeof(FORMATETC));
170
171 return &ret->IEnumFORMATETC_iface;
172}
173
174/**********************************************************
175 * CreateFormatEnumerator (urlmon.@)
176 */
177HRESULT WINAPI CreateFormatEnumerator(UINT cfmtetc, FORMATETC *rgfmtetc,
178 IEnumFORMATETC** ppenumfmtetc)
179{
180 TRACE("(%d %p %p)\n", cfmtetc, rgfmtetc, ppenumfmtetc);
181
182 if(!ppenumfmtetc)
183 return E_INVALIDARG;
184 if(!cfmtetc)
185 return E_FAIL;
186
187 *ppenumfmtetc = EnumFORMATETC_Create(cfmtetc, rgfmtetc, 0);
188 return S_OK;
189}
190
191/**********************************************************
192 * RegisterFormatEnumerator (urlmon.@)
193 */
195{
196 TRACE("(%p %p %d)\n", pBC, pEFetc, reserved);
197
198 if(reserved)
199 WARN("reserved != 0\n");
200
201 if(!pBC || !pEFetc)
202 return E_INVALIDARG;
203
204 return IBindCtx_RegisterObjectParam(pBC, wszEnumFORMATETC, (IUnknown*)pEFetc);
205}
206
207/**********************************************************
208 * RevokeFormatEnumerator (urlmon.@)
209 */
211{
212 TRACE("(%p %p)\n", pbc, pEFetc);
213
214 if(!pbc)
215 return E_INVALIDARG;
216
217 return IBindCtx_RevokeObjectParam(pbc, wszEnumFORMATETC);
218}
static void * heap_alloc(size_t len)
Definition: appwiz.h:66
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define WARN(fmt,...)
Definition: precomp.h:61
const GUID IID_IUnknown
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
static ULONG WINAPI EnumFORMATETC_Release(IEnumFORMATETC *iface)
Definition: format.c:69
HRESULT WINAPI CreateFormatEnumerator(UINT cfmtetc, FORMATETC *rgfmtetc, IEnumFORMATETC **ppenumfmtetc)
Definition: format.c:177
static HRESULT WINAPI EnumFORMATETC_Next(IEnumFORMATETC *iface, ULONG celt, FORMATETC *rgelt, ULONG *pceltFetched)
Definition: format.c:86
static IEnumFORMATETC * EnumFORMATETC_Create(UINT cfmtetc, const FORMATETC *rgfmtetc, UINT it)
Definition: format.c:157
static EnumFORMATETC * impl_from_IEnumFORMATETC(IEnumFORMATETC *iface)
Definition: format.c:36
static HRESULT WINAPI EnumFORMATETC_Skip(IEnumFORMATETC *iface, ULONG celt)
Definition: format.c:114
HRESULT WINAPI RegisterFormatEnumerator(LPBC pBC, IEnumFORMATETC *pEFetc, DWORD reserved)
Definition: format.c:194
static ULONG WINAPI EnumFORMATETC_AddRef(IEnumFORMATETC *iface)
Definition: format.c:61
static WCHAR wszEnumFORMATETC[]
Definition: format.c:24
HRESULT WINAPI RevokeFormatEnumerator(LPBC pbc, IEnumFORMATETC *pEFetc)
Definition: format.c:210
static HRESULT WINAPI EnumFORMATETC_QueryInterface(IEnumFORMATETC *iface, REFIID riid, void **ppv)
Definition: format.c:43
static const IEnumFORMATETCVtbl EnumFORMATETCVtbl
Definition: format.c:147
static HRESULT WINAPI EnumFORMATETC_Clone(IEnumFORMATETC *iface, IEnumFORMATETC **ppenum)
Definition: format.c:134
static HRESULT WINAPI EnumFORMATETC_Reset(IEnumFORMATETC *iface)
Definition: format.c:124
r reserved
Definition: btrfs.c:3006
unsigned long DWORD
Definition: ntddk_ex.h:95
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define debugstr_guid
Definition: kernel32.h:35
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned int UINT
Definition: ndis.h:50
interface IBindCtx * LPBC
Definition: objfwd.h:18
const GUID IID_IEnumFORMATETC
long LONG
Definition: pedump.c:60
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
#define TRACE(s)
Definition: solgame.cpp:4
FORMATETC * fetc
Definition: format.c:29
LONG ref
Definition: format.c:33
IEnumFORMATETC IEnumFORMATETC_iface
Definition: format.c:27
UINT it
Definition: format.c:31
UINT fetc_cnt
Definition: format.c:30
Definition: send.c:48
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
static void URLMON_LockModule(void)
Definition: urlmon_main.h:68
static void URLMON_UnlockModule(void)
Definition: urlmon_main.h:69
int ret
#define WINAPI
Definition: msvc.h:6
#define S_FALSE
Definition: winerror.h:2357
#define E_NOINTERFACE
Definition: winerror.h:2364
__wchar_t WCHAR
Definition: xmlstorage.h:180