wined3d: Factor out acquire_graphics_pipeline_resources().
[wine.git] / dlls / oleaut32 / usrmarshal.c
blobda524c85ebbeaa44f13e0bcdadfcedd13d593dfe
1 /*
2 * Misc marshalling routines
4 * Copyright 2002 Ove Kaaven
5 * Copyright 2003 Mike Hearn
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <stdarg.h>
23 #include <string.h>
25 #define COBJMACROS
26 #define NONAMELESSUNION
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "winerror.h"
34 #include "ole2.h"
35 #include "oleauto.h"
36 #include "typelib.h"
37 #include "ocidl.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(ole);
42 #define ALIGNED_LENGTH(_Len, _Align) (((_Len)+(_Align))&~(_Align))
43 #define ALIGNED_POINTER(_Ptr, _Align) ((LPVOID)ALIGNED_LENGTH((ULONG_PTR)(_Ptr), _Align))
44 #define ALIGN_LENGTH(_Len, _Align) _Len = ALIGNED_LENGTH(_Len, _Align)
45 #define ALIGN_POINTER(_Ptr, _Align) _Ptr = ALIGNED_POINTER(_Ptr, _Align)
47 /* ole32 exports those, not defined in public headers */
48 ULONG __RPC_USER WdtpInterfacePointer_UserSize(ULONG*, ULONG, ULONG, IUnknown*, REFIID);
49 unsigned char * __RPC_USER WdtpInterfacePointer_UserMarshal(ULONG*, ULONG, unsigned char*, IUnknown*, REFIID);
50 unsigned char * __RPC_USER WdtpInterfacePointer_UserUnmarshal(ULONG*, unsigned char*, IUnknown**, REFIID);
52 static void dump_user_flags(const ULONG *pFlags)
54 if (HIWORD(*pFlags) == NDR_LOCAL_DATA_REPRESENTATION)
55 TRACE("MAKELONG(NDR_LOCAL_REPRESENTATION, ");
56 else
57 TRACE("MAKELONG(0x%04x, ", HIWORD(*pFlags));
58 switch (LOWORD(*pFlags))
60 case MSHCTX_LOCAL: TRACE("MSHCTX_LOCAL)"); break;
61 case MSHCTX_NOSHAREDMEM: TRACE("MSHCTX_NOSHAREDMEM)"); break;
62 case MSHCTX_DIFFERENTMACHINE: TRACE("MSHCTX_DIFFERENTMACHINE)"); break;
63 case MSHCTX_INPROC: TRACE("MSHCTX_INPROC)"); break;
64 default: TRACE("%d)", LOWORD(*pFlags));
68 /* CLEANLOCALSTORAGE */
70 #define CLS_FUNCDESC 'f'
71 #define CLS_LIBATTR 'l'
72 #define CLS_TYPEATTR 't'
73 #define CLS_VARDESC 'v'
75 ULONG WINAPI CLEANLOCALSTORAGE_UserSize(ULONG *pFlags, ULONG Start, CLEANLOCALSTORAGE *pstg)
77 ALIGN_LENGTH(Start, 3);
78 return Start + sizeof(DWORD);
81 unsigned char * WINAPI CLEANLOCALSTORAGE_UserMarshal(ULONG *pFlags, unsigned char *Buffer, CLEANLOCALSTORAGE *pstg)
83 ALIGN_POINTER(Buffer, 3);
84 *(DWORD*)Buffer = pstg->flags;
86 if (!pstg->pInterface)
87 return Buffer + sizeof(DWORD);
89 switch(pstg->flags)
91 case CLS_LIBATTR:
92 ITypeLib_ReleaseTLibAttr((ITypeLib*)pstg->pInterface, *(TLIBATTR**)pstg->pStorage);
93 break;
94 case CLS_TYPEATTR:
95 ITypeInfo_ReleaseTypeAttr((ITypeInfo*)pstg->pInterface, *(TYPEATTR**)pstg->pStorage);
96 break;
97 case CLS_FUNCDESC:
98 ITypeInfo_ReleaseFuncDesc((ITypeInfo*)pstg->pInterface, *(FUNCDESC**)pstg->pStorage);
99 break;
100 case CLS_VARDESC:
101 ITypeInfo_ReleaseVarDesc((ITypeInfo*)pstg->pInterface, *(VARDESC**)pstg->pStorage);
102 break;
104 default:
105 ERR("Unknown type %x\n", pstg->flags);
108 *(VOID**)pstg->pStorage = NULL;
109 IUnknown_Release(pstg->pInterface);
110 pstg->pInterface = NULL;
112 return Buffer + sizeof(DWORD);
115 unsigned char * WINAPI CLEANLOCALSTORAGE_UserUnmarshal(ULONG *pFlags, unsigned char *Buffer, CLEANLOCALSTORAGE *pstr)
117 ALIGN_POINTER(Buffer, 3);
118 pstr->flags = *(DWORD*)Buffer;
119 return Buffer + sizeof(DWORD);
122 void WINAPI CLEANLOCALSTORAGE_UserFree(ULONG *pFlags, CLEANLOCALSTORAGE *pstr)
124 /* Nothing to do */
127 /* BSTR */
129 typedef struct
131 DWORD len; /* No. of chars not including trailing '\0' */
132 DWORD byte_len; /* len * 2 or 0xffffffff if len == 0 */
133 DWORD len2; /* == len */
134 } bstr_wire_t;
136 ULONG WINAPI BSTR_UserSize(ULONG *pFlags, ULONG Start, BSTR *pstr)
138 TRACE("(%x,%d,%p) => %p\n", *pFlags, Start, pstr, *pstr);
139 if (*pstr) TRACE("string=%s\n", debugstr_w(*pstr));
140 ALIGN_LENGTH(Start, 3);
141 Start += sizeof(bstr_wire_t) + ((SysStringByteLen(*pstr) + 1) & ~1);
142 TRACE("returning %d\n", Start);
143 return Start;
146 unsigned char * WINAPI BSTR_UserMarshal(ULONG *pFlags, unsigned char *Buffer, BSTR *pstr)
148 bstr_wire_t *header;
149 DWORD len = SysStringByteLen(*pstr);
151 TRACE("(%x,%p,%p) => %p\n", *pFlags, Buffer, pstr, *pstr);
152 if (*pstr) TRACE("string=%s\n", debugstr_w(*pstr));
154 ALIGN_POINTER(Buffer, 3);
155 header = (bstr_wire_t*)Buffer;
156 header->len = header->len2 = (len + 1) / 2;
157 if (*pstr)
159 header->byte_len = len;
160 memcpy(header + 1, *pstr, header->len * 2);
162 else
163 header->byte_len = 0xffffffff; /* special case for a null bstr */
165 return Buffer + sizeof(*header) + sizeof(OLECHAR) * header->len;
168 unsigned char * WINAPI BSTR_UserUnmarshal(ULONG *pFlags, unsigned char *Buffer, BSTR *pstr)
170 bstr_wire_t *header;
171 TRACE("(%x,%p,%p) => %p\n", *pFlags, Buffer, pstr, *pstr);
173 ALIGN_POINTER(Buffer, 3);
174 header = (bstr_wire_t*)Buffer;
175 if(header->len != header->len2)
176 FIXME("len %08x != len2 %08x\n", header->len, header->len2);
178 if (header->byte_len == 0xffffffff)
180 SysFreeString(*pstr);
181 *pstr = NULL;
183 else SysReAllocStringLen( pstr, (OLECHAR *)(header + 1), header->len );
185 if (*pstr) TRACE("string=%s\n", debugstr_w(*pstr));
186 return Buffer + sizeof(*header) + sizeof(OLECHAR) * header->len;
189 void WINAPI BSTR_UserFree(ULONG *pFlags, BSTR *pstr)
191 TRACE("(%x,%p) => %p\n", *pFlags, pstr, *pstr);
192 SysFreeString(*pstr);
193 *pstr = NULL;
196 /* VARIANT */
198 typedef struct
200 DWORD clSize;
201 DWORD rpcReserved;
202 USHORT vt;
203 USHORT wReserved1;
204 USHORT wReserved2;
205 USHORT wReserved3;
206 DWORD switch_is;
207 } variant_wire_t;
209 unsigned int get_type_size(ULONG *pFlags, VARTYPE vt)
211 if (vt & VT_ARRAY) return 4;
213 switch (vt & ~VT_BYREF) {
214 case VT_EMPTY:
215 case VT_NULL:
216 return 0;
217 case VT_I1:
218 case VT_UI1:
219 return sizeof(CHAR);
220 case VT_I2:
221 case VT_UI2:
222 return sizeof(SHORT);
223 case VT_I4:
224 case VT_UI4:
225 case VT_HRESULT:
226 return sizeof(LONG);
227 case VT_INT:
228 case VT_UINT:
229 return sizeof(INT);
230 case VT_R4:
231 return sizeof(FLOAT);
232 case VT_R8:
233 return sizeof(DOUBLE);
234 case VT_BOOL:
235 return sizeof(VARIANT_BOOL);
236 case VT_ERROR:
237 return sizeof(SCODE);
238 case VT_DATE:
239 return sizeof(DATE);
240 case VT_CY:
241 return sizeof(CY);
242 case VT_DECIMAL:
243 return sizeof(DECIMAL);
244 case VT_BSTR:
245 return sizeof(ULONG);
246 case VT_VARIANT:
247 return sizeof(VARIANT);
248 case VT_UNKNOWN:
249 case VT_DISPATCH:
250 case VT_RECORD:
251 return 0;
252 default:
253 FIXME("unhandled VT %d\n", vt);
254 return 0;
258 static unsigned int get_type_alignment(ULONG *pFlags, VARTYPE vt)
260 unsigned int size = get_type_size(pFlags, vt);
261 if(vt & VT_BYREF) return 3;
262 if(size == 0) return 0;
263 if(size <= 4) return size - 1;
264 return 7;
267 /* WdtpInterfacePointer_UserSize takes care of 2 additional DWORDs to store marshalling buffer size */
268 static unsigned interface_variant_size(ULONG *pFlags, REFIID riid, IUnknown *punk)
270 ULONG size = 0;
272 if (punk)
274 size = WdtpInterfacePointer_UserSize(pFlags, LOWORD(*pFlags), 0, punk, riid);
275 if (!size)
277 ERR("interface variant buffer size calculation failed\n");
278 return 0;
281 size += sizeof(ULONG);
282 TRACE("wire-size extra of interface variant is %d\n", size);
283 return size;
286 static ULONG wire_extra_user_size(ULONG *pFlags, ULONG Start, VARIANT *pvar)
288 if (V_ISARRAY(pvar))
290 if (V_ISBYREF(pvar))
291 return LPSAFEARRAY_UserSize(pFlags, Start, V_ARRAYREF(pvar));
292 else
293 return LPSAFEARRAY_UserSize(pFlags, Start, &V_ARRAY(pvar));
296 switch (V_VT(pvar)) {
297 case VT_BSTR:
298 return BSTR_UserSize(pFlags, Start, &V_BSTR(pvar));
299 case VT_BSTR | VT_BYREF:
300 return BSTR_UserSize(pFlags, Start, V_BSTRREF(pvar));
301 case VT_VARIANT | VT_BYREF:
302 return VARIANT_UserSize(pFlags, Start, V_VARIANTREF(pvar));
303 case VT_UNKNOWN:
304 return Start + interface_variant_size(pFlags, &IID_IUnknown, V_UNKNOWN(pvar));
305 case VT_UNKNOWN | VT_BYREF:
306 return Start + interface_variant_size(pFlags, &IID_IUnknown, *V_UNKNOWNREF(pvar));
307 case VT_DISPATCH:
308 return Start + interface_variant_size(pFlags, &IID_IDispatch, (IUnknown*)V_DISPATCH(pvar));
309 case VT_DISPATCH | VT_BYREF:
310 return Start + interface_variant_size(pFlags, &IID_IDispatch, (IUnknown*)*V_DISPATCHREF(pvar));
311 case VT_RECORD:
312 FIXME("wire-size record\n");
313 return Start;
314 case VT_SAFEARRAY:
315 case VT_SAFEARRAY | VT_BYREF:
316 FIXME("wire-size safearray: shouldn't be marshaling this\n");
317 return Start;
318 default:
319 return Start;
323 /* helper: called for VT_DISPATCH variants to marshal the IDispatch* into the buffer */
324 static unsigned char* interface_variant_marshal(ULONG *pFlags, unsigned char *Buffer,
325 REFIID riid, IUnknown *punk)
327 TRACE("pFlags=%d, Buffer=%p, pUnk=%p\n", *pFlags, Buffer, punk);
329 /* first DWORD is used to store pointer itself, truncated on win64 */
330 if(!punk)
332 memset(Buffer, 0, sizeof(ULONG));
333 return Buffer + sizeof(ULONG);
335 else
337 *(DWORD*)Buffer = (DWORD_PTR)punk;
338 Buffer += sizeof(DWORD);
341 return WdtpInterfacePointer_UserMarshal(pFlags, LOWORD(*pFlags), Buffer, punk, riid);
344 /* helper: called for VT_DISPATCH / VT_UNKNOWN variants to unmarshal the buffer */
345 static unsigned char *interface_variant_unmarshal(ULONG *pFlags, unsigned char *Buffer,
346 REFIID riid, IUnknown **ppunk)
348 DWORD ptr;
350 TRACE("pFlags=%d, Buffer=%p, ppUnk=%p\n", *pFlags, Buffer, ppunk);
352 /* skip pointer part itself */
353 ptr = *(DWORD*)Buffer;
354 Buffer += sizeof(DWORD);
356 if(!ptr)
357 return Buffer;
359 return WdtpInterfacePointer_UserUnmarshal(pFlags, Buffer, ppunk, riid);
362 ULONG WINAPI VARIANT_UserSize(ULONG *pFlags, ULONG Start, VARIANT *pvar)
364 int align;
365 TRACE("(%x,%d,%p)\n", *pFlags, Start, pvar);
366 TRACE("vt=%04x\n", V_VT(pvar));
368 ALIGN_LENGTH(Start, 7);
369 Start += sizeof(variant_wire_t);
370 if(V_VT(pvar) & VT_BYREF)
371 Start += 4;
373 align = get_type_alignment(pFlags, V_VT(pvar));
374 ALIGN_LENGTH(Start, align);
375 if(V_VT(pvar) == (VT_VARIANT | VT_BYREF))
376 Start += 4;
377 else
378 Start += get_type_size(pFlags, V_VT(pvar));
379 Start = wire_extra_user_size(pFlags, Start, pvar);
381 TRACE("returning %d\n", Start);
382 return Start;
385 unsigned char * WINAPI VARIANT_UserMarshal(ULONG *pFlags, unsigned char *Buffer, VARIANT *pvar)
387 variant_wire_t *header;
388 ULONG type_size;
389 int align;
390 unsigned char *Pos;
392 TRACE("(%x,%p,%p)\n", *pFlags, Buffer, pvar);
393 TRACE("vt=%04x\n", V_VT(pvar));
395 ALIGN_POINTER(Buffer, 7);
397 header = (variant_wire_t *)Buffer;
399 header->clSize = 0; /* fixed up at the end */
400 header->rpcReserved = 0;
401 header->vt = pvar->n1.n2.vt;
402 header->wReserved1 = pvar->n1.n2.wReserved1;
403 header->wReserved2 = pvar->n1.n2.wReserved2;
404 header->wReserved3 = pvar->n1.n2.wReserved3;
405 header->switch_is = pvar->n1.n2.vt;
406 if(header->switch_is & VT_ARRAY)
407 header->switch_is &= ~VT_TYPEMASK;
409 Pos = (unsigned char*)(header + 1);
410 type_size = get_type_size(pFlags, V_VT(pvar));
411 align = get_type_alignment(pFlags, V_VT(pvar));
412 ALIGN_POINTER(Pos, align);
414 if(header->vt & VT_BYREF)
416 *(DWORD *)Pos = max(type_size, 4);
417 Pos += 4;
418 if((header->vt & VT_TYPEMASK) != VT_VARIANT)
420 memcpy(Pos, pvar->n1.n2.n3.byref, type_size);
421 Pos += type_size;
423 else
425 *(DWORD*)Pos = 'U' | 's' << 8 | 'e' << 16 | 'r' << 24;
426 Pos += 4;
429 else
431 if((header->vt & VT_TYPEMASK) == VT_DECIMAL)
432 memcpy(Pos, pvar, type_size);
433 else
434 memcpy(Pos, &pvar->n1.n2.n3, type_size);
435 Pos += type_size;
438 if(header->vt & VT_ARRAY)
440 if(header->vt & VT_BYREF)
441 Pos = LPSAFEARRAY_UserMarshal(pFlags, Pos, V_ARRAYREF(pvar));
442 else
443 Pos = LPSAFEARRAY_UserMarshal(pFlags, Pos, &V_ARRAY(pvar));
445 else
447 switch (header->vt)
449 case VT_BSTR:
450 Pos = BSTR_UserMarshal(pFlags, Pos, &V_BSTR(pvar));
451 break;
452 case VT_BSTR | VT_BYREF:
453 Pos = BSTR_UserMarshal(pFlags, Pos, V_BSTRREF(pvar));
454 break;
455 case VT_VARIANT | VT_BYREF:
456 Pos = VARIANT_UserMarshal(pFlags, Pos, V_VARIANTREF(pvar));
457 break;
458 case VT_UNKNOWN:
459 Pos = interface_variant_marshal(pFlags, Pos, &IID_IUnknown, V_UNKNOWN(pvar));
460 break;
461 case VT_UNKNOWN | VT_BYREF:
462 Pos = interface_variant_marshal(pFlags, Pos, &IID_IUnknown, *V_UNKNOWNREF(pvar));
463 break;
464 case VT_DISPATCH:
465 Pos = interface_variant_marshal(pFlags, Pos, &IID_IDispatch, (IUnknown*)V_DISPATCH(pvar));
466 break;
467 case VT_DISPATCH | VT_BYREF:
468 Pos = interface_variant_marshal(pFlags, Pos, &IID_IDispatch, (IUnknown*)*V_DISPATCHREF(pvar));
469 break;
470 case VT_RECORD:
471 FIXME("handle BRECORD by val\n");
472 break;
473 case VT_RECORD | VT_BYREF:
474 FIXME("handle BRECORD by ref\n");
475 break;
478 header->clSize = ((Pos - Buffer) + 7) >> 3;
479 TRACE("marshalled size=%d\n", header->clSize);
480 return Pos;
483 unsigned char * WINAPI VARIANT_UserUnmarshal(ULONG *pFlags, unsigned char *Buffer, VARIANT *pvar)
485 variant_wire_t *header;
486 ULONG type_size;
487 int align;
488 unsigned char *Pos;
490 TRACE("(%x,%p,%p)\n", *pFlags, Buffer, pvar);
492 ALIGN_POINTER(Buffer, 7);
494 header = (variant_wire_t *)Buffer;
496 Pos = (unsigned char*)(header + 1);
497 type_size = get_type_size(pFlags, header->vt);
498 align = get_type_alignment(pFlags, header->vt);
499 ALIGN_POINTER(Pos, align);
501 if(header->vt & VT_BYREF)
503 ULONG mem_size;
504 Pos += 4;
506 switch (header->vt & ~VT_BYREF)
508 /* these types have a different memory size compared to wire size */
509 case VT_UNKNOWN:
510 case VT_DISPATCH:
511 case VT_BSTR:
512 mem_size = sizeof(void *);
513 break;
514 default:
515 mem_size = type_size;
516 break;
519 if (V_VT(pvar) != header->vt)
521 VariantClear(pvar);
522 V_BYREF(pvar) = CoTaskMemAlloc(mem_size);
523 memset(V_BYREF(pvar), 0, mem_size);
525 else if (!V_BYREF(pvar))
527 V_BYREF(pvar) = CoTaskMemAlloc(mem_size);
528 memset(V_BYREF(pvar), 0, mem_size);
531 if(!(header->vt & VT_ARRAY)
532 && (header->vt & VT_TYPEMASK) != VT_BSTR
533 && (header->vt & VT_TYPEMASK) != VT_VARIANT
534 && (header->vt & VT_TYPEMASK) != VT_UNKNOWN
535 && (header->vt & VT_TYPEMASK) != VT_DISPATCH
536 && (header->vt & VT_TYPEMASK) != VT_RECORD)
537 memcpy(V_BYREF(pvar), Pos, type_size);
539 if((header->vt & VT_TYPEMASK) != VT_VARIANT)
540 Pos += type_size;
541 else
542 Pos += 4;
544 else
546 VariantClear(pvar);
547 if(header->vt & VT_ARRAY)
548 V_ARRAY(pvar) = NULL;
549 else if((header->vt & VT_TYPEMASK) == VT_BSTR)
550 V_BSTR(pvar) = NULL;
551 else if((header->vt & VT_TYPEMASK) == VT_UNKNOWN)
552 V_UNKNOWN(pvar) = NULL;
553 else if((header->vt & VT_TYPEMASK) == VT_DISPATCH)
554 V_DISPATCH(pvar) = NULL;
555 else if((header->vt & VT_TYPEMASK) == VT_RECORD)
556 V_RECORD(pvar) = NULL;
557 else if((header->vt & VT_TYPEMASK) == VT_DECIMAL)
558 memcpy(pvar, Pos, type_size);
559 else
560 memcpy(&pvar->n1.n2.n3, Pos, type_size);
561 Pos += type_size;
564 pvar->n1.n2.vt = header->vt;
565 pvar->n1.n2.wReserved1 = header->wReserved1;
566 pvar->n1.n2.wReserved2 = header->wReserved2;
567 pvar->n1.n2.wReserved3 = header->wReserved3;
569 if(header->vt & VT_ARRAY)
571 if(header->vt & VT_BYREF)
572 Pos = LPSAFEARRAY_UserUnmarshal(pFlags, Pos, V_ARRAYREF(pvar));
573 else
574 Pos = LPSAFEARRAY_UserUnmarshal(pFlags, Pos, &V_ARRAY(pvar));
576 else
578 switch (header->vt)
580 case VT_BSTR:
581 Pos = BSTR_UserUnmarshal(pFlags, Pos, &V_BSTR(pvar));
582 break;
583 case VT_BSTR | VT_BYREF:
584 Pos = BSTR_UserUnmarshal(pFlags, Pos, V_BSTRREF(pvar));
585 break;
586 case VT_VARIANT | VT_BYREF:
587 Pos = VARIANT_UserUnmarshal(pFlags, Pos, V_VARIANTREF(pvar));
588 break;
589 case VT_UNKNOWN:
590 Pos = interface_variant_unmarshal(pFlags, Pos, &IID_IUnknown, &V_UNKNOWN(pvar));
591 break;
592 case VT_UNKNOWN | VT_BYREF:
593 Pos = interface_variant_unmarshal(pFlags, Pos, &IID_IUnknown, V_UNKNOWNREF(pvar));
594 break;
595 case VT_DISPATCH:
596 Pos = interface_variant_unmarshal(pFlags, Pos, &IID_IDispatch, (IUnknown**)&V_DISPATCH(pvar));
597 break;
598 case VT_DISPATCH | VT_BYREF:
599 Pos = interface_variant_unmarshal(pFlags, Pos, &IID_IDispatch, (IUnknown**)V_DISPATCHREF(pvar));
600 break;
601 case VT_RECORD:
602 FIXME("handle BRECORD by val\n");
603 break;
604 case VT_RECORD | VT_BYREF:
605 FIXME("handle BRECORD by ref\n");
606 break;
609 return Pos;
612 void WINAPI VARIANT_UserFree(ULONG *pFlags, VARIANT *pvar)
614 VARTYPE vt = V_VT(pvar);
615 PVOID ref = NULL;
617 TRACE("(%x,%p)\n", *pFlags, pvar);
618 TRACE("vt=%04x\n", V_VT(pvar));
620 if (vt & VT_BYREF) ref = pvar->n1.n2.n3.byref;
622 VariantClear(pvar);
623 if (!ref) return;
625 if(vt & VT_ARRAY)
627 if (vt & VT_BYREF)
628 LPSAFEARRAY_UserFree(pFlags, V_ARRAYREF(pvar));
629 else
630 LPSAFEARRAY_UserFree(pFlags, &V_ARRAY(pvar));
632 else
634 switch (vt)
636 case VT_BSTR | VT_BYREF:
637 BSTR_UserFree(pFlags, V_BSTRREF(pvar));
638 break;
639 case VT_VARIANT | VT_BYREF:
640 VARIANT_UserFree(pFlags, V_VARIANTREF(pvar));
641 break;
642 case VT_RECORD | VT_BYREF:
643 FIXME("handle BRECORD by ref\n");
644 break;
645 case VT_UNKNOWN | VT_BYREF:
646 case VT_DISPATCH | VT_BYREF:
647 IUnknown_Release(*V_UNKNOWNREF(pvar));
648 break;
652 CoTaskMemFree(ref);
655 /* LPSAFEARRAY */
657 /* Get the number of cells in a SafeArray */
658 static ULONG SAFEARRAY_GetCellCount(const SAFEARRAY *psa)
660 const SAFEARRAYBOUND* psab = psa->rgsabound;
661 USHORT cCount = psa->cDims;
662 ULONG ulNumCells = 1;
664 while (cCount--)
666 /* This is a valid bordercase. See testcases. -Marcus */
667 if (!psab->cElements)
668 return 0;
669 ulNumCells *= psab->cElements;
670 psab++;
672 return ulNumCells;
675 static inline SF_TYPE SAFEARRAY_GetUnionType(SAFEARRAY *psa)
677 VARTYPE vt;
678 HRESULT hr;
680 hr = SafeArrayGetVartype(psa, &vt);
681 if (FAILED(hr))
683 if(psa->fFeatures & FADF_VARIANT) return SF_VARIANT;
685 switch(psa->cbElements)
687 case 1: vt = VT_I1; break;
688 case 2: vt = VT_I2; break;
689 case 4: vt = VT_I4; break;
690 case 8: vt = VT_I8; break;
691 default:
692 RpcRaiseException(hr);
696 if (psa->fFeatures & FADF_HAVEIID)
697 return SF_HAVEIID;
699 switch (vt)
701 case VT_I1:
702 case VT_UI1: return SF_I1;
703 case VT_BOOL:
704 case VT_I2:
705 case VT_UI2: return SF_I2;
706 case VT_INT:
707 case VT_UINT:
708 case VT_I4:
709 case VT_UI4:
710 case VT_R4: return SF_I4;
711 case VT_DATE:
712 case VT_CY:
713 case VT_R8:
714 case VT_I8:
715 case VT_UI8: return SF_I8;
716 case VT_INT_PTR:
717 case VT_UINT_PTR: return (sizeof(UINT_PTR) == 4 ? SF_I4 : SF_I8);
718 case VT_BSTR: return SF_BSTR;
719 case VT_DISPATCH: return SF_DISPATCH;
720 case VT_VARIANT: return SF_VARIANT;
721 case VT_UNKNOWN: return SF_UNKNOWN;
722 /* Note: Return a non-zero size to indicate vt is valid. The actual size
723 * of a UDT is taken from the result of IRecordInfo_GetSize().
725 case VT_RECORD: return SF_RECORD;
726 default: return SF_ERROR;
730 static DWORD elem_wire_size(LPSAFEARRAY lpsa, SF_TYPE sftype)
732 if (sftype == SF_BSTR)
733 return sizeof(DWORD);
734 else if (sftype == SF_VARIANT)
735 return sizeof(variant_wire_t) - sizeof(DWORD);
736 else
737 return lpsa->cbElements;
740 static DWORD elem_mem_size(wireSAFEARRAY wiresa, SF_TYPE sftype)
742 if (sftype == SF_BSTR)
743 return sizeof(BSTR);
744 else if (sftype == SF_VARIANT)
745 return sizeof(VARIANT);
746 else
747 return wiresa->cbElements;
750 ULONG WINAPI LPSAFEARRAY_UserSize(ULONG *pFlags, ULONG StartingSize, LPSAFEARRAY *ppsa)
752 ULONG size = StartingSize;
754 TRACE("("); dump_user_flags(pFlags); TRACE(", %d, %p\n", StartingSize, *ppsa);
756 ALIGN_LENGTH(size, 3);
757 size += sizeof(ULONG);
758 if (*ppsa)
760 SAFEARRAY *psa = *ppsa;
761 ULONG ulCellCount = SAFEARRAY_GetCellCount(psa);
762 SF_TYPE sftype;
763 HRESULT hr;
765 size += sizeof(ULONG);
766 size += 2 * sizeof(USHORT) + 2 * sizeof(ULONG);
768 sftype = SAFEARRAY_GetUnionType(psa);
769 size += sizeof(ULONG);
771 size += sizeof(ULONG);
772 size += sizeof(ULONG);
773 if (sftype == SF_HAVEIID)
774 size += sizeof(IID);
776 size += sizeof(psa->rgsabound[0]) * psa->cDims;
778 size += sizeof(ULONG);
780 switch (sftype)
782 case SF_BSTR:
784 BSTR* lpBstr;
786 for (lpBstr = psa->pvData; ulCellCount; ulCellCount--, lpBstr++)
787 size = BSTR_UserSize(pFlags, size, lpBstr);
789 break;
791 case SF_DISPATCH:
792 case SF_UNKNOWN:
793 case SF_HAVEIID:
794 FIXME("size interfaces\n");
795 break;
796 case SF_VARIANT:
798 VARIANT* lpVariant;
800 for (lpVariant = psa->pvData; ulCellCount; ulCellCount--, lpVariant++)
801 size = VARIANT_UserSize(pFlags, size, lpVariant);
803 break;
805 case SF_RECORD:
807 IRecordInfo* pRecInfo = NULL;
809 hr = SafeArrayGetRecordInfo(psa, &pRecInfo);
810 if (FAILED(hr))
811 RpcRaiseException(hr);
813 if (pRecInfo)
815 FIXME("size record info %p\n", pRecInfo);
817 IRecordInfo_Release(pRecInfo);
819 break;
821 case SF_I8:
822 ALIGN_LENGTH(size, 7);
823 /* fallthrough */
824 case SF_I1:
825 case SF_I2:
826 case SF_I4:
827 size += ulCellCount * psa->cbElements;
828 break;
829 default:
830 break;
835 return size;
838 unsigned char * WINAPI LPSAFEARRAY_UserMarshal(ULONG *pFlags, unsigned char *Buffer, LPSAFEARRAY *ppsa)
840 HRESULT hr;
842 TRACE("("); dump_user_flags(pFlags); TRACE(", %p, &%p\n", Buffer, *ppsa);
844 ALIGN_POINTER(Buffer, 3);
845 *(ULONG *)Buffer = *ppsa ? 0x1 : 0x0;
846 Buffer += sizeof(ULONG);
847 if (*ppsa)
849 VARTYPE vt;
850 SAFEARRAY *psa = *ppsa;
851 ULONG ulCellCount = SAFEARRAY_GetCellCount(psa);
852 SAFEARRAYBOUND *bound;
853 SF_TYPE sftype;
854 GUID guid;
855 INT i;
857 sftype = SAFEARRAY_GetUnionType(psa);
859 *(ULONG *)Buffer = psa->cDims;
860 Buffer += sizeof(ULONG);
861 *(USHORT *)Buffer = psa->cDims;
862 Buffer += sizeof(USHORT);
863 *(USHORT *)Buffer = psa->fFeatures;
864 Buffer += sizeof(USHORT);
865 *(ULONG *)Buffer = elem_wire_size(psa, sftype);
866 Buffer += sizeof(ULONG);
868 hr = SafeArrayGetVartype(psa, &vt);
869 if (FAILED(hr)) vt = 0;
871 *(ULONG *)Buffer = (USHORT)psa->cLocks | (vt << 16);
872 Buffer += sizeof(ULONG);
874 *(ULONG *)Buffer = sftype;
875 Buffer += sizeof(ULONG);
877 *(ULONG *)Buffer = ulCellCount;
878 Buffer += sizeof(ULONG);
879 *(ULONG *)Buffer = psa->pvData ? 0x2 : 0x0;
880 Buffer += sizeof(ULONG);
881 if (sftype == SF_HAVEIID)
883 SafeArrayGetIID(psa, &guid);
884 memcpy(Buffer, &guid, sizeof(guid));
885 Buffer += sizeof(guid);
888 /* bounds are marshaled in opposite order comparing to storage layout */
889 bound = (SAFEARRAYBOUND*)Buffer;
890 for (i = 0; i < psa->cDims; i++)
892 memcpy(bound++, &psa->rgsabound[psa->cDims-i-1], sizeof(psa->rgsabound[0]));
894 Buffer += sizeof(psa->rgsabound[0]) * psa->cDims;
896 *(ULONG *)Buffer = ulCellCount;
897 Buffer += sizeof(ULONG);
899 if (psa->pvData)
901 switch (sftype)
903 case SF_BSTR:
905 BSTR* lpBstr;
907 for (lpBstr = psa->pvData; ulCellCount; ulCellCount--, lpBstr++)
908 Buffer = BSTR_UserMarshal(pFlags, Buffer, lpBstr);
910 break;
912 case SF_DISPATCH:
913 case SF_UNKNOWN:
914 case SF_HAVEIID:
915 FIXME("marshal interfaces\n");
916 break;
917 case SF_VARIANT:
919 VARIANT* lpVariant;
921 for (lpVariant = psa->pvData; ulCellCount; ulCellCount--, lpVariant++)
922 Buffer = VARIANT_UserMarshal(pFlags, Buffer, lpVariant);
924 break;
926 case SF_RECORD:
928 IRecordInfo* pRecInfo = NULL;
930 hr = SafeArrayGetRecordInfo(psa, &pRecInfo);
931 if (FAILED(hr))
932 RpcRaiseException(hr);
934 if (pRecInfo)
936 FIXME("write record info %p\n", pRecInfo);
938 IRecordInfo_Release(pRecInfo);
940 break;
943 case SF_I8:
944 ALIGN_POINTER(Buffer, 7);
945 /* fallthrough */
946 case SF_I1:
947 case SF_I2:
948 case SF_I4:
949 /* Just copy the data over */
950 memcpy(Buffer, psa->pvData, ulCellCount * psa->cbElements);
951 Buffer += ulCellCount * psa->cbElements;
952 break;
953 default:
954 break;
959 return Buffer;
962 #define FADF_AUTOSETFLAGS (FADF_HAVEIID | FADF_RECORD | FADF_HAVEVARTYPE | \
963 FADF_BSTR | FADF_UNKNOWN | FADF_DISPATCH | \
964 FADF_VARIANT | FADF_CREATEVECTOR)
966 unsigned char * WINAPI LPSAFEARRAY_UserUnmarshal(ULONG *pFlags, unsigned char *Buffer, LPSAFEARRAY *ppsa)
968 ULONG ptr;
969 wireSAFEARRAY wiresa;
970 ULONG cDims;
971 HRESULT hr;
972 SF_TYPE sftype;
973 ULONG cell_count;
974 GUID guid;
975 VARTYPE vt;
976 SAFEARRAYBOUND *wiresab;
978 TRACE("("); dump_user_flags(pFlags); TRACE(", %p, %p\n", Buffer, ppsa);
980 ALIGN_POINTER(Buffer, 3);
981 ptr = *(ULONG *)Buffer;
982 Buffer += sizeof(ULONG);
984 if (!ptr)
986 SafeArrayDestroy(*ppsa);
987 *ppsa = NULL;
989 TRACE("NULL safe array unmarshaled\n");
991 return Buffer;
994 cDims = *(ULONG *)Buffer;
995 Buffer += sizeof(ULONG);
997 wiresa = (wireSAFEARRAY)Buffer;
998 Buffer += 2 * sizeof(USHORT) + 2 * sizeof(ULONG);
1000 if (cDims != wiresa->cDims)
1001 RpcRaiseException(RPC_S_INVALID_BOUND);
1003 /* FIXME: there should be a limit on how large cDims can be */
1005 vt = HIWORD(wiresa->cLocks);
1007 sftype = *(ULONG *)Buffer;
1008 Buffer += sizeof(ULONG);
1010 cell_count = *(ULONG *)Buffer;
1011 Buffer += sizeof(ULONG);
1012 ptr = *(ULONG *)Buffer;
1013 Buffer += sizeof(ULONG);
1014 if (sftype == SF_HAVEIID)
1016 memcpy(&guid, Buffer, sizeof(guid));
1017 Buffer += sizeof(guid);
1020 wiresab = (SAFEARRAYBOUND *)Buffer;
1021 Buffer += sizeof(wiresab[0]) * wiresa->cDims;
1023 if(*ppsa && (*ppsa)->cDims==wiresa->cDims)
1025 if(((*ppsa)->fFeatures & ~FADF_AUTOSETFLAGS) != (wiresa->fFeatures & ~FADF_AUTOSETFLAGS))
1026 RpcRaiseException(DISP_E_BADCALLEE);
1028 if(SAFEARRAY_GetCellCount(*ppsa)*(*ppsa)->cbElements != cell_count*elem_mem_size(wiresa, sftype))
1030 if((*ppsa)->fFeatures & (FADF_AUTO|FADF_STATIC|FADF_EMBEDDED|FADF_FIXEDSIZE))
1031 RpcRaiseException(DISP_E_BADCALLEE);
1033 hr = SafeArrayDestroyData(*ppsa);
1034 if(FAILED(hr))
1035 RpcRaiseException(hr);
1037 memcpy((*ppsa)->rgsabound, wiresab, sizeof(*wiresab)*wiresa->cDims);
1039 if((*ppsa)->fFeatures & FADF_HAVEVARTYPE)
1040 ((DWORD*)(*ppsa))[-1] = vt;
1042 else if(vt)
1044 SafeArrayDestroy(*ppsa);
1045 *ppsa = SafeArrayCreateEx(vt, wiresa->cDims, wiresab, NULL);
1046 if (!*ppsa) RpcRaiseException(E_OUTOFMEMORY);
1048 else
1050 SafeArrayDestroy(*ppsa);
1051 if (FAILED(SafeArrayAllocDescriptor(wiresa->cDims, ppsa)))
1052 RpcRaiseException(E_OUTOFMEMORY);
1053 memcpy((*ppsa)->rgsabound, wiresab, sizeof(SAFEARRAYBOUND) * wiresa->cDims);
1056 /* be careful about which flags we set since they could be a security
1057 * risk */
1058 (*ppsa)->fFeatures &= FADF_AUTOSETFLAGS;
1059 (*ppsa)->fFeatures |= (wiresa->fFeatures & ~(FADF_AUTOSETFLAGS));
1060 /* FIXME: there should be a limit on how large wiresa->cbElements can be */
1061 (*ppsa)->cbElements = elem_mem_size(wiresa, sftype);
1063 /* SafeArrayCreateEx allocates the data for us, but
1064 * SafeArrayAllocDescriptor doesn't */
1065 if(!(*ppsa)->pvData)
1067 hr = SafeArrayAllocData(*ppsa);
1068 if (FAILED(hr))
1069 RpcRaiseException(hr);
1072 if ((*(ULONG *)Buffer != cell_count) || (SAFEARRAY_GetCellCount(*ppsa) != cell_count))
1073 RpcRaiseException(RPC_S_INVALID_BOUND);
1074 Buffer += sizeof(ULONG);
1076 if (ptr)
1078 switch (sftype)
1080 case SF_BSTR:
1082 BSTR* lpBstr;
1084 for (lpBstr = (*ppsa)->pvData; cell_count; cell_count--, lpBstr++)
1085 Buffer = BSTR_UserUnmarshal(pFlags, Buffer, lpBstr);
1087 break;
1089 case SF_DISPATCH:
1090 case SF_UNKNOWN:
1091 case SF_HAVEIID:
1092 FIXME("marshal interfaces\n");
1093 break;
1094 case SF_VARIANT:
1096 VARIANT* lpVariant;
1098 for (lpVariant = (*ppsa)->pvData; cell_count; cell_count--, lpVariant++)
1099 Buffer = VARIANT_UserUnmarshal(pFlags, Buffer, lpVariant);
1101 break;
1103 case SF_RECORD:
1105 FIXME("set record info\n");
1107 break;
1110 case SF_I8:
1111 ALIGN_POINTER(Buffer, 7);
1112 /* fallthrough */
1113 case SF_I1:
1114 case SF_I2:
1115 case SF_I4:
1116 /* Just copy the data over */
1117 memcpy((*ppsa)->pvData, Buffer, cell_count * (*ppsa)->cbElements);
1118 Buffer += cell_count * (*ppsa)->cbElements;
1119 break;
1120 default:
1121 break;
1125 TRACE("safe array unmarshaled: %p\n", *ppsa);
1127 return Buffer;
1130 void WINAPI LPSAFEARRAY_UserFree(ULONG *pFlags, LPSAFEARRAY *ppsa)
1132 TRACE("("); dump_user_flags(pFlags); TRACE(", &%p\n", *ppsa);
1134 SafeArrayDestroy(*ppsa);
1135 *ppsa = NULL;
1139 ULONG WINAPI HFONT_UserSize(ULONG *pFlags, ULONG Start, HFONT *phfont)
1141 FIXME(":stub\n");
1142 return 0;
1145 unsigned char * WINAPI HFONT_UserMarshal(ULONG *pFlags, unsigned char *Buffer, HFONT *phfont)
1147 FIXME(":stub\n");
1148 return NULL;
1151 unsigned char * WINAPI HFONT_UserUnmarshal(ULONG *pFlags, unsigned char *Buffer, HFONT *phfont)
1153 FIXME(":stub\n");
1154 return NULL;
1157 void WINAPI HFONT_UserFree(ULONG *pFlags, HFONT *phfont)
1159 FIXME(":stub\n");
1160 return;
1164 /* IDispatch */
1165 /* exactly how Invoke is marshalled is not very clear to me yet,
1166 * but the way I've done it seems to work for me */
1168 HRESULT CALLBACK IDispatch_Invoke_Proxy(
1169 IDispatch* This,
1170 DISPID dispIdMember,
1171 REFIID riid,
1172 LCID lcid,
1173 WORD wFlags,
1174 DISPPARAMS* pDispParams,
1175 VARIANT* pVarResult,
1176 EXCEPINFO* pExcepInfo,
1177 UINT* puArgErr)
1179 HRESULT hr;
1180 VARIANT VarResult;
1181 UINT* rgVarRefIdx = NULL;
1182 VARIANTARG* rgVarRef = NULL;
1183 UINT u, cVarRef;
1184 UINT uArgErr;
1185 EXCEPINFO ExcepInfo;
1187 TRACE("(%p)->(%d,%s,%x,%x,%p,%p,%p,%p)\n", This,
1188 dispIdMember, debugstr_guid(riid),
1189 lcid, wFlags, pDispParams, pVarResult,
1190 pExcepInfo, puArgErr);
1192 /* [out] args can't be null, use dummy vars if needed */
1193 if (!pVarResult) pVarResult = &VarResult;
1194 if (!puArgErr) puArgErr = &uArgErr;
1195 if (!pExcepInfo) pExcepInfo = &ExcepInfo;
1197 /* count by-ref args */
1198 for (cVarRef=0,u=0; u<pDispParams->cArgs; u++) {
1199 VARIANTARG* arg = &pDispParams->rgvarg[u];
1200 if (V_ISBYREF(arg)) {
1201 cVarRef++;
1204 if (cVarRef) {
1205 rgVarRefIdx = CoTaskMemAlloc(sizeof(UINT)*cVarRef);
1206 rgVarRef = CoTaskMemAlloc(sizeof(VARIANTARG)*cVarRef);
1207 /* make list of by-ref args */
1208 for (cVarRef=0,u=0; u<pDispParams->cArgs; u++) {
1209 VARIANTARG* arg = &pDispParams->rgvarg[u];
1210 if (V_ISBYREF(arg)) {
1211 rgVarRefIdx[cVarRef] = u;
1212 VariantInit(&rgVarRef[cVarRef]);
1213 VariantCopy(&rgVarRef[cVarRef], arg);
1214 VariantClear(arg);
1215 cVarRef++;
1218 } else {
1219 /* [out] args still can't be null,
1220 * but we can point these anywhere in this case,
1221 * since they won't be written to when cVarRef is 0 */
1222 rgVarRefIdx = puArgErr;
1223 rgVarRef = pVarResult;
1225 TRACE("passed by ref: %d args\n", cVarRef);
1226 hr = IDispatch_RemoteInvoke_Proxy(This,
1227 dispIdMember,
1228 riid,
1229 lcid,
1230 wFlags,
1231 pDispParams,
1232 pVarResult,
1233 pExcepInfo,
1234 puArgErr,
1235 cVarRef,
1236 rgVarRefIdx,
1237 rgVarRef);
1238 if (cVarRef) {
1239 for (u=0; u<cVarRef; u++) {
1240 unsigned i = rgVarRefIdx[u];
1241 VariantCopy(&pDispParams->rgvarg[i],
1242 &rgVarRef[u]);
1243 VariantClear(&rgVarRef[u]);
1245 CoTaskMemFree(rgVarRef);
1246 CoTaskMemFree(rgVarRefIdx);
1249 if(pExcepInfo == &ExcepInfo)
1251 SysFreeString(pExcepInfo->bstrSource);
1252 SysFreeString(pExcepInfo->bstrDescription);
1253 SysFreeString(pExcepInfo->bstrHelpFile);
1255 return hr;
1258 HRESULT __RPC_STUB IDispatch_Invoke_Stub(
1259 IDispatch* This,
1260 DISPID dispIdMember,
1261 REFIID riid,
1262 LCID lcid,
1263 DWORD dwFlags,
1264 DISPPARAMS* pDispParams,
1265 VARIANT* pVarResult,
1266 EXCEPINFO* pExcepInfo,
1267 UINT* pArgErr,
1268 UINT cVarRef,
1269 UINT* rgVarRefIdx,
1270 VARIANTARG* rgVarRef)
1272 HRESULT hr = S_OK;
1273 VARIANTARG *rgvarg, *arg;
1274 UINT u;
1276 /* initialize out parameters, so that they can be marshalled
1277 * in case the real Invoke doesn't initialize them */
1278 VariantInit(pVarResult);
1279 memset(pExcepInfo, 0, sizeof(*pExcepInfo));
1280 *pArgErr = 0;
1282 /* let the real Invoke operate on a copy of the in parameters,
1283 * so we don't risk losing pointers to allocated memory */
1284 rgvarg = pDispParams->rgvarg;
1285 arg = CoTaskMemAlloc(sizeof(VARIANTARG)*pDispParams->cArgs);
1286 if (!arg) return E_OUTOFMEMORY;
1288 /* init all args so we can call VariantClear on all the args if the copy
1289 * below fails */
1290 for (u = 0; u < pDispParams->cArgs; u++)
1291 VariantInit(&arg[u]);
1293 for (u = 0; u < pDispParams->cArgs; u++) {
1294 hr = VariantCopy(&arg[u], &rgvarg[u]);
1295 if (FAILED(hr))
1296 break;
1299 if (SUCCEEDED(hr)) {
1300 /* copy ref args to arg array */
1301 for (u=0; u<cVarRef; u++) {
1302 unsigned i = rgVarRefIdx[u];
1303 VariantCopy(&arg[i], &rgVarRef[u]);
1306 pDispParams->rgvarg = arg;
1308 hr = IDispatch_Invoke(This,
1309 dispIdMember,
1310 riid,
1311 lcid,
1312 dwFlags,
1313 pDispParams,
1314 pVarResult,
1315 pExcepInfo,
1316 pArgErr);
1318 /* copy ref args from arg array */
1319 for (u=0; u<cVarRef; u++) {
1320 unsigned i = rgVarRefIdx[u];
1321 VariantCopy(&rgVarRef[u], &arg[i]);
1325 /* clear the duplicate argument list */
1326 for (u=0; u<pDispParams->cArgs; u++)
1327 VariantClear(&arg[u]);
1329 pDispParams->rgvarg = rgvarg;
1330 CoTaskMemFree(arg);
1332 return hr;
1335 /* IEnumVARIANT */
1337 HRESULT CALLBACK IEnumVARIANT_Next_Proxy(
1338 IEnumVARIANT* This,
1339 ULONG celt,
1340 VARIANT* rgVar,
1341 ULONG* pCeltFetched)
1343 ULONG fetched;
1344 if (!pCeltFetched)
1345 pCeltFetched = &fetched;
1346 return IEnumVARIANT_RemoteNext_Proxy(This,
1347 celt,
1348 rgVar,
1349 pCeltFetched);
1352 HRESULT __RPC_STUB IEnumVARIANT_Next_Stub(
1353 IEnumVARIANT* This,
1354 ULONG celt,
1355 VARIANT* rgVar,
1356 ULONG* pCeltFetched)
1358 HRESULT hr;
1359 *pCeltFetched = 0;
1360 hr = IEnumVARIANT_Next(This,
1361 celt,
1362 rgVar,
1363 pCeltFetched);
1364 if (hr == S_OK) *pCeltFetched = celt;
1365 return hr;
1368 /* TypeInfo related freers */
1370 static void free_embedded_typedesc(TYPEDESC *tdesc);
1371 static void free_embedded_arraydesc(ARRAYDESC *adesc)
1373 switch(adesc->tdescElem.vt)
1375 case VT_PTR:
1376 case VT_SAFEARRAY:
1377 free_embedded_typedesc(adesc->tdescElem.u.lptdesc);
1378 CoTaskMemFree(adesc->tdescElem.u.lptdesc);
1379 break;
1380 case VT_CARRAY:
1381 free_embedded_arraydesc(adesc->tdescElem.u.lpadesc);
1382 CoTaskMemFree(adesc->tdescElem.u.lpadesc);
1383 break;
1387 static void free_embedded_typedesc(TYPEDESC *tdesc)
1389 switch(tdesc->vt)
1391 case VT_PTR:
1392 case VT_SAFEARRAY:
1393 free_embedded_typedesc(tdesc->u.lptdesc);
1394 CoTaskMemFree(tdesc->u.lptdesc);
1395 break;
1396 case VT_CARRAY:
1397 free_embedded_arraydesc(tdesc->u.lpadesc);
1398 CoTaskMemFree(tdesc->u.lpadesc);
1399 break;
1403 static void free_embedded_elemdesc(ELEMDESC *edesc)
1405 free_embedded_typedesc(&edesc->tdesc);
1406 if(edesc->u.paramdesc.wParamFlags & PARAMFLAG_FHASDEFAULT)
1407 CoTaskMemFree(edesc->u.paramdesc.pparamdescex);
1410 /* ITypeComp */
1412 HRESULT CALLBACK ITypeComp_Bind_Proxy(
1413 ITypeComp* This,
1414 LPOLESTR name,
1415 ULONG lHashVal,
1416 WORD flags,
1417 ITypeInfo **ti,
1418 DESCKIND *desckind,
1419 BINDPTR *bindptr)
1421 CLEANLOCALSTORAGE stg = { 0 };
1422 ITypeComp *typecomp;
1423 FUNCDESC *funcdesc;
1424 VARDESC *vardesc;
1425 HRESULT hr;
1427 TRACE("(%p, %s, %#x, %#x, %p, %p, %p)\n", This, debugstr_w(name), lHashVal, flags, ti,
1428 desckind, bindptr);
1430 *desckind = DESCKIND_NONE;
1431 memset(bindptr, 0, sizeof(*bindptr));
1433 hr = ITypeComp_RemoteBind_Proxy(This, name, lHashVal, flags, ti, desckind,
1434 &funcdesc, &vardesc, &typecomp, &stg);
1436 if (hr == S_OK)
1438 switch (*desckind)
1440 case DESCKIND_FUNCDESC:
1441 bindptr->lpfuncdesc = funcdesc;
1442 break;
1443 case DESCKIND_VARDESC:
1444 case DESCKIND_IMPLICITAPPOBJ:
1445 bindptr->lpvardesc = vardesc;
1446 break;
1447 case DESCKIND_TYPECOMP:
1448 bindptr->lptcomp = typecomp;
1449 break;
1450 default:
1455 return hr;
1458 HRESULT __RPC_STUB ITypeComp_Bind_Stub(
1459 ITypeComp* This,
1460 LPOLESTR name,
1461 ULONG lHashVal,
1462 WORD flags,
1463 ITypeInfo **ti,
1464 DESCKIND *desckind,
1465 FUNCDESC **funcdesc,
1466 VARDESC **vardesc,
1467 ITypeComp **typecomp,
1468 CLEANLOCALSTORAGE *stg)
1470 BINDPTR bindptr;
1471 HRESULT hr;
1473 TRACE("(%p, %s, %#x, %#x, %p, %p, %p, %p, %p, %p)\n", This, debugstr_w(name),
1474 lHashVal, flags, ti, desckind, funcdesc, vardesc, typecomp, stg);
1476 memset(stg, 0, sizeof(*stg));
1477 memset(&bindptr, 0, sizeof(bindptr));
1479 *funcdesc = NULL;
1480 *vardesc = NULL;
1481 *typecomp = NULL;
1482 *ti = NULL;
1484 hr = ITypeComp_Bind(This, name, lHashVal, flags, ti, desckind, &bindptr);
1485 if(hr != S_OK)
1486 return hr;
1488 switch (*desckind)
1490 case DESCKIND_FUNCDESC:
1491 *funcdesc = bindptr.lpfuncdesc;
1492 stg->pInterface = (IUnknown*)*ti;
1493 stg->pStorage = funcdesc;
1494 stg->flags = CLS_FUNCDESC;
1495 break;
1496 case DESCKIND_VARDESC:
1497 case DESCKIND_IMPLICITAPPOBJ:
1498 *vardesc = bindptr.lpvardesc;
1499 stg->pInterface = (IUnknown*)*ti;
1500 stg->pStorage = vardesc;
1501 stg->flags = CLS_VARDESC;
1502 break;
1503 case DESCKIND_TYPECOMP:
1504 *typecomp = bindptr.lptcomp;
1505 break;
1506 default:
1510 if (stg->pInterface)
1511 IUnknown_AddRef(stg->pInterface);
1513 return hr;
1516 HRESULT CALLBACK ITypeComp_BindType_Proxy(
1517 ITypeComp* This,
1518 LPOLESTR name,
1519 ULONG lHashVal,
1520 ITypeInfo **ti,
1521 ITypeComp **typecomp)
1523 HRESULT hr;
1525 TRACE("(%p, %s, %#x, %p, %p)\n", This, debugstr_w(name), lHashVal, ti, typecomp);
1527 hr = ITypeComp_RemoteBindType_Proxy(This, name, lHashVal, ti);
1528 if (hr == S_OK)
1529 ITypeInfo_GetTypeComp(*ti, typecomp);
1530 else if (typecomp)
1531 *typecomp = NULL;
1533 return hr;
1536 HRESULT __RPC_STUB ITypeComp_BindType_Stub(
1537 ITypeComp* This,
1538 LPOLESTR name,
1539 ULONG lHashVal,
1540 ITypeInfo **ti)
1542 ITypeComp *typecomp = NULL;
1543 HRESULT hr;
1545 TRACE("(%p, %s, %#x, %p)\n", This, debugstr_w(name), lHashVal, ti);
1547 hr = ITypeComp_BindType(This, name, lHashVal, ti, &typecomp);
1549 if (typecomp)
1550 ITypeComp_Release(typecomp);
1552 return hr;
1555 /* ITypeInfo */
1557 HRESULT CALLBACK ITypeInfo_GetTypeAttr_Proxy(
1558 ITypeInfo* This,
1559 TYPEATTR** ppTypeAttr)
1562 CLEANLOCALSTORAGE stg;
1563 TRACE("(%p, %p)\n", This, ppTypeAttr);
1565 stg.flags = 0;
1566 stg.pStorage = NULL;
1567 stg.pInterface = NULL;
1569 return ITypeInfo_RemoteGetTypeAttr_Proxy(This, ppTypeAttr, &stg);
1572 HRESULT __RPC_STUB ITypeInfo_GetTypeAttr_Stub(
1573 ITypeInfo* This,
1574 LPTYPEATTR* ppTypeAttr,
1575 CLEANLOCALSTORAGE* pDummy)
1577 HRESULT hr;
1578 TRACE("(%p, %p)\n", This, ppTypeAttr);
1580 hr = ITypeInfo_GetTypeAttr(This, ppTypeAttr);
1581 if(hr != S_OK)
1582 return hr;
1584 pDummy->flags = CLS_TYPEATTR;
1585 ITypeInfo_AddRef(This);
1586 pDummy->pInterface = (IUnknown*)This;
1587 pDummy->pStorage = ppTypeAttr;
1588 return hr;
1591 HRESULT CALLBACK ITypeInfo_GetFuncDesc_Proxy(
1592 ITypeInfo* This,
1593 UINT index,
1594 FUNCDESC** ppFuncDesc)
1596 CLEANLOCALSTORAGE stg;
1597 TRACE("(%p, %d, %p)\n", This, index, ppFuncDesc);
1599 stg.flags = 0;
1600 stg.pStorage = NULL;
1601 stg.pInterface = NULL;
1603 return ITypeInfo_RemoteGetFuncDesc_Proxy(This, index, ppFuncDesc, &stg);
1606 HRESULT __RPC_STUB ITypeInfo_GetFuncDesc_Stub(
1607 ITypeInfo* This,
1608 UINT index,
1609 LPFUNCDESC* ppFuncDesc,
1610 CLEANLOCALSTORAGE* pDummy)
1612 HRESULT hr;
1613 TRACE("(%p, %d, %p)\n", This, index, ppFuncDesc);
1615 hr = ITypeInfo_GetFuncDesc(This, index, ppFuncDesc);
1616 if(hr != S_OK)
1617 return hr;
1619 pDummy->flags = CLS_FUNCDESC;
1620 ITypeInfo_AddRef(This);
1621 pDummy->pInterface = (IUnknown*)This;
1622 pDummy->pStorage = ppFuncDesc;
1623 return hr;
1626 HRESULT CALLBACK ITypeInfo_GetVarDesc_Proxy(
1627 ITypeInfo* This,
1628 UINT index,
1629 VARDESC** ppVarDesc)
1631 CLEANLOCALSTORAGE stg;
1632 TRACE("(%p, %d, %p)\n", This, index, ppVarDesc);
1634 stg.flags = 0;
1635 stg.pStorage = NULL;
1636 stg.pInterface = NULL;
1638 return ITypeInfo_RemoteGetVarDesc_Proxy(This, index, ppVarDesc, &stg);
1641 HRESULT __RPC_STUB ITypeInfo_GetVarDesc_Stub(
1642 ITypeInfo* This,
1643 UINT index,
1644 LPVARDESC* ppVarDesc,
1645 CLEANLOCALSTORAGE* pDummy)
1647 HRESULT hr;
1648 TRACE("(%p, %d, %p)\n", This, index, ppVarDesc);
1650 hr = ITypeInfo_GetVarDesc(This, index, ppVarDesc);
1651 if(hr != S_OK)
1652 return hr;
1654 pDummy->flags = CLS_VARDESC;
1655 ITypeInfo_AddRef(This);
1656 pDummy->pInterface = (IUnknown*)This;
1657 pDummy->pStorage = ppVarDesc;
1658 return hr;
1661 HRESULT CALLBACK ITypeInfo_GetNames_Proxy(
1662 ITypeInfo* This,
1663 MEMBERID memid,
1664 BSTR* rgBstrNames,
1665 UINT cMaxNames,
1666 UINT* pcNames)
1668 TRACE("(%p, %08x, %p, %d, %p)\n", This, memid, rgBstrNames, cMaxNames, pcNames);
1670 return ITypeInfo_RemoteGetNames_Proxy(This, memid, rgBstrNames, cMaxNames, pcNames);
1673 HRESULT __RPC_STUB ITypeInfo_GetNames_Stub(
1674 ITypeInfo* This,
1675 MEMBERID memid,
1676 BSTR* rgBstrNames,
1677 UINT cMaxNames,
1678 UINT* pcNames)
1680 TRACE("(%p, %08x, %p, %d, %p)\n", This, memid, rgBstrNames, cMaxNames, pcNames);
1682 return ITypeInfo_GetNames(This, memid, rgBstrNames, cMaxNames, pcNames);
1685 HRESULT CALLBACK ITypeInfo_GetIDsOfNames_Proxy(
1686 ITypeInfo* This,
1687 LPOLESTR* rgszNames,
1688 UINT cNames,
1689 MEMBERID* pMemId)
1691 FIXME("not implemented\n");
1692 return E_FAIL;
1695 HRESULT __RPC_STUB ITypeInfo_GetIDsOfNames_Stub(
1696 ITypeInfo* This)
1698 FIXME("not implemented\n");
1699 return E_FAIL;
1702 HRESULT CALLBACK ITypeInfo_Invoke_Proxy(
1703 ITypeInfo* This,
1704 PVOID pvInstance,
1705 MEMBERID memid,
1706 WORD wFlags,
1707 DISPPARAMS* pDispParams,
1708 VARIANT* pVarResult,
1709 EXCEPINFO* pExcepInfo,
1710 UINT* puArgErr)
1712 FIXME("not implemented\n");
1713 return E_FAIL;
1716 HRESULT __RPC_STUB ITypeInfo_Invoke_Stub(
1717 ITypeInfo* This)
1719 FIXME("not implemented\n");
1720 return E_FAIL;
1723 HRESULT CALLBACK ITypeInfo_GetDocumentation_Proxy(ITypeInfo *This, MEMBERID memid,
1724 BSTR *name, BSTR *doc_string,
1725 DWORD *help_context, BSTR *help_file)
1727 DWORD dummy_help_context, flags = 0;
1728 BSTR dummy_name, dummy_doc_string, dummy_help_file;
1729 HRESULT hr;
1730 TRACE("(%p, %08x, %p, %p, %p, %p)\n", This, memid, name, doc_string, help_context, help_file);
1732 if(!name) name = &dummy_name;
1733 else flags = 1;
1735 if(!doc_string) doc_string = &dummy_doc_string;
1736 else flags |= 2;
1738 if(!help_context) help_context = &dummy_help_context;
1739 else flags |= 4;
1741 if(!help_file) help_file = &dummy_help_file;
1742 else flags |= 8;
1744 hr = ITypeInfo_RemoteGetDocumentation_Proxy(This, memid, flags, name, doc_string, help_context, help_file);
1746 /* We don't need to free the dummy BSTRs since the stub ensures that these will be NULLs. */
1748 return hr;
1751 HRESULT __RPC_STUB ITypeInfo_GetDocumentation_Stub(ITypeInfo *This, MEMBERID memid,
1752 DWORD flags, BSTR *name, BSTR *doc_string,
1753 DWORD *help_context, BSTR *help_file)
1755 TRACE("(%p, %08x, %08x, %p, %p, %p, %p)\n", This, memid, flags, name, doc_string, help_context, help_file);
1757 *name = *doc_string = *help_file = NULL;
1758 *help_context = 0;
1760 if(!(flags & 1)) name = NULL;
1761 if(!(flags & 2)) doc_string = NULL;
1762 if(!(flags & 4)) help_context = NULL;
1763 if(!(flags & 8)) help_file = NULL;
1765 return ITypeInfo_GetDocumentation(This, memid, name, doc_string, help_context, help_file);
1768 HRESULT CALLBACK ITypeInfo_GetDllEntry_Proxy(ITypeInfo *This, MEMBERID memid,
1769 INVOKEKIND invkind, BSTR *dll_name,
1770 BSTR* name, WORD *ordinal)
1772 DWORD flags = 0;
1773 BSTR dummy_dll_name, dummy_name;
1774 WORD dummy_ordinal;
1775 HRESULT hr;
1776 TRACE("(%p, %08x, %x, %p, %p, %p)\n", This, memid, invkind, dll_name, name, ordinal);
1778 if(!dll_name) dll_name = &dummy_dll_name;
1779 else flags = 1;
1781 if(!name) name = &dummy_name;
1782 else flags |= 2;
1784 if(!ordinal) ordinal = &dummy_ordinal;
1785 else flags |= 4;
1787 hr = ITypeInfo_RemoteGetDllEntry_Proxy(This, memid, invkind, flags, dll_name, name, ordinal);
1789 /* We don't need to free the dummy BSTRs since the stub ensures that these will be NULLs. */
1791 return hr;
1794 HRESULT __RPC_STUB ITypeInfo_GetDllEntry_Stub(ITypeInfo *This, MEMBERID memid,
1795 INVOKEKIND invkind, DWORD flags,
1796 BSTR *dll_name, BSTR *name,
1797 WORD *ordinal)
1799 TRACE("(%p, %08x, %x, %p, %p, %p)\n", This, memid, invkind, dll_name, name, ordinal);
1801 *dll_name = *name = NULL;
1802 *ordinal = 0;
1804 if(!(flags & 1)) dll_name = NULL;
1805 if(!(flags & 2)) name = NULL;
1806 if(!(flags & 4)) ordinal = NULL;
1808 return ITypeInfo_GetDllEntry(This, memid, invkind, dll_name, name, ordinal);
1811 HRESULT CALLBACK ITypeInfo_AddressOfMember_Proxy(
1812 ITypeInfo* This,
1813 MEMBERID memid,
1814 INVOKEKIND invKind,
1815 PVOID* ppv)
1817 FIXME("not implemented\n");
1818 return E_FAIL;
1821 HRESULT __RPC_STUB ITypeInfo_AddressOfMember_Stub(
1822 ITypeInfo* This)
1824 FIXME("not implemented\n");
1825 return E_FAIL;
1828 HRESULT CALLBACK ITypeInfo_CreateInstance_Proxy(
1829 ITypeInfo* This,
1830 IUnknown* pUnkOuter,
1831 REFIID riid,
1832 PVOID* ppvObj)
1834 FIXME("not implemented\n");
1835 return E_FAIL;
1838 HRESULT __RPC_STUB ITypeInfo_CreateInstance_Stub(
1839 ITypeInfo* This,
1840 REFIID riid,
1841 IUnknown** ppvObj)
1843 FIXME("not implemented\n");
1844 return E_FAIL;
1847 HRESULT CALLBACK ITypeInfo_GetContainingTypeLib_Proxy(
1848 ITypeInfo* This,
1849 ITypeLib** ppTLib,
1850 UINT* pIndex)
1852 ITypeLib *pTL;
1853 UINT index;
1854 HRESULT hr;
1856 TRACE("(%p, %p, %p)\n", This, ppTLib, pIndex );
1858 hr = ITypeInfo_RemoteGetContainingTypeLib_Proxy(This, &pTL, &index);
1859 if(SUCCEEDED(hr))
1861 if(pIndex)
1862 *pIndex = index;
1864 if(ppTLib)
1865 *ppTLib = pTL;
1866 else
1867 ITypeLib_Release(pTL);
1869 return hr;
1872 HRESULT __RPC_STUB ITypeInfo_GetContainingTypeLib_Stub(
1873 ITypeInfo* This,
1874 ITypeLib** ppTLib,
1875 UINT* pIndex)
1877 TRACE("(%p, %p, %p)\n", This, ppTLib, pIndex );
1878 return ITypeInfo_GetContainingTypeLib(This, ppTLib, pIndex);
1881 void CALLBACK ITypeInfo_ReleaseTypeAttr_Proxy(
1882 ITypeInfo* This,
1883 TYPEATTR* pTypeAttr)
1885 TRACE("(%p, %p)\n", This, pTypeAttr);
1886 free_embedded_typedesc(&pTypeAttr->tdescAlias);
1887 CoTaskMemFree(pTypeAttr);
1890 HRESULT __RPC_STUB ITypeInfo_ReleaseTypeAttr_Stub(
1891 ITypeInfo* This)
1893 TRACE("nothing to do\n");
1894 return S_OK;
1897 void CALLBACK ITypeInfo_ReleaseFuncDesc_Proxy(
1898 ITypeInfo* This,
1899 FUNCDESC* pFuncDesc)
1901 SHORT param;
1902 TRACE("(%p, %p)\n", This, pFuncDesc);
1904 for(param = 0; param < pFuncDesc->cParams; param++)
1905 free_embedded_elemdesc(pFuncDesc->lprgelemdescParam + param);
1906 if(param)
1907 CoTaskMemFree(pFuncDesc->lprgelemdescParam);
1909 free_embedded_elemdesc(&pFuncDesc->elemdescFunc);
1911 if(pFuncDesc->cScodes != 0 && pFuncDesc->cScodes != -1)
1912 CoTaskMemFree(pFuncDesc->lprgscode);
1914 CoTaskMemFree(pFuncDesc);
1917 HRESULT __RPC_STUB ITypeInfo_ReleaseFuncDesc_Stub(
1918 ITypeInfo* This)
1920 TRACE("nothing to do\n");
1921 return S_OK;
1924 void CALLBACK ITypeInfo_ReleaseVarDesc_Proxy(
1925 ITypeInfo* This,
1926 VARDESC* pVarDesc)
1928 TRACE("(%p, %p)\n", This, pVarDesc);
1930 CoTaskMemFree(pVarDesc->lpstrSchema);
1932 if(pVarDesc->varkind == VAR_CONST)
1933 CoTaskMemFree(pVarDesc->u.lpvarValue);
1935 free_embedded_elemdesc(&pVarDesc->elemdescVar);
1936 CoTaskMemFree(pVarDesc);
1939 HRESULT __RPC_STUB ITypeInfo_ReleaseVarDesc_Stub(
1940 ITypeInfo* This)
1942 TRACE("nothing to do\n");
1943 return S_OK;
1947 /* ITypeInfo2 */
1949 HRESULT CALLBACK ITypeInfo2_GetDocumentation2_Proxy(ITypeInfo2 *This, MEMBERID memid,
1950 LCID lcid, BSTR *help_string,
1951 DWORD *help_context, BSTR *help_dll)
1953 DWORD dummy_help_context, flags = 0;
1954 BSTR dummy_help_string, dummy_help_dll;
1955 HRESULT hr;
1956 TRACE("(%p, %08x, %08x, %p, %p, %p)\n", This, memid, lcid, help_string, help_context, help_dll);
1958 if(!help_string) help_string = &dummy_help_string;
1959 else flags = 1;
1961 if(!help_context) help_context = &dummy_help_context;
1962 else flags |= 2;
1964 if(!help_dll) help_dll = &dummy_help_dll;
1965 else flags |= 4;
1967 hr = ITypeInfo2_RemoteGetDocumentation2_Proxy(This, memid, lcid, flags, help_string, help_context, help_dll);
1969 /* We don't need to free the dummy BSTRs since the stub ensures that these will be NULLs. */
1971 return hr;
1974 HRESULT __RPC_STUB ITypeInfo2_GetDocumentation2_Stub(ITypeInfo2 *This, MEMBERID memid,
1975 LCID lcid, DWORD flags,
1976 BSTR *help_string, DWORD *help_context,
1977 BSTR *help_dll)
1979 TRACE("(%p, %08x, %08x, %08x, %p, %p, %p)\n", This, memid, lcid, flags, help_string, help_context, help_dll);
1981 *help_string = *help_dll = NULL;
1982 *help_context = 0;
1984 if(!(flags & 1)) help_string = NULL;
1985 if(!(flags & 2)) help_context = NULL;
1986 if(!(flags & 4)) help_dll = NULL;
1988 return ITypeInfo2_GetDocumentation2(This, memid, lcid, help_string, help_context, help_dll);
1991 /* ITypeLib */
1993 UINT CALLBACK ITypeLib_GetTypeInfoCount_Proxy(
1994 ITypeLib* This)
1996 UINT count = 0;
1997 TRACE("(%p)\n", This);
1999 ITypeLib_RemoteGetTypeInfoCount_Proxy(This, &count);
2001 return count;
2004 HRESULT __RPC_STUB ITypeLib_GetTypeInfoCount_Stub(
2005 ITypeLib* This,
2006 UINT* pcTInfo)
2008 TRACE("(%p, %p)\n", This, pcTInfo);
2009 *pcTInfo = ITypeLib_GetTypeInfoCount(This);
2010 return S_OK;
2013 HRESULT CALLBACK ITypeLib_GetLibAttr_Proxy(
2014 ITypeLib* This,
2015 TLIBATTR** ppTLibAttr)
2017 CLEANLOCALSTORAGE stg;
2018 TRACE("(%p, %p)\n", This, ppTLibAttr);
2020 stg.flags = 0;
2021 stg.pStorage = NULL;
2022 stg.pInterface = NULL;
2024 return ITypeLib_RemoteGetLibAttr_Proxy(This, ppTLibAttr, &stg);
2027 HRESULT __RPC_STUB ITypeLib_GetLibAttr_Stub(
2028 ITypeLib* This,
2029 LPTLIBATTR* ppTLibAttr,
2030 CLEANLOCALSTORAGE* pDummy)
2032 HRESULT hr;
2033 TRACE("(%p, %p)\n", This, ppTLibAttr);
2035 hr = ITypeLib_GetLibAttr(This, ppTLibAttr);
2036 if(hr != S_OK)
2037 return hr;
2039 pDummy->flags = CLS_LIBATTR;
2040 ITypeLib_AddRef(This);
2041 pDummy->pInterface = (IUnknown*)This;
2042 pDummy->pStorage = ppTLibAttr;
2043 return hr;
2046 HRESULT CALLBACK ITypeLib_GetDocumentation_Proxy(ITypeLib *This, INT index, BSTR *name,
2047 BSTR *doc_string, DWORD *help_context,
2048 BSTR *help_file)
2050 DWORD dummy_help_context, flags = 0;
2051 BSTR dummy_name, dummy_doc_string, dummy_help_file;
2052 HRESULT hr;
2053 TRACE("(%p, %d, %p, %p, %p, %p)\n", This, index, name, doc_string, help_context, help_file);
2055 if(!name) name = &dummy_name;
2056 else flags = 1;
2058 if(!doc_string) doc_string = &dummy_doc_string;
2059 else flags |= 2;
2061 if(!help_context) help_context = &dummy_help_context;
2062 else flags |= 4;
2064 if(!help_file) help_file = &dummy_help_file;
2065 else flags |= 8;
2067 hr = ITypeLib_RemoteGetDocumentation_Proxy(This, index, flags, name, doc_string, help_context, help_file);
2069 /* We don't need to free the dummy BSTRs since the stub ensures that these will be NULLs. */
2071 return hr;
2074 HRESULT __RPC_STUB ITypeLib_GetDocumentation_Stub(ITypeLib *This, INT index, DWORD flags,
2075 BSTR *name, BSTR *doc_string,
2076 DWORD *help_context, BSTR *help_file)
2078 TRACE("(%p, %d, %08x, %p, %p, %p, %p)\n", This, index, flags, name, doc_string, help_context, help_file);
2080 *name = *doc_string = *help_file = NULL;
2081 *help_context = 0;
2083 if(!(flags & 1)) name = NULL;
2084 if(!(flags & 2)) doc_string = NULL;
2085 if(!(flags & 4)) help_context = NULL;
2086 if(!(flags & 8)) help_file = NULL;
2088 return ITypeLib_GetDocumentation(This, index, name, doc_string, help_context, help_file);
2091 HRESULT CALLBACK ITypeLib_IsName_Proxy(
2092 ITypeLib* This,
2093 LPOLESTR szNameBuf,
2094 ULONG lHashVal,
2095 BOOL* pfName)
2097 FIXME("not implemented\n");
2098 return E_FAIL;
2101 HRESULT __RPC_STUB ITypeLib_IsName_Stub(
2102 ITypeLib* This,
2103 LPOLESTR szNameBuf,
2104 ULONG lHashVal,
2105 BOOL* pfName,
2106 BSTR* pBstrLibName)
2108 FIXME("not implemented\n");
2109 return E_FAIL;
2112 HRESULT CALLBACK ITypeLib_FindName_Proxy(
2113 ITypeLib* This,
2114 LPOLESTR szNameBuf,
2115 ULONG lHashVal,
2116 ITypeInfo** ppTInfo,
2117 MEMBERID* rgMemId,
2118 USHORT* pcFound)
2120 FIXME("not implemented\n");
2121 return E_FAIL;
2124 HRESULT __RPC_STUB ITypeLib_FindName_Stub(
2125 ITypeLib* This,
2126 LPOLESTR szNameBuf,
2127 ULONG lHashVal,
2128 ITypeInfo** ppTInfo,
2129 MEMBERID* rgMemId,
2130 USHORT* pcFound,
2131 BSTR* pBstrLibName)
2133 FIXME("not implemented\n");
2134 return E_FAIL;
2137 void CALLBACK ITypeLib_ReleaseTLibAttr_Proxy(
2138 ITypeLib* This,
2139 TLIBATTR* pTLibAttr)
2141 TRACE("(%p, %p)\n", This, pTLibAttr);
2142 CoTaskMemFree(pTLibAttr);
2145 HRESULT __RPC_STUB ITypeLib_ReleaseTLibAttr_Stub(
2146 ITypeLib* This)
2148 TRACE("nothing to do\n");
2149 return S_OK;
2153 /* ITypeLib2 */
2155 HRESULT CALLBACK ITypeLib2_GetLibStatistics_Proxy(
2156 ITypeLib2* This,
2157 ULONG* pcUniqueNames,
2158 ULONG* pcchUniqueNames)
2160 FIXME("not implemented\n");
2161 return E_FAIL;
2164 HRESULT __RPC_STUB ITypeLib2_GetLibStatistics_Stub(
2165 ITypeLib2* This,
2166 ULONG* pcUniqueNames,
2167 ULONG* pcchUniqueNames)
2169 FIXME("not implemented\n");
2170 return E_FAIL;
2173 HRESULT CALLBACK ITypeLib2_GetDocumentation2_Proxy(ITypeLib2 *This, INT index,
2174 LCID lcid, BSTR *help_string,
2175 DWORD *help_context, BSTR *help_dll)
2177 DWORD dummy_help_context, flags = 0;
2178 BSTR dummy_help_string, dummy_help_dll;
2179 HRESULT hr;
2180 TRACE("(%p, %d, %08x, %p, %p, %p)\n", This, index, lcid, help_string, help_context, help_dll);
2182 if(!help_string) help_string = &dummy_help_string;
2183 else flags = 1;
2185 if(!help_context) help_context = &dummy_help_context;
2186 else flags |= 2;
2188 if(!help_dll) help_dll = &dummy_help_dll;
2189 else flags |= 4;
2191 hr = ITypeLib2_RemoteGetDocumentation2_Proxy(This, index, lcid, flags, help_string, help_context, help_dll);
2193 /* We don't need to free the dummy BSTRs since the stub ensures that these will be NULLs. */
2195 return hr;
2198 HRESULT __RPC_STUB ITypeLib2_GetDocumentation2_Stub(ITypeLib2 *This, INT index, LCID lcid,
2199 DWORD flags, BSTR *help_string,
2200 DWORD *help_context, BSTR *help_dll)
2202 TRACE("(%p, %d, %08x, %08x, %p, %p, %p)\n", This, index, lcid, flags, help_string, help_context, help_dll);
2204 *help_string = *help_dll = NULL;
2205 *help_context = 0;
2207 if(!(flags & 1)) help_string = NULL;
2208 if(!(flags & 2)) help_context = NULL;
2209 if(!(flags & 4)) help_dll = NULL;
2211 return ITypeLib2_GetDocumentation2(This, index, lcid, help_string, help_context, help_dll);
2214 HRESULT CALLBACK IPropertyBag_Read_Proxy(
2215 IPropertyBag* This,
2216 LPCOLESTR pszPropName,
2217 VARIANT *pVar,
2218 IErrorLog *pErrorLog)
2220 IUnknown *pUnk = NULL;
2221 TRACE("(%p, %s, %p, %p)\n", This, debugstr_w(pszPropName), pVar, pErrorLog);
2223 if(!pVar)
2224 return E_POINTER;
2226 if(V_VT(pVar) & (VT_BYREF | VT_ARRAY | VT_VECTOR))
2228 FIXME("Variant type %x is byref, array or vector. Not implemented.\n", V_VT(pVar));
2229 return E_NOTIMPL;
2232 switch(V_VT(pVar))
2234 case VT_DISPATCH:
2235 pUnk = (IUnknown*)V_DISPATCH(pVar);
2236 break;
2237 case VT_UNKNOWN:
2238 pUnk = V_UNKNOWN(pVar);
2239 break;
2240 case VT_SAFEARRAY:
2241 FIXME("Safearray support not yet implemented.\n");
2242 return E_NOTIMPL;
2243 default:
2244 FIXME("Unknown V_VT %d - support not yet implemented.\n", V_VT(pVar));
2245 return E_NOTIMPL;
2248 return IPropertyBag_RemoteRead_Proxy(This, pszPropName, pVar, pErrorLog,
2249 V_VT(pVar), pUnk);
2252 HRESULT __RPC_STUB IPropertyBag_Read_Stub(
2253 IPropertyBag* This,
2254 LPCOLESTR pszPropName,
2255 VARIANT *pVar,
2256 IErrorLog *pErrorLog,
2257 DWORD varType,
2258 IUnknown *pUnkObj)
2260 static const WCHAR emptyWstr[] = {0};
2261 IDispatch *disp;
2262 HRESULT hr;
2263 TRACE("(%p, %s, %p, %p, %x, %p)\n", This, debugstr_w(pszPropName), pVar,
2264 pErrorLog, varType, pUnkObj);
2266 if(varType & (VT_BYREF | VT_ARRAY | VT_VECTOR))
2268 FIXME("Variant type %x is byref, array or vector. Not implemented.\n", V_VT(pVar));
2269 return E_NOTIMPL;
2272 V_VT(pVar) = varType;
2273 switch(varType)
2275 case VT_DISPATCH:
2276 hr = IUnknown_QueryInterface(pUnkObj, &IID_IDispatch, (LPVOID*)&disp);
2277 if(FAILED(hr))
2278 return hr;
2279 IUnknown_Release(pUnkObj);
2280 V_DISPATCH(pVar) = disp;
2281 break;
2282 case VT_UNKNOWN:
2283 V_UNKNOWN(pVar) = pUnkObj;
2284 break;
2285 case VT_BSTR:
2286 V_BSTR(pVar) = SysAllocString(emptyWstr);
2287 break;
2288 case VT_SAFEARRAY:
2289 FIXME("Safearray support not yet implemented.\n");
2290 return E_NOTIMPL;
2291 default:
2292 break;
2294 hr = IPropertyBag_Read(This, pszPropName, pVar, pErrorLog);
2295 if(FAILED(hr))
2296 VariantClear(pVar);
2298 return hr;
2301 /* call_as/local stubs for ocidl.idl */
2303 HRESULT CALLBACK IClassFactory2_CreateInstanceLic_Proxy(
2304 IClassFactory2* This,
2305 IUnknown *pUnkOuter,
2306 IUnknown *pUnkReserved,
2307 REFIID riid,
2308 BSTR bstrKey,
2309 PVOID *ppvObj)
2311 TRACE("(%p, %s, %p)\n", pUnkOuter, debugstr_guid(riid), ppvObj);
2313 *ppvObj = NULL;
2315 if (pUnkOuter)
2317 ERR("aggregation is not allowed on remote objects\n");
2318 return CLASS_E_NOAGGREGATION;
2321 return IClassFactory2_RemoteCreateInstanceLic_Proxy(This, riid, bstrKey, (IUnknown**)ppvObj);
2324 HRESULT __RPC_STUB IClassFactory2_CreateInstanceLic_Stub(
2325 IClassFactory2* This,
2326 REFIID riid,
2327 BSTR bstrKey,
2328 IUnknown **ppvObj)
2330 TRACE("(%s, %p)\n", debugstr_guid(riid), ppvObj);
2331 return IClassFactory2_CreateInstanceLic(This, NULL, NULL, riid, bstrKey, (void**)ppvObj);
2334 HRESULT CALLBACK IEnumConnections_Next_Proxy(
2335 IEnumConnections* This,
2336 ULONG cConnections,
2337 LPCONNECTDATA rgcd,
2338 ULONG *pcFetched)
2340 ULONG fetched;
2342 TRACE("(%u, %p %p)\n", cConnections, rgcd, pcFetched);
2344 if (!pcFetched)
2345 pcFetched = &fetched;
2347 return IEnumConnections_RemoteNext_Proxy(This, cConnections, rgcd, pcFetched);
2350 HRESULT __RPC_STUB IEnumConnections_Next_Stub(
2351 IEnumConnections* This,
2352 ULONG cConnections,
2353 LPCONNECTDATA rgcd,
2354 ULONG *pcFetched)
2356 HRESULT hr;
2358 TRACE("(%u, %p, %p)\n", cConnections, rgcd, pcFetched);
2360 *pcFetched = 0;
2361 hr = IEnumConnections_Next(This, cConnections, rgcd, pcFetched);
2362 if (hr == S_OK)
2363 *pcFetched = cConnections;
2365 return hr;
2368 HRESULT CALLBACK IEnumConnectionPoints_Next_Proxy(
2369 IEnumConnectionPoints* This,
2370 ULONG cConnections,
2371 IConnectionPoint **ppCP,
2372 ULONG *pcFetched)
2374 ULONG fetched;
2376 TRACE("(%u, %p %p)\n", cConnections, ppCP, pcFetched);
2378 if (!pcFetched)
2379 pcFetched = &fetched;
2381 return IEnumConnectionPoints_RemoteNext_Proxy(This, cConnections, ppCP, pcFetched);
2384 HRESULT __RPC_STUB IEnumConnectionPoints_Next_Stub(
2385 IEnumConnectionPoints* This,
2386 ULONG cConnections,
2387 IConnectionPoint **ppCP,
2388 ULONG *pcFetched)
2390 HRESULT hr;
2392 TRACE("(%u, %p, %p)\n", cConnections, ppCP, pcFetched);
2394 *pcFetched = 0;
2395 hr = IEnumConnectionPoints_Next(This, cConnections, ppCP, pcFetched);
2396 if (hr == S_OK)
2397 *pcFetched = cConnections;
2399 return hr;
2402 HRESULT CALLBACK IPersistMemory_Load_Proxy(
2403 IPersistMemory* This,
2404 LPVOID pMem,
2405 ULONG cbSize)
2407 TRACE("(%p, %u)\n", pMem, cbSize);
2409 if (!pMem)
2410 return E_POINTER;
2412 return IPersistMemory_RemoteLoad_Proxy(This, pMem, cbSize);
2415 HRESULT __RPC_STUB IPersistMemory_Load_Stub(
2416 IPersistMemory* This,
2417 BYTE *pMem,
2418 ULONG cbSize)
2420 TRACE("(%p, %u)\n", pMem, cbSize);
2421 return IPersistMemory_Load(This, pMem, cbSize);
2424 HRESULT CALLBACK IPersistMemory_Save_Proxy(
2425 IPersistMemory* This,
2426 LPVOID pMem,
2427 BOOL fClearDirty,
2428 ULONG cbSize)
2430 TRACE("(%p, %d, %u)\n", pMem, fClearDirty, cbSize);
2432 if (!pMem)
2433 return E_POINTER;
2435 return IPersistMemory_RemoteSave_Proxy(This, pMem, fClearDirty, cbSize);
2438 HRESULT __RPC_STUB IPersistMemory_Save_Stub(
2439 IPersistMemory* This,
2440 BYTE *pMem,
2441 BOOL fClearDirty,
2442 ULONG cbSize)
2444 TRACE("(%p, %d, %u)\n", pMem, fClearDirty, cbSize);
2445 return IPersistMemory_Save(This, pMem, fClearDirty, cbSize);
2448 void CALLBACK IAdviseSinkEx_OnViewStatusChange_Proxy(
2449 IAdviseSinkEx* This,
2450 DWORD dwViewStatus)
2452 TRACE("(%p, 0x%08x)\n", This, dwViewStatus);
2453 IAdviseSinkEx_RemoteOnViewStatusChange_Proxy(This, dwViewStatus);
2456 HRESULT __RPC_STUB IAdviseSinkEx_OnViewStatusChange_Stub(
2457 IAdviseSinkEx* This,
2458 DWORD dwViewStatus)
2460 TRACE("(%p, 0x%08x)\n", This, dwViewStatus);
2461 IAdviseSinkEx_OnViewStatusChange(This, dwViewStatus);
2462 return S_OK;
2465 HRESULT CALLBACK IEnumOleUndoUnits_Next_Proxy(
2466 IEnumOleUndoUnits* This,
2467 ULONG cElt,
2468 IOleUndoUnit **rgElt,
2469 ULONG *pcEltFetched)
2471 ULONG fetched;
2473 TRACE("(%u, %p %p)\n", cElt, rgElt, pcEltFetched);
2475 if (!pcEltFetched)
2476 pcEltFetched = &fetched;
2478 return IEnumOleUndoUnits_RemoteNext_Proxy(This, cElt, rgElt, pcEltFetched);
2481 HRESULT __RPC_STUB IEnumOleUndoUnits_Next_Stub(
2482 IEnumOleUndoUnits* This,
2483 ULONG cElt,
2484 IOleUndoUnit **rgElt,
2485 ULONG *pcEltFetched)
2487 HRESULT hr;
2489 TRACE("(%u, %p, %p)\n", cElt, rgElt, pcEltFetched);
2491 *pcEltFetched = 0;
2492 hr = IEnumOleUndoUnits_Next(This, cElt, rgElt, pcEltFetched);
2493 if (hr == S_OK)
2494 *pcEltFetched = cElt;
2496 return hr;
2499 HRESULT CALLBACK IQuickActivate_QuickActivate_Proxy(
2500 IQuickActivate* This,
2501 QACONTAINER *pQaContainer,
2502 QACONTROL *pQaControl)
2504 FIXME("not implemented\n");
2505 return E_NOTIMPL;
2508 HRESULT __RPC_STUB IQuickActivate_QuickActivate_Stub(
2509 IQuickActivate* This,
2510 QACONTAINER *pQaContainer,
2511 QACONTROL *pQaControl)
2513 FIXME("not implemented\n");
2514 return E_NOTIMPL;