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.s.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.s.LowPart,&res);
171 if (hres) { FIXME("Failed Read %lx\n",hres); goto fail;}
172 IStream_Release(pStm);
173 xsize = ststg.cbSize.s.LowPart;
174 xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
175 hres = xbuf_add(buf,tempbuf,ststg.cbSize.s.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 typedef struct _TMAsmProxy {
286 } WINE_PACKED TMAsmProxy;
288 typedef struct _TMProxyImpl {
290 ICOM_VTABLE(IRpcProxyBuffer) *lpvtbl2;
293 TMAsmProxy *asmstubs;
295 IRpcChannelBuffer* chanbuf;
299 static HRESULT WINAPI
300 TMProxyImpl_QueryInterface(LPRPCPROXYBUFFER iface, REFIID riid, LPVOID *ppv) {
302 if (IsEqualIID(riid,&IID_IUnknown)||IsEqualIID(riid,&IID_IRpcProxyBuffer)) {
303 *ppv = (LPVOID)iface;
304 IRpcProxyBuffer_AddRef(iface);
307 FIXME("no interface for %s\n",debugstr_guid(riid));
308 return E_NOINTERFACE;
312 TMProxyImpl_AddRef(LPRPCPROXYBUFFER iface) {
313 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
321 TMProxyImpl_Release(LPRPCPROXYBUFFER iface) {
322 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
326 if (This->ref) return This->ref;
327 if (This->chanbuf) IRpcChannelBuffer_Release(This->chanbuf);
328 HeapFree(GetProcessHeap(),0,This);
332 static HRESULT WINAPI
334 LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer
336 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
338 TRACE("(%p)\n",pRpcChannelBuffer);
339 This->chanbuf = pRpcChannelBuffer;
340 IRpcChannelBuffer_AddRef(This->chanbuf);
345 TMProxyImpl_Disconnect(LPRPCPROXYBUFFER iface) {
346 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
349 IRpcChannelBuffer_Release(This->chanbuf);
350 This->chanbuf = NULL;
354 static ICOM_VTABLE(IRpcProxyBuffer) tmproxyvtable = {
355 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
356 TMProxyImpl_QueryInterface,
360 TMProxyImpl_Disconnect
363 /* how much space do we use on stack in DWORD steps. */
368 return sizeof(DATE)/sizeof(DWORD);
370 return (sizeof(VARIANT)+3)/sizeof(DWORD);
377 _xsize(TYPEDESC *td) {
382 return sizeof(VARIANT)+3;
385 ARRAYDESC *adesc = td->u.lpadesc;
387 for (i=0;i<adesc->cDims;i++)
388 arrsize *= adesc->rgbounds[i].cElements;
389 return arrsize*_xsize(&adesc->tdescElem);
414 TRACE("(tdesc.vt %d)\n",tdesc->vt);
417 case VT_EMPTY: /* nothing. empty variant for instance */
428 if (debugout) MESSAGE("%lx",*arg);
430 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
434 VARIANT *vt = (VARIANT*)arg;
435 DWORD vttype = V_VT(vt);
437 if (debugout) MESSAGE("Vt(%ld)(",vttype);
440 hres = xbuf_add(buf,(LPBYTE)&vttype,sizeof(vttype));
441 if (hres) return hres;
443 /* need to recurse since we need to free the stuff */
444 hres = serialize_param(tinfo,writeit,debugout,dealloc,&tdesc2,&(V_I4(vt)),buf);
445 if (debugout) MESSAGE(")");
451 MESSAGE("%s",debugstr_w((BSTR)*arg));
453 MESSAGE("<bstr NULL>");
458 hres = xbuf_add(buf,(LPBYTE)&fakelen,4);
462 DWORD *bstr = ((DWORD*)(*arg))-1;
464 hres = xbuf_add(buf,(LPBYTE)bstr,bstr[0]+4);
470 SysFreeString((BSTR)arg);
476 if (debugout) MESSAGE("*");
478 cookie = *arg ? 0x42424242 : 0;
479 hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
484 if (debugout) MESSAGE("NULL");
487 hres = serialize_param(tinfo,writeit,debugout,dealloc,tdesc->u.lptdesc,(DWORD*)*arg,buf);
488 if (dealloc) HeapFree(GetProcessHeap(),0,(LPVOID)arg);
492 if (debugout) MESSAGE("unk(0x%lx)",*arg);
494 hres = _marshal_interface(buf,&IID_IUnknown,(LPUNKNOWN)*arg);
497 if (debugout) MESSAGE("idisp(0x%lx)",*arg);
499 hres = _marshal_interface(buf,&IID_IDispatch,(LPUNKNOWN)*arg);
502 if (debugout) MESSAGE("<void>");
504 case VT_USERDEFINED: {
508 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
510 FIXME("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
513 ITypeInfo_GetTypeAttr(tinfo2,&tattr);
514 switch (tattr->typekind) {
516 case TKIND_INTERFACE:
518 hres=_marshal_interface(buf,&(tattr->guid),(LPUNKNOWN)arg);
522 if (debugout) MESSAGE("{");
523 for (i=0;i<tattr->cVars;i++) {
528 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
530 FIXME("Could not get vardesc of %d\n",i);
533 /* Need them for hack below */
535 memset(names,0,sizeof(names));
536 hres = ITypeInfo_GetNames(tinfo2,vdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
537 if (nrofnames > sizeof(names)/sizeof(names[0])) {
538 ERR("Need more names!\n");
540 if (!hres && debugout)
541 MESSAGE("%s=",debugstr_w(names[0]));
543 elem2 = &vdesc->elemdescVar;
544 tdesc2 = &elem2->tdesc;
545 hres = serialize_param(
551 (DWORD*)(((LPBYTE)arg)+vdesc->u.oInst),
556 if (debugout && (i<(tattr->cVars-1)))
559 if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
560 memcpy(&(buf->iid),arg,sizeof(buf->iid));
561 if (debugout) MESSAGE("}");
565 FIXME("Unhandled typekind %d\n",tattr->typekind);
569 ITypeInfo_Release(tinfo2);
573 ARRAYDESC *adesc = tdesc->u.lpadesc;
576 if (debugout) MESSAGE("carr");
577 for (i=0;i<adesc->cDims;i++) {
578 if (debugout) MESSAGE("[%ld]",adesc->rgbounds[i].cElements);
579 arrsize *= adesc->rgbounds[i].cElements;
581 if (debugout) MESSAGE("[");
582 for (i=0;i<arrsize;i++) {
583 hres = serialize_param(tinfo, writeit, debugout, dealloc, &adesc->tdescElem, (DWORD*)((LPBYTE)arg+i*_xsize(&adesc->tdescElem)), buf);
586 if (debugout && (i<arrsize-1)) MESSAGE(",");
588 if (debugout) MESSAGE("]");
592 ERR("Unhandled marshal type %d.\n",tdesc->vt);
598 serialize_LPVOID_ptr(
610 if ((tdesc->vt != VT_PTR) ||
611 (tdesc->u.lptdesc->vt != VT_PTR) ||
612 (tdesc->u.lptdesc->u.lptdesc->vt != VT_VOID)
614 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
617 cookie = (*arg) ? 0x42424242: 0x0;
619 hres = xbuf_add(buf, (LPVOID)&cookie, sizeof(cookie));
624 if (debugout) MESSAGE("<lpvoid NULL>");
628 MESSAGE("ppv(%p)",*(LPUNKNOWN*)*arg);
630 hres = _marshal_interface(buf,&(buf->iid),*(LPUNKNOWN*)*arg);
635 HeapFree(GetProcessHeap(),0,(LPVOID)*arg);
640 serialize_DISPPARAM_ptr(
654 if ((tdesc->vt != VT_PTR) || (tdesc->u.lptdesc->vt != VT_USERDEFINED)) {
655 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
659 cookie = *arg ? 0x42424242 : 0x0;
661 hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
666 if (debugout) MESSAGE("<DISPPARAMS NULL>");
669 disp = (DISPPARAMS*)*arg;
671 hres = xbuf_add(buf,(LPBYTE)&disp->cArgs,sizeof(disp->cArgs));
675 if (debugout) MESSAGE("D{");
676 for (i=0;i<disp->cArgs;i++) {
679 vtdesc.vt = VT_VARIANT;
686 (DWORD*)(disp->rgvarg+i),
689 if (debugout && (i<disp->cArgs-1))
693 HeapFree(GetProcessHeap(),0,disp->rgvarg);
695 hres = xbuf_add(buf,(LPBYTE)&disp->cNamedArgs,sizeof(disp->cNamedArgs));
699 if (debugout) MESSAGE("}{");
700 for (i=0;i<disp->cNamedArgs;i++) {
710 (DWORD*)(disp->rgdispidNamedArgs+i),
713 if (debugout && (i<disp->cNamedArgs-1))
716 if (debugout) MESSAGE("}");
718 HeapFree(GetProcessHeap(),0,disp->rgdispidNamedArgs);
719 HeapFree(GetProcessHeap(),0,disp);
736 TRACE("vt %d at %p\n",tdesc->vt,arg);
741 if (debugout) MESSAGE("<empty>");
744 if (debugout) MESSAGE("<null>");
747 VARIANT *vt = (VARIANT*)arg;
752 hres = xbuf_get(buf,(LPBYTE)&vttype,sizeof(vttype));
754 FIXME("vt type not read?\n");
757 memset(&tdesc2,0,sizeof(tdesc2));
760 if (debugout) MESSAGE("Vt(%ld)(",vttype);
761 hres = deserialize_param(tinfo, readit, debugout, alloc, &tdesc2, &(V_I4(vt)), buf);
770 case VT_BOOL: case VT_I4: case VT_UI4: case VT_UINT: case VT_R4:
774 hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
775 if (hres) FIXME("Failed to read integer 4 byte\n");
777 if (debugout) MESSAGE("%lx",*arg);
784 hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
786 FIXME("failed to read bstr klen\n");
791 if (debugout) MESSAGE("<bstr NULL>");
793 str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len+sizeof(WCHAR));
794 hres = xbuf_get(buf,(LPBYTE)str,len);
796 FIXME("Failed to read BSTR.\n");
799 *arg = (DWORD)SysAllocStringLen(str,len);
800 if (debugout) MESSAGE("%s",debugstr_w(str));
801 HeapFree(GetProcessHeap(),0,str);
812 derefhere = (tdesc->u.lptdesc->vt != VT_USERDEFINED);
815 hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
817 FIXME("Failed to load pointer cookie.\n");
820 if (cookie != 0x42424242) {
821 if (debugout) MESSAGE("NULL");
825 if (debugout) MESSAGE("*");
829 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,_xsize(tdesc->u.lptdesc));
832 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, (LPDWORD)*arg, buf);
834 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, arg, buf);
837 /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
839 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
842 hres = _unmarshal_interface(buf,&IID_IUnknown,(LPUNKNOWN*)arg);
844 MESSAGE("unk(%p)",arg);
849 hres = _unmarshal_interface(buf,&IID_IDispatch,(LPUNKNOWN*)arg);
851 MESSAGE("idisp(%p)",arg);
854 if (debugout) MESSAGE("<void>");
856 case VT_USERDEFINED: {
860 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
862 FIXME("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
865 hres = ITypeInfo_GetTypeAttr(tinfo2,&tattr);
867 FIXME("Could not get typeattr in VT_USERDEFINED.\n");
870 *arg = (DWORD)HeapAlloc(GetProcessHeap(),0,tattr->cbSizeInstance);
871 switch (tattr->typekind) {
873 case TKIND_INTERFACE:
875 hres = _unmarshal_interface(buf,&(tattr->guid),(LPUNKNOWN*)arg);
880 if (debugout) MESSAGE("{");
881 for (i=0;i<tattr->cVars;i++) {
884 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
886 FIXME("Could not get vardesc of %d\n",i);
889 hres = deserialize_param(
894 &vdesc->elemdescVar.tdesc,
895 (DWORD*)(((LPBYTE)*arg)+vdesc->u.oInst),
898 if (debugout && (i<tattr->cVars-1)) MESSAGE(",");
900 if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
901 memcpy(&(buf->iid),(LPBYTE)*arg,sizeof(buf->iid));
902 if (debugout) MESSAGE("}");
906 ERR("Unhandled typekind %d\n",tattr->typekind);
912 FIXME("failed to stuballoc in TKIND_RECORD.\n");
913 ITypeInfo_Release(tinfo2);
917 /* arg is pointing to the start of the array. */
918 ARRAYDESC *adesc = tdesc->u.lpadesc;
921 if (adesc->cDims > 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
922 for (i=0;i<adesc->cDims;i++)
923 arrsize *= adesc->rgbounds[i].cElements;
924 for (i=0;i<arrsize;i++)
931 (DWORD*)((LPBYTE)(arg)+i*_xsize(&adesc->tdescElem)),
937 ERR("No handler for VT type %d!\n",tdesc->vt);
944 deserialize_LPVOID_ptr(
956 if ((tdesc->vt != VT_PTR) ||
957 (tdesc->u.lptdesc->vt != VT_PTR) ||
958 (tdesc->u.lptdesc->u.lptdesc->vt != VT_VOID)
960 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
964 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(LPVOID));
966 hres = xbuf_get(buf, (LPVOID)&cookie, sizeof(cookie));
969 if (cookie != 0x42424242) {
971 if (debugout) MESSAGE("<lpvoid NULL>");
976 hres = _unmarshal_interface(buf,&buf->iid,(LPUNKNOWN*)*arg);
980 if (debugout) MESSAGE("ppv(%p)",(LPVOID)*arg);
985 deserialize_DISPPARAM_ptr(
999 if ((tdesc->vt != VT_PTR) || (tdesc->u.lptdesc->vt != VT_USERDEFINED)) {
1000 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
1004 hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
1009 if (debugout) MESSAGE("<DISPPARAMS NULL>");
1014 *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPPARAMS));
1015 disps = (DISPPARAMS*)*arg;
1018 hres = xbuf_get(buf, (LPBYTE)&disps->cArgs, sizeof(disps->cArgs));
1022 disps->rgvarg = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(VARIANT)*disps->cArgs);
1023 if (debugout) MESSAGE("D{");
1024 for (i=0; i< disps->cArgs; i++) {
1027 vdesc.vt = VT_VARIANT;
1028 hres = deserialize_param(
1034 (DWORD*)(disps->rgvarg+i),
1038 if (debugout) MESSAGE("}{");
1039 hres = xbuf_get(buf, (LPBYTE)&disps->cNamedArgs, sizeof(disps->cNamedArgs));
1042 if (disps->cNamedArgs) {
1044 disps->rgdispidNamedArgs = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPID)*disps->cNamedArgs);
1045 for (i=0; i< disps->cNamedArgs; i++) {
1049 hres = deserialize_param(
1055 (DWORD*)(disps->rgdispidNamedArgs+i),
1058 if (debugout && i<(disps->cNamedArgs-1)) MESSAGE(",");
1061 if (debugout) MESSAGE("}");
1065 /* Searches function, also in inherited interfaces */
1068 ITypeInfo *tinfo, int iMethod, FUNCDESC **fdesc, BSTR *iname, BSTR *fname
1073 if (fname) *fname = NULL;
1074 if (iname) *iname = NULL;
1077 hres = ITypeInfo_GetFuncDesc(tinfo, i, fdesc);
1083 hres = ITypeInfo_GetTypeAttr(tinfo, &attr);
1085 FIXME("GetTypeAttr failed with %lx\n",hres);
1088 /* Not found, so look in inherited ifaces. */
1089 for (j=0;j<attr->cImplTypes;j++) {
1090 hres = ITypeInfo_GetRefTypeOfImplType(tinfo, j, &href);
1092 FIXME("Did not find a reftype for interface offset %d?\n",j);
1095 hres = ITypeInfo_GetRefTypeInfo(tinfo, href, &tinfo2);
1097 FIXME("Did not find a typeinfo for reftype %ld?\n",href);
1100 hres = _get_funcdesc(tinfo2,iMethod,fdesc,iname,fname);
1101 ITypeInfo_Release(tinfo2);
1102 if (!hres) return S_OK;
1106 if (((*fdesc)->oVft/4) == iMethod) {
1108 ITypeInfo_GetDocumentation(tinfo,(*fdesc)->memid,fname,NULL,NULL,NULL);
1110 ITypeInfo_GetDocumentation(tinfo,-1,iname,NULL,NULL,NULL);
1119 xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */) {
1120 DWORD *args = ((DWORD*)&tpinfo)+1, *xargs;
1123 int i, relaydeb = TRACE_ON(olerelay);
1131 hres = _get_funcdesc(tpinfo->tinfo,method,&fdesc,&iname,&fname);
1133 ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method);
1137 /*dump_FUNCDESC(fdesc);*/
1139 TRACE_(olerelay)("->");
1141 MESSAGE("%s:",debugstr_w(iname));
1143 MESSAGE("%s(%d)",debugstr_w(fname),method);
1145 MESSAGE("%d",method);
1147 if (iname) SysFreeString(iname);
1148 if (fname) SysFreeString(fname);
1150 /* Need them for hack below */
1151 memset(names,0,sizeof(names));
1152 if (ITypeInfo_GetNames(tpinfo->tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames))
1154 if (nrofnames > sizeof(names)/sizeof(names[0]))
1155 ERR("Need more names!\n");
1157 memset(&buf,0,sizeof(buf));
1158 buf.iid = IID_IUnknown;
1160 xbuf_add(&buf,(LPBYTE)args[0],sizeof(IID));
1161 if (relaydeb) MESSAGE("riid=%s,[out]",debugstr_guid((REFIID)args[0]));
1164 for (i=0;i<fdesc->cParams;i++) {
1165 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1166 BOOL isserialized = FALSE;
1168 if (i) MESSAGE(",");
1169 if (i+1<nrofnames && names[i+1])
1170 MESSAGE("%s=",debugstr_w(names[i+1]));
1172 /* No need to marshal other data than FIN */
1173 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN)) {
1174 xargs+=_argsize(elem->tdesc.vt);
1175 if (relaydeb) MESSAGE("[out]");
1178 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1179 /* If the parameter is 'riid', we use it as interface IID
1180 * for a later ppvObject serialization.
1182 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1184 /* DISPPARAMS* needs special serializer */
1185 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1186 hres = serialize_DISPPARAM_ptr(
1188 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1195 isserialized = TRUE;
1197 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1198 hres = serialize_LPVOID_ptr(
1200 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1208 isserialized = TRUE;
1212 hres = serialize_param(
1214 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1223 FIXME("Failed to serialize param, hres %lx\n",hres);
1226 xargs+=_argsize(elem->tdesc.vt);
1229 if (relaydeb) MESSAGE(")");
1230 memset(&msg,0,sizeof(msg));
1231 msg.cbBuffer = buf.curoff;
1232 msg.iMethod = method;
1233 hres = IRpcChannelBuffer_GetBuffer(tpinfo->chanbuf,&msg,&(tpinfo->iid));
1235 FIXME("RpcChannelBuffer GetBuffer failed, %lx\n",hres);
1238 memcpy(msg.Buffer,buf.base,buf.curoff);
1239 if (relaydeb) MESSAGE("\n");
1240 hres = IRpcChannelBuffer_SendReceive(tpinfo->chanbuf,&msg,&status);
1242 FIXME("RpcChannelBuffer SendReceive failed, %lx\n",hres);
1245 relaydeb = TRACE_ON(olerelay);
1246 if (relaydeb) MESSAGE(" = %08lx (",status);
1248 buf.base = HeapReAlloc(GetProcessHeap(),0,buf.base,msg.cbBuffer);
1250 buf.base = HeapAlloc(GetProcessHeap(),0,msg.cbBuffer);
1251 buf.size = msg.cbBuffer;
1252 memcpy(buf.base,msg.Buffer,buf.size);
1255 _unmarshal_interface(&buf,(REFIID)args[0],(LPUNKNOWN*)args[1]);
1256 if (relaydeb) MESSAGE("[in],%p",*((DWORD**)args[1]));
1259 for (i=0;i<fdesc->cParams;i++) {
1260 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1261 BOOL isdeserialized = FALSE;
1264 if (i) MESSAGE(",");
1265 if (i+1<nrofnames && names[i+1]) MESSAGE("%s=",debugstr_w(names[i+1]));
1267 /* No need to marshal other data than FOUT I think */
1268 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT)) {
1269 xargs += _argsize(elem->tdesc.vt);
1270 if (relaydeb) MESSAGE("[in]");
1273 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1274 /* If the parameter is 'riid', we use it as interface IID
1275 * for a later ppvObject serialization.
1277 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1279 /* deserialize DISPPARAM */
1280 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1281 hres = deserialize_DISPPARAM_ptr(
1283 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1291 FIXME("Failed to deserialize DISPPARAM*, hres %lx\n",hres);
1294 isdeserialized = TRUE;
1296 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1297 hres = deserialize_LPVOID_ptr(
1299 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1307 isdeserialized = TRUE;
1310 if (!isdeserialized)
1311 hres = deserialize_param(
1313 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1321 FIXME("Failed to unmarshall param, hres %lx\n",hres);
1324 xargs += _argsize(elem->tdesc.vt);
1327 if (relaydeb) MESSAGE(")\n\n");
1328 HeapFree(GetProcessHeap(),0,buf.base);
1332 static HRESULT WINAPI
1333 PSFacBuf_CreateProxy(
1334 LPPSFACTORYBUFFER iface, IUnknown* pUnkOuter, REFIID riid,
1335 IRpcProxyBuffer **ppProxy, LPVOID *ppv
1343 TRACE("(...%s...)\n",debugstr_guid(riid));
1344 hres = _get_typeinfo_for_iid(riid,&tinfo);
1346 FIXME("No typeinfo for %s?\n",debugstr_guid(riid));
1349 nroffuncs = _nroffuncs(tinfo);
1350 proxy = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TMProxyImpl));
1351 if (!proxy) return E_OUTOFMEMORY;
1352 proxy->asmstubs=HeapAlloc(GetProcessHeap(),0,sizeof(TMAsmProxy)*nroffuncs);
1354 assert(sizeof(TMAsmProxy) == 12);
1356 proxy->lpvtbl = HeapAlloc(GetProcessHeap(),0,sizeof(LPBYTE)*nroffuncs);
1357 for (i=0;i<nroffuncs;i++) {
1359 TMAsmProxy *xasm = proxy->asmstubs+i;
1361 /* nrofargs without This */
1363 case 0: nrofargs = 2;
1365 case 1: case 2: nrofargs = 0;
1369 hres = _get_funcdesc(tinfo,i,&fdesc,NULL,NULL);
1371 FIXME("GetFuncDesc %lx should not fail here.\n",hres);
1374 /* some args take more than 4 byte on the stack */
1376 for (j=0;j<fdesc->cParams;j++)
1377 nrofargs += _argsize(fdesc->lprgelemdescParam[j].tdesc.vt);
1379 if (fdesc->callconv != CC_STDCALL) {
1380 ERR("calling convention is not stdcall????\n");
1386 /* popl %eax - return ptr
1393 * arg3 arg2 arg1 <method> <returnptr>
1395 xasm->popleax = 0x58;
1396 xasm->pushlval = 0x6a;
1398 xasm->pushleax = 0x50;
1399 xasm->lcall = 0xe8; /* relative jump */
1400 xasm->xcall = (DWORD)xCall;
1401 xasm->xcall -= (DWORD)&(xasm->lret);
1403 xasm->bytestopop= (nrofargs+2)*4; /* pop args, This, iMethod */
1404 proxy->lpvtbl[i] = (DWORD)xasm;
1406 proxy->lpvtbl2 = &tmproxyvtable;
1408 proxy->tinfo = tinfo;
1409 memcpy(&proxy->iid,riid,sizeof(*riid));
1410 *ppv = (LPVOID)proxy;
1411 *ppProxy = (IRpcProxyBuffer *)&(proxy->lpvtbl2);
1415 typedef struct _TMStubImpl {
1416 ICOM_VTABLE(IRpcStubBuffer) *lpvtbl;
1424 static HRESULT WINAPI
1425 TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface, REFIID riid, LPVOID *ppv) {
1426 if (IsEqualIID(riid,&IID_IRpcStubBuffer)||IsEqualIID(riid,&IID_IUnknown)){
1427 *ppv = (LPVOID)iface;
1428 IRpcStubBuffer_AddRef(iface);
1431 FIXME("%s, not supported IID.\n",debugstr_guid(riid));
1432 return E_NOINTERFACE;
1436 TMStubImpl_AddRef(LPRPCSTUBBUFFER iface) {
1437 ICOM_THIS(TMStubImpl,iface);
1444 TMStubImpl_Release(LPRPCSTUBBUFFER iface) {
1445 ICOM_THIS(TMStubImpl,iface);
1450 HeapFree(GetProcessHeap(),0,This);
1454 static HRESULT WINAPI
1455 TMStubImpl_Connect(LPRPCSTUBBUFFER iface, LPUNKNOWN pUnkServer) {
1456 ICOM_THIS(TMStubImpl,iface);
1458 IUnknown_AddRef(pUnkServer);
1459 This->pUnk = pUnkServer;
1464 TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface) {
1465 ICOM_THIS(TMStubImpl,iface);
1467 IUnknown_Release(This->pUnk);
1472 static HRESULT WINAPI
1474 LPRPCSTUBBUFFER iface, RPCOLEMESSAGE* xmsg,IRpcChannelBuffer*rpcchanbuf
1478 ICOM_THIS(TMStubImpl,iface);
1480 DWORD *args, res, *xargs, nrofargs;
1485 memset(&buf,0,sizeof(buf));
1486 buf.size = xmsg->cbBuffer;
1487 buf.base = xmsg->Buffer;
1489 buf.iid = IID_IUnknown;
1492 if (xmsg->iMethod == 0) { /* QI */
1494 /* in: IID, out: <iface> */
1496 xbuf_get(&buf,(LPBYTE)&xiid,sizeof(xiid));
1498 hres = _marshal_interface(&buf,&xiid,This->pUnk);
1499 xmsg->Buffer = buf.base; /* Might have been reallocated */
1500 xmsg->cbBuffer = buf.size;
1503 hres = _get_funcdesc(This->tinfo,xmsg->iMethod,&fdesc,NULL,NULL);
1505 FIXME("GetFuncDesc on method %ld failed with %lx\n",xmsg->iMethod,hres);
1508 /* Need them for hack below */
1509 memset(names,0,sizeof(names));
1510 ITypeInfo_GetNames(This->tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
1511 if (nrofnames > sizeof(names)/sizeof(names[0])) {
1512 ERR("Need more names!\n");
1515 /*dump_FUNCDESC(fdesc);*/
1517 for (i=0;i<fdesc->cParams;i++)
1518 nrofargs += _argsize(fdesc->lprgelemdescParam[i].tdesc.vt);
1519 args = HeapAlloc(GetProcessHeap(),0,(nrofargs+1)*sizeof(DWORD));
1520 if (!args) return E_OUTOFMEMORY;
1522 /* Allocate all stuff used by call. */
1524 for (i=0;i<fdesc->cParams;i++) {
1525 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1526 BOOL isdeserialized = FALSE;
1528 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1529 /* If the parameter is 'riid', we use it as interface IID
1530 * for a later ppvObject serialization.
1532 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1534 /* deserialize DISPPARAM */
1535 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1536 hres = deserialize_DISPPARAM_ptr(
1538 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1546 FIXME("Failed to deserialize DISPPARAM*, hres %lx\n",hres);
1549 isdeserialized = TRUE;
1551 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1552 hres = deserialize_LPVOID_ptr(
1554 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1562 isdeserialized = TRUE;
1565 if (!isdeserialized)
1566 hres = deserialize_param(
1568 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1575 xargs += _argsize(elem->tdesc.vt);
1577 FIXME("Failed to deserialize param %s, hres %lx\n",debugstr_w(names[i+1]),hres);
1581 hres = IUnknown_QueryInterface(This->pUnk,&(This->iid),(LPVOID*)&(args[0]));
1583 ERR("Does not support iface %s\n",debugstr_guid(&(This->iid)));
1587 (*((FARPROC**)args[0]))[fdesc->oVft/4],
1592 IUnknown_Release((LPUNKNOWN)args[0]);
1595 for (i=0;i<fdesc->cParams;i++) {
1596 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1597 BOOL isserialized = FALSE;
1599 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1600 /* If the parameter is 'riid', we use it as interface IID
1601 * for a later ppvObject serialization.
1603 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1605 /* DISPPARAMS* needs special serializer */
1606 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1607 hres = serialize_DISPPARAM_ptr(
1609 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1616 isserialized = TRUE;
1618 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1619 hres = serialize_LPVOID_ptr(
1621 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1629 isserialized = TRUE;
1633 hres = serialize_param(
1635 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1642 xargs += _argsize(elem->tdesc.vt);
1644 FIXME("Failed to stuballoc param, hres %lx\n",hres);
1648 /* might need to use IRpcChannelBuffer_GetBuffer ? */
1649 xmsg->cbBuffer = buf.curoff;
1650 xmsg->Buffer = buf.base;
1651 HeapFree(GetProcessHeap(),0,args);
1655 static LPRPCSTUBBUFFER WINAPI
1656 TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface, REFIID riid) {
1657 FIXME("Huh (%s)?\n",debugstr_guid(riid));
1662 TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface) {
1663 ICOM_THIS(TMStubImpl,iface);
1665 return This->ref; /*FIXME? */
1668 static HRESULT WINAPI
1669 TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface, LPVOID *ppv) {
1674 TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface, LPVOID ppv) {
1678 ICOM_VTABLE(IRpcStubBuffer) tmstubvtbl = {
1679 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1680 TMStubImpl_QueryInterface,
1684 TMStubImpl_Disconnect,
1686 TMStubImpl_IsIIDSupported,
1687 TMStubImpl_CountRefs,
1688 TMStubImpl_DebugServerQueryInterface,
1689 TMStubImpl_DebugServerRelease
1692 static HRESULT WINAPI
1693 PSFacBuf_CreateStub(
1694 LPPSFACTORYBUFFER iface, REFIID riid,IUnknown *pUnkServer,
1695 IRpcStubBuffer** ppStub
1701 TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub);
1702 hres = _get_typeinfo_for_iid(riid,&tinfo);
1704 FIXME("No typeinfo for %s?\n",debugstr_guid(riid));
1707 stub = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TMStubImpl));
1709 return E_OUTOFMEMORY;
1710 stub->lpvtbl = &tmstubvtbl;
1712 stub->tinfo = tinfo;
1713 memcpy(&(stub->iid),riid,sizeof(*riid));
1714 hres = IRpcStubBuffer_Connect((LPRPCSTUBBUFFER)stub,pUnkServer);
1715 *ppStub = (LPRPCSTUBBUFFER)stub;
1717 FIXME("Connect to pUnkServer failed?\n");
1721 static ICOM_VTABLE(IPSFactoryBuffer) psfacbufvtbl = {
1722 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1723 PSFacBuf_QueryInterface,
1726 PSFacBuf_CreateProxy,
1730 /* This is the whole PSFactoryBuffer object, just the vtableptr */
1731 static ICOM_VTABLE(IPSFactoryBuffer) *lppsfac = &psfacbufvtbl;
1733 /***********************************************************************
1734 * DllGetClassObject [OLE32.63]
1737 TypeLibFac_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
1739 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)) {
1743 return E_NOINTERFACE;