4 * Copyright 1997 Marcus Meissner
13 #include "wine/winbase16.h"
14 #include "wine/obj_base.h"
15 #include "debugtools.h"
20 DEFAULT_DEBUG_CHANNEL(relay);
22 /* --- IUnknown implementation */
27 ICOM_VFIELD(IUnknown);
31 /******************************************************************************
32 * IUnknown_AddRef [VTABLE:IUNKNOWN.1]
34 static ULONG WINAPI IUnknown_fnAddRef(LPUNKNOWN iface) {
35 ICOM_THIS(IUnknownImpl,iface);
36 TRACE("(%p)->AddRef()\n",This);
40 /******************************************************************************
41 * IUnknown_Release [VTABLE:IUNKNOWN.2]
43 static ULONG WINAPI IUnknown_fnRelease(LPUNKNOWN iface) {
44 ICOM_THIS(IUnknownImpl,iface);
45 TRACE("(%p)->Release()\n",This);
47 HeapFree(GetProcessHeap(),0,This);
53 /******************************************************************************
54 * IUnknown_QueryInterface [VTABLE:IUNKNOWN.0]
56 static HRESULT WINAPI IUnknown_fnQueryInterface(LPUNKNOWN iface,REFIID refiid,LPVOID *obj) {
57 ICOM_THIS(IUnknownImpl,iface);
59 TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(refiid),obj);
61 if (!memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown))) {
65 return OLE_E_ENUM_NOMORE;
68 static ICOM_VTABLE(IUnknown) uvt =
70 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
71 IUnknown_fnQueryInterface,
76 /******************************************************************************
77 * IUnknown_Constructor [INTERNAL]
80 IUnknown_Constructor() {
83 unk = (IUnknownImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IUnknownImpl));
84 ICOM_VTBL(unk) = &uvt;
86 return (LPUNKNOWN)unk;
90 /* --- IMalloc16 implementation */
96 ICOM_VFIELD(IMalloc16);
98 /* IMalloc16 fields */
101 /******************************************************************************
102 * IMalloc16_QueryInterface [COMPOBJ.500]
104 HRESULT WINAPI IMalloc16_fnQueryInterface(IMalloc16* iface,REFIID refiid,LPVOID *obj) {
105 ICOM_THIS(IMalloc16Impl,iface);
107 TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(refiid),obj);
108 if ( !memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) ||
109 !memcmp(&IID_IMalloc,refiid,sizeof(IID_IMalloc))
114 return OLE_E_ENUM_NOMORE;
117 /******************************************************************************
118 * IMalloc16_AddRef [COMPOBJ.501]
120 ULONG WINAPI IMalloc16_fnAddRef(IMalloc16* iface) {
121 ICOM_THIS(IMalloc16Impl,iface);
122 TRACE("(%p)->AddRef()\n",This);
123 return 1; /* cannot be freed */
126 /******************************************************************************
127 * IMalloc16_Release [COMPOBJ.502]
129 ULONG WINAPI IMalloc16_fnRelease(IMalloc16* iface) {
130 ICOM_THIS(IMalloc16Impl,iface);
131 TRACE("(%p)->Release()\n",This);
132 return 1; /* cannot be freed */
135 /******************************************************************************
136 * IMalloc16_Alloc [COMPOBJ.503]
138 SEGPTR WINAPI IMalloc16_fnAlloc(IMalloc16* iface,DWORD cb) {
139 ICOM_THIS(IMalloc16Impl,iface);
140 TRACE("(%p)->Alloc(%ld)\n",This,cb);
141 return MapLS( HeapAlloc( GetProcessHeap(), HEAP_WINE_SEGPTR, cb ) );
144 /******************************************************************************
145 * IMalloc16_Realloc [COMPOBJ.504]
147 SEGPTR WINAPI IMalloc16_fnRealloc(IMalloc16* iface,SEGPTR pv,DWORD cb) {
148 ICOM_THIS(IMalloc16Impl,iface);
149 TRACE("(%p)->Realloc(%08lx,%ld)\n",This,pv,cb);
150 return MapLS( HeapReAlloc( GetProcessHeap(), HEAP_WINE_SEGPTR, MapSL(pv), cb ) );
153 /******************************************************************************
154 * IMalloc16_Free [COMPOBJ.505]
156 VOID WINAPI IMalloc16_fnFree(IMalloc16* iface,SEGPTR pv) {
157 ICOM_THIS(IMalloc16Impl,iface);
158 TRACE("(%p)->Free(%08lx)\n",This,pv);
159 HeapFree( GetProcessHeap(), HEAP_WINE_SEGPTR, MapSL(pv) );
162 /******************************************************************************
163 * IMalloc16_GetSize [COMPOBJ.506]
165 DWORD WINAPI IMalloc16_fnGetSize(const IMalloc16* iface,SEGPTR pv)
167 ICOM_CTHIS(IMalloc16Impl,iface);
168 TRACE("(%p)->GetSize(%08lx)\n",This,pv);
169 return HeapSize( GetProcessHeap(), HEAP_WINE_SEGPTR, MapSL(pv) );
172 /******************************************************************************
173 * IMalloc16_DidAlloc [COMPOBJ.507]
175 INT16 WINAPI IMalloc16_fnDidAlloc(const IMalloc16* iface,LPVOID pv) {
176 ICOM_CTHIS(IMalloc16,iface);
177 TRACE("(%p)->DidAlloc(%p)\n",This,pv);
181 /******************************************************************************
182 * IMalloc16_HeapMinimize [COMPOBJ.508]
184 LPVOID WINAPI IMalloc16_fnHeapMinimize(IMalloc16* iface) {
185 ICOM_THIS(IMalloc16Impl,iface);
186 TRACE("(%p)->HeapMinimize()\n",This);
190 static ICOM_VTABLE(IMalloc16)* msegvt16 = NULL;
192 /******************************************************************************
193 * IMalloc16_Constructor [VTABLE]
196 IMalloc16_Constructor() {
198 HMODULE16 hcomp = GetModuleHandle16("COMPOBJ");
200 This = (IMalloc16Impl*)SEGPTR_NEW(IMalloc16Impl);
202 msegvt16 = SEGPTR_NEW(ICOM_VTABLE(IMalloc16));
204 #define VTENT(x) msegvt16->x = (void*)GetProcAddress16(hcomp,"IMalloc16_"#x);assert(msegvt16->x)
205 VTENT(QueryInterface);
216 ICOM_VTBL(This) = (ICOM_VTABLE(IMalloc16)*)SEGPTR_GET(msegvt16);
218 return (LPMALLOC16)SEGPTR_GET(This);
222 /* --- IMalloc32 implementation */
226 /* IUnknown fields */
227 ICOM_VFIELD(IMalloc);
231 /******************************************************************************
232 * IMalloc32_QueryInterface [VTABLE]
234 static HRESULT WINAPI IMalloc_fnQueryInterface(LPMALLOC iface,REFIID refiid,LPVOID *obj) {
235 ICOM_THIS(IMalloc32Impl,iface);
237 TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(refiid),obj);
238 if ( !memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) ||
239 !memcmp(&IID_IMalloc,refiid,sizeof(IID_IMalloc))
244 return OLE_E_ENUM_NOMORE;
247 /******************************************************************************
248 * IMalloc32_AddRef [VTABLE]
250 static ULONG WINAPI IMalloc_fnAddRef(LPMALLOC iface) {
251 ICOM_THIS(IMalloc32Impl,iface);
252 TRACE("(%p)->AddRef()\n",This);
253 return 1; /* cannot be freed */
256 /******************************************************************************
257 * IMalloc32_Release [VTABLE]
259 static ULONG WINAPI IMalloc_fnRelease(LPMALLOC iface) {
260 ICOM_THIS(IMalloc32Impl,iface);
261 TRACE("(%p)->Release()\n",This);
262 return 1; /* cannot be freed */
265 /******************************************************************************
266 * IMalloc32_Alloc [VTABLE]
268 static LPVOID WINAPI IMalloc_fnAlloc(LPMALLOC iface,DWORD cb) {
270 ICOM_THIS(IMalloc32Impl,iface);
271 addr = HeapAlloc(GetProcessHeap(),0,cb);
272 TRACE("(%p)->Alloc(%ld) -> %p\n",This,cb,addr);
276 /******************************************************************************
277 * IMalloc32_Realloc [VTABLE]
279 static LPVOID WINAPI IMalloc_fnRealloc(LPMALLOC iface,LPVOID pv,DWORD cb) {
280 ICOM_THIS(IMalloc32Impl,iface);
281 TRACE("(%p)->Realloc(%p,%ld)\n",This,pv,cb);
282 return HeapReAlloc(GetProcessHeap(),0,pv,cb);
285 /******************************************************************************
286 * IMalloc32_Free [VTABLE]
288 static VOID WINAPI IMalloc_fnFree(LPMALLOC iface,LPVOID pv) {
289 ICOM_THIS(IMalloc32Impl,iface);
290 TRACE("(%p)->Free(%p)\n",This,pv);
291 HeapFree(GetProcessHeap(),0,pv);
294 /******************************************************************************
295 * IMalloc32_GetSize [VTABLE]
297 static DWORD WINAPI IMalloc_fnGetSize(LPMALLOC iface,LPVOID pv) {
298 ICOM_CTHIS(IMalloc,iface);
299 TRACE("(%p)->GetSize(%p)\n",This,pv);
300 return HeapSize(GetProcessHeap(),0,pv);
303 /******************************************************************************
304 * IMalloc32_DidAlloc [VTABLE]
306 static INT WINAPI IMalloc_fnDidAlloc(LPMALLOC iface,LPVOID pv) {
307 ICOM_CTHIS(IMalloc32Impl,iface);
308 TRACE("(%p)->DidAlloc(%p)\n",This,pv);
312 /******************************************************************************
313 * IMalloc32_HeapMinimize [VTABLE]
315 static VOID WINAPI IMalloc_fnHeapMinimize(LPMALLOC iface) {
316 ICOM_THIS(IMalloc32Impl,iface);
317 TRACE("(%p)->HeapMinimize()\n",This);
320 static ICOM_VTABLE(IMalloc) VT_IMalloc32 =
322 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
323 IMalloc_fnQueryInterface,
331 IMalloc_fnHeapMinimize
334 /******************************************************************************
335 * IMalloc32_Constructor [VTABLE]
338 IMalloc_Constructor() {
341 This = (IMalloc32Impl*)HeapAlloc(GetProcessHeap(),0,sizeof(IMalloc32Impl));
342 ICOM_VTBL(This) = &VT_IMalloc32;
344 return (LPMALLOC)This;
347 /****************************************************************************
351 /******************************************************************************
352 * IsValidInterface [OLE32.78]
355 * True, if the passed pointer is a valid interface
357 BOOL WINAPI IsValidInterface(
358 LPUNKNOWN punk /* [in] interface to be tested */
361 IsBadReadPtr(punk,4) ||
362 IsBadReadPtr(ICOM_VTBL(punk),4) ||
363 IsBadReadPtr(ICOM_VTBL(punk)->QueryInterface,9) ||
364 IsBadCodePtr((FARPROC)ICOM_VTBL(punk)->QueryInterface)