4 * Copyright 2002,2005 Marcus Meissner
6 * The olerelay debug channel allows you to see calls marshalled by
7 * the typelib marshaller. It is not a generic COM relaying system.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #define NONAMELESSUNION
35 #define NONAMELESSSTRUCT
47 #include "wine/debug.h"
49 static const WCHAR IDispatchW[] = { 'I','D','i','s','p','a','t','c','h',0};
51 WINE_DEFAULT_DEBUG_CHANNEL(ole);
52 WINE_DECLARE_DEBUG_CHANNEL(olerelay);
54 #define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
56 typedef struct _marshal_state {
62 /* used in the olerelay code to avoid having the L"" stuff added by debugstr_w */
63 static char *relaystr(WCHAR *in) {
64 char *tmp = (char *)debugstr_w(in);
66 tmp[strlen(tmp)-1] = '\0';
71 xbuf_add(marshal_state *buf, LPBYTE stuff, DWORD size) {
72 while (buf->size - buf->curoff < size) {
75 buf->base = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,buf->base,buf->size);
79 buf->base = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,32);
85 memcpy(buf->base+buf->curoff,stuff,size);
91 xbuf_get(marshal_state *buf, LPBYTE stuff, DWORD size) {
92 if (buf->size < buf->curoff+size) return E_FAIL;
93 memcpy(stuff,buf->base+buf->curoff,size);
99 xbuf_skip(marshal_state *buf, DWORD size) {
100 if (buf->size < buf->curoff+size) return E_FAIL;
106 _unmarshal_interface(marshal_state *buf, REFIID riid, LPUNKNOWN *pUnk) {
108 ULARGE_INTEGER newpos;
109 LARGE_INTEGER seekto;
114 TRACE("...%s...\n",debugstr_guid(riid));
117 hres = xbuf_get(buf,(LPBYTE)&xsize,sizeof(xsize));
119 ERR("xbuf_get failed\n");
123 if (xsize == 0) return S_OK;
125 hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
127 ERR("Stream create failed %lx\n",hres);
131 hres = IStream_Write(pStm,buf->base+buf->curoff,xsize,&res);
133 ERR("stream write %lx\n",hres);
137 memset(&seekto,0,sizeof(seekto));
138 hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
140 ERR("Failed Seek %lx\n",hres);
144 hres = CoUnmarshalInterface(pStm,riid,(LPVOID*)pUnk);
146 ERR("Unmarshalling interface %s failed with %lx\n",debugstr_guid(riid),hres);
150 IStream_Release(pStm);
151 return xbuf_skip(buf,xsize);
155 _marshal_interface(marshal_state *buf, REFIID riid, LPUNKNOWN pUnk) {
156 LPBYTE tempbuf = NULL;
157 IStream *pStm = NULL;
159 ULARGE_INTEGER newpos;
160 LARGE_INTEGER seekto;
166 /* this is valid, if for instance we serialize
167 * a VT_DISPATCH with NULL ptr which apparently
168 * can happen. S_OK to make sure we continue
171 WARN("pUnk is NULL\n");
173 return xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
178 TRACE("...%s...\n",debugstr_guid(riid));
180 hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
182 ERR("Stream create failed %lx\n",hres);
186 hres = CoMarshalInterface(pStm,riid,pUnk,0,NULL,0);
188 ERR("Marshalling interface %s failed with %lx\n", debugstr_guid(riid), hres);
192 hres = IStream_Stat(pStm,&ststg,0);
194 ERR("Stream stat failed\n");
198 tempbuf = HeapAlloc(GetProcessHeap(), 0, ststg.cbSize.u.LowPart);
199 memset(&seekto,0,sizeof(seekto));
200 hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
202 ERR("Failed Seek %lx\n",hres);
206 hres = IStream_Read(pStm,tempbuf,ststg.cbSize.u.LowPart,&res);
208 ERR("Failed Read %lx\n",hres);
212 xsize = ststg.cbSize.u.LowPart;
213 xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
214 hres = xbuf_add(buf,tempbuf,ststg.cbSize.u.LowPart);
216 HeapFree(GetProcessHeap(),0,tempbuf);
217 IStream_Release(pStm);
223 xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
224 if (pStm) IUnknown_Release(pStm);
225 HeapFree(GetProcessHeap(), 0, tempbuf);
229 /********************* OLE Proxy/Stub Factory ********************************/
230 static HRESULT WINAPI
231 PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface, REFIID iid, LPVOID *ppv) {
232 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)||IsEqualIID(iid,&IID_IUnknown)) {
233 *ppv = (LPVOID)iface;
234 /* No ref counting, static class */
237 FIXME("(%s) unknown IID?\n",debugstr_guid(iid));
238 return E_NOINTERFACE;
241 static ULONG WINAPI PSFacBuf_AddRef(LPPSFACTORYBUFFER iface) { return 2; }
242 static ULONG WINAPI PSFacBuf_Release(LPPSFACTORYBUFFER iface) { return 1; }
245 _get_typeinfo_for_iid(REFIID riid, ITypeInfo**ti) {
248 char tlguid[200],typelibkey[300],interfacekey[300],ver[100];
251 DWORD tlguidlen, verlen, type;
255 sprintf( interfacekey, "Interface\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\Typelib",
256 riid->Data1, riid->Data2, riid->Data3,
257 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
258 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7]
261 if (RegOpenKeyA(HKEY_CLASSES_ROOT,interfacekey,&ikey)) {
262 ERR("No %s key found.\n",interfacekey);
266 tlguidlen = sizeof(tlguid);
267 if (RegQueryValueExA(ikey,NULL,NULL,&type,(LPBYTE)tlguid,&tlguidlen)) {
268 ERR("Getting typelib guid failed.\n");
273 verlen = sizeof(ver);
274 if (RegQueryValueExA(ikey,"Version",NULL,&type,(LPBYTE)ver,&verlen)) {
275 ERR("Could not get version value?\n");
280 sprintf(typelibkey,"Typelib\\%s\\%s\\0\\win32",tlguid,ver);
281 tlfnlen = sizeof(tlfn);
282 if (RegQueryValueA(HKEY_CLASSES_ROOT,typelibkey,tlfn,&tlfnlen)) {
283 ERR("Could not get typelib fn?\n");
286 MultiByteToWideChar(CP_ACP, 0, tlfn, -1, tlfnW, -1);
287 hres = LoadTypeLib(tlfnW,&tl);
289 ERR("Failed to load typelib for %s, but it should be there.\n",debugstr_guid(riid));
292 hres = ITypeLib_GetTypeInfoOfGuid(tl,riid,ti);
294 ERR("typelib does not contain info for %s?\n",debugstr_guid(riid));
295 ITypeLib_Release(tl);
298 /* FIXME: do this? ITypeLib_Release(tl); */
302 /* Determine nr of functions. Since we use the toplevel interface and all
303 * inherited ones have lower numbers, we are ok to not to descent into
304 * the inheritance tree I think.
306 static int _nroffuncs(ITypeInfo *tinfo) {
308 const FUNCDESC *fdesc;
313 hres = ITypeInfoImpl_GetInternalFuncDesc(tinfo,n,&fdesc);
316 if (fdesc->oVft/4 > max)
325 #include "pshpack1.h"
327 typedef struct _TMAsmProxy {
341 # warning You need to implement stubless proxies for your architecture
342 typedef struct _TMAsmProxy {
346 typedef struct _TMProxyImpl {
348 const IRpcProxyBufferVtbl *lpvtbl2;
351 TMAsmProxy *asmstubs;
353 IRpcChannelBuffer* chanbuf;
355 CRITICAL_SECTION crit;
356 IUnknown *outerunknown;
360 static HRESULT WINAPI
361 TMProxyImpl_QueryInterface(LPRPCPROXYBUFFER iface, REFIID riid, LPVOID *ppv)
364 if (IsEqualIID(riid,&IID_IUnknown)||IsEqualIID(riid,&IID_IRpcProxyBuffer)) {
365 *ppv = (LPVOID)iface;
366 IRpcProxyBuffer_AddRef(iface);
369 FIXME("no interface for %s\n",debugstr_guid(riid));
370 return E_NOINTERFACE;
374 TMProxyImpl_AddRef(LPRPCPROXYBUFFER iface)
376 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
377 ULONG refCount = InterlockedIncrement(&This->ref);
379 TRACE("(%p)->(ref before=%lu)\n",This, refCount - 1);
385 TMProxyImpl_Release(LPRPCPROXYBUFFER iface)
387 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
388 ULONG refCount = InterlockedDecrement(&This->ref);
390 TRACE("(%p)->(ref before=%lu)\n",This, refCount + 1);
394 if (This->dispatch) IDispatch_Release(This->dispatch);
395 DeleteCriticalSection(&This->crit);
396 if (This->chanbuf) IRpcChannelBuffer_Release(This->chanbuf);
397 VirtualFree(This->asmstubs, 0, MEM_RELEASE);
403 static HRESULT WINAPI
405 LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer)
407 ICOM_THIS_MULTI(TMProxyImpl, lpvtbl2, iface);
409 TRACE("(%p)\n", pRpcChannelBuffer);
411 EnterCriticalSection(&This->crit);
413 IRpcChannelBuffer_AddRef(pRpcChannelBuffer);
414 This->chanbuf = pRpcChannelBuffer;
416 LeaveCriticalSection(&This->crit);
422 TMProxyImpl_Disconnect(LPRPCPROXYBUFFER iface)
424 ICOM_THIS_MULTI(TMProxyImpl, lpvtbl2, iface);
428 EnterCriticalSection(&This->crit);
430 IRpcChannelBuffer_Release(This->chanbuf);
431 This->chanbuf = NULL;
433 LeaveCriticalSection(&This->crit);
437 static const IRpcProxyBufferVtbl tmproxyvtable = {
438 TMProxyImpl_QueryInterface,
442 TMProxyImpl_Disconnect
445 /* how much space do we use on stack in DWORD steps. */
450 return 8/sizeof(DWORD);
452 return sizeof(double)/sizeof(DWORD);
454 return sizeof(CY)/sizeof(DWORD);
456 return sizeof(DATE)/sizeof(DWORD);
458 return (sizeof(VARIANT)+3)/sizeof(DWORD);
465 _xsize(TYPEDESC *td) {
470 return sizeof(VARIANT)+3;
473 ARRAYDESC *adesc = td->u.lpadesc;
475 for (i=0;i<adesc->cDims;i++)
476 arrsize *= adesc->rgbounds[i].cElements;
477 return arrsize*_xsize(&adesc->tdescElem);
505 TRACE("(tdesc.vt %s)\n",debugstr_vt(tdesc->vt));
508 case VT_EMPTY: /* nothing. empty variant for instance */
514 if (debugout) TRACE_(olerelay)("%lx%lx",arg[0],arg[1]);
516 hres = xbuf_add(buf,(LPBYTE)arg,8);
525 if (debugout) TRACE_(olerelay)("%lx",*arg);
527 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
532 if (debugout) TRACE_(olerelay)("%04lx",*arg & 0xffff);
534 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
539 if (debugout) TRACE_(olerelay)("%02lx",*arg & 0xff);
541 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
545 if (debugout) TRACE_(olerelay)("&0x%lx",*arg);
547 hres = xbuf_add(buf,(LPBYTE)(DWORD*)*arg,sizeof(DWORD));
548 /* do not dealloc at this time */
552 VARIANT *vt = (VARIANT*)arg;
553 DWORD vttype = V_VT(vt);
555 if (debugout) TRACE_(olerelay)("Vt(%s%s)(",debugstr_vt(vttype),debugstr_vf(vttype));
558 hres = xbuf_add(buf,(LPBYTE)&vttype,sizeof(vttype));
559 if (hres) return hres;
561 /* need to recurse since we need to free the stuff */
562 hres = serialize_param(tinfo,writeit,debugout,dealloc,&tdesc2,(DWORD*)&(V_I4(vt)),buf);
563 if (debugout) TRACE_(olerelay)(")");
566 case VT_BSTR|VT_BYREF: {
567 if (debugout) TRACE_(olerelay)("[byref]'%s'", *(BSTR*)*arg ? relaystr(*((BSTR*)*arg)) : "<bstr NULL>");
569 /* ptr to ptr to magic widestring, basically */
570 BSTR *bstr = (BSTR *) *arg;
573 /* -1 means "null string" which is equivalent to empty string */
575 hres = xbuf_add(buf, (LPBYTE)&len,sizeof(DWORD));
576 if (hres) return hres;
578 len = *((DWORD*)*bstr-1)/sizeof(WCHAR);
579 hres = xbuf_add(buf,(LPBYTE)&len,sizeof(DWORD));
580 if (hres) return hres;
581 hres = xbuf_add(buf,(LPBYTE)*bstr,len * sizeof(WCHAR));
582 if (hres) return hres;
586 if (dealloc && arg) {
587 BSTR *str = *((BSTR **)arg);
596 TRACE_(olerelay)("%s",relaystr((WCHAR*)*arg));
598 TRACE_(olerelay)("<bstr NULL>");
601 BSTR bstr = (BSTR)*arg;
605 hres = xbuf_add(buf,(LPBYTE)&len,sizeof(DWORD));
606 if (hres) return hres;
608 len = *((DWORD*)bstr-1)/sizeof(WCHAR);
609 hres = xbuf_add(buf,(LPBYTE)&len,sizeof(DWORD));
610 if (hres) return hres;
611 hres = xbuf_add(buf,(LPBYTE)bstr,len * sizeof(WCHAR));
612 if (hres) return hres;
617 SysFreeString((BSTR)*arg);
622 BOOL derefhere = TRUE;
624 if (tdesc->u.lptdesc->vt == VT_USERDEFINED) {
628 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.lptdesc->u.hreftype,&tinfo2);
630 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.lptdesc->u.hreftype);
633 ITypeInfo_GetTypeAttr(tinfo2,&tattr);
634 switch (tattr->typekind) {
635 case TKIND_ENUM: /* confirmed */
636 case TKIND_RECORD: /* FIXME: mostly untested */
639 case TKIND_ALIAS: /* FIXME: untested */
640 case TKIND_DISPATCH: /* will be done in VT_USERDEFINED case */
641 case TKIND_INTERFACE: /* will be done in VT_USERDEFINED case */
645 FIXME("unhandled switch cases tattr->typekind %d\n", tattr->typekind);
649 ITypeInfo_Release(tinfo2);
652 if (debugout) TRACE_(olerelay)("*");
653 /* Write always, so the other side knows when it gets a NULL pointer.
655 cookie = *arg ? 0x42424242 : 0;
656 hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
660 if (debugout) TRACE_(olerelay)("NULL");
663 hres = serialize_param(tinfo,writeit,debugout,dealloc,tdesc->u.lptdesc,(DWORD*)*arg,buf);
664 if (derefhere && dealloc) HeapFree(GetProcessHeap(),0,(LPVOID)*arg);
668 if (debugout) TRACE_(olerelay)("unk(0x%lx)",*arg);
670 hres = _marshal_interface(buf,&IID_IUnknown,(LPUNKNOWN)*arg);
673 if (debugout) TRACE_(olerelay)("idisp(0x%lx)",*arg);
675 hres = _marshal_interface(buf,&IID_IDispatch,(LPUNKNOWN)*arg);
678 if (debugout) TRACE_(olerelay)("<void>");
680 case VT_USERDEFINED: {
684 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
686 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
689 ITypeInfo_GetTypeAttr(tinfo2,&tattr);
690 switch (tattr->typekind) {
692 case TKIND_INTERFACE:
694 hres=_marshal_interface(buf,&(tattr->guid),(LPUNKNOWN)arg);
696 IUnknown_Release((LPUNKNOWN)arg);
700 if (debugout) TRACE_(olerelay)("{");
701 for (i=0;i<tattr->cVars;i++) {
706 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
708 ERR("Could not get vardesc of %d\n",i);
711 /* Need them for hack below */
713 memset(names,0,sizeof(names));
714 hres = ITypeInfo_GetNames(tinfo2,vdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
715 if (nrofnames > sizeof(names)/sizeof(names[0])) {
716 ERR("Need more names!\n");
718 if (!hres && debugout)
719 TRACE_(olerelay)("%s=",relaystr(names[0]));
721 elem2 = &vdesc->elemdescVar;
722 tdesc2 = &elem2->tdesc;
723 hres = serialize_param(
729 (DWORD*)(((LPBYTE)arg)+vdesc->u.oInst),
732 ITypeInfo_ReleaseVarDesc(tinfo2, vdesc);
735 if (debugout && (i<(tattr->cVars-1)))
736 TRACE_(olerelay)(",");
738 if (debugout) TRACE_(olerelay)("}");
742 return serialize_param(tinfo2,writeit,debugout,dealloc,&tattr->tdescAlias,arg,buf);
745 if (debugout) TRACE_(olerelay)("%lx",*arg);
747 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
750 FIXME("Unhandled typekind %d\n",tattr->typekind);
754 ITypeInfo_Release(tinfo2);
758 ARRAYDESC *adesc = tdesc->u.lpadesc;
761 if (debugout) TRACE_(olerelay)("carr");
762 for (i=0;i<adesc->cDims;i++) {
763 if (debugout) TRACE_(olerelay)("[%ld]",adesc->rgbounds[i].cElements);
764 arrsize *= adesc->rgbounds[i].cElements;
766 if (debugout) TRACE_(olerelay)("(vt %s)",debugstr_vt(adesc->tdescElem.vt));
767 if (debugout) TRACE_(olerelay)("[");
768 for (i=0;i<arrsize;i++) {
769 hres = serialize_param(tinfo, writeit, debugout, dealloc, &adesc->tdescElem, (DWORD*)((LPBYTE)arg+i*_xsize(&adesc->tdescElem)), buf);
772 if (debugout && (i<arrsize-1)) TRACE_(olerelay)(",");
774 if (debugout) TRACE_(olerelay)("]");
778 ERR("Unhandled marshal type %d.\n",tdesc->vt);
795 TRACE("vt %s at %p\n",debugstr_vt(tdesc->vt),arg);
800 if (debugout) TRACE_(olerelay)("<empty>");
803 if (debugout) TRACE_(olerelay)("<null>");
806 VARIANT *vt = (VARIANT*)arg;
811 hres = xbuf_get(buf,(LPBYTE)&vttype,sizeof(vttype));
813 FIXME("vt type not read?\n");
816 memset(&tdesc2,0,sizeof(tdesc2));
819 if (debugout) TRACE_(olerelay)("Vt(%s%s)(",debugstr_vt(vttype),debugstr_vf(vttype));
820 hres = deserialize_param(tinfo, readit, debugout, alloc, &tdesc2, (DWORD*)&(V_I4(vt)), buf);
821 TRACE_(olerelay)(")");
832 hres = xbuf_get(buf,(LPBYTE)arg,8);
833 if (hres) ERR("Failed to read integer 8 byte\n");
835 if (debugout) TRACE_(olerelay)("%lx%lx",arg[0],arg[1]);
844 hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
845 if (hres) ERR("Failed to read integer 4 byte\n");
847 if (debugout) TRACE_(olerelay)("%lx",*arg);
853 hres = xbuf_get(buf,(LPBYTE)&x,sizeof(DWORD));
854 if (hres) ERR("Failed to read integer 4 byte\n");
857 if (debugout) TRACE_(olerelay)("%04lx",*arg & 0xffff);
863 hres = xbuf_get(buf,(LPBYTE)&x,sizeof(DWORD));
864 if (hres) ERR("Failed to read integer 4 byte\n");
867 if (debugout) TRACE_(olerelay)("%02lx",*arg & 0xff);
872 *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
874 hres = xbuf_get(buf,(LPBYTE)*arg,sizeof(DWORD));
875 if (hres) ERR("Failed to read integer 4 byte\n");
877 if (debugout) TRACE_(olerelay)("&0x%lx",*(DWORD*)*arg);
879 case VT_BSTR|VT_BYREF: {
880 BSTR **bstr = (BSTR **)arg;
885 hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
887 ERR("failed to read bstr klen\n");
891 *bstr = CoTaskMemAlloc(sizeof(BSTR *));
893 if (debugout) TRACE_(olerelay)("<bstr NULL>");
895 str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
896 hres = xbuf_get(buf,(LPBYTE)str,len*sizeof(WCHAR));
898 ERR("Failed to read BSTR.\n");
901 *bstr = CoTaskMemAlloc(sizeof(BSTR *));
902 **bstr = SysAllocStringLen(str,len);
903 if (debugout) TRACE_(olerelay)("%s",relaystr(str));
904 HeapFree(GetProcessHeap(),0,str);
916 hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
918 ERR("failed to read bstr klen\n");
923 if (debugout) TRACE_(olerelay)("<bstr NULL>");
925 str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
926 hres = xbuf_get(buf,(LPBYTE)str,len*sizeof(WCHAR));
928 ERR("Failed to read BSTR.\n");
931 *arg = (DWORD)SysAllocStringLen(str,len);
932 if (debugout) TRACE_(olerelay)("%s",relaystr(str));
933 HeapFree(GetProcessHeap(),0,str);
942 BOOL derefhere = TRUE;
944 if (tdesc->u.lptdesc->vt == VT_USERDEFINED) {
948 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.lptdesc->u.hreftype,&tinfo2);
950 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.lptdesc->u.hreftype);
953 ITypeInfo_GetTypeAttr(tinfo2,&tattr);
954 switch (tattr->typekind) {
955 case TKIND_ENUM: /* confirmed */
956 case TKIND_RECORD: /* FIXME: mostly untested */
959 case TKIND_ALIAS: /* FIXME: untested */
960 case TKIND_DISPATCH: /* will be done in VT_USERDEFINED case */
961 case TKIND_INTERFACE: /* will be done in VT_USERDEFINED case */
965 FIXME("unhandled switch cases tattr->typekind %d\n", tattr->typekind);
969 ITypeInfo_Release(tinfo2);
971 /* read it in all cases, we need to know if we have
972 * NULL pointer or not.
974 hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
976 ERR("Failed to load pointer cookie.\n");
979 if (cookie != 0x42424242) {
980 /* we read a NULL ptr from the remote side */
981 if (debugout) TRACE_(olerelay)("NULL");
985 if (debugout) TRACE_(olerelay)("*");
987 /* Allocate space for the referenced struct */
989 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,_xsize(tdesc->u.lptdesc));
992 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, (LPDWORD)*arg, buf);
994 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, arg, buf);
997 /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
999 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
1002 hres = _unmarshal_interface(buf,&IID_IUnknown,(LPUNKNOWN*)arg);
1004 TRACE_(olerelay)("unk(%p)",arg);
1009 hres = _unmarshal_interface(buf,&IID_IDispatch,(LPUNKNOWN*)arg);
1011 TRACE_(olerelay)("idisp(%p)",arg);
1014 if (debugout) TRACE_(olerelay)("<void>");
1016 case VT_USERDEFINED: {
1020 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
1022 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
1025 hres = ITypeInfo_GetTypeAttr(tinfo2,&tattr);
1027 ERR("Could not get typeattr in VT_USERDEFINED.\n");
1029 switch (tattr->typekind) {
1030 case TKIND_DISPATCH:
1031 case TKIND_INTERFACE:
1033 hres = _unmarshal_interface(buf,&(tattr->guid),(LPUNKNOWN*)arg);
1035 case TKIND_RECORD: {
1039 *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,tattr->cbSizeInstance);
1041 if (debugout) TRACE_(olerelay)("{");
1042 for (i=0;i<tattr->cVars;i++) {
1045 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
1047 ERR("Could not get vardesc of %d\n",i);
1050 hres = deserialize_param(
1055 &vdesc->elemdescVar.tdesc,
1056 (DWORD*)(((LPBYTE)*arg)+vdesc->u.oInst),
1059 ITypeInfo2_ReleaseVarDesc(tinfo2, vdesc);
1060 if (debugout && (i<tattr->cVars-1)) TRACE_(olerelay)(",");
1062 if (debugout) TRACE_(olerelay)("}");
1066 return deserialize_param(tinfo2,readit,debugout,alloc,&tattr->tdescAlias,arg,buf);
1069 hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
1070 if (hres) ERR("Failed to read enum (4 byte)\n");
1072 if (debugout) TRACE_(olerelay)("%lx",*arg);
1075 ERR("Unhandled typekind %d\n",tattr->typekind);
1081 ERR("failed to stuballoc in TKIND_RECORD.\n");
1082 ITypeInfo_Release(tinfo2);
1086 /* arg is pointing to the start of the array. */
1087 ARRAYDESC *adesc = tdesc->u.lpadesc;
1090 if (adesc->cDims > 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
1091 for (i=0;i<adesc->cDims;i++)
1092 arrsize *= adesc->rgbounds[i].cElements;
1093 for (i=0;i<arrsize;i++)
1100 (DWORD*)((LPBYTE)(arg)+i*_xsize(&adesc->tdescElem)),
1106 ERR("No handler for VT type %d!\n",tdesc->vt);
1112 /* Searches function, also in inherited interfaces */
1115 ITypeInfo *tinfo, int iMethod, ITypeInfo **tactual, const FUNCDESC **fdesc, BSTR *iname, BSTR *fname)
1120 if (fname) *fname = NULL;
1121 if (iname) *iname = NULL;
1124 ITypeInfo_AddRef(*tactual);
1127 hres = ITypeInfoImpl_GetInternalFuncDesc(tinfo, i, fdesc);
1134 hres = ITypeInfo_GetTypeAttr(tinfo, &attr);
1136 ERR("GetTypeAttr failed with %lx\n",hres);
1139 /* Not found, so look in inherited ifaces. */
1140 for (j=0;j<attr->cImplTypes;j++) {
1141 hres = ITypeInfo_GetRefTypeOfImplType(tinfo, j, &href);
1143 ERR("Did not find a reftype for interface offset %d?\n",j);
1146 hres = ITypeInfo_GetRefTypeInfo(tinfo, href, &tinfo2);
1148 ERR("Did not find a typeinfo for reftype %ld?\n",href);
1151 hres = _get_funcdesc(tinfo2,iMethod,tactual,fdesc,iname,fname);
1152 ITypeInfo_Release(tinfo2);
1153 if (!hres) return S_OK;
1157 if (((*fdesc)->oVft/4) == iMethod) {
1159 ITypeInfo_GetDocumentation(tinfo,(*fdesc)->memid,fname,NULL,NULL,NULL);
1161 ITypeInfo_GetDocumentation(tinfo,-1,iname,NULL,NULL,NULL);
1169 xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */)
1171 DWORD *args = ((DWORD*)&tpinfo)+1, *xargs;
1172 const FUNCDESC *fdesc;
1174 int i, relaydeb = TRACE_ON(olerelay);
1181 DWORD remoteresult = 0;
1183 IRpcChannelBuffer *chanbuf;
1185 EnterCriticalSection(&tpinfo->crit);
1187 hres = _get_funcdesc(tpinfo->tinfo,method,&tinfo,&fdesc,&iname,&fname);
1189 ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method);
1190 ITypeInfo_Release(tinfo);
1191 LeaveCriticalSection(&tpinfo->crit);
1195 if (!tpinfo->chanbuf)
1197 WARN("Tried to use disconnected proxy\n");
1198 ITypeInfo_Release(tinfo);
1199 LeaveCriticalSection(&tpinfo->crit);
1200 return RPC_E_DISCONNECTED;
1202 chanbuf = tpinfo->chanbuf;
1203 IRpcChannelBuffer_AddRef(chanbuf);
1205 LeaveCriticalSection(&tpinfo->crit);
1208 TRACE_(olerelay)("->");
1210 TRACE_(olerelay)("%s:",relaystr(iname));
1212 TRACE_(olerelay)("%s(%d)",relaystr(fname),method);
1214 TRACE_(olerelay)("%d",method);
1215 TRACE_(olerelay)("(");
1218 if (iname) SysFreeString(iname);
1219 if (fname) SysFreeString(fname);
1221 memset(&buf,0,sizeof(buf));
1223 /* normal typelib driven serializing */
1225 /* Need them for hack below */
1226 memset(names,0,sizeof(names));
1227 if (ITypeInfo_GetNames(tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames))
1229 if (nrofnames > sizeof(names)/sizeof(names[0]))
1230 ERR("Need more names!\n");
1233 for (i=0;i<fdesc->cParams;i++) {
1234 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1236 if (i) TRACE_(olerelay)(",");
1237 if (i+1<nrofnames && names[i+1])
1238 TRACE_(olerelay)("%s=",relaystr(names[i+1]));
1240 /* No need to marshal other data than FIN and any VT_PTR. */
1241 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN || !elem->u.paramdesc.wParamFlags) && (elem->tdesc.vt != VT_PTR)) {
1242 xargs+=_argsize(elem->tdesc.vt);
1243 if (relaydeb) TRACE_(olerelay)("[out]");
1246 hres = serialize_param(
1248 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN || !elem->u.paramdesc.wParamFlags,
1257 ERR("Failed to serialize param, hres %lx\n",hres);
1260 xargs+=_argsize(elem->tdesc.vt);
1262 if (relaydeb) TRACE_(olerelay)(")");
1264 memset(&msg,0,sizeof(msg));
1265 msg.cbBuffer = buf.curoff;
1266 msg.iMethod = method;
1267 hres = IRpcChannelBuffer_GetBuffer(chanbuf,&msg,&(tpinfo->iid));
1269 ERR("RpcChannelBuffer GetBuffer failed, %lx\n",hres);
1272 memcpy(msg.Buffer,buf.base,buf.curoff);
1273 if (relaydeb) TRACE_(olerelay)("\n");
1274 hres = IRpcChannelBuffer_SendReceive(chanbuf,&msg,&status);
1276 ERR("RpcChannelBuffer SendReceive failed, %lx\n",hres);
1280 if (relaydeb) TRACE_(olerelay)(" status = %08lx (",status);
1282 buf.base = HeapReAlloc(GetProcessHeap(),0,buf.base,msg.cbBuffer);
1284 buf.base = HeapAlloc(GetProcessHeap(),0,msg.cbBuffer);
1285 buf.size = msg.cbBuffer;
1286 memcpy(buf.base,msg.Buffer,buf.size);
1289 /* generic deserializer using typelib description */
1292 for (i=0;i<fdesc->cParams;i++) {
1293 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1296 if (i) TRACE_(olerelay)(",");
1297 if (i+1<nrofnames && names[i+1]) TRACE_(olerelay)("%s=",relaystr(names[i+1]));
1299 /* No need to marshal other data than FOUT and any VT_PTR */
1300 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT) && (elem->tdesc.vt != VT_PTR)) {
1301 xargs += _argsize(elem->tdesc.vt);
1302 if (relaydeb) TRACE_(olerelay)("[in]");
1305 hres = deserialize_param(
1307 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1315 ERR("Failed to unmarshall param, hres %lx\n",hres);
1319 xargs += _argsize(elem->tdesc.vt);
1322 hres = xbuf_get(&buf, (LPBYTE)&remoteresult, sizeof(DWORD));
1325 if (relaydeb) TRACE_(olerelay)(") = %08lx\n", remoteresult);
1327 hres = remoteresult;
1330 HeapFree(GetProcessHeap(),0,buf.base);
1331 IRpcChannelBuffer_Release(chanbuf);
1332 ITypeInfo_Release(tinfo);
1333 TRACE("-- 0x%08lx\n", hres);
1337 HRESULT WINAPI ProxyIUnknown_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
1339 TMProxyImpl *proxy = (TMProxyImpl *)iface;
1341 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
1343 if (proxy->outerunknown)
1344 return IUnknown_QueryInterface(proxy->outerunknown, riid, ppv);
1346 FIXME("No interface\n");
1347 return E_NOINTERFACE;
1350 ULONG WINAPI ProxyIUnknown_AddRef(IUnknown *iface)
1352 TMProxyImpl *proxy = (TMProxyImpl *)iface;
1356 if (proxy->outerunknown)
1357 return IUnknown_AddRef(proxy->outerunknown);
1359 return 2; /* FIXME */
1362 ULONG WINAPI ProxyIUnknown_Release(IUnknown *iface)
1364 TMProxyImpl *proxy = (TMProxyImpl *)iface;
1368 if (proxy->outerunknown)
1369 return IUnknown_Release(proxy->outerunknown);
1371 return 1; /* FIXME */
1374 static HRESULT WINAPI ProxyIDispatch_GetTypeInfoCount(LPDISPATCH iface, UINT * pctinfo)
1376 TMProxyImpl *This = (TMProxyImpl *)iface;
1379 TRACE("(%p)\n", pctinfo);
1381 if (!This->dispatch)
1383 hr = IUnknown_QueryInterface(This->outerunknown, &IID_IDispatch,
1384 (LPVOID *)&This->dispatch);
1387 hr = IDispatch_GetTypeInfoCount(This->dispatch, pctinfo);
1392 static HRESULT WINAPI ProxyIDispatch_GetTypeInfo(LPDISPATCH iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)
1394 TMProxyImpl *This = (TMProxyImpl *)iface;
1397 TRACE("(%d, %lx, %p)\n", iTInfo, lcid, ppTInfo);
1399 if (!This->dispatch)
1401 hr = IUnknown_QueryInterface(This->outerunknown, &IID_IDispatch,
1402 (LPVOID *)&This->dispatch);
1405 hr = IDispatch_GetTypeInfo(This->dispatch, iTInfo, lcid, ppTInfo);
1410 static HRESULT WINAPI ProxyIDispatch_GetIDsOfNames(LPDISPATCH iface, REFIID riid, LPOLESTR * rgszNames, UINT cNames, LCID lcid, DISPID * rgDispId)
1412 TMProxyImpl *This = (TMProxyImpl *)iface;
1415 TRACE("(%s, %p, %d, 0x%lx, %p)\n", debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
1417 if (!This->dispatch)
1419 hr = IUnknown_QueryInterface(This->outerunknown, &IID_IDispatch,
1420 (LPVOID *)&This->dispatch);
1423 hr = IDispatch_GetIDsOfNames(This->dispatch, riid, rgszNames,
1424 cNames, lcid, rgDispId);
1429 static HRESULT WINAPI ProxyIDispatch_Invoke(LPDISPATCH iface, DISPID dispIdMember, REFIID riid, LCID lcid,
1430 WORD wFlags, DISPPARAMS * pDispParams, VARIANT * pVarResult,
1431 EXCEPINFO * pExcepInfo, UINT * puArgErr)
1433 TMProxyImpl *This = (TMProxyImpl *)iface;
1436 TRACE("(%ld, %s, 0x%lx, 0x%x, %p, %p, %p, %p)\n", dispIdMember, debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1438 if (!This->dispatch)
1440 hr = IUnknown_QueryInterface(This->outerunknown, &IID_IDispatch,
1441 (LPVOID *)&This->dispatch);
1444 hr = IDispatch_Invoke(This->dispatch, dispIdMember, riid, lcid,
1445 wFlags, pDispParams, pVarResult, pExcepInfo,
1451 static HRESULT WINAPI
1452 PSFacBuf_CreateProxy(
1453 LPPSFACTORYBUFFER iface, IUnknown* pUnkOuter, REFIID riid,
1454 IRpcProxyBuffer **ppProxy, LPVOID *ppv)
1459 const FUNCDESC *fdesc;
1463 TRACE("(...%s...)\n",debugstr_guid(riid));
1464 hres = _get_typeinfo_for_iid(riid,&tinfo);
1466 ERR("No typeinfo for %s?\n",debugstr_guid(riid));
1469 nroffuncs = _nroffuncs(tinfo);
1470 proxy = CoTaskMemAlloc(sizeof(TMProxyImpl));
1471 if (!proxy) return E_OUTOFMEMORY;
1473 assert(sizeof(TMAsmProxy) == 12);
1475 proxy->dispatch = NULL;
1476 proxy->outerunknown = pUnkOuter;
1477 proxy->asmstubs = VirtualAlloc(NULL, sizeof(TMAsmProxy) * nroffuncs, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
1478 if (!proxy->asmstubs) {
1479 ERR("Could not commit pages for proxy thunks\n");
1480 CoTaskMemFree(proxy);
1481 return E_OUTOFMEMORY;
1484 InitializeCriticalSection(&proxy->crit);
1486 proxy->lpvtbl = HeapAlloc(GetProcessHeap(),0,sizeof(LPBYTE)*nroffuncs);
1487 for (i=0;i<nroffuncs;i++) {
1488 TMAsmProxy *xasm = proxy->asmstubs+i;
1492 proxy->lpvtbl[i] = ProxyIUnknown_QueryInterface;
1495 proxy->lpvtbl[i] = ProxyIUnknown_AddRef;
1498 proxy->lpvtbl[i] = ProxyIUnknown_Release;
1502 /* nrofargs without This */
1505 hres = _get_funcdesc(tinfo,i,&tinfo2,&fdesc,NULL,NULL);
1506 ITypeInfo_Release(tinfo2);
1508 ERR("GetFuncDesc %lx should not fail here.\n",hres);
1511 /* some args take more than 4 byte on the stack */
1513 for (j=0;j<fdesc->cParams;j++)
1514 nrofargs += _argsize(fdesc->lprgelemdescParam[j].tdesc.vt);
1517 if (fdesc->callconv != CC_STDCALL) {
1518 ERR("calling convention is not stdcall????\n");
1521 /* popl %eax - return ptr
1528 * arg3 arg2 arg1 <method> <returnptr>
1530 xasm->popleax = 0x58;
1531 xasm->pushlval = 0x6a;
1533 xasm->pushleax = 0x50;
1534 xasm->lcall = 0xe8; /* relative jump */
1535 xasm->xcall = (DWORD)xCall;
1536 xasm->xcall -= (DWORD)&(xasm->lret);
1538 xasm->bytestopop= (nrofargs+2)*4; /* pop args, This, iMethod */
1539 proxy->lpvtbl[i] = xasm;
1542 FIXME("not implemented on non i386\n");
1549 /* if we derive from IDispatch then defer to its proxy for its methods */
1550 hres = ITypeInfo_GetTypeAttr(tinfo, &typeattr);
1553 if (typeattr->wTypeFlags & TYPEFLAG_FDISPATCHABLE)
1555 proxy->lpvtbl[3] = ProxyIDispatch_GetTypeInfoCount;
1556 proxy->lpvtbl[4] = ProxyIDispatch_GetTypeInfo;
1557 proxy->lpvtbl[5] = ProxyIDispatch_GetIDsOfNames;
1558 proxy->lpvtbl[6] = ProxyIDispatch_Invoke;
1560 ITypeInfo_ReleaseTypeAttr(tinfo, typeattr);
1563 proxy->lpvtbl2 = &tmproxyvtable;
1564 /* one reference for the proxy */
1566 proxy->tinfo = tinfo;
1567 memcpy(&proxy->iid,riid,sizeof(*riid));
1569 *ppv = (LPVOID)proxy;
1570 *ppProxy = (IRpcProxyBuffer *)&(proxy->lpvtbl2);
1571 IUnknown_AddRef((IUnknown *)*ppv);
1575 typedef struct _TMStubImpl {
1576 const IRpcStubBufferVtbl *lpvtbl;
1584 static HRESULT WINAPI
1585 TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface, REFIID riid, LPVOID *ppv)
1587 if (IsEqualIID(riid,&IID_IRpcStubBuffer)||IsEqualIID(riid,&IID_IUnknown)){
1588 *ppv = (LPVOID)iface;
1589 IRpcStubBuffer_AddRef(iface);
1592 FIXME("%s, not supported IID.\n",debugstr_guid(riid));
1593 return E_NOINTERFACE;
1597 TMStubImpl_AddRef(LPRPCSTUBBUFFER iface)
1599 TMStubImpl *This = (TMStubImpl *)iface;
1600 ULONG refCount = InterlockedIncrement(&This->ref);
1602 TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
1608 TMStubImpl_Release(LPRPCSTUBBUFFER iface)
1610 TMStubImpl *This = (TMStubImpl *)iface;
1611 ULONG refCount = InterlockedDecrement(&This->ref);
1613 TRACE("(%p)->(ref before=%lu)\n", This, refCount + 1);
1617 IRpcStubBuffer_Disconnect(iface);
1618 ITypeInfo_Release(This->tinfo);
1619 CoTaskMemFree(This);
1624 static HRESULT WINAPI
1625 TMStubImpl_Connect(LPRPCSTUBBUFFER iface, LPUNKNOWN pUnkServer)
1627 TMStubImpl *This = (TMStubImpl *)iface;
1629 TRACE("(%p)->(%p)\n", This, pUnkServer);
1631 IUnknown_AddRef(pUnkServer);
1632 This->pUnk = pUnkServer;
1637 TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface)
1639 TMStubImpl *This = (TMStubImpl *)iface;
1641 TRACE("(%p)->()\n", This);
1645 IUnknown_Release(This->pUnk);
1650 static HRESULT WINAPI
1652 LPRPCSTUBBUFFER iface, RPCOLEMESSAGE* xmsg,IRpcChannelBuffer*rpcchanbuf)
1655 const FUNCDESC *fdesc;
1656 TMStubImpl *This = (TMStubImpl *)iface;
1658 DWORD *args, res, *xargs, nrofargs;
1665 memset(&buf,0,sizeof(buf));
1666 buf.size = xmsg->cbBuffer;
1667 buf.base = HeapAlloc(GetProcessHeap(), 0, xmsg->cbBuffer);
1668 memcpy(buf.base, xmsg->Buffer, xmsg->cbBuffer);
1673 if (xmsg->iMethod < 3) {
1674 ERR("IUnknown methods cannot be marshaled by the typelib marshaler\n");
1675 return E_UNEXPECTED;
1678 hres = _get_funcdesc(This->tinfo,xmsg->iMethod,&tinfo,&fdesc,&iname,NULL);
1680 ERR("GetFuncDesc on method %ld failed with %lx\n",xmsg->iMethod,hres);
1684 if (iname && !lstrcmpW(iname, IDispatchW))
1686 ERR("IDispatch cannot be marshaled by the typelib marshaler\n");
1687 ITypeInfo_Release(tinfo);
1688 return E_UNEXPECTED;
1691 if (iname) SysFreeString (iname);
1693 /* Need them for hack below */
1694 memset(names,0,sizeof(names));
1695 ITypeInfo_GetNames(tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
1696 if (nrofnames > sizeof(names)/sizeof(names[0])) {
1697 ERR("Need more names!\n");
1700 /*dump_FUNCDESC(fdesc);*/
1702 for (i=0;i<fdesc->cParams;i++)
1703 nrofargs += _argsize(fdesc->lprgelemdescParam[i].tdesc.vt);
1704 args = HeapAlloc(GetProcessHeap(),0,(nrofargs+1)*sizeof(DWORD));
1705 if (!args) return E_OUTOFMEMORY;
1707 /* Allocate all stuff used by call. */
1709 for (i=0;i<fdesc->cParams;i++) {
1710 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1712 hres = deserialize_param(
1714 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN || !elem->u.paramdesc.wParamFlags,
1721 xargs += _argsize(elem->tdesc.vt);
1723 ERR("Failed to deserialize param %s, hres %lx\n",relaystr(names[i+1]),hres);
1728 args[0] = (DWORD)This->pUnk;
1730 (*((FARPROC**)args[0]))[fdesc->oVft/4],
1738 for (i=0;i<fdesc->cParams;i++) {
1739 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1740 hres = serialize_param(
1742 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1749 xargs += _argsize(elem->tdesc.vt);
1751 ERR("Failed to stuballoc param, hres %lx\n",hres);
1756 hres = xbuf_add (&buf, (LPBYTE)&res, sizeof(DWORD));
1760 ITypeInfo_Release(tinfo);
1761 HeapFree(GetProcessHeap(), 0, args);
1763 xmsg->cbBuffer = buf.curoff;
1766 hres = IRpcChannelBuffer_GetBuffer(rpcchanbuf, xmsg, &This->iid);
1768 ERR("IRpcChannelBuffer_GetBuffer failed with error 0x%08lx\n", hres);
1772 /* FIXME: remove this case when we start sending an IRpcChannelBuffer
1773 * object with builtin OLE */
1774 RPC_STATUS status = I_RpcGetBuffer((RPC_MESSAGE *)xmsg);
1775 if (status != RPC_S_OK)
1777 ERR("I_RpcGetBuffer failed with error %ld\n", status);
1783 memcpy(xmsg->Buffer, buf.base, buf.curoff);
1785 HeapFree(GetProcessHeap(), 0, buf.base);
1787 TRACE("returning\n");
1791 static LPRPCSTUBBUFFER WINAPI
1792 TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface, REFIID riid) {
1793 FIXME("Huh (%s)?\n",debugstr_guid(riid));
1798 TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface) {
1799 TMStubImpl *This = (TMStubImpl *)iface;
1802 return This->ref; /*FIXME? */
1805 static HRESULT WINAPI
1806 TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface, LPVOID *ppv) {
1811 TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface, LPVOID ppv) {
1815 static const IRpcStubBufferVtbl tmstubvtbl = {
1816 TMStubImpl_QueryInterface,
1820 TMStubImpl_Disconnect,
1822 TMStubImpl_IsIIDSupported,
1823 TMStubImpl_CountRefs,
1824 TMStubImpl_DebugServerQueryInterface,
1825 TMStubImpl_DebugServerRelease
1828 static HRESULT WINAPI
1829 PSFacBuf_CreateStub(
1830 LPPSFACTORYBUFFER iface, REFIID riid,IUnknown *pUnkServer,
1831 IRpcStubBuffer** ppStub
1837 TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub);
1838 hres = _get_typeinfo_for_iid(riid,&tinfo);
1840 ERR("No typeinfo for %s?\n",debugstr_guid(riid));
1843 stub = CoTaskMemAlloc(sizeof(TMStubImpl));
1845 return E_OUTOFMEMORY;
1846 stub->lpvtbl = &tmstubvtbl;
1848 stub->tinfo = tinfo;
1849 memcpy(&(stub->iid),riid,sizeof(*riid));
1850 hres = IRpcStubBuffer_Connect((LPRPCSTUBBUFFER)stub,pUnkServer);
1851 *ppStub = (LPRPCSTUBBUFFER)stub;
1852 TRACE("IRpcStubBuffer: %p\n", stub);
1854 ERR("Connect to pUnkServer failed?\n");
1858 static const IPSFactoryBufferVtbl psfacbufvtbl = {
1859 PSFacBuf_QueryInterface,
1862 PSFacBuf_CreateProxy,
1866 /* This is the whole PSFactoryBuffer object, just the vtableptr */
1867 static const IPSFactoryBufferVtbl *lppsfac = &psfacbufvtbl;
1869 /***********************************************************************
1870 * TMARSHAL_DllGetClassObject
1872 HRESULT TMARSHAL_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
1874 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)) {
1878 return E_NOINTERFACE;