4 * Copyright 2002 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 LPUNKNOWN newiface = NULL;
163 LPBYTE tempbuf = NULL;
164 IStream *pStm = NULL;
166 ULARGE_INTEGER newpos;
167 LARGE_INTEGER seekto;
174 ERR("pUnk is NULL?\n");
178 TRACE("...%s...\n",debugstr_guid(riid));
179 hres = IUnknown_QueryInterface(pUnk,riid,(LPVOID*)&newiface);
181 WARN("%p does not support iface %s\n",pUnk,debugstr_guid(riid));
185 hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
187 ERR("Stream create failed %lx\n",hres);
191 hres = CoMarshalInterface(pStm,riid,newiface,0,NULL,0);
193 ERR("Marshalling interface %s failed with %lx\n", debugstr_guid(riid), hres);
197 hres = IStream_Stat(pStm,&ststg,0);
199 ERR("Stream stat failed\n");
203 tempbuf = HeapAlloc(GetProcessHeap(), 0, ststg.cbSize.u.LowPart);
204 memset(&seekto,0,sizeof(seekto));
205 hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
207 ERR("Failed Seek %lx\n",hres);
211 hres = IStream_Read(pStm,tempbuf,ststg.cbSize.u.LowPart,&res);
213 ERR("Failed Read %lx\n",hres);
217 xsize = ststg.cbSize.u.LowPart;
218 xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
219 hres = xbuf_add(buf,tempbuf,ststg.cbSize.u.LowPart);
221 HeapFree(GetProcessHeap(),0,tempbuf);
222 IUnknown_Release(newiface);
223 IStream_Release(pStm);
229 xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
230 if (pStm) IUnknown_Release(pStm);
231 if (newiface) IUnknown_Release(newiface);
232 HeapFree(GetProcessHeap(), 0, tempbuf);
236 /********************* OLE Proxy/Stub Factory ********************************/
237 static HRESULT WINAPI
238 PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface, REFIID iid, LPVOID *ppv) {
239 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)||IsEqualIID(iid,&IID_IUnknown)) {
240 *ppv = (LPVOID)iface;
241 /* No ref counting, static class */
244 FIXME("(%s) unknown IID?\n",debugstr_guid(iid));
245 return E_NOINTERFACE;
248 static ULONG WINAPI PSFacBuf_AddRef(LPPSFACTORYBUFFER iface) { return 2; }
249 static ULONG WINAPI PSFacBuf_Release(LPPSFACTORYBUFFER iface) { return 1; }
252 _get_typeinfo_for_iid(REFIID riid, ITypeInfo**ti) {
255 char tlguid[200],typelibkey[300],interfacekey[300],ver[100];
258 DWORD tlguidlen, verlen, type, tlfnlen;
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,tlguid,&tlguidlen)) {
274 ERR("Getting typelib guid failed.\n");
279 verlen = sizeof(ver);
280 if (RegQueryValueExA(ikey,"Version",NULL,&type,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 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 IRpcProxyBufferVtbl tmproxyvtable = {
440 TMProxyImpl_QueryInterface,
444 TMProxyImpl_Disconnect
447 /* how much space do we use on stack in DWORD steps. */
452 return sizeof(DATE)/sizeof(DWORD);
454 return (sizeof(VARIANT)+3)/sizeof(DWORD);
461 _xsize(TYPEDESC *td) {
466 return sizeof(VARIANT)+3;
469 ARRAYDESC *adesc = td->u.lpadesc;
471 for (i=0;i<adesc->cDims;i++)
472 arrsize *= adesc->rgbounds[i].cElements;
473 return arrsize*_xsize(&adesc->tdescElem);
498 TRACE("(tdesc.vt %d)\n",tdesc->vt);
501 case VT_EMPTY: /* nothing. empty variant for instance */
510 if (debugout) TRACE_(olerelay)("%lx",*arg);
512 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
517 if (debugout) TRACE_(olerelay)("%04lx",*arg & 0xffff);
519 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
524 if (debugout) TRACE_(olerelay)("%02lx",*arg & 0xff);
526 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
530 VARIANT *vt = (VARIANT*)arg;
531 DWORD vttype = V_VT(vt);
533 if (debugout) TRACE_(olerelay)("Vt(%ld)(",vttype);
536 hres = xbuf_add(buf,(LPBYTE)&vttype,sizeof(vttype));
537 if (hres) return hres;
539 /* need to recurse since we need to free the stuff */
540 hres = serialize_param(tinfo,writeit,debugout,dealloc,&tdesc2,&(V_I4(vt)),buf);
541 if (debugout) TRACE_(olerelay)(")");
544 case VT_BSTR|VT_BYREF: {
545 if (debugout) TRACE_(olerelay)("[byref]'%s'", *arg ? relaystr(*((BSTR*)*arg)) : "<bstr NULL>");
547 /* ptr to ptr to magic widestring, basically */
548 BSTR *bstr = (BSTR *) *arg;
550 /* -1 means "null string" which is equivalent to empty string */
552 xbuf_add(buf, (LPBYTE)&fakelen,4);
554 /* BSTRs store the length behind the first character */
555 DWORD *len = ((DWORD *)(*bstr))-1;
556 hres = xbuf_add(buf, (LPBYTE) len, *len + 4);
557 if (hres) return hres;
561 if (dealloc && arg) {
562 BSTR *str = *((BSTR **)arg);
571 TRACE_(olerelay)("%s",relaystr((BSTR)*arg));
573 TRACE_(olerelay)("<bstr NULL>");
578 hres = xbuf_add(buf,(LPBYTE)&fakelen,4);
582 DWORD *bstr = ((DWORD*)(*arg))-1;
584 hres = xbuf_add(buf,(LPBYTE)bstr,bstr[0]+4);
591 SysFreeString((BSTR)*arg);
597 if (debugout) TRACE_(olerelay)("*");
598 /* Write always, so the other side knows when it gets a NULL pointer.
600 cookie = *arg ? 0x42424242 : 0;
601 hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
605 if (debugout) TRACE_(olerelay)("NULL");
608 hres = serialize_param(tinfo,writeit,debugout,dealloc,tdesc->u.lptdesc,(DWORD*)*arg,buf);
609 if (dealloc) HeapFree(GetProcessHeap(),0,(LPVOID)arg);
613 if (debugout) TRACE_(olerelay)("unk(0x%lx)",*arg);
615 hres = _marshal_interface(buf,&IID_IUnknown,(LPUNKNOWN)*arg);
618 if (debugout) TRACE_(olerelay)("idisp(0x%lx)",*arg);
620 hres = _marshal_interface(buf,&IID_IDispatch,(LPUNKNOWN)*arg);
623 if (debugout) TRACE_(olerelay)("<void>");
625 case VT_USERDEFINED: {
629 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
631 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
634 ITypeInfo_GetTypeAttr(tinfo2,&tattr);
635 switch (tattr->typekind) {
637 case TKIND_INTERFACE:
639 hres=_marshal_interface(buf,&(tattr->guid),(LPUNKNOWN)arg);
643 if (debugout) TRACE_(olerelay)("{");
644 for (i=0;i<tattr->cVars;i++) {
649 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
651 ERR("Could not get vardesc of %d\n",i);
654 /* Need them for hack below */
656 memset(names,0,sizeof(names));
657 hres = ITypeInfo_GetNames(tinfo2,vdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
658 if (nrofnames > sizeof(names)/sizeof(names[0])) {
659 ERR("Need more names!\n");
661 if (!hres && debugout)
662 TRACE_(olerelay)("%s=",relaystr(names[0]));
664 elem2 = &vdesc->elemdescVar;
665 tdesc2 = &elem2->tdesc;
666 hres = serialize_param(
672 (DWORD*)(((LPBYTE)arg)+vdesc->u.oInst),
677 if (debugout && (i<(tattr->cVars-1)))
678 TRACE_(olerelay)(",");
680 if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
681 memcpy(&(buf->iid),arg,sizeof(buf->iid));
682 if (debugout) TRACE_(olerelay)("}");
686 FIXME("Unhandled typekind %d\n",tattr->typekind);
690 ITypeInfo_Release(tinfo2);
694 ARRAYDESC *adesc = tdesc->u.lpadesc;
697 if (debugout) TRACE_(olerelay)("carr");
698 for (i=0;i<adesc->cDims;i++) {
699 if (debugout) TRACE_(olerelay)("[%ld]",adesc->rgbounds[i].cElements);
700 arrsize *= adesc->rgbounds[i].cElements;
702 if (debugout) TRACE_(olerelay)("(vt %d)",adesc->tdescElem.vt);
703 if (debugout) TRACE_(olerelay)("[");
704 for (i=0;i<arrsize;i++) {
705 hres = serialize_param(tinfo, writeit, debugout, dealloc, &adesc->tdescElem, (DWORD*)((LPBYTE)arg+i*_xsize(&adesc->tdescElem)), buf);
708 if (debugout && (i<arrsize-1)) TRACE_(olerelay)(",");
710 if (debugout) TRACE_(olerelay)("]");
714 ERR("Unhandled marshal type %d.\n",tdesc->vt);
720 * HRESULT GetIDsOfNames(
721 * [in] REFIID riid, args[1]
722 * [in, size_is(cNames)] LPOLESTR *rgszNames, args[2]
723 * [in] UINT cNames, args[3]
724 * [in] LCID lcid, args[4]
725 * [out, size_is(cNames)] DISPID *rgDispId); args[5]
730 * LPOLESTR rgszNames[cNames];
731 * DWORD bytestrlen (incl 0)
732 * BYTE data[bytestrlen] (incl 0)
736 serialize_IDispatch_GetIDsOfNames(
743 DWORD cNames = args[2];
744 LPOLESTR *rgszNames = (LPOLESTR*)args[1];
748 if (debugout) TRACE_(olerelay)("riid=%s,",debugstr_guid((REFIID)args[0]));
749 hres = xbuf_add(buf, (LPBYTE)args[0], sizeof(IID));
751 FIXME("serialize of IID failed.\n");
754 if (debugout) TRACE_(olerelay)("cNames=%ld,",cNames);
755 hres = xbuf_add(buf, (LPBYTE)&cNames, sizeof(DWORD));
757 FIXME("serialize of cNames failed.\n");
760 if (debugout) TRACE_(olerelay)("rgszNames=[");
761 for (i=0;i<cNames;i++) {
762 DWORD len = 2*(lstrlenW(rgszNames[i])+1);
764 if (debugout) TRACE_(olerelay)("%s,",relaystr(rgszNames[i]));
765 hres = xbuf_add(buf, (LPBYTE)&len, sizeof(DWORD));
767 FIXME("serialize of len failed.\n");
770 hres = xbuf_add(buf, (LPBYTE)rgszNames[i], len);
772 FIXME("serialize of rgszNames[i] failed.\n");
776 if (debugout) TRACE_(olerelay)("],lcid=%04lx)",args[3]);
777 hres = xbuf_add(buf, (LPBYTE)&args[3], sizeof(DWORD));
779 FIXME("serialize of lcid failed.\n");
783 DISPID *rgDispId = (DISPID*)args[4];
785 hres = xbuf_add(buf, (LPBYTE)rgDispId, sizeof(DISPID) * cNames);
787 FIXME("serialize of rgDispId failed.\n");
791 TRACE_(olerelay)("riid=[in],rgszNames=[in],cNames=[in],rgDispId=[");
792 for (i=0;i<cNames;i++)
793 TRACE_(olerelay)("%08lx,",rgDispId[i]);
794 TRACE_(olerelay)("])");
796 HeapFree(GetProcessHeap(),0,(IID*)args[0]);
797 rgszNames = (LPOLESTR*)args[1];
798 for (i=0;i<cNames;i++) HeapFree(GetProcessHeap(),0,rgszNames[i]);
799 HeapFree(GetProcessHeap(),0,rgszNames);
800 HeapFree(GetProcessHeap(),0,rgDispId);
806 deserialize_IDispatch_GetIDsOfNames(
818 args[0] = (DWORD)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IID));
819 if (!args[0]) return E_FAIL;
820 hres = xbuf_get(buf, (LPBYTE)args[0], sizeof(IID));
822 FIXME("deserialize of IID failed.\n");
825 if (debugout) TRACE_(olerelay)("riid=%s,",debugstr_guid((REFIID)args[0]));
827 hres = xbuf_get(buf, (LPBYTE)&cNames, sizeof(DWORD));
829 FIXME("deserialize of cNames failed.\n");
833 if (debugout) TRACE_(olerelay)("cNames=%ld,",cNames);
834 if (debugout) TRACE_(olerelay)("rgszNames=[");
835 rgszNames = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(LPOLESTR) * cNames);
836 if (!rgszNames) return E_FAIL;
837 args[1] = (DWORD)rgszNames;
838 for (i=0;i<cNames;i++) {
841 hres = xbuf_get(buf, (LPBYTE)&len, sizeof(DWORD));
843 FIXME("serialize of len failed.\n");
846 rgszNames[i] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
848 FIXME("heapalloc of %ld bytes failed\n", len);
851 hres = xbuf_get(buf, (LPBYTE)rgszNames[i], len);
853 FIXME("serialize of rgszNames[i] failed.\n");
856 if (debugout) TRACE_(olerelay)("%s,",relaystr(rgszNames[i]));
858 hres = xbuf_get(buf, (LPBYTE)&args[3], sizeof(DWORD));
860 FIXME("deserialize of lcid failed.\n");
863 if (debugout) TRACE_(olerelay)("],lcid=%04lx,rgDispId=[out])",args[3]);
864 args[4] = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPID) * cNames);
866 hres = xbuf_get(buf, (LPBYTE)args[4], sizeof(DISPID) * args[2]);
868 FIXME("serialize of rgDispId failed.\n");
872 TRACE_(olerelay)("dispid=[");
873 for (i=0;i<args[2];i++)
874 TRACE_(olerelay)("%08lx,",((DISPID*)args[4])[i]);
875 TRACE_(olerelay)("])");
882 serialize_LPVOID_ptr(
894 if ((tdesc->vt != VT_PTR) ||
895 (tdesc->u.lptdesc->vt != VT_PTR) ||
896 (tdesc->u.lptdesc->u.lptdesc->vt != VT_VOID)
898 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
901 cookie = (*arg) ? 0x42424242: 0x0;
903 hres = xbuf_add(buf, (LPVOID)&cookie, sizeof(cookie));
908 if (debugout) TRACE_(olerelay)("<lpvoid NULL>");
912 TRACE_(olerelay)("ppv(%p)",*(LPUNKNOWN*)*arg);
914 hres = _marshal_interface(buf,&(buf->iid),*(LPUNKNOWN*)*arg);
919 HeapFree(GetProcessHeap(),0,(LPVOID)*arg);
924 serialize_DISPPARAM_ptr(
938 if ((tdesc->vt != VT_PTR) || (tdesc->u.lptdesc->vt != VT_USERDEFINED)) {
939 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
943 cookie = *arg ? 0x42424242 : 0x0;
945 hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
950 if (debugout) TRACE_(olerelay)("<DISPPARAMS NULL>");
953 disp = (DISPPARAMS*)*arg;
955 hres = xbuf_add(buf,(LPBYTE)&disp->cArgs,sizeof(disp->cArgs));
959 if (debugout) TRACE_(olerelay)("D{");
960 for (i=0;i<disp->cArgs;i++) {
963 vtdesc.vt = VT_VARIANT;
970 (DWORD*)(disp->rgvarg+i),
973 if (debugout && (i<disp->cArgs-1))
974 TRACE_(olerelay)(",");
977 HeapFree(GetProcessHeap(),0,disp->rgvarg);
979 hres = xbuf_add(buf,(LPBYTE)&disp->cNamedArgs,sizeof(disp->cNamedArgs));
983 if (debugout) TRACE_(olerelay)("}{");
984 for (i=0;i<disp->cNamedArgs;i++) {
994 (DWORD*)(disp->rgdispidNamedArgs+i),
997 if (debugout && (i<disp->cNamedArgs-1))
998 TRACE_(olerelay)(",");
1000 if (debugout) TRACE_(olerelay)("}");
1002 HeapFree(GetProcessHeap(),0,disp->rgdispidNamedArgs);
1003 HeapFree(GetProcessHeap(),0,disp);
1018 HRESULT hres = S_OK;
1020 TRACE("vt %d at %p\n",tdesc->vt,arg);
1023 switch (tdesc->vt) {
1025 if (debugout) TRACE_(olerelay)("<empty>");
1028 if (debugout) TRACE_(olerelay)("<null>");
1031 VARIANT *vt = (VARIANT*)arg;
1036 hres = xbuf_get(buf,(LPBYTE)&vttype,sizeof(vttype));
1038 FIXME("vt type not read?\n");
1041 memset(&tdesc2,0,sizeof(tdesc2));
1044 if (debugout) TRACE_(olerelay)("Vt(%ld)(",vttype);
1045 hres = deserialize_param(tinfo, readit, debugout, alloc, &tdesc2, &(V_I4(vt)), buf);
1046 TRACE_(olerelay)(")");
1060 hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
1061 if (hres) ERR("Failed to read integer 4 byte\n");
1063 if (debugout) TRACE_(olerelay)("%lx",*arg);
1069 hres = xbuf_get(buf,(LPBYTE)&x,sizeof(DWORD));
1070 if (hres) ERR("Failed to read integer 4 byte\n");
1073 if (debugout) TRACE_(olerelay)("%04lx",*arg & 0xffff);
1079 hres = xbuf_get(buf,(LPBYTE)&x,sizeof(DWORD));
1080 if (hres) ERR("Failed to read integer 4 byte\n");
1083 if (debugout) TRACE_(olerelay)("%02lx",*arg & 0xff);
1085 case VT_BSTR|VT_BYREF: {
1086 BSTR **bstr = (BSTR **)arg;
1091 hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
1093 ERR("failed to read bstr klen\n");
1098 if (debugout) TRACE_(olerelay)("<bstr NULL>");
1100 str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len+sizeof(WCHAR));
1101 hres = xbuf_get(buf,(LPBYTE)str,len);
1103 ERR("Failed to read BSTR.\n");
1106 *bstr = CoTaskMemAlloc(sizeof(BSTR *));
1107 **bstr = SysAllocStringLen(str,len);
1108 if (debugout) TRACE_(olerelay)("%s",relaystr(str));
1109 HeapFree(GetProcessHeap(),0,str);
1121 hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
1123 ERR("failed to read bstr klen\n");
1128 if (debugout) TRACE_(olerelay)("<bstr NULL>");
1130 str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len+sizeof(WCHAR));
1131 hres = xbuf_get(buf,(LPBYTE)str,len);
1133 ERR("Failed to read BSTR.\n");
1136 *arg = (DWORD)SysAllocStringLen(str,len);
1137 if (debugout) TRACE_(olerelay)("%s",relaystr(str));
1138 HeapFree(GetProcessHeap(),0,str);
1149 derefhere = (tdesc->u.lptdesc->vt != VT_USERDEFINED);
1150 /* read it in all cases, we need to know if we have
1151 * NULL pointer or not.
1153 hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
1155 ERR("Failed to load pointer cookie.\n");
1158 if (cookie != 0x42424242) {
1159 /* we read a NULL ptr from the remote side */
1160 if (debugout) TRACE_(olerelay)("NULL");
1164 if (debugout) TRACE_(olerelay)("*");
1166 /* Allocate space for the referenced struct */
1168 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,_xsize(tdesc->u.lptdesc));
1171 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, (LPDWORD)*arg, buf);
1173 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, arg, buf);
1176 /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
1178 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
1181 hres = _unmarshal_interface(buf,&IID_IUnknown,(LPUNKNOWN*)arg);
1183 TRACE_(olerelay)("unk(%p)",arg);
1188 hres = _unmarshal_interface(buf,&IID_IDispatch,(LPUNKNOWN*)arg);
1190 TRACE_(olerelay)("idisp(%p)",arg);
1193 if (debugout) TRACE_(olerelay)("<void>");
1195 case VT_USERDEFINED: {
1199 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
1201 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
1204 hres = ITypeInfo_GetTypeAttr(tinfo2,&tattr);
1206 ERR("Could not get typeattr in VT_USERDEFINED.\n");
1208 switch (tattr->typekind) {
1209 case TKIND_DISPATCH:
1210 case TKIND_INTERFACE:
1212 hres = _unmarshal_interface(buf,&(tattr->guid),(LPUNKNOWN*)arg);
1214 case TKIND_RECORD: {
1218 *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,tattr->cbSizeInstance);
1220 if (debugout) TRACE_(olerelay)("{");
1221 for (i=0;i<tattr->cVars;i++) {
1224 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
1226 ERR("Could not get vardesc of %d\n",i);
1229 hres = deserialize_param(
1234 &vdesc->elemdescVar.tdesc,
1235 (DWORD*)(((LPBYTE)*arg)+vdesc->u.oInst),
1238 if (debugout && (i<tattr->cVars-1)) TRACE_(olerelay)(",");
1240 if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
1241 memcpy(&(buf->iid),(LPBYTE)*arg,sizeof(buf->iid));
1242 if (debugout) TRACE_(olerelay)("}");
1246 ERR("Unhandled typekind %d\n",tattr->typekind);
1252 ERR("failed to stuballoc in TKIND_RECORD.\n");
1253 ITypeInfo_Release(tinfo2);
1257 /* arg is pointing to the start of the array. */
1258 ARRAYDESC *adesc = tdesc->u.lpadesc;
1261 if (adesc->cDims > 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
1262 for (i=0;i<adesc->cDims;i++)
1263 arrsize *= adesc->rgbounds[i].cElements;
1264 for (i=0;i<arrsize;i++)
1271 (DWORD*)((LPBYTE)(arg)+i*_xsize(&adesc->tdescElem)),
1277 ERR("No handler for VT type %d!\n",tdesc->vt);
1284 deserialize_LPVOID_ptr(
1296 if ((tdesc->vt != VT_PTR) ||
1297 (tdesc->u.lptdesc->vt != VT_PTR) ||
1298 (tdesc->u.lptdesc->u.lptdesc->vt != VT_VOID)
1300 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
1304 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(LPVOID));
1306 hres = xbuf_get(buf, (LPVOID)&cookie, sizeof(cookie));
1309 if (cookie != 0x42424242) {
1311 if (debugout) TRACE_(olerelay)("<lpvoid NULL>");
1316 hres = _unmarshal_interface(buf,&buf->iid,(LPUNKNOWN*)*arg);
1318 FIXME("_unmarshal_interface of %s , %p failed with %lx\n", debugstr_guid(&buf->iid), (LPUNKNOWN*)*arg, hres);
1322 if (debugout) TRACE_(olerelay)("ppv(%p)",(LPVOID)*arg);
1327 deserialize_DISPPARAM_ptr(
1341 if ((tdesc->vt != VT_PTR) || (tdesc->u.lptdesc->vt != VT_USERDEFINED)) {
1342 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
1346 hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
1351 if (debugout) TRACE_(olerelay)("<DISPPARAMS NULL>");
1356 *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPPARAMS));
1357 disps = (DISPPARAMS*)*arg;
1360 hres = xbuf_get(buf, (LPBYTE)&disps->cArgs, sizeof(disps->cArgs));
1364 disps->rgvarg = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(VARIANT)*disps->cArgs);
1365 if (debugout) TRACE_(olerelay)("D{");
1366 for (i=0; i< disps->cArgs; i++) {
1369 vdesc.vt = VT_VARIANT;
1370 hres = deserialize_param(
1376 (DWORD*)(disps->rgvarg+i),
1380 if (debugout) TRACE_(olerelay)("}{");
1381 hres = xbuf_get(buf, (LPBYTE)&disps->cNamedArgs, sizeof(disps->cNamedArgs));
1384 if (disps->cNamedArgs) {
1386 disps->rgdispidNamedArgs = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPID)*disps->cNamedArgs);
1387 for (i=0; i< disps->cNamedArgs; i++) {
1391 hres = deserialize_param(
1397 (DWORD*)(disps->rgdispidNamedArgs+i),
1400 if (debugout && i<(disps->cNamedArgs-1)) TRACE_(olerelay)(",");
1403 if (debugout) TRACE_(olerelay)("}");
1407 /* Searches function, also in inherited interfaces */
1410 ITypeInfo *tinfo, int iMethod, FUNCDESC **fdesc, BSTR *iname, BSTR *fname)
1415 if (fname) *fname = NULL;
1416 if (iname) *iname = NULL;
1419 hres = ITypeInfo_GetFuncDesc(tinfo, i, fdesc);
1425 hres = ITypeInfo_GetTypeAttr(tinfo, &attr);
1427 ERR("GetTypeAttr failed with %lx\n",hres);
1430 /* Not found, so look in inherited ifaces. */
1431 for (j=0;j<attr->cImplTypes;j++) {
1432 hres = ITypeInfo_GetRefTypeOfImplType(tinfo, j, &href);
1434 ERR("Did not find a reftype for interface offset %d?\n",j);
1437 hres = ITypeInfo_GetRefTypeInfo(tinfo, href, &tinfo2);
1439 ERR("Did not find a typeinfo for reftype %ld?\n",href);
1442 hres = _get_funcdesc(tinfo2,iMethod,fdesc,iname,fname);
1443 ITypeInfo_Release(tinfo2);
1444 if (!hres) return S_OK;
1448 if (((*fdesc)->oVft/4) == iMethod) {
1450 ITypeInfo_GetDocumentation(tinfo,(*fdesc)->memid,fname,NULL,NULL,NULL);
1452 ITypeInfo_GetDocumentation(tinfo,-1,iname,NULL,NULL,NULL);
1460 xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */)
1462 DWORD *args = ((DWORD*)&tpinfo)+1, *xargs;
1465 int i, relaydeb = TRACE_ON(olerelay);
1472 int is_idispatch_getidsofnames = 0;
1474 EnterCriticalSection(&tpinfo->crit);
1476 hres = _get_funcdesc(tpinfo->tinfo,method,&fdesc,&iname,&fname);
1478 ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method);
1479 LeaveCriticalSection(&tpinfo->crit);
1483 if (!tpinfo->chanbuf)
1485 WARN("Tried to use disconnected proxy\n");
1486 LeaveCriticalSection(&tpinfo->crit);
1487 return RPC_E_DISCONNECTED;
1491 TRACE_(olerelay)("->");
1493 TRACE_(olerelay)("%s:",relaystr(iname));
1495 TRACE_(olerelay)("%s(%d)",relaystr(fname),method);
1497 TRACE_(olerelay)("%d",method);
1498 TRACE_(olerelay)("(");
1500 if (iname && fname && !lstrcmpW(iname,IDispatchW) && !lstrcmpW(fname,GetIDsOfNamesW))
1501 is_idispatch_getidsofnames = 1;
1503 if (iname) SysFreeString(iname);
1504 if (fname) SysFreeString(fname);
1506 memset(&buf,0,sizeof(buf));
1507 buf.iid = IID_IUnknown;
1509 /* Special IDispatch::GetIDsOfNames() serializer */
1510 if (is_idispatch_getidsofnames) {
1511 hres = serialize_IDispatch_GetIDsOfNames(TRUE,relaydeb,args,&buf);
1513 FIXME("serialize of IDispatch::GetIDsOfNames failed!\n");
1516 goto afterserialize;
1519 /* special QueryInterface serialize */
1521 xbuf_add(&buf,(LPBYTE)args[0],sizeof(IID));
1522 if (relaydeb) TRACE_(olerelay)("riid=%s,[out])",debugstr_guid((REFIID)args[0]));
1523 goto afterserialize;
1526 /* normal typelib driven serializing */
1528 /* Need them for hack below */
1529 memset(names,0,sizeof(names));
1530 if (ITypeInfo_GetNames(tpinfo->tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames))
1532 if (nrofnames > sizeof(names)/sizeof(names[0]))
1533 ERR("Need more names!\n");
1536 for (i=0;i<fdesc->cParams;i++) {
1537 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1538 BOOL isserialized = FALSE;
1540 if (i) TRACE_(olerelay)(",");
1541 if (i+1<nrofnames && names[i+1])
1542 TRACE_(olerelay)("%s=",relaystr(names[i+1]));
1544 /* No need to marshal other data than FIN and any VT_PTR. */
1545 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN) && (elem->tdesc.vt != VT_PTR)) {
1546 xargs+=_argsize(elem->tdesc.vt);
1547 if (relaydeb) TRACE_(olerelay)("[out]");
1550 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1551 /* If the parameter is 'riid', we use it as interface IID
1552 * for a later ppvObject serialization.
1554 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1556 /* DISPPARAMS* needs special serializer */
1557 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1558 hres = serialize_DISPPARAM_ptr(
1560 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1567 isserialized = TRUE;
1569 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1570 hres = serialize_LPVOID_ptr(
1572 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1580 isserialized = TRUE;
1584 hres = serialize_param(
1586 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1595 ERR("Failed to serialize param, hres %lx\n",hres);
1598 xargs+=_argsize(elem->tdesc.vt);
1600 if (relaydeb) TRACE_(olerelay)(")");
1603 memset(&msg,0,sizeof(msg));
1604 msg.cbBuffer = buf.curoff;
1605 msg.iMethod = method;
1606 hres = IRpcChannelBuffer_GetBuffer(tpinfo->chanbuf,&msg,&(tpinfo->iid));
1608 ERR("RpcChannelBuffer GetBuffer failed, %lx\n",hres);
1609 LeaveCriticalSection(&tpinfo->crit);
1612 memcpy(msg.Buffer,buf.base,buf.curoff);
1613 if (relaydeb) TRACE_(olerelay)("\n");
1614 hres = IRpcChannelBuffer_SendReceive(tpinfo->chanbuf,&msg,&status);
1616 ERR("RpcChannelBuffer SendReceive failed, %lx\n",hres);
1617 LeaveCriticalSection(&tpinfo->crit);
1621 if (relaydeb) TRACE_(olerelay)(" = %08lx (",status);
1623 buf.base = HeapReAlloc(GetProcessHeap(),0,buf.base,msg.cbBuffer);
1625 buf.base = HeapAlloc(GetProcessHeap(),0,msg.cbBuffer);
1626 buf.size = msg.cbBuffer;
1627 memcpy(buf.base,msg.Buffer,buf.size);
1630 /* Special IDispatch::GetIDsOfNames() deserializer */
1631 if (is_idispatch_getidsofnames) {
1632 hres = deserialize_IDispatch_GetIDsOfNames(FALSE,relaydeb,args,&buf);
1634 FIXME("deserialize of IDispatch::GetIDsOfNames failed!\n");
1637 goto after_deserialize;
1639 /* Special QueryInterface deserializer */
1641 _unmarshal_interface(&buf,(REFIID)args[0],(LPUNKNOWN*)args[1]);
1642 if (relaydeb) TRACE_(olerelay)("[in],%p",*((DWORD**)args[1]));
1643 goto after_deserialize;
1646 /* generic deserializer using typelib description */
1648 for (i=0;i<fdesc->cParams;i++) {
1649 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1650 BOOL isdeserialized = FALSE;
1653 if (i) TRACE_(olerelay)(",");
1654 if (i+1<nrofnames && names[i+1]) TRACE_(olerelay)("%s=",relaystr(names[i+1]));
1656 /* No need to marshal other data than FOUT and any VT_PTR */
1657 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT) && (elem->tdesc.vt != VT_PTR)) {
1658 xargs += _argsize(elem->tdesc.vt);
1659 if (relaydeb) TRACE_(olerelay)("[in]");
1662 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1663 /* If the parameter is 'riid', we use it as interface IID
1664 * for a later ppvObject serialization.
1666 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1668 /* deserialize DISPPARAM */
1669 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1670 hres = deserialize_DISPPARAM_ptr(
1672 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1680 ERR("Failed to deserialize DISPPARAM*, hres %lx\n",hres);
1683 isdeserialized = TRUE;
1685 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1686 hres = deserialize_LPVOID_ptr(
1688 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1696 isdeserialized = TRUE;
1699 if (!isdeserialized)
1700 hres = deserialize_param(
1702 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1710 ERR("Failed to unmarshall param, hres %lx\n",hres);
1714 xargs += _argsize(elem->tdesc.vt);
1717 if (relaydeb) TRACE_(olerelay)(")\n");
1718 HeapFree(GetProcessHeap(),0,buf.base);
1720 LeaveCriticalSection(&tpinfo->crit);
1725 HRESULT WINAPI ProxyIUnknown_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
1727 TMProxyImpl *proxy = (TMProxyImpl *)iface;
1729 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
1731 if (proxy->outerunknown)
1732 return IUnknown_QueryInterface(proxy->outerunknown, riid, ppv);
1734 FIXME("No interface\n");
1735 return E_NOINTERFACE;
1738 ULONG WINAPI ProxyIUnknown_AddRef(IUnknown *iface)
1740 TMProxyImpl *proxy = (TMProxyImpl *)iface;
1744 if (proxy->outerunknown)
1745 return IUnknown_AddRef(proxy->outerunknown);
1747 return 2; /* FIXME */
1750 ULONG WINAPI ProxyIUnknown_Release(IUnknown *iface)
1752 TMProxyImpl *proxy = (TMProxyImpl *)iface;
1756 if (proxy->outerunknown)
1757 return IUnknown_Release(proxy->outerunknown);
1759 return 1; /* FIXME */
1762 static HRESULT WINAPI
1763 PSFacBuf_CreateProxy(
1764 LPPSFACTORYBUFFER iface, IUnknown* pUnkOuter, REFIID riid,
1765 IRpcProxyBuffer **ppProxy, LPVOID *ppv)
1773 TRACE("(...%s...)\n",debugstr_guid(riid));
1774 hres = _get_typeinfo_for_iid(riid,&tinfo);
1776 ERR("No typeinfo for %s?\n",debugstr_guid(riid));
1779 nroffuncs = _nroffuncs(tinfo);
1780 proxy = CoTaskMemAlloc(sizeof(TMProxyImpl));
1781 if (!proxy) return E_OUTOFMEMORY;
1783 assert(sizeof(TMAsmProxy) == 12);
1785 proxy->outerunknown = pUnkOuter;
1786 proxy->asmstubs = VirtualAlloc(NULL, sizeof(TMAsmProxy) * nroffuncs, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
1787 if (!proxy->asmstubs) {
1788 ERR("Could not commit pages for proxy thunks\n");
1789 CoTaskMemFree(proxy);
1790 return E_OUTOFMEMORY;
1793 InitializeCriticalSection(&proxy->crit);
1795 proxy->lpvtbl = HeapAlloc(GetProcessHeap(),0,sizeof(LPBYTE)*nroffuncs);
1796 for (i=0;i<nroffuncs;i++) {
1797 TMAsmProxy *xasm = proxy->asmstubs+i;
1801 proxy->lpvtbl[i] = ProxyIUnknown_QueryInterface;
1804 proxy->lpvtbl[i] = ProxyIUnknown_AddRef;
1807 proxy->lpvtbl[i] = ProxyIUnknown_Release;
1811 /* nrofargs without This */
1813 hres = _get_funcdesc(tinfo,i,&fdesc,NULL,NULL);
1815 ERR("GetFuncDesc %lx should not fail here.\n",hres);
1818 /* some args take more than 4 byte on the stack */
1820 for (j=0;j<fdesc->cParams;j++)
1821 nrofargs += _argsize(fdesc->lprgelemdescParam[j].tdesc.vt);
1823 if (fdesc->callconv != CC_STDCALL) {
1824 ERR("calling convention is not stdcall????\n");
1827 /* popl %eax - return ptr
1834 * arg3 arg2 arg1 <method> <returnptr>
1836 xasm->popleax = 0x58;
1837 xasm->pushlval = 0x6a;
1839 xasm->pushleax = 0x50;
1840 xasm->lcall = 0xe8; /* relative jump */
1841 xasm->xcall = (DWORD)xCall;
1842 xasm->xcall -= (DWORD)&(xasm->lret);
1844 xasm->bytestopop= (nrofargs+2)*4; /* pop args, This, iMethod */
1845 proxy->lpvtbl[i] = xasm;
1850 proxy->lpvtbl2 = &tmproxyvtable;
1851 /* 1 reference for the proxy and 1 for the object */
1853 proxy->tinfo = tinfo;
1854 memcpy(&proxy->iid,riid,sizeof(*riid));
1856 *ppv = (LPVOID)proxy;
1857 *ppProxy = (IRpcProxyBuffer *)&(proxy->lpvtbl2);
1861 typedef struct _TMStubImpl {
1862 IRpcStubBufferVtbl *lpvtbl;
1870 static HRESULT WINAPI
1871 TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface, REFIID riid, LPVOID *ppv)
1873 if (IsEqualIID(riid,&IID_IRpcStubBuffer)||IsEqualIID(riid,&IID_IUnknown)){
1874 *ppv = (LPVOID)iface;
1875 IRpcStubBuffer_AddRef(iface);
1878 FIXME("%s, not supported IID.\n",debugstr_guid(riid));
1879 return E_NOINTERFACE;
1883 TMStubImpl_AddRef(LPRPCSTUBBUFFER iface)
1885 TMStubImpl *This = (TMStubImpl *)iface;
1886 ULONG refCount = InterlockedIncrement(&This->ref);
1888 TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
1894 TMStubImpl_Release(LPRPCSTUBBUFFER iface)
1896 TMStubImpl *This = (TMStubImpl *)iface;
1897 ULONG refCount = InterlockedDecrement(&This->ref);
1899 TRACE("(%p)->(ref before=%lu)\n", This, refCount + 1);
1903 IRpcStubBuffer_Disconnect(iface);
1904 CoTaskMemFree(This);
1909 static HRESULT WINAPI
1910 TMStubImpl_Connect(LPRPCSTUBBUFFER iface, LPUNKNOWN pUnkServer)
1912 TMStubImpl *This = (TMStubImpl *)iface;
1914 TRACE("(%p)->(%p)\n", This, pUnkServer);
1916 IUnknown_AddRef(pUnkServer);
1917 This->pUnk = pUnkServer;
1922 TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface)
1924 TMStubImpl *This = (TMStubImpl *)iface;
1926 TRACE("(%p)->()\n", This);
1928 IUnknown_Release(This->pUnk);
1933 static HRESULT WINAPI
1935 LPRPCSTUBBUFFER iface, RPCOLEMESSAGE* xmsg,IRpcChannelBuffer*rpcchanbuf)
1939 TMStubImpl *This = (TMStubImpl *)iface;
1941 DWORD *args, res, *xargs, nrofargs;
1945 BSTR fname = NULL,iname = NULL;
1946 BOOL is_idispatch_getidsofnames = 0;
1948 memset(&buf,0,sizeof(buf));
1949 buf.size = xmsg->cbBuffer;
1950 buf.base = xmsg->Buffer;
1952 buf.iid = IID_IUnknown;
1955 if (xmsg->iMethod == 0) { /* QI */
1957 /* in: IID, out: <iface> */
1959 xbuf_get(&buf,(LPBYTE)&xiid,sizeof(xiid));
1961 hres = _marshal_interface(&buf,&xiid,This->pUnk);
1962 xmsg->Buffer = buf.base; /* Might have been reallocated */
1963 xmsg->cbBuffer = buf.size;
1966 hres = _get_funcdesc(This->tinfo,xmsg->iMethod,&fdesc,&iname,&fname);
1968 ERR("GetFuncDesc on method %ld failed with %lx\n",xmsg->iMethod,hres);
1972 if (iname && fname && !lstrcmpW(iname, IDispatchW) && !lstrcmpW(fname, GetIDsOfNamesW))
1973 is_idispatch_getidsofnames = 1;
1975 if (iname) SysFreeString (iname);
1976 if (fname) SysFreeString (fname);
1978 /* Need them for hack below */
1979 memset(names,0,sizeof(names));
1980 ITypeInfo_GetNames(This->tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
1981 if (nrofnames > sizeof(names)/sizeof(names[0])) {
1982 ERR("Need more names!\n");
1985 /*dump_FUNCDESC(fdesc);*/
1987 for (i=0;i<fdesc->cParams;i++)
1988 nrofargs += _argsize(fdesc->lprgelemdescParam[i].tdesc.vt);
1989 args = HeapAlloc(GetProcessHeap(),0,(nrofargs+1)*sizeof(DWORD));
1990 if (!args) return E_OUTOFMEMORY;
1992 if (is_idispatch_getidsofnames) {
1993 hres = deserialize_IDispatch_GetIDsOfNames(TRUE,FALSE,args+1,&buf);
1995 FIXME("deserialize_IDispatch_GetIDsOfNames failed!\n");
1999 goto afterdeserialize;
2002 /* Allocate all stuff used by call. */
2004 for (i=0;i<fdesc->cParams;i++) {
2005 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
2006 BOOL isdeserialized = FALSE;
2008 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
2009 /* If the parameter is 'riid', we use it as interface IID
2010 * for a later ppvObject serialization.
2012 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
2014 /* deserialize DISPPARAM */
2015 if (!lstrcmpW(names[i+1],pdispparamsW)) {
2016 hres = deserialize_DISPPARAM_ptr(
2018 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
2026 ERR("Failed to deserialize DISPPARAM*, hres %lx\n",hres);
2029 isdeserialized = TRUE;
2031 if (!lstrcmpW(names[i+1],ppvObjectW)) {
2032 hres = deserialize_LPVOID_ptr(
2034 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
2042 isdeserialized = TRUE;
2045 if (!isdeserialized)
2046 hres = deserialize_param(
2048 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
2055 xargs += _argsize(elem->tdesc.vt);
2057 ERR("Failed to deserialize param %s, hres %lx\n",relaystr(names[i+1]),hres);
2062 hres = IUnknown_QueryInterface(This->pUnk,&(This->iid),(LPVOID*)&(args[0]));
2064 ERR("Does not support iface %s, returning %lx\n",debugstr_guid(&(This->iid)), hres);
2068 (*((FARPROC**)args[0]))[fdesc->oVft/4],
2073 IUnknown_Release((LPUNKNOWN)args[0]);
2076 /* special IDispatch::GetIDsOfNames serializer */
2077 if (is_idispatch_getidsofnames) {
2078 hres = serialize_IDispatch_GetIDsOfNames(FALSE,FALSE,args+1,&buf);
2080 FIXME("serialize of IDispatch::GetIDsOfNames failed!\n");
2083 goto afterserialize;
2086 for (i=0;i<fdesc->cParams;i++) {
2087 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
2088 BOOL isserialized = FALSE;
2090 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
2091 /* If the parameter is 'riid', we use it as interface IID
2092 * for a later ppvObject serialization.
2094 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
2096 /* DISPPARAMS* needs special serializer */
2097 if (!lstrcmpW(names[i+1],pdispparamsW)) {
2098 hres = serialize_DISPPARAM_ptr(
2100 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
2107 isserialized = TRUE;
2109 if (!lstrcmpW(names[i+1],ppvObjectW)) {
2110 hres = serialize_LPVOID_ptr(
2112 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
2120 isserialized = TRUE;
2124 hres = serialize_param(
2126 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
2133 xargs += _argsize(elem->tdesc.vt);
2135 ERR("Failed to stuballoc param, hres %lx\n",hres);
2140 /* might need to use IRpcChannelBuffer_GetBuffer ? */
2141 xmsg->cbBuffer = buf.curoff;
2142 xmsg->Buffer = buf.base;
2143 HeapFree(GetProcessHeap(),0,args);
2147 static LPRPCSTUBBUFFER WINAPI
2148 TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface, REFIID riid) {
2149 FIXME("Huh (%s)?\n",debugstr_guid(riid));
2154 TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface) {
2155 TMStubImpl *This = (TMStubImpl *)iface;
2157 return This->ref; /*FIXME? */
2160 static HRESULT WINAPI
2161 TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface, LPVOID *ppv) {
2166 TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface, LPVOID ppv) {
2170 IRpcStubBufferVtbl tmstubvtbl = {
2171 TMStubImpl_QueryInterface,
2175 TMStubImpl_Disconnect,
2177 TMStubImpl_IsIIDSupported,
2178 TMStubImpl_CountRefs,
2179 TMStubImpl_DebugServerQueryInterface,
2180 TMStubImpl_DebugServerRelease
2183 static HRESULT WINAPI
2184 PSFacBuf_CreateStub(
2185 LPPSFACTORYBUFFER iface, REFIID riid,IUnknown *pUnkServer,
2186 IRpcStubBuffer** ppStub
2192 TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub);
2193 hres = _get_typeinfo_for_iid(riid,&tinfo);
2195 ERR("No typeinfo for %s?\n",debugstr_guid(riid));
2198 stub = CoTaskMemAlloc(sizeof(TMStubImpl));
2200 return E_OUTOFMEMORY;
2201 stub->lpvtbl = &tmstubvtbl;
2203 stub->tinfo = tinfo;
2204 memcpy(&(stub->iid),riid,sizeof(*riid));
2205 hres = IRpcStubBuffer_Connect((LPRPCSTUBBUFFER)stub,pUnkServer);
2206 *ppStub = (LPRPCSTUBBUFFER)stub;
2207 TRACE("IRpcStubBuffer: %p\n", stub);
2209 ERR("Connect to pUnkServer failed?\n");
2213 static IPSFactoryBufferVtbl psfacbufvtbl = {
2214 PSFacBuf_QueryInterface,
2217 PSFacBuf_CreateProxy,
2221 /* This is the whole PSFactoryBuffer object, just the vtableptr */
2222 static IPSFactoryBufferVtbl *lppsfac = &psfacbufvtbl;
2224 /***********************************************************************
2225 * DllGetClassObject [OLE32.63]
2228 TypeLibFac_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
2230 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)) {
2234 return E_NOINTERFACE;