4 * Copyright 2002 Marcus Meissner
6 * The olerelay debug channel allows you to see calls marshalled by
7 * the typelib marshaller. It is not a generic COM relaying system.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #define NONAMELESSUNION
35 #define NONAMELESSSTRUCT
45 #include "wine/unicode.h"
48 #include "wine/debug.h"
51 static const WCHAR riidW[5] = {'r','i','i','d',0};
52 static const WCHAR pdispparamsW[] = {'p','d','i','s','p','p','a','r','a','m','s',0};
53 static const WCHAR ppvObjectW[] = {'p','p','v','O','b','j','e','c','t',0};
55 WINE_DEFAULT_DEBUG_CHANNEL(ole);
56 WINE_DECLARE_DEBUG_CHANNEL(olerelay);
58 #define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
60 typedef struct _marshal_state {
66 IID iid; /* HACK: for VT_VOID */
69 /* used in the olerelay code to avoid having the L"" stuff added by debugstr_w */
70 static char *relaystr(WCHAR *in) {
71 char *tmp = (char *)debugstr_w(in);
73 tmp[strlen(tmp)-1] = '\0';
78 xbuf_add(marshal_state *buf, LPBYTE stuff, DWORD size) {
79 while (buf->size - buf->curoff < size) {
82 buf->base = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,buf->base,buf->size);
86 buf->base = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,32);
92 memcpy(buf->base+buf->curoff,stuff,size);
98 xbuf_get(marshal_state *buf, LPBYTE stuff, DWORD size) {
99 if (buf->size < buf->curoff+size) return E_FAIL;
100 memcpy(stuff,buf->base+buf->curoff,size);
106 xbuf_skip(marshal_state *buf, DWORD size) {
107 if (buf->size < buf->curoff+size) return E_FAIL;
113 _unmarshal_interface(marshal_state *buf, REFIID riid, LPUNKNOWN *pUnk) {
115 ULARGE_INTEGER newpos;
116 LARGE_INTEGER seekto;
121 TRACE("...%s...\n",debugstr_guid(riid));
123 hres = xbuf_get(buf,(LPBYTE)&xsize,sizeof(xsize));
124 if (hres) return hres;
125 if (xsize == 0) return S_OK;
126 hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
128 FIXME("Stream create failed %lx\n",hres);
131 hres = IStream_Write(pStm,buf->base+buf->curoff,xsize,&res);
132 if (hres) { FIXME("stream write %lx\n",hres); return hres; }
133 memset(&seekto,0,sizeof(seekto));
134 hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
135 if (hres) { FIXME("Failed Seek %lx\n",hres); return hres;}
136 hres = CoUnmarshalInterface(pStm,riid,(LPVOID*)pUnk);
138 FIXME("Marshalling interface %s failed with %lx\n",debugstr_guid(riid),hres);
141 IStream_Release(pStm);
142 return xbuf_skip(buf,xsize);
146 _marshal_interface(marshal_state *buf, REFIID riid, LPUNKNOWN pUnk) {
151 ULARGE_INTEGER newpos;
152 LARGE_INTEGER seekto;
161 TRACE("...%s...\n",debugstr_guid(riid));
162 hres=IUnknown_QueryInterface(pUnk,riid,(LPVOID*)&newiface);
164 TRACE("%p does not support iface %s\n",pUnk,debugstr_guid(riid));
167 hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
169 FIXME("Stream create failed %lx\n",hres);
172 hres = CoMarshalInterface(pStm,riid,newiface,0,NULL,0);
173 IUnknown_Release(newiface);
175 FIXME("Marshalling interface %s failed with %lx\n",
176 debugstr_guid(riid),hres
180 hres = IStream_Stat(pStm,&ststg,0);
181 tempbuf = HeapAlloc(GetProcessHeap(), 0, ststg.cbSize.u.LowPart);
182 memset(&seekto,0,sizeof(seekto));
183 hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
184 if (hres) { FIXME("Failed Seek %lx\n",hres); goto fail;}
185 hres = IStream_Read(pStm,tempbuf,ststg.cbSize.u.LowPart,&res);
186 if (hres) { FIXME("Failed Read %lx\n",hres); goto fail;}
187 IStream_Release(pStm);
188 xsize = ststg.cbSize.u.LowPart;
189 xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
190 hres = xbuf_add(buf,tempbuf,ststg.cbSize.u.LowPart);
191 HeapFree(GetProcessHeap(),0,tempbuf);
195 xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
199 /********************* OLE Proxy/Stub Factory ********************************/
200 static HRESULT WINAPI
201 PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface, REFIID iid, LPVOID *ppv) {
202 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)||IsEqualIID(iid,&IID_IUnknown)) {
203 *ppv = (LPVOID)iface;
204 /* No ref counting, static class */
207 FIXME("(%s) unknown IID?\n",debugstr_guid(iid));
208 return E_NOINTERFACE;
211 static ULONG WINAPI PSFacBuf_AddRef(LPPSFACTORYBUFFER iface) { return 2; }
212 static ULONG WINAPI PSFacBuf_Release(LPPSFACTORYBUFFER iface) { return 1; }
215 _get_typeinfo_for_iid(REFIID riid, ITypeInfo**ti) {
218 char tlguid[200],typelibkey[300],interfacekey[300],ver[100];
221 DWORD tlguidlen, verlen, type, tlfnlen;
224 sprintf( interfacekey, "Interface\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\Typelib",
225 riid->Data1, riid->Data2, riid->Data3,
226 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
227 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7]
230 if (RegOpenKeyA(HKEY_CLASSES_ROOT,interfacekey,&ikey)) {
231 FIXME("No %s key found.\n",interfacekey);
235 tlguidlen = sizeof(tlguid);
236 if (RegQueryValueExA(ikey,NULL,NULL,&type,tlguid,&tlguidlen)) {
237 FIXME("Getting typelib guid failed.\n");
242 verlen = sizeof(ver);
243 if (RegQueryValueExA(ikey,"Version",NULL,&type,ver,&verlen)) {
244 FIXME("Could not get version value?\n");
249 sprintf(typelibkey,"Typelib\\%s\\%s\\0\\win32",tlguid,ver);
250 tlfnlen = sizeof(tlfn);
251 if (RegQueryValueA(HKEY_CLASSES_ROOT,typelibkey,tlfn,&tlfnlen)) {
252 FIXME("Could not get typelib fn?\n");
255 MultiByteToWideChar(CP_ACP, 0, tlfn, -1, tlfnW, -1);
256 hres = LoadTypeLib(tlfnW,&tl);
258 ERR("Failed to load typelib for %s, but it should be there.\n",debugstr_guid(riid));
261 hres = ITypeLib_GetTypeInfoOfGuid(tl,riid,ti);
263 ERR("typelib does not contain info for %s?\n",debugstr_guid(riid));
264 ITypeLib_Release(tl);
267 /* FIXME: do this? ITypeLib_Release(tl); */
271 /* Determine nr of functions. Since we use the toplevel interface and all
272 * inherited ones have lower numbers, we are ok to not to descent into
273 * the inheritance tree I think.
275 static int _nroffuncs(ITypeInfo *tinfo) {
282 hres = ITypeInfo_GetFuncDesc(tinfo,n,&fdesc);
285 if (fdesc->oVft/4 > max)
294 #include "pshpack1.h"
296 typedef struct _TMAsmProxy {
310 # error You need to implement stubless proxies for your architecture
313 typedef struct _TMProxyImpl {
315 IRpcProxyBufferVtbl *lpvtbl2;
318 TMAsmProxy *asmstubs;
320 IRpcChannelBuffer* chanbuf;
322 CRITICAL_SECTION crit;
325 static HRESULT WINAPI
326 TMProxyImpl_QueryInterface(LPRPCPROXYBUFFER iface, REFIID riid, LPVOID *ppv)
329 if (IsEqualIID(riid,&IID_IUnknown)||IsEqualIID(riid,&IID_IRpcProxyBuffer)) {
330 *ppv = (LPVOID)iface;
331 IRpcProxyBuffer_AddRef(iface);
334 FIXME("no interface for %s\n",debugstr_guid(riid));
335 return E_NOINTERFACE;
339 TMProxyImpl_AddRef(LPRPCPROXYBUFFER iface)
341 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
345 return InterlockedIncrement(&This->ref);
349 TMProxyImpl_Release(LPRPCPROXYBUFFER iface)
352 ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
356 refs = InterlockedDecrement(&This->ref);
359 DeleteCriticalSection(&This->crit);
360 if (This->chanbuf) IRpcChannelBuffer_Release(This->chanbuf);
361 VirtualFree(This->asmstubs, 0, MEM_RELEASE);
367 static HRESULT WINAPI
369 LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer)
371 ICOM_THIS_MULTI(TMProxyImpl, lpvtbl2, iface);
373 TRACE("(%p)\n", pRpcChannelBuffer);
375 EnterCriticalSection(&This->crit);
377 IRpcChannelBuffer_AddRef(pRpcChannelBuffer);
378 This->chanbuf = pRpcChannelBuffer;
380 LeaveCriticalSection(&This->crit);
386 TMProxyImpl_Disconnect(LPRPCPROXYBUFFER iface)
388 ICOM_THIS_MULTI(TMProxyImpl, lpvtbl2, iface);
392 EnterCriticalSection(&This->crit);
394 IRpcChannelBuffer_Release(This->chanbuf);
395 This->chanbuf = NULL;
397 LeaveCriticalSection(&This->crit);
401 static IRpcProxyBufferVtbl tmproxyvtable = {
402 TMProxyImpl_QueryInterface,
406 TMProxyImpl_Disconnect
409 /* how much space do we use on stack in DWORD steps. */
414 return sizeof(DATE)/sizeof(DWORD);
416 return (sizeof(VARIANT)+3)/sizeof(DWORD);
423 _xsize(TYPEDESC *td) {
428 return sizeof(VARIANT)+3;
431 ARRAYDESC *adesc = td->u.lpadesc;
433 for (i=0;i<adesc->cDims;i++)
434 arrsize *= adesc->rgbounds[i].cElements;
435 return arrsize*_xsize(&adesc->tdescElem);
460 TRACE("(tdesc.vt %d)\n",tdesc->vt);
463 case VT_EMPTY: /* nothing. empty variant for instance */
474 if (debugout) TRACE_(olerelay)("%lx",*arg);
476 hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
480 VARIANT *vt = (VARIANT*)arg;
481 DWORD vttype = V_VT(vt);
483 if (debugout) TRACE_(olerelay)("Vt(%ld)(",vttype);
486 hres = xbuf_add(buf,(LPBYTE)&vttype,sizeof(vttype));
487 if (hres) return hres;
489 /* need to recurse since we need to free the stuff */
490 hres = serialize_param(tinfo,writeit,debugout,dealloc,&tdesc2,&(V_I4(vt)),buf);
491 if (debugout) TRACE_(olerelay)(")");
497 TRACE_(olerelay)("%s",relaystr((BSTR)*arg));
499 TRACE_(olerelay)("<bstr NULL>");
504 hres = xbuf_add(buf,(LPBYTE)&fakelen,4);
508 DWORD *bstr = ((DWORD*)(*arg))-1;
510 hres = xbuf_add(buf,(LPBYTE)bstr,bstr[0]+4);
517 SysFreeString((BSTR)*arg);
523 if (debugout) TRACE_(olerelay)("*");
525 cookie = *arg ? 0x42424242 : 0;
526 hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
531 if (debugout) TRACE_(olerelay)("NULL");
534 hres = serialize_param(tinfo,writeit,debugout,dealloc,tdesc->u.lptdesc,(DWORD*)*arg,buf);
535 if (dealloc) HeapFree(GetProcessHeap(),0,(LPVOID)arg);
539 if (debugout) TRACE_(olerelay)("unk(0x%lx)",*arg);
541 hres = _marshal_interface(buf,&IID_IUnknown,(LPUNKNOWN)*arg);
544 if (debugout) TRACE_(olerelay)("idisp(0x%lx)",*arg);
546 hres = _marshal_interface(buf,&IID_IDispatch,(LPUNKNOWN)*arg);
549 if (debugout) TRACE_(olerelay)("<void>");
551 case VT_USERDEFINED: {
555 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
557 FIXME("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
560 ITypeInfo_GetTypeAttr(tinfo2,&tattr);
561 switch (tattr->typekind) {
563 case TKIND_INTERFACE:
565 hres=_marshal_interface(buf,&(tattr->guid),(LPUNKNOWN)arg);
569 if (debugout) TRACE_(olerelay)("{");
570 for (i=0;i<tattr->cVars;i++) {
575 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
577 FIXME("Could not get vardesc of %d\n",i);
580 /* Need them for hack below */
582 memset(names,0,sizeof(names));
583 hres = ITypeInfo_GetNames(tinfo2,vdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
584 if (nrofnames > sizeof(names)/sizeof(names[0])) {
585 ERR("Need more names!\n");
587 if (!hres && debugout)
588 TRACE_(olerelay)("%s=",relaystr(names[0]));
590 elem2 = &vdesc->elemdescVar;
591 tdesc2 = &elem2->tdesc;
592 hres = serialize_param(
598 (DWORD*)(((LPBYTE)arg)+vdesc->u.oInst),
603 if (debugout && (i<(tattr->cVars-1)))
604 TRACE_(olerelay)(",");
606 if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
607 memcpy(&(buf->iid),arg,sizeof(buf->iid));
608 if (debugout) TRACE_(olerelay)("}");
612 FIXME("Unhandled typekind %d\n",tattr->typekind);
616 ITypeInfo_Release(tinfo2);
620 ARRAYDESC *adesc = tdesc->u.lpadesc;
623 if (debugout) TRACE_(olerelay)("carr");
624 for (i=0;i<adesc->cDims;i++) {
625 if (debugout) TRACE_(olerelay)("[%ld]",adesc->rgbounds[i].cElements);
626 arrsize *= adesc->rgbounds[i].cElements;
628 if (debugout) TRACE_(olerelay)("[");
629 for (i=0;i<arrsize;i++) {
630 hres = serialize_param(tinfo, writeit, debugout, dealloc, &adesc->tdescElem, (DWORD*)((LPBYTE)arg+i*_xsize(&adesc->tdescElem)), buf);
633 if (debugout && (i<arrsize-1)) TRACE_(olerelay)(",");
635 if (debugout) TRACE_(olerelay)("]");
639 ERR("Unhandled marshal type %d.\n",tdesc->vt);
645 serialize_LPVOID_ptr(
657 if ((tdesc->vt != VT_PTR) ||
658 (tdesc->u.lptdesc->vt != VT_PTR) ||
659 (tdesc->u.lptdesc->u.lptdesc->vt != VT_VOID)
661 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
664 cookie = (*arg) ? 0x42424242: 0x0;
666 hres = xbuf_add(buf, (LPVOID)&cookie, sizeof(cookie));
671 if (debugout) TRACE_(olerelay)("<lpvoid NULL>");
675 TRACE_(olerelay)("ppv(%p)",*(LPUNKNOWN*)*arg);
677 hres = _marshal_interface(buf,&(buf->iid),*(LPUNKNOWN*)*arg);
682 HeapFree(GetProcessHeap(),0,(LPVOID)*arg);
687 serialize_DISPPARAM_ptr(
701 if ((tdesc->vt != VT_PTR) || (tdesc->u.lptdesc->vt != VT_USERDEFINED)) {
702 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
706 cookie = *arg ? 0x42424242 : 0x0;
708 hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
713 if (debugout) TRACE_(olerelay)("<DISPPARAMS NULL>");
716 disp = (DISPPARAMS*)*arg;
718 hres = xbuf_add(buf,(LPBYTE)&disp->cArgs,sizeof(disp->cArgs));
722 if (debugout) TRACE_(olerelay)("D{");
723 for (i=0;i<disp->cArgs;i++) {
726 vtdesc.vt = VT_VARIANT;
733 (DWORD*)(disp->rgvarg+i),
736 if (debugout && (i<disp->cArgs-1))
737 TRACE_(olerelay)(",");
740 HeapFree(GetProcessHeap(),0,disp->rgvarg);
742 hres = xbuf_add(buf,(LPBYTE)&disp->cNamedArgs,sizeof(disp->cNamedArgs));
746 if (debugout) TRACE_(olerelay)("}{");
747 for (i=0;i<disp->cNamedArgs;i++) {
757 (DWORD*)(disp->rgdispidNamedArgs+i),
760 if (debugout && (i<disp->cNamedArgs-1))
761 TRACE_(olerelay)(",");
763 if (debugout) TRACE_(olerelay)("}");
765 HeapFree(GetProcessHeap(),0,disp->rgdispidNamedArgs);
766 HeapFree(GetProcessHeap(),0,disp);
783 TRACE("vt %d at %p\n",tdesc->vt,arg);
788 if (debugout) TRACE_(olerelay)("<empty>");
791 if (debugout) TRACE_(olerelay)("<null>");
794 VARIANT *vt = (VARIANT*)arg;
799 hres = xbuf_get(buf,(LPBYTE)&vttype,sizeof(vttype));
801 FIXME("vt type not read?\n");
804 memset(&tdesc2,0,sizeof(tdesc2));
807 if (debugout) TRACE_(olerelay)("Vt(%ld)(",vttype);
808 hres = deserialize_param(tinfo, readit, debugout, alloc, &tdesc2, &(V_I4(vt)), buf);
809 TRACE_(olerelay)(")");
817 case VT_BOOL: case VT_I4: case VT_UI4: case VT_UINT: case VT_R4:
821 hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
822 if (hres) FIXME("Failed to read integer 4 byte\n");
824 if (debugout) TRACE_(olerelay)("%lx",*arg);
831 hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
833 FIXME("failed to read bstr klen\n");
838 if (debugout) TRACE_(olerelay)("<bstr NULL>");
840 str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len+sizeof(WCHAR));
841 hres = xbuf_get(buf,(LPBYTE)str,len);
843 FIXME("Failed to read BSTR.\n");
846 *arg = (DWORD)SysAllocStringLen(str,len);
847 if (debugout) TRACE_(olerelay)("%s",relaystr(str));
848 HeapFree(GetProcessHeap(),0,str);
859 derefhere = (tdesc->u.lptdesc->vt != VT_USERDEFINED);
862 hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
864 FIXME("Failed to load pointer cookie.\n");
867 if (cookie != 0x42424242) {
868 if (debugout) TRACE_(olerelay)("NULL");
872 if (debugout) TRACE_(olerelay)("*");
876 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,_xsize(tdesc->u.lptdesc));
879 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, (LPDWORD)*arg, buf);
881 return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, arg, buf);
884 /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
886 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
889 hres = _unmarshal_interface(buf,&IID_IUnknown,(LPUNKNOWN*)arg);
891 TRACE_(olerelay)("unk(%p)",arg);
896 hres = _unmarshal_interface(buf,&IID_IDispatch,(LPUNKNOWN*)arg);
898 TRACE_(olerelay)("idisp(%p)",arg);
901 if (debugout) TRACE_(olerelay)("<void>");
903 case VT_USERDEFINED: {
907 hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
909 FIXME("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
912 hres = ITypeInfo_GetTypeAttr(tinfo2,&tattr);
914 FIXME("Could not get typeattr in VT_USERDEFINED.\n");
917 *arg = (DWORD)HeapAlloc(GetProcessHeap(),0,tattr->cbSizeInstance);
918 switch (tattr->typekind) {
920 case TKIND_INTERFACE:
922 hres = _unmarshal_interface(buf,&(tattr->guid),(LPUNKNOWN*)arg);
927 if (debugout) TRACE_(olerelay)("{");
928 for (i=0;i<tattr->cVars;i++) {
931 hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
933 FIXME("Could not get vardesc of %d\n",i);
936 hres = deserialize_param(
941 &vdesc->elemdescVar.tdesc,
942 (DWORD*)(((LPBYTE)*arg)+vdesc->u.oInst),
945 if (debugout && (i<tattr->cVars-1)) TRACE_(olerelay)(",");
947 if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
948 memcpy(&(buf->iid),(LPBYTE)*arg,sizeof(buf->iid));
949 if (debugout) TRACE_(olerelay)("}");
953 ERR("Unhandled typekind %d\n",tattr->typekind);
959 FIXME("failed to stuballoc in TKIND_RECORD.\n");
960 ITypeInfo_Release(tinfo2);
964 /* arg is pointing to the start of the array. */
965 ARRAYDESC *adesc = tdesc->u.lpadesc;
968 if (adesc->cDims > 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
969 for (i=0;i<adesc->cDims;i++)
970 arrsize *= adesc->rgbounds[i].cElements;
971 for (i=0;i<arrsize;i++)
978 (DWORD*)((LPBYTE)(arg)+i*_xsize(&adesc->tdescElem)),
984 ERR("No handler for VT type %d!\n",tdesc->vt);
991 deserialize_LPVOID_ptr(
1003 if ((tdesc->vt != VT_PTR) ||
1004 (tdesc->u.lptdesc->vt != VT_PTR) ||
1005 (tdesc->u.lptdesc->u.lptdesc->vt != VT_VOID)
1007 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
1011 *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(LPVOID));
1013 hres = xbuf_get(buf, (LPVOID)&cookie, sizeof(cookie));
1016 if (cookie != 0x42424242) {
1018 if (debugout) TRACE_(olerelay)("<lpvoid NULL>");
1023 hres = _unmarshal_interface(buf,&buf->iid,(LPUNKNOWN*)*arg);
1027 if (debugout) TRACE_(olerelay)("ppv(%p)",(LPVOID)*arg);
1032 deserialize_DISPPARAM_ptr(
1046 if ((tdesc->vt != VT_PTR) || (tdesc->u.lptdesc->vt != VT_USERDEFINED)) {
1047 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
1051 hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
1056 if (debugout) TRACE_(olerelay)("<DISPPARAMS NULL>");
1061 *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPPARAMS));
1062 disps = (DISPPARAMS*)*arg;
1065 hres = xbuf_get(buf, (LPBYTE)&disps->cArgs, sizeof(disps->cArgs));
1069 disps->rgvarg = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(VARIANT)*disps->cArgs);
1070 if (debugout) TRACE_(olerelay)("D{");
1071 for (i=0; i< disps->cArgs; i++) {
1074 vdesc.vt = VT_VARIANT;
1075 hres = deserialize_param(
1081 (DWORD*)(disps->rgvarg+i),
1085 if (debugout) TRACE_(olerelay)("}{");
1086 hres = xbuf_get(buf, (LPBYTE)&disps->cNamedArgs, sizeof(disps->cNamedArgs));
1089 if (disps->cNamedArgs) {
1091 disps->rgdispidNamedArgs = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPID)*disps->cNamedArgs);
1092 for (i=0; i< disps->cNamedArgs; i++) {
1096 hres = deserialize_param(
1102 (DWORD*)(disps->rgdispidNamedArgs+i),
1105 if (debugout && i<(disps->cNamedArgs-1)) TRACE_(olerelay)(",");
1108 if (debugout) TRACE_(olerelay)("}");
1112 /* Searches function, also in inherited interfaces */
1115 ITypeInfo *tinfo, int iMethod, FUNCDESC **fdesc, BSTR *iname, BSTR *fname)
1120 if (fname) *fname = NULL;
1121 if (iname) *iname = NULL;
1124 hres = ITypeInfo_GetFuncDesc(tinfo, i, fdesc);
1130 hres = ITypeInfo_GetTypeAttr(tinfo, &attr);
1132 FIXME("GetTypeAttr failed with %lx\n",hres);
1135 /* Not found, so look in inherited ifaces. */
1136 for (j=0;j<attr->cImplTypes;j++) {
1137 hres = ITypeInfo_GetRefTypeOfImplType(tinfo, j, &href);
1139 FIXME("Did not find a reftype for interface offset %d?\n",j);
1142 hres = ITypeInfo_GetRefTypeInfo(tinfo, href, &tinfo2);
1144 FIXME("Did not find a typeinfo for reftype %ld?\n",href);
1147 hres = _get_funcdesc(tinfo2,iMethod,fdesc,iname,fname);
1148 ITypeInfo_Release(tinfo2);
1149 if (!hres) return S_OK;
1153 if (((*fdesc)->oVft/4) == iMethod) {
1155 ITypeInfo_GetDocumentation(tinfo,(*fdesc)->memid,fname,NULL,NULL,NULL);
1157 ITypeInfo_GetDocumentation(tinfo,-1,iname,NULL,NULL,NULL);
1166 xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */)
1168 DWORD *args = ((DWORD*)&tpinfo)+1, *xargs;
1171 int i, relaydeb = TRACE_ON(olerelay);
1179 EnterCriticalSection(&tpinfo->crit);
1181 hres = _get_funcdesc(tpinfo->tinfo,method,&fdesc,&iname,&fname);
1183 ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method);
1184 LeaveCriticalSection(&tpinfo->crit);
1189 TRACE_(olerelay)("->");
1191 TRACE_(olerelay)("%s:",relaystr(iname));
1193 TRACE_(olerelay)("%s(%d)",relaystr(fname),method);
1195 TRACE_(olerelay)("%d",method);
1196 TRACE_(olerelay)("(");
1197 if (iname) SysFreeString(iname);
1198 if (fname) SysFreeString(fname);
1200 /* Need them for hack below */
1201 memset(names,0,sizeof(names));
1202 if (ITypeInfo_GetNames(tpinfo->tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames))
1204 if (nrofnames > sizeof(names)/sizeof(names[0]))
1205 ERR("Need more names!\n");
1207 memset(&buf,0,sizeof(buf));
1208 buf.iid = IID_IUnknown;
1210 xbuf_add(&buf,(LPBYTE)args[0],sizeof(IID));
1211 if (relaydeb) TRACE_(olerelay)("riid=%s,[out]",debugstr_guid((REFIID)args[0]));
1214 for (i=0;i<fdesc->cParams;i++) {
1215 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1216 BOOL isserialized = FALSE;
1218 if (i) TRACE_(olerelay)(",");
1219 if (i+1<nrofnames && names[i+1])
1220 TRACE_(olerelay)("%s=",relaystr(names[i+1]));
1222 /* No need to marshal other data than FIN */
1223 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN)) {
1224 xargs+=_argsize(elem->tdesc.vt);
1225 if (relaydeb) TRACE_(olerelay)("[out]");
1228 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1229 /* If the parameter is 'riid', we use it as interface IID
1230 * for a later ppvObject serialization.
1232 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1234 /* DISPPARAMS* needs special serializer */
1235 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1236 hres = serialize_DISPPARAM_ptr(
1238 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1245 isserialized = TRUE;
1247 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1248 hres = serialize_LPVOID_ptr(
1250 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1258 isserialized = TRUE;
1262 hres = serialize_param(
1264 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1273 FIXME("Failed to serialize param, hres %lx\n",hres);
1276 xargs+=_argsize(elem->tdesc.vt);
1279 if (relaydeb) TRACE_(olerelay)(")");
1280 memset(&msg,0,sizeof(msg));
1281 msg.cbBuffer = buf.curoff;
1282 msg.iMethod = method;
1283 hres = IRpcChannelBuffer_GetBuffer(tpinfo->chanbuf,&msg,&(tpinfo->iid));
1285 FIXME("RpcChannelBuffer GetBuffer failed, %lx\n",hres);
1286 LeaveCriticalSection(&tpinfo->crit);
1289 memcpy(msg.Buffer,buf.base,buf.curoff);
1290 if (relaydeb) TRACE_(olerelay)("\n");
1291 hres = IRpcChannelBuffer_SendReceive(tpinfo->chanbuf,&msg,&status);
1293 FIXME("RpcChannelBuffer SendReceive failed, %lx\n",hres);
1294 LeaveCriticalSection(&tpinfo->crit);
1298 if (relaydeb) TRACE_(olerelay)(" = %08lx (",status);
1300 buf.base = HeapReAlloc(GetProcessHeap(),0,buf.base,msg.cbBuffer);
1302 buf.base = HeapAlloc(GetProcessHeap(),0,msg.cbBuffer);
1303 buf.size = msg.cbBuffer;
1304 memcpy(buf.base,msg.Buffer,buf.size);
1307 _unmarshal_interface(&buf,(REFIID)args[0],(LPUNKNOWN*)args[1]);
1308 if (relaydeb) TRACE_(olerelay)("[in],%p",*((DWORD**)args[1]));
1311 for (i=0;i<fdesc->cParams;i++) {
1312 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1313 BOOL isdeserialized = FALSE;
1316 if (i) TRACE_(olerelay)(",");
1317 if (i+1<nrofnames && names[i+1]) TRACE_(olerelay)("%s=",relaystr(names[i+1]));
1319 /* No need to marshal other data than FOUT I think */
1320 if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT)) {
1321 xargs += _argsize(elem->tdesc.vt);
1322 if (relaydeb) TRACE_(olerelay)("[in]");
1325 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1326 /* If the parameter is 'riid', we use it as interface IID
1327 * for a later ppvObject serialization.
1329 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1331 /* deserialize DISPPARAM */
1332 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1333 hres = deserialize_DISPPARAM_ptr(
1335 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1343 FIXME("Failed to deserialize DISPPARAM*, hres %lx\n",hres);
1346 isdeserialized = TRUE;
1348 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1349 hres = deserialize_LPVOID_ptr(
1351 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1359 isdeserialized = TRUE;
1362 if (!isdeserialized)
1363 hres = deserialize_param(
1365 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1373 FIXME("Failed to unmarshall param, hres %lx\n",hres);
1376 xargs += _argsize(elem->tdesc.vt);
1379 if (relaydeb) TRACE_(olerelay)(")\n");
1380 HeapFree(GetProcessHeap(),0,buf.base);
1382 LeaveCriticalSection(&tpinfo->crit);
1387 static HRESULT WINAPI
1388 PSFacBuf_CreateProxy(
1389 LPPSFACTORYBUFFER iface, IUnknown* pUnkOuter, REFIID riid,
1390 IRpcProxyBuffer **ppProxy, LPVOID *ppv)
1398 TRACE("(...%s...)\n",debugstr_guid(riid));
1399 hres = _get_typeinfo_for_iid(riid,&tinfo);
1401 FIXME("No typeinfo for %s?\n",debugstr_guid(riid));
1404 nroffuncs = _nroffuncs(tinfo);
1405 proxy = CoTaskMemAlloc(sizeof(TMProxyImpl));
1406 if (!proxy) return E_OUTOFMEMORY;
1408 assert(sizeof(TMAsmProxy) == 12);
1410 proxy->asmstubs = VirtualAlloc(NULL, sizeof(TMAsmProxy) * nroffuncs, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
1411 if (!proxy->asmstubs) {
1412 ERR("Could not commit pages for proxy thunks\n");
1413 CoTaskMemFree(proxy);
1414 return E_OUTOFMEMORY;
1417 InitializeCriticalSection(&proxy->crit);
1419 proxy->lpvtbl = HeapAlloc(GetProcessHeap(),0,sizeof(LPBYTE)*nroffuncs);
1420 for (i=0;i<nroffuncs;i++) {
1422 TMAsmProxy *xasm = proxy->asmstubs+i;
1424 /* nrofargs without This */
1426 case 0: nrofargs = 2;
1428 case 1: case 2: nrofargs = 0;
1432 hres = _get_funcdesc(tinfo,i,&fdesc,NULL,NULL);
1434 FIXME("GetFuncDesc %lx should not fail here.\n",hres);
1437 /* some args take more than 4 byte on the stack */
1439 for (j=0;j<fdesc->cParams;j++)
1440 nrofargs += _argsize(fdesc->lprgelemdescParam[j].tdesc.vt);
1442 if (fdesc->callconv != CC_STDCALL) {
1443 ERR("calling convention is not stdcall????\n");
1449 /* popl %eax - return ptr
1456 * arg3 arg2 arg1 <method> <returnptr>
1458 xasm->popleax = 0x58;
1459 xasm->pushlval = 0x6a;
1461 xasm->pushleax = 0x50;
1462 xasm->lcall = 0xe8; /* relative jump */
1463 xasm->xcall = (DWORD)xCall;
1464 xasm->xcall -= (DWORD)&(xasm->lret);
1466 xasm->bytestopop= (nrofargs+2)*4; /* pop args, This, iMethod */
1467 proxy->lpvtbl[i] = xasm;
1469 proxy->lpvtbl2 = &tmproxyvtable;
1470 /* 1 reference for the proxy and 1 for the object */
1472 proxy->tinfo = tinfo;
1473 memcpy(&proxy->iid,riid,sizeof(*riid));
1474 *ppv = (LPVOID)proxy;
1475 *ppProxy = (IRpcProxyBuffer *)&(proxy->lpvtbl2);
1479 typedef struct _TMStubImpl {
1480 IRpcStubBufferVtbl *lpvtbl;
1488 static HRESULT WINAPI
1489 TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface, REFIID riid, LPVOID *ppv)
1491 if (IsEqualIID(riid,&IID_IRpcStubBuffer)||IsEqualIID(riid,&IID_IUnknown)){
1492 *ppv = (LPVOID)iface;
1493 IRpcStubBuffer_AddRef(iface);
1496 FIXME("%s, not supported IID.\n",debugstr_guid(riid));
1497 return E_NOINTERFACE;
1501 TMStubImpl_AddRef(LPRPCSTUBBUFFER iface)
1503 TMStubImpl *This = (TMStubImpl *)iface;
1505 TRACE("(%p) before %lu\n", This, This->ref);
1507 return InterlockedIncrement(&This->ref);
1511 TMStubImpl_Release(LPRPCSTUBBUFFER iface)
1514 TMStubImpl *This = (TMStubImpl *)iface;
1516 TRACE("(%p) after %lu\n", This, This->ref-1);
1518 refs = InterlockedDecrement(&This->ref);
1521 IRpcStubBuffer_Disconnect(iface);
1522 CoTaskMemFree(This);
1527 static HRESULT WINAPI
1528 TMStubImpl_Connect(LPRPCSTUBBUFFER iface, LPUNKNOWN pUnkServer)
1530 TMStubImpl *This = (TMStubImpl *)iface;
1532 TRACE("(%p)->(%p)\n", This, pUnkServer);
1534 IUnknown_AddRef(pUnkServer);
1535 This->pUnk = pUnkServer;
1540 TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface)
1542 TMStubImpl *This = (TMStubImpl *)iface;
1544 TRACE("(%p)->()\n", This);
1546 IUnknown_Release(This->pUnk);
1551 static HRESULT WINAPI
1553 LPRPCSTUBBUFFER iface, RPCOLEMESSAGE* xmsg,IRpcChannelBuffer*rpcchanbuf)
1557 TMStubImpl *This = (TMStubImpl *)iface;
1559 DWORD *args, res, *xargs, nrofargs;
1564 memset(&buf,0,sizeof(buf));
1565 buf.size = xmsg->cbBuffer;
1566 buf.base = xmsg->Buffer;
1568 buf.iid = IID_IUnknown;
1571 if (xmsg->iMethod == 0) { /* QI */
1573 /* in: IID, out: <iface> */
1575 xbuf_get(&buf,(LPBYTE)&xiid,sizeof(xiid));
1577 hres = _marshal_interface(&buf,&xiid,This->pUnk);
1578 xmsg->Buffer = buf.base; /* Might have been reallocated */
1579 xmsg->cbBuffer = buf.size;
1582 hres = _get_funcdesc(This->tinfo,xmsg->iMethod,&fdesc,NULL,NULL);
1584 FIXME("GetFuncDesc on method %ld failed with %lx\n",xmsg->iMethod,hres);
1587 /* Need them for hack below */
1588 memset(names,0,sizeof(names));
1589 ITypeInfo_GetNames(This->tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
1590 if (nrofnames > sizeof(names)/sizeof(names[0])) {
1591 ERR("Need more names!\n");
1594 /*dump_FUNCDESC(fdesc);*/
1596 for (i=0;i<fdesc->cParams;i++)
1597 nrofargs += _argsize(fdesc->lprgelemdescParam[i].tdesc.vt);
1598 args = HeapAlloc(GetProcessHeap(),0,(nrofargs+1)*sizeof(DWORD));
1599 if (!args) return E_OUTOFMEMORY;
1601 /* Allocate all stuff used by call. */
1603 for (i=0;i<fdesc->cParams;i++) {
1604 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1605 BOOL isdeserialized = FALSE;
1607 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1608 /* If the parameter is 'riid', we use it as interface IID
1609 * for a later ppvObject serialization.
1611 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1613 /* deserialize DISPPARAM */
1614 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1615 hres = deserialize_DISPPARAM_ptr(
1617 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1625 FIXME("Failed to deserialize DISPPARAM*, hres %lx\n",hres);
1628 isdeserialized = TRUE;
1630 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1631 hres = deserialize_LPVOID_ptr(
1633 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1641 isdeserialized = TRUE;
1644 if (!isdeserialized)
1645 hres = deserialize_param(
1647 elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
1654 xargs += _argsize(elem->tdesc.vt);
1656 FIXME("Failed to deserialize param %s, hres %lx\n",relaystr(names[i+1]),hres);
1660 hres = IUnknown_QueryInterface(This->pUnk,&(This->iid),(LPVOID*)&(args[0]));
1662 ERR("Does not support iface %s\n",debugstr_guid(&(This->iid)));
1666 (*((FARPROC**)args[0]))[fdesc->oVft/4],
1671 IUnknown_Release((LPUNKNOWN)args[0]);
1674 for (i=0;i<fdesc->cParams;i++) {
1675 ELEMDESC *elem = fdesc->lprgelemdescParam+i;
1676 BOOL isserialized = FALSE;
1678 if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
1679 /* If the parameter is 'riid', we use it as interface IID
1680 * for a later ppvObject serialization.
1682 buf.thisisiid = !lstrcmpW(names[i+1],riidW);
1684 /* DISPPARAMS* needs special serializer */
1685 if (!lstrcmpW(names[i+1],pdispparamsW)) {
1686 hres = serialize_DISPPARAM_ptr(
1688 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1695 isserialized = TRUE;
1697 if (!lstrcmpW(names[i+1],ppvObjectW)) {
1698 hres = serialize_LPVOID_ptr(
1700 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1708 isserialized = TRUE;
1712 hres = serialize_param(
1714 elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
1721 xargs += _argsize(elem->tdesc.vt);
1723 FIXME("Failed to stuballoc param, hres %lx\n",hres);
1727 /* might need to use IRpcChannelBuffer_GetBuffer ? */
1728 xmsg->cbBuffer = buf.curoff;
1729 xmsg->Buffer = buf.base;
1730 HeapFree(GetProcessHeap(),0,args);
1734 static LPRPCSTUBBUFFER WINAPI
1735 TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface, REFIID riid) {
1736 FIXME("Huh (%s)?\n",debugstr_guid(riid));
1741 TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface) {
1742 TMStubImpl *This = (TMStubImpl *)iface;
1744 return This->ref; /*FIXME? */
1747 static HRESULT WINAPI
1748 TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface, LPVOID *ppv) {
1753 TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface, LPVOID ppv) {
1757 IRpcStubBufferVtbl tmstubvtbl = {
1758 TMStubImpl_QueryInterface,
1762 TMStubImpl_Disconnect,
1764 TMStubImpl_IsIIDSupported,
1765 TMStubImpl_CountRefs,
1766 TMStubImpl_DebugServerQueryInterface,
1767 TMStubImpl_DebugServerRelease
1770 static HRESULT WINAPI
1771 PSFacBuf_CreateStub(
1772 LPPSFACTORYBUFFER iface, REFIID riid,IUnknown *pUnkServer,
1773 IRpcStubBuffer** ppStub
1779 TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub);
1780 hres = _get_typeinfo_for_iid(riid,&tinfo);
1782 FIXME("No typeinfo for %s?\n",debugstr_guid(riid));
1785 stub = CoTaskMemAlloc(sizeof(TMStubImpl));
1787 return E_OUTOFMEMORY;
1788 stub->lpvtbl = &tmstubvtbl;
1790 stub->tinfo = tinfo;
1791 memcpy(&(stub->iid),riid,sizeof(*riid));
1792 hres = IRpcStubBuffer_Connect((LPRPCSTUBBUFFER)stub,pUnkServer);
1793 *ppStub = (LPRPCSTUBBUFFER)stub;
1794 TRACE("IRpcStubBuffer: %p\n", stub);
1796 FIXME("Connect to pUnkServer failed?\n");
1800 static IPSFactoryBufferVtbl psfacbufvtbl = {
1801 PSFacBuf_QueryInterface,
1804 PSFacBuf_CreateProxy,
1808 /* This is the whole PSFactoryBuffer object, just the vtableptr */
1809 static IPSFactoryBufferVtbl *lppsfac = &psfacbufvtbl;
1811 /***********************************************************************
1812 * DllGetClassObject [OLE32.63]
1815 TypeLibFac_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
1817 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)) {
1821 return E_NOINTERFACE;