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
33 #define NONAMELESSUNION
34 #define NONAMELESSSTRUCT
43 #include "wine/unicode.h"
46 #include "wine/debug.h"
49 static const WCHAR riidW[5] = {'r','i','i','d',0};
50 static const WCHAR pdispparamsW[] = {'p','d','i','s','p','p','a','r','a','m','s',0};
51 static const WCHAR ppvObjectW[] = {'p','p','v','O','b','j','e','c','t',0};
53 WINE_DEFAULT_DEBUG_CHANNEL(ole);
54 WINE_DECLARE_DEBUG_CHANNEL(olerelay);
56 typedef struct _marshal_state {
62 IID iid; /* HACK: for VT_VOID */
65 /* used in the olerelay code to avoid having the L"" stuff added by debugstr_w */
66 static char *relaystr(WCHAR *in) {
67 char *tmp = (char *)debugstr_w(in);
69 tmp[strlen(tmp)-1] = '\0';
74 xbuf_add(marshal_state *buf, LPBYTE stuff, DWORD size) {
75 while (buf->size - buf->curoff < size) {
78 buf->base = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,buf->base,buf->size);
82 buf->base = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,32);
88 memcpy(buf->base+buf->curoff,stuff,size);
94 xbuf_get(marshal_state *buf, LPBYTE stuff, DWORD size) {
95 if (buf->size < buf->curoff+size) return E_FAIL;
96 memcpy(stuff,buf->base+buf->curoff,size);
102 xbuf_skip(marshal_state *buf, DWORD size) {
103 if (buf->size < buf->curoff+size) return E_FAIL;
109 _unmarshal_interface(marshal_state *buf, REFIID riid, LPUNKNOWN *pUnk) {
111 ULARGE_INTEGER newpos;
112 LARGE_INTEGER seekto;
117 TRACE("...%s...\n",debugstr_guid(riid));
119 hres = xbuf_get(buf,(LPBYTE)&xsize,sizeof(xsize));
120 if (hres) return hres;
121 if (xsize == 0) return S_OK;
122 hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
124 FIXME("Stream create failed %lx\n",hres);
127 hres = IStream_Write(pStm,buf->base+buf->curoff,xsize,&res);
128 if (hres) { FIXME("stream write %lx\n",hres); return hres; }
129 memset(&seekto,0,sizeof(seekto));
130 hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
131 if (hres) { FIXME("Failed Seek %lx\n",hres); return hres;}
132 hres = CoUnmarshalInterface(pStm,riid,(LPVOID*)pUnk);
134 FIXME("Marshalling interface %s failed with %lx\n",debugstr_guid(riid),hres);
137 IStream_Release(pStm);
138 return xbuf_skip(buf,xsize);
142 _marshal_interface(marshal_state *buf, REFIID riid, LPUNKNOWN pUnk) {
147 ULARGE_INTEGER newpos;
148 LARGE_INTEGER seekto;
157 TRACE("...%s...\n",debugstr_guid(riid));
158 hres=IUnknown_QueryInterface(pUnk,riid,(LPVOID*)&newiface);
160 TRACE("%p does not support iface %s\n",pUnk,debugstr_guid(riid));
163 hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
165 FIXME("Stream create failed %lx\n",hres);
168 hres = CoMarshalInterface(pStm,riid,newiface,0,NULL,0);
169 IUnknown_Release(newiface);
171 FIXME("Marshalling interface %s failed with %lx\n",
172 debugstr_guid(riid),hres
176 hres = IStream_Stat(pStm,&ststg,0);
177 tempbuf = HeapAlloc(GetProcessHeap(), 0, ststg.cbSize.u.LowPart);
178 memset(&seekto,0,sizeof(seekto));
179 hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
180 if (hres) { FIXME("Failed Seek %lx\n",hres); goto fail;}
181 hres = IStream_Read(pStm,tempbuf,ststg.cbSize.u.LowPart,&res);
182 if (hres) { FIXME("Failed Read %lx\n",hres); goto fail;}
183 IStream_Release(pStm);
184 xsize = ststg.cbSize.u.LowPart;
185 xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
186 hres = xbuf_add(buf,tempbuf,ststg.cbSize.u.LowPart);
187 HeapFree(GetProcessHeap(),0,tempbuf);
191 xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
195 /********************* OLE Proxy/Stub Factory ********************************/
196 static HRESULT WINAPI
197 PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface, REFIID iid, LPVOID *ppv) {
198 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)||IsEqualIID(iid,&IID_IUnknown)) {
199 *ppv = (LPVOID)iface;
200 /* No ref counting, static class */
203 FIXME("(%s) unknown IID?\n",debugstr_guid(iid));
204 return E_NOINTERFACE;
207 static ULONG WINAPI PSFacBuf_AddRef(LPPSFACTORYBUFFER iface) { return 2; }
208 static ULONG WINAPI PSFacBuf_Release(LPPSFACTORYBUFFER iface) { return 1; }
211 _get_typeinfo_for_iid(REFIID riid, ITypeInfo**ti) {
214 char tlguid[200],typelibkey[300],interfacekey[300],ver[100];
217 DWORD tlguidlen, verlen, type, tlfnlen;
220 sprintf( interfacekey, "Interface\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\Typelib",
221 riid->Data1, riid->Data2, riid->Data3,
222 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
223 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7]
226 if (RegOpenKeyA(HKEY_CLASSES_ROOT,interfacekey,&ikey)) {
227 FIXME("No %s key found.\n",interfacekey);
231 tlguidlen = sizeof(tlguid);
232 if (RegQueryValueExA(ikey,NULL,NULL,&type,tlguid,&tlguidlen)) {
233 FIXME("Getting typelib guid failed.\n");
238 verlen = sizeof(ver);
239 if (RegQueryValueExA(ikey,"Version",NULL,&type,ver,&verlen)) {
240 FIXME("Could not get version value?\n");
245 sprintf(typelibkey,"Typelib\\%s\\%s\\0\\win32",tlguid,ver);
246 tlfnlen = sizeof(tlfn);
247 if (RegQueryValueA(HKEY_CLASSES_ROOT,typelibkey,tlfn,&tlfnlen)) {
248 FIXME("Could not get typelib fn?\n");
251 MultiByteToWideChar(CP_ACP, 0, tlfn, -1, tlfnW, -1);
252 hres = LoadTypeLib(tlfnW,&tl);
254 ERR("Failed to load typelib for %s, but it should be there.\n",debugstr_guid(riid));
257 hres = ITypeLib_GetTypeInfoOfGuid(tl,riid,ti);
259 ERR("typelib does not contain info for %s?\n",debugstr_guid(riid));
260 ITypeLib_Release(tl);
263 /* FIXME: do this? ITypeLib_Release(tl); */
267 /* Determine nr of functions. Since we use the toplevel interface and all
268 * inherited ones have lower numbers, we are ok to not to descent into
269 * the inheritance tree I think.
271 static int _nroffuncs(ITypeInfo *tinfo) {
278 hres = ITypeInfo_GetFuncDesc(tinfo,n,&fdesc);
281 if (fdesc->oVft/4 > max)
288 #include "pshpack1.h"
290 typedef struct _TMAsmProxy {
303 typedef struct _TMProxyImpl {
305 ICOM_VTABLE(IRpcProxyBuffer) *lpvtbl2;
308 TMAsmProxy *asmstubs;
310 IRpcChannelBuffer* chanbuf;
314 static HRESULT WINAPI
315 TMProxyImpl_QueryInterface(LPRPCPROXYBUFFER iface, REFIID riid, LPVOID *ppv) {
317 if (IsEqualIID(riid,&IID_IUnknown)||IsEqualIID(riid,&IID_IRpcProxyBuffer)) {
318 *ppv = (LPVOID)iface;
319 IRpcProxyBuffer_AddRef(iface);
322 FIXME("no interface for %s\n",debugstr_guid(riid));
323 return E_NOINTERFACE;
327 TMProxyImpl_AddRef(LPRPCPROXYBUFFER iface) {
328 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
336 TMProxyImpl_Release(LPRPCPROXYBUFFER iface) {
337 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
341 if (This->ref) return This->ref;
342 if (This->chanbuf) IRpcChannelBuffer_Release(This->chanbuf);
343 VirtualFree(This->asmstubs, 0, MEM_RELEASE);
344 HeapFree(GetProcessHeap(),0,This);
348 static HRESULT WINAPI
350 LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer
352 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
354 TRACE("(%p)\n",pRpcChannelBuffer);
355 This->chanbuf = pRpcChannelBuffer;
356 IRpcChannelBuffer_AddRef(This->chanbuf);
361 TMProxyImpl_Disconnect(LPRPCPROXYBUFFER iface) {
362 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
365 IRpcChannelBuffer_Release(This->chanbuf);
366 This->chanbuf = NULL;
370 static ICOM_VTABLE(IRpcProxyBuffer) tmproxyvtable = {
371 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
372 TMProxyImpl_QueryInterface,
376 TMProxyImpl_Disconnect
379 /* how much space do we use on stack in DWORD steps. */
384 return sizeof(DATE)/sizeof(DWORD);
386 return (sizeof(VARIANT)+3)/sizeof(DWORD);
393 _xsize(TYPEDESC *td) {
398 return sizeof(VARIANT)+3;
401 ARRAYDESC *adesc = td->u.lpadesc;
403 for (i=0;i<adesc->cDims;i++)
404 arrsize *= adesc->rgbounds[i].cElements;
405 return arrsize*_xsize(&adesc->tdescElem);
430 TRACE("(tdesc.vt %d)\n",tdesc->vt);
433 case VT_EMPTY: /* nothing. empty variant for instance */
444 if (debugout) TRACE_(olerelay)("%lx",*arg);
446 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
450 VARIANT *vt = (VARIANT*)arg;
451 DWORD vttype = V_VT(vt);
453 if (debugout) TRACE_(olerelay)("Vt(%ld)(",vttype);
456 hres = xbuf_add(buf,(LPBYTE)&vttype,sizeof(vttype));
457 if (hres) return hres;
459 /* need to recurse since we need to free the stuff */
460 hres = serialize_param(tinfo,writeit,debugout,dealloc,&tdesc2,&(V_I4(vt)),buf);
461 if (debugout) TRACE_(olerelay)(")");
467 TRACE_(olerelay)("%s",relaystr((BSTR)*arg));
469 TRACE_(olerelay)("<bstr NULL>");
474 hres = xbuf_add(buf,(LPBYTE)&fakelen,4);
478 DWORD *bstr = ((DWORD*)(*arg))-1;
480 hres = xbuf_add(buf,(LPBYTE)bstr,bstr[0]+4);
487 SysFreeString((BSTR)*arg);
493 if (debugout) TRACE_(olerelay)("*");
495 cookie = *arg ? 0x42424242 : 0;
496 hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
501 if (debugout) TRACE_(olerelay)("NULL");
504 hres = serialize_param(tinfo,writeit,debugout,dealloc,tdesc->u.lptdesc,(DWORD*)*arg,buf);
505 if (dealloc) HeapFree(GetProcessHeap(),0,(LPVOID)arg);
509 if (debugout) TRACE_(olerelay)("unk(0x%lx)",*arg);
511 hres = _marshal_interface(buf,&IID_IUnknown,(LPUNKNOWN)*arg);
514 if (debugout) TRACE_(olerelay)("idisp(0x%lx)",*arg);
516 hres = _marshal_interface(buf,&IID_IDispatch,(LPUNKNOWN)*arg);
519 if (debugout) TRACE_(olerelay)("<void>");
521 case VT_USERDEFINED: {
525 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
527 FIXME("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
530 ITypeInfo_GetTypeAttr(tinfo2,&tattr);
531 switch (tattr->typekind) {
533 case TKIND_INTERFACE:
535 hres=_marshal_interface(buf,&(tattr->guid),(LPUNKNOWN)arg);
539 if (debugout) TRACE_(olerelay)("{");
540 for (i=0;i<tattr->cVars;i++) {
545 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
547 FIXME("Could not get vardesc of %d\n",i);
550 /* Need them for hack below */
552 memset(names,0,sizeof(names));
553 hres = ITypeInfo_GetNames(tinfo2,vdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
554 if (nrofnames > sizeof(names)/sizeof(names[0])) {
555 ERR("Need more names!\n");
557 if (!hres && debugout)
558 TRACE_(olerelay)("%s=",relaystr(names[0]));
560 elem2 = &vdesc->elemdescVar;
561 tdesc2 = &elem2->tdesc;
562 hres = serialize_param(
568 (DWORD*)(((LPBYTE)arg)+vdesc->u.oInst),
573 if (debugout && (i<(tattr->cVars-1)))
574 TRACE_(olerelay)(",");
576 if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
577 memcpy(&(buf->iid),arg,sizeof(buf->iid));
578 if (debugout) TRACE_(olerelay)("}");
582 FIXME("Unhandled typekind %d\n",tattr->typekind);
586 ITypeInfo_Release(tinfo2);
590 ARRAYDESC *adesc = tdesc->u.lpadesc;
593 if (debugout) TRACE_(olerelay)("carr");
594 for (i=0;i<adesc->cDims;i++) {
595 if (debugout) TRACE_(olerelay)("[%ld]",adesc->rgbounds[i].cElements);
596 arrsize *= adesc->rgbounds[i].cElements;
598 if (debugout) TRACE_(olerelay)("[");
599 for (i=0;i<arrsize;i++) {
600 hres = serialize_param(tinfo, writeit, debugout, dealloc, &adesc->tdescElem, (DWORD*)((LPBYTE)arg+i*_xsize(&adesc->tdescElem)), buf);
603 if (debugout && (i<arrsize-1)) TRACE_(olerelay)(",");
605 if (debugout) TRACE_(olerelay)("]");
609 ERR("Unhandled marshal type %d.\n",tdesc->vt);
615 serialize_LPVOID_ptr(
627 if ((tdesc->vt != VT_PTR) ||
628 (tdesc->u.lptdesc->vt != VT_PTR) ||
629 (tdesc->u.lptdesc->u.lptdesc->vt != VT_VOID)
631 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
634 cookie = (*arg) ? 0x42424242: 0x0;
636 hres = xbuf_add(buf, (LPVOID)&cookie, sizeof(cookie));
641 if (debugout) TRACE_(olerelay)("<lpvoid NULL>");
645 TRACE_(olerelay)("ppv(%p)",*(LPUNKNOWN*)*arg);
647 hres = _marshal_interface(buf,&(buf->iid),*(LPUNKNOWN*)*arg);
652 HeapFree(GetProcessHeap(),0,(LPVOID)*arg);
657 serialize_DISPPARAM_ptr(
671 if ((tdesc->vt != VT_PTR) || (tdesc->u.lptdesc->vt != VT_USERDEFINED)) {
672 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
676 cookie = *arg ? 0x42424242 : 0x0;
678 hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
683 if (debugout) TRACE_(olerelay)("<DISPPARAMS NULL>");
686 disp = (DISPPARAMS*)*arg;
688 hres = xbuf_add(buf,(LPBYTE)&disp->cArgs,sizeof(disp->cArgs));
692 if (debugout) TRACE_(olerelay)("D{");
693 for (i=0;i<disp->cArgs;i++) {
696 vtdesc.vt = VT_VARIANT;
703 (DWORD*)(disp->rgvarg+i),
706 if (debugout && (i<disp->cArgs-1))
707 TRACE_(olerelay)(",");
710 HeapFree(GetProcessHeap(),0,disp->rgvarg);
712 hres = xbuf_add(buf,(LPBYTE)&disp->cNamedArgs,sizeof(disp->cNamedArgs));
716 if (debugout) TRACE_(olerelay)("}{");
717 for (i=0;i<disp->cNamedArgs;i++) {
727 (DWORD*)(disp->rgdispidNamedArgs+i),
730 if (debugout && (i<disp->cNamedArgs-1))
731 TRACE_(olerelay)(",");
733 if (debugout) TRACE_(olerelay)("}");
735 HeapFree(GetProcessHeap(),0,disp->rgdispidNamedArgs);
736 HeapFree(GetProcessHeap(),0,disp);
753 TRACE("vt %d at %p\n",tdesc->vt,arg);
758 if (debugout) TRACE_(olerelay)("<empty>");
761 if (debugout) TRACE_(olerelay)("<null>");
764 VARIANT *vt = (VARIANT*)arg;
769 hres = xbuf_get(buf,(LPBYTE)&vttype,sizeof(vttype));
771 FIXME("vt type not read?\n");
774 memset(&tdesc2,0,sizeof(tdesc2));
777 if (debugout) TRACE_(olerelay)("Vt(%ld)(",vttype);
778 hres = deserialize_param(tinfo, readit, debugout, alloc, &tdesc2, &(V_I4(vt)), buf);
779 TRACE_(olerelay)(")");
787 case VT_BOOL: case VT_I4: case VT_UI4: case VT_UINT: case VT_R4:
791 hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
792 if (hres) FIXME("Failed to read integer 4 byte\n");
794 if (debugout) TRACE_(olerelay)("%lx",*arg);
801 hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
803 FIXME("failed to read bstr klen\n");
808 if (debugout) TRACE_(olerelay)("<bstr NULL>");
810 str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len+sizeof(WCHAR));
811 hres = xbuf_get(buf,(LPBYTE)str,len);
813 FIXME("Failed to read BSTR.\n");
816 *arg = (DWORD)SysAllocStringLen(str,len);
817 if (debugout) TRACE_(olerelay)("%s",relaystr(str));
818 HeapFree(GetProcessHeap(),0,str);
829 derefhere = (tdesc->u.lptdesc->vt != VT_USERDEFINED);
832 hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
834 FIXME("Failed to load pointer cookie.\n");
837 if (cookie != 0x42424242) {
838 if (debugout) TRACE_(olerelay)("NULL");
842 if (debugout) TRACE_(olerelay)("*");
846 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,_xsize(tdesc->u.lptdesc));
849 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, (LPDWORD)*arg, buf);
851 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, arg, buf);
854 /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
856 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
859 hres = _unmarshal_interface(buf,&IID_IUnknown,(LPUNKNOWN*)arg);
861 TRACE_(olerelay)("unk(%p)",arg);
866 hres = _unmarshal_interface(buf,&IID_IDispatch,(LPUNKNOWN*)arg);
868 TRACE_(olerelay)("idisp(%p)",arg);
871 if (debugout) TRACE_(olerelay)("<void>");
873 case VT_USERDEFINED: {
877 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
879 FIXME("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
882 hres = ITypeInfo_GetTypeAttr(tinfo2,&tattr);
884 FIXME("Could not get typeattr in VT_USERDEFINED.\n");
887 *arg = (DWORD)HeapAlloc(GetProcessHeap(),0,tattr->cbSizeInstance);
888 switch (tattr->typekind) {
890 case TKIND_INTERFACE:
892 hres = _unmarshal_interface(buf,&(tattr->guid),(LPUNKNOWN*)arg);
897 if (debugout) TRACE_(olerelay)("{");
898 for (i=0;i<tattr->cVars;i++) {
901 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
903 FIXME("Could not get vardesc of %d\n",i);
906 hres = deserialize_param(
911 &vdesc->elemdescVar.tdesc,
912 (DWORD*)(((LPBYTE)*arg)+vdesc->u.oInst),
915 if (debugout && (i<tattr->cVars-1)) TRACE_(olerelay)(",");
917 if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
918 memcpy(&(buf->iid),(LPBYTE)*arg,sizeof(buf->iid));
919 if (debugout) TRACE_(olerelay)("}");
923 ERR("Unhandled typekind %d\n",tattr->typekind);
929 FIXME("failed to stuballoc in TKIND_RECORD.\n");
930 ITypeInfo_Release(tinfo2);
934 /* arg is pointing to the start of the array. */
935 ARRAYDESC *adesc = tdesc->u.lpadesc;
938 if (adesc->cDims > 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
939 for (i=0;i<adesc->cDims;i++)
940 arrsize *= adesc->rgbounds[i].cElements;
941 for (i=0;i<arrsize;i++)
948 (DWORD*)((LPBYTE)(arg)+i*_xsize(&adesc->tdescElem)),
954 ERR("No handler for VT type %d!\n",tdesc->vt);
961 deserialize_LPVOID_ptr(
973 if ((tdesc->vt != VT_PTR) ||
974 (tdesc->u.lptdesc->vt != VT_PTR) ||
975 (tdesc->u.lptdesc->u.lptdesc->vt != VT_VOID)
977 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
981 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(LPVOID));
983 hres = xbuf_get(buf, (LPVOID)&cookie, sizeof(cookie));
986 if (cookie != 0x42424242) {
988 if (debugout) TRACE_(olerelay)("<lpvoid NULL>");
993 hres = _unmarshal_interface(buf,&buf->iid,(LPUNKNOWN*)*arg);
997 if (debugout) TRACE_(olerelay)("ppv(%p)",(LPVOID)*arg);
1002 deserialize_DISPPARAM_ptr(
1016 if ((tdesc->vt != VT_PTR) || (tdesc->u.lptdesc->vt != VT_USERDEFINED)) {
1017 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
1021 hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
1026 if (debugout) TRACE_(olerelay)("<DISPPARAMS NULL>");
1031 *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPPARAMS));
1032 disps = (DISPPARAMS*)*arg;
1035 hres = xbuf_get(buf, (LPBYTE)&disps->cArgs, sizeof(disps->cArgs));
1039 disps->rgvarg = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(VARIANT)*disps->cArgs);
1040 if (debugout) TRACE_(olerelay)("D{");
1041 for (i=0; i< disps->cArgs; i++) {
1044 vdesc.vt = VT_VARIANT;
1045 hres = deserialize_param(
1051 (DWORD*)(disps->rgvarg+i),
1055 if (debugout) TRACE_(olerelay)("}{");
1056 hres = xbuf_get(buf, (LPBYTE)&disps->cNamedArgs, sizeof(disps->cNamedArgs));
1059 if (disps->cNamedArgs) {
1061 disps->rgdispidNamedArgs = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPID)*disps->cNamedArgs);
1062 for (i=0; i< disps->cNamedArgs; i++) {
1066 hres = deserialize_param(
1072 (DWORD*)(disps->rgdispidNamedArgs+i),
1075 if (debugout && i<(disps->cNamedArgs-1)) TRACE_(olerelay)(",");
1078 if (debugout) TRACE_(olerelay)("}");
1082 /* Searches function, also in inherited interfaces */
1085 ITypeInfo *tinfo, int iMethod, FUNCDESC **fdesc, BSTR *iname, BSTR *fname
1090 if (fname) *fname = NULL;
1091 if (iname) *iname = NULL;
1094 hres = ITypeInfo_GetFuncDesc(tinfo, i, fdesc);
1100 hres = ITypeInfo_GetTypeAttr(tinfo, &attr);
1102 FIXME("GetTypeAttr failed with %lx\n",hres);
1105 /* Not found, so look in inherited ifaces. */
1106 for (j=0;j<attr->cImplTypes;j++) {
1107 hres = ITypeInfo_GetRefTypeOfImplType(tinfo, j, &href);
1109 FIXME("Did not find a reftype for interface offset %d?\n",j);
1112 hres = ITypeInfo_GetRefTypeInfo(tinfo, href, &tinfo2);
1114 FIXME("Did not find a typeinfo for reftype %ld?\n",href);
1117 hres = _get_funcdesc(tinfo2,iMethod,fdesc,iname,fname);
1118 ITypeInfo_Release(tinfo2);
1119 if (!hres) return S_OK;
1123 if (((*fdesc)->oVft/4) == iMethod) {
1125 ITypeInfo_GetDocumentation(tinfo,(*fdesc)->memid,fname,NULL,NULL,NULL);
1127 ITypeInfo_GetDocumentation(tinfo,-1,iname,NULL,NULL,NULL);
1136 xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */) {
1137 DWORD *args = ((DWORD*)&tpinfo)+1, *xargs;
1140 int i, relaydeb = TRACE_ON(olerelay);
1148 hres = _get_funcdesc(tpinfo->tinfo,method,&fdesc,&iname,&fname);
1150 ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method);
1155 TRACE_(olerelay)("->");
1157 TRACE_(olerelay)("%s:",relaystr(iname));
1159 TRACE_(olerelay)("%s(%d)",relaystr(fname),method);
1161 TRACE_(olerelay)("%d",method);
1162 TRACE_(olerelay)("(");
1163 if (iname) SysFreeString(iname);
1164 if (fname) SysFreeString(fname);
1166 /* Need them for hack below */
1167 memset(names,0,sizeof(names));
1168 if (ITypeInfo_GetNames(tpinfo->tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames))
1170 if (nrofnames > sizeof(names)/sizeof(names[0]))
1171 ERR("Need more names!\n");
1173 memset(&buf,0,sizeof(buf));
1174 buf.iid = IID_IUnknown;
1176 xbuf_add(&buf,(LPBYTE)args[0],sizeof(IID));
1177 if (relaydeb) TRACE_(olerelay)("riid=%s,[out]",debugstr_guid((REFIID)args[0]));
1180 for (i=0;i<fdesc->cParams;i++) {
1181 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1182 BOOL isserialized = FALSE;
1184 if (i) TRACE_(olerelay)(",");
1185 if (i+1<nrofnames && names[i+1])
1186 TRACE_(olerelay)("%s=",relaystr(names[i+1]));
1188 /* No need to marshal other data than FIN */
1189 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN)) {
1190 xargs+=_argsize(elem->tdesc.vt);
1191 if (relaydeb) TRACE_(olerelay)("[out]");
1194 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1195 /* If the parameter is 'riid', we use it as interface IID
1196 * for a later ppvObject serialization.
1198 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1200 /* DISPPARAMS* needs special serializer */
1201 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1202 hres = serialize_DISPPARAM_ptr(
1204 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1211 isserialized = TRUE;
1213 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1214 hres = serialize_LPVOID_ptr(
1216 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1224 isserialized = TRUE;
1228 hres = serialize_param(
1230 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1239 FIXME("Failed to serialize param, hres %lx\n",hres);
1242 xargs+=_argsize(elem->tdesc.vt);
1245 if (relaydeb) TRACE_(olerelay)(")");
1246 memset(&msg,0,sizeof(msg));
1247 msg.cbBuffer = buf.curoff;
1248 msg.iMethod = method;
1249 hres = IRpcChannelBuffer_GetBuffer(tpinfo->chanbuf,&msg,&(tpinfo->iid));
1251 FIXME("RpcChannelBuffer GetBuffer failed, %lx\n",hres);
1254 memcpy(msg.Buffer,buf.base,buf.curoff);
1255 if (relaydeb) TRACE_(olerelay)("\n");
1256 hres = IRpcChannelBuffer_SendReceive(tpinfo->chanbuf,&msg,&status);
1258 FIXME("RpcChannelBuffer SendReceive failed, %lx\n",hres);
1262 if (relaydeb) TRACE_(olerelay)(" = %08lx (",status);
1264 buf.base = HeapReAlloc(GetProcessHeap(),0,buf.base,msg.cbBuffer);
1266 buf.base = HeapAlloc(GetProcessHeap(),0,msg.cbBuffer);
1267 buf.size = msg.cbBuffer;
1268 memcpy(buf.base,msg.Buffer,buf.size);
1271 _unmarshal_interface(&buf,(REFIID)args[0],(LPUNKNOWN*)args[1]);
1272 if (relaydeb) TRACE_(olerelay)("[in],%p",*((DWORD**)args[1]));
1275 for (i=0;i<fdesc->cParams;i++) {
1276 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1277 BOOL isdeserialized = FALSE;
1280 if (i) TRACE_(olerelay)(",");
1281 if (i+1<nrofnames && names[i+1]) TRACE_(olerelay)("%s=",relaystr(names[i+1]));
1283 /* No need to marshal other data than FOUT I think */
1284 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT)) {
1285 xargs += _argsize(elem->tdesc.vt);
1286 if (relaydeb) TRACE_(olerelay)("[in]");
1289 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1290 /* If the parameter is 'riid', we use it as interface IID
1291 * for a later ppvObject serialization.
1293 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1295 /* deserialize DISPPARAM */
1296 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1297 hres = deserialize_DISPPARAM_ptr(
1299 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1307 FIXME("Failed to deserialize DISPPARAM*, hres %lx\n",hres);
1310 isdeserialized = TRUE;
1312 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1313 hres = deserialize_LPVOID_ptr(
1315 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1323 isdeserialized = TRUE;
1326 if (!isdeserialized)
1327 hres = deserialize_param(
1329 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1337 FIXME("Failed to unmarshall param, hres %lx\n",hres);
1340 xargs += _argsize(elem->tdesc.vt);
1343 if (relaydeb) TRACE_(olerelay)(")\n");
1344 HeapFree(GetProcessHeap(),0,buf.base);
1348 static HRESULT WINAPI
1349 PSFacBuf_CreateProxy(
1350 LPPSFACTORYBUFFER iface, IUnknown* pUnkOuter, REFIID riid,
1351 IRpcProxyBuffer **ppProxy, LPVOID *ppv
1359 TRACE("(...%s...)\n",debugstr_guid(riid));
1360 hres = _get_typeinfo_for_iid(riid,&tinfo);
1362 FIXME("No typeinfo for %s?\n",debugstr_guid(riid));
1365 nroffuncs = _nroffuncs(tinfo);
1366 proxy = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TMProxyImpl));
1367 if (!proxy) return E_OUTOFMEMORY;
1369 assert(sizeof(TMAsmProxy) == 12);
1371 proxy->asmstubs = VirtualAlloc(NULL, sizeof(TMAsmProxy) * nroffuncs, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
1372 if (!proxy->asmstubs) {
1373 ERR("Could not commit pages for proxy thunks\n");
1374 HeapFree(GetProcessHeap(), 0, proxy);
1375 return E_OUTOFMEMORY;
1378 proxy->lpvtbl = HeapAlloc(GetProcessHeap(),0,sizeof(LPBYTE)*nroffuncs);
1379 for (i=0;i<nroffuncs;i++) {
1381 TMAsmProxy *xasm = proxy->asmstubs+i;
1383 /* nrofargs without This */
1385 case 0: nrofargs = 2;
1387 case 1: case 2: nrofargs = 0;
1391 hres = _get_funcdesc(tinfo,i,&fdesc,NULL,NULL);
1393 FIXME("GetFuncDesc %lx should not fail here.\n",hres);
1396 /* some args take more than 4 byte on the stack */
1398 for (j=0;j<fdesc->cParams;j++)
1399 nrofargs += _argsize(fdesc->lprgelemdescParam[j].tdesc.vt);
1401 if (fdesc->callconv != CC_STDCALL) {
1402 ERR("calling convention is not stdcall????\n");
1408 /* popl %eax - return ptr
1415 * arg3 arg2 arg1 <method> <returnptr>
1417 xasm->popleax = 0x58;
1418 xasm->pushlval = 0x6a;
1420 xasm->pushleax = 0x50;
1421 xasm->lcall = 0xe8; /* relative jump */
1422 xasm->xcall = (DWORD)xCall;
1423 xasm->xcall -= (DWORD)&(xasm->lret);
1425 xasm->bytestopop= (nrofargs+2)*4; /* pop args, This, iMethod */
1426 proxy->lpvtbl[i] = (DWORD)xasm;
1428 proxy->lpvtbl2 = &tmproxyvtable;
1429 /* 1 reference for the proxy and 1 for the object */
1431 proxy->tinfo = tinfo;
1432 memcpy(&proxy->iid,riid,sizeof(*riid));
1433 *ppv = (LPVOID)proxy;
1434 *ppProxy = (IRpcProxyBuffer *)&(proxy->lpvtbl2);
1438 typedef struct _TMStubImpl {
1439 ICOM_VTABLE(IRpcStubBuffer) *lpvtbl;
1447 static HRESULT WINAPI
1448 TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface, REFIID riid, LPVOID *ppv) {
1449 if (IsEqualIID(riid,&IID_IRpcStubBuffer)||IsEqualIID(riid,&IID_IUnknown)){
1450 *ppv = (LPVOID)iface;
1451 IRpcStubBuffer_AddRef(iface);
1454 FIXME("%s, not supported IID.\n",debugstr_guid(riid));
1455 return E_NOINTERFACE;
1459 TMStubImpl_AddRef(LPRPCSTUBBUFFER iface) {
1460 ICOM_THIS(TMStubImpl,iface);
1462 TRACE("(%p) before %lu\n", This, This->ref);
1469 TMStubImpl_Release(LPRPCSTUBBUFFER iface) {
1470 ICOM_THIS(TMStubImpl,iface);
1472 TRACE("(%p) after %lu\n", This, This->ref-1);
1478 IRpcStubBuffer_Disconnect(iface);
1480 HeapFree(GetProcessHeap(),0,This);
1484 static HRESULT WINAPI
1485 TMStubImpl_Connect(LPRPCSTUBBUFFER iface, LPUNKNOWN pUnkServer) {
1486 ICOM_THIS(TMStubImpl,iface);
1488 TRACE("(%p)->(%p)\n", This, pUnkServer);
1490 IUnknown_AddRef(pUnkServer);
1491 This->pUnk = pUnkServer;
1496 TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface) {
1497 ICOM_THIS(TMStubImpl,iface);
1499 TRACE("(%p)->()\n", This);
1501 IUnknown_Release(This->pUnk);
1506 static HRESULT WINAPI
1508 LPRPCSTUBBUFFER iface, RPCOLEMESSAGE* xmsg,IRpcChannelBuffer*rpcchanbuf
1512 ICOM_THIS(TMStubImpl,iface);
1514 DWORD *args, res, *xargs, nrofargs;
1519 memset(&buf,0,sizeof(buf));
1520 buf.size = xmsg->cbBuffer;
1521 buf.base = xmsg->Buffer;
1523 buf.iid = IID_IUnknown;
1526 if (xmsg->iMethod == 0) { /* QI */
1528 /* in: IID, out: <iface> */
1530 xbuf_get(&buf,(LPBYTE)&xiid,sizeof(xiid));
1532 hres = _marshal_interface(&buf,&xiid,This->pUnk);
1533 xmsg->Buffer = buf.base; /* Might have been reallocated */
1534 xmsg->cbBuffer = buf.size;
1537 hres = _get_funcdesc(This->tinfo,xmsg->iMethod,&fdesc,NULL,NULL);
1539 FIXME("GetFuncDesc on method %ld failed with %lx\n",xmsg->iMethod,hres);
1542 /* Need them for hack below */
1543 memset(names,0,sizeof(names));
1544 ITypeInfo_GetNames(This->tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
1545 if (nrofnames > sizeof(names)/sizeof(names[0])) {
1546 ERR("Need more names!\n");
1549 /*dump_FUNCDESC(fdesc);*/
1551 for (i=0;i<fdesc->cParams;i++)
1552 nrofargs += _argsize(fdesc->lprgelemdescParam[i].tdesc.vt);
1553 args = HeapAlloc(GetProcessHeap(),0,(nrofargs+1)*sizeof(DWORD));
1554 if (!args) return E_OUTOFMEMORY;
1556 /* Allocate all stuff used by call. */
1558 for (i=0;i<fdesc->cParams;i++) {
1559 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1560 BOOL isdeserialized = FALSE;
1562 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1563 /* If the parameter is 'riid', we use it as interface IID
1564 * for a later ppvObject serialization.
1566 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1568 /* deserialize DISPPARAM */
1569 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1570 hres = deserialize_DISPPARAM_ptr(
1572 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1580 FIXME("Failed to deserialize DISPPARAM*, hres %lx\n",hres);
1583 isdeserialized = TRUE;
1585 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1586 hres = deserialize_LPVOID_ptr(
1588 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1596 isdeserialized = TRUE;
1599 if (!isdeserialized)
1600 hres = deserialize_param(
1602 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1609 xargs += _argsize(elem->tdesc.vt);
1611 FIXME("Failed to deserialize param %s, hres %lx\n",relaystr(names[i+1]),hres);
1615 hres = IUnknown_QueryInterface(This->pUnk,&(This->iid),(LPVOID*)&(args[0]));
1617 ERR("Does not support iface %s\n",debugstr_guid(&(This->iid)));
1621 (*((FARPROC**)args[0]))[fdesc->oVft/4],
1626 IUnknown_Release((LPUNKNOWN)args[0]);
1629 for (i=0;i<fdesc->cParams;i++) {
1630 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1631 BOOL isserialized = FALSE;
1633 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1634 /* If the parameter is 'riid', we use it as interface IID
1635 * for a later ppvObject serialization.
1637 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1639 /* DISPPARAMS* needs special serializer */
1640 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1641 hres = serialize_DISPPARAM_ptr(
1643 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1650 isserialized = TRUE;
1652 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1653 hres = serialize_LPVOID_ptr(
1655 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1663 isserialized = TRUE;
1667 hres = serialize_param(
1669 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1676 xargs += _argsize(elem->tdesc.vt);
1678 FIXME("Failed to stuballoc param, hres %lx\n",hres);
1682 /* might need to use IRpcChannelBuffer_GetBuffer ? */
1683 xmsg->cbBuffer = buf.curoff;
1684 xmsg->Buffer = buf.base;
1685 HeapFree(GetProcessHeap(),0,args);
1689 static LPRPCSTUBBUFFER WINAPI
1690 TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface, REFIID riid) {
1691 FIXME("Huh (%s)?\n",debugstr_guid(riid));
1696 TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface) {
1697 ICOM_THIS(TMStubImpl,iface);
1699 return This->ref; /*FIXME? */
1702 static HRESULT WINAPI
1703 TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface, LPVOID *ppv) {
1708 TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface, LPVOID ppv) {
1712 ICOM_VTABLE(IRpcStubBuffer) tmstubvtbl = {
1713 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1714 TMStubImpl_QueryInterface,
1718 TMStubImpl_Disconnect,
1720 TMStubImpl_IsIIDSupported,
1721 TMStubImpl_CountRefs,
1722 TMStubImpl_DebugServerQueryInterface,
1723 TMStubImpl_DebugServerRelease
1726 static HRESULT WINAPI
1727 PSFacBuf_CreateStub(
1728 LPPSFACTORYBUFFER iface, REFIID riid,IUnknown *pUnkServer,
1729 IRpcStubBuffer** ppStub
1735 TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub);
1736 hres = _get_typeinfo_for_iid(riid,&tinfo);
1738 FIXME("No typeinfo for %s?\n",debugstr_guid(riid));
1741 stub = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TMStubImpl));
1743 return E_OUTOFMEMORY;
1744 stub->lpvtbl = &tmstubvtbl;
1746 stub->tinfo = tinfo;
1747 memcpy(&(stub->iid),riid,sizeof(*riid));
1748 hres = IRpcStubBuffer_Connect((LPRPCSTUBBUFFER)stub,pUnkServer);
1749 *ppStub = (LPRPCSTUBBUFFER)stub;
1750 TRACE("IRpcStubBuffer: %p\n", stub);
1752 FIXME("Connect to pUnkServer failed?\n");
1756 static ICOM_VTABLE(IPSFactoryBuffer) psfacbufvtbl = {
1757 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1758 PSFacBuf_QueryInterface,
1761 PSFacBuf_CreateProxy,
1765 /* This is the whole PSFactoryBuffer object, just the vtableptr */
1766 static ICOM_VTABLE(IPSFactoryBuffer) *lppsfac = &psfacbufvtbl;
1768 /***********************************************************************
1769 * DllGetClassObject [OLE32.63]
1772 TypeLibFac_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
1774 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)) {
1778 return E_NOINTERFACE;