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;
358 IRpcProxyBuffer *dispatch_proxy;
361 static HRESULT WINAPI
362 TMProxyImpl_QueryInterface(LPRPCPROXYBUFFER iface, REFIID riid, LPVOID *ppv)
365 if (IsEqualIID(riid,&IID_IUnknown)||IsEqualIID(riid,&IID_IRpcProxyBuffer)) {
366 *ppv = (LPVOID)iface;
367 IRpcProxyBuffer_AddRef(iface);
370 FIXME("no interface for %s\n",debugstr_guid(riid));
371 return E_NOINTERFACE;
375 TMProxyImpl_AddRef(LPRPCPROXYBUFFER iface)
377 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
378 ULONG refCount = InterlockedIncrement(&This->ref);
380 TRACE("(%p)->(ref before=%lu)\n",This, refCount - 1);
386 TMProxyImpl_Release(LPRPCPROXYBUFFER iface)
388 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
389 ULONG refCount = InterlockedDecrement(&This->ref);
391 TRACE("(%p)->(ref before=%lu)\n",This, refCount + 1);
395 if (This->dispatch_proxy) IRpcProxyBuffer_Release(This->dispatch_proxy);
396 DeleteCriticalSection(&This->crit);
397 if (This->chanbuf) IRpcChannelBuffer_Release(This->chanbuf);
398 VirtualFree(This->asmstubs, 0, MEM_RELEASE);
404 static HRESULT WINAPI
406 LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer)
408 ICOM_THIS_MULTI(TMProxyImpl, lpvtbl2, iface);
410 TRACE("(%p)\n", pRpcChannelBuffer);
412 EnterCriticalSection(&This->crit);
414 IRpcChannelBuffer_AddRef(pRpcChannelBuffer);
415 This->chanbuf = pRpcChannelBuffer;
417 LeaveCriticalSection(&This->crit);
419 if (This->dispatch_proxy)
420 IRpcProxyBuffer_Connect(This->dispatch_proxy, pRpcChannelBuffer);
426 TMProxyImpl_Disconnect(LPRPCPROXYBUFFER iface)
428 ICOM_THIS_MULTI(TMProxyImpl, lpvtbl2, iface);
432 EnterCriticalSection(&This->crit);
434 IRpcChannelBuffer_Release(This->chanbuf);
435 This->chanbuf = NULL;
437 LeaveCriticalSection(&This->crit);
439 if (This->dispatch_proxy)
440 IRpcProxyBuffer_Disconnect(This->dispatch_proxy);
444 static const IRpcProxyBufferVtbl tmproxyvtable = {
445 TMProxyImpl_QueryInterface,
449 TMProxyImpl_Disconnect
452 /* how much space do we use on stack in DWORD steps. */
457 return 8/sizeof(DWORD);
459 return sizeof(double)/sizeof(DWORD);
461 return sizeof(CY)/sizeof(DWORD);
463 return sizeof(DATE)/sizeof(DWORD);
465 return (sizeof(VARIANT)+3)/sizeof(DWORD);
472 _xsize(TYPEDESC *td) {
477 return sizeof(VARIANT)+3;
480 ARRAYDESC *adesc = td->u.lpadesc;
482 for (i=0;i<adesc->cDims;i++)
483 arrsize *= adesc->rgbounds[i].cElements;
484 return arrsize*_xsize(&adesc->tdescElem);
512 TRACE("(tdesc.vt %s)\n",debugstr_vt(tdesc->vt));
515 case VT_EMPTY: /* nothing. empty variant for instance */
521 if (debugout) TRACE_(olerelay)("%lx%lx",arg[0],arg[1]);
523 hres = xbuf_add(buf,(LPBYTE)arg,8);
533 if (debugout) TRACE_(olerelay)("%lx",*arg);
535 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
540 if (debugout) TRACE_(olerelay)("%04lx",*arg & 0xffff);
542 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
547 if (debugout) TRACE_(olerelay)("%02lx",*arg & 0xff);
549 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
553 if (debugout) TRACE_(olerelay)("&0x%lx",*arg);
555 hres = xbuf_add(buf,(LPBYTE)(DWORD*)*arg,sizeof(DWORD));
556 /* do not dealloc at this time */
560 VARIANT *vt = (VARIANT*)arg;
561 DWORD vttype = V_VT(vt);
563 if (debugout) TRACE_(olerelay)("Vt(%s%s)(",debugstr_vt(vttype),debugstr_vf(vttype));
566 hres = xbuf_add(buf,(LPBYTE)&vttype,sizeof(vttype));
567 if (hres) return hres;
569 /* need to recurse since we need to free the stuff */
570 hres = serialize_param(tinfo,writeit,debugout,dealloc,&tdesc2,(DWORD*)&(V_I4(vt)),buf);
571 if (debugout) TRACE_(olerelay)(")");
574 case VT_BSTR|VT_BYREF: {
575 if (debugout) TRACE_(olerelay)("[byref]'%s'", *(BSTR*)*arg ? relaystr(*((BSTR*)*arg)) : "<bstr NULL>");
577 /* ptr to ptr to magic widestring, basically */
578 BSTR *bstr = (BSTR *) *arg;
581 /* -1 means "null string" which is equivalent to empty string */
583 hres = xbuf_add(buf, (LPBYTE)&len,sizeof(DWORD));
584 if (hres) return hres;
586 len = *((DWORD*)*bstr-1)/sizeof(WCHAR);
587 hres = xbuf_add(buf,(LPBYTE)&len,sizeof(DWORD));
588 if (hres) return hres;
589 hres = xbuf_add(buf,(LPBYTE)*bstr,len * sizeof(WCHAR));
590 if (hres) return hres;
594 if (dealloc && arg) {
595 BSTR *str = *((BSTR **)arg);
604 TRACE_(olerelay)("%s",relaystr((WCHAR*)*arg));
606 TRACE_(olerelay)("<bstr NULL>");
609 BSTR bstr = (BSTR)*arg;
613 hres = xbuf_add(buf,(LPBYTE)&len,sizeof(DWORD));
614 if (hres) return hres;
616 len = *((DWORD*)bstr-1)/sizeof(WCHAR);
617 hres = xbuf_add(buf,(LPBYTE)&len,sizeof(DWORD));
618 if (hres) return hres;
619 hres = xbuf_add(buf,(LPBYTE)bstr,len * sizeof(WCHAR));
620 if (hres) return hres;
625 SysFreeString((BSTR)*arg);
630 BOOL derefhere = TRUE;
632 if (tdesc->u.lptdesc->vt == VT_USERDEFINED) {
636 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.lptdesc->u.hreftype,&tinfo2);
638 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.lptdesc->u.hreftype);
641 ITypeInfo_GetTypeAttr(tinfo2,&tattr);
642 switch (tattr->typekind) {
643 case TKIND_ENUM: /* confirmed */
644 case TKIND_RECORD: /* FIXME: mostly untested */
647 case TKIND_ALIAS: /* FIXME: untested */
648 case TKIND_DISPATCH: /* will be done in VT_USERDEFINED case */
649 case TKIND_INTERFACE: /* will be done in VT_USERDEFINED case */
653 FIXME("unhandled switch cases tattr->typekind %d\n", tattr->typekind);
657 ITypeInfo_Release(tinfo2);
660 if (debugout) TRACE_(olerelay)("*");
661 /* Write always, so the other side knows when it gets a NULL pointer.
663 cookie = *arg ? 0x42424242 : 0;
664 hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
668 if (debugout) TRACE_(olerelay)("NULL");
671 hres = serialize_param(tinfo,writeit,debugout,dealloc,tdesc->u.lptdesc,(DWORD*)*arg,buf);
672 if (derefhere && dealloc) HeapFree(GetProcessHeap(),0,(LPVOID)*arg);
676 if (debugout) TRACE_(olerelay)("unk(0x%lx)",*arg);
678 hres = _marshal_interface(buf,&IID_IUnknown,(LPUNKNOWN)*arg);
679 if (dealloc && *(IUnknown **)arg)
680 IUnknown_Release((LPUNKNOWN)*arg);
683 if (debugout) TRACE_(olerelay)("idisp(0x%lx)",*arg);
685 hres = _marshal_interface(buf,&IID_IDispatch,(LPUNKNOWN)*arg);
686 if (dealloc && *(IUnknown **)arg)
687 IUnknown_Release((LPUNKNOWN)*arg);
690 if (debugout) TRACE_(olerelay)("<void>");
692 case VT_USERDEFINED: {
696 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
698 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
701 ITypeInfo_GetTypeAttr(tinfo2,&tattr);
702 switch (tattr->typekind) {
704 case TKIND_INTERFACE:
706 hres=_marshal_interface(buf,&(tattr->guid),(LPUNKNOWN)arg);
708 IUnknown_Release((LPUNKNOWN)arg);
712 if (debugout) TRACE_(olerelay)("{");
713 for (i=0;i<tattr->cVars;i++) {
718 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
720 ERR("Could not get vardesc of %d\n",i);
723 /* Need them for hack below */
725 memset(names,0,sizeof(names));
726 hres = ITypeInfo_GetNames(tinfo2,vdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
727 if (nrofnames > sizeof(names)/sizeof(names[0])) {
728 ERR("Need more names!\n");
730 if (!hres && debugout)
731 TRACE_(olerelay)("%s=",relaystr(names[0]));
733 elem2 = &vdesc->elemdescVar;
734 tdesc2 = &elem2->tdesc;
735 hres = serialize_param(
741 (DWORD*)(((LPBYTE)arg)+vdesc->u.oInst),
744 ITypeInfo_ReleaseVarDesc(tinfo2, vdesc);
747 if (debugout && (i<(tattr->cVars-1)))
748 TRACE_(olerelay)(",");
750 if (debugout) TRACE_(olerelay)("}");
754 return serialize_param(tinfo2,writeit,debugout,dealloc,&tattr->tdescAlias,arg,buf);
757 if (debugout) TRACE_(olerelay)("%lx",*arg);
759 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
762 FIXME("Unhandled typekind %d\n",tattr->typekind);
766 ITypeInfo_Release(tinfo2);
770 ARRAYDESC *adesc = tdesc->u.lpadesc;
773 if (debugout) TRACE_(olerelay)("carr");
774 for (i=0;i<adesc->cDims;i++) {
775 if (debugout) TRACE_(olerelay)("[%ld]",adesc->rgbounds[i].cElements);
776 arrsize *= adesc->rgbounds[i].cElements;
778 if (debugout) TRACE_(olerelay)("(vt %s)",debugstr_vt(adesc->tdescElem.vt));
779 if (debugout) TRACE_(olerelay)("[");
780 for (i=0;i<arrsize;i++) {
781 hres = serialize_param(tinfo, writeit, debugout, dealloc, &adesc->tdescElem, (DWORD*)((LPBYTE)arg+i*_xsize(&adesc->tdescElem)), buf);
784 if (debugout && (i<arrsize-1)) TRACE_(olerelay)(",");
786 if (debugout) TRACE_(olerelay)("]");
790 ERR("Unhandled marshal type %d.\n",tdesc->vt);
807 TRACE("vt %s at %p\n",debugstr_vt(tdesc->vt),arg);
812 if (debugout) TRACE_(olerelay)("<empty>");
815 if (debugout) TRACE_(olerelay)("<null>");
818 VARIANT *vt = (VARIANT*)arg;
823 hres = xbuf_get(buf,(LPBYTE)&vttype,sizeof(vttype));
825 FIXME("vt type not read?\n");
828 memset(&tdesc2,0,sizeof(tdesc2));
831 if (debugout) TRACE_(olerelay)("Vt(%s%s)(",debugstr_vt(vttype),debugstr_vf(vttype));
832 hres = deserialize_param(tinfo, readit, debugout, alloc, &tdesc2, (DWORD*)&(V_I4(vt)), buf);
833 TRACE_(olerelay)(")");
844 hres = xbuf_get(buf,(LPBYTE)arg,8);
845 if (hres) ERR("Failed to read integer 8 byte\n");
847 if (debugout) TRACE_(olerelay)("%lx%lx",arg[0],arg[1]);
857 hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
858 if (hres) ERR("Failed to read integer 4 byte\n");
860 if (debugout) TRACE_(olerelay)("%lx",*arg);
866 hres = xbuf_get(buf,(LPBYTE)&x,sizeof(DWORD));
867 if (hres) ERR("Failed to read integer 4 byte\n");
870 if (debugout) TRACE_(olerelay)("%04lx",*arg & 0xffff);
876 hres = xbuf_get(buf,(LPBYTE)&x,sizeof(DWORD));
877 if (hres) ERR("Failed to read integer 4 byte\n");
880 if (debugout) TRACE_(olerelay)("%02lx",*arg & 0xff);
885 *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
887 hres = xbuf_get(buf,(LPBYTE)*arg,sizeof(DWORD));
888 if (hres) ERR("Failed to read integer 4 byte\n");
890 if (debugout) TRACE_(olerelay)("&0x%lx",*(DWORD*)*arg);
892 case VT_BSTR|VT_BYREF: {
893 BSTR **bstr = (BSTR **)arg;
898 hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
900 ERR("failed to read bstr klen\n");
904 *bstr = CoTaskMemAlloc(sizeof(BSTR *));
906 if (debugout) TRACE_(olerelay)("<bstr NULL>");
908 str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
909 hres = xbuf_get(buf,(LPBYTE)str,len*sizeof(WCHAR));
911 ERR("Failed to read BSTR.\n");
914 *bstr = CoTaskMemAlloc(sizeof(BSTR *));
915 **bstr = SysAllocStringLen(str,len);
916 if (debugout) TRACE_(olerelay)("%s",relaystr(str));
917 HeapFree(GetProcessHeap(),0,str);
929 hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
931 ERR("failed to read bstr klen\n");
936 if (debugout) TRACE_(olerelay)("<bstr NULL>");
938 str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
939 hres = xbuf_get(buf,(LPBYTE)str,len*sizeof(WCHAR));
941 ERR("Failed to read BSTR.\n");
944 *arg = (DWORD)SysAllocStringLen(str,len);
945 if (debugout) TRACE_(olerelay)("%s",relaystr(str));
946 HeapFree(GetProcessHeap(),0,str);
955 BOOL derefhere = TRUE;
957 if (tdesc->u.lptdesc->vt == VT_USERDEFINED) {
961 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.lptdesc->u.hreftype,&tinfo2);
963 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.lptdesc->u.hreftype);
966 ITypeInfo_GetTypeAttr(tinfo2,&tattr);
967 switch (tattr->typekind) {
968 case TKIND_ENUM: /* confirmed */
969 case TKIND_RECORD: /* FIXME: mostly untested */
972 case TKIND_ALIAS: /* FIXME: untested */
973 case TKIND_DISPATCH: /* will be done in VT_USERDEFINED case */
974 case TKIND_INTERFACE: /* will be done in VT_USERDEFINED case */
978 FIXME("unhandled switch cases tattr->typekind %d\n", tattr->typekind);
982 ITypeInfo_Release(tinfo2);
984 /* read it in all cases, we need to know if we have
985 * NULL pointer or not.
987 hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
989 ERR("Failed to load pointer cookie.\n");
992 if (cookie != 0x42424242) {
993 /* we read a NULL ptr from the remote side */
994 if (debugout) TRACE_(olerelay)("NULL");
998 if (debugout) TRACE_(olerelay)("*");
1000 /* Allocate space for the referenced struct */
1002 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,_xsize(tdesc->u.lptdesc));
1005 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, (LPDWORD)*arg, buf);
1007 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, arg, buf);
1010 /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
1012 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
1015 hres = _unmarshal_interface(buf,&IID_IUnknown,(LPUNKNOWN*)arg);
1017 TRACE_(olerelay)("unk(%p)",arg);
1022 hres = _unmarshal_interface(buf,&IID_IDispatch,(LPUNKNOWN*)arg);
1024 TRACE_(olerelay)("idisp(%p)",arg);
1027 if (debugout) TRACE_(olerelay)("<void>");
1029 case VT_USERDEFINED: {
1033 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
1035 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
1038 hres = ITypeInfo_GetTypeAttr(tinfo2,&tattr);
1040 ERR("Could not get typeattr in VT_USERDEFINED.\n");
1042 switch (tattr->typekind) {
1043 case TKIND_DISPATCH:
1044 case TKIND_INTERFACE:
1046 hres = _unmarshal_interface(buf,&(tattr->guid),(LPUNKNOWN*)arg);
1048 case TKIND_RECORD: {
1052 *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,tattr->cbSizeInstance);
1054 if (debugout) TRACE_(olerelay)("{");
1055 for (i=0;i<tattr->cVars;i++) {
1058 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
1060 ERR("Could not get vardesc of %d\n",i);
1063 hres = deserialize_param(
1068 &vdesc->elemdescVar.tdesc,
1069 (DWORD*)(((LPBYTE)*arg)+vdesc->u.oInst),
1072 ITypeInfo2_ReleaseVarDesc(tinfo2, vdesc);
1073 if (debugout && (i<tattr->cVars-1)) TRACE_(olerelay)(",");
1075 if (debugout) TRACE_(olerelay)("}");
1079 return deserialize_param(tinfo2,readit,debugout,alloc,&tattr->tdescAlias,arg,buf);
1082 hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
1083 if (hres) ERR("Failed to read enum (4 byte)\n");
1085 if (debugout) TRACE_(olerelay)("%lx",*arg);
1088 ERR("Unhandled typekind %d\n",tattr->typekind);
1094 ERR("failed to stuballoc in TKIND_RECORD.\n");
1095 ITypeInfo_Release(tinfo2);
1099 /* arg is pointing to the start of the array. */
1100 ARRAYDESC *adesc = tdesc->u.lpadesc;
1103 if (adesc->cDims > 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
1104 for (i=0;i<adesc->cDims;i++)
1105 arrsize *= adesc->rgbounds[i].cElements;
1106 for (i=0;i<arrsize;i++)
1113 (DWORD*)((LPBYTE)(arg)+i*_xsize(&adesc->tdescElem)),
1119 ERR("No handler for VT type %d!\n",tdesc->vt);
1125 /* Searches function, also in inherited interfaces */
1128 ITypeInfo *tinfo, int iMethod, ITypeInfo **tactual, const FUNCDESC **fdesc, BSTR *iname, BSTR *fname)
1133 if (fname) *fname = NULL;
1134 if (iname) *iname = NULL;
1137 ITypeInfo_AddRef(*tactual);
1140 hres = ITypeInfoImpl_GetInternalFuncDesc(tinfo, i, fdesc);
1147 hres = ITypeInfo_GetTypeAttr(tinfo, &attr);
1149 ERR("GetTypeAttr failed with %lx\n",hres);
1152 /* Not found, so look in inherited ifaces. */
1153 for (j=0;j<attr->cImplTypes;j++) {
1154 hres = ITypeInfo_GetRefTypeOfImplType(tinfo, j, &href);
1156 ERR("Did not find a reftype for interface offset %d?\n",j);
1159 hres = ITypeInfo_GetRefTypeInfo(tinfo, href, &tinfo2);
1161 ERR("Did not find a typeinfo for reftype %ld?\n",href);
1164 hres = _get_funcdesc(tinfo2,iMethod,tactual,fdesc,iname,fname);
1165 ITypeInfo_Release(tinfo2);
1166 if (!hres) return S_OK;
1170 if (((*fdesc)->oVft/4) == iMethod) {
1172 ITypeInfo_GetDocumentation(tinfo,(*fdesc)->memid,fname,NULL,NULL,NULL);
1174 ITypeInfo_GetDocumentation(tinfo,-1,iname,NULL,NULL,NULL);
1182 xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */)
1184 DWORD *args = ((DWORD*)&tpinfo)+1, *xargs;
1185 const FUNCDESC *fdesc;
1187 int i, relaydeb = TRACE_ON(olerelay);
1194 DWORD remoteresult = 0;
1196 IRpcChannelBuffer *chanbuf;
1198 EnterCriticalSection(&tpinfo->crit);
1200 hres = _get_funcdesc(tpinfo->tinfo,method,&tinfo,&fdesc,&iname,&fname);
1202 ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method);
1203 ITypeInfo_Release(tinfo);
1204 LeaveCriticalSection(&tpinfo->crit);
1208 if (!tpinfo->chanbuf)
1210 WARN("Tried to use disconnected proxy\n");
1211 ITypeInfo_Release(tinfo);
1212 LeaveCriticalSection(&tpinfo->crit);
1213 return RPC_E_DISCONNECTED;
1215 chanbuf = tpinfo->chanbuf;
1216 IRpcChannelBuffer_AddRef(chanbuf);
1218 LeaveCriticalSection(&tpinfo->crit);
1221 TRACE_(olerelay)("->");
1223 TRACE_(olerelay)("%s:",relaystr(iname));
1225 TRACE_(olerelay)("%s(%d)",relaystr(fname),method);
1227 TRACE_(olerelay)("%d",method);
1228 TRACE_(olerelay)("(");
1231 if (iname) SysFreeString(iname);
1232 if (fname) SysFreeString(fname);
1234 memset(&buf,0,sizeof(buf));
1236 /* normal typelib driven serializing */
1238 /* Need them for hack below */
1239 memset(names,0,sizeof(names));
1240 if (ITypeInfo_GetNames(tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames))
1242 if (nrofnames > sizeof(names)/sizeof(names[0]))
1243 ERR("Need more names!\n");
1246 for (i=0;i<fdesc->cParams;i++) {
1247 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1249 if (i) TRACE_(olerelay)(",");
1250 if (i+1<nrofnames && names[i+1])
1251 TRACE_(olerelay)("%s=",relaystr(names[i+1]));
1253 /* No need to marshal other data than FIN and any VT_PTR. */
1254 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN || !elem->u.paramdesc.wParamFlags) && (elem->tdesc.vt != VT_PTR)) {
1255 xargs+=_argsize(elem->tdesc.vt);
1256 if (relaydeb) TRACE_(olerelay)("[out]");
1259 hres = serialize_param(
1261 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN || !elem->u.paramdesc.wParamFlags,
1270 ERR("Failed to serialize param, hres %lx\n",hres);
1273 xargs+=_argsize(elem->tdesc.vt);
1275 if (relaydeb) TRACE_(olerelay)(")");
1277 memset(&msg,0,sizeof(msg));
1278 msg.cbBuffer = buf.curoff;
1279 msg.iMethod = method;
1280 hres = IRpcChannelBuffer_GetBuffer(chanbuf,&msg,&(tpinfo->iid));
1282 ERR("RpcChannelBuffer GetBuffer failed, %lx\n",hres);
1285 memcpy(msg.Buffer,buf.base,buf.curoff);
1286 if (relaydeb) TRACE_(olerelay)("\n");
1287 hres = IRpcChannelBuffer_SendReceive(chanbuf,&msg,&status);
1289 ERR("RpcChannelBuffer SendReceive failed, %lx\n",hres);
1293 if (relaydeb) TRACE_(olerelay)(" status = %08lx (",status);
1295 buf.base = HeapReAlloc(GetProcessHeap(),0,buf.base,msg.cbBuffer);
1297 buf.base = HeapAlloc(GetProcessHeap(),0,msg.cbBuffer);
1298 buf.size = msg.cbBuffer;
1299 memcpy(buf.base,msg.Buffer,buf.size);
1302 /* generic deserializer using typelib description */
1305 for (i=0;i<fdesc->cParams;i++) {
1306 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1309 if (i) TRACE_(olerelay)(",");
1310 if (i+1<nrofnames && names[i+1]) TRACE_(olerelay)("%s=",relaystr(names[i+1]));
1312 /* No need to marshal other data than FOUT and any VT_PTR */
1313 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT) && (elem->tdesc.vt != VT_PTR)) {
1314 xargs += _argsize(elem->tdesc.vt);
1315 if (relaydeb) TRACE_(olerelay)("[in]");
1318 hres = deserialize_param(
1320 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1328 ERR("Failed to unmarshall param, hres %lx\n",hres);
1332 xargs += _argsize(elem->tdesc.vt);
1335 hres = xbuf_get(&buf, (LPBYTE)&remoteresult, sizeof(DWORD));
1338 if (relaydeb) TRACE_(olerelay)(") = %08lx\n", remoteresult);
1340 hres = remoteresult;
1343 HeapFree(GetProcessHeap(),0,buf.base);
1344 IRpcChannelBuffer_Release(chanbuf);
1345 ITypeInfo_Release(tinfo);
1346 TRACE("-- 0x%08lx\n", hres);
1350 HRESULT WINAPI ProxyIUnknown_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
1352 TMProxyImpl *proxy = (TMProxyImpl *)iface;
1354 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
1356 if (proxy->outerunknown)
1357 return IUnknown_QueryInterface(proxy->outerunknown, riid, ppv);
1359 FIXME("No interface\n");
1360 return E_NOINTERFACE;
1363 ULONG WINAPI ProxyIUnknown_AddRef(IUnknown *iface)
1365 TMProxyImpl *proxy = (TMProxyImpl *)iface;
1369 if (proxy->outerunknown)
1370 return IUnknown_AddRef(proxy->outerunknown);
1372 return 2; /* FIXME */
1375 ULONG WINAPI ProxyIUnknown_Release(IUnknown *iface)
1377 TMProxyImpl *proxy = (TMProxyImpl *)iface;
1381 if (proxy->outerunknown)
1382 return IUnknown_Release(proxy->outerunknown);
1384 return 1; /* FIXME */
1387 static HRESULT WINAPI ProxyIDispatch_GetTypeInfoCount(LPDISPATCH iface, UINT * pctinfo)
1389 TMProxyImpl *This = (TMProxyImpl *)iface;
1391 TRACE("(%p)\n", pctinfo);
1393 return IDispatch_GetTypeInfoCount(This->dispatch, pctinfo);
1396 static HRESULT WINAPI ProxyIDispatch_GetTypeInfo(LPDISPATCH iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)
1398 TMProxyImpl *This = (TMProxyImpl *)iface;
1400 TRACE("(%d, %lx, %p)\n", iTInfo, lcid, ppTInfo);
1402 return IDispatch_GetTypeInfo(This->dispatch, iTInfo, lcid, ppTInfo);
1405 static HRESULT WINAPI ProxyIDispatch_GetIDsOfNames(LPDISPATCH iface, REFIID riid, LPOLESTR * rgszNames, UINT cNames, LCID lcid, DISPID * rgDispId)
1407 TMProxyImpl *This = (TMProxyImpl *)iface;
1409 TRACE("(%s, %p, %d, 0x%lx, %p)\n", debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
1411 return IDispatch_GetIDsOfNames(This->dispatch, riid, rgszNames,
1412 cNames, lcid, rgDispId);
1415 static HRESULT WINAPI ProxyIDispatch_Invoke(LPDISPATCH iface, DISPID dispIdMember, REFIID riid, LCID lcid,
1416 WORD wFlags, DISPPARAMS * pDispParams, VARIANT * pVarResult,
1417 EXCEPINFO * pExcepInfo, UINT * puArgErr)
1419 TMProxyImpl *This = (TMProxyImpl *)iface;
1421 TRACE("(%ld, %s, 0x%lx, 0x%x, %p, %p, %p, %p)\n", dispIdMember,
1422 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult,
1423 pExcepInfo, puArgErr);
1425 return IDispatch_Invoke(This->dispatch, dispIdMember, riid, lcid,
1426 wFlags, pDispParams, pVarResult, pExcepInfo,
1430 static inline HRESULT get_facbuf_for_iid(REFIID riid, IPSFactoryBuffer **facbuf)
1435 if ((hr = CoGetPSClsid(riid, &clsid)))
1437 return CoGetClassObject(&clsid, CLSCTX_INPROC_SERVER, NULL,
1438 &IID_IPSFactoryBuffer, (LPVOID*)facbuf);
1441 static HRESULT WINAPI
1442 PSFacBuf_CreateProxy(
1443 LPPSFACTORYBUFFER iface, IUnknown* pUnkOuter, REFIID riid,
1444 IRpcProxyBuffer **ppProxy, LPVOID *ppv)
1449 const FUNCDESC *fdesc;
1453 TRACE("(...%s...)\n",debugstr_guid(riid));
1454 hres = _get_typeinfo_for_iid(riid,&tinfo);
1456 ERR("No typeinfo for %s?\n",debugstr_guid(riid));
1459 nroffuncs = _nroffuncs(tinfo);
1460 proxy = CoTaskMemAlloc(sizeof(TMProxyImpl));
1461 if (!proxy) return E_OUTOFMEMORY;
1463 assert(sizeof(TMAsmProxy) == 12);
1465 proxy->dispatch = NULL;
1466 proxy->dispatch_proxy = NULL;
1467 proxy->outerunknown = pUnkOuter;
1468 proxy->asmstubs = VirtualAlloc(NULL, sizeof(TMAsmProxy) * nroffuncs, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
1469 if (!proxy->asmstubs) {
1470 ERR("Could not commit pages for proxy thunks\n");
1471 CoTaskMemFree(proxy);
1472 return E_OUTOFMEMORY;
1475 InitializeCriticalSection(&proxy->crit);
1477 proxy->lpvtbl = HeapAlloc(GetProcessHeap(),0,sizeof(LPBYTE)*nroffuncs);
1478 for (i=0;i<nroffuncs;i++) {
1479 TMAsmProxy *xasm = proxy->asmstubs+i;
1483 proxy->lpvtbl[i] = ProxyIUnknown_QueryInterface;
1486 proxy->lpvtbl[i] = ProxyIUnknown_AddRef;
1489 proxy->lpvtbl[i] = ProxyIUnknown_Release;
1493 /* nrofargs without This */
1496 hres = _get_funcdesc(tinfo,i,&tinfo2,&fdesc,NULL,NULL);
1497 ITypeInfo_Release(tinfo2);
1499 ERR("GetFuncDesc %lx should not fail here.\n",hres);
1502 /* some args take more than 4 byte on the stack */
1504 for (j=0;j<fdesc->cParams;j++)
1505 nrofargs += _argsize(fdesc->lprgelemdescParam[j].tdesc.vt);
1508 if (fdesc->callconv != CC_STDCALL) {
1509 ERR("calling convention is not stdcall????\n");
1512 /* popl %eax - return ptr
1519 * arg3 arg2 arg1 <method> <returnptr>
1521 xasm->popleax = 0x58;
1522 xasm->pushlval = 0x6a;
1524 xasm->pushleax = 0x50;
1525 xasm->lcall = 0xe8; /* relative jump */
1526 xasm->xcall = (DWORD)xCall;
1527 xasm->xcall -= (DWORD)&(xasm->lret);
1529 xasm->bytestopop= (nrofargs+2)*4; /* pop args, This, iMethod */
1530 proxy->lpvtbl[i] = xasm;
1533 FIXME("not implemented on non i386\n");
1540 /* if we derive from IDispatch then defer to its proxy for its methods */
1541 hres = ITypeInfo_GetTypeAttr(tinfo, &typeattr);
1544 if (typeattr->wTypeFlags & TYPEFLAG_FDISPATCHABLE)
1546 IPSFactoryBuffer *factory_buffer;
1547 hres = get_facbuf_for_iid(&IID_IDispatch, &factory_buffer);
1550 hres = IPSFactoryBuffer_CreateProxy(factory_buffer, NULL,
1551 &IID_IDispatch, &proxy->dispatch_proxy,
1552 (void **)&proxy->dispatch);
1553 IPSFactoryBuffer_Release(factory_buffer);
1557 proxy->lpvtbl[3] = ProxyIDispatch_GetTypeInfoCount;
1558 proxy->lpvtbl[4] = ProxyIDispatch_GetTypeInfo;
1559 proxy->lpvtbl[5] = ProxyIDispatch_GetIDsOfNames;
1560 proxy->lpvtbl[6] = ProxyIDispatch_Invoke;
1563 ITypeInfo_ReleaseTypeAttr(tinfo, typeattr);
1566 proxy->lpvtbl2 = &tmproxyvtable;
1567 /* one reference for the proxy */
1569 proxy->tinfo = tinfo;
1570 memcpy(&proxy->iid,riid,sizeof(*riid));
1574 *ppv = (LPVOID)proxy;
1575 *ppProxy = (IRpcProxyBuffer *)&(proxy->lpvtbl2);
1576 IUnknown_AddRef((IUnknown *)*ppv);
1580 TMProxyImpl_Release((IRpcProxyBuffer *)&proxy->lpvtbl2);
1584 typedef struct _TMStubImpl {
1585 const IRpcStubBufferVtbl *lpvtbl;
1591 IRpcStubBuffer *dispatch_stub;
1594 static HRESULT WINAPI
1595 TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface, REFIID riid, LPVOID *ppv)
1597 if (IsEqualIID(riid,&IID_IRpcStubBuffer)||IsEqualIID(riid,&IID_IUnknown)){
1598 *ppv = (LPVOID)iface;
1599 IRpcStubBuffer_AddRef(iface);
1602 FIXME("%s, not supported IID.\n",debugstr_guid(riid));
1603 return E_NOINTERFACE;
1607 TMStubImpl_AddRef(LPRPCSTUBBUFFER iface)
1609 TMStubImpl *This = (TMStubImpl *)iface;
1610 ULONG refCount = InterlockedIncrement(&This->ref);
1612 TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
1618 TMStubImpl_Release(LPRPCSTUBBUFFER iface)
1620 TMStubImpl *This = (TMStubImpl *)iface;
1621 ULONG refCount = InterlockedDecrement(&This->ref);
1623 TRACE("(%p)->(ref before=%lu)\n", This, refCount + 1);
1627 IRpcStubBuffer_Disconnect(iface);
1628 ITypeInfo_Release(This->tinfo);
1629 CoTaskMemFree(This);
1634 static HRESULT WINAPI
1635 TMStubImpl_Connect(LPRPCSTUBBUFFER iface, LPUNKNOWN pUnkServer)
1637 TMStubImpl *This = (TMStubImpl *)iface;
1639 TRACE("(%p)->(%p)\n", This, pUnkServer);
1641 IUnknown_AddRef(pUnkServer);
1642 This->pUnk = pUnkServer;
1644 if (This->dispatch_stub)
1645 IRpcStubBuffer_Connect(This->dispatch_stub, pUnkServer);
1651 TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface)
1653 TMStubImpl *This = (TMStubImpl *)iface;
1655 TRACE("(%p)->()\n", This);
1659 IUnknown_Release(This->pUnk);
1663 if (This->dispatch_stub)
1664 IRpcStubBuffer_Disconnect(This->dispatch_stub);
1667 static HRESULT WINAPI
1669 LPRPCSTUBBUFFER iface, RPCOLEMESSAGE* xmsg,IRpcChannelBuffer*rpcchanbuf)
1672 const FUNCDESC *fdesc;
1673 TMStubImpl *This = (TMStubImpl *)iface;
1675 DWORD *args, res, *xargs, nrofargs;
1684 if (xmsg->iMethod < 3) {
1685 ERR("IUnknown methods cannot be marshaled by the typelib marshaler\n");
1686 return E_UNEXPECTED;
1689 if (This->dispatch_stub && xmsg->iMethod < sizeof(IDispatchVtbl)/sizeof(void *))
1690 return IRpcStubBuffer_Invoke(This->dispatch_stub, xmsg, rpcchanbuf);
1692 memset(&buf,0,sizeof(buf));
1693 buf.size = xmsg->cbBuffer;
1694 buf.base = HeapAlloc(GetProcessHeap(), 0, xmsg->cbBuffer);
1695 memcpy(buf.base, xmsg->Buffer, xmsg->cbBuffer);
1698 hres = _get_funcdesc(This->tinfo,xmsg->iMethod,&tinfo,&fdesc,&iname,NULL);
1700 ERR("GetFuncDesc on method %ld failed with %lx\n",xmsg->iMethod,hres);
1704 if (iname && !lstrcmpW(iname, IDispatchW))
1706 ERR("IDispatch cannot be marshaled by the typelib marshaler\n");
1707 ITypeInfo_Release(tinfo);
1708 return E_UNEXPECTED;
1711 if (iname) SysFreeString (iname);
1713 /* Need them for hack below */
1714 memset(names,0,sizeof(names));
1715 ITypeInfo_GetNames(tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
1716 if (nrofnames > sizeof(names)/sizeof(names[0])) {
1717 ERR("Need more names!\n");
1720 /*dump_FUNCDESC(fdesc);*/
1722 for (i=0;i<fdesc->cParams;i++)
1723 nrofargs += _argsize(fdesc->lprgelemdescParam[i].tdesc.vt);
1724 args = HeapAlloc(GetProcessHeap(),0,(nrofargs+1)*sizeof(DWORD));
1725 if (!args) return E_OUTOFMEMORY;
1727 /* Allocate all stuff used by call. */
1729 for (i=0;i<fdesc->cParams;i++) {
1730 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1732 hres = deserialize_param(
1734 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN || !elem->u.paramdesc.wParamFlags,
1741 xargs += _argsize(elem->tdesc.vt);
1743 ERR("Failed to deserialize param %s, hres %lx\n",relaystr(names[i+1]),hres);
1748 args[0] = (DWORD)This->pUnk;
1750 (*((FARPROC**)args[0]))[fdesc->oVft/4],
1758 for (i=0;i<fdesc->cParams;i++) {
1759 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1760 hres = serialize_param(
1762 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1769 xargs += _argsize(elem->tdesc.vt);
1771 ERR("Failed to stuballoc param, hres %lx\n",hres);
1776 hres = xbuf_add (&buf, (LPBYTE)&res, sizeof(DWORD));
1780 ITypeInfo_Release(tinfo);
1781 HeapFree(GetProcessHeap(), 0, args);
1783 xmsg->cbBuffer = buf.curoff;
1786 hres = IRpcChannelBuffer_GetBuffer(rpcchanbuf, xmsg, &This->iid);
1788 ERR("IRpcChannelBuffer_GetBuffer failed with error 0x%08lx\n", hres);
1792 /* FIXME: remove this case when we start sending an IRpcChannelBuffer
1793 * object with builtin OLE */
1794 RPC_STATUS status = I_RpcGetBuffer((RPC_MESSAGE *)xmsg);
1795 if (status != RPC_S_OK)
1797 ERR("I_RpcGetBuffer failed with error %ld\n", status);
1803 memcpy(xmsg->Buffer, buf.base, buf.curoff);
1805 HeapFree(GetProcessHeap(), 0, buf.base);
1807 TRACE("returning\n");
1811 static LPRPCSTUBBUFFER WINAPI
1812 TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface, REFIID riid) {
1813 FIXME("Huh (%s)?\n",debugstr_guid(riid));
1818 TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface) {
1819 TMStubImpl *This = (TMStubImpl *)iface;
1822 return This->ref; /*FIXME? */
1825 static HRESULT WINAPI
1826 TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface, LPVOID *ppv) {
1831 TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface, LPVOID ppv) {
1835 static const IRpcStubBufferVtbl tmstubvtbl = {
1836 TMStubImpl_QueryInterface,
1840 TMStubImpl_Disconnect,
1842 TMStubImpl_IsIIDSupported,
1843 TMStubImpl_CountRefs,
1844 TMStubImpl_DebugServerQueryInterface,
1845 TMStubImpl_DebugServerRelease
1848 static HRESULT WINAPI
1849 PSFacBuf_CreateStub(
1850 LPPSFACTORYBUFFER iface, REFIID riid,IUnknown *pUnkServer,
1851 IRpcStubBuffer** ppStub
1858 TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub);
1860 hres = _get_typeinfo_for_iid(riid,&tinfo);
1862 ERR("No typeinfo for %s?\n",debugstr_guid(riid));
1866 stub = CoTaskMemAlloc(sizeof(TMStubImpl));
1868 return E_OUTOFMEMORY;
1869 stub->lpvtbl = &tmstubvtbl;
1871 stub->tinfo = tinfo;
1872 stub->dispatch_stub = NULL;
1873 memcpy(&(stub->iid),riid,sizeof(*riid));
1874 hres = IRpcStubBuffer_Connect((LPRPCSTUBBUFFER)stub,pUnkServer);
1875 *ppStub = (LPRPCSTUBBUFFER)stub;
1876 TRACE("IRpcStubBuffer: %p\n", stub);
1878 ERR("Connect to pUnkServer failed?\n");
1880 /* if we derive from IDispatch then defer to its stub for some of its methods */
1881 hres = ITypeInfo_GetTypeAttr(tinfo, &typeattr);
1884 if (typeattr->wTypeFlags & TYPEFLAG_FDISPATCHABLE)
1886 IPSFactoryBuffer *factory_buffer;
1887 hres = get_facbuf_for_iid(&IID_IDispatch, &factory_buffer);
1890 hres = IPSFactoryBuffer_CreateStub(factory_buffer, &IID_IDispatch,
1891 pUnkServer, &stub->dispatch_stub);
1892 IPSFactoryBuffer_Release(factory_buffer);
1895 ITypeInfo_ReleaseTypeAttr(tinfo, typeattr);
1901 static const IPSFactoryBufferVtbl psfacbufvtbl = {
1902 PSFacBuf_QueryInterface,
1905 PSFacBuf_CreateProxy,
1909 /* This is the whole PSFactoryBuffer object, just the vtableptr */
1910 static const IPSFactoryBufferVtbl *lppsfac = &psfacbufvtbl;
1912 /***********************************************************************
1913 * TMARSHAL_DllGetClassObject
1915 HRESULT TMARSHAL_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
1917 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)) {
1921 return E_NOINTERFACE;