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
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
43 #define ALIGNED_LENGTH(_Len, _Align) (((_Len)+(_Align))&~(_Align))
44 #define ALIGNED_POINTER(_Ptr, _Align) ((LPVOID)ALIGNED_LENGTH((ULONG_PTR)(_Ptr), _Align))
45 #define ALIGN_LENGTH(_Len, _Align) _Len = ALIGNED_LENGTH(_Len, _Align)
46 #define ALIGN_POINTER(_Ptr, _Align) _Ptr = ALIGNED_POINTER(_Ptr, _Align)
48 static void dump_user_flags(const ULONG
*pFlags
)
50 if (HIWORD(*pFlags
) == NDR_LOCAL_DATA_REPRESENTATION
)
51 TRACE("MAKELONG(NDR_LOCAL_REPRESENTATION, ");
53 TRACE("MAKELONG(0x%04x, ", HIWORD(*pFlags
));
54 switch (LOWORD(*pFlags
))
56 case MSHCTX_LOCAL
: TRACE("MSHCTX_LOCAL)"); break;
57 case MSHCTX_NOSHAREDMEM
: TRACE("MSHCTX_NOSHAREDMEM)"); break;
58 case MSHCTX_DIFFERENTMACHINE
: TRACE("MSHCTX_DIFFERENTMACHINE)"); break;
59 case MSHCTX_INPROC
: TRACE("MSHCTX_INPROC)"); break;
60 default: TRACE("%d)", LOWORD(*pFlags
));
64 /* CLEANLOCALSTORAGE */
66 #define CLS_FUNCDESC 'f'
67 #define CLS_LIBATTR 'l'
68 #define CLS_TYPEATTR 't'
69 #define CLS_VARDESC 'v'
71 ULONG WINAPI
CLEANLOCALSTORAGE_UserSize(ULONG
*pFlags
, ULONG Start
, CLEANLOCALSTORAGE
*pstg
)
73 ALIGN_LENGTH(Start
, 3);
74 return Start
+ sizeof(DWORD
);
77 unsigned char * WINAPI
CLEANLOCALSTORAGE_UserMarshal(ULONG
*pFlags
, unsigned char *Buffer
, CLEANLOCALSTORAGE
*pstg
)
79 ALIGN_POINTER(Buffer
, 3);
80 *(DWORD
*)Buffer
= pstg
->flags
;
84 ITypeLib_ReleaseTLibAttr((ITypeLib
*)pstg
->pInterface
, *(TLIBATTR
**)pstg
->pStorage
);
87 ITypeInfo_ReleaseTypeAttr((ITypeInfo
*)pstg
->pInterface
, *(TYPEATTR
**)pstg
->pStorage
);
90 ITypeInfo_ReleaseFuncDesc((ITypeInfo
*)pstg
->pInterface
, *(FUNCDESC
**)pstg
->pStorage
);
93 ITypeInfo_ReleaseVarDesc((ITypeInfo
*)pstg
->pInterface
, *(VARDESC
**)pstg
->pStorage
);
97 ERR("Unknown type %x\n", pstg
->flags
);
100 *(VOID
**)pstg
->pStorage
= NULL
;
101 IUnknown_Release(pstg
->pInterface
);
102 pstg
->pInterface
= NULL
;
104 return Buffer
+ sizeof(DWORD
);
107 unsigned char * WINAPI
CLEANLOCALSTORAGE_UserUnmarshal(ULONG
*pFlags
, unsigned char *Buffer
, CLEANLOCALSTORAGE
*pstr
)
109 ALIGN_POINTER(Buffer
, 3);
110 pstr
->flags
= *(DWORD
*)Buffer
;
111 return Buffer
+ sizeof(DWORD
);
114 void WINAPI
CLEANLOCALSTORAGE_UserFree(ULONG
*pFlags
, CLEANLOCALSTORAGE
*pstr
)
123 DWORD len
; /* No. of chars not including trailing '\0' */
124 DWORD byte_len
; /* len * 2 or 0xffffffff if len == 0 */
125 DWORD len2
; /* == len */
128 ULONG WINAPI
BSTR_UserSize(ULONG
*pFlags
, ULONG Start
, BSTR
*pstr
)
130 TRACE("(%x,%d,%p) => %p\n", *pFlags
, Start
, pstr
, *pstr
);
131 if (*pstr
) TRACE("string=%s\n", debugstr_w(*pstr
));
132 ALIGN_LENGTH(Start
, 3);
133 Start
+= sizeof(bstr_wire_t
) + ((SysStringByteLen(*pstr
) + 1) & ~1);
134 TRACE("returning %d\n", Start
);
138 unsigned char * WINAPI
BSTR_UserMarshal(ULONG
*pFlags
, unsigned char *Buffer
, BSTR
*pstr
)
141 DWORD len
= SysStringByteLen(*pstr
);
143 TRACE("(%x,%p,%p) => %p\n", *pFlags
, Buffer
, pstr
, *pstr
);
144 if (*pstr
) TRACE("string=%s\n", debugstr_w(*pstr
));
146 ALIGN_POINTER(Buffer
, 3);
147 header
= (bstr_wire_t
*)Buffer
;
148 header
->len
= header
->len2
= (len
+ 1) / 2;
151 header
->byte_len
= len
;
152 memcpy(header
+ 1, *pstr
, header
->len
* 2);
155 header
->byte_len
= 0xffffffff; /* special case for a null bstr */
157 return Buffer
+ sizeof(*header
) + sizeof(OLECHAR
) * header
->len
;
160 unsigned char * WINAPI
BSTR_UserUnmarshal(ULONG
*pFlags
, unsigned char *Buffer
, BSTR
*pstr
)
163 TRACE("(%x,%p,%p) => %p\n", *pFlags
, Buffer
, pstr
, *pstr
);
165 ALIGN_POINTER(Buffer
, 3);
166 header
= (bstr_wire_t
*)Buffer
;
167 if(header
->len
!= header
->len2
)
168 FIXME("len %08x != len2 %08x\n", header
->len
, header
->len2
);
170 if (header
->byte_len
== 0xffffffff)
172 SysFreeString(*pstr
);
175 else SysReAllocStringLen( pstr
, (OLECHAR
*)(header
+ 1), header
->len
);
177 if (*pstr
) TRACE("string=%s\n", debugstr_w(*pstr
));
178 return Buffer
+ sizeof(*header
) + sizeof(OLECHAR
) * header
->len
;
181 void WINAPI
BSTR_UserFree(ULONG
*pFlags
, BSTR
*pstr
)
183 TRACE("(%x,%p) => %p\n", *pFlags
, pstr
, *pstr
);
184 SysFreeString(*pstr
);
201 static unsigned int get_type_size(ULONG
*pFlags
, VARTYPE vt
)
203 if (vt
& VT_ARRAY
) return 4;
205 switch (vt
& ~VT_BYREF
) {
214 return sizeof(SHORT
);
222 return sizeof(FLOAT
);
224 return sizeof(DOUBLE
);
226 return sizeof(VARIANT_BOOL
);
228 return sizeof(SCODE
);
234 return sizeof(DECIMAL
);
236 return sizeof(ULONG
);
238 return sizeof(VARIANT
);
244 FIXME("unhandled VT %d\n", vt
);
249 static unsigned int get_type_alignment(ULONG
*pFlags
, VARTYPE vt
)
251 unsigned int size
= get_type_size(pFlags
, vt
);
252 if(vt
& VT_BYREF
) return 3;
253 if(size
== 0) return 0;
254 if(size
<= 4) return size
- 1;
258 static unsigned interface_variant_size(const ULONG
*pFlags
, REFIID riid
, IUnknown
*punk
)
265 hr
= CoGetMarshalSizeMax(&size
, riid
, punk
, LOWORD(*pFlags
), NULL
, MSHLFLAGS_NORMAL
);
268 ERR("interface variant buffer size calculation failed, HRESULT=0x%x\n", hr
);
272 size
+= sizeof(ULONG
); /* we have to store the buffersize in the stream */
273 TRACE("wire-size extra of interface variant is %d\n", size
);
277 static ULONG
wire_extra_user_size(ULONG
*pFlags
, ULONG Start
, VARIANT
*pvar
)
282 return LPSAFEARRAY_UserSize(pFlags
, Start
, V_ARRAYREF(pvar
));
284 return LPSAFEARRAY_UserSize(pFlags
, Start
, &V_ARRAY(pvar
));
287 switch (V_VT(pvar
)) {
289 return BSTR_UserSize(pFlags
, Start
, &V_BSTR(pvar
));
290 case VT_BSTR
| VT_BYREF
:
291 return BSTR_UserSize(pFlags
, Start
, V_BSTRREF(pvar
));
292 case VT_VARIANT
| VT_BYREF
:
293 return VARIANT_UserSize(pFlags
, Start
, V_VARIANTREF(pvar
));
295 return Start
+ interface_variant_size(pFlags
, &IID_IUnknown
, V_UNKNOWN(pvar
));
296 case VT_UNKNOWN
| VT_BYREF
:
297 return Start
+ interface_variant_size(pFlags
, &IID_IUnknown
, *V_UNKNOWNREF(pvar
));
299 return Start
+ interface_variant_size(pFlags
, &IID_IDispatch
, (IUnknown
*)V_DISPATCH(pvar
));
300 case VT_DISPATCH
| VT_BYREF
:
301 return Start
+ interface_variant_size(pFlags
, &IID_IDispatch
, (IUnknown
*)*V_DISPATCHREF(pvar
));
303 FIXME("wire-size record\n");
306 case VT_SAFEARRAY
| VT_BYREF
:
307 FIXME("wire-size safearray: shouldn't be marshaling this\n");
314 /* helper: called for VT_DISPATCH variants to marshal the IDispatch* into the buffer. returns Buffer on failure, new position otherwise */
315 static unsigned char* interface_variant_marshal(const ULONG
*pFlags
, unsigned char *Buffer
,
316 REFIID riid
, IUnknown
*punk
)
320 void *working_memlocked
;
321 unsigned char *oldpos
;
325 TRACE("pFlags=%d, Buffer=%p, pUnk=%p\n", *pFlags
, Buffer
, punk
);
329 memset(Buffer
, 0, sizeof(ULONG
));
330 return Buffer
+ sizeof(ULONG
);
335 /* CoMarshalInterface needs a stream, whereas at this level we are operating in terms of buffers.
336 * We create a stream on an HGLOBAL, so we can simply do a memcpy to move it to the buffer.
337 * in rpcrt4/ndr_ole.c, a simple IStream implementation is wrapped around the buffer object,
338 * but that would be overkill here, hence this implementation. We save the size because the unmarshal
339 * code has no way to know how long the marshalled buffer is. */
341 size
= interface_variant_size(pFlags
, riid
, punk
);
343 working_mem
= GlobalAlloc(0, size
);
344 if (!working_mem
) return oldpos
;
346 hr
= CreateStreamOnHGlobal(working_mem
, TRUE
, &working
);
348 GlobalFree(working_mem
);
352 hr
= CoMarshalInterface(working
, riid
, punk
, LOWORD(*pFlags
), NULL
, MSHLFLAGS_NORMAL
);
354 IStream_Release(working
); /* this also releases the hglobal */
358 working_memlocked
= GlobalLock(working_mem
);
359 memcpy(Buffer
, &size
, sizeof(ULONG
)); /* copy the buffersize */
360 memcpy(Buffer
+ sizeof(ULONG
), working_memlocked
, size
- sizeof(ULONG
));
361 GlobalUnlock(working_mem
);
363 IStream_Release(working
);
365 /* size includes the ULONG for the size written above */
366 TRACE("done, size=%d\n", size
);
367 return Buffer
+ size
;
370 /* helper: called for VT_DISPATCH / VT_UNKNOWN variants to unmarshal the buffer. returns Buffer on failure, new position otherwise */
371 static unsigned char *interface_variant_unmarshal(const ULONG
*pFlags
, unsigned char *Buffer
,
372 REFIID riid
, IUnknown
**ppunk
)
376 void *working_memlocked
;
377 unsigned char *oldpos
;
381 TRACE("pFlags=%d, Buffer=%p, ppUnk=%p\n", *pFlags
, Buffer
, ppunk
);
385 /* get the buffersize */
386 memcpy(&size
, Buffer
, sizeof(ULONG
));
387 TRACE("buffersize=%d\n", size
);
392 return Buffer
+ sizeof(ULONG
);
395 working_mem
= GlobalAlloc(0, size
);
396 if (!working_mem
) return oldpos
;
398 hr
= CreateStreamOnHGlobal(working_mem
, TRUE
, &working
);
400 GlobalFree(working_mem
);
404 working_memlocked
= GlobalLock(working_mem
);
406 /* now we copy the contents of the marshalling buffer to working_memlocked, unlock it, and demarshal the stream */
407 memcpy(working_memlocked
, Buffer
+ sizeof(ULONG
), size
);
408 GlobalUnlock(working_mem
);
410 hr
= CoUnmarshalInterface(working
, riid
, (void**)ppunk
);
412 IStream_Release(working
);
416 IStream_Release(working
); /* this also frees the underlying hglobal */
418 /* size includes the ULONG for the size written above */
419 TRACE("done, processed=%d bytes\n", size
);
420 return Buffer
+ size
;
424 ULONG WINAPI
VARIANT_UserSize(ULONG
*pFlags
, ULONG Start
, VARIANT
*pvar
)
427 TRACE("(%x,%d,%p)\n", *pFlags
, Start
, pvar
);
428 TRACE("vt=%04x\n", V_VT(pvar
));
430 ALIGN_LENGTH(Start
, 7);
431 Start
+= sizeof(variant_wire_t
);
432 if(V_VT(pvar
) & VT_BYREF
)
435 align
= get_type_alignment(pFlags
, V_VT(pvar
));
436 ALIGN_LENGTH(Start
, align
);
437 if(V_VT(pvar
) == (VT_VARIANT
| VT_BYREF
))
440 Start
+= get_type_size(pFlags
, V_VT(pvar
));
441 Start
= wire_extra_user_size(pFlags
, Start
, pvar
);
443 TRACE("returning %d\n", Start
);
447 unsigned char * WINAPI
VARIANT_UserMarshal(ULONG
*pFlags
, unsigned char *Buffer
, VARIANT
*pvar
)
449 variant_wire_t
*header
;
454 TRACE("(%x,%p,%p)\n", *pFlags
, Buffer
, pvar
);
455 TRACE("vt=%04x\n", V_VT(pvar
));
457 ALIGN_POINTER(Buffer
, 7);
459 header
= (variant_wire_t
*)Buffer
;
461 header
->clSize
= 0; /* fixed up at the end */
462 header
->rpcReserved
= 0;
463 header
->vt
= pvar
->n1
.n2
.vt
;
464 header
->wReserved1
= pvar
->n1
.n2
.wReserved1
;
465 header
->wReserved2
= pvar
->n1
.n2
.wReserved2
;
466 header
->wReserved3
= pvar
->n1
.n2
.wReserved3
;
467 header
->switch_is
= pvar
->n1
.n2
.vt
;
468 if(header
->switch_is
& VT_ARRAY
)
469 header
->switch_is
&= ~VT_TYPEMASK
;
471 Pos
= (unsigned char*)(header
+ 1);
472 type_size
= get_type_size(pFlags
, V_VT(pvar
));
473 align
= get_type_alignment(pFlags
, V_VT(pvar
));
474 ALIGN_POINTER(Pos
, align
);
476 if(header
->vt
& VT_BYREF
)
478 *(DWORD
*)Pos
= max(type_size
, 4);
480 if((header
->vt
& VT_TYPEMASK
) != VT_VARIANT
)
482 memcpy(Pos
, pvar
->n1
.n2
.n3
.byref
, type_size
);
487 *(DWORD
*)Pos
= 'U' | 's' << 8 | 'e' << 16 | 'r' << 24;
493 if((header
->vt
& VT_TYPEMASK
) == VT_DECIMAL
)
494 memcpy(Pos
, pvar
, type_size
);
496 memcpy(Pos
, &pvar
->n1
.n2
.n3
, type_size
);
500 if(header
->vt
& VT_ARRAY
)
502 if(header
->vt
& VT_BYREF
)
503 Pos
= LPSAFEARRAY_UserMarshal(pFlags
, Pos
, V_ARRAYREF(pvar
));
505 Pos
= LPSAFEARRAY_UserMarshal(pFlags
, Pos
, &V_ARRAY(pvar
));
512 Pos
= BSTR_UserMarshal(pFlags
, Pos
, &V_BSTR(pvar
));
514 case VT_BSTR
| VT_BYREF
:
515 Pos
= BSTR_UserMarshal(pFlags
, Pos
, V_BSTRREF(pvar
));
517 case VT_VARIANT
| VT_BYREF
:
518 Pos
= VARIANT_UserMarshal(pFlags
, Pos
, V_VARIANTREF(pvar
));
521 /* this should probably call WdtpInterfacePointer_UserMarshal in ole32.dll */
522 Pos
= interface_variant_marshal(pFlags
, Pos
, &IID_IUnknown
, V_UNKNOWN(pvar
));
524 case VT_UNKNOWN
| VT_BYREF
:
525 /* this should probably call WdtpInterfacePointer_UserMarshal in ole32.dll */
526 Pos
= interface_variant_marshal(pFlags
, Pos
, &IID_IUnknown
, *V_UNKNOWNREF(pvar
));
529 /* this should probably call WdtpInterfacePointer_UserMarshal in ole32.dll */
530 Pos
= interface_variant_marshal(pFlags
, Pos
, &IID_IDispatch
, (IUnknown
*)V_DISPATCH(pvar
));
532 case VT_DISPATCH
| VT_BYREF
:
533 /* this should probably call WdtpInterfacePointer_UserMarshal in ole32.dll */
534 Pos
= interface_variant_marshal(pFlags
, Pos
, &IID_IDispatch
, (IUnknown
*)*V_DISPATCHREF(pvar
));
537 FIXME("handle BRECORD by val\n");
539 case VT_RECORD
| VT_BYREF
:
540 FIXME("handle BRECORD by ref\n");
544 header
->clSize
= ((Pos
- Buffer
) + 7) >> 3;
545 TRACE("marshalled size=%d\n", header
->clSize
);
549 unsigned char * WINAPI
VARIANT_UserUnmarshal(ULONG
*pFlags
, unsigned char *Buffer
, VARIANT
*pvar
)
551 variant_wire_t
*header
;
556 TRACE("(%x,%p,%p)\n", *pFlags
, Buffer
, pvar
);
558 ALIGN_POINTER(Buffer
, 7);
560 header
= (variant_wire_t
*)Buffer
;
562 Pos
= (unsigned char*)(header
+ 1);
563 type_size
= get_type_size(pFlags
, header
->vt
);
564 align
= get_type_alignment(pFlags
, header
->vt
);
565 ALIGN_POINTER(Pos
, align
);
567 if(header
->vt
& VT_BYREF
)
572 switch (header
->vt
& ~VT_BYREF
)
574 /* these types have a different memory size compared to wire size */
578 mem_size
= sizeof(void *);
581 mem_size
= type_size
;
585 if (V_VT(pvar
) != header
->vt
)
588 V_BYREF(pvar
) = CoTaskMemAlloc(mem_size
);
590 else if (!V_BYREF(pvar
))
591 V_BYREF(pvar
) = CoTaskMemAlloc(mem_size
);
592 memcpy(V_BYREF(pvar
), Pos
, type_size
);
593 if((header
->vt
& VT_TYPEMASK
) != VT_VARIANT
)
601 if((header
->vt
& VT_TYPEMASK
) == VT_DECIMAL
)
602 memcpy(pvar
, Pos
, type_size
);
604 memcpy(&pvar
->n1
.n2
.n3
, Pos
, type_size
);
608 pvar
->n1
.n2
.vt
= header
->vt
;
609 pvar
->n1
.n2
.wReserved1
= header
->wReserved1
;
610 pvar
->n1
.n2
.wReserved2
= header
->wReserved2
;
611 pvar
->n1
.n2
.wReserved3
= header
->wReserved3
;
613 if(header
->vt
& VT_ARRAY
)
615 if(header
->vt
& VT_BYREF
)
616 Pos
= LPSAFEARRAY_UserUnmarshal(pFlags
, Pos
, V_ARRAYREF(pvar
));
618 Pos
= LPSAFEARRAY_UserUnmarshal(pFlags
, Pos
, &V_ARRAY(pvar
));
626 Pos
= BSTR_UserUnmarshal(pFlags
, Pos
, &V_BSTR(pvar
));
628 case VT_BSTR
| VT_BYREF
:
629 *V_BSTRREF(pvar
) = NULL
;
630 Pos
= BSTR_UserUnmarshal(pFlags
, Pos
, V_BSTRREF(pvar
));
632 case VT_VARIANT
| VT_BYREF
:
633 Pos
= VARIANT_UserUnmarshal(pFlags
, Pos
, V_VARIANTREF(pvar
));
636 /* this should probably call WdtpInterfacePointer_UserUnmarshal in ole32.dll */
637 Pos
= interface_variant_unmarshal(pFlags
, Pos
, &IID_IUnknown
, &V_UNKNOWN(pvar
));
639 case VT_UNKNOWN
| VT_BYREF
:
640 /* this should probably call WdtpInterfacePointer_UserUnmarshal in ole32.dll */
641 Pos
= interface_variant_unmarshal(pFlags
, Pos
, &IID_IUnknown
, V_UNKNOWNREF(pvar
));
644 /* this should probably call WdtpInterfacePointer_UserUnmarshal in ole32.dll */
645 Pos
= interface_variant_unmarshal(pFlags
, Pos
, &IID_IDispatch
, (IUnknown
**)&V_DISPATCH(pvar
));
647 case VT_DISPATCH
| VT_BYREF
:
648 /* this should probably call WdtpInterfacePointer_UserUnmarshal in ole32.dll */
649 Pos
= interface_variant_unmarshal(pFlags
, Pos
, &IID_IDispatch
, (IUnknown
**)V_DISPATCHREF(pvar
));
652 FIXME("handle BRECORD by val\n");
654 case VT_RECORD
| VT_BYREF
:
655 FIXME("handle BRECORD by ref\n");
662 void WINAPI
VARIANT_UserFree(ULONG
*pFlags
, VARIANT
*pvar
)
664 VARTYPE vt
= V_VT(pvar
);
667 TRACE("(%x,%p)\n", *pFlags
, pvar
);
668 TRACE("vt=%04x\n", V_VT(pvar
));
670 if (vt
& VT_BYREF
) ref
= pvar
->n1
.n2
.n3
.byref
;
678 LPSAFEARRAY_UserFree(pFlags
, V_ARRAYREF(pvar
));
680 LPSAFEARRAY_UserFree(pFlags
, &V_ARRAY(pvar
));
686 case VT_BSTR
| VT_BYREF
:
687 BSTR_UserFree(pFlags
, V_BSTRREF(pvar
));
689 case VT_VARIANT
| VT_BYREF
:
690 VARIANT_UserFree(pFlags
, V_VARIANTREF(pvar
));
692 case VT_RECORD
| VT_BYREF
:
693 FIXME("handle BRECORD by ref\n");
695 case VT_UNKNOWN
| VT_BYREF
:
696 case VT_DISPATCH
| VT_BYREF
:
697 IUnknown_Release(*V_UNKNOWNREF(pvar
));
707 /* Get the number of cells in a SafeArray */
708 static ULONG
SAFEARRAY_GetCellCount(const SAFEARRAY
*psa
)
710 const SAFEARRAYBOUND
* psab
= psa
->rgsabound
;
711 USHORT cCount
= psa
->cDims
;
712 ULONG ulNumCells
= 1;
716 /* This is a valid bordercase. See testcases. -Marcus */
717 if (!psab
->cElements
)
719 ulNumCells
*= psab
->cElements
;
725 static inline SF_TYPE
SAFEARRAY_GetUnionType(SAFEARRAY
*psa
)
730 hr
= SafeArrayGetVartype(psa
, &vt
);
733 if(psa
->fFeatures
& FADF_VARIANT
) return SF_VARIANT
;
735 switch(psa
->cbElements
)
737 case 1: vt
= VT_I1
; break;
738 case 2: vt
= VT_I2
; break;
739 case 4: vt
= VT_I4
; break;
740 case 8: vt
= VT_I8
; break;
742 RpcRaiseException(hr
);
746 if (psa
->fFeatures
& FADF_HAVEIID
)
752 case VT_UI1
: return SF_I1
;
755 case VT_UI2
: return SF_I2
;
760 case VT_R4
: return SF_I4
;
765 case VT_UI8
: return SF_I8
;
767 case VT_UINT_PTR
: return (sizeof(UINT_PTR
) == 4 ? SF_I4
: SF_I8
);
768 case VT_BSTR
: return SF_BSTR
;
769 case VT_DISPATCH
: return SF_DISPATCH
;
770 case VT_VARIANT
: return SF_VARIANT
;
771 case VT_UNKNOWN
: return SF_UNKNOWN
;
772 /* Note: Return a non-zero size to indicate vt is valid. The actual size
773 * of a UDT is taken from the result of IRecordInfo_GetSize().
775 case VT_RECORD
: return SF_RECORD
;
776 default: return SF_ERROR
;
780 static DWORD
elem_wire_size(LPSAFEARRAY lpsa
, SF_TYPE sftype
)
782 if (sftype
== SF_BSTR
)
783 return sizeof(DWORD
);
784 else if (sftype
== SF_VARIANT
)
785 return sizeof(variant_wire_t
) - sizeof(DWORD
);
787 return lpsa
->cbElements
;
790 static DWORD
elem_mem_size(wireSAFEARRAY wiresa
, SF_TYPE sftype
)
792 if (sftype
== SF_BSTR
)
794 else if (sftype
== SF_VARIANT
)
795 return sizeof(VARIANT
);
797 return wiresa
->cbElements
;
800 ULONG WINAPI
LPSAFEARRAY_UserSize(ULONG
*pFlags
, ULONG StartingSize
, LPSAFEARRAY
*ppsa
)
802 ULONG size
= StartingSize
;
804 TRACE("("); dump_user_flags(pFlags
); TRACE(", %d, %p\n", StartingSize
, *ppsa
);
806 ALIGN_LENGTH(size
, 3);
807 size
+= sizeof(ULONG
);
810 SAFEARRAY
*psa
= *ppsa
;
811 ULONG ulCellCount
= SAFEARRAY_GetCellCount(psa
);
815 size
+= sizeof(ULONG
);
816 size
+= 2 * sizeof(USHORT
) + 2 * sizeof(ULONG
);
818 sftype
= SAFEARRAY_GetUnionType(psa
);
819 size
+= sizeof(ULONG
);
821 size
+= sizeof(ULONG
);
822 size
+= sizeof(ULONG
);
823 if (sftype
== SF_HAVEIID
)
826 size
+= sizeof(psa
->rgsabound
[0]) * psa
->cDims
;
828 size
+= sizeof(ULONG
);
836 for (lpBstr
= psa
->pvData
; ulCellCount
; ulCellCount
--, lpBstr
++)
837 size
= BSTR_UserSize(pFlags
, size
, lpBstr
);
844 FIXME("size interfaces\n");
850 for (lpVariant
= psa
->pvData
; ulCellCount
; ulCellCount
--, lpVariant
++)
851 size
= VARIANT_UserSize(pFlags
, size
, lpVariant
);
857 IRecordInfo
* pRecInfo
= NULL
;
859 hr
= SafeArrayGetRecordInfo(psa
, &pRecInfo
);
861 RpcRaiseException(hr
);
865 FIXME("size record info %p\n", pRecInfo
);
867 IRecordInfo_Release(pRecInfo
);
872 ALIGN_LENGTH(size
, 7);
877 size
+= ulCellCount
* psa
->cbElements
;
888 unsigned char * WINAPI
LPSAFEARRAY_UserMarshal(ULONG
*pFlags
, unsigned char *Buffer
, LPSAFEARRAY
*ppsa
)
892 TRACE("("); dump_user_flags(pFlags
); TRACE(", %p, &%p\n", Buffer
, *ppsa
);
894 ALIGN_POINTER(Buffer
, 3);
895 *(ULONG
*)Buffer
= *ppsa
? 0x1 : 0x0;
896 Buffer
+= sizeof(ULONG
);
900 SAFEARRAY
*psa
= *ppsa
;
901 ULONG ulCellCount
= SAFEARRAY_GetCellCount(psa
);
902 SAFEARRAYBOUND
*bound
;
907 sftype
= SAFEARRAY_GetUnionType(psa
);
909 *(ULONG
*)Buffer
= psa
->cDims
;
910 Buffer
+= sizeof(ULONG
);
911 *(USHORT
*)Buffer
= psa
->cDims
;
912 Buffer
+= sizeof(USHORT
);
913 *(USHORT
*)Buffer
= psa
->fFeatures
;
914 Buffer
+= sizeof(USHORT
);
915 *(ULONG
*)Buffer
= elem_wire_size(psa
, sftype
);
916 Buffer
+= sizeof(ULONG
);
918 hr
= SafeArrayGetVartype(psa
, &vt
);
919 if (FAILED(hr
)) vt
= 0;
921 *(ULONG
*)Buffer
= (USHORT
)psa
->cLocks
| (vt
<< 16);
922 Buffer
+= sizeof(ULONG
);
924 *(ULONG
*)Buffer
= sftype
;
925 Buffer
+= sizeof(ULONG
);
927 *(ULONG
*)Buffer
= ulCellCount
;
928 Buffer
+= sizeof(ULONG
);
929 *(ULONG
*)Buffer
= psa
->pvData
? 0x2 : 0x0;
930 Buffer
+= sizeof(ULONG
);
931 if (sftype
== SF_HAVEIID
)
933 SafeArrayGetIID(psa
, &guid
);
934 memcpy(Buffer
, &guid
, sizeof(guid
));
935 Buffer
+= sizeof(guid
);
938 /* bounds are marshaled in opposite order comparing to storage layout */
939 bound
= (SAFEARRAYBOUND
*)Buffer
;
940 for (i
= 0; i
< psa
->cDims
; i
++)
942 memcpy(bound
++, &psa
->rgsabound
[psa
->cDims
-i
-1], sizeof(psa
->rgsabound
[0]));
944 Buffer
+= sizeof(psa
->rgsabound
[0]) * psa
->cDims
;
946 *(ULONG
*)Buffer
= ulCellCount
;
947 Buffer
+= sizeof(ULONG
);
957 for (lpBstr
= psa
->pvData
; ulCellCount
; ulCellCount
--, lpBstr
++)
958 Buffer
= BSTR_UserMarshal(pFlags
, Buffer
, lpBstr
);
965 FIXME("marshal interfaces\n");
971 for (lpVariant
= psa
->pvData
; ulCellCount
; ulCellCount
--, lpVariant
++)
972 Buffer
= VARIANT_UserMarshal(pFlags
, Buffer
, lpVariant
);
978 IRecordInfo
* pRecInfo
= NULL
;
980 hr
= SafeArrayGetRecordInfo(psa
, &pRecInfo
);
982 RpcRaiseException(hr
);
986 FIXME("write record info %p\n", pRecInfo
);
988 IRecordInfo_Release(pRecInfo
);
994 ALIGN_POINTER(Buffer
, 7);
999 /* Just copy the data over */
1000 memcpy(Buffer
, psa
->pvData
, ulCellCount
* psa
->cbElements
);
1001 Buffer
+= ulCellCount
* psa
->cbElements
;
1012 #define FADF_AUTOSETFLAGS (FADF_HAVEIID | FADF_RECORD | FADF_HAVEVARTYPE | \
1013 FADF_BSTR | FADF_UNKNOWN | FADF_DISPATCH | \
1014 FADF_VARIANT | FADF_CREATEVECTOR)
1016 unsigned char * WINAPI
LPSAFEARRAY_UserUnmarshal(ULONG
*pFlags
, unsigned char *Buffer
, LPSAFEARRAY
*ppsa
)
1019 wireSAFEARRAY wiresa
;
1026 SAFEARRAYBOUND
*wiresab
;
1028 TRACE("("); dump_user_flags(pFlags
); TRACE(", %p, %p\n", Buffer
, ppsa
);
1030 ALIGN_POINTER(Buffer
, 3);
1031 ptr
= *(ULONG
*)Buffer
;
1032 Buffer
+= sizeof(ULONG
);
1038 TRACE("NULL safe array unmarshaled\n");
1043 cDims
= *(ULONG
*)Buffer
;
1044 Buffer
+= sizeof(ULONG
);
1046 wiresa
= (wireSAFEARRAY
)Buffer
;
1047 Buffer
+= 2 * sizeof(USHORT
) + 2 * sizeof(ULONG
);
1049 if (cDims
!= wiresa
->cDims
)
1050 RpcRaiseException(RPC_S_INVALID_BOUND
);
1052 /* FIXME: there should be a limit on how large cDims can be */
1054 vt
= HIWORD(wiresa
->cLocks
);
1056 sftype
= *(ULONG
*)Buffer
;
1057 Buffer
+= sizeof(ULONG
);
1059 cell_count
= *(ULONG
*)Buffer
;
1060 Buffer
+= sizeof(ULONG
);
1061 ptr
= *(ULONG
*)Buffer
;
1062 Buffer
+= sizeof(ULONG
);
1063 if (sftype
== SF_HAVEIID
)
1065 memcpy(&guid
, Buffer
, sizeof(guid
));
1066 Buffer
+= sizeof(guid
);
1069 wiresab
= (SAFEARRAYBOUND
*)Buffer
;
1070 Buffer
+= sizeof(wiresab
[0]) * wiresa
->cDims
;
1073 *ppsa
= SafeArrayCreateEx(vt
, wiresa
->cDims
, wiresab
, NULL
);
1076 SafeArrayAllocDescriptor(wiresa
->cDims
, ppsa
);
1078 memcpy((*ppsa
)->rgsabound
, wiresab
, sizeof(SAFEARRAYBOUND
) * wiresa
->cDims
);
1081 RpcRaiseException(E_OUTOFMEMORY
);
1083 /* be careful about which flags we set since they could be a security
1085 (*ppsa
)->fFeatures
&= FADF_AUTOSETFLAGS
;
1086 (*ppsa
)->fFeatures
|= (wiresa
->fFeatures
& ~(FADF_AUTOSETFLAGS
));
1087 /* FIXME: there should be a limit on how large wiresa->cbElements can be */
1088 (*ppsa
)->cbElements
= elem_mem_size(wiresa
, sftype
);
1089 (*ppsa
)->cLocks
= 0;
1091 /* SafeArrayCreateEx allocates the data for us, but
1092 * SafeArrayAllocDescriptor doesn't */
1095 hr
= SafeArrayAllocData(*ppsa
);
1097 RpcRaiseException(hr
);
1100 if ((*(ULONG
*)Buffer
!= cell_count
) || (SAFEARRAY_GetCellCount(*ppsa
) != cell_count
))
1101 RpcRaiseException(RPC_S_INVALID_BOUND
);
1102 Buffer
+= sizeof(ULONG
);
1112 for (lpBstr
= (*ppsa
)->pvData
; cell_count
; cell_count
--, lpBstr
++)
1113 Buffer
= BSTR_UserUnmarshal(pFlags
, Buffer
, lpBstr
);
1120 FIXME("marshal interfaces\n");
1126 for (lpVariant
= (*ppsa
)->pvData
; cell_count
; cell_count
--, lpVariant
++)
1127 Buffer
= VARIANT_UserUnmarshal(pFlags
, Buffer
, lpVariant
);
1133 FIXME("set record info\n");
1139 ALIGN_POINTER(Buffer
, 7);
1144 /* Just copy the data over */
1145 memcpy((*ppsa
)->pvData
, Buffer
, cell_count
* (*ppsa
)->cbElements
);
1146 Buffer
+= cell_count
* (*ppsa
)->cbElements
;
1153 TRACE("safe array unmarshaled: %p\n", *ppsa
);
1158 void WINAPI
LPSAFEARRAY_UserFree(ULONG
*pFlags
, LPSAFEARRAY
*ppsa
)
1160 TRACE("("); dump_user_flags(pFlags
); TRACE(", &%p\n", *ppsa
);
1162 SafeArrayDestroy(*ppsa
);
1166 ULONG WINAPI
HFONT_UserSize(ULONG
*pFlags
, ULONG Start
, HFONT
*phfont
)
1172 unsigned char * WINAPI
HFONT_UserMarshal(ULONG
*pFlags
, unsigned char *Buffer
, HFONT
*phfont
)
1178 unsigned char * WINAPI
HFONT_UserUnmarshal(ULONG
*pFlags
, unsigned char *Buffer
, HFONT
*phfont
)
1184 void WINAPI
HFONT_UserFree(ULONG
*pFlags
, HFONT
*phfont
)
1192 /* exactly how Invoke is marshalled is not very clear to me yet,
1193 * but the way I've done it seems to work for me */
1195 HRESULT CALLBACK
IDispatch_Invoke_Proxy(
1197 DISPID dispIdMember
,
1201 DISPPARAMS
* pDispParams
,
1202 VARIANT
* pVarResult
,
1203 EXCEPINFO
* pExcepInfo
,
1208 UINT
* rgVarRefIdx
= NULL
;
1209 VARIANTARG
* rgVarRef
= NULL
;
1212 EXCEPINFO ExcepInfo
;
1214 TRACE("(%p)->(%d,%s,%x,%x,%p,%p,%p,%p)\n", This
,
1215 dispIdMember
, debugstr_guid(riid
),
1216 lcid
, wFlags
, pDispParams
, pVarResult
,
1217 pExcepInfo
, puArgErr
);
1219 /* [out] args can't be null, use dummy vars if needed */
1220 if (!pVarResult
) pVarResult
= &VarResult
;
1221 if (!puArgErr
) puArgErr
= &uArgErr
;
1222 if (!pExcepInfo
) pExcepInfo
= &ExcepInfo
;
1224 /* count by-ref args */
1225 for (cVarRef
=0,u
=0; u
<pDispParams
->cArgs
; u
++) {
1226 VARIANTARG
* arg
= &pDispParams
->rgvarg
[u
];
1227 if (V_ISBYREF(arg
)) {
1232 rgVarRefIdx
= CoTaskMemAlloc(sizeof(UINT
)*cVarRef
);
1233 rgVarRef
= CoTaskMemAlloc(sizeof(VARIANTARG
)*cVarRef
);
1234 /* make list of by-ref args */
1235 for (cVarRef
=0,u
=0; u
<pDispParams
->cArgs
; u
++) {
1236 VARIANTARG
* arg
= &pDispParams
->rgvarg
[u
];
1237 if (V_ISBYREF(arg
)) {
1238 rgVarRefIdx
[cVarRef
] = u
;
1239 VariantInit(&rgVarRef
[cVarRef
]);
1240 VariantCopy(&rgVarRef
[cVarRef
], arg
);
1246 /* [out] args still can't be null,
1247 * but we can point these anywhere in this case,
1248 * since they won't be written to when cVarRef is 0 */
1249 rgVarRefIdx
= puArgErr
;
1250 rgVarRef
= pVarResult
;
1252 TRACE("passed by ref: %d args\n", cVarRef
);
1253 hr
= IDispatch_RemoteInvoke_Proxy(This
,
1266 for (u
=0; u
<cVarRef
; u
++) {
1267 unsigned i
= rgVarRefIdx
[u
];
1268 VariantCopy(&pDispParams
->rgvarg
[i
],
1270 VariantClear(&rgVarRef
[u
]);
1272 CoTaskMemFree(rgVarRef
);
1273 CoTaskMemFree(rgVarRefIdx
);
1276 if(pExcepInfo
== &ExcepInfo
)
1278 SysFreeString(pExcepInfo
->bstrSource
);
1279 SysFreeString(pExcepInfo
->bstrDescription
);
1280 SysFreeString(pExcepInfo
->bstrHelpFile
);
1285 HRESULT __RPC_STUB
IDispatch_Invoke_Stub(
1287 DISPID dispIdMember
,
1291 DISPPARAMS
* pDispParams
,
1292 VARIANT
* pVarResult
,
1293 EXCEPINFO
* pExcepInfo
,
1297 VARIANTARG
* rgVarRef
)
1300 VARIANTARG
*rgvarg
, *arg
;
1303 /* initialize out parameters, so that they can be marshalled
1304 * in case the real Invoke doesn't initialize them */
1305 VariantInit(pVarResult
);
1306 memset(pExcepInfo
, 0, sizeof(*pExcepInfo
));
1309 /* let the real Invoke operate on a copy of the in parameters,
1310 * so we don't risk losing pointers to allocated memory */
1311 rgvarg
= pDispParams
->rgvarg
;
1312 arg
= CoTaskMemAlloc(sizeof(VARIANTARG
)*pDispParams
->cArgs
);
1313 if (!arg
) return E_OUTOFMEMORY
;
1315 /* init all args so we can call VariantClear on all the args if the copy
1317 for (u
= 0; u
< pDispParams
->cArgs
; u
++)
1318 VariantInit(&arg
[u
]);
1320 for (u
= 0; u
< pDispParams
->cArgs
; u
++) {
1321 hr
= VariantCopy(&arg
[u
], &rgvarg
[u
]);
1326 if (SUCCEEDED(hr
)) {
1327 /* copy ref args to arg array */
1328 for (u
=0; u
<cVarRef
; u
++) {
1329 unsigned i
= rgVarRefIdx
[u
];
1330 VariantCopy(&arg
[i
], &rgVarRef
[u
]);
1333 pDispParams
->rgvarg
= arg
;
1335 hr
= IDispatch_Invoke(This
,
1345 /* copy ref args from arg array */
1346 for (u
=0; u
<cVarRef
; u
++) {
1347 unsigned i
= rgVarRefIdx
[u
];
1348 VariantCopy(&rgVarRef
[u
], &arg
[i
]);
1352 /* clear the duplicate argument list */
1353 for (u
=0; u
<pDispParams
->cArgs
; u
++)
1354 VariantClear(&arg
[u
]);
1356 pDispParams
->rgvarg
= rgvarg
;
1364 HRESULT CALLBACK
IEnumVARIANT_Next_Proxy(
1368 ULONG
* pCeltFetched
)
1372 pCeltFetched
= &fetched
;
1373 return IEnumVARIANT_RemoteNext_Proxy(This
,
1379 HRESULT __RPC_STUB
IEnumVARIANT_Next_Stub(
1383 ULONG
* pCeltFetched
)
1387 hr
= IEnumVARIANT_Next(This
,
1391 if (hr
== S_OK
) *pCeltFetched
= celt
;
1395 /* TypeInfo related freers */
1397 static void free_embedded_typedesc(TYPEDESC
*tdesc
);
1398 static void free_embedded_arraydesc(ARRAYDESC
*adesc
)
1400 switch(adesc
->tdescElem
.vt
)
1404 free_embedded_typedesc(adesc
->tdescElem
.u
.lptdesc
);
1405 CoTaskMemFree(adesc
->tdescElem
.u
.lptdesc
);
1408 free_embedded_arraydesc(adesc
->tdescElem
.u
.lpadesc
);
1409 CoTaskMemFree(adesc
->tdescElem
.u
.lpadesc
);
1414 static void free_embedded_typedesc(TYPEDESC
*tdesc
)
1420 free_embedded_typedesc(tdesc
->u
.lptdesc
);
1421 CoTaskMemFree(tdesc
->u
.lptdesc
);
1424 free_embedded_arraydesc(tdesc
->u
.lpadesc
);
1425 CoTaskMemFree(tdesc
->u
.lpadesc
);
1430 static void free_embedded_elemdesc(ELEMDESC
*edesc
)
1432 free_embedded_typedesc(&edesc
->tdesc
);
1433 if(edesc
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FHASDEFAULT
)
1434 CoTaskMemFree(edesc
->u
.paramdesc
.pparamdescex
);
1439 HRESULT CALLBACK
ITypeComp_Bind_Proxy(
1444 ITypeInfo
** ppTInfo
,
1445 DESCKIND
* pDescKind
,
1448 FIXME("not implemented\n");
1452 HRESULT __RPC_STUB
ITypeComp_Bind_Stub(
1457 ITypeInfo
** ppTInfo
,
1458 DESCKIND
* pDescKind
,
1459 LPFUNCDESC
* ppFuncDesc
,
1460 LPVARDESC
* ppVarDesc
,
1461 ITypeComp
** ppTypeComp
,
1462 CLEANLOCALSTORAGE
* pDummy
)
1464 FIXME("not implemented\n");
1468 HRESULT CALLBACK
ITypeComp_BindType_Proxy(
1472 ITypeInfo
** ppTInfo
,
1473 ITypeComp
** ppTComp
)
1475 FIXME("not implemented\n");
1479 HRESULT __RPC_STUB
ITypeComp_BindType_Stub(
1483 ITypeInfo
** ppTInfo
)
1485 FIXME("not implemented\n");
1491 HRESULT CALLBACK
ITypeInfo_GetTypeAttr_Proxy(
1493 TYPEATTR
** ppTypeAttr
)
1496 CLEANLOCALSTORAGE stg
;
1497 TRACE("(%p, %p)\n", This
, ppTypeAttr
);
1500 stg
.pStorage
= NULL
;
1501 stg
.pInterface
= NULL
;
1503 return ITypeInfo_RemoteGetTypeAttr_Proxy(This
, ppTypeAttr
, &stg
);
1506 HRESULT __RPC_STUB
ITypeInfo_GetTypeAttr_Stub(
1508 LPTYPEATTR
* ppTypeAttr
,
1509 CLEANLOCALSTORAGE
* pDummy
)
1512 TRACE("(%p, %p)\n", This
, ppTypeAttr
);
1514 hr
= ITypeInfo_GetTypeAttr(This
, ppTypeAttr
);
1518 pDummy
->flags
= CLS_TYPEATTR
;
1519 ITypeInfo_AddRef(This
);
1520 pDummy
->pInterface
= (IUnknown
*)This
;
1521 pDummy
->pStorage
= ppTypeAttr
;
1525 HRESULT CALLBACK
ITypeInfo_GetFuncDesc_Proxy(
1528 FUNCDESC
** ppFuncDesc
)
1530 CLEANLOCALSTORAGE stg
;
1531 TRACE("(%p, %d, %p)\n", This
, index
, ppFuncDesc
);
1534 stg
.pStorage
= NULL
;
1535 stg
.pInterface
= NULL
;
1537 return ITypeInfo_RemoteGetFuncDesc_Proxy(This
, index
, ppFuncDesc
, &stg
);
1540 HRESULT __RPC_STUB
ITypeInfo_GetFuncDesc_Stub(
1543 LPFUNCDESC
* ppFuncDesc
,
1544 CLEANLOCALSTORAGE
* pDummy
)
1547 TRACE("(%p, %d, %p)\n", This
, index
, ppFuncDesc
);
1549 hr
= ITypeInfo_GetFuncDesc(This
, index
, ppFuncDesc
);
1553 pDummy
->flags
= CLS_FUNCDESC
;
1554 ITypeInfo_AddRef(This
);
1555 pDummy
->pInterface
= (IUnknown
*)This
;
1556 pDummy
->pStorage
= ppFuncDesc
;
1560 HRESULT CALLBACK
ITypeInfo_GetVarDesc_Proxy(
1563 VARDESC
** ppVarDesc
)
1565 CLEANLOCALSTORAGE stg
;
1566 TRACE("(%p, %d, %p)\n", This
, index
, ppVarDesc
);
1569 stg
.pStorage
= NULL
;
1570 stg
.pInterface
= NULL
;
1572 return ITypeInfo_RemoteGetVarDesc_Proxy(This
, index
, ppVarDesc
, &stg
);
1575 HRESULT __RPC_STUB
ITypeInfo_GetVarDesc_Stub(
1578 LPVARDESC
* ppVarDesc
,
1579 CLEANLOCALSTORAGE
* pDummy
)
1582 TRACE("(%p, %d, %p)\n", This
, index
, ppVarDesc
);
1584 hr
= ITypeInfo_GetVarDesc(This
, index
, ppVarDesc
);
1588 pDummy
->flags
= CLS_VARDESC
;
1589 ITypeInfo_AddRef(This
);
1590 pDummy
->pInterface
= (IUnknown
*)This
;
1591 pDummy
->pStorage
= ppVarDesc
;
1595 HRESULT CALLBACK
ITypeInfo_GetNames_Proxy(
1602 TRACE("(%p, %08x, %p, %d, %p)\n", This
, memid
, rgBstrNames
, cMaxNames
, pcNames
);
1604 return ITypeInfo_RemoteGetNames_Proxy(This
, memid
, rgBstrNames
, cMaxNames
, pcNames
);
1607 HRESULT __RPC_STUB
ITypeInfo_GetNames_Stub(
1614 TRACE("(%p, %08x, %p, %d, %p)\n", This
, memid
, rgBstrNames
, cMaxNames
, pcNames
);
1616 return ITypeInfo_GetNames(This
, memid
, rgBstrNames
, cMaxNames
, pcNames
);
1619 HRESULT CALLBACK
ITypeInfo_GetIDsOfNames_Proxy(
1621 LPOLESTR
* rgszNames
,
1625 FIXME("not implemented\n");
1629 HRESULT __RPC_STUB
ITypeInfo_GetIDsOfNames_Stub(
1632 FIXME("not implemented\n");
1636 HRESULT CALLBACK
ITypeInfo_Invoke_Proxy(
1641 DISPPARAMS
* pDispParams
,
1642 VARIANT
* pVarResult
,
1643 EXCEPINFO
* pExcepInfo
,
1646 FIXME("not implemented\n");
1650 HRESULT __RPC_STUB
ITypeInfo_Invoke_Stub(
1653 FIXME("not implemented\n");
1657 HRESULT CALLBACK
ITypeInfo_GetDocumentation_Proxy(ITypeInfo
*This
, MEMBERID memid
,
1658 BSTR
*name
, BSTR
*doc_string
,
1659 DWORD
*help_context
, BSTR
*help_file
)
1661 DWORD dummy_help_context
, flags
= 0;
1662 BSTR dummy_name
, dummy_doc_string
, dummy_help_file
;
1664 TRACE("(%p, %08x, %p, %p, %p, %p)\n", This
, memid
, name
, doc_string
, help_context
, help_file
);
1666 if(!name
) name
= &dummy_name
;
1669 if(!doc_string
) doc_string
= &dummy_doc_string
;
1672 if(!help_context
) help_context
= &dummy_help_context
;
1675 if(!help_file
) help_file
= &dummy_help_file
;
1678 hr
= ITypeInfo_RemoteGetDocumentation_Proxy(This
, memid
, flags
, name
, doc_string
, help_context
, help_file
);
1680 /* We don't need to free the dummy BSTRs since the stub ensures that these will be NULLs. */
1685 HRESULT __RPC_STUB
ITypeInfo_GetDocumentation_Stub(ITypeInfo
*This
, MEMBERID memid
,
1686 DWORD flags
, BSTR
*name
, BSTR
*doc_string
,
1687 DWORD
*help_context
, BSTR
*help_file
)
1689 TRACE("(%p, %08x, %08x, %p, %p, %p, %p)\n", This
, memid
, flags
, name
, doc_string
, help_context
, help_file
);
1691 *name
= *doc_string
= *help_file
= NULL
;
1694 if(!(flags
& 1)) name
= NULL
;
1695 if(!(flags
& 2)) doc_string
= NULL
;
1696 if(!(flags
& 4)) help_context
= NULL
;
1697 if(!(flags
& 8)) help_file
= NULL
;
1699 return ITypeInfo_GetDocumentation(This
, memid
, name
, doc_string
, help_context
, help_file
);
1702 HRESULT CALLBACK
ITypeInfo_GetDllEntry_Proxy(ITypeInfo
*This
, MEMBERID memid
,
1703 INVOKEKIND invkind
, BSTR
*dll_name
,
1704 BSTR
* name
, WORD
*ordinal
)
1707 BSTR dummy_dll_name
, dummy_name
;
1710 TRACE("(%p, %08x, %x, %p, %p, %p)\n", This
, memid
, invkind
, dll_name
, name
, ordinal
);
1712 if(!dll_name
) dll_name
= &dummy_dll_name
;
1715 if(!name
) name
= &dummy_name
;
1718 if(!ordinal
) ordinal
= &dummy_ordinal
;
1721 hr
= ITypeInfo_RemoteGetDllEntry_Proxy(This
, memid
, invkind
, flags
, dll_name
, name
, ordinal
);
1723 /* We don't need to free the dummy BSTRs since the stub ensures that these will be NULLs. */
1728 HRESULT __RPC_STUB
ITypeInfo_GetDllEntry_Stub(ITypeInfo
*This
, MEMBERID memid
,
1729 INVOKEKIND invkind
, DWORD flags
,
1730 BSTR
*dll_name
, BSTR
*name
,
1733 TRACE("(%p, %08x, %x, %p, %p, %p)\n", This
, memid
, invkind
, dll_name
, name
, ordinal
);
1735 *dll_name
= *name
= NULL
;
1738 if(!(flags
& 1)) dll_name
= NULL
;
1739 if(!(flags
& 2)) name
= NULL
;
1740 if(!(flags
& 4)) ordinal
= NULL
;
1742 return ITypeInfo_GetDllEntry(This
, memid
, invkind
, dll_name
, name
, ordinal
);
1745 HRESULT CALLBACK
ITypeInfo_AddressOfMember_Proxy(
1751 FIXME("not implemented\n");
1755 HRESULT __RPC_STUB
ITypeInfo_AddressOfMember_Stub(
1758 FIXME("not implemented\n");
1762 HRESULT CALLBACK
ITypeInfo_CreateInstance_Proxy(
1764 IUnknown
* pUnkOuter
,
1768 FIXME("not implemented\n");
1772 HRESULT __RPC_STUB
ITypeInfo_CreateInstance_Stub(
1777 FIXME("not implemented\n");
1781 HRESULT CALLBACK
ITypeInfo_GetContainingTypeLib_Proxy(
1790 TRACE("(%p, %p, %p)\n", This
, ppTLib
, pIndex
);
1792 hr
= ITypeInfo_RemoteGetContainingTypeLib_Proxy(This
, &pTL
, &index
);
1801 ITypeLib_Release(pTL
);
1806 HRESULT __RPC_STUB
ITypeInfo_GetContainingTypeLib_Stub(
1811 TRACE("(%p, %p, %p)\n", This
, ppTLib
, pIndex
);
1812 return ITypeInfo_GetContainingTypeLib(This
, ppTLib
, pIndex
);
1815 void CALLBACK
ITypeInfo_ReleaseTypeAttr_Proxy(
1817 TYPEATTR
* pTypeAttr
)
1819 TRACE("(%p, %p)\n", This
, pTypeAttr
);
1820 free_embedded_typedesc(&pTypeAttr
->tdescAlias
);
1821 CoTaskMemFree(pTypeAttr
);
1824 HRESULT __RPC_STUB
ITypeInfo_ReleaseTypeAttr_Stub(
1827 TRACE("nothing to do\n");
1831 void CALLBACK
ITypeInfo_ReleaseFuncDesc_Proxy(
1833 FUNCDESC
* pFuncDesc
)
1836 TRACE("(%p, %p)\n", This
, pFuncDesc
);
1838 for(param
= 0; param
< pFuncDesc
->cParams
; param
++)
1839 free_embedded_elemdesc(pFuncDesc
->lprgelemdescParam
+ param
);
1841 CoTaskMemFree(pFuncDesc
->lprgelemdescParam
);
1843 free_embedded_elemdesc(&pFuncDesc
->elemdescFunc
);
1845 if(pFuncDesc
->cScodes
!= 0 && pFuncDesc
->cScodes
!= -1)
1846 CoTaskMemFree(pFuncDesc
->lprgscode
);
1848 CoTaskMemFree(pFuncDesc
);
1851 HRESULT __RPC_STUB
ITypeInfo_ReleaseFuncDesc_Stub(
1854 TRACE("nothing to do\n");
1858 void CALLBACK
ITypeInfo_ReleaseVarDesc_Proxy(
1862 TRACE("(%p, %p)\n", This
, pVarDesc
);
1864 CoTaskMemFree(pVarDesc
->lpstrSchema
);
1866 if(pVarDesc
->varkind
== VAR_CONST
)
1867 CoTaskMemFree(pVarDesc
->u
.lpvarValue
);
1869 free_embedded_elemdesc(&pVarDesc
->elemdescVar
);
1870 CoTaskMemFree(pVarDesc
);
1873 HRESULT __RPC_STUB
ITypeInfo_ReleaseVarDesc_Stub(
1876 TRACE("nothing to do\n");
1883 HRESULT CALLBACK
ITypeInfo2_GetDocumentation2_Proxy(ITypeInfo2
*This
, MEMBERID memid
,
1884 LCID lcid
, BSTR
*help_string
,
1885 DWORD
*help_context
, BSTR
*help_dll
)
1887 DWORD dummy_help_context
, flags
= 0;
1888 BSTR dummy_help_string
, dummy_help_dll
;
1890 TRACE("(%p, %08x, %08x, %p, %p, %p)\n", This
, memid
, lcid
, help_string
, help_context
, help_dll
);
1892 if(!help_string
) help_string
= &dummy_help_string
;
1895 if(!help_context
) help_context
= &dummy_help_context
;
1898 if(!help_dll
) help_dll
= &dummy_help_dll
;
1901 hr
= ITypeInfo2_RemoteGetDocumentation2_Proxy(This
, memid
, lcid
, flags
, help_string
, help_context
, help_dll
);
1903 /* We don't need to free the dummy BSTRs since the stub ensures that these will be NULLs. */
1908 HRESULT __RPC_STUB
ITypeInfo2_GetDocumentation2_Stub(ITypeInfo2
*This
, MEMBERID memid
,
1909 LCID lcid
, DWORD flags
,
1910 BSTR
*help_string
, DWORD
*help_context
,
1913 TRACE("(%p, %08x, %08x, %08x, %p, %p, %p)\n", This
, memid
, lcid
, flags
, help_string
, help_context
, help_dll
);
1915 *help_string
= *help_dll
= NULL
;
1918 if(!(flags
& 1)) help_string
= NULL
;
1919 if(!(flags
& 2)) help_context
= NULL
;
1920 if(!(flags
& 4)) help_dll
= NULL
;
1922 return ITypeInfo2_GetDocumentation2(This
, memid
, lcid
, help_string
, help_context
, help_dll
);
1927 UINT CALLBACK
ITypeLib_GetTypeInfoCount_Proxy(
1931 TRACE("(%p)\n", This
);
1933 ITypeLib_RemoteGetTypeInfoCount_Proxy(This
, &count
);
1938 HRESULT __RPC_STUB
ITypeLib_GetTypeInfoCount_Stub(
1942 TRACE("(%p, %p)\n", This
, pcTInfo
);
1943 *pcTInfo
= ITypeLib_GetTypeInfoCount(This
);
1947 HRESULT CALLBACK
ITypeLib_GetLibAttr_Proxy(
1949 TLIBATTR
** ppTLibAttr
)
1951 CLEANLOCALSTORAGE stg
;
1952 TRACE("(%p, %p)\n", This
, ppTLibAttr
);
1955 stg
.pStorage
= NULL
;
1956 stg
.pInterface
= NULL
;
1958 return ITypeLib_RemoteGetLibAttr_Proxy(This
, ppTLibAttr
, &stg
);
1961 HRESULT __RPC_STUB
ITypeLib_GetLibAttr_Stub(
1963 LPTLIBATTR
* ppTLibAttr
,
1964 CLEANLOCALSTORAGE
* pDummy
)
1967 TRACE("(%p, %p)\n", This
, ppTLibAttr
);
1969 hr
= ITypeLib_GetLibAttr(This
, ppTLibAttr
);
1973 pDummy
->flags
= CLS_LIBATTR
;
1974 ITypeLib_AddRef(This
);
1975 pDummy
->pInterface
= (IUnknown
*)This
;
1976 pDummy
->pStorage
= ppTLibAttr
;
1980 HRESULT CALLBACK
ITypeLib_GetDocumentation_Proxy(ITypeLib
*This
, INT index
, BSTR
*name
,
1981 BSTR
*doc_string
, DWORD
*help_context
,
1984 DWORD dummy_help_context
, flags
= 0;
1985 BSTR dummy_name
, dummy_doc_string
, dummy_help_file
;
1987 TRACE("(%p, %d, %p, %p, %p, %p)\n", This
, index
, name
, doc_string
, help_context
, help_file
);
1989 if(!name
) name
= &dummy_name
;
1992 if(!doc_string
) doc_string
= &dummy_doc_string
;
1995 if(!help_context
) help_context
= &dummy_help_context
;
1998 if(!help_file
) help_file
= &dummy_help_file
;
2001 hr
= ITypeLib_RemoteGetDocumentation_Proxy(This
, index
, flags
, name
, doc_string
, help_context
, help_file
);
2003 /* We don't need to free the dummy BSTRs since the stub ensures that these will be NULLs. */
2008 HRESULT __RPC_STUB
ITypeLib_GetDocumentation_Stub(ITypeLib
*This
, INT index
, DWORD flags
,
2009 BSTR
*name
, BSTR
*doc_string
,
2010 DWORD
*help_context
, BSTR
*help_file
)
2012 TRACE("(%p, %d, %08x, %p, %p, %p, %p)\n", This
, index
, flags
, name
, doc_string
, help_context
, help_file
);
2014 *name
= *doc_string
= *help_file
= NULL
;
2017 if(!(flags
& 1)) name
= NULL
;
2018 if(!(flags
& 2)) doc_string
= NULL
;
2019 if(!(flags
& 4)) help_context
= NULL
;
2020 if(!(flags
& 8)) help_file
= NULL
;
2022 return ITypeLib_GetDocumentation(This
, index
, name
, doc_string
, help_context
, help_file
);
2025 HRESULT CALLBACK
ITypeLib_IsName_Proxy(
2031 FIXME("not implemented\n");
2035 HRESULT __RPC_STUB
ITypeLib_IsName_Stub(
2042 FIXME("not implemented\n");
2046 HRESULT CALLBACK
ITypeLib_FindName_Proxy(
2050 ITypeInfo
** ppTInfo
,
2054 FIXME("not implemented\n");
2058 HRESULT __RPC_STUB
ITypeLib_FindName_Stub(
2062 ITypeInfo
** ppTInfo
,
2067 FIXME("not implemented\n");
2071 void CALLBACK
ITypeLib_ReleaseTLibAttr_Proxy(
2073 TLIBATTR
* pTLibAttr
)
2075 TRACE("(%p, %p)\n", This
, pTLibAttr
);
2076 CoTaskMemFree(pTLibAttr
);
2079 HRESULT __RPC_STUB
ITypeLib_ReleaseTLibAttr_Stub(
2082 TRACE("nothing to do\n");
2089 HRESULT CALLBACK
ITypeLib2_GetLibStatistics_Proxy(
2091 ULONG
* pcUniqueNames
,
2092 ULONG
* pcchUniqueNames
)
2094 FIXME("not implemented\n");
2098 HRESULT __RPC_STUB
ITypeLib2_GetLibStatistics_Stub(
2100 ULONG
* pcUniqueNames
,
2101 ULONG
* pcchUniqueNames
)
2103 FIXME("not implemented\n");
2107 HRESULT CALLBACK
ITypeLib2_GetDocumentation2_Proxy(ITypeLib2
*This
, INT index
,
2108 LCID lcid
, BSTR
*help_string
,
2109 DWORD
*help_context
, BSTR
*help_dll
)
2111 DWORD dummy_help_context
, flags
= 0;
2112 BSTR dummy_help_string
, dummy_help_dll
;
2114 TRACE("(%p, %d, %08x, %p, %p, %p)\n", This
, index
, lcid
, help_string
, help_context
, help_dll
);
2116 if(!help_string
) help_string
= &dummy_help_string
;
2119 if(!help_context
) help_context
= &dummy_help_context
;
2122 if(!help_dll
) help_dll
= &dummy_help_dll
;
2125 hr
= ITypeLib2_RemoteGetDocumentation2_Proxy(This
, index
, lcid
, flags
, help_string
, help_context
, help_dll
);
2127 /* We don't need to free the dummy BSTRs since the stub ensures that these will be NULLs. */
2132 HRESULT __RPC_STUB
ITypeLib2_GetDocumentation2_Stub(ITypeLib2
*This
, INT index
, LCID lcid
,
2133 DWORD flags
, BSTR
*help_string
,
2134 DWORD
*help_context
, BSTR
*help_dll
)
2136 TRACE("(%p, %d, %08x, %08x, %p, %p, %p)\n", This
, index
, lcid
, flags
, help_string
, help_context
, help_dll
);
2138 *help_string
= *help_dll
= NULL
;
2141 if(!(flags
& 1)) help_string
= NULL
;
2142 if(!(flags
& 2)) help_context
= NULL
;
2143 if(!(flags
& 4)) help_dll
= NULL
;
2145 return ITypeLib2_GetDocumentation2(This
, index
, lcid
, help_string
, help_context
, help_dll
);
2148 HRESULT CALLBACK
IPropertyBag_Read_Proxy(
2150 LPCOLESTR pszPropName
,
2152 IErrorLog
*pErrorLog
)
2154 IUnknown
*pUnk
= NULL
;
2155 TRACE("(%p, %s, %p, %p)\n", This
, debugstr_w(pszPropName
), pVar
, pErrorLog
);
2160 if(V_VT(pVar
) & (VT_BYREF
| VT_ARRAY
| VT_VECTOR
))
2162 FIXME("Variant type %x is byref, array or vector. Not implemented.\n", V_VT(pVar
));
2169 pUnk
= (IUnknown
*)V_DISPATCH(pVar
);
2172 pUnk
= V_UNKNOWN(pVar
);
2175 FIXME("Safearray support not yet implemented.\n");
2178 FIXME("Unknown V_VT %d - support not yet implemented.\n", V_VT(pVar
));
2182 return IPropertyBag_RemoteRead_Proxy(This
, pszPropName
, pVar
, pErrorLog
,
2186 HRESULT __RPC_STUB
IPropertyBag_Read_Stub(
2188 LPCOLESTR pszPropName
,
2190 IErrorLog
*pErrorLog
,
2194 static const WCHAR emptyWstr
[] = {0};
2197 TRACE("(%p, %s, %p, %p, %x, %p)\n", This
, debugstr_w(pszPropName
), pVar
,
2198 pErrorLog
, varType
, pUnkObj
);
2200 if(varType
& (VT_BYREF
| VT_ARRAY
| VT_VECTOR
))
2202 FIXME("Variant type %x is byref, array or vector. Not implemented.\n", V_VT(pVar
));
2206 V_VT(pVar
) = varType
;
2210 hr
= IUnknown_QueryInterface(pUnkObj
, &IID_IDispatch
, (LPVOID
*)&disp
);
2213 IUnknown_Release(pUnkObj
);
2214 V_DISPATCH(pVar
) = disp
;
2217 V_UNKNOWN(pVar
) = pUnkObj
;
2220 V_BSTR(pVar
) = SysAllocString(emptyWstr
);
2223 FIXME("Safearray support not yet implemented.\n");
2228 hr
= IPropertyBag_Read(This
, pszPropName
, pVar
, pErrorLog
);
2235 /* call_as/local stubs for ocidl.idl */
2237 HRESULT CALLBACK
IClassFactory2_CreateInstanceLic_Proxy(
2238 IClassFactory2
* This
,
2239 IUnknown
*pUnkOuter
,
2240 IUnknown
*pUnkReserved
,
2245 FIXME("not implemented\n");
2249 HRESULT __RPC_STUB
IClassFactory2_CreateInstanceLic_Stub(
2250 IClassFactory2
* This
,
2255 FIXME("not implemented\n");
2259 HRESULT CALLBACK
IEnumConnections_Next_Proxy(
2260 IEnumConnections
* This
,
2265 FIXME("not implemented\n");
2269 HRESULT __RPC_STUB
IEnumConnections_Next_Stub(
2270 IEnumConnections
* This
,
2275 FIXME("not implemented\n");
2279 HRESULT CALLBACK
IEnumConnectionPoints_Next_Proxy(
2280 IEnumConnectionPoints
* This
,
2282 LPCONNECTIONPOINT
*ppCP
,
2285 FIXME("not implemented\n");
2289 HRESULT __RPC_STUB
IEnumConnectionPoints_Next_Stub(
2290 IEnumConnectionPoints
* This
,
2292 LPCONNECTIONPOINT
*ppCP
,
2295 FIXME("not implemented\n");
2299 HRESULT CALLBACK
IPersistMemory_Load_Proxy(
2300 IPersistMemory
* This
,
2304 FIXME("not implemented\n");
2308 HRESULT __RPC_STUB
IPersistMemory_Load_Stub(
2309 IPersistMemory
* This
,
2313 FIXME("not implemented\n");
2317 HRESULT CALLBACK
IPersistMemory_Save_Proxy(
2318 IPersistMemory
* This
,
2323 FIXME("not implemented\n");
2327 HRESULT __RPC_STUB
IPersistMemory_Save_Stub(
2328 IPersistMemory
* This
,
2333 FIXME("not implemented\n");
2337 void CALLBACK
IAdviseSinkEx_OnViewStatusChange_Proxy(
2338 IAdviseSinkEx
* This
,
2341 FIXME("not implemented\n");
2344 HRESULT __RPC_STUB
IAdviseSinkEx_OnViewStatusChange_Stub(
2345 IAdviseSinkEx
* This
,
2348 FIXME("not implemented\n");
2352 HRESULT CALLBACK
IEnumOleUndoUnits_Next_Proxy(
2353 IEnumOleUndoUnits
* This
,
2355 IOleUndoUnit
**rgElt
,
2356 ULONG
*pcEltFetched
)
2358 FIXME("not implemented\n");
2362 HRESULT __RPC_STUB
IEnumOleUndoUnits_Next_Stub(
2363 IEnumOleUndoUnits
* This
,
2365 IOleUndoUnit
**rgElt
,
2366 ULONG
*pcEltFetched
)
2368 FIXME("not implemented\n");
2372 HRESULT CALLBACK
IQuickActivate_QuickActivate_Proxy(
2373 IQuickActivate
* This
,
2374 QACONTAINER
*pQaContainer
,
2375 QACONTROL
*pQaControl
)
2377 FIXME("not implemented\n");
2381 HRESULT __RPC_STUB
IQuickActivate_QuickActivate_Stub(
2382 IQuickActivate
* This
,
2383 QACONTAINER
*pQaContainer
,
2384 QACONTROL
*pQaControl
)
2386 FIXME("not implemented\n");