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
28 #include <wine/exception.h>
30 static const WCHAR IDispatchW
[] = { 'I','D','i','s','p','a','t','c','h',0};
32 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
33 WINE_DECLARE_DEBUG_CHANNEL(olerelay
);
35 static HRESULT
TMarshalDispatchChannel_Create(
36 IRpcChannelBuffer
*pDelegateChannel
, REFIID tmarshal_riid
,
37 IRpcChannelBuffer
**ppChannel
);
39 typedef struct _marshal_state
{
45 /* used in the olerelay code to avoid having the L"" stuff added by debugstr_w */
46 static char *relaystr(WCHAR
*in
) {
47 char *tmp
= (char *)debugstr_w(in
);
49 tmp
[strlen(tmp
)-1] = '\0';
54 xbuf_resize(marshal_state
*buf
, DWORD newsize
)
56 if(buf
->size
>= newsize
)
61 buf
->base
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, buf
->base
, newsize
);
67 buf
->base
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, newsize
);
76 xbuf_add(marshal_state
*buf
, const BYTE
*stuff
, DWORD size
)
80 if(buf
->size
- buf
->curoff
< size
)
82 hr
= xbuf_resize(buf
, buf
->size
+ size
+ 100);
83 if(FAILED(hr
)) return hr
;
85 memcpy(buf
->base
+buf
->curoff
,stuff
,size
);
91 xbuf_get(marshal_state
*buf
, LPBYTE stuff
, DWORD size
) {
92 if (buf
->size
< buf
->curoff
+size
) return E_FAIL
;
93 memcpy(stuff
,buf
->base
+buf
->curoff
,size
);
99 xbuf_skip(marshal_state
*buf
, DWORD size
) {
100 if (buf
->size
< buf
->curoff
+size
) return E_FAIL
;
106 _unmarshal_interface(marshal_state
*buf
, REFIID riid
, LPUNKNOWN
*pUnk
) {
108 ULARGE_INTEGER newpos
;
109 LARGE_INTEGER seekto
;
114 TRACE("...%s...\n",debugstr_guid(riid
));
117 hres
= xbuf_get(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
119 ERR("xbuf_get failed\n");
123 if (xsize
== 0) return S_OK
;
125 hres
= CreateStreamOnHGlobal(0,TRUE
,&pStm
);
127 ERR("Stream create failed %x\n",hres
);
131 hres
= IStream_Write(pStm
,buf
->base
+buf
->curoff
,xsize
,&res
);
133 ERR("stream write %x\n",hres
);
134 IStream_Release(pStm
);
138 memset(&seekto
,0,sizeof(seekto
));
139 hres
= IStream_Seek(pStm
,seekto
,SEEK_SET
,&newpos
);
141 ERR("Failed Seek %x\n",hres
);
142 IStream_Release(pStm
);
146 hres
= CoUnmarshalInterface(pStm
,riid
,(LPVOID
*)pUnk
);
148 ERR("Unmarshalling interface %s failed with %x\n",debugstr_guid(riid
),hres
);
149 IStream_Release(pStm
);
153 IStream_Release(pStm
);
154 return xbuf_skip(buf
,xsize
);
158 _marshal_interface(marshal_state
*buf
, REFIID riid
, LPUNKNOWN pUnk
) {
159 LPBYTE tempbuf
= NULL
;
160 IStream
*pStm
= NULL
;
162 ULARGE_INTEGER newpos
;
163 LARGE_INTEGER seekto
;
169 /* this is valid, if for instance we serialize
170 * a VT_DISPATCH with NULL ptr which apparently
171 * can happen. S_OK to make sure we continue
174 WARN("pUnk is NULL\n");
176 return xbuf_add(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
179 TRACE("...%s...\n",debugstr_guid(riid
));
181 hres
= CreateStreamOnHGlobal(0,TRUE
,&pStm
);
183 ERR("Stream create failed %x\n",hres
);
187 hres
= CoMarshalInterface(pStm
,riid
,pUnk
,0,NULL
,0);
189 ERR("Marshalling interface %s failed with %x\n", debugstr_guid(riid
), hres
);
193 hres
= IStream_Stat(pStm
,&ststg
,STATFLAG_NONAME
);
195 ERR("Stream stat failed\n");
199 tempbuf
= HeapAlloc(GetProcessHeap(), 0, ststg
.cbSize
.u
.LowPart
);
200 memset(&seekto
,0,sizeof(seekto
));
201 hres
= IStream_Seek(pStm
,seekto
,SEEK_SET
,&newpos
);
203 ERR("Failed Seek %x\n",hres
);
207 hres
= IStream_Read(pStm
,tempbuf
,ststg
.cbSize
.u
.LowPart
,&res
);
209 ERR("Failed Read %x\n",hres
);
213 xsize
= ststg
.cbSize
.u
.LowPart
;
214 xbuf_add(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
215 hres
= xbuf_add(buf
,tempbuf
,ststg
.cbSize
.u
.LowPart
);
217 HeapFree(GetProcessHeap(),0,tempbuf
);
218 IStream_Release(pStm
);
224 xbuf_add(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
225 if (pStm
) IStream_Release(pStm
);
226 HeapFree(GetProcessHeap(), 0, tempbuf
);
230 /********************* OLE Proxy/Stub Factory ********************************/
231 static HRESULT WINAPI
232 PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface
, REFIID iid
, LPVOID
*ppv
) {
233 if (IsEqualIID(iid
,&IID_IPSFactoryBuffer
)||IsEqualIID(iid
,&IID_IUnknown
)) {
235 /* No ref counting, static class */
238 FIXME("(%s) unknown IID?\n",debugstr_guid(iid
));
239 return E_NOINTERFACE
;
242 static ULONG WINAPI
PSFacBuf_AddRef(LPPSFACTORYBUFFER iface
) { return 2; }
243 static ULONG WINAPI
PSFacBuf_Release(LPPSFACTORYBUFFER iface
) { return 1; }
245 struct ifacepsredirect_data
257 struct tlibredirect_data
271 static BOOL
actctx_get_typelib_module(REFIID riid
, WCHAR
*module
, DWORD len
)
273 struct ifacepsredirect_data
*iface
;
274 struct tlibredirect_data
*tlib
;
275 ACTCTX_SECTION_KEYED_DATA data
;
278 data
.cbSize
= sizeof(data
);
279 if (!FindActCtxSectionGuid(0, NULL
, ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION
,
283 iface
= (struct ifacepsredirect_data
*)data
.lpData
;
284 if (!FindActCtxSectionGuid(0, NULL
, ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION
,
285 &iface
->tlbid
, &data
))
288 tlib
= (struct tlibredirect_data
*)data
.lpData
;
289 ptrW
= (WCHAR
*)((BYTE
*)data
.lpSectionBase
+ tlib
->name_offset
);
291 if (tlib
->name_len
/sizeof(WCHAR
) >= len
) {
292 ERR("need larger module buffer, %u\n", tlib
->name_len
);
296 memcpy(module
, ptrW
, tlib
->name_len
);
297 module
[tlib
->name_len
/sizeof(WCHAR
)] = 0;
301 static HRESULT
reg_get_typelib_module(REFIID riid
, WCHAR
*module
, DWORD len
)
304 REGSAM opposite
= (sizeof(void*) == 8) ? KEY_WOW64_32KEY
: KEY_WOW64_64KEY
;
306 char tlguid
[200],typelibkey
[300],interfacekey
[300],ver
[100];
308 DWORD tlguidlen
, verlen
, type
;
311 sprintf( interfacekey
, "Interface\\{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\Typelib",
312 riid
->Data1
, riid
->Data2
, riid
->Data3
,
313 riid
->Data4
[0], riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3],
314 riid
->Data4
[4], riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]
317 err
= RegOpenKeyExA(HKEY_CLASSES_ROOT
,interfacekey
,0,KEY_READ
,&ikey
);
318 if (err
&& (opposite
== KEY_WOW64_32KEY
|| (IsWow64Process(GetCurrentProcess(), &is_wow64
)
320 err
= RegOpenKeyExA(HKEY_CLASSES_ROOT
,interfacekey
,0,KEY_READ
|opposite
,&ikey
);
323 ERR("No %s key found.\n",interfacekey
);
326 tlguidlen
= sizeof(tlguid
);
327 if (RegQueryValueExA(ikey
,NULL
,NULL
,&type
,(LPBYTE
)tlguid
,&tlguidlen
)) {
328 ERR("Getting typelib guid failed.\n");
332 verlen
= sizeof(ver
);
333 if (RegQueryValueExA(ikey
,"Version",NULL
,&type
,(LPBYTE
)ver
,&verlen
)) {
334 ERR("Could not get version value?\n");
339 sprintf(typelibkey
,"Typelib\\%s\\%s\\0\\win%u",tlguid
,ver
,(sizeof(void*) == 8) ? 64 : 32);
340 tlfnlen
= sizeof(tlfn
);
341 if (RegQueryValueA(HKEY_CLASSES_ROOT
,typelibkey
,tlfn
,&tlfnlen
)) {
343 sprintf(typelibkey
,"Typelib\\%s\\%s\\0\\win32",tlguid
,ver
);
344 tlfnlen
= sizeof(tlfn
);
345 if (RegQueryValueA(HKEY_CLASSES_ROOT
,typelibkey
,tlfn
,&tlfnlen
)) {
347 ERR("Could not get typelib fn?\n");
353 MultiByteToWideChar(CP_ACP
, 0, tlfn
, -1, module
, len
);
358 _get_typeinfo_for_iid(REFIID riid
, ITypeInfo
**typeinfo
)
360 OLECHAR moduleW
[260];
367 if (!actctx_get_typelib_module(riid
, moduleW
, sizeof(moduleW
)/sizeof(moduleW
[0]))) {
368 hres
= reg_get_typelib_module(riid
, moduleW
, sizeof(moduleW
)/sizeof(moduleW
[0]));
373 hres
= LoadTypeLib(moduleW
, &typelib
);
375 ERR("Failed to load typelib for %s, but it should be there.\n",debugstr_guid(riid
));
379 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
, riid
, typeinfo
);
380 ITypeLib_Release(typelib
);
382 ERR("typelib does not contain info for %s\n", debugstr_guid(riid
));
388 * Determine the number of functions including all inherited functions
389 * and well as the size of the vtbl.
390 * Note for non-dual dispinterfaces we simply return the size of IDispatch.
392 static HRESULT
num_of_funcs(ITypeInfo
*tinfo
, unsigned int *num
,
393 unsigned int *vtbl_size
)
398 UINT inherited_funcs
= 0, i
;
401 if(vtbl_size
) *vtbl_size
= 0;
403 hr
= ITypeInfo_GetTypeAttr(tinfo
, &attr
);
406 ERR("GetTypeAttr failed with %x\n", hr
);
410 if(attr
->typekind
== TKIND_DISPATCH
)
412 if(attr
->wTypeFlags
& TYPEFLAG_FDUAL
)
416 ITypeInfo_ReleaseTypeAttr(tinfo
, attr
);
417 hr
= ITypeInfo_GetRefTypeOfImplType(tinfo
, -1, &href
);
420 ERR("Unable to get interface href from dual dispinterface\n");
423 hr
= ITypeInfo_GetRefTypeInfo(tinfo
, href
, &tinfo2
);
426 ERR("Unable to get interface from dual dispinterface\n");
429 hr
= num_of_funcs(tinfo2
, num
, vtbl_size
);
430 ITypeInfo_Release(tinfo2
);
433 else /* non-dual dispinterface */
435 /* These will be the size of IDispatchVtbl */
436 *num
= attr
->cbSizeVft
/ sizeof(void *);
437 if(vtbl_size
) *vtbl_size
= attr
->cbSizeVft
;
438 ITypeInfo_ReleaseTypeAttr(tinfo
, attr
);
443 for (i
= 0; i
< attr
->cImplTypes
; i
++)
446 ITypeInfo
*pSubTypeInfo
;
449 hr
= ITypeInfo_GetRefTypeOfImplType(tinfo
, i
, &href
);
450 if (FAILED(hr
)) goto end
;
451 hr
= ITypeInfo_GetRefTypeInfo(tinfo
, href
, &pSubTypeInfo
);
452 if (FAILED(hr
)) goto end
;
454 hr
= num_of_funcs(pSubTypeInfo
, &sub_funcs
, NULL
);
455 ITypeInfo_Release(pSubTypeInfo
);
457 if(FAILED(hr
)) goto end
;
458 inherited_funcs
+= sub_funcs
;
461 *num
= inherited_funcs
+ attr
->cFuncs
;
462 if(vtbl_size
) *vtbl_size
= attr
->cbSizeVft
;
465 ITypeInfo_ReleaseTypeAttr(tinfo
, attr
);
471 #include "pshpack1.h"
472 typedef struct _TMAsmProxy
{
485 #elif defined(__x86_64__)
487 #include "pshpack1.h"
488 typedef struct _TMAsmProxy
{
490 BYTE movq_rsp_rbp
[3];
492 DWORD movq_rcx_0x10rbp
;
493 DWORD movq_rdx_0x18rbp
;
494 DWORD movq_r8_0x20rbp
;
495 DWORD movq_r9_0x28rbp
;
498 DWORD leaq_0x10rbp_rdx
;
502 BYTE movq_rbp_rsp
[3];
511 #pragma message("You need to implement stubless proxies for your architecture")
513 # warning You need to implement stubless proxies for your architecture
515 typedef struct _TMAsmProxy
{
520 typedef struct _TMProxyImpl
{
522 IRpcProxyBuffer IRpcProxyBuffer_iface
;
525 TMAsmProxy
*asmstubs
;
527 IRpcChannelBuffer
* chanbuf
;
529 CRITICAL_SECTION crit
;
530 IUnknown
*outerunknown
;
532 IRpcProxyBuffer
*dispatch_proxy
;
535 static inline TMProxyImpl
*impl_from_IRpcProxyBuffer( IRpcProxyBuffer
*iface
)
537 return CONTAINING_RECORD(iface
, TMProxyImpl
, IRpcProxyBuffer_iface
);
540 static HRESULT WINAPI
541 TMProxyImpl_QueryInterface(LPRPCPROXYBUFFER iface
, REFIID riid
, LPVOID
*ppv
)
544 if (IsEqualIID(riid
,&IID_IUnknown
)||IsEqualIID(riid
,&IID_IRpcProxyBuffer
)) {
546 IRpcProxyBuffer_AddRef(iface
);
549 FIXME("no interface for %s\n",debugstr_guid(riid
));
550 return E_NOINTERFACE
;
554 TMProxyImpl_AddRef(LPRPCPROXYBUFFER iface
)
556 TMProxyImpl
*This
= impl_from_IRpcProxyBuffer( iface
);
557 ULONG refCount
= InterlockedIncrement(&This
->ref
);
559 TRACE("(%p)->(ref before=%u)\n",This
, refCount
- 1);
565 TMProxyImpl_Release(LPRPCPROXYBUFFER iface
)
567 TMProxyImpl
*This
= impl_from_IRpcProxyBuffer( iface
);
568 ULONG refCount
= InterlockedDecrement(&This
->ref
);
570 TRACE("(%p)->(ref before=%u)\n",This
, refCount
+ 1);
574 if (This
->dispatch_proxy
) IRpcProxyBuffer_Release(This
->dispatch_proxy
);
575 This
->crit
.DebugInfo
->Spare
[0] = 0;
576 DeleteCriticalSection(&This
->crit
);
577 if (This
->chanbuf
) IRpcChannelBuffer_Release(This
->chanbuf
);
578 VirtualFree(This
->asmstubs
, 0, MEM_RELEASE
);
579 HeapFree(GetProcessHeap(), 0, This
->lpvtbl
);
580 ITypeInfo_Release(This
->tinfo
);
586 static HRESULT WINAPI
588 LPRPCPROXYBUFFER iface
,IRpcChannelBuffer
* pRpcChannelBuffer
)
590 TMProxyImpl
*This
= impl_from_IRpcProxyBuffer( iface
);
592 TRACE("(%p)\n", pRpcChannelBuffer
);
594 EnterCriticalSection(&This
->crit
);
596 IRpcChannelBuffer_AddRef(pRpcChannelBuffer
);
597 This
->chanbuf
= pRpcChannelBuffer
;
599 LeaveCriticalSection(&This
->crit
);
601 if (This
->dispatch_proxy
)
603 IRpcChannelBuffer
*pDelegateChannel
;
604 HRESULT hr
= TMarshalDispatchChannel_Create(pRpcChannelBuffer
, &This
->iid
, &pDelegateChannel
);
607 hr
= IRpcProxyBuffer_Connect(This
->dispatch_proxy
, pDelegateChannel
);
608 IRpcChannelBuffer_Release(pDelegateChannel
);
616 TMProxyImpl_Disconnect(LPRPCPROXYBUFFER iface
)
618 TMProxyImpl
*This
= impl_from_IRpcProxyBuffer( iface
);
622 EnterCriticalSection(&This
->crit
);
624 IRpcChannelBuffer_Release(This
->chanbuf
);
625 This
->chanbuf
= NULL
;
627 LeaveCriticalSection(&This
->crit
);
629 if (This
->dispatch_proxy
)
630 IRpcProxyBuffer_Disconnect(This
->dispatch_proxy
);
634 static const IRpcProxyBufferVtbl tmproxyvtable
= {
635 TMProxyImpl_QueryInterface
,
639 TMProxyImpl_Disconnect
642 /* how much space do we use on stack in DWORD_PTR steps. */
644 _argsize(TYPEDESC
*tdesc
, ITypeInfo
*tinfo
) {
652 ret
= sizeof(double);
661 ret
= sizeof(DECIMAL
);
664 ret
= sizeof(VARIANT
);
672 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.hreftype
,&tinfo2
);
674 return 0; /* should fail critically in serialize_param */
675 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
676 ret
= tattr
->cbSizeInstance
;
677 ITypeInfo_ReleaseTypeAttr(tinfo2
, tattr
);
678 ITypeInfo_Release(tinfo2
);
682 ret
= sizeof(DWORD_PTR
);
686 return (ret
+ sizeof(DWORD_PTR
) - 1) / sizeof(DWORD_PTR
);
689 /* how much space do we use on the heap (in bytes) */
691 _xsize(const TYPEDESC
*td
, ITypeInfo
*tinfo
) {
698 return sizeof(VARIANT
);
701 const ARRAYDESC
*adesc
= td
->u
.lpadesc
;
703 for (i
=0;i
<adesc
->cDims
;i
++)
704 arrsize
*= adesc
->rgbounds
[i
].cElements
;
705 return arrsize
*_xsize(&adesc
->tdescElem
, tinfo
);
725 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,td
->u
.hreftype
,&tinfo2
);
728 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
729 ret
= tattr
->cbSizeInstance
;
730 ITypeInfo_ReleaseTypeAttr(tinfo2
, tattr
);
731 ITypeInfo_Release(tinfo2
);
735 return sizeof(DWORD_PTR
);
739 /* Whether we pass this type by reference or by value */
741 _passbyref(const TYPEDESC
*td
, ITypeInfo
*tinfo
) {
742 return (td
->vt
== VT_USERDEFINED
||
743 td
->vt
== VT_VARIANT
||
760 TRACE("(tdesc.vt %s)\n",debugstr_vt(tdesc
->vt
));
763 if ((vartype
& 0xf000) == VT_ARRAY
)
764 vartype
= VT_SAFEARRAY
;
773 if (debugout
) TRACE_(olerelay
)("%s\n", wine_dbgstr_longlong(*(ULONGLONG
*)arg
));
775 hres
= xbuf_add(buf
,(LPBYTE
)arg
,8);
784 if (debugout
) TRACE_(olerelay
)("%x\n", *(DWORD
*)arg
);
786 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
792 if (debugout
) TRACE_(olerelay
)("%04x\n", *(WORD
*)arg
);
794 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
799 if (debugout
) TRACE_(olerelay
)("%02x\n", *(BYTE
*)arg
);
801 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
804 if (debugout
) TRACE_(olerelay
)("%s", debugstr_variant((VARIANT
*)arg
));
807 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
808 ULONG size
= VARIANT_UserSize(&flags
, buf
->curoff
, (VARIANT
*)arg
);
809 xbuf_resize(buf
, size
);
810 VARIANT_UserMarshal(&flags
, buf
->base
+ buf
->curoff
, (VARIANT
*)arg
);
815 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
816 VARIANT_UserFree(&flags
, (VARIANT
*)arg
);
821 if (writeit
&& debugout
) {
823 TRACE_(olerelay
)("%s",relaystr((WCHAR
*)*arg
));
825 TRACE_(olerelay
)("<bstr NULL>");
829 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
830 ULONG size
= BSTR_UserSize(&flags
, buf
->curoff
, (BSTR
*)arg
);
831 xbuf_resize(buf
, size
);
832 BSTR_UserMarshal(&flags
, buf
->base
+ buf
->curoff
, (BSTR
*)arg
);
837 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
838 BSTR_UserFree(&flags
, (BSTR
*)arg
);
844 BOOL derefhere
= TRUE
;
846 if (tdesc
->u
.lptdesc
->vt
== VT_USERDEFINED
) {
850 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.lptdesc
->u
.hreftype
,&tinfo2
);
852 ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc
->u
.lptdesc
->u
.hreftype
);
855 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
856 switch (tattr
->typekind
) {
858 if (tattr
->tdescAlias
.vt
== VT_USERDEFINED
)
860 DWORD href
= tattr
->tdescAlias
.u
.hreftype
;
861 ITypeInfo_ReleaseTypeAttr(tinfo
, tattr
);
862 ITypeInfo_Release(tinfo2
);
863 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,href
,&tinfo2
);
865 ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc
->u
.lptdesc
->u
.hreftype
);
868 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
869 derefhere
= (tattr
->typekind
!= TKIND_DISPATCH
&&
870 tattr
->typekind
!= TKIND_INTERFACE
&&
871 tattr
->typekind
!= TKIND_COCLASS
);
874 case TKIND_ENUM
: /* confirmed */
875 case TKIND_RECORD
: /* FIXME: mostly untested */
877 case TKIND_DISPATCH
: /* will be done in VT_USERDEFINED case */
878 case TKIND_INTERFACE
: /* will be done in VT_USERDEFINED case */
879 case TKIND_COCLASS
: /* will be done in VT_USERDEFINED case */
883 FIXME("unhandled switch cases tattr->typekind %d\n", tattr
->typekind
);
887 ITypeInfo_ReleaseTypeAttr(tinfo
, tattr
);
888 ITypeInfo_Release(tinfo2
);
891 if (debugout
) TRACE_(olerelay
)("*");
892 /* Write always, so the other side knows when it gets a NULL pointer.
894 cookie
= *arg
? 0x42424242 : 0;
895 hres
= xbuf_add(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
899 if (debugout
) TRACE_(olerelay
)("NULL");
902 hres
= serialize_param(tinfo
,writeit
,debugout
,dealloc
,tdesc
->u
.lptdesc
,(DWORD_PTR
*)*arg
,buf
);
903 if (derefhere
&& dealloc
) HeapFree(GetProcessHeap(),0,(LPVOID
)*arg
);
907 if (debugout
) TRACE_(olerelay
)("unk(0x%lx)", *arg
);
909 hres
= _marshal_interface(buf
,&IID_IUnknown
,(LPUNKNOWN
)*arg
);
910 if (dealloc
&& *(IUnknown
**)arg
)
911 IUnknown_Release((LPUNKNOWN
)*arg
);
914 if (debugout
) TRACE_(olerelay
)("idisp(0x%lx)", *arg
);
916 hres
= _marshal_interface(buf
,&IID_IDispatch
,(LPUNKNOWN
)*arg
);
917 if (dealloc
&& *(IUnknown
**)arg
)
918 IUnknown_Release((LPUNKNOWN
)*arg
);
921 if (debugout
) TRACE_(olerelay
)("<void>");
923 case VT_USERDEFINED
: {
927 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.hreftype
,&tinfo2
);
929 ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc
->u
.hreftype
);
932 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
933 switch (tattr
->typekind
) {
935 case TKIND_INTERFACE
:
937 hres
=_marshal_interface(buf
,&(tattr
->guid
),(LPUNKNOWN
)arg
);
939 IUnknown_Release((LPUNKNOWN
)arg
);
941 case TKIND_COCLASS
: {
942 GUID iid
= tattr
->guid
;
946 for(i
= 0; i
< tattr
->cImplTypes
; i
++) {
947 if(SUCCEEDED(ITypeInfo_GetImplTypeFlags(tinfo2
, i
, &type_flags
)) &&
948 type_flags
== (IMPLTYPEFLAG_FSOURCE
|IMPLTYPEFLAG_FDEFAULT
)) {
952 if(FAILED(ITypeInfo_GetRefTypeOfImplType(tinfo2
, i
, &href
)))
954 if(FAILED(ITypeInfo_GetRefTypeInfo(tinfo2
, href
, &tinfo3
)))
956 if(SUCCEEDED(ITypeInfo_GetTypeAttr(tinfo3
, &tattr2
))) {
958 ITypeInfo_ReleaseTypeAttr(tinfo3
, tattr2
);
960 ITypeInfo_Release(tinfo3
);
966 hres
=_marshal_interface(buf
, &iid
, (LPUNKNOWN
)arg
);
968 IUnknown_Release((LPUNKNOWN
)arg
);
973 if (debugout
) TRACE_(olerelay
)("{");
974 for (i
=0;i
<tattr
->cVars
;i
++) {
979 hres
= ITypeInfo_GetVarDesc(tinfo2
, i
, &vdesc
);
981 ERR("Could not get vardesc of %d\n",i
);
984 elem2
= &vdesc
->elemdescVar
;
985 tdesc2
= &elem2
->tdesc
;
986 hres
= serialize_param(
992 (DWORD_PTR
*)(((LPBYTE
)arg
)+vdesc
->u
.oInst
),
995 ITypeInfo_ReleaseVarDesc(tinfo2
, vdesc
);
998 if (debugout
&& (i
<(tattr
->cVars
-1)))
999 TRACE_(olerelay
)(",");
1001 if (debugout
) TRACE_(olerelay
)("}");
1005 hres
= serialize_param(tinfo2
,writeit
,debugout
,dealloc
,&tattr
->tdescAlias
,arg
,buf
);
1009 if (debugout
) TRACE_(olerelay
)("%x", *(DWORD
*)arg
);
1011 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
1014 FIXME("Unhandled typekind %d\n",tattr
->typekind
);
1018 ITypeInfo_ReleaseTypeAttr(tinfo2
, tattr
);
1019 ITypeInfo_Release(tinfo2
);
1023 ARRAYDESC
*adesc
= tdesc
->u
.lpadesc
;
1026 if (debugout
) TRACE_(olerelay
)("carr");
1027 for (i
=0;i
<adesc
->cDims
;i
++) {
1028 if (debugout
) TRACE_(olerelay
)("[%d]",adesc
->rgbounds
[i
].cElements
);
1029 arrsize
*= adesc
->rgbounds
[i
].cElements
;
1031 if (debugout
) TRACE_(olerelay
)("(vt %s)",debugstr_vt(adesc
->tdescElem
.vt
));
1032 if (debugout
) TRACE_(olerelay
)("[");
1033 for (i
=0;i
<arrsize
;i
++) {
1034 LPBYTE base
= _passbyref(&adesc
->tdescElem
, tinfo
) ? (LPBYTE
) *arg
: (LPBYTE
) arg
;
1035 hres
= serialize_param(tinfo
, writeit
, debugout
, dealloc
, &adesc
->tdescElem
, (DWORD_PTR
*)((LPBYTE
)base
+i
*_xsize(&adesc
->tdescElem
, tinfo
)), buf
);
1038 if (debugout
&& (i
<arrsize
-1)) TRACE_(olerelay
)(",");
1040 if (debugout
) TRACE_(olerelay
)("]");
1042 HeapFree(GetProcessHeap(), 0, *(void **)arg
);
1045 case VT_SAFEARRAY
: {
1048 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
1049 ULONG size
= LPSAFEARRAY_UserSize(&flags
, buf
->curoff
, (LPSAFEARRAY
*)arg
);
1050 xbuf_resize(buf
, size
);
1051 LPSAFEARRAY_UserMarshal(&flags
, buf
->base
+ buf
->curoff
, (LPSAFEARRAY
*)arg
);
1056 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
1057 LPSAFEARRAY_UserFree(&flags
, (LPSAFEARRAY
*)arg
);
1062 ERR("Unhandled marshal type %d.\n",tdesc
->vt
);
1077 HRESULT hres
= S_OK
;
1080 TRACE("vt %s at %p\n",debugstr_vt(tdesc
->vt
),arg
);
1082 vartype
= tdesc
->vt
;
1083 if ((vartype
& 0xf000) == VT_ARRAY
)
1084 vartype
= VT_SAFEARRAY
;
1091 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
1092 unsigned char *buffer
;
1093 buffer
= VARIANT_UserUnmarshal(&flags
, buf
->base
+ buf
->curoff
, (VARIANT
*)arg
);
1094 buf
->curoff
= buffer
- buf
->base
;
1104 hres
= xbuf_get(buf
,(LPBYTE
)arg
,8);
1105 if (hres
) ERR("Failed to read integer 8 byte\n");
1107 if (debugout
) TRACE_(olerelay
)("%s", wine_dbgstr_longlong(*(ULONGLONG
*)arg
));
1116 hres
= xbuf_get(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
1117 if (hres
) ERR("Failed to read integer 4 byte\n");
1119 if (debugout
) TRACE_(olerelay
)("%x", *(DWORD
*)arg
);
1126 hres
= xbuf_get(buf
,(LPBYTE
)&x
,sizeof(DWORD
));
1127 if (hres
) ERR("Failed to read integer 4 byte\n");
1130 if (debugout
) TRACE_(olerelay
)("%04x", *(WORD
*)arg
);
1136 hres
= xbuf_get(buf
,(LPBYTE
)&x
,sizeof(DWORD
));
1137 if (hres
) ERR("Failed to read integer 4 byte\n");
1140 if (debugout
) TRACE_(olerelay
)("%02x", *(BYTE
*)arg
);
1145 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
1146 unsigned char *buffer
;
1147 buffer
= BSTR_UserUnmarshal(&flags
, buf
->base
+ buf
->curoff
, (BSTR
*)arg
);
1148 buf
->curoff
= buffer
- buf
->base
;
1149 if (debugout
) TRACE_(olerelay
)("%s",debugstr_w(*(BSTR
*)arg
));
1155 BOOL derefhere
= TRUE
;
1157 if (tdesc
->u
.lptdesc
->vt
== VT_USERDEFINED
) {
1161 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.lptdesc
->u
.hreftype
,&tinfo2
);
1163 ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc
->u
.lptdesc
->u
.hreftype
);
1166 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
1167 switch (tattr
->typekind
) {
1169 if (tattr
->tdescAlias
.vt
== VT_USERDEFINED
)
1171 DWORD href
= tattr
->tdescAlias
.u
.hreftype
;
1172 ITypeInfo_ReleaseTypeAttr(tinfo
, tattr
);
1173 ITypeInfo_Release(tinfo2
);
1174 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,href
,&tinfo2
);
1176 ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc
->u
.lptdesc
->u
.hreftype
);
1179 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
1180 derefhere
= (tattr
->typekind
!= TKIND_DISPATCH
&&
1181 tattr
->typekind
!= TKIND_INTERFACE
&&
1182 tattr
->typekind
!= TKIND_COCLASS
);
1185 case TKIND_ENUM
: /* confirmed */
1186 case TKIND_RECORD
: /* FIXME: mostly untested */
1188 case TKIND_DISPATCH
: /* will be done in VT_USERDEFINED case */
1189 case TKIND_INTERFACE
: /* will be done in VT_USERDEFINED case */
1190 case TKIND_COCLASS
: /* will be done in VT_USERDEFINED case */
1194 FIXME("unhandled switch cases tattr->typekind %d\n", tattr
->typekind
);
1198 ITypeInfo_ReleaseTypeAttr(tinfo2
, tattr
);
1199 ITypeInfo_Release(tinfo2
);
1201 /* read it in all cases, we need to know if we have
1202 * NULL pointer or not.
1204 hres
= xbuf_get(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
1206 ERR("Failed to load pointer cookie.\n");
1209 if (cookie
!= 0x42424242) {
1210 /* we read a NULL ptr from the remote side */
1211 if (debugout
) TRACE_(olerelay
)("NULL");
1215 if (debugout
) TRACE_(olerelay
)("*");
1217 /* Allocate space for the referenced struct */
1219 *arg
=(DWORD_PTR
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,_xsize(tdesc
->u
.lptdesc
, tinfo
));
1222 return deserialize_param(tinfo
, readit
, debugout
, alloc
, tdesc
->u
.lptdesc
, (DWORD_PTR
*)*arg
, buf
);
1224 return deserialize_param(tinfo
, readit
, debugout
, alloc
, tdesc
->u
.lptdesc
, arg
, buf
);
1227 /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
1229 *arg
=(DWORD_PTR
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DWORD_PTR
));
1232 hres
= _unmarshal_interface(buf
,&IID_IUnknown
,(LPUNKNOWN
*)arg
);
1234 TRACE_(olerelay
)("unk(%p)",arg
);
1239 hres
= _unmarshal_interface(buf
,&IID_IDispatch
,(LPUNKNOWN
*)arg
);
1241 TRACE_(olerelay
)("idisp(%p)",arg
);
1244 if (debugout
) TRACE_(olerelay
)("<void>");
1246 case VT_USERDEFINED
: {
1250 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.hreftype
,&tinfo2
);
1252 ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc
->u
.hreftype
);
1255 hres
= ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
1257 ERR("Could not get typeattr in VT_USERDEFINED.\n");
1259 switch (tattr
->typekind
) {
1260 case TKIND_DISPATCH
:
1261 case TKIND_INTERFACE
:
1263 hres
= _unmarshal_interface(buf
,&(tattr
->guid
),(LPUNKNOWN
*)arg
);
1265 case TKIND_COCLASS
: {
1266 GUID iid
= tattr
->guid
;
1270 for(i
= 0; i
< tattr
->cImplTypes
; i
++) {
1271 if(SUCCEEDED(ITypeInfo_GetImplTypeFlags(tinfo2
, i
, &type_flags
)) &&
1272 type_flags
== (IMPLTYPEFLAG_FSOURCE
|IMPLTYPEFLAG_FDEFAULT
)) {
1276 if(FAILED(ITypeInfo_GetRefTypeOfImplType(tinfo2
, i
, &href
)))
1278 if(FAILED(ITypeInfo_GetRefTypeInfo(tinfo2
, href
, &tinfo3
)))
1280 if(SUCCEEDED(ITypeInfo_GetTypeAttr(tinfo3
, &tattr2
))) {
1282 ITypeInfo_ReleaseTypeAttr(tinfo3
, tattr2
);
1284 ITypeInfo_Release(tinfo3
);
1290 hres
= _unmarshal_interface(buf
, &iid
, (LPUNKNOWN
*)arg
);
1293 case TKIND_RECORD
: {
1296 if (debugout
) TRACE_(olerelay
)("{");
1297 for (i
=0;i
<tattr
->cVars
;i
++) {
1300 hres
= ITypeInfo_GetVarDesc(tinfo2
, i
, &vdesc
);
1302 ERR("Could not get vardesc of %d\n",i
);
1303 ITypeInfo_ReleaseTypeAttr(tinfo2
, tattr
);
1304 ITypeInfo_Release(tinfo2
);
1307 hres
= deserialize_param(
1312 &vdesc
->elemdescVar
.tdesc
,
1313 (DWORD_PTR
*)(((LPBYTE
)arg
)+vdesc
->u
.oInst
),
1316 ITypeInfo_ReleaseVarDesc(tinfo2
, vdesc
);
1317 if (debugout
&& (i
<tattr
->cVars
-1)) TRACE_(olerelay
)(",");
1319 if (debugout
) TRACE_(olerelay
)("}");
1323 hres
= deserialize_param(tinfo2
,readit
,debugout
,alloc
,&tattr
->tdescAlias
,arg
,buf
);
1327 hres
= xbuf_get(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
1328 if (hres
) ERR("Failed to read enum (4 byte)\n");
1330 if (debugout
) TRACE_(olerelay
)("%x", *(DWORD
*)arg
);
1333 ERR("Unhandled typekind %d\n",tattr
->typekind
);
1337 ITypeInfo_ReleaseTypeAttr(tinfo2
, tattr
);
1340 ERR("failed to stuballoc in TKIND_RECORD.\n");
1341 ITypeInfo_Release(tinfo2
);
1345 /* arg is pointing to the start of the array. */
1346 LPBYTE base
= (LPBYTE
) arg
;
1347 ARRAYDESC
*adesc
= tdesc
->u
.lpadesc
;
1350 if (adesc
->cDims
> 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
1351 for (i
=0;i
<adesc
->cDims
;i
++)
1352 arrsize
*= adesc
->rgbounds
[i
].cElements
;
1353 if (_passbyref(&adesc
->tdescElem
, tinfo
))
1355 base
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,_xsize(tdesc
->u
.lptdesc
, tinfo
) * arrsize
);
1356 *arg
= (DWORD_PTR
)base
;
1358 for (i
=0;i
<arrsize
;i
++)
1365 (DWORD_PTR
*)(base
+ i
*_xsize(&adesc
->tdescElem
, tinfo
)),
1370 case VT_SAFEARRAY
: {
1373 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
1374 unsigned char *buffer
;
1375 buffer
= LPSAFEARRAY_UserUnmarshal(&flags
, buf
->base
+ buf
->curoff
, (LPSAFEARRAY
*)arg
);
1376 buf
->curoff
= buffer
- buf
->base
;
1381 ERR("No handler for VT type %d!\n",tdesc
->vt
);
1387 /* Retrieves a function's funcdesc, searching back into inherited interfaces. */
1388 static HRESULT
get_funcdesc(ITypeInfo
*tinfo
, int iMethod
, ITypeInfo
**tactual
, const FUNCDESC
**fdesc
,
1389 BSTR
*iname
, BSTR
*fname
, UINT
*num
)
1393 UINT inherited_funcs
= 0;
1396 if (fname
) *fname
= NULL
;
1397 if (iname
) *iname
= NULL
;
1401 hr
= ITypeInfo_GetTypeAttr(tinfo
, &attr
);
1404 ERR("GetTypeAttr failed with %x\n",hr
);
1408 if(attr
->typekind
== TKIND_DISPATCH
)
1410 if(attr
->wTypeFlags
& TYPEFLAG_FDUAL
)
1415 hr
= ITypeInfo_GetRefTypeOfImplType(tinfo
, -1, &href
);
1418 ERR("Cannot get interface href from dual dispinterface\n");
1419 ITypeInfo_ReleaseTypeAttr(tinfo
, attr
);
1422 hr
= ITypeInfo_GetRefTypeInfo(tinfo
, href
, &tinfo2
);
1425 ERR("Cannot get interface from dual dispinterface\n");
1426 ITypeInfo_ReleaseTypeAttr(tinfo
, attr
);
1429 hr
= get_funcdesc(tinfo2
, iMethod
, tactual
, fdesc
, iname
, fname
, num
);
1430 ITypeInfo_Release(tinfo2
);
1431 ITypeInfo_ReleaseTypeAttr(tinfo
, attr
);
1434 ERR("Shouldn't be called with a non-dual dispinterface\n");
1438 impl_types
= attr
->cImplTypes
;
1439 ITypeInfo_ReleaseTypeAttr(tinfo
, attr
);
1441 for (i
= 0; i
< impl_types
; i
++)
1444 ITypeInfo
*pSubTypeInfo
;
1447 hr
= ITypeInfo_GetRefTypeOfImplType(tinfo
, i
, &href
);
1448 if (FAILED(hr
)) return hr
;
1449 hr
= ITypeInfo_GetRefTypeInfo(tinfo
, href
, &pSubTypeInfo
);
1450 if (FAILED(hr
)) return hr
;
1452 hr
= get_funcdesc(pSubTypeInfo
, iMethod
, tactual
, fdesc
, iname
, fname
, &sub_funcs
);
1453 inherited_funcs
+= sub_funcs
;
1454 ITypeInfo_Release(pSubTypeInfo
);
1455 if(SUCCEEDED(hr
)) return hr
;
1457 if(iMethod
< inherited_funcs
)
1459 ERR("shouldn't be here\n");
1460 return E_INVALIDARG
;
1463 for(i
= inherited_funcs
; i
<= iMethod
; i
++)
1465 hr
= ITypeInfoImpl_GetInternalFuncDesc(tinfo
, i
- inherited_funcs
, fdesc
);
1473 /* found it. We don't care about num so zero it */
1476 ITypeInfo_AddRef(*tactual
);
1477 if (fname
) ITypeInfo_GetDocumentation(tinfo
,(*fdesc
)->memid
,fname
,NULL
,NULL
,NULL
);
1478 if (iname
) ITypeInfo_GetDocumentation(tinfo
,-1,iname
,NULL
,NULL
,NULL
);
1482 static inline BOOL
is_in_elem(const ELEMDESC
*elem
)
1484 return (elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
|| !elem
->u
.paramdesc
.wParamFlags
);
1487 static inline BOOL
is_out_elem(const ELEMDESC
*elem
)
1489 return (elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
|| !elem
->u
.paramdesc
.wParamFlags
);
1492 static DWORD WINAPI
xCall(int method
, void **args
)
1494 TMProxyImpl
*tpinfo
= args
[0];
1496 const FUNCDESC
*fdesc
;
1505 DWORD remoteresult
= 0;
1507 IRpcChannelBuffer
*chanbuf
;
1509 EnterCriticalSection(&tpinfo
->crit
);
1511 hres
= get_funcdesc(tpinfo
->tinfo
,method
,&tinfo
,&fdesc
,&iname
,&fname
,NULL
);
1513 ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method
);
1514 LeaveCriticalSection(&tpinfo
->crit
);
1518 if (!tpinfo
->chanbuf
)
1520 WARN("Tried to use disconnected proxy\n");
1521 ITypeInfo_Release(tinfo
);
1522 LeaveCriticalSection(&tpinfo
->crit
);
1523 return RPC_E_DISCONNECTED
;
1525 chanbuf
= tpinfo
->chanbuf
;
1526 IRpcChannelBuffer_AddRef(chanbuf
);
1528 LeaveCriticalSection(&tpinfo
->crit
);
1530 if (TRACE_ON(olerelay
)) {
1531 TRACE_(olerelay
)("->");
1533 TRACE_(olerelay
)("%s:",relaystr(iname
));
1535 TRACE_(olerelay
)("%s(%d)",relaystr(fname
),method
);
1537 TRACE_(olerelay
)("%d",method
);
1538 TRACE_(olerelay
)("(");
1541 SysFreeString(iname
);
1542 SysFreeString(fname
);
1544 memset(&buf
,0,sizeof(buf
));
1546 /* normal typelib driven serializing */
1548 /* Need them for hack below */
1549 memset(names
,0,sizeof(names
));
1550 if (ITypeInfo_GetNames(tinfo
,fdesc
->memid
,names
,sizeof(names
)/sizeof(names
[0]),&nrofnames
))
1552 if (nrofnames
> sizeof(names
)/sizeof(names
[0]))
1553 ERR("Need more names!\n");
1555 xargs
= (DWORD_PTR
*)(args
+ 1);
1556 for (i
=0;i
<fdesc
->cParams
;i
++) {
1557 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1558 if (TRACE_ON(olerelay
)) {
1559 if (i
) TRACE_(olerelay
)(",");
1560 if (i
+1<nrofnames
&& names
[i
+1])
1561 TRACE_(olerelay
)("%s=",relaystr(names
[i
+1]));
1563 /* No need to marshal other data than FIN and any VT_PTR. */
1564 if (!is_in_elem(elem
))
1566 if (elem
->tdesc
.vt
!= VT_PTR
)
1568 xargs
+=_argsize(&elem
->tdesc
, tinfo
);
1569 TRACE_(olerelay
)("[out]");
1574 memset( *(void **)xargs
, 0, _xsize( elem
->tdesc
.u
.lptdesc
, tinfo
) );
1578 hres
= serialize_param(
1589 ERR("Failed to serialize param, hres %x\n",hres
);
1592 xargs
+=_argsize(&elem
->tdesc
, tinfo
);
1594 TRACE_(olerelay
)(")");
1596 memset(&msg
,0,sizeof(msg
));
1597 msg
.cbBuffer
= buf
.curoff
;
1598 msg
.iMethod
= method
;
1599 hres
= IRpcChannelBuffer_GetBuffer(chanbuf
,&msg
,&(tpinfo
->iid
));
1601 ERR("RpcChannelBuffer GetBuffer failed, %x\n",hres
);
1604 memcpy(msg
.Buffer
,buf
.base
,buf
.curoff
);
1605 TRACE_(olerelay
)("\n");
1606 hres
= IRpcChannelBuffer_SendReceive(chanbuf
,&msg
,&status
);
1608 ERR("RpcChannelBuffer SendReceive failed, %x\n",hres
);
1612 TRACE_(olerelay
)(" status = %08x (",status
);
1614 buf
.base
= HeapReAlloc(GetProcessHeap(),0,buf
.base
,msg
.cbBuffer
);
1616 buf
.base
= HeapAlloc(GetProcessHeap(),0,msg
.cbBuffer
);
1617 buf
.size
= msg
.cbBuffer
;
1618 memcpy(buf
.base
,msg
.Buffer
,buf
.size
);
1621 /* generic deserializer using typelib description */
1622 xargs
= (DWORD_PTR
*)(args
+ 1);
1624 for (i
=0;i
<fdesc
->cParams
;i
++) {
1625 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1627 if (i
) TRACE_(olerelay
)(",");
1628 if (i
+1<nrofnames
&& names
[i
+1]) TRACE_(olerelay
)("%s=",relaystr(names
[i
+1]));
1630 /* No need to marshal other data than FOUT and any VT_PTR */
1631 if (!is_out_elem(elem
) && (elem
->tdesc
.vt
!= VT_PTR
)) {
1632 xargs
+= _argsize(&elem
->tdesc
, tinfo
);
1633 TRACE_(olerelay
)("[in]");
1636 hres
= deserialize_param(
1646 ERR("Failed to unmarshall param, hres %x\n",hres
);
1650 xargs
+= _argsize(&elem
->tdesc
, tinfo
);
1653 hres
= xbuf_get(&buf
, (LPBYTE
)&remoteresult
, sizeof(DWORD
));
1656 TRACE_(olerelay
)(") = %08x\n", remoteresult
);
1658 hres
= remoteresult
;
1661 IRpcChannelBuffer_FreeBuffer(chanbuf
,&msg
);
1662 for (i
= 0; i
< nrofnames
; i
++)
1663 SysFreeString(names
[i
]);
1664 HeapFree(GetProcessHeap(),0,buf
.base
);
1665 IRpcChannelBuffer_Release(chanbuf
);
1666 ITypeInfo_Release(tinfo
);
1667 TRACE("-- 0x%08x\n", hres
);
1671 static HRESULT WINAPI
ProxyIUnknown_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
1673 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1675 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
1677 if (proxy
->outerunknown
)
1678 return IUnknown_QueryInterface(proxy
->outerunknown
, riid
, ppv
);
1680 FIXME("No interface\n");
1681 return E_NOINTERFACE
;
1684 static ULONG WINAPI
ProxyIUnknown_AddRef(IUnknown
*iface
)
1686 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1690 if (proxy
->outerunknown
)
1691 return IUnknown_AddRef(proxy
->outerunknown
);
1693 return 2; /* FIXME */
1696 static ULONG WINAPI
ProxyIUnknown_Release(IUnknown
*iface
)
1698 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1702 if (proxy
->outerunknown
)
1703 return IUnknown_Release(proxy
->outerunknown
);
1705 return 1; /* FIXME */
1708 static HRESULT WINAPI
ProxyIDispatch_GetTypeInfoCount(LPDISPATCH iface
, UINT
* pctinfo
)
1710 TMProxyImpl
*This
= (TMProxyImpl
*)iface
;
1712 TRACE("(%p)\n", pctinfo
);
1714 return IDispatch_GetTypeInfoCount(This
->dispatch
, pctinfo
);
1717 static HRESULT WINAPI
ProxyIDispatch_GetTypeInfo(LPDISPATCH iface
, UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
1719 TMProxyImpl
*This
= (TMProxyImpl
*)iface
;
1721 TRACE("(%d, %x, %p)\n", iTInfo
, lcid
, ppTInfo
);
1723 return IDispatch_GetTypeInfo(This
->dispatch
, iTInfo
, lcid
, ppTInfo
);
1726 static HRESULT WINAPI
ProxyIDispatch_GetIDsOfNames(LPDISPATCH iface
, REFIID riid
, LPOLESTR
* rgszNames
, UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
1728 TMProxyImpl
*This
= (TMProxyImpl
*)iface
;
1730 TRACE("(%s, %p, %d, 0x%x, %p)\n", debugstr_guid(riid
), rgszNames
, cNames
, lcid
, rgDispId
);
1732 return IDispatch_GetIDsOfNames(This
->dispatch
, riid
, rgszNames
,
1733 cNames
, lcid
, rgDispId
);
1736 static HRESULT WINAPI
ProxyIDispatch_Invoke(LPDISPATCH iface
, DISPID dispIdMember
, REFIID riid
, LCID lcid
,
1737 WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
,
1738 EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
1740 TMProxyImpl
*This
= (TMProxyImpl
*)iface
;
1742 TRACE("(%d, %s, 0x%x, 0x%x, %p, %p, %p, %p)\n", dispIdMember
,
1743 debugstr_guid(riid
), lcid
, wFlags
, pDispParams
, pVarResult
,
1744 pExcepInfo
, puArgErr
);
1746 return IDispatch_Invoke(This
->dispatch
, dispIdMember
, riid
, lcid
,
1747 wFlags
, pDispParams
, pVarResult
, pExcepInfo
,
1753 IRpcChannelBuffer IRpcChannelBuffer_iface
;
1755 /* the IDispatch-derived interface we are handling */
1757 IRpcChannelBuffer
*pDelegateChannel
;
1758 } TMarshalDispatchChannel
;
1760 static inline TMarshalDispatchChannel
*impl_from_IRpcChannelBuffer(IRpcChannelBuffer
*iface
)
1762 return CONTAINING_RECORD(iface
, TMarshalDispatchChannel
, IRpcChannelBuffer_iface
);
1765 static HRESULT WINAPI
TMarshalDispatchChannel_QueryInterface(IRpcChannelBuffer
*iface
, REFIID riid
, LPVOID
*ppv
)
1768 if (IsEqualIID(riid
,&IID_IRpcChannelBuffer
) || IsEqualIID(riid
,&IID_IUnknown
))
1771 IRpcChannelBuffer_AddRef(iface
);
1774 return E_NOINTERFACE
;
1777 static ULONG WINAPI
TMarshalDispatchChannel_AddRef(LPRPCCHANNELBUFFER iface
)
1779 TMarshalDispatchChannel
*This
= impl_from_IRpcChannelBuffer(iface
);
1780 return InterlockedIncrement(&This
->refs
);
1783 static ULONG WINAPI
TMarshalDispatchChannel_Release(LPRPCCHANNELBUFFER iface
)
1785 TMarshalDispatchChannel
*This
= impl_from_IRpcChannelBuffer(iface
);
1788 ref
= InterlockedDecrement(&This
->refs
);
1792 IRpcChannelBuffer_Release(This
->pDelegateChannel
);
1793 HeapFree(GetProcessHeap(), 0, This
);
1797 static HRESULT WINAPI
TMarshalDispatchChannel_GetBuffer(LPRPCCHANNELBUFFER iface
, RPCOLEMESSAGE
* olemsg
, REFIID riid
)
1799 TMarshalDispatchChannel
*This
= impl_from_IRpcChannelBuffer(iface
);
1800 TRACE("(%p, %s)\n", olemsg
, debugstr_guid(riid
));
1801 /* Note: we are pretending to invoke a method on the interface identified
1802 * by tmarshal_iid so that we can re-use the IDispatch proxy/stub code
1803 * without the RPC runtime getting confused by not exporting an IDispatch interface */
1804 return IRpcChannelBuffer_GetBuffer(This
->pDelegateChannel
, olemsg
, &This
->tmarshal_iid
);
1807 static HRESULT WINAPI
TMarshalDispatchChannel_SendReceive(LPRPCCHANNELBUFFER iface
, RPCOLEMESSAGE
*olemsg
, ULONG
*pstatus
)
1809 TMarshalDispatchChannel
*This
= impl_from_IRpcChannelBuffer(iface
);
1810 TRACE("(%p, %p)\n", olemsg
, pstatus
);
1811 return IRpcChannelBuffer_SendReceive(This
->pDelegateChannel
, olemsg
, pstatus
);
1814 static HRESULT WINAPI
TMarshalDispatchChannel_FreeBuffer(LPRPCCHANNELBUFFER iface
, RPCOLEMESSAGE
* olemsg
)
1816 TMarshalDispatchChannel
*This
= impl_from_IRpcChannelBuffer(iface
);
1817 TRACE("(%p)\n", olemsg
);
1818 return IRpcChannelBuffer_FreeBuffer(This
->pDelegateChannel
, olemsg
);
1821 static HRESULT WINAPI
TMarshalDispatchChannel_GetDestCtx(LPRPCCHANNELBUFFER iface
, DWORD
* pdwDestContext
, void** ppvDestContext
)
1823 TMarshalDispatchChannel
*This
= impl_from_IRpcChannelBuffer(iface
);
1824 TRACE("(%p,%p)\n", pdwDestContext
, ppvDestContext
);
1825 return IRpcChannelBuffer_GetDestCtx(This
->pDelegateChannel
, pdwDestContext
, ppvDestContext
);
1828 static HRESULT WINAPI
TMarshalDispatchChannel_IsConnected(LPRPCCHANNELBUFFER iface
)
1830 TMarshalDispatchChannel
*This
= impl_from_IRpcChannelBuffer(iface
);
1832 return IRpcChannelBuffer_IsConnected(This
->pDelegateChannel
);
1835 static const IRpcChannelBufferVtbl TMarshalDispatchChannelVtbl
=
1837 TMarshalDispatchChannel_QueryInterface
,
1838 TMarshalDispatchChannel_AddRef
,
1839 TMarshalDispatchChannel_Release
,
1840 TMarshalDispatchChannel_GetBuffer
,
1841 TMarshalDispatchChannel_SendReceive
,
1842 TMarshalDispatchChannel_FreeBuffer
,
1843 TMarshalDispatchChannel_GetDestCtx
,
1844 TMarshalDispatchChannel_IsConnected
1847 static HRESULT
TMarshalDispatchChannel_Create(
1848 IRpcChannelBuffer
*pDelegateChannel
, REFIID tmarshal_riid
,
1849 IRpcChannelBuffer
**ppChannel
)
1851 TMarshalDispatchChannel
*This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
1853 return E_OUTOFMEMORY
;
1855 This
->IRpcChannelBuffer_iface
.lpVtbl
= &TMarshalDispatchChannelVtbl
;
1857 IRpcChannelBuffer_AddRef(pDelegateChannel
);
1858 This
->pDelegateChannel
= pDelegateChannel
;
1859 This
->tmarshal_iid
= *tmarshal_riid
;
1861 *ppChannel
= &This
->IRpcChannelBuffer_iface
;
1866 static inline HRESULT
get_facbuf_for_iid(REFIID riid
, IPSFactoryBuffer
**facbuf
)
1871 if ((hr
= CoGetPSClsid(riid
, &clsid
)))
1873 return CoGetClassObject(&clsid
, CLSCTX_INPROC_SERVER
, NULL
,
1874 &IID_IPSFactoryBuffer
, (LPVOID
*)facbuf
);
1877 static HRESULT
init_proxy_entry_point(TMProxyImpl
*proxy
, unsigned int num
)
1880 /* nrofargs including This */
1883 TMAsmProxy
*xasm
= proxy
->asmstubs
+ num
;
1885 const FUNCDESC
*fdesc
;
1887 hres
= get_funcdesc(proxy
->tinfo
, num
, &tinfo2
, &fdesc
, NULL
, NULL
, NULL
);
1889 ERR("GetFuncDesc %x should not fail here.\n",hres
);
1892 ITypeInfo_Release(tinfo2
);
1893 /* some args take more than 4 byte on the stack */
1894 for (j
=0;j
<fdesc
->cParams
;j
++)
1895 nrofargs
+= _argsize(&fdesc
->lprgelemdescParam
[j
].tdesc
, proxy
->tinfo
);
1898 if (fdesc
->callconv
!= CC_STDCALL
) {
1899 ERR("calling convention is not stdcall????\n");
1902 /* leal 4(%esp),%eax
1908 xasm
->lealeax
= 0x0424448d;
1909 xasm
->pushleax
= 0x50;
1910 xasm
->pushlval
= 0x68;
1913 xasm
->xcall
= (char *)xCall
- (char *)&xasm
->lret
;
1915 xasm
->bytestopop
= nrofargs
* 4;
1917 proxy
->lpvtbl
[fdesc
->oVft
/ sizeof(void *)] = xasm
;
1919 #elif defined(__x86_64__)
1921 xasm
->pushq_rbp
= 0x55; /* pushq %rbp */
1922 xasm
->movq_rsp_rbp
[0] = 0x48; /* movq %rsp,%rbp */
1923 xasm
->movq_rsp_rbp
[1] = 0x89;
1924 xasm
->movq_rsp_rbp
[2] = 0xe5;
1925 xasm
->subq_0x20_rsp
= 0x20ec8348; /* subq 0x20,%rsp */
1926 xasm
->movq_rcx_0x10rbp
= 0x104d8948; /* movq %rcx,0x10(%rbp) */
1927 xasm
->movq_rdx_0x18rbp
= 0x18558948; /* movq %rdx,0x18(%rbp) */
1928 xasm
->movq_r8_0x20rbp
= 0x2045894c; /* movq %r8,0x20(%rbp) */
1929 xasm
->movq_r9_0x28rbp
= 0x284d894c; /* movq %r9,0x28(%rbp) */
1930 xasm
->movq_rcx
[0] = 0x48; /* movq <num>,%rcx */
1931 xasm
->movq_rcx
[1] = 0xc7;
1932 xasm
->movq_rcx
[2] = 0xc1;
1934 xasm
->leaq_0x10rbp_rdx
= 0x10558d48; /* leaq 0x10(%rbp),%rdx */
1935 xasm
->movq_rax
= 0xb848; /* movq <xCall>,%rax */
1936 xasm
->xcall
= xCall
;
1937 xasm
->callq_rax
= 0xd0ff; /* callq *%rax */
1938 xasm
->movq_rbp_rsp
[0] = 0x48; /* movq %rbp,%rsp */
1939 xasm
->movq_rbp_rsp
[1] = 0x89;
1940 xasm
->movq_rbp_rsp
[2] = 0xec;
1941 xasm
->popq_rbp
= 0x5d; /* popq %rbp */
1942 xasm
->ret
= 0xc3; /* ret */
1943 xasm
->nop
= 0x90909090; /* nop */
1944 proxy
->lpvtbl
[fdesc
->oVft
/ sizeof(void *)] = xasm
;
1947 FIXME("not implemented on non i386\n");
1953 static HRESULT WINAPI
1954 PSFacBuf_CreateProxy(
1955 LPPSFACTORYBUFFER iface
, IUnknown
* pUnkOuter
, REFIID riid
,
1956 IRpcProxyBuffer
**ppProxy
, LPVOID
*ppv
)
1960 unsigned int i
, nroffuncs
, vtbl_size
;
1963 BOOL defer_to_dispatch
= FALSE
;
1965 TRACE("(...%s...)\n",debugstr_guid(riid
));
1966 hres
= _get_typeinfo_for_iid(riid
,&tinfo
);
1968 ERR("No typeinfo for %s?\n",debugstr_guid(riid
));
1972 hres
= num_of_funcs(tinfo
, &nroffuncs
, &vtbl_size
);
1973 TRACE("Got %d funcs, vtbl size %d\n", nroffuncs
, vtbl_size
);
1976 ERR("Cannot get number of functions for typeinfo %s\n",debugstr_guid(riid
));
1977 ITypeInfo_Release(tinfo
);
1981 proxy
= CoTaskMemAlloc(sizeof(TMProxyImpl
));
1982 if (!proxy
) return E_OUTOFMEMORY
;
1984 proxy
->dispatch
= NULL
;
1985 proxy
->dispatch_proxy
= NULL
;
1986 proxy
->outerunknown
= pUnkOuter
;
1987 proxy
->asmstubs
= VirtualAlloc(NULL
, sizeof(TMAsmProxy
) * nroffuncs
, MEM_COMMIT
, PAGE_EXECUTE_READWRITE
);
1988 if (!proxy
->asmstubs
) {
1989 ERR("Could not commit pages for proxy thunks\n");
1990 CoTaskMemFree(proxy
);
1991 return E_OUTOFMEMORY
;
1993 proxy
->IRpcProxyBuffer_iface
.lpVtbl
= &tmproxyvtable
;
1994 /* one reference for the proxy */
1996 proxy
->tinfo
= tinfo
;
2000 InitializeCriticalSection(&proxy
->crit
);
2001 proxy
->crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": TMProxyImpl.crit");
2003 proxy
->lpvtbl
= HeapAlloc(GetProcessHeap(), 0, vtbl_size
);
2005 /* if we derive from IDispatch then defer to its proxy for its methods */
2006 hres
= ITypeInfo_GetTypeAttr(tinfo
, &typeattr
);
2009 if (typeattr
->wTypeFlags
& TYPEFLAG_FDISPATCHABLE
)
2011 IPSFactoryBuffer
*factory_buffer
;
2012 hres
= get_facbuf_for_iid(&IID_IDispatch
, &factory_buffer
);
2015 hres
= IPSFactoryBuffer_CreateProxy(factory_buffer
, NULL
,
2016 &IID_IDispatch
, &proxy
->dispatch_proxy
,
2017 (void **)&proxy
->dispatch
);
2018 IPSFactoryBuffer_Release(factory_buffer
);
2020 if ((hres
== S_OK
) && (nroffuncs
< 7))
2022 ERR("nroffuncs calculated incorrectly (%d)\n", nroffuncs
);
2023 hres
= E_UNEXPECTED
;
2027 defer_to_dispatch
= TRUE
;
2030 ITypeInfo_ReleaseTypeAttr(tinfo
, typeattr
);
2033 for (i
=0;i
<nroffuncs
;i
++) {
2036 proxy
->lpvtbl
[i
] = ProxyIUnknown_QueryInterface
;
2039 proxy
->lpvtbl
[i
] = ProxyIUnknown_AddRef
;
2042 proxy
->lpvtbl
[i
] = ProxyIUnknown_Release
;
2045 if(!defer_to_dispatch
) hres
= init_proxy_entry_point(proxy
, i
);
2046 else proxy
->lpvtbl
[3] = ProxyIDispatch_GetTypeInfoCount
;
2049 if(!defer_to_dispatch
) hres
= init_proxy_entry_point(proxy
, i
);
2050 else proxy
->lpvtbl
[4] = ProxyIDispatch_GetTypeInfo
;
2053 if(!defer_to_dispatch
) hres
= init_proxy_entry_point(proxy
, i
);
2054 else proxy
->lpvtbl
[5] = ProxyIDispatch_GetIDsOfNames
;
2057 if(!defer_to_dispatch
) hres
= init_proxy_entry_point(proxy
, i
);
2058 else proxy
->lpvtbl
[6] = ProxyIDispatch_Invoke
;
2061 hres
= init_proxy_entry_point(proxy
, i
);
2068 *ppProxy
= &proxy
->IRpcProxyBuffer_iface
;
2069 IUnknown_AddRef((IUnknown
*)*ppv
);
2073 TMProxyImpl_Release(&proxy
->IRpcProxyBuffer_iface
);
2077 typedef struct _TMStubImpl
{
2078 IRpcStubBuffer IRpcStubBuffer_iface
;
2084 IRpcStubBuffer
*dispatch_stub
;
2085 BOOL dispatch_derivative
;
2088 static inline TMStubImpl
*impl_from_IRpcStubBuffer(IRpcStubBuffer
*iface
)
2090 return CONTAINING_RECORD(iface
, TMStubImpl
, IRpcStubBuffer_iface
);
2093 static HRESULT WINAPI
2094 TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface
, REFIID riid
, LPVOID
*ppv
)
2096 if (IsEqualIID(riid
,&IID_IRpcStubBuffer
)||IsEqualIID(riid
,&IID_IUnknown
)){
2098 IRpcStubBuffer_AddRef(iface
);
2101 FIXME("%s, not supported IID.\n",debugstr_guid(riid
));
2102 return E_NOINTERFACE
;
2106 TMStubImpl_AddRef(LPRPCSTUBBUFFER iface
)
2108 TMStubImpl
*This
= impl_from_IRpcStubBuffer(iface
);
2109 ULONG refCount
= InterlockedIncrement(&This
->ref
);
2111 TRACE("(%p)->(ref before=%u)\n", This
, refCount
- 1);
2117 TMStubImpl_Release(LPRPCSTUBBUFFER iface
)
2119 TMStubImpl
*This
= impl_from_IRpcStubBuffer(iface
);
2120 ULONG refCount
= InterlockedDecrement(&This
->ref
);
2122 TRACE("(%p)->(ref before=%u)\n", This
, refCount
+ 1);
2126 IRpcStubBuffer_Disconnect(iface
);
2127 ITypeInfo_Release(This
->tinfo
);
2128 if (This
->dispatch_stub
)
2129 IRpcStubBuffer_Release(This
->dispatch_stub
);
2130 CoTaskMemFree(This
);
2135 static HRESULT WINAPI
2136 TMStubImpl_Connect(LPRPCSTUBBUFFER iface
, LPUNKNOWN pUnkServer
)
2138 TMStubImpl
*This
= impl_from_IRpcStubBuffer(iface
);
2140 TRACE("(%p)->(%p)\n", This
, pUnkServer
);
2142 IUnknown_AddRef(pUnkServer
);
2143 This
->pUnk
= pUnkServer
;
2145 if (This
->dispatch_stub
)
2146 IRpcStubBuffer_Connect(This
->dispatch_stub
, pUnkServer
);
2152 TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface
)
2154 TMStubImpl
*This
= impl_from_IRpcStubBuffer(iface
);
2156 TRACE("(%p)->()\n", This
);
2160 IUnknown_Release(This
->pUnk
);
2164 if (This
->dispatch_stub
)
2165 IRpcStubBuffer_Disconnect(This
->dispatch_stub
);
2168 static HRESULT WINAPI
2170 LPRPCSTUBBUFFER iface
, RPCOLEMESSAGE
* xmsg
,IRpcChannelBuffer
*rpcchanbuf
)
2172 #if defined(__i386__) || defined(__x86_64__)
2174 const FUNCDESC
*fdesc
;
2175 TMStubImpl
*This
= impl_from_IRpcStubBuffer(iface
);
2177 DWORD_PTR
*args
= NULL
, *xargs
;
2178 DWORD res
, nrofargs
;
2183 ITypeInfo
*tinfo
= NULL
;
2187 if (xmsg
->iMethod
< 3) {
2188 ERR("IUnknown methods cannot be marshaled by the typelib marshaler\n");
2189 return E_UNEXPECTED
;
2192 if (This
->dispatch_derivative
&& xmsg
->iMethod
< sizeof(IDispatchVtbl
)/sizeof(void *))
2194 if (!This
->dispatch_stub
)
2196 IPSFactoryBuffer
*factory_buffer
;
2197 hres
= get_facbuf_for_iid(&IID_IDispatch
, &factory_buffer
);
2200 hres
= IPSFactoryBuffer_CreateStub(factory_buffer
, &IID_IDispatch
,
2201 This
->pUnk
, &This
->dispatch_stub
);
2202 IPSFactoryBuffer_Release(factory_buffer
);
2207 return IRpcStubBuffer_Invoke(This
->dispatch_stub
, xmsg
, rpcchanbuf
);
2210 memset(&buf
,0,sizeof(buf
));
2211 buf
.size
= xmsg
->cbBuffer
;
2212 buf
.base
= HeapAlloc(GetProcessHeap(), 0, xmsg
->cbBuffer
);
2213 memcpy(buf
.base
, xmsg
->Buffer
, xmsg
->cbBuffer
);
2216 hres
= get_funcdesc(This
->tinfo
,xmsg
->iMethod
,&tinfo
,&fdesc
,&iname
,NULL
,NULL
);
2218 ERR("GetFuncDesc on method %d failed with %x\n",xmsg
->iMethod
,hres
);
2222 if (iname
&& !lstrcmpW(iname
, IDispatchW
))
2224 ERR("IDispatch cannot be marshaled by the typelib marshaler\n");
2225 hres
= E_UNEXPECTED
;
2226 SysFreeString (iname
);
2230 SysFreeString (iname
);
2232 /* Need them for hack below */
2233 memset(names
,0,sizeof(names
));
2234 ITypeInfo_GetNames(tinfo
,fdesc
->memid
,names
,sizeof(names
)/sizeof(names
[0]),&nrofnames
);
2235 if (nrofnames
> sizeof(names
)/sizeof(names
[0])) {
2236 ERR("Need more names!\n");
2239 /*dump_FUNCDESC(fdesc);*/
2241 for (i
=0;i
<fdesc
->cParams
;i
++)
2242 nrofargs
+= _argsize(&fdesc
->lprgelemdescParam
[i
].tdesc
, tinfo
);
2243 args
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (nrofargs
+1)*sizeof(DWORD_PTR
));
2246 hres
= E_OUTOFMEMORY
;
2250 /* Allocate all stuff used by call. */
2252 for (i
=0;i
<fdesc
->cParams
;i
++) {
2253 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
2255 hres
= deserialize_param(
2264 xargs
+= _argsize(&elem
->tdesc
, tinfo
);
2266 ERR("Failed to deserialize param %s, hres %x\n",relaystr(names
[i
+1]),hres
);
2271 args
[0] = (DWORD_PTR
)This
->pUnk
;
2276 (*((FARPROC
**)args
[0]))[fdesc
->oVft
/ sizeof(DWORD_PTR
)],
2284 DWORD dwExceptionCode
= GetExceptionCode();
2285 ERR("invoke call failed with exception 0x%08x (%d)\n", dwExceptionCode
, dwExceptionCode
);
2286 if (FAILED(dwExceptionCode
))
2287 hres
= dwExceptionCode
;
2289 hres
= HRESULT_FROM_WIN32(dwExceptionCode
);
2299 for (i
=0;i
<fdesc
->cParams
;i
++) {
2300 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
2301 hres
= serialize_param(
2310 xargs
+= _argsize(&elem
->tdesc
, tinfo
);
2312 ERR("Failed to stuballoc param, hres %x\n",hres
);
2317 hres
= xbuf_add (&buf
, (LPBYTE
)&res
, sizeof(DWORD
));
2322 xmsg
->cbBuffer
= buf
.curoff
;
2323 hres
= IRpcChannelBuffer_GetBuffer(rpcchanbuf
, xmsg
, &This
->iid
);
2325 ERR("IRpcChannelBuffer_GetBuffer failed with error 0x%08x\n", hres
);
2328 memcpy(xmsg
->Buffer
, buf
.base
, buf
.curoff
);
2331 for (i
= 0; i
< nrofnames
; i
++)
2332 SysFreeString(names
[i
]);
2334 ITypeInfo_Release(tinfo
);
2335 HeapFree(GetProcessHeap(), 0, args
);
2337 HeapFree(GetProcessHeap(), 0, buf
.base
);
2339 TRACE("returning\n");
2342 FIXME( "not implemented on non-i386\n" );
2347 static LPRPCSTUBBUFFER WINAPI
2348 TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface
, REFIID riid
) {
2349 FIXME("Huh (%s)?\n",debugstr_guid(riid
));
2354 TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface
) {
2355 TMStubImpl
*This
= impl_from_IRpcStubBuffer(iface
);
2358 return This
->ref
; /*FIXME? */
2361 static HRESULT WINAPI
2362 TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface
, LPVOID
*ppv
) {
2367 TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface
, LPVOID ppv
) {
2371 static const IRpcStubBufferVtbl tmstubvtbl
= {
2372 TMStubImpl_QueryInterface
,
2376 TMStubImpl_Disconnect
,
2378 TMStubImpl_IsIIDSupported
,
2379 TMStubImpl_CountRefs
,
2380 TMStubImpl_DebugServerQueryInterface
,
2381 TMStubImpl_DebugServerRelease
2384 static HRESULT WINAPI
2385 PSFacBuf_CreateStub(
2386 LPPSFACTORYBUFFER iface
, REFIID riid
,IUnknown
*pUnkServer
,
2387 IRpcStubBuffer
** ppStub
2395 TRACE("(%s,%p,%p)\n",debugstr_guid(riid
),pUnkServer
,ppStub
);
2397 hres
= _get_typeinfo_for_iid(riid
,&tinfo
);
2399 ERR("No typeinfo for %s?\n",debugstr_guid(riid
));
2403 /* FIXME: This is not exactly right. We should probably call QI later. */
2404 hres
= IUnknown_QueryInterface(pUnkServer
, riid
, (void**)&obj
);
2406 WARN("Could not get %s iface: %08x\n", debugstr_guid(riid
), hres
);
2408 IUnknown_AddRef(obj
);
2411 stub
= CoTaskMemAlloc(sizeof(TMStubImpl
));
2413 IUnknown_Release(obj
);
2414 return E_OUTOFMEMORY
;
2416 stub
->IRpcStubBuffer_iface
.lpVtbl
= &tmstubvtbl
;
2418 stub
->tinfo
= tinfo
;
2419 stub
->dispatch_stub
= NULL
;
2420 stub
->dispatch_derivative
= FALSE
;
2422 hres
= IRpcStubBuffer_Connect(&stub
->IRpcStubBuffer_iface
, obj
);
2423 *ppStub
= &stub
->IRpcStubBuffer_iface
;
2424 TRACE("IRpcStubBuffer: %p\n", stub
);
2426 ERR("Connect to pUnkServer failed?\n");
2428 /* if we derive from IDispatch then defer to its stub for some of its methods */
2429 hres
= ITypeInfo_GetTypeAttr(tinfo
, &typeattr
);
2432 if (typeattr
->wTypeFlags
& TYPEFLAG_FDISPATCHABLE
)
2433 stub
->dispatch_derivative
= TRUE
;
2434 ITypeInfo_ReleaseTypeAttr(tinfo
, typeattr
);
2437 IUnknown_Release(obj
);
2441 static const IPSFactoryBufferVtbl psfacbufvtbl
= {
2442 PSFacBuf_QueryInterface
,
2445 PSFacBuf_CreateProxy
,
2449 static IPSFactoryBuffer psfac
= { &psfacbufvtbl
};
2451 /***********************************************************************
2452 * TMARSHAL_DllGetClassObject
2454 HRESULT
TMARSHAL_DllGetClassObject(REFCLSID rclsid
, REFIID iid
, void **ppv
)
2456 return IPSFactoryBuffer_QueryInterface(&psfac
, iid
, ppv
);