ReactOS  0.4.14-dev-390-g34947ad
utils.c
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Piotr Caban for CodeWeavers
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 "vbscript.h"
20 
21 #include "wine/debug.h"
22 
24 
25 typedef struct {
27 
29 
33 
35 {
36  return CONTAINING_RECORD(iface, safearray_iter, IEnumVARIANT_iface);
37 }
38 
40  IEnumVARIANT *iface, REFIID riid, void **ppv)
41 {
43 
45  TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
46  *ppv = &This->IEnumVARIANT_iface;
47  }else if(IsEqualGUID(riid, &IID_IEnumVARIANT)) {
48  TRACE("(%p)->(IID_IEnumVARIANT %p)\n", This, ppv);
49  *ppv = &This->IEnumVARIANT_iface;
50  }else {
51  FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
52  *ppv = NULL;
53  return E_NOINTERFACE;
54  }
55 
56  IUnknown_AddRef((IUnknown*)*ppv);
57  return S_OK;
58 }
59 
61 {
64 
65  TRACE("(%p) ref=%d\n", This, ref);
66 
67  return ref;
68 }
69 
71 {
74 
75  TRACE("(%p) ref=%d\n", iface, ref);
76 
77  if(!ref) {
78  if(This->sa)
79  SafeArrayUnlock(This->sa);
80  heap_free(This);
81  }
82 
83  return ref;
84 }
85 
87  ULONG celt, VARIANT *rgVar, ULONG *pCeltFetched)
88 {
90  HRESULT hres;
91  VARIANT *v;
92 
93  TRACE("(%p)->(%u %p %p)\n", This, celt, rgVar, pCeltFetched);
94 
95  if(celt != 1) {
96  FIXME("celt != 1\n");
97  return E_NOTIMPL;
98  }
99 
100  if(This->i >= This->size) {
101  if(pCeltFetched)
102  *pCeltFetched = 0;
103  return S_FALSE;
104  }
105 
106  if(!This->sa->cLocks)
107  ERR("SAFEARRAY not locked\n");
108 
109  v = (VARIANT*)(((BYTE*)This->sa->pvData) + This->i * This->sa->cbElements);
110  V_VT(rgVar) = VT_EMPTY;
111  hres = VariantCopy(rgVar, v);
112  if(FAILED(hres))
113  return hres;
114 
115  This->i++;
116  if(pCeltFetched)
117  *pCeltFetched = 1;
118  return S_OK;
119 }
120 
122 {
123  FIXME("\n");
124  return E_NOTIMPL;
125 }
126 
128 {
129  FIXME("\n");
130  return E_NOTIMPL;
131 }
132 
134  IEnumVARIANT *iface, IEnumVARIANT **ppEnum)
135 {
136  FIXME("\n");
137  return E_NOTIMPL;
138 }
139 
140 static const IEnumVARIANTVtbl safearray_iter_EnumVARIANTVtbl = {
148 };
149 
151 {
152  ULONG ret = 1;
153  USHORT i;
154 
155  if(!sa)
156  return 0;
157 
158  for(i=0; i<sa->cDims && ret; i++)
159  ret *= sa->rgsabound[i].cElements;
160  return ret;
161 }
162 
164 {
165  safearray_iter *iter;
166  HRESULT hres;
167 
168  if(sa && !(sa->fFeatures & FADF_VARIANT)) {
169  FIXME("enumeration not supported: %x\n", sa->fFeatures);
170  return E_NOTIMPL;
171  }
172 
173  iter = heap_alloc(sizeof(*iter));
174  if(!iter)
175  return E_OUTOFMEMORY;
176 
177  if(sa) {
178  hres = SafeArrayLock(sa);
179  if(FAILED(hres)) {
180  heap_free(iter);
181  return hres;
182  }
183  }
184 
186  iter->ref = 1;
187  iter->sa = sa;
188  iter->i = 0;
189  iter->size = get_safearray_size(sa);
190 
191  *ev = &iter->IEnumVARIANT_iface;
192  return S_OK;
193 }
ULONG size
Definition: utils.c:31
static HRESULT WINAPI safearray_iter_IEnumVARIANT_QueryInterface(IEnumVARIANT *iface, REFIID riid, void **ppv)
Definition: utils.c:39
#define REFIID
Definition: guiddef.h:118
#define E_NOINTERFACE
Definition: winerror.h:2364
static ULONG WINAPI safearray_iter_IEnumVARIANT_Release(IEnumVARIANT *iface)
Definition: utils.c:70
REFIID riid
Definition: precomp.h:44
static safearray_iter * impl_from_IEnumVARIANT(IEnumVARIANT *iface)
Definition: utils.c:34
REFIID LPVOID * ppv
Definition: atlbase.h:39
Definition: send.c:47
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
static ULONG get_safearray_size(SAFEARRAY *sa)
Definition: utils.c:150
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static ULONG WINAPI safearray_iter_IEnumVARIANT_AddRef(IEnumVARIANT *iface)
Definition: utils.c:60
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
long LONG
Definition: pedump.c:60
GLenum GLint ref
Definition: glext.h:6028
#define FIXME(fmt,...)
Definition: debug.h:110
#define S_FALSE
Definition: winerror.h:2357
smooth NULL
Definition: ftsmooth.c:416
static HRESULT WINAPI safearray_iter_IEnumVARIANT_Reset(IEnumVARIANT *iface)
Definition: utils.c:127
static const IEnumVARIANTVtbl safearray_iter_EnumVARIANTVtbl
Definition: utils.c:140
#define debugstr_guid
Definition: kernel32.h:35
SAFEARRAY * sa
Definition: utils.c:30
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
HRESULT WINAPI SafeArrayLock(SAFEARRAY *psa)
Definition: safearray.c:797
HRESULT WINAPI SafeArrayUnlock(SAFEARRAY *psa)
Definition: safearray.c:833
#define TRACE(s)
Definition: solgame.cpp:4
HRESULT hres
Definition: protocol.c:465
LONG HRESULT
Definition: typedefs.h:77
LONG ref
Definition: utils.c:28
const GUID IID_IUnknown
IEnumVARIANT IEnumVARIANT_iface
Definition: utils.c:26
#define WINAPI
Definition: msvc.h:8
WINE_DEFAULT_DEBUG_CHANNEL(d3dcompiler)
static HRESULT WINAPI safearray_iter_IEnumVARIANT_Skip(IEnumVARIANT *iface, ULONG celt)
Definition: utils.c:121
int ret
#define InterlockedDecrement
Definition: armddk.h:52
#define V_VT(A)
Definition: oleauto.h:211
static HRESULT WINAPI safearray_iter_IEnumVARIANT_Next(IEnumVARIANT *iface, ULONG celt, VARIANT *rgVar, ULONG *pCeltFetched)
Definition: utils.c:86
unsigned char BYTE
Definition: mem.h:68
#define ERR(fmt,...)
Definition: debug.h:109
ULONG i
Definition: utils.c:31
#define S_OK
Definition: intsafe.h:59
#define InterlockedIncrement
Definition: armddk.h:53
const GLdouble * v
Definition: gl.h:2040
unsigned short USHORT
Definition: pedump.c:61
#define E_NOTIMPL
Definition: ddrawi.h:99
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
unsigned int ULONG
Definition: retypes.h:1
HRESULT WINAPI VariantCopy(VARIANTARG *pvargDest, VARIANTARG *pvargSrc)
Definition: variant.c:751
static struct sockaddr_in sa
Definition: adnsresfilter.c:69
HRESULT create_safearray_iter(SAFEARRAY *sa, IEnumVARIANT **ev)
Definition: utils.c:163
static BOOL heap_free(void *mem)
Definition: appwiz.h:75
static HRESULT WINAPI safearray_iter_IEnumVARIANT_Clone(IEnumVARIANT *iface, IEnumVARIANT **ppEnum)
Definition: utils.c:133