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 const 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 const IRpcProxyBufferVtbl tmproxyvtable = {
447 TMProxyImpl_QueryInterface,
451 TMProxyImpl_Disconnect
454 /* how much space do we use on stack in DWORD steps. */
459 return sizeof(double)/sizeof(DWORD);
461 return sizeof(CY)/sizeof(DWORD);
463 return sizeof(DATE)/sizeof(DWORD);
465 return (sizeof(VARIANT)+3)/sizeof(DWORD);
472 _xsize(TYPEDESC *td) {
477 return sizeof(VARIANT)+3;
480 ARRAYDESC *adesc = td->u.lpadesc;
482 for (i=0;i<adesc->cDims;i++)
483 arrsize *= adesc->rgbounds[i].cElements;
484 return arrsize*_xsize(&adesc->tdescElem);
509 TRACE("(tdesc.vt %d)\n",tdesc->vt);
512 case VT_EMPTY: /* nothing. empty variant for instance */
521 if (debugout) TRACE_(olerelay)("%lx",*arg);
523 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
528 if (debugout) TRACE_(olerelay)("%04lx",*arg & 0xffff);
530 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
535 if (debugout) TRACE_(olerelay)("%02lx",*arg & 0xff);
537 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
541 if (debugout) TRACE_(olerelay)("&0x%lx",*arg);
543 hres = xbuf_add(buf,(LPBYTE)(DWORD*)*arg,sizeof(DWORD));
544 /* do not dealloc at this time */
548 VARIANT *vt = (VARIANT*)arg;
549 DWORD vttype = V_VT(vt);
551 if (debugout) TRACE_(olerelay)("Vt(%ld)(",vttype);
554 hres = xbuf_add(buf,(LPBYTE)&vttype,sizeof(vttype));
555 if (hres) return hres;
557 /* need to recurse since we need to free the stuff */
558 hres = serialize_param(tinfo,writeit,debugout,dealloc,&tdesc2,&(V_I4(vt)),buf);
559 if (debugout) TRACE_(olerelay)(")");
562 case VT_BSTR|VT_BYREF: {
563 if (debugout) TRACE_(olerelay)("[byref]'%s'", *(BSTR*)*arg ? relaystr(*((BSTR*)*arg)) : "<bstr NULL>");
565 /* ptr to ptr to magic widestring, basically */
566 BSTR *bstr = (BSTR *) *arg;
568 /* -1 means "null string" which is equivalent to empty string */
570 xbuf_add(buf, (LPBYTE)&fakelen,4);
572 /* BSTRs store the length behind the first character */
573 DWORD *len = ((DWORD *)(*bstr))-1;
574 hres = xbuf_add(buf, (LPBYTE) len, *len + 4);
575 if (hres) return hres;
579 if (dealloc && arg) {
580 BSTR *str = *((BSTR **)arg);
589 TRACE_(olerelay)("%s",relaystr((WCHAR*)*arg));
591 TRACE_(olerelay)("<bstr NULL>");
596 hres = xbuf_add(buf,(LPBYTE)&fakelen,4);
600 DWORD *bstr = ((DWORD*)(*arg))-1;
602 hres = xbuf_add(buf,(LPBYTE)bstr,bstr[0]+4);
609 SysFreeString((BSTR)*arg);
616 derefhere = (tdesc->u.lptdesc->vt != VT_USERDEFINED);
618 if (debugout) TRACE_(olerelay)("*");
619 /* Write always, so the other side knows when it gets a NULL pointer.
621 cookie = *arg ? 0x42424242 : 0;
622 hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
626 if (debugout) TRACE_(olerelay)("NULL");
629 hres = serialize_param(tinfo,writeit,debugout,dealloc,tdesc->u.lptdesc,(DWORD*)*arg,buf);
630 if (derefhere && dealloc) HeapFree(GetProcessHeap(),0,(LPVOID)*arg);
634 if (debugout) TRACE_(olerelay)("unk(0x%lx)",*arg);
636 hres = _marshal_interface(buf,&IID_IUnknown,(LPUNKNOWN)*arg);
639 if (debugout) TRACE_(olerelay)("idisp(0x%lx)",*arg);
641 hres = _marshal_interface(buf,&IID_IDispatch,(LPUNKNOWN)*arg);
644 if (debugout) TRACE_(olerelay)("<void>");
646 case VT_USERDEFINED: {
650 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
652 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
655 ITypeInfo_GetTypeAttr(tinfo2,&tattr);
656 switch (tattr->typekind) {
658 case TKIND_INTERFACE:
660 hres=_marshal_interface(buf,&(tattr->guid),(LPUNKNOWN)arg);
664 if (debugout) TRACE_(olerelay)("{");
665 for (i=0;i<tattr->cVars;i++) {
670 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
672 ERR("Could not get vardesc of %d\n",i);
675 /* Need them for hack below */
677 memset(names,0,sizeof(names));
678 hres = ITypeInfo_GetNames(tinfo2,vdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
679 if (nrofnames > sizeof(names)/sizeof(names[0])) {
680 ERR("Need more names!\n");
682 if (!hres && debugout)
683 TRACE_(olerelay)("%s=",relaystr(names[0]));
685 elem2 = &vdesc->elemdescVar;
686 tdesc2 = &elem2->tdesc;
687 hres = serialize_param(
693 (DWORD*)(((LPBYTE)arg)+vdesc->u.oInst),
696 ITypeInfo_ReleaseVarDesc(tinfo2, vdesc);
699 if (debugout && (i<(tattr->cVars-1)))
700 TRACE_(olerelay)(",");
702 if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
703 memcpy(&(buf->iid),arg,sizeof(buf->iid));
704 if (debugout) TRACE_(olerelay)("}");
708 FIXME("Unhandled typekind %d\n",tattr->typekind);
712 ITypeInfo_Release(tinfo2);
716 ARRAYDESC *adesc = tdesc->u.lpadesc;
719 if (debugout) TRACE_(olerelay)("carr");
720 for (i=0;i<adesc->cDims;i++) {
721 if (debugout) TRACE_(olerelay)("[%ld]",adesc->rgbounds[i].cElements);
722 arrsize *= adesc->rgbounds[i].cElements;
724 if (debugout) TRACE_(olerelay)("(vt %d)",adesc->tdescElem.vt);
725 if (debugout) TRACE_(olerelay)("[");
726 for (i=0;i<arrsize;i++) {
727 hres = serialize_param(tinfo, writeit, debugout, dealloc, &adesc->tdescElem, (DWORD*)((LPBYTE)arg+i*_xsize(&adesc->tdescElem)), buf);
730 if (debugout && (i<arrsize-1)) TRACE_(olerelay)(",");
732 if (debugout) TRACE_(olerelay)("]");
736 ERR("Unhandled marshal type %d.\n",tdesc->vt);
742 * HRESULT GetIDsOfNames(
743 * [in] REFIID riid, args[1]
744 * [in, size_is(cNames)] LPOLESTR *rgszNames, args[2]
745 * [in] UINT cNames, args[3]
746 * [in] LCID lcid, args[4]
747 * [out, size_is(cNames)] DISPID *rgDispId); args[5]
752 * LPOLESTR rgszNames[cNames];
753 * DWORD bytestrlen (incl 0)
754 * BYTE data[bytestrlen] (incl 0)
758 serialize_IDispatch_GetIDsOfNames(
765 DWORD cNames = args[2];
766 LPOLESTR *rgszNames = (LPOLESTR*)args[1];
770 if (debugout) TRACE_(olerelay)("riid=%s,",debugstr_guid((REFIID)args[0]));
771 hres = xbuf_add(buf, (LPBYTE)args[0], sizeof(IID));
773 FIXME("serialize of IID failed.\n");
776 if (debugout) TRACE_(olerelay)("cNames=%ld,",cNames);
777 hres = xbuf_add(buf, (LPBYTE)&cNames, sizeof(DWORD));
779 FIXME("serialize of cNames failed.\n");
782 if (debugout) TRACE_(olerelay)("rgszNames=[");
783 for (i=0;i<cNames;i++) {
784 DWORD len = 2*(lstrlenW(rgszNames[i])+1);
786 if (debugout) TRACE_(olerelay)("%s,",relaystr(rgszNames[i]));
787 hres = xbuf_add(buf, (LPBYTE)&len, sizeof(DWORD));
789 FIXME("serialize of len failed.\n");
792 hres = xbuf_add(buf, (LPBYTE)rgszNames[i], len);
794 FIXME("serialize of rgszNames[i] failed.\n");
798 if (debugout) TRACE_(olerelay)("],lcid=%04lx)",args[3]);
799 hres = xbuf_add(buf, (LPBYTE)&args[3], sizeof(DWORD));
801 FIXME("serialize of lcid failed.\n");
805 DISPID *rgDispId = (DISPID*)args[4];
807 hres = xbuf_add(buf, (LPBYTE)rgDispId, sizeof(DISPID) * cNames);
809 FIXME("serialize of rgDispId failed.\n");
813 TRACE_(olerelay)("riid=[in],rgszNames=[in],cNames=[in],rgDispId=[");
814 for (i=0;i<cNames;i++)
815 TRACE_(olerelay)("%08lx,",rgDispId[i]);
816 TRACE_(olerelay)("])");
818 HeapFree(GetProcessHeap(),0,(IID*)args[0]);
819 rgszNames = (LPOLESTR*)args[1];
820 for (i=0;i<cNames;i++) HeapFree(GetProcessHeap(),0,rgszNames[i]);
821 HeapFree(GetProcessHeap(),0,rgszNames);
822 HeapFree(GetProcessHeap(),0,rgDispId);
828 deserialize_IDispatch_GetIDsOfNames(
840 args[0] = (DWORD)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IID));
841 if (!args[0]) return E_FAIL;
842 hres = xbuf_get(buf, (LPBYTE)args[0], sizeof(IID));
844 FIXME("deserialize of IID failed.\n");
847 if (debugout) TRACE_(olerelay)("riid=%s,",debugstr_guid((REFIID)args[0]));
849 hres = xbuf_get(buf, (LPBYTE)&cNames, sizeof(DWORD));
851 FIXME("deserialize of cNames failed.\n");
855 if (debugout) TRACE_(olerelay)("cNames=%ld,",cNames);
856 if (debugout) TRACE_(olerelay)("rgszNames=[");
857 rgszNames = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(LPOLESTR) * cNames);
858 if (!rgszNames) return E_FAIL;
859 args[1] = (DWORD)rgszNames;
860 for (i=0;i<cNames;i++) {
863 hres = xbuf_get(buf, (LPBYTE)&len, sizeof(DWORD));
865 FIXME("serialize of len failed.\n");
868 rgszNames[i] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
870 FIXME("heapalloc of %ld bytes failed\n", len);
873 hres = xbuf_get(buf, (LPBYTE)rgszNames[i], len);
875 FIXME("serialize of rgszNames[i] failed.\n");
878 if (debugout) TRACE_(olerelay)("%s,",relaystr(rgszNames[i]));
880 hres = xbuf_get(buf, (LPBYTE)&args[3], sizeof(DWORD));
882 FIXME("deserialize of lcid failed.\n");
885 if (debugout) TRACE_(olerelay)("],lcid=%04lx,rgDispId=[out])",args[3]);
886 args[4] = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPID) * cNames);
888 hres = xbuf_get(buf, (LPBYTE)args[4], sizeof(DISPID) * args[2]);
890 FIXME("serialize of rgDispId failed.\n");
894 TRACE_(olerelay)("dispid=[");
895 for (i=0;i<args[2];i++)
896 TRACE_(olerelay)("%08lx,",((DISPID*)args[4])[i]);
897 TRACE_(olerelay)("])");
904 serialize_LPVOID_ptr(
916 if ((tdesc->vt != VT_PTR) ||
917 (tdesc->u.lptdesc->vt != VT_PTR) ||
918 (tdesc->u.lptdesc->u.lptdesc->vt != VT_VOID)
920 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
923 cookie = (*(DWORD*)*arg) ? 0x42424242: 0x0;
925 hres = xbuf_add(buf, (LPVOID)&cookie, sizeof(cookie));
929 if (!*(DWORD*)*arg) {
930 if (debugout) TRACE_(olerelay)("<lpvoid NULL>");
934 TRACE_(olerelay)("ppv(%p)",*(LPUNKNOWN*)*arg);
936 hres = _marshal_interface(buf,&(buf->iid),*(LPUNKNOWN*)*arg);
941 HeapFree(GetProcessHeap(),0,(LPVOID)*arg);
946 serialize_DISPPARAM_ptr(
960 if ((tdesc->vt != VT_PTR) || (tdesc->u.lptdesc->vt != VT_USERDEFINED)) {
961 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
965 cookie = *arg ? 0x42424242 : 0x0;
967 hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
972 if (debugout) TRACE_(olerelay)("<DISPPARAMS NULL>");
975 disp = (DISPPARAMS*)*arg;
977 hres = xbuf_add(buf,(LPBYTE)&disp->cArgs,sizeof(disp->cArgs));
981 if (debugout) TRACE_(olerelay)("D{");
982 for (i=0;i<disp->cArgs;i++) {
985 vtdesc.vt = VT_VARIANT;
992 (DWORD*)(disp->rgvarg+i),
995 if (debugout && (i<disp->cArgs-1))
996 TRACE_(olerelay)(",");
999 HeapFree(GetProcessHeap(),0,disp->rgvarg);
1001 hres = xbuf_add(buf,(LPBYTE)&disp->cNamedArgs,sizeof(disp->cNamedArgs));
1005 if (debugout) TRACE_(olerelay)("}{");
1006 for (i=0;i<disp->cNamedArgs;i++) {
1009 vtdesc.vt = VT_UINT;
1016 (DWORD*)(disp->rgdispidNamedArgs+i),
1019 if (debugout && (i<disp->cNamedArgs-1))
1020 TRACE_(olerelay)(",");
1022 if (debugout) TRACE_(olerelay)("}");
1024 HeapFree(GetProcessHeap(),0,disp->rgdispidNamedArgs);
1025 HeapFree(GetProcessHeap(),0,disp);
1040 HRESULT hres = S_OK;
1042 TRACE("vt %d at %p\n",tdesc->vt,arg);
1045 switch (tdesc->vt) {
1047 if (debugout) TRACE_(olerelay)("<empty>");
1050 if (debugout) TRACE_(olerelay)("<null>");
1053 VARIANT *vt = (VARIANT*)arg;
1058 hres = xbuf_get(buf,(LPBYTE)&vttype,sizeof(vttype));
1060 FIXME("vt type not read?\n");
1063 memset(&tdesc2,0,sizeof(tdesc2));
1066 if (debugout) TRACE_(olerelay)("Vt(%ld)(",vttype);
1067 hres = deserialize_param(tinfo, readit, debugout, alloc, &tdesc2, &(V_I4(vt)), buf);
1068 TRACE_(olerelay)(")");
1082 hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
1083 if (hres) ERR("Failed to read integer 4 byte\n");
1085 if (debugout) TRACE_(olerelay)("%lx",*arg);
1091 hres = xbuf_get(buf,(LPBYTE)&x,sizeof(DWORD));
1092 if (hres) ERR("Failed to read integer 4 byte\n");
1095 if (debugout) TRACE_(olerelay)("%04lx",*arg & 0xffff);
1101 hres = xbuf_get(buf,(LPBYTE)&x,sizeof(DWORD));
1102 if (hres) ERR("Failed to read integer 4 byte\n");
1105 if (debugout) TRACE_(olerelay)("%02lx",*arg & 0xff);
1107 case VT_I4|VT_BYREF:
1110 *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
1112 hres = xbuf_get(buf,(LPBYTE)*arg,sizeof(DWORD));
1113 if (hres) ERR("Failed to read integer 4 byte\n");
1115 if (debugout) TRACE_(olerelay)("&0x%lx",*(DWORD*)*arg);
1117 case VT_BSTR|VT_BYREF: {
1118 BSTR **bstr = (BSTR **)arg;
1123 hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
1125 ERR("failed to read bstr klen\n");
1129 *bstr = CoTaskMemAlloc(sizeof(BSTR *));
1131 if (debugout) TRACE_(olerelay)("<bstr NULL>");
1133 str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len+sizeof(WCHAR));
1134 hres = xbuf_get(buf,(LPBYTE)str,len);
1136 ERR("Failed to read BSTR.\n");
1139 *bstr = CoTaskMemAlloc(sizeof(BSTR *));
1140 **bstr = SysAllocStringLen(str,len);
1141 if (debugout) TRACE_(olerelay)("%s",relaystr(str));
1142 HeapFree(GetProcessHeap(),0,str);
1154 hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
1156 ERR("failed to read bstr klen\n");
1161 if (debugout) TRACE_(olerelay)("<bstr NULL>");
1163 str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len+sizeof(WCHAR));
1164 hres = xbuf_get(buf,(LPBYTE)str,len);
1166 ERR("Failed to read BSTR.\n");
1169 *arg = (DWORD)SysAllocStringLen(str,len);
1170 if (debugout) TRACE_(olerelay)("%s",relaystr(str));
1171 HeapFree(GetProcessHeap(),0,str);
1182 derefhere = (tdesc->u.lptdesc->vt != VT_USERDEFINED);
1183 /* read it in all cases, we need to know if we have
1184 * NULL pointer or not.
1186 hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
1188 ERR("Failed to load pointer cookie.\n");
1191 if (cookie != 0x42424242) {
1192 /* we read a NULL ptr from the remote side */
1193 if (debugout) TRACE_(olerelay)("NULL");
1197 if (debugout) TRACE_(olerelay)("*");
1199 /* Allocate space for the referenced struct */
1201 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,_xsize(tdesc->u.lptdesc));
1204 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, (LPDWORD)*arg, buf);
1206 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, arg, buf);
1209 /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
1211 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
1214 hres = _unmarshal_interface(buf,&IID_IUnknown,(LPUNKNOWN*)arg);
1216 TRACE_(olerelay)("unk(%p)",arg);
1221 hres = _unmarshal_interface(buf,&IID_IDispatch,(LPUNKNOWN*)arg);
1223 TRACE_(olerelay)("idisp(%p)",arg);
1226 if (debugout) TRACE_(olerelay)("<void>");
1228 case VT_USERDEFINED: {
1232 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
1234 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
1237 hres = ITypeInfo_GetTypeAttr(tinfo2,&tattr);
1239 ERR("Could not get typeattr in VT_USERDEFINED.\n");
1241 switch (tattr->typekind) {
1242 case TKIND_DISPATCH:
1243 case TKIND_INTERFACE:
1245 hres = _unmarshal_interface(buf,&(tattr->guid),(LPUNKNOWN*)arg);
1247 case TKIND_RECORD: {
1251 *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,tattr->cbSizeInstance);
1253 if (debugout) TRACE_(olerelay)("{");
1254 for (i=0;i<tattr->cVars;i++) {
1257 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
1259 ERR("Could not get vardesc of %d\n",i);
1262 hres = deserialize_param(
1267 &vdesc->elemdescVar.tdesc,
1268 (DWORD*)(((LPBYTE)*arg)+vdesc->u.oInst),
1271 if (debugout && (i<tattr->cVars-1)) TRACE_(olerelay)(",");
1273 if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
1274 memcpy(&(buf->iid),(LPBYTE)*arg,sizeof(buf->iid));
1275 if (debugout) TRACE_(olerelay)("}");
1279 ERR("Unhandled typekind %d\n",tattr->typekind);
1285 ERR("failed to stuballoc in TKIND_RECORD.\n");
1286 ITypeInfo_Release(tinfo2);
1290 /* arg is pointing to the start of the array. */
1291 ARRAYDESC *adesc = tdesc->u.lpadesc;
1294 if (adesc->cDims > 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
1295 for (i=0;i<adesc->cDims;i++)
1296 arrsize *= adesc->rgbounds[i].cElements;
1297 for (i=0;i<arrsize;i++)
1304 (DWORD*)((LPBYTE)(arg)+i*_xsize(&adesc->tdescElem)),
1310 ERR("No handler for VT type %d!\n",tdesc->vt);
1317 deserialize_LPVOID_ptr(
1329 if ((tdesc->vt != VT_PTR) ||
1330 (tdesc->u.lptdesc->vt != VT_PTR) ||
1331 (tdesc->u.lptdesc->u.lptdesc->vt != VT_VOID)
1333 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
1337 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(LPVOID));
1339 hres = xbuf_get(buf, (LPVOID)&cookie, sizeof(cookie));
1342 if (cookie != 0x42424242) {
1344 if (debugout) TRACE_(olerelay)("<lpvoid NULL>");
1349 hres = _unmarshal_interface(buf,&buf->iid,(LPUNKNOWN*)*arg);
1351 FIXME("_unmarshal_interface of %s , %p failed with %lx\n", debugstr_guid(&buf->iid), (LPUNKNOWN*)*arg, hres);
1355 if (debugout) TRACE_(olerelay)("ppv(%p)",(LPVOID)*arg);
1360 deserialize_DISPPARAM_ptr(
1374 if ((tdesc->vt != VT_PTR) || (tdesc->u.lptdesc->vt != VT_USERDEFINED)) {
1375 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
1379 hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
1384 if (debugout) TRACE_(olerelay)("<DISPPARAMS NULL>");
1389 *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPPARAMS));
1390 disps = (DISPPARAMS*)*arg;
1393 hres = xbuf_get(buf, (LPBYTE)&disps->cArgs, sizeof(disps->cArgs));
1397 disps->rgvarg = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(VARIANT)*disps->cArgs);
1398 if (debugout) TRACE_(olerelay)("D{");
1399 for (i=0; i< disps->cArgs; i++) {
1402 vdesc.vt = VT_VARIANT;
1403 hres = deserialize_param(
1409 (DWORD*)(disps->rgvarg+i),
1413 if (debugout) TRACE_(olerelay)("}{");
1414 hres = xbuf_get(buf, (LPBYTE)&disps->cNamedArgs, sizeof(disps->cNamedArgs));
1417 if (disps->cNamedArgs) {
1419 disps->rgdispidNamedArgs = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPID)*disps->cNamedArgs);
1420 for (i=0; i< disps->cNamedArgs; i++) {
1424 hres = deserialize_param(
1430 (DWORD*)(disps->rgdispidNamedArgs+i),
1433 if (debugout && i<(disps->cNamedArgs-1)) TRACE_(olerelay)(",");
1436 if (debugout) TRACE_(olerelay)("}");
1440 /* Searches function, also in inherited interfaces */
1443 ITypeInfo *tinfo, int iMethod, ITypeInfo **tactual, FUNCDESC **fdesc, BSTR *iname, BSTR *fname)
1448 if (fname) *fname = NULL;
1449 if (iname) *iname = NULL;
1452 ITypeInfo_AddRef(*tactual);
1455 hres = ITypeInfo_GetFuncDesc(tinfo, i, fdesc);
1461 hres = ITypeInfo_GetTypeAttr(tinfo, &attr);
1463 ERR("GetTypeAttr failed with %lx\n",hres);
1466 /* Not found, so look in inherited ifaces. */
1467 for (j=0;j<attr->cImplTypes;j++) {
1468 hres = ITypeInfo_GetRefTypeOfImplType(tinfo, j, &href);
1470 ERR("Did not find a reftype for interface offset %d?\n",j);
1473 hres = ITypeInfo_GetRefTypeInfo(tinfo, href, &tinfo2);
1475 ERR("Did not find a typeinfo for reftype %ld?\n",href);
1478 hres = _get_funcdesc(tinfo2,iMethod,tactual,fdesc,iname,fname);
1479 ITypeInfo_Release(tinfo2);
1480 if (!hres) return S_OK;
1484 if (((*fdesc)->oVft/4) == iMethod) {
1486 ITypeInfo_GetDocumentation(tinfo,(*fdesc)->memid,fname,NULL,NULL,NULL);
1488 ITypeInfo_GetDocumentation(tinfo,-1,iname,NULL,NULL,NULL);
1496 xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */)
1498 DWORD *args = ((DWORD*)&tpinfo)+1, *xargs;
1501 int i, relaydeb = TRACE_ON(olerelay);
1508 int is_idispatch_getidsofnames = 0;
1509 DWORD remoteresult = 0;
1512 EnterCriticalSection(&tpinfo->crit);
1514 hres = _get_funcdesc(tpinfo->tinfo,method,&tinfo,&fdesc,&iname,&fname);
1516 ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method);
1517 ITypeInfo_Release(tinfo);
1518 LeaveCriticalSection(&tpinfo->crit);
1522 if (!tpinfo->chanbuf)
1524 WARN("Tried to use disconnected proxy\n");
1525 ITypeInfo_Release(tinfo);
1526 LeaveCriticalSection(&tpinfo->crit);
1527 return RPC_E_DISCONNECTED;
1531 TRACE_(olerelay)("->");
1533 TRACE_(olerelay)("%s:",relaystr(iname));
1535 TRACE_(olerelay)("%s(%d)",relaystr(fname),method);
1537 TRACE_(olerelay)("%d",method);
1538 TRACE_(olerelay)("(");
1540 if (iname && fname && !lstrcmpW(iname,IDispatchW) && !lstrcmpW(fname,GetIDsOfNamesW))
1541 is_idispatch_getidsofnames = 1;
1543 if (iname) SysFreeString(iname);
1544 if (fname) SysFreeString(fname);
1546 memset(&buf,0,sizeof(buf));
1547 buf.iid = IID_IUnknown;
1549 /* Special IDispatch::GetIDsOfNames() serializer */
1550 if (is_idispatch_getidsofnames) {
1551 hres = serialize_IDispatch_GetIDsOfNames(TRUE,relaydeb,args,&buf);
1553 FIXME("serialize of IDispatch::GetIDsOfNames failed!\n");
1554 ITypeInfo_Release(tinfo);
1555 LeaveCriticalSection(&tpinfo->crit);
1558 goto afterserialize;
1561 /* special QueryInterface serialize */
1563 xbuf_add(&buf,(LPBYTE)args[0],sizeof(IID));
1564 if (relaydeb) TRACE_(olerelay)("riid=%s,[out])",debugstr_guid((REFIID)args[0]));
1565 goto afterserialize;
1568 /* normal typelib driven serializing */
1570 /* Need them for hack below */
1571 memset(names,0,sizeof(names));
1572 if (ITypeInfo_GetNames(tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames))
1574 if (nrofnames > sizeof(names)/sizeof(names[0]))
1575 ERR("Need more names!\n");
1578 for (i=0;i<fdesc->cParams;i++) {
1579 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1580 BOOL isserialized = FALSE;
1582 if (i) TRACE_(olerelay)(",");
1583 if (i+1<nrofnames && names[i+1])
1584 TRACE_(olerelay)("%s=",relaystr(names[i+1]));
1586 /* No need to marshal other data than FIN and any VT_PTR. */
1587 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN) && (elem->tdesc.vt != VT_PTR)) {
1588 xargs+=_argsize(elem->tdesc.vt);
1589 if (relaydeb) TRACE_(olerelay)("[out]");
1592 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1593 /* If the parameter is 'riid', we use it as interface IID
1594 * for a later ppvObject serialization.
1596 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1598 /* DISPPARAMS* needs special serializer */
1599 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1600 hres = serialize_DISPPARAM_ptr(
1602 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1609 isserialized = TRUE;
1611 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1612 hres = serialize_LPVOID_ptr(
1614 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1622 isserialized = TRUE;
1626 hres = serialize_param(
1628 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1637 ERR("Failed to serialize param, hres %lx\n",hres);
1640 xargs+=_argsize(elem->tdesc.vt);
1642 if (relaydeb) TRACE_(olerelay)(")");
1645 memset(&msg,0,sizeof(msg));
1646 msg.cbBuffer = buf.curoff;
1647 msg.iMethod = method;
1648 hres = IRpcChannelBuffer_GetBuffer(tpinfo->chanbuf,&msg,&(tpinfo->iid));
1650 ERR("RpcChannelBuffer GetBuffer failed, %lx\n",hres);
1651 LeaveCriticalSection(&tpinfo->crit);
1654 memcpy(msg.Buffer,buf.base,buf.curoff);
1655 if (relaydeb) TRACE_(olerelay)("\n");
1656 hres = IRpcChannelBuffer_SendReceive(tpinfo->chanbuf,&msg,&status);
1658 ERR("RpcChannelBuffer SendReceive failed, %lx\n",hres);
1659 LeaveCriticalSection(&tpinfo->crit);
1663 if (relaydeb) TRACE_(olerelay)(" status = %08lx (",status);
1665 buf.base = HeapReAlloc(GetProcessHeap(),0,buf.base,msg.cbBuffer);
1667 buf.base = HeapAlloc(GetProcessHeap(),0,msg.cbBuffer);
1668 buf.size = msg.cbBuffer;
1669 memcpy(buf.base,msg.Buffer,buf.size);
1672 /* Special IDispatch::GetIDsOfNames() deserializer */
1673 if (is_idispatch_getidsofnames) {
1674 hres = deserialize_IDispatch_GetIDsOfNames(FALSE,relaydeb,args,&buf);
1676 FIXME("deserialize of IDispatch::GetIDsOfNames failed!\n");
1679 goto after_deserialize;
1681 /* Special QueryInterface deserializer */
1683 _unmarshal_interface(&buf,(REFIID)args[0],(LPUNKNOWN*)args[1]);
1684 if (relaydeb) TRACE_(olerelay)("[in],%p",*((DWORD**)args[1]));
1685 goto after_deserialize;
1688 /* generic deserializer using typelib description */
1691 for (i=0;i<fdesc->cParams;i++) {
1692 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1693 BOOL isdeserialized = FALSE;
1696 if (i) TRACE_(olerelay)(",");
1697 if (i+1<nrofnames && names[i+1]) TRACE_(olerelay)("%s=",relaystr(names[i+1]));
1699 /* No need to marshal other data than FOUT and any VT_PTR */
1700 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT) && (elem->tdesc.vt != VT_PTR)) {
1701 xargs += _argsize(elem->tdesc.vt);
1702 if (relaydeb) TRACE_(olerelay)("[in]");
1705 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1706 /* If the parameter is 'riid', we use it as interface IID
1707 * for a later ppvObject serialization.
1709 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1711 /* deserialize DISPPARAM */
1712 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1713 hres = deserialize_DISPPARAM_ptr(
1715 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1723 ERR("Failed to deserialize DISPPARAM*, hres %lx\n",hres);
1726 isdeserialized = TRUE;
1728 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1729 hres = deserialize_LPVOID_ptr(
1731 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1739 isdeserialized = TRUE;
1742 if (!isdeserialized)
1743 hres = deserialize_param(
1745 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1753 ERR("Failed to unmarshall param, hres %lx\n",hres);
1757 xargs += _argsize(elem->tdesc.vt);
1760 hres = xbuf_get(&buf, (LPBYTE)&remoteresult, sizeof(DWORD));
1763 if (relaydeb) TRACE_(olerelay)(") = %08lx\n", remoteresult);
1765 if (status != S_OK) /* OLE/COM internal error */
1768 HeapFree(GetProcessHeap(),0,buf.base);
1769 ITypeInfo_Release(tinfo);
1770 LeaveCriticalSection(&tpinfo->crit);
1771 return remoteresult;
1774 HRESULT WINAPI ProxyIUnknown_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
1776 TMProxyImpl *proxy = (TMProxyImpl *)iface;
1778 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
1780 if (proxy->outerunknown)
1781 return IUnknown_QueryInterface(proxy->outerunknown, riid, ppv);
1783 FIXME("No interface\n");
1784 return E_NOINTERFACE;
1787 ULONG WINAPI ProxyIUnknown_AddRef(IUnknown *iface)
1789 TMProxyImpl *proxy = (TMProxyImpl *)iface;
1793 if (proxy->outerunknown)
1794 return IUnknown_AddRef(proxy->outerunknown);
1796 return 2; /* FIXME */
1799 ULONG WINAPI ProxyIUnknown_Release(IUnknown *iface)
1801 TMProxyImpl *proxy = (TMProxyImpl *)iface;
1805 if (proxy->outerunknown)
1806 return IUnknown_Release(proxy->outerunknown);
1808 return 1; /* FIXME */
1811 static HRESULT WINAPI
1812 PSFacBuf_CreateProxy(
1813 LPPSFACTORYBUFFER iface, IUnknown* pUnkOuter, REFIID riid,
1814 IRpcProxyBuffer **ppProxy, LPVOID *ppv)
1822 TRACE("(...%s...)\n",debugstr_guid(riid));
1823 hres = _get_typeinfo_for_iid(riid,&tinfo);
1825 ERR("No typeinfo for %s?\n",debugstr_guid(riid));
1828 nroffuncs = _nroffuncs(tinfo);
1829 proxy = CoTaskMemAlloc(sizeof(TMProxyImpl));
1830 if (!proxy) return E_OUTOFMEMORY;
1832 assert(sizeof(TMAsmProxy) == 12);
1834 proxy->outerunknown = pUnkOuter;
1835 proxy->asmstubs = VirtualAlloc(NULL, sizeof(TMAsmProxy) * nroffuncs, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
1836 if (!proxy->asmstubs) {
1837 ERR("Could not commit pages for proxy thunks\n");
1838 CoTaskMemFree(proxy);
1839 return E_OUTOFMEMORY;
1842 InitializeCriticalSection(&proxy->crit);
1844 proxy->lpvtbl = HeapAlloc(GetProcessHeap(),0,sizeof(LPBYTE)*nroffuncs);
1845 for (i=0;i<nroffuncs;i++) {
1846 TMAsmProxy *xasm = proxy->asmstubs+i;
1850 proxy->lpvtbl[i] = ProxyIUnknown_QueryInterface;
1853 proxy->lpvtbl[i] = ProxyIUnknown_AddRef;
1856 proxy->lpvtbl[i] = ProxyIUnknown_Release;
1860 /* nrofargs without This */
1863 hres = _get_funcdesc(tinfo,i,&tinfo2,&fdesc,NULL,NULL);
1864 ITypeInfo_Release(tinfo2);
1866 ERR("GetFuncDesc %lx should not fail here.\n",hres);
1869 /* some args take more than 4 byte on the stack */
1871 for (j=0;j<fdesc->cParams;j++)
1872 nrofargs += _argsize(fdesc->lprgelemdescParam[j].tdesc.vt);
1874 if (fdesc->callconv != CC_STDCALL) {
1875 ERR("calling convention is not stdcall????\n");
1878 /* popl %eax - return ptr
1885 * arg3 arg2 arg1 <method> <returnptr>
1887 xasm->popleax = 0x58;
1888 xasm->pushlval = 0x6a;
1890 xasm->pushleax = 0x50;
1891 xasm->lcall = 0xe8; /* relative jump */
1892 xasm->xcall = (DWORD)xCall;
1893 xasm->xcall -= (DWORD)&(xasm->lret);
1895 xasm->bytestopop= (nrofargs+2)*4; /* pop args, This, iMethod */
1896 proxy->lpvtbl[i] = xasm;
1901 proxy->lpvtbl2 = &tmproxyvtable;
1902 /* 1 reference for the proxy and 1 for the object */
1904 proxy->tinfo = tinfo;
1905 memcpy(&proxy->iid,riid,sizeof(*riid));
1907 *ppv = (LPVOID)proxy;
1908 *ppProxy = (IRpcProxyBuffer *)&(proxy->lpvtbl2);
1912 typedef struct _TMStubImpl {
1913 const IRpcStubBufferVtbl *lpvtbl;
1921 static HRESULT WINAPI
1922 TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface, REFIID riid, LPVOID *ppv)
1924 if (IsEqualIID(riid,&IID_IRpcStubBuffer)||IsEqualIID(riid,&IID_IUnknown)){
1925 *ppv = (LPVOID)iface;
1926 IRpcStubBuffer_AddRef(iface);
1929 FIXME("%s, not supported IID.\n",debugstr_guid(riid));
1930 return E_NOINTERFACE;
1934 TMStubImpl_AddRef(LPRPCSTUBBUFFER iface)
1936 TMStubImpl *This = (TMStubImpl *)iface;
1937 ULONG refCount = InterlockedIncrement(&This->ref);
1939 TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
1945 TMStubImpl_Release(LPRPCSTUBBUFFER iface)
1947 TMStubImpl *This = (TMStubImpl *)iface;
1948 ULONG refCount = InterlockedDecrement(&This->ref);
1950 TRACE("(%p)->(ref before=%lu)\n", This, refCount + 1);
1954 IRpcStubBuffer_Disconnect(iface);
1955 CoTaskMemFree(This);
1960 static HRESULT WINAPI
1961 TMStubImpl_Connect(LPRPCSTUBBUFFER iface, LPUNKNOWN pUnkServer)
1963 TMStubImpl *This = (TMStubImpl *)iface;
1965 TRACE("(%p)->(%p)\n", This, pUnkServer);
1967 IUnknown_AddRef(pUnkServer);
1968 This->pUnk = pUnkServer;
1973 TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface)
1975 TMStubImpl *This = (TMStubImpl *)iface;
1977 TRACE("(%p)->()\n", This);
1979 IUnknown_Release(This->pUnk);
1984 static HRESULT WINAPI
1986 LPRPCSTUBBUFFER iface, RPCOLEMESSAGE* xmsg,IRpcChannelBuffer*rpcchanbuf)
1990 TMStubImpl *This = (TMStubImpl *)iface;
1992 DWORD *args, res, *xargs, nrofargs;
1996 BSTR fname = NULL,iname = NULL;
1997 BOOL is_idispatch_getidsofnames = 0;
2000 memset(&buf,0,sizeof(buf));
2001 buf.size = xmsg->cbBuffer;
2002 buf.base = HeapAlloc(GetProcessHeap(), 0, xmsg->cbBuffer);
2003 memcpy(buf.base, xmsg->Buffer, xmsg->cbBuffer);
2005 buf.iid = IID_IUnknown;
2008 if (xmsg->iMethod == 0) { /* QI */
2010 /* in: IID, out: <iface> */
2012 xbuf_get(&buf,(LPBYTE)&xiid,sizeof(xiid));
2014 hres = _marshal_interface(&buf,&xiid,This->pUnk);
2015 xmsg->Buffer = buf.base; /* Might have been reallocated */
2016 xmsg->cbBuffer = buf.size;
2019 hres = _get_funcdesc(This->tinfo,xmsg->iMethod,&tinfo,&fdesc,&iname,&fname);
2021 ERR("GetFuncDesc on method %ld failed with %lx\n",xmsg->iMethod,hres);
2025 if (iname && fname && !lstrcmpW(iname, IDispatchW) && !lstrcmpW(fname, GetIDsOfNamesW))
2026 is_idispatch_getidsofnames = 1;
2028 if (iname) SysFreeString (iname);
2029 if (fname) SysFreeString (fname);
2031 /* Need them for hack below */
2032 memset(names,0,sizeof(names));
2033 ITypeInfo_GetNames(tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
2034 if (nrofnames > sizeof(names)/sizeof(names[0])) {
2035 ERR("Need more names!\n");
2038 /*dump_FUNCDESC(fdesc);*/
2040 for (i=0;i<fdesc->cParams;i++)
2041 nrofargs += _argsize(fdesc->lprgelemdescParam[i].tdesc.vt);
2042 args = HeapAlloc(GetProcessHeap(),0,(nrofargs+1)*sizeof(DWORD));
2043 if (!args) return E_OUTOFMEMORY;
2045 if (is_idispatch_getidsofnames) {
2046 hres = deserialize_IDispatch_GetIDsOfNames(TRUE,FALSE,args+1,&buf);
2048 FIXME("deserialize_IDispatch_GetIDsOfNames failed!\n");
2052 goto afterdeserialize;
2055 /* Allocate all stuff used by call. */
2057 for (i=0;i<fdesc->cParams;i++) {
2058 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
2059 BOOL isdeserialized = FALSE;
2061 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
2062 /* If the parameter is 'riid', we use it as interface IID
2063 * for a later ppvObject serialization.
2065 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
2067 /* deserialize DISPPARAM */
2068 if (!lstrcmpW(names[i+1],pdispparamsW)) {
2069 hres = deserialize_DISPPARAM_ptr(
2071 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
2079 ERR("Failed to deserialize DISPPARAM*, hres %lx\n",hres);
2082 isdeserialized = TRUE;
2084 if (!lstrcmpW(names[i+1],ppvObjectW)) {
2085 hres = deserialize_LPVOID_ptr(
2087 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
2095 isdeserialized = TRUE;
2098 if (!isdeserialized)
2099 hres = deserialize_param(
2101 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
2108 xargs += _argsize(elem->tdesc.vt);
2110 ERR("Failed to deserialize param %s, hres %lx\n",relaystr(names[i+1]),hres);
2115 hres = IUnknown_QueryInterface(This->pUnk,&(This->iid),(LPVOID*)&(args[0]));
2117 ERR("Does not support iface %s, returning %lx\n",debugstr_guid(&(This->iid)), hres);
2121 (*((FARPROC**)args[0]))[fdesc->oVft/4],
2126 IUnknown_Release((LPUNKNOWN)args[0]);
2129 /* special IDispatch::GetIDsOfNames serializer */
2130 if (is_idispatch_getidsofnames) {
2131 hres = serialize_IDispatch_GetIDsOfNames(FALSE,FALSE,args+1,&buf);
2133 FIXME("serialize of IDispatch::GetIDsOfNames failed!\n");
2136 goto afterserialize;
2139 for (i=0;i<fdesc->cParams;i++) {
2140 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
2141 BOOL isserialized = FALSE;
2143 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
2144 /* If the parameter is 'riid', we use it as interface IID
2145 * for a later ppvObject serialization.
2147 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
2149 /* DISPPARAMS* needs special serializer */
2150 if (!lstrcmpW(names[i+1],pdispparamsW)) {
2151 hres = serialize_DISPPARAM_ptr(
2153 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
2160 isserialized = TRUE;
2162 if (!lstrcmpW(names[i+1],ppvObjectW)) {
2163 hres = serialize_LPVOID_ptr(
2165 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
2173 isserialized = TRUE;
2177 hres = serialize_param(
2179 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
2186 xargs += _argsize(elem->tdesc.vt);
2188 ERR("Failed to stuballoc param, hres %lx\n",hres);
2193 hres = xbuf_add (&buf, (LPBYTE)&res, sizeof(DWORD));
2197 ITypeInfo_Release(tinfo);
2198 xmsg->cbBuffer = buf.curoff;
2199 I_RpcGetBuffer((RPC_MESSAGE *)xmsg);
2200 memcpy(xmsg->Buffer, buf.base, buf.curoff);
2201 HeapFree(GetProcessHeap(),0,args);
2205 static LPRPCSTUBBUFFER WINAPI
2206 TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface, REFIID riid) {
2207 FIXME("Huh (%s)?\n",debugstr_guid(riid));
2212 TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface) {
2213 TMStubImpl *This = (TMStubImpl *)iface;
2215 return This->ref; /*FIXME? */
2218 static HRESULT WINAPI
2219 TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface, LPVOID *ppv) {
2224 TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface, LPVOID ppv) {
2228 static const IRpcStubBufferVtbl tmstubvtbl = {
2229 TMStubImpl_QueryInterface,
2233 TMStubImpl_Disconnect,
2235 TMStubImpl_IsIIDSupported,
2236 TMStubImpl_CountRefs,
2237 TMStubImpl_DebugServerQueryInterface,
2238 TMStubImpl_DebugServerRelease
2241 static HRESULT WINAPI
2242 PSFacBuf_CreateStub(
2243 LPPSFACTORYBUFFER iface, REFIID riid,IUnknown *pUnkServer,
2244 IRpcStubBuffer** ppStub
2250 TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub);
2251 hres = _get_typeinfo_for_iid(riid,&tinfo);
2253 ERR("No typeinfo for %s?\n",debugstr_guid(riid));
2256 stub = CoTaskMemAlloc(sizeof(TMStubImpl));
2258 return E_OUTOFMEMORY;
2259 stub->lpvtbl = &tmstubvtbl;
2261 stub->tinfo = tinfo;
2262 memcpy(&(stub->iid),riid,sizeof(*riid));
2263 hres = IRpcStubBuffer_Connect((LPRPCSTUBBUFFER)stub,pUnkServer);
2264 *ppStub = (LPRPCSTUBBUFFER)stub;
2265 TRACE("IRpcStubBuffer: %p\n", stub);
2267 ERR("Connect to pUnkServer failed?\n");
2271 static const IPSFactoryBufferVtbl psfacbufvtbl = {
2272 PSFacBuf_QueryInterface,
2275 PSFacBuf_CreateProxy,
2279 /* This is the whole PSFactoryBuffer object, just the vtableptr */
2280 static const IPSFactoryBufferVtbl *lppsfac = &psfacbufvtbl;
2282 /***********************************************************************
2283 * DllGetClassObject [OLE32.63]
2286 TypeLibFac_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
2288 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)) {
2292 return E_NOINTERFACE;