source: trunk/src/ole32/ifs.c@ 6648

Last change on this file since 6648 was 6648, checked in by bird, 24 years ago

Added $Id:$ keyword.

File size: 10.7 KB
Line 
1/* $Id: ifs.c,v 1.2 2001-09-05 13:17:09 bird Exp $ */
2/*
3 * basic interfaces
4 *
5 * Copyright 1997 Marcus Meissner
6 */
7
8#include <ctype.h>
9#include <stdlib.h>
10#include <string.h>
11#include <assert.h>
12#include "winerror.h"
13#include "heap.h"
14#include "wine/winbase16.h"
15#include "wine/obj_base.h"
16#include "debugtools.h"
17
18#include "ole.h"
19#include "ifs.h"
20
21DEFAULT_DEBUG_CHANNEL(relay);
22
23/* --- IUnknown implementation */
24
25typedef struct
26{
27 /* IUnknown fields */
28 ICOM_VFIELD(IUnknown);
29 DWORD ref;
30} IUnknownImpl;
31
32/******************************************************************************
33 * IUnknown_AddRef [VTABLE:IUNKNOWN.1]
34 */
35static ULONG WINAPI IUnknown_fnAddRef(LPUNKNOWN iface) {
36 ICOM_THIS(IUnknownImpl,iface);
37 TRACE("(%p)->AddRef()\n",This);
38 return ++(This->ref);
39}
40
41/******************************************************************************
42 * IUnknown_Release [VTABLE:IUNKNOWN.2]
43 */
44static ULONG WINAPI IUnknown_fnRelease(LPUNKNOWN iface) {
45 ICOM_THIS(IUnknownImpl,iface);
46 TRACE("(%p)->Release()\n",This);
47 if (!--(This->ref)) {
48 HeapFree(GetProcessHeap(),0,This);
49 return 0;
50 }
51 return This->ref;
52}
53
54/******************************************************************************
55 * IUnknown_QueryInterface [VTABLE:IUNKNOWN.0]
56 */
57static HRESULT WINAPI IUnknown_fnQueryInterface(LPUNKNOWN iface,REFIID refiid,LPVOID *obj) {
58 ICOM_THIS(IUnknownImpl,iface);
59
60 TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(refiid),obj);
61
62 if (!memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown))) {
63 *obj = This;
64 return 0;
65 }
66 return OLE_E_ENUM_NOMORE;
67}
68
69static ICOM_VTABLE(IUnknown) uvt =
70{
71 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
72 IUnknown_fnQueryInterface,
73 IUnknown_fnAddRef,
74 IUnknown_fnRelease
75};
76
77/******************************************************************************
78 * IUnknown_Constructor [INTERNAL]
79 */
80LPUNKNOWN
81IUnknown_Constructor() {
82 IUnknownImpl* unk;
83
84 unk = (IUnknownImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IUnknownImpl));
85 ICOM_VTBL(unk) = &uvt;
86 unk->ref = 1;
87 return (LPUNKNOWN)unk;
88}
89
90#ifndef __WIN32OS2__
91/* --- IMalloc16 implementation */
92
93
94typedef struct
95{
96 /* IUnknown fields */
97 ICOM_VFIELD(IMalloc16);
98 DWORD ref;
99 /* IMalloc16 fields */
100} IMalloc16Impl;
101
102/******************************************************************************
103 * IMalloc16_QueryInterface [COMPOBJ.500]
104 */
105HRESULT WINAPI IMalloc16_fnQueryInterface(IMalloc16* iface,REFIID refiid,LPVOID *obj) {
106 ICOM_THIS(IMalloc16Impl,iface);
107
108 TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(refiid),obj);
109 if ( !memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) ||
110 !memcmp(&IID_IMalloc,refiid,sizeof(IID_IMalloc))
111 ) {
112 *obj = This;
113 return 0;
114 }
115 return OLE_E_ENUM_NOMORE;
116}
117
118/******************************************************************************
119 * IMalloc16_AddRef [COMPOBJ.501]
120 */
121ULONG WINAPI IMalloc16_fnAddRef(IMalloc16* iface) {
122 ICOM_THIS(IMalloc16Impl,iface);
123 TRACE("(%p)->AddRef()\n",This);
124 return 1; /* cannot be freed */
125}
126
127/******************************************************************************
128 * IMalloc16_Release [COMPOBJ.502]
129 */
130ULONG WINAPI IMalloc16_fnRelease(IMalloc16* iface) {
131 ICOM_THIS(IMalloc16Impl,iface);
132 TRACE("(%p)->Release()\n",This);
133 return 1; /* cannot be freed */
134}
135
136/******************************************************************************
137 * IMalloc16_Alloc [COMPOBJ.503]
138 */
139SEGPTR WINAPI IMalloc16_fnAlloc(IMalloc16* iface,DWORD cb) {
140 ICOM_THIS(IMalloc16Impl,iface);
141 TRACE("(%p)->Alloc(%ld)\n",This,cb);
142 return MapLS( HeapAlloc( GetProcessHeap(), HEAP_WINE_SEGPTR, cb ) );
143}
144
145/******************************************************************************
146 * IMalloc16_Realloc [COMPOBJ.504]
147 */
148SEGPTR WINAPI IMalloc16_fnRealloc(IMalloc16* iface,SEGPTR pv,DWORD cb) {
149 ICOM_THIS(IMalloc16Impl,iface);
150 TRACE("(%p)->Realloc(%08lx,%ld)\n",This,pv,cb);
151 return MapLS( HeapReAlloc( GetProcessHeap(), HEAP_WINE_SEGPTR, MapSL(pv), cb ) );
152}
153
154/******************************************************************************
155 * IMalloc16_Free [COMPOBJ.505]
156 */
157VOID WINAPI IMalloc16_fnFree(IMalloc16* iface,SEGPTR pv) {
158 ICOM_THIS(IMalloc16Impl,iface);
159 TRACE("(%p)->Free(%08lx)\n",This,pv);
160 HeapFree( GetProcessHeap(), HEAP_WINE_SEGPTR, MapSL(pv) );
161}
162
163/******************************************************************************
164 * IMalloc16_GetSize [COMPOBJ.506]
165 */
166DWORD WINAPI IMalloc16_fnGetSize(const IMalloc16* iface,SEGPTR pv)
167{
168 ICOM_CTHIS(IMalloc16Impl,iface);
169 TRACE("(%p)->GetSize(%08lx)\n",This,pv);
170 return HeapSize( GetProcessHeap(), HEAP_WINE_SEGPTR, MapSL(pv) );
171}
172
173/******************************************************************************
174 * IMalloc16_DidAlloc [COMPOBJ.507]
175 */
176INT16 WINAPI IMalloc16_fnDidAlloc(const IMalloc16* iface,LPVOID pv) {
177 ICOM_CTHIS(IMalloc16,iface);
178 TRACE("(%p)->DidAlloc(%p)\n",This,pv);
179 return (INT16)-1;
180}
181
182/******************************************************************************
183 * IMalloc16_HeapMinimize [COMPOBJ.508]
184 */
185LPVOID WINAPI IMalloc16_fnHeapMinimize(IMalloc16* iface) {
186 ICOM_THIS(IMalloc16Impl,iface);
187 TRACE("(%p)->HeapMinimize()\n",This);
188 return NULL;
189}
190
191static ICOM_VTABLE(IMalloc16)* msegvt16 = NULL;
192
193/******************************************************************************
194 * IMalloc16_Constructor [VTABLE]
195 */
196LPMALLOC16
197IMalloc16_Constructor() {
198 IMalloc16Impl* This;
199 HMODULE16 hcomp = GetModuleHandle16("COMPOBJ");
200
201 This = (IMalloc16Impl*)SEGPTR_NEW(IMalloc16Impl);
202 if (!msegvt16) {
203 msegvt16 = SEGPTR_NEW(ICOM_VTABLE(IMalloc16));
204
205#define VTENT(x) msegvt16->x = (void*)GetProcAddress16(hcomp,"IMalloc16_"#x);assert(msegvt16->x)
206 VTENT(QueryInterface);
207 VTENT(AddRef);
208 VTENT(Release);
209 VTENT(Alloc);
210 VTENT(Realloc);
211 VTENT(Free);
212 VTENT(GetSize);
213 VTENT(DidAlloc);
214 VTENT(HeapMinimize);
215#undef VTENT
216 }
217 ICOM_VTBL(This) = (ICOM_VTABLE(IMalloc16)*)SEGPTR_GET(msegvt16);
218 This->ref = 1;
219 return (LPMALLOC16)SEGPTR_GET(This);
220}
221#endif
222
223/* --- IMalloc32 implementation */
224
225typedef struct
226{
227 /* IUnknown fields */
228 ICOM_VFIELD(IMalloc);
229 DWORD ref;
230} IMalloc32Impl;
231
232/******************************************************************************
233 * IMalloc32_QueryInterface [VTABLE]
234 */
235static HRESULT WINAPI IMalloc_fnQueryInterface(LPMALLOC iface,REFIID refiid,LPVOID *obj) {
236 ICOM_THIS(IMalloc32Impl,iface);
237
238 TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(refiid),obj);
239 if ( !memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) ||
240 !memcmp(&IID_IMalloc,refiid,sizeof(IID_IMalloc))
241 ) {
242 *obj = This;
243 return S_OK;
244 }
245 return OLE_E_ENUM_NOMORE;
246}
247
248/******************************************************************************
249 * IMalloc32_AddRef [VTABLE]
250 */
251static ULONG WINAPI IMalloc_fnAddRef(LPMALLOC iface) {
252 ICOM_THIS(IMalloc32Impl,iface);
253 TRACE("(%p)->AddRef()\n",This);
254 return 1; /* cannot be freed */
255}
256
257/******************************************************************************
258 * IMalloc32_Release [VTABLE]
259 */
260static ULONG WINAPI IMalloc_fnRelease(LPMALLOC iface) {
261 ICOM_THIS(IMalloc32Impl,iface);
262 TRACE("(%p)->Release()\n",This);
263 return 1; /* cannot be freed */
264}
265
266/******************************************************************************
267 * IMalloc32_Alloc [VTABLE]
268 */
269static LPVOID WINAPI IMalloc_fnAlloc(LPMALLOC iface,DWORD cb) {
270 LPVOID addr;
271 ICOM_THIS(IMalloc32Impl,iface);
272 addr = HeapAlloc(GetProcessHeap(),0,cb);
273 TRACE("(%p)->Alloc(%ld) -> %p\n",This,cb,addr);
274 return addr;
275}
276
277/******************************************************************************
278 * IMalloc32_Realloc [VTABLE]
279 */
280static LPVOID WINAPI IMalloc_fnRealloc(LPMALLOC iface,LPVOID pv,DWORD cb) {
281 ICOM_THIS(IMalloc32Impl,iface);
282 TRACE("(%p)->Realloc(%p,%ld)\n",This,pv,cb);
283 return HeapReAlloc(GetProcessHeap(),0,pv,cb);
284}
285
286/******************************************************************************
287 * IMalloc32_Free [VTABLE]
288 */
289static VOID WINAPI IMalloc_fnFree(LPMALLOC iface,LPVOID pv) {
290 ICOM_THIS(IMalloc32Impl,iface);
291 TRACE("(%p)->Free(%p)\n",This,pv);
292 HeapFree(GetProcessHeap(),0,pv);
293}
294
295/******************************************************************************
296 * IMalloc32_GetSize [VTABLE]
297 */
298static DWORD WINAPI IMalloc_fnGetSize(LPMALLOC iface,LPVOID pv) {
299 ICOM_CTHIS(IMalloc,iface);
300 TRACE("(%p)->GetSize(%p)\n",This,pv);
301 return HeapSize(GetProcessHeap(),0,pv);
302}
303
304/******************************************************************************
305 * IMalloc32_DidAlloc [VTABLE]
306 */
307static INT WINAPI IMalloc_fnDidAlloc(LPMALLOC iface,LPVOID pv) {
308 ICOM_CTHIS(IMalloc32Impl,iface);
309 TRACE("(%p)->DidAlloc(%p)\n",This,pv);
310 return -1;
311}
312
313/******************************************************************************
314 * IMalloc32_HeapMinimize [VTABLE]
315 */
316static VOID WINAPI IMalloc_fnHeapMinimize(LPMALLOC iface) {
317 ICOM_THIS(IMalloc32Impl,iface);
318 TRACE("(%p)->HeapMinimize()\n",This);
319}
320
321static ICOM_VTABLE(IMalloc) VT_IMalloc32 =
322{
323 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
324 IMalloc_fnQueryInterface,
325 IMalloc_fnAddRef,
326 IMalloc_fnRelease,
327 IMalloc_fnAlloc,
328 IMalloc_fnRealloc,
329 IMalloc_fnFree,
330 IMalloc_fnGetSize,
331 IMalloc_fnDidAlloc,
332 IMalloc_fnHeapMinimize
333};
334
335/******************************************************************************
336 * IMalloc32_Constructor [VTABLE]
337 */
338LPMALLOC
339IMalloc_Constructor() {
340 IMalloc32Impl* This;
341
342 This = (IMalloc32Impl*)HeapAlloc(GetProcessHeap(),0,sizeof(IMalloc32Impl));
343 ICOM_VTBL(This) = &VT_IMalloc32;
344 This->ref = 1;
345 return (LPMALLOC)This;
346}
347
348/****************************************************************************
349 * API Functions
350 */
351
352/******************************************************************************
353 * IsValidInterface [OLE32.78]
354 *
355 * RETURNS
356 * True, if the passed pointer is a valid interface
357 */
358BOOL WINAPI IsValidInterface(
359 LPUNKNOWN punk /* [in] interface to be tested */
360) {
361 return !(
362 IsBadReadPtr(punk,4) ||
363 IsBadReadPtr(ICOM_VTBL(punk),4) ||
364#ifdef __WIN32OS2__
365 IsBadReadPtr(ICOM_VTBL(punk)->fnQueryInterface,9) ||
366 IsBadCodePtr((FARPROC)ICOM_VTBL(punk)->fnQueryInterface)
367#else
368 IsBadReadPtr(ICOM_VTBL(punk)->QueryInterface,9) ||
369 IsBadCodePtr((FARPROC)ICOM_VTBL(punk)->QueryInterface)
370#endif
371 );
372}
Note: See TracBrowser for help on using the repository browser.