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
;
333 hres
= ITypeInfoImpl_GetInternalFuncDesc(tinfo
,n
,&fdesc
);
336 if (fdesc
->oVft
/4 > max
)
345 #include "pshpack1.h"
347 typedef struct _TMAsmProxy
{
361 # warning You need to implement stubless proxies for your architecture
362 typedef struct _TMAsmProxy
{
366 typedef struct _TMProxyImpl
{
368 const IRpcProxyBufferVtbl
*lpvtbl2
;
371 TMAsmProxy
*asmstubs
;
373 IRpcChannelBuffer
* chanbuf
;
375 CRITICAL_SECTION crit
;
376 IUnknown
*outerunknown
;
378 IRpcProxyBuffer
*dispatch_proxy
;
381 static HRESULT WINAPI
382 TMProxyImpl_QueryInterface(LPRPCPROXYBUFFER iface
, REFIID riid
, LPVOID
*ppv
)
385 if (IsEqualIID(riid
,&IID_IUnknown
)||IsEqualIID(riid
,&IID_IRpcProxyBuffer
)) {
386 *ppv
= (LPVOID
)iface
;
387 IRpcProxyBuffer_AddRef(iface
);
390 FIXME("no interface for %s\n",debugstr_guid(riid
));
391 return E_NOINTERFACE
;
395 TMProxyImpl_AddRef(LPRPCPROXYBUFFER iface
)
397 ICOM_THIS_MULTI(TMProxyImpl
,lpvtbl2
,iface
);
398 ULONG refCount
= InterlockedIncrement(&This
->ref
);
400 TRACE("(%p)->(ref before=%u)\n",This
, refCount
- 1);
406 TMProxyImpl_Release(LPRPCPROXYBUFFER iface
)
408 ICOM_THIS_MULTI(TMProxyImpl
,lpvtbl2
,iface
);
409 ULONG refCount
= InterlockedDecrement(&This
->ref
);
411 TRACE("(%p)->(ref before=%u)\n",This
, refCount
+ 1);
415 if (This
->dispatch_proxy
) IRpcProxyBuffer_Release(This
->dispatch_proxy
);
416 DeleteCriticalSection(&This
->crit
);
417 if (This
->chanbuf
) IRpcChannelBuffer_Release(This
->chanbuf
);
418 VirtualFree(This
->asmstubs
, 0, MEM_RELEASE
);
419 HeapFree(GetProcessHeap(), 0, This
->lpvtbl
);
420 ITypeInfo_Release(This
->tinfo
);
426 static HRESULT WINAPI
428 LPRPCPROXYBUFFER iface
,IRpcChannelBuffer
* pRpcChannelBuffer
)
430 ICOM_THIS_MULTI(TMProxyImpl
, lpvtbl2
, iface
);
432 TRACE("(%p)\n", pRpcChannelBuffer
);
434 EnterCriticalSection(&This
->crit
);
436 IRpcChannelBuffer_AddRef(pRpcChannelBuffer
);
437 This
->chanbuf
= pRpcChannelBuffer
;
439 LeaveCriticalSection(&This
->crit
);
441 if (This
->dispatch_proxy
)
442 IRpcProxyBuffer_Connect(This
->dispatch_proxy
, pRpcChannelBuffer
);
448 TMProxyImpl_Disconnect(LPRPCPROXYBUFFER iface
)
450 ICOM_THIS_MULTI(TMProxyImpl
, lpvtbl2
, iface
);
454 EnterCriticalSection(&This
->crit
);
456 IRpcChannelBuffer_Release(This
->chanbuf
);
457 This
->chanbuf
= NULL
;
459 LeaveCriticalSection(&This
->crit
);
461 if (This
->dispatch_proxy
)
462 IRpcProxyBuffer_Disconnect(This
->dispatch_proxy
);
466 static const IRpcProxyBufferVtbl tmproxyvtable
= {
467 TMProxyImpl_QueryInterface
,
471 TMProxyImpl_Disconnect
474 /* how much space do we use on stack in DWORD steps. */
479 return 8/sizeof(DWORD
);
481 return sizeof(double)/sizeof(DWORD
);
483 return sizeof(CY
)/sizeof(DWORD
);
485 return sizeof(DATE
)/sizeof(DWORD
);
487 return (sizeof(VARIANT
)+3)/sizeof(DWORD
);
494 _xsize(TYPEDESC
*td
) {
499 return sizeof(VARIANT
)+3;
502 ARRAYDESC
*adesc
= td
->u
.lpadesc
;
504 for (i
=0;i
<adesc
->cDims
;i
++)
505 arrsize
*= adesc
->rgbounds
[i
].cElements
;
506 return arrsize
*_xsize(&adesc
->tdescElem
);
534 TRACE("(tdesc.vt %s)\n",debugstr_vt(tdesc
->vt
));
537 case VT_EMPTY
: /* nothing. empty variant for instance */
543 if (debugout
) TRACE_(olerelay
)("%x%x\n",arg
[0],arg
[1]);
545 hres
= xbuf_add(buf
,(LPBYTE
)arg
,8);
555 if (debugout
) TRACE_(olerelay
)("%x\n",*arg
);
557 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
562 if (debugout
) TRACE_(olerelay
)("%04x\n",*arg
& 0xffff);
564 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
569 if (debugout
) TRACE_(olerelay
)("%02x\n",*arg
& 0xff);
571 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
575 if (debugout
) TRACE_(olerelay
)("&0x%x\n",*arg
);
577 hres
= xbuf_add(buf
,(LPBYTE
)(DWORD
*)*arg
,sizeof(DWORD
));
578 /* do not dealloc at this time */
582 VARIANT
*vt
= (VARIANT
*)arg
;
583 DWORD vttype
= V_VT(vt
);
585 if (debugout
) TRACE_(olerelay
)("Vt(%s%s)(",debugstr_vt(vttype
),debugstr_vf(vttype
));
588 hres
= xbuf_add(buf
,(LPBYTE
)&vttype
,sizeof(vttype
));
589 if (hres
) return hres
;
591 /* need to recurse since we need to free the stuff */
592 hres
= serialize_param(tinfo
,writeit
,debugout
,dealloc
,&tdesc2
,(DWORD
*)&(V_I4(vt
)),buf
);
593 if (debugout
) TRACE_(olerelay
)(")");
596 case VT_BSTR
|VT_BYREF
: {
597 if (debugout
) TRACE_(olerelay
)("[byref]'%s'", *(BSTR
*)*arg
? relaystr(*((BSTR
*)*arg
)) : "<bstr NULL>");
599 /* ptr to ptr to magic widestring, basically */
600 BSTR
*bstr
= (BSTR
*) *arg
;
603 /* -1 means "null string" which is equivalent to empty string */
605 hres
= xbuf_add(buf
, (LPBYTE
)&len
,sizeof(DWORD
));
606 if (hres
) return hres
;
608 len
= *((DWORD
*)*bstr
-1)/sizeof(WCHAR
);
609 hres
= xbuf_add(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
610 if (hres
) return hres
;
611 hres
= xbuf_add(buf
,(LPBYTE
)*bstr
,len
* sizeof(WCHAR
));
612 if (hres
) return hres
;
616 if (dealloc
&& arg
) {
617 BSTR
*str
= *((BSTR
**)arg
);
626 TRACE_(olerelay
)("%s",relaystr((WCHAR
*)*arg
));
628 TRACE_(olerelay
)("<bstr NULL>");
631 BSTR bstr
= (BSTR
)*arg
;
635 hres
= xbuf_add(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
636 if (hres
) return hres
;
638 len
= *((DWORD
*)bstr
-1)/sizeof(WCHAR
);
639 hres
= xbuf_add(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
640 if (hres
) return hres
;
641 hres
= xbuf_add(buf
,(LPBYTE
)bstr
,len
* sizeof(WCHAR
));
642 if (hres
) return hres
;
647 SysFreeString((BSTR
)*arg
);
652 BOOL derefhere
= TRUE
;
654 if (tdesc
->u
.lptdesc
->vt
== VT_USERDEFINED
) {
658 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.lptdesc
->u
.hreftype
,&tinfo2
);
660 ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc
->u
.lptdesc
->u
.hreftype
);
663 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
664 switch (tattr
->typekind
) {
665 case TKIND_ENUM
: /* confirmed */
666 case TKIND_RECORD
: /* FIXME: mostly untested */
669 case TKIND_ALIAS
: /* FIXME: untested */
670 case TKIND_DISPATCH
: /* will be done in VT_USERDEFINED case */
671 case TKIND_INTERFACE
: /* will be done in VT_USERDEFINED case */
675 FIXME("unhandled switch cases tattr->typekind %d\n", tattr
->typekind
);
679 ITypeInfo_ReleaseTypeAttr(tinfo
, tattr
);
680 ITypeInfo_Release(tinfo2
);
683 if (debugout
) TRACE_(olerelay
)("*");
684 /* Write always, so the other side knows when it gets a NULL pointer.
686 cookie
= *arg
? 0x42424242 : 0;
687 hres
= xbuf_add(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
691 if (debugout
) TRACE_(olerelay
)("NULL");
694 hres
= serialize_param(tinfo
,writeit
,debugout
,dealloc
,tdesc
->u
.lptdesc
,(DWORD
*)*arg
,buf
);
695 if (derefhere
&& dealloc
) HeapFree(GetProcessHeap(),0,(LPVOID
)*arg
);
699 if (debugout
) TRACE_(olerelay
)("unk(0x%x)",*arg
);
701 hres
= _marshal_interface(buf
,&IID_IUnknown
,(LPUNKNOWN
)*arg
);
702 if (dealloc
&& *(IUnknown
**)arg
)
703 IUnknown_Release((LPUNKNOWN
)*arg
);
706 if (debugout
) TRACE_(olerelay
)("idisp(0x%x)",*arg
);
708 hres
= _marshal_interface(buf
,&IID_IDispatch
,(LPUNKNOWN
)*arg
);
709 if (dealloc
&& *(IUnknown
**)arg
)
710 IUnknown_Release((LPUNKNOWN
)*arg
);
713 if (debugout
) TRACE_(olerelay
)("<void>");
715 case VT_USERDEFINED
: {
719 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.hreftype
,&tinfo2
);
721 ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc
->u
.hreftype
);
724 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
725 switch (tattr
->typekind
) {
727 case TKIND_INTERFACE
:
729 hres
=_marshal_interface(buf
,&(tattr
->guid
),(LPUNKNOWN
)arg
);
731 IUnknown_Release((LPUNKNOWN
)arg
);
735 if (debugout
) TRACE_(olerelay
)("{");
736 for (i
=0;i
<tattr
->cVars
;i
++) {
741 hres
= ITypeInfo2_GetVarDesc(tinfo2
, i
, &vdesc
);
743 ERR("Could not get vardesc of %d\n",i
);
746 elem2
= &vdesc
->elemdescVar
;
747 tdesc2
= &elem2
->tdesc
;
748 hres
= serialize_param(
754 (DWORD
*)(((LPBYTE
)arg
)+vdesc
->u
.oInst
),
757 ITypeInfo_ReleaseVarDesc(tinfo2
, vdesc
);
760 if (debugout
&& (i
<(tattr
->cVars
-1)))
761 TRACE_(olerelay
)(",");
763 if (debugout
) TRACE_(olerelay
)("}");
767 hres
= serialize_param(tinfo2
,writeit
,debugout
,dealloc
,&tattr
->tdescAlias
,arg
,buf
);
771 if (debugout
) TRACE_(olerelay
)("%x",*arg
);
773 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
776 FIXME("Unhandled typekind %d\n",tattr
->typekind
);
780 ITypeInfo_ReleaseTypeAttr(tinfo2
, tattr
);
781 ITypeInfo_Release(tinfo2
);
785 ARRAYDESC
*adesc
= tdesc
->u
.lpadesc
;
788 if (debugout
) TRACE_(olerelay
)("carr");
789 for (i
=0;i
<adesc
->cDims
;i
++) {
790 if (debugout
) TRACE_(olerelay
)("[%d]",adesc
->rgbounds
[i
].cElements
);
791 arrsize
*= adesc
->rgbounds
[i
].cElements
;
793 if (debugout
) TRACE_(olerelay
)("(vt %s)",debugstr_vt(adesc
->tdescElem
.vt
));
794 if (debugout
) TRACE_(olerelay
)("[");
795 for (i
=0;i
<arrsize
;i
++) {
796 hres
= serialize_param(tinfo
, writeit
, debugout
, dealloc
, &adesc
->tdescElem
, (DWORD
*)((LPBYTE
)arg
+i
*_xsize(&adesc
->tdescElem
)), buf
);
799 if (debugout
&& (i
<arrsize
-1)) TRACE_(olerelay
)(",");
801 if (debugout
) TRACE_(olerelay
)("]");
807 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
808 ULONG size
= LPSAFEARRAY_UserSize(&flags
, buf
->curoff
, (LPSAFEARRAY
*)arg
);
809 xbuf_resize(buf
, size
);
810 LPSAFEARRAY_UserMarshal(&flags
, buf
->base
+ buf
->curoff
, (LPSAFEARRAY
*)arg
);
816 ERR("Unhandled marshal type %d.\n",tdesc
->vt
);
833 TRACE("vt %s at %p\n",debugstr_vt(tdesc
->vt
),arg
);
838 if (debugout
) TRACE_(olerelay
)("<empty>\n");
841 if (debugout
) TRACE_(olerelay
)("<null>\n");
844 VARIANT
*vt
= (VARIANT
*)arg
;
849 hres
= xbuf_get(buf
,(LPBYTE
)&vttype
,sizeof(vttype
));
851 FIXME("vt type not read?\n");
854 memset(&tdesc2
,0,sizeof(tdesc2
));
857 if (debugout
) TRACE_(olerelay
)("Vt(%s%s)(",debugstr_vt(vttype
),debugstr_vf(vttype
));
858 hres
= deserialize_param(tinfo
, readit
, debugout
, alloc
, &tdesc2
, (DWORD
*)&(V_I4(vt
)), buf
);
859 TRACE_(olerelay
)(")");
870 hres
= xbuf_get(buf
,(LPBYTE
)arg
,8);
871 if (hres
) ERR("Failed to read integer 8 byte\n");
873 if (debugout
) TRACE_(olerelay
)("%x%x",arg
[0],arg
[1]);
883 hres
= xbuf_get(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
884 if (hres
) ERR("Failed to read integer 4 byte\n");
886 if (debugout
) TRACE_(olerelay
)("%x",*arg
);
892 hres
= xbuf_get(buf
,(LPBYTE
)&x
,sizeof(DWORD
));
893 if (hres
) ERR("Failed to read integer 4 byte\n");
896 if (debugout
) TRACE_(olerelay
)("%04x",*arg
& 0xffff);
902 hres
= xbuf_get(buf
,(LPBYTE
)&x
,sizeof(DWORD
));
903 if (hres
) ERR("Failed to read integer 4 byte\n");
906 if (debugout
) TRACE_(olerelay
)("%02x",*arg
& 0xff);
911 *arg
= (DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DWORD
));
913 hres
= xbuf_get(buf
,(LPBYTE
)*arg
,sizeof(DWORD
));
914 if (hres
) ERR("Failed to read integer 4 byte\n");
916 if (debugout
) TRACE_(olerelay
)("&0x%x",*(DWORD
*)*arg
);
918 case VT_BSTR
|VT_BYREF
: {
919 BSTR
**bstr
= (BSTR
**)arg
;
924 hres
= xbuf_get(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
926 ERR("failed to read bstr klen\n");
930 *bstr
= CoTaskMemAlloc(sizeof(BSTR
*));
932 if (debugout
) TRACE_(olerelay
)("<bstr NULL>");
934 str
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,(len
+1)*sizeof(WCHAR
));
935 hres
= xbuf_get(buf
,(LPBYTE
)str
,len
*sizeof(WCHAR
));
937 ERR("Failed to read BSTR.\n");
940 *bstr
= CoTaskMemAlloc(sizeof(BSTR
*));
941 **bstr
= SysAllocStringLen(str
,len
);
942 if (debugout
) TRACE_(olerelay
)("%s",relaystr(str
));
943 HeapFree(GetProcessHeap(),0,str
);
955 hres
= xbuf_get(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
957 ERR("failed to read bstr klen\n");
962 if (debugout
) TRACE_(olerelay
)("<bstr NULL>");
964 str
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,(len
+1)*sizeof(WCHAR
));
965 hres
= xbuf_get(buf
,(LPBYTE
)str
,len
*sizeof(WCHAR
));
967 ERR("Failed to read BSTR.\n");
970 *arg
= (DWORD
)SysAllocStringLen(str
,len
);
971 if (debugout
) TRACE_(olerelay
)("%s",relaystr(str
));
972 HeapFree(GetProcessHeap(),0,str
);
981 BOOL derefhere
= TRUE
;
983 if (tdesc
->u
.lptdesc
->vt
== VT_USERDEFINED
) {
987 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.lptdesc
->u
.hreftype
,&tinfo2
);
989 ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc
->u
.lptdesc
->u
.hreftype
);
992 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
993 switch (tattr
->typekind
) {
994 case TKIND_ENUM
: /* confirmed */
995 case TKIND_RECORD
: /* FIXME: mostly untested */
998 case TKIND_ALIAS
: /* FIXME: untested */
999 case TKIND_DISPATCH
: /* will be done in VT_USERDEFINED case */
1000 case TKIND_INTERFACE
: /* will be done in VT_USERDEFINED case */
1004 FIXME("unhandled switch cases tattr->typekind %d\n", tattr
->typekind
);
1008 ITypeInfo_ReleaseTypeAttr(tinfo2
, tattr
);
1009 ITypeInfo_Release(tinfo2
);
1011 /* read it in all cases, we need to know if we have
1012 * NULL pointer or not.
1014 hres
= xbuf_get(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
1016 ERR("Failed to load pointer cookie.\n");
1019 if (cookie
!= 0x42424242) {
1020 /* we read a NULL ptr from the remote side */
1021 if (debugout
) TRACE_(olerelay
)("NULL");
1025 if (debugout
) TRACE_(olerelay
)("*");
1027 /* Allocate space for the referenced struct */
1029 *arg
=(DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,_xsize(tdesc
->u
.lptdesc
));
1032 return deserialize_param(tinfo
, readit
, debugout
, alloc
, tdesc
->u
.lptdesc
, (LPDWORD
)*arg
, buf
);
1034 return deserialize_param(tinfo
, readit
, debugout
, alloc
, tdesc
->u
.lptdesc
, arg
, buf
);
1037 /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
1039 *arg
=(DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DWORD
));
1042 hres
= _unmarshal_interface(buf
,&IID_IUnknown
,(LPUNKNOWN
*)arg
);
1044 TRACE_(olerelay
)("unk(%p)",arg
);
1049 hres
= _unmarshal_interface(buf
,&IID_IDispatch
,(LPUNKNOWN
*)arg
);
1051 TRACE_(olerelay
)("idisp(%p)",arg
);
1054 if (debugout
) TRACE_(olerelay
)("<void>");
1056 case VT_USERDEFINED
: {
1060 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.hreftype
,&tinfo2
);
1062 ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc
->u
.hreftype
);
1065 hres
= ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
1067 ERR("Could not get typeattr in VT_USERDEFINED.\n");
1069 switch (tattr
->typekind
) {
1070 case TKIND_DISPATCH
:
1071 case TKIND_INTERFACE
:
1073 hres
= _unmarshal_interface(buf
,&(tattr
->guid
),(LPUNKNOWN
*)arg
);
1075 case TKIND_RECORD
: {
1079 *arg
= (DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,tattr
->cbSizeInstance
);
1081 if (debugout
) TRACE_(olerelay
)("{");
1082 for (i
=0;i
<tattr
->cVars
;i
++) {
1085 hres
= ITypeInfo2_GetVarDesc(tinfo2
, i
, &vdesc
);
1087 ERR("Could not get vardesc of %d\n",i
);
1088 ITypeInfo_ReleaseTypeAttr(tinfo2
, tattr
);
1089 ITypeInfo_Release(tinfo2
);
1092 hres
= deserialize_param(
1097 &vdesc
->elemdescVar
.tdesc
,
1098 (DWORD
*)(((LPBYTE
)*arg
)+vdesc
->u
.oInst
),
1101 ITypeInfo2_ReleaseVarDesc(tinfo2
, vdesc
);
1102 if (debugout
&& (i
<tattr
->cVars
-1)) TRACE_(olerelay
)(",");
1104 if (debugout
) TRACE_(olerelay
)("}");
1108 hres
= deserialize_param(tinfo2
,readit
,debugout
,alloc
,&tattr
->tdescAlias
,arg
,buf
);
1112 hres
= xbuf_get(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
1113 if (hres
) ERR("Failed to read enum (4 byte)\n");
1115 if (debugout
) TRACE_(olerelay
)("%x",*arg
);
1118 ERR("Unhandled typekind %d\n",tattr
->typekind
);
1122 ITypeInfo_ReleaseTypeAttr(tinfo2
, tattr
);
1125 ERR("failed to stuballoc in TKIND_RECORD.\n");
1126 ITypeInfo_Release(tinfo2
);
1130 /* arg is pointing to the start of the array. */
1131 ARRAYDESC
*adesc
= tdesc
->u
.lpadesc
;
1134 if (adesc
->cDims
> 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
1135 for (i
=0;i
<adesc
->cDims
;i
++)
1136 arrsize
*= adesc
->rgbounds
[i
].cElements
;
1137 for (i
=0;i
<arrsize
;i
++)
1144 (DWORD
*)((LPBYTE
)(arg
)+i
*_xsize(&adesc
->tdescElem
)),
1149 case VT_SAFEARRAY
: {
1152 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
1153 unsigned char *buffer
;
1154 buffer
= LPSAFEARRAY_UserUnmarshal(&flags
, buf
->base
+ buf
->curoff
, (LPSAFEARRAY
*)arg
);
1155 buf
->curoff
= buffer
- buf
->base
;
1160 ERR("No handler for VT type %d!\n",tdesc
->vt
);
1166 /* Searches function, also in inherited interfaces */
1169 ITypeInfo
*tinfo
, int iMethod
, ITypeInfo
**tactual
, const FUNCDESC
**fdesc
, BSTR
*iname
, BSTR
*fname
)
1174 if (fname
) *fname
= NULL
;
1175 if (iname
) *iname
= NULL
;
1178 hres
= ITypeInfoImpl_GetInternalFuncDesc(tinfo
, i
, fdesc
);
1185 hres
= ITypeInfo_GetTypeAttr(tinfo
, &attr
);
1187 ERR("GetTypeAttr failed with %x\n",hres
);
1190 /* Not found, so look in inherited ifaces. */
1191 for (j
=0;j
<attr
->cImplTypes
;j
++) {
1192 hres
= ITypeInfo_GetRefTypeOfImplType(tinfo
, j
, &href
);
1194 ERR("Did not find a reftype for interface offset %d?\n",j
);
1197 hres
= ITypeInfo_GetRefTypeInfo(tinfo
, href
, &tinfo2
);
1199 ERR("Did not find a typeinfo for reftype %d?\n",href
);
1202 hres
= _get_funcdesc(tinfo2
,iMethod
,tactual
,fdesc
,iname
,fname
);
1203 ITypeInfo_Release(tinfo2
);
1205 ITypeInfo_ReleaseTypeAttr(tinfo
, attr
);
1209 ITypeInfo_ReleaseTypeAttr(tinfo
, attr
);
1212 if (((*fdesc
)->oVft
/4) == iMethod
) {
1214 ITypeInfo_GetDocumentation(tinfo
,(*fdesc
)->memid
,fname
,NULL
,NULL
,NULL
);
1216 ITypeInfo_GetDocumentation(tinfo
,-1,iname
,NULL
,NULL
,NULL
);
1218 ITypeInfo_AddRef(*tactual
);
1226 xCall(LPVOID retptr
, int method
, TMProxyImpl
*tpinfo
/*, args */)
1228 DWORD
*args
= ((DWORD
*)&tpinfo
)+1, *xargs
;
1229 const FUNCDESC
*fdesc
;
1231 int i
, relaydeb
= TRACE_ON(olerelay
);
1238 DWORD remoteresult
= 0;
1240 IRpcChannelBuffer
*chanbuf
;
1242 EnterCriticalSection(&tpinfo
->crit
);
1244 hres
= _get_funcdesc(tpinfo
->tinfo
,method
,&tinfo
,&fdesc
,&iname
,&fname
);
1246 ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method
);
1247 ITypeInfo_Release(tinfo
);
1248 LeaveCriticalSection(&tpinfo
->crit
);
1252 if (!tpinfo
->chanbuf
)
1254 WARN("Tried to use disconnected proxy\n");
1255 ITypeInfo_Release(tinfo
);
1256 LeaveCriticalSection(&tpinfo
->crit
);
1257 return RPC_E_DISCONNECTED
;
1259 chanbuf
= tpinfo
->chanbuf
;
1260 IRpcChannelBuffer_AddRef(chanbuf
);
1262 LeaveCriticalSection(&tpinfo
->crit
);
1265 TRACE_(olerelay
)("->");
1267 TRACE_(olerelay
)("%s:",relaystr(iname
));
1269 TRACE_(olerelay
)("%s(%d)",relaystr(fname
),method
);
1271 TRACE_(olerelay
)("%d",method
);
1272 TRACE_(olerelay
)("(");
1275 if (iname
) SysFreeString(iname
);
1276 if (fname
) SysFreeString(fname
);
1278 memset(&buf
,0,sizeof(buf
));
1280 /* normal typelib driven serializing */
1282 /* Need them for hack below */
1283 memset(names
,0,sizeof(names
));
1284 if (ITypeInfo_GetNames(tinfo
,fdesc
->memid
,names
,sizeof(names
)/sizeof(names
[0]),&nrofnames
))
1286 if (nrofnames
> sizeof(names
)/sizeof(names
[0]))
1287 ERR("Need more names!\n");
1290 for (i
=0;i
<fdesc
->cParams
;i
++) {
1291 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1293 if (i
) TRACE_(olerelay
)(",");
1294 if (i
+1<nrofnames
&& names
[i
+1])
1295 TRACE_(olerelay
)("%s=",relaystr(names
[i
+1]));
1297 /* No need to marshal other data than FIN and any VT_PTR. */
1298 if (!(elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
|| !elem
->u
.paramdesc
.wParamFlags
) && (elem
->tdesc
.vt
!= VT_PTR
)) {
1299 xargs
+=_argsize(elem
->tdesc
.vt
);
1300 if (relaydeb
) TRACE_(olerelay
)("[out]");
1303 hres
= serialize_param(
1305 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
|| !elem
->u
.paramdesc
.wParamFlags
,
1314 ERR("Failed to serialize param, hres %x\n",hres
);
1317 xargs
+=_argsize(elem
->tdesc
.vt
);
1319 if (relaydeb
) TRACE_(olerelay
)(")");
1321 memset(&msg
,0,sizeof(msg
));
1322 msg
.cbBuffer
= buf
.curoff
;
1323 msg
.iMethod
= method
;
1324 hres
= IRpcChannelBuffer_GetBuffer(chanbuf
,&msg
,&(tpinfo
->iid
));
1326 ERR("RpcChannelBuffer GetBuffer failed, %x\n",hres
);
1329 memcpy(msg
.Buffer
,buf
.base
,buf
.curoff
);
1330 if (relaydeb
) TRACE_(olerelay
)("\n");
1331 hres
= IRpcChannelBuffer_SendReceive(chanbuf
,&msg
,&status
);
1333 ERR("RpcChannelBuffer SendReceive failed, %x\n",hres
);
1337 if (relaydeb
) TRACE_(olerelay
)(" status = %08x (",status
);
1339 buf
.base
= HeapReAlloc(GetProcessHeap(),0,buf
.base
,msg
.cbBuffer
);
1341 buf
.base
= HeapAlloc(GetProcessHeap(),0,msg
.cbBuffer
);
1342 buf
.size
= msg
.cbBuffer
;
1343 memcpy(buf
.base
,msg
.Buffer
,buf
.size
);
1346 /* generic deserializer using typelib description */
1349 for (i
=0;i
<fdesc
->cParams
;i
++) {
1350 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1353 if (i
) TRACE_(olerelay
)(",");
1354 if (i
+1<nrofnames
&& names
[i
+1]) TRACE_(olerelay
)("%s=",relaystr(names
[i
+1]));
1356 /* No need to marshal other data than FOUT and any VT_PTR */
1357 if (!(elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
) && (elem
->tdesc
.vt
!= VT_PTR
)) {
1358 xargs
+= _argsize(elem
->tdesc
.vt
);
1359 if (relaydeb
) TRACE_(olerelay
)("[in]");
1362 hres
= deserialize_param(
1364 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
1372 ERR("Failed to unmarshall param, hres %x\n",hres
);
1376 xargs
+= _argsize(elem
->tdesc
.vt
);
1379 hres
= xbuf_get(&buf
, (LPBYTE
)&remoteresult
, sizeof(DWORD
));
1382 if (relaydeb
) TRACE_(olerelay
)(") = %08x\n", remoteresult
);
1384 hres
= remoteresult
;
1387 for (i
= 0; i
< nrofnames
; i
++)
1388 SysFreeString(names
[i
]);
1389 HeapFree(GetProcessHeap(),0,buf
.base
);
1390 IRpcChannelBuffer_Release(chanbuf
);
1391 ITypeInfo_Release(tinfo
);
1392 TRACE("-- 0x%08x\n", hres
);
1396 static HRESULT WINAPI
ProxyIUnknown_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
1398 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1400 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
1402 if (proxy
->outerunknown
)
1403 return IUnknown_QueryInterface(proxy
->outerunknown
, riid
, ppv
);
1405 FIXME("No interface\n");
1406 return E_NOINTERFACE
;
1409 static ULONG WINAPI
ProxyIUnknown_AddRef(IUnknown
*iface
)
1411 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1415 if (proxy
->outerunknown
)
1416 return IUnknown_AddRef(proxy
->outerunknown
);
1418 return 2; /* FIXME */
1421 static ULONG WINAPI
ProxyIUnknown_Release(IUnknown
*iface
)
1423 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1427 if (proxy
->outerunknown
)
1428 return IUnknown_Release(proxy
->outerunknown
);
1430 return 1; /* FIXME */
1433 static HRESULT WINAPI
ProxyIDispatch_GetTypeInfoCount(LPDISPATCH iface
, UINT
* pctinfo
)
1435 TMProxyImpl
*This
= (TMProxyImpl
*)iface
;
1437 TRACE("(%p)\n", pctinfo
);
1439 return IDispatch_GetTypeInfoCount(This
->dispatch
, pctinfo
);
1442 static HRESULT WINAPI
ProxyIDispatch_GetTypeInfo(LPDISPATCH iface
, UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
1444 TMProxyImpl
*This
= (TMProxyImpl
*)iface
;
1446 TRACE("(%d, %x, %p)\n", iTInfo
, lcid
, ppTInfo
);
1448 return IDispatch_GetTypeInfo(This
->dispatch
, iTInfo
, lcid
, ppTInfo
);
1451 static HRESULT WINAPI
ProxyIDispatch_GetIDsOfNames(LPDISPATCH iface
, REFIID riid
, LPOLESTR
* rgszNames
, UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
1453 TMProxyImpl
*This
= (TMProxyImpl
*)iface
;
1455 TRACE("(%s, %p, %d, 0x%x, %p)\n", debugstr_guid(riid
), rgszNames
, cNames
, lcid
, rgDispId
);
1457 return IDispatch_GetIDsOfNames(This
->dispatch
, riid
, rgszNames
,
1458 cNames
, lcid
, rgDispId
);
1461 static HRESULT WINAPI
ProxyIDispatch_Invoke(LPDISPATCH iface
, DISPID dispIdMember
, REFIID riid
, LCID lcid
,
1462 WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
,
1463 EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
1465 TMProxyImpl
*This
= (TMProxyImpl
*)iface
;
1467 TRACE("(%d, %s, 0x%x, 0x%x, %p, %p, %p, %p)\n", dispIdMember
,
1468 debugstr_guid(riid
), lcid
, wFlags
, pDispParams
, pVarResult
,
1469 pExcepInfo
, puArgErr
);
1471 return IDispatch_Invoke(This
->dispatch
, dispIdMember
, riid
, lcid
,
1472 wFlags
, pDispParams
, pVarResult
, pExcepInfo
,
1476 static inline HRESULT
get_facbuf_for_iid(REFIID riid
, IPSFactoryBuffer
**facbuf
)
1481 if ((hr
= CoGetPSClsid(riid
, &clsid
)))
1483 return CoGetClassObject(&clsid
, CLSCTX_INPROC_SERVER
, NULL
,
1484 &IID_IPSFactoryBuffer
, (LPVOID
*)facbuf
);
1487 static HRESULT WINAPI
1488 PSFacBuf_CreateProxy(
1489 LPPSFACTORYBUFFER iface
, IUnknown
* pUnkOuter
, REFIID riid
,
1490 IRpcProxyBuffer
**ppProxy
, LPVOID
*ppv
)
1495 const FUNCDESC
*fdesc
;
1499 TRACE("(...%s...)\n",debugstr_guid(riid
));
1500 hres
= _get_typeinfo_for_iid(riid
,&tinfo
);
1502 ERR("No typeinfo for %s?\n",debugstr_guid(riid
));
1505 nroffuncs
= _nroffuncs(tinfo
);
1506 proxy
= CoTaskMemAlloc(sizeof(TMProxyImpl
));
1507 if (!proxy
) return E_OUTOFMEMORY
;
1509 assert(sizeof(TMAsmProxy
) == 12);
1511 proxy
->dispatch
= NULL
;
1512 proxy
->dispatch_proxy
= NULL
;
1513 proxy
->outerunknown
= pUnkOuter
;
1514 proxy
->asmstubs
= VirtualAlloc(NULL
, sizeof(TMAsmProxy
) * nroffuncs
, MEM_COMMIT
, PAGE_EXECUTE_READWRITE
);
1515 if (!proxy
->asmstubs
) {
1516 ERR("Could not commit pages for proxy thunks\n");
1517 CoTaskMemFree(proxy
);
1518 return E_OUTOFMEMORY
;
1521 InitializeCriticalSection(&proxy
->crit
);
1523 proxy
->lpvtbl
= HeapAlloc(GetProcessHeap(),0,sizeof(LPBYTE
)*nroffuncs
);
1524 for (i
=0;i
<nroffuncs
;i
++) {
1525 TMAsmProxy
*xasm
= proxy
->asmstubs
+i
;
1529 proxy
->lpvtbl
[i
] = ProxyIUnknown_QueryInterface
;
1532 proxy
->lpvtbl
[i
] = ProxyIUnknown_AddRef
;
1535 proxy
->lpvtbl
[i
] = ProxyIUnknown_Release
;
1539 /* nrofargs without This */
1542 hres
= _get_funcdesc(tinfo
,i
,&tinfo2
,&fdesc
,NULL
,NULL
);
1543 ITypeInfo_Release(tinfo2
);
1545 ERR("GetFuncDesc %x should not fail here.\n",hres
);
1548 /* some args take more than 4 byte on the stack */
1550 for (j
=0;j
<fdesc
->cParams
;j
++)
1551 nrofargs
+= _argsize(fdesc
->lprgelemdescParam
[j
].tdesc
.vt
);
1554 if (fdesc
->callconv
!= CC_STDCALL
) {
1555 ERR("calling convention is not stdcall????\n");
1558 /* popl %eax - return ptr
1565 * arg3 arg2 arg1 <method> <returnptr>
1567 xasm
->popleax
= 0x58;
1568 xasm
->pushlval
= 0x6a;
1570 xasm
->pushleax
= 0x50;
1571 xasm
->lcall
= 0xe8; /* relative jump */
1572 xasm
->xcall
= (DWORD
)xCall
;
1573 xasm
->xcall
-= (DWORD
)&(xasm
->lret
);
1575 xasm
->bytestopop
= (nrofargs
+2)*4; /* pop args, This, iMethod */
1576 proxy
->lpvtbl
[i
] = xasm
;
1579 FIXME("not implemented on non i386\n");
1586 /* if we derive from IDispatch then defer to its proxy for its methods */
1587 hres
= ITypeInfo_GetTypeAttr(tinfo
, &typeattr
);
1590 if (typeattr
->wTypeFlags
& TYPEFLAG_FDISPATCHABLE
)
1592 IPSFactoryBuffer
*factory_buffer
;
1593 hres
= get_facbuf_for_iid(&IID_IDispatch
, &factory_buffer
);
1596 hres
= IPSFactoryBuffer_CreateProxy(factory_buffer
, NULL
,
1597 &IID_IDispatch
, &proxy
->dispatch_proxy
,
1598 (void **)&proxy
->dispatch
);
1599 IPSFactoryBuffer_Release(factory_buffer
);
1603 proxy
->lpvtbl
[3] = ProxyIDispatch_GetTypeInfoCount
;
1604 proxy
->lpvtbl
[4] = ProxyIDispatch_GetTypeInfo
;
1605 proxy
->lpvtbl
[5] = ProxyIDispatch_GetIDsOfNames
;
1606 proxy
->lpvtbl
[6] = ProxyIDispatch_Invoke
;
1609 ITypeInfo_ReleaseTypeAttr(tinfo
, typeattr
);
1612 proxy
->lpvtbl2
= &tmproxyvtable
;
1613 /* one reference for the proxy */
1615 proxy
->tinfo
= tinfo
;
1616 memcpy(&proxy
->iid
,riid
,sizeof(*riid
));
1620 *ppv
= (LPVOID
)proxy
;
1621 *ppProxy
= (IRpcProxyBuffer
*)&(proxy
->lpvtbl2
);
1622 IUnknown_AddRef((IUnknown
*)*ppv
);
1626 TMProxyImpl_Release((IRpcProxyBuffer
*)&proxy
->lpvtbl2
);
1630 typedef struct _TMStubImpl
{
1631 const IRpcStubBufferVtbl
*lpvtbl
;
1637 IRpcStubBuffer
*dispatch_stub
;
1638 BOOL dispatch_derivative
;
1641 static HRESULT WINAPI
1642 TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface
, REFIID riid
, LPVOID
*ppv
)
1644 if (IsEqualIID(riid
,&IID_IRpcStubBuffer
)||IsEqualIID(riid
,&IID_IUnknown
)){
1645 *ppv
= (LPVOID
)iface
;
1646 IRpcStubBuffer_AddRef(iface
);
1649 FIXME("%s, not supported IID.\n",debugstr_guid(riid
));
1650 return E_NOINTERFACE
;
1654 TMStubImpl_AddRef(LPRPCSTUBBUFFER iface
)
1656 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1657 ULONG refCount
= InterlockedIncrement(&This
->ref
);
1659 TRACE("(%p)->(ref before=%u)\n", This
, refCount
- 1);
1665 TMStubImpl_Release(LPRPCSTUBBUFFER iface
)
1667 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1668 ULONG refCount
= InterlockedDecrement(&This
->ref
);
1670 TRACE("(%p)->(ref before=%u)\n", This
, refCount
+ 1);
1674 IRpcStubBuffer_Disconnect(iface
);
1675 ITypeInfo_Release(This
->tinfo
);
1676 if (This
->dispatch_stub
)
1677 IRpcStubBuffer_Release(This
->dispatch_stub
);
1678 CoTaskMemFree(This
);
1683 static HRESULT WINAPI
1684 TMStubImpl_Connect(LPRPCSTUBBUFFER iface
, LPUNKNOWN pUnkServer
)
1686 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1688 TRACE("(%p)->(%p)\n", This
, pUnkServer
);
1690 IUnknown_AddRef(pUnkServer
);
1691 This
->pUnk
= pUnkServer
;
1693 if (This
->dispatch_stub
)
1694 IRpcStubBuffer_Connect(This
->dispatch_stub
, pUnkServer
);
1700 TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface
)
1702 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1704 TRACE("(%p)->()\n", This
);
1708 IUnknown_Release(This
->pUnk
);
1712 if (This
->dispatch_stub
)
1713 IRpcStubBuffer_Disconnect(This
->dispatch_stub
);
1716 static HRESULT WINAPI
1718 LPRPCSTUBBUFFER iface
, RPCOLEMESSAGE
* xmsg
,IRpcChannelBuffer
*rpcchanbuf
)
1721 const FUNCDESC
*fdesc
;
1722 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1724 DWORD
*args
= NULL
, res
, *xargs
, nrofargs
;
1729 ITypeInfo
*tinfo
= NULL
;
1733 if (xmsg
->iMethod
< 3) {
1734 ERR("IUnknown methods cannot be marshaled by the typelib marshaler\n");
1735 return E_UNEXPECTED
;
1738 if (This
->dispatch_derivative
&& xmsg
->iMethod
< sizeof(IDispatchVtbl
)/sizeof(void *))
1740 IPSFactoryBuffer
*factory_buffer
;
1741 hres
= get_facbuf_for_iid(&IID_IDispatch
, &factory_buffer
);
1744 hres
= IPSFactoryBuffer_CreateStub(factory_buffer
, &IID_IDispatch
,
1745 This
->pUnk
, &This
->dispatch_stub
);
1746 IPSFactoryBuffer_Release(factory_buffer
);
1750 return IRpcStubBuffer_Invoke(This
->dispatch_stub
, xmsg
, rpcchanbuf
);
1753 memset(&buf
,0,sizeof(buf
));
1754 buf
.size
= xmsg
->cbBuffer
;
1755 buf
.base
= HeapAlloc(GetProcessHeap(), 0, xmsg
->cbBuffer
);
1756 memcpy(buf
.base
, xmsg
->Buffer
, xmsg
->cbBuffer
);
1759 hres
= _get_funcdesc(This
->tinfo
,xmsg
->iMethod
,&tinfo
,&fdesc
,&iname
,NULL
);
1761 ERR("GetFuncDesc on method %d failed with %x\n",xmsg
->iMethod
,hres
);
1765 if (iname
&& !lstrcmpW(iname
, IDispatchW
))
1767 ERR("IDispatch cannot be marshaled by the typelib marshaler\n");
1768 hres
= E_UNEXPECTED
;
1769 SysFreeString (iname
);
1773 if (iname
) SysFreeString (iname
);
1775 /* Need them for hack below */
1776 memset(names
,0,sizeof(names
));
1777 ITypeInfo_GetNames(tinfo
,fdesc
->memid
,names
,sizeof(names
)/sizeof(names
[0]),&nrofnames
);
1778 if (nrofnames
> sizeof(names
)/sizeof(names
[0])) {
1779 ERR("Need more names!\n");
1782 /*dump_FUNCDESC(fdesc);*/
1784 for (i
=0;i
<fdesc
->cParams
;i
++)
1785 nrofargs
+= _argsize(fdesc
->lprgelemdescParam
[i
].tdesc
.vt
);
1786 args
= HeapAlloc(GetProcessHeap(),0,(nrofargs
+1)*sizeof(DWORD
));
1789 hres
= E_OUTOFMEMORY
;
1793 /* Allocate all stuff used by call. */
1795 for (i
=0;i
<fdesc
->cParams
;i
++) {
1796 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1798 hres
= deserialize_param(
1800 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
|| !elem
->u
.paramdesc
.wParamFlags
,
1807 xargs
+= _argsize(elem
->tdesc
.vt
);
1809 ERR("Failed to deserialize param %s, hres %x\n",relaystr(names
[i
+1]),hres
);
1814 args
[0] = (DWORD
)This
->pUnk
;
1819 (*((FARPROC
**)args
[0]))[fdesc
->oVft
/4],
1827 DWORD dwExceptionCode
= GetExceptionCode();
1828 ERR("invoke call failed with exception 0x%08x (%d)\n", dwExceptionCode
, dwExceptionCode
);
1829 if (FAILED(dwExceptionCode
))
1830 hres
= dwExceptionCode
;
1832 hres
= HRESULT_FROM_WIN32(dwExceptionCode
);
1842 for (i
=0;i
<fdesc
->cParams
;i
++) {
1843 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1844 hres
= serialize_param(
1846 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
1853 xargs
+= _argsize(elem
->tdesc
.vt
);
1855 ERR("Failed to stuballoc param, hres %x\n",hres
);
1860 hres
= xbuf_add (&buf
, (LPBYTE
)&res
, sizeof(DWORD
));
1865 xmsg
->cbBuffer
= buf
.curoff
;
1866 hres
= IRpcChannelBuffer_GetBuffer(rpcchanbuf
, xmsg
, &This
->iid
);
1868 ERR("IRpcChannelBuffer_GetBuffer failed with error 0x%08x\n", hres
);
1871 memcpy(xmsg
->Buffer
, buf
.base
, buf
.curoff
);
1874 for (i
= 0; i
< nrofnames
; i
++)
1875 SysFreeString(names
[i
]);
1877 ITypeInfo_Release(tinfo
);
1878 HeapFree(GetProcessHeap(), 0, args
);
1880 HeapFree(GetProcessHeap(), 0, buf
.base
);
1882 TRACE("returning\n");
1886 static LPRPCSTUBBUFFER WINAPI
1887 TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface
, REFIID riid
) {
1888 FIXME("Huh (%s)?\n",debugstr_guid(riid
));
1893 TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface
) {
1894 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1897 return This
->ref
; /*FIXME? */
1900 static HRESULT WINAPI
1901 TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface
, LPVOID
*ppv
) {
1906 TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface
, LPVOID ppv
) {
1910 static const IRpcStubBufferVtbl tmstubvtbl
= {
1911 TMStubImpl_QueryInterface
,
1915 TMStubImpl_Disconnect
,
1917 TMStubImpl_IsIIDSupported
,
1918 TMStubImpl_CountRefs
,
1919 TMStubImpl_DebugServerQueryInterface
,
1920 TMStubImpl_DebugServerRelease
1923 static HRESULT WINAPI
1924 PSFacBuf_CreateStub(
1925 LPPSFACTORYBUFFER iface
, REFIID riid
,IUnknown
*pUnkServer
,
1926 IRpcStubBuffer
** ppStub
1933 TRACE("(%s,%p,%p)\n",debugstr_guid(riid
),pUnkServer
,ppStub
);
1935 hres
= _get_typeinfo_for_iid(riid
,&tinfo
);
1937 ERR("No typeinfo for %s?\n",debugstr_guid(riid
));
1941 stub
= CoTaskMemAlloc(sizeof(TMStubImpl
));
1943 return E_OUTOFMEMORY
;
1944 stub
->lpvtbl
= &tmstubvtbl
;
1946 stub
->tinfo
= tinfo
;
1947 stub
->dispatch_stub
= NULL
;
1948 stub
->dispatch_derivative
= FALSE
;
1949 memcpy(&(stub
->iid
),riid
,sizeof(*riid
));
1950 hres
= IRpcStubBuffer_Connect((LPRPCSTUBBUFFER
)stub
,pUnkServer
);
1951 *ppStub
= (LPRPCSTUBBUFFER
)stub
;
1952 TRACE("IRpcStubBuffer: %p\n", stub
);
1954 ERR("Connect to pUnkServer failed?\n");
1956 /* if we derive from IDispatch then defer to its stub for some of its methods */
1957 hres
= ITypeInfo_GetTypeAttr(tinfo
, &typeattr
);
1960 if (typeattr
->wTypeFlags
& TYPEFLAG_FDISPATCHABLE
)
1961 stub
->dispatch_derivative
= TRUE
;
1962 ITypeInfo_ReleaseTypeAttr(tinfo
, typeattr
);
1968 static const IPSFactoryBufferVtbl psfacbufvtbl
= {
1969 PSFacBuf_QueryInterface
,
1972 PSFacBuf_CreateProxy
,
1976 /* This is the whole PSFactoryBuffer object, just the vtableptr */
1977 static const IPSFactoryBufferVtbl
*lppsfac
= &psfacbufvtbl
;
1979 /***********************************************************************
1980 * TMARSHAL_DllGetClassObject
1982 HRESULT
TMARSHAL_DllGetClassObject(REFCLSID rclsid
, REFIID iid
,LPVOID
*ppv
)
1984 if (IsEqualIID(iid
,&IID_IPSFactoryBuffer
)) {
1988 return E_NOINTERFACE
;