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
35 #include "wine/unicode.h"
36 #include "wine/obj_base.h"
37 #include "wine/obj_channel.h"
38 #include "wine/obj_storage.h"
42 #include "wine/debug.h"
45 static const WCHAR riidW[5] = {'r','i','i','d',0};
46 static const WCHAR pdispparamsW[] = {'p','d','i','s','p','p','a','r','a','m','s',0};
47 static const WCHAR ppvObjectW[] = {'p','p','v','O','b','j','e','c','t',0};
49 WINE_DEFAULT_DEBUG_CHANNEL(ole);
50 WINE_DECLARE_DEBUG_CHANNEL(olerelay);
52 typedef struct _marshal_state {
58 IID iid; /* HACK: for VT_VOID */
62 xbuf_add(marshal_state *buf, LPBYTE stuff, DWORD size) {
63 while (buf->size - buf->curoff < size) {
66 buf->base = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,buf->base,buf->size);
70 buf->base = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,32);
76 memcpy(buf->base+buf->curoff,stuff,size);
82 xbuf_get(marshal_state *buf, LPBYTE stuff, DWORD size) {
83 if (buf->size < buf->curoff+size) return E_FAIL;
84 memcpy(stuff,buf->base+buf->curoff,size);
90 xbuf_skip(marshal_state *buf, DWORD size) {
91 if (buf->size < buf->curoff+size) return E_FAIL;
97 _unmarshal_interface(marshal_state *buf, REFIID riid, LPUNKNOWN *pUnk) {
99 ULARGE_INTEGER newpos;
100 LARGE_INTEGER seekto;
105 TRACE("...%s...\n",debugstr_guid(riid));
107 hres = xbuf_get(buf,(LPBYTE)&xsize,sizeof(xsize));
108 if (hres) return hres;
109 if (xsize == 0) return S_OK;
110 hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
112 FIXME("Stream create failed %lx\n",hres);
115 hres = IStream_Write(pStm,buf->base+buf->curoff,xsize,&res);
116 if (hres) { FIXME("stream write %lx\n",hres); return hres; }
117 memset(&seekto,0,sizeof(seekto));
118 hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
119 if (hres) { FIXME("Failed Seek %lx\n",hres); return hres;}
120 hres = CoUnmarshalInterface(pStm,riid,(LPVOID*)pUnk);
122 FIXME("Marshaling interface %s failed with %lx\n",debugstr_guid(riid),hres);
125 IStream_Release(pStm);
126 return xbuf_skip(buf,xsize);
130 _marshal_interface(marshal_state *buf, REFIID riid, LPUNKNOWN pUnk) {
135 ULARGE_INTEGER newpos;
136 LARGE_INTEGER seekto;
145 TRACE("...%s...\n",debugstr_guid(riid));
146 hres=IUnknown_QueryInterface(pUnk,riid,(LPVOID*)&newiface);
148 TRACE("%p does not support iface %s\n",pUnk,debugstr_guid(riid));
151 hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
153 FIXME("Stream create failed %lx\n",hres);
156 hres = CoMarshalInterface(pStm,riid,newiface,0,NULL,0);
157 IUnknown_Release(newiface);
159 FIXME("Marshaling interface %s failed with %lx\n",
160 debugstr_guid(riid),hres
164 hres = IStream_Stat(pStm,&ststg,0);
165 tempbuf = HeapAlloc(GetProcessHeap(), 0, ststg.cbSize.s.LowPart);
166 memset(&seekto,0,sizeof(seekto));
167 hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
168 if (hres) { FIXME("Failed Seek %lx\n",hres); goto fail;}
169 hres = IStream_Read(pStm,tempbuf,ststg.cbSize.s.LowPart,&res);
170 if (hres) { FIXME("Failed Read %lx\n",hres); goto fail;}
171 IStream_Release(pStm);
172 xsize = ststg.cbSize.s.LowPart;
173 xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
174 hres = xbuf_add(buf,tempbuf,ststg.cbSize.s.LowPart);
175 HeapFree(GetProcessHeap(),0,tempbuf);
179 xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
183 /********************* OLE Proxy/Stub Factory ********************************/
184 static HRESULT WINAPI
185 PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface, REFIID iid, LPVOID *ppv) {
186 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)||IsEqualIID(iid,&IID_IUnknown)) {
187 *ppv = (LPVOID)iface;
188 /* No ref counting, static class */
191 FIXME("(%s) unknown IID?\n",debugstr_guid(iid));
192 return E_NOINTERFACE;
195 static ULONG WINAPI PSFacBuf_AddRef(LPPSFACTORYBUFFER iface) { return 2; }
196 static ULONG WINAPI PSFacBuf_Release(LPPSFACTORYBUFFER iface) { return 1; }
199 _get_typeinfo_for_iid(REFIID riid, ITypeInfo**ti) {
202 char tlguid[200],typelibkey[300],interfacekey[300],ver[100];
205 DWORD tlguidlen, verlen, type, tlfnlen;
208 sprintf( interfacekey, "Interface\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\Typelib",
209 riid->Data1, riid->Data2, riid->Data3,
210 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
211 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7]
214 if (RegOpenKeyA(HKEY_CLASSES_ROOT,interfacekey,&ikey)) {
215 FIXME("No %s key found.\n",interfacekey);
219 tlguidlen = sizeof(tlguid);
220 if (RegQueryValueExA(ikey,NULL,NULL,&type,tlguid,&tlguidlen)) {
221 FIXME("Getting typelib guid failed.\n");
226 verlen = sizeof(ver);
227 if (RegQueryValueExA(ikey,"Version",NULL,&type,ver,&verlen)) {
228 FIXME("Could not get version value?\n");
233 sprintf(typelibkey,"Typelib\\%s\\%s\\0\\win32",tlguid,ver);
234 tlfnlen = sizeof(tlfn);
235 if (RegQueryValueA(HKEY_CLASSES_ROOT,typelibkey,tlfn,&tlfnlen)) {
236 FIXME("Could not get typelib fn?\n");
239 MultiByteToWideChar(CP_ACP, 0, tlfn, -1, tlfnW, -1);
240 hres = LoadTypeLib(tlfnW,&tl);
242 ERR("Failed to load typelib for %s, but it should be there.\n",debugstr_guid(riid));
245 hres = ITypeLib_GetTypeInfoOfGuid(tl,riid,ti);
247 ERR("typelib does not contain info for %s?\n",debugstr_guid(riid));
248 ITypeLib_Release(tl);
251 /* FIXME: do this? ITypeLib_Release(tl); */
255 /* Determine nr of functions. Since we use the toplevel interface and all
256 * inherited ones have lower numbers, we are ok to not to descent into
257 * the inheritance tree I think.
259 static int _nroffuncs(ITypeInfo *tinfo) {
266 hres = ITypeInfo_GetFuncDesc(tinfo,n,&fdesc);
267 if (fdesc->oVft/4 > max)
276 typedef struct _TMAsmProxy {
285 } WINE_PACKED TMAsmProxy;
287 typedef struct _TMProxyImpl {
289 ICOM_VTABLE(IRpcProxyBuffer) *lpvtbl2;
292 TMAsmProxy *asmstubs;
294 IRpcChannelBuffer* chanbuf;
298 static HRESULT WINAPI
299 TMProxyImpl_QueryInterface(LPRPCPROXYBUFFER iface, REFIID riid, LPVOID *ppv) {
301 if (IsEqualIID(riid,&IID_IUnknown)||IsEqualIID(riid,&IID_IRpcProxyBuffer)) {
302 *ppv = (LPVOID)iface;
303 IRpcProxyBuffer_AddRef(iface);
306 FIXME("no interface for %s\n",debugstr_guid(riid));
307 return E_NOINTERFACE;
311 TMProxyImpl_AddRef(LPRPCPROXYBUFFER iface) {
312 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
320 TMProxyImpl_Release(LPRPCPROXYBUFFER iface) {
321 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
325 if (This->ref) return This->ref;
326 if (This->chanbuf) IRpcChannelBuffer_Release(This->chanbuf);
327 HeapFree(GetProcessHeap(),0,This);
331 static HRESULT WINAPI
333 LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer
335 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
337 TRACE("(%p)\n",pRpcChannelBuffer);
338 This->chanbuf = pRpcChannelBuffer;
339 IRpcChannelBuffer_AddRef(This->chanbuf);
344 TMProxyImpl_Disconnect(LPRPCPROXYBUFFER iface) {
345 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
348 IRpcChannelBuffer_Release(This->chanbuf);
349 This->chanbuf = NULL;
353 static ICOM_VTABLE(IRpcProxyBuffer) tmproxyvtable = {
354 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
355 TMProxyImpl_QueryInterface,
359 TMProxyImpl_Disconnect
362 /* how much space do we use on stack in DWORD steps. */
367 return sizeof(DATE)/sizeof(DWORD);
369 return (sizeof(VARIANT)+3)/sizeof(DWORD);
376 _xsize(TYPEDESC *td) {
381 return sizeof(VARIANT)+3;
384 ARRAYDESC *adesc = td->u.lpadesc;
386 for (i=0;i<adesc->cDims;i++)
387 arrsize *= adesc->rgbounds[i].cElements;
388 return arrsize*_xsize(&adesc->tdescElem);
413 TRACE("(tdesc.vt %d)\n",tdesc->vt);
416 case VT_EMPTY: /* nothing. empty variant for instance */
427 if (debugout) MESSAGE("%lx",*arg);
429 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
433 VARIANT *vt = (VARIANT*)arg;
434 DWORD vttype = V_VT(vt);
436 if (debugout) MESSAGE("Vt(%ld)(",vttype);
439 hres = xbuf_add(buf,(LPBYTE)&vttype,sizeof(vttype));
440 if (hres) return hres;
442 /* need to recurse since we need to free the stuff */
443 hres = serialize_param(tinfo,writeit,debugout,dealloc,&tdesc2,&(V_I4(vt)),buf);
444 if (debugout) MESSAGE(")");
450 MESSAGE("%s",debugstr_w((BSTR)*arg));
452 MESSAGE("<bstr NULL>");
457 hres = xbuf_add(buf,(LPBYTE)&fakelen,4);
461 DWORD *bstr = ((DWORD*)(*arg))-1;
463 hres = xbuf_add(buf,(LPBYTE)bstr,bstr[0]+4);
469 SysFreeString((BSTR)arg);
475 if (debugout) MESSAGE("*");
477 cookie = *arg ? 0x42424242 : 0;
478 hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
483 if (debugout) MESSAGE("NULL");
486 hres = serialize_param(tinfo,writeit,debugout,dealloc,tdesc->u.lptdesc,(DWORD*)*arg,buf);
487 if (dealloc) HeapFree(GetProcessHeap(),0,(LPVOID)arg);
491 if (debugout) MESSAGE("unk(0x%lx)",*arg);
493 hres = _marshal_interface(buf,&IID_IUnknown,(LPUNKNOWN)*arg);
496 if (debugout) MESSAGE("idisp(0x%lx)",*arg);
498 hres = _marshal_interface(buf,&IID_IDispatch,(LPUNKNOWN)*arg);
501 if (debugout) MESSAGE("<void>");
503 case VT_USERDEFINED: {
507 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
509 FIXME("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
512 ITypeInfo_GetTypeAttr(tinfo2,&tattr);
513 switch (tattr->typekind) {
514 case TKIND_INTERFACE:
516 hres=_marshal_interface(buf,&(tattr->guid),(LPUNKNOWN)arg);
520 if (debugout) MESSAGE("{");
521 for (i=0;i<tattr->cVars;i++) {
526 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
528 FIXME("Could not get vardesc of %d\n",i);
531 /* Need them for hack below */
533 memset(names,0,sizeof(names));
534 hres = ITypeInfo_GetNames(tinfo2,vdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
535 if (nrofnames > sizeof(names)/sizeof(names[0])) {
536 ERR("Need more names!\n");
538 if (!hres && debugout)
539 MESSAGE("%s=",debugstr_w(names[0]));
541 elem2 = &vdesc->elemdescVar;
542 tdesc2 = &elem2->tdesc;
543 hres = serialize_param(
549 (DWORD*)(((LPBYTE)arg)+vdesc->u.oInst),
554 if (debugout && (i<(tattr->cVars-1)))
557 if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
558 memcpy(&(buf->iid),arg,sizeof(buf->iid));
559 if (debugout) MESSAGE("}");
563 FIXME("Don't know how to marshal type kind %d\n",tattr->typekind);
567 ITypeInfo_Release(tinfo2);
571 ARRAYDESC *adesc = tdesc->u.lpadesc;
574 if (debugout) MESSAGE("carr");
575 for (i=0;i<adesc->cDims;i++) {
576 if (debugout) MESSAGE("[%ld]",adesc->rgbounds[i].cElements);
577 arrsize *= adesc->rgbounds[i].cElements;
579 if (debugout) MESSAGE("[");
580 for (i=0;i<arrsize;i++) {
581 hres = serialize_param(tinfo, writeit, debugout, dealloc, &adesc->tdescElem, (DWORD*)((LPBYTE)arg+i*_xsize(&adesc->tdescElem)), buf);
584 if (debugout && (i<arrsize-1)) MESSAGE(",");
586 if (debugout) MESSAGE("]");
590 ERR("Unhandled marshal type %d.\n",tdesc->vt);
596 serialize_LPVOID_ptr(
608 if ((tdesc->vt != VT_PTR) ||
609 (tdesc->u.lptdesc->vt != VT_PTR) ||
610 (tdesc->u.lptdesc->u.lptdesc->vt != VT_VOID)
612 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
615 cookie = (*arg) ? 0x42424242: 0x0;
617 hres = xbuf_add(buf, (LPVOID)&cookie, sizeof(cookie));
622 if (debugout) MESSAGE("<lpvoid NULL>");
626 MESSAGE("ppv(%p)",*(LPUNKNOWN*)*arg);
628 hres = _marshal_interface(buf,&(buf->iid),*(LPUNKNOWN*)*arg);
633 HeapFree(GetProcessHeap(),0,(LPVOID)*arg);
638 serialize_DISPPARAM_ptr(
652 if ((tdesc->vt != VT_PTR) || (tdesc->u.lptdesc->vt != VT_USERDEFINED)) {
653 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
657 cookie = *arg ? 0x42424242 : 0x0;
659 hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
664 if (debugout) MESSAGE("<DISPPARAMS NULL>");
667 disp = (DISPPARAMS*)*arg;
669 hres = xbuf_add(buf,(LPBYTE)&disp->cArgs,sizeof(disp->cArgs));
673 if (debugout) MESSAGE("D{");
674 for (i=0;i<disp->cArgs;i++) {
677 vtdesc.vt = VT_VARIANT;
684 (DWORD*)(disp->rgvarg+i),
687 if (debugout && (i<disp->cArgs-1))
691 HeapFree(GetProcessHeap(),0,disp->rgvarg);
693 hres = xbuf_add(buf,(LPBYTE)&disp->cNamedArgs,sizeof(disp->cNamedArgs));
697 if (debugout) MESSAGE("}{");
698 for (i=0;i<disp->cNamedArgs;i++) {
708 (DWORD*)(disp->rgdispidNamedArgs+i),
711 if (debugout && (i<disp->cNamedArgs-1))
714 if (debugout) MESSAGE("}");
716 HeapFree(GetProcessHeap(),0,disp->rgdispidNamedArgs);
717 HeapFree(GetProcessHeap(),0,disp);
734 TRACE("vt %d at %p\n",tdesc->vt,arg);
739 if (debugout) MESSAGE("<empty>");
742 if (debugout) MESSAGE("<null>");
745 VARIANT *vt = (VARIANT*)arg;
750 hres = xbuf_get(buf,(LPBYTE)&vttype,sizeof(vttype));
752 FIXME("vt type not read?\n");
755 memset(&tdesc2,0,sizeof(tdesc2));
758 if (debugout) MESSAGE("Vt(%ld)(",vttype);
759 hres = deserialize_param(tinfo, readit, debugout, alloc, &tdesc2, &(V_I4(vt)), buf);
768 case VT_BOOL: case VT_I4: case VT_UI4: case VT_UINT: case VT_R4:
772 hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
773 if (hres) FIXME("Failed to read integer 4 byte\n");
775 if (debugout) MESSAGE("%lx",*arg);
782 hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
784 FIXME("failed to read bstr klen\n");
789 if (debugout) MESSAGE("<bstr NULL>");
791 str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len+sizeof(WCHAR));
792 hres = xbuf_get(buf,(LPBYTE)str,len);
794 FIXME("Failed to read BSTR.\n");
797 *arg = (DWORD)SysAllocStringLen(str,len);
798 if (debugout) MESSAGE("%s",debugstr_w(str));
799 HeapFree(GetProcessHeap(),0,str);
810 derefhere = (tdesc->u.lptdesc->vt != VT_USERDEFINED);
813 hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
815 FIXME("Failed to load pointer cookie.\n");
818 if (cookie != 0x42424242) {
819 if (debugout) MESSAGE("NULL");
823 if (debugout) MESSAGE("*");
827 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,_xsize(tdesc->u.lptdesc));
830 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, (LPDWORD)*arg, buf);
832 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, arg, buf);
835 /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
837 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
840 hres = _unmarshal_interface(buf,&IID_IUnknown,(LPUNKNOWN*)arg);
842 MESSAGE("unk(%p)",arg);
847 hres = _unmarshal_interface(buf,&IID_IDispatch,(LPUNKNOWN*)arg);
849 MESSAGE("idisp(%p)",arg);
852 if (debugout) MESSAGE("<void>");
854 case VT_USERDEFINED: {
858 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
860 FIXME("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
863 hres = ITypeInfo_GetTypeAttr(tinfo2,&tattr);
865 FIXME("Could not get typeattr in VT_USERDEFINED.\n");
868 *arg = (DWORD)HeapAlloc(GetProcessHeap(),0,tattr->cbSizeInstance);
869 switch (tattr->typekind) {
870 case TKIND_INTERFACE:
872 hres = _unmarshal_interface(buf,&(tattr->guid),(LPUNKNOWN*)arg);
877 if (debugout) MESSAGE("{");
878 for (i=0;i<tattr->cVars;i++) {
881 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
883 FIXME("Could not get vardesc of %d\n",i);
886 hres = deserialize_param(
891 &vdesc->elemdescVar.tdesc,
892 (DWORD*)(((LPBYTE)*arg)+vdesc->u.oInst),
895 if (debugout && (i<tattr->cVars-1)) MESSAGE(",");
897 if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
898 memcpy(&(buf->iid),(LPBYTE)*arg,sizeof(buf->iid));
899 if (debugout) MESSAGE("}");
903 FIXME("Don't know how to marshal type kind %d\n",tattr->typekind);
909 FIXME("failed to stuballoc in TKIND_RECORD.\n");
910 ITypeInfo_Release(tinfo2);
914 /* arg is pointing to the start of the array. */
915 ARRAYDESC *adesc = tdesc->u.lpadesc;
918 if (adesc->cDims > 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
919 for (i=0;i<adesc->cDims;i++)
920 arrsize *= adesc->rgbounds[i].cElements;
921 for (i=0;i<arrsize;i++)
928 (DWORD*)((LPBYTE)(arg)+i*_xsize(&adesc->tdescElem)),
934 ERR("No handler for VT type %d!\n",tdesc->vt);
941 deserialize_LPVOID_ptr(
953 if ((tdesc->vt != VT_PTR) ||
954 (tdesc->u.lptdesc->vt != VT_PTR) ||
955 (tdesc->u.lptdesc->u.lptdesc->vt != VT_VOID)
957 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
961 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(LPVOID));
963 hres = xbuf_get(buf, (LPVOID)&cookie, sizeof(cookie));
966 if (cookie != 0x42424242) {
968 if (debugout) MESSAGE("<lpvoid NULL>");
973 hres = _unmarshal_interface(buf,&buf->iid,(LPUNKNOWN*)*arg);
977 if (debugout) MESSAGE("ppv(%p)",(LPVOID)*arg);
982 deserialize_DISPPARAM_ptr(
996 if ((tdesc->vt != VT_PTR) || (tdesc->u.lptdesc->vt != VT_USERDEFINED)) {
997 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
1001 hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
1006 if (debugout) MESSAGE("<DISPPARAMS NULL>");
1011 *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPPARAMS));
1012 disps = (DISPPARAMS*)*arg;
1015 hres = xbuf_get(buf, (LPBYTE)&disps->cArgs, sizeof(disps->cArgs));
1019 disps->rgvarg = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(VARIANT)*disps->cArgs);
1020 if (debugout) MESSAGE("D{");
1021 for (i=0; i< disps->cArgs; i++) {
1024 vdesc.vt = VT_VARIANT;
1025 hres = deserialize_param(
1031 (DWORD*)(disps->rgvarg+i),
1035 if (debugout) MESSAGE("}{");
1036 hres = xbuf_get(buf, (LPBYTE)&disps->cNamedArgs, sizeof(disps->cNamedArgs));
1039 if (disps->cNamedArgs) {
1041 disps->rgdispidNamedArgs = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPID)*disps->cNamedArgs);
1042 for (i=0; i< disps->cNamedArgs; i++) {
1046 hres = deserialize_param(
1052 (DWORD*)(disps->rgdispidNamedArgs+i),
1055 if (debugout && i<(disps->cNamedArgs-1)) MESSAGE(",");
1058 if (debugout) MESSAGE("}");
1062 /* Searches function, also in inherited interfaces */
1065 ITypeInfo *tinfo, int iMethod, FUNCDESC **fdesc, BSTR *iname, BSTR *fname
1070 if (fname) *fname = NULL;
1071 if (iname) *iname = NULL;
1074 hres = ITypeInfo_GetFuncDesc(tinfo, i, fdesc);
1080 hres = ITypeInfo_GetTypeAttr(tinfo, &attr);
1082 FIXME("GetTypeAttr failed with %lx\n",hres);
1085 /* Not found, so look in inherited ifaces. */
1086 for (j=0;j<attr->cImplTypes;j++) {
1087 hres = ITypeInfo_GetRefTypeOfImplType(tinfo, j, &href);
1089 FIXME("Did not find a reftype for interface offset %d?\n",j);
1092 hres = ITypeInfo_GetRefTypeInfo(tinfo, href, &tinfo2);
1094 FIXME("Did not find a typeinfo for reftype %ld?\n",href);
1097 hres = _get_funcdesc(tinfo2,iMethod,fdesc,iname,fname);
1098 ITypeInfo_Release(tinfo2);
1099 if (!hres) return S_OK;
1103 if (((*fdesc)->oVft/4) == iMethod) {
1105 ITypeInfo_GetDocumentation(tinfo,(*fdesc)->memid,fname,NULL,NULL,NULL);
1107 ITypeInfo_GetDocumentation(tinfo,-1,iname,NULL,NULL,NULL);
1116 xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */) {
1117 DWORD *args = ((DWORD*)&tpinfo)+1, *xargs;
1120 int i, relaydeb = TRACE_ON(olerelay);
1128 hres = _get_funcdesc(tpinfo->tinfo,method,&fdesc,&iname,&fname);
1130 ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method);
1134 /*dump_FUNCDESC(fdesc);*/
1136 TRACE_(olerelay)("->");
1138 MESSAGE("%s:",debugstr_w(iname));
1140 MESSAGE("%s(%d)",debugstr_w(fname),method);
1142 MESSAGE("%d",method);
1144 if (iname) SysFreeString(iname);
1145 if (fname) SysFreeString(fname);
1147 /* Need them for hack below */
1148 memset(names,0,sizeof(names));
1149 if (ITypeInfo_GetNames(tpinfo->tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames))
1151 if (nrofnames > sizeof(names)/sizeof(names[0]))
1152 ERR("Need more names!\n");
1154 memset(&buf,0,sizeof(buf));
1155 buf.iid = IID_IUnknown;
1157 xbuf_add(&buf,(LPBYTE)args[0],sizeof(IID));
1158 if (relaydeb) MESSAGE("riid=%s,[out]",debugstr_guid((REFIID)args[0]));
1161 for (i=0;i<fdesc->cParams;i++) {
1162 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1163 BOOL isserialized = FALSE;
1165 if (i) MESSAGE(",");
1166 if (i+1<nrofnames && names[i+1])
1167 MESSAGE("%s=",debugstr_w(names[i+1]));
1169 /* No need to marshal other data than FIN */
1170 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN)) {
1171 xargs+=_argsize(elem->tdesc.vt);
1172 if (relaydeb) MESSAGE("[out]");
1175 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1176 /* If the parameter is 'riid', we use it as interface IID
1177 * for a later ppvObject serialization.
1179 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1181 /* DISPPARAMS* needs special serializer */
1182 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1183 hres = serialize_DISPPARAM_ptr(
1185 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1192 isserialized = TRUE;
1194 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1195 hres = serialize_LPVOID_ptr(
1197 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1205 isserialized = TRUE;
1209 hres = serialize_param(
1211 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1220 FIXME("Failed to serialize param, hres %lx\n",hres);
1223 xargs+=_argsize(elem->tdesc.vt);
1226 if (relaydeb) MESSAGE(")");
1227 memset(&msg,0,sizeof(msg));
1228 msg.cbBuffer = buf.curoff;
1229 msg.iMethod = method;
1230 hres = IRpcChannelBuffer_GetBuffer(tpinfo->chanbuf,&msg,&(tpinfo->iid));
1232 FIXME("RpcChannelBuffer GetBuffer failed, %lx\n",hres);
1235 memcpy(msg.Buffer,buf.base,buf.curoff);
1236 if (relaydeb) MESSAGE("\n");
1237 hres = IRpcChannelBuffer_SendReceive(tpinfo->chanbuf,&msg,&status);
1239 FIXME("RpcChannelBuffer SendReceive failed, %lx\n",hres);
1242 relaydeb = TRACE_ON(olerelay);
1243 if (relaydeb) MESSAGE(" = %08lx (",status);
1245 buf.base = HeapReAlloc(GetProcessHeap(),0,buf.base,msg.cbBuffer);
1247 buf.base = HeapAlloc(GetProcessHeap(),0,msg.cbBuffer);
1248 buf.size = msg.cbBuffer;
1249 memcpy(buf.base,msg.Buffer,buf.size);
1252 _unmarshal_interface(&buf,(REFIID)args[0],(LPUNKNOWN*)args[1]);
1253 if (relaydeb) MESSAGE("[in],%p",*((DWORD**)args[1]));
1256 for (i=0;i<fdesc->cParams;i++) {
1257 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1258 BOOL isdeserialized = FALSE;
1261 if (i) MESSAGE(",");
1262 if (i+1<nrofnames && names[i+1]) MESSAGE("%s=",debugstr_w(names[i+1]));
1264 /* No need to marshal other data than FOUT I think */
1265 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT)) {
1266 xargs += _argsize(elem->tdesc.vt);
1267 if (relaydeb) MESSAGE("[in]");
1270 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1271 /* If the parameter is 'riid', we use it as interface IID
1272 * for a later ppvObject serialization.
1274 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1276 /* deserialize DISPPARAM */
1277 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1278 hres = deserialize_DISPPARAM_ptr(
1280 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1288 FIXME("Failed to deserialize DISPPARAM*, hres %lx\n",hres);
1291 isdeserialized = TRUE;
1293 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1294 hres = deserialize_LPVOID_ptr(
1296 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1304 isdeserialized = TRUE;
1307 if (!isdeserialized)
1308 hres = deserialize_param(
1310 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1318 FIXME("Failed to unmarshall param, hres %lx\n",hres);
1321 xargs += _argsize(elem->tdesc.vt);
1324 if (relaydeb) MESSAGE(")\n\n");
1325 HeapFree(GetProcessHeap(),0,buf.base);
1329 static HRESULT WINAPI
1330 PSFacBuf_CreateProxy(
1331 LPPSFACTORYBUFFER iface, IUnknown* pUnkOuter, REFIID riid,
1332 IRpcProxyBuffer **ppProxy, LPVOID *ppv
1340 TRACE("(...%s...)\n",debugstr_guid(riid));
1341 hres = _get_typeinfo_for_iid(riid,&tinfo);
1343 FIXME("No typeinfo for %s?\n",debugstr_guid(riid));
1346 nroffuncs = _nroffuncs(tinfo);
1347 proxy = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TMProxyImpl));
1348 if (!proxy) return E_OUTOFMEMORY;
1349 proxy->asmstubs=HeapAlloc(GetProcessHeap(),0,sizeof(TMAsmProxy)*nroffuncs);
1351 assert(sizeof(TMAsmProxy) == 12);
1353 proxy->lpvtbl = HeapAlloc(GetProcessHeap(),0,sizeof(LPBYTE)*nroffuncs);
1354 for (i=0;i<nroffuncs;i++) {
1356 TMAsmProxy *xasm = proxy->asmstubs+i;
1358 /* nrofargs without This */
1360 case 0: nrofargs = 2;
1362 case 1: case 2: nrofargs = 0;
1366 hres = _get_funcdesc(tinfo,i,&fdesc,NULL,NULL);
1368 FIXME("GetFuncDesc %lx should not fail here.\n",hres);
1371 /* some args take more than 4 byte on the stack */
1373 for (j=0;j<fdesc->cParams;j++)
1374 nrofargs += _argsize(fdesc->lprgelemdescParam[j].tdesc.vt);
1376 if (fdesc->callconv != CC_STDCALL) {
1377 ERR("calling convention is not stdcall????\n");
1383 /* popl %eax - return ptr
1390 * arg3 arg2 arg1 <method> <returnptr>
1392 xasm->popleax = 0x58;
1393 xasm->pushlval = 0x6a;
1395 xasm->pushleax = 0x50;
1396 xasm->lcall = 0xe8; /* relative jump */
1397 xasm->xcall = (DWORD)xCall;
1398 xasm->xcall -= (DWORD)&(xasm->lret);
1400 xasm->bytestopop= (nrofargs+2)*4; /* pop args, This, iMethod */
1401 proxy->lpvtbl[i] = (DWORD)xasm;
1403 proxy->lpvtbl2 = &tmproxyvtable;
1405 proxy->tinfo = tinfo;
1406 memcpy(&proxy->iid,riid,sizeof(*riid));
1407 *ppv = (LPVOID)proxy;
1408 *ppProxy = (IRpcProxyBuffer *)&(proxy->lpvtbl2);
1412 typedef struct _TMStubImpl {
1413 ICOM_VTABLE(IRpcStubBuffer) *lpvtbl;
1421 static HRESULT WINAPI
1422 TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface, REFIID riid, LPVOID *ppv) {
1423 if (IsEqualIID(riid,&IID_IRpcStubBuffer)||IsEqualIID(riid,&IID_IUnknown)){
1424 *ppv = (LPVOID)iface;
1425 IRpcStubBuffer_AddRef(iface);
1428 FIXME("%s, not supported IID.\n",debugstr_guid(riid));
1429 return E_NOINTERFACE;
1433 TMStubImpl_AddRef(LPRPCSTUBBUFFER iface) {
1434 ICOM_THIS(TMStubImpl,iface);
1441 TMStubImpl_Release(LPRPCSTUBBUFFER iface) {
1442 ICOM_THIS(TMStubImpl,iface);
1447 HeapFree(GetProcessHeap(),0,This);
1451 static HRESULT WINAPI
1452 TMStubImpl_Connect(LPRPCSTUBBUFFER iface, LPUNKNOWN pUnkServer) {
1453 ICOM_THIS(TMStubImpl,iface);
1455 IUnknown_AddRef(pUnkServer);
1456 This->pUnk = pUnkServer;
1461 TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface) {
1462 ICOM_THIS(TMStubImpl,iface);
1464 IUnknown_Release(This->pUnk);
1469 static HRESULT WINAPI
1471 LPRPCSTUBBUFFER iface, RPCOLEMESSAGE* xmsg,IRpcChannelBuffer*rpcchanbuf
1475 ICOM_THIS(TMStubImpl,iface);
1477 DWORD *args, res, *xargs, nrofargs;
1482 memset(&buf,0,sizeof(buf));
1483 buf.size = xmsg->cbBuffer;
1484 buf.base = xmsg->Buffer;
1486 buf.iid = IID_IUnknown;
1489 if (xmsg->iMethod == 0) { /* QI */
1491 /* in: IID, out: <iface> */
1493 xbuf_get(&buf,(LPBYTE)&xiid,sizeof(xiid));
1495 hres = _marshal_interface(&buf,&xiid,This->pUnk);
1496 xmsg->Buffer = buf.base; /* Might have been reallocated */
1497 xmsg->cbBuffer = buf.size;
1500 hres = _get_funcdesc(This->tinfo,xmsg->iMethod,&fdesc,NULL,NULL);
1502 FIXME("GetFuncDesc on method %ld failed with %lx\n",xmsg->iMethod,hres);
1505 /* Need them for hack below */
1506 memset(names,0,sizeof(names));
1507 ITypeInfo_GetNames(This->tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
1508 if (nrofnames > sizeof(names)/sizeof(names[0])) {
1509 ERR("Need more names!\n");
1512 /*dump_FUNCDESC(fdesc);*/
1514 for (i=0;i<fdesc->cParams;i++)
1515 nrofargs += _argsize(fdesc->lprgelemdescParam[i].tdesc.vt);
1516 args = HeapAlloc(GetProcessHeap(),0,(nrofargs+1)*sizeof(DWORD));
1517 if (!args) return E_OUTOFMEMORY;
1519 /* Allocate all stuff used by call. */
1521 for (i=0;i<fdesc->cParams;i++) {
1522 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1523 BOOL isdeserialized = FALSE;
1525 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1526 /* If the parameter is 'riid', we use it as interface IID
1527 * for a later ppvObject serialization.
1529 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1531 /* deserialize DISPPARAM */
1532 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1533 hres = deserialize_DISPPARAM_ptr(
1535 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1543 FIXME("Failed to deserialize DISPPARAM*, hres %lx\n",hres);
1546 isdeserialized = TRUE;
1548 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1549 hres = deserialize_LPVOID_ptr(
1551 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1559 isdeserialized = TRUE;
1562 if (!isdeserialized)
1563 hres = deserialize_param(
1565 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1572 xargs += _argsize(elem->tdesc.vt);
1574 FIXME("Failed to deserialize param %s, hres %lx\n",debugstr_w(names[i+1]),hres);
1578 hres = IUnknown_QueryInterface(This->pUnk,&(This->iid),(LPVOID*)&(args[0]));
1580 ERR("Does not support iface %s\n",debugstr_guid(&(This->iid)));
1584 (*((LPVOID**)args[0]))[fdesc->oVft/4],
1589 IUnknown_Release((LPUNKNOWN)args[0]);
1592 for (i=0;i<fdesc->cParams;i++) {
1593 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1594 BOOL isserialized = FALSE;
1596 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1597 /* If the parameter is 'riid', we use it as interface IID
1598 * for a later ppvObject serialization.
1600 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1602 /* DISPPARAMS* needs special serializer */
1603 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1604 hres = serialize_DISPPARAM_ptr(
1606 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1613 isserialized = TRUE;
1615 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1616 hres = serialize_LPVOID_ptr(
1618 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1626 isserialized = TRUE;
1630 hres = serialize_param(
1632 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1639 xargs += _argsize(elem->tdesc.vt);
1641 FIXME("Failed to stuballoc param, hres %lx\n",hres);
1645 /* might need to use IRpcChannelBuffer_GetBuffer ? */
1646 xmsg->cbBuffer = buf.curoff;
1647 xmsg->Buffer = buf.base;
1648 HeapFree(GetProcessHeap(),0,args);
1652 static LPRPCSTUBBUFFER WINAPI
1653 TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface, REFIID riid) {
1654 FIXME("Huh (%s)?\n",debugstr_guid(riid));
1659 TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface) {
1660 ICOM_THIS(TMStubImpl,iface);
1662 return This->ref; /*FIXME? */
1665 static HRESULT WINAPI
1666 TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface, LPVOID *ppv) {
1671 TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface, LPVOID ppv) {
1675 ICOM_VTABLE(IRpcStubBuffer) tmstubvtbl = {
1676 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1677 TMStubImpl_QueryInterface,
1681 TMStubImpl_Disconnect,
1683 TMStubImpl_IsIIDSupported,
1684 TMStubImpl_CountRefs,
1685 TMStubImpl_DebugServerQueryInterface,
1686 TMStubImpl_DebugServerRelease
1689 static HRESULT WINAPI
1690 PSFacBuf_CreateStub(
1691 LPPSFACTORYBUFFER iface, REFIID riid,IUnknown *pUnkServer,
1692 IRpcStubBuffer** ppStub
1698 TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub);
1699 hres = _get_typeinfo_for_iid(riid,&tinfo);
1701 FIXME("No typeinfo for %s?\n",debugstr_guid(riid));
1704 stub = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TMStubImpl));
1706 return E_OUTOFMEMORY;
1707 stub->lpvtbl = &tmstubvtbl;
1709 stub->tinfo = tinfo;
1710 memcpy(&(stub->iid),riid,sizeof(*riid));
1711 hres = IRpcStubBuffer_Connect((LPRPCSTUBBUFFER)stub,pUnkServer);
1712 *ppStub = (LPRPCSTUBBUFFER)stub;
1714 FIXME("Connect to pUnkServer failed?\n");
1718 static ICOM_VTABLE(IPSFactoryBuffer) psfacbufvtbl = {
1719 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1720 PSFacBuf_QueryInterface,
1723 PSFacBuf_CreateProxy,
1727 /* This is the whole PSFactoryBuffer object, just the vtableptr */
1728 static ICOM_VTABLE(IPSFactoryBuffer) *lppsfac = &psfacbufvtbl;
1730 /***********************************************************************
1731 * DllGetClassObject [OLE32.63]
1734 TypeLibFac_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
1736 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)) {
1740 return E_NOINTERFACE;