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
46 #include "wine/debug.h"
48 static const WCHAR IDispatchW[] = { 'I','D','i','s','p','a','t','c','h',0};
50 WINE_DEFAULT_DEBUG_CHANNEL(ole);
51 WINE_DECLARE_DEBUG_CHANNEL(olerelay);
53 #define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
55 typedef struct _marshal_state {
61 /* used in the olerelay code to avoid having the L"" stuff added by debugstr_w */
62 static char *relaystr(WCHAR *in) {
63 char *tmp = (char *)debugstr_w(in);
65 tmp[strlen(tmp)-1] = '\0';
70 xbuf_add(marshal_state *buf, LPBYTE stuff, DWORD size) {
71 while (buf->size - buf->curoff < size) {
74 buf->base = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,buf->base,buf->size);
78 buf->base = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,32);
84 memcpy(buf->base+buf->curoff,stuff,size);
90 xbuf_get(marshal_state *buf, LPBYTE stuff, DWORD size) {
91 if (buf->size < buf->curoff+size) return E_FAIL;
92 memcpy(stuff,buf->base+buf->curoff,size);
98 xbuf_skip(marshal_state *buf, DWORD size) {
99 if (buf->size < buf->curoff+size) return E_FAIL;
105 _unmarshal_interface(marshal_state *buf, REFIID riid, LPUNKNOWN *pUnk) {
107 ULARGE_INTEGER newpos;
108 LARGE_INTEGER seekto;
113 TRACE("...%s...\n",debugstr_guid(riid));
116 hres = xbuf_get(buf,(LPBYTE)&xsize,sizeof(xsize));
118 ERR("xbuf_get failed\n");
122 if (xsize == 0) return S_OK;
124 hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
126 ERR("Stream create failed %lx\n",hres);
130 hres = IStream_Write(pStm,buf->base+buf->curoff,xsize,&res);
132 ERR("stream write %lx\n",hres);
136 memset(&seekto,0,sizeof(seekto));
137 hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
139 ERR("Failed Seek %lx\n",hres);
143 hres = CoUnmarshalInterface(pStm,riid,(LPVOID*)pUnk);
145 ERR("Unmarshalling interface %s failed with %lx\n",debugstr_guid(riid),hres);
149 IStream_Release(pStm);
150 return xbuf_skip(buf,xsize);
154 _marshal_interface(marshal_state *buf, REFIID riid, LPUNKNOWN pUnk) {
155 LPBYTE tempbuf = NULL;
156 IStream *pStm = NULL;
158 ULARGE_INTEGER newpos;
159 LARGE_INTEGER seekto;
165 /* this is valid, if for instance we serialize
166 * a VT_DISPATCH with NULL ptr which apparently
167 * can happen. S_OK to make sure we continue
170 ERR("pUnk is NULL?\n");
172 return xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
177 TRACE("...%s...\n",debugstr_guid(riid));
179 hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
181 ERR("Stream create failed %lx\n",hres);
185 hres = CoMarshalInterface(pStm,riid,pUnk,0,NULL,0);
187 ERR("Marshalling interface %s failed with %lx\n", debugstr_guid(riid), hres);
191 hres = IStream_Stat(pStm,&ststg,0);
193 ERR("Stream stat failed\n");
197 tempbuf = HeapAlloc(GetProcessHeap(), 0, ststg.cbSize.u.LowPart);
198 memset(&seekto,0,sizeof(seekto));
199 hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
201 ERR("Failed Seek %lx\n",hres);
205 hres = IStream_Read(pStm,tempbuf,ststg.cbSize.u.LowPart,&res);
207 ERR("Failed Read %lx\n",hres);
211 xsize = ststg.cbSize.u.LowPart;
212 xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
213 hres = xbuf_add(buf,tempbuf,ststg.cbSize.u.LowPart);
215 HeapFree(GetProcessHeap(),0,tempbuf);
216 IStream_Release(pStm);
222 xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
223 if (pStm) IUnknown_Release(pStm);
224 HeapFree(GetProcessHeap(), 0, tempbuf);
228 /********************* OLE Proxy/Stub Factory ********************************/
229 static HRESULT WINAPI
230 PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface, REFIID iid, LPVOID *ppv) {
231 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)||IsEqualIID(iid,&IID_IUnknown)) {
232 *ppv = (LPVOID)iface;
233 /* No ref counting, static class */
236 FIXME("(%s) unknown IID?\n",debugstr_guid(iid));
237 return E_NOINTERFACE;
240 static ULONG WINAPI PSFacBuf_AddRef(LPPSFACTORYBUFFER iface) { return 2; }
241 static ULONG WINAPI PSFacBuf_Release(LPPSFACTORYBUFFER iface) { return 1; }
244 _get_typeinfo_for_iid(REFIID riid, ITypeInfo**ti) {
247 char tlguid[200],typelibkey[300],interfacekey[300],ver[100];
250 DWORD tlguidlen, verlen, type;
254 sprintf( interfacekey, "Interface\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\Typelib",
255 riid->Data1, riid->Data2, riid->Data3,
256 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
257 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7]
260 if (RegOpenKeyA(HKEY_CLASSES_ROOT,interfacekey,&ikey)) {
261 ERR("No %s key found.\n",interfacekey);
265 tlguidlen = sizeof(tlguid);
266 if (RegQueryValueExA(ikey,NULL,NULL,&type,(LPBYTE)tlguid,&tlguidlen)) {
267 ERR("Getting typelib guid failed.\n");
272 verlen = sizeof(ver);
273 if (RegQueryValueExA(ikey,"Version",NULL,&type,(LPBYTE)ver,&verlen)) {
274 ERR("Could not get version value?\n");
279 sprintf(typelibkey,"Typelib\\%s\\%s\\0\\win32",tlguid,ver);
280 tlfnlen = sizeof(tlfn);
281 if (RegQueryValueA(HKEY_CLASSES_ROOT,typelibkey,tlfn,&tlfnlen)) {
282 ERR("Could not get typelib fn?\n");
285 MultiByteToWideChar(CP_ACP, 0, tlfn, -1, tlfnW, -1);
286 hres = LoadTypeLib(tlfnW,&tl);
288 ERR("Failed to load typelib for %s, but it should be there.\n",debugstr_guid(riid));
291 hres = ITypeLib_GetTypeInfoOfGuid(tl,riid,ti);
293 ERR("typelib does not contain info for %s?\n",debugstr_guid(riid));
294 ITypeLib_Release(tl);
297 /* FIXME: do this? ITypeLib_Release(tl); */
301 /* Determine nr of functions. Since we use the toplevel interface and all
302 * inherited ones have lower numbers, we are ok to not to descent into
303 * the inheritance tree I think.
305 static int _nroffuncs(ITypeInfo *tinfo) {
307 const FUNCDESC *fdesc;
312 hres = ITypeInfoImpl_GetInternalFuncDesc(tinfo,n,&fdesc);
315 if (fdesc->oVft/4 > max)
324 #include "pshpack1.h"
326 typedef struct _TMAsmProxy {
340 # warning You need to implement stubless proxies for your architecture
341 typedef struct _TMAsmProxy {
345 typedef struct _TMProxyImpl {
347 const IRpcProxyBufferVtbl *lpvtbl2;
350 TMAsmProxy *asmstubs;
352 IRpcChannelBuffer* chanbuf;
354 CRITICAL_SECTION crit;
355 IUnknown *outerunknown;
359 static HRESULT WINAPI
360 TMProxyImpl_QueryInterface(LPRPCPROXYBUFFER iface, REFIID riid, LPVOID *ppv)
363 if (IsEqualIID(riid,&IID_IUnknown)||IsEqualIID(riid,&IID_IRpcProxyBuffer)) {
364 *ppv = (LPVOID)iface;
365 IRpcProxyBuffer_AddRef(iface);
368 FIXME("no interface for %s\n",debugstr_guid(riid));
369 return E_NOINTERFACE;
373 TMProxyImpl_AddRef(LPRPCPROXYBUFFER iface)
375 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
376 ULONG refCount = InterlockedIncrement(&This->ref);
378 TRACE("(%p)->(ref before=%lu)\n",This, refCount - 1);
384 TMProxyImpl_Release(LPRPCPROXYBUFFER iface)
386 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
387 ULONG refCount = InterlockedDecrement(&This->ref);
389 TRACE("(%p)->(ref before=%lu)\n",This, refCount + 1);
393 if (This->dispatch) IDispatch_Release(This->dispatch);
394 DeleteCriticalSection(&This->crit);
395 if (This->chanbuf) IRpcChannelBuffer_Release(This->chanbuf);
396 VirtualFree(This->asmstubs, 0, MEM_RELEASE);
402 static HRESULT WINAPI
404 LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer)
406 ICOM_THIS_MULTI(TMProxyImpl, lpvtbl2, iface);
408 TRACE("(%p)\n", pRpcChannelBuffer);
410 EnterCriticalSection(&This->crit);
412 IRpcChannelBuffer_AddRef(pRpcChannelBuffer);
413 This->chanbuf = pRpcChannelBuffer;
415 LeaveCriticalSection(&This->crit);
421 TMProxyImpl_Disconnect(LPRPCPROXYBUFFER iface)
423 ICOM_THIS_MULTI(TMProxyImpl, lpvtbl2, iface);
427 EnterCriticalSection(&This->crit);
429 IRpcChannelBuffer_Release(This->chanbuf);
430 This->chanbuf = NULL;
432 LeaveCriticalSection(&This->crit);
436 static const IRpcProxyBufferVtbl tmproxyvtable = {
437 TMProxyImpl_QueryInterface,
441 TMProxyImpl_Disconnect
444 /* how much space do we use on stack in DWORD steps. */
449 return 8/sizeof(DWORD);
451 return sizeof(double)/sizeof(DWORD);
453 return sizeof(CY)/sizeof(DWORD);
455 return sizeof(DATE)/sizeof(DWORD);
457 return (sizeof(VARIANT)+3)/sizeof(DWORD);
464 _xsize(TYPEDESC *td) {
469 return sizeof(VARIANT)+3;
472 ARRAYDESC *adesc = td->u.lpadesc;
474 for (i=0;i<adesc->cDims;i++)
475 arrsize *= adesc->rgbounds[i].cElements;
476 return arrsize*_xsize(&adesc->tdescElem);
504 TRACE("(tdesc.vt %d)\n",tdesc->vt);
507 case VT_EMPTY: /* nothing. empty variant for instance */
512 if (debugout) TRACE_(olerelay)("%lx%lx",arg[0],arg[1]);
514 hres = xbuf_add(buf,(LPBYTE)arg,8);
523 if (debugout) TRACE_(olerelay)("%lx",*arg);
525 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
530 if (debugout) TRACE_(olerelay)("%04lx",*arg & 0xffff);
532 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
537 if (debugout) TRACE_(olerelay)("%02lx",*arg & 0xff);
539 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
543 if (debugout) TRACE_(olerelay)("&0x%lx",*arg);
545 hres = xbuf_add(buf,(LPBYTE)(DWORD*)*arg,sizeof(DWORD));
546 /* do not dealloc at this time */
550 VARIANT *vt = (VARIANT*)arg;
551 DWORD vttype = V_VT(vt);
553 if (debugout) TRACE_(olerelay)("Vt(%ld)(",vttype);
556 hres = xbuf_add(buf,(LPBYTE)&vttype,sizeof(vttype));
557 if (hres) return hres;
559 /* need to recurse since we need to free the stuff */
560 hres = serialize_param(tinfo,writeit,debugout,dealloc,&tdesc2,(DWORD*)&(V_I4(vt)),buf);
561 if (debugout) TRACE_(olerelay)(")");
564 case VT_BSTR|VT_BYREF: {
565 if (debugout) TRACE_(olerelay)("[byref]'%s'", *(BSTR*)*arg ? relaystr(*((BSTR*)*arg)) : "<bstr NULL>");
567 /* ptr to ptr to magic widestring, basically */
568 BSTR *bstr = (BSTR *) *arg;
571 /* -1 means "null string" which is equivalent to empty string */
573 hres = xbuf_add(buf, (LPBYTE)&len,sizeof(DWORD));
574 if (hres) return hres;
576 len = *((DWORD*)*bstr-1)/sizeof(WCHAR);
577 hres = xbuf_add(buf,(LPBYTE)&len,sizeof(DWORD));
578 if (hres) return hres;
579 hres = xbuf_add(buf,(LPBYTE)*bstr,len * sizeof(WCHAR));
580 if (hres) return hres;
584 if (dealloc && arg) {
585 BSTR *str = *((BSTR **)arg);
594 TRACE_(olerelay)("%s",relaystr((WCHAR*)*arg));
596 TRACE_(olerelay)("<bstr NULL>");
599 BSTR bstr = (BSTR)*arg;
603 hres = xbuf_add(buf,(LPBYTE)&len,sizeof(DWORD));
604 if (hres) return hres;
606 len = *((DWORD*)bstr-1)/sizeof(WCHAR);
607 hres = xbuf_add(buf,(LPBYTE)&len,sizeof(DWORD));
608 if (hres) return hres;
609 hres = xbuf_add(buf,(LPBYTE)bstr,len * sizeof(WCHAR));
610 if (hres) return hres;
615 SysFreeString((BSTR)*arg);
620 BOOL derefhere = TRUE;
622 if (tdesc->u.lptdesc->vt == VT_USERDEFINED) {
626 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.lptdesc->u.hreftype,&tinfo2);
628 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.lptdesc->u.hreftype);
631 ITypeInfo_GetTypeAttr(tinfo2,&tattr);
632 switch (tattr->typekind) {
633 case TKIND_ENUM: /* confirmed */
634 case TKIND_RECORD: /* FIXME: mostly untested */
637 case TKIND_ALIAS: /* FIXME: untested */
638 case TKIND_DISPATCH: /* will be done in VT_USERDEFINED case */
639 case TKIND_INTERFACE: /* will be done in VT_USERDEFINED case */
643 FIXME("unhandled switch cases tattr->typekind %d\n", tattr->typekind);
647 ITypeInfo_Release(tinfo2);
650 if (debugout) TRACE_(olerelay)("*");
651 /* Write always, so the other side knows when it gets a NULL pointer.
653 cookie = *arg ? 0x42424242 : 0;
654 hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
658 if (debugout) TRACE_(olerelay)("NULL");
661 hres = serialize_param(tinfo,writeit,debugout,dealloc,tdesc->u.lptdesc,(DWORD*)*arg,buf);
662 if (derefhere && dealloc) HeapFree(GetProcessHeap(),0,(LPVOID)*arg);
666 if (debugout) TRACE_(olerelay)("unk(0x%lx)",*arg);
668 hres = _marshal_interface(buf,&IID_IUnknown,(LPUNKNOWN)*arg);
671 if (debugout) TRACE_(olerelay)("idisp(0x%lx)",*arg);
673 hres = _marshal_interface(buf,&IID_IDispatch,(LPUNKNOWN)*arg);
676 if (debugout) TRACE_(olerelay)("<void>");
678 case VT_USERDEFINED: {
682 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
684 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
687 ITypeInfo_GetTypeAttr(tinfo2,&tattr);
688 switch (tattr->typekind) {
690 case TKIND_INTERFACE:
692 hres=_marshal_interface(buf,&(tattr->guid),(LPUNKNOWN)arg);
694 IUnknown_Release((LPUNKNOWN)arg);
698 if (debugout) TRACE_(olerelay)("{");
699 for (i=0;i<tattr->cVars;i++) {
704 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
706 ERR("Could not get vardesc of %d\n",i);
709 /* Need them for hack below */
711 memset(names,0,sizeof(names));
712 hres = ITypeInfo_GetNames(tinfo2,vdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
713 if (nrofnames > sizeof(names)/sizeof(names[0])) {
714 ERR("Need more names!\n");
716 if (!hres && debugout)
717 TRACE_(olerelay)("%s=",relaystr(names[0]));
719 elem2 = &vdesc->elemdescVar;
720 tdesc2 = &elem2->tdesc;
721 hres = serialize_param(
727 (DWORD*)(((LPBYTE)arg)+vdesc->u.oInst),
730 ITypeInfo_ReleaseVarDesc(tinfo2, vdesc);
733 if (debugout && (i<(tattr->cVars-1)))
734 TRACE_(olerelay)(",");
736 if (debugout) TRACE_(olerelay)("}");
740 return serialize_param(tinfo2,writeit,debugout,dealloc,&tattr->tdescAlias,arg,buf);
743 if (debugout) TRACE_(olerelay)("%lx",*arg);
745 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
748 FIXME("Unhandled typekind %d\n",tattr->typekind);
752 ITypeInfo_Release(tinfo2);
756 ARRAYDESC *adesc = tdesc->u.lpadesc;
759 if (debugout) TRACE_(olerelay)("carr");
760 for (i=0;i<adesc->cDims;i++) {
761 if (debugout) TRACE_(olerelay)("[%ld]",adesc->rgbounds[i].cElements);
762 arrsize *= adesc->rgbounds[i].cElements;
764 if (debugout) TRACE_(olerelay)("(vt %d)",adesc->tdescElem.vt);
765 if (debugout) TRACE_(olerelay)("[");
766 for (i=0;i<arrsize;i++) {
767 hres = serialize_param(tinfo, writeit, debugout, dealloc, &adesc->tdescElem, (DWORD*)((LPBYTE)arg+i*_xsize(&adesc->tdescElem)), buf);
770 if (debugout && (i<arrsize-1)) TRACE_(olerelay)(",");
772 if (debugout) TRACE_(olerelay)("]");
776 ERR("Unhandled marshal type %d.\n",tdesc->vt);
793 TRACE("vt %d at %p\n",tdesc->vt,arg);
798 if (debugout) TRACE_(olerelay)("<empty>");
801 if (debugout) TRACE_(olerelay)("<null>");
804 VARIANT *vt = (VARIANT*)arg;
809 hres = xbuf_get(buf,(LPBYTE)&vttype,sizeof(vttype));
811 FIXME("vt type not read?\n");
814 memset(&tdesc2,0,sizeof(tdesc2));
817 if (debugout) TRACE_(olerelay)("Vt(%ld)(",vttype);
818 hres = deserialize_param(tinfo, readit, debugout, alloc, &tdesc2, (DWORD*)&(V_I4(vt)), buf);
819 TRACE_(olerelay)(")");
829 hres = xbuf_get(buf,(LPBYTE)arg,8);
830 if (hres) ERR("Failed to read integer 8 byte\n");
832 if (debugout) TRACE_(olerelay)("%lx%lx",arg[0],arg[1]);
841 hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
842 if (hres) ERR("Failed to read integer 4 byte\n");
844 if (debugout) TRACE_(olerelay)("%lx",*arg);
850 hres = xbuf_get(buf,(LPBYTE)&x,sizeof(DWORD));
851 if (hres) ERR("Failed to read integer 4 byte\n");
854 if (debugout) TRACE_(olerelay)("%04lx",*arg & 0xffff);
860 hres = xbuf_get(buf,(LPBYTE)&x,sizeof(DWORD));
861 if (hres) ERR("Failed to read integer 4 byte\n");
864 if (debugout) TRACE_(olerelay)("%02lx",*arg & 0xff);
869 *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
871 hres = xbuf_get(buf,(LPBYTE)*arg,sizeof(DWORD));
872 if (hres) ERR("Failed to read integer 4 byte\n");
874 if (debugout) TRACE_(olerelay)("&0x%lx",*(DWORD*)*arg);
876 case VT_BSTR|VT_BYREF: {
877 BSTR **bstr = (BSTR **)arg;
882 hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
884 ERR("failed to read bstr klen\n");
888 *bstr = CoTaskMemAlloc(sizeof(BSTR *));
890 if (debugout) TRACE_(olerelay)("<bstr NULL>");
892 str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
893 hres = xbuf_get(buf,(LPBYTE)str,len*sizeof(WCHAR));
895 ERR("Failed to read BSTR.\n");
898 *bstr = CoTaskMemAlloc(sizeof(BSTR *));
899 **bstr = SysAllocStringLen(str,len);
900 if (debugout) TRACE_(olerelay)("%s",relaystr(str));
901 HeapFree(GetProcessHeap(),0,str);
913 hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
915 ERR("failed to read bstr klen\n");
920 if (debugout) TRACE_(olerelay)("<bstr NULL>");
922 str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
923 hres = xbuf_get(buf,(LPBYTE)str,len*sizeof(WCHAR));
925 ERR("Failed to read BSTR.\n");
928 *arg = (DWORD)SysAllocStringLen(str,len);
929 if (debugout) TRACE_(olerelay)("%s",relaystr(str));
930 HeapFree(GetProcessHeap(),0,str);
939 BOOL derefhere = TRUE;
941 if (tdesc->u.lptdesc->vt == VT_USERDEFINED) {
945 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.lptdesc->u.hreftype,&tinfo2);
947 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.lptdesc->u.hreftype);
950 ITypeInfo_GetTypeAttr(tinfo2,&tattr);
951 switch (tattr->typekind) {
952 case TKIND_ENUM: /* confirmed */
953 case TKIND_RECORD: /* FIXME: mostly untested */
956 case TKIND_ALIAS: /* FIXME: untested */
957 case TKIND_DISPATCH: /* will be done in VT_USERDEFINED case */
958 case TKIND_INTERFACE: /* will be done in VT_USERDEFINED case */
962 FIXME("unhandled switch cases tattr->typekind %d\n", tattr->typekind);
966 ITypeInfo_Release(tinfo2);
968 /* read it in all cases, we need to know if we have
969 * NULL pointer or not.
971 hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
973 ERR("Failed to load pointer cookie.\n");
976 if (cookie != 0x42424242) {
977 /* we read a NULL ptr from the remote side */
978 if (debugout) TRACE_(olerelay)("NULL");
982 if (debugout) TRACE_(olerelay)("*");
984 /* Allocate space for the referenced struct */
986 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,_xsize(tdesc->u.lptdesc));
989 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, (LPDWORD)*arg, buf);
991 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, arg, buf);
994 /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
996 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
999 hres = _unmarshal_interface(buf,&IID_IUnknown,(LPUNKNOWN*)arg);
1001 TRACE_(olerelay)("unk(%p)",arg);
1006 hres = _unmarshal_interface(buf,&IID_IDispatch,(LPUNKNOWN*)arg);
1008 TRACE_(olerelay)("idisp(%p)",arg);
1011 if (debugout) TRACE_(olerelay)("<void>");
1013 case VT_USERDEFINED: {
1017 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
1019 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
1022 hres = ITypeInfo_GetTypeAttr(tinfo2,&tattr);
1024 ERR("Could not get typeattr in VT_USERDEFINED.\n");
1026 switch (tattr->typekind) {
1027 case TKIND_DISPATCH:
1028 case TKIND_INTERFACE:
1030 hres = _unmarshal_interface(buf,&(tattr->guid),(LPUNKNOWN*)arg);
1032 case TKIND_RECORD: {
1036 *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,tattr->cbSizeInstance);
1038 if (debugout) TRACE_(olerelay)("{");
1039 for (i=0;i<tattr->cVars;i++) {
1042 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
1044 ERR("Could not get vardesc of %d\n",i);
1047 hres = deserialize_param(
1052 &vdesc->elemdescVar.tdesc,
1053 (DWORD*)(((LPBYTE)*arg)+vdesc->u.oInst),
1056 ITypeInfo2_ReleaseVarDesc(tinfo2, vdesc);
1057 if (debugout && (i<tattr->cVars-1)) TRACE_(olerelay)(",");
1059 if (debugout) TRACE_(olerelay)("}");
1063 return deserialize_param(tinfo2,readit,debugout,alloc,&tattr->tdescAlias,arg,buf);
1066 hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
1067 if (hres) ERR("Failed to read enum (4 byte)\n");
1069 if (debugout) TRACE_(olerelay)("%lx",*arg);
1072 ERR("Unhandled typekind %d\n",tattr->typekind);
1078 ERR("failed to stuballoc in TKIND_RECORD.\n");
1079 ITypeInfo_Release(tinfo2);
1083 /* arg is pointing to the start of the array. */
1084 ARRAYDESC *adesc = tdesc->u.lpadesc;
1087 if (adesc->cDims > 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
1088 for (i=0;i<adesc->cDims;i++)
1089 arrsize *= adesc->rgbounds[i].cElements;
1090 for (i=0;i<arrsize;i++)
1097 (DWORD*)((LPBYTE)(arg)+i*_xsize(&adesc->tdescElem)),
1103 ERR("No handler for VT type %d!\n",tdesc->vt);
1109 /* Searches function, also in inherited interfaces */
1112 ITypeInfo *tinfo, int iMethod, ITypeInfo **tactual, const FUNCDESC **fdesc, BSTR *iname, BSTR *fname)
1117 if (fname) *fname = NULL;
1118 if (iname) *iname = NULL;
1121 ITypeInfo_AddRef(*tactual);
1124 hres = ITypeInfoImpl_GetInternalFuncDesc(tinfo, i, fdesc);
1131 hres = ITypeInfo_GetTypeAttr(tinfo, &attr);
1133 ERR("GetTypeAttr failed with %lx\n",hres);
1136 /* Not found, so look in inherited ifaces. */
1137 for (j=0;j<attr->cImplTypes;j++) {
1138 hres = ITypeInfo_GetRefTypeOfImplType(tinfo, j, &href);
1140 ERR("Did not find a reftype for interface offset %d?\n",j);
1143 hres = ITypeInfo_GetRefTypeInfo(tinfo, href, &tinfo2);
1145 ERR("Did not find a typeinfo for reftype %ld?\n",href);
1148 hres = _get_funcdesc(tinfo2,iMethod,tactual,fdesc,iname,fname);
1149 ITypeInfo_Release(tinfo2);
1150 if (!hres) return S_OK;
1154 if (((*fdesc)->oVft/4) == iMethod) {
1156 ITypeInfo_GetDocumentation(tinfo,(*fdesc)->memid,fname,NULL,NULL,NULL);
1158 ITypeInfo_GetDocumentation(tinfo,-1,iname,NULL,NULL,NULL);
1166 xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */)
1168 DWORD *args = ((DWORD*)&tpinfo)+1, *xargs;
1169 const FUNCDESC *fdesc;
1171 int i, relaydeb = TRACE_ON(olerelay);
1178 DWORD remoteresult = 0;
1180 IRpcChannelBuffer *chanbuf;
1182 EnterCriticalSection(&tpinfo->crit);
1184 hres = _get_funcdesc(tpinfo->tinfo,method,&tinfo,&fdesc,&iname,&fname);
1186 ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method);
1187 ITypeInfo_Release(tinfo);
1188 LeaveCriticalSection(&tpinfo->crit);
1192 if (!tpinfo->chanbuf)
1194 WARN("Tried to use disconnected proxy\n");
1195 ITypeInfo_Release(tinfo);
1196 LeaveCriticalSection(&tpinfo->crit);
1197 return RPC_E_DISCONNECTED;
1199 chanbuf = tpinfo->chanbuf;
1200 IRpcChannelBuffer_AddRef(chanbuf);
1202 LeaveCriticalSection(&tpinfo->crit);
1205 TRACE_(olerelay)("->");
1207 TRACE_(olerelay)("%s:",relaystr(iname));
1209 TRACE_(olerelay)("%s(%d)",relaystr(fname),method);
1211 TRACE_(olerelay)("%d",method);
1212 TRACE_(olerelay)("(");
1215 if (iname) SysFreeString(iname);
1216 if (fname) SysFreeString(fname);
1218 memset(&buf,0,sizeof(buf));
1220 /* normal typelib driven serializing */
1222 /* Need them for hack below */
1223 memset(names,0,sizeof(names));
1224 if (ITypeInfo_GetNames(tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames))
1226 if (nrofnames > sizeof(names)/sizeof(names[0]))
1227 ERR("Need more names!\n");
1230 for (i=0;i<fdesc->cParams;i++) {
1231 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1233 if (i) TRACE_(olerelay)(",");
1234 if (i+1<nrofnames && names[i+1])
1235 TRACE_(olerelay)("%s=",relaystr(names[i+1]));
1237 /* No need to marshal other data than FIN and any VT_PTR. */
1238 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN || !elem->u.paramdesc.wParamFlags) && (elem->tdesc.vt != VT_PTR)) {
1239 xargs+=_argsize(elem->tdesc.vt);
1240 if (relaydeb) TRACE_(olerelay)("[out]");
1243 hres = serialize_param(
1245 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN || !elem->u.paramdesc.wParamFlags,
1254 ERR("Failed to serialize param, hres %lx\n",hres);
1257 xargs+=_argsize(elem->tdesc.vt);
1259 if (relaydeb) TRACE_(olerelay)(")");
1261 memset(&msg,0,sizeof(msg));
1262 msg.cbBuffer = buf.curoff;
1263 msg.iMethod = method;
1264 hres = IRpcChannelBuffer_GetBuffer(chanbuf,&msg,&(tpinfo->iid));
1266 ERR("RpcChannelBuffer GetBuffer failed, %lx\n",hres);
1269 memcpy(msg.Buffer,buf.base,buf.curoff);
1270 if (relaydeb) TRACE_(olerelay)("\n");
1271 hres = IRpcChannelBuffer_SendReceive(chanbuf,&msg,&status);
1273 ERR("RpcChannelBuffer SendReceive failed, %lx\n",hres);
1277 if (relaydeb) TRACE_(olerelay)(" status = %08lx (",status);
1279 buf.base = HeapReAlloc(GetProcessHeap(),0,buf.base,msg.cbBuffer);
1281 buf.base = HeapAlloc(GetProcessHeap(),0,msg.cbBuffer);
1282 buf.size = msg.cbBuffer;
1283 memcpy(buf.base,msg.Buffer,buf.size);
1286 /* generic deserializer using typelib description */
1289 for (i=0;i<fdesc->cParams;i++) {
1290 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1293 if (i) TRACE_(olerelay)(",");
1294 if (i+1<nrofnames && names[i+1]) TRACE_(olerelay)("%s=",relaystr(names[i+1]));
1296 /* No need to marshal other data than FOUT and any VT_PTR */
1297 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT) && (elem->tdesc.vt != VT_PTR)) {
1298 xargs += _argsize(elem->tdesc.vt);
1299 if (relaydeb) TRACE_(olerelay)("[in]");
1302 hres = deserialize_param(
1304 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1312 ERR("Failed to unmarshall param, hres %lx\n",hres);
1316 xargs += _argsize(elem->tdesc.vt);
1319 hres = xbuf_get(&buf, (LPBYTE)&remoteresult, sizeof(DWORD));
1322 if (relaydeb) TRACE_(olerelay)(") = %08lx\n", remoteresult);
1324 hres = remoteresult;
1327 HeapFree(GetProcessHeap(),0,buf.base);
1328 IRpcChannelBuffer_Release(chanbuf);
1329 ITypeInfo_Release(tinfo);
1330 TRACE("-- 0x%08lx\n", hres);
1334 HRESULT WINAPI ProxyIUnknown_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
1336 TMProxyImpl *proxy = (TMProxyImpl *)iface;
1338 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
1340 if (proxy->outerunknown)
1341 return IUnknown_QueryInterface(proxy->outerunknown, riid, ppv);
1343 FIXME("No interface\n");
1344 return E_NOINTERFACE;
1347 ULONG WINAPI ProxyIUnknown_AddRef(IUnknown *iface)
1349 TMProxyImpl *proxy = (TMProxyImpl *)iface;
1353 if (proxy->outerunknown)
1354 return IUnknown_AddRef(proxy->outerunknown);
1356 return 2; /* FIXME */
1359 ULONG WINAPI ProxyIUnknown_Release(IUnknown *iface)
1361 TMProxyImpl *proxy = (TMProxyImpl *)iface;
1365 if (proxy->outerunknown)
1366 return IUnknown_Release(proxy->outerunknown);
1368 return 1; /* FIXME */
1371 static HRESULT WINAPI ProxyIDispatch_GetTypeInfoCount(LPDISPATCH iface, UINT * pctinfo)
1373 TMProxyImpl *This = (TMProxyImpl *)iface;
1376 TRACE("(%p)\n", pctinfo);
1378 if (!This->dispatch)
1380 hr = IUnknown_QueryInterface(This->outerunknown, &IID_IDispatch,
1381 (LPVOID *)&This->dispatch);
1384 hr = IDispatch_GetTypeInfoCount(This->dispatch, pctinfo);
1389 static HRESULT WINAPI ProxyIDispatch_GetTypeInfo(LPDISPATCH iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)
1391 TMProxyImpl *This = (TMProxyImpl *)iface;
1394 TRACE("(%d, %lx, %p)\n", iTInfo, lcid, ppTInfo);
1396 if (!This->dispatch)
1398 hr = IUnknown_QueryInterface(This->outerunknown, &IID_IDispatch,
1399 (LPVOID *)&This->dispatch);
1402 hr = IDispatch_GetTypeInfo(This->dispatch, iTInfo, lcid, ppTInfo);
1407 static HRESULT WINAPI ProxyIDispatch_GetIDsOfNames(LPDISPATCH iface, REFIID riid, LPOLESTR * rgszNames, UINT cNames, LCID lcid, DISPID * rgDispId)
1409 TMProxyImpl *This = (TMProxyImpl *)iface;
1412 TRACE("(%s, %p, %d, 0x%lx, %p)\n", debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
1414 if (!This->dispatch)
1416 hr = IUnknown_QueryInterface(This->outerunknown, &IID_IDispatch,
1417 (LPVOID *)&This->dispatch);
1420 hr = IDispatch_GetIDsOfNames(This->dispatch, riid, rgszNames,
1421 cNames, lcid, rgDispId);
1426 static HRESULT WINAPI ProxyIDispatch_Invoke(LPDISPATCH iface, DISPID dispIdMember, REFIID riid, LCID lcid,
1427 WORD wFlags, DISPPARAMS * pDispParams, VARIANT * pVarResult,
1428 EXCEPINFO * pExcepInfo, UINT * puArgErr)
1430 TMProxyImpl *This = (TMProxyImpl *)iface;
1433 TRACE("(%ld, %s, 0x%lx, 0x%x, %p, %p, %p, %p)\n", dispIdMember, debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1435 if (!This->dispatch)
1437 hr = IUnknown_QueryInterface(This->outerunknown, &IID_IDispatch,
1438 (LPVOID *)&This->dispatch);
1441 hr = IDispatch_Invoke(This->dispatch, dispIdMember, riid, lcid,
1442 wFlags, pDispParams, pVarResult, pExcepInfo,
1448 static HRESULT WINAPI
1449 PSFacBuf_CreateProxy(
1450 LPPSFACTORYBUFFER iface, IUnknown* pUnkOuter, REFIID riid,
1451 IRpcProxyBuffer **ppProxy, LPVOID *ppv)
1456 const FUNCDESC *fdesc;
1460 TRACE("(...%s...)\n",debugstr_guid(riid));
1461 hres = _get_typeinfo_for_iid(riid,&tinfo);
1463 ERR("No typeinfo for %s?\n",debugstr_guid(riid));
1466 nroffuncs = _nroffuncs(tinfo);
1467 proxy = CoTaskMemAlloc(sizeof(TMProxyImpl));
1468 if (!proxy) return E_OUTOFMEMORY;
1470 assert(sizeof(TMAsmProxy) == 12);
1472 proxy->dispatch = NULL;
1473 proxy->outerunknown = pUnkOuter;
1474 proxy->asmstubs = VirtualAlloc(NULL, sizeof(TMAsmProxy) * nroffuncs, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
1475 if (!proxy->asmstubs) {
1476 ERR("Could not commit pages for proxy thunks\n");
1477 CoTaskMemFree(proxy);
1478 return E_OUTOFMEMORY;
1481 InitializeCriticalSection(&proxy->crit);
1483 proxy->lpvtbl = HeapAlloc(GetProcessHeap(),0,sizeof(LPBYTE)*nroffuncs);
1484 for (i=0;i<nroffuncs;i++) {
1485 TMAsmProxy *xasm = proxy->asmstubs+i;
1489 proxy->lpvtbl[i] = ProxyIUnknown_QueryInterface;
1492 proxy->lpvtbl[i] = ProxyIUnknown_AddRef;
1495 proxy->lpvtbl[i] = ProxyIUnknown_Release;
1499 /* nrofargs without This */
1502 hres = _get_funcdesc(tinfo,i,&tinfo2,&fdesc,NULL,NULL);
1503 ITypeInfo_Release(tinfo2);
1505 ERR("GetFuncDesc %lx should not fail here.\n",hres);
1508 /* some args take more than 4 byte on the stack */
1510 for (j=0;j<fdesc->cParams;j++)
1511 nrofargs += _argsize(fdesc->lprgelemdescParam[j].tdesc.vt);
1514 if (fdesc->callconv != CC_STDCALL) {
1515 ERR("calling convention is not stdcall????\n");
1518 /* popl %eax - return ptr
1525 * arg3 arg2 arg1 <method> <returnptr>
1527 xasm->popleax = 0x58;
1528 xasm->pushlval = 0x6a;
1530 xasm->pushleax = 0x50;
1531 xasm->lcall = 0xe8; /* relative jump */
1532 xasm->xcall = (DWORD)xCall;
1533 xasm->xcall -= (DWORD)&(xasm->lret);
1535 xasm->bytestopop= (nrofargs+2)*4; /* pop args, This, iMethod */
1536 proxy->lpvtbl[i] = xasm;
1539 FIXME("not implemented on non i386\n");
1546 /* if we derive from IDispatch then defer to its proxy for its methods */
1547 hres = ITypeInfo_GetTypeAttr(tinfo, &typeattr);
1550 if (typeattr->wTypeFlags & TYPEFLAG_FDISPATCHABLE)
1552 proxy->lpvtbl[3] = ProxyIDispatch_GetTypeInfoCount;
1553 proxy->lpvtbl[4] = ProxyIDispatch_GetTypeInfo;
1554 proxy->lpvtbl[5] = ProxyIDispatch_GetIDsOfNames;
1555 proxy->lpvtbl[6] = ProxyIDispatch_Invoke;
1557 ITypeInfo_ReleaseTypeAttr(tinfo, typeattr);
1560 proxy->lpvtbl2 = &tmproxyvtable;
1561 /* one reference for the proxy */
1563 proxy->tinfo = tinfo;
1564 memcpy(&proxy->iid,riid,sizeof(*riid));
1566 *ppv = (LPVOID)proxy;
1567 *ppProxy = (IRpcProxyBuffer *)&(proxy->lpvtbl2);
1568 IUnknown_AddRef((IUnknown *)*ppv);
1572 typedef struct _TMStubImpl {
1573 const IRpcStubBufferVtbl *lpvtbl;
1581 static HRESULT WINAPI
1582 TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface, REFIID riid, LPVOID *ppv)
1584 if (IsEqualIID(riid,&IID_IRpcStubBuffer)||IsEqualIID(riid,&IID_IUnknown)){
1585 *ppv = (LPVOID)iface;
1586 IRpcStubBuffer_AddRef(iface);
1589 FIXME("%s, not supported IID.\n",debugstr_guid(riid));
1590 return E_NOINTERFACE;
1594 TMStubImpl_AddRef(LPRPCSTUBBUFFER iface)
1596 TMStubImpl *This = (TMStubImpl *)iface;
1597 ULONG refCount = InterlockedIncrement(&This->ref);
1599 TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
1605 TMStubImpl_Release(LPRPCSTUBBUFFER iface)
1607 TMStubImpl *This = (TMStubImpl *)iface;
1608 ULONG refCount = InterlockedDecrement(&This->ref);
1610 TRACE("(%p)->(ref before=%lu)\n", This, refCount + 1);
1614 IRpcStubBuffer_Disconnect(iface);
1615 ITypeInfo_Release(This->tinfo);
1616 CoTaskMemFree(This);
1621 static HRESULT WINAPI
1622 TMStubImpl_Connect(LPRPCSTUBBUFFER iface, LPUNKNOWN pUnkServer)
1624 TMStubImpl *This = (TMStubImpl *)iface;
1626 TRACE("(%p)->(%p)\n", This, pUnkServer);
1628 IUnknown_AddRef(pUnkServer);
1629 This->pUnk = pUnkServer;
1634 TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface)
1636 TMStubImpl *This = (TMStubImpl *)iface;
1638 TRACE("(%p)->()\n", This);
1642 IUnknown_Release(This->pUnk);
1647 static HRESULT WINAPI
1649 LPRPCSTUBBUFFER iface, RPCOLEMESSAGE* xmsg,IRpcChannelBuffer*rpcchanbuf)
1652 const FUNCDESC *fdesc;
1653 TMStubImpl *This = (TMStubImpl *)iface;
1655 DWORD *args, res, *xargs, nrofargs;
1662 memset(&buf,0,sizeof(buf));
1663 buf.size = xmsg->cbBuffer;
1664 buf.base = HeapAlloc(GetProcessHeap(), 0, xmsg->cbBuffer);
1665 memcpy(buf.base, xmsg->Buffer, xmsg->cbBuffer);
1670 if (xmsg->iMethod < 3) {
1671 ERR("IUnknown methods cannot be marshaled by the typelib marshaler\n");
1672 return E_UNEXPECTED;
1675 hres = _get_funcdesc(This->tinfo,xmsg->iMethod,&tinfo,&fdesc,&iname,NULL);
1677 ERR("GetFuncDesc on method %ld failed with %lx\n",xmsg->iMethod,hres);
1681 if (iname && !lstrcmpW(iname, IDispatchW))
1683 ERR("IDispatch cannot be marshaled by the typelib marshaler\n");
1684 ITypeInfo_Release(tinfo);
1685 return E_UNEXPECTED;
1688 if (iname) SysFreeString (iname);
1690 /* Need them for hack below */
1691 memset(names,0,sizeof(names));
1692 ITypeInfo_GetNames(tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
1693 if (nrofnames > sizeof(names)/sizeof(names[0])) {
1694 ERR("Need more names!\n");
1697 /*dump_FUNCDESC(fdesc);*/
1699 for (i=0;i<fdesc->cParams;i++)
1700 nrofargs += _argsize(fdesc->lprgelemdescParam[i].tdesc.vt);
1701 args = HeapAlloc(GetProcessHeap(),0,(nrofargs+1)*sizeof(DWORD));
1702 if (!args) return E_OUTOFMEMORY;
1704 /* Allocate all stuff used by call. */
1706 for (i=0;i<fdesc->cParams;i++) {
1707 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1709 hres = deserialize_param(
1711 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN || !elem->u.paramdesc.wParamFlags,
1718 xargs += _argsize(elem->tdesc.vt);
1720 ERR("Failed to deserialize param %s, hres %lx\n",relaystr(names[i+1]),hres);
1725 args[0] = (DWORD)This->pUnk;
1727 (*((FARPROC**)args[0]))[fdesc->oVft/4],
1735 for (i=0;i<fdesc->cParams;i++) {
1736 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1737 hres = serialize_param(
1739 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1746 xargs += _argsize(elem->tdesc.vt);
1748 ERR("Failed to stuballoc param, hres %lx\n",hres);
1753 hres = xbuf_add (&buf, (LPBYTE)&res, sizeof(DWORD));
1757 ITypeInfo_Release(tinfo);
1758 HeapFree(GetProcessHeap(), 0, args);
1760 xmsg->cbBuffer = buf.curoff;
1763 hres = IRpcChannelBuffer_GetBuffer(rpcchanbuf, xmsg, &This->iid);
1765 ERR("IRpcChannelBuffer_GetBuffer failed with error 0x%08lx\n", hres);
1769 /* FIXME: remove this case when we start sending an IRpcChannelBuffer
1770 * object with builtin OLE */
1771 RPC_STATUS status = I_RpcGetBuffer((RPC_MESSAGE *)xmsg);
1772 if (status != RPC_S_OK)
1774 ERR("I_RpcGetBuffer failed with error %ld\n", status);
1780 memcpy(xmsg->Buffer, buf.base, buf.curoff);
1782 HeapFree(GetProcessHeap(), 0, buf.base);
1784 TRACE("returning\n");
1788 static LPRPCSTUBBUFFER WINAPI
1789 TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface, REFIID riid) {
1790 FIXME("Huh (%s)?\n",debugstr_guid(riid));
1795 TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface) {
1796 TMStubImpl *This = (TMStubImpl *)iface;
1799 return This->ref; /*FIXME? */
1802 static HRESULT WINAPI
1803 TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface, LPVOID *ppv) {
1808 TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface, LPVOID ppv) {
1812 static const IRpcStubBufferVtbl tmstubvtbl = {
1813 TMStubImpl_QueryInterface,
1817 TMStubImpl_Disconnect,
1819 TMStubImpl_IsIIDSupported,
1820 TMStubImpl_CountRefs,
1821 TMStubImpl_DebugServerQueryInterface,
1822 TMStubImpl_DebugServerRelease
1825 static HRESULT WINAPI
1826 PSFacBuf_CreateStub(
1827 LPPSFACTORYBUFFER iface, REFIID riid,IUnknown *pUnkServer,
1828 IRpcStubBuffer** ppStub
1834 TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub);
1835 hres = _get_typeinfo_for_iid(riid,&tinfo);
1837 ERR("No typeinfo for %s?\n",debugstr_guid(riid));
1840 stub = CoTaskMemAlloc(sizeof(TMStubImpl));
1842 return E_OUTOFMEMORY;
1843 stub->lpvtbl = &tmstubvtbl;
1845 stub->tinfo = tinfo;
1846 memcpy(&(stub->iid),riid,sizeof(*riid));
1847 hres = IRpcStubBuffer_Connect((LPRPCSTUBBUFFER)stub,pUnkServer);
1848 *ppStub = (LPRPCSTUBBUFFER)stub;
1849 TRACE("IRpcStubBuffer: %p\n", stub);
1851 ERR("Connect to pUnkServer failed?\n");
1855 static const IPSFactoryBufferVtbl psfacbufvtbl = {
1856 PSFacBuf_QueryInterface,
1859 PSFacBuf_CreateProxy,
1863 /* This is the whole PSFactoryBuffer object, just the vtableptr */
1864 static const IPSFactoryBufferVtbl *lppsfac = &psfacbufvtbl;
1866 /***********************************************************************
1867 * TMARSHAL_DllGetClassObject
1869 HRESULT TMARSHAL_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
1871 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)) {
1875 return E_NOINTERFACE;