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 riidW[5] = {'r','i','i','d',0};
49 static const WCHAR pdispparamsW[] = {'p','d','i','s','p','p','a','r','a','m','s',0};
50 static const WCHAR ppvObjectW[] = {'p','p','v','O','b','j','e','c','t',0};
51 static const WCHAR IDispatchW[] = { 'I','D','i','s','p','a','t','c','h',0};
52 static const WCHAR GetIDsOfNamesW[] = { 'G','e','t','I','D','s','O','f','N','a','m','e','s',0};
54 WINE_DEFAULT_DEBUG_CHANNEL(ole);
55 WINE_DECLARE_DEBUG_CHANNEL(olerelay);
57 #define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
59 typedef struct _marshal_state {
65 IID iid; /* HACK: for VT_VOID */
68 /* used in the olerelay code to avoid having the L"" stuff added by debugstr_w */
69 static char *relaystr(WCHAR *in) {
70 char *tmp = (char *)debugstr_w(in);
72 tmp[strlen(tmp)-1] = '\0';
77 xbuf_add(marshal_state *buf, LPBYTE stuff, DWORD size) {
78 while (buf->size - buf->curoff < size) {
81 buf->base = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,buf->base,buf->size);
85 buf->base = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,32);
91 memcpy(buf->base+buf->curoff,stuff,size);
97 xbuf_get(marshal_state *buf, LPBYTE stuff, DWORD size) {
98 if (buf->size < buf->curoff+size) return E_FAIL;
99 memcpy(stuff,buf->base+buf->curoff,size);
105 xbuf_skip(marshal_state *buf, DWORD size) {
106 if (buf->size < buf->curoff+size) return E_FAIL;
112 _unmarshal_interface(marshal_state *buf, REFIID riid, LPUNKNOWN *pUnk) {
114 ULARGE_INTEGER newpos;
115 LARGE_INTEGER seekto;
120 TRACE("...%s...\n",debugstr_guid(riid));
123 hres = xbuf_get(buf,(LPBYTE)&xsize,sizeof(xsize));
125 ERR("xbuf_get failed\n");
129 if (xsize == 0) return S_OK;
131 hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
133 ERR("Stream create failed %lx\n",hres);
137 hres = IStream_Write(pStm,buf->base+buf->curoff,xsize,&res);
139 ERR("stream write %lx\n",hres);
143 memset(&seekto,0,sizeof(seekto));
144 hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
146 ERR("Failed Seek %lx\n",hres);
150 hres = CoUnmarshalInterface(pStm,riid,(LPVOID*)pUnk);
152 ERR("Unmarshalling interface %s failed with %lx\n",debugstr_guid(riid),hres);
156 IStream_Release(pStm);
157 return xbuf_skip(buf,xsize);
161 _marshal_interface(marshal_state *buf, REFIID riid, LPUNKNOWN pUnk) {
162 LPBYTE tempbuf = NULL;
163 IStream *pStm = NULL;
165 ULARGE_INTEGER newpos;
166 LARGE_INTEGER seekto;
172 /* this is valid, if for instance we serialize
173 * a VT_DISPATCH with NULL ptr which apparently
174 * can happen. S_OK to make sure we continue
177 ERR("pUnk is NULL?\n");
179 return xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
184 TRACE("...%s...\n",debugstr_guid(riid));
186 hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
188 ERR("Stream create failed %lx\n",hres);
192 hres = CoMarshalInterface(pStm,riid,pUnk,0,NULL,0);
194 ERR("Marshalling interface %s failed with %lx\n", debugstr_guid(riid), hres);
198 hres = IStream_Stat(pStm,&ststg,0);
200 ERR("Stream stat failed\n");
204 tempbuf = HeapAlloc(GetProcessHeap(), 0, ststg.cbSize.u.LowPart);
205 memset(&seekto,0,sizeof(seekto));
206 hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
208 ERR("Failed Seek %lx\n",hres);
212 hres = IStream_Read(pStm,tempbuf,ststg.cbSize.u.LowPart,&res);
214 ERR("Failed Read %lx\n",hres);
218 xsize = ststg.cbSize.u.LowPart;
219 xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
220 hres = xbuf_add(buf,tempbuf,ststg.cbSize.u.LowPart);
222 HeapFree(GetProcessHeap(),0,tempbuf);
223 IStream_Release(pStm);
229 xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
230 if (pStm) IUnknown_Release(pStm);
231 HeapFree(GetProcessHeap(), 0, tempbuf);
235 /********************* OLE Proxy/Stub Factory ********************************/
236 static HRESULT WINAPI
237 PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface, REFIID iid, LPVOID *ppv) {
238 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)||IsEqualIID(iid,&IID_IUnknown)) {
239 *ppv = (LPVOID)iface;
240 /* No ref counting, static class */
243 FIXME("(%s) unknown IID?\n",debugstr_guid(iid));
244 return E_NOINTERFACE;
247 static ULONG WINAPI PSFacBuf_AddRef(LPPSFACTORYBUFFER iface) { return 2; }
248 static ULONG WINAPI PSFacBuf_Release(LPPSFACTORYBUFFER iface) { return 1; }
251 _get_typeinfo_for_iid(REFIID riid, ITypeInfo**ti) {
254 char tlguid[200],typelibkey[300],interfacekey[300],ver[100];
257 DWORD tlguidlen, verlen, type;
261 sprintf( interfacekey, "Interface\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\Typelib",
262 riid->Data1, riid->Data2, riid->Data3,
263 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
264 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7]
267 if (RegOpenKeyA(HKEY_CLASSES_ROOT,interfacekey,&ikey)) {
268 ERR("No %s key found.\n",interfacekey);
272 tlguidlen = sizeof(tlguid);
273 if (RegQueryValueExA(ikey,NULL,NULL,&type,(LPBYTE)tlguid,&tlguidlen)) {
274 ERR("Getting typelib guid failed.\n");
279 verlen = sizeof(ver);
280 if (RegQueryValueExA(ikey,"Version",NULL,&type,(LPBYTE)ver,&verlen)) {
281 ERR("Could not get version value?\n");
286 sprintf(typelibkey,"Typelib\\%s\\%s\\0\\win32",tlguid,ver);
287 tlfnlen = sizeof(tlfn);
288 if (RegQueryValueA(HKEY_CLASSES_ROOT,typelibkey,tlfn,&tlfnlen)) {
289 ERR("Could not get typelib fn?\n");
292 MultiByteToWideChar(CP_ACP, 0, tlfn, -1, tlfnW, -1);
293 hres = LoadTypeLib(tlfnW,&tl);
295 ERR("Failed to load typelib for %s, but it should be there.\n",debugstr_guid(riid));
298 hres = ITypeLib_GetTypeInfoOfGuid(tl,riid,ti);
300 ERR("typelib does not contain info for %s?\n",debugstr_guid(riid));
301 ITypeLib_Release(tl);
304 /* FIXME: do this? ITypeLib_Release(tl); */
308 /* Determine nr of functions. Since we use the toplevel interface and all
309 * inherited ones have lower numbers, we are ok to not to descent into
310 * the inheritance tree I think.
312 static int _nroffuncs(ITypeInfo *tinfo) {
319 hres = ITypeInfo_GetFuncDesc(tinfo,n,&fdesc);
322 if (fdesc->oVft/4 > max)
331 #include "pshpack1.h"
333 typedef struct _TMAsmProxy {
347 # error You need to implement stubless proxies for your architecture
350 typedef struct _TMProxyImpl {
352 const IRpcProxyBufferVtbl *lpvtbl2;
355 TMAsmProxy *asmstubs;
357 IRpcChannelBuffer* chanbuf;
359 CRITICAL_SECTION crit;
360 IUnknown *outerunknown;
363 static HRESULT WINAPI
364 TMProxyImpl_QueryInterface(LPRPCPROXYBUFFER iface, REFIID riid, LPVOID *ppv)
367 if (IsEqualIID(riid,&IID_IUnknown)||IsEqualIID(riid,&IID_IRpcProxyBuffer)) {
368 *ppv = (LPVOID)iface;
369 IRpcProxyBuffer_AddRef(iface);
372 FIXME("no interface for %s\n",debugstr_guid(riid));
373 return E_NOINTERFACE;
377 TMProxyImpl_AddRef(LPRPCPROXYBUFFER iface)
379 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
380 ULONG refCount = InterlockedIncrement(&This->ref);
382 TRACE("(%p)->(ref before=%lu)\n",This, refCount - 1);
388 TMProxyImpl_Release(LPRPCPROXYBUFFER iface)
390 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
391 ULONG refCount = InterlockedDecrement(&This->ref);
393 TRACE("(%p)->(ref before=%lu)\n",This, refCount + 1);
397 DeleteCriticalSection(&This->crit);
398 if (This->chanbuf) IRpcChannelBuffer_Release(This->chanbuf);
399 VirtualFree(This->asmstubs, 0, MEM_RELEASE);
405 static HRESULT WINAPI
407 LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer)
409 ICOM_THIS_MULTI(TMProxyImpl, lpvtbl2, iface);
411 TRACE("(%p)\n", pRpcChannelBuffer);
413 EnterCriticalSection(&This->crit);
415 IRpcChannelBuffer_AddRef(pRpcChannelBuffer);
416 This->chanbuf = pRpcChannelBuffer;
418 LeaveCriticalSection(&This->crit);
424 TMProxyImpl_Disconnect(LPRPCPROXYBUFFER iface)
426 ICOM_THIS_MULTI(TMProxyImpl, lpvtbl2, iface);
430 EnterCriticalSection(&This->crit);
432 IRpcChannelBuffer_Release(This->chanbuf);
433 This->chanbuf = NULL;
435 LeaveCriticalSection(&This->crit);
439 static const IRpcProxyBufferVtbl tmproxyvtable = {
440 TMProxyImpl_QueryInterface,
444 TMProxyImpl_Disconnect
447 /* how much space do we use on stack in DWORD steps. */
452 return sizeof(double)/sizeof(DWORD);
454 return sizeof(CY)/sizeof(DWORD);
456 return sizeof(DATE)/sizeof(DWORD);
458 return (sizeof(VARIANT)+3)/sizeof(DWORD);
465 _xsize(TYPEDESC *td) {
470 return sizeof(VARIANT)+3;
473 ARRAYDESC *adesc = td->u.lpadesc;
475 for (i=0;i<adesc->cDims;i++)
476 arrsize *= adesc->rgbounds[i].cElements;
477 return arrsize*_xsize(&adesc->tdescElem);
502 TRACE("(tdesc.vt %d)\n",tdesc->vt);
505 case VT_EMPTY: /* nothing. empty variant for instance */
514 if (debugout) TRACE_(olerelay)("%lx",*arg);
516 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
521 if (debugout) TRACE_(olerelay)("%04lx",*arg & 0xffff);
523 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
528 if (debugout) TRACE_(olerelay)("%02lx",*arg & 0xff);
530 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
534 if (debugout) TRACE_(olerelay)("&0x%lx",*arg);
536 hres = xbuf_add(buf,(LPBYTE)(DWORD*)*arg,sizeof(DWORD));
537 /* do not dealloc at this time */
541 VARIANT *vt = (VARIANT*)arg;
542 DWORD vttype = V_VT(vt);
544 if (debugout) TRACE_(olerelay)("Vt(%ld)(",vttype);
547 hres = xbuf_add(buf,(LPBYTE)&vttype,sizeof(vttype));
548 if (hres) return hres;
550 /* need to recurse since we need to free the stuff */
551 hres = serialize_param(tinfo,writeit,debugout,dealloc,&tdesc2,(DWORD*)&(V_I4(vt)),buf);
552 if (debugout) TRACE_(olerelay)(")");
555 case VT_BSTR|VT_BYREF: {
556 if (debugout) TRACE_(olerelay)("[byref]'%s'", *(BSTR*)*arg ? relaystr(*((BSTR*)*arg)) : "<bstr NULL>");
558 /* ptr to ptr to magic widestring, basically */
559 BSTR *bstr = (BSTR *) *arg;
562 /* -1 means "null string" which is equivalent to empty string */
564 hres = xbuf_add(buf, (LPBYTE)&len,sizeof(DWORD));
565 if (hres) return hres;
567 len = *((DWORD*)*bstr-1)/sizeof(WCHAR);
568 hres = xbuf_add(buf,(LPBYTE)&len,sizeof(DWORD));
569 if (hres) return hres;
570 hres = xbuf_add(buf,(LPBYTE)*bstr,len * sizeof(WCHAR));
571 if (hres) return hres;
575 if (dealloc && arg) {
576 BSTR *str = *((BSTR **)arg);
585 TRACE_(olerelay)("%s",relaystr((WCHAR*)*arg));
587 TRACE_(olerelay)("<bstr NULL>");
590 BSTR bstr = (BSTR)*arg;
594 hres = xbuf_add(buf,(LPBYTE)&len,sizeof(DWORD));
595 if (hres) return hres;
597 len = *((DWORD*)bstr-1)/sizeof(WCHAR);
598 hres = xbuf_add(buf,(LPBYTE)&len,sizeof(DWORD));
599 if (hres) return hres;
600 hres = xbuf_add(buf,(LPBYTE)bstr,len * sizeof(WCHAR));
601 if (hres) return hres;
606 SysFreeString((BSTR)*arg);
611 BOOL derefhere = TRUE;
613 if (tdesc->u.lptdesc->vt == VT_USERDEFINED) {
617 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.lptdesc->u.hreftype,&tinfo2);
619 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.lptdesc->u.hreftype);
622 ITypeInfo_GetTypeAttr(tinfo2,&tattr);
623 switch (tattr->typekind) {
624 case TKIND_ENUM: /* confirmed */
625 case TKIND_RECORD: /* FIXME: mostly untested */
628 case TKIND_ALIAS: /* FIXME: untested */
629 case TKIND_DISPATCH: /* will be done in VT_USERDEFINED case */
630 case TKIND_INTERFACE: /* will be done in VT_USERDEFINED case */
634 FIXME("unhandled switch cases tattr->typekind %d\n", tattr->typekind);
638 ITypeInfo_Release(tinfo2);
641 if (debugout) TRACE_(olerelay)("*");
642 /* Write always, so the other side knows when it gets a NULL pointer.
644 cookie = *arg ? 0x42424242 : 0;
645 hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
649 if (debugout) TRACE_(olerelay)("NULL");
652 hres = serialize_param(tinfo,writeit,debugout,dealloc,tdesc->u.lptdesc,(DWORD*)*arg,buf);
653 if (derefhere && dealloc) HeapFree(GetProcessHeap(),0,(LPVOID)*arg);
657 if (debugout) TRACE_(olerelay)("unk(0x%lx)",*arg);
659 hres = _marshal_interface(buf,&IID_IUnknown,(LPUNKNOWN)*arg);
662 if (debugout) TRACE_(olerelay)("idisp(0x%lx)",*arg);
664 hres = _marshal_interface(buf,&IID_IDispatch,(LPUNKNOWN)*arg);
667 if (debugout) TRACE_(olerelay)("<void>");
669 case VT_USERDEFINED: {
673 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
675 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
678 ITypeInfo_GetTypeAttr(tinfo2,&tattr);
679 switch (tattr->typekind) {
681 case TKIND_INTERFACE:
683 hres=_marshal_interface(buf,&(tattr->guid),(LPUNKNOWN)arg);
685 IUnknown_Release((LPUNKNOWN)arg);
689 if (debugout) TRACE_(olerelay)("{");
690 for (i=0;i<tattr->cVars;i++) {
695 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
697 ERR("Could not get vardesc of %d\n",i);
700 /* Need them for hack below */
702 memset(names,0,sizeof(names));
703 hres = ITypeInfo_GetNames(tinfo2,vdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
704 if (nrofnames > sizeof(names)/sizeof(names[0])) {
705 ERR("Need more names!\n");
707 if (!hres && debugout)
708 TRACE_(olerelay)("%s=",relaystr(names[0]));
710 elem2 = &vdesc->elemdescVar;
711 tdesc2 = &elem2->tdesc;
712 hres = serialize_param(
718 (DWORD*)(((LPBYTE)arg)+vdesc->u.oInst),
721 ITypeInfo_ReleaseVarDesc(tinfo2, vdesc);
724 if (debugout && (i<(tattr->cVars-1)))
725 TRACE_(olerelay)(",");
727 if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
728 memcpy(&(buf->iid),arg,sizeof(buf->iid));
729 if (debugout) TRACE_(olerelay)("}");
733 return serialize_param(tinfo2,writeit,debugout,dealloc,&tattr->tdescAlias,arg,buf);
736 if (debugout) TRACE_(olerelay)("%lx",*arg);
738 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
741 FIXME("Unhandled typekind %d\n",tattr->typekind);
745 ITypeInfo_Release(tinfo2);
749 ARRAYDESC *adesc = tdesc->u.lpadesc;
752 if (debugout) TRACE_(olerelay)("carr");
753 for (i=0;i<adesc->cDims;i++) {
754 if (debugout) TRACE_(olerelay)("[%ld]",adesc->rgbounds[i].cElements);
755 arrsize *= adesc->rgbounds[i].cElements;
757 if (debugout) TRACE_(olerelay)("(vt %d)",adesc->tdescElem.vt);
758 if (debugout) TRACE_(olerelay)("[");
759 for (i=0;i<arrsize;i++) {
760 hres = serialize_param(tinfo, writeit, debugout, dealloc, &adesc->tdescElem, (DWORD*)((LPBYTE)arg+i*_xsize(&adesc->tdescElem)), buf);
763 if (debugout && (i<arrsize-1)) TRACE_(olerelay)(",");
765 if (debugout) TRACE_(olerelay)("]");
769 ERR("Unhandled marshal type %d.\n",tdesc->vt);
775 * HRESULT GetIDsOfNames(
776 * [in] REFIID riid, args[1]
777 * [in, size_is(cNames)] LPOLESTR *rgszNames, args[2]
778 * [in] UINT cNames, args[3]
779 * [in] LCID lcid, args[4]
780 * [out, size_is(cNames)] DISPID *rgDispId); args[5]
785 * LPOLESTR rgszNames[cNames];
786 * DWORD bytestrlen (incl 0)
787 * BYTE data[bytestrlen] (incl 0)
791 serialize_IDispatch_GetIDsOfNames(
798 DWORD cNames = args[2];
799 LPOLESTR *rgszNames = (LPOLESTR*)args[1];
803 if (debugout) TRACE_(olerelay)("riid=%s,",debugstr_guid((REFIID)args[0]));
804 hres = xbuf_add(buf, (LPBYTE)args[0], sizeof(IID));
806 FIXME("serialize of IID failed.\n");
809 if (debugout) TRACE_(olerelay)("cNames=%ld,",cNames);
810 hres = xbuf_add(buf, (LPBYTE)&cNames, sizeof(DWORD));
812 FIXME("serialize of cNames failed.\n");
815 if (debugout) TRACE_(olerelay)("rgszNames=[");
816 for (i=0;i<cNames;i++) {
817 DWORD len = 2*(lstrlenW(rgszNames[i])+1);
819 if (debugout) TRACE_(olerelay)("%s,",relaystr(rgszNames[i]));
820 hres = xbuf_add(buf, (LPBYTE)&len, sizeof(DWORD));
822 FIXME("serialize of len failed.\n");
825 hres = xbuf_add(buf, (LPBYTE)rgszNames[i], len);
827 FIXME("serialize of rgszNames[i] failed.\n");
831 if (debugout) TRACE_(olerelay)("],lcid=%04lx)",args[3]);
832 hres = xbuf_add(buf, (LPBYTE)&args[3], sizeof(DWORD));
834 FIXME("serialize of lcid failed.\n");
838 DISPID *rgDispId = (DISPID*)args[4];
840 hres = xbuf_add(buf, (LPBYTE)rgDispId, sizeof(DISPID) * cNames);
842 FIXME("serialize of rgDispId failed.\n");
846 TRACE_(olerelay)("riid=[in],rgszNames=[in],cNames=[in],rgDispId=[");
847 for (i=0;i<cNames;i++)
848 TRACE_(olerelay)("%08lx,",rgDispId[i]);
849 TRACE_(olerelay)("])");
851 HeapFree(GetProcessHeap(),0,(IID*)args[0]);
852 rgszNames = (LPOLESTR*)args[1];
853 for (i=0;i<cNames;i++) HeapFree(GetProcessHeap(),0,rgszNames[i]);
854 HeapFree(GetProcessHeap(),0,rgszNames);
855 HeapFree(GetProcessHeap(),0,rgDispId);
861 deserialize_IDispatch_GetIDsOfNames(
873 args[0] = (DWORD)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IID));
874 if (!args[0]) return E_FAIL;
875 hres = xbuf_get(buf, (LPBYTE)args[0], sizeof(IID));
877 FIXME("deserialize of IID failed.\n");
880 if (debugout) TRACE_(olerelay)("riid=%s,",debugstr_guid((REFIID)args[0]));
882 hres = xbuf_get(buf, (LPBYTE)&cNames, sizeof(DWORD));
884 FIXME("deserialize of cNames failed.\n");
888 if (debugout) TRACE_(olerelay)("cNames=%ld,",cNames);
889 if (debugout) TRACE_(olerelay)("rgszNames=[");
890 rgszNames = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(LPOLESTR) * cNames);
891 if (!rgszNames) return E_FAIL;
892 args[1] = (DWORD)rgszNames;
893 for (i=0;i<cNames;i++) {
896 hres = xbuf_get(buf, (LPBYTE)&len, sizeof(DWORD));
898 FIXME("serialize of len failed.\n");
901 rgszNames[i] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
903 FIXME("heapalloc of %ld bytes failed\n", len);
906 hres = xbuf_get(buf, (LPBYTE)rgszNames[i], len);
908 FIXME("serialize of rgszNames[i] failed.\n");
911 if (debugout) TRACE_(olerelay)("%s,",relaystr(rgszNames[i]));
913 hres = xbuf_get(buf, (LPBYTE)&args[3], sizeof(DWORD));
915 FIXME("deserialize of lcid failed.\n");
918 if (debugout) TRACE_(olerelay)("],lcid=%04lx,rgDispId=[out])",args[3]);
919 args[4] = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPID) * cNames);
921 hres = xbuf_get(buf, (LPBYTE)args[4], sizeof(DISPID) * args[2]);
923 FIXME("serialize of rgDispId failed.\n");
927 TRACE_(olerelay)("dispid=[");
928 for (i=0;i<args[2];i++)
929 TRACE_(olerelay)("%08lx,",((DISPID*)args[4])[i]);
930 TRACE_(olerelay)("])");
937 serialize_LPVOID_ptr(
949 if ((tdesc->vt != VT_PTR) ||
950 (tdesc->u.lptdesc->vt != VT_PTR) ||
951 (tdesc->u.lptdesc->u.lptdesc->vt != VT_VOID)
953 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
956 cookie = (*(DWORD*)*arg) ? 0x42424242: 0x0;
958 hres = xbuf_add(buf, (LPVOID)&cookie, sizeof(cookie));
962 if (!*(DWORD*)*arg) {
963 if (debugout) TRACE_(olerelay)("<lpvoid NULL>");
967 TRACE_(olerelay)("ppv(%p)",*(LPUNKNOWN*)*arg);
969 hres = _marshal_interface(buf,&(buf->iid),*(LPUNKNOWN*)*arg);
974 HeapFree(GetProcessHeap(),0,(LPVOID)*arg);
979 serialize_DISPPARAM_ptr(
993 if ((tdesc->vt != VT_PTR) || (tdesc->u.lptdesc->vt != VT_USERDEFINED)) {
994 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
998 cookie = *arg ? 0x42424242 : 0x0;
1000 hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
1005 if (debugout) TRACE_(olerelay)("<DISPPARAMS NULL>");
1008 disp = (DISPPARAMS*)*arg;
1010 hres = xbuf_add(buf,(LPBYTE)&disp->cArgs,sizeof(disp->cArgs));
1014 if (debugout) TRACE_(olerelay)("D{");
1015 for (i=0;i<disp->cArgs;i++) {
1018 vtdesc.vt = VT_VARIANT;
1025 (DWORD*)(disp->rgvarg+i),
1028 if (debugout && (i<disp->cArgs-1))
1029 TRACE_(olerelay)(",");
1032 HeapFree(GetProcessHeap(),0,disp->rgvarg);
1034 hres = xbuf_add(buf,(LPBYTE)&disp->cNamedArgs,sizeof(disp->cNamedArgs));
1038 if (debugout) TRACE_(olerelay)("}{");
1039 for (i=0;i<disp->cNamedArgs;i++) {
1042 vtdesc.vt = VT_UINT;
1049 (DWORD*)(disp->rgdispidNamedArgs+i),
1052 if (debugout && (i<disp->cNamedArgs-1))
1053 TRACE_(olerelay)(",");
1055 if (debugout) TRACE_(olerelay)("}");
1057 HeapFree(GetProcessHeap(),0,disp->rgdispidNamedArgs);
1058 HeapFree(GetProcessHeap(),0,disp);
1073 HRESULT hres = S_OK;
1075 TRACE("vt %d at %p\n",tdesc->vt,arg);
1078 switch (tdesc->vt) {
1080 if (debugout) TRACE_(olerelay)("<empty>");
1083 if (debugout) TRACE_(olerelay)("<null>");
1086 VARIANT *vt = (VARIANT*)arg;
1091 hres = xbuf_get(buf,(LPBYTE)&vttype,sizeof(vttype));
1093 FIXME("vt type not read?\n");
1096 memset(&tdesc2,0,sizeof(tdesc2));
1099 if (debugout) TRACE_(olerelay)("Vt(%ld)(",vttype);
1100 hres = deserialize_param(tinfo, readit, debugout, alloc, &tdesc2, (DWORD*)&(V_I4(vt)), buf);
1101 TRACE_(olerelay)(")");
1115 hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
1116 if (hres) ERR("Failed to read integer 4 byte\n");
1118 if (debugout) TRACE_(olerelay)("%lx",*arg);
1124 hres = xbuf_get(buf,(LPBYTE)&x,sizeof(DWORD));
1125 if (hres) ERR("Failed to read integer 4 byte\n");
1128 if (debugout) TRACE_(olerelay)("%04lx",*arg & 0xffff);
1134 hres = xbuf_get(buf,(LPBYTE)&x,sizeof(DWORD));
1135 if (hres) ERR("Failed to read integer 4 byte\n");
1138 if (debugout) TRACE_(olerelay)("%02lx",*arg & 0xff);
1140 case VT_I4|VT_BYREF:
1143 *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
1145 hres = xbuf_get(buf,(LPBYTE)*arg,sizeof(DWORD));
1146 if (hres) ERR("Failed to read integer 4 byte\n");
1148 if (debugout) TRACE_(olerelay)("&0x%lx",*(DWORD*)*arg);
1150 case VT_BSTR|VT_BYREF: {
1151 BSTR **bstr = (BSTR **)arg;
1156 hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
1158 ERR("failed to read bstr klen\n");
1162 *bstr = CoTaskMemAlloc(sizeof(BSTR *));
1164 if (debugout) TRACE_(olerelay)("<bstr NULL>");
1166 str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
1167 hres = xbuf_get(buf,(LPBYTE)str,len*sizeof(WCHAR));
1169 ERR("Failed to read BSTR.\n");
1172 *bstr = CoTaskMemAlloc(sizeof(BSTR *));
1173 **bstr = SysAllocStringLen(str,len);
1174 if (debugout) TRACE_(olerelay)("%s",relaystr(str));
1175 HeapFree(GetProcessHeap(),0,str);
1187 hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
1189 ERR("failed to read bstr klen\n");
1194 if (debugout) TRACE_(olerelay)("<bstr NULL>");
1196 str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
1197 hres = xbuf_get(buf,(LPBYTE)str,len*sizeof(WCHAR));
1199 ERR("Failed to read BSTR.\n");
1202 *arg = (DWORD)SysAllocStringLen(str,len);
1203 if (debugout) TRACE_(olerelay)("%s",relaystr(str));
1204 HeapFree(GetProcessHeap(),0,str);
1213 BOOL derefhere = TRUE;
1215 if (tdesc->u.lptdesc->vt == VT_USERDEFINED) {
1219 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.lptdesc->u.hreftype,&tinfo2);
1221 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.lptdesc->u.hreftype);
1224 ITypeInfo_GetTypeAttr(tinfo2,&tattr);
1225 switch (tattr->typekind) {
1226 case TKIND_ENUM: /* confirmed */
1227 case TKIND_RECORD: /* FIXME: mostly untested */
1230 case TKIND_ALIAS: /* FIXME: untested */
1231 case TKIND_DISPATCH: /* will be done in VT_USERDEFINED case */
1232 case TKIND_INTERFACE: /* will be done in VT_USERDEFINED case */
1236 FIXME("unhandled switch cases tattr->typekind %d\n", tattr->typekind);
1240 ITypeInfo_Release(tinfo2);
1242 /* read it in all cases, we need to know if we have
1243 * NULL pointer or not.
1245 hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
1247 ERR("Failed to load pointer cookie.\n");
1250 if (cookie != 0x42424242) {
1251 /* we read a NULL ptr from the remote side */
1252 if (debugout) TRACE_(olerelay)("NULL");
1256 if (debugout) TRACE_(olerelay)("*");
1258 /* Allocate space for the referenced struct */
1260 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,_xsize(tdesc->u.lptdesc));
1263 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, (LPDWORD)*arg, buf);
1265 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, arg, buf);
1268 /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
1270 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
1273 hres = _unmarshal_interface(buf,&IID_IUnknown,(LPUNKNOWN*)arg);
1275 TRACE_(olerelay)("unk(%p)",arg);
1280 hres = _unmarshal_interface(buf,&IID_IDispatch,(LPUNKNOWN*)arg);
1282 TRACE_(olerelay)("idisp(%p)",arg);
1285 if (debugout) TRACE_(olerelay)("<void>");
1287 case VT_USERDEFINED: {
1291 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
1293 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
1296 hres = ITypeInfo_GetTypeAttr(tinfo2,&tattr);
1298 ERR("Could not get typeattr in VT_USERDEFINED.\n");
1300 switch (tattr->typekind) {
1301 case TKIND_DISPATCH:
1302 case TKIND_INTERFACE:
1304 hres = _unmarshal_interface(buf,&(tattr->guid),(LPUNKNOWN*)arg);
1306 case TKIND_RECORD: {
1310 *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,tattr->cbSizeInstance);
1312 if (debugout) TRACE_(olerelay)("{");
1313 for (i=0;i<tattr->cVars;i++) {
1316 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
1318 ERR("Could not get vardesc of %d\n",i);
1321 hres = deserialize_param(
1326 &vdesc->elemdescVar.tdesc,
1327 (DWORD*)(((LPBYTE)*arg)+vdesc->u.oInst),
1330 if (debugout && (i<tattr->cVars-1)) TRACE_(olerelay)(",");
1332 if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
1333 memcpy(&(buf->iid),(LPBYTE)*arg,sizeof(buf->iid));
1334 if (debugout) TRACE_(olerelay)("}");
1338 return deserialize_param(tinfo2,readit,debugout,alloc,&tattr->tdescAlias,arg,buf);
1341 hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
1342 if (hres) ERR("Failed to read enum (4 byte)\n");
1344 if (debugout) TRACE_(olerelay)("%lx",*arg);
1347 ERR("Unhandled typekind %d\n",tattr->typekind);
1353 ERR("failed to stuballoc in TKIND_RECORD.\n");
1354 ITypeInfo_Release(tinfo2);
1358 /* arg is pointing to the start of the array. */
1359 ARRAYDESC *adesc = tdesc->u.lpadesc;
1362 if (adesc->cDims > 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
1363 for (i=0;i<adesc->cDims;i++)
1364 arrsize *= adesc->rgbounds[i].cElements;
1365 for (i=0;i<arrsize;i++)
1372 (DWORD*)((LPBYTE)(arg)+i*_xsize(&adesc->tdescElem)),
1378 ERR("No handler for VT type %d!\n",tdesc->vt);
1385 deserialize_LPVOID_ptr(
1397 if ((tdesc->vt != VT_PTR) ||
1398 (tdesc->u.lptdesc->vt != VT_PTR) ||
1399 (tdesc->u.lptdesc->u.lptdesc->vt != VT_VOID)
1401 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
1405 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(LPVOID));
1407 hres = xbuf_get(buf, (LPVOID)&cookie, sizeof(cookie));
1410 if (cookie != 0x42424242) {
1412 if (debugout) TRACE_(olerelay)("<lpvoid NULL>");
1417 hres = _unmarshal_interface(buf,&buf->iid,(LPUNKNOWN*)*arg);
1419 FIXME("_unmarshal_interface of %s , %p failed with %lx\n", debugstr_guid(&buf->iid), (LPUNKNOWN*)*arg, hres);
1423 if (debugout) TRACE_(olerelay)("ppv(%p)",(LPVOID)*arg);
1428 deserialize_DISPPARAM_ptr(
1442 if ((tdesc->vt != VT_PTR) || (tdesc->u.lptdesc->vt != VT_USERDEFINED)) {
1443 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
1447 hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
1452 if (debugout) TRACE_(olerelay)("<DISPPARAMS NULL>");
1457 *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPPARAMS));
1458 disps = (DISPPARAMS*)*arg;
1461 hres = xbuf_get(buf, (LPBYTE)&disps->cArgs, sizeof(disps->cArgs));
1465 disps->rgvarg = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(VARIANT)*disps->cArgs);
1466 if (debugout) TRACE_(olerelay)("D{");
1467 for (i=0; i< disps->cArgs; i++) {
1470 vdesc.vt = VT_VARIANT;
1471 hres = deserialize_param(
1477 (DWORD*)(disps->rgvarg+i),
1481 if (debugout) TRACE_(olerelay)("}{");
1482 hres = xbuf_get(buf, (LPBYTE)&disps->cNamedArgs, sizeof(disps->cNamedArgs));
1485 if (disps->cNamedArgs) {
1487 disps->rgdispidNamedArgs = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPID)*disps->cNamedArgs);
1488 for (i=0; i< disps->cNamedArgs; i++) {
1492 hres = deserialize_param(
1498 (DWORD*)(disps->rgdispidNamedArgs+i),
1501 if (debugout && i<(disps->cNamedArgs-1)) TRACE_(olerelay)(",");
1504 if (debugout) TRACE_(olerelay)("}");
1508 /* Searches function, also in inherited interfaces */
1511 ITypeInfo *tinfo, int iMethod, ITypeInfo **tactual, FUNCDESC **fdesc, BSTR *iname, BSTR *fname)
1516 if (fname) *fname = NULL;
1517 if (iname) *iname = NULL;
1520 ITypeInfo_AddRef(*tactual);
1523 hres = ITypeInfo_GetFuncDesc(tinfo, i, fdesc);
1529 hres = ITypeInfo_GetTypeAttr(tinfo, &attr);
1531 ERR("GetTypeAttr failed with %lx\n",hres);
1534 /* Not found, so look in inherited ifaces. */
1535 for (j=0;j<attr->cImplTypes;j++) {
1536 hres = ITypeInfo_GetRefTypeOfImplType(tinfo, j, &href);
1538 ERR("Did not find a reftype for interface offset %d?\n",j);
1541 hres = ITypeInfo_GetRefTypeInfo(tinfo, href, &tinfo2);
1543 ERR("Did not find a typeinfo for reftype %ld?\n",href);
1546 hres = _get_funcdesc(tinfo2,iMethod,tactual,fdesc,iname,fname);
1547 ITypeInfo_Release(tinfo2);
1548 if (!hres) return S_OK;
1552 if (((*fdesc)->oVft/4) == iMethod) {
1554 ITypeInfo_GetDocumentation(tinfo,(*fdesc)->memid,fname,NULL,NULL,NULL);
1556 ITypeInfo_GetDocumentation(tinfo,-1,iname,NULL,NULL,NULL);
1564 xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */)
1566 DWORD *args = ((DWORD*)&tpinfo)+1, *xargs;
1569 int i, relaydeb = TRACE_ON(olerelay);
1576 int is_idispatch_getidsofnames = 0;
1577 DWORD remoteresult = 0;
1580 EnterCriticalSection(&tpinfo->crit);
1582 hres = _get_funcdesc(tpinfo->tinfo,method,&tinfo,&fdesc,&iname,&fname);
1584 ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method);
1585 ITypeInfo_Release(tinfo);
1586 LeaveCriticalSection(&tpinfo->crit);
1590 if (!tpinfo->chanbuf)
1592 WARN("Tried to use disconnected proxy\n");
1593 ITypeInfo_Release(tinfo);
1594 LeaveCriticalSection(&tpinfo->crit);
1595 return RPC_E_DISCONNECTED;
1599 TRACE_(olerelay)("->");
1601 TRACE_(olerelay)("%s:",relaystr(iname));
1603 TRACE_(olerelay)("%s(%d)",relaystr(fname),method);
1605 TRACE_(olerelay)("%d",method);
1606 TRACE_(olerelay)("(");
1608 if (iname && fname && !lstrcmpW(iname,IDispatchW) && !lstrcmpW(fname,GetIDsOfNamesW))
1609 is_idispatch_getidsofnames = 1;
1611 if (iname) SysFreeString(iname);
1612 if (fname) SysFreeString(fname);
1614 memset(&buf,0,sizeof(buf));
1615 buf.iid = IID_IUnknown;
1617 /* Special IDispatch::GetIDsOfNames() serializer */
1618 if (is_idispatch_getidsofnames) {
1619 hres = serialize_IDispatch_GetIDsOfNames(TRUE,relaydeb,args,&buf);
1621 FIXME("serialize of IDispatch::GetIDsOfNames failed!\n");
1622 ITypeInfo_Release(tinfo);
1623 LeaveCriticalSection(&tpinfo->crit);
1626 goto afterserialize;
1629 /* special QueryInterface serialize */
1631 xbuf_add(&buf,(LPBYTE)args[0],sizeof(IID));
1632 if (relaydeb) TRACE_(olerelay)("riid=%s,[out])",debugstr_guid((REFIID)args[0]));
1633 goto afterserialize;
1636 /* normal typelib driven serializing */
1638 /* Need them for hack below */
1639 memset(names,0,sizeof(names));
1640 if (ITypeInfo_GetNames(tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames))
1642 if (nrofnames > sizeof(names)/sizeof(names[0]))
1643 ERR("Need more names!\n");
1646 for (i=0;i<fdesc->cParams;i++) {
1647 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1648 BOOL isserialized = FALSE;
1650 if (i) TRACE_(olerelay)(",");
1651 if (i+1<nrofnames && names[i+1])
1652 TRACE_(olerelay)("%s=",relaystr(names[i+1]));
1654 /* No need to marshal other data than FIN and any VT_PTR. */
1655 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN) && (elem->tdesc.vt != VT_PTR)) {
1656 xargs+=_argsize(elem->tdesc.vt);
1657 if (relaydeb) TRACE_(olerelay)("[out]");
1660 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1661 /* If the parameter is 'riid', we use it as interface IID
1662 * for a later ppvObject serialization.
1664 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1666 /* DISPPARAMS* needs special serializer */
1667 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1668 hres = serialize_DISPPARAM_ptr(
1670 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1677 isserialized = TRUE;
1679 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1680 hres = serialize_LPVOID_ptr(
1682 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1690 isserialized = TRUE;
1694 hres = serialize_param(
1696 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1705 ERR("Failed to serialize param, hres %lx\n",hres);
1708 xargs+=_argsize(elem->tdesc.vt);
1710 if (relaydeb) TRACE_(olerelay)(")");
1713 memset(&msg,0,sizeof(msg));
1714 msg.cbBuffer = buf.curoff;
1715 msg.iMethod = method;
1716 hres = IRpcChannelBuffer_GetBuffer(tpinfo->chanbuf,&msg,&(tpinfo->iid));
1718 ERR("RpcChannelBuffer GetBuffer failed, %lx\n",hres);
1719 LeaveCriticalSection(&tpinfo->crit);
1722 memcpy(msg.Buffer,buf.base,buf.curoff);
1723 if (relaydeb) TRACE_(olerelay)("\n");
1724 hres = IRpcChannelBuffer_SendReceive(tpinfo->chanbuf,&msg,&status);
1726 ERR("RpcChannelBuffer SendReceive failed, %lx\n",hres);
1727 LeaveCriticalSection(&tpinfo->crit);
1731 if (relaydeb) TRACE_(olerelay)(" status = %08lx (",status);
1733 buf.base = HeapReAlloc(GetProcessHeap(),0,buf.base,msg.cbBuffer);
1735 buf.base = HeapAlloc(GetProcessHeap(),0,msg.cbBuffer);
1736 buf.size = msg.cbBuffer;
1737 memcpy(buf.base,msg.Buffer,buf.size);
1740 /* Special IDispatch::GetIDsOfNames() deserializer */
1741 if (is_idispatch_getidsofnames) {
1742 hres = deserialize_IDispatch_GetIDsOfNames(FALSE,relaydeb,args,&buf);
1744 FIXME("deserialize of IDispatch::GetIDsOfNames failed!\n");
1747 goto after_deserialize;
1749 /* Special QueryInterface deserializer */
1751 _unmarshal_interface(&buf,(REFIID)args[0],(LPUNKNOWN*)args[1]);
1752 if (relaydeb) TRACE_(olerelay)("[in],%p",*((DWORD**)args[1]));
1753 goto after_deserialize;
1756 /* generic deserializer using typelib description */
1759 for (i=0;i<fdesc->cParams;i++) {
1760 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1761 BOOL isdeserialized = FALSE;
1764 if (i) TRACE_(olerelay)(",");
1765 if (i+1<nrofnames && names[i+1]) TRACE_(olerelay)("%s=",relaystr(names[i+1]));
1767 /* No need to marshal other data than FOUT and any VT_PTR */
1768 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT) && (elem->tdesc.vt != VT_PTR)) {
1769 xargs += _argsize(elem->tdesc.vt);
1770 if (relaydeb) TRACE_(olerelay)("[in]");
1773 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1774 /* If the parameter is 'riid', we use it as interface IID
1775 * for a later ppvObject serialization.
1777 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1779 /* deserialize DISPPARAM */
1780 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1781 hres = deserialize_DISPPARAM_ptr(
1783 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1791 ERR("Failed to deserialize DISPPARAM*, hres %lx\n",hres);
1794 isdeserialized = TRUE;
1796 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1797 hres = deserialize_LPVOID_ptr(
1799 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1807 isdeserialized = TRUE;
1810 if (!isdeserialized)
1811 hres = deserialize_param(
1813 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1821 ERR("Failed to unmarshall param, hres %lx\n",hres);
1825 xargs += _argsize(elem->tdesc.vt);
1828 hres = xbuf_get(&buf, (LPBYTE)&remoteresult, sizeof(DWORD));
1831 if (relaydeb) TRACE_(olerelay)(") = %08lx\n", remoteresult);
1833 if (status != S_OK) /* OLE/COM internal error */
1836 HeapFree(GetProcessHeap(),0,buf.base);
1837 ITypeInfo_Release(tinfo);
1838 LeaveCriticalSection(&tpinfo->crit);
1839 return remoteresult;
1842 HRESULT WINAPI ProxyIUnknown_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
1844 TMProxyImpl *proxy = (TMProxyImpl *)iface;
1846 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
1848 if (proxy->outerunknown)
1849 return IUnknown_QueryInterface(proxy->outerunknown, riid, ppv);
1851 FIXME("No interface\n");
1852 return E_NOINTERFACE;
1855 ULONG WINAPI ProxyIUnknown_AddRef(IUnknown *iface)
1857 TMProxyImpl *proxy = (TMProxyImpl *)iface;
1861 if (proxy->outerunknown)
1862 return IUnknown_AddRef(proxy->outerunknown);
1864 return 2; /* FIXME */
1867 ULONG WINAPI ProxyIUnknown_Release(IUnknown *iface)
1869 TMProxyImpl *proxy = (TMProxyImpl *)iface;
1873 if (proxy->outerunknown)
1874 return IUnknown_Release(proxy->outerunknown);
1876 return 1; /* FIXME */
1879 static HRESULT WINAPI
1880 PSFacBuf_CreateProxy(
1881 LPPSFACTORYBUFFER iface, IUnknown* pUnkOuter, REFIID riid,
1882 IRpcProxyBuffer **ppProxy, LPVOID *ppv)
1890 TRACE("(...%s...)\n",debugstr_guid(riid));
1891 hres = _get_typeinfo_for_iid(riid,&tinfo);
1893 ERR("No typeinfo for %s?\n",debugstr_guid(riid));
1896 nroffuncs = _nroffuncs(tinfo);
1897 proxy = CoTaskMemAlloc(sizeof(TMProxyImpl));
1898 if (!proxy) return E_OUTOFMEMORY;
1900 assert(sizeof(TMAsmProxy) == 12);
1902 proxy->outerunknown = pUnkOuter;
1903 proxy->asmstubs = VirtualAlloc(NULL, sizeof(TMAsmProxy) * nroffuncs, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
1904 if (!proxy->asmstubs) {
1905 ERR("Could not commit pages for proxy thunks\n");
1906 CoTaskMemFree(proxy);
1907 return E_OUTOFMEMORY;
1910 InitializeCriticalSection(&proxy->crit);
1912 proxy->lpvtbl = HeapAlloc(GetProcessHeap(),0,sizeof(LPBYTE)*nroffuncs);
1913 for (i=0;i<nroffuncs;i++) {
1914 TMAsmProxy *xasm = proxy->asmstubs+i;
1918 proxy->lpvtbl[i] = ProxyIUnknown_QueryInterface;
1921 proxy->lpvtbl[i] = ProxyIUnknown_AddRef;
1924 proxy->lpvtbl[i] = ProxyIUnknown_Release;
1928 /* nrofargs without This */
1931 hres = _get_funcdesc(tinfo,i,&tinfo2,&fdesc,NULL,NULL);
1932 ITypeInfo_Release(tinfo2);
1934 ERR("GetFuncDesc %lx should not fail here.\n",hres);
1937 /* some args take more than 4 byte on the stack */
1939 for (j=0;j<fdesc->cParams;j++)
1940 nrofargs += _argsize(fdesc->lprgelemdescParam[j].tdesc.vt);
1942 if (fdesc->callconv != CC_STDCALL) {
1943 ERR("calling convention is not stdcall????\n");
1946 /* popl %eax - return ptr
1953 * arg3 arg2 arg1 <method> <returnptr>
1955 xasm->popleax = 0x58;
1956 xasm->pushlval = 0x6a;
1958 xasm->pushleax = 0x50;
1959 xasm->lcall = 0xe8; /* relative jump */
1960 xasm->xcall = (DWORD)xCall;
1961 xasm->xcall -= (DWORD)&(xasm->lret);
1963 xasm->bytestopop= (nrofargs+2)*4; /* pop args, This, iMethod */
1964 proxy->lpvtbl[i] = xasm;
1969 proxy->lpvtbl2 = &tmproxyvtable;
1970 /* 1 reference for the proxy and 1 for the object */
1972 proxy->tinfo = tinfo;
1973 memcpy(&proxy->iid,riid,sizeof(*riid));
1975 *ppv = (LPVOID)proxy;
1976 *ppProxy = (IRpcProxyBuffer *)&(proxy->lpvtbl2);
1980 typedef struct _TMStubImpl {
1981 const IRpcStubBufferVtbl *lpvtbl;
1989 static HRESULT WINAPI
1990 TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface, REFIID riid, LPVOID *ppv)
1992 if (IsEqualIID(riid,&IID_IRpcStubBuffer)||IsEqualIID(riid,&IID_IUnknown)){
1993 *ppv = (LPVOID)iface;
1994 IRpcStubBuffer_AddRef(iface);
1997 FIXME("%s, not supported IID.\n",debugstr_guid(riid));
1998 return E_NOINTERFACE;
2002 TMStubImpl_AddRef(LPRPCSTUBBUFFER iface)
2004 TMStubImpl *This = (TMStubImpl *)iface;
2005 ULONG refCount = InterlockedIncrement(&This->ref);
2007 TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
2013 TMStubImpl_Release(LPRPCSTUBBUFFER iface)
2015 TMStubImpl *This = (TMStubImpl *)iface;
2016 ULONG refCount = InterlockedDecrement(&This->ref);
2018 TRACE("(%p)->(ref before=%lu)\n", This, refCount + 1);
2022 IRpcStubBuffer_Disconnect(iface);
2023 ITypeInfo_Release(This->tinfo);
2024 CoTaskMemFree(This);
2029 static HRESULT WINAPI
2030 TMStubImpl_Connect(LPRPCSTUBBUFFER iface, LPUNKNOWN pUnkServer)
2032 TMStubImpl *This = (TMStubImpl *)iface;
2034 TRACE("(%p)->(%p)\n", This, pUnkServer);
2036 IUnknown_AddRef(pUnkServer);
2037 This->pUnk = pUnkServer;
2042 TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface)
2044 TMStubImpl *This = (TMStubImpl *)iface;
2046 TRACE("(%p)->()\n", This);
2050 IUnknown_Release(This->pUnk);
2055 static HRESULT WINAPI
2057 LPRPCSTUBBUFFER iface, RPCOLEMESSAGE* xmsg,IRpcChannelBuffer*rpcchanbuf)
2061 TMStubImpl *This = (TMStubImpl *)iface;
2063 DWORD *args, res, *xargs, nrofargs;
2067 BSTR fname = NULL,iname = NULL;
2068 BOOL is_idispatch_getidsofnames = 0;
2071 memset(&buf,0,sizeof(buf));
2072 buf.size = xmsg->cbBuffer;
2073 buf.base = HeapAlloc(GetProcessHeap(), 0, xmsg->cbBuffer);
2074 memcpy(buf.base, xmsg->Buffer, xmsg->cbBuffer);
2076 buf.iid = IID_IUnknown;
2079 if (xmsg->iMethod == 0) { /* QI */
2081 /* in: IID, out: <iface> */
2083 xbuf_get(&buf,(LPBYTE)&xiid,sizeof(xiid));
2085 hres = _marshal_interface(&buf,&xiid,This->pUnk);
2086 xmsg->Buffer = buf.base; /* Might have been reallocated */
2087 xmsg->cbBuffer = buf.size;
2090 hres = _get_funcdesc(This->tinfo,xmsg->iMethod,&tinfo,&fdesc,&iname,&fname);
2092 ERR("GetFuncDesc on method %ld failed with %lx\n",xmsg->iMethod,hres);
2096 if (iname && fname && !lstrcmpW(iname, IDispatchW) && !lstrcmpW(fname, GetIDsOfNamesW))
2097 is_idispatch_getidsofnames = 1;
2099 if (iname) SysFreeString (iname);
2100 if (fname) SysFreeString (fname);
2102 /* Need them for hack below */
2103 memset(names,0,sizeof(names));
2104 ITypeInfo_GetNames(tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
2105 if (nrofnames > sizeof(names)/sizeof(names[0])) {
2106 ERR("Need more names!\n");
2109 /*dump_FUNCDESC(fdesc);*/
2111 for (i=0;i<fdesc->cParams;i++)
2112 nrofargs += _argsize(fdesc->lprgelemdescParam[i].tdesc.vt);
2113 args = HeapAlloc(GetProcessHeap(),0,(nrofargs+1)*sizeof(DWORD));
2114 if (!args) return E_OUTOFMEMORY;
2116 if (is_idispatch_getidsofnames) {
2117 hres = deserialize_IDispatch_GetIDsOfNames(TRUE,FALSE,args+1,&buf);
2119 FIXME("deserialize_IDispatch_GetIDsOfNames failed!\n");
2123 goto afterdeserialize;
2126 /* Allocate all stuff used by call. */
2128 for (i=0;i<fdesc->cParams;i++) {
2129 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
2130 BOOL isdeserialized = FALSE;
2132 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
2133 /* If the parameter is 'riid', we use it as interface IID
2134 * for a later ppvObject serialization.
2136 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
2138 /* deserialize DISPPARAM */
2139 if (!lstrcmpW(names[i+1],pdispparamsW)) {
2140 hres = deserialize_DISPPARAM_ptr(
2142 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
2150 ERR("Failed to deserialize DISPPARAM*, hres %lx\n",hres);
2153 isdeserialized = TRUE;
2155 if (!lstrcmpW(names[i+1],ppvObjectW)) {
2156 hres = deserialize_LPVOID_ptr(
2158 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
2166 isdeserialized = TRUE;
2169 if (!isdeserialized)
2170 hres = deserialize_param(
2172 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
2179 xargs += _argsize(elem->tdesc.vt);
2181 ERR("Failed to deserialize param %s, hres %lx\n",relaystr(names[i+1]),hres);
2186 hres = IUnknown_QueryInterface(This->pUnk,&(This->iid),(LPVOID*)&(args[0]));
2188 ERR("Does not support iface %s, returning %lx\n",debugstr_guid(&(This->iid)), hres);
2192 (*((FARPROC**)args[0]))[fdesc->oVft/4],
2197 IUnknown_Release((LPUNKNOWN)args[0]);
2200 /* special IDispatch::GetIDsOfNames serializer */
2201 if (is_idispatch_getidsofnames) {
2202 hres = serialize_IDispatch_GetIDsOfNames(FALSE,FALSE,args+1,&buf);
2204 FIXME("serialize of IDispatch::GetIDsOfNames failed!\n");
2207 goto afterserialize;
2210 for (i=0;i<fdesc->cParams;i++) {
2211 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
2212 BOOL isserialized = FALSE;
2214 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
2215 /* If the parameter is 'riid', we use it as interface IID
2216 * for a later ppvObject serialization.
2218 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
2220 /* DISPPARAMS* needs special serializer */
2221 if (!lstrcmpW(names[i+1],pdispparamsW)) {
2222 hres = serialize_DISPPARAM_ptr(
2224 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
2231 isserialized = TRUE;
2233 if (!lstrcmpW(names[i+1],ppvObjectW)) {
2234 hres = serialize_LPVOID_ptr(
2236 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
2244 isserialized = TRUE;
2248 hres = serialize_param(
2250 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
2257 xargs += _argsize(elem->tdesc.vt);
2259 ERR("Failed to stuballoc param, hres %lx\n",hres);
2264 hres = xbuf_add (&buf, (LPBYTE)&res, sizeof(DWORD));
2268 ITypeInfo_Release(tinfo);
2269 HeapFree(GetProcessHeap(), 0, args);
2271 xmsg->cbBuffer = buf.curoff;
2274 hres = IRpcChannelBuffer_GetBuffer(rpcchanbuf, xmsg, &This->iid);
2276 ERR("IRpcChannelBuffer_GetBuffer failed with error 0x%08lx\n", hres);
2280 /* FIXME: remove this case when we start sending an IRpcChannelBuffer
2281 * object with builtin OLE */
2282 RPC_STATUS status = I_RpcGetBuffer((RPC_MESSAGE *)xmsg);
2283 if (status != RPC_S_OK)
2285 ERR("I_RpcGetBuffer failed with error %ld\n", status);
2291 memcpy(xmsg->Buffer, buf.base, buf.curoff);
2293 HeapFree(GetProcessHeap(), 0, buf.base);
2295 TRACE("returning\n");
2299 static LPRPCSTUBBUFFER WINAPI
2300 TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface, REFIID riid) {
2301 FIXME("Huh (%s)?\n",debugstr_guid(riid));
2306 TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface) {
2307 TMStubImpl *This = (TMStubImpl *)iface;
2310 return This->ref; /*FIXME? */
2313 static HRESULT WINAPI
2314 TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface, LPVOID *ppv) {
2319 TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface, LPVOID ppv) {
2323 static const IRpcStubBufferVtbl tmstubvtbl = {
2324 TMStubImpl_QueryInterface,
2328 TMStubImpl_Disconnect,
2330 TMStubImpl_IsIIDSupported,
2331 TMStubImpl_CountRefs,
2332 TMStubImpl_DebugServerQueryInterface,
2333 TMStubImpl_DebugServerRelease
2336 static HRESULT WINAPI
2337 PSFacBuf_CreateStub(
2338 LPPSFACTORYBUFFER iface, REFIID riid,IUnknown *pUnkServer,
2339 IRpcStubBuffer** ppStub
2345 TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub);
2346 hres = _get_typeinfo_for_iid(riid,&tinfo);
2348 ERR("No typeinfo for %s?\n",debugstr_guid(riid));
2351 stub = CoTaskMemAlloc(sizeof(TMStubImpl));
2353 return E_OUTOFMEMORY;
2354 stub->lpvtbl = &tmstubvtbl;
2356 stub->tinfo = tinfo;
2357 memcpy(&(stub->iid),riid,sizeof(*riid));
2358 hres = IRpcStubBuffer_Connect((LPRPCSTUBBUFFER)stub,pUnkServer);
2359 *ppStub = (LPRPCSTUBBUFFER)stub;
2360 TRACE("IRpcStubBuffer: %p\n", stub);
2362 ERR("Connect to pUnkServer failed?\n");
2366 static const IPSFactoryBufferVtbl psfacbufvtbl = {
2367 PSFacBuf_QueryInterface,
2370 PSFacBuf_CreateProxy,
2374 /* This is the whole PSFactoryBuffer object, just the vtableptr */
2375 static const IPSFactoryBufferVtbl *lppsfac = &psfacbufvtbl;
2377 /***********************************************************************
2378 * TMARSHAL_DllGetClassObject
2380 HRESULT TMARSHAL_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
2382 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)) {
2386 return E_NOINTERFACE;