4 * Copyright 2002,2005 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
46 #include "wine/debug.h"
48 static const WCHAR riidW
[5] = {'r','i','i','d',0};
49 static const WCHAR pdispparamsW
[] = {'p','d','i','s','p','p','a','r','a','m','s',0};
50 static const WCHAR ppvObjectW
[] = {'p','p','v','O','b','j','e','c','t',0};
51 static const WCHAR IDispatchW
[] = { 'I','D','i','s','p','a','t','c','h',0};
52 static const WCHAR GetIDsOfNamesW
[] = { 'G','e','t','I','D','s','O','f','N','a','m','e','s',0};
54 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
55 WINE_DECLARE_DEBUG_CHANNEL(olerelay
);
57 #define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
59 typedef struct _marshal_state
{
65 IID iid
; /* HACK: for VT_VOID */
68 /* used in the olerelay code to avoid having the L"" stuff added by debugstr_w */
69 static char *relaystr(WCHAR
*in
) {
70 char *tmp
= (char *)debugstr_w(in
);
72 tmp
[strlen(tmp
)-1] = '\0';
77 xbuf_add(marshal_state
*buf
, LPBYTE stuff
, DWORD size
) {
78 while (buf
->size
- buf
->curoff
< size
) {
81 buf
->base
= HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,buf
->base
,buf
->size
);
85 buf
->base
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,32);
91 memcpy(buf
->base
+buf
->curoff
,stuff
,size
);
97 xbuf_get(marshal_state
*buf
, LPBYTE stuff
, DWORD size
) {
98 if (buf
->size
< buf
->curoff
+size
) return E_FAIL
;
99 memcpy(stuff
,buf
->base
+buf
->curoff
,size
);
105 xbuf_skip(marshal_state
*buf
, DWORD size
) {
106 if (buf
->size
< buf
->curoff
+size
) return E_FAIL
;
112 _unmarshal_interface(marshal_state
*buf
, REFIID riid
, LPUNKNOWN
*pUnk
) {
114 ULARGE_INTEGER newpos
;
115 LARGE_INTEGER seekto
;
120 TRACE("...%s...\n",debugstr_guid(riid
));
123 hres
= xbuf_get(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
125 ERR("xbuf_get failed\n");
129 if (xsize
== 0) return S_OK
;
131 hres
= CreateStreamOnHGlobal(0,TRUE
,&pStm
);
133 ERR("Stream create failed %lx\n",hres
);
137 hres
= IStream_Write(pStm
,buf
->base
+buf
->curoff
,xsize
,&res
);
139 ERR("stream write %lx\n",hres
);
143 memset(&seekto
,0,sizeof(seekto
));
144 hres
= IStream_Seek(pStm
,seekto
,SEEK_SET
,&newpos
);
146 ERR("Failed Seek %lx\n",hres
);
150 hres
= CoUnmarshalInterface(pStm
,riid
,(LPVOID
*)pUnk
);
152 ERR("Unmarshalling interface %s failed with %lx\n",debugstr_guid(riid
),hres
);
156 IStream_Release(pStm
);
157 return xbuf_skip(buf
,xsize
);
161 _marshal_interface(marshal_state
*buf
, REFIID riid
, LPUNKNOWN pUnk
) {
162 LPBYTE tempbuf
= NULL
;
163 IStream
*pStm
= NULL
;
165 ULARGE_INTEGER newpos
;
166 LARGE_INTEGER seekto
;
172 /* this is valid, if for instance we serialize
173 * a VT_DISPATCH with NULL ptr which apparently
174 * can happen. S_OK to make sure we continue
177 ERR("pUnk is NULL?\n");
179 return xbuf_add(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
184 TRACE("...%s...\n",debugstr_guid(riid
));
186 hres
= CreateStreamOnHGlobal(0,TRUE
,&pStm
);
188 ERR("Stream create failed %lx\n",hres
);
192 hres
= CoMarshalInterface(pStm
,riid
,pUnk
,0,NULL
,0);
194 ERR("Marshalling interface %s failed with %lx\n", debugstr_guid(riid
), hres
);
198 hres
= IStream_Stat(pStm
,&ststg
,0);
200 ERR("Stream stat failed\n");
204 tempbuf
= HeapAlloc(GetProcessHeap(), 0, ststg
.cbSize
.u
.LowPart
);
205 memset(&seekto
,0,sizeof(seekto
));
206 hres
= IStream_Seek(pStm
,seekto
,SEEK_SET
,&newpos
);
208 ERR("Failed Seek %lx\n",hres
);
212 hres
= IStream_Read(pStm
,tempbuf
,ststg
.cbSize
.u
.LowPart
,&res
);
214 ERR("Failed Read %lx\n",hres
);
218 xsize
= ststg
.cbSize
.u
.LowPart
;
219 xbuf_add(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
220 hres
= xbuf_add(buf
,tempbuf
,ststg
.cbSize
.u
.LowPart
);
222 HeapFree(GetProcessHeap(),0,tempbuf
);
223 IStream_Release(pStm
);
229 xbuf_add(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
230 if (pStm
) IUnknown_Release(pStm
);
231 HeapFree(GetProcessHeap(), 0, tempbuf
);
235 /********************* OLE Proxy/Stub Factory ********************************/
236 static HRESULT WINAPI
237 PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface
, REFIID iid
, LPVOID
*ppv
) {
238 if (IsEqualIID(iid
,&IID_IPSFactoryBuffer
)||IsEqualIID(iid
,&IID_IUnknown
)) {
239 *ppv
= (LPVOID
)iface
;
240 /* No ref counting, static class */
243 FIXME("(%s) unknown IID?\n",debugstr_guid(iid
));
244 return E_NOINTERFACE
;
247 static ULONG WINAPI
PSFacBuf_AddRef(LPPSFACTORYBUFFER iface
) { return 2; }
248 static ULONG WINAPI
PSFacBuf_Release(LPPSFACTORYBUFFER iface
) { return 1; }
251 _get_typeinfo_for_iid(REFIID riid
, ITypeInfo
**ti
) {
254 char tlguid
[200],typelibkey
[300],interfacekey
[300],ver
[100];
257 DWORD tlguidlen
, verlen
, type
;
261 sprintf( interfacekey
, "Interface\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\Typelib",
262 riid
->Data1
, riid
->Data2
, riid
->Data3
,
263 riid
->Data4
[0], riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3],
264 riid
->Data4
[4], riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]
267 if (RegOpenKeyA(HKEY_CLASSES_ROOT
,interfacekey
,&ikey
)) {
268 ERR("No %s key found.\n",interfacekey
);
272 tlguidlen
= sizeof(tlguid
);
273 if (RegQueryValueExA(ikey
,NULL
,NULL
,&type
,(LPBYTE
)tlguid
,&tlguidlen
)) {
274 ERR("Getting typelib guid failed.\n");
279 verlen
= sizeof(ver
);
280 if (RegQueryValueExA(ikey
,"Version",NULL
,&type
,(LPBYTE
)ver
,&verlen
)) {
281 ERR("Could not get version value?\n");
286 sprintf(typelibkey
,"Typelib\\%s\\%s\\0\\win32",tlguid
,ver
);
287 tlfnlen
= sizeof(tlfn
);
288 if (RegQueryValueA(HKEY_CLASSES_ROOT
,typelibkey
,tlfn
,&tlfnlen
)) {
289 ERR("Could not get typelib fn?\n");
292 MultiByteToWideChar(CP_ACP
, 0, tlfn
, -1, tlfnW
, -1);
293 hres
= LoadTypeLib(tlfnW
,&tl
);
295 ERR("Failed to load typelib for %s, but it should be there.\n",debugstr_guid(riid
));
298 hres
= ITypeLib_GetTypeInfoOfGuid(tl
,riid
,ti
);
300 ERR("typelib does not contain info for %s?\n",debugstr_guid(riid
));
301 ITypeLib_Release(tl
);
304 /* FIXME: do this? ITypeLib_Release(tl); */
308 /* Determine nr of functions. Since we use the toplevel interface and all
309 * inherited ones have lower numbers, we are ok to not to descent into
310 * the inheritance tree I think.
312 static int _nroffuncs(ITypeInfo
*tinfo
) {
319 hres
= ITypeInfo_GetFuncDesc(tinfo
,n
,&fdesc
);
322 if (fdesc
->oVft
/4 > max
)
331 #include "pshpack1.h"
333 typedef struct _TMAsmProxy
{
347 # warning You need to implement stubless proxies for your architecture
348 typedef struct _TMAsmProxy
{
352 typedef struct _TMProxyImpl
{
354 const IRpcProxyBufferVtbl
*lpvtbl2
;
357 TMAsmProxy
*asmstubs
;
359 IRpcChannelBuffer
* chanbuf
;
361 CRITICAL_SECTION crit
;
362 IUnknown
*outerunknown
;
365 static HRESULT WINAPI
366 TMProxyImpl_QueryInterface(LPRPCPROXYBUFFER iface
, REFIID riid
, LPVOID
*ppv
)
369 if (IsEqualIID(riid
,&IID_IUnknown
)||IsEqualIID(riid
,&IID_IRpcProxyBuffer
)) {
370 *ppv
= (LPVOID
)iface
;
371 IRpcProxyBuffer_AddRef(iface
);
374 FIXME("no interface for %s\n",debugstr_guid(riid
));
375 return E_NOINTERFACE
;
379 TMProxyImpl_AddRef(LPRPCPROXYBUFFER iface
)
381 ICOM_THIS_MULTI(TMProxyImpl
,lpvtbl2
,iface
);
382 ULONG refCount
= InterlockedIncrement(&This
->ref
);
384 TRACE("(%p)->(ref before=%lu)\n",This
, refCount
- 1);
390 TMProxyImpl_Release(LPRPCPROXYBUFFER iface
)
392 ICOM_THIS_MULTI(TMProxyImpl
,lpvtbl2
,iface
);
393 ULONG refCount
= InterlockedDecrement(&This
->ref
);
395 TRACE("(%p)->(ref before=%lu)\n",This
, refCount
+ 1);
399 DeleteCriticalSection(&This
->crit
);
400 if (This
->chanbuf
) IRpcChannelBuffer_Release(This
->chanbuf
);
401 VirtualFree(This
->asmstubs
, 0, MEM_RELEASE
);
407 static HRESULT WINAPI
409 LPRPCPROXYBUFFER iface
,IRpcChannelBuffer
* pRpcChannelBuffer
)
411 ICOM_THIS_MULTI(TMProxyImpl
, lpvtbl2
, iface
);
413 TRACE("(%p)\n", pRpcChannelBuffer
);
415 EnterCriticalSection(&This
->crit
);
417 IRpcChannelBuffer_AddRef(pRpcChannelBuffer
);
418 This
->chanbuf
= pRpcChannelBuffer
;
420 LeaveCriticalSection(&This
->crit
);
426 TMProxyImpl_Disconnect(LPRPCPROXYBUFFER iface
)
428 ICOM_THIS_MULTI(TMProxyImpl
, lpvtbl2
, iface
);
432 EnterCriticalSection(&This
->crit
);
434 IRpcChannelBuffer_Release(This
->chanbuf
);
435 This
->chanbuf
= NULL
;
437 LeaveCriticalSection(&This
->crit
);
441 static const IRpcProxyBufferVtbl tmproxyvtable
= {
442 TMProxyImpl_QueryInterface
,
446 TMProxyImpl_Disconnect
449 /* how much space do we use on stack in DWORD steps. */
454 return sizeof(double)/sizeof(DWORD
);
456 return sizeof(CY
)/sizeof(DWORD
);
458 return sizeof(DATE
)/sizeof(DWORD
);
460 return (sizeof(VARIANT
)+3)/sizeof(DWORD
);
467 _xsize(TYPEDESC
*td
) {
472 return sizeof(VARIANT
)+3;
475 ARRAYDESC
*adesc
= td
->u
.lpadesc
;
477 for (i
=0;i
<adesc
->cDims
;i
++)
478 arrsize
*= adesc
->rgbounds
[i
].cElements
;
479 return arrsize
*_xsize(&adesc
->tdescElem
);
504 TRACE("(tdesc.vt %d)\n",tdesc
->vt
);
507 case VT_EMPTY
: /* nothing. empty variant for instance */
516 if (debugout
) TRACE_(olerelay
)("%lx",*arg
);
518 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
523 if (debugout
) TRACE_(olerelay
)("%04lx",*arg
& 0xffff);
525 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
530 if (debugout
) TRACE_(olerelay
)("%02lx",*arg
& 0xff);
532 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
536 if (debugout
) TRACE_(olerelay
)("&0x%lx",*arg
);
538 hres
= xbuf_add(buf
,(LPBYTE
)(DWORD
*)*arg
,sizeof(DWORD
));
539 /* do not dealloc at this time */
543 VARIANT
*vt
= (VARIANT
*)arg
;
544 DWORD vttype
= V_VT(vt
);
546 if (debugout
) TRACE_(olerelay
)("Vt(%ld)(",vttype
);
549 hres
= xbuf_add(buf
,(LPBYTE
)&vttype
,sizeof(vttype
));
550 if (hres
) return hres
;
552 /* need to recurse since we need to free the stuff */
553 hres
= serialize_param(tinfo
,writeit
,debugout
,dealloc
,&tdesc2
,(DWORD
*)&(V_I4(vt
)),buf
);
554 if (debugout
) TRACE_(olerelay
)(")");
557 case VT_BSTR
|VT_BYREF
: {
558 if (debugout
) TRACE_(olerelay
)("[byref]'%s'", *(BSTR
*)*arg
? relaystr(*((BSTR
*)*arg
)) : "<bstr NULL>");
560 /* ptr to ptr to magic widestring, basically */
561 BSTR
*bstr
= (BSTR
*) *arg
;
564 /* -1 means "null string" which is equivalent to empty string */
566 hres
= xbuf_add(buf
, (LPBYTE
)&len
,sizeof(DWORD
));
567 if (hres
) return hres
;
569 len
= *((DWORD
*)*bstr
-1)/sizeof(WCHAR
);
570 hres
= xbuf_add(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
571 if (hres
) return hres
;
572 hres
= xbuf_add(buf
,(LPBYTE
)*bstr
,len
* sizeof(WCHAR
));
573 if (hres
) return hres
;
577 if (dealloc
&& arg
) {
578 BSTR
*str
= *((BSTR
**)arg
);
587 TRACE_(olerelay
)("%s",relaystr((WCHAR
*)*arg
));
589 TRACE_(olerelay
)("<bstr NULL>");
592 BSTR bstr
= (BSTR
)*arg
;
596 hres
= xbuf_add(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
597 if (hres
) return hres
;
599 len
= *((DWORD
*)bstr
-1)/sizeof(WCHAR
);
600 hres
= xbuf_add(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
601 if (hres
) return hres
;
602 hres
= xbuf_add(buf
,(LPBYTE
)bstr
,len
* sizeof(WCHAR
));
603 if (hres
) return hres
;
608 SysFreeString((BSTR
)*arg
);
613 BOOL derefhere
= TRUE
;
615 if (tdesc
->u
.lptdesc
->vt
== VT_USERDEFINED
) {
619 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.lptdesc
->u
.hreftype
,&tinfo2
);
621 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc
->u
.lptdesc
->u
.hreftype
);
624 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
625 switch (tattr
->typekind
) {
626 case TKIND_ENUM
: /* confirmed */
627 case TKIND_RECORD
: /* FIXME: mostly untested */
630 case TKIND_ALIAS
: /* FIXME: untested */
631 case TKIND_DISPATCH
: /* will be done in VT_USERDEFINED case */
632 case TKIND_INTERFACE
: /* will be done in VT_USERDEFINED case */
636 FIXME("unhandled switch cases tattr->typekind %d\n", tattr
->typekind
);
640 ITypeInfo_Release(tinfo2
);
643 if (debugout
) TRACE_(olerelay
)("*");
644 /* Write always, so the other side knows when it gets a NULL pointer.
646 cookie
= *arg
? 0x42424242 : 0;
647 hres
= xbuf_add(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
651 if (debugout
) TRACE_(olerelay
)("NULL");
654 hres
= serialize_param(tinfo
,writeit
,debugout
,dealloc
,tdesc
->u
.lptdesc
,(DWORD
*)*arg
,buf
);
655 if (derefhere
&& dealloc
) HeapFree(GetProcessHeap(),0,(LPVOID
)*arg
);
659 if (debugout
) TRACE_(olerelay
)("unk(0x%lx)",*arg
);
661 hres
= _marshal_interface(buf
,&IID_IUnknown
,(LPUNKNOWN
)*arg
);
664 if (debugout
) TRACE_(olerelay
)("idisp(0x%lx)",*arg
);
666 hres
= _marshal_interface(buf
,&IID_IDispatch
,(LPUNKNOWN
)*arg
);
669 if (debugout
) TRACE_(olerelay
)("<void>");
671 case VT_USERDEFINED
: {
675 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.hreftype
,&tinfo2
);
677 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc
->u
.hreftype
);
680 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
681 switch (tattr
->typekind
) {
683 case TKIND_INTERFACE
:
685 hres
=_marshal_interface(buf
,&(tattr
->guid
),(LPUNKNOWN
)arg
);
687 IUnknown_Release((LPUNKNOWN
)arg
);
691 if (debugout
) TRACE_(olerelay
)("{");
692 for (i
=0;i
<tattr
->cVars
;i
++) {
697 hres
= ITypeInfo2_GetVarDesc(tinfo2
, i
, &vdesc
);
699 ERR("Could not get vardesc of %d\n",i
);
702 /* Need them for hack below */
704 memset(names,0,sizeof(names));
705 hres = ITypeInfo_GetNames(tinfo2,vdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
706 if (nrofnames > sizeof(names)/sizeof(names[0])) {
707 ERR("Need more names!\n");
709 if (!hres && debugout)
710 TRACE_(olerelay)("%s=",relaystr(names[0]));
712 elem2
= &vdesc
->elemdescVar
;
713 tdesc2
= &elem2
->tdesc
;
714 hres
= serialize_param(
720 (DWORD
*)(((LPBYTE
)arg
)+vdesc
->u
.oInst
),
723 ITypeInfo_ReleaseVarDesc(tinfo2
, vdesc
);
726 if (debugout
&& (i
<(tattr
->cVars
-1)))
727 TRACE_(olerelay
)(",");
729 if (buf
->thisisiid
&& (tattr
->cbSizeInstance
==sizeof(GUID
)))
730 memcpy(&(buf
->iid
),arg
,sizeof(buf
->iid
));
731 if (debugout
) TRACE_(olerelay
)("}");
735 return serialize_param(tinfo2
,writeit
,debugout
,dealloc
,&tattr
->tdescAlias
,arg
,buf
);
738 if (debugout
) TRACE_(olerelay
)("%lx",*arg
);
740 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
743 FIXME("Unhandled typekind %d\n",tattr
->typekind
);
747 ITypeInfo_Release(tinfo2
);
751 ARRAYDESC
*adesc
= tdesc
->u
.lpadesc
;
754 if (debugout
) TRACE_(olerelay
)("carr");
755 for (i
=0;i
<adesc
->cDims
;i
++) {
756 if (debugout
) TRACE_(olerelay
)("[%ld]",adesc
->rgbounds
[i
].cElements
);
757 arrsize
*= adesc
->rgbounds
[i
].cElements
;
759 if (debugout
) TRACE_(olerelay
)("(vt %d)",adesc
->tdescElem
.vt
);
760 if (debugout
) TRACE_(olerelay
)("[");
761 for (i
=0;i
<arrsize
;i
++) {
762 hres
= serialize_param(tinfo
, writeit
, debugout
, dealloc
, &adesc
->tdescElem
, (DWORD
*)((LPBYTE
)arg
+i
*_xsize(&adesc
->tdescElem
)), buf
);
765 if (debugout
&& (i
<arrsize
-1)) TRACE_(olerelay
)(",");
767 if (debugout
) TRACE_(olerelay
)("]");
771 ERR("Unhandled marshal type %d.\n",tdesc
->vt
);
777 * HRESULT GetIDsOfNames(
778 * [in] REFIID riid, args[1]
779 * [in, size_is(cNames)] LPOLESTR *rgszNames, args[2]
780 * [in] UINT cNames, args[3]
781 * [in] LCID lcid, args[4]
782 * [out, size_is(cNames)] DISPID *rgDispId); args[5]
787 * LPOLESTR rgszNames[cNames];
788 * DWORD bytestrlen (incl 0)
789 * BYTE data[bytestrlen] (incl 0)
793 serialize_IDispatch_GetIDsOfNames(
800 DWORD cNames
= args
[2];
801 LPOLESTR
*rgszNames
= (LPOLESTR
*)args
[1];
805 if (debugout
) TRACE_(olerelay
)("riid=%s,",debugstr_guid((REFIID
)args
[0]));
806 hres
= xbuf_add(buf
, (LPBYTE
)args
[0], sizeof(IID
));
808 FIXME("serialize of IID failed.\n");
811 if (debugout
) TRACE_(olerelay
)("cNames=%ld,",cNames
);
812 hres
= xbuf_add(buf
, (LPBYTE
)&cNames
, sizeof(DWORD
));
814 FIXME("serialize of cNames failed.\n");
817 if (debugout
) TRACE_(olerelay
)("rgszNames=[");
818 for (i
=0;i
<cNames
;i
++) {
819 DWORD len
= 2*(lstrlenW(rgszNames
[i
])+1);
821 if (debugout
) TRACE_(olerelay
)("%s,",relaystr(rgszNames
[i
]));
822 hres
= xbuf_add(buf
, (LPBYTE
)&len
, sizeof(DWORD
));
824 FIXME("serialize of len failed.\n");
827 hres
= xbuf_add(buf
, (LPBYTE
)rgszNames
[i
], len
);
829 FIXME("serialize of rgszNames[i] failed.\n");
833 if (debugout
) TRACE_(olerelay
)("],lcid=%04lx)",args
[3]);
834 hres
= xbuf_add(buf
, (LPBYTE
)&args
[3], sizeof(DWORD
));
836 FIXME("serialize of lcid failed.\n");
840 DISPID
*rgDispId
= (DISPID
*)args
[4];
842 hres
= xbuf_add(buf
, (LPBYTE
)rgDispId
, sizeof(DISPID
) * cNames
);
844 FIXME("serialize of rgDispId failed.\n");
848 TRACE_(olerelay
)("riid=[in],rgszNames=[in],cNames=[in],rgDispId=[");
849 for (i
=0;i
<cNames
;i
++)
850 TRACE_(olerelay
)("%08lx,",rgDispId
[i
]);
851 TRACE_(olerelay
)("])");
853 HeapFree(GetProcessHeap(),0,(IID
*)args
[0]);
854 rgszNames
= (LPOLESTR
*)args
[1];
855 for (i
=0;i
<cNames
;i
++) HeapFree(GetProcessHeap(),0,rgszNames
[i
]);
856 HeapFree(GetProcessHeap(),0,rgszNames
);
857 HeapFree(GetProcessHeap(),0,rgDispId
);
863 deserialize_IDispatch_GetIDsOfNames(
875 args
[0] = (DWORD
)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IID
));
876 if (!args
[0]) return E_FAIL
;
877 hres
= xbuf_get(buf
, (LPBYTE
)args
[0], sizeof(IID
));
879 FIXME("deserialize of IID failed.\n");
882 if (debugout
) TRACE_(olerelay
)("riid=%s,",debugstr_guid((REFIID
)args
[0]));
884 hres
= xbuf_get(buf
, (LPBYTE
)&cNames
, sizeof(DWORD
));
886 FIXME("deserialize of cNames failed.\n");
890 if (debugout
) TRACE_(olerelay
)("cNames=%ld,",cNames
);
891 if (debugout
) TRACE_(olerelay
)("rgszNames=[");
892 rgszNames
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(LPOLESTR
) * cNames
);
893 if (!rgszNames
) return E_FAIL
;
894 args
[1] = (DWORD
)rgszNames
;
895 for (i
=0;i
<cNames
;i
++) {
898 hres
= xbuf_get(buf
, (LPBYTE
)&len
, sizeof(DWORD
));
900 FIXME("serialize of len failed.\n");
903 rgszNames
[i
] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
905 FIXME("heapalloc of %ld bytes failed\n", len
);
908 hres
= xbuf_get(buf
, (LPBYTE
)rgszNames
[i
], len
);
910 FIXME("serialize of rgszNames[i] failed.\n");
913 if (debugout
) TRACE_(olerelay
)("%s,",relaystr(rgszNames
[i
]));
915 hres
= xbuf_get(buf
, (LPBYTE
)&args
[3], sizeof(DWORD
));
917 FIXME("deserialize of lcid failed.\n");
920 if (debugout
) TRACE_(olerelay
)("],lcid=%04lx,rgDispId=[out])",args
[3]);
921 args
[4] = (DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DISPID
) * cNames
);
923 hres
= xbuf_get(buf
, (LPBYTE
)args
[4], sizeof(DISPID
) * args
[2]);
925 FIXME("serialize of rgDispId failed.\n");
929 TRACE_(olerelay
)("dispid=[");
930 for (i
=0;i
<args
[2];i
++)
931 TRACE_(olerelay
)("%08lx,",((DISPID
*)args
[4])[i
]);
932 TRACE_(olerelay
)("])");
939 serialize_LPVOID_ptr(
951 if ((tdesc
->vt
!= VT_PTR
) ||
952 (tdesc
->u
.lptdesc
->vt
!= VT_PTR
) ||
953 (tdesc
->u
.lptdesc
->u
.lptdesc
->vt
!= VT_VOID
)
955 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
958 cookie
= (*(DWORD
*)*arg
) ? 0x42424242: 0x0;
960 hres
= xbuf_add(buf
, (LPVOID
)&cookie
, sizeof(cookie
));
964 if (!*(DWORD
*)*arg
) {
965 if (debugout
) TRACE_(olerelay
)("<lpvoid NULL>");
969 TRACE_(olerelay
)("ppv(%p)",*(LPUNKNOWN
*)*arg
);
971 hres
= _marshal_interface(buf
,&(buf
->iid
),*(LPUNKNOWN
*)*arg
);
976 HeapFree(GetProcessHeap(),0,(LPVOID
)*arg
);
981 serialize_DISPPARAM_ptr(
995 if ((tdesc
->vt
!= VT_PTR
) || (tdesc
->u
.lptdesc
->vt
!= VT_USERDEFINED
)) {
996 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
1000 cookie
= *arg
? 0x42424242 : 0x0;
1002 hres
= xbuf_add(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
1007 if (debugout
) TRACE_(olerelay
)("<DISPPARAMS NULL>");
1010 disp
= (DISPPARAMS
*)*arg
;
1012 hres
= xbuf_add(buf
,(LPBYTE
)&disp
->cArgs
,sizeof(disp
->cArgs
));
1016 if (debugout
) TRACE_(olerelay
)("D{");
1017 for (i
=0;i
<disp
->cArgs
;i
++) {
1020 vtdesc
.vt
= VT_VARIANT
;
1027 (DWORD
*)(disp
->rgvarg
+i
),
1030 if (debugout
&& (i
<disp
->cArgs
-1))
1031 TRACE_(olerelay
)(",");
1034 HeapFree(GetProcessHeap(),0,disp
->rgvarg
);
1036 hres
= xbuf_add(buf
,(LPBYTE
)&disp
->cNamedArgs
,sizeof(disp
->cNamedArgs
));
1040 if (debugout
) TRACE_(olerelay
)("}{");
1041 for (i
=0;i
<disp
->cNamedArgs
;i
++) {
1044 vtdesc
.vt
= VT_UINT
;
1051 (DWORD
*)(disp
->rgdispidNamedArgs
+i
),
1054 if (debugout
&& (i
<disp
->cNamedArgs
-1))
1055 TRACE_(olerelay
)(",");
1057 if (debugout
) TRACE_(olerelay
)("}");
1059 HeapFree(GetProcessHeap(),0,disp
->rgdispidNamedArgs
);
1060 HeapFree(GetProcessHeap(),0,disp
);
1075 HRESULT hres
= S_OK
;
1077 TRACE("vt %d at %p\n",tdesc
->vt
,arg
);
1080 switch (tdesc
->vt
) {
1082 if (debugout
) TRACE_(olerelay
)("<empty>");
1085 if (debugout
) TRACE_(olerelay
)("<null>");
1088 VARIANT
*vt
= (VARIANT
*)arg
;
1093 hres
= xbuf_get(buf
,(LPBYTE
)&vttype
,sizeof(vttype
));
1095 FIXME("vt type not read?\n");
1098 memset(&tdesc2
,0,sizeof(tdesc2
));
1101 if (debugout
) TRACE_(olerelay
)("Vt(%ld)(",vttype
);
1102 hres
= deserialize_param(tinfo
, readit
, debugout
, alloc
, &tdesc2
, (DWORD
*)&(V_I4(vt
)), buf
);
1103 TRACE_(olerelay
)(")");
1117 hres
= xbuf_get(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
1118 if (hres
) ERR("Failed to read integer 4 byte\n");
1120 if (debugout
) TRACE_(olerelay
)("%lx",*arg
);
1126 hres
= xbuf_get(buf
,(LPBYTE
)&x
,sizeof(DWORD
));
1127 if (hres
) ERR("Failed to read integer 4 byte\n");
1130 if (debugout
) TRACE_(olerelay
)("%04lx",*arg
& 0xffff);
1136 hres
= xbuf_get(buf
,(LPBYTE
)&x
,sizeof(DWORD
));
1137 if (hres
) ERR("Failed to read integer 4 byte\n");
1140 if (debugout
) TRACE_(olerelay
)("%02lx",*arg
& 0xff);
1142 case VT_I4
|VT_BYREF
:
1145 *arg
= (DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DWORD
));
1147 hres
= xbuf_get(buf
,(LPBYTE
)*arg
,sizeof(DWORD
));
1148 if (hres
) ERR("Failed to read integer 4 byte\n");
1150 if (debugout
) TRACE_(olerelay
)("&0x%lx",*(DWORD
*)*arg
);
1152 case VT_BSTR
|VT_BYREF
: {
1153 BSTR
**bstr
= (BSTR
**)arg
;
1158 hres
= xbuf_get(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
1160 ERR("failed to read bstr klen\n");
1164 *bstr
= CoTaskMemAlloc(sizeof(BSTR
*));
1166 if (debugout
) TRACE_(olerelay
)("<bstr NULL>");
1168 str
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,(len
+1)*sizeof(WCHAR
));
1169 hres
= xbuf_get(buf
,(LPBYTE
)str
,len
*sizeof(WCHAR
));
1171 ERR("Failed to read BSTR.\n");
1174 *bstr
= CoTaskMemAlloc(sizeof(BSTR
*));
1175 **bstr
= SysAllocStringLen(str
,len
);
1176 if (debugout
) TRACE_(olerelay
)("%s",relaystr(str
));
1177 HeapFree(GetProcessHeap(),0,str
);
1189 hres
= xbuf_get(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
1191 ERR("failed to read bstr klen\n");
1196 if (debugout
) TRACE_(olerelay
)("<bstr NULL>");
1198 str
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,(len
+1)*sizeof(WCHAR
));
1199 hres
= xbuf_get(buf
,(LPBYTE
)str
,len
*sizeof(WCHAR
));
1201 ERR("Failed to read BSTR.\n");
1204 *arg
= (DWORD
)SysAllocStringLen(str
,len
);
1205 if (debugout
) TRACE_(olerelay
)("%s",relaystr(str
));
1206 HeapFree(GetProcessHeap(),0,str
);
1215 BOOL derefhere
= TRUE
;
1217 if (tdesc
->u
.lptdesc
->vt
== VT_USERDEFINED
) {
1221 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.lptdesc
->u
.hreftype
,&tinfo2
);
1223 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc
->u
.lptdesc
->u
.hreftype
);
1226 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
1227 switch (tattr
->typekind
) {
1228 case TKIND_ENUM
: /* confirmed */
1229 case TKIND_RECORD
: /* FIXME: mostly untested */
1232 case TKIND_ALIAS
: /* FIXME: untested */
1233 case TKIND_DISPATCH
: /* will be done in VT_USERDEFINED case */
1234 case TKIND_INTERFACE
: /* will be done in VT_USERDEFINED case */
1238 FIXME("unhandled switch cases tattr->typekind %d\n", tattr
->typekind
);
1242 ITypeInfo_Release(tinfo2
);
1244 /* read it in all cases, we need to know if we have
1245 * NULL pointer or not.
1247 hres
= xbuf_get(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
1249 ERR("Failed to load pointer cookie.\n");
1252 if (cookie
!= 0x42424242) {
1253 /* we read a NULL ptr from the remote side */
1254 if (debugout
) TRACE_(olerelay
)("NULL");
1258 if (debugout
) TRACE_(olerelay
)("*");
1260 /* Allocate space for the referenced struct */
1262 *arg
=(DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,_xsize(tdesc
->u
.lptdesc
));
1265 return deserialize_param(tinfo
, readit
, debugout
, alloc
, tdesc
->u
.lptdesc
, (LPDWORD
)*arg
, buf
);
1267 return deserialize_param(tinfo
, readit
, debugout
, alloc
, tdesc
->u
.lptdesc
, arg
, buf
);
1270 /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
1272 *arg
=(DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DWORD
));
1275 hres
= _unmarshal_interface(buf
,&IID_IUnknown
,(LPUNKNOWN
*)arg
);
1277 TRACE_(olerelay
)("unk(%p)",arg
);
1282 hres
= _unmarshal_interface(buf
,&IID_IDispatch
,(LPUNKNOWN
*)arg
);
1284 TRACE_(olerelay
)("idisp(%p)",arg
);
1287 if (debugout
) TRACE_(olerelay
)("<void>");
1289 case VT_USERDEFINED
: {
1293 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.hreftype
,&tinfo2
);
1295 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc
->u
.hreftype
);
1298 hres
= ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
1300 ERR("Could not get typeattr in VT_USERDEFINED.\n");
1302 switch (tattr
->typekind
) {
1303 case TKIND_DISPATCH
:
1304 case TKIND_INTERFACE
:
1306 hres
= _unmarshal_interface(buf
,&(tattr
->guid
),(LPUNKNOWN
*)arg
);
1308 case TKIND_RECORD
: {
1312 *arg
= (DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,tattr
->cbSizeInstance
);
1314 if (debugout
) TRACE_(olerelay
)("{");
1315 for (i
=0;i
<tattr
->cVars
;i
++) {
1318 hres
= ITypeInfo2_GetVarDesc(tinfo2
, i
, &vdesc
);
1320 ERR("Could not get vardesc of %d\n",i
);
1323 hres
= deserialize_param(
1328 &vdesc
->elemdescVar
.tdesc
,
1329 (DWORD
*)(((LPBYTE
)*arg
)+vdesc
->u
.oInst
),
1332 if (debugout
&& (i
<tattr
->cVars
-1)) TRACE_(olerelay
)(",");
1334 if (buf
->thisisiid
&& (tattr
->cbSizeInstance
==sizeof(GUID
)))
1335 memcpy(&(buf
->iid
),(LPBYTE
)*arg
,sizeof(buf
->iid
));
1336 if (debugout
) TRACE_(olerelay
)("}");
1340 return deserialize_param(tinfo2
,readit
,debugout
,alloc
,&tattr
->tdescAlias
,arg
,buf
);
1343 hres
= xbuf_get(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
1344 if (hres
) ERR("Failed to read enum (4 byte)\n");
1346 if (debugout
) TRACE_(olerelay
)("%lx",*arg
);
1349 ERR("Unhandled typekind %d\n",tattr
->typekind
);
1355 ERR("failed to stuballoc in TKIND_RECORD.\n");
1356 ITypeInfo_Release(tinfo2
);
1360 /* arg is pointing to the start of the array. */
1361 ARRAYDESC
*adesc
= tdesc
->u
.lpadesc
;
1364 if (adesc
->cDims
> 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
1365 for (i
=0;i
<adesc
->cDims
;i
++)
1366 arrsize
*= adesc
->rgbounds
[i
].cElements
;
1367 for (i
=0;i
<arrsize
;i
++)
1374 (DWORD
*)((LPBYTE
)(arg
)+i
*_xsize(&adesc
->tdescElem
)),
1380 ERR("No handler for VT type %d!\n",tdesc
->vt
);
1387 deserialize_LPVOID_ptr(
1399 if ((tdesc
->vt
!= VT_PTR
) ||
1400 (tdesc
->u
.lptdesc
->vt
!= VT_PTR
) ||
1401 (tdesc
->u
.lptdesc
->u
.lptdesc
->vt
!= VT_VOID
)
1403 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
1407 *arg
=(DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(LPVOID
));
1409 hres
= xbuf_get(buf
, (LPVOID
)&cookie
, sizeof(cookie
));
1412 if (cookie
!= 0x42424242) {
1414 if (debugout
) TRACE_(olerelay
)("<lpvoid NULL>");
1419 hres
= _unmarshal_interface(buf
,&buf
->iid
,(LPUNKNOWN
*)*arg
);
1421 FIXME("_unmarshal_interface of %s , %p failed with %lx\n", debugstr_guid(&buf
->iid
), (LPUNKNOWN
*)*arg
, hres
);
1425 if (debugout
) TRACE_(olerelay
)("ppv(%p)",(LPVOID
)*arg
);
1430 deserialize_DISPPARAM_ptr(
1444 if ((tdesc
->vt
!= VT_PTR
) || (tdesc
->u
.lptdesc
->vt
!= VT_USERDEFINED
)) {
1445 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
1449 hres
= xbuf_get(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
1454 if (debugout
) TRACE_(olerelay
)("<DISPPARAMS NULL>");
1459 *arg
= (DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DISPPARAMS
));
1460 disps
= (DISPPARAMS
*)*arg
;
1463 hres
= xbuf_get(buf
, (LPBYTE
)&disps
->cArgs
, sizeof(disps
->cArgs
));
1467 disps
->rgvarg
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(VARIANT
)*disps
->cArgs
);
1468 if (debugout
) TRACE_(olerelay
)("D{");
1469 for (i
=0; i
< disps
->cArgs
; i
++) {
1472 vdesc
.vt
= VT_VARIANT
;
1473 hres
= deserialize_param(
1479 (DWORD
*)(disps
->rgvarg
+i
),
1483 if (debugout
) TRACE_(olerelay
)("}{");
1484 hres
= xbuf_get(buf
, (LPBYTE
)&disps
->cNamedArgs
, sizeof(disps
->cNamedArgs
));
1487 if (disps
->cNamedArgs
) {
1489 disps
->rgdispidNamedArgs
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DISPID
)*disps
->cNamedArgs
);
1490 for (i
=0; i
< disps
->cNamedArgs
; i
++) {
1494 hres
= deserialize_param(
1500 (DWORD
*)(disps
->rgdispidNamedArgs
+i
),
1503 if (debugout
&& i
<(disps
->cNamedArgs
-1)) TRACE_(olerelay
)(",");
1506 if (debugout
) TRACE_(olerelay
)("}");
1510 /* Searches function, also in inherited interfaces */
1513 ITypeInfo
*tinfo
, int iMethod
, ITypeInfo
**tactual
, FUNCDESC
**fdesc
, BSTR
*iname
, BSTR
*fname
)
1518 if (fname
) *fname
= NULL
;
1519 if (iname
) *iname
= NULL
;
1522 ITypeInfo_AddRef(*tactual
);
1525 hres
= ITypeInfo_GetFuncDesc(tinfo
, i
, fdesc
);
1531 hres
= ITypeInfo_GetTypeAttr(tinfo
, &attr
);
1533 ERR("GetTypeAttr failed with %lx\n",hres
);
1536 /* Not found, so look in inherited ifaces. */
1537 for (j
=0;j
<attr
->cImplTypes
;j
++) {
1538 hres
= ITypeInfo_GetRefTypeOfImplType(tinfo
, j
, &href
);
1540 ERR("Did not find a reftype for interface offset %d?\n",j
);
1543 hres
= ITypeInfo_GetRefTypeInfo(tinfo
, href
, &tinfo2
);
1545 ERR("Did not find a typeinfo for reftype %ld?\n",href
);
1548 hres
= _get_funcdesc(tinfo2
,iMethod
,tactual
,fdesc
,iname
,fname
);
1549 ITypeInfo_Release(tinfo2
);
1550 if (!hres
) return S_OK
;
1554 if (((*fdesc
)->oVft
/4) == iMethod
) {
1556 ITypeInfo_GetDocumentation(tinfo
,(*fdesc
)->memid
,fname
,NULL
,NULL
,NULL
);
1558 ITypeInfo_GetDocumentation(tinfo
,-1,iname
,NULL
,NULL
,NULL
);
1566 xCall(LPVOID retptr
, int method
, TMProxyImpl
*tpinfo
/*, args */)
1568 DWORD
*args
= ((DWORD
*)&tpinfo
)+1, *xargs
;
1571 int i
, relaydeb
= TRACE_ON(olerelay
);
1578 int is_idispatch_getidsofnames
= 0;
1579 DWORD remoteresult
= 0;
1582 EnterCriticalSection(&tpinfo
->crit
);
1584 hres
= _get_funcdesc(tpinfo
->tinfo
,method
,&tinfo
,&fdesc
,&iname
,&fname
);
1586 ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method
);
1587 ITypeInfo_Release(tinfo
);
1588 LeaveCriticalSection(&tpinfo
->crit
);
1592 if (!tpinfo
->chanbuf
)
1594 WARN("Tried to use disconnected proxy\n");
1595 ITypeInfo_Release(tinfo
);
1596 LeaveCriticalSection(&tpinfo
->crit
);
1597 return RPC_E_DISCONNECTED
;
1601 TRACE_(olerelay
)("->");
1603 TRACE_(olerelay
)("%s:",relaystr(iname
));
1605 TRACE_(olerelay
)("%s(%d)",relaystr(fname
),method
);
1607 TRACE_(olerelay
)("%d",method
);
1608 TRACE_(olerelay
)("(");
1610 if (iname
&& fname
&& !lstrcmpW(iname
,IDispatchW
) && !lstrcmpW(fname
,GetIDsOfNamesW
))
1611 is_idispatch_getidsofnames
= 1;
1613 if (iname
) SysFreeString(iname
);
1614 if (fname
) SysFreeString(fname
);
1616 memset(&buf
,0,sizeof(buf
));
1617 buf
.iid
= IID_IUnknown
;
1619 /* Special IDispatch::GetIDsOfNames() serializer */
1620 if (is_idispatch_getidsofnames
) {
1621 hres
= serialize_IDispatch_GetIDsOfNames(TRUE
,relaydeb
,args
,&buf
);
1623 FIXME("serialize of IDispatch::GetIDsOfNames failed!\n");
1624 ITypeInfo_Release(tinfo
);
1625 LeaveCriticalSection(&tpinfo
->crit
);
1628 goto afterserialize
;
1631 /* special QueryInterface serialize */
1633 xbuf_add(&buf
,(LPBYTE
)args
[0],sizeof(IID
));
1634 if (relaydeb
) TRACE_(olerelay
)("riid=%s,[out])",debugstr_guid((REFIID
)args
[0]));
1635 goto afterserialize
;
1638 /* normal typelib driven serializing */
1640 /* Need them for hack below */
1641 memset(names
,0,sizeof(names
));
1642 if (ITypeInfo_GetNames(tinfo
,fdesc
->memid
,names
,sizeof(names
)/sizeof(names
[0]),&nrofnames
))
1644 if (nrofnames
> sizeof(names
)/sizeof(names
[0]))
1645 ERR("Need more names!\n");
1648 for (i
=0;i
<fdesc
->cParams
;i
++) {
1649 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1650 BOOL isserialized
= FALSE
;
1652 if (i
) TRACE_(olerelay
)(",");
1653 if (i
+1<nrofnames
&& names
[i
+1])
1654 TRACE_(olerelay
)("%s=",relaystr(names
[i
+1]));
1656 /* No need to marshal other data than FIN and any VT_PTR. */
1657 if (!(elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
) && (elem
->tdesc
.vt
!= VT_PTR
)) {
1658 xargs
+=_argsize(elem
->tdesc
.vt
);
1659 if (relaydeb
) TRACE_(olerelay
)("[out]");
1662 if (((i
+1)<nrofnames
) && !IsBadStringPtrW(names
[i
+1],1)) {
1663 /* If the parameter is 'riid', we use it as interface IID
1664 * for a later ppvObject serialization.
1666 buf
.thisisiid
= !lstrcmpW(names
[i
+1],riidW
);
1668 /* DISPPARAMS* needs special serializer */
1669 if (!lstrcmpW(names
[i
+1],pdispparamsW
)) {
1670 hres
= serialize_DISPPARAM_ptr(
1672 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
1679 isserialized
= TRUE
;
1681 if (!lstrcmpW(names
[i
+1],ppvObjectW
)) {
1682 hres
= serialize_LPVOID_ptr(
1684 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
1692 isserialized
= TRUE
;
1696 hres
= serialize_param(
1698 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
1707 ERR("Failed to serialize param, hres %lx\n",hres
);
1710 xargs
+=_argsize(elem
->tdesc
.vt
);
1712 if (relaydeb
) TRACE_(olerelay
)(")");
1715 memset(&msg
,0,sizeof(msg
));
1716 msg
.cbBuffer
= buf
.curoff
;
1717 msg
.iMethod
= method
;
1718 hres
= IRpcChannelBuffer_GetBuffer(tpinfo
->chanbuf
,&msg
,&(tpinfo
->iid
));
1720 ERR("RpcChannelBuffer GetBuffer failed, %lx\n",hres
);
1721 LeaveCriticalSection(&tpinfo
->crit
);
1724 memcpy(msg
.Buffer
,buf
.base
,buf
.curoff
);
1725 if (relaydeb
) TRACE_(olerelay
)("\n");
1726 hres
= IRpcChannelBuffer_SendReceive(tpinfo
->chanbuf
,&msg
,&status
);
1728 ERR("RpcChannelBuffer SendReceive failed, %lx\n",hres
);
1729 LeaveCriticalSection(&tpinfo
->crit
);
1733 if (relaydeb
) TRACE_(olerelay
)(" status = %08lx (",status
);
1735 buf
.base
= HeapReAlloc(GetProcessHeap(),0,buf
.base
,msg
.cbBuffer
);
1737 buf
.base
= HeapAlloc(GetProcessHeap(),0,msg
.cbBuffer
);
1738 buf
.size
= msg
.cbBuffer
;
1739 memcpy(buf
.base
,msg
.Buffer
,buf
.size
);
1742 /* Special IDispatch::GetIDsOfNames() deserializer */
1743 if (is_idispatch_getidsofnames
) {
1744 hres
= deserialize_IDispatch_GetIDsOfNames(FALSE
,relaydeb
,args
,&buf
);
1746 FIXME("deserialize of IDispatch::GetIDsOfNames failed!\n");
1749 goto after_deserialize
;
1751 /* Special QueryInterface deserializer */
1753 _unmarshal_interface(&buf
,(REFIID
)args
[0],(LPUNKNOWN
*)args
[1]);
1754 if (relaydeb
) TRACE_(olerelay
)("[in],%p",*((DWORD
**)args
[1]));
1755 goto after_deserialize
;
1758 /* generic deserializer using typelib description */
1761 for (i
=0;i
<fdesc
->cParams
;i
++) {
1762 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1763 BOOL isdeserialized
= FALSE
;
1766 if (i
) TRACE_(olerelay
)(",");
1767 if (i
+1<nrofnames
&& names
[i
+1]) TRACE_(olerelay
)("%s=",relaystr(names
[i
+1]));
1769 /* No need to marshal other data than FOUT and any VT_PTR */
1770 if (!(elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
) && (elem
->tdesc
.vt
!= VT_PTR
)) {
1771 xargs
+= _argsize(elem
->tdesc
.vt
);
1772 if (relaydeb
) TRACE_(olerelay
)("[in]");
1775 if (((i
+1)<nrofnames
) && !IsBadStringPtrW(names
[i
+1],1)) {
1776 /* If the parameter is 'riid', we use it as interface IID
1777 * for a later ppvObject serialization.
1779 buf
.thisisiid
= !lstrcmpW(names
[i
+1],riidW
);
1781 /* deserialize DISPPARAM */
1782 if (!lstrcmpW(names
[i
+1],pdispparamsW
)) {
1783 hres
= deserialize_DISPPARAM_ptr(
1785 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
1793 ERR("Failed to deserialize DISPPARAM*, hres %lx\n",hres
);
1796 isdeserialized
= TRUE
;
1798 if (!lstrcmpW(names
[i
+1],ppvObjectW
)) {
1799 hres
= deserialize_LPVOID_ptr(
1801 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
1809 isdeserialized
= TRUE
;
1812 if (!isdeserialized
)
1813 hres
= deserialize_param(
1815 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
1823 ERR("Failed to unmarshall param, hres %lx\n",hres
);
1827 xargs
+= _argsize(elem
->tdesc
.vt
);
1830 hres
= xbuf_get(&buf
, (LPBYTE
)&remoteresult
, sizeof(DWORD
));
1833 if (relaydeb
) TRACE_(olerelay
)(") = %08lx\n", remoteresult
);
1835 if (status
!= S_OK
) /* OLE/COM internal error */
1838 HeapFree(GetProcessHeap(),0,buf
.base
);
1839 ITypeInfo_Release(tinfo
);
1840 LeaveCriticalSection(&tpinfo
->crit
);
1841 return remoteresult
;
1844 HRESULT WINAPI
ProxyIUnknown_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
1846 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1848 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
1850 if (proxy
->outerunknown
)
1851 return IUnknown_QueryInterface(proxy
->outerunknown
, riid
, ppv
);
1853 FIXME("No interface\n");
1854 return E_NOINTERFACE
;
1857 ULONG WINAPI
ProxyIUnknown_AddRef(IUnknown
*iface
)
1859 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1863 if (proxy
->outerunknown
)
1864 return IUnknown_AddRef(proxy
->outerunknown
);
1866 return 2; /* FIXME */
1869 ULONG WINAPI
ProxyIUnknown_Release(IUnknown
*iface
)
1871 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1875 if (proxy
->outerunknown
)
1876 return IUnknown_Release(proxy
->outerunknown
);
1878 return 1; /* FIXME */
1881 static HRESULT WINAPI
1882 PSFacBuf_CreateProxy(
1883 LPPSFACTORYBUFFER iface
, IUnknown
* pUnkOuter
, REFIID riid
,
1884 IRpcProxyBuffer
**ppProxy
, LPVOID
*ppv
)
1892 TRACE("(...%s...)\n",debugstr_guid(riid
));
1893 hres
= _get_typeinfo_for_iid(riid
,&tinfo
);
1895 ERR("No typeinfo for %s?\n",debugstr_guid(riid
));
1898 nroffuncs
= _nroffuncs(tinfo
);
1899 proxy
= CoTaskMemAlloc(sizeof(TMProxyImpl
));
1900 if (!proxy
) return E_OUTOFMEMORY
;
1902 assert(sizeof(TMAsmProxy
) == 12);
1904 proxy
->outerunknown
= pUnkOuter
;
1905 proxy
->asmstubs
= VirtualAlloc(NULL
, sizeof(TMAsmProxy
) * nroffuncs
, MEM_COMMIT
, PAGE_EXECUTE_READWRITE
);
1906 if (!proxy
->asmstubs
) {
1907 ERR("Could not commit pages for proxy thunks\n");
1908 CoTaskMemFree(proxy
);
1909 return E_OUTOFMEMORY
;
1912 InitializeCriticalSection(&proxy
->crit
);
1914 proxy
->lpvtbl
= HeapAlloc(GetProcessHeap(),0,sizeof(LPBYTE
)*nroffuncs
);
1915 for (i
=0;i
<nroffuncs
;i
++) {
1916 TMAsmProxy
*xasm
= proxy
->asmstubs
+i
;
1920 proxy
->lpvtbl
[i
] = ProxyIUnknown_QueryInterface
;
1923 proxy
->lpvtbl
[i
] = ProxyIUnknown_AddRef
;
1926 proxy
->lpvtbl
[i
] = ProxyIUnknown_Release
;
1930 /* nrofargs without This */
1933 hres
= _get_funcdesc(tinfo
,i
,&tinfo2
,&fdesc
,NULL
,NULL
);
1934 ITypeInfo_Release(tinfo2
);
1936 ERR("GetFuncDesc %lx should not fail here.\n",hres
);
1939 /* some args take more than 4 byte on the stack */
1941 for (j
=0;j
<fdesc
->cParams
;j
++)
1942 nrofargs
+= _argsize(fdesc
->lprgelemdescParam
[j
].tdesc
.vt
);
1945 if (fdesc
->callconv
!= CC_STDCALL
) {
1946 ERR("calling convention is not stdcall????\n");
1949 /* popl %eax - return ptr
1956 * arg3 arg2 arg1 <method> <returnptr>
1958 xasm
->popleax
= 0x58;
1959 xasm
->pushlval
= 0x6a;
1961 xasm
->pushleax
= 0x50;
1962 xasm
->lcall
= 0xe8; /* relative jump */
1963 xasm
->xcall
= (DWORD
)xCall
;
1964 xasm
->xcall
-= (DWORD
)&(xasm
->lret
);
1966 xasm
->bytestopop
= (nrofargs
+2)*4; /* pop args, This, iMethod */
1967 proxy
->lpvtbl
[i
] = xasm
;
1970 FIXME("not implemented on non i386\n");
1976 proxy
->lpvtbl2
= &tmproxyvtable
;
1977 /* one reference for the proxy */
1979 proxy
->tinfo
= tinfo
;
1980 memcpy(&proxy
->iid
,riid
,sizeof(*riid
));
1982 *ppv
= (LPVOID
)proxy
;
1983 *ppProxy
= (IRpcProxyBuffer
*)&(proxy
->lpvtbl2
);
1984 IUnknown_AddRef((IUnknown
*)*ppv
);
1988 typedef struct _TMStubImpl
{
1989 const IRpcStubBufferVtbl
*lpvtbl
;
1997 static HRESULT WINAPI
1998 TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface
, REFIID riid
, LPVOID
*ppv
)
2000 if (IsEqualIID(riid
,&IID_IRpcStubBuffer
)||IsEqualIID(riid
,&IID_IUnknown
)){
2001 *ppv
= (LPVOID
)iface
;
2002 IRpcStubBuffer_AddRef(iface
);
2005 FIXME("%s, not supported IID.\n",debugstr_guid(riid
));
2006 return E_NOINTERFACE
;
2010 TMStubImpl_AddRef(LPRPCSTUBBUFFER iface
)
2012 TMStubImpl
*This
= (TMStubImpl
*)iface
;
2013 ULONG refCount
= InterlockedIncrement(&This
->ref
);
2015 TRACE("(%p)->(ref before=%lu)\n", This
, refCount
- 1);
2021 TMStubImpl_Release(LPRPCSTUBBUFFER iface
)
2023 TMStubImpl
*This
= (TMStubImpl
*)iface
;
2024 ULONG refCount
= InterlockedDecrement(&This
->ref
);
2026 TRACE("(%p)->(ref before=%lu)\n", This
, refCount
+ 1);
2030 IRpcStubBuffer_Disconnect(iface
);
2031 ITypeInfo_Release(This
->tinfo
);
2032 CoTaskMemFree(This
);
2037 static HRESULT WINAPI
2038 TMStubImpl_Connect(LPRPCSTUBBUFFER iface
, LPUNKNOWN pUnkServer
)
2040 TMStubImpl
*This
= (TMStubImpl
*)iface
;
2042 TRACE("(%p)->(%p)\n", This
, pUnkServer
);
2044 IUnknown_AddRef(pUnkServer
);
2045 This
->pUnk
= pUnkServer
;
2050 TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface
)
2052 TMStubImpl
*This
= (TMStubImpl
*)iface
;
2054 TRACE("(%p)->()\n", This
);
2058 IUnknown_Release(This
->pUnk
);
2063 static HRESULT WINAPI
2065 LPRPCSTUBBUFFER iface
, RPCOLEMESSAGE
* xmsg
,IRpcChannelBuffer
*rpcchanbuf
)
2069 TMStubImpl
*This
= (TMStubImpl
*)iface
;
2071 DWORD
*args
, res
, *xargs
, nrofargs
;
2075 BSTR fname
= NULL
,iname
= NULL
;
2076 BOOL is_idispatch_getidsofnames
= 0;
2079 memset(&buf
,0,sizeof(buf
));
2080 buf
.size
= xmsg
->cbBuffer
;
2081 buf
.base
= HeapAlloc(GetProcessHeap(), 0, xmsg
->cbBuffer
);
2082 memcpy(buf
.base
, xmsg
->Buffer
, xmsg
->cbBuffer
);
2084 buf
.iid
= IID_IUnknown
;
2087 if (xmsg
->iMethod
== 0) { /* QI */
2089 /* in: IID, out: <iface> */
2091 xbuf_get(&buf
,(LPBYTE
)&xiid
,sizeof(xiid
));
2093 hres
= _marshal_interface(&buf
,&xiid
,This
->pUnk
);
2094 xmsg
->Buffer
= buf
.base
; /* Might have been reallocated */
2095 xmsg
->cbBuffer
= buf
.size
;
2098 hres
= _get_funcdesc(This
->tinfo
,xmsg
->iMethod
,&tinfo
,&fdesc
,&iname
,&fname
);
2100 ERR("GetFuncDesc on method %ld failed with %lx\n",xmsg
->iMethod
,hres
);
2104 if (iname
&& fname
&& !lstrcmpW(iname
, IDispatchW
) && !lstrcmpW(fname
, GetIDsOfNamesW
))
2105 is_idispatch_getidsofnames
= 1;
2107 if (iname
) SysFreeString (iname
);
2108 if (fname
) SysFreeString (fname
);
2110 /* Need them for hack below */
2111 memset(names
,0,sizeof(names
));
2112 ITypeInfo_GetNames(tinfo
,fdesc
->memid
,names
,sizeof(names
)/sizeof(names
[0]),&nrofnames
);
2113 if (nrofnames
> sizeof(names
)/sizeof(names
[0])) {
2114 ERR("Need more names!\n");
2117 /*dump_FUNCDESC(fdesc);*/
2119 for (i
=0;i
<fdesc
->cParams
;i
++)
2120 nrofargs
+= _argsize(fdesc
->lprgelemdescParam
[i
].tdesc
.vt
);
2121 args
= HeapAlloc(GetProcessHeap(),0,(nrofargs
+1)*sizeof(DWORD
));
2122 if (!args
) return E_OUTOFMEMORY
;
2124 if (is_idispatch_getidsofnames
) {
2125 hres
= deserialize_IDispatch_GetIDsOfNames(TRUE
,FALSE
,args
+1,&buf
);
2127 FIXME("deserialize_IDispatch_GetIDsOfNames failed!\n");
2131 goto afterdeserialize
;
2134 /* Allocate all stuff used by call. */
2136 for (i
=0;i
<fdesc
->cParams
;i
++) {
2137 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
2138 BOOL isdeserialized
= FALSE
;
2140 if (((i
+1)<nrofnames
) && !IsBadStringPtrW(names
[i
+1],1)) {
2141 /* If the parameter is 'riid', we use it as interface IID
2142 * for a later ppvObject serialization.
2144 buf
.thisisiid
= !lstrcmpW(names
[i
+1],riidW
);
2146 /* deserialize DISPPARAM */
2147 if (!lstrcmpW(names
[i
+1],pdispparamsW
)) {
2148 hres
= deserialize_DISPPARAM_ptr(
2150 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
2158 ERR("Failed to deserialize DISPPARAM*, hres %lx\n",hres
);
2161 isdeserialized
= TRUE
;
2163 if (!lstrcmpW(names
[i
+1],ppvObjectW
)) {
2164 hres
= deserialize_LPVOID_ptr(
2166 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
2174 isdeserialized
= TRUE
;
2177 if (!isdeserialized
)
2178 hres
= deserialize_param(
2180 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
2187 xargs
+= _argsize(elem
->tdesc
.vt
);
2189 ERR("Failed to deserialize param %s, hres %lx\n",relaystr(names
[i
+1]),hres
);
2194 hres
= IUnknown_QueryInterface(This
->pUnk
,&(This
->iid
),(LPVOID
*)&(args
[0]));
2196 ERR("Does not support iface %s, returning %lx\n",debugstr_guid(&(This
->iid
)), hres
);
2200 (*((FARPROC
**)args
[0]))[fdesc
->oVft
/4],
2205 IUnknown_Release((LPUNKNOWN
)args
[0]);
2208 /* special IDispatch::GetIDsOfNames serializer */
2209 if (is_idispatch_getidsofnames
) {
2210 hres
= serialize_IDispatch_GetIDsOfNames(FALSE
,FALSE
,args
+1,&buf
);
2212 FIXME("serialize of IDispatch::GetIDsOfNames failed!\n");
2215 goto afterserialize
;
2218 for (i
=0;i
<fdesc
->cParams
;i
++) {
2219 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
2220 BOOL isserialized
= FALSE
;
2222 if (((i
+1)<nrofnames
) && !IsBadStringPtrW(names
[i
+1],1)) {
2223 /* If the parameter is 'riid', we use it as interface IID
2224 * for a later ppvObject serialization.
2226 buf
.thisisiid
= !lstrcmpW(names
[i
+1],riidW
);
2228 /* DISPPARAMS* needs special serializer */
2229 if (!lstrcmpW(names
[i
+1],pdispparamsW
)) {
2230 hres
= serialize_DISPPARAM_ptr(
2232 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
2239 isserialized
= TRUE
;
2241 if (!lstrcmpW(names
[i
+1],ppvObjectW
)) {
2242 hres
= serialize_LPVOID_ptr(
2244 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
2252 isserialized
= TRUE
;
2256 hres
= serialize_param(
2258 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
2265 xargs
+= _argsize(elem
->tdesc
.vt
);
2267 ERR("Failed to stuballoc param, hres %lx\n",hres
);
2272 hres
= xbuf_add (&buf
, (LPBYTE
)&res
, sizeof(DWORD
));
2276 ITypeInfo_Release(tinfo
);
2277 HeapFree(GetProcessHeap(), 0, args
);
2279 xmsg
->cbBuffer
= buf
.curoff
;
2282 hres
= IRpcChannelBuffer_GetBuffer(rpcchanbuf
, xmsg
, &This
->iid
);
2284 ERR("IRpcChannelBuffer_GetBuffer failed with error 0x%08lx\n", hres
);
2288 /* FIXME: remove this case when we start sending an IRpcChannelBuffer
2289 * object with builtin OLE */
2290 RPC_STATUS status
= I_RpcGetBuffer((RPC_MESSAGE
*)xmsg
);
2291 if (status
!= RPC_S_OK
)
2293 ERR("I_RpcGetBuffer failed with error %ld\n", status
);
2299 memcpy(xmsg
->Buffer
, buf
.base
, buf
.curoff
);
2301 HeapFree(GetProcessHeap(), 0, buf
.base
);
2303 TRACE("returning\n");
2307 static LPRPCSTUBBUFFER WINAPI
2308 TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface
, REFIID riid
) {
2309 FIXME("Huh (%s)?\n",debugstr_guid(riid
));
2314 TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface
) {
2315 TMStubImpl
*This
= (TMStubImpl
*)iface
;
2318 return This
->ref
; /*FIXME? */
2321 static HRESULT WINAPI
2322 TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface
, LPVOID
*ppv
) {
2327 TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface
, LPVOID ppv
) {
2331 static const IRpcStubBufferVtbl tmstubvtbl
= {
2332 TMStubImpl_QueryInterface
,
2336 TMStubImpl_Disconnect
,
2338 TMStubImpl_IsIIDSupported
,
2339 TMStubImpl_CountRefs
,
2340 TMStubImpl_DebugServerQueryInterface
,
2341 TMStubImpl_DebugServerRelease
2344 static HRESULT WINAPI
2345 PSFacBuf_CreateStub(
2346 LPPSFACTORYBUFFER iface
, REFIID riid
,IUnknown
*pUnkServer
,
2347 IRpcStubBuffer
** ppStub
2353 TRACE("(%s,%p,%p)\n",debugstr_guid(riid
),pUnkServer
,ppStub
);
2354 hres
= _get_typeinfo_for_iid(riid
,&tinfo
);
2356 ERR("No typeinfo for %s?\n",debugstr_guid(riid
));
2359 stub
= CoTaskMemAlloc(sizeof(TMStubImpl
));
2361 return E_OUTOFMEMORY
;
2362 stub
->lpvtbl
= &tmstubvtbl
;
2364 stub
->tinfo
= tinfo
;
2365 memcpy(&(stub
->iid
),riid
,sizeof(*riid
));
2366 hres
= IRpcStubBuffer_Connect((LPRPCSTUBBUFFER
)stub
,pUnkServer
);
2367 *ppStub
= (LPRPCSTUBBUFFER
)stub
;
2368 TRACE("IRpcStubBuffer: %p\n", stub
);
2370 ERR("Connect to pUnkServer failed?\n");
2374 static const IPSFactoryBufferVtbl psfacbufvtbl
= {
2375 PSFacBuf_QueryInterface
,
2378 PSFacBuf_CreateProxy
,
2382 /* This is the whole PSFactoryBuffer object, just the vtableptr */
2383 static const IPSFactoryBufferVtbl
*lppsfac
= &psfacbufvtbl
;
2385 /***********************************************************************
2386 * TMARSHAL_DllGetClassObject
2388 HRESULT
TMARSHAL_DllGetClassObject(REFCLSID rclsid
, REFIID iid
,LPVOID
*ppv
)
2390 if (IsEqualIID(iid
,&IID_IPSFactoryBuffer
)) {
2394 return E_NOINTERFACE
;