4 * Copyright 1997 Marcus Meissner
17 #include "interfaces.h"
23 /* --- IUnknown implementation */
25 typedef struct _IUnknown
{
27 ICOM_VTABLE(IUnknown
)* lpvtbl
;
31 /******************************************************************************
32 * IUnknown_AddRef [VTABLE:IUNKNOWN.1]
34 static ULONG WINAPI
IUnknown_fnAddRef(LPUNKNOWN iface
) {
35 ICOM_THIS(IUnknown
,iface
);
36 TRACE(relay
,"(%p)->AddRef()\n",this);
40 /******************************************************************************
41 * IUnknown_Release [VTABLE:IUNKNOWN.2]
43 static ULONG WINAPI
IUnknown_fnRelease(LPUNKNOWN iface
) {
44 ICOM_THIS(IUnknown
,iface
);
45 TRACE(relay
,"(%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(IUnknown
,iface
);
60 WINE_StringFromCLSID((LPCLSID
)refiid
,xrefiid
);
61 TRACE(relay
,"(%p)->QueryInterface(%s,%p)\n",this,xrefiid
,obj
);
63 if (!memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
))) {
67 return OLE_E_ENUM_NOMORE
;
70 static ICOM_VTABLE(IUnknown
) uvt
= {
71 IUnknown_fnQueryInterface
,
76 /******************************************************************************
77 * IUnknown_Constructor [INTERNAL]
80 IUnknown_Constructor() {
83 unk
= (_IUnknown
*)HeapAlloc(GetProcessHeap(),0,sizeof(IUnknown
));
86 return (LPUNKNOWN
)unk
;
93 /******************************************************************************
94 * IMalloc16_AddRef [COMPOBJ.501]
96 ULONG WINAPI
IMalloc16_AddRef(LPMALLOC16
this) {
97 TRACE(relay
,"(%p)->AddRef()\n",this);
98 return 1; /* cannot be freed */
101 /******************************************************************************
102 * IMalloc16_Release [COMPOBJ.502]
104 ULONG WINAPI
IMalloc16_Release(LPMALLOC16
this) {
105 TRACE(relay
,"(%p)->Release()\n",this);
106 return 1; /* cannot be freed */
109 /******************************************************************************
110 * IMalloc16_QueryInterface [COMPOBJ.500]
112 HRESULT WINAPI
IMalloc16_QueryInterface(LPMALLOC16
this,REFIID refiid
,LPVOID
*obj
) {
115 WINE_StringFromCLSID((LPCLSID
)refiid
,xrefiid
);
116 TRACE(relay
,"(%p)->QueryInterface(%s,%p)\n",this,xrefiid
,obj
);
117 if ( !memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
)) ||
118 !memcmp(&IID_IMalloc
,refiid
,sizeof(IID_IMalloc
))
123 return OLE_E_ENUM_NOMORE
;
126 /******************************************************************************
127 * IMalloc16_Alloc [COMPOBJ.503]
129 LPVOID WINAPI
IMalloc16_Alloc(LPMALLOC16
this,DWORD cb
) {
130 TRACE(relay
,"(%p)->Alloc(%ld)\n",this,cb
);
131 return (LPVOID
)PTR_SEG_OFF_TO_SEGPTR(this->heap
,LOCAL_Alloc(this->heap
,0,cb
));
134 /******************************************************************************
135 * IMalloc16_Realloc [COMPOBJ.504]
137 LPVOID WINAPI
IMalloc16_Realloc(LPMALLOC16
this,LPVOID pv
,DWORD cb
) {
138 TRACE(relay
,"(%p)->Realloc(%p,%ld)\n",this,pv
,cb
);
139 return (LPVOID
)PTR_SEG_OFF_TO_SEGPTR(this->heap
,LOCAL_ReAlloc(this->heap
,0,LOWORD(pv
),cb
));
142 /******************************************************************************
143 * IMalloc16_Free [COMPOBJ.505]
145 VOID WINAPI
IMalloc16_Free(LPMALLOC16
this,LPVOID pv
) {
146 TRACE(relay
,"(%p)->Free(%p)\n",this,pv
);
147 LOCAL_Free(this->heap
,LOWORD(pv
));
150 /******************************************************************************
151 * IMalloc16_GetSize [COMPOBJ.506]
153 DWORD WINAPI
IMalloc16_GetSize(LPMALLOC16
this,LPVOID pv
) {
154 TRACE(relay
,"(%p)->GetSize(%p)\n",this,pv
);
155 return LOCAL_Size(this->heap
,LOWORD(pv
));
158 /******************************************************************************
159 * IMalloc16_DidAlloc [COMPOBJ.507]
161 INT16 WINAPI
IMalloc16_DidAlloc(LPMALLOC16
this,LPVOID pv
) {
162 TRACE(relay
,"(%p)->DidAlloc(%p)\n",this,pv
);
166 /******************************************************************************
167 * IMalloc16_HeapMinimize [COMPOBJ.508]
169 LPVOID WINAPI
IMalloc16_HeapMinimize(LPMALLOC16
this) {
170 TRACE(relay
,"(%p)->HeapMinimize()\n",this);
175 /* FIXME: This is unused */
176 static IMalloc16_VTable mvt16
= {
177 IMalloc16_QueryInterface
,
185 IMalloc16_HeapMinimize
,
188 static IMalloc16_VTable
*msegvt16
= NULL
;
190 /******************************************************************************
191 * IMalloc16_Constructor [VTABLE]
194 IMalloc16_Constructor() {
196 HMODULE16 hcomp
= GetModuleHandle16("COMPOBJ");
198 this = (LPMALLOC16
)SEGPTR_NEW(IMalloc16
);
200 this->lpvtbl
= msegvt16
= SEGPTR_NEW(IMalloc16_VTable
);
202 #define FN(x) this->lpvtbl->fn##x = (void*)WIN32_GetProcAddress16(hcomp,"IMalloc16_"#x);assert(this->lpvtbl->fn##x)
212 msegvt16
= (LPMALLOC16_VTABLE
)SEGPTR_GET(msegvt16
);
214 this->lpvtbl
= msegvt16
;
217 /* FIXME: implement multiple heaps */
218 this->heap
= GlobalAlloc16(GMEM_MOVEABLE
,64000);
219 LocalInit(this->heap
,0,64000);
220 return (LPMALLOC16
)SEGPTR_GET(this);
227 /******************************************************************************
228 * IMalloc32_AddRef [VTABLE]
230 static ULONG WINAPI
IMalloc32_AddRef(LPMALLOC32
this) {
231 TRACE(relay
,"(%p)->AddRef()\n",this);
232 return 1; /* cannot be freed */
235 /******************************************************************************
236 * IMalloc32_Release [VTABLE]
238 static ULONG WINAPI
IMalloc32_Release(LPMALLOC32
this) {
239 TRACE(relay
,"(%p)->Release()\n",this);
240 return 1; /* cannot be freed */
243 /******************************************************************************
244 * IMalloc32_QueryInterface [VTABLE]
246 static HRESULT WINAPI
IMalloc32_QueryInterface(LPMALLOC32
this,REFIID refiid
,LPVOID
*obj
) {
249 WINE_StringFromCLSID((LPCLSID
)refiid
,xrefiid
);
250 TRACE(relay
,"(%p)->QueryInterface(%s,%p)\n",this,xrefiid
,obj
);
251 if ( !memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
)) ||
252 !memcmp(&IID_IMalloc
,refiid
,sizeof(IID_IMalloc
))
257 return OLE_E_ENUM_NOMORE
;
260 /******************************************************************************
261 * IMalloc32_Alloc [VTABLE]
263 static LPVOID WINAPI
IMalloc32_Alloc(LPMALLOC32
this,DWORD cb
) {
264 TRACE(relay
,"(%p)->Alloc(%ld)\n",this,cb
);
265 return HeapAlloc(GetProcessHeap(),0,cb
);
268 /******************************************************************************
269 * IMalloc32_Realloc [VTABLE]
271 static LPVOID WINAPI
IMalloc32_Realloc(LPMALLOC32
this,LPVOID pv
,DWORD cb
) {
272 TRACE(relay
,"(%p)->Realloc(%p,%ld)\n",this,pv
,cb
);
273 return HeapReAlloc(GetProcessHeap(),0,pv
,cb
);
276 /******************************************************************************
277 * IMalloc32_Free [VTABLE]
279 static VOID WINAPI
IMalloc32_Free(LPMALLOC32
this,LPVOID pv
) {
280 TRACE(relay
,"(%p)->Free(%p)\n",this,pv
);
281 HeapFree(GetProcessHeap(),0,pv
);
284 /******************************************************************************
285 * IMalloc32_GetSize [VTABLE]
287 static DWORD WINAPI
IMalloc32_GetSize(LPMALLOC32
this,LPVOID pv
) {
288 TRACE(relay
,"(%p)->GetSize(%p)\n",this,pv
);
289 return HeapSize(GetProcessHeap(),0,pv
);
292 /******************************************************************************
293 * IMalloc32_DidAlloc [VTABLE]
295 static INT32 WINAPI
IMalloc32_DidAlloc(LPMALLOC32
this,LPVOID pv
) {
296 TRACE(relay
,"(%p)->DidAlloc(%p)\n",this,pv
);
300 /******************************************************************************
301 * IMalloc32_HeapMinimize [VTABLE]
303 static LPVOID WINAPI
IMalloc32_HeapMinimize(LPMALLOC32
this) {
304 TRACE(relay
,"(%p)->HeapMinimize()\n",this);
308 static IMalloc32_VTable VT_IMalloc32
= {
309 IMalloc32_QueryInterface
,
317 IMalloc32_HeapMinimize
,
320 /******************************************************************************
321 * IMalloc32_Constructor [VTABLE]
324 IMalloc32_Constructor() {
327 this = (LPMALLOC32
)HeapAlloc(GetProcessHeap(),0,sizeof(IMalloc32
));
328 this->lpvtbl
= &VT_IMalloc32
;
333 /****************************************************************************
337 /******************************************************************************
338 * IsValidInterface32 [OLE32.78]
341 * True, if the passed pointer is a valid interface
343 BOOL32 WINAPI
IsValidInterface32(
344 LPUNKNOWN punk
/* [in] interface to be tested */
347 IsBadReadPtr32(punk
,4) ||
348 IsBadReadPtr32(punk
->lpvtbl
,4) ||
349 IsBadReadPtr32(punk
->lpvtbl
->fnQueryInterface
,9) ||
350 IsBadCodePtr32(punk
->lpvtbl
->fnQueryInterface
)