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 LPUNKNOWN newiface = NULL;
163 LPBYTE tempbuf = NULL;
164 IStream *pStm = NULL;
166 ULARGE_INTEGER newpos;
167 LARGE_INTEGER seekto;
173 /* this is valid, if for instance we serialize
174 * a VT_DISPATCH with NULL ptr which apparently
175 * can happen. S_OK to make sure we continue
178 ERR("pUnk is NULL?\n");
180 return xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
185 TRACE("...%s...\n",debugstr_guid(riid));
186 hres = IUnknown_QueryInterface(pUnk,riid,(LPVOID*)&newiface);
188 WARN("%p does not support iface %s\n",pUnk,debugstr_guid(riid));
192 hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
194 ERR("Stream create failed %lx\n",hres);
198 hres = CoMarshalInterface(pStm,riid,newiface,0,NULL,0);
200 ERR("Marshalling interface %s failed with %lx\n", debugstr_guid(riid), hres);
204 hres = IStream_Stat(pStm,&ststg,0);
206 ERR("Stream stat failed\n");
210 tempbuf = HeapAlloc(GetProcessHeap(), 0, ststg.cbSize.u.LowPart);
211 memset(&seekto,0,sizeof(seekto));
212 hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
214 ERR("Failed Seek %lx\n",hres);
218 hres = IStream_Read(pStm,tempbuf,ststg.cbSize.u.LowPart,&res);
220 ERR("Failed Read %lx\n",hres);
224 xsize = ststg.cbSize.u.LowPart;
225 xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
226 hres = xbuf_add(buf,tempbuf,ststg.cbSize.u.LowPart);
228 HeapFree(GetProcessHeap(),0,tempbuf);
229 IUnknown_Release(newiface);
230 IStream_Release(pStm);
236 xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
237 if (pStm) IUnknown_Release(pStm);
238 if (newiface) IUnknown_Release(newiface);
239 HeapFree(GetProcessHeap(), 0, tempbuf);
243 /********************* OLE Proxy/Stub Factory ********************************/
244 static HRESULT WINAPI
245 PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface, REFIID iid, LPVOID *ppv) {
246 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)||IsEqualIID(iid,&IID_IUnknown)) {
247 *ppv = (LPVOID)iface;
248 /* No ref counting, static class */
251 FIXME("(%s) unknown IID?\n",debugstr_guid(iid));
252 return E_NOINTERFACE;
255 static ULONG WINAPI PSFacBuf_AddRef(LPPSFACTORYBUFFER iface) { return 2; }
256 static ULONG WINAPI PSFacBuf_Release(LPPSFACTORYBUFFER iface) { return 1; }
259 _get_typeinfo_for_iid(REFIID riid, ITypeInfo**ti) {
262 char tlguid[200],typelibkey[300],interfacekey[300],ver[100];
265 DWORD tlguidlen, verlen, type, tlfnlen;
268 sprintf( interfacekey, "Interface\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\Typelib",
269 riid->Data1, riid->Data2, riid->Data3,
270 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
271 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7]
274 if (RegOpenKeyA(HKEY_CLASSES_ROOT,interfacekey,&ikey)) {
275 ERR("No %s key found.\n",interfacekey);
279 tlguidlen = sizeof(tlguid);
280 if (RegQueryValueExA(ikey,NULL,NULL,&type,tlguid,&tlguidlen)) {
281 ERR("Getting typelib guid failed.\n");
286 verlen = sizeof(ver);
287 if (RegQueryValueExA(ikey,"Version",NULL,&type,ver,&verlen)) {
288 ERR("Could not get version value?\n");
293 sprintf(typelibkey,"Typelib\\%s\\%s\\0\\win32",tlguid,ver);
294 tlfnlen = sizeof(tlfn);
295 if (RegQueryValueA(HKEY_CLASSES_ROOT,typelibkey,tlfn,&tlfnlen)) {
296 ERR("Could not get typelib fn?\n");
299 MultiByteToWideChar(CP_ACP, 0, tlfn, -1, tlfnW, -1);
300 hres = LoadTypeLib(tlfnW,&tl);
302 ERR("Failed to load typelib for %s, but it should be there.\n",debugstr_guid(riid));
305 hres = ITypeLib_GetTypeInfoOfGuid(tl,riid,ti);
307 ERR("typelib does not contain info for %s?\n",debugstr_guid(riid));
308 ITypeLib_Release(tl);
311 /* FIXME: do this? ITypeLib_Release(tl); */
315 /* Determine nr of functions. Since we use the toplevel interface and all
316 * inherited ones have lower numbers, we are ok to not to descent into
317 * the inheritance tree I think.
319 static int _nroffuncs(ITypeInfo *tinfo) {
326 hres = ITypeInfo_GetFuncDesc(tinfo,n,&fdesc);
329 if (fdesc->oVft/4 > max)
338 #include "pshpack1.h"
340 typedef struct _TMAsmProxy {
354 # error You need to implement stubless proxies for your architecture
357 typedef struct _TMProxyImpl {
359 IRpcProxyBufferVtbl *lpvtbl2;
362 TMAsmProxy *asmstubs;
364 IRpcChannelBuffer* chanbuf;
366 CRITICAL_SECTION crit;
367 IUnknown *outerunknown;
370 static HRESULT WINAPI
371 TMProxyImpl_QueryInterface(LPRPCPROXYBUFFER iface, REFIID riid, LPVOID *ppv)
374 if (IsEqualIID(riid,&IID_IUnknown)||IsEqualIID(riid,&IID_IRpcProxyBuffer)) {
375 *ppv = (LPVOID)iface;
376 IRpcProxyBuffer_AddRef(iface);
379 FIXME("no interface for %s\n",debugstr_guid(riid));
380 return E_NOINTERFACE;
384 TMProxyImpl_AddRef(LPRPCPROXYBUFFER iface)
386 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
387 ULONG refCount = InterlockedIncrement(&This->ref);
389 TRACE("(%p)->(ref before=%lu)\n",This, refCount - 1);
395 TMProxyImpl_Release(LPRPCPROXYBUFFER iface)
397 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
398 ULONG refCount = InterlockedDecrement(&This->ref);
400 TRACE("(%p)->(ref before=%lu)\n",This, refCount + 1);
404 DeleteCriticalSection(&This->crit);
405 if (This->chanbuf) IRpcChannelBuffer_Release(This->chanbuf);
406 VirtualFree(This->asmstubs, 0, MEM_RELEASE);
412 static HRESULT WINAPI
414 LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer)
416 ICOM_THIS_MULTI(TMProxyImpl, lpvtbl2, iface);
418 TRACE("(%p)\n", pRpcChannelBuffer);
420 EnterCriticalSection(&This->crit);
422 IRpcChannelBuffer_AddRef(pRpcChannelBuffer);
423 This->chanbuf = pRpcChannelBuffer;
425 LeaveCriticalSection(&This->crit);
431 TMProxyImpl_Disconnect(LPRPCPROXYBUFFER iface)
433 ICOM_THIS_MULTI(TMProxyImpl, lpvtbl2, iface);
437 EnterCriticalSection(&This->crit);
439 IRpcChannelBuffer_Release(This->chanbuf);
440 This->chanbuf = NULL;
442 LeaveCriticalSection(&This->crit);
446 static IRpcProxyBufferVtbl tmproxyvtable = {
447 TMProxyImpl_QueryInterface,
451 TMProxyImpl_Disconnect
454 /* how much space do we use on stack in DWORD steps. */
459 return sizeof(DATE)/sizeof(DWORD);
461 return (sizeof(VARIANT)+3)/sizeof(DWORD);
468 _xsize(TYPEDESC *td) {
473 return sizeof(VARIANT)+3;
476 ARRAYDESC *adesc = td->u.lpadesc;
478 for (i=0;i<adesc->cDims;i++)
479 arrsize *= adesc->rgbounds[i].cElements;
480 return arrsize*_xsize(&adesc->tdescElem);
505 TRACE("(tdesc.vt %d)\n",tdesc->vt);
508 case VT_EMPTY: /* nothing. empty variant for instance */
517 if (debugout) TRACE_(olerelay)("%lx",*arg);
519 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
524 if (debugout) TRACE_(olerelay)("%04lx",*arg & 0xffff);
526 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
531 if (debugout) TRACE_(olerelay)("%02lx",*arg & 0xff);
533 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
537 if (debugout) TRACE_(olerelay)("&0x%lx",*arg);
539 hres = xbuf_add(buf,(LPBYTE)(DWORD*)*arg,sizeof(DWORD));
540 /* do not dealloc at this time */
544 VARIANT *vt = (VARIANT*)arg;
545 DWORD vttype = V_VT(vt);
547 if (debugout) TRACE_(olerelay)("Vt(%ld)(",vttype);
550 hres = xbuf_add(buf,(LPBYTE)&vttype,sizeof(vttype));
551 if (hres) return hres;
553 /* need to recurse since we need to free the stuff */
554 hres = serialize_param(tinfo,writeit,debugout,dealloc,&tdesc2,&(V_I4(vt)),buf);
555 if (debugout) TRACE_(olerelay)(")");
558 case VT_BSTR|VT_BYREF: {
559 if (debugout) TRACE_(olerelay)("[byref]'%s'", *(BSTR*)*arg ? relaystr(*((BSTR*)*arg)) : "<bstr NULL>");
561 /* ptr to ptr to magic widestring, basically */
562 BSTR *bstr = (BSTR *) *arg;
564 /* -1 means "null string" which is equivalent to empty string */
566 xbuf_add(buf, (LPBYTE)&fakelen,4);
568 /* BSTRs store the length behind the first character */
569 DWORD *len = ((DWORD *)(*bstr))-1;
570 hres = xbuf_add(buf, (LPBYTE) len, *len + 4);
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>");
592 hres = xbuf_add(buf,(LPBYTE)&fakelen,4);
596 DWORD *bstr = ((DWORD*)(*arg))-1;
598 hres = xbuf_add(buf,(LPBYTE)bstr,bstr[0]+4);
605 SysFreeString((BSTR)*arg);
611 if (debugout) TRACE_(olerelay)("*");
612 /* Write always, so the other side knows when it gets a NULL pointer.
614 cookie = *arg ? 0x42424242 : 0;
615 hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
619 if (debugout) TRACE_(olerelay)("NULL");
622 hres = serialize_param(tinfo,writeit,debugout,dealloc,tdesc->u.lptdesc,(DWORD*)*arg,buf);
623 if (dealloc) HeapFree(GetProcessHeap(),0,(LPVOID)arg);
627 if (debugout) TRACE_(olerelay)("unk(0x%lx)",*arg);
629 hres = _marshal_interface(buf,&IID_IUnknown,(LPUNKNOWN)*arg);
632 if (debugout) TRACE_(olerelay)("idisp(0x%lx)",*arg);
634 hres = _marshal_interface(buf,&IID_IDispatch,(LPUNKNOWN)*arg);
637 if (debugout) TRACE_(olerelay)("<void>");
639 case VT_USERDEFINED: {
643 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
645 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
648 ITypeInfo_GetTypeAttr(tinfo2,&tattr);
649 switch (tattr->typekind) {
651 case TKIND_INTERFACE:
653 hres=_marshal_interface(buf,&(tattr->guid),(LPUNKNOWN)arg);
657 if (debugout) TRACE_(olerelay)("{");
658 for (i=0;i<tattr->cVars;i++) {
663 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
665 ERR("Could not get vardesc of %d\n",i);
668 /* Need them for hack below */
670 memset(names,0,sizeof(names));
671 hres = ITypeInfo_GetNames(tinfo2,vdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
672 if (nrofnames > sizeof(names)/sizeof(names[0])) {
673 ERR("Need more names!\n");
675 if (!hres && debugout)
676 TRACE_(olerelay)("%s=",relaystr(names[0]));
678 elem2 = &vdesc->elemdescVar;
679 tdesc2 = &elem2->tdesc;
680 hres = serialize_param(
686 (DWORD*)(((LPBYTE)arg)+vdesc->u.oInst),
689 ITypeInfo_ReleaseVarDesc(tinfo2, vdesc);
692 if (debugout && (i<(tattr->cVars-1)))
693 TRACE_(olerelay)(",");
695 if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
696 memcpy(&(buf->iid),arg,sizeof(buf->iid));
697 if (debugout) TRACE_(olerelay)("}");
701 FIXME("Unhandled typekind %d\n",tattr->typekind);
705 ITypeInfo_Release(tinfo2);
709 ARRAYDESC *adesc = tdesc->u.lpadesc;
712 if (debugout) TRACE_(olerelay)("carr");
713 for (i=0;i<adesc->cDims;i++) {
714 if (debugout) TRACE_(olerelay)("[%ld]",adesc->rgbounds[i].cElements);
715 arrsize *= adesc->rgbounds[i].cElements;
717 if (debugout) TRACE_(olerelay)("(vt %d)",adesc->tdescElem.vt);
718 if (debugout) TRACE_(olerelay)("[");
719 for (i=0;i<arrsize;i++) {
720 hres = serialize_param(tinfo, writeit, debugout, dealloc, &adesc->tdescElem, (DWORD*)((LPBYTE)arg+i*_xsize(&adesc->tdescElem)), buf);
723 if (debugout && (i<arrsize-1)) TRACE_(olerelay)(",");
725 if (debugout) TRACE_(olerelay)("]");
729 ERR("Unhandled marshal type %d.\n",tdesc->vt);
735 * HRESULT GetIDsOfNames(
736 * [in] REFIID riid, args[1]
737 * [in, size_is(cNames)] LPOLESTR *rgszNames, args[2]
738 * [in] UINT cNames, args[3]
739 * [in] LCID lcid, args[4]
740 * [out, size_is(cNames)] DISPID *rgDispId); args[5]
745 * LPOLESTR rgszNames[cNames];
746 * DWORD bytestrlen (incl 0)
747 * BYTE data[bytestrlen] (incl 0)
751 serialize_IDispatch_GetIDsOfNames(
758 DWORD cNames = args[2];
759 LPOLESTR *rgszNames = (LPOLESTR*)args[1];
763 if (debugout) TRACE_(olerelay)("riid=%s,",debugstr_guid((REFIID)args[0]));
764 hres = xbuf_add(buf, (LPBYTE)args[0], sizeof(IID));
766 FIXME("serialize of IID failed.\n");
769 if (debugout) TRACE_(olerelay)("cNames=%ld,",cNames);
770 hres = xbuf_add(buf, (LPBYTE)&cNames, sizeof(DWORD));
772 FIXME("serialize of cNames failed.\n");
775 if (debugout) TRACE_(olerelay)("rgszNames=[");
776 for (i=0;i<cNames;i++) {
777 DWORD len = 2*(lstrlenW(rgszNames[i])+1);
779 if (debugout) TRACE_(olerelay)("%s,",relaystr(rgszNames[i]));
780 hres = xbuf_add(buf, (LPBYTE)&len, sizeof(DWORD));
782 FIXME("serialize of len failed.\n");
785 hres = xbuf_add(buf, (LPBYTE)rgszNames[i], len);
787 FIXME("serialize of rgszNames[i] failed.\n");
791 if (debugout) TRACE_(olerelay)("],lcid=%04lx)",args[3]);
792 hres = xbuf_add(buf, (LPBYTE)&args[3], sizeof(DWORD));
794 FIXME("serialize of lcid failed.\n");
798 DISPID *rgDispId = (DISPID*)args[4];
800 hres = xbuf_add(buf, (LPBYTE)rgDispId, sizeof(DISPID) * cNames);
802 FIXME("serialize of rgDispId failed.\n");
806 TRACE_(olerelay)("riid=[in],rgszNames=[in],cNames=[in],rgDispId=[");
807 for (i=0;i<cNames;i++)
808 TRACE_(olerelay)("%08lx,",rgDispId[i]);
809 TRACE_(olerelay)("])");
811 HeapFree(GetProcessHeap(),0,(IID*)args[0]);
812 rgszNames = (LPOLESTR*)args[1];
813 for (i=0;i<cNames;i++) HeapFree(GetProcessHeap(),0,rgszNames[i]);
814 HeapFree(GetProcessHeap(),0,rgszNames);
815 HeapFree(GetProcessHeap(),0,rgDispId);
821 deserialize_IDispatch_GetIDsOfNames(
833 args[0] = (DWORD)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IID));
834 if (!args[0]) return E_FAIL;
835 hres = xbuf_get(buf, (LPBYTE)args[0], sizeof(IID));
837 FIXME("deserialize of IID failed.\n");
840 if (debugout) TRACE_(olerelay)("riid=%s,",debugstr_guid((REFIID)args[0]));
842 hres = xbuf_get(buf, (LPBYTE)&cNames, sizeof(DWORD));
844 FIXME("deserialize of cNames failed.\n");
848 if (debugout) TRACE_(olerelay)("cNames=%ld,",cNames);
849 if (debugout) TRACE_(olerelay)("rgszNames=[");
850 rgszNames = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(LPOLESTR) * cNames);
851 if (!rgszNames) return E_FAIL;
852 args[1] = (DWORD)rgszNames;
853 for (i=0;i<cNames;i++) {
856 hres = xbuf_get(buf, (LPBYTE)&len, sizeof(DWORD));
858 FIXME("serialize of len failed.\n");
861 rgszNames[i] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
863 FIXME("heapalloc of %ld bytes failed\n", len);
866 hres = xbuf_get(buf, (LPBYTE)rgszNames[i], len);
868 FIXME("serialize of rgszNames[i] failed.\n");
871 if (debugout) TRACE_(olerelay)("%s,",relaystr(rgszNames[i]));
873 hres = xbuf_get(buf, (LPBYTE)&args[3], sizeof(DWORD));
875 FIXME("deserialize of lcid failed.\n");
878 if (debugout) TRACE_(olerelay)("],lcid=%04lx,rgDispId=[out])",args[3]);
879 args[4] = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPID) * cNames);
881 hres = xbuf_get(buf, (LPBYTE)args[4], sizeof(DISPID) * args[2]);
883 FIXME("serialize of rgDispId failed.\n");
887 TRACE_(olerelay)("dispid=[");
888 for (i=0;i<args[2];i++)
889 TRACE_(olerelay)("%08lx,",((DISPID*)args[4])[i]);
890 TRACE_(olerelay)("])");
897 serialize_LPVOID_ptr(
909 if ((tdesc->vt != VT_PTR) ||
910 (tdesc->u.lptdesc->vt != VT_PTR) ||
911 (tdesc->u.lptdesc->u.lptdesc->vt != VT_VOID)
913 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
916 cookie = (*(DWORD*)*arg) ? 0x42424242: 0x0;
918 hres = xbuf_add(buf, (LPVOID)&cookie, sizeof(cookie));
922 if (!*(DWORD*)*arg) {
923 if (debugout) TRACE_(olerelay)("<lpvoid NULL>");
927 TRACE_(olerelay)("ppv(%p)",*(LPUNKNOWN*)*arg);
929 hres = _marshal_interface(buf,&(buf->iid),*(LPUNKNOWN*)*arg);
934 HeapFree(GetProcessHeap(),0,(LPVOID)*arg);
939 serialize_DISPPARAM_ptr(
953 if ((tdesc->vt != VT_PTR) || (tdesc->u.lptdesc->vt != VT_USERDEFINED)) {
954 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
958 cookie = *arg ? 0x42424242 : 0x0;
960 hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
965 if (debugout) TRACE_(olerelay)("<DISPPARAMS NULL>");
968 disp = (DISPPARAMS*)*arg;
970 hres = xbuf_add(buf,(LPBYTE)&disp->cArgs,sizeof(disp->cArgs));
974 if (debugout) TRACE_(olerelay)("D{");
975 for (i=0;i<disp->cArgs;i++) {
978 vtdesc.vt = VT_VARIANT;
985 (DWORD*)(disp->rgvarg+i),
988 if (debugout && (i<disp->cArgs-1))
989 TRACE_(olerelay)(",");
992 HeapFree(GetProcessHeap(),0,disp->rgvarg);
994 hres = xbuf_add(buf,(LPBYTE)&disp->cNamedArgs,sizeof(disp->cNamedArgs));
998 if (debugout) TRACE_(olerelay)("}{");
999 for (i=0;i<disp->cNamedArgs;i++) {
1002 vtdesc.vt = VT_UINT;
1009 (DWORD*)(disp->rgdispidNamedArgs+i),
1012 if (debugout && (i<disp->cNamedArgs-1))
1013 TRACE_(olerelay)(",");
1015 if (debugout) TRACE_(olerelay)("}");
1017 HeapFree(GetProcessHeap(),0,disp->rgdispidNamedArgs);
1018 HeapFree(GetProcessHeap(),0,disp);
1033 HRESULT hres = S_OK;
1035 TRACE("vt %d at %p\n",tdesc->vt,arg);
1038 switch (tdesc->vt) {
1040 if (debugout) TRACE_(olerelay)("<empty>");
1043 if (debugout) TRACE_(olerelay)("<null>");
1046 VARIANT *vt = (VARIANT*)arg;
1051 hres = xbuf_get(buf,(LPBYTE)&vttype,sizeof(vttype));
1053 FIXME("vt type not read?\n");
1056 memset(&tdesc2,0,sizeof(tdesc2));
1059 if (debugout) TRACE_(olerelay)("Vt(%ld)(",vttype);
1060 hres = deserialize_param(tinfo, readit, debugout, alloc, &tdesc2, &(V_I4(vt)), buf);
1061 TRACE_(olerelay)(")");
1075 hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
1076 if (hres) ERR("Failed to read integer 4 byte\n");
1078 if (debugout) TRACE_(olerelay)("%lx",*arg);
1084 hres = xbuf_get(buf,(LPBYTE)&x,sizeof(DWORD));
1085 if (hres) ERR("Failed to read integer 4 byte\n");
1088 if (debugout) TRACE_(olerelay)("%04lx",*arg & 0xffff);
1094 hres = xbuf_get(buf,(LPBYTE)&x,sizeof(DWORD));
1095 if (hres) ERR("Failed to read integer 4 byte\n");
1098 if (debugout) TRACE_(olerelay)("%02lx",*arg & 0xff);
1100 case VT_I4|VT_BYREF:
1103 *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
1105 hres = xbuf_get(buf,(LPBYTE)*arg,sizeof(DWORD));
1106 if (hres) ERR("Failed to read integer 4 byte\n");
1108 if (debugout) TRACE_(olerelay)("&0x%lx",*(DWORD*)*arg);
1110 case VT_BSTR|VT_BYREF: {
1111 BSTR **bstr = (BSTR **)arg;
1116 hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
1118 ERR("failed to read bstr klen\n");
1122 *bstr = CoTaskMemAlloc(sizeof(BSTR *));
1124 if (debugout) TRACE_(olerelay)("<bstr NULL>");
1126 str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len+sizeof(WCHAR));
1127 hres = xbuf_get(buf,(LPBYTE)str,len);
1129 ERR("Failed to read BSTR.\n");
1132 *bstr = CoTaskMemAlloc(sizeof(BSTR *));
1133 **bstr = SysAllocStringLen(str,len);
1134 if (debugout) TRACE_(olerelay)("%s",relaystr(str));
1135 HeapFree(GetProcessHeap(),0,str);
1147 hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
1149 ERR("failed to read bstr klen\n");
1154 if (debugout) TRACE_(olerelay)("<bstr NULL>");
1156 str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len+sizeof(WCHAR));
1157 hres = xbuf_get(buf,(LPBYTE)str,len);
1159 ERR("Failed to read BSTR.\n");
1162 *arg = (DWORD)SysAllocStringLen(str,len);
1163 if (debugout) TRACE_(olerelay)("%s",relaystr(str));
1164 HeapFree(GetProcessHeap(),0,str);
1175 derefhere = (tdesc->u.lptdesc->vt != VT_USERDEFINED);
1176 /* read it in all cases, we need to know if we have
1177 * NULL pointer or not.
1179 hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
1181 ERR("Failed to load pointer cookie.\n");
1184 if (cookie != 0x42424242) {
1185 /* we read a NULL ptr from the remote side */
1186 if (debugout) TRACE_(olerelay)("NULL");
1190 if (debugout) TRACE_(olerelay)("*");
1192 /* Allocate space for the referenced struct */
1194 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,_xsize(tdesc->u.lptdesc));
1197 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, (LPDWORD)*arg, buf);
1199 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, arg, buf);
1202 /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
1204 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
1207 hres = _unmarshal_interface(buf,&IID_IUnknown,(LPUNKNOWN*)arg);
1209 TRACE_(olerelay)("unk(%p)",arg);
1214 hres = _unmarshal_interface(buf,&IID_IDispatch,(LPUNKNOWN*)arg);
1216 TRACE_(olerelay)("idisp(%p)",arg);
1219 if (debugout) TRACE_(olerelay)("<void>");
1221 case VT_USERDEFINED: {
1225 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
1227 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
1230 hres = ITypeInfo_GetTypeAttr(tinfo2,&tattr);
1232 ERR("Could not get typeattr in VT_USERDEFINED.\n");
1234 switch (tattr->typekind) {
1235 case TKIND_DISPATCH:
1236 case TKIND_INTERFACE:
1238 hres = _unmarshal_interface(buf,&(tattr->guid),(LPUNKNOWN*)arg);
1240 case TKIND_RECORD: {
1244 *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,tattr->cbSizeInstance);
1246 if (debugout) TRACE_(olerelay)("{");
1247 for (i=0;i<tattr->cVars;i++) {
1250 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
1252 ERR("Could not get vardesc of %d\n",i);
1255 hres = deserialize_param(
1260 &vdesc->elemdescVar.tdesc,
1261 (DWORD*)(((LPBYTE)*arg)+vdesc->u.oInst),
1264 if (debugout && (i<tattr->cVars-1)) TRACE_(olerelay)(",");
1266 if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
1267 memcpy(&(buf->iid),(LPBYTE)*arg,sizeof(buf->iid));
1268 if (debugout) TRACE_(olerelay)("}");
1272 ERR("Unhandled typekind %d\n",tattr->typekind);
1278 ERR("failed to stuballoc in TKIND_RECORD.\n");
1279 ITypeInfo_Release(tinfo2);
1283 /* arg is pointing to the start of the array. */
1284 ARRAYDESC *adesc = tdesc->u.lpadesc;
1287 if (adesc->cDims > 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
1288 for (i=0;i<adesc->cDims;i++)
1289 arrsize *= adesc->rgbounds[i].cElements;
1290 for (i=0;i<arrsize;i++)
1297 (DWORD*)((LPBYTE)(arg)+i*_xsize(&adesc->tdescElem)),
1303 ERR("No handler for VT type %d!\n",tdesc->vt);
1310 deserialize_LPVOID_ptr(
1322 if ((tdesc->vt != VT_PTR) ||
1323 (tdesc->u.lptdesc->vt != VT_PTR) ||
1324 (tdesc->u.lptdesc->u.lptdesc->vt != VT_VOID)
1326 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
1330 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(LPVOID));
1332 hres = xbuf_get(buf, (LPVOID)&cookie, sizeof(cookie));
1335 if (cookie != 0x42424242) {
1337 if (debugout) TRACE_(olerelay)("<lpvoid NULL>");
1342 hres = _unmarshal_interface(buf,&buf->iid,(LPUNKNOWN*)*arg);
1344 FIXME("_unmarshal_interface of %s , %p failed with %lx\n", debugstr_guid(&buf->iid), (LPUNKNOWN*)*arg, hres);
1348 if (debugout) TRACE_(olerelay)("ppv(%p)",(LPVOID)*arg);
1353 deserialize_DISPPARAM_ptr(
1367 if ((tdesc->vt != VT_PTR) || (tdesc->u.lptdesc->vt != VT_USERDEFINED)) {
1368 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
1372 hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
1377 if (debugout) TRACE_(olerelay)("<DISPPARAMS NULL>");
1382 *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPPARAMS));
1383 disps = (DISPPARAMS*)*arg;
1386 hres = xbuf_get(buf, (LPBYTE)&disps->cArgs, sizeof(disps->cArgs));
1390 disps->rgvarg = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(VARIANT)*disps->cArgs);
1391 if (debugout) TRACE_(olerelay)("D{");
1392 for (i=0; i< disps->cArgs; i++) {
1395 vdesc.vt = VT_VARIANT;
1396 hres = deserialize_param(
1402 (DWORD*)(disps->rgvarg+i),
1406 if (debugout) TRACE_(olerelay)("}{");
1407 hres = xbuf_get(buf, (LPBYTE)&disps->cNamedArgs, sizeof(disps->cNamedArgs));
1410 if (disps->cNamedArgs) {
1412 disps->rgdispidNamedArgs = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPID)*disps->cNamedArgs);
1413 for (i=0; i< disps->cNamedArgs; i++) {
1417 hres = deserialize_param(
1423 (DWORD*)(disps->rgdispidNamedArgs+i),
1426 if (debugout && i<(disps->cNamedArgs-1)) TRACE_(olerelay)(",");
1429 if (debugout) TRACE_(olerelay)("}");
1433 /* Searches function, also in inherited interfaces */
1436 ITypeInfo *tinfo, int iMethod, ITypeInfo **tactual, FUNCDESC **fdesc, BSTR *iname, BSTR *fname)
1441 if (fname) *fname = NULL;
1442 if (iname) *iname = NULL;
1445 ITypeInfo_AddRef(*tactual);
1448 hres = ITypeInfo_GetFuncDesc(tinfo, i, fdesc);
1454 hres = ITypeInfo_GetTypeAttr(tinfo, &attr);
1456 ERR("GetTypeAttr failed with %lx\n",hres);
1459 /* Not found, so look in inherited ifaces. */
1460 for (j=0;j<attr->cImplTypes;j++) {
1461 hres = ITypeInfo_GetRefTypeOfImplType(tinfo, j, &href);
1463 ERR("Did not find a reftype for interface offset %d?\n",j);
1466 hres = ITypeInfo_GetRefTypeInfo(tinfo, href, &tinfo2);
1468 ERR("Did not find a typeinfo for reftype %ld?\n",href);
1471 hres = _get_funcdesc(tinfo2,iMethod,tactual,fdesc,iname,fname);
1472 ITypeInfo_Release(tinfo2);
1473 if (!hres) return S_OK;
1477 if (((*fdesc)->oVft/4) == iMethod) {
1479 ITypeInfo_GetDocumentation(tinfo,(*fdesc)->memid,fname,NULL,NULL,NULL);
1481 ITypeInfo_GetDocumentation(tinfo,-1,iname,NULL,NULL,NULL);
1489 xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */)
1491 DWORD *args = ((DWORD*)&tpinfo)+1, *xargs;
1494 int i, relaydeb = TRACE_ON(olerelay);
1501 int is_idispatch_getidsofnames = 0;
1502 DWORD remoteresult = 0;
1505 EnterCriticalSection(&tpinfo->crit);
1507 hres = _get_funcdesc(tpinfo->tinfo,method,&tinfo,&fdesc,&iname,&fname);
1509 ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method);
1510 ITypeInfo_Release(tinfo);
1511 LeaveCriticalSection(&tpinfo->crit);
1515 if (!tpinfo->chanbuf)
1517 WARN("Tried to use disconnected proxy\n");
1518 ITypeInfo_Release(tinfo);
1519 LeaveCriticalSection(&tpinfo->crit);
1520 return RPC_E_DISCONNECTED;
1524 TRACE_(olerelay)("->");
1526 TRACE_(olerelay)("%s:",relaystr(iname));
1528 TRACE_(olerelay)("%s(%d)",relaystr(fname),method);
1530 TRACE_(olerelay)("%d",method);
1531 TRACE_(olerelay)("(");
1533 if (iname && fname && !lstrcmpW(iname,IDispatchW) && !lstrcmpW(fname,GetIDsOfNamesW))
1534 is_idispatch_getidsofnames = 1;
1536 if (iname) SysFreeString(iname);
1537 if (fname) SysFreeString(fname);
1539 memset(&buf,0,sizeof(buf));
1540 buf.iid = IID_IUnknown;
1542 /* Special IDispatch::GetIDsOfNames() serializer */
1543 if (is_idispatch_getidsofnames) {
1544 hres = serialize_IDispatch_GetIDsOfNames(TRUE,relaydeb,args,&buf);
1546 FIXME("serialize of IDispatch::GetIDsOfNames failed!\n");
1547 ITypeInfo_Release(tinfo);
1548 LeaveCriticalSection(&tpinfo->crit);
1551 goto afterserialize;
1554 /* special QueryInterface serialize */
1556 xbuf_add(&buf,(LPBYTE)args[0],sizeof(IID));
1557 if (relaydeb) TRACE_(olerelay)("riid=%s,[out])",debugstr_guid((REFIID)args[0]));
1558 goto afterserialize;
1561 /* normal typelib driven serializing */
1563 /* Need them for hack below */
1564 memset(names,0,sizeof(names));
1565 if (ITypeInfo_GetNames(tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames))
1567 if (nrofnames > sizeof(names)/sizeof(names[0]))
1568 ERR("Need more names!\n");
1571 for (i=0;i<fdesc->cParams;i++) {
1572 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1573 BOOL isserialized = FALSE;
1575 if (i) TRACE_(olerelay)(",");
1576 if (i+1<nrofnames && names[i+1])
1577 TRACE_(olerelay)("%s=",relaystr(names[i+1]));
1579 /* No need to marshal other data than FIN and any VT_PTR. */
1580 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN) && (elem->tdesc.vt != VT_PTR)) {
1581 xargs+=_argsize(elem->tdesc.vt);
1582 if (relaydeb) TRACE_(olerelay)("[out]");
1585 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1586 /* If the parameter is 'riid', we use it as interface IID
1587 * for a later ppvObject serialization.
1589 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1591 /* DISPPARAMS* needs special serializer */
1592 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1593 hres = serialize_DISPPARAM_ptr(
1595 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1602 isserialized = TRUE;
1604 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1605 hres = serialize_LPVOID_ptr(
1607 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1615 isserialized = TRUE;
1619 hres = serialize_param(
1621 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1630 ERR("Failed to serialize param, hres %lx\n",hres);
1633 xargs+=_argsize(elem->tdesc.vt);
1635 if (relaydeb) TRACE_(olerelay)(")");
1638 memset(&msg,0,sizeof(msg));
1639 msg.cbBuffer = buf.curoff;
1640 msg.iMethod = method;
1641 hres = IRpcChannelBuffer_GetBuffer(tpinfo->chanbuf,&msg,&(tpinfo->iid));
1643 ERR("RpcChannelBuffer GetBuffer failed, %lx\n",hres);
1644 LeaveCriticalSection(&tpinfo->crit);
1647 memcpy(msg.Buffer,buf.base,buf.curoff);
1648 if (relaydeb) TRACE_(olerelay)("\n");
1649 hres = IRpcChannelBuffer_SendReceive(tpinfo->chanbuf,&msg,&status);
1651 ERR("RpcChannelBuffer SendReceive failed, %lx\n",hres);
1652 LeaveCriticalSection(&tpinfo->crit);
1656 if (relaydeb) TRACE_(olerelay)(" status = %08lx (",status);
1658 buf.base = HeapReAlloc(GetProcessHeap(),0,buf.base,msg.cbBuffer);
1660 buf.base = HeapAlloc(GetProcessHeap(),0,msg.cbBuffer);
1661 buf.size = msg.cbBuffer;
1662 memcpy(buf.base,msg.Buffer,buf.size);
1665 /* Special IDispatch::GetIDsOfNames() deserializer */
1666 if (is_idispatch_getidsofnames) {
1667 hres = deserialize_IDispatch_GetIDsOfNames(FALSE,relaydeb,args,&buf);
1669 FIXME("deserialize of IDispatch::GetIDsOfNames failed!\n");
1672 goto after_deserialize;
1674 /* Special QueryInterface deserializer */
1676 _unmarshal_interface(&buf,(REFIID)args[0],(LPUNKNOWN*)args[1]);
1677 if (relaydeb) TRACE_(olerelay)("[in],%p",*((DWORD**)args[1]));
1678 goto after_deserialize;
1681 /* generic deserializer using typelib description */
1684 for (i=0;i<fdesc->cParams;i++) {
1685 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1686 BOOL isdeserialized = FALSE;
1689 if (i) TRACE_(olerelay)(",");
1690 if (i+1<nrofnames && names[i+1]) TRACE_(olerelay)("%s=",relaystr(names[i+1]));
1692 /* No need to marshal other data than FOUT and any VT_PTR */
1693 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT) && (elem->tdesc.vt != VT_PTR)) {
1694 xargs += _argsize(elem->tdesc.vt);
1695 if (relaydeb) TRACE_(olerelay)("[in]");
1698 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1699 /* If the parameter is 'riid', we use it as interface IID
1700 * for a later ppvObject serialization.
1702 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1704 /* deserialize DISPPARAM */
1705 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1706 hres = deserialize_DISPPARAM_ptr(
1708 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1716 ERR("Failed to deserialize DISPPARAM*, hres %lx\n",hres);
1719 isdeserialized = TRUE;
1721 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1722 hres = deserialize_LPVOID_ptr(
1724 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1732 isdeserialized = TRUE;
1735 if (!isdeserialized)
1736 hres = deserialize_param(
1738 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1746 ERR("Failed to unmarshall param, hres %lx\n",hres);
1750 xargs += _argsize(elem->tdesc.vt);
1753 hres = xbuf_get(&buf, (LPBYTE)&remoteresult, sizeof(DWORD));
1756 if (relaydeb) TRACE_(olerelay)(") = %08lx\n", remoteresult);
1758 if (status != S_OK) /* OLE/COM internal error */
1761 HeapFree(GetProcessHeap(),0,buf.base);
1762 ITypeInfo_Release(tinfo);
1763 LeaveCriticalSection(&tpinfo->crit);
1764 return remoteresult;
1767 HRESULT WINAPI ProxyIUnknown_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
1769 TMProxyImpl *proxy = (TMProxyImpl *)iface;
1771 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
1773 if (proxy->outerunknown)
1774 return IUnknown_QueryInterface(proxy->outerunknown, riid, ppv);
1776 FIXME("No interface\n");
1777 return E_NOINTERFACE;
1780 ULONG WINAPI ProxyIUnknown_AddRef(IUnknown *iface)
1782 TMProxyImpl *proxy = (TMProxyImpl *)iface;
1786 if (proxy->outerunknown)
1787 return IUnknown_AddRef(proxy->outerunknown);
1789 return 2; /* FIXME */
1792 ULONG WINAPI ProxyIUnknown_Release(IUnknown *iface)
1794 TMProxyImpl *proxy = (TMProxyImpl *)iface;
1798 if (proxy->outerunknown)
1799 return IUnknown_Release(proxy->outerunknown);
1801 return 1; /* FIXME */
1804 static HRESULT WINAPI
1805 PSFacBuf_CreateProxy(
1806 LPPSFACTORYBUFFER iface, IUnknown* pUnkOuter, REFIID riid,
1807 IRpcProxyBuffer **ppProxy, LPVOID *ppv)
1815 TRACE("(...%s...)\n",debugstr_guid(riid));
1816 hres = _get_typeinfo_for_iid(riid,&tinfo);
1818 ERR("No typeinfo for %s?\n",debugstr_guid(riid));
1821 nroffuncs = _nroffuncs(tinfo);
1822 proxy = CoTaskMemAlloc(sizeof(TMProxyImpl));
1823 if (!proxy) return E_OUTOFMEMORY;
1825 assert(sizeof(TMAsmProxy) == 12);
1827 proxy->outerunknown = pUnkOuter;
1828 proxy->asmstubs = VirtualAlloc(NULL, sizeof(TMAsmProxy) * nroffuncs, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
1829 if (!proxy->asmstubs) {
1830 ERR("Could not commit pages for proxy thunks\n");
1831 CoTaskMemFree(proxy);
1832 return E_OUTOFMEMORY;
1835 InitializeCriticalSection(&proxy->crit);
1837 proxy->lpvtbl = HeapAlloc(GetProcessHeap(),0,sizeof(LPBYTE)*nroffuncs);
1838 for (i=0;i<nroffuncs;i++) {
1839 TMAsmProxy *xasm = proxy->asmstubs+i;
1843 proxy->lpvtbl[i] = ProxyIUnknown_QueryInterface;
1846 proxy->lpvtbl[i] = ProxyIUnknown_AddRef;
1849 proxy->lpvtbl[i] = ProxyIUnknown_Release;
1853 /* nrofargs without This */
1856 hres = _get_funcdesc(tinfo,i,&tinfo2,&fdesc,NULL,NULL);
1857 ITypeInfo_Release(tinfo2);
1859 ERR("GetFuncDesc %lx should not fail here.\n",hres);
1862 /* some args take more than 4 byte on the stack */
1864 for (j=0;j<fdesc->cParams;j++)
1865 nrofargs += _argsize(fdesc->lprgelemdescParam[j].tdesc.vt);
1867 if (fdesc->callconv != CC_STDCALL) {
1868 ERR("calling convention is not stdcall????\n");
1871 /* popl %eax - return ptr
1878 * arg3 arg2 arg1 <method> <returnptr>
1880 xasm->popleax = 0x58;
1881 xasm->pushlval = 0x6a;
1883 xasm->pushleax = 0x50;
1884 xasm->lcall = 0xe8; /* relative jump */
1885 xasm->xcall = (DWORD)xCall;
1886 xasm->xcall -= (DWORD)&(xasm->lret);
1888 xasm->bytestopop= (nrofargs+2)*4; /* pop args, This, iMethod */
1889 proxy->lpvtbl[i] = xasm;
1894 proxy->lpvtbl2 = &tmproxyvtable;
1895 /* 1 reference for the proxy and 1 for the object */
1897 proxy->tinfo = tinfo;
1898 memcpy(&proxy->iid,riid,sizeof(*riid));
1900 *ppv = (LPVOID)proxy;
1901 *ppProxy = (IRpcProxyBuffer *)&(proxy->lpvtbl2);
1905 typedef struct _TMStubImpl {
1906 IRpcStubBufferVtbl *lpvtbl;
1914 static HRESULT WINAPI
1915 TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface, REFIID riid, LPVOID *ppv)
1917 if (IsEqualIID(riid,&IID_IRpcStubBuffer)||IsEqualIID(riid,&IID_IUnknown)){
1918 *ppv = (LPVOID)iface;
1919 IRpcStubBuffer_AddRef(iface);
1922 FIXME("%s, not supported IID.\n",debugstr_guid(riid));
1923 return E_NOINTERFACE;
1927 TMStubImpl_AddRef(LPRPCSTUBBUFFER iface)
1929 TMStubImpl *This = (TMStubImpl *)iface;
1930 ULONG refCount = InterlockedIncrement(&This->ref);
1932 TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
1938 TMStubImpl_Release(LPRPCSTUBBUFFER iface)
1940 TMStubImpl *This = (TMStubImpl *)iface;
1941 ULONG refCount = InterlockedDecrement(&This->ref);
1943 TRACE("(%p)->(ref before=%lu)\n", This, refCount + 1);
1947 IRpcStubBuffer_Disconnect(iface);
1948 CoTaskMemFree(This);
1953 static HRESULT WINAPI
1954 TMStubImpl_Connect(LPRPCSTUBBUFFER iface, LPUNKNOWN pUnkServer)
1956 TMStubImpl *This = (TMStubImpl *)iface;
1958 TRACE("(%p)->(%p)\n", This, pUnkServer);
1960 IUnknown_AddRef(pUnkServer);
1961 This->pUnk = pUnkServer;
1966 TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface)
1968 TMStubImpl *This = (TMStubImpl *)iface;
1970 TRACE("(%p)->()\n", This);
1972 IUnknown_Release(This->pUnk);
1977 static HRESULT WINAPI
1979 LPRPCSTUBBUFFER iface, RPCOLEMESSAGE* xmsg,IRpcChannelBuffer*rpcchanbuf)
1983 TMStubImpl *This = (TMStubImpl *)iface;
1985 DWORD *args, res, *xargs, nrofargs;
1989 BSTR fname = NULL,iname = NULL;
1990 BOOL is_idispatch_getidsofnames = 0;
1993 memset(&buf,0,sizeof(buf));
1994 buf.size = xmsg->cbBuffer;
1995 buf.base = HeapAlloc(GetProcessHeap(), 0, xmsg->cbBuffer);
1996 memcpy(buf.base, xmsg->Buffer, xmsg->cbBuffer);
1998 buf.iid = IID_IUnknown;
2001 if (xmsg->iMethod == 0) { /* QI */
2003 /* in: IID, out: <iface> */
2005 xbuf_get(&buf,(LPBYTE)&xiid,sizeof(xiid));
2007 hres = _marshal_interface(&buf,&xiid,This->pUnk);
2008 xmsg->Buffer = buf.base; /* Might have been reallocated */
2009 xmsg->cbBuffer = buf.size;
2012 hres = _get_funcdesc(This->tinfo,xmsg->iMethod,&tinfo,&fdesc,&iname,&fname);
2014 ERR("GetFuncDesc on method %ld failed with %lx\n",xmsg->iMethod,hres);
2018 if (iname && fname && !lstrcmpW(iname, IDispatchW) && !lstrcmpW(fname, GetIDsOfNamesW))
2019 is_idispatch_getidsofnames = 1;
2021 if (iname) SysFreeString (iname);
2022 if (fname) SysFreeString (fname);
2024 /* Need them for hack below */
2025 memset(names,0,sizeof(names));
2026 ITypeInfo_GetNames(tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
2027 if (nrofnames > sizeof(names)/sizeof(names[0])) {
2028 ERR("Need more names!\n");
2031 /*dump_FUNCDESC(fdesc);*/
2033 for (i=0;i<fdesc->cParams;i++)
2034 nrofargs += _argsize(fdesc->lprgelemdescParam[i].tdesc.vt);
2035 args = HeapAlloc(GetProcessHeap(),0,(nrofargs+1)*sizeof(DWORD));
2036 if (!args) return E_OUTOFMEMORY;
2038 if (is_idispatch_getidsofnames) {
2039 hres = deserialize_IDispatch_GetIDsOfNames(TRUE,FALSE,args+1,&buf);
2041 FIXME("deserialize_IDispatch_GetIDsOfNames failed!\n");
2045 goto afterdeserialize;
2048 /* Allocate all stuff used by call. */
2050 for (i=0;i<fdesc->cParams;i++) {
2051 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
2052 BOOL isdeserialized = FALSE;
2054 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
2055 /* If the parameter is 'riid', we use it as interface IID
2056 * for a later ppvObject serialization.
2058 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
2060 /* deserialize DISPPARAM */
2061 if (!lstrcmpW(names[i+1],pdispparamsW)) {
2062 hres = deserialize_DISPPARAM_ptr(
2064 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
2072 ERR("Failed to deserialize DISPPARAM*, hres %lx\n",hres);
2075 isdeserialized = TRUE;
2077 if (!lstrcmpW(names[i+1],ppvObjectW)) {
2078 hres = deserialize_LPVOID_ptr(
2080 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
2088 isdeserialized = TRUE;
2091 if (!isdeserialized)
2092 hres = deserialize_param(
2094 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
2101 xargs += _argsize(elem->tdesc.vt);
2103 ERR("Failed to deserialize param %s, hres %lx\n",relaystr(names[i+1]),hres);
2108 hres = IUnknown_QueryInterface(This->pUnk,&(This->iid),(LPVOID*)&(args[0]));
2110 ERR("Does not support iface %s, returning %lx\n",debugstr_guid(&(This->iid)), hres);
2114 (*((FARPROC**)args[0]))[fdesc->oVft/4],
2119 IUnknown_Release((LPUNKNOWN)args[0]);
2122 /* special IDispatch::GetIDsOfNames serializer */
2123 if (is_idispatch_getidsofnames) {
2124 hres = serialize_IDispatch_GetIDsOfNames(FALSE,FALSE,args+1,&buf);
2126 FIXME("serialize of IDispatch::GetIDsOfNames failed!\n");
2129 goto afterserialize;
2132 for (i=0;i<fdesc->cParams;i++) {
2133 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
2134 BOOL isserialized = FALSE;
2136 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
2137 /* If the parameter is 'riid', we use it as interface IID
2138 * for a later ppvObject serialization.
2140 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
2142 /* DISPPARAMS* needs special serializer */
2143 if (!lstrcmpW(names[i+1],pdispparamsW)) {
2144 hres = serialize_DISPPARAM_ptr(
2146 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
2153 isserialized = TRUE;
2155 if (!lstrcmpW(names[i+1],ppvObjectW)) {
2156 hres = serialize_LPVOID_ptr(
2158 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
2166 isserialized = TRUE;
2170 hres = serialize_param(
2172 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
2179 xargs += _argsize(elem->tdesc.vt);
2181 ERR("Failed to stuballoc param, hres %lx\n",hres);
2186 hres = xbuf_add (&buf, (LPBYTE)&res, sizeof(DWORD));
2190 ITypeInfo_Release(tinfo);
2191 xmsg->cbBuffer = buf.curoff;
2192 I_RpcGetBuffer((RPC_MESSAGE *)xmsg);
2193 memcpy(xmsg->Buffer, buf.base, buf.curoff);
2194 HeapFree(GetProcessHeap(),0,args);
2198 static LPRPCSTUBBUFFER WINAPI
2199 TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface, REFIID riid) {
2200 FIXME("Huh (%s)?\n",debugstr_guid(riid));
2205 TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface) {
2206 TMStubImpl *This = (TMStubImpl *)iface;
2208 return This->ref; /*FIXME? */
2211 static HRESULT WINAPI
2212 TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface, LPVOID *ppv) {
2217 TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface, LPVOID ppv) {
2221 IRpcStubBufferVtbl tmstubvtbl = {
2222 TMStubImpl_QueryInterface,
2226 TMStubImpl_Disconnect,
2228 TMStubImpl_IsIIDSupported,
2229 TMStubImpl_CountRefs,
2230 TMStubImpl_DebugServerQueryInterface,
2231 TMStubImpl_DebugServerRelease
2234 static HRESULT WINAPI
2235 PSFacBuf_CreateStub(
2236 LPPSFACTORYBUFFER iface, REFIID riid,IUnknown *pUnkServer,
2237 IRpcStubBuffer** ppStub
2243 TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub);
2244 hres = _get_typeinfo_for_iid(riid,&tinfo);
2246 ERR("No typeinfo for %s?\n",debugstr_guid(riid));
2249 stub = CoTaskMemAlloc(sizeof(TMStubImpl));
2251 return E_OUTOFMEMORY;
2252 stub->lpvtbl = &tmstubvtbl;
2254 stub->tinfo = tinfo;
2255 memcpy(&(stub->iid),riid,sizeof(*riid));
2256 hres = IRpcStubBuffer_Connect((LPRPCSTUBBUFFER)stub,pUnkServer);
2257 *ppStub = (LPRPCSTUBBUFFER)stub;
2258 TRACE("IRpcStubBuffer: %p\n", stub);
2260 ERR("Connect to pUnkServer failed?\n");
2264 static IPSFactoryBufferVtbl psfacbufvtbl = {
2265 PSFacBuf_QueryInterface,
2268 PSFacBuf_CreateProxy,
2272 /* This is the whole PSFactoryBuffer object, just the vtableptr */
2273 static IPSFactoryBufferVtbl *lppsfac = &psfacbufvtbl;
2275 /***********************************************************************
2276 * DllGetClassObject [OLE32.63]
2279 TypeLibFac_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
2281 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)) {
2285 return E_NOINTERFACE;