4 * Copyright 1997 Marcus Meissner
14 #include "wine/winbase16.h"
15 #include "wine/obj_base.h"
22 /* --- IUnknown implementation */
27 ICOM_VTABLE(IUnknown
)* lpvtbl
;
31 /******************************************************************************
32 * IUnknown_AddRef [VTABLE:IUNKNOWN.1]
34 static ULONG WINAPI
IUnknown_fnAddRef(LPUNKNOWN iface
) {
35 ICOM_THIS(IUnknownImpl
,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(IUnknownImpl
,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(IUnknownImpl
,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
= (IUnknownImpl
*)HeapAlloc(GetProcessHeap(),0,sizeof(IUnknownImpl
));
86 return (LPUNKNOWN
)unk
;
90 /* --- IMalloc16 implementation */
96 ICOM_VTABLE(IMalloc16
)* lpvtbl
;
98 /* IMalloc16 fields */
99 /* Gmm, I think one is not enough, we should probably manage a list of
105 /******************************************************************************
106 * IMalloc16_QueryInterface [COMPOBJ.500]
108 HRESULT WINAPI
IMalloc16_fnQueryInterface(IMalloc16
* iface
,REFIID refiid
,LPVOID
*obj
) {
109 ICOM_THIS(IMalloc16Impl
,iface
);
112 WINE_StringFromCLSID((LPCLSID
)refiid
,xrefiid
);
113 TRACE(relay
,"(%p)->QueryInterface(%s,%p)\n",This
,xrefiid
,obj
);
114 if ( !memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
)) ||
115 !memcmp(&IID_IMalloc
,refiid
,sizeof(IID_IMalloc
))
120 return OLE_E_ENUM_NOMORE
;
123 /******************************************************************************
124 * IMalloc16_AddRef [COMPOBJ.501]
126 ULONG WINAPI
IMalloc16_fnAddRef(IMalloc16
* iface
) {
127 ICOM_THIS(IMalloc16Impl
,iface
);
128 TRACE(relay
,"(%p)->AddRef()\n",This
);
129 return 1; /* cannot be freed */
132 /******************************************************************************
133 * IMalloc16_Release [COMPOBJ.502]
135 ULONG WINAPI
IMalloc16_fnRelease(IMalloc16
* iface
) {
136 ICOM_THIS(IMalloc16Impl
,iface
);
137 TRACE(relay
,"(%p)->Release()\n",This
);
138 return 1; /* cannot be freed */
141 /******************************************************************************
142 * IMalloc16_Alloc [COMPOBJ.503]
144 LPVOID WINAPI
IMalloc16_fnAlloc(IMalloc16
* iface
,DWORD cb
) {
145 ICOM_THIS(IMalloc16Impl
,iface
);
146 TRACE(relay
,"(%p)->Alloc(%ld)\n",This
,cb
);
147 return (LPVOID
)PTR_SEG_OFF_TO_SEGPTR(This
->heap
,LOCAL_Alloc(This
->heap
,0,cb
));
150 /******************************************************************************
151 * IMalloc16_Realloc [COMPOBJ.504]
153 LPVOID WINAPI
IMalloc16_fnRealloc(IMalloc16
* iface
,LPVOID pv
,DWORD cb
) {
154 ICOM_THIS(IMalloc16Impl
,iface
);
155 TRACE(relay
,"(%p)->Realloc(%p,%ld)\n",This
,pv
,cb
);
156 return (LPVOID
)PTR_SEG_OFF_TO_SEGPTR(This
->heap
,LOCAL_ReAlloc(This
->heap
,0,LOWORD(pv
),cb
));
159 /******************************************************************************
160 * IMalloc16_Free [COMPOBJ.505]
162 VOID WINAPI
IMalloc16_fnFree(IMalloc16
* iface
,LPVOID pv
) {
163 ICOM_THIS(IMalloc16Impl
,iface
);
164 TRACE(relay
,"(%p)->Free(%p)\n",This
,pv
);
165 LOCAL_Free(This
->heap
,LOWORD(pv
));
168 /******************************************************************************
169 * IMalloc16_GetSize [COMPOBJ.506]
171 DWORD WINAPI
IMalloc16_fnGetSize(const IMalloc16
* iface
,LPVOID pv
) {
172 ICOM_CTHIS(IMalloc16Impl
,iface
);
173 TRACE(relay
,"(%p)->GetSize(%p)\n",This
,pv
);
174 return LOCAL_Size(This
->heap
,LOWORD(pv
));
177 /******************************************************************************
178 * IMalloc16_DidAlloc [COMPOBJ.507]
180 INT16 WINAPI
IMalloc16_fnDidAlloc(const IMalloc16
* iface
,LPVOID pv
) {
181 ICOM_CTHIS(IMalloc16
,iface
);
182 TRACE(relay
,"(%p)->DidAlloc(%p)\n",This
,pv
);
186 /******************************************************************************
187 * IMalloc16_HeapMinimize [COMPOBJ.508]
189 LPVOID WINAPI
IMalloc16_fnHeapMinimize(IMalloc16
* iface
) {
190 ICOM_THIS(IMalloc16Impl
,iface
);
191 TRACE(relay
,"(%p)->HeapMinimize()\n",This
);
195 static ICOM_VTABLE(IMalloc16
)* msegvt16
= NULL
;
197 /******************************************************************************
198 * IMalloc16_Constructor [VTABLE]
201 IMalloc16_Constructor() {
203 HMODULE16 hcomp
= GetModuleHandle16("COMPOBJ");
205 This
= (IMalloc16Impl
*)SEGPTR_NEW(IMalloc16Impl
);
207 This
->lpvtbl
= msegvt16
= SEGPTR_NEW(ICOM_VTABLE(IMalloc16
));
209 #define VTENT(x) msegvt16->fn##x = (void*)WIN32_GetProcAddress16(hcomp,"IMalloc16_"#x);assert(msegvt16->fn##x)
210 VTENT(QueryInterface
);
219 msegvt16
= (ICOM_VTABLE(IMalloc16
)*)SEGPTR_GET(msegvt16
);
223 /* FIXME: implement multiple heaps */
224 This
->heap
= GlobalAlloc16(GMEM_MOVEABLE
,64000);
225 LocalInit16(This
->heap
,0,64000);
226 return (LPMALLOC16
)SEGPTR_GET(This
);
230 /* --- IMalloc32 implementation */
234 /* IUnknown fields */
235 ICOM_VTABLE(IMalloc
)* lpvtbl
;
239 /******************************************************************************
240 * IMalloc32_QueryInterface [VTABLE]
242 static HRESULT WINAPI
IMalloc_fnQueryInterface(LPMALLOC iface
,REFIID refiid
,LPVOID
*obj
) {
243 ICOM_THIS(IMalloc32Impl
,iface
);
246 WINE_StringFromCLSID((LPCLSID
)refiid
,xrefiid
);
247 TRACE(relay
,"(%p)->QueryInterface(%s,%p)\n",This
,xrefiid
,obj
);
248 if ( !memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
)) ||
249 !memcmp(&IID_IMalloc
,refiid
,sizeof(IID_IMalloc
))
254 return OLE_E_ENUM_NOMORE
;
257 /******************************************************************************
258 * IMalloc32_AddRef [VTABLE]
260 static ULONG WINAPI
IMalloc_fnAddRef(LPMALLOC iface
) {
261 ICOM_THIS(IMalloc32Impl
,iface
);
262 TRACE(relay
,"(%p)->AddRef()\n",This
);
263 return 1; /* cannot be freed */
266 /******************************************************************************
267 * IMalloc32_Release [VTABLE]
269 static ULONG WINAPI
IMalloc_fnRelease(LPMALLOC iface
) {
270 ICOM_THIS(IMalloc32Impl
,iface
);
271 TRACE(relay
,"(%p)->Release()\n",This
);
272 return 1; /* cannot be freed */
275 /******************************************************************************
276 * IMalloc32_Alloc [VTABLE]
278 static LPVOID WINAPI
IMalloc_fnAlloc(LPMALLOC iface
,DWORD cb
) {
279 ICOM_THIS(IMalloc32Impl
,iface
);
280 TRACE(relay
,"(%p)->Alloc(%ld)\n",This
,cb
);
281 return HeapAlloc(GetProcessHeap(),0,cb
);
284 /******************************************************************************
285 * IMalloc32_Realloc [VTABLE]
287 static LPVOID WINAPI
IMalloc_fnRealloc(LPMALLOC iface
,LPVOID pv
,DWORD cb
) {
288 ICOM_THIS(IMalloc32Impl
,iface
);
289 TRACE(relay
,"(%p)->Realloc(%p,%ld)\n",This
,pv
,cb
);
290 return HeapReAlloc(GetProcessHeap(),0,pv
,cb
);
293 /******************************************************************************
294 * IMalloc32_Free [VTABLE]
296 static VOID WINAPI
IMalloc_fnFree(LPMALLOC iface
,LPVOID pv
) {
297 ICOM_THIS(IMalloc32Impl
,iface
);
298 TRACE(relay
,"(%p)->Free(%p)\n",This
,pv
);
299 HeapFree(GetProcessHeap(),0,pv
);
302 /******************************************************************************
303 * IMalloc32_GetSize [VTABLE]
305 static DWORD WINAPI
IMalloc_fnGetSize(const IMalloc
* iface
,LPVOID pv
) {
306 ICOM_CTHIS(IMalloc
,iface
);
307 TRACE(relay
,"(%p)->GetSize(%p)\n",This
,pv
);
308 return HeapSize(GetProcessHeap(),0,pv
);
311 /******************************************************************************
312 * IMalloc32_DidAlloc [VTABLE]
314 static INT WINAPI
IMalloc_fnDidAlloc(const IMalloc
* iface
,LPVOID pv
) {
315 ICOM_CTHIS(IMalloc32Impl
,iface
);
316 TRACE(relay
,"(%p)->DidAlloc(%p)\n",This
,pv
);
320 /******************************************************************************
321 * IMalloc32_HeapMinimize [VTABLE]
323 static LPVOID WINAPI
IMalloc_fnHeapMinimize(LPMALLOC iface
) {
324 ICOM_THIS(IMalloc32Impl
,iface
);
325 TRACE(relay
,"(%p)->HeapMinimize()\n",This
);
329 static ICOM_VTABLE(IMalloc
) VT_IMalloc32
= {
330 IMalloc_fnQueryInterface
,
338 IMalloc_fnHeapMinimize
341 /******************************************************************************
342 * IMalloc32_Constructor [VTABLE]
345 IMalloc_Constructor() {
348 This
= (IMalloc32Impl
*)HeapAlloc(GetProcessHeap(),0,sizeof(IMalloc32Impl
));
349 This
->lpvtbl
= &VT_IMalloc32
;
351 return (LPMALLOC
)This
;
354 /****************************************************************************
358 /******************************************************************************
359 * IsValidInterface32 [OLE32.78]
362 * True, if the passed pointer is a valid interface
364 BOOL WINAPI
IsValidInterface(
365 LPUNKNOWN punk
/* [in] interface to be tested */
368 IsBadReadPtr(punk
,4) ||
369 IsBadReadPtr(punk
->lpvtbl
,4) ||
370 IsBadReadPtr(punk
->lpvtbl
->fnQueryInterface
,9) ||
371 IsBadCodePtr(punk
->lpvtbl
->fnQueryInterface
)