ReactOS  0.4.14-dev-297-g23e575c
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 
24 static WCHAR wszEnumFORMATETC[] = {'_','E','n','u','m','F','O','R','M','A','T','E','T','C','_',0};
25 
26 typedef struct {
28 
29  FORMATETC *fetc;
32 
35 
37 {
38  return CONTAINING_RECORD(iface, EnumFORMATETC, IEnumFORMATETC_iface);
39 }
40 
41 static 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);
78  heap_free(This);
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 
147 static const IEnumFORMATETCVtbl EnumFORMATETCVtbl = {
155 };
156 
157 static 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  */
177 HRESULT 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 }
#define REFIID
Definition: guiddef.h:118
#define E_NOINTERFACE
Definition: winerror.h:2364
interface IBindCtx * LPBC
Definition: objfwd.h:18
REFIID riid
Definition: precomp.h:44
#define WARN(fmt,...)
Definition: debug.h:111
static ULONG WINAPI EnumFORMATETC_AddRef(IEnumFORMATETC *iface)
Definition: format.c:61
REFIID LPVOID * ppv
Definition: atlbase.h:39
HRESULT WINAPI RevokeFormatEnumerator(LPBC pbc, IEnumFORMATETC *pEFetc)
Definition: format.c:210
static IEnumFORMATETC * EnumFORMATETC_Create(UINT cfmtetc, const FORMATETC *rgfmtetc, UINT it)
Definition: format.c:157
static const IEnumFORMATETCVtbl EnumFORMATETCVtbl
Definition: format.c:147
#define E_FAIL
Definition: ddrawi.h:102
Definition: send.c:47
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
static ULONG WINAPI EnumFORMATETC_Release(IEnumFORMATETC *iface)
Definition: format.c:69
static HRESULT WINAPI EnumFORMATETC_Skip(IEnumFORMATETC *iface, ULONG celt)
Definition: format.c:114
long LONG
Definition: pedump.c:60
LONG ref
Definition: format.c:33
GLenum GLint ref
Definition: glext.h:6028
static HRESULT WINAPI EnumFORMATETC_Next(IEnumFORMATETC *iface, ULONG celt, FORMATETC *rgelt, ULONG *pceltFetched)
Definition: format.c:86
r reserved
Definition: btrfs.c:2893
#define S_FALSE
Definition: winerror.h:2357
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
FORMATETC * fetc
Definition: format.c:29
static HRESULT WINAPI EnumFORMATETC_QueryInterface(IEnumFORMATETC *iface, REFIID riid, void **ppv)
Definition: format.c:43
#define debugstr_guid
Definition: kernel32.h:35
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
UINT it
Definition: format.c:31
static void URLMON_UnlockModule(void)
Definition: urlmon_main.h:68
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
const GUID IID_IUnknown
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
const GUID IID_IEnumFORMATETC
static WCHAR wszEnumFORMATETC[]
Definition: format.c:24
int ret
#define InterlockedDecrement
Definition: armddk.h:52
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static HRESULT WINAPI EnumFORMATETC_Clone(IEnumFORMATETC *iface, IEnumFORMATETC **ppenum)
Definition: format.c:134
#define S_OK
Definition: intsafe.h:59
IEnumFORMATETC IEnumFORMATETC_iface
Definition: format.c:27
#define InterlockedIncrement
Definition: armddk.h:53
HRESULT WINAPI RegisterFormatEnumerator(LPBC pBC, IEnumFORMATETC *pEFetc, DWORD reserved)
Definition: format.c:194
UINT fetc_cnt
Definition: format.c:30
unsigned int UINT
Definition: ndis.h:50
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
HRESULT WINAPI CreateFormatEnumerator(UINT cfmtetc, FORMATETC *rgfmtetc, IEnumFORMATETC **ppenumfmtetc)
Definition: format.c:177
unsigned int ULONG
Definition: retypes.h:1
static void URLMON_LockModule(void)
Definition: urlmon_main.h:67
static HRESULT WINAPI EnumFORMATETC_Reset(IEnumFORMATETC *iface)
Definition: format.c:124
WINE_DEFAULT_DEBUG_CHANNEL(msacm)
static IEnumFORMATETC EnumFORMATETC
Definition: dragdrop.c:440
static EnumFORMATETC * impl_from_IEnumFORMATETC(IEnumFORMATETC *iface)
Definition: format.c:36
static BOOL heap_free(void *mem)
Definition: appwiz.h:75