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
25 #include "wine/port.h"
35 #define NONAMELESSUNION
45 #include "propidl.h" /* for LPSAFEARRAY_User* functions */
48 #include "wine/debug.h"
49 #include "wine/exception.h"
51 static const WCHAR IDispatchW
[] = { 'I','D','i','s','p','a','t','c','h',0};
53 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
54 WINE_DECLARE_DEBUG_CHANNEL(olerelay
);
56 static HRESULT
TMarshalDispatchChannel_Create(
57 IRpcChannelBuffer
*pDelegateChannel
, REFIID tmarshal_riid
,
58 IRpcChannelBuffer
**ppChannel
);
60 typedef struct _marshal_state
{
66 /* used in the olerelay code to avoid having the L"" stuff added by debugstr_w */
67 static char *relaystr(WCHAR
*in
) {
68 char *tmp
= (char *)debugstr_w(in
);
70 tmp
[strlen(tmp
)-1] = '\0';
75 xbuf_resize(marshal_state
*buf
, DWORD newsize
)
77 if(buf
->size
>= newsize
)
82 newsize
= max(newsize
, buf
->size
* 2);
83 buf
->base
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, buf
->base
, newsize
);
89 newsize
= max(newsize
, 256);
90 buf
->base
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, newsize
);
99 xbuf_add(marshal_state
*buf
, const BYTE
*stuff
, DWORD size
)
103 if(buf
->size
- buf
->curoff
< size
)
105 hr
= xbuf_resize(buf
, buf
->size
+ size
);
106 if(FAILED(hr
)) return hr
;
108 memcpy(buf
->base
+buf
->curoff
,stuff
,size
);
114 xbuf_get(marshal_state
*buf
, LPBYTE stuff
, DWORD size
) {
115 if (buf
->size
< buf
->curoff
+size
) return E_FAIL
;
116 memcpy(stuff
,buf
->base
+buf
->curoff
,size
);
122 xbuf_skip(marshal_state
*buf
, DWORD size
) {
123 if (buf
->size
< buf
->curoff
+size
) return E_FAIL
;
129 _unmarshal_interface(marshal_state
*buf
, REFIID riid
, LPUNKNOWN
*pUnk
) {
131 ULARGE_INTEGER newpos
;
132 LARGE_INTEGER seekto
;
137 TRACE("...%s...\n",debugstr_guid(riid
));
140 hres
= xbuf_get(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
142 ERR("xbuf_get failed\n");
146 if (xsize
== 0) return S_OK
;
148 hres
= CreateStreamOnHGlobal(0,TRUE
,&pStm
);
150 ERR("Stream create failed %x\n",hres
);
154 hres
= IStream_Write(pStm
,buf
->base
+buf
->curoff
,xsize
,&res
);
156 ERR("stream write %x\n",hres
);
157 IStream_Release(pStm
);
161 memset(&seekto
,0,sizeof(seekto
));
162 hres
= IStream_Seek(pStm
,seekto
,SEEK_SET
,&newpos
);
164 ERR("Failed Seek %x\n",hres
);
165 IStream_Release(pStm
);
169 hres
= CoUnmarshalInterface(pStm
,riid
,(LPVOID
*)pUnk
);
171 ERR("Unmarshalling interface %s failed with %x\n",debugstr_guid(riid
),hres
);
172 IStream_Release(pStm
);
176 IStream_Release(pStm
);
177 return xbuf_skip(buf
,xsize
);
181 _marshal_interface(marshal_state
*buf
, REFIID riid
, LPUNKNOWN pUnk
) {
182 LPBYTE tempbuf
= NULL
;
183 IStream
*pStm
= NULL
;
185 ULARGE_INTEGER newpos
;
186 LARGE_INTEGER seekto
;
192 /* this is valid, if for instance we serialize
193 * a VT_DISPATCH with NULL ptr which apparently
194 * can happen. S_OK to make sure we continue
197 WARN("pUnk is NULL\n");
199 return xbuf_add(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
202 TRACE("...%s...\n",debugstr_guid(riid
));
204 hres
= CreateStreamOnHGlobal(0,TRUE
,&pStm
);
206 ERR("Stream create failed %x\n",hres
);
210 hres
= CoMarshalInterface(pStm
,riid
,pUnk
,0,NULL
,0);
212 ERR("Marshalling interface %s failed with %x\n", debugstr_guid(riid
), hres
);
216 hres
= IStream_Stat(pStm
,&ststg
,STATFLAG_NONAME
);
218 ERR("Stream stat failed\n");
222 tempbuf
= HeapAlloc(GetProcessHeap(), 0, ststg
.cbSize
.u
.LowPart
);
223 memset(&seekto
,0,sizeof(seekto
));
224 hres
= IStream_Seek(pStm
,seekto
,SEEK_SET
,&newpos
);
226 ERR("Failed Seek %x\n",hres
);
230 hres
= IStream_Read(pStm
,tempbuf
,ststg
.cbSize
.u
.LowPart
,&res
);
232 ERR("Failed Read %x\n",hres
);
236 xsize
= ststg
.cbSize
.u
.LowPart
;
237 xbuf_add(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
238 hres
= xbuf_add(buf
,tempbuf
,ststg
.cbSize
.u
.LowPart
);
240 HeapFree(GetProcessHeap(),0,tempbuf
);
241 IStream_Release(pStm
);
247 xbuf_add(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
248 if (pStm
) IStream_Release(pStm
);
249 HeapFree(GetProcessHeap(), 0, tempbuf
);
253 /********************* OLE Proxy/Stub Factory ********************************/
254 static HRESULT WINAPI
255 PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface
, REFIID iid
, LPVOID
*ppv
) {
256 if (IsEqualIID(iid
,&IID_IPSFactoryBuffer
)||IsEqualIID(iid
,&IID_IUnknown
)) {
258 /* No ref counting, static class */
261 FIXME("(%s) unknown IID?\n",debugstr_guid(iid
));
262 return E_NOINTERFACE
;
265 static ULONG WINAPI
PSFacBuf_AddRef(LPPSFACTORYBUFFER iface
) { return 2; }
266 static ULONG WINAPI
PSFacBuf_Release(LPPSFACTORYBUFFER iface
) { return 1; }
268 struct ifacepsredirect_data
280 struct tlibredirect_data
294 static BOOL
actctx_get_typelib_module(REFIID riid
, WCHAR
*module
, DWORD len
)
296 struct ifacepsredirect_data
*iface
;
297 struct tlibredirect_data
*tlib
;
298 ACTCTX_SECTION_KEYED_DATA data
;
301 data
.cbSize
= sizeof(data
);
302 if (!FindActCtxSectionGuid(0, NULL
, ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION
,
306 iface
= (struct ifacepsredirect_data
*)data
.lpData
;
307 if (!FindActCtxSectionGuid(0, NULL
, ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION
,
308 &iface
->tlbid
, &data
))
311 tlib
= (struct tlibredirect_data
*)data
.lpData
;
312 ptrW
= (WCHAR
*)((BYTE
*)data
.lpSectionBase
+ tlib
->name_offset
);
314 if (tlib
->name_len
/sizeof(WCHAR
) >= len
) {
315 ERR("need larger module buffer, %u\n", tlib
->name_len
);
319 memcpy(module
, ptrW
, tlib
->name_len
);
320 module
[tlib
->name_len
/sizeof(WCHAR
)] = 0;
324 static HRESULT
reg_get_typelib_module(REFIID riid
, WCHAR
*module
, DWORD len
)
327 REGSAM opposite
= (sizeof(void*) == 8) ? KEY_WOW64_32KEY
: KEY_WOW64_64KEY
;
329 char tlguid
[200],typelibkey
[300],interfacekey
[300],ver
[100];
331 DWORD tlguidlen
, verlen
, type
;
334 sprintf( interfacekey
, "Interface\\{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\Typelib",
335 riid
->Data1
, riid
->Data2
, riid
->Data3
,
336 riid
->Data4
[0], riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3],
337 riid
->Data4
[4], riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]
340 err
= RegOpenKeyExA(HKEY_CLASSES_ROOT
,interfacekey
,0,KEY_READ
,&ikey
);
341 if (err
&& (opposite
== KEY_WOW64_32KEY
|| (IsWow64Process(GetCurrentProcess(), &is_wow64
)
343 err
= RegOpenKeyExA(HKEY_CLASSES_ROOT
,interfacekey
,0,KEY_READ
|opposite
,&ikey
);
346 ERR("No %s key found.\n",interfacekey
);
349 tlguidlen
= sizeof(tlguid
);
350 if (RegQueryValueExA(ikey
,NULL
,NULL
,&type
,(LPBYTE
)tlguid
,&tlguidlen
)) {
351 ERR("Getting typelib guid failed.\n");
355 verlen
= sizeof(ver
);
356 if (RegQueryValueExA(ikey
,"Version",NULL
,&type
,(LPBYTE
)ver
,&verlen
)) {
357 ERR("Could not get version value?\n");
362 sprintf(typelibkey
,"Typelib\\%s\\%s\\0\\win%u",tlguid
,ver
,(sizeof(void*) == 8) ? 64 : 32);
363 tlfnlen
= sizeof(tlfn
);
364 if (RegQueryValueA(HKEY_CLASSES_ROOT
,typelibkey
,tlfn
,&tlfnlen
)) {
366 sprintf(typelibkey
,"Typelib\\%s\\%s\\0\\win32",tlguid
,ver
);
367 tlfnlen
= sizeof(tlfn
);
368 if (RegQueryValueA(HKEY_CLASSES_ROOT
,typelibkey
,tlfn
,&tlfnlen
)) {
370 ERR("Could not get typelib fn?\n");
376 MultiByteToWideChar(CP_ACP
, 0, tlfn
, -1, module
, len
);
381 _get_typeinfo_for_iid(REFIID riid
, ITypeInfo
**typeinfo
)
383 OLECHAR moduleW
[260];
390 if (!actctx_get_typelib_module(riid
, moduleW
, sizeof(moduleW
)/sizeof(moduleW
[0]))) {
391 hres
= reg_get_typelib_module(riid
, moduleW
, sizeof(moduleW
)/sizeof(moduleW
[0]));
396 hres
= LoadTypeLib(moduleW
, &typelib
);
398 ERR("Failed to load typelib for %s, but it should be there.\n",debugstr_guid(riid
));
402 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
, riid
, typeinfo
);
403 ITypeLib_Release(typelib
);
405 ERR("typelib does not contain info for %s\n", debugstr_guid(riid
));
411 * Determine the number of functions including all inherited functions
412 * and well as the size of the vtbl.
413 * Note for non-dual dispinterfaces we simply return the size of IDispatch.
415 static HRESULT
num_of_funcs(ITypeInfo
*tinfo
, unsigned int *num
,
416 unsigned int *vtbl_size
)
421 UINT inherited_funcs
= 0, i
;
424 if(vtbl_size
) *vtbl_size
= 0;
426 hr
= ITypeInfo_GetTypeAttr(tinfo
, &attr
);
429 ERR("GetTypeAttr failed with %x\n", hr
);
433 if(attr
->typekind
== TKIND_DISPATCH
)
435 if(attr
->wTypeFlags
& TYPEFLAG_FDUAL
)
439 ITypeInfo_ReleaseTypeAttr(tinfo
, attr
);
440 hr
= ITypeInfo_GetRefTypeOfImplType(tinfo
, -1, &href
);
443 ERR("Unable to get interface href from dual dispinterface\n");
446 hr
= ITypeInfo_GetRefTypeInfo(tinfo
, href
, &tinfo2
);
449 ERR("Unable to get interface from dual dispinterface\n");
452 hr
= num_of_funcs(tinfo2
, num
, vtbl_size
);
453 ITypeInfo_Release(tinfo2
);
456 else /* non-dual dispinterface */
458 /* These will be the size of IDispatchVtbl */
459 *num
= attr
->cbSizeVft
/ sizeof(void *);
460 if(vtbl_size
) *vtbl_size
= attr
->cbSizeVft
;
461 ITypeInfo_ReleaseTypeAttr(tinfo
, attr
);
466 for (i
= 0; i
< attr
->cImplTypes
; i
++)
469 ITypeInfo
*pSubTypeInfo
;
472 hr
= ITypeInfo_GetRefTypeOfImplType(tinfo
, i
, &href
);
473 if (FAILED(hr
)) goto end
;
474 hr
= ITypeInfo_GetRefTypeInfo(tinfo
, href
, &pSubTypeInfo
);
475 if (FAILED(hr
)) goto end
;
477 hr
= num_of_funcs(pSubTypeInfo
, &sub_funcs
, NULL
);
478 ITypeInfo_Release(pSubTypeInfo
);
480 if(FAILED(hr
)) goto end
;
481 inherited_funcs
+= sub_funcs
;
484 *num
= inherited_funcs
+ attr
->cFuncs
;
485 if(vtbl_size
) *vtbl_size
= attr
->cbSizeVft
;
488 ITypeInfo_ReleaseTypeAttr(tinfo
, attr
);
494 #include "pshpack1.h"
495 typedef struct _TMAsmProxy
{
508 #elif defined(__x86_64__)
510 #include "pshpack1.h"
511 typedef struct _TMAsmProxy
{
513 BYTE movq_rsp_rbp
[3];
515 DWORD movq_rcx_0x10rbp
;
516 DWORD movq_rdx_0x18rbp
;
517 DWORD movq_r8_0x20rbp
;
518 DWORD movq_r9_0x28rbp
;
521 DWORD leaq_0x10rbp_rdx
;
525 BYTE movq_rbp_rsp
[3];
534 #pragma message("You need to implement stubless proxies for your architecture")
536 # warning You need to implement stubless proxies for your architecture
538 typedef struct _TMAsmProxy
{
543 typedef struct _TMProxyImpl
{
545 IRpcProxyBuffer IRpcProxyBuffer_iface
;
548 TMAsmProxy
*asmstubs
;
550 IRpcChannelBuffer
* chanbuf
;
552 CRITICAL_SECTION crit
;
553 IUnknown
*outerunknown
;
555 IRpcProxyBuffer
*dispatch_proxy
;
558 static inline TMProxyImpl
*impl_from_IRpcProxyBuffer( IRpcProxyBuffer
*iface
)
560 return CONTAINING_RECORD(iface
, TMProxyImpl
, IRpcProxyBuffer_iface
);
563 static HRESULT WINAPI
564 TMProxyImpl_QueryInterface(LPRPCPROXYBUFFER iface
, REFIID riid
, LPVOID
*ppv
)
567 if (IsEqualIID(riid
,&IID_IUnknown
)||IsEqualIID(riid
,&IID_IRpcProxyBuffer
)) {
569 IRpcProxyBuffer_AddRef(iface
);
572 FIXME("no interface for %s\n",debugstr_guid(riid
));
573 return E_NOINTERFACE
;
577 TMProxyImpl_AddRef(LPRPCPROXYBUFFER iface
)
579 TMProxyImpl
*This
= impl_from_IRpcProxyBuffer( iface
);
580 ULONG refCount
= InterlockedIncrement(&This
->ref
);
582 TRACE("(%p)->(ref before=%u)\n",This
, refCount
- 1);
588 TMProxyImpl_Release(LPRPCPROXYBUFFER iface
)
590 TMProxyImpl
*This
= impl_from_IRpcProxyBuffer( iface
);
591 ULONG refCount
= InterlockedDecrement(&This
->ref
);
593 TRACE("(%p)->(ref before=%u)\n",This
, refCount
+ 1);
597 if (This
->dispatch_proxy
) IRpcProxyBuffer_Release(This
->dispatch_proxy
);
598 This
->crit
.DebugInfo
->Spare
[0] = 0;
599 DeleteCriticalSection(&This
->crit
);
600 if (This
->chanbuf
) IRpcChannelBuffer_Release(This
->chanbuf
);
601 VirtualFree(This
->asmstubs
, 0, MEM_RELEASE
);
602 HeapFree(GetProcessHeap(), 0, This
->lpvtbl
);
603 ITypeInfo_Release(This
->tinfo
);
609 static HRESULT WINAPI
611 LPRPCPROXYBUFFER iface
,IRpcChannelBuffer
* pRpcChannelBuffer
)
613 TMProxyImpl
*This
= impl_from_IRpcProxyBuffer( iface
);
615 TRACE("(%p)\n", pRpcChannelBuffer
);
617 EnterCriticalSection(&This
->crit
);
619 IRpcChannelBuffer_AddRef(pRpcChannelBuffer
);
620 This
->chanbuf
= pRpcChannelBuffer
;
622 LeaveCriticalSection(&This
->crit
);
624 if (This
->dispatch_proxy
)
626 IRpcChannelBuffer
*pDelegateChannel
;
627 HRESULT hr
= TMarshalDispatchChannel_Create(pRpcChannelBuffer
, &This
->iid
, &pDelegateChannel
);
630 hr
= IRpcProxyBuffer_Connect(This
->dispatch_proxy
, pDelegateChannel
);
631 IRpcChannelBuffer_Release(pDelegateChannel
);
639 TMProxyImpl_Disconnect(LPRPCPROXYBUFFER iface
)
641 TMProxyImpl
*This
= impl_from_IRpcProxyBuffer( iface
);
645 EnterCriticalSection(&This
->crit
);
647 IRpcChannelBuffer_Release(This
->chanbuf
);
648 This
->chanbuf
= NULL
;
650 LeaveCriticalSection(&This
->crit
);
652 if (This
->dispatch_proxy
)
653 IRpcProxyBuffer_Disconnect(This
->dispatch_proxy
);
657 static const IRpcProxyBufferVtbl tmproxyvtable
= {
658 TMProxyImpl_QueryInterface
,
662 TMProxyImpl_Disconnect
665 /* how much space do we use on stack in DWORD_PTR steps. */
667 _argsize(TYPEDESC
*tdesc
, ITypeInfo
*tinfo
) {
675 ret
= sizeof(double);
684 ret
= sizeof(DECIMAL
);
687 ret
= sizeof(VARIANT
);
695 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.hreftype
,&tinfo2
);
697 return 0; /* should fail critically in serialize_param */
698 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
699 ret
= tattr
->cbSizeInstance
;
700 ITypeInfo_ReleaseTypeAttr(tinfo2
, tattr
);
701 ITypeInfo_Release(tinfo2
);
705 ret
= sizeof(DWORD_PTR
);
709 return (ret
+ sizeof(DWORD_PTR
) - 1) / sizeof(DWORD_PTR
);
712 /* how much space do we use on the heap (in bytes) */
714 _xsize(const TYPEDESC
*td
, ITypeInfo
*tinfo
) {
721 return sizeof(VARIANT
);
724 const ARRAYDESC
*adesc
= td
->u
.lpadesc
;
726 for (i
=0;i
<adesc
->cDims
;i
++)
727 arrsize
*= adesc
->rgbounds
[i
].cElements
;
728 return arrsize
*_xsize(&adesc
->tdescElem
, tinfo
);
748 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,td
->u
.hreftype
,&tinfo2
);
751 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
752 ret
= tattr
->cbSizeInstance
;
753 ITypeInfo_ReleaseTypeAttr(tinfo2
, tattr
);
754 ITypeInfo_Release(tinfo2
);
758 return sizeof(DWORD_PTR
);
762 /* Whether we pass this type by reference or by value */
764 _passbyref(const TYPEDESC
*td
, ITypeInfo
*tinfo
) {
765 return (td
->vt
== VT_USERDEFINED
||
766 td
->vt
== VT_VARIANT
||
783 TRACE("(tdesc.vt %s)\n",debugstr_vt(tdesc
->vt
));
786 if ((vartype
& 0xf000) == VT_ARRAY
)
787 vartype
= VT_SAFEARRAY
;
796 if (debugout
) TRACE_(olerelay
)("%s\n", wine_dbgstr_longlong(*(ULONGLONG
*)arg
));
798 hres
= xbuf_add(buf
,(LPBYTE
)arg
,8);
807 if (debugout
) TRACE_(olerelay
)("%x\n", *(DWORD
*)arg
);
809 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
815 if (debugout
) TRACE_(olerelay
)("%04x\n", *(WORD
*)arg
);
817 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
822 if (debugout
) TRACE_(olerelay
)("%02x\n", *(BYTE
*)arg
);
824 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
827 if (debugout
) TRACE_(olerelay
)("%s", debugstr_variant((VARIANT
*)arg
));
830 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
831 ULONG size
= VARIANT_UserSize(&flags
, buf
->curoff
, (VARIANT
*)arg
);
832 xbuf_resize(buf
, size
);
833 VARIANT_UserMarshal(&flags
, buf
->base
+ buf
->curoff
, (VARIANT
*)arg
);
838 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
839 VARIANT_UserFree(&flags
, (VARIANT
*)arg
);
844 if (writeit
&& debugout
) {
846 TRACE_(olerelay
)("%s",relaystr((WCHAR
*)*arg
));
848 TRACE_(olerelay
)("<bstr NULL>");
852 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
853 ULONG size
= BSTR_UserSize(&flags
, buf
->curoff
, (BSTR
*)arg
);
854 xbuf_resize(buf
, size
);
855 BSTR_UserMarshal(&flags
, buf
->base
+ buf
->curoff
, (BSTR
*)arg
);
860 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
861 BSTR_UserFree(&flags
, (BSTR
*)arg
);
867 BOOL derefhere
= TRUE
;
869 if (tdesc
->u
.lptdesc
->vt
== VT_USERDEFINED
) {
873 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.lptdesc
->u
.hreftype
,&tinfo2
);
875 ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc
->u
.lptdesc
->u
.hreftype
);
878 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
879 switch (tattr
->typekind
) {
881 if (tattr
->tdescAlias
.vt
== VT_USERDEFINED
)
883 DWORD href
= tattr
->tdescAlias
.u
.hreftype
;
884 ITypeInfo_ReleaseTypeAttr(tinfo
, tattr
);
885 ITypeInfo_Release(tinfo2
);
886 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,href
,&tinfo2
);
888 ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc
->u
.lptdesc
->u
.hreftype
);
891 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
892 derefhere
= (tattr
->typekind
!= TKIND_DISPATCH
&&
893 tattr
->typekind
!= TKIND_INTERFACE
&&
894 tattr
->typekind
!= TKIND_COCLASS
);
897 case TKIND_ENUM
: /* confirmed */
898 case TKIND_RECORD
: /* FIXME: mostly untested */
900 case TKIND_DISPATCH
: /* will be done in VT_USERDEFINED case */
901 case TKIND_INTERFACE
: /* will be done in VT_USERDEFINED case */
902 case TKIND_COCLASS
: /* will be done in VT_USERDEFINED case */
906 FIXME("unhandled switch cases tattr->typekind %d\n", tattr
->typekind
);
910 ITypeInfo_ReleaseTypeAttr(tinfo
, tattr
);
911 ITypeInfo_Release(tinfo2
);
914 if (debugout
) TRACE_(olerelay
)("*");
915 /* Write always, so the other side knows when it gets a NULL pointer.
917 cookie
= *arg
? 0x42424242 : 0;
918 hres
= xbuf_add(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
922 if (debugout
) TRACE_(olerelay
)("NULL");
925 hres
= serialize_param(tinfo
,writeit
,debugout
,dealloc
,tdesc
->u
.lptdesc
,(DWORD_PTR
*)*arg
,buf
);
926 if (derefhere
&& dealloc
) HeapFree(GetProcessHeap(),0,(LPVOID
)*arg
);
930 if (debugout
) TRACE_(olerelay
)("unk(0x%lx)", *arg
);
932 hres
= _marshal_interface(buf
,&IID_IUnknown
,(LPUNKNOWN
)*arg
);
933 if (dealloc
&& *(IUnknown
**)arg
)
934 IUnknown_Release((LPUNKNOWN
)*arg
);
937 if (debugout
) TRACE_(olerelay
)("idisp(0x%lx)", *arg
);
939 hres
= _marshal_interface(buf
,&IID_IDispatch
,(LPUNKNOWN
)*arg
);
940 if (dealloc
&& *(IUnknown
**)arg
)
941 IUnknown_Release((LPUNKNOWN
)*arg
);
944 if (debugout
) TRACE_(olerelay
)("<void>");
946 case VT_USERDEFINED
: {
950 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.hreftype
,&tinfo2
);
952 ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc
->u
.hreftype
);
955 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
956 switch (tattr
->typekind
) {
958 case TKIND_INTERFACE
:
960 hres
=_marshal_interface(buf
,&(tattr
->guid
),(LPUNKNOWN
)arg
);
962 IUnknown_Release((LPUNKNOWN
)arg
);
964 case TKIND_COCLASS
: {
965 GUID iid
= tattr
->guid
;
969 for(i
= 0; i
< tattr
->cImplTypes
; i
++) {
970 if(SUCCEEDED(ITypeInfo_GetImplTypeFlags(tinfo2
, i
, &type_flags
)) &&
971 type_flags
== (IMPLTYPEFLAG_FSOURCE
|IMPLTYPEFLAG_FDEFAULT
)) {
975 if(FAILED(ITypeInfo_GetRefTypeOfImplType(tinfo2
, i
, &href
)))
977 if(FAILED(ITypeInfo_GetRefTypeInfo(tinfo2
, href
, &tinfo3
)))
979 if(SUCCEEDED(ITypeInfo_GetTypeAttr(tinfo3
, &tattr2
))) {
981 ITypeInfo_ReleaseTypeAttr(tinfo3
, tattr2
);
983 ITypeInfo_Release(tinfo3
);
989 hres
=_marshal_interface(buf
, &iid
, (LPUNKNOWN
)arg
);
991 IUnknown_Release((LPUNKNOWN
)arg
);
996 if (debugout
) TRACE_(olerelay
)("{");
997 for (i
=0;i
<tattr
->cVars
;i
++) {
1002 hres
= ITypeInfo_GetVarDesc(tinfo2
, i
, &vdesc
);
1004 ERR("Could not get vardesc of %d\n",i
);
1007 elem2
= &vdesc
->elemdescVar
;
1008 tdesc2
= &elem2
->tdesc
;
1009 hres
= serialize_param(
1015 (DWORD_PTR
*)(((LPBYTE
)arg
)+vdesc
->u
.oInst
),
1018 ITypeInfo_ReleaseVarDesc(tinfo2
, vdesc
);
1021 if (debugout
&& (i
<(tattr
->cVars
-1)))
1022 TRACE_(olerelay
)(",");
1024 if (debugout
) TRACE_(olerelay
)("}");
1028 hres
= serialize_param(tinfo2
,writeit
,debugout
,dealloc
,&tattr
->tdescAlias
,arg
,buf
);
1032 if (debugout
) TRACE_(olerelay
)("%x", *(DWORD
*)arg
);
1034 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
1037 FIXME("Unhandled typekind %d\n",tattr
->typekind
);
1041 ITypeInfo_ReleaseTypeAttr(tinfo2
, tattr
);
1042 ITypeInfo_Release(tinfo2
);
1046 ARRAYDESC
*adesc
= tdesc
->u
.lpadesc
;
1049 if (debugout
) TRACE_(olerelay
)("carr");
1050 for (i
=0;i
<adesc
->cDims
;i
++) {
1051 if (debugout
) TRACE_(olerelay
)("[%d]",adesc
->rgbounds
[i
].cElements
);
1052 arrsize
*= adesc
->rgbounds
[i
].cElements
;
1054 if (debugout
) TRACE_(olerelay
)("(vt %s)",debugstr_vt(adesc
->tdescElem
.vt
));
1055 if (debugout
) TRACE_(olerelay
)("[");
1056 for (i
=0;i
<arrsize
;i
++) {
1057 LPBYTE base
= _passbyref(&adesc
->tdescElem
, tinfo
) ? (LPBYTE
) *arg
: (LPBYTE
) arg
;
1058 hres
= serialize_param(tinfo
, writeit
, debugout
, dealloc
, &adesc
->tdescElem
, (DWORD_PTR
*)((LPBYTE
)base
+i
*_xsize(&adesc
->tdescElem
, tinfo
)), buf
);
1061 if (debugout
&& (i
<arrsize
-1)) TRACE_(olerelay
)(",");
1063 if (debugout
) TRACE_(olerelay
)("]");
1065 HeapFree(GetProcessHeap(), 0, *(void **)arg
);
1068 case VT_SAFEARRAY
: {
1071 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
1072 ULONG size
= LPSAFEARRAY_UserSize(&flags
, buf
->curoff
, (LPSAFEARRAY
*)arg
);
1073 xbuf_resize(buf
, size
);
1074 LPSAFEARRAY_UserMarshal(&flags
, buf
->base
+ buf
->curoff
, (LPSAFEARRAY
*)arg
);
1079 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
1080 LPSAFEARRAY_UserFree(&flags
, (LPSAFEARRAY
*)arg
);
1085 ERR("Unhandled marshal type %d.\n",tdesc
->vt
);
1100 HRESULT hres
= S_OK
;
1103 TRACE("vt %s at %p\n",debugstr_vt(tdesc
->vt
),arg
);
1105 vartype
= tdesc
->vt
;
1106 if ((vartype
& 0xf000) == VT_ARRAY
)
1107 vartype
= VT_SAFEARRAY
;
1114 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
1115 unsigned char *buffer
;
1116 buffer
= VARIANT_UserUnmarshal(&flags
, buf
->base
+ buf
->curoff
, (VARIANT
*)arg
);
1117 buf
->curoff
= buffer
- buf
->base
;
1127 hres
= xbuf_get(buf
,(LPBYTE
)arg
,8);
1128 if (hres
) ERR("Failed to read integer 8 byte\n");
1130 if (debugout
) TRACE_(olerelay
)("%s", wine_dbgstr_longlong(*(ULONGLONG
*)arg
));
1139 hres
= xbuf_get(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
1140 if (hres
) ERR("Failed to read integer 4 byte\n");
1142 if (debugout
) TRACE_(olerelay
)("%x", *(DWORD
*)arg
);
1149 hres
= xbuf_get(buf
,(LPBYTE
)&x
,sizeof(DWORD
));
1150 if (hres
) ERR("Failed to read integer 4 byte\n");
1151 else memcpy(arg
,&x
,2);
1153 if (debugout
) TRACE_(olerelay
)("%04x", *(WORD
*)arg
);
1159 hres
= xbuf_get(buf
,(LPBYTE
)&x
,sizeof(DWORD
));
1160 if (hres
) ERR("Failed to read integer 4 byte\n");
1161 else memcpy(arg
,&x
,1);
1163 if (debugout
) TRACE_(olerelay
)("%02x", *(BYTE
*)arg
);
1168 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
1169 unsigned char *buffer
;
1170 buffer
= BSTR_UserUnmarshal(&flags
, buf
->base
+ buf
->curoff
, (BSTR
*)arg
);
1171 buf
->curoff
= buffer
- buf
->base
;
1172 if (debugout
) TRACE_(olerelay
)("%s",debugstr_w(*(BSTR
*)arg
));
1178 BOOL derefhere
= TRUE
;
1180 if (tdesc
->u
.lptdesc
->vt
== VT_USERDEFINED
) {
1184 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.lptdesc
->u
.hreftype
,&tinfo2
);
1186 ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc
->u
.lptdesc
->u
.hreftype
);
1189 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
1190 switch (tattr
->typekind
) {
1192 if (tattr
->tdescAlias
.vt
== VT_USERDEFINED
)
1194 DWORD href
= tattr
->tdescAlias
.u
.hreftype
;
1195 ITypeInfo_ReleaseTypeAttr(tinfo
, tattr
);
1196 ITypeInfo_Release(tinfo2
);
1197 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,href
,&tinfo2
);
1199 ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc
->u
.lptdesc
->u
.hreftype
);
1202 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
1203 derefhere
= (tattr
->typekind
!= TKIND_DISPATCH
&&
1204 tattr
->typekind
!= TKIND_INTERFACE
&&
1205 tattr
->typekind
!= TKIND_COCLASS
);
1208 case TKIND_ENUM
: /* confirmed */
1209 case TKIND_RECORD
: /* FIXME: mostly untested */
1211 case TKIND_DISPATCH
: /* will be done in VT_USERDEFINED case */
1212 case TKIND_INTERFACE
: /* will be done in VT_USERDEFINED case */
1213 case TKIND_COCLASS
: /* will be done in VT_USERDEFINED case */
1217 FIXME("unhandled switch cases tattr->typekind %d\n", tattr
->typekind
);
1221 ITypeInfo_ReleaseTypeAttr(tinfo2
, tattr
);
1222 ITypeInfo_Release(tinfo2
);
1224 /* read it in all cases, we need to know if we have
1225 * NULL pointer or not.
1227 hres
= xbuf_get(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
1229 ERR("Failed to load pointer cookie.\n");
1232 if (cookie
!= 0x42424242) {
1233 /* we read a NULL ptr from the remote side */
1234 if (debugout
) TRACE_(olerelay
)("NULL");
1238 if (debugout
) TRACE_(olerelay
)("*");
1240 /* Allocate space for the referenced struct */
1242 *arg
=(DWORD_PTR
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,_xsize(tdesc
->u
.lptdesc
, tinfo
));
1245 return deserialize_param(tinfo
, readit
, debugout
, alloc
, tdesc
->u
.lptdesc
, (DWORD_PTR
*)*arg
, buf
);
1247 return deserialize_param(tinfo
, readit
, debugout
, alloc
, tdesc
->u
.lptdesc
, arg
, buf
);
1250 /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
1252 *arg
=(DWORD_PTR
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DWORD_PTR
));
1255 hres
= _unmarshal_interface(buf
,&IID_IUnknown
,(LPUNKNOWN
*)arg
);
1257 TRACE_(olerelay
)("unk(%p)",arg
);
1262 hres
= _unmarshal_interface(buf
,&IID_IDispatch
,(LPUNKNOWN
*)arg
);
1264 TRACE_(olerelay
)("idisp(%p)",arg
);
1267 if (debugout
) TRACE_(olerelay
)("<void>");
1269 case VT_USERDEFINED
: {
1273 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.hreftype
,&tinfo2
);
1275 ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc
->u
.hreftype
);
1278 hres
= ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
1280 ERR("Could not get typeattr in VT_USERDEFINED.\n");
1282 switch (tattr
->typekind
) {
1283 case TKIND_DISPATCH
:
1284 case TKIND_INTERFACE
:
1286 hres
= _unmarshal_interface(buf
,&(tattr
->guid
),(LPUNKNOWN
*)arg
);
1288 case TKIND_COCLASS
: {
1289 GUID iid
= tattr
->guid
;
1293 for(i
= 0; i
< tattr
->cImplTypes
; i
++) {
1294 if(SUCCEEDED(ITypeInfo_GetImplTypeFlags(tinfo2
, i
, &type_flags
)) &&
1295 type_flags
== (IMPLTYPEFLAG_FSOURCE
|IMPLTYPEFLAG_FDEFAULT
)) {
1299 if(FAILED(ITypeInfo_GetRefTypeOfImplType(tinfo2
, i
, &href
)))
1301 if(FAILED(ITypeInfo_GetRefTypeInfo(tinfo2
, href
, &tinfo3
)))
1303 if(SUCCEEDED(ITypeInfo_GetTypeAttr(tinfo3
, &tattr2
))) {
1305 ITypeInfo_ReleaseTypeAttr(tinfo3
, tattr2
);
1307 ITypeInfo_Release(tinfo3
);
1313 hres
= _unmarshal_interface(buf
, &iid
, (LPUNKNOWN
*)arg
);
1316 case TKIND_RECORD
: {
1319 if (debugout
) TRACE_(olerelay
)("{");
1320 for (i
=0;i
<tattr
->cVars
;i
++) {
1323 hres
= ITypeInfo_GetVarDesc(tinfo2
, i
, &vdesc
);
1325 ERR("Could not get vardesc of %d\n",i
);
1326 ITypeInfo_ReleaseTypeAttr(tinfo2
, tattr
);
1327 ITypeInfo_Release(tinfo2
);
1330 hres
= deserialize_param(
1335 &vdesc
->elemdescVar
.tdesc
,
1336 (DWORD_PTR
*)(((LPBYTE
)arg
)+vdesc
->u
.oInst
),
1339 ITypeInfo_ReleaseVarDesc(tinfo2
, vdesc
);
1340 if (debugout
&& (i
<tattr
->cVars
-1)) TRACE_(olerelay
)(",");
1342 if (debugout
) TRACE_(olerelay
)("}");
1346 hres
= deserialize_param(tinfo2
,readit
,debugout
,alloc
,&tattr
->tdescAlias
,arg
,buf
);
1350 hres
= xbuf_get(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
1351 if (hres
) ERR("Failed to read enum (4 byte)\n");
1353 if (debugout
) TRACE_(olerelay
)("%x", *(DWORD
*)arg
);
1356 ERR("Unhandled typekind %d\n",tattr
->typekind
);
1360 ITypeInfo_ReleaseTypeAttr(tinfo2
, tattr
);
1363 ERR("failed to stuballoc in TKIND_RECORD.\n");
1364 ITypeInfo_Release(tinfo2
);
1368 /* arg is pointing to the start of the array. */
1369 LPBYTE base
= (LPBYTE
) arg
;
1370 ARRAYDESC
*adesc
= tdesc
->u
.lpadesc
;
1373 if (adesc
->cDims
> 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
1374 for (i
=0;i
<adesc
->cDims
;i
++)
1375 arrsize
*= adesc
->rgbounds
[i
].cElements
;
1376 if (_passbyref(&adesc
->tdescElem
, tinfo
))
1378 base
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,_xsize(tdesc
->u
.lptdesc
, tinfo
) * arrsize
);
1379 *arg
= (DWORD_PTR
)base
;
1381 for (i
=0;i
<arrsize
;i
++)
1388 (DWORD_PTR
*)(base
+ i
*_xsize(&adesc
->tdescElem
, tinfo
)),
1393 case VT_SAFEARRAY
: {
1396 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
1397 unsigned char *buffer
;
1398 buffer
= LPSAFEARRAY_UserUnmarshal(&flags
, buf
->base
+ buf
->curoff
, (LPSAFEARRAY
*)arg
);
1399 buf
->curoff
= buffer
- buf
->base
;
1404 ERR("No handler for VT type %d!\n",tdesc
->vt
);
1410 /* Retrieves a function's funcdesc, searching back into inherited interfaces. */
1411 static HRESULT
get_funcdesc(ITypeInfo
*tinfo
, int iMethod
, ITypeInfo
**tactual
, const FUNCDESC
**fdesc
,
1412 BSTR
*iname
, BSTR
*fname
, UINT
*num
)
1416 UINT inherited_funcs
= 0;
1419 if (fname
) *fname
= NULL
;
1420 if (iname
) *iname
= NULL
;
1424 hr
= ITypeInfo_GetTypeAttr(tinfo
, &attr
);
1427 ERR("GetTypeAttr failed with %x\n",hr
);
1431 if(attr
->typekind
== TKIND_DISPATCH
)
1433 if(attr
->wTypeFlags
& TYPEFLAG_FDUAL
)
1438 hr
= ITypeInfo_GetRefTypeOfImplType(tinfo
, -1, &href
);
1441 ERR("Cannot get interface href from dual dispinterface\n");
1442 ITypeInfo_ReleaseTypeAttr(tinfo
, attr
);
1445 hr
= ITypeInfo_GetRefTypeInfo(tinfo
, href
, &tinfo2
);
1448 ERR("Cannot get interface from dual dispinterface\n");
1449 ITypeInfo_ReleaseTypeAttr(tinfo
, attr
);
1452 hr
= get_funcdesc(tinfo2
, iMethod
, tactual
, fdesc
, iname
, fname
, num
);
1453 ITypeInfo_Release(tinfo2
);
1454 ITypeInfo_ReleaseTypeAttr(tinfo
, attr
);
1457 ERR("Shouldn't be called with a non-dual dispinterface\n");
1461 impl_types
= attr
->cImplTypes
;
1462 ITypeInfo_ReleaseTypeAttr(tinfo
, attr
);
1464 for (i
= 0; i
< impl_types
; i
++)
1467 ITypeInfo
*pSubTypeInfo
;
1470 hr
= ITypeInfo_GetRefTypeOfImplType(tinfo
, i
, &href
);
1471 if (FAILED(hr
)) return hr
;
1472 hr
= ITypeInfo_GetRefTypeInfo(tinfo
, href
, &pSubTypeInfo
);
1473 if (FAILED(hr
)) return hr
;
1475 hr
= get_funcdesc(pSubTypeInfo
, iMethod
, tactual
, fdesc
, iname
, fname
, &sub_funcs
);
1476 inherited_funcs
+= sub_funcs
;
1477 ITypeInfo_Release(pSubTypeInfo
);
1478 if(SUCCEEDED(hr
)) return hr
;
1480 if(iMethod
< inherited_funcs
)
1482 ERR("shouldn't be here\n");
1483 return E_INVALIDARG
;
1486 for(i
= inherited_funcs
; i
<= iMethod
; i
++)
1488 hr
= ITypeInfoImpl_GetInternalFuncDesc(tinfo
, i
- inherited_funcs
, fdesc
);
1496 /* found it. We don't care about num so zero it */
1499 ITypeInfo_AddRef(*tactual
);
1500 if (fname
) ITypeInfo_GetDocumentation(tinfo
,(*fdesc
)->memid
,fname
,NULL
,NULL
,NULL
);
1501 if (iname
) ITypeInfo_GetDocumentation(tinfo
,-1,iname
,NULL
,NULL
,NULL
);
1505 static inline BOOL
is_in_elem(const ELEMDESC
*elem
)
1507 return (elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
|| !elem
->u
.paramdesc
.wParamFlags
);
1510 static inline BOOL
is_out_elem(const ELEMDESC
*elem
)
1512 return (elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
|| !elem
->u
.paramdesc
.wParamFlags
);
1515 static DWORD WINAPI
xCall(int method
, void **args
)
1517 TMProxyImpl
*tpinfo
= args
[0];
1519 const FUNCDESC
*fdesc
;
1528 DWORD remoteresult
= 0;
1530 IRpcChannelBuffer
*chanbuf
;
1532 EnterCriticalSection(&tpinfo
->crit
);
1534 hres
= get_funcdesc(tpinfo
->tinfo
,method
,&tinfo
,&fdesc
,&iname
,&fname
,NULL
);
1536 ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method
);
1537 LeaveCriticalSection(&tpinfo
->crit
);
1541 if (!tpinfo
->chanbuf
)
1543 WARN("Tried to use disconnected proxy\n");
1544 ITypeInfo_Release(tinfo
);
1545 LeaveCriticalSection(&tpinfo
->crit
);
1546 return RPC_E_DISCONNECTED
;
1548 chanbuf
= tpinfo
->chanbuf
;
1549 IRpcChannelBuffer_AddRef(chanbuf
);
1551 LeaveCriticalSection(&tpinfo
->crit
);
1553 if (TRACE_ON(olerelay
)) {
1554 TRACE_(olerelay
)("->");
1556 TRACE_(olerelay
)("%s:",relaystr(iname
));
1558 TRACE_(olerelay
)("%s(%d)",relaystr(fname
),method
);
1560 TRACE_(olerelay
)("%d",method
);
1561 TRACE_(olerelay
)("(");
1564 SysFreeString(iname
);
1565 SysFreeString(fname
);
1567 memset(&buf
,0,sizeof(buf
));
1569 /* normal typelib driven serializing */
1571 /* Need them for hack below */
1572 memset(names
,0,sizeof(names
));
1573 if (ITypeInfo_GetNames(tinfo
,fdesc
->memid
,names
,sizeof(names
)/sizeof(names
[0]),&nrofnames
))
1575 if (nrofnames
> sizeof(names
)/sizeof(names
[0]))
1576 ERR("Need more names!\n");
1578 xargs
= (DWORD_PTR
*)(args
+ 1);
1579 for (i
=0;i
<fdesc
->cParams
;i
++) {
1580 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1581 if (TRACE_ON(olerelay
)) {
1582 if (i
) TRACE_(olerelay
)(",");
1583 if (i
+1<nrofnames
&& names
[i
+1])
1584 TRACE_(olerelay
)("%s=",relaystr(names
[i
+1]));
1586 /* No need to marshal other data than FIN and any VT_PTR. */
1587 if (!is_in_elem(elem
))
1589 if (elem
->tdesc
.vt
!= VT_PTR
)
1591 xargs
+=_argsize(&elem
->tdesc
, tinfo
);
1592 TRACE_(olerelay
)("[out]");
1597 memset( *(void **)xargs
, 0, _xsize( elem
->tdesc
.u
.lptdesc
, tinfo
) );
1601 hres
= serialize_param(
1612 ERR("Failed to serialize param, hres %x\n",hres
);
1615 xargs
+=_argsize(&elem
->tdesc
, tinfo
);
1617 TRACE_(olerelay
)(")");
1619 memset(&msg
,0,sizeof(msg
));
1620 msg
.cbBuffer
= buf
.curoff
;
1621 msg
.iMethod
= method
;
1622 hres
= IRpcChannelBuffer_GetBuffer(chanbuf
,&msg
,&(tpinfo
->iid
));
1624 ERR("RpcChannelBuffer GetBuffer failed, %x\n",hres
);
1627 memcpy(msg
.Buffer
,buf
.base
,buf
.curoff
);
1628 TRACE_(olerelay
)("\n");
1629 hres
= IRpcChannelBuffer_SendReceive(chanbuf
,&msg
,&status
);
1631 ERR("RpcChannelBuffer SendReceive failed, %x\n",hres
);
1635 TRACE_(olerelay
)(" status = %08x (",status
);
1637 buf
.base
= HeapReAlloc(GetProcessHeap(),0,buf
.base
,msg
.cbBuffer
);
1639 buf
.base
= HeapAlloc(GetProcessHeap(),0,msg
.cbBuffer
);
1640 buf
.size
= msg
.cbBuffer
;
1641 memcpy(buf
.base
,msg
.Buffer
,buf
.size
);
1644 /* generic deserializer using typelib description */
1645 xargs
= (DWORD_PTR
*)(args
+ 1);
1647 for (i
=0;i
<fdesc
->cParams
;i
++) {
1648 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1650 if (i
) TRACE_(olerelay
)(",");
1651 if (i
+1<nrofnames
&& names
[i
+1]) TRACE_(olerelay
)("%s=",relaystr(names
[i
+1]));
1653 /* No need to marshal other data than FOUT and any VT_PTR */
1654 if (!is_out_elem(elem
) && (elem
->tdesc
.vt
!= VT_PTR
)) {
1655 xargs
+= _argsize(&elem
->tdesc
, tinfo
);
1656 TRACE_(olerelay
)("[in]");
1659 hres
= deserialize_param(
1669 ERR("Failed to unmarshall param, hres %x\n",hres
);
1673 xargs
+= _argsize(&elem
->tdesc
, tinfo
);
1676 hres
= xbuf_get(&buf
, (LPBYTE
)&remoteresult
, sizeof(DWORD
));
1679 TRACE_(olerelay
)(") = %08x\n", remoteresult
);
1681 hres
= remoteresult
;
1684 IRpcChannelBuffer_FreeBuffer(chanbuf
,&msg
);
1685 for (i
= 0; i
< nrofnames
; i
++)
1686 SysFreeString(names
[i
]);
1687 HeapFree(GetProcessHeap(),0,buf
.base
);
1688 IRpcChannelBuffer_Release(chanbuf
);
1689 ITypeInfo_Release(tinfo
);
1690 TRACE("-- 0x%08x\n", hres
);
1694 static HRESULT WINAPI
ProxyIUnknown_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
1696 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1698 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
1700 if (proxy
->outerunknown
)
1701 return IUnknown_QueryInterface(proxy
->outerunknown
, riid
, ppv
);
1703 FIXME("No interface\n");
1704 return E_NOINTERFACE
;
1707 static ULONG WINAPI
ProxyIUnknown_AddRef(IUnknown
*iface
)
1709 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1713 if (proxy
->outerunknown
)
1714 return IUnknown_AddRef(proxy
->outerunknown
);
1716 return 2; /* FIXME */
1719 static ULONG WINAPI
ProxyIUnknown_Release(IUnknown
*iface
)
1721 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1725 if (proxy
->outerunknown
)
1726 return IUnknown_Release(proxy
->outerunknown
);
1728 return 1; /* FIXME */
1731 static HRESULT WINAPI
ProxyIDispatch_GetTypeInfoCount(LPDISPATCH iface
, UINT
* pctinfo
)
1733 TMProxyImpl
*This
= (TMProxyImpl
*)iface
;
1735 TRACE("(%p)\n", pctinfo
);
1737 return IDispatch_GetTypeInfoCount(This
->dispatch
, pctinfo
);
1740 static HRESULT WINAPI
ProxyIDispatch_GetTypeInfo(LPDISPATCH iface
, UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
1742 TMProxyImpl
*This
= (TMProxyImpl
*)iface
;
1744 TRACE("(%d, %x, %p)\n", iTInfo
, lcid
, ppTInfo
);
1746 return IDispatch_GetTypeInfo(This
->dispatch
, iTInfo
, lcid
, ppTInfo
);
1749 static HRESULT WINAPI
ProxyIDispatch_GetIDsOfNames(LPDISPATCH iface
, REFIID riid
, LPOLESTR
* rgszNames
, UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
1751 TMProxyImpl
*This
= (TMProxyImpl
*)iface
;
1753 TRACE("(%s, %p, %d, 0x%x, %p)\n", debugstr_guid(riid
), rgszNames
, cNames
, lcid
, rgDispId
);
1755 return IDispatch_GetIDsOfNames(This
->dispatch
, riid
, rgszNames
,
1756 cNames
, lcid
, rgDispId
);
1759 static HRESULT WINAPI
ProxyIDispatch_Invoke(LPDISPATCH iface
, DISPID dispIdMember
, REFIID riid
, LCID lcid
,
1760 WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
,
1761 EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
1763 TMProxyImpl
*This
= (TMProxyImpl
*)iface
;
1765 TRACE("(%d, %s, 0x%x, 0x%x, %p, %p, %p, %p)\n", dispIdMember
,
1766 debugstr_guid(riid
), lcid
, wFlags
, pDispParams
, pVarResult
,
1767 pExcepInfo
, puArgErr
);
1769 return IDispatch_Invoke(This
->dispatch
, dispIdMember
, riid
, lcid
,
1770 wFlags
, pDispParams
, pVarResult
, pExcepInfo
,
1776 IRpcChannelBuffer IRpcChannelBuffer_iface
;
1778 /* the IDispatch-derived interface we are handling */
1780 IRpcChannelBuffer
*pDelegateChannel
;
1781 } TMarshalDispatchChannel
;
1783 static inline TMarshalDispatchChannel
*impl_from_IRpcChannelBuffer(IRpcChannelBuffer
*iface
)
1785 return CONTAINING_RECORD(iface
, TMarshalDispatchChannel
, IRpcChannelBuffer_iface
);
1788 static HRESULT WINAPI
TMarshalDispatchChannel_QueryInterface(IRpcChannelBuffer
*iface
, REFIID riid
, LPVOID
*ppv
)
1791 if (IsEqualIID(riid
,&IID_IRpcChannelBuffer
) || IsEqualIID(riid
,&IID_IUnknown
))
1794 IRpcChannelBuffer_AddRef(iface
);
1797 return E_NOINTERFACE
;
1800 static ULONG WINAPI
TMarshalDispatchChannel_AddRef(LPRPCCHANNELBUFFER iface
)
1802 TMarshalDispatchChannel
*This
= impl_from_IRpcChannelBuffer(iface
);
1803 return InterlockedIncrement(&This
->refs
);
1806 static ULONG WINAPI
TMarshalDispatchChannel_Release(LPRPCCHANNELBUFFER iface
)
1808 TMarshalDispatchChannel
*This
= impl_from_IRpcChannelBuffer(iface
);
1811 ref
= InterlockedDecrement(&This
->refs
);
1815 IRpcChannelBuffer_Release(This
->pDelegateChannel
);
1816 HeapFree(GetProcessHeap(), 0, This
);
1820 static HRESULT WINAPI
TMarshalDispatchChannel_GetBuffer(LPRPCCHANNELBUFFER iface
, RPCOLEMESSAGE
* olemsg
, REFIID riid
)
1822 TMarshalDispatchChannel
*This
= impl_from_IRpcChannelBuffer(iface
);
1823 TRACE("(%p, %s)\n", olemsg
, debugstr_guid(riid
));
1824 /* Note: we are pretending to invoke a method on the interface identified
1825 * by tmarshal_iid so that we can re-use the IDispatch proxy/stub code
1826 * without the RPC runtime getting confused by not exporting an IDispatch interface */
1827 return IRpcChannelBuffer_GetBuffer(This
->pDelegateChannel
, olemsg
, &This
->tmarshal_iid
);
1830 static HRESULT WINAPI
TMarshalDispatchChannel_SendReceive(LPRPCCHANNELBUFFER iface
, RPCOLEMESSAGE
*olemsg
, ULONG
*pstatus
)
1832 TMarshalDispatchChannel
*This
= impl_from_IRpcChannelBuffer(iface
);
1833 TRACE("(%p, %p)\n", olemsg
, pstatus
);
1834 return IRpcChannelBuffer_SendReceive(This
->pDelegateChannel
, olemsg
, pstatus
);
1837 static HRESULT WINAPI
TMarshalDispatchChannel_FreeBuffer(LPRPCCHANNELBUFFER iface
, RPCOLEMESSAGE
* olemsg
)
1839 TMarshalDispatchChannel
*This
= impl_from_IRpcChannelBuffer(iface
);
1840 TRACE("(%p)\n", olemsg
);
1841 return IRpcChannelBuffer_FreeBuffer(This
->pDelegateChannel
, olemsg
);
1844 static HRESULT WINAPI
TMarshalDispatchChannel_GetDestCtx(LPRPCCHANNELBUFFER iface
, DWORD
* pdwDestContext
, void** ppvDestContext
)
1846 TMarshalDispatchChannel
*This
= impl_from_IRpcChannelBuffer(iface
);
1847 TRACE("(%p,%p)\n", pdwDestContext
, ppvDestContext
);
1848 return IRpcChannelBuffer_GetDestCtx(This
->pDelegateChannel
, pdwDestContext
, ppvDestContext
);
1851 static HRESULT WINAPI
TMarshalDispatchChannel_IsConnected(LPRPCCHANNELBUFFER iface
)
1853 TMarshalDispatchChannel
*This
= impl_from_IRpcChannelBuffer(iface
);
1855 return IRpcChannelBuffer_IsConnected(This
->pDelegateChannel
);
1858 static const IRpcChannelBufferVtbl TMarshalDispatchChannelVtbl
=
1860 TMarshalDispatchChannel_QueryInterface
,
1861 TMarshalDispatchChannel_AddRef
,
1862 TMarshalDispatchChannel_Release
,
1863 TMarshalDispatchChannel_GetBuffer
,
1864 TMarshalDispatchChannel_SendReceive
,
1865 TMarshalDispatchChannel_FreeBuffer
,
1866 TMarshalDispatchChannel_GetDestCtx
,
1867 TMarshalDispatchChannel_IsConnected
1870 static HRESULT
TMarshalDispatchChannel_Create(
1871 IRpcChannelBuffer
*pDelegateChannel
, REFIID tmarshal_riid
,
1872 IRpcChannelBuffer
**ppChannel
)
1874 TMarshalDispatchChannel
*This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
1876 return E_OUTOFMEMORY
;
1878 This
->IRpcChannelBuffer_iface
.lpVtbl
= &TMarshalDispatchChannelVtbl
;
1880 IRpcChannelBuffer_AddRef(pDelegateChannel
);
1881 This
->pDelegateChannel
= pDelegateChannel
;
1882 This
->tmarshal_iid
= *tmarshal_riid
;
1884 *ppChannel
= &This
->IRpcChannelBuffer_iface
;
1889 static inline HRESULT
get_facbuf_for_iid(REFIID riid
, IPSFactoryBuffer
**facbuf
)
1894 if ((hr
= CoGetPSClsid(riid
, &clsid
)))
1896 return CoGetClassObject(&clsid
, CLSCTX_INPROC_SERVER
, NULL
,
1897 &IID_IPSFactoryBuffer
, (LPVOID
*)facbuf
);
1900 static HRESULT
init_proxy_entry_point(TMProxyImpl
*proxy
, unsigned int num
)
1903 /* nrofargs including This */
1906 TMAsmProxy
*xasm
= proxy
->asmstubs
+ num
;
1908 const FUNCDESC
*fdesc
;
1910 hres
= get_funcdesc(proxy
->tinfo
, num
, &tinfo2
, &fdesc
, NULL
, NULL
, NULL
);
1912 ERR("GetFuncDesc %x should not fail here.\n",hres
);
1915 ITypeInfo_Release(tinfo2
);
1916 /* some args take more than 4 byte on the stack */
1917 for (j
=0;j
<fdesc
->cParams
;j
++)
1918 nrofargs
+= _argsize(&fdesc
->lprgelemdescParam
[j
].tdesc
, proxy
->tinfo
);
1921 if (fdesc
->callconv
!= CC_STDCALL
) {
1922 ERR("calling convention is not stdcall????\n");
1925 /* leal 4(%esp),%eax
1931 xasm
->lealeax
= 0x0424448d;
1932 xasm
->pushleax
= 0x50;
1933 xasm
->pushlval
= 0x68;
1936 xasm
->xcall
= (char *)xCall
- (char *)&xasm
->lret
;
1938 xasm
->bytestopop
= nrofargs
* 4;
1940 proxy
->lpvtbl
[fdesc
->oVft
/ sizeof(void *)] = xasm
;
1942 #elif defined(__x86_64__)
1944 xasm
->pushq_rbp
= 0x55; /* pushq %rbp */
1945 xasm
->movq_rsp_rbp
[0] = 0x48; /* movq %rsp,%rbp */
1946 xasm
->movq_rsp_rbp
[1] = 0x89;
1947 xasm
->movq_rsp_rbp
[2] = 0xe5;
1948 xasm
->subq_0x20_rsp
= 0x20ec8348; /* subq 0x20,%rsp */
1949 xasm
->movq_rcx_0x10rbp
= 0x104d8948; /* movq %rcx,0x10(%rbp) */
1950 xasm
->movq_rdx_0x18rbp
= 0x18558948; /* movq %rdx,0x18(%rbp) */
1951 xasm
->movq_r8_0x20rbp
= 0x2045894c; /* movq %r8,0x20(%rbp) */
1952 xasm
->movq_r9_0x28rbp
= 0x284d894c; /* movq %r9,0x28(%rbp) */
1953 xasm
->movq_rcx
[0] = 0x48; /* movq <num>,%rcx */
1954 xasm
->movq_rcx
[1] = 0xc7;
1955 xasm
->movq_rcx
[2] = 0xc1;
1957 xasm
->leaq_0x10rbp_rdx
= 0x10558d48; /* leaq 0x10(%rbp),%rdx */
1958 xasm
->movq_rax
= 0xb848; /* movq <xCall>,%rax */
1959 xasm
->xcall
= xCall
;
1960 xasm
->callq_rax
= 0xd0ff; /* callq *%rax */
1961 xasm
->movq_rbp_rsp
[0] = 0x48; /* movq %rbp,%rsp */
1962 xasm
->movq_rbp_rsp
[1] = 0x89;
1963 xasm
->movq_rbp_rsp
[2] = 0xec;
1964 xasm
->popq_rbp
= 0x5d; /* popq %rbp */
1965 xasm
->ret
= 0xc3; /* ret */
1966 xasm
->nop
= 0x90909090; /* nop */
1967 proxy
->lpvtbl
[fdesc
->oVft
/ sizeof(void *)] = xasm
;
1970 FIXME("not implemented on non i386\n");
1976 static HRESULT WINAPI
1977 PSFacBuf_CreateProxy(
1978 LPPSFACTORYBUFFER iface
, IUnknown
* pUnkOuter
, REFIID riid
,
1979 IRpcProxyBuffer
**ppProxy
, LPVOID
*ppv
)
1983 unsigned int i
, nroffuncs
, vtbl_size
;
1986 BOOL defer_to_dispatch
= FALSE
;
1988 TRACE("(...%s...)\n",debugstr_guid(riid
));
1989 hres
= _get_typeinfo_for_iid(riid
,&tinfo
);
1991 ERR("No typeinfo for %s?\n",debugstr_guid(riid
));
1995 hres
= num_of_funcs(tinfo
, &nroffuncs
, &vtbl_size
);
1996 TRACE("Got %d funcs, vtbl size %d\n", nroffuncs
, vtbl_size
);
1999 ERR("Cannot get number of functions for typeinfo %s\n",debugstr_guid(riid
));
2000 ITypeInfo_Release(tinfo
);
2004 proxy
= CoTaskMemAlloc(sizeof(TMProxyImpl
));
2005 if (!proxy
) return E_OUTOFMEMORY
;
2007 proxy
->dispatch
= NULL
;
2008 proxy
->dispatch_proxy
= NULL
;
2009 proxy
->outerunknown
= pUnkOuter
;
2010 proxy
->asmstubs
= VirtualAlloc(NULL
, sizeof(TMAsmProxy
) * nroffuncs
, MEM_COMMIT
, PAGE_EXECUTE_READWRITE
);
2011 if (!proxy
->asmstubs
) {
2012 ERR("Could not commit pages for proxy thunks\n");
2013 CoTaskMemFree(proxy
);
2014 return E_OUTOFMEMORY
;
2016 proxy
->IRpcProxyBuffer_iface
.lpVtbl
= &tmproxyvtable
;
2017 /* one reference for the proxy */
2019 proxy
->tinfo
= tinfo
;
2023 InitializeCriticalSection(&proxy
->crit
);
2024 proxy
->crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": TMProxyImpl.crit");
2026 proxy
->lpvtbl
= HeapAlloc(GetProcessHeap(), 0, vtbl_size
);
2028 /* if we derive from IDispatch then defer to its proxy for its methods */
2029 hres
= ITypeInfo_GetTypeAttr(tinfo
, &typeattr
);
2032 if (typeattr
->wTypeFlags
& TYPEFLAG_FDISPATCHABLE
)
2034 IPSFactoryBuffer
*factory_buffer
;
2035 hres
= get_facbuf_for_iid(&IID_IDispatch
, &factory_buffer
);
2038 hres
= IPSFactoryBuffer_CreateProxy(factory_buffer
, NULL
,
2039 &IID_IDispatch
, &proxy
->dispatch_proxy
,
2040 (void **)&proxy
->dispatch
);
2041 IPSFactoryBuffer_Release(factory_buffer
);
2043 if ((hres
== S_OK
) && (nroffuncs
< 7))
2045 ERR("nroffuncs calculated incorrectly (%d)\n", nroffuncs
);
2046 hres
= E_UNEXPECTED
;
2050 defer_to_dispatch
= TRUE
;
2053 ITypeInfo_ReleaseTypeAttr(tinfo
, typeattr
);
2056 for (i
=0;i
<nroffuncs
;i
++) {
2059 proxy
->lpvtbl
[i
] = ProxyIUnknown_QueryInterface
;
2062 proxy
->lpvtbl
[i
] = ProxyIUnknown_AddRef
;
2065 proxy
->lpvtbl
[i
] = ProxyIUnknown_Release
;
2068 if(!defer_to_dispatch
) hres
= init_proxy_entry_point(proxy
, i
);
2069 else proxy
->lpvtbl
[3] = ProxyIDispatch_GetTypeInfoCount
;
2072 if(!defer_to_dispatch
) hres
= init_proxy_entry_point(proxy
, i
);
2073 else proxy
->lpvtbl
[4] = ProxyIDispatch_GetTypeInfo
;
2076 if(!defer_to_dispatch
) hres
= init_proxy_entry_point(proxy
, i
);
2077 else proxy
->lpvtbl
[5] = ProxyIDispatch_GetIDsOfNames
;
2080 if(!defer_to_dispatch
) hres
= init_proxy_entry_point(proxy
, i
);
2081 else proxy
->lpvtbl
[6] = ProxyIDispatch_Invoke
;
2084 hres
= init_proxy_entry_point(proxy
, i
);
2091 *ppProxy
= &proxy
->IRpcProxyBuffer_iface
;
2092 IUnknown_AddRef((IUnknown
*)*ppv
);
2096 TMProxyImpl_Release(&proxy
->IRpcProxyBuffer_iface
);
2100 typedef struct _TMStubImpl
{
2101 IRpcStubBuffer IRpcStubBuffer_iface
;
2107 IRpcStubBuffer
*dispatch_stub
;
2108 BOOL dispatch_derivative
;
2111 static inline TMStubImpl
*impl_from_IRpcStubBuffer(IRpcStubBuffer
*iface
)
2113 return CONTAINING_RECORD(iface
, TMStubImpl
, IRpcStubBuffer_iface
);
2116 static HRESULT WINAPI
2117 TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface
, REFIID riid
, LPVOID
*ppv
)
2119 if (IsEqualIID(riid
,&IID_IRpcStubBuffer
)||IsEqualIID(riid
,&IID_IUnknown
)){
2121 IRpcStubBuffer_AddRef(iface
);
2124 FIXME("%s, not supported IID.\n",debugstr_guid(riid
));
2125 return E_NOINTERFACE
;
2129 TMStubImpl_AddRef(LPRPCSTUBBUFFER iface
)
2131 TMStubImpl
*This
= impl_from_IRpcStubBuffer(iface
);
2132 ULONG refCount
= InterlockedIncrement(&This
->ref
);
2134 TRACE("(%p)->(ref before=%u)\n", This
, refCount
- 1);
2140 TMStubImpl_Release(LPRPCSTUBBUFFER iface
)
2142 TMStubImpl
*This
= impl_from_IRpcStubBuffer(iface
);
2143 ULONG refCount
= InterlockedDecrement(&This
->ref
);
2145 TRACE("(%p)->(ref before=%u)\n", This
, refCount
+ 1);
2149 IRpcStubBuffer_Disconnect(iface
);
2150 ITypeInfo_Release(This
->tinfo
);
2151 if (This
->dispatch_stub
)
2152 IRpcStubBuffer_Release(This
->dispatch_stub
);
2153 CoTaskMemFree(This
);
2158 static HRESULT WINAPI
2159 TMStubImpl_Connect(LPRPCSTUBBUFFER iface
, LPUNKNOWN pUnkServer
)
2161 TMStubImpl
*This
= impl_from_IRpcStubBuffer(iface
);
2163 TRACE("(%p)->(%p)\n", This
, pUnkServer
);
2165 IUnknown_AddRef(pUnkServer
);
2166 This
->pUnk
= pUnkServer
;
2168 if (This
->dispatch_stub
)
2169 IRpcStubBuffer_Connect(This
->dispatch_stub
, pUnkServer
);
2175 TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface
)
2177 TMStubImpl
*This
= impl_from_IRpcStubBuffer(iface
);
2179 TRACE("(%p)->()\n", This
);
2183 IUnknown_Release(This
->pUnk
);
2187 if (This
->dispatch_stub
)
2188 IRpcStubBuffer_Disconnect(This
->dispatch_stub
);
2191 static HRESULT WINAPI
2193 LPRPCSTUBBUFFER iface
, RPCOLEMESSAGE
* xmsg
,IRpcChannelBuffer
*rpcchanbuf
)
2195 #if defined(__i386__) || defined(__x86_64__)
2197 const FUNCDESC
*fdesc
;
2198 TMStubImpl
*This
= impl_from_IRpcStubBuffer(iface
);
2200 DWORD_PTR
*args
= NULL
, *xargs
;
2201 DWORD res
, nrofargs
;
2206 ITypeInfo
*tinfo
= NULL
;
2210 if (xmsg
->iMethod
< 3) {
2211 ERR("IUnknown methods cannot be marshaled by the typelib marshaler\n");
2212 return E_UNEXPECTED
;
2215 if (This
->dispatch_derivative
&& xmsg
->iMethod
< sizeof(IDispatchVtbl
)/sizeof(void *))
2217 if (!This
->dispatch_stub
)
2219 IPSFactoryBuffer
*factory_buffer
;
2220 hres
= get_facbuf_for_iid(&IID_IDispatch
, &factory_buffer
);
2223 hres
= IPSFactoryBuffer_CreateStub(factory_buffer
, &IID_IDispatch
,
2224 This
->pUnk
, &This
->dispatch_stub
);
2225 IPSFactoryBuffer_Release(factory_buffer
);
2230 return IRpcStubBuffer_Invoke(This
->dispatch_stub
, xmsg
, rpcchanbuf
);
2233 memset(&buf
,0,sizeof(buf
));
2234 buf
.size
= xmsg
->cbBuffer
;
2235 buf
.base
= HeapAlloc(GetProcessHeap(), 0, xmsg
->cbBuffer
);
2236 memcpy(buf
.base
, xmsg
->Buffer
, xmsg
->cbBuffer
);
2239 hres
= get_funcdesc(This
->tinfo
,xmsg
->iMethod
,&tinfo
,&fdesc
,&iname
,NULL
,NULL
);
2241 ERR("GetFuncDesc on method %d failed with %x\n",xmsg
->iMethod
,hres
);
2245 if (iname
&& !lstrcmpW(iname
, IDispatchW
))
2247 ERR("IDispatch cannot be marshaled by the typelib marshaler\n");
2248 hres
= E_UNEXPECTED
;
2249 SysFreeString (iname
);
2253 SysFreeString (iname
);
2255 /* Need them for hack below */
2256 memset(names
,0,sizeof(names
));
2257 ITypeInfo_GetNames(tinfo
,fdesc
->memid
,names
,sizeof(names
)/sizeof(names
[0]),&nrofnames
);
2258 if (nrofnames
> sizeof(names
)/sizeof(names
[0])) {
2259 ERR("Need more names!\n");
2262 /*dump_FUNCDESC(fdesc);*/
2264 for (i
=0;i
<fdesc
->cParams
;i
++)
2265 nrofargs
+= _argsize(&fdesc
->lprgelemdescParam
[i
].tdesc
, tinfo
);
2266 args
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (nrofargs
+1)*sizeof(DWORD_PTR
));
2269 hres
= E_OUTOFMEMORY
;
2273 /* Allocate all stuff used by call. */
2275 for (i
=0;i
<fdesc
->cParams
;i
++) {
2276 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
2278 hres
= deserialize_param(
2287 xargs
+= _argsize(&elem
->tdesc
, tinfo
);
2289 ERR("Failed to deserialize param %s, hres %x\n",relaystr(names
[i
+1]),hres
);
2294 args
[0] = (DWORD_PTR
)This
->pUnk
;
2299 (*((FARPROC
**)args
[0]))[fdesc
->oVft
/ sizeof(DWORD_PTR
)],
2307 DWORD dwExceptionCode
= GetExceptionCode();
2308 ERR("invoke call failed with exception 0x%08x (%d)\n", dwExceptionCode
, dwExceptionCode
);
2309 if (FAILED(dwExceptionCode
))
2310 hres
= dwExceptionCode
;
2312 hres
= HRESULT_FROM_WIN32(dwExceptionCode
);
2322 for (i
=0;i
<fdesc
->cParams
;i
++) {
2323 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
2324 hres
= serialize_param(
2333 xargs
+= _argsize(&elem
->tdesc
, tinfo
);
2335 ERR("Failed to stuballoc param, hres %x\n",hres
);
2340 hres
= xbuf_add (&buf
, (LPBYTE
)&res
, sizeof(DWORD
));
2345 xmsg
->cbBuffer
= buf
.curoff
;
2346 hres
= IRpcChannelBuffer_GetBuffer(rpcchanbuf
, xmsg
, &This
->iid
);
2348 ERR("IRpcChannelBuffer_GetBuffer failed with error 0x%08x\n", hres
);
2351 memcpy(xmsg
->Buffer
, buf
.base
, buf
.curoff
);
2354 for (i
= 0; i
< nrofnames
; i
++)
2355 SysFreeString(names
[i
]);
2357 ITypeInfo_Release(tinfo
);
2358 HeapFree(GetProcessHeap(), 0, args
);
2360 HeapFree(GetProcessHeap(), 0, buf
.base
);
2362 TRACE("returning\n");
2365 FIXME( "not implemented on non-i386\n" );
2370 static LPRPCSTUBBUFFER WINAPI
2371 TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface
, REFIID riid
) {
2372 FIXME("Huh (%s)?\n",debugstr_guid(riid
));
2377 TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface
) {
2378 TMStubImpl
*This
= impl_from_IRpcStubBuffer(iface
);
2381 return This
->ref
; /*FIXME? */
2384 static HRESULT WINAPI
2385 TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface
, LPVOID
*ppv
) {
2390 TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface
, LPVOID ppv
) {
2394 static const IRpcStubBufferVtbl tmstubvtbl
= {
2395 TMStubImpl_QueryInterface
,
2399 TMStubImpl_Disconnect
,
2401 TMStubImpl_IsIIDSupported
,
2402 TMStubImpl_CountRefs
,
2403 TMStubImpl_DebugServerQueryInterface
,
2404 TMStubImpl_DebugServerRelease
2407 static HRESULT WINAPI
2408 PSFacBuf_CreateStub(
2409 LPPSFACTORYBUFFER iface
, REFIID riid
,IUnknown
*pUnkServer
,
2410 IRpcStubBuffer
** ppStub
2418 TRACE("(%s,%p,%p)\n",debugstr_guid(riid
),pUnkServer
,ppStub
);
2420 hres
= _get_typeinfo_for_iid(riid
,&tinfo
);
2422 ERR("No typeinfo for %s?\n",debugstr_guid(riid
));
2426 /* FIXME: This is not exactly right. We should probably call QI later. */
2427 hres
= IUnknown_QueryInterface(pUnkServer
, riid
, (void**)&obj
);
2429 WARN("Could not get %s iface: %08x\n", debugstr_guid(riid
), hres
);
2431 IUnknown_AddRef(obj
);
2434 stub
= CoTaskMemAlloc(sizeof(TMStubImpl
));
2436 IUnknown_Release(obj
);
2437 return E_OUTOFMEMORY
;
2439 stub
->IRpcStubBuffer_iface
.lpVtbl
= &tmstubvtbl
;
2441 stub
->tinfo
= tinfo
;
2442 stub
->dispatch_stub
= NULL
;
2443 stub
->dispatch_derivative
= FALSE
;
2445 hres
= IRpcStubBuffer_Connect(&stub
->IRpcStubBuffer_iface
, obj
);
2446 *ppStub
= &stub
->IRpcStubBuffer_iface
;
2447 TRACE("IRpcStubBuffer: %p\n", stub
);
2449 ERR("Connect to pUnkServer failed?\n");
2451 /* if we derive from IDispatch then defer to its stub for some of its methods */
2452 hres
= ITypeInfo_GetTypeAttr(tinfo
, &typeattr
);
2455 if (typeattr
->wTypeFlags
& TYPEFLAG_FDISPATCHABLE
)
2456 stub
->dispatch_derivative
= TRUE
;
2457 ITypeInfo_ReleaseTypeAttr(tinfo
, typeattr
);
2460 IUnknown_Release(obj
);
2464 static const IPSFactoryBufferVtbl psfacbufvtbl
= {
2465 PSFacBuf_QueryInterface
,
2468 PSFacBuf_CreateProxy
,
2472 static IPSFactoryBuffer psfac
= { &psfacbufvtbl
};
2474 /***********************************************************************
2475 * TMARSHAL_DllGetClassObject
2477 HRESULT
TMARSHAL_DllGetClassObject(REFCLSID rclsid
, REFIID iid
, void **ppv
)
2479 return IPSFactoryBuffer_QueryInterface(&psfac
, iid
, ppv
);