windows.applicationmodel/tests: Use PathRemoveFileSpecW() instead of PathCchRemoveFil...
[wine.git] / dlls / oleaut32 / usrmarshal.c
blob25bce3155bf2b660a56809eb7a63d1cfaae413a9
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 #include "windef.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "winuser.h"
30 #include "winerror.h"
32 #include "ole2.h"
33 #include "oleauto.h"
34 #include "typelib.h"
35 #include "ocidl.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(ole);
40 #define ALIGNED_LENGTH(_Len, _Align) (((_Len)+(_Align))&~(_Align))
41 #define ALIGNED_POINTER(_Ptr, _Align) ((LPVOID)ALIGNED_LENGTH((ULONG_PTR)(_Ptr), _Align))
42 #define ALIGN_LENGTH(_Len, _Align) _Len = ALIGNED_LENGTH(_Len, _Align)
43 #define ALIGN_POINTER(_Ptr, _Align) _Ptr = ALIGNED_POINTER(_Ptr, _Align)
45 /* ole32 exports those, not defined in public headers */
46 ULONG __RPC_USER WdtpInterfacePointer_UserSize(ULONG*, ULONG, ULONG, IUnknown*, REFIID);
47 unsigned char * __RPC_USER WdtpInterfacePointer_UserMarshal(ULONG*, ULONG, unsigned char*, IUnknown*, REFIID);
48 unsigned char * __RPC_USER WdtpInterfacePointer_UserUnmarshal(ULONG*, unsigned char*, IUnknown**, REFIID);
50 static void dump_user_flags(const ULONG *pFlags)
52 if (HIWORD(*pFlags) == NDR_LOCAL_DATA_REPRESENTATION)
53 TRACE("MAKELONG(NDR_LOCAL_REPRESENTATION, ");
54 else
55 TRACE("MAKELONG(0x%04x, ", HIWORD(*pFlags));
56 switch (LOWORD(*pFlags))
58 case MSHCTX_LOCAL: TRACE("MSHCTX_LOCAL)"); break;
59 case MSHCTX_NOSHAREDMEM: TRACE("MSHCTX_NOSHAREDMEM)"); break;
60 case MSHCTX_DIFFERENTMACHINE: TRACE("MSHCTX_DIFFERENTMACHINE)"); break;
61 case MSHCTX_INPROC: TRACE("MSHCTX_INPROC)"); break;
62 default: TRACE("%d)", LOWORD(*pFlags));
66 /* CLEANLOCALSTORAGE */
68 #define CLS_FUNCDESC 'f'
69 #define CLS_LIBATTR 'l'
70 #define CLS_TYPEATTR 't'
71 #define CLS_VARDESC 'v'
73 ULONG WINAPI CLEANLOCALSTORAGE_UserSize(ULONG *pFlags, ULONG Start, CLEANLOCALSTORAGE *pstg)
75 ALIGN_LENGTH(Start, 3);
76 return Start + sizeof(DWORD);
79 unsigned char * WINAPI CLEANLOCALSTORAGE_UserMarshal(ULONG *pFlags, unsigned char *Buffer, CLEANLOCALSTORAGE *pstg)
81 ALIGN_POINTER(Buffer, 3);
82 *(DWORD*)Buffer = pstg->flags;
84 if (!pstg->pInterface)
85 return Buffer + sizeof(DWORD);
87 switch(pstg->flags)
89 case CLS_LIBATTR:
90 ITypeLib_ReleaseTLibAttr((ITypeLib*)pstg->pInterface, *(TLIBATTR**)pstg->pStorage);
91 break;
92 case CLS_TYPEATTR:
93 ITypeInfo_ReleaseTypeAttr((ITypeInfo*)pstg->pInterface, *(TYPEATTR**)pstg->pStorage);
94 break;
95 case CLS_FUNCDESC:
96 ITypeInfo_ReleaseFuncDesc((ITypeInfo*)pstg->pInterface, *(FUNCDESC**)pstg->pStorage);
97 break;
98 case CLS_VARDESC:
99 ITypeInfo_ReleaseVarDesc((ITypeInfo*)pstg->pInterface, *(VARDESC**)pstg->pStorage);
100 break;
102 default:
103 ERR("Unknown type %lx\n", pstg->flags);
106 *(VOID**)pstg->pStorage = NULL;
107 IUnknown_Release(pstg->pInterface);
108 pstg->pInterface = NULL;
110 return Buffer + sizeof(DWORD);
113 unsigned char * WINAPI CLEANLOCALSTORAGE_UserUnmarshal(ULONG *pFlags, unsigned char *Buffer, CLEANLOCALSTORAGE *pstr)
115 ALIGN_POINTER(Buffer, 3);
116 pstr->flags = *(DWORD*)Buffer;
117 return Buffer + sizeof(DWORD);
120 void WINAPI CLEANLOCALSTORAGE_UserFree(ULONG *pFlags, CLEANLOCALSTORAGE *pstr)
122 /* Nothing to do */
125 /* BSTR */
127 typedef struct
129 DWORD len; /* No. of chars not including trailing '\0' */
130 DWORD byte_len; /* len * 2 or 0xffffffff if len == 0 */
131 DWORD len2; /* == len */
132 } bstr_wire_t;
134 ULONG WINAPI BSTR_UserSize(ULONG *pFlags, ULONG Start, BSTR *pstr)
136 TRACE("%#lx, %lu, %p => %p\n", *pFlags, Start, pstr, *pstr);
137 if (*pstr) TRACE("string=%s\n", debugstr_w(*pstr));
138 ALIGN_LENGTH(Start, 3);
139 Start += sizeof(bstr_wire_t) + ((SysStringByteLen(*pstr) + 1) & ~1);
140 TRACE("returning %ld\n", Start);
141 return Start;
144 unsigned char * WINAPI BSTR_UserMarshal(ULONG *pFlags, unsigned char *Buffer, BSTR *pstr)
146 bstr_wire_t *header;
147 DWORD len = SysStringByteLen(*pstr);
149 TRACE("%#lx, %p, %p => %p\n", *pFlags, Buffer, pstr, *pstr);
150 if (*pstr) TRACE("string=%s\n", debugstr_w(*pstr));
152 ALIGN_POINTER(Buffer, 3);
153 header = (bstr_wire_t*)Buffer;
154 header->len = header->len2 = (len + 1) / 2;
155 if (*pstr)
157 header->byte_len = len;
158 memcpy(header + 1, *pstr, header->len * 2);
160 else
161 header->byte_len = 0xffffffff; /* special case for a null bstr */
163 return Buffer + sizeof(*header) + sizeof(OLECHAR) * header->len;
166 unsigned char * WINAPI BSTR_UserUnmarshal(ULONG *pFlags, unsigned char *Buffer, BSTR *pstr)
168 bstr_wire_t *header;
169 TRACE("%#lx, %p, %p => %p\n", *pFlags, Buffer, pstr, *pstr);
171 ALIGN_POINTER(Buffer, 3);
172 header = (bstr_wire_t*)Buffer;
173 if(header->len != header->len2)
174 FIXME("len %#lx != len2 %#lx\n", header->len, header->len2);
176 if (header->byte_len == 0xffffffff)
178 SysFreeString(*pstr);
179 *pstr = NULL;
181 else SysReAllocStringLen( pstr, (OLECHAR *)(header + 1), header->len );
183 if (*pstr) TRACE("string=%s\n", debugstr_w(*pstr));
184 return Buffer + sizeof(*header) + sizeof(OLECHAR) * header->len;
187 void WINAPI BSTR_UserFree(ULONG *pFlags, BSTR *pstr)
189 TRACE("%#lx, %p => %p\n", *pFlags, pstr, *pstr);
190 SysFreeString(*pstr);
191 *pstr = NULL;
194 /* VARIANT */
196 typedef struct
198 DWORD clSize;
199 DWORD rpcReserved;
200 USHORT vt;
201 USHORT wReserved1;
202 USHORT wReserved2;
203 USHORT wReserved3;
204 DWORD switch_is;
205 } variant_wire_t;
207 unsigned int get_type_size(ULONG *pFlags, VARTYPE vt)
209 if (vt & VT_ARRAY) return 4;
211 switch (vt & ~VT_BYREF) {
212 case VT_EMPTY:
213 case VT_NULL:
214 return 0;
215 case VT_I1:
216 case VT_UI1:
217 return sizeof(CHAR);
218 case VT_I2:
219 case VT_UI2:
220 return sizeof(SHORT);
221 case VT_I4:
222 case VT_UI4:
223 case VT_HRESULT:
224 return sizeof(LONG);
225 case VT_INT:
226 case VT_UINT:
227 return sizeof(INT);
228 case VT_I8:
229 case VT_UI8:
230 return sizeof(LONGLONG);
231 case VT_R4:
232 return sizeof(FLOAT);
233 case VT_R8:
234 return sizeof(DOUBLE);
235 case VT_BOOL:
236 return sizeof(VARIANT_BOOL);
237 case VT_ERROR:
238 return sizeof(SCODE);
239 case VT_DATE:
240 return sizeof(DATE);
241 case VT_CY:
242 return sizeof(CY);
243 case VT_DECIMAL:
244 return sizeof(DECIMAL);
245 case VT_BSTR:
246 return sizeof(ULONG);
247 case VT_VARIANT:
248 return sizeof(VARIANT);
249 case VT_UNKNOWN:
250 case VT_DISPATCH:
251 case VT_RECORD:
252 return 0;
253 default:
254 FIXME("unhandled VT %d\n", vt);
255 return 0;
259 static unsigned int get_type_alignment(ULONG *pFlags, VARTYPE vt)
261 unsigned int size = get_type_size(pFlags, vt);
262 if(vt & VT_BYREF) return 3;
263 if(size == 0) return 0;
264 if(size <= 4) return size - 1;
265 return 7;
268 /* WdtpInterfacePointer_UserSize takes care of 2 additional DWORDs to store marshalling buffer size */
269 static unsigned interface_user_size(ULONG *pFlags, ULONG Start, REFIID riid, IUnknown *punk)
271 ULONG size = 0;
273 if (punk)
275 size = WdtpInterfacePointer_UserSize(pFlags, LOWORD(*pFlags), 0, punk, riid);
276 if (!size)
278 ERR("interface variant buffer size calculation failed\n");
279 return 0;
282 size += sizeof(ULONG);
283 TRACE("wire-size extra of interface variant is %ld.\n", size);
284 return Start + size;
287 static ULONG wire_extra_user_size(ULONG *pFlags, ULONG Start, VARIANT *pvar)
289 if (V_ISARRAY(pvar))
291 if (V_ISBYREF(pvar))
292 return LPSAFEARRAY_UserSize(pFlags, Start, V_ARRAYREF(pvar));
293 else
294 return LPSAFEARRAY_UserSize(pFlags, Start, &V_ARRAY(pvar));
297 switch (V_VT(pvar)) {
298 case VT_BSTR:
299 return BSTR_UserSize(pFlags, Start, &V_BSTR(pvar));
300 case VT_BSTR | VT_BYREF:
301 return BSTR_UserSize(pFlags, Start, V_BSTRREF(pvar));
302 case VT_VARIANT | VT_BYREF:
303 return VARIANT_UserSize(pFlags, Start, V_VARIANTREF(pvar));
304 case VT_UNKNOWN:
305 return interface_user_size(pFlags, Start, &IID_IUnknown, V_UNKNOWN(pvar));
306 case VT_UNKNOWN | VT_BYREF:
307 return interface_user_size(pFlags, Start, &IID_IUnknown, *V_UNKNOWNREF(pvar));
308 case VT_DISPATCH:
309 return interface_user_size(pFlags, Start, &IID_IDispatch, (IUnknown*)V_DISPATCH(pvar));
310 case VT_DISPATCH | VT_BYREF:
311 return interface_user_size(pFlags, Start, &IID_IDispatch, (IUnknown*)*V_DISPATCHREF(pvar));
312 case VT_RECORD:
313 FIXME("wire-size record\n");
314 return Start;
315 case VT_SAFEARRAY:
316 case VT_SAFEARRAY | VT_BYREF:
317 FIXME("wire-size safearray: shouldn't be marshaling this\n");
318 return Start;
319 default:
320 return Start;
324 /* helper: called for VT_DISPATCH variants to marshal the IDispatch* into the buffer */
325 static unsigned char* interface_user_marshal(ULONG *pFlags, unsigned char *Buffer,
326 REFIID riid, IUnknown *punk)
328 TRACE("%#lx, %p, %p.\n", *pFlags, Buffer, punk);
330 /* first DWORD is used to store pointer itself, truncated on win64 */
331 if(!punk)
333 memset(Buffer, 0, sizeof(ULONG));
334 return Buffer + sizeof(ULONG);
336 else
338 *(DWORD*)Buffer = (DWORD_PTR)punk;
339 Buffer += sizeof(DWORD);
342 return WdtpInterfacePointer_UserMarshal(pFlags, LOWORD(*pFlags), Buffer, punk, riid);
345 /* helper: called for VT_DISPATCH / VT_UNKNOWN variants to unmarshal the buffer */
346 static unsigned char *interface_user_unmarshal(ULONG *pFlags, unsigned char *Buffer,
347 REFIID riid, IUnknown **ppunk)
349 DWORD ptr;
351 TRACE("%#lx, %p, %p.\n", *pFlags, Buffer, ppunk);
353 /* skip pointer part itself */
354 ptr = *(DWORD*)Buffer;
355 Buffer += sizeof(DWORD);
357 if(!ptr)
358 return Buffer;
360 return WdtpInterfacePointer_UserUnmarshal(pFlags, Buffer, ppunk, riid);
363 ULONG WINAPI VARIANT_UserSize(ULONG *pFlags, ULONG Start, VARIANT *pvar)
365 int align;
366 TRACE("%#lx, %lu, %p.\n", *pFlags, Start, pvar);
367 TRACE("vt=%04x\n", V_VT(pvar));
369 ALIGN_LENGTH(Start, 7);
370 Start += sizeof(variant_wire_t);
371 if(V_VT(pvar) & VT_BYREF)
372 Start += 4;
374 align = get_type_alignment(pFlags, V_VT(pvar));
375 ALIGN_LENGTH(Start, align);
376 if(V_VT(pvar) == (VT_VARIANT | VT_BYREF))
377 Start += 4;
378 else
379 Start += get_type_size(pFlags, V_VT(pvar));
380 Start = wire_extra_user_size(pFlags, Start, pvar);
382 TRACE("returning %ld\n", Start);
383 return Start;
386 unsigned char * WINAPI VARIANT_UserMarshal(ULONG *pFlags, unsigned char *Buffer, VARIANT *pvar)
388 variant_wire_t *header;
389 ULONG type_size;
390 int align;
391 unsigned char *Pos;
393 TRACE("%#lx, %p, %p.\n", *pFlags, Buffer, pvar);
394 TRACE("vt=%04x\n", V_VT(pvar));
396 ALIGN_POINTER(Buffer, 7);
398 header = (variant_wire_t *)Buffer;
400 header->clSize = 0; /* fixed up at the end */
401 header->rpcReserved = 0;
402 header->vt = V_VT(pvar);
403 header->wReserved1 = pvar->wReserved1;
404 header->wReserved2 = pvar->wReserved2;
405 header->wReserved3 = pvar->wReserved3;
406 header->switch_is = V_VT(pvar);
407 if(header->switch_is & VT_ARRAY)
408 header->switch_is &= ~VT_TYPEMASK;
410 Pos = (unsigned char*)(header + 1);
411 type_size = get_type_size(pFlags, V_VT(pvar));
412 align = get_type_alignment(pFlags, V_VT(pvar));
413 ALIGN_POINTER(Pos, align);
415 if(header->vt & VT_BYREF)
417 *(DWORD *)Pos = max(type_size, 4);
418 Pos += 4;
419 if((header->vt & VT_TYPEMASK) != VT_VARIANT)
421 memcpy(Pos, V_BYREF(pvar), type_size);
422 Pos += type_size;
424 else
426 *(DWORD*)Pos = 'U' | 's' << 8 | 'e' << 16 | 'r' << 24;
427 Pos += 4;
430 else
432 if((header->vt & VT_TYPEMASK) == VT_DECIMAL)
433 memcpy(Pos, pvar, type_size);
434 else
435 memcpy(Pos, &V_UI8(pvar), type_size);
436 Pos += type_size;
439 if(header->vt & VT_ARRAY)
441 if(header->vt & VT_BYREF)
442 Pos = LPSAFEARRAY_UserMarshal(pFlags, Pos, V_ARRAYREF(pvar));
443 else
444 Pos = LPSAFEARRAY_UserMarshal(pFlags, Pos, &V_ARRAY(pvar));
446 else
448 switch (header->vt)
450 case VT_BSTR:
451 Pos = BSTR_UserMarshal(pFlags, Pos, &V_BSTR(pvar));
452 break;
453 case VT_BSTR | VT_BYREF:
454 Pos = BSTR_UserMarshal(pFlags, Pos, V_BSTRREF(pvar));
455 break;
456 case VT_VARIANT | VT_BYREF:
457 Pos = VARIANT_UserMarshal(pFlags, Pos, V_VARIANTREF(pvar));
458 break;
459 case VT_UNKNOWN:
460 Pos = interface_user_marshal(pFlags, Pos, &IID_IUnknown, V_UNKNOWN(pvar));
461 break;
462 case VT_UNKNOWN | VT_BYREF:
463 Pos = interface_user_marshal(pFlags, Pos, &IID_IUnknown, *V_UNKNOWNREF(pvar));
464 break;
465 case VT_DISPATCH:
466 Pos = interface_user_marshal(pFlags, Pos, &IID_IDispatch, (IUnknown*)V_DISPATCH(pvar));
467 break;
468 case VT_DISPATCH | VT_BYREF:
469 Pos = interface_user_marshal(pFlags, Pos, &IID_IDispatch, (IUnknown*)*V_DISPATCHREF(pvar));
470 break;
471 case VT_RECORD:
472 FIXME("handle BRECORD by val\n");
473 break;
474 case VT_RECORD | VT_BYREF:
475 FIXME("handle BRECORD by ref\n");
476 break;
479 header->clSize = ((Pos - Buffer) + 7) >> 3;
480 TRACE("marshalled size %ld\n", header->clSize);
481 return Pos;
484 unsigned char * WINAPI VARIANT_UserUnmarshal(ULONG *pFlags, unsigned char *Buffer, VARIANT *pvar)
486 variant_wire_t *header;
487 ULONG type_size;
488 int align;
489 unsigned char *Pos;
491 TRACE("%#lx, %p, %p.\n", *pFlags, Buffer, pvar);
493 ALIGN_POINTER(Buffer, 7);
495 header = (variant_wire_t *)Buffer;
497 Pos = (unsigned char*)(header + 1);
498 type_size = get_type_size(pFlags, header->vt);
499 align = get_type_alignment(pFlags, header->vt);
500 ALIGN_POINTER(Pos, align);
502 if(header->vt & VT_BYREF)
504 ULONG mem_size;
505 Pos += 4;
507 /* byref array needs to allocate a SAFEARRAY pointer */
508 if (header->vt & VT_ARRAY)
509 mem_size = sizeof(void *);
510 else switch (header->vt & ~VT_BYREF)
512 /* these types have a different memory size compared to wire size */
513 case VT_UNKNOWN:
514 case VT_DISPATCH:
515 case VT_BSTR:
516 mem_size = sizeof(void *);
517 break;
518 default:
519 mem_size = type_size;
520 break;
523 if (V_VT(pvar) != header->vt)
525 VariantClear(pvar);
526 V_BYREF(pvar) = CoTaskMemAlloc(mem_size);
527 memset(V_BYREF(pvar), 0, mem_size);
529 else if (!V_BYREF(pvar))
531 V_BYREF(pvar) = CoTaskMemAlloc(mem_size);
532 memset(V_BYREF(pvar), 0, mem_size);
535 if(!(header->vt & VT_ARRAY)
536 && (header->vt & VT_TYPEMASK) != VT_BSTR
537 && (header->vt & VT_TYPEMASK) != VT_VARIANT
538 && (header->vt & VT_TYPEMASK) != VT_UNKNOWN
539 && (header->vt & VT_TYPEMASK) != VT_DISPATCH
540 && (header->vt & VT_TYPEMASK) != VT_RECORD)
541 memcpy(V_BYREF(pvar), Pos, type_size);
543 if((header->vt & VT_TYPEMASK) != VT_VARIANT)
544 Pos += type_size;
545 else
546 Pos += 4;
548 else
550 VariantClear(pvar);
551 if(header->vt & VT_ARRAY)
552 V_ARRAY(pvar) = NULL;
553 else if((header->vt & VT_TYPEMASK) == VT_BSTR)
554 V_BSTR(pvar) = NULL;
555 else if((header->vt & VT_TYPEMASK) == VT_UNKNOWN)
556 V_UNKNOWN(pvar) = NULL;
557 else if((header->vt & VT_TYPEMASK) == VT_DISPATCH)
558 V_DISPATCH(pvar) = NULL;
559 else if((header->vt & VT_TYPEMASK) == VT_RECORD)
560 V_RECORD(pvar) = NULL;
561 else if((header->vt & VT_TYPEMASK) == VT_DECIMAL)
562 memcpy(pvar, Pos, type_size);
563 else
564 memcpy(&V_UI8(pvar), Pos, type_size);
565 Pos += type_size;
568 V_VT(pvar) = header->vt;
569 pvar->wReserved1 = header->wReserved1;
570 pvar->wReserved2 = header->wReserved2;
571 pvar->wReserved3 = header->wReserved3;
573 if(header->vt & VT_ARRAY)
575 if(header->vt & VT_BYREF)
576 Pos = LPSAFEARRAY_UserUnmarshal(pFlags, Pos, V_ARRAYREF(pvar));
577 else
578 Pos = LPSAFEARRAY_UserUnmarshal(pFlags, Pos, &V_ARRAY(pvar));
580 else
582 switch (header->vt)
584 case VT_BSTR:
585 Pos = BSTR_UserUnmarshal(pFlags, Pos, &V_BSTR(pvar));
586 break;
587 case VT_BSTR | VT_BYREF:
588 Pos = BSTR_UserUnmarshal(pFlags, Pos, V_BSTRREF(pvar));
589 break;
590 case VT_VARIANT | VT_BYREF:
591 Pos = VARIANT_UserUnmarshal(pFlags, Pos, V_VARIANTREF(pvar));
592 break;
593 case VT_UNKNOWN:
594 Pos = interface_user_unmarshal(pFlags, Pos, &IID_IUnknown, &V_UNKNOWN(pvar));
595 break;
596 case VT_UNKNOWN | VT_BYREF:
597 Pos = interface_user_unmarshal(pFlags, Pos, &IID_IUnknown, V_UNKNOWNREF(pvar));
598 break;
599 case VT_DISPATCH:
600 Pos = interface_user_unmarshal(pFlags, Pos, &IID_IDispatch, (IUnknown**)&V_DISPATCH(pvar));
601 break;
602 case VT_DISPATCH | VT_BYREF:
603 Pos = interface_user_unmarshal(pFlags, Pos, &IID_IDispatch, (IUnknown**)V_DISPATCHREF(pvar));
604 break;
605 case VT_RECORD:
606 FIXME("handle BRECORD by val\n");
607 break;
608 case VT_RECORD | VT_BYREF:
609 FIXME("handle BRECORD by ref\n");
610 break;
613 return Pos;
616 void WINAPI VARIANT_UserFree(ULONG *pFlags, VARIANT *pvar)
618 VARTYPE vt = V_VT(pvar);
619 PVOID ref = NULL;
621 TRACE("%#lx, %p.\n", *pFlags, pvar);
622 TRACE("vt=%04x\n", V_VT(pvar));
624 if (vt & VT_BYREF) ref = V_BYREF(pvar);
626 VariantClear(pvar);
627 if (!ref) return;
629 if(vt & VT_ARRAY)
631 if (vt & VT_BYREF)
632 LPSAFEARRAY_UserFree(pFlags, V_ARRAYREF(pvar));
633 else
634 LPSAFEARRAY_UserFree(pFlags, &V_ARRAY(pvar));
636 else
638 switch (vt)
640 case VT_BSTR | VT_BYREF:
641 BSTR_UserFree(pFlags, V_BSTRREF(pvar));
642 break;
643 case VT_VARIANT | VT_BYREF:
644 VARIANT_UserFree(pFlags, V_VARIANTREF(pvar));
645 break;
646 case VT_RECORD | VT_BYREF:
647 FIXME("handle BRECORD by ref\n");
648 break;
649 case VT_UNKNOWN | VT_BYREF:
650 case VT_DISPATCH | VT_BYREF:
651 if (*V_UNKNOWNREF(pvar))
652 IUnknown_Release(*V_UNKNOWNREF(pvar));
653 break;
657 CoTaskMemFree(ref);
660 /* LPSAFEARRAY */
662 /* Get the number of cells in a SafeArray */
663 static ULONG SAFEARRAY_GetCellCount(const SAFEARRAY *psa)
665 const SAFEARRAYBOUND* psab = psa->rgsabound;
666 USHORT cCount = psa->cDims;
667 ULONG ulNumCells = 1;
669 while (cCount--)
671 /* This is a valid bordercase. See testcases. -Marcus */
672 if (!psab->cElements)
673 return 0;
674 ulNumCells *= psab->cElements;
675 psab++;
677 return ulNumCells;
680 static inline SF_TYPE SAFEARRAY_GetUnionType(SAFEARRAY *psa)
682 VARTYPE vt;
683 HRESULT hr;
685 hr = SafeArrayGetVartype(psa, &vt);
686 if (FAILED(hr))
688 if(psa->fFeatures & FADF_VARIANT) return SF_VARIANT;
690 switch(psa->cbElements)
692 case 1: vt = VT_I1; break;
693 case 2: vt = VT_I2; break;
694 case 4: vt = VT_I4; break;
695 case 8: vt = VT_I8; break;
696 default:
697 RpcRaiseException(hr);
701 if (psa->fFeatures & FADF_HAVEIID)
702 return SF_HAVEIID;
704 switch (vt)
706 case VT_I1:
707 case VT_UI1: return SF_I1;
708 case VT_BOOL:
709 case VT_I2:
710 case VT_UI2: return SF_I2;
711 case VT_INT:
712 case VT_UINT:
713 case VT_I4:
714 case VT_UI4:
715 case VT_R4: return SF_I4;
716 case VT_DATE:
717 case VT_CY:
718 case VT_R8:
719 case VT_I8:
720 case VT_UI8: return SF_I8;
721 case VT_INT_PTR:
722 case VT_UINT_PTR: return (sizeof(UINT_PTR) == 4 ? SF_I4 : SF_I8);
723 case VT_BSTR: return SF_BSTR;
724 case VT_DISPATCH: return SF_DISPATCH;
725 case VT_VARIANT: return SF_VARIANT;
726 case VT_UNKNOWN: return SF_UNKNOWN;
727 /* Note: Return a non-zero size to indicate vt is valid. The actual size
728 * of a UDT is taken from the result of IRecordInfo_GetSize().
730 case VT_RECORD: return SF_RECORD;
731 default: return SF_ERROR;
735 static DWORD elem_wire_size(LPSAFEARRAY lpsa, SF_TYPE sftype)
737 switch (sftype)
739 case SF_BSTR:
740 case SF_HAVEIID:
741 case SF_UNKNOWN:
742 case SF_DISPATCH:
743 return sizeof(DWORD);
745 case SF_VARIANT:
746 return sizeof(variant_wire_t) - sizeof(DWORD);
748 default:
749 return lpsa->cbElements;
753 static DWORD elem_mem_size(wireSAFEARRAY wiresa, SF_TYPE sftype)
755 switch (sftype)
757 case SF_HAVEIID:
758 case SF_UNKNOWN:
759 case SF_DISPATCH:
760 return sizeof(void *);
762 case SF_BSTR:
763 return sizeof(BSTR);
765 case SF_VARIANT:
766 return sizeof(VARIANT);
768 default:
769 return wiresa->cbElements;
773 ULONG WINAPI LPSAFEARRAY_UserSize(ULONG *pFlags, ULONG StartingSize, LPSAFEARRAY *ppsa)
775 ULONG size = StartingSize;
777 TRACE("("); dump_user_flags(pFlags); TRACE(", %ld, %p\n", StartingSize, *ppsa);
779 ALIGN_LENGTH(size, 3);
780 size += sizeof(ULONG);
781 if (*ppsa)
783 SAFEARRAY *psa = *ppsa;
784 ULONG ulCellCount = SAFEARRAY_GetCellCount(psa);
785 SF_TYPE sftype;
786 HRESULT hr;
788 size += sizeof(ULONG);
789 size += 2 * sizeof(USHORT) + 2 * sizeof(ULONG);
791 sftype = SAFEARRAY_GetUnionType(psa);
792 size += sizeof(ULONG);
794 size += sizeof(ULONG);
795 size += sizeof(ULONG);
796 if (sftype == SF_HAVEIID)
797 size += sizeof(IID);
799 size += sizeof(psa->rgsabound[0]) * psa->cDims;
801 size += sizeof(ULONG);
803 switch (sftype)
805 case SF_BSTR:
807 BSTR* lpBstr;
809 for (lpBstr = psa->pvData; ulCellCount; ulCellCount--, lpBstr++)
810 size = BSTR_UserSize(pFlags, size, lpBstr);
812 break;
814 case SF_DISPATCH:
815 case SF_UNKNOWN:
816 case SF_HAVEIID:
818 IUnknown **lpUnk;
819 GUID guid;
821 if (sftype == SF_HAVEIID)
822 SafeArrayGetIID(psa, &guid);
823 else if (sftype == SF_UNKNOWN)
824 guid = IID_IUnknown;
825 else
826 guid = IID_IDispatch;
828 for (lpUnk = psa->pvData; ulCellCount; ulCellCount--, lpUnk++)
829 size = interface_user_size(pFlags, size, &guid, *lpUnk);
831 break;
833 case SF_VARIANT:
835 VARIANT* lpVariant;
837 for (lpVariant = psa->pvData; ulCellCount; ulCellCount--, lpVariant++)
838 size = VARIANT_UserSize(pFlags, size, lpVariant);
840 break;
842 case SF_RECORD:
844 IRecordInfo* pRecInfo = NULL;
846 hr = SafeArrayGetRecordInfo(psa, &pRecInfo);
847 if (FAILED(hr))
848 RpcRaiseException(hr);
850 if (pRecInfo)
852 FIXME("size record info %p\n", pRecInfo);
854 IRecordInfo_Release(pRecInfo);
856 break;
858 case SF_I8:
859 ALIGN_LENGTH(size, 7);
860 /* fallthrough */
861 case SF_I1:
862 case SF_I2:
863 case SF_I4:
864 size += ulCellCount * psa->cbElements;
865 break;
866 default:
867 break;
872 return size;
875 unsigned char * WINAPI LPSAFEARRAY_UserMarshal(ULONG *pFlags, unsigned char *Buffer, LPSAFEARRAY *ppsa)
877 HRESULT hr;
879 TRACE("("); dump_user_flags(pFlags); TRACE(", %p, &%p\n", Buffer, *ppsa);
881 ALIGN_POINTER(Buffer, 3);
882 *(ULONG *)Buffer = *ppsa ? 0x1 : 0x0;
883 Buffer += sizeof(ULONG);
884 if (*ppsa)
886 VARTYPE vt;
887 SAFEARRAY *psa = *ppsa;
888 ULONG ulCellCount = SAFEARRAY_GetCellCount(psa);
889 SAFEARRAYBOUND *bound;
890 SF_TYPE sftype;
891 GUID guid;
892 INT i;
894 sftype = SAFEARRAY_GetUnionType(psa);
896 *(ULONG *)Buffer = psa->cDims;
897 Buffer += sizeof(ULONG);
898 *(USHORT *)Buffer = psa->cDims;
899 Buffer += sizeof(USHORT);
900 *(USHORT *)Buffer = psa->fFeatures;
901 Buffer += sizeof(USHORT);
902 *(ULONG *)Buffer = elem_wire_size(psa, sftype);
903 Buffer += sizeof(ULONG);
905 hr = SafeArrayGetVartype(psa, &vt);
906 if ((psa->fFeatures & FADF_HAVEIID) || FAILED(hr)) vt = 0;
908 *(ULONG *)Buffer = (USHORT)psa->cLocks | (vt << 16);
909 Buffer += sizeof(ULONG);
911 *(ULONG *)Buffer = sftype;
912 Buffer += sizeof(ULONG);
914 *(ULONG *)Buffer = ulCellCount;
915 Buffer += sizeof(ULONG);
916 *(ULONG *)Buffer = psa->pvData ? 0x2 : 0x0;
917 Buffer += sizeof(ULONG);
918 if (sftype == SF_HAVEIID)
920 SafeArrayGetIID(psa, &guid);
921 memcpy(Buffer, &guid, sizeof(guid));
922 Buffer += sizeof(guid);
925 /* bounds are marshaled in opposite order comparing to storage layout */
926 bound = (SAFEARRAYBOUND*)Buffer;
927 for (i = 0; i < psa->cDims; i++)
929 memcpy(bound++, &psa->rgsabound[psa->cDims-i-1], sizeof(psa->rgsabound[0]));
931 Buffer += sizeof(psa->rgsabound[0]) * psa->cDims;
933 *(ULONG *)Buffer = ulCellCount;
934 Buffer += sizeof(ULONG);
936 if (psa->pvData)
938 switch (sftype)
940 case SF_BSTR:
942 BSTR* lpBstr;
944 for (lpBstr = psa->pvData; ulCellCount; ulCellCount--, lpBstr++)
945 Buffer = BSTR_UserMarshal(pFlags, Buffer, lpBstr);
947 break;
949 case SF_DISPATCH:
950 case SF_UNKNOWN:
951 case SF_HAVEIID:
953 IUnknown **lpUnk;
954 const GUID *iid;
956 if (sftype == SF_HAVEIID)
957 iid = &guid;
958 else if (sftype == SF_UNKNOWN)
959 iid = &IID_IUnknown;
960 else
961 iid = &IID_IDispatch;
963 for (lpUnk = psa->pvData; ulCellCount; ulCellCount--, lpUnk++)
964 Buffer = interface_user_marshal(pFlags, Buffer, iid, *lpUnk);
966 break;
968 case SF_VARIANT:
970 VARIANT* lpVariant;
972 for (lpVariant = psa->pvData; ulCellCount; ulCellCount--, lpVariant++)
973 Buffer = VARIANT_UserMarshal(pFlags, Buffer, lpVariant);
975 break;
977 case SF_RECORD:
979 IRecordInfo* pRecInfo = NULL;
981 hr = SafeArrayGetRecordInfo(psa, &pRecInfo);
982 if (FAILED(hr))
983 RpcRaiseException(hr);
985 if (pRecInfo)
987 FIXME("write record info %p\n", pRecInfo);
989 IRecordInfo_Release(pRecInfo);
991 break;
994 case SF_I8:
995 ALIGN_POINTER(Buffer, 7);
996 /* fallthrough */
997 case SF_I1:
998 case SF_I2:
999 case SF_I4:
1000 /* Just copy the data over */
1001 memcpy(Buffer, psa->pvData, ulCellCount * psa->cbElements);
1002 Buffer += ulCellCount * psa->cbElements;
1003 break;
1004 default:
1005 break;
1010 return Buffer;
1013 #define FADF_AUTOSETFLAGS (FADF_HAVEIID | FADF_RECORD | FADF_HAVEVARTYPE | \
1014 FADF_BSTR | FADF_UNKNOWN | FADF_DISPATCH | \
1015 FADF_VARIANT | FADF_CREATEVECTOR)
1017 unsigned char * WINAPI LPSAFEARRAY_UserUnmarshal(ULONG *pFlags, unsigned char *Buffer, LPSAFEARRAY *ppsa)
1019 ULONG ptr;
1020 wireSAFEARRAY wiresa;
1021 ULONG cDims;
1022 HRESULT hr;
1023 SF_TYPE sftype;
1024 ULONG cell_count;
1025 GUID guid;
1026 VARTYPE vt;
1027 SAFEARRAYBOUND *wiresab;
1029 TRACE("("); dump_user_flags(pFlags); TRACE(", %p, %p\n", Buffer, ppsa);
1031 ALIGN_POINTER(Buffer, 3);
1032 ptr = *(ULONG *)Buffer;
1033 Buffer += sizeof(ULONG);
1035 if (!ptr)
1037 SafeArrayDestroy(*ppsa);
1038 *ppsa = NULL;
1040 TRACE("NULL safe array unmarshaled\n");
1042 return Buffer;
1045 cDims = *(ULONG *)Buffer;
1046 Buffer += sizeof(ULONG);
1048 wiresa = (wireSAFEARRAY)Buffer;
1049 Buffer += 2 * sizeof(USHORT) + 2 * sizeof(ULONG);
1051 if (cDims != wiresa->cDims)
1052 RpcRaiseException(RPC_S_INVALID_BOUND);
1054 /* FIXME: there should be a limit on how large cDims can be */
1056 vt = HIWORD(wiresa->cLocks);
1058 sftype = *(ULONG *)Buffer;
1059 Buffer += sizeof(ULONG);
1061 cell_count = *(ULONG *)Buffer;
1062 Buffer += sizeof(ULONG);
1063 ptr = *(ULONG *)Buffer;
1064 Buffer += sizeof(ULONG);
1065 if (sftype == SF_HAVEIID)
1067 memcpy(&guid, Buffer, sizeof(guid));
1068 Buffer += sizeof(guid);
1071 wiresab = (SAFEARRAYBOUND *)Buffer;
1072 Buffer += sizeof(wiresab[0]) * wiresa->cDims;
1074 if(*ppsa && (*ppsa)->cDims==wiresa->cDims)
1076 if(((*ppsa)->fFeatures & ~FADF_AUTOSETFLAGS) != (wiresa->fFeatures & ~FADF_AUTOSETFLAGS))
1077 RpcRaiseException(DISP_E_BADCALLEE);
1079 if(SAFEARRAY_GetCellCount(*ppsa)*(*ppsa)->cbElements != cell_count*elem_mem_size(wiresa, sftype))
1081 if((*ppsa)->fFeatures & (FADF_AUTO|FADF_STATIC|FADF_EMBEDDED|FADF_FIXEDSIZE))
1082 RpcRaiseException(DISP_E_BADCALLEE);
1084 hr = SafeArrayDestroyData(*ppsa);
1085 if(FAILED(hr))
1086 RpcRaiseException(hr);
1088 memcpy((*ppsa)->rgsabound, wiresab, sizeof(*wiresab)*wiresa->cDims);
1090 if((*ppsa)->fFeatures & FADF_HAVEVARTYPE)
1091 ((DWORD*)(*ppsa))[-1] = vt;
1093 else if(vt)
1095 SafeArrayDestroy(*ppsa);
1096 *ppsa = SafeArrayCreateEx(vt, wiresa->cDims, wiresab, NULL);
1097 if (!*ppsa) RpcRaiseException(E_OUTOFMEMORY);
1099 else
1101 SafeArrayDestroy(*ppsa);
1102 if (FAILED(SafeArrayAllocDescriptor(wiresa->cDims, ppsa)))
1103 RpcRaiseException(E_OUTOFMEMORY);
1104 memcpy((*ppsa)->rgsabound, wiresab, sizeof(SAFEARRAYBOUND) * wiresa->cDims);
1107 /* be careful about which flags we set since they could be a security
1108 * risk */
1109 (*ppsa)->fFeatures &= FADF_AUTOSETFLAGS;
1110 (*ppsa)->fFeatures |= (wiresa->fFeatures & ~(FADF_AUTOSETFLAGS));
1111 /* FIXME: there should be a limit on how large wiresa->cbElements can be */
1112 (*ppsa)->cbElements = elem_mem_size(wiresa, sftype);
1114 /* SafeArrayCreateEx allocates the data for us, but
1115 * SafeArrayAllocDescriptor doesn't */
1116 if(!(*ppsa)->pvData)
1118 hr = SafeArrayAllocData(*ppsa);
1119 if (FAILED(hr))
1120 RpcRaiseException(hr);
1123 if ((*(ULONG *)Buffer != cell_count) || (SAFEARRAY_GetCellCount(*ppsa) != cell_count))
1124 RpcRaiseException(RPC_S_INVALID_BOUND);
1125 Buffer += sizeof(ULONG);
1127 if (ptr)
1129 switch (sftype)
1131 case SF_BSTR:
1133 BSTR* lpBstr;
1135 for (lpBstr = (*ppsa)->pvData; cell_count; cell_count--, lpBstr++)
1136 Buffer = BSTR_UserUnmarshal(pFlags, Buffer, lpBstr);
1138 break;
1140 case SF_DISPATCH:
1141 case SF_UNKNOWN:
1142 case SF_HAVEIID:
1144 IUnknown **lpUnk;
1145 const GUID *iid;
1147 if (sftype == SF_HAVEIID)
1148 iid = &guid;
1149 else if (sftype == SF_UNKNOWN)
1150 iid = &IID_IUnknown;
1151 else
1152 iid = &IID_IDispatch;
1154 for (lpUnk = (*ppsa)->pvData; cell_count; cell_count--, lpUnk++)
1155 Buffer = interface_user_unmarshal(pFlags, Buffer, iid, lpUnk);
1157 break;
1159 case SF_VARIANT:
1161 VARIANT* lpVariant;
1163 for (lpVariant = (*ppsa)->pvData; cell_count; cell_count--, lpVariant++)
1164 Buffer = VARIANT_UserUnmarshal(pFlags, Buffer, lpVariant);
1166 break;
1168 case SF_RECORD:
1170 FIXME("set record info\n");
1172 break;
1175 case SF_I8:
1176 ALIGN_POINTER(Buffer, 7);
1177 /* fallthrough */
1178 case SF_I1:
1179 case SF_I2:
1180 case SF_I4:
1181 /* Just copy the data over */
1182 memcpy((*ppsa)->pvData, Buffer, cell_count * (*ppsa)->cbElements);
1183 Buffer += cell_count * (*ppsa)->cbElements;
1184 break;
1185 default:
1186 break;
1190 TRACE("safe array unmarshaled: %p\n", *ppsa);
1192 return Buffer;
1195 void WINAPI LPSAFEARRAY_UserFree(ULONG *pFlags, LPSAFEARRAY *ppsa)
1197 TRACE("("); dump_user_flags(pFlags); TRACE(", &%p\n", *ppsa);
1199 SafeArrayDestroy(*ppsa);
1200 *ppsa = NULL;
1204 ULONG WINAPI HFONT_UserSize(ULONG *pFlags, ULONG Start, HFONT *phfont)
1206 FIXME(":stub\n");
1207 return 0;
1210 unsigned char * WINAPI HFONT_UserMarshal(ULONG *pFlags, unsigned char *Buffer, HFONT *phfont)
1212 FIXME(":stub\n");
1213 return NULL;
1216 unsigned char * WINAPI HFONT_UserUnmarshal(ULONG *pFlags, unsigned char *Buffer, HFONT *phfont)
1218 FIXME(":stub\n");
1219 return NULL;
1222 void WINAPI HFONT_UserFree(ULONG *pFlags, HFONT *phfont)
1224 FIXME(":stub\n");
1225 return;
1229 /* IDispatch */
1230 /* exactly how Invoke is marshalled is not very clear to me yet,
1231 * but the way I've done it seems to work for me */
1233 HRESULT CALLBACK IDispatch_Invoke_Proxy(
1234 IDispatch* This,
1235 DISPID dispIdMember,
1236 REFIID riid,
1237 LCID lcid,
1238 WORD wFlags,
1239 DISPPARAMS* pDispParams,
1240 VARIANT* pVarResult,
1241 EXCEPINFO* pExcepInfo,
1242 UINT* puArgErr)
1244 HRESULT hr;
1245 VARIANT VarResult;
1246 UINT* rgVarRefIdx = NULL;
1247 VARIANTARG* rgVarRef = NULL;
1248 UINT u, cVarRef;
1249 UINT uArgErr;
1250 EXCEPINFO ExcepInfo;
1252 TRACE("%p, %ld, %s, %#lx, %x, %p, %p, %p, %p.\n", This,
1253 dispIdMember, debugstr_guid(riid),
1254 lcid, wFlags, pDispParams, pVarResult,
1255 pExcepInfo, puArgErr);
1257 /* [out] args can't be null, use dummy vars if needed */
1258 if (!pVarResult) pVarResult = &VarResult;
1259 if (!puArgErr) puArgErr = &uArgErr;
1260 if (!pExcepInfo) pExcepInfo = &ExcepInfo;
1262 /* count by-ref args */
1263 for (cVarRef=0,u=0; u<pDispParams->cArgs; u++) {
1264 VARIANTARG* arg = &pDispParams->rgvarg[u];
1265 if (V_ISBYREF(arg)) {
1266 cVarRef++;
1269 if (cVarRef) {
1270 rgVarRefIdx = CoTaskMemAlloc(sizeof(UINT)*cVarRef);
1271 rgVarRef = CoTaskMemAlloc(sizeof(VARIANTARG)*cVarRef);
1272 /* make list of by-ref args */
1273 for (cVarRef=0,u=0; u<pDispParams->cArgs; u++) {
1274 VARIANTARG* arg = &pDispParams->rgvarg[u];
1275 if (V_ISBYREF(arg)) {
1276 rgVarRefIdx[cVarRef] = u;
1277 VariantInit(&rgVarRef[cVarRef]);
1278 VariantCopy(&rgVarRef[cVarRef], arg);
1279 VariantClear(arg);
1280 cVarRef++;
1283 } else {
1284 /* [out] args still can't be null,
1285 * but we can point these anywhere in this case,
1286 * since they won't be written to when cVarRef is 0 */
1287 rgVarRefIdx = puArgErr;
1288 rgVarRef = pVarResult;
1290 TRACE("passed by ref: %d args\n", cVarRef);
1291 hr = IDispatch_RemoteInvoke_Proxy(This,
1292 dispIdMember,
1293 riid,
1294 lcid,
1295 wFlags,
1296 pDispParams,
1297 pVarResult,
1298 pExcepInfo,
1299 puArgErr,
1300 cVarRef,
1301 rgVarRefIdx,
1302 rgVarRef);
1303 if (cVarRef) {
1304 for (u=0; u<cVarRef; u++) {
1305 unsigned i = rgVarRefIdx[u];
1306 VariantCopy(&pDispParams->rgvarg[i],
1307 &rgVarRef[u]);
1308 VariantClear(&rgVarRef[u]);
1310 CoTaskMemFree(rgVarRef);
1311 CoTaskMemFree(rgVarRefIdx);
1314 if(pExcepInfo == &ExcepInfo)
1316 SysFreeString(pExcepInfo->bstrSource);
1317 SysFreeString(pExcepInfo->bstrDescription);
1318 SysFreeString(pExcepInfo->bstrHelpFile);
1320 return hr;
1323 HRESULT __RPC_STUB IDispatch_Invoke_Stub(
1324 IDispatch* This,
1325 DISPID dispIdMember,
1326 REFIID riid,
1327 LCID lcid,
1328 DWORD dwFlags,
1329 DISPPARAMS* pDispParams,
1330 VARIANT* pVarResult,
1331 EXCEPINFO* pExcepInfo,
1332 UINT* pArgErr,
1333 UINT cVarRef,
1334 UINT* rgVarRefIdx,
1335 VARIANTARG* rgVarRef)
1337 HRESULT hr = S_OK;
1338 VARIANTARG *rgvarg, *arg;
1339 UINT u;
1341 /* initialize out parameters, so that they can be marshalled
1342 * in case the real Invoke doesn't initialize them */
1343 VariantInit(pVarResult);
1344 memset(pExcepInfo, 0, sizeof(*pExcepInfo));
1345 *pArgErr = 0;
1347 /* let the real Invoke operate on a copy of the in parameters,
1348 * so we don't risk losing pointers to allocated memory */
1349 rgvarg = pDispParams->rgvarg;
1350 arg = CoTaskMemAlloc(sizeof(VARIANTARG)*pDispParams->cArgs);
1351 if (!arg) return E_OUTOFMEMORY;
1353 /* init all args so we can call VariantClear on all the args if the copy
1354 * below fails */
1355 for (u = 0; u < pDispParams->cArgs; u++)
1356 VariantInit(&arg[u]);
1358 for (u = 0; u < pDispParams->cArgs; u++) {
1359 hr = VariantCopy(&arg[u], &rgvarg[u]);
1360 if (FAILED(hr))
1361 break;
1364 if (SUCCEEDED(hr)) {
1365 /* copy ref args to arg array */
1366 for (u=0; u<cVarRef; u++) {
1367 unsigned i = rgVarRefIdx[u];
1368 VariantCopy(&arg[i], &rgVarRef[u]);
1371 pDispParams->rgvarg = arg;
1373 hr = IDispatch_Invoke(This,
1374 dispIdMember,
1375 riid,
1376 lcid,
1377 dwFlags,
1378 pDispParams,
1379 pVarResult,
1380 pExcepInfo,
1381 pArgErr);
1383 /* copy ref args from arg array */
1384 for (u=0; u<cVarRef; u++) {
1385 unsigned i = rgVarRefIdx[u];
1386 VariantCopy(&rgVarRef[u], &arg[i]);
1390 /* clear the duplicate argument list */
1391 for (u=0; u<pDispParams->cArgs; u++)
1392 VariantClear(&arg[u]);
1394 pDispParams->rgvarg = rgvarg;
1395 CoTaskMemFree(arg);
1397 return hr;
1400 /* IEnumVARIANT */
1402 HRESULT CALLBACK IEnumVARIANT_Next_Proxy(
1403 IEnumVARIANT* This,
1404 ULONG celt,
1405 VARIANT* rgVar,
1406 ULONG* pCeltFetched)
1408 ULONG fetched;
1409 if (!pCeltFetched)
1410 pCeltFetched = &fetched;
1411 return IEnumVARIANT_RemoteNext_Proxy(This,
1412 celt,
1413 rgVar,
1414 pCeltFetched);
1417 HRESULT __RPC_STUB IEnumVARIANT_Next_Stub(
1418 IEnumVARIANT* This,
1419 ULONG celt,
1420 VARIANT* rgVar,
1421 ULONG* pCeltFetched)
1423 HRESULT hr;
1424 *pCeltFetched = 0;
1425 hr = IEnumVARIANT_Next(This,
1426 celt,
1427 rgVar,
1428 pCeltFetched);
1429 if (hr == S_OK) *pCeltFetched = celt;
1430 return hr;
1433 /* TypeInfo related freers */
1435 static void free_embedded_typedesc(TYPEDESC *tdesc);
1436 static void free_embedded_arraydesc(ARRAYDESC *adesc)
1438 switch(adesc->tdescElem.vt)
1440 case VT_PTR:
1441 case VT_SAFEARRAY:
1442 free_embedded_typedesc(adesc->tdescElem.lptdesc);
1443 CoTaskMemFree(adesc->tdescElem.lptdesc);
1444 break;
1445 case VT_CARRAY:
1446 free_embedded_arraydesc(adesc->tdescElem.lpadesc);
1447 CoTaskMemFree(adesc->tdescElem.lpadesc);
1448 break;
1452 static void free_embedded_typedesc(TYPEDESC *tdesc)
1454 switch(tdesc->vt)
1456 case VT_PTR:
1457 case VT_SAFEARRAY:
1458 free_embedded_typedesc(tdesc->lptdesc);
1459 CoTaskMemFree(tdesc->lptdesc);
1460 break;
1461 case VT_CARRAY:
1462 free_embedded_arraydesc(tdesc->lpadesc);
1463 CoTaskMemFree(tdesc->lpadesc);
1464 break;
1468 static void free_embedded_elemdesc(ELEMDESC *edesc)
1470 free_embedded_typedesc(&edesc->tdesc);
1471 if(edesc->paramdesc.wParamFlags & PARAMFLAG_FHASDEFAULT)
1472 CoTaskMemFree(edesc->paramdesc.pparamdescex);
1475 /* ITypeComp */
1477 HRESULT CALLBACK ITypeComp_Bind_Proxy(
1478 ITypeComp* This,
1479 LPOLESTR name,
1480 ULONG lHashVal,
1481 WORD flags,
1482 ITypeInfo **ti,
1483 DESCKIND *desckind,
1484 BINDPTR *bindptr)
1486 CLEANLOCALSTORAGE stg = { 0 };
1487 ITypeComp *typecomp;
1488 FUNCDESC *funcdesc;
1489 VARDESC *vardesc;
1490 HRESULT hr;
1492 TRACE("%p, %s, %#lx, %#x, %p, %p, %p.\n", This, debugstr_w(name), lHashVal, flags, ti,
1493 desckind, bindptr);
1495 *desckind = DESCKIND_NONE;
1496 memset(bindptr, 0, sizeof(*bindptr));
1498 hr = ITypeComp_RemoteBind_Proxy(This, name, lHashVal, flags, ti, desckind,
1499 &funcdesc, &vardesc, &typecomp, &stg);
1501 if (hr == S_OK)
1503 switch (*desckind)
1505 case DESCKIND_FUNCDESC:
1506 bindptr->lpfuncdesc = funcdesc;
1507 break;
1508 case DESCKIND_VARDESC:
1509 case DESCKIND_IMPLICITAPPOBJ:
1510 bindptr->lpvardesc = vardesc;
1511 break;
1512 case DESCKIND_TYPECOMP:
1513 bindptr->lptcomp = typecomp;
1514 break;
1515 default:
1520 return hr;
1523 HRESULT __RPC_STUB ITypeComp_Bind_Stub(
1524 ITypeComp* This,
1525 LPOLESTR name,
1526 ULONG lHashVal,
1527 WORD flags,
1528 ITypeInfo **ti,
1529 DESCKIND *desckind,
1530 FUNCDESC **funcdesc,
1531 VARDESC **vardesc,
1532 ITypeComp **typecomp,
1533 CLEANLOCALSTORAGE *stg)
1535 BINDPTR bindptr;
1536 HRESULT hr;
1538 TRACE("%p, %s, %#lx, %#x, %p, %p, %p, %p, %p, %p.\n", This, debugstr_w(name),
1539 lHashVal, flags, ti, desckind, funcdesc, vardesc, typecomp, stg);
1541 memset(stg, 0, sizeof(*stg));
1542 memset(&bindptr, 0, sizeof(bindptr));
1544 *funcdesc = NULL;
1545 *vardesc = NULL;
1546 *typecomp = NULL;
1547 *ti = NULL;
1549 hr = ITypeComp_Bind(This, name, lHashVal, flags, ti, desckind, &bindptr);
1550 if(hr != S_OK)
1551 return hr;
1553 switch (*desckind)
1555 case DESCKIND_FUNCDESC:
1556 *funcdesc = bindptr.lpfuncdesc;
1557 stg->pInterface = (IUnknown*)*ti;
1558 stg->pStorage = funcdesc;
1559 stg->flags = CLS_FUNCDESC;
1560 break;
1561 case DESCKIND_VARDESC:
1562 case DESCKIND_IMPLICITAPPOBJ:
1563 *vardesc = bindptr.lpvardesc;
1564 stg->pInterface = (IUnknown*)*ti;
1565 stg->pStorage = vardesc;
1566 stg->flags = CLS_VARDESC;
1567 break;
1568 case DESCKIND_TYPECOMP:
1569 *typecomp = bindptr.lptcomp;
1570 break;
1571 default:
1575 if (stg->pInterface)
1576 IUnknown_AddRef(stg->pInterface);
1578 return hr;
1581 HRESULT CALLBACK ITypeComp_BindType_Proxy(
1582 ITypeComp* This,
1583 LPOLESTR name,
1584 ULONG lHashVal,
1585 ITypeInfo **ti,
1586 ITypeComp **typecomp)
1588 HRESULT hr;
1590 TRACE("%p, %s, %#lx, %p, %p.\n", This, debugstr_w(name), lHashVal, ti, typecomp);
1592 hr = ITypeComp_RemoteBindType_Proxy(This, name, lHashVal, ti);
1593 if (hr == S_OK)
1594 ITypeInfo_GetTypeComp(*ti, typecomp);
1595 else if (typecomp)
1596 *typecomp = NULL;
1598 return hr;
1601 HRESULT __RPC_STUB ITypeComp_BindType_Stub(
1602 ITypeComp* This,
1603 LPOLESTR name,
1604 ULONG lHashVal,
1605 ITypeInfo **ti)
1607 ITypeComp *typecomp = NULL;
1608 HRESULT hr;
1610 TRACE("%p, %s, %#lx, %p.\n", This, debugstr_w(name), lHashVal, ti);
1612 hr = ITypeComp_BindType(This, name, lHashVal, ti, &typecomp);
1614 if (typecomp)
1615 ITypeComp_Release(typecomp);
1617 return hr;
1620 /* ITypeInfo */
1622 HRESULT CALLBACK ITypeInfo_GetTypeAttr_Proxy(
1623 ITypeInfo* This,
1624 TYPEATTR** ppTypeAttr)
1627 CLEANLOCALSTORAGE stg;
1628 TRACE("(%p, %p)\n", This, ppTypeAttr);
1630 stg.flags = 0;
1631 stg.pStorage = NULL;
1632 stg.pInterface = NULL;
1634 return ITypeInfo_RemoteGetTypeAttr_Proxy(This, ppTypeAttr, &stg);
1637 HRESULT __RPC_STUB ITypeInfo_GetTypeAttr_Stub(
1638 ITypeInfo* This,
1639 LPTYPEATTR* ppTypeAttr,
1640 CLEANLOCALSTORAGE* pDummy)
1642 HRESULT hr;
1643 TRACE("(%p, %p)\n", This, ppTypeAttr);
1645 hr = ITypeInfo_GetTypeAttr(This, ppTypeAttr);
1646 if(hr != S_OK)
1647 return hr;
1649 pDummy->flags = CLS_TYPEATTR;
1650 ITypeInfo_AddRef(This);
1651 pDummy->pInterface = (IUnknown*)This;
1652 pDummy->pStorage = ppTypeAttr;
1653 return hr;
1656 HRESULT CALLBACK ITypeInfo_GetFuncDesc_Proxy(
1657 ITypeInfo* This,
1658 UINT index,
1659 FUNCDESC** ppFuncDesc)
1661 CLEANLOCALSTORAGE stg;
1662 TRACE("(%p, %d, %p)\n", This, index, ppFuncDesc);
1664 stg.flags = 0;
1665 stg.pStorage = NULL;
1666 stg.pInterface = NULL;
1668 return ITypeInfo_RemoteGetFuncDesc_Proxy(This, index, ppFuncDesc, &stg);
1671 HRESULT __RPC_STUB ITypeInfo_GetFuncDesc_Stub(
1672 ITypeInfo* This,
1673 UINT index,
1674 LPFUNCDESC* ppFuncDesc,
1675 CLEANLOCALSTORAGE* pDummy)
1677 HRESULT hr;
1678 TRACE("(%p, %d, %p)\n", This, index, ppFuncDesc);
1680 hr = ITypeInfo_GetFuncDesc(This, index, ppFuncDesc);
1681 if(hr != S_OK)
1682 return hr;
1684 pDummy->flags = CLS_FUNCDESC;
1685 ITypeInfo_AddRef(This);
1686 pDummy->pInterface = (IUnknown*)This;
1687 pDummy->pStorage = ppFuncDesc;
1688 return hr;
1691 HRESULT CALLBACK ITypeInfo_GetVarDesc_Proxy(
1692 ITypeInfo* This,
1693 UINT index,
1694 VARDESC** ppVarDesc)
1696 CLEANLOCALSTORAGE stg;
1697 TRACE("(%p, %d, %p)\n", This, index, ppVarDesc);
1699 stg.flags = 0;
1700 stg.pStorage = NULL;
1701 stg.pInterface = NULL;
1703 return ITypeInfo_RemoteGetVarDesc_Proxy(This, index, ppVarDesc, &stg);
1706 HRESULT __RPC_STUB ITypeInfo_GetVarDesc_Stub(
1707 ITypeInfo* This,
1708 UINT index,
1709 LPVARDESC* ppVarDesc,
1710 CLEANLOCALSTORAGE* pDummy)
1712 HRESULT hr;
1713 TRACE("(%p, %d, %p)\n", This, index, ppVarDesc);
1715 hr = ITypeInfo_GetVarDesc(This, index, ppVarDesc);
1716 if(hr != S_OK)
1717 return hr;
1719 pDummy->flags = CLS_VARDESC;
1720 ITypeInfo_AddRef(This);
1721 pDummy->pInterface = (IUnknown*)This;
1722 pDummy->pStorage = ppVarDesc;
1723 return hr;
1726 HRESULT CALLBACK ITypeInfo_GetNames_Proxy(
1727 ITypeInfo* This,
1728 MEMBERID memid,
1729 BSTR* rgBstrNames,
1730 UINT cMaxNames,
1731 UINT* pcNames)
1733 TRACE("%p, %#lx, %p, %d, %p.\n", This, memid, rgBstrNames, cMaxNames, pcNames);
1735 return ITypeInfo_RemoteGetNames_Proxy(This, memid, rgBstrNames, cMaxNames, pcNames);
1738 HRESULT __RPC_STUB ITypeInfo_GetNames_Stub(
1739 ITypeInfo* This,
1740 MEMBERID memid,
1741 BSTR* rgBstrNames,
1742 UINT cMaxNames,
1743 UINT* pcNames)
1745 TRACE("%p, %#lx, %p, %d, %p.\n", This, memid, rgBstrNames, cMaxNames, pcNames);
1747 return ITypeInfo_GetNames(This, memid, rgBstrNames, cMaxNames, pcNames);
1750 HRESULT CALLBACK ITypeInfo_GetIDsOfNames_Proxy(
1751 ITypeInfo* This,
1752 LPOLESTR* rgszNames,
1753 UINT cNames,
1754 MEMBERID* pMemId)
1756 FIXME("not implemented\n");
1757 return E_FAIL;
1760 HRESULT __RPC_STUB ITypeInfo_GetIDsOfNames_Stub(
1761 ITypeInfo* This)
1763 FIXME("not implemented\n");
1764 return E_FAIL;
1767 HRESULT CALLBACK ITypeInfo_Invoke_Proxy(
1768 ITypeInfo* This,
1769 PVOID pvInstance,
1770 MEMBERID memid,
1771 WORD wFlags,
1772 DISPPARAMS* pDispParams,
1773 VARIANT* pVarResult,
1774 EXCEPINFO* pExcepInfo,
1775 UINT* puArgErr)
1777 FIXME("not implemented\n");
1778 return E_FAIL;
1781 HRESULT __RPC_STUB ITypeInfo_Invoke_Stub(
1782 ITypeInfo* This)
1784 FIXME("not implemented\n");
1785 return E_FAIL;
1788 HRESULT CALLBACK ITypeInfo_GetDocumentation_Proxy(ITypeInfo *This, MEMBERID memid,
1789 BSTR *name, BSTR *doc_string,
1790 DWORD *help_context, BSTR *help_file)
1792 DWORD dummy_help_context, flags = 0;
1793 BSTR dummy_name, dummy_doc_string, dummy_help_file;
1794 HRESULT hr;
1796 TRACE("%p, %#lx, %p, %p, %p, %p.\n", This, memid, name, doc_string, help_context, help_file);
1798 if(!name) name = &dummy_name;
1799 else flags = 1;
1801 if(!doc_string) doc_string = &dummy_doc_string;
1802 else flags |= 2;
1804 if(!help_context) help_context = &dummy_help_context;
1805 else flags |= 4;
1807 if(!help_file) help_file = &dummy_help_file;
1808 else flags |= 8;
1810 hr = ITypeInfo_RemoteGetDocumentation_Proxy(This, memid, flags, name, doc_string, help_context, help_file);
1812 /* We don't need to free the dummy BSTRs since the stub ensures that these will be NULLs. */
1814 return hr;
1817 HRESULT __RPC_STUB ITypeInfo_GetDocumentation_Stub(ITypeInfo *This, MEMBERID memid,
1818 DWORD flags, BSTR *name, BSTR *doc_string,
1819 DWORD *help_context, BSTR *help_file)
1821 TRACE("%p, %#lx, %#lx, %p, %p, %p, %p.\n", This, memid, flags, name, doc_string, help_context, help_file);
1823 *name = *doc_string = *help_file = NULL;
1824 *help_context = 0;
1826 if(!(flags & 1)) name = NULL;
1827 if(!(flags & 2)) doc_string = NULL;
1828 if(!(flags & 4)) help_context = NULL;
1829 if(!(flags & 8)) help_file = NULL;
1831 return ITypeInfo_GetDocumentation(This, memid, name, doc_string, help_context, help_file);
1834 HRESULT CALLBACK ITypeInfo_GetDllEntry_Proxy(ITypeInfo *This, MEMBERID memid,
1835 INVOKEKIND invkind, BSTR *dll_name,
1836 BSTR* name, WORD *ordinal)
1838 DWORD flags = 0;
1839 BSTR dummy_dll_name, dummy_name;
1840 WORD dummy_ordinal;
1841 HRESULT hr;
1843 TRACE("%p, %#lx, %#x, %p, %p, %p.\n", This, memid, invkind, dll_name, name, ordinal);
1845 if(!dll_name) dll_name = &dummy_dll_name;
1846 else flags = 1;
1848 if(!name) name = &dummy_name;
1849 else flags |= 2;
1851 if(!ordinal) ordinal = &dummy_ordinal;
1852 else flags |= 4;
1854 hr = ITypeInfo_RemoteGetDllEntry_Proxy(This, memid, invkind, flags, dll_name, name, ordinal);
1856 /* We don't need to free the dummy BSTRs since the stub ensures that these will be NULLs. */
1858 return hr;
1861 HRESULT __RPC_STUB ITypeInfo_GetDllEntry_Stub(ITypeInfo *This, MEMBERID memid,
1862 INVOKEKIND invkind, DWORD flags,
1863 BSTR *dll_name, BSTR *name,
1864 WORD *ordinal)
1866 TRACE("%p, %#lx, %x, %p, %p, %p.\n", This, memid, invkind, dll_name, name, ordinal);
1868 *dll_name = *name = NULL;
1869 *ordinal = 0;
1871 if(!(flags & 1)) dll_name = NULL;
1872 if(!(flags & 2)) name = NULL;
1873 if(!(flags & 4)) ordinal = NULL;
1875 return ITypeInfo_GetDllEntry(This, memid, invkind, dll_name, name, ordinal);
1878 HRESULT CALLBACK ITypeInfo_AddressOfMember_Proxy(
1879 ITypeInfo* This,
1880 MEMBERID memid,
1881 INVOKEKIND invKind,
1882 PVOID* ppv)
1884 FIXME("not implemented\n");
1885 return E_FAIL;
1888 HRESULT __RPC_STUB ITypeInfo_AddressOfMember_Stub(
1889 ITypeInfo* This)
1891 FIXME("not implemented\n");
1892 return E_FAIL;
1895 HRESULT CALLBACK ITypeInfo_CreateInstance_Proxy(
1896 ITypeInfo* This,
1897 IUnknown* pUnkOuter,
1898 REFIID riid,
1899 PVOID* ppvObj)
1901 FIXME("not implemented\n");
1902 return E_FAIL;
1905 HRESULT __RPC_STUB ITypeInfo_CreateInstance_Stub(
1906 ITypeInfo* This,
1907 REFIID riid,
1908 IUnknown** ppvObj)
1910 FIXME("not implemented\n");
1911 return E_FAIL;
1914 HRESULT CALLBACK ITypeInfo_GetContainingTypeLib_Proxy(
1915 ITypeInfo* This,
1916 ITypeLib** ppTLib,
1917 UINT* pIndex)
1919 ITypeLib *pTL;
1920 UINT index;
1921 HRESULT hr;
1923 TRACE("(%p, %p, %p)\n", This, ppTLib, pIndex );
1925 hr = ITypeInfo_RemoteGetContainingTypeLib_Proxy(This, &pTL, &index);
1926 if(SUCCEEDED(hr))
1928 if(pIndex)
1929 *pIndex = index;
1931 if(ppTLib)
1932 *ppTLib = pTL;
1933 else
1934 ITypeLib_Release(pTL);
1936 return hr;
1939 HRESULT __RPC_STUB ITypeInfo_GetContainingTypeLib_Stub(
1940 ITypeInfo* This,
1941 ITypeLib** ppTLib,
1942 UINT* pIndex)
1944 TRACE("(%p, %p, %p)\n", This, ppTLib, pIndex );
1945 return ITypeInfo_GetContainingTypeLib(This, ppTLib, pIndex);
1948 void CALLBACK ITypeInfo_ReleaseTypeAttr_Proxy(
1949 ITypeInfo* This,
1950 TYPEATTR* pTypeAttr)
1952 TRACE("(%p, %p)\n", This, pTypeAttr);
1953 free_embedded_typedesc(&pTypeAttr->tdescAlias);
1954 CoTaskMemFree(pTypeAttr);
1957 HRESULT __RPC_STUB ITypeInfo_ReleaseTypeAttr_Stub(
1958 ITypeInfo* This)
1960 TRACE("nothing to do\n");
1961 return S_OK;
1964 void CALLBACK ITypeInfo_ReleaseFuncDesc_Proxy(
1965 ITypeInfo* This,
1966 FUNCDESC* pFuncDesc)
1968 SHORT param;
1969 TRACE("(%p, %p)\n", This, pFuncDesc);
1971 for(param = 0; param < pFuncDesc->cParams; param++)
1972 free_embedded_elemdesc(pFuncDesc->lprgelemdescParam + param);
1973 if(param)
1974 CoTaskMemFree(pFuncDesc->lprgelemdescParam);
1976 free_embedded_elemdesc(&pFuncDesc->elemdescFunc);
1978 if(pFuncDesc->cScodes != 0 && pFuncDesc->cScodes != -1)
1979 CoTaskMemFree(pFuncDesc->lprgscode);
1981 CoTaskMemFree(pFuncDesc);
1984 HRESULT __RPC_STUB ITypeInfo_ReleaseFuncDesc_Stub(
1985 ITypeInfo* This)
1987 TRACE("nothing to do\n");
1988 return S_OK;
1991 void CALLBACK ITypeInfo_ReleaseVarDesc_Proxy(
1992 ITypeInfo* This,
1993 VARDESC* pVarDesc)
1995 TRACE("(%p, %p)\n", This, pVarDesc);
1997 CoTaskMemFree(pVarDesc->lpstrSchema);
1999 if(pVarDesc->varkind == VAR_CONST)
2000 CoTaskMemFree(pVarDesc->lpvarValue);
2002 free_embedded_elemdesc(&pVarDesc->elemdescVar);
2003 CoTaskMemFree(pVarDesc);
2006 HRESULT __RPC_STUB ITypeInfo_ReleaseVarDesc_Stub(
2007 ITypeInfo* This)
2009 TRACE("nothing to do\n");
2010 return S_OK;
2014 /* ITypeInfo2 */
2016 HRESULT CALLBACK ITypeInfo2_GetDocumentation2_Proxy(ITypeInfo2 *This, MEMBERID memid,
2017 LCID lcid, BSTR *help_string,
2018 DWORD *help_context, BSTR *help_dll)
2020 DWORD dummy_help_context, flags = 0;
2021 BSTR dummy_help_string, dummy_help_dll;
2022 HRESULT hr;
2024 TRACE("%p, %#lx, %#lx, %p, %p, %p.\n", This, memid, lcid, help_string, help_context, help_dll);
2026 if(!help_string) help_string = &dummy_help_string;
2027 else flags = 1;
2029 if(!help_context) help_context = &dummy_help_context;
2030 else flags |= 2;
2032 if(!help_dll) help_dll = &dummy_help_dll;
2033 else flags |= 4;
2035 hr = ITypeInfo2_RemoteGetDocumentation2_Proxy(This, memid, lcid, flags, help_string, help_context, help_dll);
2037 /* We don't need to free the dummy BSTRs since the stub ensures that these will be NULLs. */
2039 return hr;
2042 HRESULT __RPC_STUB ITypeInfo2_GetDocumentation2_Stub(ITypeInfo2 *This, MEMBERID memid,
2043 LCID lcid, DWORD flags,
2044 BSTR *help_string, DWORD *help_context,
2045 BSTR *help_dll)
2047 TRACE("%p, %#lx, %#lx, %#lx, %p, %p, %p.\n", This, memid, lcid, flags, help_string, help_context, help_dll);
2049 *help_string = *help_dll = NULL;
2050 *help_context = 0;
2052 if(!(flags & 1)) help_string = NULL;
2053 if(!(flags & 2)) help_context = NULL;
2054 if(!(flags & 4)) help_dll = NULL;
2056 return ITypeInfo2_GetDocumentation2(This, memid, lcid, help_string, help_context, help_dll);
2059 /* ITypeLib */
2061 UINT CALLBACK ITypeLib_GetTypeInfoCount_Proxy(
2062 ITypeLib* This)
2064 UINT count = 0;
2065 TRACE("(%p)\n", This);
2067 ITypeLib_RemoteGetTypeInfoCount_Proxy(This, &count);
2069 return count;
2072 HRESULT __RPC_STUB ITypeLib_GetTypeInfoCount_Stub(
2073 ITypeLib* This,
2074 UINT* pcTInfo)
2076 TRACE("(%p, %p)\n", This, pcTInfo);
2077 *pcTInfo = ITypeLib_GetTypeInfoCount(This);
2078 return S_OK;
2081 HRESULT CALLBACK ITypeLib_GetLibAttr_Proxy(
2082 ITypeLib* This,
2083 TLIBATTR** ppTLibAttr)
2085 CLEANLOCALSTORAGE stg;
2086 TRACE("(%p, %p)\n", This, ppTLibAttr);
2088 stg.flags = 0;
2089 stg.pStorage = NULL;
2090 stg.pInterface = NULL;
2092 return ITypeLib_RemoteGetLibAttr_Proxy(This, ppTLibAttr, &stg);
2095 HRESULT __RPC_STUB ITypeLib_GetLibAttr_Stub(
2096 ITypeLib* This,
2097 LPTLIBATTR* ppTLibAttr,
2098 CLEANLOCALSTORAGE* pDummy)
2100 HRESULT hr;
2101 TRACE("(%p, %p)\n", This, ppTLibAttr);
2103 hr = ITypeLib_GetLibAttr(This, ppTLibAttr);
2104 if(hr != S_OK)
2105 return hr;
2107 pDummy->flags = CLS_LIBATTR;
2108 ITypeLib_AddRef(This);
2109 pDummy->pInterface = (IUnknown*)This;
2110 pDummy->pStorage = ppTLibAttr;
2111 return hr;
2114 HRESULT CALLBACK ITypeLib_GetDocumentation_Proxy(ITypeLib *This, INT index, BSTR *name,
2115 BSTR *doc_string, DWORD *help_context,
2116 BSTR *help_file)
2118 DWORD dummy_help_context, flags = 0;
2119 BSTR dummy_name, dummy_doc_string, dummy_help_file;
2120 HRESULT hr;
2121 TRACE("(%p, %d, %p, %p, %p, %p)\n", This, index, name, doc_string, help_context, help_file);
2123 if(!name) name = &dummy_name;
2124 else flags = 1;
2126 if(!doc_string) doc_string = &dummy_doc_string;
2127 else flags |= 2;
2129 if(!help_context) help_context = &dummy_help_context;
2130 else flags |= 4;
2132 if(!help_file) help_file = &dummy_help_file;
2133 else flags |= 8;
2135 hr = ITypeLib_RemoteGetDocumentation_Proxy(This, index, flags, name, doc_string, help_context, help_file);
2137 /* We don't need to free the dummy BSTRs since the stub ensures that these will be NULLs. */
2139 return hr;
2142 HRESULT __RPC_STUB ITypeLib_GetDocumentation_Stub(ITypeLib *This, INT index, DWORD flags,
2143 BSTR *name, BSTR *doc_string,
2144 DWORD *help_context, BSTR *help_file)
2146 TRACE("%p, %d, %#lx, %p, %p, %p, %p.\n", This, index, flags, name, doc_string, help_context, help_file);
2148 *name = *doc_string = *help_file = NULL;
2149 *help_context = 0;
2151 if(!(flags & 1)) name = NULL;
2152 if(!(flags & 2)) doc_string = NULL;
2153 if(!(flags & 4)) help_context = NULL;
2154 if(!(flags & 8)) help_file = NULL;
2156 return ITypeLib_GetDocumentation(This, index, name, doc_string, help_context, help_file);
2159 HRESULT CALLBACK ITypeLib_IsName_Proxy(
2160 ITypeLib* This,
2161 LPOLESTR szNameBuf,
2162 ULONG lHashVal,
2163 BOOL* pfName)
2165 FIXME("not implemented\n");
2166 return E_FAIL;
2169 HRESULT __RPC_STUB ITypeLib_IsName_Stub(
2170 ITypeLib* This,
2171 LPOLESTR szNameBuf,
2172 ULONG lHashVal,
2173 BOOL* pfName,
2174 BSTR* pBstrLibName)
2176 FIXME("not implemented\n");
2177 return E_FAIL;
2180 HRESULT CALLBACK ITypeLib_FindName_Proxy(
2181 ITypeLib* This,
2182 LPOLESTR szNameBuf,
2183 ULONG lHashVal,
2184 ITypeInfo** ppTInfo,
2185 MEMBERID* rgMemId,
2186 USHORT* pcFound)
2188 FIXME("not implemented\n");
2189 return E_FAIL;
2192 HRESULT __RPC_STUB ITypeLib_FindName_Stub(
2193 ITypeLib* This,
2194 LPOLESTR szNameBuf,
2195 ULONG lHashVal,
2196 ITypeInfo** ppTInfo,
2197 MEMBERID* rgMemId,
2198 USHORT* pcFound,
2199 BSTR* pBstrLibName)
2201 FIXME("not implemented\n");
2202 return E_FAIL;
2205 void CALLBACK ITypeLib_ReleaseTLibAttr_Proxy(
2206 ITypeLib* This,
2207 TLIBATTR* pTLibAttr)
2209 TRACE("(%p, %p)\n", This, pTLibAttr);
2210 CoTaskMemFree(pTLibAttr);
2213 HRESULT __RPC_STUB ITypeLib_ReleaseTLibAttr_Stub(
2214 ITypeLib* This)
2216 TRACE("nothing to do\n");
2217 return S_OK;
2221 /* ITypeLib2 */
2223 HRESULT CALLBACK ITypeLib2_GetLibStatistics_Proxy(
2224 ITypeLib2* This,
2225 ULONG* pcUniqueNames,
2226 ULONG* pcchUniqueNames)
2228 FIXME("not implemented\n");
2229 return E_FAIL;
2232 HRESULT __RPC_STUB ITypeLib2_GetLibStatistics_Stub(
2233 ITypeLib2* This,
2234 ULONG* pcUniqueNames,
2235 ULONG* pcchUniqueNames)
2237 FIXME("not implemented\n");
2238 return E_FAIL;
2241 HRESULT CALLBACK ITypeLib2_GetDocumentation2_Proxy(ITypeLib2 *This, INT index,
2242 LCID lcid, BSTR *help_string,
2243 DWORD *help_context, BSTR *help_dll)
2245 DWORD dummy_help_context, flags = 0;
2246 BSTR dummy_help_string, dummy_help_dll;
2247 HRESULT hr;
2249 TRACE("%p, %d, %#lx, %p, %p, %p.\n", This, index, lcid, help_string, help_context, help_dll);
2251 if(!help_string) help_string = &dummy_help_string;
2252 else flags = 1;
2254 if(!help_context) help_context = &dummy_help_context;
2255 else flags |= 2;
2257 if(!help_dll) help_dll = &dummy_help_dll;
2258 else flags |= 4;
2260 hr = ITypeLib2_RemoteGetDocumentation2_Proxy(This, index, lcid, flags, help_string, help_context, help_dll);
2262 /* We don't need to free the dummy BSTRs since the stub ensures that these will be NULLs. */
2264 return hr;
2267 HRESULT __RPC_STUB ITypeLib2_GetDocumentation2_Stub(ITypeLib2 *This, INT index, LCID lcid,
2268 DWORD flags, BSTR *help_string,
2269 DWORD *help_context, BSTR *help_dll)
2271 TRACE("%p, %d, %#lx, %#lx, %p, %p, %p.\n", This, index, lcid, flags, help_string, help_context, help_dll);
2273 *help_string = *help_dll = NULL;
2274 *help_context = 0;
2276 if(!(flags & 1)) help_string = NULL;
2277 if(!(flags & 2)) help_context = NULL;
2278 if(!(flags & 4)) help_dll = NULL;
2280 return ITypeLib2_GetDocumentation2(This, index, lcid, help_string, help_context, help_dll);
2283 HRESULT CALLBACK IPropertyBag_Read_Proxy(
2284 IPropertyBag* This,
2285 LPCOLESTR pszPropName,
2286 VARIANT *pVar,
2287 IErrorLog *pErrorLog)
2289 IUnknown *pUnk = NULL;
2290 TRACE("(%p, %s, %p, %p)\n", This, debugstr_w(pszPropName), pVar, pErrorLog);
2292 if(!pVar)
2293 return E_POINTER;
2295 if(V_VT(pVar) & (VT_BYREF | VT_ARRAY | VT_VECTOR))
2297 FIXME("Variant type %x is byref, array or vector. Not implemented.\n", V_VT(pVar));
2298 return E_NOTIMPL;
2301 switch(V_VT(pVar))
2303 case VT_DISPATCH:
2304 pUnk = (IUnknown*)V_DISPATCH(pVar);
2305 break;
2306 case VT_UNKNOWN:
2307 pUnk = V_UNKNOWN(pVar);
2308 break;
2309 case VT_SAFEARRAY:
2310 FIXME("Safearray support not yet implemented.\n");
2311 return E_NOTIMPL;
2312 default:
2313 FIXME("Unknown V_VT %d - support not yet implemented.\n", V_VT(pVar));
2314 return E_NOTIMPL;
2317 return IPropertyBag_RemoteRead_Proxy(This, pszPropName, pVar, pErrorLog,
2318 V_VT(pVar), pUnk);
2321 HRESULT __RPC_STUB IPropertyBag_Read_Stub(
2322 IPropertyBag* This,
2323 LPCOLESTR pszPropName,
2324 VARIANT *pVar,
2325 IErrorLog *pErrorLog,
2326 DWORD varType,
2327 IUnknown *pUnkObj)
2329 IDispatch *disp;
2330 HRESULT hr;
2332 TRACE("%p, %s, %p, %p, %lx, %p.\n", This, debugstr_w(pszPropName), pVar,
2333 pErrorLog, varType, pUnkObj);
2335 if(varType & (VT_BYREF | VT_ARRAY | VT_VECTOR))
2337 FIXME("Variant type %x is byref, array or vector. Not implemented.\n", V_VT(pVar));
2338 return E_NOTIMPL;
2341 V_VT(pVar) = varType;
2342 switch(varType)
2344 case VT_DISPATCH:
2345 hr = IUnknown_QueryInterface(pUnkObj, &IID_IDispatch, (LPVOID*)&disp);
2346 if(FAILED(hr))
2347 return hr;
2348 IUnknown_Release(pUnkObj);
2349 V_DISPATCH(pVar) = disp;
2350 break;
2351 case VT_UNKNOWN:
2352 V_UNKNOWN(pVar) = pUnkObj;
2353 break;
2354 case VT_BSTR:
2355 V_BSTR(pVar) = SysAllocString(L"");
2356 break;
2357 case VT_SAFEARRAY:
2358 FIXME("Safearray support not yet implemented.\n");
2359 return E_NOTIMPL;
2360 default:
2361 break;
2363 hr = IPropertyBag_Read(This, pszPropName, pVar, pErrorLog);
2364 if(FAILED(hr))
2365 VariantClear(pVar);
2367 return hr;
2370 /* call_as/local stubs for ocidl.idl */
2372 HRESULT CALLBACK IClassFactory2_CreateInstanceLic_Proxy(
2373 IClassFactory2* This,
2374 IUnknown *pUnkOuter,
2375 IUnknown *pUnkReserved,
2376 REFIID riid,
2377 BSTR bstrKey,
2378 PVOID *ppvObj)
2380 TRACE("(%p, %s, %p)\n", pUnkOuter, debugstr_guid(riid), ppvObj);
2382 *ppvObj = NULL;
2384 if (pUnkOuter)
2386 ERR("aggregation is not allowed on remote objects\n");
2387 return CLASS_E_NOAGGREGATION;
2390 return IClassFactory2_RemoteCreateInstanceLic_Proxy(This, riid, bstrKey, (IUnknown**)ppvObj);
2393 HRESULT __RPC_STUB IClassFactory2_CreateInstanceLic_Stub(
2394 IClassFactory2* This,
2395 REFIID riid,
2396 BSTR bstrKey,
2397 IUnknown **ppvObj)
2399 TRACE("(%s, %p)\n", debugstr_guid(riid), ppvObj);
2400 return IClassFactory2_CreateInstanceLic(This, NULL, NULL, riid, bstrKey, (void**)ppvObj);
2403 HRESULT CALLBACK IEnumConnections_Next_Proxy(
2404 IEnumConnections* This,
2405 ULONG cConnections,
2406 LPCONNECTDATA rgcd,
2407 ULONG *pcFetched)
2409 ULONG fetched;
2411 TRACE("%lu, %p, %p.\n", cConnections, rgcd, pcFetched);
2413 if (!pcFetched)
2414 pcFetched = &fetched;
2416 return IEnumConnections_RemoteNext_Proxy(This, cConnections, rgcd, pcFetched);
2419 HRESULT __RPC_STUB IEnumConnections_Next_Stub(
2420 IEnumConnections* This,
2421 ULONG cConnections,
2422 LPCONNECTDATA rgcd,
2423 ULONG *pcFetched)
2425 HRESULT hr;
2427 TRACE("%lu, %p, %p.\n", cConnections, rgcd, pcFetched);
2429 *pcFetched = 0;
2430 hr = IEnumConnections_Next(This, cConnections, rgcd, pcFetched);
2431 if (hr == S_OK)
2432 *pcFetched = cConnections;
2434 return hr;
2437 HRESULT CALLBACK IEnumConnectionPoints_Next_Proxy(
2438 IEnumConnectionPoints* This,
2439 ULONG cConnections,
2440 IConnectionPoint **ppCP,
2441 ULONG *pcFetched)
2443 ULONG fetched;
2445 TRACE("%lu, %p %p.\n", cConnections, ppCP, pcFetched);
2447 if (!pcFetched)
2448 pcFetched = &fetched;
2450 return IEnumConnectionPoints_RemoteNext_Proxy(This, cConnections, ppCP, pcFetched);
2453 HRESULT __RPC_STUB IEnumConnectionPoints_Next_Stub(
2454 IEnumConnectionPoints* This,
2455 ULONG cConnections,
2456 IConnectionPoint **ppCP,
2457 ULONG *pcFetched)
2459 HRESULT hr;
2461 TRACE("%lu, %p, %p.\n", cConnections, ppCP, pcFetched);
2463 *pcFetched = 0;
2464 hr = IEnumConnectionPoints_Next(This, cConnections, ppCP, pcFetched);
2465 if (hr == S_OK)
2466 *pcFetched = cConnections;
2468 return hr;
2471 HRESULT CALLBACK IPersistMemory_Load_Proxy(
2472 IPersistMemory* This,
2473 LPVOID pMem,
2474 ULONG cbSize)
2476 TRACE("%p, %lu.\n", pMem, cbSize);
2478 if (!pMem)
2479 return E_POINTER;
2481 return IPersistMemory_RemoteLoad_Proxy(This, pMem, cbSize);
2484 HRESULT __RPC_STUB IPersistMemory_Load_Stub(
2485 IPersistMemory* This,
2486 BYTE *pMem,
2487 ULONG cbSize)
2489 TRACE("%p, %lu.\n", pMem, cbSize);
2490 return IPersistMemory_Load(This, pMem, cbSize);
2493 HRESULT CALLBACK IPersistMemory_Save_Proxy(
2494 IPersistMemory* This,
2495 LPVOID pMem,
2496 BOOL fClearDirty,
2497 ULONG cbSize)
2499 TRACE("%p, %d, %lu.\n", pMem, fClearDirty, cbSize);
2501 if (!pMem)
2502 return E_POINTER;
2504 return IPersistMemory_RemoteSave_Proxy(This, pMem, fClearDirty, cbSize);
2507 HRESULT __RPC_STUB IPersistMemory_Save_Stub(
2508 IPersistMemory* This,
2509 BYTE *pMem,
2510 BOOL fClearDirty,
2511 ULONG cbSize)
2513 TRACE("%p, %d, %lu.\n", pMem, fClearDirty, cbSize);
2514 return IPersistMemory_Save(This, pMem, fClearDirty, cbSize);
2517 void CALLBACK IAdviseSinkEx_OnViewStatusChange_Proxy(
2518 IAdviseSinkEx* This,
2519 DWORD dwViewStatus)
2521 TRACE("%p, %#lx.\n", This, dwViewStatus);
2522 IAdviseSinkEx_RemoteOnViewStatusChange_Proxy(This, dwViewStatus);
2525 HRESULT __RPC_STUB IAdviseSinkEx_OnViewStatusChange_Stub(
2526 IAdviseSinkEx* This,
2527 DWORD dwViewStatus)
2529 TRACE("%p, %#lx.\n", This, dwViewStatus);
2530 IAdviseSinkEx_OnViewStatusChange(This, dwViewStatus);
2531 return S_OK;
2534 HRESULT CALLBACK IEnumOleUndoUnits_Next_Proxy(
2535 IEnumOleUndoUnits* This,
2536 ULONG cElt,
2537 IOleUndoUnit **rgElt,
2538 ULONG *pcEltFetched)
2540 ULONG fetched;
2542 TRACE("%lu, %p %p.\n", cElt, rgElt, pcEltFetched);
2544 if (!pcEltFetched)
2545 pcEltFetched = &fetched;
2547 return IEnumOleUndoUnits_RemoteNext_Proxy(This, cElt, rgElt, pcEltFetched);
2550 HRESULT __RPC_STUB IEnumOleUndoUnits_Next_Stub(
2551 IEnumOleUndoUnits* This,
2552 ULONG cElt,
2553 IOleUndoUnit **rgElt,
2554 ULONG *pcEltFetched)
2556 HRESULT hr;
2558 TRACE("%lu, %p, %p.\n", cElt, rgElt, pcEltFetched);
2560 *pcEltFetched = 0;
2561 hr = IEnumOleUndoUnits_Next(This, cElt, rgElt, pcEltFetched);
2562 if (hr == S_OK)
2563 *pcEltFetched = cElt;
2565 return hr;
2568 HRESULT CALLBACK IQuickActivate_QuickActivate_Proxy(
2569 IQuickActivate* This,
2570 QACONTAINER *pQaContainer,
2571 QACONTROL *pQaControl)
2573 FIXME("not implemented\n");
2574 return E_NOTIMPL;
2577 HRESULT __RPC_STUB IQuickActivate_QuickActivate_Stub(
2578 IQuickActivate* This,
2579 QACONTAINER *pQaContainer,
2580 QACONTROL *pQaControl)
2582 FIXME("not implemented\n");
2583 return E_NOTIMPL;