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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
34 #define NONAMELESSUNION
35 #define NONAMELESSSTRUCT
46 #include "propidl.h" /* for LPSAFEARRAY_User* functions */
49 #include "wine/debug.h"
50 #include "wine/exception.h"
52 static const WCHAR IDispatchW
[] = { 'I','D','i','s','p','a','t','c','h',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 /* used in the olerelay code to avoid having the L"" stuff added by debugstr_w */
66 static char *relaystr(WCHAR
*in
) {
67 char *tmp
= (char *)debugstr_w(in
);
69 tmp
[strlen(tmp
)-1] = '\0';
74 xbuf_resize(marshal_state
*buf
, DWORD newsize
)
76 if(buf
->size
>= newsize
)
81 buf
->base
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, buf
->base
, newsize
);
87 buf
->base
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, newsize
);
96 xbuf_add(marshal_state
*buf
, LPBYTE stuff
, DWORD size
)
100 if(buf
->size
- buf
->curoff
< size
)
102 hr
= xbuf_resize(buf
, buf
->size
+ size
+ 100);
103 if(FAILED(hr
)) return hr
;
105 memcpy(buf
->base
+buf
->curoff
,stuff
,size
);
111 xbuf_get(marshal_state
*buf
, LPBYTE stuff
, DWORD size
) {
112 if (buf
->size
< buf
->curoff
+size
) return E_FAIL
;
113 memcpy(stuff
,buf
->base
+buf
->curoff
,size
);
119 xbuf_skip(marshal_state
*buf
, DWORD size
) {
120 if (buf
->size
< buf
->curoff
+size
) return E_FAIL
;
126 _unmarshal_interface(marshal_state
*buf
, REFIID riid
, LPUNKNOWN
*pUnk
) {
128 ULARGE_INTEGER newpos
;
129 LARGE_INTEGER seekto
;
134 TRACE("...%s...\n",debugstr_guid(riid
));
137 hres
= xbuf_get(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
139 ERR("xbuf_get failed\n");
143 if (xsize
== 0) return S_OK
;
145 hres
= CreateStreamOnHGlobal(0,TRUE
,&pStm
);
147 ERR("Stream create failed %x\n",hres
);
151 hres
= IStream_Write(pStm
,buf
->base
+buf
->curoff
,xsize
,&res
);
153 ERR("stream write %x\n",hres
);
157 memset(&seekto
,0,sizeof(seekto
));
158 hres
= IStream_Seek(pStm
,seekto
,SEEK_SET
,&newpos
);
160 ERR("Failed Seek %x\n",hres
);
164 hres
= CoUnmarshalInterface(pStm
,riid
,(LPVOID
*)pUnk
);
166 ERR("Unmarshalling interface %s failed with %x\n",debugstr_guid(riid
),hres
);
170 IStream_Release(pStm
);
171 return xbuf_skip(buf
,xsize
);
175 _marshal_interface(marshal_state
*buf
, REFIID riid
, LPUNKNOWN pUnk
) {
176 LPBYTE tempbuf
= NULL
;
177 IStream
*pStm
= NULL
;
179 ULARGE_INTEGER newpos
;
180 LARGE_INTEGER seekto
;
186 /* this is valid, if for instance we serialize
187 * a VT_DISPATCH with NULL ptr which apparently
188 * can happen. S_OK to make sure we continue
191 WARN("pUnk is NULL\n");
193 return xbuf_add(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
198 TRACE("...%s...\n",debugstr_guid(riid
));
200 hres
= CreateStreamOnHGlobal(0,TRUE
,&pStm
);
202 ERR("Stream create failed %x\n",hres
);
206 hres
= CoMarshalInterface(pStm
,riid
,pUnk
,0,NULL
,0);
208 ERR("Marshalling interface %s failed with %x\n", debugstr_guid(riid
), hres
);
212 hres
= IStream_Stat(pStm
,&ststg
,0);
214 ERR("Stream stat failed\n");
218 tempbuf
= HeapAlloc(GetProcessHeap(), 0, ststg
.cbSize
.u
.LowPart
);
219 memset(&seekto
,0,sizeof(seekto
));
220 hres
= IStream_Seek(pStm
,seekto
,SEEK_SET
,&newpos
);
222 ERR("Failed Seek %x\n",hres
);
226 hres
= IStream_Read(pStm
,tempbuf
,ststg
.cbSize
.u
.LowPart
,&res
);
228 ERR("Failed Read %x\n",hres
);
232 xsize
= ststg
.cbSize
.u
.LowPart
;
233 xbuf_add(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
234 hres
= xbuf_add(buf
,tempbuf
,ststg
.cbSize
.u
.LowPart
);
236 HeapFree(GetProcessHeap(),0,tempbuf
);
237 IStream_Release(pStm
);
243 xbuf_add(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
244 if (pStm
) IUnknown_Release(pStm
);
245 HeapFree(GetProcessHeap(), 0, tempbuf
);
249 /********************* OLE Proxy/Stub Factory ********************************/
250 static HRESULT WINAPI
251 PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface
, REFIID iid
, LPVOID
*ppv
) {
252 if (IsEqualIID(iid
,&IID_IPSFactoryBuffer
)||IsEqualIID(iid
,&IID_IUnknown
)) {
253 *ppv
= (LPVOID
)iface
;
254 /* No ref counting, static class */
257 FIXME("(%s) unknown IID?\n",debugstr_guid(iid
));
258 return E_NOINTERFACE
;
261 static ULONG WINAPI
PSFacBuf_AddRef(LPPSFACTORYBUFFER iface
) { return 2; }
262 static ULONG WINAPI
PSFacBuf_Release(LPPSFACTORYBUFFER iface
) { return 1; }
265 _get_typeinfo_for_iid(REFIID riid
, ITypeInfo
**ti
) {
268 char tlguid
[200],typelibkey
[300],interfacekey
[300],ver
[100];
271 DWORD tlguidlen
, verlen
, type
;
275 sprintf( interfacekey
, "Interface\\{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\Typelib",
276 riid
->Data1
, riid
->Data2
, riid
->Data3
,
277 riid
->Data4
[0], riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3],
278 riid
->Data4
[4], riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]
281 if (RegOpenKeyA(HKEY_CLASSES_ROOT
,interfacekey
,&ikey
)) {
282 ERR("No %s key found.\n",interfacekey
);
286 tlguidlen
= sizeof(tlguid
);
287 if (RegQueryValueExA(ikey
,NULL
,NULL
,&type
,(LPBYTE
)tlguid
,&tlguidlen
)) {
288 ERR("Getting typelib guid failed.\n");
293 verlen
= sizeof(ver
);
294 if (RegQueryValueExA(ikey
,"Version",NULL
,&type
,(LPBYTE
)ver
,&verlen
)) {
295 ERR("Could not get version value?\n");
300 sprintf(typelibkey
,"Typelib\\%s\\%s\\0\\win32",tlguid
,ver
);
301 tlfnlen
= sizeof(tlfn
);
302 if (RegQueryValueA(HKEY_CLASSES_ROOT
,typelibkey
,tlfn
,&tlfnlen
)) {
303 ERR("Could not get typelib fn?\n");
306 MultiByteToWideChar(CP_ACP
, 0, tlfn
, -1, tlfnW
, sizeof(tlfnW
) / sizeof(tlfnW
[0]));
307 hres
= LoadTypeLib(tlfnW
,&tl
);
309 ERR("Failed to load typelib for %s, but it should be there.\n",debugstr_guid(riid
));
312 hres
= ITypeLib_GetTypeInfoOfGuid(tl
,riid
,ti
);
314 ERR("typelib does not contain info for %s?\n",debugstr_guid(riid
));
315 ITypeLib_Release(tl
);
318 ITypeLib_Release(tl
);
322 /* Determine nr of functions. Since we use the toplevel interface and all
323 * inherited ones have lower numbers, we are ok to not to descent into
324 * the inheritance tree I think.
326 static int _nroffuncs(ITypeInfo
*tinfo
) {
328 const FUNCDESC
*fdesc
;
334 hres
= ITypeInfo_GetTypeAttr(tinfo
, &attr
);
336 ERR("GetTypeAttr failed with %x\n",hres
);
339 /* look in inherited ifaces. */
340 for (j
=0;j
<attr
->cImplTypes
;j
++) {
342 hres
= ITypeInfo_GetRefTypeOfImplType(tinfo
, j
, &href
);
344 ERR("Did not find a reftype for interface offset %d?\n",j
);
347 hres
= ITypeInfo_GetRefTypeInfo(tinfo
, href
, &tinfo2
);
349 ERR("Did not find a typeinfo for reftype %d?\n",href
);
352 n
+= _nroffuncs(tinfo2
);
353 ITypeInfo_Release(tinfo2
);
357 hres
= ITypeInfoImpl_GetInternalFuncDesc(tinfo
,i
,&fdesc
);
368 #include "pshpack1.h"
370 typedef struct _TMAsmProxy
{
384 # warning You need to implement stubless proxies for your architecture
385 typedef struct _TMAsmProxy
{
389 typedef struct _TMProxyImpl
{
391 const IRpcProxyBufferVtbl
*lpvtbl2
;
394 TMAsmProxy
*asmstubs
;
396 IRpcChannelBuffer
* chanbuf
;
398 CRITICAL_SECTION crit
;
399 IUnknown
*outerunknown
;
401 IRpcProxyBuffer
*dispatch_proxy
;
404 static HRESULT WINAPI
405 TMProxyImpl_QueryInterface(LPRPCPROXYBUFFER iface
, REFIID riid
, LPVOID
*ppv
)
408 if (IsEqualIID(riid
,&IID_IUnknown
)||IsEqualIID(riid
,&IID_IRpcProxyBuffer
)) {
409 *ppv
= (LPVOID
)iface
;
410 IRpcProxyBuffer_AddRef(iface
);
413 FIXME("no interface for %s\n",debugstr_guid(riid
));
414 return E_NOINTERFACE
;
418 TMProxyImpl_AddRef(LPRPCPROXYBUFFER iface
)
420 ICOM_THIS_MULTI(TMProxyImpl
,lpvtbl2
,iface
);
421 ULONG refCount
= InterlockedIncrement(&This
->ref
);
423 TRACE("(%p)->(ref before=%u)\n",This
, refCount
- 1);
429 TMProxyImpl_Release(LPRPCPROXYBUFFER iface
)
431 ICOM_THIS_MULTI(TMProxyImpl
,lpvtbl2
,iface
);
432 ULONG refCount
= InterlockedDecrement(&This
->ref
);
434 TRACE("(%p)->(ref before=%u)\n",This
, refCount
+ 1);
438 if (This
->dispatch_proxy
) IRpcProxyBuffer_Release(This
->dispatch_proxy
);
439 DeleteCriticalSection(&This
->crit
);
440 if (This
->chanbuf
) IRpcChannelBuffer_Release(This
->chanbuf
);
441 VirtualFree(This
->asmstubs
, 0, MEM_RELEASE
);
442 HeapFree(GetProcessHeap(), 0, This
->lpvtbl
);
443 ITypeInfo_Release(This
->tinfo
);
449 static HRESULT WINAPI
451 LPRPCPROXYBUFFER iface
,IRpcChannelBuffer
* pRpcChannelBuffer
)
453 ICOM_THIS_MULTI(TMProxyImpl
, lpvtbl2
, iface
);
455 TRACE("(%p)\n", pRpcChannelBuffer
);
457 EnterCriticalSection(&This
->crit
);
459 IRpcChannelBuffer_AddRef(pRpcChannelBuffer
);
460 This
->chanbuf
= pRpcChannelBuffer
;
462 LeaveCriticalSection(&This
->crit
);
464 if (This
->dispatch_proxy
)
465 IRpcProxyBuffer_Connect(This
->dispatch_proxy
, pRpcChannelBuffer
);
471 TMProxyImpl_Disconnect(LPRPCPROXYBUFFER iface
)
473 ICOM_THIS_MULTI(TMProxyImpl
, lpvtbl2
, iface
);
477 EnterCriticalSection(&This
->crit
);
479 IRpcChannelBuffer_Release(This
->chanbuf
);
480 This
->chanbuf
= NULL
;
482 LeaveCriticalSection(&This
->crit
);
484 if (This
->dispatch_proxy
)
485 IRpcProxyBuffer_Disconnect(This
->dispatch_proxy
);
489 static const IRpcProxyBufferVtbl tmproxyvtable
= {
490 TMProxyImpl_QueryInterface
,
494 TMProxyImpl_Disconnect
497 /* how much space do we use on stack in DWORD steps. */
502 return 8/sizeof(DWORD
);
504 return sizeof(double)/sizeof(DWORD
);
506 return sizeof(CY
)/sizeof(DWORD
);
508 return sizeof(DATE
)/sizeof(DWORD
);
510 return (sizeof(VARIANT
)+3)/sizeof(DWORD
);
517 _xsize(TYPEDESC
*td
) {
522 return sizeof(VARIANT
)+3;
525 ARRAYDESC
*adesc
= td
->u
.lpadesc
;
527 for (i
=0;i
<adesc
->cDims
;i
++)
528 arrsize
*= adesc
->rgbounds
[i
].cElements
;
529 return arrsize
*_xsize(&adesc
->tdescElem
);
557 TRACE("(tdesc.vt %s)\n",debugstr_vt(tdesc
->vt
));
560 case VT_EMPTY
: /* nothing. empty variant for instance */
566 if (debugout
) TRACE_(olerelay
)("%x%x\n",arg
[0],arg
[1]);
568 hres
= xbuf_add(buf
,(LPBYTE
)arg
,8);
578 if (debugout
) TRACE_(olerelay
)("%x\n",*arg
);
580 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
585 if (debugout
) TRACE_(olerelay
)("%04x\n",*arg
& 0xffff);
587 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
592 if (debugout
) TRACE_(olerelay
)("%02x\n",*arg
& 0xff);
594 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
598 if (debugout
) TRACE_(olerelay
)("&0x%x\n",*arg
);
600 hres
= xbuf_add(buf
,(LPBYTE
)(DWORD
*)*arg
,sizeof(DWORD
));
601 /* do not dealloc at this time */
605 VARIANT
*vt
= (VARIANT
*)arg
;
606 DWORD vttype
= V_VT(vt
);
608 if (debugout
) TRACE_(olerelay
)("Vt(%s%s)(",debugstr_vt(vttype
),debugstr_vf(vttype
));
611 hres
= xbuf_add(buf
,(LPBYTE
)&vttype
,sizeof(vttype
));
612 if (hres
) return hres
;
614 /* need to recurse since we need to free the stuff */
615 hres
= serialize_param(tinfo
,writeit
,debugout
,dealloc
,&tdesc2
,(DWORD
*)&(V_I4(vt
)),buf
);
616 if (debugout
) TRACE_(olerelay
)(")");
619 case VT_BSTR
|VT_BYREF
: {
620 if (debugout
) TRACE_(olerelay
)("[byref]'%s'", *(BSTR
*)*arg
? relaystr(*((BSTR
*)*arg
)) : "<bstr NULL>");
622 /* ptr to ptr to magic widestring, basically */
623 BSTR
*bstr
= (BSTR
*) *arg
;
626 /* -1 means "null string" which is equivalent to empty string */
628 hres
= xbuf_add(buf
, (LPBYTE
)&len
,sizeof(DWORD
));
629 if (hres
) return hres
;
631 len
= *((DWORD
*)*bstr
-1)/sizeof(WCHAR
);
632 hres
= xbuf_add(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
633 if (hres
) return hres
;
634 hres
= xbuf_add(buf
,(LPBYTE
)*bstr
,len
* sizeof(WCHAR
));
635 if (hres
) return hres
;
639 if (dealloc
&& arg
) {
640 BSTR
*str
= *((BSTR
**)arg
);
649 TRACE_(olerelay
)("%s",relaystr((WCHAR
*)*arg
));
651 TRACE_(olerelay
)("<bstr NULL>");
654 BSTR bstr
= (BSTR
)*arg
;
658 hres
= xbuf_add(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
659 if (hres
) return hres
;
661 len
= *((DWORD
*)bstr
-1)/sizeof(WCHAR
);
662 hres
= xbuf_add(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
663 if (hres
) return hres
;
664 hres
= xbuf_add(buf
,(LPBYTE
)bstr
,len
* sizeof(WCHAR
));
665 if (hres
) return hres
;
670 SysFreeString((BSTR
)*arg
);
675 BOOL derefhere
= TRUE
;
677 if (tdesc
->u
.lptdesc
->vt
== VT_USERDEFINED
) {
681 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.lptdesc
->u
.hreftype
,&tinfo2
);
683 ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc
->u
.lptdesc
->u
.hreftype
);
686 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
687 switch (tattr
->typekind
) {
688 case TKIND_ENUM
: /* confirmed */
689 case TKIND_RECORD
: /* FIXME: mostly untested */
692 case TKIND_ALIAS
: /* FIXME: untested */
693 case TKIND_DISPATCH
: /* will be done in VT_USERDEFINED case */
694 case TKIND_INTERFACE
: /* will be done in VT_USERDEFINED case */
698 FIXME("unhandled switch cases tattr->typekind %d\n", tattr
->typekind
);
702 ITypeInfo_ReleaseTypeAttr(tinfo
, tattr
);
703 ITypeInfo_Release(tinfo2
);
706 if (debugout
) TRACE_(olerelay
)("*");
707 /* Write always, so the other side knows when it gets a NULL pointer.
709 cookie
= *arg
? 0x42424242 : 0;
710 hres
= xbuf_add(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
714 if (debugout
) TRACE_(olerelay
)("NULL");
717 hres
= serialize_param(tinfo
,writeit
,debugout
,dealloc
,tdesc
->u
.lptdesc
,(DWORD
*)*arg
,buf
);
718 if (derefhere
&& dealloc
) HeapFree(GetProcessHeap(),0,(LPVOID
)*arg
);
722 if (debugout
) TRACE_(olerelay
)("unk(0x%x)",*arg
);
724 hres
= _marshal_interface(buf
,&IID_IUnknown
,(LPUNKNOWN
)*arg
);
725 if (dealloc
&& *(IUnknown
**)arg
)
726 IUnknown_Release((LPUNKNOWN
)*arg
);
729 if (debugout
) TRACE_(olerelay
)("idisp(0x%x)",*arg
);
731 hres
= _marshal_interface(buf
,&IID_IDispatch
,(LPUNKNOWN
)*arg
);
732 if (dealloc
&& *(IUnknown
**)arg
)
733 IUnknown_Release((LPUNKNOWN
)*arg
);
736 if (debugout
) TRACE_(olerelay
)("<void>");
738 case VT_USERDEFINED
: {
742 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.hreftype
,&tinfo2
);
744 ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc
->u
.hreftype
);
747 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
748 switch (tattr
->typekind
) {
750 case TKIND_INTERFACE
:
752 hres
=_marshal_interface(buf
,&(tattr
->guid
),(LPUNKNOWN
)arg
);
754 IUnknown_Release((LPUNKNOWN
)arg
);
758 if (debugout
) TRACE_(olerelay
)("{");
759 for (i
=0;i
<tattr
->cVars
;i
++) {
764 hres
= ITypeInfo2_GetVarDesc(tinfo2
, i
, &vdesc
);
766 ERR("Could not get vardesc of %d\n",i
);
769 elem2
= &vdesc
->elemdescVar
;
770 tdesc2
= &elem2
->tdesc
;
771 hres
= serialize_param(
777 (DWORD
*)(((LPBYTE
)arg
)+vdesc
->u
.oInst
),
780 ITypeInfo_ReleaseVarDesc(tinfo2
, vdesc
);
783 if (debugout
&& (i
<(tattr
->cVars
-1)))
784 TRACE_(olerelay
)(",");
786 if (debugout
) TRACE_(olerelay
)("}");
790 hres
= serialize_param(tinfo2
,writeit
,debugout
,dealloc
,&tattr
->tdescAlias
,arg
,buf
);
794 if (debugout
) TRACE_(olerelay
)("%x",*arg
);
796 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
799 FIXME("Unhandled typekind %d\n",tattr
->typekind
);
803 ITypeInfo_ReleaseTypeAttr(tinfo2
, tattr
);
804 ITypeInfo_Release(tinfo2
);
808 ARRAYDESC
*adesc
= tdesc
->u
.lpadesc
;
811 if (debugout
) TRACE_(olerelay
)("carr");
812 for (i
=0;i
<adesc
->cDims
;i
++) {
813 if (debugout
) TRACE_(olerelay
)("[%d]",adesc
->rgbounds
[i
].cElements
);
814 arrsize
*= adesc
->rgbounds
[i
].cElements
;
816 if (debugout
) TRACE_(olerelay
)("(vt %s)",debugstr_vt(adesc
->tdescElem
.vt
));
817 if (debugout
) TRACE_(olerelay
)("[");
818 for (i
=0;i
<arrsize
;i
++) {
819 hres
= serialize_param(tinfo
, writeit
, debugout
, dealloc
, &adesc
->tdescElem
, (DWORD
*)((LPBYTE
)arg
+i
*_xsize(&adesc
->tdescElem
)), buf
);
822 if (debugout
&& (i
<arrsize
-1)) TRACE_(olerelay
)(",");
824 if (debugout
) TRACE_(olerelay
)("]");
830 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
831 ULONG size
= LPSAFEARRAY_UserSize(&flags
, buf
->curoff
, (LPSAFEARRAY
*)arg
);
832 xbuf_resize(buf
, size
);
833 LPSAFEARRAY_UserMarshal(&flags
, buf
->base
+ buf
->curoff
, (LPSAFEARRAY
*)arg
);
839 ERR("Unhandled marshal type %d.\n",tdesc
->vt
);
856 TRACE("vt %s at %p\n",debugstr_vt(tdesc
->vt
),arg
);
861 if (debugout
) TRACE_(olerelay
)("<empty>\n");
864 if (debugout
) TRACE_(olerelay
)("<null>\n");
867 VARIANT
*vt
= (VARIANT
*)arg
;
872 hres
= xbuf_get(buf
,(LPBYTE
)&vttype
,sizeof(vttype
));
874 FIXME("vt type not read?\n");
877 memset(&tdesc2
,0,sizeof(tdesc2
));
880 if (debugout
) TRACE_(olerelay
)("Vt(%s%s)(",debugstr_vt(vttype
),debugstr_vf(vttype
));
881 hres
= deserialize_param(tinfo
, readit
, debugout
, alloc
, &tdesc2
, (DWORD
*)&(V_I4(vt
)), buf
);
882 TRACE_(olerelay
)(")");
893 hres
= xbuf_get(buf
,(LPBYTE
)arg
,8);
894 if (hres
) ERR("Failed to read integer 8 byte\n");
896 if (debugout
) TRACE_(olerelay
)("%x%x",arg
[0],arg
[1]);
906 hres
= xbuf_get(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
907 if (hres
) ERR("Failed to read integer 4 byte\n");
909 if (debugout
) TRACE_(olerelay
)("%x",*arg
);
915 hres
= xbuf_get(buf
,(LPBYTE
)&x
,sizeof(DWORD
));
916 if (hres
) ERR("Failed to read integer 4 byte\n");
919 if (debugout
) TRACE_(olerelay
)("%04x",*arg
& 0xffff);
925 hres
= xbuf_get(buf
,(LPBYTE
)&x
,sizeof(DWORD
));
926 if (hres
) ERR("Failed to read integer 4 byte\n");
929 if (debugout
) TRACE_(olerelay
)("%02x",*arg
& 0xff);
934 *arg
= (DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DWORD
));
936 hres
= xbuf_get(buf
,(LPBYTE
)*arg
,sizeof(DWORD
));
937 if (hres
) ERR("Failed to read integer 4 byte\n");
939 if (debugout
) TRACE_(olerelay
)("&0x%x",*(DWORD
*)*arg
);
941 case VT_BSTR
|VT_BYREF
: {
942 BSTR
**bstr
= (BSTR
**)arg
;
947 hres
= xbuf_get(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
949 ERR("failed to read bstr klen\n");
953 *bstr
= CoTaskMemAlloc(sizeof(BSTR
*));
955 if (debugout
) TRACE_(olerelay
)("<bstr NULL>");
957 str
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,(len
+1)*sizeof(WCHAR
));
958 hres
= xbuf_get(buf
,(LPBYTE
)str
,len
*sizeof(WCHAR
));
960 ERR("Failed to read BSTR.\n");
963 *bstr
= CoTaskMemAlloc(sizeof(BSTR
*));
964 **bstr
= SysAllocStringLen(str
,len
);
965 if (debugout
) TRACE_(olerelay
)("%s",relaystr(str
));
966 HeapFree(GetProcessHeap(),0,str
);
978 hres
= xbuf_get(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
980 ERR("failed to read bstr klen\n");
985 if (debugout
) TRACE_(olerelay
)("<bstr NULL>");
987 str
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,(len
+1)*sizeof(WCHAR
));
988 hres
= xbuf_get(buf
,(LPBYTE
)str
,len
*sizeof(WCHAR
));
990 ERR("Failed to read BSTR.\n");
993 *arg
= (DWORD
)SysAllocStringLen(str
,len
);
994 if (debugout
) TRACE_(olerelay
)("%s",relaystr(str
));
995 HeapFree(GetProcessHeap(),0,str
);
1004 BOOL derefhere
= TRUE
;
1006 if (tdesc
->u
.lptdesc
->vt
== VT_USERDEFINED
) {
1010 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.lptdesc
->u
.hreftype
,&tinfo2
);
1012 ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc
->u
.lptdesc
->u
.hreftype
);
1015 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
1016 switch (tattr
->typekind
) {
1017 case TKIND_ENUM
: /* confirmed */
1018 case TKIND_RECORD
: /* FIXME: mostly untested */
1021 case TKIND_ALIAS
: /* FIXME: untested */
1022 case TKIND_DISPATCH
: /* will be done in VT_USERDEFINED case */
1023 case TKIND_INTERFACE
: /* will be done in VT_USERDEFINED case */
1027 FIXME("unhandled switch cases tattr->typekind %d\n", tattr
->typekind
);
1031 ITypeInfo_ReleaseTypeAttr(tinfo2
, tattr
);
1032 ITypeInfo_Release(tinfo2
);
1034 /* read it in all cases, we need to know if we have
1035 * NULL pointer or not.
1037 hres
= xbuf_get(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
1039 ERR("Failed to load pointer cookie.\n");
1042 if (cookie
!= 0x42424242) {
1043 /* we read a NULL ptr from the remote side */
1044 if (debugout
) TRACE_(olerelay
)("NULL");
1048 if (debugout
) TRACE_(olerelay
)("*");
1050 /* Allocate space for the referenced struct */
1052 *arg
=(DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,_xsize(tdesc
->u
.lptdesc
));
1055 return deserialize_param(tinfo
, readit
, debugout
, alloc
, tdesc
->u
.lptdesc
, (LPDWORD
)*arg
, buf
);
1057 return deserialize_param(tinfo
, readit
, debugout
, alloc
, tdesc
->u
.lptdesc
, arg
, buf
);
1060 /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
1062 *arg
=(DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DWORD
));
1065 hres
= _unmarshal_interface(buf
,&IID_IUnknown
,(LPUNKNOWN
*)arg
);
1067 TRACE_(olerelay
)("unk(%p)",arg
);
1072 hres
= _unmarshal_interface(buf
,&IID_IDispatch
,(LPUNKNOWN
*)arg
);
1074 TRACE_(olerelay
)("idisp(%p)",arg
);
1077 if (debugout
) TRACE_(olerelay
)("<void>");
1079 case VT_USERDEFINED
: {
1083 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.hreftype
,&tinfo2
);
1085 ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc
->u
.hreftype
);
1088 hres
= ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
1090 ERR("Could not get typeattr in VT_USERDEFINED.\n");
1092 switch (tattr
->typekind
) {
1093 case TKIND_DISPATCH
:
1094 case TKIND_INTERFACE
:
1096 hres
= _unmarshal_interface(buf
,&(tattr
->guid
),(LPUNKNOWN
*)arg
);
1098 case TKIND_RECORD
: {
1102 *arg
= (DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,tattr
->cbSizeInstance
);
1104 if (debugout
) TRACE_(olerelay
)("{");
1105 for (i
=0;i
<tattr
->cVars
;i
++) {
1108 hres
= ITypeInfo2_GetVarDesc(tinfo2
, i
, &vdesc
);
1110 ERR("Could not get vardesc of %d\n",i
);
1111 ITypeInfo_ReleaseTypeAttr(tinfo2
, tattr
);
1112 ITypeInfo_Release(tinfo2
);
1115 hres
= deserialize_param(
1120 &vdesc
->elemdescVar
.tdesc
,
1121 (DWORD
*)(((LPBYTE
)*arg
)+vdesc
->u
.oInst
),
1124 ITypeInfo2_ReleaseVarDesc(tinfo2
, vdesc
);
1125 if (debugout
&& (i
<tattr
->cVars
-1)) TRACE_(olerelay
)(",");
1127 if (debugout
) TRACE_(olerelay
)("}");
1131 hres
= deserialize_param(tinfo2
,readit
,debugout
,alloc
,&tattr
->tdescAlias
,arg
,buf
);
1135 hres
= xbuf_get(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
1136 if (hres
) ERR("Failed to read enum (4 byte)\n");
1138 if (debugout
) TRACE_(olerelay
)("%x",*arg
);
1141 ERR("Unhandled typekind %d\n",tattr
->typekind
);
1145 ITypeInfo_ReleaseTypeAttr(tinfo2
, tattr
);
1148 ERR("failed to stuballoc in TKIND_RECORD.\n");
1149 ITypeInfo_Release(tinfo2
);
1153 /* arg is pointing to the start of the array. */
1154 ARRAYDESC
*adesc
= tdesc
->u
.lpadesc
;
1157 if (adesc
->cDims
> 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
1158 for (i
=0;i
<adesc
->cDims
;i
++)
1159 arrsize
*= adesc
->rgbounds
[i
].cElements
;
1160 for (i
=0;i
<arrsize
;i
++)
1167 (DWORD
*)((LPBYTE
)(arg
)+i
*_xsize(&adesc
->tdescElem
)),
1172 case VT_SAFEARRAY
: {
1175 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
1176 unsigned char *buffer
;
1177 buffer
= LPSAFEARRAY_UserUnmarshal(&flags
, buf
->base
+ buf
->curoff
, (LPSAFEARRAY
*)arg
);
1178 buf
->curoff
= buffer
- buf
->base
;
1183 ERR("No handler for VT type %d!\n",tdesc
->vt
);
1189 /* Searches function, also in inherited interfaces */
1192 ITypeInfo
*tinfo
, int iMethod
, ITypeInfo
**tactual
, const FUNCDESC
**fdesc
, BSTR
*iname
, BSTR
*fname
)
1197 if (fname
) *fname
= NULL
;
1198 if (iname
) *iname
= NULL
;
1201 hres
= ITypeInfoImpl_GetInternalFuncDesc(tinfo
, i
, fdesc
);
1208 hres
= ITypeInfo_GetTypeAttr(tinfo
, &attr
);
1210 ERR("GetTypeAttr failed with %x\n",hres
);
1213 /* Not found, so look in inherited ifaces. */
1214 for (j
=0;j
<attr
->cImplTypes
;j
++) {
1215 hres
= ITypeInfo_GetRefTypeOfImplType(tinfo
, j
, &href
);
1217 ERR("Did not find a reftype for interface offset %d?\n",j
);
1220 hres
= ITypeInfo_GetRefTypeInfo(tinfo
, href
, &tinfo2
);
1222 ERR("Did not find a typeinfo for reftype %d?\n",href
);
1225 hres
= _get_funcdesc(tinfo2
,iMethod
,tactual
,fdesc
,iname
,fname
);
1226 ITypeInfo_Release(tinfo2
);
1228 ITypeInfo_ReleaseTypeAttr(tinfo
, attr
);
1232 ITypeInfo_ReleaseTypeAttr(tinfo
, attr
);
1235 if (((*fdesc
)->oVft
/4) == iMethod
) {
1237 ITypeInfo_GetDocumentation(tinfo
,(*fdesc
)->memid
,fname
,NULL
,NULL
,NULL
);
1239 ITypeInfo_GetDocumentation(tinfo
,-1,iname
,NULL
,NULL
,NULL
);
1241 ITypeInfo_AddRef(*tactual
);
1249 xCall(LPVOID retptr
, int method
, TMProxyImpl
*tpinfo
/*, args */)
1251 DWORD
*args
= ((DWORD
*)&tpinfo
)+1, *xargs
;
1252 const FUNCDESC
*fdesc
;
1254 int i
, relaydeb
= TRACE_ON(olerelay
);
1261 DWORD remoteresult
= 0;
1263 IRpcChannelBuffer
*chanbuf
;
1265 EnterCriticalSection(&tpinfo
->crit
);
1267 hres
= _get_funcdesc(tpinfo
->tinfo
,method
,&tinfo
,&fdesc
,&iname
,&fname
);
1269 ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method
);
1270 ITypeInfo_Release(tinfo
);
1271 LeaveCriticalSection(&tpinfo
->crit
);
1275 if (!tpinfo
->chanbuf
)
1277 WARN("Tried to use disconnected proxy\n");
1278 ITypeInfo_Release(tinfo
);
1279 LeaveCriticalSection(&tpinfo
->crit
);
1280 return RPC_E_DISCONNECTED
;
1282 chanbuf
= tpinfo
->chanbuf
;
1283 IRpcChannelBuffer_AddRef(chanbuf
);
1285 LeaveCriticalSection(&tpinfo
->crit
);
1288 TRACE_(olerelay
)("->");
1290 TRACE_(olerelay
)("%s:",relaystr(iname
));
1292 TRACE_(olerelay
)("%s(%d)",relaystr(fname
),method
);
1294 TRACE_(olerelay
)("%d",method
);
1295 TRACE_(olerelay
)("(");
1298 if (iname
) SysFreeString(iname
);
1299 if (fname
) SysFreeString(fname
);
1301 memset(&buf
,0,sizeof(buf
));
1303 /* normal typelib driven serializing */
1305 /* Need them for hack below */
1306 memset(names
,0,sizeof(names
));
1307 if (ITypeInfo_GetNames(tinfo
,fdesc
->memid
,names
,sizeof(names
)/sizeof(names
[0]),&nrofnames
))
1309 if (nrofnames
> sizeof(names
)/sizeof(names
[0]))
1310 ERR("Need more names!\n");
1313 for (i
=0;i
<fdesc
->cParams
;i
++) {
1314 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1316 if (i
) TRACE_(olerelay
)(",");
1317 if (i
+1<nrofnames
&& names
[i
+1])
1318 TRACE_(olerelay
)("%s=",relaystr(names
[i
+1]));
1320 /* No need to marshal other data than FIN and any VT_PTR. */
1321 if (!(elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
|| !elem
->u
.paramdesc
.wParamFlags
) && (elem
->tdesc
.vt
!= VT_PTR
)) {
1322 xargs
+=_argsize(elem
->tdesc
.vt
);
1323 if (relaydeb
) TRACE_(olerelay
)("[out]");
1326 hres
= serialize_param(
1328 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
|| !elem
->u
.paramdesc
.wParamFlags
,
1337 ERR("Failed to serialize param, hres %x\n",hres
);
1340 xargs
+=_argsize(elem
->tdesc
.vt
);
1342 if (relaydeb
) TRACE_(olerelay
)(")");
1344 memset(&msg
,0,sizeof(msg
));
1345 msg
.cbBuffer
= buf
.curoff
;
1346 msg
.iMethod
= method
;
1347 hres
= IRpcChannelBuffer_GetBuffer(chanbuf
,&msg
,&(tpinfo
->iid
));
1349 ERR("RpcChannelBuffer GetBuffer failed, %x\n",hres
);
1352 memcpy(msg
.Buffer
,buf
.base
,buf
.curoff
);
1353 if (relaydeb
) TRACE_(olerelay
)("\n");
1354 hres
= IRpcChannelBuffer_SendReceive(chanbuf
,&msg
,&status
);
1356 ERR("RpcChannelBuffer SendReceive failed, %x\n",hres
);
1360 if (relaydeb
) TRACE_(olerelay
)(" status = %08x (",status
);
1362 buf
.base
= HeapReAlloc(GetProcessHeap(),0,buf
.base
,msg
.cbBuffer
);
1364 buf
.base
= HeapAlloc(GetProcessHeap(),0,msg
.cbBuffer
);
1365 buf
.size
= msg
.cbBuffer
;
1366 memcpy(buf
.base
,msg
.Buffer
,buf
.size
);
1369 /* generic deserializer using typelib description */
1372 for (i
=0;i
<fdesc
->cParams
;i
++) {
1373 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1376 if (i
) TRACE_(olerelay
)(",");
1377 if (i
+1<nrofnames
&& names
[i
+1]) TRACE_(olerelay
)("%s=",relaystr(names
[i
+1]));
1379 /* No need to marshal other data than FOUT and any VT_PTR */
1380 if (!(elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
) && (elem
->tdesc
.vt
!= VT_PTR
)) {
1381 xargs
+= _argsize(elem
->tdesc
.vt
);
1382 if (relaydeb
) TRACE_(olerelay
)("[in]");
1385 hres
= deserialize_param(
1387 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
1395 ERR("Failed to unmarshall param, hres %x\n",hres
);
1399 xargs
+= _argsize(elem
->tdesc
.vt
);
1402 hres
= xbuf_get(&buf
, (LPBYTE
)&remoteresult
, sizeof(DWORD
));
1405 if (relaydeb
) TRACE_(olerelay
)(") = %08x\n", remoteresult
);
1407 hres
= remoteresult
;
1410 for (i
= 0; i
< nrofnames
; i
++)
1411 SysFreeString(names
[i
]);
1412 HeapFree(GetProcessHeap(),0,buf
.base
);
1413 IRpcChannelBuffer_Release(chanbuf
);
1414 ITypeInfo_Release(tinfo
);
1415 TRACE("-- 0x%08x\n", hres
);
1419 static HRESULT WINAPI
ProxyIUnknown_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
1421 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1423 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
1425 if (proxy
->outerunknown
)
1426 return IUnknown_QueryInterface(proxy
->outerunknown
, riid
, ppv
);
1428 FIXME("No interface\n");
1429 return E_NOINTERFACE
;
1432 static ULONG WINAPI
ProxyIUnknown_AddRef(IUnknown
*iface
)
1434 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1438 if (proxy
->outerunknown
)
1439 return IUnknown_AddRef(proxy
->outerunknown
);
1441 return 2; /* FIXME */
1444 static ULONG WINAPI
ProxyIUnknown_Release(IUnknown
*iface
)
1446 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1450 if (proxy
->outerunknown
)
1451 return IUnknown_Release(proxy
->outerunknown
);
1453 return 1; /* FIXME */
1456 static HRESULT WINAPI
ProxyIDispatch_GetTypeInfoCount(LPDISPATCH iface
, UINT
* pctinfo
)
1458 TMProxyImpl
*This
= (TMProxyImpl
*)iface
;
1460 TRACE("(%p)\n", pctinfo
);
1462 return IDispatch_GetTypeInfoCount(This
->dispatch
, pctinfo
);
1465 static HRESULT WINAPI
ProxyIDispatch_GetTypeInfo(LPDISPATCH iface
, UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
1467 TMProxyImpl
*This
= (TMProxyImpl
*)iface
;
1469 TRACE("(%d, %x, %p)\n", iTInfo
, lcid
, ppTInfo
);
1471 return IDispatch_GetTypeInfo(This
->dispatch
, iTInfo
, lcid
, ppTInfo
);
1474 static HRESULT WINAPI
ProxyIDispatch_GetIDsOfNames(LPDISPATCH iface
, REFIID riid
, LPOLESTR
* rgszNames
, UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
1476 TMProxyImpl
*This
= (TMProxyImpl
*)iface
;
1478 TRACE("(%s, %p, %d, 0x%x, %p)\n", debugstr_guid(riid
), rgszNames
, cNames
, lcid
, rgDispId
);
1480 return IDispatch_GetIDsOfNames(This
->dispatch
, riid
, rgszNames
,
1481 cNames
, lcid
, rgDispId
);
1484 static HRESULT WINAPI
ProxyIDispatch_Invoke(LPDISPATCH iface
, DISPID dispIdMember
, REFIID riid
, LCID lcid
,
1485 WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
,
1486 EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
1488 TMProxyImpl
*This
= (TMProxyImpl
*)iface
;
1490 TRACE("(%d, %s, 0x%x, 0x%x, %p, %p, %p, %p)\n", dispIdMember
,
1491 debugstr_guid(riid
), lcid
, wFlags
, pDispParams
, pVarResult
,
1492 pExcepInfo
, puArgErr
);
1494 return IDispatch_Invoke(This
->dispatch
, dispIdMember
, riid
, lcid
,
1495 wFlags
, pDispParams
, pVarResult
, pExcepInfo
,
1499 static inline HRESULT
get_facbuf_for_iid(REFIID riid
, IPSFactoryBuffer
**facbuf
)
1504 if ((hr
= CoGetPSClsid(riid
, &clsid
)))
1506 return CoGetClassObject(&clsid
, CLSCTX_INPROC_SERVER
, NULL
,
1507 &IID_IPSFactoryBuffer
, (LPVOID
*)facbuf
);
1510 static HRESULT WINAPI
1511 PSFacBuf_CreateProxy(
1512 LPPSFACTORYBUFFER iface
, IUnknown
* pUnkOuter
, REFIID riid
,
1513 IRpcProxyBuffer
**ppProxy
, LPVOID
*ppv
)
1518 const FUNCDESC
*fdesc
;
1522 TRACE("(...%s...)\n",debugstr_guid(riid
));
1523 hres
= _get_typeinfo_for_iid(riid
,&tinfo
);
1525 ERR("No typeinfo for %s?\n",debugstr_guid(riid
));
1528 nroffuncs
= _nroffuncs(tinfo
);
1529 proxy
= CoTaskMemAlloc(sizeof(TMProxyImpl
));
1530 if (!proxy
) return E_OUTOFMEMORY
;
1532 assert(sizeof(TMAsmProxy
) == 12);
1534 proxy
->dispatch
= NULL
;
1535 proxy
->dispatch_proxy
= NULL
;
1536 proxy
->outerunknown
= pUnkOuter
;
1537 proxy
->asmstubs
= VirtualAlloc(NULL
, sizeof(TMAsmProxy
) * nroffuncs
, MEM_COMMIT
, PAGE_EXECUTE_READWRITE
);
1538 if (!proxy
->asmstubs
) {
1539 ERR("Could not commit pages for proxy thunks\n");
1540 CoTaskMemFree(proxy
);
1541 return E_OUTOFMEMORY
;
1543 proxy
->lpvtbl2
= &tmproxyvtable
;
1544 /* one reference for the proxy */
1546 proxy
->tinfo
= tinfo
;
1547 memcpy(&proxy
->iid
,riid
,sizeof(*riid
));
1550 InitializeCriticalSection(&proxy
->crit
);
1552 proxy
->lpvtbl
= HeapAlloc(GetProcessHeap(),0,sizeof(LPBYTE
)*nroffuncs
);
1553 for (i
=0;i
<nroffuncs
;i
++) {
1554 TMAsmProxy
*xasm
= proxy
->asmstubs
+i
;
1558 proxy
->lpvtbl
[i
] = ProxyIUnknown_QueryInterface
;
1561 proxy
->lpvtbl
[i
] = ProxyIUnknown_AddRef
;
1564 proxy
->lpvtbl
[i
] = ProxyIUnknown_Release
;
1568 /* nrofargs without This */
1571 hres
= _get_funcdesc(tinfo
,i
,&tinfo2
,&fdesc
,NULL
,NULL
);
1572 ITypeInfo_Release(tinfo2
);
1574 ERR("GetFuncDesc %x should not fail here.\n",hres
);
1577 /* some args take more than 4 byte on the stack */
1579 for (j
=0;j
<fdesc
->cParams
;j
++)
1580 nrofargs
+= _argsize(fdesc
->lprgelemdescParam
[j
].tdesc
.vt
);
1583 if (fdesc
->callconv
!= CC_STDCALL
) {
1584 ERR("calling convention is not stdcall????\n");
1587 /* popl %eax - return ptr
1594 * arg3 arg2 arg1 <method> <returnptr>
1596 xasm
->popleax
= 0x58;
1597 xasm
->pushlval
= 0x6a;
1599 xasm
->pushleax
= 0x50;
1600 xasm
->lcall
= 0xe8; /* relative jump */
1601 xasm
->xcall
= (DWORD
)xCall
;
1602 xasm
->xcall
-= (DWORD
)&(xasm
->lret
);
1604 xasm
->bytestopop
= (nrofargs
+2)*4; /* pop args, This, iMethod */
1605 proxy
->lpvtbl
[i
] = xasm
;
1608 FIXME("not implemented on non i386\n");
1615 /* if we derive from IDispatch then defer to its proxy for its methods */
1616 hres
= ITypeInfo_GetTypeAttr(tinfo
, &typeattr
);
1619 if (typeattr
->wTypeFlags
& TYPEFLAG_FDISPATCHABLE
)
1621 IPSFactoryBuffer
*factory_buffer
;
1622 hres
= get_facbuf_for_iid(&IID_IDispatch
, &factory_buffer
);
1625 hres
= IPSFactoryBuffer_CreateProxy(factory_buffer
, NULL
,
1626 &IID_IDispatch
, &proxy
->dispatch_proxy
,
1627 (void **)&proxy
->dispatch
);
1628 IPSFactoryBuffer_Release(factory_buffer
);
1630 if ((hres
== S_OK
) && (nroffuncs
< 7))
1632 ERR("nroffuncs calculated incorrectly (%d)\n", nroffuncs
);
1633 hres
= E_UNEXPECTED
;
1637 proxy
->lpvtbl
[3] = ProxyIDispatch_GetTypeInfoCount
;
1638 proxy
->lpvtbl
[4] = ProxyIDispatch_GetTypeInfo
;
1639 proxy
->lpvtbl
[5] = ProxyIDispatch_GetIDsOfNames
;
1640 proxy
->lpvtbl
[6] = ProxyIDispatch_Invoke
;
1643 ITypeInfo_ReleaseTypeAttr(tinfo
, typeattr
);
1648 *ppv
= (LPVOID
)proxy
;
1649 *ppProxy
= (IRpcProxyBuffer
*)&(proxy
->lpvtbl2
);
1650 IUnknown_AddRef((IUnknown
*)*ppv
);
1654 TMProxyImpl_Release((IRpcProxyBuffer
*)&proxy
->lpvtbl2
);
1658 typedef struct _TMStubImpl
{
1659 const IRpcStubBufferVtbl
*lpvtbl
;
1665 IRpcStubBuffer
*dispatch_stub
;
1666 BOOL dispatch_derivative
;
1669 static HRESULT WINAPI
1670 TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface
, REFIID riid
, LPVOID
*ppv
)
1672 if (IsEqualIID(riid
,&IID_IRpcStubBuffer
)||IsEqualIID(riid
,&IID_IUnknown
)){
1673 *ppv
= (LPVOID
)iface
;
1674 IRpcStubBuffer_AddRef(iface
);
1677 FIXME("%s, not supported IID.\n",debugstr_guid(riid
));
1678 return E_NOINTERFACE
;
1682 TMStubImpl_AddRef(LPRPCSTUBBUFFER iface
)
1684 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1685 ULONG refCount
= InterlockedIncrement(&This
->ref
);
1687 TRACE("(%p)->(ref before=%u)\n", This
, refCount
- 1);
1693 TMStubImpl_Release(LPRPCSTUBBUFFER iface
)
1695 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1696 ULONG refCount
= InterlockedDecrement(&This
->ref
);
1698 TRACE("(%p)->(ref before=%u)\n", This
, refCount
+ 1);
1702 IRpcStubBuffer_Disconnect(iface
);
1703 ITypeInfo_Release(This
->tinfo
);
1704 if (This
->dispatch_stub
)
1705 IRpcStubBuffer_Release(This
->dispatch_stub
);
1706 CoTaskMemFree(This
);
1711 static HRESULT WINAPI
1712 TMStubImpl_Connect(LPRPCSTUBBUFFER iface
, LPUNKNOWN pUnkServer
)
1714 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1716 TRACE("(%p)->(%p)\n", This
, pUnkServer
);
1718 IUnknown_AddRef(pUnkServer
);
1719 This
->pUnk
= pUnkServer
;
1721 if (This
->dispatch_stub
)
1722 IRpcStubBuffer_Connect(This
->dispatch_stub
, pUnkServer
);
1728 TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface
)
1730 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1732 TRACE("(%p)->()\n", This
);
1736 IUnknown_Release(This
->pUnk
);
1740 if (This
->dispatch_stub
)
1741 IRpcStubBuffer_Disconnect(This
->dispatch_stub
);
1744 static HRESULT WINAPI
1746 LPRPCSTUBBUFFER iface
, RPCOLEMESSAGE
* xmsg
,IRpcChannelBuffer
*rpcchanbuf
)
1749 const FUNCDESC
*fdesc
;
1750 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1752 DWORD
*args
= NULL
, res
, *xargs
, nrofargs
;
1757 ITypeInfo
*tinfo
= NULL
;
1761 if (xmsg
->iMethod
< 3) {
1762 ERR("IUnknown methods cannot be marshaled by the typelib marshaler\n");
1763 return E_UNEXPECTED
;
1766 if (This
->dispatch_derivative
&& xmsg
->iMethod
< sizeof(IDispatchVtbl
)/sizeof(void *))
1768 IPSFactoryBuffer
*factory_buffer
;
1769 hres
= get_facbuf_for_iid(&IID_IDispatch
, &factory_buffer
);
1772 hres
= IPSFactoryBuffer_CreateStub(factory_buffer
, &IID_IDispatch
,
1773 This
->pUnk
, &This
->dispatch_stub
);
1774 IPSFactoryBuffer_Release(factory_buffer
);
1778 return IRpcStubBuffer_Invoke(This
->dispatch_stub
, xmsg
, rpcchanbuf
);
1781 memset(&buf
,0,sizeof(buf
));
1782 buf
.size
= xmsg
->cbBuffer
;
1783 buf
.base
= HeapAlloc(GetProcessHeap(), 0, xmsg
->cbBuffer
);
1784 memcpy(buf
.base
, xmsg
->Buffer
, xmsg
->cbBuffer
);
1787 hres
= _get_funcdesc(This
->tinfo
,xmsg
->iMethod
,&tinfo
,&fdesc
,&iname
,NULL
);
1789 ERR("GetFuncDesc on method %d failed with %x\n",xmsg
->iMethod
,hres
);
1793 if (iname
&& !lstrcmpW(iname
, IDispatchW
))
1795 ERR("IDispatch cannot be marshaled by the typelib marshaler\n");
1796 hres
= E_UNEXPECTED
;
1797 SysFreeString (iname
);
1801 if (iname
) SysFreeString (iname
);
1803 /* Need them for hack below */
1804 memset(names
,0,sizeof(names
));
1805 ITypeInfo_GetNames(tinfo
,fdesc
->memid
,names
,sizeof(names
)/sizeof(names
[0]),&nrofnames
);
1806 if (nrofnames
> sizeof(names
)/sizeof(names
[0])) {
1807 ERR("Need more names!\n");
1810 /*dump_FUNCDESC(fdesc);*/
1812 for (i
=0;i
<fdesc
->cParams
;i
++)
1813 nrofargs
+= _argsize(fdesc
->lprgelemdescParam
[i
].tdesc
.vt
);
1814 args
= HeapAlloc(GetProcessHeap(),0,(nrofargs
+1)*sizeof(DWORD
));
1817 hres
= E_OUTOFMEMORY
;
1821 /* Allocate all stuff used by call. */
1823 for (i
=0;i
<fdesc
->cParams
;i
++) {
1824 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1826 hres
= deserialize_param(
1828 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
|| !elem
->u
.paramdesc
.wParamFlags
,
1835 xargs
+= _argsize(elem
->tdesc
.vt
);
1837 ERR("Failed to deserialize param %s, hres %x\n",relaystr(names
[i
+1]),hres
);
1842 args
[0] = (DWORD
)This
->pUnk
;
1847 (*((FARPROC
**)args
[0]))[fdesc
->oVft
/4],
1855 DWORD dwExceptionCode
= GetExceptionCode();
1856 ERR("invoke call failed with exception 0x%08x (%d)\n", dwExceptionCode
, dwExceptionCode
);
1857 if (FAILED(dwExceptionCode
))
1858 hres
= dwExceptionCode
;
1860 hres
= HRESULT_FROM_WIN32(dwExceptionCode
);
1870 for (i
=0;i
<fdesc
->cParams
;i
++) {
1871 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1872 hres
= serialize_param(
1874 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
1881 xargs
+= _argsize(elem
->tdesc
.vt
);
1883 ERR("Failed to stuballoc param, hres %x\n",hres
);
1888 hres
= xbuf_add (&buf
, (LPBYTE
)&res
, sizeof(DWORD
));
1893 xmsg
->cbBuffer
= buf
.curoff
;
1894 hres
= IRpcChannelBuffer_GetBuffer(rpcchanbuf
, xmsg
, &This
->iid
);
1896 ERR("IRpcChannelBuffer_GetBuffer failed with error 0x%08x\n", hres
);
1899 memcpy(xmsg
->Buffer
, buf
.base
, buf
.curoff
);
1902 for (i
= 0; i
< nrofnames
; i
++)
1903 SysFreeString(names
[i
]);
1905 ITypeInfo_Release(tinfo
);
1906 HeapFree(GetProcessHeap(), 0, args
);
1908 HeapFree(GetProcessHeap(), 0, buf
.base
);
1910 TRACE("returning\n");
1914 static LPRPCSTUBBUFFER WINAPI
1915 TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface
, REFIID riid
) {
1916 FIXME("Huh (%s)?\n",debugstr_guid(riid
));
1921 TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface
) {
1922 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1925 return This
->ref
; /*FIXME? */
1928 static HRESULT WINAPI
1929 TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface
, LPVOID
*ppv
) {
1934 TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface
, LPVOID ppv
) {
1938 static const IRpcStubBufferVtbl tmstubvtbl
= {
1939 TMStubImpl_QueryInterface
,
1943 TMStubImpl_Disconnect
,
1945 TMStubImpl_IsIIDSupported
,
1946 TMStubImpl_CountRefs
,
1947 TMStubImpl_DebugServerQueryInterface
,
1948 TMStubImpl_DebugServerRelease
1951 static HRESULT WINAPI
1952 PSFacBuf_CreateStub(
1953 LPPSFACTORYBUFFER iface
, REFIID riid
,IUnknown
*pUnkServer
,
1954 IRpcStubBuffer
** ppStub
1961 TRACE("(%s,%p,%p)\n",debugstr_guid(riid
),pUnkServer
,ppStub
);
1963 hres
= _get_typeinfo_for_iid(riid
,&tinfo
);
1965 ERR("No typeinfo for %s?\n",debugstr_guid(riid
));
1969 stub
= CoTaskMemAlloc(sizeof(TMStubImpl
));
1971 return E_OUTOFMEMORY
;
1972 stub
->lpvtbl
= &tmstubvtbl
;
1974 stub
->tinfo
= tinfo
;
1975 stub
->dispatch_stub
= NULL
;
1976 stub
->dispatch_derivative
= FALSE
;
1977 memcpy(&(stub
->iid
),riid
,sizeof(*riid
));
1978 hres
= IRpcStubBuffer_Connect((LPRPCSTUBBUFFER
)stub
,pUnkServer
);
1979 *ppStub
= (LPRPCSTUBBUFFER
)stub
;
1980 TRACE("IRpcStubBuffer: %p\n", stub
);
1982 ERR("Connect to pUnkServer failed?\n");
1984 /* if we derive from IDispatch then defer to its stub for some of its methods */
1985 hres
= ITypeInfo_GetTypeAttr(tinfo
, &typeattr
);
1988 if (typeattr
->wTypeFlags
& TYPEFLAG_FDISPATCHABLE
)
1989 stub
->dispatch_derivative
= TRUE
;
1990 ITypeInfo_ReleaseTypeAttr(tinfo
, typeattr
);
1996 static const IPSFactoryBufferVtbl psfacbufvtbl
= {
1997 PSFacBuf_QueryInterface
,
2000 PSFacBuf_CreateProxy
,
2004 /* This is the whole PSFactoryBuffer object, just the vtableptr */
2005 static const IPSFactoryBufferVtbl
*lppsfac
= &psfacbufvtbl
;
2007 /***********************************************************************
2008 * TMARSHAL_DllGetClassObject
2010 HRESULT
TMARSHAL_DllGetClassObject(REFCLSID rclsid
, REFIID iid
,LPVOID
*ppv
)
2012 if (IsEqualIID(iid
,&IID_IPSFactoryBuffer
)) {
2016 return E_NOINTERFACE
;