4 * Copyright 1997 Marcus Meissner
17 #include "interfaces.h"
23 /****************************************************************************
26 static ULONG WINAPI
IUnknown_AddRef(LPUNKNOWN
this) {
27 TRACE(relay
,"(%p)->AddRef()\n",this);
30 static ULONG WINAPI
IUnknown_Release(LPUNKNOWN
this) {
31 TRACE(relay
,"(%p)->Release()\n",this);
33 HeapFree(GetProcessHeap(),0,this);
39 static HRESULT WINAPI
IUnknown_QueryInterface(LPUNKNOWN
this,REFIID refiid
,LPVOID
*obj
) {
42 WINE_StringFromCLSID((LPCLSID
)refiid
,xrefiid
);
43 TRACE(relay
,"(%p)->QueryInterface(%s,%p)\n",this,xrefiid
,obj
);
45 if (!memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
))) {
49 return OLE_E_ENUM_NOMORE
;
52 static IUnknown_VTable uvt
= {
53 IUnknown_QueryInterface
,
60 IUnknown_Constructor() {
63 unk
= (LPUNKNOWN
)HeapAlloc(GetProcessHeap(),0,sizeof(IUnknown
));
69 /****************************************************************************
72 ULONG WINAPI
IMalloc16_AddRef(LPMALLOC16
this) {
73 TRACE(relay
,"(%p)->AddRef()\n",this);
74 return 1; /* cannot be freed */
77 ULONG WINAPI
IMalloc16_Release(LPMALLOC16
this) {
78 TRACE(relay
,"(%p)->Release()\n",this);
79 return 1; /* cannot be freed */
82 HRESULT WINAPI
IMalloc16_QueryInterface(LPMALLOC16
this,REFIID refiid
,LPVOID
*obj
) {
85 WINE_StringFromCLSID((LPCLSID
)refiid
,xrefiid
);
86 TRACE(relay
,"(%p)->QueryInterface(%s,%p)\n",this,xrefiid
,obj
);
87 if ( !memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
)) ||
88 !memcmp(&IID_IMalloc
,refiid
,sizeof(IID_IMalloc
))
93 return OLE_E_ENUM_NOMORE
;
96 LPVOID WINAPI
IMalloc16_Alloc(LPMALLOC16
this,DWORD cb
) {
97 TRACE(relay
,"(%p)->Alloc(%ld)\n",this,cb
);
98 return (LPVOID
)PTR_SEG_OFF_TO_SEGPTR(this->heap
,LOCAL_Alloc(this->heap
,0,cb
));
101 LPVOID WINAPI
IMalloc16_Realloc(LPMALLOC16
this,LPVOID pv
,DWORD cb
) {
102 TRACE(relay
,"(%p)->Realloc(%p,%ld)\n",this,pv
,cb
);
103 return (LPVOID
)PTR_SEG_OFF_TO_SEGPTR(this->heap
,LOCAL_ReAlloc(this->heap
,0,LOWORD(pv
),cb
));
105 VOID WINAPI
IMalloc16_Free(LPMALLOC16
this,LPVOID pv
) {
106 TRACE(relay
,"(%p)->Free(%p)\n",this,pv
);
107 LOCAL_Free(this->heap
,LOWORD(pv
));
110 DWORD WINAPI
IMalloc16_GetSize(LPMALLOC16
this,LPVOID pv
) {
111 TRACE(relay
,"(%p)->GetSize(%p)\n",this,pv
);
112 return LOCAL_Size(this->heap
,LOWORD(pv
));
115 INT16 WINAPI
IMalloc16_DidAlloc(LPMALLOC16
this,LPVOID pv
) {
116 TRACE(relay
,"(%p)->DidAlloc(%p)\n",this,pv
);
119 LPVOID WINAPI
IMalloc16_HeapMinimize(LPMALLOC16
this) {
120 TRACE(relay
,"(%p)->HeapMinimize()\n",this);
125 /* FIXME: This is unused */
126 static IMalloc16_VTable mvt16
= {
127 IMalloc16_QueryInterface
,
135 IMalloc16_HeapMinimize
,
138 static IMalloc16_VTable
*msegvt16
= NULL
;
141 IMalloc16_Constructor() {
143 HMODULE16 hcomp
= GetModuleHandle16("COMPOBJ");
145 this = (LPMALLOC16
)SEGPTR_NEW(IMalloc16
);
147 this->lpvtbl
= msegvt16
= SEGPTR_NEW(IMalloc16_VTable
);
149 #define FN(x) this->lpvtbl->fn##x = (void*)WIN32_GetProcAddress16(hcomp,"IMalloc16_"#x);assert(this->lpvtbl->fn##x)
159 msegvt16
= (LPMALLOC16_VTABLE
)SEGPTR_GET(msegvt16
);
161 this->lpvtbl
= msegvt16
;
164 /* FIXME: implement multiple heaps */
165 this->heap
= GlobalAlloc16(GMEM_MOVEABLE
,64000);
166 LocalInit(this->heap
,0,64000);
167 return (LPMALLOC16
)SEGPTR_GET(this);
170 /****************************************************************************
173 static ULONG WINAPI
IMalloc32_AddRef(LPMALLOC32
this) {
174 TRACE(relay
,"(%p)->AddRef()\n",this);
175 return 1; /* cannot be freed */
178 static ULONG WINAPI
IMalloc32_Release(LPMALLOC32
this) {
179 TRACE(relay
,"(%p)->Release()\n",this);
180 return 1; /* cannot be freed */
183 static HRESULT WINAPI
IMalloc32_QueryInterface(LPMALLOC32
this,REFIID refiid
,LPVOID
*obj
) {
186 WINE_StringFromCLSID((LPCLSID
)refiid
,xrefiid
);
187 TRACE(relay
,"(%p)->QueryInterface(%s,%p)\n",this,xrefiid
,obj
);
188 if ( !memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
)) ||
189 !memcmp(&IID_IMalloc
,refiid
,sizeof(IID_IMalloc
))
194 return OLE_E_ENUM_NOMORE
;
197 static LPVOID WINAPI
IMalloc32_Alloc(LPMALLOC32
this,DWORD cb
) {
198 TRACE(relay
,"(%p)->Alloc(%ld)\n",this,cb
);
199 return HeapAlloc(GetProcessHeap(),0,cb
);
202 static LPVOID WINAPI
IMalloc32_Realloc(LPMALLOC32
this,LPVOID pv
,DWORD cb
) {
203 TRACE(relay
,"(%p)->Realloc(%p,%ld)\n",this,pv
,cb
);
204 return HeapReAlloc(GetProcessHeap(),0,pv
,cb
);
206 static VOID WINAPI
IMalloc32_Free(LPMALLOC32
this,LPVOID pv
) {
207 TRACE(relay
,"(%p)->Free(%p)\n",this,pv
);
208 HeapFree(GetProcessHeap(),0,pv
);
211 static DWORD WINAPI
IMalloc32_GetSize(LPMALLOC32
this,LPVOID pv
) {
212 TRACE(relay
,"(%p)->GetSize(%p)\n",this,pv
);
213 return HeapSize(GetProcessHeap(),0,pv
);
216 static INT32 WINAPI
IMalloc32_DidAlloc(LPMALLOC32
this,LPVOID pv
) {
217 TRACE(relay
,"(%p)->DidAlloc(%p)\n",this,pv
);
220 static LPVOID WINAPI
IMalloc32_HeapMinimize(LPMALLOC32
this) {
221 TRACE(relay
,"(%p)->HeapMinimize()\n",this);
225 static IMalloc32_VTable VT_IMalloc32
= {
226 IMalloc32_QueryInterface
,
234 IMalloc32_HeapMinimize
,
238 IMalloc32_Constructor() {
241 this = (LPMALLOC32
)HeapAlloc(GetProcessHeap(),0,sizeof(IMalloc32
));
242 this->lpvtbl
= &VT_IMalloc32
;
246 /****************************************************************************
249 /****************************************************************************
250 * IsValidInterface (OLE32.78)
252 * True, if the passed pointer is a valid interface
254 BOOL32 WINAPI
IsValidInterface32(
255 LPUNKNOWN punk
/* [in] interface to be tested */
258 IsBadReadPtr32(punk
,4) ||
259 IsBadReadPtr32(punk
->lpvtbl
,4) ||
260 IsBadReadPtr32(punk
->lpvtbl
->fnQueryInterface
,9) ||
261 IsBadCodePtr32(punk
->lpvtbl
->fnQueryInterface
)