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) {
312 hres = ITypeInfo_GetFuncDesc(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 sizeof(double)/sizeof(DWORD);
451 return sizeof(CY)/sizeof(DWORD);
453 return sizeof(DATE)/sizeof(DWORD);
455 return (sizeof(VARIANT)+3)/sizeof(DWORD);
462 _xsize(TYPEDESC *td) {
467 return sizeof(VARIANT)+3;
470 ARRAYDESC *adesc = td->u.lpadesc;
472 for (i=0;i<adesc->cDims;i++)
473 arrsize *= adesc->rgbounds[i].cElements;
474 return arrsize*_xsize(&adesc->tdescElem);
499 TRACE("(tdesc.vt %d)\n",tdesc->vt);
502 case VT_EMPTY: /* nothing. empty variant for instance */
511 if (debugout) TRACE_(olerelay)("%lx",*arg);
513 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
518 if (debugout) TRACE_(olerelay)("%04lx",*arg & 0xffff);
520 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
525 if (debugout) TRACE_(olerelay)("%02lx",*arg & 0xff);
527 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
531 if (debugout) TRACE_(olerelay)("&0x%lx",*arg);
533 hres = xbuf_add(buf,(LPBYTE)(DWORD*)*arg,sizeof(DWORD));
534 /* do not dealloc at this time */
538 VARIANT *vt = (VARIANT*)arg;
539 DWORD vttype = V_VT(vt);
541 if (debugout) TRACE_(olerelay)("Vt(%ld)(",vttype);
544 hres = xbuf_add(buf,(LPBYTE)&vttype,sizeof(vttype));
545 if (hres) return hres;
547 /* need to recurse since we need to free the stuff */
548 hres = serialize_param(tinfo,writeit,debugout,dealloc,&tdesc2,(DWORD*)&(V_I4(vt)),buf);
549 if (debugout) TRACE_(olerelay)(")");
552 case VT_BSTR|VT_BYREF: {
553 if (debugout) TRACE_(olerelay)("[byref]'%s'", *(BSTR*)*arg ? relaystr(*((BSTR*)*arg)) : "<bstr NULL>");
555 /* ptr to ptr to magic widestring, basically */
556 BSTR *bstr = (BSTR *) *arg;
559 /* -1 means "null string" which is equivalent to empty string */
561 hres = xbuf_add(buf, (LPBYTE)&len,sizeof(DWORD));
562 if (hres) return hres;
564 len = *((DWORD*)*bstr-1)/sizeof(WCHAR);
565 hres = xbuf_add(buf,(LPBYTE)&len,sizeof(DWORD));
566 if (hres) return hres;
567 hres = xbuf_add(buf,(LPBYTE)*bstr,len * sizeof(WCHAR));
568 if (hres) return hres;
572 if (dealloc && arg) {
573 BSTR *str = *((BSTR **)arg);
582 TRACE_(olerelay)("%s",relaystr((WCHAR*)*arg));
584 TRACE_(olerelay)("<bstr NULL>");
587 BSTR bstr = (BSTR)*arg;
591 hres = xbuf_add(buf,(LPBYTE)&len,sizeof(DWORD));
592 if (hres) return hres;
594 len = *((DWORD*)bstr-1)/sizeof(WCHAR);
595 hres = xbuf_add(buf,(LPBYTE)&len,sizeof(DWORD));
596 if (hres) return hres;
597 hres = xbuf_add(buf,(LPBYTE)bstr,len * sizeof(WCHAR));
598 if (hres) return hres;
603 SysFreeString((BSTR)*arg);
608 BOOL derefhere = TRUE;
610 if (tdesc->u.lptdesc->vt == VT_USERDEFINED) {
614 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.lptdesc->u.hreftype,&tinfo2);
616 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.lptdesc->u.hreftype);
619 ITypeInfo_GetTypeAttr(tinfo2,&tattr);
620 switch (tattr->typekind) {
621 case TKIND_ENUM: /* confirmed */
622 case TKIND_RECORD: /* FIXME: mostly untested */
625 case TKIND_ALIAS: /* FIXME: untested */
626 case TKIND_DISPATCH: /* will be done in VT_USERDEFINED case */
627 case TKIND_INTERFACE: /* will be done in VT_USERDEFINED case */
631 FIXME("unhandled switch cases tattr->typekind %d\n", tattr->typekind);
635 ITypeInfo_Release(tinfo2);
638 if (debugout) TRACE_(olerelay)("*");
639 /* Write always, so the other side knows when it gets a NULL pointer.
641 cookie = *arg ? 0x42424242 : 0;
642 hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
646 if (debugout) TRACE_(olerelay)("NULL");
649 hres = serialize_param(tinfo,writeit,debugout,dealloc,tdesc->u.lptdesc,(DWORD*)*arg,buf);
650 if (derefhere && dealloc) HeapFree(GetProcessHeap(),0,(LPVOID)*arg);
654 if (debugout) TRACE_(olerelay)("unk(0x%lx)",*arg);
656 hres = _marshal_interface(buf,&IID_IUnknown,(LPUNKNOWN)*arg);
659 if (debugout) TRACE_(olerelay)("idisp(0x%lx)",*arg);
661 hres = _marshal_interface(buf,&IID_IDispatch,(LPUNKNOWN)*arg);
664 if (debugout) TRACE_(olerelay)("<void>");
666 case VT_USERDEFINED: {
670 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
672 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
675 ITypeInfo_GetTypeAttr(tinfo2,&tattr);
676 switch (tattr->typekind) {
678 case TKIND_INTERFACE:
680 hres=_marshal_interface(buf,&(tattr->guid),(LPUNKNOWN)arg);
682 IUnknown_Release((LPUNKNOWN)arg);
686 if (debugout) TRACE_(olerelay)("{");
687 for (i=0;i<tattr->cVars;i++) {
692 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
694 ERR("Could not get vardesc of %d\n",i);
697 /* Need them for hack below */
699 memset(names,0,sizeof(names));
700 hres = ITypeInfo_GetNames(tinfo2,vdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
701 if (nrofnames > sizeof(names)/sizeof(names[0])) {
702 ERR("Need more names!\n");
704 if (!hres && debugout)
705 TRACE_(olerelay)("%s=",relaystr(names[0]));
707 elem2 = &vdesc->elemdescVar;
708 tdesc2 = &elem2->tdesc;
709 hres = serialize_param(
715 (DWORD*)(((LPBYTE)arg)+vdesc->u.oInst),
718 ITypeInfo_ReleaseVarDesc(tinfo2, vdesc);
721 if (debugout && (i<(tattr->cVars-1)))
722 TRACE_(olerelay)(",");
724 if (debugout) TRACE_(olerelay)("}");
728 return serialize_param(tinfo2,writeit,debugout,dealloc,&tattr->tdescAlias,arg,buf);
731 if (debugout) TRACE_(olerelay)("%lx",*arg);
733 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
736 FIXME("Unhandled typekind %d\n",tattr->typekind);
740 ITypeInfo_Release(tinfo2);
744 ARRAYDESC *adesc = tdesc->u.lpadesc;
747 if (debugout) TRACE_(olerelay)("carr");
748 for (i=0;i<adesc->cDims;i++) {
749 if (debugout) TRACE_(olerelay)("[%ld]",adesc->rgbounds[i].cElements);
750 arrsize *= adesc->rgbounds[i].cElements;
752 if (debugout) TRACE_(olerelay)("(vt %d)",adesc->tdescElem.vt);
753 if (debugout) TRACE_(olerelay)("[");
754 for (i=0;i<arrsize;i++) {
755 hres = serialize_param(tinfo, writeit, debugout, dealloc, &adesc->tdescElem, (DWORD*)((LPBYTE)arg+i*_xsize(&adesc->tdescElem)), buf);
758 if (debugout && (i<arrsize-1)) TRACE_(olerelay)(",");
760 if (debugout) TRACE_(olerelay)("]");
764 ERR("Unhandled marshal type %d.\n",tdesc->vt);
781 TRACE("vt %d at %p\n",tdesc->vt,arg);
786 if (debugout) TRACE_(olerelay)("<empty>");
789 if (debugout) TRACE_(olerelay)("<null>");
792 VARIANT *vt = (VARIANT*)arg;
797 hres = xbuf_get(buf,(LPBYTE)&vttype,sizeof(vttype));
799 FIXME("vt type not read?\n");
802 memset(&tdesc2,0,sizeof(tdesc2));
805 if (debugout) TRACE_(olerelay)("Vt(%ld)(",vttype);
806 hres = deserialize_param(tinfo, readit, debugout, alloc, &tdesc2, (DWORD*)&(V_I4(vt)), buf);
807 TRACE_(olerelay)(")");
821 hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
822 if (hres) ERR("Failed to read integer 4 byte\n");
824 if (debugout) TRACE_(olerelay)("%lx",*arg);
830 hres = xbuf_get(buf,(LPBYTE)&x,sizeof(DWORD));
831 if (hres) ERR("Failed to read integer 4 byte\n");
834 if (debugout) TRACE_(olerelay)("%04lx",*arg & 0xffff);
840 hres = xbuf_get(buf,(LPBYTE)&x,sizeof(DWORD));
841 if (hres) ERR("Failed to read integer 4 byte\n");
844 if (debugout) TRACE_(olerelay)("%02lx",*arg & 0xff);
849 *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
851 hres = xbuf_get(buf,(LPBYTE)*arg,sizeof(DWORD));
852 if (hres) ERR("Failed to read integer 4 byte\n");
854 if (debugout) TRACE_(olerelay)("&0x%lx",*(DWORD*)*arg);
856 case VT_BSTR|VT_BYREF: {
857 BSTR **bstr = (BSTR **)arg;
862 hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
864 ERR("failed to read bstr klen\n");
868 *bstr = CoTaskMemAlloc(sizeof(BSTR *));
870 if (debugout) TRACE_(olerelay)("<bstr NULL>");
872 str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
873 hres = xbuf_get(buf,(LPBYTE)str,len*sizeof(WCHAR));
875 ERR("Failed to read BSTR.\n");
878 *bstr = CoTaskMemAlloc(sizeof(BSTR *));
879 **bstr = SysAllocStringLen(str,len);
880 if (debugout) TRACE_(olerelay)("%s",relaystr(str));
881 HeapFree(GetProcessHeap(),0,str);
893 hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
895 ERR("failed to read bstr klen\n");
900 if (debugout) TRACE_(olerelay)("<bstr NULL>");
902 str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
903 hres = xbuf_get(buf,(LPBYTE)str,len*sizeof(WCHAR));
905 ERR("Failed to read BSTR.\n");
908 *arg = (DWORD)SysAllocStringLen(str,len);
909 if (debugout) TRACE_(olerelay)("%s",relaystr(str));
910 HeapFree(GetProcessHeap(),0,str);
919 BOOL derefhere = TRUE;
921 if (tdesc->u.lptdesc->vt == VT_USERDEFINED) {
925 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.lptdesc->u.hreftype,&tinfo2);
927 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.lptdesc->u.hreftype);
930 ITypeInfo_GetTypeAttr(tinfo2,&tattr);
931 switch (tattr->typekind) {
932 case TKIND_ENUM: /* confirmed */
933 case TKIND_RECORD: /* FIXME: mostly untested */
936 case TKIND_ALIAS: /* FIXME: untested */
937 case TKIND_DISPATCH: /* will be done in VT_USERDEFINED case */
938 case TKIND_INTERFACE: /* will be done in VT_USERDEFINED case */
942 FIXME("unhandled switch cases tattr->typekind %d\n", tattr->typekind);
946 ITypeInfo_Release(tinfo2);
948 /* read it in all cases, we need to know if we have
949 * NULL pointer or not.
951 hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
953 ERR("Failed to load pointer cookie.\n");
956 if (cookie != 0x42424242) {
957 /* we read a NULL ptr from the remote side */
958 if (debugout) TRACE_(olerelay)("NULL");
962 if (debugout) TRACE_(olerelay)("*");
964 /* Allocate space for the referenced struct */
966 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,_xsize(tdesc->u.lptdesc));
969 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, (LPDWORD)*arg, buf);
971 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, arg, buf);
974 /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
976 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
979 hres = _unmarshal_interface(buf,&IID_IUnknown,(LPUNKNOWN*)arg);
981 TRACE_(olerelay)("unk(%p)",arg);
986 hres = _unmarshal_interface(buf,&IID_IDispatch,(LPUNKNOWN*)arg);
988 TRACE_(olerelay)("idisp(%p)",arg);
991 if (debugout) TRACE_(olerelay)("<void>");
993 case VT_USERDEFINED: {
997 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
999 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
1002 hres = ITypeInfo_GetTypeAttr(tinfo2,&tattr);
1004 ERR("Could not get typeattr in VT_USERDEFINED.\n");
1006 switch (tattr->typekind) {
1007 case TKIND_DISPATCH:
1008 case TKIND_INTERFACE:
1010 hres = _unmarshal_interface(buf,&(tattr->guid),(LPUNKNOWN*)arg);
1012 case TKIND_RECORD: {
1016 *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,tattr->cbSizeInstance);
1018 if (debugout) TRACE_(olerelay)("{");
1019 for (i=0;i<tattr->cVars;i++) {
1022 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
1024 ERR("Could not get vardesc of %d\n",i);
1027 hres = deserialize_param(
1032 &vdesc->elemdescVar.tdesc,
1033 (DWORD*)(((LPBYTE)*arg)+vdesc->u.oInst),
1036 if (debugout && (i<tattr->cVars-1)) TRACE_(olerelay)(",");
1038 if (debugout) TRACE_(olerelay)("}");
1042 return deserialize_param(tinfo2,readit,debugout,alloc,&tattr->tdescAlias,arg,buf);
1045 hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
1046 if (hres) ERR("Failed to read enum (4 byte)\n");
1048 if (debugout) TRACE_(olerelay)("%lx",*arg);
1051 ERR("Unhandled typekind %d\n",tattr->typekind);
1057 ERR("failed to stuballoc in TKIND_RECORD.\n");
1058 ITypeInfo_Release(tinfo2);
1062 /* arg is pointing to the start of the array. */
1063 ARRAYDESC *adesc = tdesc->u.lpadesc;
1066 if (adesc->cDims > 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
1067 for (i=0;i<adesc->cDims;i++)
1068 arrsize *= adesc->rgbounds[i].cElements;
1069 for (i=0;i<arrsize;i++)
1076 (DWORD*)((LPBYTE)(arg)+i*_xsize(&adesc->tdescElem)),
1082 ERR("No handler for VT type %d!\n",tdesc->vt);
1088 /* Searches function, also in inherited interfaces */
1091 ITypeInfo *tinfo, int iMethod, ITypeInfo **tactual, FUNCDESC **fdesc, BSTR *iname, BSTR *fname)
1096 if (fname) *fname = NULL;
1097 if (iname) *iname = NULL;
1100 ITypeInfo_AddRef(*tactual);
1103 hres = ITypeInfo_GetFuncDesc(tinfo, i, fdesc);
1109 hres = ITypeInfo_GetTypeAttr(tinfo, &attr);
1111 ERR("GetTypeAttr failed with %lx\n",hres);
1114 /* Not found, so look in inherited ifaces. */
1115 for (j=0;j<attr->cImplTypes;j++) {
1116 hres = ITypeInfo_GetRefTypeOfImplType(tinfo, j, &href);
1118 ERR("Did not find a reftype for interface offset %d?\n",j);
1121 hres = ITypeInfo_GetRefTypeInfo(tinfo, href, &tinfo2);
1123 ERR("Did not find a typeinfo for reftype %ld?\n",href);
1126 hres = _get_funcdesc(tinfo2,iMethod,tactual,fdesc,iname,fname);
1127 ITypeInfo_Release(tinfo2);
1128 if (!hres) return S_OK;
1132 if (((*fdesc)->oVft/4) == iMethod) {
1134 ITypeInfo_GetDocumentation(tinfo,(*fdesc)->memid,fname,NULL,NULL,NULL);
1136 ITypeInfo_GetDocumentation(tinfo,-1,iname,NULL,NULL,NULL);
1144 xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */)
1146 DWORD *args = ((DWORD*)&tpinfo)+1, *xargs;
1149 int i, relaydeb = TRACE_ON(olerelay);
1156 DWORD remoteresult = 0;
1159 EnterCriticalSection(&tpinfo->crit);
1161 hres = _get_funcdesc(tpinfo->tinfo,method,&tinfo,&fdesc,&iname,&fname);
1163 ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method);
1164 ITypeInfo_Release(tinfo);
1165 LeaveCriticalSection(&tpinfo->crit);
1169 if (!tpinfo->chanbuf)
1171 WARN("Tried to use disconnected proxy\n");
1172 ITypeInfo_Release(tinfo);
1173 LeaveCriticalSection(&tpinfo->crit);
1174 return RPC_E_DISCONNECTED;
1178 TRACE_(olerelay)("->");
1180 TRACE_(olerelay)("%s:",relaystr(iname));
1182 TRACE_(olerelay)("%s(%d)",relaystr(fname),method);
1184 TRACE_(olerelay)("%d",method);
1185 TRACE_(olerelay)("(");
1188 if (iname) SysFreeString(iname);
1189 if (fname) SysFreeString(fname);
1191 memset(&buf,0,sizeof(buf));
1193 /* normal typelib driven serializing */
1195 /* Need them for hack below */
1196 memset(names,0,sizeof(names));
1197 if (ITypeInfo_GetNames(tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames))
1199 if (nrofnames > sizeof(names)/sizeof(names[0]))
1200 ERR("Need more names!\n");
1203 for (i=0;i<fdesc->cParams;i++) {
1204 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1206 if (i) TRACE_(olerelay)(",");
1207 if (i+1<nrofnames && names[i+1])
1208 TRACE_(olerelay)("%s=",relaystr(names[i+1]));
1210 /* No need to marshal other data than FIN and any VT_PTR. */
1211 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN || !elem->u.paramdesc.wParamFlags) && (elem->tdesc.vt != VT_PTR)) {
1212 xargs+=_argsize(elem->tdesc.vt);
1213 if (relaydeb) TRACE_(olerelay)("[out]");
1216 hres = serialize_param(
1218 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN || !elem->u.paramdesc.wParamFlags,
1227 ERR("Failed to serialize param, hres %lx\n",hres);
1230 xargs+=_argsize(elem->tdesc.vt);
1232 if (relaydeb) TRACE_(olerelay)(")");
1234 memset(&msg,0,sizeof(msg));
1235 msg.cbBuffer = buf.curoff;
1236 msg.iMethod = method;
1237 hres = IRpcChannelBuffer_GetBuffer(tpinfo->chanbuf,&msg,&(tpinfo->iid));
1239 ERR("RpcChannelBuffer GetBuffer failed, %lx\n",hres);
1240 LeaveCriticalSection(&tpinfo->crit);
1243 memcpy(msg.Buffer,buf.base,buf.curoff);
1244 if (relaydeb) TRACE_(olerelay)("\n");
1245 hres = IRpcChannelBuffer_SendReceive(tpinfo->chanbuf,&msg,&status);
1247 ERR("RpcChannelBuffer SendReceive failed, %lx\n",hres);
1248 LeaveCriticalSection(&tpinfo->crit);
1252 if (relaydeb) TRACE_(olerelay)(" status = %08lx (",status);
1254 buf.base = HeapReAlloc(GetProcessHeap(),0,buf.base,msg.cbBuffer);
1256 buf.base = HeapAlloc(GetProcessHeap(),0,msg.cbBuffer);
1257 buf.size = msg.cbBuffer;
1258 memcpy(buf.base,msg.Buffer,buf.size);
1261 /* generic deserializer using typelib description */
1264 for (i=0;i<fdesc->cParams;i++) {
1265 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1268 if (i) TRACE_(olerelay)(",");
1269 if (i+1<nrofnames && names[i+1]) TRACE_(olerelay)("%s=",relaystr(names[i+1]));
1271 /* No need to marshal other data than FOUT and any VT_PTR */
1272 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT) && (elem->tdesc.vt != VT_PTR)) {
1273 xargs += _argsize(elem->tdesc.vt);
1274 if (relaydeb) TRACE_(olerelay)("[in]");
1277 hres = deserialize_param(
1279 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1287 ERR("Failed to unmarshall param, hres %lx\n",hres);
1291 xargs += _argsize(elem->tdesc.vt);
1294 hres = xbuf_get(&buf, (LPBYTE)&remoteresult, sizeof(DWORD));
1297 if (relaydeb) TRACE_(olerelay)(") = %08lx\n", remoteresult);
1299 if (status != S_OK) /* OLE/COM internal error */
1302 HeapFree(GetProcessHeap(),0,buf.base);
1303 ITypeInfo_Release(tinfo);
1304 LeaveCriticalSection(&tpinfo->crit);
1305 return remoteresult;
1308 HRESULT WINAPI ProxyIUnknown_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
1310 TMProxyImpl *proxy = (TMProxyImpl *)iface;
1312 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
1314 if (proxy->outerunknown)
1315 return IUnknown_QueryInterface(proxy->outerunknown, riid, ppv);
1317 FIXME("No interface\n");
1318 return E_NOINTERFACE;
1321 ULONG WINAPI ProxyIUnknown_AddRef(IUnknown *iface)
1323 TMProxyImpl *proxy = (TMProxyImpl *)iface;
1327 if (proxy->outerunknown)
1328 return IUnknown_AddRef(proxy->outerunknown);
1330 return 2; /* FIXME */
1333 ULONG WINAPI ProxyIUnknown_Release(IUnknown *iface)
1335 TMProxyImpl *proxy = (TMProxyImpl *)iface;
1339 if (proxy->outerunknown)
1340 return IUnknown_Release(proxy->outerunknown);
1342 return 1; /* FIXME */
1345 static HRESULT WINAPI ProxyIDispatch_GetTypeInfoCount(LPDISPATCH iface, UINT * pctinfo)
1347 TMProxyImpl *This = (TMProxyImpl *)iface;
1350 TRACE("(%p)\n", pctinfo);
1352 if (!This->dispatch)
1354 hr = IUnknown_QueryInterface(This->outerunknown, &IID_IDispatch,
1355 (LPVOID *)&This->dispatch);
1358 hr = IDispatch_GetTypeInfoCount(This->dispatch, pctinfo);
1363 static HRESULT WINAPI ProxyIDispatch_GetTypeInfo(LPDISPATCH iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)
1365 TMProxyImpl *This = (TMProxyImpl *)iface;
1368 TRACE("(%d, %lx, %p)\n", iTInfo, lcid, ppTInfo);
1370 if (!This->dispatch)
1372 hr = IUnknown_QueryInterface(This->outerunknown, &IID_IDispatch,
1373 (LPVOID *)&This->dispatch);
1376 hr = IDispatch_GetTypeInfo(This->dispatch, iTInfo, lcid, ppTInfo);
1381 static HRESULT WINAPI ProxyIDispatch_GetIDsOfNames(LPDISPATCH iface, REFIID riid, LPOLESTR * rgszNames, UINT cNames, LCID lcid, DISPID * rgDispId)
1383 TMProxyImpl *This = (TMProxyImpl *)iface;
1386 TRACE("(%s, %p, %d, 0x%lx, %p)\n", debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
1388 if (!This->dispatch)
1390 hr = IUnknown_QueryInterface(This->outerunknown, &IID_IDispatch,
1391 (LPVOID *)&This->dispatch);
1394 hr = IDispatch_GetIDsOfNames(This->dispatch, riid, rgszNames,
1395 cNames, lcid, rgDispId);
1400 static HRESULT WINAPI ProxyIDispatch_Invoke(LPDISPATCH iface, DISPID dispIdMember, REFIID riid, LCID lcid,
1401 WORD wFlags, DISPPARAMS * pDispParams, VARIANT * pVarResult,
1402 EXCEPINFO * pExcepInfo, UINT * puArgErr)
1404 TMProxyImpl *This = (TMProxyImpl *)iface;
1407 TRACE("(%ld, %s, 0x%lx, 0x%x, %p, %p, %p, %p)\n", dispIdMember, debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1409 if (!This->dispatch)
1411 hr = IUnknown_QueryInterface(This->outerunknown, &IID_IDispatch,
1412 (LPVOID *)&This->dispatch);
1415 hr = IDispatch_Invoke(This->dispatch, dispIdMember, riid, lcid,
1416 wFlags, pDispParams, pVarResult, pExcepInfo,
1422 static HRESULT WINAPI
1423 PSFacBuf_CreateProxy(
1424 LPPSFACTORYBUFFER iface, IUnknown* pUnkOuter, REFIID riid,
1425 IRpcProxyBuffer **ppProxy, LPVOID *ppv)
1434 TRACE("(...%s...)\n",debugstr_guid(riid));
1435 hres = _get_typeinfo_for_iid(riid,&tinfo);
1437 ERR("No typeinfo for %s?\n",debugstr_guid(riid));
1440 nroffuncs = _nroffuncs(tinfo);
1441 proxy = CoTaskMemAlloc(sizeof(TMProxyImpl));
1442 if (!proxy) return E_OUTOFMEMORY;
1444 assert(sizeof(TMAsmProxy) == 12);
1446 proxy->dispatch = NULL;
1447 proxy->outerunknown = pUnkOuter;
1448 proxy->asmstubs = VirtualAlloc(NULL, sizeof(TMAsmProxy) * nroffuncs, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
1449 if (!proxy->asmstubs) {
1450 ERR("Could not commit pages for proxy thunks\n");
1451 CoTaskMemFree(proxy);
1452 return E_OUTOFMEMORY;
1455 InitializeCriticalSection(&proxy->crit);
1457 proxy->lpvtbl = HeapAlloc(GetProcessHeap(),0,sizeof(LPBYTE)*nroffuncs);
1458 for (i=0;i<nroffuncs;i++) {
1459 TMAsmProxy *xasm = proxy->asmstubs+i;
1463 proxy->lpvtbl[i] = ProxyIUnknown_QueryInterface;
1466 proxy->lpvtbl[i] = ProxyIUnknown_AddRef;
1469 proxy->lpvtbl[i] = ProxyIUnknown_Release;
1473 /* nrofargs without This */
1476 hres = _get_funcdesc(tinfo,i,&tinfo2,&fdesc,NULL,NULL);
1477 ITypeInfo_Release(tinfo2);
1479 ERR("GetFuncDesc %lx should not fail here.\n",hres);
1482 /* some args take more than 4 byte on the stack */
1484 for (j=0;j<fdesc->cParams;j++)
1485 nrofargs += _argsize(fdesc->lprgelemdescParam[j].tdesc.vt);
1488 if (fdesc->callconv != CC_STDCALL) {
1489 ERR("calling convention is not stdcall????\n");
1492 /* popl %eax - return ptr
1499 * arg3 arg2 arg1 <method> <returnptr>
1501 xasm->popleax = 0x58;
1502 xasm->pushlval = 0x6a;
1504 xasm->pushleax = 0x50;
1505 xasm->lcall = 0xe8; /* relative jump */
1506 xasm->xcall = (DWORD)xCall;
1507 xasm->xcall -= (DWORD)&(xasm->lret);
1509 xasm->bytestopop= (nrofargs+2)*4; /* pop args, This, iMethod */
1510 proxy->lpvtbl[i] = xasm;
1513 FIXME("not implemented on non i386\n");
1520 /* if we derive from IDispatch then defer to its proxy for its methods */
1521 hres = ITypeInfo_GetTypeAttr(tinfo, &typeattr);
1524 if (typeattr->wTypeFlags & TYPEFLAG_FDISPATCHABLE)
1526 proxy->lpvtbl[3] = ProxyIDispatch_GetTypeInfoCount;
1527 proxy->lpvtbl[4] = ProxyIDispatch_GetTypeInfo;
1528 proxy->lpvtbl[5] = ProxyIDispatch_GetIDsOfNames;
1529 proxy->lpvtbl[6] = ProxyIDispatch_Invoke;
1531 ITypeInfo_ReleaseTypeAttr(tinfo, typeattr);
1534 proxy->lpvtbl2 = &tmproxyvtable;
1535 /* one reference for the proxy */
1537 proxy->tinfo = tinfo;
1538 memcpy(&proxy->iid,riid,sizeof(*riid));
1540 *ppv = (LPVOID)proxy;
1541 *ppProxy = (IRpcProxyBuffer *)&(proxy->lpvtbl2);
1542 IUnknown_AddRef((IUnknown *)*ppv);
1546 typedef struct _TMStubImpl {
1547 const IRpcStubBufferVtbl *lpvtbl;
1555 static HRESULT WINAPI
1556 TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface, REFIID riid, LPVOID *ppv)
1558 if (IsEqualIID(riid,&IID_IRpcStubBuffer)||IsEqualIID(riid,&IID_IUnknown)){
1559 *ppv = (LPVOID)iface;
1560 IRpcStubBuffer_AddRef(iface);
1563 FIXME("%s, not supported IID.\n",debugstr_guid(riid));
1564 return E_NOINTERFACE;
1568 TMStubImpl_AddRef(LPRPCSTUBBUFFER iface)
1570 TMStubImpl *This = (TMStubImpl *)iface;
1571 ULONG refCount = InterlockedIncrement(&This->ref);
1573 TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
1579 TMStubImpl_Release(LPRPCSTUBBUFFER iface)
1581 TMStubImpl *This = (TMStubImpl *)iface;
1582 ULONG refCount = InterlockedDecrement(&This->ref);
1584 TRACE("(%p)->(ref before=%lu)\n", This, refCount + 1);
1588 IRpcStubBuffer_Disconnect(iface);
1589 ITypeInfo_Release(This->tinfo);
1590 CoTaskMemFree(This);
1595 static HRESULT WINAPI
1596 TMStubImpl_Connect(LPRPCSTUBBUFFER iface, LPUNKNOWN pUnkServer)
1598 TMStubImpl *This = (TMStubImpl *)iface;
1600 TRACE("(%p)->(%p)\n", This, pUnkServer);
1602 IUnknown_AddRef(pUnkServer);
1603 This->pUnk = pUnkServer;
1608 TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface)
1610 TMStubImpl *This = (TMStubImpl *)iface;
1612 TRACE("(%p)->()\n", This);
1616 IUnknown_Release(This->pUnk);
1621 static HRESULT WINAPI
1623 LPRPCSTUBBUFFER iface, RPCOLEMESSAGE* xmsg,IRpcChannelBuffer*rpcchanbuf)
1627 TMStubImpl *This = (TMStubImpl *)iface;
1629 DWORD *args, res, *xargs, nrofargs;
1636 memset(&buf,0,sizeof(buf));
1637 buf.size = xmsg->cbBuffer;
1638 buf.base = HeapAlloc(GetProcessHeap(), 0, xmsg->cbBuffer);
1639 memcpy(buf.base, xmsg->Buffer, xmsg->cbBuffer);
1644 if (xmsg->iMethod < 3) {
1645 ERR("IUnknown methods cannot be marshaled by the typelib marshaler\n");
1646 return E_UNEXPECTED;
1649 hres = _get_funcdesc(This->tinfo,xmsg->iMethod,&tinfo,&fdesc,&iname,NULL);
1651 ERR("GetFuncDesc on method %ld failed with %lx\n",xmsg->iMethod,hres);
1655 if (iname && !lstrcmpW(iname, IDispatchW))
1657 ERR("IDispatch cannot be marshaled by the typelib marshaler\n");
1658 ITypeInfo_Release(tinfo);
1659 return E_UNEXPECTED;
1662 if (iname) SysFreeString (iname);
1664 /* Need them for hack below */
1665 memset(names,0,sizeof(names));
1666 ITypeInfo_GetNames(tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
1667 if (nrofnames > sizeof(names)/sizeof(names[0])) {
1668 ERR("Need more names!\n");
1671 /*dump_FUNCDESC(fdesc);*/
1673 for (i=0;i<fdesc->cParams;i++)
1674 nrofargs += _argsize(fdesc->lprgelemdescParam[i].tdesc.vt);
1675 args = HeapAlloc(GetProcessHeap(),0,(nrofargs+1)*sizeof(DWORD));
1676 if (!args) return E_OUTOFMEMORY;
1678 /* Allocate all stuff used by call. */
1680 for (i=0;i<fdesc->cParams;i++) {
1681 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1683 hres = deserialize_param(
1685 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN || !elem->u.paramdesc.wParamFlags,
1692 xargs += _argsize(elem->tdesc.vt);
1694 ERR("Failed to deserialize param %s, hres %lx\n",relaystr(names[i+1]),hres);
1699 hres = IUnknown_QueryInterface(This->pUnk,&(This->iid),(LPVOID*)&(args[0]));
1701 ERR("Does not support iface %s, returning %lx\n",debugstr_guid(&(This->iid)), hres);
1705 (*((FARPROC**)args[0]))[fdesc->oVft/4],
1710 IUnknown_Release((LPUNKNOWN)args[0]);
1714 for (i=0;i<fdesc->cParams;i++) {
1715 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1716 hres = serialize_param(
1718 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1725 xargs += _argsize(elem->tdesc.vt);
1727 ERR("Failed to stuballoc param, hres %lx\n",hres);
1732 hres = xbuf_add (&buf, (LPBYTE)&res, sizeof(DWORD));
1736 ITypeInfo_Release(tinfo);
1737 HeapFree(GetProcessHeap(), 0, args);
1739 xmsg->cbBuffer = buf.curoff;
1742 hres = IRpcChannelBuffer_GetBuffer(rpcchanbuf, xmsg, &This->iid);
1744 ERR("IRpcChannelBuffer_GetBuffer failed with error 0x%08lx\n", hres);
1748 /* FIXME: remove this case when we start sending an IRpcChannelBuffer
1749 * object with builtin OLE */
1750 RPC_STATUS status = I_RpcGetBuffer((RPC_MESSAGE *)xmsg);
1751 if (status != RPC_S_OK)
1753 ERR("I_RpcGetBuffer failed with error %ld\n", status);
1759 memcpy(xmsg->Buffer, buf.base, buf.curoff);
1761 HeapFree(GetProcessHeap(), 0, buf.base);
1763 TRACE("returning\n");
1767 static LPRPCSTUBBUFFER WINAPI
1768 TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface, REFIID riid) {
1769 FIXME("Huh (%s)?\n",debugstr_guid(riid));
1774 TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface) {
1775 TMStubImpl *This = (TMStubImpl *)iface;
1778 return This->ref; /*FIXME? */
1781 static HRESULT WINAPI
1782 TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface, LPVOID *ppv) {
1787 TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface, LPVOID ppv) {
1791 static const IRpcStubBufferVtbl tmstubvtbl = {
1792 TMStubImpl_QueryInterface,
1796 TMStubImpl_Disconnect,
1798 TMStubImpl_IsIIDSupported,
1799 TMStubImpl_CountRefs,
1800 TMStubImpl_DebugServerQueryInterface,
1801 TMStubImpl_DebugServerRelease
1804 static HRESULT WINAPI
1805 PSFacBuf_CreateStub(
1806 LPPSFACTORYBUFFER iface, REFIID riid,IUnknown *pUnkServer,
1807 IRpcStubBuffer** ppStub
1813 TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub);
1814 hres = _get_typeinfo_for_iid(riid,&tinfo);
1816 ERR("No typeinfo for %s?\n",debugstr_guid(riid));
1819 stub = CoTaskMemAlloc(sizeof(TMStubImpl));
1821 return E_OUTOFMEMORY;
1822 stub->lpvtbl = &tmstubvtbl;
1824 stub->tinfo = tinfo;
1825 memcpy(&(stub->iid),riid,sizeof(*riid));
1826 hres = IRpcStubBuffer_Connect((LPRPCSTUBBUFFER)stub,pUnkServer);
1827 *ppStub = (LPRPCSTUBBUFFER)stub;
1828 TRACE("IRpcStubBuffer: %p\n", stub);
1830 ERR("Connect to pUnkServer failed?\n");
1834 static const IPSFactoryBufferVtbl psfacbufvtbl = {
1835 PSFacBuf_QueryInterface,
1838 PSFacBuf_CreateProxy,
1842 /* This is the whole PSFactoryBuffer object, just the vtableptr */
1843 static const IPSFactoryBufferVtbl *lppsfac = &psfacbufvtbl;
1845 /***********************************************************************
1846 * TMARSHAL_DllGetClassObject
1848 HRESULT TMARSHAL_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
1850 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)) {
1854 return E_NOINTERFACE;