Initialize the output buffer parameters to 0 in RegQueryValue*
[wine.git] / ole / ifs.c
blob91e9549022d420d45f8eedc74951ccded4eb1984
1 /*
2 * basic interfaces
4 * Copyright 1997 Marcus Meissner
5 */
7 #include <ctype.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <assert.h>
11 #include "winerror.h"
12 #include "ldt.h"
13 #include "heap.h"
14 #include "wine/winbase16.h"
15 #include "wine/obj_base.h"
16 #include "local.h"
17 #include "module.h"
18 #include "debug.h"
20 #include "ifs.h"
22 DEFAULT_DEBUG_CHANNEL(relay)
24 /* --- IUnknown implementation */
26 typedef struct
28 /* IUnknown fields */
29 ICOM_VTABLE(IUnknown)* lpvtbl;
30 DWORD ref;
31 } IUnknownImpl;
33 /******************************************************************************
34 * IUnknown_AddRef [VTABLE:IUNKNOWN.1]
36 static ULONG WINAPI IUnknown_fnAddRef(LPUNKNOWN iface) {
37 ICOM_THIS(IUnknownImpl,iface);
38 TRACE(relay,"(%p)->AddRef()\n",This);
39 return ++(This->ref);
42 /******************************************************************************
43 * IUnknown_Release [VTABLE:IUNKNOWN.2]
45 static ULONG WINAPI IUnknown_fnRelease(LPUNKNOWN iface) {
46 ICOM_THIS(IUnknownImpl,iface);
47 TRACE(relay,"(%p)->Release()\n",This);
48 if (!--(This->ref)) {
49 HeapFree(GetProcessHeap(),0,This);
50 return 0;
52 return This->ref;
55 /******************************************************************************
56 * IUnknown_QueryInterface [VTABLE:IUNKNOWN.0]
58 static HRESULT WINAPI IUnknown_fnQueryInterface(LPUNKNOWN iface,REFIID refiid,LPVOID *obj) {
59 ICOM_THIS(IUnknownImpl,iface);
60 char xrefiid[50];
62 WINE_StringFromCLSID((LPCLSID)refiid,xrefiid);
63 TRACE(relay,"(%p)->QueryInterface(%s,%p)\n",This,xrefiid,obj);
65 if (!memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown))) {
66 *obj = This;
67 return 0;
69 return OLE_E_ENUM_NOMORE;
72 static ICOM_VTABLE(IUnknown) uvt = {
73 IUnknown_fnQueryInterface,
74 IUnknown_fnAddRef,
75 IUnknown_fnRelease
78 /******************************************************************************
79 * IUnknown_Constructor [INTERNAL]
81 LPUNKNOWN
82 IUnknown_Constructor() {
83 IUnknownImpl* unk;
85 unk = (IUnknownImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IUnknownImpl));
86 unk->lpvtbl = &uvt;
87 unk->ref = 1;
88 return (LPUNKNOWN)unk;
92 /* --- IMalloc16 implementation */
95 typedef struct
97 /* IUnknown fields */
98 ICOM_VTABLE(IMalloc16)* lpvtbl;
99 DWORD ref;
100 /* IMalloc16 fields */
101 /* Gmm, I think one is not enough, we should probably manage a list of
102 * heaps
104 HGLOBAL16 heap;
105 } IMalloc16Impl;
107 /******************************************************************************
108 * IMalloc16_QueryInterface [COMPOBJ.500]
110 HRESULT WINAPI IMalloc16_fnQueryInterface(IMalloc16* iface,REFIID refiid,LPVOID *obj) {
111 ICOM_THIS(IMalloc16Impl,iface);
112 char xrefiid[50];
114 WINE_StringFromCLSID((LPCLSID)refiid,xrefiid);
115 TRACE(relay,"(%p)->QueryInterface(%s,%p)\n",This,xrefiid,obj);
116 if ( !memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) ||
117 !memcmp(&IID_IMalloc,refiid,sizeof(IID_IMalloc))
119 *obj = This;
120 return 0;
122 return OLE_E_ENUM_NOMORE;
125 /******************************************************************************
126 * IMalloc16_AddRef [COMPOBJ.501]
128 ULONG WINAPI IMalloc16_fnAddRef(IMalloc16* iface) {
129 ICOM_THIS(IMalloc16Impl,iface);
130 TRACE(relay,"(%p)->AddRef()\n",This);
131 return 1; /* cannot be freed */
134 /******************************************************************************
135 * IMalloc16_Release [COMPOBJ.502]
137 ULONG WINAPI IMalloc16_fnRelease(IMalloc16* iface) {
138 ICOM_THIS(IMalloc16Impl,iface);
139 TRACE(relay,"(%p)->Release()\n",This);
140 return 1; /* cannot be freed */
143 /******************************************************************************
144 * IMalloc16_Alloc [COMPOBJ.503]
146 LPVOID WINAPI IMalloc16_fnAlloc(IMalloc16* iface,DWORD cb) {
147 ICOM_THIS(IMalloc16Impl,iface);
148 TRACE(relay,"(%p)->Alloc(%ld)\n",This,cb);
149 return (LPVOID)PTR_SEG_OFF_TO_SEGPTR(This->heap,LOCAL_Alloc(This->heap,0,cb));
152 /******************************************************************************
153 * IMalloc16_Realloc [COMPOBJ.504]
155 LPVOID WINAPI IMalloc16_fnRealloc(IMalloc16* iface,LPVOID pv,DWORD cb) {
156 ICOM_THIS(IMalloc16Impl,iface);
157 TRACE(relay,"(%p)->Realloc(%p,%ld)\n",This,pv,cb);
158 return (LPVOID)PTR_SEG_OFF_TO_SEGPTR(This->heap,LOCAL_ReAlloc(This->heap,0,LOWORD(pv),cb));
161 /******************************************************************************
162 * IMalloc16_Free [COMPOBJ.505]
164 VOID WINAPI IMalloc16_fnFree(IMalloc16* iface,LPVOID pv) {
165 ICOM_THIS(IMalloc16Impl,iface);
166 TRACE(relay,"(%p)->Free(%p)\n",This,pv);
167 LOCAL_Free(This->heap,LOWORD(pv));
170 /******************************************************************************
171 * IMalloc16_GetSize [COMPOBJ.506]
173 DWORD WINAPI IMalloc16_fnGetSize(const IMalloc16* iface,LPVOID pv) {
174 ICOM_CTHIS(IMalloc16Impl,iface);
175 TRACE(relay,"(%p)->GetSize(%p)\n",This,pv);
176 return LOCAL_Size(This->heap,LOWORD(pv));
179 /******************************************************************************
180 * IMalloc16_DidAlloc [COMPOBJ.507]
182 INT16 WINAPI IMalloc16_fnDidAlloc(const IMalloc16* iface,LPVOID pv) {
183 ICOM_CTHIS(IMalloc16,iface);
184 TRACE(relay,"(%p)->DidAlloc(%p)\n",This,pv);
185 return (INT16)-1;
188 /******************************************************************************
189 * IMalloc16_HeapMinimize [COMPOBJ.508]
191 LPVOID WINAPI IMalloc16_fnHeapMinimize(IMalloc16* iface) {
192 ICOM_THIS(IMalloc16Impl,iface);
193 TRACE(relay,"(%p)->HeapMinimize()\n",This);
194 return NULL;
197 static ICOM_VTABLE(IMalloc16)* msegvt16 = NULL;
199 /******************************************************************************
200 * IMalloc16_Constructor [VTABLE]
202 LPMALLOC16
203 IMalloc16_Constructor() {
204 IMalloc16Impl* This;
205 HMODULE16 hcomp = GetModuleHandle16("COMPOBJ");
207 This = (IMalloc16Impl*)SEGPTR_NEW(IMalloc16Impl);
208 if (!msegvt16) {
209 This->lpvtbl = msegvt16 = SEGPTR_NEW(ICOM_VTABLE(IMalloc16));
211 #define VTENT(x) msegvt16->fn##x = (void*)WIN32_GetProcAddress16(hcomp,"IMalloc16_"#x);assert(msegvt16->fn##x)
212 VTENT(QueryInterface);
213 VTENT(AddRef);
214 VTENT(Release);
215 VTENT(Alloc);
216 VTENT(Realloc);
217 VTENT(Free);
218 VTENT(GetSize);
219 VTENT(DidAlloc);
220 VTENT(HeapMinimize);
221 msegvt16 = (ICOM_VTABLE(IMalloc16)*)SEGPTR_GET(msegvt16);
222 #undef VTENT
224 This->ref = 1;
225 /* FIXME: implement multiple heaps */
226 This->heap = GlobalAlloc16(GMEM_MOVEABLE,64000);
227 LocalInit16(This->heap,0,64000);
228 return (LPMALLOC16)SEGPTR_GET(This);
232 /* --- IMalloc32 implementation */
234 typedef struct
236 /* IUnknown fields */
237 ICOM_VTABLE(IMalloc)* lpvtbl;
238 DWORD ref;
239 } IMalloc32Impl;
241 /******************************************************************************
242 * IMalloc32_QueryInterface [VTABLE]
244 static HRESULT WINAPI IMalloc_fnQueryInterface(LPMALLOC iface,REFIID refiid,LPVOID *obj) {
245 ICOM_THIS(IMalloc32Impl,iface);
246 char xrefiid[50];
248 WINE_StringFromCLSID((LPCLSID)refiid,xrefiid);
249 TRACE(relay,"(%p)->QueryInterface(%s,%p)\n",This,xrefiid,obj);
250 if ( !memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) ||
251 !memcmp(&IID_IMalloc,refiid,sizeof(IID_IMalloc))
253 *obj = This;
254 return S_OK;
256 return OLE_E_ENUM_NOMORE;
259 /******************************************************************************
260 * IMalloc32_AddRef [VTABLE]
262 static ULONG WINAPI IMalloc_fnAddRef(LPMALLOC iface) {
263 ICOM_THIS(IMalloc32Impl,iface);
264 TRACE(relay,"(%p)->AddRef()\n",This);
265 return 1; /* cannot be freed */
268 /******************************************************************************
269 * IMalloc32_Release [VTABLE]
271 static ULONG WINAPI IMalloc_fnRelease(LPMALLOC iface) {
272 ICOM_THIS(IMalloc32Impl,iface);
273 TRACE(relay,"(%p)->Release()\n",This);
274 return 1; /* cannot be freed */
277 /******************************************************************************
278 * IMalloc32_Alloc [VTABLE]
280 static LPVOID WINAPI IMalloc_fnAlloc(LPMALLOC iface,DWORD cb) {
281 ICOM_THIS(IMalloc32Impl,iface);
282 TRACE(relay,"(%p)->Alloc(%ld)\n",This,cb);
283 return HeapAlloc(GetProcessHeap(),0,cb);
286 /******************************************************************************
287 * IMalloc32_Realloc [VTABLE]
289 static LPVOID WINAPI IMalloc_fnRealloc(LPMALLOC iface,LPVOID pv,DWORD cb) {
290 ICOM_THIS(IMalloc32Impl,iface);
291 TRACE(relay,"(%p)->Realloc(%p,%ld)\n",This,pv,cb);
292 return HeapReAlloc(GetProcessHeap(),0,pv,cb);
295 /******************************************************************************
296 * IMalloc32_Free [VTABLE]
298 static VOID WINAPI IMalloc_fnFree(LPMALLOC iface,LPVOID pv) {
299 ICOM_THIS(IMalloc32Impl,iface);
300 TRACE(relay,"(%p)->Free(%p)\n",This,pv);
301 HeapFree(GetProcessHeap(),0,pv);
304 /******************************************************************************
305 * IMalloc32_GetSize [VTABLE]
307 static DWORD WINAPI IMalloc_fnGetSize(const IMalloc* iface,LPVOID pv) {
308 ICOM_CTHIS(IMalloc,iface);
309 TRACE(relay,"(%p)->GetSize(%p)\n",This,pv);
310 return HeapSize(GetProcessHeap(),0,pv);
313 /******************************************************************************
314 * IMalloc32_DidAlloc [VTABLE]
316 static INT WINAPI IMalloc_fnDidAlloc(const IMalloc* iface,LPVOID pv) {
317 ICOM_CTHIS(IMalloc32Impl,iface);
318 TRACE(relay,"(%p)->DidAlloc(%p)\n",This,pv);
319 return -1;
322 /******************************************************************************
323 * IMalloc32_HeapMinimize [VTABLE]
325 static LPVOID WINAPI IMalloc_fnHeapMinimize(LPMALLOC iface) {
326 ICOM_THIS(IMalloc32Impl,iface);
327 TRACE(relay,"(%p)->HeapMinimize()\n",This);
328 return NULL;
331 static ICOM_VTABLE(IMalloc) VT_IMalloc32 = {
332 IMalloc_fnQueryInterface,
333 IMalloc_fnAddRef,
334 IMalloc_fnRelease,
335 IMalloc_fnAlloc,
336 IMalloc_fnRealloc,
337 IMalloc_fnFree,
338 IMalloc_fnGetSize,
339 IMalloc_fnDidAlloc,
340 IMalloc_fnHeapMinimize
343 /******************************************************************************
344 * IMalloc32_Constructor [VTABLE]
346 LPMALLOC
347 IMalloc_Constructor() {
348 IMalloc32Impl* This;
350 This = (IMalloc32Impl*)HeapAlloc(GetProcessHeap(),0,sizeof(IMalloc32Impl));
351 This->lpvtbl = &VT_IMalloc32;
352 This->ref = 1;
353 return (LPMALLOC)This;
356 /****************************************************************************
357 * API Functions
360 /******************************************************************************
361 * IsValidInterface32 [OLE32.78]
363 * RETURNS
364 * True, if the passed pointer is a valid interface
366 BOOL WINAPI IsValidInterface(
367 LPUNKNOWN punk /* [in] interface to be tested */
369 return !(
370 IsBadReadPtr(punk,4) ||
371 IsBadReadPtr(punk->lpvtbl,4) ||
372 IsBadReadPtr(punk->lpvtbl->fnQueryInterface,9) ||
373 IsBadCodePtr(punk->lpvtbl->fnQueryInterface)