wintrust: In SoftpubLoadSignature, don't assume a message is present.
[wine] / dlls / oleaut32 / usrmarshal.c
1 /*
2  * Misc marshalling routines
3  *
4  * Copyright 2002 Ove Kaaven
5  * Copyright 2003 Mike Hearn
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #include <stdarg.h>
23 #include <string.h>
24
25 #define COBJMACROS
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "winerror.h"
34
35 #include "ole2.h"
36 #include "oleauto.h"
37 #include "rpcproxy.h"
38 #include "typelib.h"
39 #include "wine/debug.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(ole);
42
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)
47
48 static CStdPSFactoryBuffer PSFactoryBuffer;
49
50 CSTDSTUBBUFFERRELEASE(&PSFactoryBuffer)
51
52 extern const ExtendedProxyFileInfo oaidl_ProxyFileInfo;
53
54 static const ProxyFileInfo *OLEAUT32_ProxyFileList[] = {
55   &oaidl_ProxyFileInfo,
56   NULL
57 };
58
59 HRESULT OLEAUTPS_DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
60 {
61   return NdrDllGetClassObject(rclsid, riid, ppv, OLEAUT32_ProxyFileList,
62                               &CLSID_PSDispatch, &PSFactoryBuffer);
63 }
64
65 static void dump_user_flags(const ULONG *pFlags)
66 {
67     if (HIWORD(*pFlags) == NDR_LOCAL_DATA_REPRESENTATION)
68         TRACE("MAKELONG(NDR_LOCAL_REPRESENTATION, ");
69     else
70         TRACE("MAKELONG(0x%04x, ", HIWORD(*pFlags));
71     switch (LOWORD(*pFlags))
72     {
73         case MSHCTX_LOCAL: TRACE("MSHCTX_LOCAL)"); break;
74         case MSHCTX_NOSHAREDMEM: TRACE("MSHCTX_NOSHAREDMEM)"); break;
75         case MSHCTX_DIFFERENTMACHINE: TRACE("MSHCTX_DIFFERENTMACHINE)"); break;
76         case MSHCTX_INPROC: TRACE("MSHCTX_INPROC)"); break;
77         default: TRACE("%d)", LOWORD(*pFlags));
78     }
79 }
80
81 /* CLEANLOCALSTORAGE */
82
83 #define CLS_FUNCDESC  'f'
84 #define CLS_LIBATTR   'l'
85 #define CLS_TYPEATTR  't'
86 #define CLS_VARDESC   'v'
87
88 ULONG WINAPI CLEANLOCALSTORAGE_UserSize(ULONG *pFlags, ULONG Start, CLEANLOCALSTORAGE *pstg)
89 {
90     ALIGN_LENGTH(Start, 3);
91     return Start + sizeof(DWORD);
92 }
93
94 unsigned char * WINAPI CLEANLOCALSTORAGE_UserMarshal(ULONG *pFlags, unsigned char *Buffer, CLEANLOCALSTORAGE *pstg)
95 {
96     ALIGN_POINTER(Buffer, 3);
97     *(DWORD*)Buffer = pstg->flags;
98     switch(pstg->flags)
99     {
100     case CLS_LIBATTR:
101         ITypeLib_ReleaseTLibAttr((ITypeLib*)pstg->pInterface, *(TLIBATTR**)pstg->pStorage);
102         break;
103     case CLS_TYPEATTR:
104         ITypeInfo_ReleaseTypeAttr((ITypeInfo*)pstg->pInterface, *(TYPEATTR**)pstg->pStorage); 
105         break;
106     case CLS_FUNCDESC:
107         ITypeInfo_ReleaseFuncDesc((ITypeInfo*)pstg->pInterface, *(FUNCDESC**)pstg->pStorage); 
108         break;
109     case CLS_VARDESC:
110         ITypeInfo_ReleaseVarDesc((ITypeInfo*)pstg->pInterface, *(VARDESC**)pstg->pStorage);
111         break;
112
113     default:
114         ERR("Unknown type %x\n", pstg->flags);
115     }
116
117     *(VOID**)pstg->pStorage = NULL;
118     IUnknown_Release(pstg->pInterface);
119     pstg->pInterface = NULL;
120
121     return Buffer + sizeof(DWORD);
122 }
123
124 unsigned char * WINAPI CLEANLOCALSTORAGE_UserUnmarshal(ULONG *pFlags, unsigned char *Buffer, CLEANLOCALSTORAGE *pstr)
125 {
126     ALIGN_POINTER(Buffer, 3);
127     pstr->flags = *(DWORD*)Buffer;
128     return Buffer + sizeof(DWORD);
129 }
130
131 void WINAPI CLEANLOCALSTORAGE_UserFree(ULONG *pFlags, CLEANLOCALSTORAGE *pstr)
132 {
133     /* Nothing to do */
134 }
135
136 /* BSTR */
137
138 typedef struct
139 {
140     DWORD len;          /* No. of chars not including trailing '\0' */
141     DWORD byte_len;     /* len * 2 or 0xffffffff if len == 0 */
142     DWORD len2;         /* == len */
143 } bstr_wire_t;
144
145 ULONG WINAPI BSTR_UserSize(ULONG *pFlags, ULONG Start, BSTR *pstr)
146 {
147     TRACE("(%x,%d,%p) => %p\n", *pFlags, Start, pstr, *pstr);
148     if (*pstr) TRACE("string=%s\n", debugstr_w(*pstr));
149     ALIGN_LENGTH(Start, 3);
150     Start += sizeof(bstr_wire_t) + ((SysStringByteLen(*pstr) + 1) & ~1);
151     TRACE("returning %d\n", Start);
152     return Start;
153 }
154
155 unsigned char * WINAPI BSTR_UserMarshal(ULONG *pFlags, unsigned char *Buffer, BSTR *pstr)
156 {
157     bstr_wire_t *header;
158     DWORD len = SysStringByteLen(*pstr);
159
160     TRACE("(%x,%p,%p) => %p\n", *pFlags, Buffer, pstr, *pstr);
161     if (*pstr) TRACE("string=%s\n", debugstr_w(*pstr));
162
163     ALIGN_POINTER(Buffer, 3);
164     header = (bstr_wire_t*)Buffer;
165     header->len = header->len2 = (len + 1) / 2;
166     if (*pstr)
167     {
168         header->byte_len = len;
169         memcpy(header + 1, *pstr, header->len * 2);
170     }
171     else
172         header->byte_len = 0xffffffff; /* special case for a null bstr */
173
174     return Buffer + sizeof(*header) + sizeof(OLECHAR) * header->len;
175 }
176
177 unsigned char * WINAPI BSTR_UserUnmarshal(ULONG *pFlags, unsigned char *Buffer, BSTR *pstr)
178 {
179     bstr_wire_t *header;
180     TRACE("(%x,%p,%p) => %p\n", *pFlags, Buffer, pstr, *pstr);
181
182     ALIGN_POINTER(Buffer, 3);
183     header = (bstr_wire_t*)Buffer;
184     if(header->len != header->len2)
185         FIXME("len %08x != len2 %08x\n", header->len, header->len2);
186     
187     if(*pstr)
188     {
189         SysFreeString(*pstr);
190         *pstr = NULL;
191     }
192
193     if(header->byte_len != 0xffffffff)
194         *pstr = SysAllocStringByteLen((char*)(header + 1), header->byte_len);
195
196     if (*pstr) TRACE("string=%s\n", debugstr_w(*pstr));
197     return Buffer + sizeof(*header) + sizeof(OLECHAR) * header->len;
198 }
199
200 void WINAPI BSTR_UserFree(ULONG *pFlags, BSTR *pstr)
201 {
202     TRACE("(%x,%p) => %p\n", *pFlags, pstr, *pstr);
203     if (*pstr)
204     {
205         SysFreeString(*pstr);
206         *pstr = NULL;
207     }
208 }
209
210 /* VARIANT */
211
212 typedef struct
213 {
214     DWORD clSize;
215     DWORD rpcReserverd;
216     USHORT vt;
217     USHORT wReserved1;
218     USHORT wReserved2;
219     USHORT wReserved3;
220     DWORD switch_is;
221 } variant_wire_t;
222
223 static unsigned int get_type_size(ULONG *pFlags, const VARIANT *pvar)
224 {
225     if (V_VT(pvar) & VT_ARRAY) return 4;
226
227     switch (V_VT(pvar) & ~VT_BYREF) {
228     case VT_EMPTY:
229     case VT_NULL:
230         return 0;
231     case VT_I1:
232     case VT_UI1:
233         return sizeof(CHAR);
234     case VT_I2:
235     case VT_UI2:
236         return sizeof(SHORT);
237     case VT_I4:
238     case VT_UI4:
239         return sizeof(LONG);
240     case VT_INT:
241     case VT_UINT:
242         return sizeof(INT);
243     case VT_R4:
244         return sizeof(FLOAT);
245     case VT_R8:
246         return sizeof(DOUBLE);
247     case VT_BOOL:
248         return sizeof(VARIANT_BOOL);
249     case VT_ERROR:
250         return sizeof(SCODE);
251     case VT_DATE:
252         return sizeof(DATE);
253     case VT_CY:
254         return sizeof(CY);
255     case VT_DECIMAL:
256         return sizeof(DECIMAL);
257     case VT_BSTR:
258         return sizeof(BSTR);
259     case VT_VARIANT:
260         return sizeof(VARIANT);
261     case VT_UNKNOWN:
262     case VT_DISPATCH:
263     case VT_RECORD:
264         return 0;
265     default:
266         FIXME("unhandled VT %d\n", V_VT(pvar));
267         return 0;
268     }
269 }
270
271 static unsigned int get_type_alignment(ULONG *pFlags, const VARIANT *pvar)
272 {
273     unsigned int size = get_type_size(pFlags, pvar);
274     if(V_VT(pvar) & VT_BYREF) return 3;
275     if(size == 0) return 0;
276     if(size <= 4) return size - 1;
277     return 7;
278 }
279
280 static unsigned interface_variant_size(const ULONG *pFlags, REFIID riid, IUnknown *punk)
281 {
282   ULONG size;
283   HRESULT hr;
284   /* find the buffer size of the marshalled dispatch interface */
285   hr = CoGetMarshalSizeMax(&size, riid, punk, LOWORD(*pFlags), NULL, MSHLFLAGS_NORMAL);
286   if (FAILED(hr)) {
287     if (!punk)
288       WARN("NULL dispatch pointer\n");
289     else
290       ERR("Dispatch variant buffer size calculation failed, HRESULT=0x%x\n", hr);
291     return 0;
292   }
293   size += sizeof(ULONG); /* we have to store the buffersize in the stream */
294   TRACE("wire-size extra of dispatch variant is %d\n", size);
295   return size;
296 }
297
298 static ULONG wire_extra_user_size(ULONG *pFlags, ULONG Start, VARIANT *pvar)
299 {
300   if (V_ISARRAY(pvar))
301   {
302     if (V_ISBYREF(pvar))
303       return LPSAFEARRAY_UserSize(pFlags, Start, V_ARRAYREF(pvar));
304     else 
305       return LPSAFEARRAY_UserSize(pFlags, Start, &V_ARRAY(pvar));
306   }
307
308   switch (V_VT(pvar)) {
309   case VT_BSTR:
310     return BSTR_UserSize(pFlags, Start, &V_BSTR(pvar));
311   case VT_BSTR | VT_BYREF:
312     return BSTR_UserSize(pFlags, Start, V_BSTRREF(pvar));
313   case VT_VARIANT | VT_BYREF:
314     return VARIANT_UserSize(pFlags, Start, V_VARIANTREF(pvar));
315   case VT_UNKNOWN:
316     return Start + interface_variant_size(pFlags, &IID_IUnknown, V_UNKNOWN(pvar));
317   case VT_UNKNOWN | VT_BYREF:
318     return Start + interface_variant_size(pFlags, &IID_IUnknown, *V_UNKNOWNREF(pvar));
319   case VT_DISPATCH:
320     return Start + interface_variant_size(pFlags, &IID_IDispatch, (IUnknown*)V_DISPATCH(pvar));
321   case VT_DISPATCH | VT_BYREF:
322     return Start + interface_variant_size(pFlags, &IID_IDispatch, (IUnknown*)*V_DISPATCHREF(pvar));
323   case VT_RECORD:
324     FIXME("wire-size record\n");
325     return Start;
326   case VT_SAFEARRAY:
327   case VT_SAFEARRAY | VT_BYREF:
328     FIXME("wire-size safearray: shouldn't be marshaling this\n");
329     return Start;
330   default:
331     return Start;
332   }
333 }
334
335 /* helper: called for VT_DISPATCH variants to marshal the IDispatch* into the buffer. returns Buffer on failure, new position otherwise */
336 static unsigned char* interface_variant_marshal(const ULONG *pFlags, unsigned char *Buffer,
337                                                 REFIID riid, IUnknown *punk)
338 {
339   IStream *working; 
340   HGLOBAL working_mem;
341   void *working_memlocked;
342   unsigned char *oldpos;
343   ULONG size;
344   HRESULT hr;
345   
346   TRACE("pFlags=%d, Buffer=%p, pUnk=%p\n", *pFlags, Buffer, punk);
347
348   oldpos = Buffer;
349   
350   /* CoMarshalInterface needs a stream, whereas at this level we are operating in terms of buffers.
351    * We create a stream on an HGLOBAL, so we can simply do a memcpy to move it to the buffer.
352    * in rpcrt4/ndr_ole.c, a simple IStream implementation is wrapped around the buffer object,
353    * but that would be overkill here, hence this implementation. We save the size because the unmarshal
354    * code has no way to know how long the marshalled buffer is. */
355
356   size = interface_variant_size(pFlags, riid, punk);
357   
358   working_mem = GlobalAlloc(0, size);
359   if (!working_mem) return oldpos;
360
361   hr = CreateStreamOnHGlobal(working_mem, TRUE, &working);
362   if (hr != S_OK) {
363     GlobalFree(working_mem);
364     return oldpos;
365   }
366   
367   hr = CoMarshalInterface(working, riid, punk, LOWORD(*pFlags), NULL, MSHLFLAGS_NORMAL);
368   if (hr != S_OK) {
369     IStream_Release(working); /* this also releases the hglobal */
370     return oldpos;
371   }
372
373   working_memlocked = GlobalLock(working_mem);
374   memcpy(Buffer, &size, sizeof(ULONG)); /* copy the buffersize */
375   memcpy(Buffer + sizeof(ULONG), working_memlocked, size - sizeof(ULONG));
376   GlobalUnlock(working_mem);
377
378   IStream_Release(working);
379
380   /* size includes the ULONG for the size written above */
381   TRACE("done, size=%d\n", size);
382   return Buffer + size;
383 }
384
385 /* helper: called for VT_DISPATCH / VT_UNKNOWN variants to unmarshal the buffer. returns Buffer on failure, new position otherwise */
386 static unsigned char *interface_variant_unmarshal(const ULONG *pFlags, unsigned char *Buffer,
387                                                   REFIID riid, IUnknown **ppunk)
388 {
389   IStream *working;
390   HGLOBAL working_mem;
391   void *working_memlocked;
392   unsigned char *oldpos;
393   ULONG size;
394   HRESULT hr;
395   
396   TRACE("pFlags=%d, Buffer=%p, ppUnk=%p\n", *pFlags, Buffer, ppunk);
397
398   oldpos = Buffer;
399
400   /* get the buffersize */
401   memcpy(&size, Buffer, sizeof(ULONG));
402   TRACE("buffersize=%d\n", size);
403
404   working_mem = GlobalAlloc(0, size);
405   if (!working_mem) return oldpos;
406
407   hr = CreateStreamOnHGlobal(working_mem, TRUE, &working);
408   if (hr != S_OK) {
409     GlobalFree(working_mem);
410     return oldpos;
411   }
412
413   working_memlocked = GlobalLock(working_mem);
414   
415   /* now we copy the contents of the marshalling buffer to working_memlocked, unlock it, and demarshal the stream */
416   memcpy(working_memlocked, Buffer + sizeof(ULONG), size);
417   GlobalUnlock(working_mem);
418
419   hr = CoUnmarshalInterface(working, riid, (void**)ppunk);
420   if (hr != S_OK) {
421     IStream_Release(working);
422     return oldpos;
423   }
424
425   IStream_Release(working); /* this also frees the underlying hglobal */
426
427   /* size includes the ULONG for the size written above */
428   TRACE("done, processed=%d bytes\n", size);
429   return Buffer + size;
430 }
431
432
433 ULONG WINAPI VARIANT_UserSize(ULONG *pFlags, ULONG Start, VARIANT *pvar)
434 {
435     int align;
436     TRACE("(%x,%d,%p)\n", *pFlags, Start, pvar);
437     TRACE("vt=%04x\n", V_VT(pvar));
438
439     ALIGN_LENGTH(Start, 7);
440     Start += sizeof(variant_wire_t);
441     if(V_VT(pvar) & VT_BYREF)
442         Start += 4;
443
444     align = get_type_alignment(pFlags, pvar);
445     ALIGN_LENGTH(Start, align);
446     if(V_VT(pvar) == (VT_VARIANT | VT_BYREF))
447         Start += 4;
448     else
449         Start += get_type_size(pFlags, pvar);
450     Start = wire_extra_user_size(pFlags, Start, pvar);
451
452     TRACE("returning %d\n", Start);
453     return Start;
454 }
455
456 unsigned char * WINAPI VARIANT_UserMarshal(ULONG *pFlags, unsigned char *Buffer, VARIANT *pvar)
457 {
458     variant_wire_t *header;
459     ULONG type_size;
460     int align;
461     unsigned char *Pos;
462
463     TRACE("(%x,%p,%p)\n", *pFlags, Buffer, pvar);
464     TRACE("vt=%04x\n", V_VT(pvar));
465
466     ALIGN_POINTER(Buffer, 7);
467
468     header = (variant_wire_t *)Buffer; 
469
470     header->clSize = 0; /* fixed up at the end */
471     header->rpcReserverd = 0;
472     header->vt = pvar->n1.n2.vt;
473     header->wReserved1 = pvar->n1.n2.wReserved1;
474     header->wReserved2 = pvar->n1.n2.wReserved2;
475     header->wReserved3 = pvar->n1.n2.wReserved3;
476     header->switch_is = pvar->n1.n2.vt;
477     if(header->switch_is & VT_ARRAY)
478         header->switch_is &= ~VT_TYPEMASK;
479
480     Pos = (unsigned char*)(header + 1);
481     type_size = get_type_size(pFlags, pvar);
482     align = get_type_alignment(pFlags, pvar);
483     ALIGN_POINTER(Pos, align);
484
485     if(header->vt & VT_BYREF)
486     {
487         *(DWORD *)Pos = max(type_size, 4);
488         Pos += 4;
489         if((header->vt & VT_TYPEMASK) != VT_VARIANT)
490         {
491             memcpy(Pos, pvar->n1.n2.n3.byref, type_size);
492             Pos += type_size;
493         }
494         else
495         {
496             *(DWORD*)Pos = 'U' | 's' << 8 | 'e' << 16 | 'r' << 24;
497             Pos += 4;
498         }
499     } 
500     else
501     {
502         if((header->vt & VT_TYPEMASK) == VT_DECIMAL)
503             memcpy(Pos, pvar, type_size);
504         else
505             memcpy(Pos, &pvar->n1.n2.n3, type_size);
506         Pos += type_size;
507     }
508
509     if(header->vt & VT_ARRAY)
510     {
511         if(header->vt & VT_BYREF)
512             Pos = LPSAFEARRAY_UserMarshal(pFlags, Pos, V_ARRAYREF(pvar));
513         else
514             Pos = LPSAFEARRAY_UserMarshal(pFlags, Pos, &V_ARRAY(pvar));
515     }
516     else
517     {
518         switch (header->vt)
519         {
520         case VT_BSTR:
521             Pos = BSTR_UserMarshal(pFlags, Pos, &V_BSTR(pvar));
522             break;
523         case VT_BSTR | VT_BYREF:
524             Pos = BSTR_UserMarshal(pFlags, Pos, V_BSTRREF(pvar));
525             break;
526         case VT_VARIANT | VT_BYREF:
527             Pos = VARIANT_UserMarshal(pFlags, Pos, V_VARIANTREF(pvar));
528             break;
529         case VT_UNKNOWN:
530             /* this should probably call WdtpInterfacePointer_UserMarshal in ole32.dll */
531             Pos = interface_variant_marshal(pFlags, Pos, &IID_IUnknown, V_UNKNOWN(pvar));
532             break;
533         case VT_UNKNOWN | VT_BYREF:
534             /* this should probably call WdtpInterfacePointer_UserMarshal in ole32.dll */
535             Pos = interface_variant_marshal(pFlags, Pos, &IID_IUnknown, *V_UNKNOWNREF(pvar));
536             break;
537         case VT_DISPATCH:
538             /* this should probably call WdtpInterfacePointer_UserMarshal in ole32.dll */
539             Pos = interface_variant_marshal(pFlags, Pos, &IID_IDispatch, (IUnknown*)V_DISPATCH(pvar));
540             break;
541         case VT_DISPATCH | VT_BYREF:
542             /* this should probably call WdtpInterfacePointer_UserMarshal in ole32.dll */
543             Pos = interface_variant_marshal(pFlags, Pos, &IID_IDispatch, (IUnknown*)*V_DISPATCHREF(pvar));
544             break;
545         case VT_RECORD:
546             FIXME("handle BRECORD by val\n");
547             break;
548         case VT_RECORD | VT_BYREF:
549             FIXME("handle BRECORD by ref\n");
550             break;
551         }
552     }
553     header->clSize = ((Pos - Buffer) + 7) >> 3;
554     TRACE("marshalled size=%d\n", header->clSize);
555     return Pos;
556 }
557
558 unsigned char * WINAPI VARIANT_UserUnmarshal(ULONG *pFlags, unsigned char *Buffer, VARIANT *pvar)
559 {
560     variant_wire_t *header;
561     ULONG type_size;
562     int align;
563     unsigned char *Pos;
564
565     TRACE("(%x,%p,%p)\n", *pFlags, Buffer, pvar);
566
567     ALIGN_POINTER(Buffer, 7);
568     VariantClear(pvar);
569
570     header = (variant_wire_t *)Buffer; 
571     
572     pvar->n1.n2.vt = header->vt;
573     pvar->n1.n2.wReserved1 = header->wReserved1;
574     pvar->n1.n2.wReserved2 = header->wReserved2;
575     pvar->n1.n2.wReserved3 = header->wReserved3;
576
577     Pos = (unsigned char*)(header + 1);
578     type_size = get_type_size(pFlags, pvar);
579     align = get_type_alignment(pFlags, pvar);
580     ALIGN_POINTER(Pos, align);
581
582     if(header->vt & VT_BYREF)
583     {
584         Pos += 4;
585         pvar->n1.n2.n3.byref = CoTaskMemAlloc(type_size);
586         memcpy(pvar->n1.n2.n3.byref, Pos, type_size); 
587         if((header->vt & VT_TYPEMASK) != VT_VARIANT)
588            Pos += type_size;
589         else
590             Pos += 4;
591     }
592     else
593     {
594         if((header->vt & VT_TYPEMASK) == VT_DECIMAL)
595             memcpy(pvar, Pos, type_size);
596         else
597             memcpy(&pvar->n1.n2.n3, Pos, type_size);
598         Pos += type_size;
599     }
600
601     if(header->vt & VT_ARRAY)
602     {
603         if(header->vt & VT_BYREF)
604             Pos = LPSAFEARRAY_UserUnmarshal(pFlags, Pos, V_ARRAYREF(pvar));
605         else
606             Pos = LPSAFEARRAY_UserUnmarshal(pFlags, Pos, &V_ARRAY(pvar));
607     }
608     else
609     {
610         switch (header->vt)
611         {
612         case VT_BSTR:
613             V_BSTR(pvar) = NULL;
614             Pos = BSTR_UserUnmarshal(pFlags, Pos, &V_BSTR(pvar));
615             break;
616         case VT_BSTR | VT_BYREF:
617             *V_BSTRREF(pvar) = NULL;
618             Pos = BSTR_UserUnmarshal(pFlags, Pos, V_BSTRREF(pvar));
619             break;
620         case VT_VARIANT | VT_BYREF:
621             Pos = VARIANT_UserUnmarshal(pFlags, Pos, V_VARIANTREF(pvar));
622             break;
623         case VT_UNKNOWN:
624             /* this should probably call WdtpInterfacePointer_UserUnmarshal in ole32.dll */
625             Pos = interface_variant_unmarshal(pFlags, Pos, &IID_IUnknown, &V_UNKNOWN(pvar));
626             break;
627         case VT_UNKNOWN | VT_BYREF:
628             /* this should probably call WdtpInterfacePointer_UserUnmarshal in ole32.dll */
629             Pos = interface_variant_unmarshal(pFlags, Pos, &IID_IUnknown, V_UNKNOWNREF(pvar));
630             break;
631         case VT_DISPATCH:
632             /* this should probably call WdtpInterfacePointer_UserUnmarshal in ole32.dll */
633             Pos = interface_variant_unmarshal(pFlags, Pos, &IID_IDispatch, (IUnknown**)&V_DISPATCH(pvar));
634             break;
635         case VT_DISPATCH | VT_BYREF:
636             /* this should probably call WdtpInterfacePointer_UserUnmarshal in ole32.dll */
637             Pos = interface_variant_unmarshal(pFlags, Pos, &IID_IDispatch, (IUnknown**)V_DISPATCHREF(pvar));
638             break;
639         case VT_RECORD:
640             FIXME("handle BRECORD by val\n");
641             break;
642         case VT_RECORD | VT_BYREF:
643             FIXME("handle BRECORD by ref\n");
644             break;
645         }
646     }
647     return Pos;
648 }
649
650 void WINAPI VARIANT_UserFree(ULONG *pFlags, VARIANT *pvar)
651 {
652   VARTYPE vt = V_VT(pvar);
653   PVOID ref = NULL;
654
655   TRACE("(%x,%p)\n", *pFlags, pvar);
656   TRACE("vt=%04x\n", V_VT(pvar));
657
658   if (vt & VT_BYREF) ref = pvar->n1.n2.n3.byref;
659
660   VariantClear(pvar);
661   if (!ref) return;
662
663   if(vt & VT_ARRAY)
664     LPSAFEARRAY_UserFree(pFlags, V_ARRAYREF(pvar));
665   else
666   {
667     switch (vt)
668     {
669     case VT_BSTR | VT_BYREF:
670       BSTR_UserFree(pFlags, V_BSTRREF(pvar));
671       break;
672     case VT_VARIANT | VT_BYREF:
673       VARIANT_UserFree(pFlags, V_VARIANTREF(pvar));
674       break;
675     case VT_RECORD | VT_BYREF:
676       FIXME("handle BRECORD by ref\n");
677       break;
678     case VT_UNKNOWN | VT_BYREF:
679     case VT_DISPATCH | VT_BYREF:
680       IUnknown_Release(*V_UNKNOWNREF(pvar));
681       break;
682     }
683   }
684
685   CoTaskMemFree(ref);
686 }
687
688 /* LPSAFEARRAY */
689
690 /* Get the number of cells in a SafeArray */
691 static ULONG SAFEARRAY_GetCellCount(const SAFEARRAY *psa)
692 {
693     const SAFEARRAYBOUND* psab = psa->rgsabound;
694     USHORT cCount = psa->cDims;
695     ULONG ulNumCells = 1;
696
697     while (cCount--)
698     {
699         /* This is a valid bordercase. See testcases. -Marcus */
700         if (!psab->cElements)
701             return 0;
702         ulNumCells *= psab->cElements;
703         psab++;
704     }
705     return ulNumCells;
706 }
707
708 static inline SF_TYPE SAFEARRAY_GetUnionType(SAFEARRAY *psa)
709 {
710     VARTYPE vt;
711     HRESULT hr;
712
713     hr = SafeArrayGetVartype(psa, &vt);
714     if (FAILED(hr))
715     {
716         if(psa->fFeatures & FADF_VARIANT) return SF_VARIANT;
717
718         switch(psa->cbElements)
719         {
720         case 1: vt = VT_I1; break;
721         case 2: vt = VT_I2; break;
722         case 4: vt = VT_I4; break;
723         case 8: vt = VT_I8; break;
724         default:
725             RpcRaiseException(hr);
726         }
727     }
728
729     if (psa->fFeatures & FADF_HAVEIID)
730         return SF_HAVEIID;
731
732     switch (vt)
733     {
734     case VT_I1:
735     case VT_UI1:      return SF_I1;
736     case VT_BOOL:
737     case VT_I2:
738     case VT_UI2:      return SF_I2;
739     case VT_INT:
740     case VT_UINT:
741     case VT_I4:
742     case VT_UI4:
743     case VT_R4:       return SF_I4;
744     case VT_DATE:
745     case VT_CY:
746     case VT_R8:
747     case VT_I8:
748     case VT_UI8:      return SF_I8;
749     case VT_INT_PTR:
750     case VT_UINT_PTR: return (sizeof(UINT_PTR) == 4 ? SF_I4 : SF_I8);
751     case VT_BSTR:     return SF_BSTR;
752     case VT_DISPATCH: return SF_DISPATCH;
753     case VT_VARIANT:  return SF_VARIANT;
754     case VT_UNKNOWN:  return SF_UNKNOWN;
755     /* Note: Return a non-zero size to indicate vt is valid. The actual size
756      * of a UDT is taken from the result of IRecordInfo_GetSize().
757      */
758     case VT_RECORD:   return SF_RECORD;
759     default:          return SF_ERROR;
760     }
761 }
762
763 ULONG WINAPI LPSAFEARRAY_UserSize(ULONG *pFlags, ULONG StartingSize, LPSAFEARRAY *ppsa)
764 {
765     ULONG size = StartingSize;
766
767     TRACE("("); dump_user_flags(pFlags); TRACE(", %d, %p\n", StartingSize, *ppsa);
768
769     ALIGN_LENGTH(size, 3);
770     size += sizeof(ULONG_PTR);
771     if (*ppsa)
772     {
773         SAFEARRAY *psa = *ppsa;
774         ULONG ulCellCount = SAFEARRAY_GetCellCount(psa);
775         SF_TYPE sftype;
776         HRESULT hr;
777
778         size += sizeof(ULONG);
779         size += FIELD_OFFSET(struct _wireSAFEARRAY, uArrayStructs);
780
781         sftype = SAFEARRAY_GetUnionType(psa);
782         size += sizeof(ULONG);
783
784         size += sizeof(ULONG);
785         size += sizeof(ULONG_PTR);
786         if (sftype == SF_HAVEIID)
787             size += sizeof(IID);
788
789         size += sizeof(psa->rgsabound[0]) * psa->cDims;
790
791         size += sizeof(ULONG);
792
793         switch (sftype)
794         {
795             case SF_BSTR:
796             {
797                 BSTR* lpBstr;
798
799                 for (lpBstr = (BSTR*)psa->pvData; ulCellCount; ulCellCount--, lpBstr++)
800                     size = BSTR_UserSize(pFlags, size, lpBstr);
801
802                 break;
803             }
804             case SF_DISPATCH:
805             case SF_UNKNOWN:
806             case SF_HAVEIID:
807                 FIXME("size interfaces\n");
808                 break;
809             case SF_VARIANT:
810             {
811                 VARIANT* lpVariant;
812
813                 for (lpVariant = (VARIANT*)psa->pvData; ulCellCount; ulCellCount--, lpVariant++)
814                     size = VARIANT_UserSize(pFlags, size, lpVariant);
815
816                 break;
817             }
818             case SF_RECORD:
819             {
820                 IRecordInfo* pRecInfo = NULL;
821
822                 hr = SafeArrayGetRecordInfo(psa, &pRecInfo);
823                 if (FAILED(hr))
824                     RpcRaiseException(hr);
825
826                 if (pRecInfo)
827                 {
828                     FIXME("size record info %p\n", pRecInfo);
829
830                     IRecordInfo_Release(pRecInfo);
831                 }
832                 break;
833             }
834             case SF_I8:
835                 ALIGN_LENGTH(size, 7);
836                 /* fallthrough */
837             case SF_I1:
838             case SF_I2:
839             case SF_I4:
840                 size += ulCellCount * psa->cbElements;
841                 break;
842             default:
843                 break;
844         }
845
846     }
847
848     return size;
849 }
850
851 unsigned char * WINAPI LPSAFEARRAY_UserMarshal(ULONG *pFlags, unsigned char *Buffer, LPSAFEARRAY *ppsa)
852 {
853     HRESULT hr;
854
855     TRACE("("); dump_user_flags(pFlags); TRACE(", %p, &%p\n", Buffer, *ppsa);
856
857     ALIGN_POINTER(Buffer, 3);
858     *(ULONG_PTR *)Buffer = *ppsa ? TRUE : FALSE;
859     Buffer += sizeof(ULONG_PTR);
860     if (*ppsa)
861     {
862         VARTYPE vt;
863         SAFEARRAY *psa = *ppsa;
864         ULONG ulCellCount = SAFEARRAY_GetCellCount(psa);
865         wireSAFEARRAY wiresa;
866         SF_TYPE sftype;
867         GUID guid;
868
869         *(ULONG *)Buffer = psa->cDims;
870         Buffer += sizeof(ULONG);
871         wiresa = (wireSAFEARRAY)Buffer;
872         wiresa->cDims = psa->cDims;
873         wiresa->fFeatures = psa->fFeatures;
874         wiresa->cbElements = psa->cbElements;
875
876         hr = SafeArrayGetVartype(psa, &vt);
877         if (FAILED(hr)) vt = 0;
878
879         wiresa->cLocks = (USHORT)psa->cLocks | (vt << 16);
880
881         Buffer += FIELD_OFFSET(struct _wireSAFEARRAY, uArrayStructs);
882
883         sftype = SAFEARRAY_GetUnionType(psa);
884         *(ULONG *)Buffer = sftype;
885         Buffer += sizeof(ULONG);
886
887         *(ULONG *)Buffer = ulCellCount;
888         Buffer += sizeof(ULONG);
889         *(ULONG_PTR *)Buffer = (ULONG_PTR)psa->pvData;
890         Buffer += sizeof(ULONG_PTR);
891         if (sftype == SF_HAVEIID)
892         {
893             SafeArrayGetIID(psa, &guid);
894             memcpy(Buffer, &guid, sizeof(guid));
895             Buffer += sizeof(guid);
896         }
897
898         memcpy(Buffer, psa->rgsabound, sizeof(psa->rgsabound[0]) * psa->cDims);
899         Buffer += sizeof(psa->rgsabound[0]) * psa->cDims;
900
901         *(ULONG *)Buffer = ulCellCount;
902         Buffer += sizeof(ULONG);
903
904         if (psa->pvData)
905         {
906             switch (sftype)
907             {
908                 case SF_BSTR:
909                 {
910                     BSTR* lpBstr;
911
912                     for (lpBstr = (BSTR*)psa->pvData; ulCellCount; ulCellCount--, lpBstr++)
913                         Buffer = BSTR_UserMarshal(pFlags, Buffer, lpBstr);
914
915                     break;
916                 }
917                 case SF_DISPATCH:
918                 case SF_UNKNOWN:
919                 case SF_HAVEIID:
920                     FIXME("marshal interfaces\n");
921                     break;
922                 case SF_VARIANT:
923                 {
924                     VARIANT* lpVariant;
925
926                     for (lpVariant = (VARIANT*)psa->pvData; ulCellCount; ulCellCount--, lpVariant++)
927                         Buffer = VARIANT_UserMarshal(pFlags, Buffer, lpVariant);
928
929                     break;
930                 }
931                 case SF_RECORD:
932                 {
933                     IRecordInfo* pRecInfo = NULL;
934
935                     hr = SafeArrayGetRecordInfo(psa, &pRecInfo);
936                     if (FAILED(hr))
937                         RpcRaiseException(hr);
938
939                     if (pRecInfo)
940                     {
941                         FIXME("write record info %p\n", pRecInfo);
942
943                         IRecordInfo_Release(pRecInfo);
944                     }
945                     break;
946                 }
947
948                 case SF_I8:
949                     ALIGN_POINTER(Buffer, 7);
950                     /* fallthrough */
951                 case SF_I1:
952                 case SF_I2:
953                 case SF_I4:
954                     /* Just copy the data over */
955                     memcpy(Buffer, psa->pvData, ulCellCount * psa->cbElements);
956                     Buffer += ulCellCount * psa->cbElements;
957                     break;
958                 default:
959                     break;
960             }
961         }
962
963     }
964     return Buffer;
965 }
966
967 #define FADF_AUTOSETFLAGS (FADF_HAVEIID | FADF_RECORD | FADF_HAVEVARTYPE | \
968                            FADF_BSTR | FADF_UNKNOWN | FADF_DISPATCH | \
969                            FADF_VARIANT | FADF_CREATEVECTOR)
970
971 unsigned char * WINAPI LPSAFEARRAY_UserUnmarshal(ULONG *pFlags, unsigned char *Buffer, LPSAFEARRAY *ppsa)
972 {
973     ULONG_PTR ptr;
974     wireSAFEARRAY wiresa;
975     ULONG cDims;
976     HRESULT hr;
977     SF_TYPE sftype;
978     ULONG cell_count;
979     GUID guid;
980     VARTYPE vt;
981     SAFEARRAYBOUND *wiresab;
982
983     TRACE("("); dump_user_flags(pFlags); TRACE(", %p, %p\n", Buffer, ppsa);
984
985     ALIGN_POINTER(Buffer, 3);
986     ptr = *(ULONG_PTR *)Buffer;
987     Buffer += sizeof(ULONG_PTR);
988
989     if (!ptr)
990     {
991         *ppsa = NULL;
992
993         TRACE("NULL safe array unmarshaled\n");
994
995         return Buffer;
996     }
997
998     cDims = *(ULONG *)Buffer;
999     Buffer += sizeof(ULONG);
1000
1001     wiresa = (wireSAFEARRAY)Buffer;
1002     Buffer += FIELD_OFFSET(struct _wireSAFEARRAY, uArrayStructs);
1003
1004     if (cDims != wiresa->cDims)
1005         RpcRaiseException(RPC_S_INVALID_BOUND);
1006
1007     /* FIXME: there should be a limit on how large cDims can be */
1008
1009     vt = HIWORD(wiresa->cLocks);
1010
1011     sftype = *(ULONG *)Buffer;
1012     Buffer += sizeof(ULONG);
1013
1014     cell_count = *(ULONG *)Buffer;
1015     Buffer += sizeof(ULONG);
1016     ptr = *(ULONG_PTR *)Buffer;
1017     Buffer += sizeof(ULONG_PTR);
1018     if (sftype == SF_HAVEIID)
1019     {
1020         memcpy(&guid, Buffer, sizeof(guid));
1021         Buffer += sizeof(guid);
1022     }
1023
1024     wiresab = (SAFEARRAYBOUND *)Buffer;
1025     Buffer += sizeof(wiresab[0]) * wiresa->cDims;
1026
1027     if(vt)
1028         *ppsa = SafeArrayCreateEx(vt, wiresa->cDims, wiresab, NULL);
1029     else
1030     {
1031         SafeArrayAllocDescriptor(wiresa->cDims, ppsa);
1032         if(*ppsa)
1033             memcpy((*ppsa)->rgsabound, wiresab, sizeof(SAFEARRAYBOUND) * wiresa->cDims);
1034     }
1035     if (!*ppsa)
1036         RpcRaiseException(E_OUTOFMEMORY);
1037
1038     /* be careful about which flags we set since they could be a security
1039      * risk */
1040     (*ppsa)->fFeatures &= FADF_AUTOSETFLAGS;
1041     (*ppsa)->fFeatures |= (wiresa->fFeatures & ~(FADF_AUTOSETFLAGS));
1042     /* FIXME: there should be a limit on how large wiresa->cbElements can be */
1043     (*ppsa)->cbElements = wiresa->cbElements;
1044     (*ppsa)->cLocks = LOWORD(wiresa->cLocks);
1045
1046     hr = SafeArrayAllocData(*ppsa);
1047     if (FAILED(hr))
1048         RpcRaiseException(hr);
1049
1050     if ((*(ULONG *)Buffer != cell_count) || (SAFEARRAY_GetCellCount(*ppsa) != cell_count))
1051         RpcRaiseException(RPC_S_INVALID_BOUND);
1052     Buffer += sizeof(ULONG);
1053
1054     if (ptr)
1055     {
1056         switch (sftype)
1057         {
1058             case SF_BSTR:
1059             {
1060                 BSTR* lpBstr;
1061
1062                 for (lpBstr = (BSTR*)(*ppsa)->pvData; cell_count; cell_count--, lpBstr++)
1063                     Buffer = BSTR_UserUnmarshal(pFlags, Buffer, lpBstr);
1064
1065                 break;
1066             }
1067             case SF_DISPATCH:
1068             case SF_UNKNOWN:
1069             case SF_HAVEIID:
1070                 FIXME("marshal interfaces\n");
1071                 break;
1072             case SF_VARIANT:
1073             {
1074                 VARIANT* lpVariant;
1075
1076                 for (lpVariant = (VARIANT*)(*ppsa)->pvData; cell_count; cell_count--, lpVariant++)
1077                     Buffer = VARIANT_UserUnmarshal(pFlags, Buffer, lpVariant);
1078
1079                 break;
1080             }
1081             case SF_RECORD:
1082             {
1083                 FIXME("set record info\n");
1084
1085                 break;
1086             }
1087
1088             case SF_I8:
1089                 ALIGN_POINTER(Buffer, 7);
1090                 /* fallthrough */
1091             case SF_I1:
1092             case SF_I2:
1093             case SF_I4:
1094                 /* Just copy the data over */
1095                 memcpy((*ppsa)->pvData, Buffer, cell_count * (*ppsa)->cbElements);
1096                 Buffer += cell_count * (*ppsa)->cbElements;
1097                 break;
1098             default:
1099                 break;
1100         }
1101     }
1102
1103     TRACE("safe array unmarshaled: %p\n", *ppsa);
1104
1105     return Buffer;
1106 }
1107
1108 void WINAPI LPSAFEARRAY_UserFree(ULONG *pFlags, LPSAFEARRAY *ppsa)
1109 {
1110     TRACE("("); dump_user_flags(pFlags); TRACE(", &%p\n", *ppsa);
1111
1112     SafeArrayDestroy(*ppsa);
1113 }
1114
1115 /* IDispatch */
1116 /* exactly how Invoke is marshalled is not very clear to me yet,
1117  * but the way I've done it seems to work for me */
1118
1119 HRESULT CALLBACK IDispatch_Invoke_Proxy(
1120     IDispatch* This,
1121     DISPID dispIdMember,
1122     REFIID riid,
1123     LCID lcid,
1124     WORD wFlags,
1125     DISPPARAMS* pDispParams,
1126     VARIANT* pVarResult,
1127     EXCEPINFO* pExcepInfo,
1128     UINT* puArgErr)
1129 {
1130   HRESULT hr;
1131   VARIANT VarResult;
1132   UINT* rgVarRefIdx = NULL;
1133   VARIANTARG* rgVarRef = NULL;
1134   UINT u, cVarRef;
1135   UINT uArgErr;
1136   EXCEPINFO ExcepInfo;
1137
1138   TRACE("(%p)->(%d,%s,%x,%x,%p,%p,%p,%p)\n", This,
1139         dispIdMember, debugstr_guid(riid),
1140         lcid, wFlags, pDispParams, pVarResult,
1141         pExcepInfo, puArgErr);
1142
1143   /* [out] args can't be null, use dummy vars if needed */
1144   if (!pVarResult) pVarResult = &VarResult;
1145   if (!puArgErr) puArgErr = &uArgErr;
1146   if (!pExcepInfo) pExcepInfo = &ExcepInfo;
1147
1148   /* count by-ref args */
1149   for (cVarRef=0,u=0; u<pDispParams->cArgs; u++) {
1150     VARIANTARG* arg = &pDispParams->rgvarg[u];
1151     if (V_ISBYREF(arg)) {
1152       cVarRef++;
1153     }
1154   }
1155   if (cVarRef) {
1156     rgVarRefIdx = CoTaskMemAlloc(sizeof(UINT)*cVarRef);
1157     rgVarRef = CoTaskMemAlloc(sizeof(VARIANTARG)*cVarRef);
1158     /* make list of by-ref args */
1159     for (cVarRef=0,u=0; u<pDispParams->cArgs; u++) {
1160       VARIANTARG* arg = &pDispParams->rgvarg[u];
1161       if (V_ISBYREF(arg)) {
1162         rgVarRefIdx[cVarRef] = u;
1163         VariantInit(&rgVarRef[cVarRef]);
1164         cVarRef++;
1165       }
1166     }
1167   } else {
1168     /* [out] args still can't be null,
1169      * but we can point these anywhere in this case,
1170      * since they won't be written to when cVarRef is 0 */
1171     rgVarRefIdx = puArgErr;
1172     rgVarRef = pVarResult;
1173   }
1174   TRACE("passed by ref: %d args\n", cVarRef);
1175   hr = IDispatch_RemoteInvoke_Proxy(This,
1176                                     dispIdMember,
1177                                     riid,
1178                                     lcid,
1179                                     wFlags,
1180                                     pDispParams,
1181                                     pVarResult,
1182                                     pExcepInfo,
1183                                     puArgErr,
1184                                     cVarRef,
1185                                     rgVarRefIdx,
1186                                     rgVarRef);
1187   if (cVarRef) {
1188     for (u=0; u<cVarRef; u++) {
1189       unsigned i = rgVarRefIdx[u];
1190       VariantCopy(&pDispParams->rgvarg[i],
1191                   &rgVarRef[u]);
1192       VariantClear(&rgVarRef[u]);
1193     }
1194     CoTaskMemFree(rgVarRef);
1195     CoTaskMemFree(rgVarRefIdx);
1196   }
1197
1198   if(pExcepInfo == &ExcepInfo)
1199   {
1200     SysFreeString(pExcepInfo->bstrSource);
1201     SysFreeString(pExcepInfo->bstrDescription);
1202     SysFreeString(pExcepInfo->bstrHelpFile);
1203   }
1204   return hr;
1205 }
1206
1207 HRESULT __RPC_STUB IDispatch_Invoke_Stub(
1208     IDispatch* This,
1209     DISPID dispIdMember,
1210     REFIID riid,
1211     LCID lcid,
1212     DWORD dwFlags,
1213     DISPPARAMS* pDispParams,
1214     VARIANT* pVarResult,
1215     EXCEPINFO* pExcepInfo,
1216     UINT* pArgErr,
1217     UINT cVarRef,
1218     UINT* rgVarRefIdx,
1219     VARIANTARG* rgVarRef)
1220 {
1221   HRESULT hr = S_OK;
1222   VARIANTARG *rgvarg, *arg;
1223   UINT u;
1224
1225   /* initialize out parameters, so that they can be marshalled
1226    * in case the real Invoke doesn't initialize them */
1227   VariantInit(pVarResult);
1228   memset(pExcepInfo, 0, sizeof(*pExcepInfo));
1229   *pArgErr = 0;
1230
1231   /* let the real Invoke operate on a copy of the in parameters,
1232    * so we don't risk losing pointers to allocated memory */
1233   rgvarg = pDispParams->rgvarg;
1234   arg = CoTaskMemAlloc(sizeof(VARIANTARG)*pDispParams->cArgs);
1235   if (!arg) return E_OUTOFMEMORY;
1236
1237   /* init all args so we can call VariantClear on all the args if the copy
1238    * below fails */
1239   for (u = 0; u < pDispParams->cArgs; u++)
1240     VariantInit(&arg[u]);
1241
1242   for (u = 0; u < pDispParams->cArgs; u++) {
1243     hr = VariantCopy(&arg[u], &rgvarg[u]);
1244     if (FAILED(hr))
1245         break;
1246   }
1247
1248   if (SUCCEEDED(hr)) {
1249     pDispParams->rgvarg = arg;
1250
1251     hr = IDispatch_Invoke(This,
1252                           dispIdMember,
1253                           riid,
1254                           lcid,
1255                           dwFlags,
1256                           pDispParams,
1257                           pVarResult,
1258                           pExcepInfo,
1259                           pArgErr);
1260
1261     /* copy ref args to out list */
1262     for (u=0; u<cVarRef; u++) {
1263       unsigned i = rgVarRefIdx[u];
1264       VariantInit(&rgVarRef[u]);
1265       VariantCopy(&rgVarRef[u], &arg[i]);
1266       /* clear original if equal, to avoid double-free */
1267       if (V_BYREF(&rgVarRef[u]) == V_BYREF(&rgvarg[i]))
1268         VariantClear(&rgvarg[i]);
1269     }
1270   }
1271
1272   /* clear the duplicate argument list */
1273   for (u=0; u<pDispParams->cArgs; u++)
1274     VariantClear(&arg[u]);
1275
1276   pDispParams->rgvarg = rgvarg;
1277   CoTaskMemFree(arg);
1278
1279   return hr;
1280 }
1281
1282 /* IEnumVARIANT */
1283
1284 HRESULT CALLBACK IEnumVARIANT_Next_Proxy(
1285     IEnumVARIANT* This,
1286     ULONG celt,
1287     VARIANT* rgVar,
1288     ULONG* pCeltFetched)
1289 {
1290   ULONG fetched;
1291   if (!pCeltFetched)
1292     pCeltFetched = &fetched;
1293   return IEnumVARIANT_RemoteNext_Proxy(This,
1294                                        celt,
1295                                        rgVar,
1296                                        pCeltFetched);
1297 }
1298
1299 HRESULT __RPC_STUB IEnumVARIANT_Next_Stub(
1300     IEnumVARIANT* This,
1301     ULONG celt,
1302     VARIANT* rgVar,
1303     ULONG* pCeltFetched)
1304 {
1305   HRESULT hr;
1306   *pCeltFetched = 0;
1307   hr = IEnumVARIANT_Next(This,
1308                          celt,
1309                          rgVar,
1310                          pCeltFetched);
1311   if (hr == S_OK) *pCeltFetched = celt;
1312   return hr;
1313 }
1314
1315 /* TypeInfo related freers */
1316
1317 static void free_embedded_typedesc(TYPEDESC *tdesc);
1318 static void free_embedded_arraydesc(ARRAYDESC *adesc)
1319 {
1320     switch(adesc->tdescElem.vt)
1321     {
1322     case VT_PTR:
1323     case VT_SAFEARRAY:
1324         free_embedded_typedesc(adesc->tdescElem.u.lptdesc);
1325         CoTaskMemFree(adesc->tdescElem.u.lptdesc);
1326         break;
1327     case VT_CARRAY:
1328         free_embedded_arraydesc(adesc->tdescElem.u.lpadesc);
1329         CoTaskMemFree(adesc->tdescElem.u.lpadesc);
1330         break;
1331     }
1332 }
1333
1334 static void free_embedded_typedesc(TYPEDESC *tdesc)
1335 {
1336     switch(tdesc->vt)
1337     {
1338     case VT_PTR:
1339     case VT_SAFEARRAY:
1340         free_embedded_typedesc(tdesc->u.lptdesc);
1341         CoTaskMemFree(tdesc->u.lptdesc);
1342         break;
1343     case VT_CARRAY:
1344         free_embedded_arraydesc(tdesc->u.lpadesc);
1345         CoTaskMemFree(tdesc->u.lpadesc);
1346         break;
1347     }
1348 }
1349
1350 static void free_embedded_elemdesc(ELEMDESC *edesc)
1351 {
1352     free_embedded_typedesc(&edesc->tdesc);
1353     if(edesc->u.paramdesc.wParamFlags & PARAMFLAG_FHASDEFAULT)
1354         CoTaskMemFree(edesc->u.paramdesc.pparamdescex);
1355 }
1356
1357 /* ITypeComp */
1358
1359 HRESULT CALLBACK ITypeComp_Bind_Proxy(
1360     ITypeComp* This,
1361     LPOLESTR szName,
1362     ULONG lHashVal,
1363     WORD wFlags,
1364     ITypeInfo** ppTInfo,
1365     DESCKIND* pDescKind,
1366     BINDPTR* pBindPtr)
1367 {
1368   FIXME("not implemented\n");
1369   return E_FAIL;
1370 }
1371
1372 HRESULT __RPC_STUB ITypeComp_Bind_Stub(
1373     ITypeComp* This,
1374     LPOLESTR szName,
1375     ULONG lHashVal,
1376     WORD wFlags,
1377     ITypeInfo** ppTInfo,
1378     DESCKIND* pDescKind,
1379     LPFUNCDESC* ppFuncDesc,
1380     LPVARDESC* ppVarDesc,
1381     ITypeComp** ppTypeComp,
1382     CLEANLOCALSTORAGE* pDummy)
1383 {
1384   FIXME("not implemented\n");
1385   return E_FAIL;
1386 }
1387
1388 HRESULT CALLBACK ITypeComp_BindType_Proxy(
1389     ITypeComp* This,
1390     LPOLESTR szName,
1391     ULONG lHashVal,
1392     ITypeInfo** ppTInfo,
1393     ITypeComp** ppTComp)
1394 {
1395   FIXME("not implemented\n");
1396   return E_FAIL;
1397 }
1398
1399 HRESULT __RPC_STUB ITypeComp_BindType_Stub(
1400     ITypeComp* This,
1401     LPOLESTR szName,
1402     ULONG lHashVal,
1403     ITypeInfo** ppTInfo)
1404 {
1405   FIXME("not implemented\n");
1406   return E_FAIL;
1407 }
1408
1409 /* ITypeInfo */
1410
1411 HRESULT CALLBACK ITypeInfo_GetTypeAttr_Proxy(
1412     ITypeInfo* This,
1413     TYPEATTR** ppTypeAttr)
1414
1415 {
1416     CLEANLOCALSTORAGE stg;
1417     TRACE("(%p, %p)\n", This, ppTypeAttr);
1418
1419     stg.flags = 0;
1420     stg.pStorage = NULL;
1421     stg.pInterface = NULL;
1422
1423     return ITypeInfo_RemoteGetTypeAttr_Proxy(This, ppTypeAttr, &stg);
1424 }
1425
1426 HRESULT __RPC_STUB ITypeInfo_GetTypeAttr_Stub(
1427     ITypeInfo* This,
1428     LPTYPEATTR* ppTypeAttr,
1429     CLEANLOCALSTORAGE* pDummy)
1430 {
1431     HRESULT hr;
1432     TRACE("(%p, %p)\n", This, ppTypeAttr);
1433
1434     hr = ITypeInfo_GetTypeAttr(This, ppTypeAttr);
1435     if(hr != S_OK)
1436         return hr;
1437
1438     pDummy->flags = CLS_TYPEATTR;
1439     ITypeInfo_AddRef(This);
1440     pDummy->pInterface = (IUnknown*)This;
1441     pDummy->pStorage = ppTypeAttr;
1442     return hr;
1443 }
1444
1445 HRESULT CALLBACK ITypeInfo_GetFuncDesc_Proxy(
1446     ITypeInfo* This,
1447     UINT index,
1448     FUNCDESC** ppFuncDesc)
1449 {
1450     CLEANLOCALSTORAGE stg;
1451     TRACE("(%p, %d, %p)\n", This, index, ppFuncDesc);
1452
1453     stg.flags = 0;
1454     stg.pStorage = NULL;
1455     stg.pInterface = NULL;
1456
1457     return ITypeInfo_RemoteGetFuncDesc_Proxy(This, index, ppFuncDesc, &stg);
1458 }
1459
1460 HRESULT __RPC_STUB ITypeInfo_GetFuncDesc_Stub(
1461     ITypeInfo* This,
1462     UINT index,
1463     LPFUNCDESC* ppFuncDesc,
1464     CLEANLOCALSTORAGE* pDummy)
1465 {
1466     HRESULT hr;
1467     TRACE("(%p, %d, %p)\n", This, index, ppFuncDesc);
1468
1469     hr = ITypeInfo_GetFuncDesc(This, index, ppFuncDesc);
1470     if(hr != S_OK)
1471         return hr;
1472
1473     pDummy->flags = CLS_FUNCDESC;
1474     ITypeInfo_AddRef(This);
1475     pDummy->pInterface = (IUnknown*)This;
1476     pDummy->pStorage = ppFuncDesc;
1477     return hr;
1478 }
1479
1480 HRESULT CALLBACK ITypeInfo_GetVarDesc_Proxy(
1481     ITypeInfo* This,
1482     UINT index,
1483     VARDESC** ppVarDesc)
1484 {
1485     CLEANLOCALSTORAGE stg;
1486     TRACE("(%p, %d, %p)\n", This, index, ppVarDesc);
1487
1488     stg.flags = 0;
1489     stg.pStorage = NULL;
1490     stg.pInterface = NULL;
1491
1492     return ITypeInfo_RemoteGetVarDesc_Proxy(This, index, ppVarDesc, &stg);
1493 }
1494
1495 HRESULT __RPC_STUB ITypeInfo_GetVarDesc_Stub(
1496     ITypeInfo* This,
1497     UINT index,
1498     LPVARDESC* ppVarDesc,
1499     CLEANLOCALSTORAGE* pDummy)
1500 {
1501     HRESULT hr;
1502     TRACE("(%p, %d, %p)\n", This, index, ppVarDesc);
1503
1504     hr = ITypeInfo_GetVarDesc(This, index, ppVarDesc);
1505     if(hr != S_OK)
1506         return hr;
1507
1508     pDummy->flags = CLS_VARDESC;
1509     ITypeInfo_AddRef(This);
1510     pDummy->pInterface = (IUnknown*)This;
1511     pDummy->pStorage = ppVarDesc;
1512     return hr;
1513 }
1514
1515 HRESULT CALLBACK ITypeInfo_GetNames_Proxy(
1516     ITypeInfo* This,
1517     MEMBERID memid,
1518     BSTR* rgBstrNames,
1519     UINT cMaxNames,
1520     UINT* pcNames)
1521 {
1522   FIXME("not implemented\n");
1523   return E_FAIL;
1524 }
1525
1526 HRESULT __RPC_STUB ITypeInfo_GetNames_Stub(
1527     ITypeInfo* This,
1528     MEMBERID memid,
1529     BSTR* rgBstrNames,
1530     UINT cMaxNames,
1531     UINT* pcNames)
1532 {
1533   FIXME("not implemented\n");
1534   return E_FAIL;
1535 }
1536
1537 HRESULT CALLBACK ITypeInfo_GetIDsOfNames_Proxy(
1538     ITypeInfo* This,
1539     LPOLESTR* rgszNames,
1540     UINT cNames,
1541     MEMBERID* pMemId)
1542 {
1543   FIXME("not implemented\n");
1544   return E_FAIL;
1545 }
1546
1547 HRESULT __RPC_STUB ITypeInfo_GetIDsOfNames_Stub(
1548     ITypeInfo* This)
1549 {
1550   FIXME("not implemented\n");
1551   return E_FAIL;
1552 }
1553
1554 HRESULT CALLBACK ITypeInfo_Invoke_Proxy(
1555     ITypeInfo* This,
1556     PVOID pvInstance,
1557     MEMBERID memid,
1558     WORD wFlags,
1559     DISPPARAMS* pDispParams,
1560     VARIANT* pVarResult,
1561     EXCEPINFO* pExcepInfo,
1562     UINT* puArgErr)
1563 {
1564   FIXME("not implemented\n");
1565   return E_FAIL;
1566 }
1567
1568 HRESULT __RPC_STUB ITypeInfo_Invoke_Stub(
1569     ITypeInfo* This)
1570 {
1571   FIXME("not implemented\n");
1572   return E_FAIL;
1573 }
1574
1575 HRESULT CALLBACK ITypeInfo_GetDocumentation_Proxy(
1576     ITypeInfo* This,
1577     MEMBERID memid,
1578     BSTR* pBstrName,
1579     BSTR* pBstrDocString,
1580     DWORD* pdwHelpContext,
1581     BSTR* pBstrHelpFile)
1582 {
1583     DWORD help_context;
1584     BSTR name, doc_string, help_file;
1585     HRESULT hr;
1586     TRACE("(%p, %08x, %p, %p, %p, %p)\n", This, memid, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
1587
1588     /* FIXME: presumably refPtrFlags is supposed to be a bitmask of which ptrs we actually want? */
1589     hr = ITypeInfo_RemoteGetDocumentation_Proxy(This, memid, 0, &name, &doc_string, &help_context, &help_file);
1590     if(SUCCEEDED(hr))
1591     {
1592         if(pBstrName) *pBstrName = name;
1593         else SysFreeString(name);
1594
1595         if(pBstrDocString) *pBstrDocString = doc_string;
1596         else SysFreeString(doc_string);
1597
1598         if(pBstrHelpFile) *pBstrHelpFile = help_file;
1599         else SysFreeString(help_file);
1600
1601         if(pdwHelpContext) *pdwHelpContext = help_context;
1602     }
1603     return hr;
1604 }
1605
1606 HRESULT __RPC_STUB ITypeInfo_GetDocumentation_Stub(
1607     ITypeInfo* This,
1608     MEMBERID memid,
1609     DWORD refPtrFlags,
1610     BSTR* pBstrName,
1611     BSTR* pBstrDocString,
1612     DWORD* pdwHelpContext,
1613     BSTR* pBstrHelpFile)
1614 {
1615     TRACE("(%p, %08x, %08x, %p, %p, %p, %p)\n", This, memid, refPtrFlags, pBstrName, pBstrDocString,
1616           pdwHelpContext, pBstrHelpFile);
1617     return ITypeInfo_GetDocumentation(This, memid, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
1618 }
1619
1620 HRESULT CALLBACK ITypeInfo_GetDllEntry_Proxy(
1621     ITypeInfo* This,
1622     MEMBERID memid,
1623     INVOKEKIND invKind,
1624     BSTR* pBstrDllName,
1625     BSTR* pBstrName,
1626     WORD* pwOrdinal)
1627 {
1628   FIXME("not implemented\n");
1629   return E_FAIL;
1630 }
1631
1632 HRESULT __RPC_STUB ITypeInfo_GetDllEntry_Stub(
1633     ITypeInfo* This,
1634     MEMBERID memid,
1635     INVOKEKIND invKind,
1636     DWORD refPtrFlags,
1637     BSTR* pBstrDllName,
1638     BSTR* pBstrName,
1639     WORD* pwOrdinal)
1640 {
1641   FIXME("not implemented\n");
1642   return E_FAIL;
1643 }
1644
1645 HRESULT CALLBACK ITypeInfo_AddressOfMember_Proxy(
1646     ITypeInfo* This,
1647     MEMBERID memid,
1648     INVOKEKIND invKind,
1649     PVOID* ppv)
1650 {
1651   FIXME("not implemented\n");
1652   return E_FAIL;
1653 }
1654
1655 HRESULT __RPC_STUB ITypeInfo_AddressOfMember_Stub(
1656     ITypeInfo* This)
1657 {
1658   FIXME("not implemented\n");
1659   return E_FAIL;
1660 }
1661
1662 HRESULT CALLBACK ITypeInfo_CreateInstance_Proxy(
1663     ITypeInfo* This,
1664     IUnknown* pUnkOuter,
1665     REFIID riid,
1666     PVOID* ppvObj)
1667 {
1668   FIXME("not implemented\n");
1669   return E_FAIL;
1670 }
1671
1672 HRESULT __RPC_STUB ITypeInfo_CreateInstance_Stub(
1673     ITypeInfo* This,
1674     REFIID riid,
1675     IUnknown** ppvObj)
1676 {
1677   FIXME("not implemented\n");
1678   return E_FAIL;
1679 }
1680
1681 HRESULT CALLBACK ITypeInfo_GetContainingTypeLib_Proxy(
1682     ITypeInfo* This,
1683     ITypeLib** ppTLib,
1684     UINT* pIndex)
1685 {
1686     ITypeLib *pTL;
1687     UINT index;
1688     HRESULT hr;
1689
1690     TRACE("(%p, %p, %p)\n", This, ppTLib, pIndex );
1691     
1692     hr = ITypeInfo_RemoteGetContainingTypeLib_Proxy(This, &pTL, &index);
1693     if(SUCCEEDED(hr))
1694     {
1695         if(pIndex)
1696             *pIndex = index;
1697
1698         if(ppTLib)
1699             *ppTLib = pTL;
1700         else
1701             ITypeLib_Release(pTL);
1702     }
1703     return hr;
1704 }
1705
1706 HRESULT __RPC_STUB ITypeInfo_GetContainingTypeLib_Stub(
1707     ITypeInfo* This,
1708     ITypeLib** ppTLib,
1709     UINT* pIndex)
1710 {
1711     TRACE("(%p, %p, %p)\n", This, ppTLib, pIndex );
1712     return ITypeInfo_GetContainingTypeLib(This, ppTLib, pIndex);
1713 }
1714
1715 void CALLBACK ITypeInfo_ReleaseTypeAttr_Proxy(
1716     ITypeInfo* This,
1717     TYPEATTR* pTypeAttr)
1718 {
1719     TRACE("(%p, %p)\n", This, pTypeAttr);
1720     free_embedded_typedesc(&pTypeAttr->tdescAlias);
1721     CoTaskMemFree(pTypeAttr);
1722 }
1723
1724 HRESULT __RPC_STUB ITypeInfo_ReleaseTypeAttr_Stub(
1725     ITypeInfo* This)
1726 {
1727     TRACE("nothing to do\n");
1728     return S_OK;
1729 }
1730
1731 void CALLBACK ITypeInfo_ReleaseFuncDesc_Proxy(
1732     ITypeInfo* This,
1733     FUNCDESC* pFuncDesc)
1734 {
1735     SHORT param;
1736     TRACE("(%p, %p)\n", This, pFuncDesc);
1737
1738     for(param = 0; param < pFuncDesc->cParams; param++)
1739         free_embedded_elemdesc(pFuncDesc->lprgelemdescParam + param);
1740     if(param)
1741         CoTaskMemFree(pFuncDesc->lprgelemdescParam);
1742
1743     free_embedded_elemdesc(&pFuncDesc->elemdescFunc);
1744
1745     if(pFuncDesc->cScodes != 0 && pFuncDesc->cScodes != -1)
1746         CoTaskMemFree(pFuncDesc->lprgscode);
1747
1748     CoTaskMemFree(pFuncDesc);
1749 }
1750
1751 HRESULT __RPC_STUB ITypeInfo_ReleaseFuncDesc_Stub(
1752     ITypeInfo* This)
1753 {
1754     TRACE("nothing to do\n");
1755     return S_OK;
1756 }
1757
1758 void CALLBACK ITypeInfo_ReleaseVarDesc_Proxy(
1759     ITypeInfo* This,
1760     VARDESC* pVarDesc)
1761 {
1762     TRACE("(%p, %p)\n", This, pVarDesc);
1763
1764     CoTaskMemFree(pVarDesc->lpstrSchema);
1765
1766     if(pVarDesc->varkind == VAR_CONST)
1767         CoTaskMemFree(pVarDesc->u.lpvarValue);
1768
1769     free_embedded_elemdesc(&pVarDesc->elemdescVar);
1770     CoTaskMemFree(pVarDesc);
1771 }
1772
1773 HRESULT __RPC_STUB ITypeInfo_ReleaseVarDesc_Stub(
1774     ITypeInfo* This)
1775 {
1776     TRACE("nothing to do\n");
1777     return S_OK;
1778 }
1779
1780
1781 /* ITypeInfo2 */
1782
1783 HRESULT CALLBACK ITypeInfo2_GetDocumentation2_Proxy(
1784     ITypeInfo2* This,
1785     MEMBERID memid,
1786     LCID lcid,
1787     BSTR* pbstrHelpString,
1788     DWORD* pdwHelpStringContext,
1789     BSTR* pbstrHelpStringDll)
1790 {
1791   FIXME("not implemented\n");
1792   return E_FAIL;
1793 }
1794
1795 HRESULT __RPC_STUB ITypeInfo2_GetDocumentation2_Stub(
1796     ITypeInfo2* This,
1797     MEMBERID memid,
1798     LCID lcid,
1799     DWORD refPtrFlags,
1800     BSTR* pbstrHelpString,
1801     DWORD* pdwHelpStringContext,
1802     BSTR* pbstrHelpStringDll)
1803 {
1804   FIXME("not implemented\n");
1805   return E_FAIL;
1806 }
1807
1808 /* ITypeLib */
1809
1810 UINT CALLBACK ITypeLib_GetTypeInfoCount_Proxy(
1811     ITypeLib* This)
1812 {
1813     UINT count = 0;
1814     TRACE("(%p)\n", This);
1815
1816     ITypeLib_RemoteGetTypeInfoCount_Proxy(This, &count);
1817     
1818     return count;
1819 }
1820
1821 HRESULT __RPC_STUB ITypeLib_GetTypeInfoCount_Stub(
1822     ITypeLib* This,
1823     UINT* pcTInfo)
1824 {
1825     TRACE("(%p, %p)\n", This, pcTInfo);
1826     *pcTInfo = ITypeLib_GetTypeInfoCount(This);
1827     return S_OK;
1828 }
1829
1830 HRESULT CALLBACK ITypeLib_GetLibAttr_Proxy(
1831     ITypeLib* This,
1832     TLIBATTR** ppTLibAttr)
1833 {
1834     CLEANLOCALSTORAGE stg;
1835     TRACE("(%p, %p)\n", This, ppTLibAttr);
1836
1837     stg.flags = 0;
1838     stg.pStorage = NULL;
1839     stg.pInterface = NULL;
1840
1841     return ITypeLib_RemoteGetLibAttr_Proxy(This, ppTLibAttr, &stg);    
1842 }
1843
1844 HRESULT __RPC_STUB ITypeLib_GetLibAttr_Stub(
1845     ITypeLib* This,
1846     LPTLIBATTR* ppTLibAttr,
1847     CLEANLOCALSTORAGE* pDummy)
1848 {
1849     HRESULT hr;
1850     TRACE("(%p, %p)\n", This, ppTLibAttr);
1851     
1852     hr = ITypeLib_GetLibAttr(This, ppTLibAttr);
1853     if(hr != S_OK)
1854         return hr;
1855
1856     pDummy->flags = CLS_LIBATTR;
1857     ITypeLib_AddRef(This);
1858     pDummy->pInterface = (IUnknown*)This;
1859     pDummy->pStorage = ppTLibAttr;
1860     return hr;
1861 }
1862
1863 HRESULT CALLBACK ITypeLib_GetDocumentation_Proxy(
1864     ITypeLib* This,
1865     INT index,
1866     BSTR* pBstrName,
1867     BSTR* pBstrDocString,
1868     DWORD* pdwHelpContext,
1869     BSTR* pBstrHelpFile)
1870 {
1871   FIXME("not implemented\n");
1872   return E_FAIL;
1873 }
1874
1875 HRESULT __RPC_STUB ITypeLib_GetDocumentation_Stub(
1876     ITypeLib* This,
1877     INT index,
1878     DWORD refPtrFlags,
1879     BSTR* pBstrName,
1880     BSTR* pBstrDocString,
1881     DWORD* pdwHelpContext,
1882     BSTR* pBstrHelpFile)
1883 {
1884   FIXME("not implemented\n");
1885   return E_FAIL;
1886 }
1887
1888 HRESULT CALLBACK ITypeLib_IsName_Proxy(
1889     ITypeLib* This,
1890     LPOLESTR szNameBuf,
1891     ULONG lHashVal,
1892     BOOL* pfName)
1893 {
1894   FIXME("not implemented\n");
1895   return E_FAIL;
1896 }
1897
1898 HRESULT __RPC_STUB ITypeLib_IsName_Stub(
1899     ITypeLib* This,
1900     LPOLESTR szNameBuf,
1901     ULONG lHashVal,
1902     BOOL* pfName,
1903     BSTR* pBstrLibName)
1904 {
1905   FIXME("not implemented\n");
1906   return E_FAIL;
1907 }
1908
1909 HRESULT CALLBACK ITypeLib_FindName_Proxy(
1910     ITypeLib* This,
1911     LPOLESTR szNameBuf,
1912     ULONG lHashVal,
1913     ITypeInfo** ppTInfo,
1914     MEMBERID* rgMemId,
1915     USHORT* pcFound)
1916 {
1917   FIXME("not implemented\n");
1918   return E_FAIL;
1919 }
1920
1921 HRESULT __RPC_STUB ITypeLib_FindName_Stub(
1922     ITypeLib* This,
1923     LPOLESTR szNameBuf,
1924     ULONG lHashVal,
1925     ITypeInfo** ppTInfo,
1926     MEMBERID* rgMemId,
1927     USHORT* pcFound,
1928     BSTR* pBstrLibName)
1929 {
1930   FIXME("not implemented\n");
1931   return E_FAIL;
1932 }
1933
1934 void CALLBACK ITypeLib_ReleaseTLibAttr_Proxy(
1935     ITypeLib* This,
1936     TLIBATTR* pTLibAttr)
1937 {
1938     TRACE("(%p, %p)\n", This, pTLibAttr);
1939     CoTaskMemFree(pTLibAttr);
1940 }
1941
1942 HRESULT __RPC_STUB ITypeLib_ReleaseTLibAttr_Stub(
1943     ITypeLib* This)
1944 {
1945     TRACE("nothing to do\n");
1946     return S_OK;
1947 }
1948
1949
1950 /* ITypeLib2 */
1951
1952 HRESULT CALLBACK ITypeLib2_GetLibStatistics_Proxy(
1953     ITypeLib2* This,
1954     ULONG* pcUniqueNames,
1955     ULONG* pcchUniqueNames)
1956 {
1957   FIXME("not implemented\n");
1958   return E_FAIL;
1959 }
1960
1961 HRESULT __RPC_STUB ITypeLib2_GetLibStatistics_Stub(
1962     ITypeLib2* This,
1963     ULONG* pcUniqueNames,
1964     ULONG* pcchUniqueNames)
1965 {
1966   FIXME("not implemented\n");
1967   return E_FAIL;
1968 }
1969
1970 HRESULT CALLBACK ITypeLib2_GetDocumentation2_Proxy(
1971     ITypeLib2* This,
1972     INT index,
1973     LCID lcid,
1974     BSTR* pbstrHelpString,
1975     DWORD* pdwHelpStringContext,
1976     BSTR* pbstrHelpStringDll)
1977 {
1978   FIXME("not implemented\n");
1979   return E_FAIL;
1980 }
1981
1982 HRESULT __RPC_STUB ITypeLib2_GetDocumentation2_Stub(
1983     ITypeLib2* This,
1984     INT index,
1985     LCID lcid,
1986     DWORD refPtrFlags,
1987     BSTR* pbstrHelpString,
1988     DWORD* pdwHelpStringContext,
1989     BSTR* pbstrHelpStringDll)
1990 {
1991   FIXME("not implemented\n");
1992   return E_FAIL;
1993 }