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);
124 static IMalloc16_VTable mvt16
= {
125 IMalloc16_QueryInterface
,
133 IMalloc16_HeapMinimize
,
135 static IMalloc16_VTable
*msegvt16
= NULL
;
138 IMalloc16_Constructor() {
141 this = (LPMALLOC16
)SEGPTR_NEW(IMalloc16
);
143 this->lpvtbl
= &mvt16
;
145 HMODULE16 hcomp
= GetModuleHandle16("COMPOBJ");
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
);
162 this->lpvtbl
= msegvt16
;
165 /* FIXME: implement multiple heaps */
166 this->heap
= GlobalAlloc16(GMEM_MOVEABLE
,64000);
167 LocalInit(this->heap
,0,64000);
168 return (LPMALLOC16
)SEGPTR_GET(this);
171 /****************************************************************************
174 static ULONG WINAPI
IMalloc32_AddRef(LPMALLOC32
this) {
175 TRACE(relay
,"(%p)->AddRef()\n",this);
176 return 1; /* cannot be freed */
179 static ULONG WINAPI
IMalloc32_Release(LPMALLOC32
this) {
180 TRACE(relay
,"(%p)->Release()\n",this);
181 return 1; /* cannot be freed */
184 static HRESULT WINAPI
IMalloc32_QueryInterface(LPMALLOC32
this,REFIID refiid
,LPVOID
*obj
) {
187 WINE_StringFromCLSID((LPCLSID
)refiid
,xrefiid
);
188 TRACE(relay
,"(%p)->QueryInterface(%s,%p)\n",this,xrefiid
,obj
);
189 if ( !memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
)) ||
190 !memcmp(&IID_IMalloc
,refiid
,sizeof(IID_IMalloc
))
195 return OLE_E_ENUM_NOMORE
;
198 static LPVOID WINAPI
IMalloc32_Alloc(LPMALLOC32
this,DWORD cb
) {
199 TRACE(relay
,"(%p)->Alloc(%ld)\n",this,cb
);
200 return HeapAlloc(GetProcessHeap(),0,cb
);
203 static LPVOID WINAPI
IMalloc32_Realloc(LPMALLOC32
this,LPVOID pv
,DWORD cb
) {
204 TRACE(relay
,"(%p)->Realloc(%p,%ld)\n",this,pv
,cb
);
205 return HeapReAlloc(GetProcessHeap(),0,pv
,cb
);
207 static VOID WINAPI
IMalloc32_Free(LPMALLOC32
this,LPVOID pv
) {
208 TRACE(relay
,"(%p)->Free(%p)\n",this,pv
);
209 HeapFree(GetProcessHeap(),0,pv
);
212 static DWORD WINAPI
IMalloc32_GetSize(LPMALLOC32
this,LPVOID pv
) {
213 TRACE(relay
,"(%p)->GetSize(%p)\n",this,pv
);
214 return HeapSize(GetProcessHeap(),0,pv
);
217 static INT32 WINAPI
IMalloc32_DidAlloc(LPMALLOC32
this,LPVOID pv
) {
218 TRACE(relay
,"(%p)->DidAlloc(%p)\n",this,pv
);
221 static LPVOID WINAPI
IMalloc32_HeapMinimize(LPMALLOC32
this) {
222 TRACE(relay
,"(%p)->HeapMinimize()\n",this);
226 static IMalloc32_VTable VT_IMalloc32
= {
227 IMalloc32_QueryInterface
,
235 IMalloc32_HeapMinimize
,
239 IMalloc32_Constructor() {
242 this = (LPMALLOC32
)HeapAlloc(GetProcessHeap(),0,sizeof(IMalloc32
));
243 this->lpvtbl
= &VT_IMalloc32
;
247 /****************************************************************************
250 /****************************************************************************
251 * IsValidInterface (OLE32.78)
253 * True, if the passed pointer is a valid interface
255 BOOL32 WINAPI
IsValidInterface32(
256 LPUNKNOWN punk
/* [in] interface to be tested */
259 IsBadReadPtr32(punk
,4) ||
260 IsBadReadPtr32(punk
->lpvtbl
,4) ||
261 IsBadReadPtr32(punk
->lpvtbl
->fnQueryInterface
,9) ||
262 IsBadCodePtr32(punk
->lpvtbl
->fnQueryInterface
)