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 */
513 if (debugout) TRACE_(olerelay)("%lx%lx",arg[0],arg[1]);
515 hres = xbuf_add(buf,(LPBYTE)arg,8);
524 if (debugout) TRACE_(olerelay)("%lx",*arg);
526 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
531 if (debugout) TRACE_(olerelay)("%04lx",*arg & 0xffff);
533 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
538 if (debugout) TRACE_(olerelay)("%02lx",*arg & 0xff);
540 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
544 if (debugout) TRACE_(olerelay)("&0x%lx",*arg);
546 hres = xbuf_add(buf,(LPBYTE)(DWORD*)*arg,sizeof(DWORD));
547 /* do not dealloc at this time */
551 VARIANT *vt = (VARIANT*)arg;
552 DWORD vttype = V_VT(vt);
554 if (debugout) TRACE_(olerelay)("Vt(%ld)(",vttype);
557 hres = xbuf_add(buf,(LPBYTE)&vttype,sizeof(vttype));
558 if (hres) return hres;
560 /* need to recurse since we need to free the stuff */
561 hres = serialize_param(tinfo,writeit,debugout,dealloc,&tdesc2,(DWORD*)&(V_I4(vt)),buf);
562 if (debugout) TRACE_(olerelay)(")");
565 case VT_BSTR|VT_BYREF: {
566 if (debugout) TRACE_(olerelay)("[byref]'%s'", *(BSTR*)*arg ? relaystr(*((BSTR*)*arg)) : "<bstr NULL>");
568 /* ptr to ptr to magic widestring, basically */
569 BSTR *bstr = (BSTR *) *arg;
572 /* -1 means "null string" which is equivalent to empty string */
574 hres = xbuf_add(buf, (LPBYTE)&len,sizeof(DWORD));
575 if (hres) return hres;
577 len = *((DWORD*)*bstr-1)/sizeof(WCHAR);
578 hres = xbuf_add(buf,(LPBYTE)&len,sizeof(DWORD));
579 if (hres) return hres;
580 hres = xbuf_add(buf,(LPBYTE)*bstr,len * sizeof(WCHAR));
581 if (hres) return hres;
585 if (dealloc && arg) {
586 BSTR *str = *((BSTR **)arg);
595 TRACE_(olerelay)("%s",relaystr((WCHAR*)*arg));
597 TRACE_(olerelay)("<bstr NULL>");
600 BSTR bstr = (BSTR)*arg;
604 hres = xbuf_add(buf,(LPBYTE)&len,sizeof(DWORD));
605 if (hres) return hres;
607 len = *((DWORD*)bstr-1)/sizeof(WCHAR);
608 hres = xbuf_add(buf,(LPBYTE)&len,sizeof(DWORD));
609 if (hres) return hres;
610 hres = xbuf_add(buf,(LPBYTE)bstr,len * sizeof(WCHAR));
611 if (hres) return hres;
616 SysFreeString((BSTR)*arg);
621 BOOL derefhere = TRUE;
623 if (tdesc->u.lptdesc->vt == VT_USERDEFINED) {
627 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.lptdesc->u.hreftype,&tinfo2);
629 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.lptdesc->u.hreftype);
632 ITypeInfo_GetTypeAttr(tinfo2,&tattr);
633 switch (tattr->typekind) {
634 case TKIND_ENUM: /* confirmed */
635 case TKIND_RECORD: /* FIXME: mostly untested */
638 case TKIND_ALIAS: /* FIXME: untested */
639 case TKIND_DISPATCH: /* will be done in VT_USERDEFINED case */
640 case TKIND_INTERFACE: /* will be done in VT_USERDEFINED case */
644 FIXME("unhandled switch cases tattr->typekind %d\n", tattr->typekind);
648 ITypeInfo_Release(tinfo2);
651 if (debugout) TRACE_(olerelay)("*");
652 /* Write always, so the other side knows when it gets a NULL pointer.
654 cookie = *arg ? 0x42424242 : 0;
655 hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
659 if (debugout) TRACE_(olerelay)("NULL");
662 hres = serialize_param(tinfo,writeit,debugout,dealloc,tdesc->u.lptdesc,(DWORD*)*arg,buf);
663 if (derefhere && dealloc) HeapFree(GetProcessHeap(),0,(LPVOID)*arg);
667 if (debugout) TRACE_(olerelay)("unk(0x%lx)",*arg);
669 hres = _marshal_interface(buf,&IID_IUnknown,(LPUNKNOWN)*arg);
672 if (debugout) TRACE_(olerelay)("idisp(0x%lx)",*arg);
674 hres = _marshal_interface(buf,&IID_IDispatch,(LPUNKNOWN)*arg);
677 if (debugout) TRACE_(olerelay)("<void>");
679 case VT_USERDEFINED: {
683 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
685 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
688 ITypeInfo_GetTypeAttr(tinfo2,&tattr);
689 switch (tattr->typekind) {
691 case TKIND_INTERFACE:
693 hres=_marshal_interface(buf,&(tattr->guid),(LPUNKNOWN)arg);
695 IUnknown_Release((LPUNKNOWN)arg);
699 if (debugout) TRACE_(olerelay)("{");
700 for (i=0;i<tattr->cVars;i++) {
705 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
707 ERR("Could not get vardesc of %d\n",i);
710 /* Need them for hack below */
712 memset(names,0,sizeof(names));
713 hres = ITypeInfo_GetNames(tinfo2,vdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
714 if (nrofnames > sizeof(names)/sizeof(names[0])) {
715 ERR("Need more names!\n");
717 if (!hres && debugout)
718 TRACE_(olerelay)("%s=",relaystr(names[0]));
720 elem2 = &vdesc->elemdescVar;
721 tdesc2 = &elem2->tdesc;
722 hres = serialize_param(
728 (DWORD*)(((LPBYTE)arg)+vdesc->u.oInst),
731 ITypeInfo_ReleaseVarDesc(tinfo2, vdesc);
734 if (debugout && (i<(tattr->cVars-1)))
735 TRACE_(olerelay)(",");
737 if (debugout) TRACE_(olerelay)("}");
741 return serialize_param(tinfo2,writeit,debugout,dealloc,&tattr->tdescAlias,arg,buf);
744 if (debugout) TRACE_(olerelay)("%lx",*arg);
746 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
749 FIXME("Unhandled typekind %d\n",tattr->typekind);
753 ITypeInfo_Release(tinfo2);
757 ARRAYDESC *adesc = tdesc->u.lpadesc;
760 if (debugout) TRACE_(olerelay)("carr");
761 for (i=0;i<adesc->cDims;i++) {
762 if (debugout) TRACE_(olerelay)("[%ld]",adesc->rgbounds[i].cElements);
763 arrsize *= adesc->rgbounds[i].cElements;
765 if (debugout) TRACE_(olerelay)("(vt %d)",adesc->tdescElem.vt);
766 if (debugout) TRACE_(olerelay)("[");
767 for (i=0;i<arrsize;i++) {
768 hres = serialize_param(tinfo, writeit, debugout, dealloc, &adesc->tdescElem, (DWORD*)((LPBYTE)arg+i*_xsize(&adesc->tdescElem)), buf);
771 if (debugout && (i<arrsize-1)) TRACE_(olerelay)(",");
773 if (debugout) TRACE_(olerelay)("]");
777 ERR("Unhandled marshal type %d.\n",tdesc->vt);
794 TRACE("vt %d at %p\n",tdesc->vt,arg);
799 if (debugout) TRACE_(olerelay)("<empty>");
802 if (debugout) TRACE_(olerelay)("<null>");
805 VARIANT *vt = (VARIANT*)arg;
810 hres = xbuf_get(buf,(LPBYTE)&vttype,sizeof(vttype));
812 FIXME("vt type not read?\n");
815 memset(&tdesc2,0,sizeof(tdesc2));
818 if (debugout) TRACE_(olerelay)("Vt(%ld)(",vttype);
819 hres = deserialize_param(tinfo, readit, debugout, alloc, &tdesc2, (DWORD*)&(V_I4(vt)), buf);
820 TRACE_(olerelay)(")");
831 hres = xbuf_get(buf,(LPBYTE)arg,8);
832 if (hres) ERR("Failed to read integer 8 byte\n");
834 if (debugout) TRACE_(olerelay)("%lx%lx",arg[0],arg[1]);
843 hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
844 if (hres) ERR("Failed to read integer 4 byte\n");
846 if (debugout) TRACE_(olerelay)("%lx",*arg);
852 hres = xbuf_get(buf,(LPBYTE)&x,sizeof(DWORD));
853 if (hres) ERR("Failed to read integer 4 byte\n");
856 if (debugout) TRACE_(olerelay)("%04lx",*arg & 0xffff);
862 hres = xbuf_get(buf,(LPBYTE)&x,sizeof(DWORD));
863 if (hres) ERR("Failed to read integer 4 byte\n");
866 if (debugout) TRACE_(olerelay)("%02lx",*arg & 0xff);
871 *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
873 hres = xbuf_get(buf,(LPBYTE)*arg,sizeof(DWORD));
874 if (hres) ERR("Failed to read integer 4 byte\n");
876 if (debugout) TRACE_(olerelay)("&0x%lx",*(DWORD*)*arg);
878 case VT_BSTR|VT_BYREF: {
879 BSTR **bstr = (BSTR **)arg;
884 hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
886 ERR("failed to read bstr klen\n");
890 *bstr = CoTaskMemAlloc(sizeof(BSTR *));
892 if (debugout) TRACE_(olerelay)("<bstr NULL>");
894 str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
895 hres = xbuf_get(buf,(LPBYTE)str,len*sizeof(WCHAR));
897 ERR("Failed to read BSTR.\n");
900 *bstr = CoTaskMemAlloc(sizeof(BSTR *));
901 **bstr = SysAllocStringLen(str,len);
902 if (debugout) TRACE_(olerelay)("%s",relaystr(str));
903 HeapFree(GetProcessHeap(),0,str);
915 hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
917 ERR("failed to read bstr klen\n");
922 if (debugout) TRACE_(olerelay)("<bstr NULL>");
924 str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
925 hres = xbuf_get(buf,(LPBYTE)str,len*sizeof(WCHAR));
927 ERR("Failed to read BSTR.\n");
930 *arg = (DWORD)SysAllocStringLen(str,len);
931 if (debugout) TRACE_(olerelay)("%s",relaystr(str));
932 HeapFree(GetProcessHeap(),0,str);
941 BOOL derefhere = TRUE;
943 if (tdesc->u.lptdesc->vt == VT_USERDEFINED) {
947 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.lptdesc->u.hreftype,&tinfo2);
949 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.lptdesc->u.hreftype);
952 ITypeInfo_GetTypeAttr(tinfo2,&tattr);
953 switch (tattr->typekind) {
954 case TKIND_ENUM: /* confirmed */
955 case TKIND_RECORD: /* FIXME: mostly untested */
958 case TKIND_ALIAS: /* FIXME: untested */
959 case TKIND_DISPATCH: /* will be done in VT_USERDEFINED case */
960 case TKIND_INTERFACE: /* will be done in VT_USERDEFINED case */
964 FIXME("unhandled switch cases tattr->typekind %d\n", tattr->typekind);
968 ITypeInfo_Release(tinfo2);
970 /* read it in all cases, we need to know if we have
971 * NULL pointer or not.
973 hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
975 ERR("Failed to load pointer cookie.\n");
978 if (cookie != 0x42424242) {
979 /* we read a NULL ptr from the remote side */
980 if (debugout) TRACE_(olerelay)("NULL");
984 if (debugout) TRACE_(olerelay)("*");
986 /* Allocate space for the referenced struct */
988 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,_xsize(tdesc->u.lptdesc));
991 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, (LPDWORD)*arg, buf);
993 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, arg, buf);
996 /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
998 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
1001 hres = _unmarshal_interface(buf,&IID_IUnknown,(LPUNKNOWN*)arg);
1003 TRACE_(olerelay)("unk(%p)",arg);
1008 hres = _unmarshal_interface(buf,&IID_IDispatch,(LPUNKNOWN*)arg);
1010 TRACE_(olerelay)("idisp(%p)",arg);
1013 if (debugout) TRACE_(olerelay)("<void>");
1015 case VT_USERDEFINED: {
1019 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
1021 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
1024 hres = ITypeInfo_GetTypeAttr(tinfo2,&tattr);
1026 ERR("Could not get typeattr in VT_USERDEFINED.\n");
1028 switch (tattr->typekind) {
1029 case TKIND_DISPATCH:
1030 case TKIND_INTERFACE:
1032 hres = _unmarshal_interface(buf,&(tattr->guid),(LPUNKNOWN*)arg);
1034 case TKIND_RECORD: {
1038 *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,tattr->cbSizeInstance);
1040 if (debugout) TRACE_(olerelay)("{");
1041 for (i=0;i<tattr->cVars;i++) {
1044 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
1046 ERR("Could not get vardesc of %d\n",i);
1049 hres = deserialize_param(
1054 &vdesc->elemdescVar.tdesc,
1055 (DWORD*)(((LPBYTE)*arg)+vdesc->u.oInst),
1058 ITypeInfo2_ReleaseVarDesc(tinfo2, vdesc);
1059 if (debugout && (i<tattr->cVars-1)) TRACE_(olerelay)(",");
1061 if (debugout) TRACE_(olerelay)("}");
1065 return deserialize_param(tinfo2,readit,debugout,alloc,&tattr->tdescAlias,arg,buf);
1068 hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
1069 if (hres) ERR("Failed to read enum (4 byte)\n");
1071 if (debugout) TRACE_(olerelay)("%lx",*arg);
1074 ERR("Unhandled typekind %d\n",tattr->typekind);
1080 ERR("failed to stuballoc in TKIND_RECORD.\n");
1081 ITypeInfo_Release(tinfo2);
1085 /* arg is pointing to the start of the array. */
1086 ARRAYDESC *adesc = tdesc->u.lpadesc;
1089 if (adesc->cDims > 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
1090 for (i=0;i<adesc->cDims;i++)
1091 arrsize *= adesc->rgbounds[i].cElements;
1092 for (i=0;i<arrsize;i++)
1099 (DWORD*)((LPBYTE)(arg)+i*_xsize(&adesc->tdescElem)),
1105 ERR("No handler for VT type %d!\n",tdesc->vt);
1111 /* Searches function, also in inherited interfaces */
1114 ITypeInfo *tinfo, int iMethod, ITypeInfo **tactual, const FUNCDESC **fdesc, BSTR *iname, BSTR *fname)
1119 if (fname) *fname = NULL;
1120 if (iname) *iname = NULL;
1123 ITypeInfo_AddRef(*tactual);
1126 hres = ITypeInfoImpl_GetInternalFuncDesc(tinfo, i, fdesc);
1133 hres = ITypeInfo_GetTypeAttr(tinfo, &attr);
1135 ERR("GetTypeAttr failed with %lx\n",hres);
1138 /* Not found, so look in inherited ifaces. */
1139 for (j=0;j<attr->cImplTypes;j++) {
1140 hres = ITypeInfo_GetRefTypeOfImplType(tinfo, j, &href);
1142 ERR("Did not find a reftype for interface offset %d?\n",j);
1145 hres = ITypeInfo_GetRefTypeInfo(tinfo, href, &tinfo2);
1147 ERR("Did not find a typeinfo for reftype %ld?\n",href);
1150 hres = _get_funcdesc(tinfo2,iMethod,tactual,fdesc,iname,fname);
1151 ITypeInfo_Release(tinfo2);
1152 if (!hres) return S_OK;
1156 if (((*fdesc)->oVft/4) == iMethod) {
1158 ITypeInfo_GetDocumentation(tinfo,(*fdesc)->memid,fname,NULL,NULL,NULL);
1160 ITypeInfo_GetDocumentation(tinfo,-1,iname,NULL,NULL,NULL);
1168 xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */)
1170 DWORD *args = ((DWORD*)&tpinfo)+1, *xargs;
1171 const FUNCDESC *fdesc;
1173 int i, relaydeb = TRACE_ON(olerelay);
1180 DWORD remoteresult = 0;
1182 IRpcChannelBuffer *chanbuf;
1184 EnterCriticalSection(&tpinfo->crit);
1186 hres = _get_funcdesc(tpinfo->tinfo,method,&tinfo,&fdesc,&iname,&fname);
1188 ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method);
1189 ITypeInfo_Release(tinfo);
1190 LeaveCriticalSection(&tpinfo->crit);
1194 if (!tpinfo->chanbuf)
1196 WARN("Tried to use disconnected proxy\n");
1197 ITypeInfo_Release(tinfo);
1198 LeaveCriticalSection(&tpinfo->crit);
1199 return RPC_E_DISCONNECTED;
1201 chanbuf = tpinfo->chanbuf;
1202 IRpcChannelBuffer_AddRef(chanbuf);
1204 LeaveCriticalSection(&tpinfo->crit);
1207 TRACE_(olerelay)("->");
1209 TRACE_(olerelay)("%s:",relaystr(iname));
1211 TRACE_(olerelay)("%s(%d)",relaystr(fname),method);
1213 TRACE_(olerelay)("%d",method);
1214 TRACE_(olerelay)("(");
1217 if (iname) SysFreeString(iname);
1218 if (fname) SysFreeString(fname);
1220 memset(&buf,0,sizeof(buf));
1222 /* normal typelib driven serializing */
1224 /* Need them for hack below */
1225 memset(names,0,sizeof(names));
1226 if (ITypeInfo_GetNames(tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames))
1228 if (nrofnames > sizeof(names)/sizeof(names[0]))
1229 ERR("Need more names!\n");
1232 for (i=0;i<fdesc->cParams;i++) {
1233 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1235 if (i) TRACE_(olerelay)(",");
1236 if (i+1<nrofnames && names[i+1])
1237 TRACE_(olerelay)("%s=",relaystr(names[i+1]));
1239 /* No need to marshal other data than FIN and any VT_PTR. */
1240 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN || !elem->u.paramdesc.wParamFlags) && (elem->tdesc.vt != VT_PTR)) {
1241 xargs+=_argsize(elem->tdesc.vt);
1242 if (relaydeb) TRACE_(olerelay)("[out]");
1245 hres = serialize_param(
1247 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN || !elem->u.paramdesc.wParamFlags,
1256 ERR("Failed to serialize param, hres %lx\n",hres);
1259 xargs+=_argsize(elem->tdesc.vt);
1261 if (relaydeb) TRACE_(olerelay)(")");
1263 memset(&msg,0,sizeof(msg));
1264 msg.cbBuffer = buf.curoff;
1265 msg.iMethod = method;
1266 hres = IRpcChannelBuffer_GetBuffer(chanbuf,&msg,&(tpinfo->iid));
1268 ERR("RpcChannelBuffer GetBuffer failed, %lx\n",hres);
1271 memcpy(msg.Buffer,buf.base,buf.curoff);
1272 if (relaydeb) TRACE_(olerelay)("\n");
1273 hres = IRpcChannelBuffer_SendReceive(chanbuf,&msg,&status);
1275 ERR("RpcChannelBuffer SendReceive failed, %lx\n",hres);
1279 if (relaydeb) TRACE_(olerelay)(" status = %08lx (",status);
1281 buf.base = HeapReAlloc(GetProcessHeap(),0,buf.base,msg.cbBuffer);
1283 buf.base = HeapAlloc(GetProcessHeap(),0,msg.cbBuffer);
1284 buf.size = msg.cbBuffer;
1285 memcpy(buf.base,msg.Buffer,buf.size);
1288 /* generic deserializer using typelib description */
1291 for (i=0;i<fdesc->cParams;i++) {
1292 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1295 if (i) TRACE_(olerelay)(",");
1296 if (i+1<nrofnames && names[i+1]) TRACE_(olerelay)("%s=",relaystr(names[i+1]));
1298 /* No need to marshal other data than FOUT and any VT_PTR */
1299 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT) && (elem->tdesc.vt != VT_PTR)) {
1300 xargs += _argsize(elem->tdesc.vt);
1301 if (relaydeb) TRACE_(olerelay)("[in]");
1304 hres = deserialize_param(
1306 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1314 ERR("Failed to unmarshall param, hres %lx\n",hres);
1318 xargs += _argsize(elem->tdesc.vt);
1321 hres = xbuf_get(&buf, (LPBYTE)&remoteresult, sizeof(DWORD));
1324 if (relaydeb) TRACE_(olerelay)(") = %08lx\n", remoteresult);
1326 hres = remoteresult;
1329 HeapFree(GetProcessHeap(),0,buf.base);
1330 IRpcChannelBuffer_Release(chanbuf);
1331 ITypeInfo_Release(tinfo);
1332 TRACE("-- 0x%08lx\n", hres);
1336 HRESULT WINAPI ProxyIUnknown_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
1338 TMProxyImpl *proxy = (TMProxyImpl *)iface;
1340 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
1342 if (proxy->outerunknown)
1343 return IUnknown_QueryInterface(proxy->outerunknown, riid, ppv);
1345 FIXME("No interface\n");
1346 return E_NOINTERFACE;
1349 ULONG WINAPI ProxyIUnknown_AddRef(IUnknown *iface)
1351 TMProxyImpl *proxy = (TMProxyImpl *)iface;
1355 if (proxy->outerunknown)
1356 return IUnknown_AddRef(proxy->outerunknown);
1358 return 2; /* FIXME */
1361 ULONG WINAPI ProxyIUnknown_Release(IUnknown *iface)
1363 TMProxyImpl *proxy = (TMProxyImpl *)iface;
1367 if (proxy->outerunknown)
1368 return IUnknown_Release(proxy->outerunknown);
1370 return 1; /* FIXME */
1373 static HRESULT WINAPI ProxyIDispatch_GetTypeInfoCount(LPDISPATCH iface, UINT * pctinfo)
1375 TMProxyImpl *This = (TMProxyImpl *)iface;
1378 TRACE("(%p)\n", pctinfo);
1380 if (!This->dispatch)
1382 hr = IUnknown_QueryInterface(This->outerunknown, &IID_IDispatch,
1383 (LPVOID *)&This->dispatch);
1386 hr = IDispatch_GetTypeInfoCount(This->dispatch, pctinfo);
1391 static HRESULT WINAPI ProxyIDispatch_GetTypeInfo(LPDISPATCH iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)
1393 TMProxyImpl *This = (TMProxyImpl *)iface;
1396 TRACE("(%d, %lx, %p)\n", iTInfo, lcid, ppTInfo);
1398 if (!This->dispatch)
1400 hr = IUnknown_QueryInterface(This->outerunknown, &IID_IDispatch,
1401 (LPVOID *)&This->dispatch);
1404 hr = IDispatch_GetTypeInfo(This->dispatch, iTInfo, lcid, ppTInfo);
1409 static HRESULT WINAPI ProxyIDispatch_GetIDsOfNames(LPDISPATCH iface, REFIID riid, LPOLESTR * rgszNames, UINT cNames, LCID lcid, DISPID * rgDispId)
1411 TMProxyImpl *This = (TMProxyImpl *)iface;
1414 TRACE("(%s, %p, %d, 0x%lx, %p)\n", debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
1416 if (!This->dispatch)
1418 hr = IUnknown_QueryInterface(This->outerunknown, &IID_IDispatch,
1419 (LPVOID *)&This->dispatch);
1422 hr = IDispatch_GetIDsOfNames(This->dispatch, riid, rgszNames,
1423 cNames, lcid, rgDispId);
1428 static HRESULT WINAPI ProxyIDispatch_Invoke(LPDISPATCH iface, DISPID dispIdMember, REFIID riid, LCID lcid,
1429 WORD wFlags, DISPPARAMS * pDispParams, VARIANT * pVarResult,
1430 EXCEPINFO * pExcepInfo, UINT * puArgErr)
1432 TMProxyImpl *This = (TMProxyImpl *)iface;
1435 TRACE("(%ld, %s, 0x%lx, 0x%x, %p, %p, %p, %p)\n", dispIdMember, debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1437 if (!This->dispatch)
1439 hr = IUnknown_QueryInterface(This->outerunknown, &IID_IDispatch,
1440 (LPVOID *)&This->dispatch);
1443 hr = IDispatch_Invoke(This->dispatch, dispIdMember, riid, lcid,
1444 wFlags, pDispParams, pVarResult, pExcepInfo,
1450 static HRESULT WINAPI
1451 PSFacBuf_CreateProxy(
1452 LPPSFACTORYBUFFER iface, IUnknown* pUnkOuter, REFIID riid,
1453 IRpcProxyBuffer **ppProxy, LPVOID *ppv)
1458 const FUNCDESC *fdesc;
1462 TRACE("(...%s...)\n",debugstr_guid(riid));
1463 hres = _get_typeinfo_for_iid(riid,&tinfo);
1465 ERR("No typeinfo for %s?\n",debugstr_guid(riid));
1468 nroffuncs = _nroffuncs(tinfo);
1469 proxy = CoTaskMemAlloc(sizeof(TMProxyImpl));
1470 if (!proxy) return E_OUTOFMEMORY;
1472 assert(sizeof(TMAsmProxy) == 12);
1474 proxy->dispatch = NULL;
1475 proxy->outerunknown = pUnkOuter;
1476 proxy->asmstubs = VirtualAlloc(NULL, sizeof(TMAsmProxy) * nroffuncs, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
1477 if (!proxy->asmstubs) {
1478 ERR("Could not commit pages for proxy thunks\n");
1479 CoTaskMemFree(proxy);
1480 return E_OUTOFMEMORY;
1483 InitializeCriticalSection(&proxy->crit);
1485 proxy->lpvtbl = HeapAlloc(GetProcessHeap(),0,sizeof(LPBYTE)*nroffuncs);
1486 for (i=0;i<nroffuncs;i++) {
1487 TMAsmProxy *xasm = proxy->asmstubs+i;
1491 proxy->lpvtbl[i] = ProxyIUnknown_QueryInterface;
1494 proxy->lpvtbl[i] = ProxyIUnknown_AddRef;
1497 proxy->lpvtbl[i] = ProxyIUnknown_Release;
1501 /* nrofargs without This */
1504 hres = _get_funcdesc(tinfo,i,&tinfo2,&fdesc,NULL,NULL);
1505 ITypeInfo_Release(tinfo2);
1507 ERR("GetFuncDesc %lx should not fail here.\n",hres);
1510 /* some args take more than 4 byte on the stack */
1512 for (j=0;j<fdesc->cParams;j++)
1513 nrofargs += _argsize(fdesc->lprgelemdescParam[j].tdesc.vt);
1516 if (fdesc->callconv != CC_STDCALL) {
1517 ERR("calling convention is not stdcall????\n");
1520 /* popl %eax - return ptr
1527 * arg3 arg2 arg1 <method> <returnptr>
1529 xasm->popleax = 0x58;
1530 xasm->pushlval = 0x6a;
1532 xasm->pushleax = 0x50;
1533 xasm->lcall = 0xe8; /* relative jump */
1534 xasm->xcall = (DWORD)xCall;
1535 xasm->xcall -= (DWORD)&(xasm->lret);
1537 xasm->bytestopop= (nrofargs+2)*4; /* pop args, This, iMethod */
1538 proxy->lpvtbl[i] = xasm;
1541 FIXME("not implemented on non i386\n");
1548 /* if we derive from IDispatch then defer to its proxy for its methods */
1549 hres = ITypeInfo_GetTypeAttr(tinfo, &typeattr);
1552 if (typeattr->wTypeFlags & TYPEFLAG_FDISPATCHABLE)
1554 proxy->lpvtbl[3] = ProxyIDispatch_GetTypeInfoCount;
1555 proxy->lpvtbl[4] = ProxyIDispatch_GetTypeInfo;
1556 proxy->lpvtbl[5] = ProxyIDispatch_GetIDsOfNames;
1557 proxy->lpvtbl[6] = ProxyIDispatch_Invoke;
1559 ITypeInfo_ReleaseTypeAttr(tinfo, typeattr);
1562 proxy->lpvtbl2 = &tmproxyvtable;
1563 /* one reference for the proxy */
1565 proxy->tinfo = tinfo;
1566 memcpy(&proxy->iid,riid,sizeof(*riid));
1568 *ppv = (LPVOID)proxy;
1569 *ppProxy = (IRpcProxyBuffer *)&(proxy->lpvtbl2);
1570 IUnknown_AddRef((IUnknown *)*ppv);
1574 typedef struct _TMStubImpl {
1575 const IRpcStubBufferVtbl *lpvtbl;
1583 static HRESULT WINAPI
1584 TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface, REFIID riid, LPVOID *ppv)
1586 if (IsEqualIID(riid,&IID_IRpcStubBuffer)||IsEqualIID(riid,&IID_IUnknown)){
1587 *ppv = (LPVOID)iface;
1588 IRpcStubBuffer_AddRef(iface);
1591 FIXME("%s, not supported IID.\n",debugstr_guid(riid));
1592 return E_NOINTERFACE;
1596 TMStubImpl_AddRef(LPRPCSTUBBUFFER iface)
1598 TMStubImpl *This = (TMStubImpl *)iface;
1599 ULONG refCount = InterlockedIncrement(&This->ref);
1601 TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
1607 TMStubImpl_Release(LPRPCSTUBBUFFER iface)
1609 TMStubImpl *This = (TMStubImpl *)iface;
1610 ULONG refCount = InterlockedDecrement(&This->ref);
1612 TRACE("(%p)->(ref before=%lu)\n", This, refCount + 1);
1616 IRpcStubBuffer_Disconnect(iface);
1617 ITypeInfo_Release(This->tinfo);
1618 CoTaskMemFree(This);
1623 static HRESULT WINAPI
1624 TMStubImpl_Connect(LPRPCSTUBBUFFER iface, LPUNKNOWN pUnkServer)
1626 TMStubImpl *This = (TMStubImpl *)iface;
1628 TRACE("(%p)->(%p)\n", This, pUnkServer);
1630 IUnknown_AddRef(pUnkServer);
1631 This->pUnk = pUnkServer;
1636 TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface)
1638 TMStubImpl *This = (TMStubImpl *)iface;
1640 TRACE("(%p)->()\n", This);
1644 IUnknown_Release(This->pUnk);
1649 static HRESULT WINAPI
1651 LPRPCSTUBBUFFER iface, RPCOLEMESSAGE* xmsg,IRpcChannelBuffer*rpcchanbuf)
1654 const FUNCDESC *fdesc;
1655 TMStubImpl *This = (TMStubImpl *)iface;
1657 DWORD *args, res, *xargs, nrofargs;
1664 memset(&buf,0,sizeof(buf));
1665 buf.size = xmsg->cbBuffer;
1666 buf.base = HeapAlloc(GetProcessHeap(), 0, xmsg->cbBuffer);
1667 memcpy(buf.base, xmsg->Buffer, xmsg->cbBuffer);
1672 if (xmsg->iMethod < 3) {
1673 ERR("IUnknown methods cannot be marshaled by the typelib marshaler\n");
1674 return E_UNEXPECTED;
1677 hres = _get_funcdesc(This->tinfo,xmsg->iMethod,&tinfo,&fdesc,&iname,NULL);
1679 ERR("GetFuncDesc on method %ld failed with %lx\n",xmsg->iMethod,hres);
1683 if (iname && !lstrcmpW(iname, IDispatchW))
1685 ERR("IDispatch cannot be marshaled by the typelib marshaler\n");
1686 ITypeInfo_Release(tinfo);
1687 return E_UNEXPECTED;
1690 if (iname) SysFreeString (iname);
1692 /* Need them for hack below */
1693 memset(names,0,sizeof(names));
1694 ITypeInfo_GetNames(tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
1695 if (nrofnames > sizeof(names)/sizeof(names[0])) {
1696 ERR("Need more names!\n");
1699 /*dump_FUNCDESC(fdesc);*/
1701 for (i=0;i<fdesc->cParams;i++)
1702 nrofargs += _argsize(fdesc->lprgelemdescParam[i].tdesc.vt);
1703 args = HeapAlloc(GetProcessHeap(),0,(nrofargs+1)*sizeof(DWORD));
1704 if (!args) return E_OUTOFMEMORY;
1706 /* Allocate all stuff used by call. */
1708 for (i=0;i<fdesc->cParams;i++) {
1709 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1711 hres = deserialize_param(
1713 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN || !elem->u.paramdesc.wParamFlags,
1720 xargs += _argsize(elem->tdesc.vt);
1722 ERR("Failed to deserialize param %s, hres %lx\n",relaystr(names[i+1]),hres);
1727 args[0] = (DWORD)This->pUnk;
1729 (*((FARPROC**)args[0]))[fdesc->oVft/4],
1737 for (i=0;i<fdesc->cParams;i++) {
1738 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1739 hres = serialize_param(
1741 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1748 xargs += _argsize(elem->tdesc.vt);
1750 ERR("Failed to stuballoc param, hres %lx\n",hres);
1755 hres = xbuf_add (&buf, (LPBYTE)&res, sizeof(DWORD));
1759 ITypeInfo_Release(tinfo);
1760 HeapFree(GetProcessHeap(), 0, args);
1762 xmsg->cbBuffer = buf.curoff;
1765 hres = IRpcChannelBuffer_GetBuffer(rpcchanbuf, xmsg, &This->iid);
1767 ERR("IRpcChannelBuffer_GetBuffer failed with error 0x%08lx\n", hres);
1771 /* FIXME: remove this case when we start sending an IRpcChannelBuffer
1772 * object with builtin OLE */
1773 RPC_STATUS status = I_RpcGetBuffer((RPC_MESSAGE *)xmsg);
1774 if (status != RPC_S_OK)
1776 ERR("I_RpcGetBuffer failed with error %ld\n", status);
1782 memcpy(xmsg->Buffer, buf.base, buf.curoff);
1784 HeapFree(GetProcessHeap(), 0, buf.base);
1786 TRACE("returning\n");
1790 static LPRPCSTUBBUFFER WINAPI
1791 TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface, REFIID riid) {
1792 FIXME("Huh (%s)?\n",debugstr_guid(riid));
1797 TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface) {
1798 TMStubImpl *This = (TMStubImpl *)iface;
1801 return This->ref; /*FIXME? */
1804 static HRESULT WINAPI
1805 TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface, LPVOID *ppv) {
1810 TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface, LPVOID ppv) {
1814 static const IRpcStubBufferVtbl tmstubvtbl = {
1815 TMStubImpl_QueryInterface,
1819 TMStubImpl_Disconnect,
1821 TMStubImpl_IsIIDSupported,
1822 TMStubImpl_CountRefs,
1823 TMStubImpl_DebugServerQueryInterface,
1824 TMStubImpl_DebugServerRelease
1827 static HRESULT WINAPI
1828 PSFacBuf_CreateStub(
1829 LPPSFACTORYBUFFER iface, REFIID riid,IUnknown *pUnkServer,
1830 IRpcStubBuffer** ppStub
1836 TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub);
1837 hres = _get_typeinfo_for_iid(riid,&tinfo);
1839 ERR("No typeinfo for %s?\n",debugstr_guid(riid));
1842 stub = CoTaskMemAlloc(sizeof(TMStubImpl));
1844 return E_OUTOFMEMORY;
1845 stub->lpvtbl = &tmstubvtbl;
1847 stub->tinfo = tinfo;
1848 memcpy(&(stub->iid),riid,sizeof(*riid));
1849 hres = IRpcStubBuffer_Connect((LPRPCSTUBBUFFER)stub,pUnkServer);
1850 *ppStub = (LPRPCSTUBBUFFER)stub;
1851 TRACE("IRpcStubBuffer: %p\n", stub);
1853 ERR("Connect to pUnkServer failed?\n");
1857 static const IPSFactoryBufferVtbl psfacbufvtbl = {
1858 PSFacBuf_QueryInterface,
1861 PSFacBuf_CreateProxy,
1865 /* This is the whole PSFactoryBuffer object, just the vtableptr */
1866 static const IPSFactoryBufferVtbl *lppsfac = &psfacbufvtbl;
1868 /***********************************************************************
1869 * TMARSHAL_DllGetClassObject
1871 HRESULT TMARSHAL_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
1873 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)) {
1877 return E_NOINTERFACE;