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"
39 #include "wine/debug.h"
42 static const WCHAR riidW[5] = {'r','i','i','d',0};
43 static const WCHAR pdispparamsW[] = {'p','d','i','s','p','p','a','r','a','m','s',0};
44 static const WCHAR ppvObjectW[] = {'p','p','v','O','b','j','e','c','t',0};
46 WINE_DEFAULT_DEBUG_CHANNEL(ole);
47 WINE_DECLARE_DEBUG_CHANNEL(olerelay);
49 typedef struct _marshal_state {
55 IID iid; /* HACK: for VT_VOID */
59 xbuf_add(marshal_state *buf, LPBYTE stuff, DWORD size) {
60 while (buf->size - buf->curoff < size) {
63 buf->base = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,buf->base,buf->size);
67 buf->base = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,32);
73 memcpy(buf->base+buf->curoff,stuff,size);
79 xbuf_get(marshal_state *buf, LPBYTE stuff, DWORD size) {
80 if (buf->size < buf->curoff+size) return E_FAIL;
81 memcpy(stuff,buf->base+buf->curoff,size);
87 xbuf_skip(marshal_state *buf, DWORD size) {
88 if (buf->size < buf->curoff+size) return E_FAIL;
94 _unmarshal_interface(marshal_state *buf, REFIID riid, LPUNKNOWN *pUnk) {
96 ULARGE_INTEGER newpos;
102 TRACE("...%s...\n",debugstr_guid(riid));
104 hres = xbuf_get(buf,(LPBYTE)&xsize,sizeof(xsize));
105 if (hres) return hres;
106 if (xsize == 0) return S_OK;
107 hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
109 FIXME("Stream create failed %lx\n",hres);
112 hres = IStream_Write(pStm,buf->base+buf->curoff,xsize,&res);
113 if (hres) { FIXME("stream write %lx\n",hres); return hres; }
114 memset(&seekto,0,sizeof(seekto));
115 hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
116 if (hres) { FIXME("Failed Seek %lx\n",hres); return hres;}
117 hres = CoUnmarshalInterface(pStm,riid,(LPVOID*)pUnk);
119 FIXME("Marshaling interface %s failed with %lx\n",debugstr_guid(riid),hres);
122 IStream_Release(pStm);
123 return xbuf_skip(buf,xsize);
127 _marshal_interface(marshal_state *buf, REFIID riid, LPUNKNOWN pUnk) {
132 ULARGE_INTEGER newpos;
133 LARGE_INTEGER seekto;
142 TRACE("...%s...\n",debugstr_guid(riid));
143 hres=IUnknown_QueryInterface(pUnk,riid,(LPVOID*)&newiface);
145 TRACE("%p does not support iface %s\n",pUnk,debugstr_guid(riid));
148 hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
150 FIXME("Stream create failed %lx\n",hres);
153 hres = CoMarshalInterface(pStm,riid,newiface,0,NULL,0);
154 IUnknown_Release(newiface);
156 FIXME("Marshaling interface %s failed with %lx\n",
157 debugstr_guid(riid),hres
161 hres = IStream_Stat(pStm,&ststg,0);
162 tempbuf = HeapAlloc(GetProcessHeap(), 0, ststg.cbSize.s.LowPart);
163 memset(&seekto,0,sizeof(seekto));
164 hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
165 if (hres) { FIXME("Failed Seek %lx\n",hres); goto fail;}
166 hres = IStream_Read(pStm,tempbuf,ststg.cbSize.s.LowPart,&res);
167 if (hres) { FIXME("Failed Read %lx\n",hres); goto fail;}
168 IStream_Release(pStm);
169 xsize = ststg.cbSize.s.LowPart;
170 xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
171 hres = xbuf_add(buf,tempbuf,ststg.cbSize.s.LowPart);
172 HeapFree(GetProcessHeap(),0,tempbuf);
176 xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
180 /********************* OLE Proxy/Stub Factory ********************************/
181 static HRESULT WINAPI
182 PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface, REFIID iid, LPVOID *ppv) {
183 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)||IsEqualIID(iid,&IID_IUnknown)) {
184 *ppv = (LPVOID)iface;
185 /* No ref counting, static class */
188 FIXME("(%s) unknown IID?\n",debugstr_guid(iid));
189 return E_NOINTERFACE;
192 static ULONG WINAPI PSFacBuf_AddRef(LPPSFACTORYBUFFER iface) { return 2; }
193 static ULONG WINAPI PSFacBuf_Release(LPPSFACTORYBUFFER iface) { return 1; }
196 _get_typeinfo_for_iid(REFIID riid, ITypeInfo**ti) {
199 char tlguid[200],typelibkey[300],interfacekey[300],ver[100];
202 DWORD tlguidlen, verlen, type, tlfnlen;
205 sprintf( interfacekey, "Interface\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\Typelib",
206 riid->Data1, riid->Data2, riid->Data3,
207 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
208 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7]
211 if (RegOpenKeyA(HKEY_CLASSES_ROOT,interfacekey,&ikey)) {
212 FIXME("No %s key found.\n",interfacekey);
216 tlguidlen = sizeof(tlguid);
217 if (RegQueryValueExA(ikey,NULL,NULL,&type,tlguid,&tlguidlen)) {
218 FIXME("Getting typelib guid failed.\n");
223 verlen = sizeof(ver);
224 if (RegQueryValueExA(ikey,"Version",NULL,&type,ver,&verlen)) {
225 FIXME("Could not get version value?\n");
230 sprintf(typelibkey,"Typelib\\%s\\%s\\0\\win32",tlguid,ver);
231 tlfnlen = sizeof(tlfn);
232 if (RegQueryValueA(HKEY_CLASSES_ROOT,typelibkey,tlfn,&tlfnlen)) {
233 FIXME("Could not get typelib fn?\n");
236 MultiByteToWideChar(CP_ACP, 0, tlfn, -1, tlfnW, -1);
237 hres = LoadTypeLib(tlfnW,&tl);
239 ERR("Failed to load typelib for %s, but it should be there.\n",debugstr_guid(riid));
242 hres = ITypeLib_GetTypeInfoOfGuid(tl,riid,ti);
244 ERR("typelib does not contain info for %s?\n",debugstr_guid(riid));
245 ITypeLib_Release(tl);
248 /* FIXME: do this? ITypeLib_Release(tl); */
252 /* Determine nr of functions. Since we use the toplevel interface and all
253 * inherited ones have lower numbers, we are ok to not to descent into
254 * the inheritance tree I think.
256 static int _nroffuncs(ITypeInfo *tinfo) {
263 hres = ITypeInfo_GetFuncDesc(tinfo,n,&fdesc);
264 if (fdesc->oVft/4 > max)
273 typedef struct _TMAsmProxy {
282 } WINE_PACKED TMAsmProxy;
284 typedef struct _TMProxyImpl {
286 ICOM_VTABLE(IRpcProxyBuffer) *lpvtbl2;
289 TMAsmProxy *asmstubs;
291 IRpcChannelBuffer* chanbuf;
295 static HRESULT WINAPI
296 TMProxyImpl_QueryInterface(LPRPCPROXYBUFFER iface, REFIID riid, LPVOID *ppv) {
298 if (IsEqualIID(riid,&IID_IUnknown)||IsEqualIID(riid,&IID_IRpcProxyBuffer)) {
299 *ppv = (LPVOID)iface;
300 IRpcProxyBuffer_AddRef(iface);
303 FIXME("no interface for %s\n",debugstr_guid(riid));
304 return E_NOINTERFACE;
308 TMProxyImpl_AddRef(LPRPCPROXYBUFFER iface) {
309 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
317 TMProxyImpl_Release(LPRPCPROXYBUFFER iface) {
318 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
322 if (This->ref) return This->ref;
323 if (This->chanbuf) IRpcChannelBuffer_Release(This->chanbuf);
324 HeapFree(GetProcessHeap(),0,This);
328 static HRESULT WINAPI
330 LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer
332 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
334 TRACE("(%p)\n",pRpcChannelBuffer);
335 This->chanbuf = pRpcChannelBuffer;
336 IRpcChannelBuffer_AddRef(This->chanbuf);
341 TMProxyImpl_Disconnect(LPRPCPROXYBUFFER iface) {
342 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
345 IRpcChannelBuffer_Release(This->chanbuf);
346 This->chanbuf = NULL;
350 static ICOM_VTABLE(IRpcProxyBuffer) tmproxyvtable = {
351 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
352 TMProxyImpl_QueryInterface,
356 TMProxyImpl_Disconnect
359 /* how much space do we use on stack in DWORD steps. */
364 return sizeof(DATE)/sizeof(DWORD);
366 return (sizeof(VARIANT)+3)/sizeof(DWORD);
373 _xsize(TYPEDESC *td) {
378 return sizeof(VARIANT)+3;
381 ARRAYDESC *adesc = td->u.lpadesc;
383 for (i=0;i<adesc->cDims;i++)
384 arrsize *= adesc->rgbounds[i].cElements;
385 return arrsize*_xsize(&adesc->tdescElem);
410 TRACE("(tdesc.vt %d)\n",tdesc->vt);
413 case VT_EMPTY: /* nothing. empty variant for instance */
424 if (debugout) MESSAGE("%lx",*arg);
426 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
430 VARIANT *vt = (VARIANT*)arg;
431 DWORD vttype = V_VT(vt);
433 if (debugout) MESSAGE("Vt(%ld)(",vttype);
436 hres = xbuf_add(buf,(LPBYTE)&vttype,sizeof(vttype));
437 if (hres) return hres;
439 /* need to recurse since we need to free the stuff */
440 hres = serialize_param(tinfo,writeit,debugout,dealloc,&tdesc2,&(V_I4(vt)),buf);
441 if (debugout) MESSAGE(")");
447 MESSAGE("%s",debugstr_w((BSTR)*arg));
449 MESSAGE("<bstr NULL>");
454 hres = xbuf_add(buf,(LPBYTE)&fakelen,4);
458 DWORD *bstr = ((DWORD*)(*arg))-1;
460 hres = xbuf_add(buf,(LPBYTE)bstr,bstr[0]+4);
466 SysFreeString((BSTR)arg);
472 if (debugout) MESSAGE("*");
474 cookie = *arg ? 0x42424242 : 0;
475 hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
480 if (debugout) MESSAGE("NULL");
483 hres = serialize_param(tinfo,writeit,debugout,dealloc,tdesc->u.lptdesc,(DWORD*)*arg,buf);
484 if (dealloc) HeapFree(GetProcessHeap(),0,(LPVOID)arg);
488 if (debugout) MESSAGE("unk(0x%lx)",*arg);
490 hres = _marshal_interface(buf,&IID_IUnknown,(LPUNKNOWN)*arg);
493 if (debugout) MESSAGE("idisp(0x%lx)",*arg);
495 hres = _marshal_interface(buf,&IID_IDispatch,(LPUNKNOWN)*arg);
498 if (debugout) MESSAGE("<void>");
500 case VT_USERDEFINED: {
504 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
506 FIXME("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
509 ITypeInfo_GetTypeAttr(tinfo2,&tattr);
510 switch (tattr->typekind) {
511 case TKIND_INTERFACE:
513 hres=_marshal_interface(buf,&(tattr->guid),(LPUNKNOWN)arg);
517 if (debugout) MESSAGE("{");
518 for (i=0;i<tattr->cVars;i++) {
523 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
525 FIXME("Could not get vardesc of %d\n",i);
528 /* Need them for hack below */
530 memset(names,0,sizeof(names));
531 hres = ITypeInfo_GetNames(tinfo2,vdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
532 if (nrofnames > sizeof(names)/sizeof(names[0])) {
533 ERR("Need more names!\n");
535 if (!hres && debugout)
536 MESSAGE("%s=",debugstr_w(names[0]));
538 elem2 = &vdesc->elemdescVar;
539 tdesc2 = &elem2->tdesc;
540 hres = serialize_param(
546 (DWORD*)(((LPBYTE)arg)+vdesc->u.oInst),
551 if (debugout && (i<(tattr->cVars-1)))
554 if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
555 memcpy(&(buf->iid),arg,sizeof(buf->iid));
556 if (debugout) MESSAGE("}");
560 FIXME("Don't know how to marshal type kind %d\n",tattr->typekind);
564 ITypeInfo_Release(tinfo2);
568 ARRAYDESC *adesc = tdesc->u.lpadesc;
571 if (debugout) MESSAGE("carr");
572 for (i=0;i<adesc->cDims;i++) {
573 if (debugout) MESSAGE("[%ld]",adesc->rgbounds[i].cElements);
574 arrsize *= adesc->rgbounds[i].cElements;
576 if (debugout) MESSAGE("[");
577 for (i=0;i<arrsize;i++) {
578 hres = serialize_param(tinfo, writeit, debugout, dealloc, &adesc->tdescElem, (DWORD*)((LPBYTE)arg+i*_xsize(&adesc->tdescElem)), buf);
581 if (debugout && (i<arrsize-1)) MESSAGE(",");
583 if (debugout) MESSAGE("]");
587 ERR("Unhandled marshal type %d.\n",tdesc->vt);
593 serialize_LPVOID_ptr(
605 if ((tdesc->vt != VT_PTR) ||
606 (tdesc->u.lptdesc->vt != VT_PTR) ||
607 (tdesc->u.lptdesc->u.lptdesc->vt != VT_VOID)
609 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
612 cookie = (*arg) ? 0x42424242: 0x0;
614 hres = xbuf_add(buf, (LPVOID)&cookie, sizeof(cookie));
619 if (debugout) MESSAGE("<lpvoid NULL>");
623 MESSAGE("ppv(%p)",*(LPUNKNOWN*)*arg);
625 hres = _marshal_interface(buf,&(buf->iid),*(LPUNKNOWN*)*arg);
630 HeapFree(GetProcessHeap(),0,(LPVOID)*arg);
635 serialize_DISPPARAM_ptr(
649 if ((tdesc->vt != VT_PTR) || (tdesc->u.lptdesc->vt != VT_USERDEFINED)) {
650 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
654 cookie = *arg ? 0x42424242 : 0x0;
656 hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
661 if (debugout) MESSAGE("<DISPPARAMS NULL>");
664 disp = (DISPPARAMS*)*arg;
666 hres = xbuf_add(buf,(LPBYTE)&disp->cArgs,sizeof(disp->cArgs));
670 if (debugout) MESSAGE("D{");
671 for (i=0;i<disp->cArgs;i++) {
674 vtdesc.vt = VT_VARIANT;
681 (DWORD*)(disp->rgvarg+i),
684 if (debugout && (i<disp->cArgs-1))
688 HeapFree(GetProcessHeap(),0,disp->rgvarg);
690 hres = xbuf_add(buf,(LPBYTE)&disp->cNamedArgs,sizeof(disp->cNamedArgs));
694 if (debugout) MESSAGE("}{");
695 for (i=0;i<disp->cNamedArgs;i++) {
705 (DWORD*)(disp->rgdispidNamedArgs+i),
708 if (debugout && (i<disp->cNamedArgs-1))
711 if (debugout) MESSAGE("}");
713 HeapFree(GetProcessHeap(),0,disp->rgdispidNamedArgs);
714 HeapFree(GetProcessHeap(),0,disp);
731 TRACE("vt %d at %p\n",tdesc->vt,arg);
736 if (debugout) MESSAGE("<empty>");
739 if (debugout) MESSAGE("<null>");
742 VARIANT *vt = (VARIANT*)arg;
747 hres = xbuf_get(buf,(LPBYTE)&vttype,sizeof(vttype));
749 FIXME("vt type not read?\n");
752 memset(&tdesc2,0,sizeof(tdesc2));
755 if (debugout) MESSAGE("Vt(%ld)(",vttype);
756 hres = deserialize_param(tinfo, readit, debugout, alloc, &tdesc2, &(V_I4(vt)), buf);
765 case VT_BOOL: case VT_I4: case VT_UI4: case VT_UINT: case VT_R4:
769 hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
770 if (hres) FIXME("Failed to read integer 4 byte\n");
772 if (debugout) MESSAGE("%lx",*arg);
779 hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
781 FIXME("failed to read bstr klen\n");
786 if (debugout) MESSAGE("<bstr NULL>");
788 str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len+sizeof(WCHAR));
789 hres = xbuf_get(buf,(LPBYTE)str,len);
791 FIXME("Failed to read BSTR.\n");
794 *arg = (DWORD)SysAllocStringLen(str,len);
795 if (debugout) MESSAGE("%s",debugstr_w(str));
796 HeapFree(GetProcessHeap(),0,str);
807 derefhere = (tdesc->u.lptdesc->vt != VT_USERDEFINED);
810 hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
812 FIXME("Failed to load pointer cookie.\n");
815 if (cookie != 0x42424242) {
816 if (debugout) MESSAGE("NULL");
820 if (debugout) MESSAGE("*");
824 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,_xsize(tdesc->u.lptdesc));
827 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, (LPDWORD)*arg, buf);
829 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, arg, buf);
832 /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
834 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
837 hres = _unmarshal_interface(buf,&IID_IUnknown,(LPUNKNOWN*)arg);
839 MESSAGE("unk(%p)",arg);
844 hres = _unmarshal_interface(buf,&IID_IDispatch,(LPUNKNOWN*)arg);
846 MESSAGE("idisp(%p)",arg);
849 if (debugout) MESSAGE("<void>");
851 case VT_USERDEFINED: {
855 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
857 FIXME("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
860 hres = ITypeInfo_GetTypeAttr(tinfo2,&tattr);
862 FIXME("Could not get typeattr in VT_USERDEFINED.\n");
865 *arg = (DWORD)HeapAlloc(GetProcessHeap(),0,tattr->cbSizeInstance);
866 switch (tattr->typekind) {
867 case TKIND_INTERFACE:
869 hres = _unmarshal_interface(buf,&(tattr->guid),(LPUNKNOWN*)arg);
874 if (debugout) MESSAGE("{");
875 for (i=0;i<tattr->cVars;i++) {
878 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
880 FIXME("Could not get vardesc of %d\n",i);
883 hres = deserialize_param(
888 &vdesc->elemdescVar.tdesc,
889 (DWORD*)(((LPBYTE)*arg)+vdesc->u.oInst),
892 if (debugout && (i<tattr->cVars-1)) MESSAGE(",");
894 if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
895 memcpy(&(buf->iid),(LPBYTE)*arg,sizeof(buf->iid));
896 if (debugout) MESSAGE("}");
900 FIXME("Don't know how to marshal type kind %d\n",tattr->typekind);
906 FIXME("failed to stuballoc in TKIND_RECORD.\n");
907 ITypeInfo_Release(tinfo2);
911 /* arg is pointing to the start of the array. */
912 ARRAYDESC *adesc = tdesc->u.lpadesc;
915 if (adesc->cDims > 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
916 for (i=0;i<adesc->cDims;i++)
917 arrsize *= adesc->rgbounds[i].cElements;
918 for (i=0;i<arrsize;i++)
925 (DWORD*)((LPBYTE)(arg)+i*_xsize(&adesc->tdescElem)),
931 ERR("No handler for VT type %d!\n",tdesc->vt);
938 deserialize_LPVOID_ptr(
950 if ((tdesc->vt != VT_PTR) ||
951 (tdesc->u.lptdesc->vt != VT_PTR) ||
952 (tdesc->u.lptdesc->u.lptdesc->vt != VT_VOID)
954 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
958 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(LPVOID));
960 hres = xbuf_get(buf, (LPVOID)&cookie, sizeof(cookie));
963 if (cookie != 0x42424242) {
965 if (debugout) MESSAGE("<lpvoid NULL>");
970 hres = _unmarshal_interface(buf,&buf->iid,(LPUNKNOWN*)*arg);
974 if (debugout) MESSAGE("ppv(%p)",(LPVOID)*arg);
979 deserialize_DISPPARAM_ptr(
993 if ((tdesc->vt != VT_PTR) || (tdesc->u.lptdesc->vt != VT_USERDEFINED)) {
994 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
998 hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
1003 if (debugout) MESSAGE("<DISPPARAMS NULL>");
1008 *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPPARAMS));
1009 disps = (DISPPARAMS*)*arg;
1012 hres = xbuf_get(buf, (LPBYTE)&disps->cArgs, sizeof(disps->cArgs));
1016 disps->rgvarg = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(VARIANT)*disps->cArgs);
1017 if (debugout) MESSAGE("D{");
1018 for (i=0; i< disps->cArgs; i++) {
1021 vdesc.vt = VT_VARIANT;
1022 hres = deserialize_param(
1028 (DWORD*)(disps->rgvarg+i),
1032 if (debugout) MESSAGE("}{");
1033 hres = xbuf_get(buf, (LPBYTE)&disps->cNamedArgs, sizeof(disps->cNamedArgs));
1036 if (disps->cNamedArgs) {
1038 disps->rgdispidNamedArgs = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPID)*disps->cNamedArgs);
1039 for (i=0; i< disps->cNamedArgs; i++) {
1043 hres = deserialize_param(
1049 (DWORD*)(disps->rgdispidNamedArgs+i),
1052 if (debugout && i<(disps->cNamedArgs-1)) MESSAGE(",");
1055 if (debugout) MESSAGE("}");
1059 /* Searches function, also in inherited interfaces */
1062 ITypeInfo *tinfo, int iMethod, FUNCDESC **fdesc, BSTR *iname, BSTR *fname
1067 if (fname) *fname = NULL;
1068 if (iname) *iname = NULL;
1071 hres = ITypeInfo_GetFuncDesc(tinfo, i, fdesc);
1077 hres = ITypeInfo_GetTypeAttr(tinfo, &attr);
1079 FIXME("GetTypeAttr failed with %lx\n",hres);
1082 /* Not found, so look in inherited ifaces. */
1083 for (j=0;j<attr->cImplTypes;j++) {
1084 hres = ITypeInfo_GetRefTypeOfImplType(tinfo, j, &href);
1086 FIXME("Did not find a reftype for interface offset %d?\n",j);
1089 hres = ITypeInfo_GetRefTypeInfo(tinfo, href, &tinfo2);
1091 FIXME("Did not find a typeinfo for reftype %ld?\n",href);
1094 hres = _get_funcdesc(tinfo2,iMethod,fdesc,iname,fname);
1095 ITypeInfo_Release(tinfo2);
1096 if (!hres) return S_OK;
1100 if (((*fdesc)->oVft/4) == iMethod) {
1102 ITypeInfo_GetDocumentation(tinfo,(*fdesc)->memid,fname,NULL,NULL,NULL);
1104 ITypeInfo_GetDocumentation(tinfo,-1,iname,NULL,NULL,NULL);
1113 xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */) {
1114 DWORD *args = ((DWORD*)&tpinfo)+1, *xargs;
1117 int i, relaydeb = TRACE_ON(olerelay);
1125 hres = _get_funcdesc(tpinfo->tinfo,method,&fdesc,&iname,&fname);
1127 ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method);
1131 /*dump_FUNCDESC(fdesc);*/
1133 TRACE_(olerelay)("->");
1135 MESSAGE("%s:",debugstr_w(iname));
1137 MESSAGE("%s(%d)",debugstr_w(fname),method);
1139 MESSAGE("%d",method);
1141 if (iname) SysFreeString(iname);
1142 if (fname) SysFreeString(fname);
1144 /* Need them for hack below */
1145 memset(names,0,sizeof(names));
1146 if (ITypeInfo_GetNames(tpinfo->tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames))
1148 if (nrofnames > sizeof(names)/sizeof(names[0]))
1149 ERR("Need more names!\n");
1151 memset(&buf,0,sizeof(buf));
1152 buf.iid = IID_IUnknown;
1154 xbuf_add(&buf,(LPBYTE)args[0],sizeof(IID));
1155 if (relaydeb) MESSAGE("riid=%s,[out]",debugstr_guid((REFIID)args[0]));
1158 for (i=0;i<fdesc->cParams;i++) {
1159 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1160 BOOL isserialized = FALSE;
1162 if (i) MESSAGE(",");
1163 if (i+1<nrofnames && names[i+1])
1164 MESSAGE("%s=",debugstr_w(names[i+1]));
1166 /* No need to marshal other data than FIN */
1167 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN)) {
1168 xargs+=_argsize(elem->tdesc.vt);
1169 if (relaydeb) MESSAGE("[out]");
1172 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1173 /* If the parameter is 'riid', we use it as interface IID
1174 * for a later ppvObject serialization.
1176 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1178 /* DISPPARAMS* needs special serializer */
1179 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1180 hres = serialize_DISPPARAM_ptr(
1182 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1189 isserialized = TRUE;
1191 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1192 hres = serialize_LPVOID_ptr(
1194 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1202 isserialized = TRUE;
1206 hres = serialize_param(
1208 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1217 FIXME("Failed to serialize param, hres %lx\n",hres);
1220 xargs+=_argsize(elem->tdesc.vt);
1223 if (relaydeb) MESSAGE(")");
1224 memset(&msg,0,sizeof(msg));
1225 msg.cbBuffer = buf.curoff;
1226 msg.iMethod = method;
1227 hres = IRpcChannelBuffer_GetBuffer(tpinfo->chanbuf,&msg,&(tpinfo->iid));
1229 FIXME("RpcChannelBuffer GetBuffer failed, %lx\n",hres);
1232 memcpy(msg.Buffer,buf.base,buf.curoff);
1233 if (relaydeb) MESSAGE("\n");
1234 hres = IRpcChannelBuffer_SendReceive(tpinfo->chanbuf,&msg,&status);
1236 FIXME("RpcChannelBuffer SendReceive failed, %lx\n",hres);
1239 relaydeb = TRACE_ON(olerelay);
1240 if (relaydeb) MESSAGE(" = %08lx (",status);
1242 buf.base = HeapReAlloc(GetProcessHeap(),0,buf.base,msg.cbBuffer);
1244 buf.base = HeapAlloc(GetProcessHeap(),0,msg.cbBuffer);
1245 buf.size = msg.cbBuffer;
1246 memcpy(buf.base,msg.Buffer,buf.size);
1249 _unmarshal_interface(&buf,(REFIID)args[0],(LPUNKNOWN*)args[1]);
1250 if (relaydeb) MESSAGE("[in],%p",*((DWORD**)args[1]));
1253 for (i=0;i<fdesc->cParams;i++) {
1254 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1255 BOOL isdeserialized = FALSE;
1258 if (i) MESSAGE(",");
1259 if (i+1<nrofnames && names[i+1]) MESSAGE("%s=",debugstr_w(names[i+1]));
1261 /* No need to marshal other data than FOUT I think */
1262 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT)) {
1263 xargs += _argsize(elem->tdesc.vt);
1264 if (relaydeb) MESSAGE("[in]");
1267 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1268 /* If the parameter is 'riid', we use it as interface IID
1269 * for a later ppvObject serialization.
1271 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1273 /* deserialize DISPPARAM */
1274 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1275 hres = deserialize_DISPPARAM_ptr(
1277 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1285 FIXME("Failed to deserialize DISPPARAM*, hres %lx\n",hres);
1288 isdeserialized = TRUE;
1290 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1291 hres = deserialize_LPVOID_ptr(
1293 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1301 isdeserialized = TRUE;
1304 if (!isdeserialized)
1305 hres = deserialize_param(
1307 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1315 FIXME("Failed to unmarshall param, hres %lx\n",hres);
1318 xargs += _argsize(elem->tdesc.vt);
1321 if (relaydeb) MESSAGE(")\n\n");
1322 HeapFree(GetProcessHeap(),0,buf.base);
1326 static HRESULT WINAPI
1327 PSFacBuf_CreateProxy(
1328 LPPSFACTORYBUFFER iface, IUnknown* pUnkOuter, REFIID riid,
1329 IRpcProxyBuffer **ppProxy, LPVOID *ppv
1337 TRACE("(...%s...)\n",debugstr_guid(riid));
1338 hres = _get_typeinfo_for_iid(riid,&tinfo);
1340 FIXME("No typeinfo for %s?\n",debugstr_guid(riid));
1343 nroffuncs = _nroffuncs(tinfo);
1344 proxy = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TMProxyImpl));
1345 if (!proxy) return E_OUTOFMEMORY;
1346 proxy->asmstubs=HeapAlloc(GetProcessHeap(),0,sizeof(TMAsmProxy)*nroffuncs);
1348 assert(sizeof(TMAsmProxy) == 12);
1350 proxy->lpvtbl = HeapAlloc(GetProcessHeap(),0,sizeof(LPBYTE)*nroffuncs);
1351 for (i=0;i<nroffuncs;i++) {
1353 TMAsmProxy *xasm = proxy->asmstubs+i;
1355 /* nrofargs without This */
1357 case 0: nrofargs = 2;
1359 case 1: case 2: nrofargs = 0;
1363 hres = _get_funcdesc(tinfo,i,&fdesc,NULL,NULL);
1365 FIXME("GetFuncDesc %lx should not fail here.\n",hres);
1368 /* some args take more than 4 byte on the stack */
1370 for (j=0;j<fdesc->cParams;j++)
1371 nrofargs += _argsize(fdesc->lprgelemdescParam[j].tdesc.vt);
1373 if (fdesc->callconv != CC_STDCALL) {
1374 ERR("calling convention is not stdcall????\n");
1380 /* popl %eax - return ptr
1387 * arg3 arg2 arg1 <method> <returnptr>
1389 xasm->popleax = 0x58;
1390 xasm->pushlval = 0x6a;
1392 xasm->pushleax = 0x50;
1393 xasm->lcall = 0xe8; /* relative jump */
1394 xasm->xcall = (DWORD)xCall;
1395 xasm->xcall -= (DWORD)&(xasm->lret);
1397 xasm->bytestopop= (nrofargs+2)*4; /* pop args, This, iMethod */
1398 proxy->lpvtbl[i] = (DWORD)xasm;
1400 proxy->lpvtbl2 = &tmproxyvtable;
1402 proxy->tinfo = tinfo;
1403 memcpy(&proxy->iid,riid,sizeof(*riid));
1404 *ppv = (LPVOID)proxy;
1405 *ppProxy = (IRpcProxyBuffer *)&(proxy->lpvtbl2);
1409 typedef struct _TMStubImpl {
1410 ICOM_VTABLE(IRpcStubBuffer) *lpvtbl;
1418 static HRESULT WINAPI
1419 TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface, REFIID riid, LPVOID *ppv) {
1420 if (IsEqualIID(riid,&IID_IRpcStubBuffer)||IsEqualIID(riid,&IID_IUnknown)){
1421 *ppv = (LPVOID)iface;
1422 IRpcStubBuffer_AddRef(iface);
1425 FIXME("%s, not supported IID.\n",debugstr_guid(riid));
1426 return E_NOINTERFACE;
1430 TMStubImpl_AddRef(LPRPCSTUBBUFFER iface) {
1431 ICOM_THIS(TMStubImpl,iface);
1438 TMStubImpl_Release(LPRPCSTUBBUFFER iface) {
1439 ICOM_THIS(TMStubImpl,iface);
1444 HeapFree(GetProcessHeap(),0,This);
1448 static HRESULT WINAPI
1449 TMStubImpl_Connect(LPRPCSTUBBUFFER iface, LPUNKNOWN pUnkServer) {
1450 ICOM_THIS(TMStubImpl,iface);
1452 IUnknown_AddRef(pUnkServer);
1453 This->pUnk = pUnkServer;
1458 TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface) {
1459 ICOM_THIS(TMStubImpl,iface);
1461 IUnknown_Release(This->pUnk);
1466 static HRESULT WINAPI
1468 LPRPCSTUBBUFFER iface, RPCOLEMESSAGE* xmsg,IRpcChannelBuffer*rpcchanbuf
1472 ICOM_THIS(TMStubImpl,iface);
1474 DWORD *args, res, *xargs, nrofargs;
1479 memset(&buf,0,sizeof(buf));
1480 buf.size = xmsg->cbBuffer;
1481 buf.base = xmsg->Buffer;
1483 buf.iid = IID_IUnknown;
1486 if (xmsg->iMethod == 0) { /* QI */
1488 /* in: IID, out: <iface> */
1490 xbuf_get(&buf,(LPBYTE)&xiid,sizeof(xiid));
1492 hres = _marshal_interface(&buf,&xiid,This->pUnk);
1493 xmsg->Buffer = buf.base; /* Might have been reallocated */
1494 xmsg->cbBuffer = buf.size;
1497 hres = _get_funcdesc(This->tinfo,xmsg->iMethod,&fdesc,NULL,NULL);
1499 FIXME("GetFuncDesc on method %ld failed with %lx\n",xmsg->iMethod,hres);
1502 /* Need them for hack below */
1503 memset(names,0,sizeof(names));
1504 ITypeInfo_GetNames(This->tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
1505 if (nrofnames > sizeof(names)/sizeof(names[0])) {
1506 ERR("Need more names!\n");
1509 /*dump_FUNCDESC(fdesc);*/
1511 for (i=0;i<fdesc->cParams;i++)
1512 nrofargs += _argsize(fdesc->lprgelemdescParam[i].tdesc.vt);
1513 args = HeapAlloc(GetProcessHeap(),0,(nrofargs+1)*sizeof(DWORD));
1514 if (!args) return E_OUTOFMEMORY;
1516 /* Allocate all stuff used by call. */
1518 for (i=0;i<fdesc->cParams;i++) {
1519 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1520 BOOL isdeserialized = FALSE;
1522 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1523 /* If the parameter is 'riid', we use it as interface IID
1524 * for a later ppvObject serialization.
1526 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1528 /* deserialize DISPPARAM */
1529 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1530 hres = deserialize_DISPPARAM_ptr(
1532 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1540 FIXME("Failed to deserialize DISPPARAM*, hres %lx\n",hres);
1543 isdeserialized = TRUE;
1545 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1546 hres = deserialize_LPVOID_ptr(
1548 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1556 isdeserialized = TRUE;
1559 if (!isdeserialized)
1560 hres = deserialize_param(
1562 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1569 xargs += _argsize(elem->tdesc.vt);
1571 FIXME("Failed to deserialize param %s, hres %lx\n",debugstr_w(names[i+1]),hres);
1575 hres = IUnknown_QueryInterface(This->pUnk,&(This->iid),(LPVOID*)&(args[0]));
1577 ERR("Does not support iface %s\n",debugstr_guid(&(This->iid)));
1581 (*((LPVOID**)args[0]))[fdesc->oVft/4],
1586 IUnknown_Release((LPUNKNOWN)args[0]);
1589 for (i=0;i<fdesc->cParams;i++) {
1590 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1591 BOOL isserialized = FALSE;
1593 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1594 /* If the parameter is 'riid', we use it as interface IID
1595 * for a later ppvObject serialization.
1597 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1599 /* DISPPARAMS* needs special serializer */
1600 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1601 hres = serialize_DISPPARAM_ptr(
1603 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1610 isserialized = TRUE;
1612 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1613 hres = serialize_LPVOID_ptr(
1615 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1623 isserialized = TRUE;
1627 hres = serialize_param(
1629 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1636 xargs += _argsize(elem->tdesc.vt);
1638 FIXME("Failed to stuballoc param, hres %lx\n",hres);
1642 /* might need to use IRpcChannelBuffer_GetBuffer ? */
1643 xmsg->cbBuffer = buf.curoff;
1644 xmsg->Buffer = buf.base;
1645 HeapFree(GetProcessHeap(),0,args);
1649 static LPRPCSTUBBUFFER WINAPI
1650 TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface, REFIID riid) {
1651 FIXME("Huh (%s)?\n",debugstr_guid(riid));
1656 TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface) {
1657 ICOM_THIS(TMStubImpl,iface);
1659 return This->ref; /*FIXME? */
1662 static HRESULT WINAPI
1663 TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface, LPVOID *ppv) {
1668 TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface, LPVOID ppv) {
1672 ICOM_VTABLE(IRpcStubBuffer) tmstubvtbl = {
1673 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1674 TMStubImpl_QueryInterface,
1678 TMStubImpl_Disconnect,
1680 TMStubImpl_IsIIDSupported,
1681 TMStubImpl_CountRefs,
1682 TMStubImpl_DebugServerQueryInterface,
1683 TMStubImpl_DebugServerRelease
1686 static HRESULT WINAPI
1687 PSFacBuf_CreateStub(
1688 LPPSFACTORYBUFFER iface, REFIID riid,IUnknown *pUnkServer,
1689 IRpcStubBuffer** ppStub
1695 TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub);
1696 hres = _get_typeinfo_for_iid(riid,&tinfo);
1698 FIXME("No typeinfo for %s?\n",debugstr_guid(riid));
1701 stub = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TMStubImpl));
1703 return E_OUTOFMEMORY;
1704 stub->lpvtbl = &tmstubvtbl;
1706 stub->tinfo = tinfo;
1707 memcpy(&(stub->iid),riid,sizeof(*riid));
1708 hres = IRpcStubBuffer_Connect((LPRPCSTUBBUFFER)stub,pUnkServer);
1709 *ppStub = (LPRPCSTUBBUFFER)stub;
1711 FIXME("Connect to pUnkServer failed?\n");
1715 static ICOM_VTABLE(IPSFactoryBuffer) psfacbufvtbl = {
1716 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1717 PSFacBuf_QueryInterface,
1720 PSFacBuf_CreateProxy,
1724 /* This is the whole PSFactoryBuffer object, just the vtableptr */
1725 static ICOM_VTABLE(IPSFactoryBuffer) *lppsfac = &psfacbufvtbl;
1727 /***********************************************************************
1728 * DllGetClassObject [OLE32.63]
1731 TypeLibFac_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
1733 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)) {
1737 return E_NOINTERFACE;