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
45 #include "propidl.h" /* for LPSAFEARRAY_User* functions */
48 #include "wine/debug.h"
50 static const WCHAR IDispatchW
[] = { 'I','D','i','s','p','a','t','c','h',0};
52 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
53 WINE_DECLARE_DEBUG_CHANNEL(olerelay
);
55 #define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
57 typedef struct _marshal_state
{
63 /* used in the olerelay code to avoid having the L"" stuff added by debugstr_w */
64 static char *relaystr(WCHAR
*in
) {
65 char *tmp
= (char *)debugstr_w(in
);
67 tmp
[strlen(tmp
)-1] = '\0';
72 xbuf_resize(marshal_state
*buf
, DWORD newsize
)
74 if(buf
->size
>= newsize
)
79 buf
->base
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, buf
->base
, newsize
);
85 buf
->base
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, newsize
);
94 xbuf_add(marshal_state
*buf
, LPBYTE stuff
, DWORD size
)
98 if(buf
->size
- buf
->curoff
< size
)
100 hr
= xbuf_resize(buf
, buf
->size
+ size
+ 100);
101 if(FAILED(hr
)) return hr
;
103 memcpy(buf
->base
+buf
->curoff
,stuff
,size
);
109 xbuf_get(marshal_state
*buf
, LPBYTE stuff
, DWORD size
) {
110 if (buf
->size
< buf
->curoff
+size
) return E_FAIL
;
111 memcpy(stuff
,buf
->base
+buf
->curoff
,size
);
117 xbuf_skip(marshal_state
*buf
, DWORD size
) {
118 if (buf
->size
< buf
->curoff
+size
) return E_FAIL
;
124 _unmarshal_interface(marshal_state
*buf
, REFIID riid
, LPUNKNOWN
*pUnk
) {
126 ULARGE_INTEGER newpos
;
127 LARGE_INTEGER seekto
;
132 TRACE("...%s...\n",debugstr_guid(riid
));
135 hres
= xbuf_get(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
137 ERR("xbuf_get failed\n");
141 if (xsize
== 0) return S_OK
;
143 hres
= CreateStreamOnHGlobal(0,TRUE
,&pStm
);
145 ERR("Stream create failed %lx\n",hres
);
149 hres
= IStream_Write(pStm
,buf
->base
+buf
->curoff
,xsize
,&res
);
151 ERR("stream write %lx\n",hres
);
155 memset(&seekto
,0,sizeof(seekto
));
156 hres
= IStream_Seek(pStm
,seekto
,SEEK_SET
,&newpos
);
158 ERR("Failed Seek %lx\n",hres
);
162 hres
= CoUnmarshalInterface(pStm
,riid
,(LPVOID
*)pUnk
);
164 ERR("Unmarshalling interface %s failed with %lx\n",debugstr_guid(riid
),hres
);
168 IStream_Release(pStm
);
169 return xbuf_skip(buf
,xsize
);
173 _marshal_interface(marshal_state
*buf
, REFIID riid
, LPUNKNOWN pUnk
) {
174 LPBYTE tempbuf
= NULL
;
175 IStream
*pStm
= NULL
;
177 ULARGE_INTEGER newpos
;
178 LARGE_INTEGER seekto
;
184 /* this is valid, if for instance we serialize
185 * a VT_DISPATCH with NULL ptr which apparently
186 * can happen. S_OK to make sure we continue
189 WARN("pUnk is NULL\n");
191 return xbuf_add(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
196 TRACE("...%s...\n",debugstr_guid(riid
));
198 hres
= CreateStreamOnHGlobal(0,TRUE
,&pStm
);
200 ERR("Stream create failed %lx\n",hres
);
204 hres
= CoMarshalInterface(pStm
,riid
,pUnk
,0,NULL
,0);
206 ERR("Marshalling interface %s failed with %lx\n", debugstr_guid(riid
), hres
);
210 hres
= IStream_Stat(pStm
,&ststg
,0);
212 ERR("Stream stat failed\n");
216 tempbuf
= HeapAlloc(GetProcessHeap(), 0, ststg
.cbSize
.u
.LowPart
);
217 memset(&seekto
,0,sizeof(seekto
));
218 hres
= IStream_Seek(pStm
,seekto
,SEEK_SET
,&newpos
);
220 ERR("Failed Seek %lx\n",hres
);
224 hres
= IStream_Read(pStm
,tempbuf
,ststg
.cbSize
.u
.LowPart
,&res
);
226 ERR("Failed Read %lx\n",hres
);
230 xsize
= ststg
.cbSize
.u
.LowPart
;
231 xbuf_add(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
232 hres
= xbuf_add(buf
,tempbuf
,ststg
.cbSize
.u
.LowPart
);
234 HeapFree(GetProcessHeap(),0,tempbuf
);
235 IStream_Release(pStm
);
241 xbuf_add(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
242 if (pStm
) IUnknown_Release(pStm
);
243 HeapFree(GetProcessHeap(), 0, tempbuf
);
247 /********************* OLE Proxy/Stub Factory ********************************/
248 static HRESULT WINAPI
249 PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface
, REFIID iid
, LPVOID
*ppv
) {
250 if (IsEqualIID(iid
,&IID_IPSFactoryBuffer
)||IsEqualIID(iid
,&IID_IUnknown
)) {
251 *ppv
= (LPVOID
)iface
;
252 /* No ref counting, static class */
255 FIXME("(%s) unknown IID?\n",debugstr_guid(iid
));
256 return E_NOINTERFACE
;
259 static ULONG WINAPI
PSFacBuf_AddRef(LPPSFACTORYBUFFER iface
) { return 2; }
260 static ULONG WINAPI
PSFacBuf_Release(LPPSFACTORYBUFFER iface
) { return 1; }
263 _get_typeinfo_for_iid(REFIID riid
, ITypeInfo
**ti
) {
266 char tlguid
[200],typelibkey
[300],interfacekey
[300],ver
[100];
269 DWORD tlguidlen
, verlen
, type
;
273 sprintf( interfacekey
, "Interface\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\Typelib",
274 riid
->Data1
, riid
->Data2
, riid
->Data3
,
275 riid
->Data4
[0], riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3],
276 riid
->Data4
[4], riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]
279 if (RegOpenKeyA(HKEY_CLASSES_ROOT
,interfacekey
,&ikey
)) {
280 ERR("No %s key found.\n",interfacekey
);
284 tlguidlen
= sizeof(tlguid
);
285 if (RegQueryValueExA(ikey
,NULL
,NULL
,&type
,(LPBYTE
)tlguid
,&tlguidlen
)) {
286 ERR("Getting typelib guid failed.\n");
291 verlen
= sizeof(ver
);
292 if (RegQueryValueExA(ikey
,"Version",NULL
,&type
,(LPBYTE
)ver
,&verlen
)) {
293 ERR("Could not get version value?\n");
298 sprintf(typelibkey
,"Typelib\\%s\\%s\\0\\win32",tlguid
,ver
);
299 tlfnlen
= sizeof(tlfn
);
300 if (RegQueryValueA(HKEY_CLASSES_ROOT
,typelibkey
,tlfn
,&tlfnlen
)) {
301 ERR("Could not get typelib fn?\n");
304 MultiByteToWideChar(CP_ACP
, 0, tlfn
, -1, tlfnW
, sizeof(tlfnW
) / sizeof(tlfnW
[0]));
305 hres
= LoadTypeLib(tlfnW
,&tl
);
307 ERR("Failed to load typelib for %s, but it should be there.\n",debugstr_guid(riid
));
310 hres
= ITypeLib_GetTypeInfoOfGuid(tl
,riid
,ti
);
312 ERR("typelib does not contain info for %s?\n",debugstr_guid(riid
));
313 ITypeLib_Release(tl
);
316 /* FIXME: do this? ITypeLib_Release(tl); */
320 /* Determine nr of functions. Since we use the toplevel interface and all
321 * inherited ones have lower numbers, we are ok to not to descent into
322 * the inheritance tree I think.
324 static int _nroffuncs(ITypeInfo
*tinfo
) {
326 const FUNCDESC
*fdesc
;
331 hres
= ITypeInfoImpl_GetInternalFuncDesc(tinfo
,n
,&fdesc
);
334 if (fdesc
->oVft
/4 > max
)
343 #include "pshpack1.h"
345 typedef struct _TMAsmProxy
{
359 # warning You need to implement stubless proxies for your architecture
360 typedef struct _TMAsmProxy
{
364 typedef struct _TMProxyImpl
{
366 const IRpcProxyBufferVtbl
*lpvtbl2
;
369 TMAsmProxy
*asmstubs
;
371 IRpcChannelBuffer
* chanbuf
;
373 CRITICAL_SECTION crit
;
374 IUnknown
*outerunknown
;
376 IRpcProxyBuffer
*dispatch_proxy
;
379 static HRESULT WINAPI
380 TMProxyImpl_QueryInterface(LPRPCPROXYBUFFER iface
, REFIID riid
, LPVOID
*ppv
)
383 if (IsEqualIID(riid
,&IID_IUnknown
)||IsEqualIID(riid
,&IID_IRpcProxyBuffer
)) {
384 *ppv
= (LPVOID
)iface
;
385 IRpcProxyBuffer_AddRef(iface
);
388 FIXME("no interface for %s\n",debugstr_guid(riid
));
389 return E_NOINTERFACE
;
393 TMProxyImpl_AddRef(LPRPCPROXYBUFFER iface
)
395 ICOM_THIS_MULTI(TMProxyImpl
,lpvtbl2
,iface
);
396 ULONG refCount
= InterlockedIncrement(&This
->ref
);
398 TRACE("(%p)->(ref before=%lu)\n",This
, refCount
- 1);
404 TMProxyImpl_Release(LPRPCPROXYBUFFER iface
)
406 ICOM_THIS_MULTI(TMProxyImpl
,lpvtbl2
,iface
);
407 ULONG refCount
= InterlockedDecrement(&This
->ref
);
409 TRACE("(%p)->(ref before=%lu)\n",This
, refCount
+ 1);
413 if (This
->dispatch_proxy
) IRpcProxyBuffer_Release(This
->dispatch_proxy
);
414 DeleteCriticalSection(&This
->crit
);
415 if (This
->chanbuf
) IRpcChannelBuffer_Release(This
->chanbuf
);
416 VirtualFree(This
->asmstubs
, 0, MEM_RELEASE
);
422 static HRESULT WINAPI
424 LPRPCPROXYBUFFER iface
,IRpcChannelBuffer
* pRpcChannelBuffer
)
426 ICOM_THIS_MULTI(TMProxyImpl
, lpvtbl2
, iface
);
428 TRACE("(%p)\n", pRpcChannelBuffer
);
430 EnterCriticalSection(&This
->crit
);
432 IRpcChannelBuffer_AddRef(pRpcChannelBuffer
);
433 This
->chanbuf
= pRpcChannelBuffer
;
435 LeaveCriticalSection(&This
->crit
);
437 if (This
->dispatch_proxy
)
438 IRpcProxyBuffer_Connect(This
->dispatch_proxy
, pRpcChannelBuffer
);
444 TMProxyImpl_Disconnect(LPRPCPROXYBUFFER iface
)
446 ICOM_THIS_MULTI(TMProxyImpl
, lpvtbl2
, iface
);
450 EnterCriticalSection(&This
->crit
);
452 IRpcChannelBuffer_Release(This
->chanbuf
);
453 This
->chanbuf
= NULL
;
455 LeaveCriticalSection(&This
->crit
);
457 if (This
->dispatch_proxy
)
458 IRpcProxyBuffer_Disconnect(This
->dispatch_proxy
);
462 static const IRpcProxyBufferVtbl tmproxyvtable
= {
463 TMProxyImpl_QueryInterface
,
467 TMProxyImpl_Disconnect
470 /* how much space do we use on stack in DWORD steps. */
475 return 8/sizeof(DWORD
);
477 return sizeof(double)/sizeof(DWORD
);
479 return sizeof(CY
)/sizeof(DWORD
);
481 return sizeof(DATE
)/sizeof(DWORD
);
483 return (sizeof(VARIANT
)+3)/sizeof(DWORD
);
490 _xsize(TYPEDESC
*td
) {
495 return sizeof(VARIANT
)+3;
498 ARRAYDESC
*adesc
= td
->u
.lpadesc
;
500 for (i
=0;i
<adesc
->cDims
;i
++)
501 arrsize
*= adesc
->rgbounds
[i
].cElements
;
502 return arrsize
*_xsize(&adesc
->tdescElem
);
530 TRACE("(tdesc.vt %s)\n",debugstr_vt(tdesc
->vt
));
533 case VT_EMPTY
: /* nothing. empty variant for instance */
539 if (debugout
) TRACE_(olerelay
)("%lx%lx",arg
[0],arg
[1]);
541 hres
= xbuf_add(buf
,(LPBYTE
)arg
,8);
551 if (debugout
) TRACE_(olerelay
)("%lx",*arg
);
553 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
558 if (debugout
) TRACE_(olerelay
)("%04lx",*arg
& 0xffff);
560 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
565 if (debugout
) TRACE_(olerelay
)("%02lx",*arg
& 0xff);
567 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
571 if (debugout
) TRACE_(olerelay
)("&0x%lx",*arg
);
573 hres
= xbuf_add(buf
,(LPBYTE
)(DWORD
*)*arg
,sizeof(DWORD
));
574 /* do not dealloc at this time */
578 VARIANT
*vt
= (VARIANT
*)arg
;
579 DWORD vttype
= V_VT(vt
);
581 if (debugout
) TRACE_(olerelay
)("Vt(%s%s)(",debugstr_vt(vttype
),debugstr_vf(vttype
));
584 hres
= xbuf_add(buf
,(LPBYTE
)&vttype
,sizeof(vttype
));
585 if (hres
) return hres
;
587 /* need to recurse since we need to free the stuff */
588 hres
= serialize_param(tinfo
,writeit
,debugout
,dealloc
,&tdesc2
,(DWORD
*)&(V_I4(vt
)),buf
);
589 if (debugout
) TRACE_(olerelay
)(")");
592 case VT_BSTR
|VT_BYREF
: {
593 if (debugout
) TRACE_(olerelay
)("[byref]'%s'", *(BSTR
*)*arg
? relaystr(*((BSTR
*)*arg
)) : "<bstr NULL>");
595 /* ptr to ptr to magic widestring, basically */
596 BSTR
*bstr
= (BSTR
*) *arg
;
599 /* -1 means "null string" which is equivalent to empty string */
601 hres
= xbuf_add(buf
, (LPBYTE
)&len
,sizeof(DWORD
));
602 if (hres
) return hres
;
604 len
= *((DWORD
*)*bstr
-1)/sizeof(WCHAR
);
605 hres
= xbuf_add(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
606 if (hres
) return hres
;
607 hres
= xbuf_add(buf
,(LPBYTE
)*bstr
,len
* sizeof(WCHAR
));
608 if (hres
) return hres
;
612 if (dealloc
&& arg
) {
613 BSTR
*str
= *((BSTR
**)arg
);
622 TRACE_(olerelay
)("%s",relaystr((WCHAR
*)*arg
));
624 TRACE_(olerelay
)("<bstr NULL>");
627 BSTR bstr
= (BSTR
)*arg
;
631 hres
= xbuf_add(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
632 if (hres
) return hres
;
634 len
= *((DWORD
*)bstr
-1)/sizeof(WCHAR
);
635 hres
= xbuf_add(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
636 if (hres
) return hres
;
637 hres
= xbuf_add(buf
,(LPBYTE
)bstr
,len
* sizeof(WCHAR
));
638 if (hres
) return hres
;
643 SysFreeString((BSTR
)*arg
);
648 BOOL derefhere
= TRUE
;
650 if (tdesc
->u
.lptdesc
->vt
== VT_USERDEFINED
) {
654 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.lptdesc
->u
.hreftype
,&tinfo2
);
656 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc
->u
.lptdesc
->u
.hreftype
);
659 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
660 switch (tattr
->typekind
) {
661 case TKIND_ENUM
: /* confirmed */
662 case TKIND_RECORD
: /* FIXME: mostly untested */
665 case TKIND_ALIAS
: /* FIXME: untested */
666 case TKIND_DISPATCH
: /* will be done in VT_USERDEFINED case */
667 case TKIND_INTERFACE
: /* will be done in VT_USERDEFINED case */
671 FIXME("unhandled switch cases tattr->typekind %d\n", tattr
->typekind
);
675 ITypeInfo_Release(tinfo2
);
678 if (debugout
) TRACE_(olerelay
)("*");
679 /* Write always, so the other side knows when it gets a NULL pointer.
681 cookie
= *arg
? 0x42424242 : 0;
682 hres
= xbuf_add(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
686 if (debugout
) TRACE_(olerelay
)("NULL");
689 hres
= serialize_param(tinfo
,writeit
,debugout
,dealloc
,tdesc
->u
.lptdesc
,(DWORD
*)*arg
,buf
);
690 if (derefhere
&& dealloc
) HeapFree(GetProcessHeap(),0,(LPVOID
)*arg
);
694 if (debugout
) TRACE_(olerelay
)("unk(0x%lx)",*arg
);
696 hres
= _marshal_interface(buf
,&IID_IUnknown
,(LPUNKNOWN
)*arg
);
697 if (dealloc
&& *(IUnknown
**)arg
)
698 IUnknown_Release((LPUNKNOWN
)*arg
);
701 if (debugout
) TRACE_(olerelay
)("idisp(0x%lx)",*arg
);
703 hres
= _marshal_interface(buf
,&IID_IDispatch
,(LPUNKNOWN
)*arg
);
704 if (dealloc
&& *(IUnknown
**)arg
)
705 IUnknown_Release((LPUNKNOWN
)*arg
);
708 if (debugout
) TRACE_(olerelay
)("<void>");
710 case VT_USERDEFINED
: {
714 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.hreftype
,&tinfo2
);
716 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc
->u
.hreftype
);
719 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
720 switch (tattr
->typekind
) {
722 case TKIND_INTERFACE
:
724 hres
=_marshal_interface(buf
,&(tattr
->guid
),(LPUNKNOWN
)arg
);
726 IUnknown_Release((LPUNKNOWN
)arg
);
730 if (debugout
) TRACE_(olerelay
)("{");
731 for (i
=0;i
<tattr
->cVars
;i
++) {
736 hres
= ITypeInfo2_GetVarDesc(tinfo2
, i
, &vdesc
);
738 ERR("Could not get vardesc of %d\n",i
);
741 /* Need them for hack below */
743 memset(names,0,sizeof(names));
744 hres = ITypeInfo_GetNames(tinfo2,vdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
745 if (nrofnames > sizeof(names)/sizeof(names[0])) {
746 ERR("Need more names!\n");
748 if (!hres && debugout)
749 TRACE_(olerelay)("%s=",relaystr(names[0]));
751 elem2
= &vdesc
->elemdescVar
;
752 tdesc2
= &elem2
->tdesc
;
753 hres
= serialize_param(
759 (DWORD
*)(((LPBYTE
)arg
)+vdesc
->u
.oInst
),
762 ITypeInfo_ReleaseVarDesc(tinfo2
, vdesc
);
765 if (debugout
&& (i
<(tattr
->cVars
-1)))
766 TRACE_(olerelay
)(",");
768 if (debugout
) TRACE_(olerelay
)("}");
772 return serialize_param(tinfo2
,writeit
,debugout
,dealloc
,&tattr
->tdescAlias
,arg
,buf
);
775 if (debugout
) TRACE_(olerelay
)("%lx",*arg
);
777 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
780 FIXME("Unhandled typekind %d\n",tattr
->typekind
);
784 ITypeInfo_Release(tinfo2
);
788 ARRAYDESC
*adesc
= tdesc
->u
.lpadesc
;
791 if (debugout
) TRACE_(olerelay
)("carr");
792 for (i
=0;i
<adesc
->cDims
;i
++) {
793 if (debugout
) TRACE_(olerelay
)("[%ld]",adesc
->rgbounds
[i
].cElements
);
794 arrsize
*= adesc
->rgbounds
[i
].cElements
;
796 if (debugout
) TRACE_(olerelay
)("(vt %s)",debugstr_vt(adesc
->tdescElem
.vt
));
797 if (debugout
) TRACE_(olerelay
)("[");
798 for (i
=0;i
<arrsize
;i
++) {
799 hres
= serialize_param(tinfo
, writeit
, debugout
, dealloc
, &adesc
->tdescElem
, (DWORD
*)((LPBYTE
)arg
+i
*_xsize(&adesc
->tdescElem
)), buf
);
802 if (debugout
&& (i
<arrsize
-1)) TRACE_(olerelay
)(",");
804 if (debugout
) TRACE_(olerelay
)("]");
810 unsigned long flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
811 unsigned long size
= LPSAFEARRAY_UserSize(&flags
, buf
->curoff
, (LPSAFEARRAY
*)arg
);
812 xbuf_resize(buf
, size
);
813 LPSAFEARRAY_UserMarshal(&flags
, buf
->base
+ buf
->curoff
, (LPSAFEARRAY
*)arg
);
819 ERR("Unhandled marshal type %d.\n",tdesc
->vt
);
836 TRACE("vt %s at %p\n",debugstr_vt(tdesc
->vt
),arg
);
841 if (debugout
) TRACE_(olerelay
)("<empty>");
844 if (debugout
) TRACE_(olerelay
)("<null>");
847 VARIANT
*vt
= (VARIANT
*)arg
;
852 hres
= xbuf_get(buf
,(LPBYTE
)&vttype
,sizeof(vttype
));
854 FIXME("vt type not read?\n");
857 memset(&tdesc2
,0,sizeof(tdesc2
));
860 if (debugout
) TRACE_(olerelay
)("Vt(%s%s)(",debugstr_vt(vttype
),debugstr_vf(vttype
));
861 hres
= deserialize_param(tinfo
, readit
, debugout
, alloc
, &tdesc2
, (DWORD
*)&(V_I4(vt
)), buf
);
862 TRACE_(olerelay
)(")");
873 hres
= xbuf_get(buf
,(LPBYTE
)arg
,8);
874 if (hres
) ERR("Failed to read integer 8 byte\n");
876 if (debugout
) TRACE_(olerelay
)("%lx%lx",arg
[0],arg
[1]);
886 hres
= xbuf_get(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
887 if (hres
) ERR("Failed to read integer 4 byte\n");
889 if (debugout
) TRACE_(olerelay
)("%lx",*arg
);
895 hres
= xbuf_get(buf
,(LPBYTE
)&x
,sizeof(DWORD
));
896 if (hres
) ERR("Failed to read integer 4 byte\n");
899 if (debugout
) TRACE_(olerelay
)("%04lx",*arg
& 0xffff);
905 hres
= xbuf_get(buf
,(LPBYTE
)&x
,sizeof(DWORD
));
906 if (hres
) ERR("Failed to read integer 4 byte\n");
909 if (debugout
) TRACE_(olerelay
)("%02lx",*arg
& 0xff);
914 *arg
= (DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DWORD
));
916 hres
= xbuf_get(buf
,(LPBYTE
)*arg
,sizeof(DWORD
));
917 if (hres
) ERR("Failed to read integer 4 byte\n");
919 if (debugout
) TRACE_(olerelay
)("&0x%lx",*(DWORD
*)*arg
);
921 case VT_BSTR
|VT_BYREF
: {
922 BSTR
**bstr
= (BSTR
**)arg
;
927 hres
= xbuf_get(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
929 ERR("failed to read bstr klen\n");
933 *bstr
= CoTaskMemAlloc(sizeof(BSTR
*));
935 if (debugout
) TRACE_(olerelay
)("<bstr NULL>");
937 str
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,(len
+1)*sizeof(WCHAR
));
938 hres
= xbuf_get(buf
,(LPBYTE
)str
,len
*sizeof(WCHAR
));
940 ERR("Failed to read BSTR.\n");
943 *bstr
= CoTaskMemAlloc(sizeof(BSTR
*));
944 **bstr
= SysAllocStringLen(str
,len
);
945 if (debugout
) TRACE_(olerelay
)("%s",relaystr(str
));
946 HeapFree(GetProcessHeap(),0,str
);
958 hres
= xbuf_get(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
960 ERR("failed to read bstr klen\n");
965 if (debugout
) TRACE_(olerelay
)("<bstr NULL>");
967 str
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,(len
+1)*sizeof(WCHAR
));
968 hres
= xbuf_get(buf
,(LPBYTE
)str
,len
*sizeof(WCHAR
));
970 ERR("Failed to read BSTR.\n");
973 *arg
= (DWORD
)SysAllocStringLen(str
,len
);
974 if (debugout
) TRACE_(olerelay
)("%s",relaystr(str
));
975 HeapFree(GetProcessHeap(),0,str
);
984 BOOL derefhere
= TRUE
;
986 if (tdesc
->u
.lptdesc
->vt
== VT_USERDEFINED
) {
990 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.lptdesc
->u
.hreftype
,&tinfo2
);
992 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc
->u
.lptdesc
->u
.hreftype
);
995 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
996 switch (tattr
->typekind
) {
997 case TKIND_ENUM
: /* confirmed */
998 case TKIND_RECORD
: /* FIXME: mostly untested */
1001 case TKIND_ALIAS
: /* FIXME: untested */
1002 case TKIND_DISPATCH
: /* will be done in VT_USERDEFINED case */
1003 case TKIND_INTERFACE
: /* will be done in VT_USERDEFINED case */
1007 FIXME("unhandled switch cases tattr->typekind %d\n", tattr
->typekind
);
1011 ITypeInfo_Release(tinfo2
);
1013 /* read it in all cases, we need to know if we have
1014 * NULL pointer or not.
1016 hres
= xbuf_get(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
1018 ERR("Failed to load pointer cookie.\n");
1021 if (cookie
!= 0x42424242) {
1022 /* we read a NULL ptr from the remote side */
1023 if (debugout
) TRACE_(olerelay
)("NULL");
1027 if (debugout
) TRACE_(olerelay
)("*");
1029 /* Allocate space for the referenced struct */
1031 *arg
=(DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,_xsize(tdesc
->u
.lptdesc
));
1034 return deserialize_param(tinfo
, readit
, debugout
, alloc
, tdesc
->u
.lptdesc
, (LPDWORD
)*arg
, buf
);
1036 return deserialize_param(tinfo
, readit
, debugout
, alloc
, tdesc
->u
.lptdesc
, arg
, buf
);
1039 /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
1041 *arg
=(DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DWORD
));
1044 hres
= _unmarshal_interface(buf
,&IID_IUnknown
,(LPUNKNOWN
*)arg
);
1046 TRACE_(olerelay
)("unk(%p)",arg
);
1051 hres
= _unmarshal_interface(buf
,&IID_IDispatch
,(LPUNKNOWN
*)arg
);
1053 TRACE_(olerelay
)("idisp(%p)",arg
);
1056 if (debugout
) TRACE_(olerelay
)("<void>");
1058 case VT_USERDEFINED
: {
1062 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.hreftype
,&tinfo2
);
1064 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc
->u
.hreftype
);
1067 hres
= ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
1069 ERR("Could not get typeattr in VT_USERDEFINED.\n");
1071 switch (tattr
->typekind
) {
1072 case TKIND_DISPATCH
:
1073 case TKIND_INTERFACE
:
1075 hres
= _unmarshal_interface(buf
,&(tattr
->guid
),(LPUNKNOWN
*)arg
);
1077 case TKIND_RECORD
: {
1081 *arg
= (DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,tattr
->cbSizeInstance
);
1083 if (debugout
) TRACE_(olerelay
)("{");
1084 for (i
=0;i
<tattr
->cVars
;i
++) {
1087 hres
= ITypeInfo2_GetVarDesc(tinfo2
, i
, &vdesc
);
1089 ERR("Could not get vardesc of %d\n",i
);
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 return deserialize_param(tinfo2
,readit
,debugout
,alloc
,&tattr
->tdescAlias
,arg
,buf
);
1111 hres
= xbuf_get(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
1112 if (hres
) ERR("Failed to read enum (4 byte)\n");
1114 if (debugout
) TRACE_(olerelay
)("%lx",*arg
);
1117 ERR("Unhandled typekind %d\n",tattr
->typekind
);
1123 ERR("failed to stuballoc in TKIND_RECORD.\n");
1124 ITypeInfo_Release(tinfo2
);
1128 /* arg is pointing to the start of the array. */
1129 ARRAYDESC
*adesc
= tdesc
->u
.lpadesc
;
1132 if (adesc
->cDims
> 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
1133 for (i
=0;i
<adesc
->cDims
;i
++)
1134 arrsize
*= adesc
->rgbounds
[i
].cElements
;
1135 for (i
=0;i
<arrsize
;i
++)
1142 (DWORD
*)((LPBYTE
)(arg
)+i
*_xsize(&adesc
->tdescElem
)),
1147 case VT_SAFEARRAY
: {
1150 unsigned long flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
1151 unsigned char *buffer
;
1152 buffer
= LPSAFEARRAY_UserUnmarshal(&flags
, buf
->base
+ buf
->curoff
, (LPSAFEARRAY
*)arg
);
1153 buf
->curoff
= buffer
- buf
->base
;
1158 ERR("No handler for VT type %d!\n",tdesc
->vt
);
1164 /* Searches function, also in inherited interfaces */
1167 ITypeInfo
*tinfo
, int iMethod
, ITypeInfo
**tactual
, const FUNCDESC
**fdesc
, BSTR
*iname
, BSTR
*fname
)
1172 if (fname
) *fname
= NULL
;
1173 if (iname
) *iname
= NULL
;
1176 ITypeInfo_AddRef(*tactual
);
1179 hres
= ITypeInfoImpl_GetInternalFuncDesc(tinfo
, i
, fdesc
);
1186 hres
= ITypeInfo_GetTypeAttr(tinfo
, &attr
);
1188 ERR("GetTypeAttr failed with %lx\n",hres
);
1191 /* Not found, so look in inherited ifaces. */
1192 for (j
=0;j
<attr
->cImplTypes
;j
++) {
1193 hres
= ITypeInfo_GetRefTypeOfImplType(tinfo
, j
, &href
);
1195 ERR("Did not find a reftype for interface offset %d?\n",j
);
1198 hres
= ITypeInfo_GetRefTypeInfo(tinfo
, href
, &tinfo2
);
1200 ERR("Did not find a typeinfo for reftype %ld?\n",href
);
1203 hres
= _get_funcdesc(tinfo2
,iMethod
,tactual
,fdesc
,iname
,fname
);
1204 ITypeInfo_Release(tinfo2
);
1205 if (!hres
) return S_OK
;
1209 if (((*fdesc
)->oVft
/4) == iMethod
) {
1211 ITypeInfo_GetDocumentation(tinfo
,(*fdesc
)->memid
,fname
,NULL
,NULL
,NULL
);
1213 ITypeInfo_GetDocumentation(tinfo
,-1,iname
,NULL
,NULL
,NULL
);
1221 xCall(LPVOID retptr
, int method
, TMProxyImpl
*tpinfo
/*, args */)
1223 DWORD
*args
= ((DWORD
*)&tpinfo
)+1, *xargs
;
1224 const FUNCDESC
*fdesc
;
1226 int i
, relaydeb
= TRACE_ON(olerelay
);
1233 DWORD remoteresult
= 0;
1235 IRpcChannelBuffer
*chanbuf
;
1237 EnterCriticalSection(&tpinfo
->crit
);
1239 hres
= _get_funcdesc(tpinfo
->tinfo
,method
,&tinfo
,&fdesc
,&iname
,&fname
);
1241 ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method
);
1242 ITypeInfo_Release(tinfo
);
1243 LeaveCriticalSection(&tpinfo
->crit
);
1247 if (!tpinfo
->chanbuf
)
1249 WARN("Tried to use disconnected proxy\n");
1250 ITypeInfo_Release(tinfo
);
1251 LeaveCriticalSection(&tpinfo
->crit
);
1252 return RPC_E_DISCONNECTED
;
1254 chanbuf
= tpinfo
->chanbuf
;
1255 IRpcChannelBuffer_AddRef(chanbuf
);
1257 LeaveCriticalSection(&tpinfo
->crit
);
1260 TRACE_(olerelay
)("->");
1262 TRACE_(olerelay
)("%s:",relaystr(iname
));
1264 TRACE_(olerelay
)("%s(%d)",relaystr(fname
),method
);
1266 TRACE_(olerelay
)("%d",method
);
1267 TRACE_(olerelay
)("(");
1270 if (iname
) SysFreeString(iname
);
1271 if (fname
) SysFreeString(fname
);
1273 memset(&buf
,0,sizeof(buf
));
1275 /* normal typelib driven serializing */
1277 /* Need them for hack below */
1278 memset(names
,0,sizeof(names
));
1279 if (ITypeInfo_GetNames(tinfo
,fdesc
->memid
,names
,sizeof(names
)/sizeof(names
[0]),&nrofnames
))
1281 if (nrofnames
> sizeof(names
)/sizeof(names
[0]))
1282 ERR("Need more names!\n");
1285 for (i
=0;i
<fdesc
->cParams
;i
++) {
1286 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1288 if (i
) TRACE_(olerelay
)(",");
1289 if (i
+1<nrofnames
&& names
[i
+1])
1290 TRACE_(olerelay
)("%s=",relaystr(names
[i
+1]));
1292 /* No need to marshal other data than FIN and any VT_PTR. */
1293 if (!(elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
|| !elem
->u
.paramdesc
.wParamFlags
) && (elem
->tdesc
.vt
!= VT_PTR
)) {
1294 xargs
+=_argsize(elem
->tdesc
.vt
);
1295 if (relaydeb
) TRACE_(olerelay
)("[out]");
1298 hres
= serialize_param(
1300 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
|| !elem
->u
.paramdesc
.wParamFlags
,
1309 ERR("Failed to serialize param, hres %lx\n",hres
);
1312 xargs
+=_argsize(elem
->tdesc
.vt
);
1314 if (relaydeb
) TRACE_(olerelay
)(")");
1316 memset(&msg
,0,sizeof(msg
));
1317 msg
.cbBuffer
= buf
.curoff
;
1318 msg
.iMethod
= method
;
1319 hres
= IRpcChannelBuffer_GetBuffer(chanbuf
,&msg
,&(tpinfo
->iid
));
1321 ERR("RpcChannelBuffer GetBuffer failed, %lx\n",hres
);
1324 memcpy(msg
.Buffer
,buf
.base
,buf
.curoff
);
1325 if (relaydeb
) TRACE_(olerelay
)("\n");
1326 hres
= IRpcChannelBuffer_SendReceive(chanbuf
,&msg
,&status
);
1328 ERR("RpcChannelBuffer SendReceive failed, %lx\n",hres
);
1332 if (relaydeb
) TRACE_(olerelay
)(" status = %08lx (",status
);
1334 buf
.base
= HeapReAlloc(GetProcessHeap(),0,buf
.base
,msg
.cbBuffer
);
1336 buf
.base
= HeapAlloc(GetProcessHeap(),0,msg
.cbBuffer
);
1337 buf
.size
= msg
.cbBuffer
;
1338 memcpy(buf
.base
,msg
.Buffer
,buf
.size
);
1341 /* generic deserializer using typelib description */
1344 for (i
=0;i
<fdesc
->cParams
;i
++) {
1345 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1348 if (i
) TRACE_(olerelay
)(",");
1349 if (i
+1<nrofnames
&& names
[i
+1]) TRACE_(olerelay
)("%s=",relaystr(names
[i
+1]));
1351 /* No need to marshal other data than FOUT and any VT_PTR */
1352 if (!(elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
) && (elem
->tdesc
.vt
!= VT_PTR
)) {
1353 xargs
+= _argsize(elem
->tdesc
.vt
);
1354 if (relaydeb
) TRACE_(olerelay
)("[in]");
1357 hres
= deserialize_param(
1359 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
1367 ERR("Failed to unmarshall param, hres %lx\n",hres
);
1371 xargs
+= _argsize(elem
->tdesc
.vt
);
1374 hres
= xbuf_get(&buf
, (LPBYTE
)&remoteresult
, sizeof(DWORD
));
1377 if (relaydeb
) TRACE_(olerelay
)(") = %08lx\n", remoteresult
);
1379 hres
= remoteresult
;
1382 HeapFree(GetProcessHeap(),0,buf
.base
);
1383 IRpcChannelBuffer_Release(chanbuf
);
1384 ITypeInfo_Release(tinfo
);
1385 TRACE("-- 0x%08lx\n", hres
);
1389 static HRESULT WINAPI
ProxyIUnknown_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
1391 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1393 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
1395 if (proxy
->outerunknown
)
1396 return IUnknown_QueryInterface(proxy
->outerunknown
, riid
, ppv
);
1398 FIXME("No interface\n");
1399 return E_NOINTERFACE
;
1402 static ULONG WINAPI
ProxyIUnknown_AddRef(IUnknown
*iface
)
1404 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1408 if (proxy
->outerunknown
)
1409 return IUnknown_AddRef(proxy
->outerunknown
);
1411 return 2; /* FIXME */
1414 static ULONG WINAPI
ProxyIUnknown_Release(IUnknown
*iface
)
1416 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1420 if (proxy
->outerunknown
)
1421 return IUnknown_Release(proxy
->outerunknown
);
1423 return 1; /* FIXME */
1426 static HRESULT WINAPI
ProxyIDispatch_GetTypeInfoCount(LPDISPATCH iface
, UINT
* pctinfo
)
1428 TMProxyImpl
*This
= (TMProxyImpl
*)iface
;
1430 TRACE("(%p)\n", pctinfo
);
1432 return IDispatch_GetTypeInfoCount(This
->dispatch
, pctinfo
);
1435 static HRESULT WINAPI
ProxyIDispatch_GetTypeInfo(LPDISPATCH iface
, UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
1437 TMProxyImpl
*This
= (TMProxyImpl
*)iface
;
1439 TRACE("(%d, %lx, %p)\n", iTInfo
, lcid
, ppTInfo
);
1441 return IDispatch_GetTypeInfo(This
->dispatch
, iTInfo
, lcid
, ppTInfo
);
1444 static HRESULT WINAPI
ProxyIDispatch_GetIDsOfNames(LPDISPATCH iface
, REFIID riid
, LPOLESTR
* rgszNames
, UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
1446 TMProxyImpl
*This
= (TMProxyImpl
*)iface
;
1448 TRACE("(%s, %p, %d, 0x%lx, %p)\n", debugstr_guid(riid
), rgszNames
, cNames
, lcid
, rgDispId
);
1450 return IDispatch_GetIDsOfNames(This
->dispatch
, riid
, rgszNames
,
1451 cNames
, lcid
, rgDispId
);
1454 static HRESULT WINAPI
ProxyIDispatch_Invoke(LPDISPATCH iface
, DISPID dispIdMember
, REFIID riid
, LCID lcid
,
1455 WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
,
1456 EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
1458 TMProxyImpl
*This
= (TMProxyImpl
*)iface
;
1460 TRACE("(%ld, %s, 0x%lx, 0x%x, %p, %p, %p, %p)\n", dispIdMember
,
1461 debugstr_guid(riid
), lcid
, wFlags
, pDispParams
, pVarResult
,
1462 pExcepInfo
, puArgErr
);
1464 return IDispatch_Invoke(This
->dispatch
, dispIdMember
, riid
, lcid
,
1465 wFlags
, pDispParams
, pVarResult
, pExcepInfo
,
1469 static inline HRESULT
get_facbuf_for_iid(REFIID riid
, IPSFactoryBuffer
**facbuf
)
1474 if ((hr
= CoGetPSClsid(riid
, &clsid
)))
1476 return CoGetClassObject(&clsid
, CLSCTX_INPROC_SERVER
, NULL
,
1477 &IID_IPSFactoryBuffer
, (LPVOID
*)facbuf
);
1480 static HRESULT WINAPI
1481 PSFacBuf_CreateProxy(
1482 LPPSFACTORYBUFFER iface
, IUnknown
* pUnkOuter
, REFIID riid
,
1483 IRpcProxyBuffer
**ppProxy
, LPVOID
*ppv
)
1488 const FUNCDESC
*fdesc
;
1492 TRACE("(...%s...)\n",debugstr_guid(riid
));
1493 hres
= _get_typeinfo_for_iid(riid
,&tinfo
);
1495 ERR("No typeinfo for %s?\n",debugstr_guid(riid
));
1498 nroffuncs
= _nroffuncs(tinfo
);
1499 proxy
= CoTaskMemAlloc(sizeof(TMProxyImpl
));
1500 if (!proxy
) return E_OUTOFMEMORY
;
1502 assert(sizeof(TMAsmProxy
) == 12);
1504 proxy
->dispatch
= NULL
;
1505 proxy
->dispatch_proxy
= NULL
;
1506 proxy
->outerunknown
= pUnkOuter
;
1507 proxy
->asmstubs
= VirtualAlloc(NULL
, sizeof(TMAsmProxy
) * nroffuncs
, MEM_COMMIT
, PAGE_EXECUTE_READWRITE
);
1508 if (!proxy
->asmstubs
) {
1509 ERR("Could not commit pages for proxy thunks\n");
1510 CoTaskMemFree(proxy
);
1511 return E_OUTOFMEMORY
;
1514 InitializeCriticalSection(&proxy
->crit
);
1516 proxy
->lpvtbl
= HeapAlloc(GetProcessHeap(),0,sizeof(LPBYTE
)*nroffuncs
);
1517 for (i
=0;i
<nroffuncs
;i
++) {
1518 TMAsmProxy
*xasm
= proxy
->asmstubs
+i
;
1522 proxy
->lpvtbl
[i
] = ProxyIUnknown_QueryInterface
;
1525 proxy
->lpvtbl
[i
] = ProxyIUnknown_AddRef
;
1528 proxy
->lpvtbl
[i
] = ProxyIUnknown_Release
;
1532 /* nrofargs without This */
1535 hres
= _get_funcdesc(tinfo
,i
,&tinfo2
,&fdesc
,NULL
,NULL
);
1536 ITypeInfo_Release(tinfo2
);
1538 ERR("GetFuncDesc %lx should not fail here.\n",hres
);
1541 /* some args take more than 4 byte on the stack */
1543 for (j
=0;j
<fdesc
->cParams
;j
++)
1544 nrofargs
+= _argsize(fdesc
->lprgelemdescParam
[j
].tdesc
.vt
);
1547 if (fdesc
->callconv
!= CC_STDCALL
) {
1548 ERR("calling convention is not stdcall????\n");
1551 /* popl %eax - return ptr
1558 * arg3 arg2 arg1 <method> <returnptr>
1560 xasm
->popleax
= 0x58;
1561 xasm
->pushlval
= 0x6a;
1563 xasm
->pushleax
= 0x50;
1564 xasm
->lcall
= 0xe8; /* relative jump */
1565 xasm
->xcall
= (DWORD
)xCall
;
1566 xasm
->xcall
-= (DWORD
)&(xasm
->lret
);
1568 xasm
->bytestopop
= (nrofargs
+2)*4; /* pop args, This, iMethod */
1569 proxy
->lpvtbl
[i
] = xasm
;
1572 FIXME("not implemented on non i386\n");
1579 /* if we derive from IDispatch then defer to its proxy for its methods */
1580 hres
= ITypeInfo_GetTypeAttr(tinfo
, &typeattr
);
1583 if (typeattr
->wTypeFlags
& TYPEFLAG_FDISPATCHABLE
)
1585 IPSFactoryBuffer
*factory_buffer
;
1586 hres
= get_facbuf_for_iid(&IID_IDispatch
, &factory_buffer
);
1589 hres
= IPSFactoryBuffer_CreateProxy(factory_buffer
, NULL
,
1590 &IID_IDispatch
, &proxy
->dispatch_proxy
,
1591 (void **)&proxy
->dispatch
);
1592 IPSFactoryBuffer_Release(factory_buffer
);
1596 proxy
->lpvtbl
[3] = ProxyIDispatch_GetTypeInfoCount
;
1597 proxy
->lpvtbl
[4] = ProxyIDispatch_GetTypeInfo
;
1598 proxy
->lpvtbl
[5] = ProxyIDispatch_GetIDsOfNames
;
1599 proxy
->lpvtbl
[6] = ProxyIDispatch_Invoke
;
1602 ITypeInfo_ReleaseTypeAttr(tinfo
, typeattr
);
1605 proxy
->lpvtbl2
= &tmproxyvtable
;
1606 /* one reference for the proxy */
1608 proxy
->tinfo
= tinfo
;
1609 memcpy(&proxy
->iid
,riid
,sizeof(*riid
));
1613 *ppv
= (LPVOID
)proxy
;
1614 *ppProxy
= (IRpcProxyBuffer
*)&(proxy
->lpvtbl2
);
1615 IUnknown_AddRef((IUnknown
*)*ppv
);
1619 TMProxyImpl_Release((IRpcProxyBuffer
*)&proxy
->lpvtbl2
);
1623 typedef struct _TMStubImpl
{
1624 const IRpcStubBufferVtbl
*lpvtbl
;
1630 IRpcStubBuffer
*dispatch_stub
;
1633 static HRESULT WINAPI
1634 TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface
, REFIID riid
, LPVOID
*ppv
)
1636 if (IsEqualIID(riid
,&IID_IRpcStubBuffer
)||IsEqualIID(riid
,&IID_IUnknown
)){
1637 *ppv
= (LPVOID
)iface
;
1638 IRpcStubBuffer_AddRef(iface
);
1641 FIXME("%s, not supported IID.\n",debugstr_guid(riid
));
1642 return E_NOINTERFACE
;
1646 TMStubImpl_AddRef(LPRPCSTUBBUFFER iface
)
1648 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1649 ULONG refCount
= InterlockedIncrement(&This
->ref
);
1651 TRACE("(%p)->(ref before=%lu)\n", This
, refCount
- 1);
1657 TMStubImpl_Release(LPRPCSTUBBUFFER iface
)
1659 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1660 ULONG refCount
= InterlockedDecrement(&This
->ref
);
1662 TRACE("(%p)->(ref before=%lu)\n", This
, refCount
+ 1);
1666 IRpcStubBuffer_Disconnect(iface
);
1667 ITypeInfo_Release(This
->tinfo
);
1668 CoTaskMemFree(This
);
1673 static HRESULT WINAPI
1674 TMStubImpl_Connect(LPRPCSTUBBUFFER iface
, LPUNKNOWN pUnkServer
)
1676 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1678 TRACE("(%p)->(%p)\n", This
, pUnkServer
);
1680 IUnknown_AddRef(pUnkServer
);
1681 This
->pUnk
= pUnkServer
;
1683 if (This
->dispatch_stub
)
1684 IRpcStubBuffer_Connect(This
->dispatch_stub
, pUnkServer
);
1690 TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface
)
1692 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1694 TRACE("(%p)->()\n", This
);
1698 IUnknown_Release(This
->pUnk
);
1702 if (This
->dispatch_stub
)
1703 IRpcStubBuffer_Disconnect(This
->dispatch_stub
);
1706 static HRESULT WINAPI
1708 LPRPCSTUBBUFFER iface
, RPCOLEMESSAGE
* xmsg
,IRpcChannelBuffer
*rpcchanbuf
)
1711 const FUNCDESC
*fdesc
;
1712 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1714 DWORD
*args
, res
, *xargs
, nrofargs
;
1723 if (xmsg
->iMethod
< 3) {
1724 ERR("IUnknown methods cannot be marshaled by the typelib marshaler\n");
1725 return E_UNEXPECTED
;
1728 if (This
->dispatch_stub
&& xmsg
->iMethod
< sizeof(IDispatchVtbl
)/sizeof(void *))
1729 return IRpcStubBuffer_Invoke(This
->dispatch_stub
, xmsg
, rpcchanbuf
);
1731 memset(&buf
,0,sizeof(buf
));
1732 buf
.size
= xmsg
->cbBuffer
;
1733 buf
.base
= HeapAlloc(GetProcessHeap(), 0, xmsg
->cbBuffer
);
1734 memcpy(buf
.base
, xmsg
->Buffer
, xmsg
->cbBuffer
);
1737 hres
= _get_funcdesc(This
->tinfo
,xmsg
->iMethod
,&tinfo
,&fdesc
,&iname
,NULL
);
1739 ERR("GetFuncDesc on method %ld failed with %lx\n",xmsg
->iMethod
,hres
);
1743 if (iname
&& !lstrcmpW(iname
, IDispatchW
))
1745 ERR("IDispatch cannot be marshaled by the typelib marshaler\n");
1746 ITypeInfo_Release(tinfo
);
1747 return E_UNEXPECTED
;
1750 if (iname
) SysFreeString (iname
);
1752 /* Need them for hack below */
1753 memset(names
,0,sizeof(names
));
1754 ITypeInfo_GetNames(tinfo
,fdesc
->memid
,names
,sizeof(names
)/sizeof(names
[0]),&nrofnames
);
1755 if (nrofnames
> sizeof(names
)/sizeof(names
[0])) {
1756 ERR("Need more names!\n");
1759 /*dump_FUNCDESC(fdesc);*/
1761 for (i
=0;i
<fdesc
->cParams
;i
++)
1762 nrofargs
+= _argsize(fdesc
->lprgelemdescParam
[i
].tdesc
.vt
);
1763 args
= HeapAlloc(GetProcessHeap(),0,(nrofargs
+1)*sizeof(DWORD
));
1764 if (!args
) return E_OUTOFMEMORY
;
1766 /* Allocate all stuff used by call. */
1768 for (i
=0;i
<fdesc
->cParams
;i
++) {
1769 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1771 hres
= deserialize_param(
1773 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
|| !elem
->u
.paramdesc
.wParamFlags
,
1780 xargs
+= _argsize(elem
->tdesc
.vt
);
1782 ERR("Failed to deserialize param %s, hres %lx\n",relaystr(names
[i
+1]),hres
);
1787 args
[0] = (DWORD
)This
->pUnk
;
1789 (*((FARPROC
**)args
[0]))[fdesc
->oVft
/4],
1797 for (i
=0;i
<fdesc
->cParams
;i
++) {
1798 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1799 hres
= serialize_param(
1801 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
1808 xargs
+= _argsize(elem
->tdesc
.vt
);
1810 ERR("Failed to stuballoc param, hres %lx\n",hres
);
1815 hres
= xbuf_add (&buf
, (LPBYTE
)&res
, sizeof(DWORD
));
1819 ITypeInfo_Release(tinfo
);
1820 HeapFree(GetProcessHeap(), 0, args
);
1822 xmsg
->cbBuffer
= buf
.curoff
;
1823 hres
= IRpcChannelBuffer_GetBuffer(rpcchanbuf
, xmsg
, &This
->iid
);
1825 ERR("IRpcChannelBuffer_GetBuffer failed with error 0x%08lx\n", hres
);
1828 memcpy(xmsg
->Buffer
, buf
.base
, buf
.curoff
);
1830 HeapFree(GetProcessHeap(), 0, buf
.base
);
1832 TRACE("returning\n");
1836 static LPRPCSTUBBUFFER WINAPI
1837 TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface
, REFIID riid
) {
1838 FIXME("Huh (%s)?\n",debugstr_guid(riid
));
1843 TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface
) {
1844 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1847 return This
->ref
; /*FIXME? */
1850 static HRESULT WINAPI
1851 TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface
, LPVOID
*ppv
) {
1856 TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface
, LPVOID ppv
) {
1860 static const IRpcStubBufferVtbl tmstubvtbl
= {
1861 TMStubImpl_QueryInterface
,
1865 TMStubImpl_Disconnect
,
1867 TMStubImpl_IsIIDSupported
,
1868 TMStubImpl_CountRefs
,
1869 TMStubImpl_DebugServerQueryInterface
,
1870 TMStubImpl_DebugServerRelease
1873 static HRESULT WINAPI
1874 PSFacBuf_CreateStub(
1875 LPPSFACTORYBUFFER iface
, REFIID riid
,IUnknown
*pUnkServer
,
1876 IRpcStubBuffer
** ppStub
1883 TRACE("(%s,%p,%p)\n",debugstr_guid(riid
),pUnkServer
,ppStub
);
1885 hres
= _get_typeinfo_for_iid(riid
,&tinfo
);
1887 ERR("No typeinfo for %s?\n",debugstr_guid(riid
));
1891 stub
= CoTaskMemAlloc(sizeof(TMStubImpl
));
1893 return E_OUTOFMEMORY
;
1894 stub
->lpvtbl
= &tmstubvtbl
;
1896 stub
->tinfo
= tinfo
;
1897 stub
->dispatch_stub
= NULL
;
1898 memcpy(&(stub
->iid
),riid
,sizeof(*riid
));
1899 hres
= IRpcStubBuffer_Connect((LPRPCSTUBBUFFER
)stub
,pUnkServer
);
1900 *ppStub
= (LPRPCSTUBBUFFER
)stub
;
1901 TRACE("IRpcStubBuffer: %p\n", stub
);
1903 ERR("Connect to pUnkServer failed?\n");
1905 /* if we derive from IDispatch then defer to its stub for some of its methods */
1906 hres
= ITypeInfo_GetTypeAttr(tinfo
, &typeattr
);
1909 if (typeattr
->wTypeFlags
& TYPEFLAG_FDISPATCHABLE
)
1911 IPSFactoryBuffer
*factory_buffer
;
1912 hres
= get_facbuf_for_iid(&IID_IDispatch
, &factory_buffer
);
1915 hres
= IPSFactoryBuffer_CreateStub(factory_buffer
, &IID_IDispatch
,
1916 pUnkServer
, &stub
->dispatch_stub
);
1917 IPSFactoryBuffer_Release(factory_buffer
);
1920 ITypeInfo_ReleaseTypeAttr(tinfo
, typeattr
);
1926 static const IPSFactoryBufferVtbl psfacbufvtbl
= {
1927 PSFacBuf_QueryInterface
,
1930 PSFacBuf_CreateProxy
,
1934 /* This is the whole PSFactoryBuffer object, just the vtableptr */
1935 static const IPSFactoryBufferVtbl
*lppsfac
= &psfacbufvtbl
;
1937 /***********************************************************************
1938 * TMARSHAL_DllGetClassObject
1940 HRESULT
TMARSHAL_DllGetClassObject(REFCLSID rclsid
, REFIID iid
,LPVOID
*ppv
)
1942 if (IsEqualIID(iid
,&IID_IPSFactoryBuffer
)) {
1946 return E_NOINTERFACE
;