4 * Copyright 1997 Marcus Meissner
14 #include "wine/winbase16.h"
15 #include "wine/obj_base.h"
18 #include "debugtools.h"
22 DEFAULT_DEBUG_CHANNEL(relay)
24 /* --- IUnknown implementation */
29 ICOM_VTABLE(IUnknown)* lpvtbl;
33 /******************************************************************************
34 * IUnknown_AddRef [VTABLE:IUNKNOWN.1]
36 static ULONG WINAPI IUnknown_fnAddRef(LPUNKNOWN iface) {
37 ICOM_THIS(IUnknownImpl,iface);
38 TRACE("(%p)->AddRef()\n",This);
42 /******************************************************************************
43 * IUnknown_Release [VTABLE:IUNKNOWN.2]
45 static ULONG WINAPI IUnknown_fnRelease(LPUNKNOWN iface) {
46 ICOM_THIS(IUnknownImpl,iface);
47 TRACE("(%p)->Release()\n",This);
49 HeapFree(GetProcessHeap(),0,This);
55 /******************************************************************************
56 * IUnknown_QueryInterface [VTABLE:IUNKNOWN.0]
58 static HRESULT WINAPI IUnknown_fnQueryInterface(LPUNKNOWN iface,REFIID refiid,LPVOID *obj) {
59 ICOM_THIS(IUnknownImpl,iface);
62 WINE_StringFromCLSID((LPCLSID)refiid,xrefiid);
63 TRACE("(%p)->QueryInterface(%s,%p)\n",This,xrefiid,obj);
65 if (!memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown))) {
69 return OLE_E_ENUM_NOMORE;
72 static ICOM_VTABLE(IUnknown) uvt =
74 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
75 IUnknown_fnQueryInterface,
80 /******************************************************************************
81 * IUnknown_Constructor [INTERNAL]
84 IUnknown_Constructor() {
87 unk = (IUnknownImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IUnknownImpl));
90 return (LPUNKNOWN)unk;
94 /* --- IMalloc16 implementation */
100 ICOM_VTABLE(IMalloc16)* lpvtbl;
102 /* IMalloc16 fields */
103 /* Gmm, I think one is not enough, we should probably manage a list of
109 /******************************************************************************
110 * IMalloc16_QueryInterface [COMPOBJ.500]
112 HRESULT WINAPI IMalloc16_fnQueryInterface(IMalloc16* iface,REFIID refiid,LPVOID *obj) {
113 ICOM_THIS(IMalloc16Impl,iface);
116 WINE_StringFromCLSID((LPCLSID)refiid,xrefiid);
117 TRACE("(%p)->QueryInterface(%s,%p)\n",This,xrefiid,obj);
118 if ( !memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) ||
119 !memcmp(&IID_IMalloc,refiid,sizeof(IID_IMalloc))
124 return OLE_E_ENUM_NOMORE;
127 /******************************************************************************
128 * IMalloc16_AddRef [COMPOBJ.501]
130 ULONG WINAPI IMalloc16_fnAddRef(IMalloc16* iface) {
131 ICOM_THIS(IMalloc16Impl,iface);
132 TRACE("(%p)->AddRef()\n",This);
133 return 1; /* cannot be freed */
136 /******************************************************************************
137 * IMalloc16_Release [COMPOBJ.502]
139 ULONG WINAPI IMalloc16_fnRelease(IMalloc16* iface) {
140 ICOM_THIS(IMalloc16Impl,iface);
141 TRACE("(%p)->Release()\n",This);
142 return 1; /* cannot be freed */
145 /******************************************************************************
146 * IMalloc16_Alloc [COMPOBJ.503]
148 LPVOID WINAPI IMalloc16_fnAlloc(IMalloc16* iface,DWORD cb) {
149 ICOM_THIS(IMalloc16Impl,iface);
150 TRACE("(%p)->Alloc(%ld)\n",This,cb);
151 return (LPVOID)PTR_SEG_OFF_TO_SEGPTR(This->heap,LOCAL_Alloc(This->heap,0,cb));
154 /******************************************************************************
155 * IMalloc16_Realloc [COMPOBJ.504]
157 LPVOID WINAPI IMalloc16_fnRealloc(IMalloc16* iface,LPVOID pv,DWORD cb) {
158 ICOM_THIS(IMalloc16Impl,iface);
159 TRACE("(%p)->Realloc(%p,%ld)\n",This,pv,cb);
160 return (LPVOID)PTR_SEG_OFF_TO_SEGPTR(This->heap,LOCAL_ReAlloc(This->heap,0,LOWORD(pv),cb));
163 /******************************************************************************
164 * IMalloc16_Free [COMPOBJ.505]
166 VOID WINAPI IMalloc16_fnFree(IMalloc16* iface,LPVOID pv) {
167 ICOM_THIS(IMalloc16Impl,iface);
168 TRACE("(%p)->Free(%p)\n",This,pv);
169 LOCAL_Free(This->heap,LOWORD(pv));
172 /******************************************************************************
173 * IMalloc16_GetSize [COMPOBJ.506]
175 DWORD WINAPI IMalloc16_fnGetSize(const IMalloc16* iface,LPVOID pv) {
176 ICOM_CTHIS(IMalloc16Impl,iface);
177 TRACE("(%p)->GetSize(%p)\n",This,pv);
178 return LOCAL_Size(This->heap,LOWORD(pv));
181 /******************************************************************************
182 * IMalloc16_DidAlloc [COMPOBJ.507]
184 INT16 WINAPI IMalloc16_fnDidAlloc(const IMalloc16* iface,LPVOID pv) {
185 ICOM_CTHIS(IMalloc16,iface);
186 TRACE("(%p)->DidAlloc(%p)\n",This,pv);
190 /******************************************************************************
191 * IMalloc16_HeapMinimize [COMPOBJ.508]
193 LPVOID WINAPI IMalloc16_fnHeapMinimize(IMalloc16* iface) {
194 ICOM_THIS(IMalloc16Impl,iface);
195 TRACE("(%p)->HeapMinimize()\n",This);
199 static ICOM_VTABLE(IMalloc16)* msegvt16 = NULL;
201 /******************************************************************************
202 * IMalloc16_Constructor [VTABLE]
205 IMalloc16_Constructor() {
207 HMODULE16 hcomp = GetModuleHandle16("COMPOBJ");
209 This = (IMalloc16Impl*)SEGPTR_NEW(IMalloc16Impl);
211 This->lpvtbl = msegvt16 = SEGPTR_NEW(ICOM_VTABLE(IMalloc16));
213 #define VTENT(x) msegvt16->fn##x = (void*)WIN32_GetProcAddress16(hcomp,"IMalloc16_"#x);assert(msegvt16->fn##x)
214 VTENT(QueryInterface);
223 msegvt16 = (ICOM_VTABLE(IMalloc16)*)SEGPTR_GET(msegvt16);
227 /* FIXME: implement multiple heaps */
228 This->heap = GlobalAlloc16(GMEM_MOVEABLE,64000);
229 LocalInit16(This->heap,0,64000);
230 return (LPMALLOC16)SEGPTR_GET(This);
234 /* --- IMalloc32 implementation */
238 /* IUnknown fields */
239 ICOM_VTABLE(IMalloc)* lpvtbl;
243 /******************************************************************************
244 * IMalloc32_QueryInterface [VTABLE]
246 static HRESULT WINAPI IMalloc_fnQueryInterface(LPMALLOC iface,REFIID refiid,LPVOID *obj) {
247 ICOM_THIS(IMalloc32Impl,iface);
250 WINE_StringFromCLSID((LPCLSID)refiid,xrefiid);
251 TRACE("(%p)->QueryInterface(%s,%p)\n",This,xrefiid,obj);
252 if ( !memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) ||
253 !memcmp(&IID_IMalloc,refiid,sizeof(IID_IMalloc))
258 return OLE_E_ENUM_NOMORE;
261 /******************************************************************************
262 * IMalloc32_AddRef [VTABLE]
264 static ULONG WINAPI IMalloc_fnAddRef(LPMALLOC iface) {
265 ICOM_THIS(IMalloc32Impl,iface);
266 TRACE("(%p)->AddRef()\n",This);
267 return 1; /* cannot be freed */
270 /******************************************************************************
271 * IMalloc32_Release [VTABLE]
273 static ULONG WINAPI IMalloc_fnRelease(LPMALLOC iface) {
274 ICOM_THIS(IMalloc32Impl,iface);
275 TRACE("(%p)->Release()\n",This);
276 return 1; /* cannot be freed */
279 /******************************************************************************
280 * IMalloc32_Alloc [VTABLE]
282 static LPVOID WINAPI IMalloc_fnAlloc(LPMALLOC iface,DWORD cb) {
283 ICOM_THIS(IMalloc32Impl,iface);
284 TRACE("(%p)->Alloc(%ld)\n",This,cb);
285 return HeapAlloc(GetProcessHeap(),0,cb);
288 /******************************************************************************
289 * IMalloc32_Realloc [VTABLE]
291 static LPVOID WINAPI IMalloc_fnRealloc(LPMALLOC iface,LPVOID pv,DWORD cb) {
292 ICOM_THIS(IMalloc32Impl,iface);
293 TRACE("(%p)->Realloc(%p,%ld)\n",This,pv,cb);
294 return HeapReAlloc(GetProcessHeap(),0,pv,cb);
297 /******************************************************************************
298 * IMalloc32_Free [VTABLE]
300 static VOID WINAPI IMalloc_fnFree(LPMALLOC iface,LPVOID pv) {
301 ICOM_THIS(IMalloc32Impl,iface);
302 TRACE("(%p)->Free(%p)\n",This,pv);
303 HeapFree(GetProcessHeap(),0,pv);
306 /******************************************************************************
307 * IMalloc32_GetSize [VTABLE]
309 static DWORD WINAPI IMalloc_fnGetSize(const IMalloc* iface,LPVOID pv) {
310 ICOM_CTHIS(IMalloc,iface);
311 TRACE("(%p)->GetSize(%p)\n",This,pv);
312 return HeapSize(GetProcessHeap(),0,pv);
315 /******************************************************************************
316 * IMalloc32_DidAlloc [VTABLE]
318 static INT WINAPI IMalloc_fnDidAlloc(const IMalloc* iface,LPVOID pv) {
319 ICOM_CTHIS(IMalloc32Impl,iface);
320 TRACE("(%p)->DidAlloc(%p)\n",This,pv);
324 /******************************************************************************
325 * IMalloc32_HeapMinimize [VTABLE]
327 static LPVOID WINAPI IMalloc_fnHeapMinimize(LPMALLOC iface) {
328 ICOM_THIS(IMalloc32Impl,iface);
329 TRACE("(%p)->HeapMinimize()\n",This);
333 static ICOM_VTABLE(IMalloc) VT_IMalloc32 =
335 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
336 IMalloc_fnQueryInterface,
344 IMalloc_fnHeapMinimize
347 /******************************************************************************
348 * IMalloc32_Constructor [VTABLE]
351 IMalloc_Constructor() {
354 This = (IMalloc32Impl*)HeapAlloc(GetProcessHeap(),0,sizeof(IMalloc32Impl));
355 This->lpvtbl = &VT_IMalloc32;
357 return (LPMALLOC)This;
360 /****************************************************************************
364 /******************************************************************************
365 * IsValidInterface32 [OLE32.78]
368 * True, if the passed pointer is a valid interface
370 BOOL WINAPI IsValidInterface(
371 LPUNKNOWN punk /* [in] interface to be tested */
374 IsBadReadPtr(punk,4) ||
375 IsBadReadPtr(punk->lpvtbl,4) ||
376 IsBadReadPtr(punk->lpvtbl->fnQueryInterface,9) ||
377 IsBadCodePtr(punk->lpvtbl->fnQueryInterface)