4 * Copyright 1997 Marcus Meissner
17 #include "interfaces.h"
27 /******************************************************************************
28 * IUnknown_AddRef [VTABLE:IUNKNOWN.1]
30 static ULONG WINAPI IUnknown_AddRef(LPUNKNOWN this) {
31 TRACE(relay,"(%p)->AddRef()\n",this);
35 /******************************************************************************
36 * IUnknown_Release [VTABLE:IUNKNOWN.2]
38 static ULONG WINAPI IUnknown_Release(LPUNKNOWN this) {
39 TRACE(relay,"(%p)->Release()\n",this);
41 HeapFree(GetProcessHeap(),0,this);
47 /******************************************************************************
48 * IUnknown_QueryInterface [VTABLE:IUNKNOWN.0]
50 static HRESULT WINAPI IUnknown_QueryInterface(LPUNKNOWN this,REFIID refiid,LPVOID *obj) {
53 WINE_StringFromCLSID((LPCLSID)refiid,xrefiid);
54 TRACE(relay,"(%p)->QueryInterface(%s,%p)\n",this,xrefiid,obj);
56 if (!memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown))) {
60 return OLE_E_ENUM_NOMORE;
63 static IUnknown_VTable uvt = {
64 IUnknown_QueryInterface,
69 /******************************************************************************
70 * IUnknown_Constructor [INTERNAL]
73 IUnknown_Constructor() {
76 unk = (LPUNKNOWN)HeapAlloc(GetProcessHeap(),0,sizeof(IUnknown));
86 /******************************************************************************
87 * IMalloc16_AddRef [COMPOBJ.501]
89 ULONG WINAPI IMalloc16_AddRef(LPMALLOC16 this) {
90 TRACE(relay,"(%p)->AddRef()\n",this);
91 return 1; /* cannot be freed */
94 /******************************************************************************
95 * IMalloc16_Release [COMPOBJ.502]
97 ULONG WINAPI IMalloc16_Release(LPMALLOC16 this) {
98 TRACE(relay,"(%p)->Release()\n",this);
99 return 1; /* cannot be freed */
102 /******************************************************************************
103 * IMalloc16_QueryInterface [COMPOBJ.500]
105 HRESULT WINAPI IMalloc16_QueryInterface(LPMALLOC16 this,REFIID refiid,LPVOID *obj) {
108 WINE_StringFromCLSID((LPCLSID)refiid,xrefiid);
109 TRACE(relay,"(%p)->QueryInterface(%s,%p)\n",this,xrefiid,obj);
110 if ( !memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) ||
111 !memcmp(&IID_IMalloc,refiid,sizeof(IID_IMalloc))
116 return OLE_E_ENUM_NOMORE;
119 /******************************************************************************
120 * IMalloc16_Alloc [COMPOBJ.503]
122 LPVOID WINAPI IMalloc16_Alloc(LPMALLOC16 this,DWORD cb) {
123 TRACE(relay,"(%p)->Alloc(%ld)\n",this,cb);
124 return (LPVOID)PTR_SEG_OFF_TO_SEGPTR(this->heap,LOCAL_Alloc(this->heap,0,cb));
127 /******************************************************************************
128 * IMalloc16_Realloc [COMPOBJ.504]
130 LPVOID WINAPI IMalloc16_Realloc(LPMALLOC16 this,LPVOID pv,DWORD cb) {
131 TRACE(relay,"(%p)->Realloc(%p,%ld)\n",this,pv,cb);
132 return (LPVOID)PTR_SEG_OFF_TO_SEGPTR(this->heap,LOCAL_ReAlloc(this->heap,0,LOWORD(pv),cb));
135 /******************************************************************************
136 * IMalloc16_Free [COMPOBJ.505]
138 VOID WINAPI IMalloc16_Free(LPMALLOC16 this,LPVOID pv) {
139 TRACE(relay,"(%p)->Free(%p)\n",this,pv);
140 LOCAL_Free(this->heap,LOWORD(pv));
143 /******************************************************************************
144 * IMalloc16_GetSize [COMPOBJ.506]
146 DWORD WINAPI IMalloc16_GetSize(LPMALLOC16 this,LPVOID pv) {
147 TRACE(relay,"(%p)->GetSize(%p)\n",this,pv);
148 return LOCAL_Size(this->heap,LOWORD(pv));
151 /******************************************************************************
152 * IMalloc16_DidAlloc [COMPOBJ.507]
154 INT16 WINAPI IMalloc16_DidAlloc(LPMALLOC16 this,LPVOID pv) {
155 TRACE(relay,"(%p)->DidAlloc(%p)\n",this,pv);
159 /******************************************************************************
160 * IMalloc16_HeapMinimize [COMPOBJ.508]
162 LPVOID WINAPI IMalloc16_HeapMinimize(LPMALLOC16 this) {
163 TRACE(relay,"(%p)->HeapMinimize()\n",this);
168 /* FIXME: This is unused */
169 static IMalloc16_VTable mvt16 = {
170 IMalloc16_QueryInterface,
178 IMalloc16_HeapMinimize,
181 static IMalloc16_VTable *msegvt16 = NULL;
183 /******************************************************************************
184 * IMalloc16_Constructor [VTABLE]
187 IMalloc16_Constructor() {
189 HMODULE16 hcomp = GetModuleHandle16("COMPOBJ");
191 this = (LPMALLOC16)SEGPTR_NEW(IMalloc16);
193 this->lpvtbl = msegvt16 = SEGPTR_NEW(IMalloc16_VTable);
195 #define FN(x) this->lpvtbl->fn##x = (void*)WIN32_GetProcAddress16(hcomp,"IMalloc16_"#x);assert(this->lpvtbl->fn##x)
205 msegvt16 = (LPMALLOC16_VTABLE)SEGPTR_GET(msegvt16);
207 this->lpvtbl = msegvt16;
210 /* FIXME: implement multiple heaps */
211 this->heap = GlobalAlloc16(GMEM_MOVEABLE,64000);
212 LocalInit(this->heap,0,64000);
213 return (LPMALLOC16)SEGPTR_GET(this);
220 /******************************************************************************
221 * IMalloc32_AddRef [VTABLE]
223 static ULONG WINAPI IMalloc32_AddRef(LPMALLOC32 this) {
224 TRACE(relay,"(%p)->AddRef()\n",this);
225 return 1; /* cannot be freed */
228 /******************************************************************************
229 * IMalloc32_Release [VTABLE]
231 static ULONG WINAPI IMalloc32_Release(LPMALLOC32 this) {
232 TRACE(relay,"(%p)->Release()\n",this);
233 return 1; /* cannot be freed */
236 /******************************************************************************
237 * IMalloc32_QueryInterface [VTABLE]
239 static HRESULT WINAPI IMalloc32_QueryInterface(LPMALLOC32 this,REFIID refiid,LPVOID *obj) {
242 WINE_StringFromCLSID((LPCLSID)refiid,xrefiid);
243 TRACE(relay,"(%p)->QueryInterface(%s,%p)\n",this,xrefiid,obj);
244 if ( !memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) ||
245 !memcmp(&IID_IMalloc,refiid,sizeof(IID_IMalloc))
250 return OLE_E_ENUM_NOMORE;
253 /******************************************************************************
254 * IMalloc32_Alloc [VTABLE]
256 static LPVOID WINAPI IMalloc32_Alloc(LPMALLOC32 this,DWORD cb) {
257 TRACE(relay,"(%p)->Alloc(%ld)\n",this,cb);
258 return HeapAlloc(GetProcessHeap(),0,cb);
261 /******************************************************************************
262 * IMalloc32_Realloc [VTABLE]
264 static LPVOID WINAPI IMalloc32_Realloc(LPMALLOC32 this,LPVOID pv,DWORD cb) {
265 TRACE(relay,"(%p)->Realloc(%p,%ld)\n",this,pv,cb);
266 return HeapReAlloc(GetProcessHeap(),0,pv,cb);
269 /******************************************************************************
270 * IMalloc32_Free [VTABLE]
272 static VOID WINAPI IMalloc32_Free(LPMALLOC32 this,LPVOID pv) {
273 TRACE(relay,"(%p)->Free(%p)\n",this,pv);
274 HeapFree(GetProcessHeap(),0,pv);
277 /******************************************************************************
278 * IMalloc32_GetSize [VTABLE]
280 static DWORD WINAPI IMalloc32_GetSize(LPMALLOC32 this,LPVOID pv) {
281 TRACE(relay,"(%p)->GetSize(%p)\n",this,pv);
282 return HeapSize(GetProcessHeap(),0,pv);
285 /******************************************************************************
286 * IMalloc32_DidAlloc [VTABLE]
288 static INT32 WINAPI IMalloc32_DidAlloc(LPMALLOC32 this,LPVOID pv) {
289 TRACE(relay,"(%p)->DidAlloc(%p)\n",this,pv);
293 /******************************************************************************
294 * IMalloc32_HeapMinimize [VTABLE]
296 static LPVOID WINAPI IMalloc32_HeapMinimize(LPMALLOC32 this) {
297 TRACE(relay,"(%p)->HeapMinimize()\n",this);
301 static IMalloc32_VTable VT_IMalloc32 = {
302 IMalloc32_QueryInterface,
310 IMalloc32_HeapMinimize,
313 /******************************************************************************
314 * IMalloc32_Constructor [VTABLE]
317 IMalloc32_Constructor() {
320 this = (LPMALLOC32)HeapAlloc(GetProcessHeap(),0,sizeof(IMalloc32));
321 this->lpvtbl = &VT_IMalloc32;
326 /****************************************************************************
330 /******************************************************************************
331 * IsValidInterface32 [OLE32.78]
334 * True, if the passed pointer is a valid interface
336 BOOL32 WINAPI IsValidInterface32(
337 LPUNKNOWN punk /* [in] interface to be tested */
340 IsBadReadPtr32(punk,4) ||
341 IsBadReadPtr32(punk->lpvtbl,4) ||
342 IsBadReadPtr32(punk->lpvtbl->fnQueryInterface,9) ||
343 IsBadCodePtr32(punk->lpvtbl->fnQueryInterface)