4 * Copyright 2002 Marcus Meissner
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #define NONAMELESSUNION
31 #define NONAMELESSSTRUCT
40 #include "wine/unicode.h"
43 #include "wine/debug.h"
46 static const WCHAR riidW[5] = {'r','i','i','d',0};
47 static const WCHAR pdispparamsW[] = {'p','d','i','s','p','p','a','r','a','m','s',0};
48 static const WCHAR ppvObjectW[] = {'p','p','v','O','b','j','e','c','t',0};
50 WINE_DEFAULT_DEBUG_CHANNEL(ole);
51 WINE_DECLARE_DEBUG_CHANNEL(olerelay);
53 typedef struct _marshal_state {
59 IID iid; /* HACK: for VT_VOID */
63 xbuf_add(marshal_state *buf, LPBYTE stuff, DWORD size) {
64 while (buf->size - buf->curoff < size) {
67 buf->base = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,buf->base,buf->size);
71 buf->base = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,32);
77 memcpy(buf->base+buf->curoff,stuff,size);
83 xbuf_get(marshal_state *buf, LPBYTE stuff, DWORD size) {
84 if (buf->size < buf->curoff+size) return E_FAIL;
85 memcpy(stuff,buf->base+buf->curoff,size);
91 xbuf_skip(marshal_state *buf, DWORD size) {
92 if (buf->size < buf->curoff+size) return E_FAIL;
98 _unmarshal_interface(marshal_state *buf, REFIID riid, LPUNKNOWN *pUnk) {
100 ULARGE_INTEGER newpos;
101 LARGE_INTEGER seekto;
106 TRACE("...%s...\n",debugstr_guid(riid));
108 hres = xbuf_get(buf,(LPBYTE)&xsize,sizeof(xsize));
109 if (hres) return hres;
110 if (xsize == 0) return S_OK;
111 hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
113 FIXME("Stream create failed %lx\n",hres);
116 hres = IStream_Write(pStm,buf->base+buf->curoff,xsize,&res);
117 if (hres) { FIXME("stream write %lx\n",hres); return hres; }
118 memset(&seekto,0,sizeof(seekto));
119 hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
120 if (hres) { FIXME("Failed Seek %lx\n",hres); return hres;}
121 hres = CoUnmarshalInterface(pStm,riid,(LPVOID*)pUnk);
123 FIXME("Marshalling interface %s failed with %lx\n",debugstr_guid(riid),hres);
126 IStream_Release(pStm);
127 return xbuf_skip(buf,xsize);
131 _marshal_interface(marshal_state *buf, REFIID riid, LPUNKNOWN pUnk) {
136 ULARGE_INTEGER newpos;
137 LARGE_INTEGER seekto;
146 TRACE("...%s...\n",debugstr_guid(riid));
147 hres=IUnknown_QueryInterface(pUnk,riid,(LPVOID*)&newiface);
149 TRACE("%p does not support iface %s\n",pUnk,debugstr_guid(riid));
152 hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
154 FIXME("Stream create failed %lx\n",hres);
157 hres = CoMarshalInterface(pStm,riid,newiface,0,NULL,0);
158 IUnknown_Release(newiface);
160 FIXME("Marshalling interface %s failed with %lx\n",
161 debugstr_guid(riid),hres
165 hres = IStream_Stat(pStm,&ststg,0);
166 tempbuf = HeapAlloc(GetProcessHeap(), 0, ststg.cbSize.u.LowPart);
167 memset(&seekto,0,sizeof(seekto));
168 hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
169 if (hres) { FIXME("Failed Seek %lx\n",hres); goto fail;}
170 hres = IStream_Read(pStm,tempbuf,ststg.cbSize.u.LowPart,&res);
171 if (hres) { FIXME("Failed Read %lx\n",hres); goto fail;}
172 IStream_Release(pStm);
173 xsize = ststg.cbSize.u.LowPart;
174 xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
175 hres = xbuf_add(buf,tempbuf,ststg.cbSize.u.LowPart);
176 HeapFree(GetProcessHeap(),0,tempbuf);
180 xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
184 /********************* OLE Proxy/Stub Factory ********************************/
185 static HRESULT WINAPI
186 PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface, REFIID iid, LPVOID *ppv) {
187 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)||IsEqualIID(iid,&IID_IUnknown)) {
188 *ppv = (LPVOID)iface;
189 /* No ref counting, static class */
192 FIXME("(%s) unknown IID?\n",debugstr_guid(iid));
193 return E_NOINTERFACE;
196 static ULONG WINAPI PSFacBuf_AddRef(LPPSFACTORYBUFFER iface) { return 2; }
197 static ULONG WINAPI PSFacBuf_Release(LPPSFACTORYBUFFER iface) { return 1; }
200 _get_typeinfo_for_iid(REFIID riid, ITypeInfo**ti) {
203 char tlguid[200],typelibkey[300],interfacekey[300],ver[100];
206 DWORD tlguidlen, verlen, type, tlfnlen;
209 sprintf( interfacekey, "Interface\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\Typelib",
210 riid->Data1, riid->Data2, riid->Data3,
211 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
212 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7]
215 if (RegOpenKeyA(HKEY_CLASSES_ROOT,interfacekey,&ikey)) {
216 FIXME("No %s key found.\n",interfacekey);
220 tlguidlen = sizeof(tlguid);
221 if (RegQueryValueExA(ikey,NULL,NULL,&type,tlguid,&tlguidlen)) {
222 FIXME("Getting typelib guid failed.\n");
227 verlen = sizeof(ver);
228 if (RegQueryValueExA(ikey,"Version",NULL,&type,ver,&verlen)) {
229 FIXME("Could not get version value?\n");
234 sprintf(typelibkey,"Typelib\\%s\\%s\\0\\win32",tlguid,ver);
235 tlfnlen = sizeof(tlfn);
236 if (RegQueryValueA(HKEY_CLASSES_ROOT,typelibkey,tlfn,&tlfnlen)) {
237 FIXME("Could not get typelib fn?\n");
240 MultiByteToWideChar(CP_ACP, 0, tlfn, -1, tlfnW, -1);
241 hres = LoadTypeLib(tlfnW,&tl);
243 ERR("Failed to load typelib for %s, but it should be there.\n",debugstr_guid(riid));
246 hres = ITypeLib_GetTypeInfoOfGuid(tl,riid,ti);
248 ERR("typelib does not contain info for %s?\n",debugstr_guid(riid));
249 ITypeLib_Release(tl);
252 /* FIXME: do this? ITypeLib_Release(tl); */
256 /* Determine nr of functions. Since we use the toplevel interface and all
257 * inherited ones have lower numbers, we are ok to not to descent into
258 * the inheritance tree I think.
260 static int _nroffuncs(ITypeInfo *tinfo) {
267 hres = ITypeInfo_GetFuncDesc(tinfo,n,&fdesc);
270 if (fdesc->oVft/4 > max)
277 #include "pshpack1.h"
279 typedef struct _TMAsmProxy {
292 typedef struct _TMProxyImpl {
294 ICOM_VTABLE(IRpcProxyBuffer) *lpvtbl2;
297 TMAsmProxy *asmstubs;
299 IRpcChannelBuffer* chanbuf;
303 static HRESULT WINAPI
304 TMProxyImpl_QueryInterface(LPRPCPROXYBUFFER iface, REFIID riid, LPVOID *ppv) {
306 if (IsEqualIID(riid,&IID_IUnknown)||IsEqualIID(riid,&IID_IRpcProxyBuffer)) {
307 *ppv = (LPVOID)iface;
308 IRpcProxyBuffer_AddRef(iface);
311 FIXME("no interface for %s\n",debugstr_guid(riid));
312 return E_NOINTERFACE;
316 TMProxyImpl_AddRef(LPRPCPROXYBUFFER iface) {
317 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
325 TMProxyImpl_Release(LPRPCPROXYBUFFER iface) {
326 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
330 if (This->ref) return This->ref;
331 if (This->chanbuf) IRpcChannelBuffer_Release(This->chanbuf);
332 HeapFree(GetProcessHeap(),0,This);
336 static HRESULT WINAPI
338 LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer
340 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
342 TRACE("(%p)\n",pRpcChannelBuffer);
343 This->chanbuf = pRpcChannelBuffer;
344 IRpcChannelBuffer_AddRef(This->chanbuf);
349 TMProxyImpl_Disconnect(LPRPCPROXYBUFFER iface) {
350 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
353 IRpcChannelBuffer_Release(This->chanbuf);
354 This->chanbuf = NULL;
358 static ICOM_VTABLE(IRpcProxyBuffer) tmproxyvtable = {
359 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
360 TMProxyImpl_QueryInterface,
364 TMProxyImpl_Disconnect
367 /* how much space do we use on stack in DWORD steps. */
372 return sizeof(DATE)/sizeof(DWORD);
374 return (sizeof(VARIANT)+3)/sizeof(DWORD);
381 _xsize(TYPEDESC *td) {
386 return sizeof(VARIANT)+3;
389 ARRAYDESC *adesc = td->u.lpadesc;
391 for (i=0;i<adesc->cDims;i++)
392 arrsize *= adesc->rgbounds[i].cElements;
393 return arrsize*_xsize(&adesc->tdescElem);
418 TRACE("(tdesc.vt %d)\n",tdesc->vt);
421 case VT_EMPTY: /* nothing. empty variant for instance */
432 if (debugout) MESSAGE("%lx",*arg);
434 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
438 VARIANT *vt = (VARIANT*)arg;
439 DWORD vttype = V_VT(vt);
441 if (debugout) MESSAGE("Vt(%ld)(",vttype);
444 hres = xbuf_add(buf,(LPBYTE)&vttype,sizeof(vttype));
445 if (hres) return hres;
447 /* need to recurse since we need to free the stuff */
448 hres = serialize_param(tinfo,writeit,debugout,dealloc,&tdesc2,&(V_I4(vt)),buf);
449 if (debugout) MESSAGE(")");
455 MESSAGE("%s",debugstr_w((BSTR)*arg));
457 MESSAGE("<bstr NULL>");
462 hres = xbuf_add(buf,(LPBYTE)&fakelen,4);
466 DWORD *bstr = ((DWORD*)(*arg))-1;
468 hres = xbuf_add(buf,(LPBYTE)bstr,bstr[0]+4);
475 SysFreeString((BSTR)*arg);
481 if (debugout) MESSAGE("*");
483 cookie = *arg ? 0x42424242 : 0;
484 hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
489 if (debugout) MESSAGE("NULL");
492 hres = serialize_param(tinfo,writeit,debugout,dealloc,tdesc->u.lptdesc,(DWORD*)*arg,buf);
493 if (dealloc) HeapFree(GetProcessHeap(),0,(LPVOID)arg);
497 if (debugout) MESSAGE("unk(0x%lx)",*arg);
499 hres = _marshal_interface(buf,&IID_IUnknown,(LPUNKNOWN)*arg);
502 if (debugout) MESSAGE("idisp(0x%lx)",*arg);
504 hres = _marshal_interface(buf,&IID_IDispatch,(LPUNKNOWN)*arg);
507 if (debugout) MESSAGE("<void>");
509 case VT_USERDEFINED: {
513 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
515 FIXME("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
518 ITypeInfo_GetTypeAttr(tinfo2,&tattr);
519 switch (tattr->typekind) {
521 case TKIND_INTERFACE:
523 hres=_marshal_interface(buf,&(tattr->guid),(LPUNKNOWN)arg);
527 if (debugout) MESSAGE("{");
528 for (i=0;i<tattr->cVars;i++) {
533 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
535 FIXME("Could not get vardesc of %d\n",i);
538 /* Need them for hack below */
540 memset(names,0,sizeof(names));
541 hres = ITypeInfo_GetNames(tinfo2,vdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
542 if (nrofnames > sizeof(names)/sizeof(names[0])) {
543 ERR("Need more names!\n");
545 if (!hres && debugout)
546 MESSAGE("%s=",debugstr_w(names[0]));
548 elem2 = &vdesc->elemdescVar;
549 tdesc2 = &elem2->tdesc;
550 hres = serialize_param(
556 (DWORD*)(((LPBYTE)arg)+vdesc->u.oInst),
561 if (debugout && (i<(tattr->cVars-1)))
564 if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
565 memcpy(&(buf->iid),arg,sizeof(buf->iid));
566 if (debugout) MESSAGE("}");
570 FIXME("Unhandled typekind %d\n",tattr->typekind);
574 ITypeInfo_Release(tinfo2);
578 ARRAYDESC *adesc = tdesc->u.lpadesc;
581 if (debugout) MESSAGE("carr");
582 for (i=0;i<adesc->cDims;i++) {
583 if (debugout) MESSAGE("[%ld]",adesc->rgbounds[i].cElements);
584 arrsize *= adesc->rgbounds[i].cElements;
586 if (debugout) MESSAGE("[");
587 for (i=0;i<arrsize;i++) {
588 hres = serialize_param(tinfo, writeit, debugout, dealloc, &adesc->tdescElem, (DWORD*)((LPBYTE)arg+i*_xsize(&adesc->tdescElem)), buf);
591 if (debugout && (i<arrsize-1)) MESSAGE(",");
593 if (debugout) MESSAGE("]");
597 ERR("Unhandled marshal type %d.\n",tdesc->vt);
603 serialize_LPVOID_ptr(
615 if ((tdesc->vt != VT_PTR) ||
616 (tdesc->u.lptdesc->vt != VT_PTR) ||
617 (tdesc->u.lptdesc->u.lptdesc->vt != VT_VOID)
619 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
622 cookie = (*arg) ? 0x42424242: 0x0;
624 hres = xbuf_add(buf, (LPVOID)&cookie, sizeof(cookie));
629 if (debugout) MESSAGE("<lpvoid NULL>");
633 MESSAGE("ppv(%p)",*(LPUNKNOWN*)*arg);
635 hres = _marshal_interface(buf,&(buf->iid),*(LPUNKNOWN*)*arg);
640 HeapFree(GetProcessHeap(),0,(LPVOID)*arg);
645 serialize_DISPPARAM_ptr(
659 if ((tdesc->vt != VT_PTR) || (tdesc->u.lptdesc->vt != VT_USERDEFINED)) {
660 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
664 cookie = *arg ? 0x42424242 : 0x0;
666 hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
671 if (debugout) MESSAGE("<DISPPARAMS NULL>");
674 disp = (DISPPARAMS*)*arg;
676 hres = xbuf_add(buf,(LPBYTE)&disp->cArgs,sizeof(disp->cArgs));
680 if (debugout) MESSAGE("D{");
681 for (i=0;i<disp->cArgs;i++) {
684 vtdesc.vt = VT_VARIANT;
691 (DWORD*)(disp->rgvarg+i),
694 if (debugout && (i<disp->cArgs-1))
698 HeapFree(GetProcessHeap(),0,disp->rgvarg);
700 hres = xbuf_add(buf,(LPBYTE)&disp->cNamedArgs,sizeof(disp->cNamedArgs));
704 if (debugout) MESSAGE("}{");
705 for (i=0;i<disp->cNamedArgs;i++) {
715 (DWORD*)(disp->rgdispidNamedArgs+i),
718 if (debugout && (i<disp->cNamedArgs-1))
721 if (debugout) MESSAGE("}");
723 HeapFree(GetProcessHeap(),0,disp->rgdispidNamedArgs);
724 HeapFree(GetProcessHeap(),0,disp);
741 TRACE("vt %d at %p\n",tdesc->vt,arg);
746 if (debugout) MESSAGE("<empty>");
749 if (debugout) MESSAGE("<null>");
752 VARIANT *vt = (VARIANT*)arg;
757 hres = xbuf_get(buf,(LPBYTE)&vttype,sizeof(vttype));
759 FIXME("vt type not read?\n");
762 memset(&tdesc2,0,sizeof(tdesc2));
765 if (debugout) MESSAGE("Vt(%ld)(",vttype);
766 hres = deserialize_param(tinfo, readit, debugout, alloc, &tdesc2, &(V_I4(vt)), buf);
775 case VT_BOOL: case VT_I4: case VT_UI4: case VT_UINT: case VT_R4:
779 hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
780 if (hres) FIXME("Failed to read integer 4 byte\n");
782 if (debugout) MESSAGE("%lx",*arg);
789 hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
791 FIXME("failed to read bstr klen\n");
796 if (debugout) MESSAGE("<bstr NULL>");
798 str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len+sizeof(WCHAR));
799 hres = xbuf_get(buf,(LPBYTE)str,len);
801 FIXME("Failed to read BSTR.\n");
804 *arg = (DWORD)SysAllocStringLen(str,len);
805 if (debugout) MESSAGE("%s",debugstr_w(str));
806 HeapFree(GetProcessHeap(),0,str);
817 derefhere = (tdesc->u.lptdesc->vt != VT_USERDEFINED);
820 hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
822 FIXME("Failed to load pointer cookie.\n");
825 if (cookie != 0x42424242) {
826 if (debugout) MESSAGE("NULL");
830 if (debugout) MESSAGE("*");
834 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,_xsize(tdesc->u.lptdesc));
837 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, (LPDWORD)*arg, buf);
839 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, arg, buf);
842 /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
844 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
847 hres = _unmarshal_interface(buf,&IID_IUnknown,(LPUNKNOWN*)arg);
849 MESSAGE("unk(%p)",arg);
854 hres = _unmarshal_interface(buf,&IID_IDispatch,(LPUNKNOWN*)arg);
856 MESSAGE("idisp(%p)",arg);
859 if (debugout) MESSAGE("<void>");
861 case VT_USERDEFINED: {
865 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
867 FIXME("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
870 hres = ITypeInfo_GetTypeAttr(tinfo2,&tattr);
872 FIXME("Could not get typeattr in VT_USERDEFINED.\n");
875 *arg = (DWORD)HeapAlloc(GetProcessHeap(),0,tattr->cbSizeInstance);
876 switch (tattr->typekind) {
878 case TKIND_INTERFACE:
880 hres = _unmarshal_interface(buf,&(tattr->guid),(LPUNKNOWN*)arg);
885 if (debugout) MESSAGE("{");
886 for (i=0;i<tattr->cVars;i++) {
889 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
891 FIXME("Could not get vardesc of %d\n",i);
894 hres = deserialize_param(
899 &vdesc->elemdescVar.tdesc,
900 (DWORD*)(((LPBYTE)*arg)+vdesc->u.oInst),
903 if (debugout && (i<tattr->cVars-1)) MESSAGE(",");
905 if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
906 memcpy(&(buf->iid),(LPBYTE)*arg,sizeof(buf->iid));
907 if (debugout) MESSAGE("}");
911 ERR("Unhandled typekind %d\n",tattr->typekind);
917 FIXME("failed to stuballoc in TKIND_RECORD.\n");
918 ITypeInfo_Release(tinfo2);
922 /* arg is pointing to the start of the array. */
923 ARRAYDESC *adesc = tdesc->u.lpadesc;
926 if (adesc->cDims > 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
927 for (i=0;i<adesc->cDims;i++)
928 arrsize *= adesc->rgbounds[i].cElements;
929 for (i=0;i<arrsize;i++)
936 (DWORD*)((LPBYTE)(arg)+i*_xsize(&adesc->tdescElem)),
942 ERR("No handler for VT type %d!\n",tdesc->vt);
949 deserialize_LPVOID_ptr(
961 if ((tdesc->vt != VT_PTR) ||
962 (tdesc->u.lptdesc->vt != VT_PTR) ||
963 (tdesc->u.lptdesc->u.lptdesc->vt != VT_VOID)
965 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
969 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(LPVOID));
971 hres = xbuf_get(buf, (LPVOID)&cookie, sizeof(cookie));
974 if (cookie != 0x42424242) {
976 if (debugout) MESSAGE("<lpvoid NULL>");
981 hres = _unmarshal_interface(buf,&buf->iid,(LPUNKNOWN*)*arg);
985 if (debugout) MESSAGE("ppv(%p)",(LPVOID)*arg);
990 deserialize_DISPPARAM_ptr(
1004 if ((tdesc->vt != VT_PTR) || (tdesc->u.lptdesc->vt != VT_USERDEFINED)) {
1005 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
1009 hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
1014 if (debugout) MESSAGE("<DISPPARAMS NULL>");
1019 *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPPARAMS));
1020 disps = (DISPPARAMS*)*arg;
1023 hres = xbuf_get(buf, (LPBYTE)&disps->cArgs, sizeof(disps->cArgs));
1027 disps->rgvarg = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(VARIANT)*disps->cArgs);
1028 if (debugout) MESSAGE("D{");
1029 for (i=0; i< disps->cArgs; i++) {
1032 vdesc.vt = VT_VARIANT;
1033 hres = deserialize_param(
1039 (DWORD*)(disps->rgvarg+i),
1043 if (debugout) MESSAGE("}{");
1044 hres = xbuf_get(buf, (LPBYTE)&disps->cNamedArgs, sizeof(disps->cNamedArgs));
1047 if (disps->cNamedArgs) {
1049 disps->rgdispidNamedArgs = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPID)*disps->cNamedArgs);
1050 for (i=0; i< disps->cNamedArgs; i++) {
1054 hres = deserialize_param(
1060 (DWORD*)(disps->rgdispidNamedArgs+i),
1063 if (debugout && i<(disps->cNamedArgs-1)) MESSAGE(",");
1066 if (debugout) MESSAGE("}");
1070 /* Searches function, also in inherited interfaces */
1073 ITypeInfo *tinfo, int iMethod, FUNCDESC **fdesc, BSTR *iname, BSTR *fname
1078 if (fname) *fname = NULL;
1079 if (iname) *iname = NULL;
1082 hres = ITypeInfo_GetFuncDesc(tinfo, i, fdesc);
1088 hres = ITypeInfo_GetTypeAttr(tinfo, &attr);
1090 FIXME("GetTypeAttr failed with %lx\n",hres);
1093 /* Not found, so look in inherited ifaces. */
1094 for (j=0;j<attr->cImplTypes;j++) {
1095 hres = ITypeInfo_GetRefTypeOfImplType(tinfo, j, &href);
1097 FIXME("Did not find a reftype for interface offset %d?\n",j);
1100 hres = ITypeInfo_GetRefTypeInfo(tinfo, href, &tinfo2);
1102 FIXME("Did not find a typeinfo for reftype %ld?\n",href);
1105 hres = _get_funcdesc(tinfo2,iMethod,fdesc,iname,fname);
1106 ITypeInfo_Release(tinfo2);
1107 if (!hres) return S_OK;
1111 if (((*fdesc)->oVft/4) == iMethod) {
1113 ITypeInfo_GetDocumentation(tinfo,(*fdesc)->memid,fname,NULL,NULL,NULL);
1115 ITypeInfo_GetDocumentation(tinfo,-1,iname,NULL,NULL,NULL);
1124 xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */) {
1125 DWORD *args = ((DWORD*)&tpinfo)+1, *xargs;
1128 int i, relaydeb = TRACE_ON(olerelay);
1136 hres = _get_funcdesc(tpinfo->tinfo,method,&fdesc,&iname,&fname);
1138 ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method);
1142 /*dump_FUNCDESC(fdesc);*/
1144 TRACE_(olerelay)("->");
1146 MESSAGE("%s:",debugstr_w(iname));
1148 MESSAGE("%s(%d)",debugstr_w(fname),method);
1150 MESSAGE("%d",method);
1152 if (iname) SysFreeString(iname);
1153 if (fname) SysFreeString(fname);
1155 /* Need them for hack below */
1156 memset(names,0,sizeof(names));
1157 if (ITypeInfo_GetNames(tpinfo->tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames))
1159 if (nrofnames > sizeof(names)/sizeof(names[0]))
1160 ERR("Need more names!\n");
1162 memset(&buf,0,sizeof(buf));
1163 buf.iid = IID_IUnknown;
1165 xbuf_add(&buf,(LPBYTE)args[0],sizeof(IID));
1166 if (relaydeb) MESSAGE("riid=%s,[out]",debugstr_guid((REFIID)args[0]));
1169 for (i=0;i<fdesc->cParams;i++) {
1170 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1171 BOOL isserialized = FALSE;
1173 if (i) MESSAGE(",");
1174 if (i+1<nrofnames && names[i+1])
1175 MESSAGE("%s=",debugstr_w(names[i+1]));
1177 /* No need to marshal other data than FIN */
1178 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN)) {
1179 xargs+=_argsize(elem->tdesc.vt);
1180 if (relaydeb) MESSAGE("[out]");
1183 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1184 /* If the parameter is 'riid', we use it as interface IID
1185 * for a later ppvObject serialization.
1187 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1189 /* DISPPARAMS* needs special serializer */
1190 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1191 hres = serialize_DISPPARAM_ptr(
1193 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1200 isserialized = TRUE;
1202 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1203 hres = serialize_LPVOID_ptr(
1205 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1213 isserialized = TRUE;
1217 hres = serialize_param(
1219 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1228 FIXME("Failed to serialize param, hres %lx\n",hres);
1231 xargs+=_argsize(elem->tdesc.vt);
1234 if (relaydeb) MESSAGE(")");
1235 memset(&msg,0,sizeof(msg));
1236 msg.cbBuffer = buf.curoff;
1237 msg.iMethod = method;
1238 hres = IRpcChannelBuffer_GetBuffer(tpinfo->chanbuf,&msg,&(tpinfo->iid));
1240 FIXME("RpcChannelBuffer GetBuffer failed, %lx\n",hres);
1243 memcpy(msg.Buffer,buf.base,buf.curoff);
1244 if (relaydeb) MESSAGE("\n");
1245 hres = IRpcChannelBuffer_SendReceive(tpinfo->chanbuf,&msg,&status);
1247 FIXME("RpcChannelBuffer SendReceive failed, %lx\n",hres);
1250 relaydeb = TRACE_ON(olerelay);
1251 if (relaydeb) MESSAGE(" = %08lx (",status);
1253 buf.base = HeapReAlloc(GetProcessHeap(),0,buf.base,msg.cbBuffer);
1255 buf.base = HeapAlloc(GetProcessHeap(),0,msg.cbBuffer);
1256 buf.size = msg.cbBuffer;
1257 memcpy(buf.base,msg.Buffer,buf.size);
1260 _unmarshal_interface(&buf,(REFIID)args[0],(LPUNKNOWN*)args[1]);
1261 if (relaydeb) MESSAGE("[in],%p",*((DWORD**)args[1]));
1264 for (i=0;i<fdesc->cParams;i++) {
1265 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1266 BOOL isdeserialized = FALSE;
1269 if (i) MESSAGE(",");
1270 if (i+1<nrofnames && names[i+1]) MESSAGE("%s=",debugstr_w(names[i+1]));
1272 /* No need to marshal other data than FOUT I think */
1273 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT)) {
1274 xargs += _argsize(elem->tdesc.vt);
1275 if (relaydeb) MESSAGE("[in]");
1278 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1279 /* If the parameter is 'riid', we use it as interface IID
1280 * for a later ppvObject serialization.
1282 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1284 /* deserialize DISPPARAM */
1285 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1286 hres = deserialize_DISPPARAM_ptr(
1288 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1296 FIXME("Failed to deserialize DISPPARAM*, hres %lx\n",hres);
1299 isdeserialized = TRUE;
1301 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1302 hres = deserialize_LPVOID_ptr(
1304 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1312 isdeserialized = TRUE;
1315 if (!isdeserialized)
1316 hres = deserialize_param(
1318 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1326 FIXME("Failed to unmarshall param, hres %lx\n",hres);
1329 xargs += _argsize(elem->tdesc.vt);
1332 if (relaydeb) MESSAGE(")\n\n");
1333 HeapFree(GetProcessHeap(),0,buf.base);
1337 static HRESULT WINAPI
1338 PSFacBuf_CreateProxy(
1339 LPPSFACTORYBUFFER iface, IUnknown* pUnkOuter, REFIID riid,
1340 IRpcProxyBuffer **ppProxy, LPVOID *ppv
1348 TRACE("(...%s...)\n",debugstr_guid(riid));
1349 hres = _get_typeinfo_for_iid(riid,&tinfo);
1351 FIXME("No typeinfo for %s?\n",debugstr_guid(riid));
1354 nroffuncs = _nroffuncs(tinfo);
1355 proxy = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TMProxyImpl));
1356 if (!proxy) return E_OUTOFMEMORY;
1357 proxy->asmstubs=HeapAlloc(GetProcessHeap(),0,sizeof(TMAsmProxy)*nroffuncs);
1359 assert(sizeof(TMAsmProxy) == 12);
1361 proxy->lpvtbl = HeapAlloc(GetProcessHeap(),0,sizeof(LPBYTE)*nroffuncs);
1362 for (i=0;i<nroffuncs;i++) {
1364 TMAsmProxy *xasm = proxy->asmstubs+i;
1366 /* nrofargs without This */
1368 case 0: nrofargs = 2;
1370 case 1: case 2: nrofargs = 0;
1374 hres = _get_funcdesc(tinfo,i,&fdesc,NULL,NULL);
1376 FIXME("GetFuncDesc %lx should not fail here.\n",hres);
1379 /* some args take more than 4 byte on the stack */
1381 for (j=0;j<fdesc->cParams;j++)
1382 nrofargs += _argsize(fdesc->lprgelemdescParam[j].tdesc.vt);
1384 if (fdesc->callconv != CC_STDCALL) {
1385 ERR("calling convention is not stdcall????\n");
1391 /* popl %eax - return ptr
1398 * arg3 arg2 arg1 <method> <returnptr>
1400 xasm->popleax = 0x58;
1401 xasm->pushlval = 0x6a;
1403 xasm->pushleax = 0x50;
1404 xasm->lcall = 0xe8; /* relative jump */
1405 xasm->xcall = (DWORD)xCall;
1406 xasm->xcall -= (DWORD)&(xasm->lret);
1408 xasm->bytestopop= (nrofargs+2)*4; /* pop args, This, iMethod */
1409 proxy->lpvtbl[i] = (DWORD)xasm;
1411 proxy->lpvtbl2 = &tmproxyvtable;
1413 proxy->tinfo = tinfo;
1414 memcpy(&proxy->iid,riid,sizeof(*riid));
1415 *ppv = (LPVOID)proxy;
1416 *ppProxy = (IRpcProxyBuffer *)&(proxy->lpvtbl2);
1420 typedef struct _TMStubImpl {
1421 ICOM_VTABLE(IRpcStubBuffer) *lpvtbl;
1429 static HRESULT WINAPI
1430 TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface, REFIID riid, LPVOID *ppv) {
1431 if (IsEqualIID(riid,&IID_IRpcStubBuffer)||IsEqualIID(riid,&IID_IUnknown)){
1432 *ppv = (LPVOID)iface;
1433 IRpcStubBuffer_AddRef(iface);
1436 FIXME("%s, not supported IID.\n",debugstr_guid(riid));
1437 return E_NOINTERFACE;
1441 TMStubImpl_AddRef(LPRPCSTUBBUFFER iface) {
1442 ICOM_THIS(TMStubImpl,iface);
1449 TMStubImpl_Release(LPRPCSTUBBUFFER iface) {
1450 ICOM_THIS(TMStubImpl,iface);
1455 HeapFree(GetProcessHeap(),0,This);
1459 static HRESULT WINAPI
1460 TMStubImpl_Connect(LPRPCSTUBBUFFER iface, LPUNKNOWN pUnkServer) {
1461 ICOM_THIS(TMStubImpl,iface);
1463 IUnknown_AddRef(pUnkServer);
1464 This->pUnk = pUnkServer;
1469 TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface) {
1470 ICOM_THIS(TMStubImpl,iface);
1472 IUnknown_Release(This->pUnk);
1477 static HRESULT WINAPI
1479 LPRPCSTUBBUFFER iface, RPCOLEMESSAGE* xmsg,IRpcChannelBuffer*rpcchanbuf
1483 ICOM_THIS(TMStubImpl,iface);
1485 DWORD *args, res, *xargs, nrofargs;
1490 memset(&buf,0,sizeof(buf));
1491 buf.size = xmsg->cbBuffer;
1492 buf.base = xmsg->Buffer;
1494 buf.iid = IID_IUnknown;
1497 if (xmsg->iMethod == 0) { /* QI */
1499 /* in: IID, out: <iface> */
1501 xbuf_get(&buf,(LPBYTE)&xiid,sizeof(xiid));
1503 hres = _marshal_interface(&buf,&xiid,This->pUnk);
1504 xmsg->Buffer = buf.base; /* Might have been reallocated */
1505 xmsg->cbBuffer = buf.size;
1508 hres = _get_funcdesc(This->tinfo,xmsg->iMethod,&fdesc,NULL,NULL);
1510 FIXME("GetFuncDesc on method %ld failed with %lx\n",xmsg->iMethod,hres);
1513 /* Need them for hack below */
1514 memset(names,0,sizeof(names));
1515 ITypeInfo_GetNames(This->tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
1516 if (nrofnames > sizeof(names)/sizeof(names[0])) {
1517 ERR("Need more names!\n");
1520 /*dump_FUNCDESC(fdesc);*/
1522 for (i=0;i<fdesc->cParams;i++)
1523 nrofargs += _argsize(fdesc->lprgelemdescParam[i].tdesc.vt);
1524 args = HeapAlloc(GetProcessHeap(),0,(nrofargs+1)*sizeof(DWORD));
1525 if (!args) return E_OUTOFMEMORY;
1527 /* Allocate all stuff used by call. */
1529 for (i=0;i<fdesc->cParams;i++) {
1530 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1531 BOOL isdeserialized = FALSE;
1533 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1534 /* If the parameter is 'riid', we use it as interface IID
1535 * for a later ppvObject serialization.
1537 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1539 /* deserialize DISPPARAM */
1540 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1541 hres = deserialize_DISPPARAM_ptr(
1543 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1551 FIXME("Failed to deserialize DISPPARAM*, hres %lx\n",hres);
1554 isdeserialized = TRUE;
1556 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1557 hres = deserialize_LPVOID_ptr(
1559 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1567 isdeserialized = TRUE;
1570 if (!isdeserialized)
1571 hres = deserialize_param(
1573 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1580 xargs += _argsize(elem->tdesc.vt);
1582 FIXME("Failed to deserialize param %s, hres %lx\n",debugstr_w(names[i+1]),hres);
1586 hres = IUnknown_QueryInterface(This->pUnk,&(This->iid),(LPVOID*)&(args[0]));
1588 ERR("Does not support iface %s\n",debugstr_guid(&(This->iid)));
1592 (*((FARPROC**)args[0]))[fdesc->oVft/4],
1597 IUnknown_Release((LPUNKNOWN)args[0]);
1600 for (i=0;i<fdesc->cParams;i++) {
1601 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1602 BOOL isserialized = FALSE;
1604 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1605 /* If the parameter is 'riid', we use it as interface IID
1606 * for a later ppvObject serialization.
1608 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1610 /* DISPPARAMS* needs special serializer */
1611 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1612 hres = serialize_DISPPARAM_ptr(
1614 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1621 isserialized = TRUE;
1623 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1624 hres = serialize_LPVOID_ptr(
1626 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1634 isserialized = TRUE;
1638 hres = serialize_param(
1640 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1647 xargs += _argsize(elem->tdesc.vt);
1649 FIXME("Failed to stuballoc param, hres %lx\n",hres);
1653 /* might need to use IRpcChannelBuffer_GetBuffer ? */
1654 xmsg->cbBuffer = buf.curoff;
1655 xmsg->Buffer = buf.base;
1656 HeapFree(GetProcessHeap(),0,args);
1660 static LPRPCSTUBBUFFER WINAPI
1661 TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface, REFIID riid) {
1662 FIXME("Huh (%s)?\n",debugstr_guid(riid));
1667 TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface) {
1668 ICOM_THIS(TMStubImpl,iface);
1670 return This->ref; /*FIXME? */
1673 static HRESULT WINAPI
1674 TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface, LPVOID *ppv) {
1679 TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface, LPVOID ppv) {
1683 ICOM_VTABLE(IRpcStubBuffer) tmstubvtbl = {
1684 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1685 TMStubImpl_QueryInterface,
1689 TMStubImpl_Disconnect,
1691 TMStubImpl_IsIIDSupported,
1692 TMStubImpl_CountRefs,
1693 TMStubImpl_DebugServerQueryInterface,
1694 TMStubImpl_DebugServerRelease
1697 static HRESULT WINAPI
1698 PSFacBuf_CreateStub(
1699 LPPSFACTORYBUFFER iface, REFIID riid,IUnknown *pUnkServer,
1700 IRpcStubBuffer** ppStub
1706 TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub);
1707 hres = _get_typeinfo_for_iid(riid,&tinfo);
1709 FIXME("No typeinfo for %s?\n",debugstr_guid(riid));
1712 stub = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TMStubImpl));
1714 return E_OUTOFMEMORY;
1715 stub->lpvtbl = &tmstubvtbl;
1717 stub->tinfo = tinfo;
1718 memcpy(&(stub->iid),riid,sizeof(*riid));
1719 hres = IRpcStubBuffer_Connect((LPRPCSTUBBUFFER)stub,pUnkServer);
1720 *ppStub = (LPRPCSTUBBUFFER)stub;
1722 FIXME("Connect to pUnkServer failed?\n");
1726 static ICOM_VTABLE(IPSFactoryBuffer) psfacbufvtbl = {
1727 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1728 PSFacBuf_QueryInterface,
1731 PSFacBuf_CreateProxy,
1735 /* This is the whole PSFactoryBuffer object, just the vtableptr */
1736 static ICOM_VTABLE(IPSFactoryBuffer) *lppsfac = &psfacbufvtbl;
1738 /***********************************************************************
1739 * DllGetClassObject [OLE32.63]
1742 TypeLibFac_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
1744 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)) {
1748 return E_NOINTERFACE;