Added the DFCS_{HOT,TRANSPARENT} definitions.
[wine/gsoc_dplay.git] / dlls / ole32 / ifs.c
blobb88abc0ef46c7c86c41661ee3cdcaf9e0734d1e5
1 /*
2 * basic interfaces
4 * Copyright 1997 Marcus Meissner
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #include <ctype.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <assert.h>
28 #include "ole2.h"
29 #include "windef.h"
30 #include "winerror.h"
32 #include "wine/obj_base.h"
33 #include "wine/winbase16.h"
34 #include "ifs.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(relay);
40 /* --- IUnknown implementation */
42 typedef struct
44 /* IUnknown fields */
45 ICOM_VFIELD(IUnknown);
46 DWORD ref;
47 } IUnknownImpl;
49 /******************************************************************************
50 * IUnknown_AddRef [VTABLE:IUNKNOWN.1]
52 static ULONG WINAPI IUnknown_fnAddRef(LPUNKNOWN iface) {
53 ICOM_THIS(IUnknownImpl,iface);
54 TRACE("(%p)->AddRef()\n",This);
55 return ++(This->ref);
58 /******************************************************************************
59 * IUnknown_Release [VTABLE:IUNKNOWN.2]
61 static ULONG WINAPI IUnknown_fnRelease(LPUNKNOWN iface) {
62 ICOM_THIS(IUnknownImpl,iface);
63 TRACE("(%p)->Release()\n",This);
64 if (!--(This->ref)) {
65 HeapFree(GetProcessHeap(),0,This);
66 return 0;
68 return This->ref;
71 /******************************************************************************
72 * IUnknown_QueryInterface [VTABLE:IUNKNOWN.0]
74 static HRESULT WINAPI IUnknown_fnQueryInterface(LPUNKNOWN iface,REFIID refiid,LPVOID *obj) {
75 ICOM_THIS(IUnknownImpl,iface);
77 TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(refiid),obj);
79 if (!memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown))) {
80 *obj = This;
81 return 0;
83 return OLE_E_ENUM_NOMORE;
86 static ICOM_VTABLE(IUnknown) uvt =
88 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
89 IUnknown_fnQueryInterface,
90 IUnknown_fnAddRef,
91 IUnknown_fnRelease
94 /******************************************************************************
95 * IUnknown_Constructor [INTERNAL]
97 LPUNKNOWN
98 IUnknown_Constructor() {
99 IUnknownImpl* unk;
101 unk = (IUnknownImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IUnknownImpl));
102 ICOM_VTBL(unk) = &uvt;
103 unk->ref = 1;
104 return (LPUNKNOWN)unk;
108 /* --- IMalloc16 implementation */
111 typedef struct
113 /* IUnknown fields */
114 ICOM_VFIELD(IMalloc16);
115 DWORD ref;
116 /* IMalloc16 fields */
117 } IMalloc16Impl;
119 /******************************************************************************
120 * IMalloc16_QueryInterface [COMPOBJ.500]
122 HRESULT WINAPI IMalloc16_fnQueryInterface(IMalloc16* iface,REFIID refiid,LPVOID *obj) {
123 ICOM_THIS(IMalloc16Impl,iface);
125 TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(refiid),obj);
126 if ( !memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) ||
127 !memcmp(&IID_IMalloc,refiid,sizeof(IID_IMalloc))
129 *obj = This;
130 return 0;
132 return OLE_E_ENUM_NOMORE;
135 /******************************************************************************
136 * IMalloc16_AddRef [COMPOBJ.501]
138 ULONG WINAPI IMalloc16_fnAddRef(IMalloc16* iface) {
139 ICOM_THIS(IMalloc16Impl,iface);
140 TRACE("(%p)->AddRef()\n",This);
141 return 1; /* cannot be freed */
144 /******************************************************************************
145 * IMalloc16_Release [COMPOBJ.502]
147 ULONG WINAPI IMalloc16_fnRelease(IMalloc16* iface) {
148 ICOM_THIS(IMalloc16Impl,iface);
149 TRACE("(%p)->Release()\n",This);
150 return 1; /* cannot be freed */
153 /******************************************************************************
154 * IMalloc16_Alloc [COMPOBJ.503]
156 SEGPTR WINAPI IMalloc16_fnAlloc(IMalloc16* iface,DWORD cb) {
157 ICOM_THIS(IMalloc16Impl,iface);
158 TRACE("(%p)->Alloc(%ld)\n",This,cb);
159 return MapLS( HeapAlloc( GetProcessHeap(), 0, cb ) );
162 /******************************************************************************
163 * IMalloc16_Realloc [COMPOBJ.504]
165 SEGPTR WINAPI IMalloc16_fnRealloc(IMalloc16* iface,SEGPTR pv,DWORD cb)
167 SEGPTR ret;
168 ICOM_THIS(IMalloc16Impl,iface);
169 TRACE("(%p)->Realloc(%08lx,%ld)\n",This,pv,cb);
170 ret = MapLS( HeapReAlloc( GetProcessHeap(), 0, MapSL(pv), cb ) );
171 UnMapLS(pv);
172 return ret;
175 /******************************************************************************
176 * IMalloc16_Free [COMPOBJ.505]
178 VOID WINAPI IMalloc16_fnFree(IMalloc16* iface,SEGPTR pv)
180 void *ptr = MapSL(pv);
181 ICOM_THIS(IMalloc16Impl,iface);
182 TRACE("(%p)->Free(%08lx)\n",This,pv);
183 UnMapLS(pv);
184 HeapFree( GetProcessHeap(), 0, ptr );
187 /******************************************************************************
188 * IMalloc16_GetSize [COMPOBJ.506]
190 DWORD WINAPI IMalloc16_fnGetSize(const IMalloc16* iface,SEGPTR pv)
192 ICOM_CTHIS(IMalloc16Impl,iface);
193 TRACE("(%p)->GetSize(%08lx)\n",This,pv);
194 return HeapSize( GetProcessHeap(), 0, MapSL(pv) );
197 /******************************************************************************
198 * IMalloc16_DidAlloc [COMPOBJ.507]
200 INT16 WINAPI IMalloc16_fnDidAlloc(const IMalloc16* iface,LPVOID pv) {
201 ICOM_CTHIS(IMalloc16,iface);
202 TRACE("(%p)->DidAlloc(%p)\n",This,pv);
203 return (INT16)-1;
206 /******************************************************************************
207 * IMalloc16_HeapMinimize [COMPOBJ.508]
209 LPVOID WINAPI IMalloc16_fnHeapMinimize(IMalloc16* iface) {
210 ICOM_THIS(IMalloc16Impl,iface);
211 TRACE("(%p)->HeapMinimize()\n",This);
212 return NULL;
215 /******************************************************************************
216 * IMalloc16_Constructor [VTABLE]
218 LPMALLOC16
219 IMalloc16_Constructor()
221 static ICOM_VTABLE(IMalloc16) vt16;
222 static SEGPTR msegvt16;
223 IMalloc16Impl* This;
224 HMODULE16 hcomp = GetModuleHandle16("COMPOBJ");
226 This = HeapAlloc( GetProcessHeap(), 0, sizeof(IMalloc16Impl) );
227 if (!msegvt16)
229 #define VTENT(x) vt16.x = (void*)GetProcAddress16(hcomp,"IMalloc16_"#x);assert(vt16.x)
230 VTENT(QueryInterface);
231 VTENT(AddRef);
232 VTENT(Release);
233 VTENT(Alloc);
234 VTENT(Realloc);
235 VTENT(Free);
236 VTENT(GetSize);
237 VTENT(DidAlloc);
238 VTENT(HeapMinimize);
239 #undef VTENT
240 msegvt16 = MapLS( &vt16 );
242 ICOM_VTBL(This) = (ICOM_VTABLE(IMalloc16)*)msegvt16;
243 This->ref = 1;
244 return (LPMALLOC16)MapLS( This );
248 /* --- IMalloc32 implementation */
250 typedef struct
252 /* IUnknown fields */
253 ICOM_VFIELD(IMalloc);
254 DWORD ref;
255 } IMalloc32Impl;
257 /******************************************************************************
258 * IMalloc32_QueryInterface [VTABLE]
260 static HRESULT WINAPI IMalloc_fnQueryInterface(LPMALLOC iface,REFIID refiid,LPVOID *obj) {
261 ICOM_THIS(IMalloc32Impl,iface);
263 TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(refiid),obj);
264 if ( !memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) ||
265 !memcmp(&IID_IMalloc,refiid,sizeof(IID_IMalloc))
267 *obj = This;
268 return S_OK;
270 return OLE_E_ENUM_NOMORE;
273 /******************************************************************************
274 * IMalloc32_AddRef [VTABLE]
276 static ULONG WINAPI IMalloc_fnAddRef(LPMALLOC iface) {
277 ICOM_THIS(IMalloc32Impl,iface);
278 TRACE("(%p)->AddRef()\n",This);
279 return 1; /* cannot be freed */
282 /******************************************************************************
283 * IMalloc32_Release [VTABLE]
285 static ULONG WINAPI IMalloc_fnRelease(LPMALLOC iface) {
286 ICOM_THIS(IMalloc32Impl,iface);
287 TRACE("(%p)->Release()\n",This);
288 return 1; /* cannot be freed */
291 /******************************************************************************
292 * IMalloc32_Alloc [VTABLE]
294 static LPVOID WINAPI IMalloc_fnAlloc(LPMALLOC iface,DWORD cb) {
295 LPVOID addr;
296 ICOM_THIS(IMalloc32Impl,iface);
297 addr = HeapAlloc(GetProcessHeap(),0,cb);
298 TRACE("(%p)->Alloc(%ld) -> %p\n",This,cb,addr);
299 return addr;
302 /******************************************************************************
303 * IMalloc32_Realloc [VTABLE]
305 static LPVOID WINAPI IMalloc_fnRealloc(LPMALLOC iface,LPVOID pv,DWORD cb) {
306 ICOM_THIS(IMalloc32Impl,iface);
307 TRACE("(%p)->Realloc(%p,%ld)\n",This,pv,cb);
308 return HeapReAlloc(GetProcessHeap(),0,pv,cb);
311 /******************************************************************************
312 * IMalloc32_Free [VTABLE]
314 static VOID WINAPI IMalloc_fnFree(LPMALLOC iface,LPVOID pv) {
315 ICOM_THIS(IMalloc32Impl,iface);
316 TRACE("(%p)->Free(%p)\n",This,pv);
317 HeapFree(GetProcessHeap(),0,pv);
320 /******************************************************************************
321 * IMalloc32_GetSize [VTABLE]
323 static DWORD WINAPI IMalloc_fnGetSize(LPMALLOC iface,LPVOID pv) {
324 ICOM_CTHIS(IMalloc,iface);
325 TRACE("(%p)->GetSize(%p)\n",This,pv);
326 return HeapSize(GetProcessHeap(),0,pv);
329 /******************************************************************************
330 * IMalloc32_DidAlloc [VTABLE]
332 static INT WINAPI IMalloc_fnDidAlloc(LPMALLOC iface,LPVOID pv) {
333 ICOM_CTHIS(IMalloc32Impl,iface);
334 TRACE("(%p)->DidAlloc(%p)\n",This,pv);
335 return -1;
338 /******************************************************************************
339 * IMalloc32_HeapMinimize [VTABLE]
341 static VOID WINAPI IMalloc_fnHeapMinimize(LPMALLOC iface) {
342 ICOM_THIS(IMalloc32Impl,iface);
343 TRACE("(%p)->HeapMinimize()\n",This);
346 static ICOM_VTABLE(IMalloc) VT_IMalloc32 =
348 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
349 IMalloc_fnQueryInterface,
350 IMalloc_fnAddRef,
351 IMalloc_fnRelease,
352 IMalloc_fnAlloc,
353 IMalloc_fnRealloc,
354 IMalloc_fnFree,
355 IMalloc_fnGetSize,
356 IMalloc_fnDidAlloc,
357 IMalloc_fnHeapMinimize
360 /******************************************************************************
361 * IMalloc32_Constructor [VTABLE]
363 LPMALLOC
364 IMalloc_Constructor() {
365 IMalloc32Impl* This;
367 This = (IMalloc32Impl*)HeapAlloc(GetProcessHeap(),0,sizeof(IMalloc32Impl));
368 ICOM_VTBL(This) = &VT_IMalloc32;
369 This->ref = 1;
370 return (LPMALLOC)This;
373 /****************************************************************************
374 * API Functions
377 /******************************************************************************
378 * IsValidInterface [OLE32.78]
380 * RETURNS
381 * True, if the passed pointer is a valid interface
383 BOOL WINAPI IsValidInterface(
384 LPUNKNOWN punk /* [in] interface to be tested */
386 return !(
387 IsBadReadPtr(punk,4) ||
388 IsBadReadPtr(ICOM_VTBL(punk),4) ||
389 IsBadReadPtr(ICOM_VTBL(punk)->QueryInterface,9) ||
390 IsBadCodePtr((FARPROC)ICOM_VTBL(punk)->QueryInterface)