1 | /*
|
---|
2 | * basic interfaces
|
---|
3 | *
|
---|
4 | * Copyright 1997 Marcus Meissner
|
---|
5 | *
|
---|
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.
|
---|
10 | *
|
---|
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.
|
---|
15 | *
|
---|
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
|
---|
19 | */
|
---|
20 |
|
---|
21 | #include "config.h"
|
---|
22 |
|
---|
23 | #include <ctype.h>
|
---|
24 | #include <stdlib.h>
|
---|
25 | #include <string.h>
|
---|
26 | #include <assert.h>
|
---|
27 |
|
---|
28 | #include "ole2.h"
|
---|
29 | #include "windef.h"
|
---|
30 | #include "winerror.h"
|
---|
31 |
|
---|
32 | #include "wine/obj_base.h"
|
---|
33 | #include "wine/winbase16.h"
|
---|
34 | #include "ifs.h"
|
---|
35 |
|
---|
36 | #include "wine/debug.h"
|
---|
37 |
|
---|
38 | WINE_DEFAULT_DEBUG_CHANNEL(relay);
|
---|
39 |
|
---|
40 | /* --- IUnknown implementation */
|
---|
41 |
|
---|
42 | typedef struct
|
---|
43 | {
|
---|
44 | /* IUnknown fields */
|
---|
45 | ICOM_VFIELD(IUnknown);
|
---|
46 | DWORD ref;
|
---|
47 | } IUnknownImpl;
|
---|
48 |
|
---|
49 | /******************************************************************************
|
---|
50 | * IUnknown_AddRef [VTABLE:IUNKNOWN.1]
|
---|
51 | */
|
---|
52 | static ULONG WINAPI IUnknown_fnAddRef(LPUNKNOWN iface) {
|
---|
53 | ICOM_THIS(IUnknownImpl,iface);
|
---|
54 | TRACE("(%p)->AddRef()\n",This);
|
---|
55 | return ++(This->ref);
|
---|
56 | }
|
---|
57 |
|
---|
58 | /******************************************************************************
|
---|
59 | * IUnknown_Release [VTABLE:IUNKNOWN.2]
|
---|
60 | */
|
---|
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;
|
---|
67 | }
|
---|
68 | return This->ref;
|
---|
69 | }
|
---|
70 |
|
---|
71 | /******************************************************************************
|
---|
72 | * IUnknown_QueryInterface [VTABLE:IUNKNOWN.0]
|
---|
73 | */
|
---|
74 | static HRESULT WINAPI IUnknown_fnQueryInterface(LPUNKNOWN iface,REFIID refiid,LPVOID *obj) {
|
---|
75 | ICOM_THIS(IUnknownImpl,iface);
|
---|
76 |
|
---|
77 | TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(refiid),obj);
|
---|
78 |
|
---|
79 | if (!memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown))) {
|
---|
80 | *obj = This;
|
---|
81 | return 0;
|
---|
82 | }
|
---|
83 | return OLE_E_ENUM_NOMORE;
|
---|
84 | }
|
---|
85 |
|
---|
86 | static ICOM_VTABLE(IUnknown) uvt =
|
---|
87 | {
|
---|
88 | ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
---|
89 | IUnknown_fnQueryInterface,
|
---|
90 | IUnknown_fnAddRef,
|
---|
91 | IUnknown_fnRelease
|
---|
92 | };
|
---|
93 |
|
---|
94 | /******************************************************************************
|
---|
95 | * IUnknown_Constructor [INTERNAL]
|
---|
96 | */
|
---|
97 | LPUNKNOWN
|
---|
98 | IUnknown_Constructor() {
|
---|
99 | IUnknownImpl* unk;
|
---|
100 |
|
---|
101 | unk = (IUnknownImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IUnknownImpl));
|
---|
102 | ICOM_VTBL(unk) = &uvt;
|
---|
103 | unk->ref = 1;
|
---|
104 | return (LPUNKNOWN)unk;
|
---|
105 | }
|
---|
106 |
|
---|
107 | #ifndef __WIN32OS2__
|
---|
108 | /* --- IMalloc16 implementation */
|
---|
109 |
|
---|
110 |
|
---|
111 | typedef struct
|
---|
112 | {
|
---|
113 | /* IUnknown fields */
|
---|
114 | ICOM_VFIELD(IMalloc16);
|
---|
115 | DWORD ref;
|
---|
116 | /* IMalloc16 fields */
|
---|
117 | } IMalloc16Impl;
|
---|
118 |
|
---|
119 | /******************************************************************************
|
---|
120 | * IMalloc16_QueryInterface [COMPOBJ.500]
|
---|
121 | */
|
---|
122 | HRESULT WINAPI IMalloc16_fnQueryInterface(IMalloc16* iface,REFIID refiid,LPVOID *obj) {
|
---|
123 | ICOM_THIS(IMalloc16Impl,iface);
|
---|
124 |
|
---|
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))
|
---|
128 | ) {
|
---|
129 | *obj = This;
|
---|
130 | return 0;
|
---|
131 | }
|
---|
132 | return OLE_E_ENUM_NOMORE;
|
---|
133 | }
|
---|
134 |
|
---|
135 | /******************************************************************************
|
---|
136 | * IMalloc16_AddRef [COMPOBJ.501]
|
---|
137 | */
|
---|
138 | ULONG WINAPI IMalloc16_fnAddRef(IMalloc16* iface) {
|
---|
139 | ICOM_THIS(IMalloc16Impl,iface);
|
---|
140 | TRACE("(%p)->AddRef()\n",This);
|
---|
141 | return 1; /* cannot be freed */
|
---|
142 | }
|
---|
143 |
|
---|
144 | /******************************************************************************
|
---|
145 | * IMalloc16_Release [COMPOBJ.502]
|
---|
146 | */
|
---|
147 | ULONG WINAPI IMalloc16_fnRelease(IMalloc16* iface) {
|
---|
148 | ICOM_THIS(IMalloc16Impl,iface);
|
---|
149 | TRACE("(%p)->Release()\n",This);
|
---|
150 | return 1; /* cannot be freed */
|
---|
151 | }
|
---|
152 |
|
---|
153 | /******************************************************************************
|
---|
154 | * IMalloc16_Alloc [COMPOBJ.503]
|
---|
155 | */
|
---|
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 ) );
|
---|
160 | }
|
---|
161 |
|
---|
162 | /******************************************************************************
|
---|
163 | * IMalloc16_Realloc [COMPOBJ.504]
|
---|
164 | */
|
---|
165 | SEGPTR WINAPI IMalloc16_fnRealloc(IMalloc16* iface,SEGPTR pv,DWORD cb)
|
---|
166 | {
|
---|
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;
|
---|
173 | }
|
---|
174 |
|
---|
175 | /******************************************************************************
|
---|
176 | * IMalloc16_Free [COMPOBJ.505]
|
---|
177 | */
|
---|
178 | VOID WINAPI IMalloc16_fnFree(IMalloc16* iface,SEGPTR pv)
|
---|
179 | {
|
---|
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 );
|
---|
185 | }
|
---|
186 |
|
---|
187 | /******************************************************************************
|
---|
188 | * IMalloc16_GetSize [COMPOBJ.506]
|
---|
189 | */
|
---|
190 | DWORD WINAPI IMalloc16_fnGetSize(const IMalloc16* iface,SEGPTR pv)
|
---|
191 | {
|
---|
192 | ICOM_CTHIS(IMalloc16Impl,iface);
|
---|
193 | TRACE("(%p)->GetSize(%08lx)\n",This,pv);
|
---|
194 | return HeapSize( GetProcessHeap(), 0, MapSL(pv) );
|
---|
195 | }
|
---|
196 |
|
---|
197 | /******************************************************************************
|
---|
198 | * IMalloc16_DidAlloc [COMPOBJ.507]
|
---|
199 | */
|
---|
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;
|
---|
204 | }
|
---|
205 |
|
---|
206 | /******************************************************************************
|
---|
207 | * IMalloc16_HeapMinimize [COMPOBJ.508]
|
---|
208 | */
|
---|
209 | LPVOID WINAPI IMalloc16_fnHeapMinimize(IMalloc16* iface) {
|
---|
210 | ICOM_THIS(IMalloc16Impl,iface);
|
---|
211 | TRACE("(%p)->HeapMinimize()\n",This);
|
---|
212 | return NULL;
|
---|
213 | }
|
---|
214 |
|
---|
215 | /******************************************************************************
|
---|
216 | * IMalloc16_Constructor [VTABLE]
|
---|
217 | */
|
---|
218 | LPMALLOC16
|
---|
219 | IMalloc16_Constructor()
|
---|
220 | {
|
---|
221 | static ICOM_VTABLE(IMalloc16) vt16;
|
---|
222 | static SEGPTR msegvt16;
|
---|
223 | IMalloc16Impl* This;
|
---|
224 | HMODULE16 hcomp = GetModuleHandle16("COMPOBJ");
|
---|
225 |
|
---|
226 | This = HeapAlloc( GetProcessHeap(), 0, sizeof(IMalloc16Impl) );
|
---|
227 | if (!msegvt16)
|
---|
228 | {
|
---|
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 );
|
---|
241 | }
|
---|
242 | ICOM_VTBL(This) = (ICOM_VTABLE(IMalloc16)*)msegvt16;
|
---|
243 | This->ref = 1;
|
---|
244 | return (LPMALLOC16)MapLS( This );
|
---|
245 | }
|
---|
246 | #endif
|
---|
247 |
|
---|
248 | /* --- IMalloc32 implementation */
|
---|
249 |
|
---|
250 | typedef struct
|
---|
251 | {
|
---|
252 | /* IUnknown fields */
|
---|
253 | ICOM_VFIELD(IMalloc);
|
---|
254 | DWORD ref;
|
---|
255 | } IMalloc32Impl;
|
---|
256 |
|
---|
257 | /******************************************************************************
|
---|
258 | * IMalloc32_QueryInterface [VTABLE]
|
---|
259 | */
|
---|
260 | static HRESULT WINAPI IMalloc_fnQueryInterface(LPMALLOC iface,REFIID refiid,LPVOID *obj) {
|
---|
261 | ICOM_THIS(IMalloc32Impl,iface);
|
---|
262 |
|
---|
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))
|
---|
266 | ) {
|
---|
267 | *obj = This;
|
---|
268 | return S_OK;
|
---|
269 | }
|
---|
270 | return OLE_E_ENUM_NOMORE;
|
---|
271 | }
|
---|
272 |
|
---|
273 | /******************************************************************************
|
---|
274 | * IMalloc32_AddRef [VTABLE]
|
---|
275 | */
|
---|
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 */
|
---|
280 | }
|
---|
281 |
|
---|
282 | /******************************************************************************
|
---|
283 | * IMalloc32_Release [VTABLE]
|
---|
284 | */
|
---|
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 */
|
---|
289 | }
|
---|
290 |
|
---|
291 | /******************************************************************************
|
---|
292 | * IMalloc32_Alloc [VTABLE]
|
---|
293 | */
|
---|
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;
|
---|
300 | }
|
---|
301 |
|
---|
302 | /******************************************************************************
|
---|
303 | * IMalloc32_Realloc [VTABLE]
|
---|
304 | */
|
---|
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);
|
---|
309 | }
|
---|
310 |
|
---|
311 | /******************************************************************************
|
---|
312 | * IMalloc32_Free [VTABLE]
|
---|
313 | */
|
---|
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);
|
---|
318 | }
|
---|
319 |
|
---|
320 | /******************************************************************************
|
---|
321 | * IMalloc32_GetSize [VTABLE]
|
---|
322 | */
|
---|
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);
|
---|
327 | }
|
---|
328 |
|
---|
329 | /******************************************************************************
|
---|
330 | * IMalloc32_DidAlloc [VTABLE]
|
---|
331 | */
|
---|
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;
|
---|
336 | }
|
---|
337 |
|
---|
338 | /******************************************************************************
|
---|
339 | * IMalloc32_HeapMinimize [VTABLE]
|
---|
340 | */
|
---|
341 | static VOID WINAPI IMalloc_fnHeapMinimize(LPMALLOC iface) {
|
---|
342 | ICOM_THIS(IMalloc32Impl,iface);
|
---|
343 | TRACE("(%p)->HeapMinimize()\n",This);
|
---|
344 | }
|
---|
345 |
|
---|
346 | static ICOM_VTABLE(IMalloc) VT_IMalloc32 =
|
---|
347 | {
|
---|
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
|
---|
358 | };
|
---|
359 |
|
---|
360 | /******************************************************************************
|
---|
361 | * IMalloc32_Constructor [VTABLE]
|
---|
362 | */
|
---|
363 | LPMALLOC
|
---|
364 | IMalloc_Constructor() {
|
---|
365 | IMalloc32Impl* This;
|
---|
366 |
|
---|
367 | This = (IMalloc32Impl*)HeapAlloc(GetProcessHeap(),0,sizeof(IMalloc32Impl));
|
---|
368 | ICOM_VTBL(This) = &VT_IMalloc32;
|
---|
369 | This->ref = 1;
|
---|
370 | return (LPMALLOC)This;
|
---|
371 | }
|
---|
372 |
|
---|
373 | /****************************************************************************
|
---|
374 | * API Functions
|
---|
375 | */
|
---|
376 |
|
---|
377 | /******************************************************************************
|
---|
378 | * IsValidInterface [OLE32.78]
|
---|
379 | *
|
---|
380 | * RETURNS
|
---|
381 | * True, if the passed pointer is a valid interface
|
---|
382 | */
|
---|
383 | BOOL WINAPI IsValidInterface(
|
---|
384 | LPUNKNOWN punk /* [in] interface to be tested */
|
---|
385 | ) {
|
---|
386 | return !(
|
---|
387 | IsBadReadPtr(punk,4) ||
|
---|
388 | IsBadReadPtr(ICOM_VTBL(punk),4) ||
|
---|
389 | #ifdef __WIN32OS2__
|
---|
390 | IsBadReadPtr(ICOM_VTBL(punk)->fnQueryInterface,9) ||
|
---|
391 | IsBadCodePtr((FARPROC)ICOM_VTBL(punk)->fnQueryInterface)
|
---|
392 | #else
|
---|
393 | IsBadReadPtr(ICOM_VTBL(punk)->QueryInterface,9) ||
|
---|
394 | IsBadCodePtr((FARPROC)ICOM_VTBL(punk)->QueryInterface)
|
---|
395 | #endif
|
---|
396 | );
|
---|
397 | }
|
---|