4 * Copyright 1997 Marcus Meissner
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #include "wine/obj_base.h"
33 #include "wine/winbase16.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(relay
);
40 /* --- IUnknown implementation */
45 ICOM_VFIELD(IUnknown
);
49 /******************************************************************************
50 * IUnknown_AddRef [VTABLE:IUNKNOWN.1]
52 static ULONG WINAPI
IUnknown_fnAddRef(LPUNKNOWN iface
) {
53 ICOM_THIS(IUnknownImpl
,iface
);
54 TRACE("(%p)->AddRef()\n",This
);
58 /******************************************************************************
59 * IUnknown_Release [VTABLE:IUNKNOWN.2]
61 static ULONG WINAPI
IUnknown_fnRelease(LPUNKNOWN iface
) {
62 ICOM_THIS(IUnknownImpl
,iface
);
63 TRACE("(%p)->Release()\n",This
);
65 HeapFree(GetProcessHeap(),0,This
);
71 /******************************************************************************
72 * IUnknown_QueryInterface [VTABLE:IUNKNOWN.0]
74 static HRESULT WINAPI
IUnknown_fnQueryInterface(LPUNKNOWN iface
,REFIID refiid
,LPVOID
*obj
) {
75 ICOM_THIS(IUnknownImpl
,iface
);
77 TRACE("(%p)->QueryInterface(%s,%p)\n",This
,debugstr_guid(refiid
),obj
);
79 if (!memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
))) {
83 return OLE_E_ENUM_NOMORE
;
86 static ICOM_VTABLE(IUnknown
) uvt
=
88 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
89 IUnknown_fnQueryInterface
,
94 /******************************************************************************
95 * IUnknown_Constructor [INTERNAL]
98 IUnknown_Constructor() {
101 unk
= (IUnknownImpl
*)HeapAlloc(GetProcessHeap(),0,sizeof(IUnknownImpl
));
102 ICOM_VTBL(unk
) = &uvt
;
104 return (LPUNKNOWN
)unk
;
108 /* --- IMalloc16 implementation */
113 /* IUnknown fields */
114 ICOM_VFIELD(IMalloc16
);
116 /* IMalloc16 fields */
119 /******************************************************************************
120 * IMalloc16_QueryInterface [COMPOBJ.500]
122 HRESULT WINAPI
IMalloc16_fnQueryInterface(IMalloc16
* iface
,REFIID refiid
,LPVOID
*obj
) {
123 ICOM_THIS(IMalloc16Impl
,iface
);
125 TRACE("(%p)->QueryInterface(%s,%p)\n",This
,debugstr_guid(refiid
),obj
);
126 if ( !memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
)) ||
127 !memcmp(&IID_IMalloc
,refiid
,sizeof(IID_IMalloc
))
132 return OLE_E_ENUM_NOMORE
;
135 /******************************************************************************
136 * IMalloc16_AddRef [COMPOBJ.501]
138 ULONG WINAPI
IMalloc16_fnAddRef(IMalloc16
* iface
) {
139 ICOM_THIS(IMalloc16Impl
,iface
);
140 TRACE("(%p)->AddRef()\n",This
);
141 return 1; /* cannot be freed */
144 /******************************************************************************
145 * IMalloc16_Release [COMPOBJ.502]
147 ULONG WINAPI
IMalloc16_fnRelease(IMalloc16
* iface
) {
148 ICOM_THIS(IMalloc16Impl
,iface
);
149 TRACE("(%p)->Release()\n",This
);
150 return 1; /* cannot be freed */
153 /******************************************************************************
154 * IMalloc16_Alloc [COMPOBJ.503]
156 SEGPTR WINAPI
IMalloc16_fnAlloc(IMalloc16
* iface
,DWORD cb
) {
157 ICOM_THIS(IMalloc16Impl
,iface
);
158 TRACE("(%p)->Alloc(%ld)\n",This
,cb
);
159 return MapLS( HeapAlloc( GetProcessHeap(), 0, cb
) );
162 /******************************************************************************
163 * IMalloc16_Realloc [COMPOBJ.504]
165 SEGPTR WINAPI
IMalloc16_fnRealloc(IMalloc16
* iface
,SEGPTR pv
,DWORD cb
)
168 ICOM_THIS(IMalloc16Impl
,iface
);
169 TRACE("(%p)->Realloc(%08lx,%ld)\n",This
,pv
,cb
);
170 ret
= MapLS( HeapReAlloc( GetProcessHeap(), 0, MapSL(pv
), cb
) );
175 /******************************************************************************
176 * IMalloc16_Free [COMPOBJ.505]
178 VOID WINAPI
IMalloc16_fnFree(IMalloc16
* iface
,SEGPTR pv
)
180 void *ptr
= MapSL(pv
);
181 ICOM_THIS(IMalloc16Impl
,iface
);
182 TRACE("(%p)->Free(%08lx)\n",This
,pv
);
184 HeapFree( GetProcessHeap(), 0, ptr
);
187 /******************************************************************************
188 * IMalloc16_GetSize [COMPOBJ.506]
190 DWORD WINAPI
IMalloc16_fnGetSize(const IMalloc16
* iface
,SEGPTR pv
)
192 ICOM_CTHIS(IMalloc16Impl
,iface
);
193 TRACE("(%p)->GetSize(%08lx)\n",This
,pv
);
194 return HeapSize( GetProcessHeap(), 0, MapSL(pv
) );
197 /******************************************************************************
198 * IMalloc16_DidAlloc [COMPOBJ.507]
200 INT16 WINAPI
IMalloc16_fnDidAlloc(const IMalloc16
* iface
,LPVOID pv
) {
201 ICOM_CTHIS(IMalloc16
,iface
);
202 TRACE("(%p)->DidAlloc(%p)\n",This
,pv
);
206 /******************************************************************************
207 * IMalloc16_HeapMinimize [COMPOBJ.508]
209 LPVOID WINAPI
IMalloc16_fnHeapMinimize(IMalloc16
* iface
) {
210 ICOM_THIS(IMalloc16Impl
,iface
);
211 TRACE("(%p)->HeapMinimize()\n",This
);
215 /******************************************************************************
216 * IMalloc16_Constructor [VTABLE]
219 IMalloc16_Constructor()
221 static ICOM_VTABLE(IMalloc16
) vt16
;
222 static SEGPTR msegvt16
;
224 HMODULE16 hcomp
= GetModuleHandle16("COMPOBJ");
226 This
= HeapAlloc( GetProcessHeap(), 0, sizeof(IMalloc16Impl
) );
229 #define VTENT(x) vt16.x = (void*)GetProcAddress16(hcomp,"IMalloc16_"#x);assert(vt16.x)
230 VTENT(QueryInterface
);
240 msegvt16
= MapLS( &vt16
);
242 ICOM_VTBL(This
) = (ICOM_VTABLE(IMalloc16
)*)msegvt16
;
244 return (LPMALLOC16
)MapLS( This
);
248 /* --- IMalloc32 implementation */
252 /* IUnknown fields */
253 ICOM_VFIELD(IMalloc
);
257 /******************************************************************************
258 * IMalloc32_QueryInterface [VTABLE]
260 static HRESULT WINAPI
IMalloc_fnQueryInterface(LPMALLOC iface
,REFIID refiid
,LPVOID
*obj
) {
261 ICOM_THIS(IMalloc32Impl
,iface
);
263 TRACE("(%p)->QueryInterface(%s,%p)\n",This
,debugstr_guid(refiid
),obj
);
264 if ( !memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
)) ||
265 !memcmp(&IID_IMalloc
,refiid
,sizeof(IID_IMalloc
))
270 return OLE_E_ENUM_NOMORE
;
273 /******************************************************************************
274 * IMalloc32_AddRef [VTABLE]
276 static ULONG WINAPI
IMalloc_fnAddRef(LPMALLOC iface
) {
277 ICOM_THIS(IMalloc32Impl
,iface
);
278 TRACE("(%p)->AddRef()\n",This
);
279 return 1; /* cannot be freed */
282 /******************************************************************************
283 * IMalloc32_Release [VTABLE]
285 static ULONG WINAPI
IMalloc_fnRelease(LPMALLOC iface
) {
286 ICOM_THIS(IMalloc32Impl
,iface
);
287 TRACE("(%p)->Release()\n",This
);
288 return 1; /* cannot be freed */
291 /******************************************************************************
292 * IMalloc32_Alloc [VTABLE]
294 static LPVOID WINAPI
IMalloc_fnAlloc(LPMALLOC iface
,DWORD cb
) {
296 ICOM_THIS(IMalloc32Impl
,iface
);
297 addr
= HeapAlloc(GetProcessHeap(),0,cb
);
298 TRACE("(%p)->Alloc(%ld) -> %p\n",This
,cb
,addr
);
302 /******************************************************************************
303 * IMalloc32_Realloc [VTABLE]
305 static LPVOID WINAPI
IMalloc_fnRealloc(LPMALLOC iface
,LPVOID pv
,DWORD cb
) {
306 ICOM_THIS(IMalloc32Impl
,iface
);
307 TRACE("(%p)->Realloc(%p,%ld)\n",This
,pv
,cb
);
308 return HeapReAlloc(GetProcessHeap(),0,pv
,cb
);
311 /******************************************************************************
312 * IMalloc32_Free [VTABLE]
314 static VOID WINAPI
IMalloc_fnFree(LPMALLOC iface
,LPVOID pv
) {
315 ICOM_THIS(IMalloc32Impl
,iface
);
316 TRACE("(%p)->Free(%p)\n",This
,pv
);
317 HeapFree(GetProcessHeap(),0,pv
);
320 /******************************************************************************
321 * IMalloc32_GetSize [VTABLE]
323 static DWORD WINAPI
IMalloc_fnGetSize(LPMALLOC iface
,LPVOID pv
) {
324 ICOM_CTHIS(IMalloc
,iface
);
325 TRACE("(%p)->GetSize(%p)\n",This
,pv
);
326 return HeapSize(GetProcessHeap(),0,pv
);
329 /******************************************************************************
330 * IMalloc32_DidAlloc [VTABLE]
332 static INT WINAPI
IMalloc_fnDidAlloc(LPMALLOC iface
,LPVOID pv
) {
333 ICOM_CTHIS(IMalloc32Impl
,iface
);
334 TRACE("(%p)->DidAlloc(%p)\n",This
,pv
);
338 /******************************************************************************
339 * IMalloc32_HeapMinimize [VTABLE]
341 static VOID WINAPI
IMalloc_fnHeapMinimize(LPMALLOC iface
) {
342 ICOM_THIS(IMalloc32Impl
,iface
);
343 TRACE("(%p)->HeapMinimize()\n",This
);
346 static ICOM_VTABLE(IMalloc
) VT_IMalloc32
=
348 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
349 IMalloc_fnQueryInterface
,
357 IMalloc_fnHeapMinimize
360 /******************************************************************************
361 * IMalloc32_Constructor [VTABLE]
364 IMalloc_Constructor() {
367 This
= (IMalloc32Impl
*)HeapAlloc(GetProcessHeap(),0,sizeof(IMalloc32Impl
));
368 ICOM_VTBL(This
) = &VT_IMalloc32
;
370 return (LPMALLOC
)This
;
373 /****************************************************************************
377 /******************************************************************************
378 * IsValidInterface [OLE32.78]
381 * True, if the passed pointer is a valid interface
383 BOOL WINAPI
IsValidInterface(
384 LPUNKNOWN punk
/* [in] interface to be tested */
387 IsBadReadPtr(punk
,4) ||
388 IsBadReadPtr(ICOM_VTBL(punk
),4) ||
389 IsBadReadPtr(ICOM_VTBL(punk
)->QueryInterface
,9) ||
390 IsBadCodePtr((FARPROC
)ICOM_VTBL(punk
)->QueryInterface
)