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"
496 typedef struct _TMAsmProxy
{
511 # warning You need to implement stubless proxies for your architecture
512 typedef struct _TMAsmProxy
{
516 typedef struct _TMProxyImpl
{
518 IRpcProxyBuffer IRpcProxyBuffer_iface
;
521 TMAsmProxy
*asmstubs
;
523 IRpcChannelBuffer
* chanbuf
;
525 CRITICAL_SECTION crit
;
526 IUnknown
*outerunknown
;
528 IRpcProxyBuffer
*dispatch_proxy
;
531 static inline TMProxyImpl
*impl_from_IRpcProxyBuffer( IRpcProxyBuffer
*iface
)
533 return CONTAINING_RECORD(iface
, TMProxyImpl
, IRpcProxyBuffer_iface
);
536 static HRESULT WINAPI
537 TMProxyImpl_QueryInterface(LPRPCPROXYBUFFER iface
, REFIID riid
, LPVOID
*ppv
)
540 if (IsEqualIID(riid
,&IID_IUnknown
)||IsEqualIID(riid
,&IID_IRpcProxyBuffer
)) {
542 IRpcProxyBuffer_AddRef(iface
);
545 FIXME("no interface for %s\n",debugstr_guid(riid
));
546 return E_NOINTERFACE
;
550 TMProxyImpl_AddRef(LPRPCPROXYBUFFER iface
)
552 TMProxyImpl
*This
= impl_from_IRpcProxyBuffer( iface
);
553 ULONG refCount
= InterlockedIncrement(&This
->ref
);
555 TRACE("(%p)->(ref before=%u)\n",This
, refCount
- 1);
561 TMProxyImpl_Release(LPRPCPROXYBUFFER iface
)
563 TMProxyImpl
*This
= impl_from_IRpcProxyBuffer( iface
);
564 ULONG refCount
= InterlockedDecrement(&This
->ref
);
566 TRACE("(%p)->(ref before=%u)\n",This
, refCount
+ 1);
570 if (This
->dispatch_proxy
) IRpcProxyBuffer_Release(This
->dispatch_proxy
);
571 This
->crit
.DebugInfo
->Spare
[0] = 0;
572 DeleteCriticalSection(&This
->crit
);
573 if (This
->chanbuf
) IRpcChannelBuffer_Release(This
->chanbuf
);
574 VirtualFree(This
->asmstubs
, 0, MEM_RELEASE
);
575 HeapFree(GetProcessHeap(), 0, This
->lpvtbl
);
576 ITypeInfo_Release(This
->tinfo
);
582 static HRESULT WINAPI
584 LPRPCPROXYBUFFER iface
,IRpcChannelBuffer
* pRpcChannelBuffer
)
586 TMProxyImpl
*This
= impl_from_IRpcProxyBuffer( iface
);
588 TRACE("(%p)\n", pRpcChannelBuffer
);
590 EnterCriticalSection(&This
->crit
);
592 IRpcChannelBuffer_AddRef(pRpcChannelBuffer
);
593 This
->chanbuf
= pRpcChannelBuffer
;
595 LeaveCriticalSection(&This
->crit
);
597 if (This
->dispatch_proxy
)
599 IRpcChannelBuffer
*pDelegateChannel
;
600 HRESULT hr
= TMarshalDispatchChannel_Create(pRpcChannelBuffer
, &This
->iid
, &pDelegateChannel
);
603 hr
= IRpcProxyBuffer_Connect(This
->dispatch_proxy
, pDelegateChannel
);
604 IRpcChannelBuffer_Release(pDelegateChannel
);
612 TMProxyImpl_Disconnect(LPRPCPROXYBUFFER iface
)
614 TMProxyImpl
*This
= impl_from_IRpcProxyBuffer( iface
);
618 EnterCriticalSection(&This
->crit
);
620 IRpcChannelBuffer_Release(This
->chanbuf
);
621 This
->chanbuf
= NULL
;
623 LeaveCriticalSection(&This
->crit
);
625 if (This
->dispatch_proxy
)
626 IRpcProxyBuffer_Disconnect(This
->dispatch_proxy
);
630 static const IRpcProxyBufferVtbl tmproxyvtable
= {
631 TMProxyImpl_QueryInterface
,
635 TMProxyImpl_Disconnect
638 /* how much space do we use on stack in DWORD steps. */
640 _argsize(TYPEDESC
*tdesc
, ITypeInfo
*tinfo
) {
644 return 8/sizeof(DWORD
);
646 return sizeof(double)/sizeof(DWORD
);
648 return sizeof(CY
)/sizeof(DWORD
);
650 return sizeof(DATE
)/sizeof(DWORD
);
652 return (sizeof(DECIMAL
)+3)/sizeof(DWORD
);
654 return (sizeof(VARIANT
)+3)/sizeof(DWORD
);
662 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.hreftype
,&tinfo2
);
664 return 0; /* should fail critically in serialize_param */
665 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
666 ret
= (tattr
->cbSizeInstance
+3)/sizeof(DWORD
);
667 ITypeInfo_ReleaseTypeAttr(tinfo2
, tattr
);
668 ITypeInfo_Release(tinfo2
);
676 /* how much space do we use on the heap (in bytes) */
678 _xsize(const TYPEDESC
*td
, ITypeInfo
*tinfo
) {
685 return sizeof(VARIANT
);
688 const ARRAYDESC
*adesc
= td
->u
.lpadesc
;
690 for (i
=0;i
<adesc
->cDims
;i
++)
691 arrsize
*= adesc
->rgbounds
[i
].cElements
;
692 return arrsize
*_xsize(&adesc
->tdescElem
, tinfo
);
712 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,td
->u
.hreftype
,&tinfo2
);
715 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
716 ret
= tattr
->cbSizeInstance
;
717 ITypeInfo_ReleaseTypeAttr(tinfo2
, tattr
);
718 ITypeInfo_Release(tinfo2
);
726 /* Whether we pass this type by reference or by value */
728 _passbyref(const TYPEDESC
*td
, ITypeInfo
*tinfo
) {
729 return (td
->vt
== VT_USERDEFINED
||
730 td
->vt
== VT_VARIANT
||
747 TRACE("(tdesc.vt %s)\n",debugstr_vt(tdesc
->vt
));
750 if ((vartype
& 0xf000) == VT_ARRAY
)
751 vartype
= VT_SAFEARRAY
;
760 if (debugout
) TRACE_(olerelay
)("%x%x\n",arg
[0],arg
[1]);
762 hres
= xbuf_add(buf
,(LPBYTE
)arg
,8);
771 if (debugout
) TRACE_(olerelay
)("%x\n",*arg
);
773 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
779 if (debugout
) TRACE_(olerelay
)("%04x\n",*arg
& 0xffff);
781 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
786 if (debugout
) TRACE_(olerelay
)("%02x\n",*arg
& 0xff);
788 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
791 if (debugout
) TRACE_(olerelay
)("%s", debugstr_variant((VARIANT
*)arg
));
794 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
795 ULONG size
= VARIANT_UserSize(&flags
, buf
->curoff
, (VARIANT
*)arg
);
796 xbuf_resize(buf
, size
);
797 VARIANT_UserMarshal(&flags
, buf
->base
+ buf
->curoff
, (VARIANT
*)arg
);
802 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
803 VARIANT_UserFree(&flags
, (VARIANT
*)arg
);
808 if (writeit
&& debugout
) {
810 TRACE_(olerelay
)("%s",relaystr((WCHAR
*)*arg
));
812 TRACE_(olerelay
)("<bstr NULL>");
816 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
817 ULONG size
= BSTR_UserSize(&flags
, buf
->curoff
, (BSTR
*)arg
);
818 xbuf_resize(buf
, size
);
819 BSTR_UserMarshal(&flags
, buf
->base
+ buf
->curoff
, (BSTR
*)arg
);
824 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
825 BSTR_UserFree(&flags
, (BSTR
*)arg
);
831 BOOL derefhere
= TRUE
;
833 if (tdesc
->u
.lptdesc
->vt
== VT_USERDEFINED
) {
837 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.lptdesc
->u
.hreftype
,&tinfo2
);
839 ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc
->u
.lptdesc
->u
.hreftype
);
842 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
843 switch (tattr
->typekind
) {
845 if (tattr
->tdescAlias
.vt
== VT_USERDEFINED
)
847 DWORD href
= tattr
->tdescAlias
.u
.hreftype
;
848 ITypeInfo_ReleaseTypeAttr(tinfo
, tattr
);
849 ITypeInfo_Release(tinfo2
);
850 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,href
,&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 derefhere
= (tattr
->typekind
!= TKIND_DISPATCH
&& tattr
->typekind
!= TKIND_INTERFACE
);
859 case TKIND_ENUM
: /* confirmed */
860 case TKIND_RECORD
: /* FIXME: mostly untested */
862 case TKIND_DISPATCH
: /* will be done in VT_USERDEFINED case */
863 case TKIND_INTERFACE
: /* will be done in VT_USERDEFINED case */
867 FIXME("unhandled switch cases tattr->typekind %d\n", tattr
->typekind
);
871 ITypeInfo_ReleaseTypeAttr(tinfo
, tattr
);
872 ITypeInfo_Release(tinfo2
);
875 if (debugout
) TRACE_(olerelay
)("*");
876 /* Write always, so the other side knows when it gets a NULL pointer.
878 cookie
= *arg
? 0x42424242 : 0;
879 hres
= xbuf_add(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
883 if (debugout
) TRACE_(olerelay
)("NULL");
886 hres
= serialize_param(tinfo
,writeit
,debugout
,dealloc
,tdesc
->u
.lptdesc
,(DWORD
*)*arg
,buf
);
887 if (derefhere
&& dealloc
) HeapFree(GetProcessHeap(),0,(LPVOID
)*arg
);
891 if (debugout
) TRACE_(olerelay
)("unk(0x%x)",*arg
);
893 hres
= _marshal_interface(buf
,&IID_IUnknown
,(LPUNKNOWN
)*arg
);
894 if (dealloc
&& *(IUnknown
**)arg
)
895 IUnknown_Release((LPUNKNOWN
)*arg
);
898 if (debugout
) TRACE_(olerelay
)("idisp(0x%x)",*arg
);
900 hres
= _marshal_interface(buf
,&IID_IDispatch
,(LPUNKNOWN
)*arg
);
901 if (dealloc
&& *(IUnknown
**)arg
)
902 IUnknown_Release((LPUNKNOWN
)*arg
);
905 if (debugout
) TRACE_(olerelay
)("<void>");
907 case VT_USERDEFINED
: {
911 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.hreftype
,&tinfo2
);
913 ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc
->u
.hreftype
);
916 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
917 switch (tattr
->typekind
) {
919 case TKIND_INTERFACE
:
921 hres
=_marshal_interface(buf
,&(tattr
->guid
),(LPUNKNOWN
)arg
);
923 IUnknown_Release((LPUNKNOWN
)arg
);
927 if (debugout
) TRACE_(olerelay
)("{");
928 for (i
=0;i
<tattr
->cVars
;i
++) {
933 hres
= ITypeInfo_GetVarDesc(tinfo2
, i
, &vdesc
);
935 ERR("Could not get vardesc of %d\n",i
);
938 elem2
= &vdesc
->elemdescVar
;
939 tdesc2
= &elem2
->tdesc
;
940 hres
= serialize_param(
946 (DWORD
*)(((LPBYTE
)arg
)+vdesc
->u
.oInst
),
949 ITypeInfo_ReleaseVarDesc(tinfo2
, vdesc
);
952 if (debugout
&& (i
<(tattr
->cVars
-1)))
953 TRACE_(olerelay
)(",");
955 if (debugout
) TRACE_(olerelay
)("}");
959 hres
= serialize_param(tinfo2
,writeit
,debugout
,dealloc
,&tattr
->tdescAlias
,arg
,buf
);
963 if (debugout
) TRACE_(olerelay
)("%x",*arg
);
965 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
968 FIXME("Unhandled typekind %d\n",tattr
->typekind
);
972 ITypeInfo_ReleaseTypeAttr(tinfo2
, tattr
);
973 ITypeInfo_Release(tinfo2
);
977 ARRAYDESC
*adesc
= tdesc
->u
.lpadesc
;
980 if (debugout
) TRACE_(olerelay
)("carr");
981 for (i
=0;i
<adesc
->cDims
;i
++) {
982 if (debugout
) TRACE_(olerelay
)("[%d]",adesc
->rgbounds
[i
].cElements
);
983 arrsize
*= adesc
->rgbounds
[i
].cElements
;
985 if (debugout
) TRACE_(olerelay
)("(vt %s)",debugstr_vt(adesc
->tdescElem
.vt
));
986 if (debugout
) TRACE_(olerelay
)("[");
987 for (i
=0;i
<arrsize
;i
++) {
988 LPBYTE base
= _passbyref(&adesc
->tdescElem
, tinfo
) ? (LPBYTE
) *arg
: (LPBYTE
) arg
;
989 hres
= serialize_param(tinfo
, writeit
, debugout
, dealloc
, &adesc
->tdescElem
, (DWORD
*)((LPBYTE
)base
+i
*_xsize(&adesc
->tdescElem
, tinfo
)), buf
);
992 if (debugout
&& (i
<arrsize
-1)) TRACE_(olerelay
)(",");
994 if (debugout
) TRACE_(olerelay
)("]");
996 HeapFree(GetProcessHeap(), 0, *(void **)arg
);
1002 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
1003 ULONG size
= LPSAFEARRAY_UserSize(&flags
, buf
->curoff
, (LPSAFEARRAY
*)arg
);
1004 xbuf_resize(buf
, size
);
1005 LPSAFEARRAY_UserMarshal(&flags
, buf
->base
+ buf
->curoff
, (LPSAFEARRAY
*)arg
);
1010 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
1011 LPSAFEARRAY_UserFree(&flags
, (LPSAFEARRAY
*)arg
);
1016 ERR("Unhandled marshal type %d.\n",tdesc
->vt
);
1031 HRESULT hres
= S_OK
;
1034 TRACE("vt %s at %p\n",debugstr_vt(tdesc
->vt
),arg
);
1036 vartype
= tdesc
->vt
;
1037 if ((vartype
& 0xf000) == VT_ARRAY
)
1038 vartype
= VT_SAFEARRAY
;
1045 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
1046 unsigned char *buffer
;
1047 buffer
= VARIANT_UserUnmarshal(&flags
, buf
->base
+ buf
->curoff
, (VARIANT
*)arg
);
1048 buf
->curoff
= buffer
- buf
->base
;
1058 hres
= xbuf_get(buf
,(LPBYTE
)arg
,8);
1059 if (hres
) ERR("Failed to read integer 8 byte\n");
1061 if (debugout
) TRACE_(olerelay
)("%x%x",arg
[0],arg
[1]);
1070 hres
= xbuf_get(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
1071 if (hres
) ERR("Failed to read integer 4 byte\n");
1073 if (debugout
) TRACE_(olerelay
)("%x",*arg
);
1080 hres
= xbuf_get(buf
,(LPBYTE
)&x
,sizeof(DWORD
));
1081 if (hres
) ERR("Failed to read integer 4 byte\n");
1084 if (debugout
) TRACE_(olerelay
)("%04x",*arg
& 0xffff);
1090 hres
= xbuf_get(buf
,(LPBYTE
)&x
,sizeof(DWORD
));
1091 if (hres
) ERR("Failed to read integer 4 byte\n");
1094 if (debugout
) TRACE_(olerelay
)("%02x",*arg
& 0xff);
1099 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
1100 unsigned char *buffer
;
1101 buffer
= BSTR_UserUnmarshal(&flags
, buf
->base
+ buf
->curoff
, (BSTR
*)arg
);
1102 buf
->curoff
= buffer
- buf
->base
;
1103 if (debugout
) TRACE_(olerelay
)("%s",debugstr_w(*(BSTR
*)arg
));
1109 BOOL derefhere
= TRUE
;
1111 if (tdesc
->u
.lptdesc
->vt
== VT_USERDEFINED
) {
1115 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.lptdesc
->u
.hreftype
,&tinfo2
);
1117 ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc
->u
.lptdesc
->u
.hreftype
);
1120 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
1121 switch (tattr
->typekind
) {
1123 if (tattr
->tdescAlias
.vt
== VT_USERDEFINED
)
1125 DWORD href
= tattr
->tdescAlias
.u
.hreftype
;
1126 ITypeInfo_ReleaseTypeAttr(tinfo
, tattr
);
1127 ITypeInfo_Release(tinfo2
);
1128 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,href
,&tinfo2
);
1130 ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc
->u
.lptdesc
->u
.hreftype
);
1133 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
1134 derefhere
= (tattr
->typekind
!= TKIND_DISPATCH
&& tattr
->typekind
!= TKIND_INTERFACE
);
1137 case TKIND_ENUM
: /* confirmed */
1138 case TKIND_RECORD
: /* FIXME: mostly untested */
1140 case TKIND_DISPATCH
: /* will be done in VT_USERDEFINED case */
1141 case TKIND_INTERFACE
: /* will be done in VT_USERDEFINED case */
1145 FIXME("unhandled switch cases tattr->typekind %d\n", tattr
->typekind
);
1149 ITypeInfo_ReleaseTypeAttr(tinfo2
, tattr
);
1150 ITypeInfo_Release(tinfo2
);
1152 /* read it in all cases, we need to know if we have
1153 * NULL pointer or not.
1155 hres
= xbuf_get(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
1157 ERR("Failed to load pointer cookie.\n");
1160 if (cookie
!= 0x42424242) {
1161 /* we read a NULL ptr from the remote side */
1162 if (debugout
) TRACE_(olerelay
)("NULL");
1166 if (debugout
) TRACE_(olerelay
)("*");
1168 /* Allocate space for the referenced struct */
1170 *arg
=(DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,_xsize(tdesc
->u
.lptdesc
, tinfo
));
1173 return deserialize_param(tinfo
, readit
, debugout
, alloc
, tdesc
->u
.lptdesc
, (LPDWORD
)*arg
, buf
);
1175 return deserialize_param(tinfo
, readit
, debugout
, alloc
, tdesc
->u
.lptdesc
, arg
, buf
);
1178 /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
1180 *arg
=(DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DWORD
));
1183 hres
= _unmarshal_interface(buf
,&IID_IUnknown
,(LPUNKNOWN
*)arg
);
1185 TRACE_(olerelay
)("unk(%p)",arg
);
1190 hres
= _unmarshal_interface(buf
,&IID_IDispatch
,(LPUNKNOWN
*)arg
);
1192 TRACE_(olerelay
)("idisp(%p)",arg
);
1195 if (debugout
) TRACE_(olerelay
)("<void>");
1197 case VT_USERDEFINED
: {
1201 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.hreftype
,&tinfo2
);
1203 ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc
->u
.hreftype
);
1206 hres
= ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
1208 ERR("Could not get typeattr in VT_USERDEFINED.\n");
1210 switch (tattr
->typekind
) {
1211 case TKIND_DISPATCH
:
1212 case TKIND_INTERFACE
:
1214 hres
= _unmarshal_interface(buf
,&(tattr
->guid
),(LPUNKNOWN
*)arg
);
1216 case TKIND_RECORD
: {
1219 if (debugout
) TRACE_(olerelay
)("{");
1220 for (i
=0;i
<tattr
->cVars
;i
++) {
1223 hres
= ITypeInfo_GetVarDesc(tinfo2
, i
, &vdesc
);
1225 ERR("Could not get vardesc of %d\n",i
);
1226 ITypeInfo_ReleaseTypeAttr(tinfo2
, tattr
);
1227 ITypeInfo_Release(tinfo2
);
1230 hres
= deserialize_param(
1235 &vdesc
->elemdescVar
.tdesc
,
1236 (DWORD
*)(((LPBYTE
)arg
)+vdesc
->u
.oInst
),
1239 ITypeInfo_ReleaseVarDesc(tinfo2
, vdesc
);
1240 if (debugout
&& (i
<tattr
->cVars
-1)) TRACE_(olerelay
)(",");
1242 if (debugout
) TRACE_(olerelay
)("}");
1246 hres
= deserialize_param(tinfo2
,readit
,debugout
,alloc
,&tattr
->tdescAlias
,arg
,buf
);
1250 hres
= xbuf_get(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
1251 if (hres
) ERR("Failed to read enum (4 byte)\n");
1253 if (debugout
) TRACE_(olerelay
)("%x",*arg
);
1256 ERR("Unhandled typekind %d\n",tattr
->typekind
);
1260 ITypeInfo_ReleaseTypeAttr(tinfo2
, tattr
);
1263 ERR("failed to stuballoc in TKIND_RECORD.\n");
1264 ITypeInfo_Release(tinfo2
);
1268 /* arg is pointing to the start of the array. */
1269 LPBYTE base
= (LPBYTE
) arg
;
1270 ARRAYDESC
*adesc
= tdesc
->u
.lpadesc
;
1273 if (adesc
->cDims
> 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
1274 for (i
=0;i
<adesc
->cDims
;i
++)
1275 arrsize
*= adesc
->rgbounds
[i
].cElements
;
1276 if (_passbyref(&adesc
->tdescElem
, tinfo
))
1278 base
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,_xsize(tdesc
->u
.lptdesc
, tinfo
) * arrsize
);
1279 *arg
= (DWORD
) base
;
1281 for (i
=0;i
<arrsize
;i
++)
1288 (DWORD
*)(base
+ i
*_xsize(&adesc
->tdescElem
, tinfo
)),
1293 case VT_SAFEARRAY
: {
1296 ULONG flags
= MAKELONG(MSHCTX_DIFFERENTMACHINE
, NDR_LOCAL_DATA_REPRESENTATION
);
1297 unsigned char *buffer
;
1298 buffer
= LPSAFEARRAY_UserUnmarshal(&flags
, buf
->base
+ buf
->curoff
, (LPSAFEARRAY
*)arg
);
1299 buf
->curoff
= buffer
- buf
->base
;
1304 ERR("No handler for VT type %d!\n",tdesc
->vt
);
1310 /* Retrieves a function's funcdesc, searching back into inherited interfaces. */
1311 static HRESULT
get_funcdesc(ITypeInfo
*tinfo
, int iMethod
, ITypeInfo
**tactual
, const FUNCDESC
**fdesc
,
1312 BSTR
*iname
, BSTR
*fname
, UINT
*num
)
1316 UINT inherited_funcs
= 0;
1319 if (fname
) *fname
= NULL
;
1320 if (iname
) *iname
= NULL
;
1324 hr
= ITypeInfo_GetTypeAttr(tinfo
, &attr
);
1327 ERR("GetTypeAttr failed with %x\n",hr
);
1331 if(attr
->typekind
== TKIND_DISPATCH
)
1333 if(attr
->wTypeFlags
& TYPEFLAG_FDUAL
)
1338 hr
= ITypeInfo_GetRefTypeOfImplType(tinfo
, -1, &href
);
1341 ERR("Cannot get interface href from dual dispinterface\n");
1342 ITypeInfo_ReleaseTypeAttr(tinfo
, attr
);
1345 hr
= ITypeInfo_GetRefTypeInfo(tinfo
, href
, &tinfo2
);
1348 ERR("Cannot get interface from dual dispinterface\n");
1349 ITypeInfo_ReleaseTypeAttr(tinfo
, attr
);
1352 hr
= get_funcdesc(tinfo2
, iMethod
, tactual
, fdesc
, iname
, fname
, num
);
1353 ITypeInfo_Release(tinfo2
);
1354 ITypeInfo_ReleaseTypeAttr(tinfo
, attr
);
1357 ERR("Shouldn't be called with a non-dual dispinterface\n");
1361 impl_types
= attr
->cImplTypes
;
1362 ITypeInfo_ReleaseTypeAttr(tinfo
, attr
);
1364 for (i
= 0; i
< impl_types
; i
++)
1367 ITypeInfo
*pSubTypeInfo
;
1370 hr
= ITypeInfo_GetRefTypeOfImplType(tinfo
, i
, &href
);
1371 if (FAILED(hr
)) return hr
;
1372 hr
= ITypeInfo_GetRefTypeInfo(tinfo
, href
, &pSubTypeInfo
);
1373 if (FAILED(hr
)) return hr
;
1375 hr
= get_funcdesc(pSubTypeInfo
, iMethod
, tactual
, fdesc
, iname
, fname
, &sub_funcs
);
1376 inherited_funcs
+= sub_funcs
;
1377 ITypeInfo_Release(pSubTypeInfo
);
1378 if(SUCCEEDED(hr
)) return hr
;
1380 if(iMethod
< inherited_funcs
)
1382 ERR("shouldn't be here\n");
1383 return E_INVALIDARG
;
1386 for(i
= inherited_funcs
; i
<= iMethod
; i
++)
1388 hr
= ITypeInfoImpl_GetInternalFuncDesc(tinfo
, i
- inherited_funcs
, fdesc
);
1396 /* found it. We don't care about num so zero it */
1399 ITypeInfo_AddRef(*tactual
);
1400 if (fname
) ITypeInfo_GetDocumentation(tinfo
,(*fdesc
)->memid
,fname
,NULL
,NULL
,NULL
);
1401 if (iname
) ITypeInfo_GetDocumentation(tinfo
,-1,iname
,NULL
,NULL
,NULL
);
1405 static inline BOOL
is_in_elem(const ELEMDESC
*elem
)
1407 return (elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
|| !elem
->u
.paramdesc
.wParamFlags
);
1410 static inline BOOL
is_out_elem(const ELEMDESC
*elem
)
1412 return (elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
|| !elem
->u
.paramdesc
.wParamFlags
);
1415 static DWORD WINAPI
xCall(int method
, void **args
)
1417 TMProxyImpl
*tpinfo
= args
[0];
1419 const FUNCDESC
*fdesc
;
1428 DWORD remoteresult
= 0;
1430 IRpcChannelBuffer
*chanbuf
;
1432 EnterCriticalSection(&tpinfo
->crit
);
1434 hres
= get_funcdesc(tpinfo
->tinfo
,method
,&tinfo
,&fdesc
,&iname
,&fname
,NULL
);
1436 ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method
);
1437 LeaveCriticalSection(&tpinfo
->crit
);
1441 if (!tpinfo
->chanbuf
)
1443 WARN("Tried to use disconnected proxy\n");
1444 ITypeInfo_Release(tinfo
);
1445 LeaveCriticalSection(&tpinfo
->crit
);
1446 return RPC_E_DISCONNECTED
;
1448 chanbuf
= tpinfo
->chanbuf
;
1449 IRpcChannelBuffer_AddRef(chanbuf
);
1451 LeaveCriticalSection(&tpinfo
->crit
);
1453 if (TRACE_ON(olerelay
)) {
1454 TRACE_(olerelay
)("->");
1456 TRACE_(olerelay
)("%s:",relaystr(iname
));
1458 TRACE_(olerelay
)("%s(%d)",relaystr(fname
),method
);
1460 TRACE_(olerelay
)("%d",method
);
1461 TRACE_(olerelay
)("(");
1464 SysFreeString(iname
);
1465 SysFreeString(fname
);
1467 memset(&buf
,0,sizeof(buf
));
1469 /* normal typelib driven serializing */
1471 /* Need them for hack below */
1472 memset(names
,0,sizeof(names
));
1473 if (ITypeInfo_GetNames(tinfo
,fdesc
->memid
,names
,sizeof(names
)/sizeof(names
[0]),&nrofnames
))
1475 if (nrofnames
> sizeof(names
)/sizeof(names
[0]))
1476 ERR("Need more names!\n");
1478 xargs
= (DWORD
*)(args
+ 1);
1479 for (i
=0;i
<fdesc
->cParams
;i
++) {
1480 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1481 if (TRACE_ON(olerelay
)) {
1482 if (i
) TRACE_(olerelay
)(",");
1483 if (i
+1<nrofnames
&& names
[i
+1])
1484 TRACE_(olerelay
)("%s=",relaystr(names
[i
+1]));
1486 /* No need to marshal other data than FIN and any VT_PTR. */
1487 if (!is_in_elem(elem
))
1489 if (elem
->tdesc
.vt
!= VT_PTR
)
1491 xargs
+=_argsize(&elem
->tdesc
, tinfo
);
1492 TRACE_(olerelay
)("[out]");
1497 memset( *(void **)xargs
, 0, _xsize( elem
->tdesc
.u
.lptdesc
, tinfo
) );
1501 hres
= serialize_param(
1512 ERR("Failed to serialize param, hres %x\n",hres
);
1515 xargs
+=_argsize(&elem
->tdesc
, tinfo
);
1517 TRACE_(olerelay
)(")");
1519 memset(&msg
,0,sizeof(msg
));
1520 msg
.cbBuffer
= buf
.curoff
;
1521 msg
.iMethod
= method
;
1522 hres
= IRpcChannelBuffer_GetBuffer(chanbuf
,&msg
,&(tpinfo
->iid
));
1524 ERR("RpcChannelBuffer GetBuffer failed, %x\n",hres
);
1527 memcpy(msg
.Buffer
,buf
.base
,buf
.curoff
);
1528 TRACE_(olerelay
)("\n");
1529 hres
= IRpcChannelBuffer_SendReceive(chanbuf
,&msg
,&status
);
1531 ERR("RpcChannelBuffer SendReceive failed, %x\n",hres
);
1535 TRACE_(olerelay
)(" status = %08x (",status
);
1537 buf
.base
= HeapReAlloc(GetProcessHeap(),0,buf
.base
,msg
.cbBuffer
);
1539 buf
.base
= HeapAlloc(GetProcessHeap(),0,msg
.cbBuffer
);
1540 buf
.size
= msg
.cbBuffer
;
1541 memcpy(buf
.base
,msg
.Buffer
,buf
.size
);
1544 /* generic deserializer using typelib description */
1545 xargs
= (DWORD
*)(args
+ 1);
1547 for (i
=0;i
<fdesc
->cParams
;i
++) {
1548 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1550 if (i
) TRACE_(olerelay
)(",");
1551 if (i
+1<nrofnames
&& names
[i
+1]) TRACE_(olerelay
)("%s=",relaystr(names
[i
+1]));
1553 /* No need to marshal other data than FOUT and any VT_PTR */
1554 if (!is_out_elem(elem
) && (elem
->tdesc
.vt
!= VT_PTR
)) {
1555 xargs
+= _argsize(&elem
->tdesc
, tinfo
);
1556 TRACE_(olerelay
)("[in]");
1559 hres
= deserialize_param(
1569 ERR("Failed to unmarshall param, hres %x\n",hres
);
1573 xargs
+= _argsize(&elem
->tdesc
, tinfo
);
1576 hres
= xbuf_get(&buf
, (LPBYTE
)&remoteresult
, sizeof(DWORD
));
1579 TRACE_(olerelay
)(") = %08x\n", remoteresult
);
1581 hres
= remoteresult
;
1584 IRpcChannelBuffer_FreeBuffer(chanbuf
,&msg
);
1585 for (i
= 0; i
< nrofnames
; i
++)
1586 SysFreeString(names
[i
]);
1587 HeapFree(GetProcessHeap(),0,buf
.base
);
1588 IRpcChannelBuffer_Release(chanbuf
);
1589 ITypeInfo_Release(tinfo
);
1590 TRACE("-- 0x%08x\n", hres
);
1594 static HRESULT WINAPI
ProxyIUnknown_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
1596 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1598 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
1600 if (proxy
->outerunknown
)
1601 return IUnknown_QueryInterface(proxy
->outerunknown
, riid
, ppv
);
1603 FIXME("No interface\n");
1604 return E_NOINTERFACE
;
1607 static ULONG WINAPI
ProxyIUnknown_AddRef(IUnknown
*iface
)
1609 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1613 if (proxy
->outerunknown
)
1614 return IUnknown_AddRef(proxy
->outerunknown
);
1616 return 2; /* FIXME */
1619 static ULONG WINAPI
ProxyIUnknown_Release(IUnknown
*iface
)
1621 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1625 if (proxy
->outerunknown
)
1626 return IUnknown_Release(proxy
->outerunknown
);
1628 return 1; /* FIXME */
1631 static HRESULT WINAPI
ProxyIDispatch_GetTypeInfoCount(LPDISPATCH iface
, UINT
* pctinfo
)
1633 TMProxyImpl
*This
= (TMProxyImpl
*)iface
;
1635 TRACE("(%p)\n", pctinfo
);
1637 return IDispatch_GetTypeInfoCount(This
->dispatch
, pctinfo
);
1640 static HRESULT WINAPI
ProxyIDispatch_GetTypeInfo(LPDISPATCH iface
, UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
1642 TMProxyImpl
*This
= (TMProxyImpl
*)iface
;
1644 TRACE("(%d, %x, %p)\n", iTInfo
, lcid
, ppTInfo
);
1646 return IDispatch_GetTypeInfo(This
->dispatch
, iTInfo
, lcid
, ppTInfo
);
1649 static HRESULT WINAPI
ProxyIDispatch_GetIDsOfNames(LPDISPATCH iface
, REFIID riid
, LPOLESTR
* rgszNames
, UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
1651 TMProxyImpl
*This
= (TMProxyImpl
*)iface
;
1653 TRACE("(%s, %p, %d, 0x%x, %p)\n", debugstr_guid(riid
), rgszNames
, cNames
, lcid
, rgDispId
);
1655 return IDispatch_GetIDsOfNames(This
->dispatch
, riid
, rgszNames
,
1656 cNames
, lcid
, rgDispId
);
1659 static HRESULT WINAPI
ProxyIDispatch_Invoke(LPDISPATCH iface
, DISPID dispIdMember
, REFIID riid
, LCID lcid
,
1660 WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
,
1661 EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
1663 TMProxyImpl
*This
= (TMProxyImpl
*)iface
;
1665 TRACE("(%d, %s, 0x%x, 0x%x, %p, %p, %p, %p)\n", dispIdMember
,
1666 debugstr_guid(riid
), lcid
, wFlags
, pDispParams
, pVarResult
,
1667 pExcepInfo
, puArgErr
);
1669 return IDispatch_Invoke(This
->dispatch
, dispIdMember
, riid
, lcid
,
1670 wFlags
, pDispParams
, pVarResult
, pExcepInfo
,
1676 IRpcChannelBuffer IRpcChannelBuffer_iface
;
1678 /* the IDispatch-derived interface we are handling */
1680 IRpcChannelBuffer
*pDelegateChannel
;
1681 } TMarshalDispatchChannel
;
1683 static inline TMarshalDispatchChannel
*impl_from_IRpcChannelBuffer(IRpcChannelBuffer
*iface
)
1685 return CONTAINING_RECORD(iface
, TMarshalDispatchChannel
, IRpcChannelBuffer_iface
);
1688 static HRESULT WINAPI
TMarshalDispatchChannel_QueryInterface(IRpcChannelBuffer
*iface
, REFIID riid
, LPVOID
*ppv
)
1691 if (IsEqualIID(riid
,&IID_IRpcChannelBuffer
) || IsEqualIID(riid
,&IID_IUnknown
))
1694 IRpcChannelBuffer_AddRef(iface
);
1697 return E_NOINTERFACE
;
1700 static ULONG WINAPI
TMarshalDispatchChannel_AddRef(LPRPCCHANNELBUFFER iface
)
1702 TMarshalDispatchChannel
*This
= impl_from_IRpcChannelBuffer(iface
);
1703 return InterlockedIncrement(&This
->refs
);
1706 static ULONG WINAPI
TMarshalDispatchChannel_Release(LPRPCCHANNELBUFFER iface
)
1708 TMarshalDispatchChannel
*This
= impl_from_IRpcChannelBuffer(iface
);
1711 ref
= InterlockedDecrement(&This
->refs
);
1715 IRpcChannelBuffer_Release(This
->pDelegateChannel
);
1716 HeapFree(GetProcessHeap(), 0, This
);
1720 static HRESULT WINAPI
TMarshalDispatchChannel_GetBuffer(LPRPCCHANNELBUFFER iface
, RPCOLEMESSAGE
* olemsg
, REFIID riid
)
1722 TMarshalDispatchChannel
*This
= impl_from_IRpcChannelBuffer(iface
);
1723 TRACE("(%p, %s)\n", olemsg
, debugstr_guid(riid
));
1724 /* Note: we are pretending to invoke a method on the interface identified
1725 * by tmarshal_iid so that we can re-use the IDispatch proxy/stub code
1726 * without the RPC runtime getting confused by not exporting an IDispatch interface */
1727 return IRpcChannelBuffer_GetBuffer(This
->pDelegateChannel
, olemsg
, &This
->tmarshal_iid
);
1730 static HRESULT WINAPI
TMarshalDispatchChannel_SendReceive(LPRPCCHANNELBUFFER iface
, RPCOLEMESSAGE
*olemsg
, ULONG
*pstatus
)
1732 TMarshalDispatchChannel
*This
= impl_from_IRpcChannelBuffer(iface
);
1733 TRACE("(%p, %p)\n", olemsg
, pstatus
);
1734 return IRpcChannelBuffer_SendReceive(This
->pDelegateChannel
, olemsg
, pstatus
);
1737 static HRESULT WINAPI
TMarshalDispatchChannel_FreeBuffer(LPRPCCHANNELBUFFER iface
, RPCOLEMESSAGE
* olemsg
)
1739 TMarshalDispatchChannel
*This
= impl_from_IRpcChannelBuffer(iface
);
1740 TRACE("(%p)\n", olemsg
);
1741 return IRpcChannelBuffer_FreeBuffer(This
->pDelegateChannel
, olemsg
);
1744 static HRESULT WINAPI
TMarshalDispatchChannel_GetDestCtx(LPRPCCHANNELBUFFER iface
, DWORD
* pdwDestContext
, void** ppvDestContext
)
1746 TMarshalDispatchChannel
*This
= impl_from_IRpcChannelBuffer(iface
);
1747 TRACE("(%p,%p)\n", pdwDestContext
, ppvDestContext
);
1748 return IRpcChannelBuffer_GetDestCtx(This
->pDelegateChannel
, pdwDestContext
, ppvDestContext
);
1751 static HRESULT WINAPI
TMarshalDispatchChannel_IsConnected(LPRPCCHANNELBUFFER iface
)
1753 TMarshalDispatchChannel
*This
= impl_from_IRpcChannelBuffer(iface
);
1755 return IRpcChannelBuffer_IsConnected(This
->pDelegateChannel
);
1758 static const IRpcChannelBufferVtbl TMarshalDispatchChannelVtbl
=
1760 TMarshalDispatchChannel_QueryInterface
,
1761 TMarshalDispatchChannel_AddRef
,
1762 TMarshalDispatchChannel_Release
,
1763 TMarshalDispatchChannel_GetBuffer
,
1764 TMarshalDispatchChannel_SendReceive
,
1765 TMarshalDispatchChannel_FreeBuffer
,
1766 TMarshalDispatchChannel_GetDestCtx
,
1767 TMarshalDispatchChannel_IsConnected
1770 static HRESULT
TMarshalDispatchChannel_Create(
1771 IRpcChannelBuffer
*pDelegateChannel
, REFIID tmarshal_riid
,
1772 IRpcChannelBuffer
**ppChannel
)
1774 TMarshalDispatchChannel
*This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
1776 return E_OUTOFMEMORY
;
1778 This
->IRpcChannelBuffer_iface
.lpVtbl
= &TMarshalDispatchChannelVtbl
;
1780 IRpcChannelBuffer_AddRef(pDelegateChannel
);
1781 This
->pDelegateChannel
= pDelegateChannel
;
1782 This
->tmarshal_iid
= *tmarshal_riid
;
1784 *ppChannel
= &This
->IRpcChannelBuffer_iface
;
1789 static inline HRESULT
get_facbuf_for_iid(REFIID riid
, IPSFactoryBuffer
**facbuf
)
1794 if ((hr
= CoGetPSClsid(riid
, &clsid
)))
1796 return CoGetClassObject(&clsid
, CLSCTX_INPROC_SERVER
, NULL
,
1797 &IID_IPSFactoryBuffer
, (LPVOID
*)facbuf
);
1800 static HRESULT
init_proxy_entry_point(TMProxyImpl
*proxy
, unsigned int num
)
1803 /* nrofargs including This */
1806 TMAsmProxy
*xasm
= proxy
->asmstubs
+ num
;
1808 const FUNCDESC
*fdesc
;
1810 hres
= get_funcdesc(proxy
->tinfo
, num
, &tinfo2
, &fdesc
, NULL
, NULL
, NULL
);
1812 ERR("GetFuncDesc %x should not fail here.\n",hres
);
1815 ITypeInfo_Release(tinfo2
);
1816 /* some args take more than 4 byte on the stack */
1817 for (j
=0;j
<fdesc
->cParams
;j
++)
1818 nrofargs
+= _argsize(&fdesc
->lprgelemdescParam
[j
].tdesc
, proxy
->tinfo
);
1821 if (fdesc
->callconv
!= CC_STDCALL
) {
1822 ERR("calling convention is not stdcall????\n");
1825 /* leal 4(%esp),%eax
1831 xasm
->lealeax
= 0x0424448d;
1832 xasm
->pushleax
= 0x50;
1833 xasm
->pushlval
= 0x68;
1836 xasm
->xcall
= (char *)xCall
- (char *)&xasm
->lret
;
1838 xasm
->bytestopop
= nrofargs
* 4;
1840 proxy
->lpvtbl
[fdesc
->oVft
/ sizeof(void *)] = xasm
;
1842 FIXME("not implemented on non i386\n");
1848 static HRESULT WINAPI
1849 PSFacBuf_CreateProxy(
1850 LPPSFACTORYBUFFER iface
, IUnknown
* pUnkOuter
, REFIID riid
,
1851 IRpcProxyBuffer
**ppProxy
, LPVOID
*ppv
)
1855 unsigned int i
, nroffuncs
, vtbl_size
;
1858 BOOL defer_to_dispatch
= FALSE
;
1860 TRACE("(...%s...)\n",debugstr_guid(riid
));
1861 hres
= _get_typeinfo_for_iid(riid
,&tinfo
);
1863 ERR("No typeinfo for %s?\n",debugstr_guid(riid
));
1867 hres
= num_of_funcs(tinfo
, &nroffuncs
, &vtbl_size
);
1868 TRACE("Got %d funcs, vtbl size %d\n", nroffuncs
, vtbl_size
);
1871 ERR("Cannot get number of functions for typeinfo %s\n",debugstr_guid(riid
));
1872 ITypeInfo_Release(tinfo
);
1876 proxy
= CoTaskMemAlloc(sizeof(TMProxyImpl
));
1877 if (!proxy
) return E_OUTOFMEMORY
;
1879 proxy
->dispatch
= NULL
;
1880 proxy
->dispatch_proxy
= NULL
;
1881 proxy
->outerunknown
= pUnkOuter
;
1882 proxy
->asmstubs
= VirtualAlloc(NULL
, sizeof(TMAsmProxy
) * nroffuncs
, MEM_COMMIT
, PAGE_EXECUTE_READWRITE
);
1883 if (!proxy
->asmstubs
) {
1884 ERR("Could not commit pages for proxy thunks\n");
1885 CoTaskMemFree(proxy
);
1886 return E_OUTOFMEMORY
;
1888 proxy
->IRpcProxyBuffer_iface
.lpVtbl
= &tmproxyvtable
;
1889 /* one reference for the proxy */
1891 proxy
->tinfo
= tinfo
;
1895 InitializeCriticalSection(&proxy
->crit
);
1896 proxy
->crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": TMProxyImpl.crit");
1898 proxy
->lpvtbl
= HeapAlloc(GetProcessHeap(), 0, vtbl_size
);
1900 /* if we derive from IDispatch then defer to its proxy for its methods */
1901 hres
= ITypeInfo_GetTypeAttr(tinfo
, &typeattr
);
1904 if (typeattr
->wTypeFlags
& TYPEFLAG_FDISPATCHABLE
)
1906 IPSFactoryBuffer
*factory_buffer
;
1907 hres
= get_facbuf_for_iid(&IID_IDispatch
, &factory_buffer
);
1910 hres
= IPSFactoryBuffer_CreateProxy(factory_buffer
, NULL
,
1911 &IID_IDispatch
, &proxy
->dispatch_proxy
,
1912 (void **)&proxy
->dispatch
);
1913 IPSFactoryBuffer_Release(factory_buffer
);
1915 if ((hres
== S_OK
) && (nroffuncs
< 7))
1917 ERR("nroffuncs calculated incorrectly (%d)\n", nroffuncs
);
1918 hres
= E_UNEXPECTED
;
1922 defer_to_dispatch
= TRUE
;
1925 ITypeInfo_ReleaseTypeAttr(tinfo
, typeattr
);
1928 for (i
=0;i
<nroffuncs
;i
++) {
1931 proxy
->lpvtbl
[i
] = ProxyIUnknown_QueryInterface
;
1934 proxy
->lpvtbl
[i
] = ProxyIUnknown_AddRef
;
1937 proxy
->lpvtbl
[i
] = ProxyIUnknown_Release
;
1940 if(!defer_to_dispatch
) hres
= init_proxy_entry_point(proxy
, i
);
1941 else proxy
->lpvtbl
[3] = ProxyIDispatch_GetTypeInfoCount
;
1944 if(!defer_to_dispatch
) hres
= init_proxy_entry_point(proxy
, i
);
1945 else proxy
->lpvtbl
[4] = ProxyIDispatch_GetTypeInfo
;
1948 if(!defer_to_dispatch
) hres
= init_proxy_entry_point(proxy
, i
);
1949 else proxy
->lpvtbl
[5] = ProxyIDispatch_GetIDsOfNames
;
1952 if(!defer_to_dispatch
) hres
= init_proxy_entry_point(proxy
, i
);
1953 else proxy
->lpvtbl
[6] = ProxyIDispatch_Invoke
;
1956 hres
= init_proxy_entry_point(proxy
, i
);
1963 *ppProxy
= &proxy
->IRpcProxyBuffer_iface
;
1964 IUnknown_AddRef((IUnknown
*)*ppv
);
1968 TMProxyImpl_Release(&proxy
->IRpcProxyBuffer_iface
);
1972 typedef struct _TMStubImpl
{
1973 IRpcStubBuffer IRpcStubBuffer_iface
;
1979 IRpcStubBuffer
*dispatch_stub
;
1980 BOOL dispatch_derivative
;
1983 static inline TMStubImpl
*impl_from_IRpcStubBuffer(IRpcStubBuffer
*iface
)
1985 return CONTAINING_RECORD(iface
, TMStubImpl
, IRpcStubBuffer_iface
);
1988 static HRESULT WINAPI
1989 TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface
, REFIID riid
, LPVOID
*ppv
)
1991 if (IsEqualIID(riid
,&IID_IRpcStubBuffer
)||IsEqualIID(riid
,&IID_IUnknown
)){
1993 IRpcStubBuffer_AddRef(iface
);
1996 FIXME("%s, not supported IID.\n",debugstr_guid(riid
));
1997 return E_NOINTERFACE
;
2001 TMStubImpl_AddRef(LPRPCSTUBBUFFER iface
)
2003 TMStubImpl
*This
= impl_from_IRpcStubBuffer(iface
);
2004 ULONG refCount
= InterlockedIncrement(&This
->ref
);
2006 TRACE("(%p)->(ref before=%u)\n", This
, refCount
- 1);
2012 TMStubImpl_Release(LPRPCSTUBBUFFER iface
)
2014 TMStubImpl
*This
= impl_from_IRpcStubBuffer(iface
);
2015 ULONG refCount
= InterlockedDecrement(&This
->ref
);
2017 TRACE("(%p)->(ref before=%u)\n", This
, refCount
+ 1);
2021 IRpcStubBuffer_Disconnect(iface
);
2022 ITypeInfo_Release(This
->tinfo
);
2023 if (This
->dispatch_stub
)
2024 IRpcStubBuffer_Release(This
->dispatch_stub
);
2025 CoTaskMemFree(This
);
2030 static HRESULT WINAPI
2031 TMStubImpl_Connect(LPRPCSTUBBUFFER iface
, LPUNKNOWN pUnkServer
)
2033 TMStubImpl
*This
= impl_from_IRpcStubBuffer(iface
);
2035 TRACE("(%p)->(%p)\n", This
, pUnkServer
);
2037 IUnknown_AddRef(pUnkServer
);
2038 This
->pUnk
= pUnkServer
;
2040 if (This
->dispatch_stub
)
2041 IRpcStubBuffer_Connect(This
->dispatch_stub
, pUnkServer
);
2047 TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface
)
2049 TMStubImpl
*This
= impl_from_IRpcStubBuffer(iface
);
2051 TRACE("(%p)->()\n", This
);
2055 IUnknown_Release(This
->pUnk
);
2059 if (This
->dispatch_stub
)
2060 IRpcStubBuffer_Disconnect(This
->dispatch_stub
);
2063 static HRESULT WINAPI
2065 LPRPCSTUBBUFFER iface
, RPCOLEMESSAGE
* xmsg
,IRpcChannelBuffer
*rpcchanbuf
)
2069 const FUNCDESC
*fdesc
;
2070 TMStubImpl
*This
= impl_from_IRpcStubBuffer(iface
);
2072 DWORD
*args
= NULL
, res
, *xargs
, nrofargs
;
2077 ITypeInfo
*tinfo
= NULL
;
2081 if (xmsg
->iMethod
< 3) {
2082 ERR("IUnknown methods cannot be marshaled by the typelib marshaler\n");
2083 return E_UNEXPECTED
;
2086 if (This
->dispatch_derivative
&& xmsg
->iMethod
< sizeof(IDispatchVtbl
)/sizeof(void *))
2088 if (!This
->dispatch_stub
)
2090 IPSFactoryBuffer
*factory_buffer
;
2091 hres
= get_facbuf_for_iid(&IID_IDispatch
, &factory_buffer
);
2094 hres
= IPSFactoryBuffer_CreateStub(factory_buffer
, &IID_IDispatch
,
2095 This
->pUnk
, &This
->dispatch_stub
);
2096 IPSFactoryBuffer_Release(factory_buffer
);
2101 return IRpcStubBuffer_Invoke(This
->dispatch_stub
, xmsg
, rpcchanbuf
);
2104 memset(&buf
,0,sizeof(buf
));
2105 buf
.size
= xmsg
->cbBuffer
;
2106 buf
.base
= HeapAlloc(GetProcessHeap(), 0, xmsg
->cbBuffer
);
2107 memcpy(buf
.base
, xmsg
->Buffer
, xmsg
->cbBuffer
);
2110 hres
= get_funcdesc(This
->tinfo
,xmsg
->iMethod
,&tinfo
,&fdesc
,&iname
,NULL
,NULL
);
2112 ERR("GetFuncDesc on method %d failed with %x\n",xmsg
->iMethod
,hres
);
2116 if (iname
&& !lstrcmpW(iname
, IDispatchW
))
2118 ERR("IDispatch cannot be marshaled by the typelib marshaler\n");
2119 hres
= E_UNEXPECTED
;
2120 SysFreeString (iname
);
2124 SysFreeString (iname
);
2126 /* Need them for hack below */
2127 memset(names
,0,sizeof(names
));
2128 ITypeInfo_GetNames(tinfo
,fdesc
->memid
,names
,sizeof(names
)/sizeof(names
[0]),&nrofnames
);
2129 if (nrofnames
> sizeof(names
)/sizeof(names
[0])) {
2130 ERR("Need more names!\n");
2133 /*dump_FUNCDESC(fdesc);*/
2135 for (i
=0;i
<fdesc
->cParams
;i
++)
2136 nrofargs
+= _argsize(&fdesc
->lprgelemdescParam
[i
].tdesc
, tinfo
);
2137 args
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,(nrofargs
+1)*sizeof(DWORD
));
2140 hres
= E_OUTOFMEMORY
;
2144 /* Allocate all stuff used by call. */
2146 for (i
=0;i
<fdesc
->cParams
;i
++) {
2147 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
2149 hres
= deserialize_param(
2158 xargs
+= _argsize(&elem
->tdesc
, tinfo
);
2160 ERR("Failed to deserialize param %s, hres %x\n",relaystr(names
[i
+1]),hres
);
2165 args
[0] = (DWORD
)This
->pUnk
;
2170 (*((FARPROC
**)args
[0]))[fdesc
->oVft
/4],
2178 DWORD dwExceptionCode
= GetExceptionCode();
2179 ERR("invoke call failed with exception 0x%08x (%d)\n", dwExceptionCode
, dwExceptionCode
);
2180 if (FAILED(dwExceptionCode
))
2181 hres
= dwExceptionCode
;
2183 hres
= HRESULT_FROM_WIN32(dwExceptionCode
);
2193 for (i
=0;i
<fdesc
->cParams
;i
++) {
2194 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
2195 hres
= serialize_param(
2204 xargs
+= _argsize(&elem
->tdesc
, tinfo
);
2206 ERR("Failed to stuballoc param, hres %x\n",hres
);
2211 hres
= xbuf_add (&buf
, (LPBYTE
)&res
, sizeof(DWORD
));
2216 xmsg
->cbBuffer
= buf
.curoff
;
2217 hres
= IRpcChannelBuffer_GetBuffer(rpcchanbuf
, xmsg
, &This
->iid
);
2219 ERR("IRpcChannelBuffer_GetBuffer failed with error 0x%08x\n", hres
);
2222 memcpy(xmsg
->Buffer
, buf
.base
, buf
.curoff
);
2225 for (i
= 0; i
< nrofnames
; i
++)
2226 SysFreeString(names
[i
]);
2228 ITypeInfo_Release(tinfo
);
2229 HeapFree(GetProcessHeap(), 0, args
);
2231 HeapFree(GetProcessHeap(), 0, buf
.base
);
2233 TRACE("returning\n");
2236 FIXME( "not implemented on non-i386\n" );
2241 static LPRPCSTUBBUFFER WINAPI
2242 TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface
, REFIID riid
) {
2243 FIXME("Huh (%s)?\n",debugstr_guid(riid
));
2248 TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface
) {
2249 TMStubImpl
*This
= impl_from_IRpcStubBuffer(iface
);
2252 return This
->ref
; /*FIXME? */
2255 static HRESULT WINAPI
2256 TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface
, LPVOID
*ppv
) {
2261 TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface
, LPVOID ppv
) {
2265 static const IRpcStubBufferVtbl tmstubvtbl
= {
2266 TMStubImpl_QueryInterface
,
2270 TMStubImpl_Disconnect
,
2272 TMStubImpl_IsIIDSupported
,
2273 TMStubImpl_CountRefs
,
2274 TMStubImpl_DebugServerQueryInterface
,
2275 TMStubImpl_DebugServerRelease
2278 static HRESULT WINAPI
2279 PSFacBuf_CreateStub(
2280 LPPSFACTORYBUFFER iface
, REFIID riid
,IUnknown
*pUnkServer
,
2281 IRpcStubBuffer
** ppStub
2289 TRACE("(%s,%p,%p)\n",debugstr_guid(riid
),pUnkServer
,ppStub
);
2291 hres
= _get_typeinfo_for_iid(riid
,&tinfo
);
2293 ERR("No typeinfo for %s?\n",debugstr_guid(riid
));
2297 /* FIXME: This is not exactly right. We should probably call QI later. */
2298 hres
= IUnknown_QueryInterface(pUnkServer
, riid
, (void**)&obj
);
2300 WARN("Could not get %s iface: %08x\n", debugstr_guid(riid
), hres
);
2302 IUnknown_AddRef(obj
);
2305 stub
= CoTaskMemAlloc(sizeof(TMStubImpl
));
2307 IUnknown_Release(obj
);
2308 return E_OUTOFMEMORY
;
2310 stub
->IRpcStubBuffer_iface
.lpVtbl
= &tmstubvtbl
;
2312 stub
->tinfo
= tinfo
;
2313 stub
->dispatch_stub
= NULL
;
2314 stub
->dispatch_derivative
= FALSE
;
2316 hres
= IRpcStubBuffer_Connect(&stub
->IRpcStubBuffer_iface
, obj
);
2317 *ppStub
= &stub
->IRpcStubBuffer_iface
;
2318 TRACE("IRpcStubBuffer: %p\n", stub
);
2320 ERR("Connect to pUnkServer failed?\n");
2322 /* if we derive from IDispatch then defer to its stub for some of its methods */
2323 hres
= ITypeInfo_GetTypeAttr(tinfo
, &typeattr
);
2326 if (typeattr
->wTypeFlags
& TYPEFLAG_FDISPATCHABLE
)
2327 stub
->dispatch_derivative
= TRUE
;
2328 ITypeInfo_ReleaseTypeAttr(tinfo
, typeattr
);
2331 IUnknown_Release(obj
);
2335 static const IPSFactoryBufferVtbl psfacbufvtbl
= {
2336 PSFacBuf_QueryInterface
,
2339 PSFacBuf_CreateProxy
,
2343 static IPSFactoryBuffer psfac
= { &psfacbufvtbl
};
2345 /***********************************************************************
2346 * TMARSHAL_DllGetClassObject
2348 HRESULT
TMARSHAL_DllGetClassObject(REFCLSID rclsid
, REFIID iid
, void **ppv
)
2350 return IPSFactoryBuffer_QueryInterface(&psfac
, iid
, ppv
);