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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #define NONAMELESSUNION
35 #define NONAMELESSSTRUCT
46 #include "wine/debug.h"
48 static const WCHAR riidW
[5] = {'r','i','i','d',0};
49 static const WCHAR pdispparamsW
[] = {'p','d','i','s','p','p','a','r','a','m','s',0};
50 static const WCHAR ppvObjectW
[] = {'p','p','v','O','b','j','e','c','t',0};
51 static const WCHAR IDispatchW
[] = { 'I','D','i','s','p','a','t','c','h',0};
52 static const WCHAR GetIDsOfNamesW
[] = { 'G','e','t','I','D','s','O','f','N','a','m','e','s',0};
54 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
55 WINE_DECLARE_DEBUG_CHANNEL(olerelay
);
57 #define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
59 typedef struct _marshal_state
{
65 IID iid
; /* HACK: for VT_VOID */
68 /* used in the olerelay code to avoid having the L"" stuff added by debugstr_w */
69 static char *relaystr(WCHAR
*in
) {
70 char *tmp
= (char *)debugstr_w(in
);
72 tmp
[strlen(tmp
)-1] = '\0';
77 xbuf_add(marshal_state
*buf
, LPBYTE stuff
, DWORD size
) {
78 while (buf
->size
- buf
->curoff
< size
) {
81 buf
->base
= HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,buf
->base
,buf
->size
);
85 buf
->base
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,32);
91 memcpy(buf
->base
+buf
->curoff
,stuff
,size
);
97 xbuf_get(marshal_state
*buf
, LPBYTE stuff
, DWORD size
) {
98 if (buf
->size
< buf
->curoff
+size
) return E_FAIL
;
99 memcpy(stuff
,buf
->base
+buf
->curoff
,size
);
105 xbuf_skip(marshal_state
*buf
, DWORD size
) {
106 if (buf
->size
< buf
->curoff
+size
) return E_FAIL
;
112 _unmarshal_interface(marshal_state
*buf
, REFIID riid
, LPUNKNOWN
*pUnk
) {
114 ULARGE_INTEGER newpos
;
115 LARGE_INTEGER seekto
;
120 TRACE("...%s...\n",debugstr_guid(riid
));
123 hres
= xbuf_get(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
125 ERR("xbuf_get failed\n");
129 if (xsize
== 0) return S_OK
;
131 hres
= CreateStreamOnHGlobal(0,TRUE
,&pStm
);
133 ERR("Stream create failed %lx\n",hres
);
137 hres
= IStream_Write(pStm
,buf
->base
+buf
->curoff
,xsize
,&res
);
139 ERR("stream write %lx\n",hres
);
143 memset(&seekto
,0,sizeof(seekto
));
144 hres
= IStream_Seek(pStm
,seekto
,SEEK_SET
,&newpos
);
146 ERR("Failed Seek %lx\n",hres
);
150 hres
= CoUnmarshalInterface(pStm
,riid
,(LPVOID
*)pUnk
);
152 ERR("Unmarshalling interface %s failed with %lx\n",debugstr_guid(riid
),hres
);
156 IStream_Release(pStm
);
157 return xbuf_skip(buf
,xsize
);
161 _marshal_interface(marshal_state
*buf
, REFIID riid
, LPUNKNOWN pUnk
) {
162 LPBYTE tempbuf
= NULL
;
163 IStream
*pStm
= NULL
;
165 ULARGE_INTEGER newpos
;
166 LARGE_INTEGER seekto
;
172 /* this is valid, if for instance we serialize
173 * a VT_DISPATCH with NULL ptr which apparently
174 * can happen. S_OK to make sure we continue
177 ERR("pUnk is NULL?\n");
179 return xbuf_add(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
184 TRACE("...%s...\n",debugstr_guid(riid
));
186 hres
= CreateStreamOnHGlobal(0,TRUE
,&pStm
);
188 ERR("Stream create failed %lx\n",hres
);
192 hres
= CoMarshalInterface(pStm
,riid
,pUnk
,0,NULL
,0);
194 ERR("Marshalling interface %s failed with %lx\n", debugstr_guid(riid
), hres
);
198 hres
= IStream_Stat(pStm
,&ststg
,0);
200 ERR("Stream stat failed\n");
204 tempbuf
= HeapAlloc(GetProcessHeap(), 0, ststg
.cbSize
.u
.LowPart
);
205 memset(&seekto
,0,sizeof(seekto
));
206 hres
= IStream_Seek(pStm
,seekto
,SEEK_SET
,&newpos
);
208 ERR("Failed Seek %lx\n",hres
);
212 hres
= IStream_Read(pStm
,tempbuf
,ststg
.cbSize
.u
.LowPart
,&res
);
214 ERR("Failed Read %lx\n",hres
);
218 xsize
= ststg
.cbSize
.u
.LowPart
;
219 xbuf_add(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
220 hres
= xbuf_add(buf
,tempbuf
,ststg
.cbSize
.u
.LowPart
);
222 HeapFree(GetProcessHeap(),0,tempbuf
);
223 IStream_Release(pStm
);
229 xbuf_add(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
230 if (pStm
) IUnknown_Release(pStm
);
231 HeapFree(GetProcessHeap(), 0, tempbuf
);
235 /********************* OLE Proxy/Stub Factory ********************************/
236 static HRESULT WINAPI
237 PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface
, REFIID iid
, LPVOID
*ppv
) {
238 if (IsEqualIID(iid
,&IID_IPSFactoryBuffer
)||IsEqualIID(iid
,&IID_IUnknown
)) {
239 *ppv
= (LPVOID
)iface
;
240 /* No ref counting, static class */
243 FIXME("(%s) unknown IID?\n",debugstr_guid(iid
));
244 return E_NOINTERFACE
;
247 static ULONG WINAPI
PSFacBuf_AddRef(LPPSFACTORYBUFFER iface
) { return 2; }
248 static ULONG WINAPI
PSFacBuf_Release(LPPSFACTORYBUFFER iface
) { return 1; }
251 _get_typeinfo_for_iid(REFIID riid
, ITypeInfo
**ti
) {
254 char tlguid
[200],typelibkey
[300],interfacekey
[300],ver
[100];
257 DWORD tlguidlen
, verlen
, type
;
261 sprintf( interfacekey
, "Interface\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\Typelib",
262 riid
->Data1
, riid
->Data2
, riid
->Data3
,
263 riid
->Data4
[0], riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3],
264 riid
->Data4
[4], riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]
267 if (RegOpenKeyA(HKEY_CLASSES_ROOT
,interfacekey
,&ikey
)) {
268 ERR("No %s key found.\n",interfacekey
);
272 tlguidlen
= sizeof(tlguid
);
273 if (RegQueryValueExA(ikey
,NULL
,NULL
,&type
,(LPBYTE
)tlguid
,&tlguidlen
)) {
274 ERR("Getting typelib guid failed.\n");
279 verlen
= sizeof(ver
);
280 if (RegQueryValueExA(ikey
,"Version",NULL
,&type
,(LPBYTE
)ver
,&verlen
)) {
281 ERR("Could not get version value?\n");
286 sprintf(typelibkey
,"Typelib\\%s\\%s\\0\\win32",tlguid
,ver
);
287 tlfnlen
= sizeof(tlfn
);
288 if (RegQueryValueA(HKEY_CLASSES_ROOT
,typelibkey
,tlfn
,&tlfnlen
)) {
289 ERR("Could not get typelib fn?\n");
292 MultiByteToWideChar(CP_ACP
, 0, tlfn
, -1, tlfnW
, -1);
293 hres
= LoadTypeLib(tlfnW
,&tl
);
295 ERR("Failed to load typelib for %s, but it should be there.\n",debugstr_guid(riid
));
298 hres
= ITypeLib_GetTypeInfoOfGuid(tl
,riid
,ti
);
300 ERR("typelib does not contain info for %s?\n",debugstr_guid(riid
));
301 ITypeLib_Release(tl
);
304 /* FIXME: do this? ITypeLib_Release(tl); */
308 /* Determine nr of functions. Since we use the toplevel interface and all
309 * inherited ones have lower numbers, we are ok to not to descent into
310 * the inheritance tree I think.
312 static int _nroffuncs(ITypeInfo
*tinfo
) {
319 hres
= ITypeInfo_GetFuncDesc(tinfo
,n
,&fdesc
);
322 if (fdesc
->oVft
/4 > max
)
331 #include "pshpack1.h"
333 typedef struct _TMAsmProxy
{
347 # error You need to implement stubless proxies for your architecture
350 typedef struct _TMProxyImpl
{
352 const IRpcProxyBufferVtbl
*lpvtbl2
;
355 TMAsmProxy
*asmstubs
;
357 IRpcChannelBuffer
* chanbuf
;
359 CRITICAL_SECTION crit
;
360 IUnknown
*outerunknown
;
363 static HRESULT WINAPI
364 TMProxyImpl_QueryInterface(LPRPCPROXYBUFFER iface
, REFIID riid
, LPVOID
*ppv
)
367 if (IsEqualIID(riid
,&IID_IUnknown
)||IsEqualIID(riid
,&IID_IRpcProxyBuffer
)) {
368 *ppv
= (LPVOID
)iface
;
369 IRpcProxyBuffer_AddRef(iface
);
372 FIXME("no interface for %s\n",debugstr_guid(riid
));
373 return E_NOINTERFACE
;
377 TMProxyImpl_AddRef(LPRPCPROXYBUFFER iface
)
379 ICOM_THIS_MULTI(TMProxyImpl
,lpvtbl2
,iface
);
380 ULONG refCount
= InterlockedIncrement(&This
->ref
);
382 TRACE("(%p)->(ref before=%lu)\n",This
, refCount
- 1);
388 TMProxyImpl_Release(LPRPCPROXYBUFFER iface
)
390 ICOM_THIS_MULTI(TMProxyImpl
,lpvtbl2
,iface
);
391 ULONG refCount
= InterlockedDecrement(&This
->ref
);
393 TRACE("(%p)->(ref before=%lu)\n",This
, refCount
+ 1);
397 DeleteCriticalSection(&This
->crit
);
398 if (This
->chanbuf
) IRpcChannelBuffer_Release(This
->chanbuf
);
399 VirtualFree(This
->asmstubs
, 0, MEM_RELEASE
);
405 static HRESULT WINAPI
407 LPRPCPROXYBUFFER iface
,IRpcChannelBuffer
* pRpcChannelBuffer
)
409 ICOM_THIS_MULTI(TMProxyImpl
, lpvtbl2
, iface
);
411 TRACE("(%p)\n", pRpcChannelBuffer
);
413 EnterCriticalSection(&This
->crit
);
415 IRpcChannelBuffer_AddRef(pRpcChannelBuffer
);
416 This
->chanbuf
= pRpcChannelBuffer
;
418 LeaveCriticalSection(&This
->crit
);
424 TMProxyImpl_Disconnect(LPRPCPROXYBUFFER iface
)
426 ICOM_THIS_MULTI(TMProxyImpl
, lpvtbl2
, iface
);
430 EnterCriticalSection(&This
->crit
);
432 IRpcChannelBuffer_Release(This
->chanbuf
);
433 This
->chanbuf
= NULL
;
435 LeaveCriticalSection(&This
->crit
);
439 static const IRpcProxyBufferVtbl tmproxyvtable
= {
440 TMProxyImpl_QueryInterface
,
444 TMProxyImpl_Disconnect
447 /* how much space do we use on stack in DWORD steps. */
452 return sizeof(double)/sizeof(DWORD
);
454 return sizeof(CY
)/sizeof(DWORD
);
456 return sizeof(DATE
)/sizeof(DWORD
);
458 return (sizeof(VARIANT
)+3)/sizeof(DWORD
);
465 _xsize(TYPEDESC
*td
) {
470 return sizeof(VARIANT
)+3;
473 ARRAYDESC
*adesc
= td
->u
.lpadesc
;
475 for (i
=0;i
<adesc
->cDims
;i
++)
476 arrsize
*= adesc
->rgbounds
[i
].cElements
;
477 return arrsize
*_xsize(&adesc
->tdescElem
);
502 TRACE("(tdesc.vt %d)\n",tdesc
->vt
);
505 case VT_EMPTY
: /* nothing. empty variant for instance */
514 if (debugout
) TRACE_(olerelay
)("%lx",*arg
);
516 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
521 if (debugout
) TRACE_(olerelay
)("%04lx",*arg
& 0xffff);
523 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
528 if (debugout
) TRACE_(olerelay
)("%02lx",*arg
& 0xff);
530 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
534 if (debugout
) TRACE_(olerelay
)("&0x%lx",*arg
);
536 hres
= xbuf_add(buf
,(LPBYTE
)(DWORD
*)*arg
,sizeof(DWORD
));
537 /* do not dealloc at this time */
541 VARIANT
*vt
= (VARIANT
*)arg
;
542 DWORD vttype
= V_VT(vt
);
544 if (debugout
) TRACE_(olerelay
)("Vt(%ld)(",vttype
);
547 hres
= xbuf_add(buf
,(LPBYTE
)&vttype
,sizeof(vttype
));
548 if (hres
) return hres
;
550 /* need to recurse since we need to free the stuff */
551 hres
= serialize_param(tinfo
,writeit
,debugout
,dealloc
,&tdesc2
,(DWORD
*)&(V_I4(vt
)),buf
);
552 if (debugout
) TRACE_(olerelay
)(")");
555 case VT_BSTR
|VT_BYREF
: {
556 if (debugout
) TRACE_(olerelay
)("[byref]'%s'", *(BSTR
*)*arg
? relaystr(*((BSTR
*)*arg
)) : "<bstr NULL>");
558 /* ptr to ptr to magic widestring, basically */
559 BSTR
*bstr
= (BSTR
*) *arg
;
562 /* -1 means "null string" which is equivalent to empty string */
564 hres
= xbuf_add(buf
, (LPBYTE
)&len
,sizeof(DWORD
));
565 if (hres
) return hres
;
567 len
= *((DWORD
*)*bstr
-1)/sizeof(WCHAR
);
568 hres
= xbuf_add(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
569 if (hres
) return hres
;
570 hres
= xbuf_add(buf
,(LPBYTE
)*bstr
,len
* sizeof(WCHAR
));
571 if (hres
) return hres
;
575 if (dealloc
&& arg
) {
576 BSTR
*str
= *((BSTR
**)arg
);
585 TRACE_(olerelay
)("%s",relaystr((WCHAR
*)*arg
));
587 TRACE_(olerelay
)("<bstr NULL>");
590 BSTR bstr
= (BSTR
)*arg
;
594 hres
= xbuf_add(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
595 if (hres
) return hres
;
597 len
= *((DWORD
*)bstr
-1)/sizeof(WCHAR
);
598 hres
= xbuf_add(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
599 if (hres
) return hres
;
600 hres
= xbuf_add(buf
,(LPBYTE
)bstr
,len
* sizeof(WCHAR
));
601 if (hres
) return hres
;
606 SysFreeString((BSTR
)*arg
);
613 derefhere
= (tdesc
->u
.lptdesc
->vt
!= VT_USERDEFINED
);
615 if (debugout
) TRACE_(olerelay
)("*");
616 /* Write always, so the other side knows when it gets a NULL pointer.
618 cookie
= *arg
? 0x42424242 : 0;
619 hres
= xbuf_add(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
623 if (debugout
) TRACE_(olerelay
)("NULL");
626 hres
= serialize_param(tinfo
,writeit
,debugout
,dealloc
,tdesc
->u
.lptdesc
,(DWORD
*)*arg
,buf
);
627 if (derefhere
&& dealloc
) HeapFree(GetProcessHeap(),0,(LPVOID
)*arg
);
631 if (debugout
) TRACE_(olerelay
)("unk(0x%lx)",*arg
);
633 hres
= _marshal_interface(buf
,&IID_IUnknown
,(LPUNKNOWN
)*arg
);
636 if (debugout
) TRACE_(olerelay
)("idisp(0x%lx)",*arg
);
638 hres
= _marshal_interface(buf
,&IID_IDispatch
,(LPUNKNOWN
)*arg
);
641 if (debugout
) TRACE_(olerelay
)("<void>");
643 case VT_USERDEFINED
: {
647 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.hreftype
,&tinfo2
);
649 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc
->u
.hreftype
);
652 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
653 switch (tattr
->typekind
) {
655 case TKIND_INTERFACE
:
657 hres
=_marshal_interface(buf
,&(tattr
->guid
),(LPUNKNOWN
)arg
);
659 IUnknown_Release((LPUNKNOWN
)arg
);
663 if (debugout
) TRACE_(olerelay
)("{");
664 for (i
=0;i
<tattr
->cVars
;i
++) {
669 hres
= ITypeInfo2_GetVarDesc(tinfo2
, i
, &vdesc
);
671 ERR("Could not get vardesc of %d\n",i
);
674 /* Need them for hack below */
676 memset(names,0,sizeof(names));
677 hres = ITypeInfo_GetNames(tinfo2,vdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
678 if (nrofnames > sizeof(names)/sizeof(names[0])) {
679 ERR("Need more names!\n");
681 if (!hres && debugout)
682 TRACE_(olerelay)("%s=",relaystr(names[0]));
684 elem2
= &vdesc
->elemdescVar
;
685 tdesc2
= &elem2
->tdesc
;
686 hres
= serialize_param(
692 (DWORD
*)(((LPBYTE
)arg
)+vdesc
->u
.oInst
),
695 ITypeInfo_ReleaseVarDesc(tinfo2
, vdesc
);
698 if (debugout
&& (i
<(tattr
->cVars
-1)))
699 TRACE_(olerelay
)(",");
701 if (buf
->thisisiid
&& (tattr
->cbSizeInstance
==sizeof(GUID
)))
702 memcpy(&(buf
->iid
),arg
,sizeof(buf
->iid
));
703 if (debugout
) TRACE_(olerelay
)("}");
707 return serialize_param(tinfo2
,writeit
,debugout
,dealloc
,&tattr
->tdescAlias
,arg
,buf
);
710 if (debugout
) TRACE_(olerelay
)("%lx",*arg
);
712 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
715 FIXME("Unhandled typekind %d\n",tattr
->typekind
);
719 ITypeInfo_Release(tinfo2
);
723 ARRAYDESC
*adesc
= tdesc
->u
.lpadesc
;
726 if (debugout
) TRACE_(olerelay
)("carr");
727 for (i
=0;i
<adesc
->cDims
;i
++) {
728 if (debugout
) TRACE_(olerelay
)("[%ld]",adesc
->rgbounds
[i
].cElements
);
729 arrsize
*= adesc
->rgbounds
[i
].cElements
;
731 if (debugout
) TRACE_(olerelay
)("(vt %d)",adesc
->tdescElem
.vt
);
732 if (debugout
) TRACE_(olerelay
)("[");
733 for (i
=0;i
<arrsize
;i
++) {
734 hres
= serialize_param(tinfo
, writeit
, debugout
, dealloc
, &adesc
->tdescElem
, (DWORD
*)((LPBYTE
)arg
+i
*_xsize(&adesc
->tdescElem
)), buf
);
737 if (debugout
&& (i
<arrsize
-1)) TRACE_(olerelay
)(",");
739 if (debugout
) TRACE_(olerelay
)("]");
743 ERR("Unhandled marshal type %d.\n",tdesc
->vt
);
749 * HRESULT GetIDsOfNames(
750 * [in] REFIID riid, args[1]
751 * [in, size_is(cNames)] LPOLESTR *rgszNames, args[2]
752 * [in] UINT cNames, args[3]
753 * [in] LCID lcid, args[4]
754 * [out, size_is(cNames)] DISPID *rgDispId); args[5]
759 * LPOLESTR rgszNames[cNames];
760 * DWORD bytestrlen (incl 0)
761 * BYTE data[bytestrlen] (incl 0)
765 serialize_IDispatch_GetIDsOfNames(
772 DWORD cNames
= args
[2];
773 LPOLESTR
*rgszNames
= (LPOLESTR
*)args
[1];
777 if (debugout
) TRACE_(olerelay
)("riid=%s,",debugstr_guid((REFIID
)args
[0]));
778 hres
= xbuf_add(buf
, (LPBYTE
)args
[0], sizeof(IID
));
780 FIXME("serialize of IID failed.\n");
783 if (debugout
) TRACE_(olerelay
)("cNames=%ld,",cNames
);
784 hres
= xbuf_add(buf
, (LPBYTE
)&cNames
, sizeof(DWORD
));
786 FIXME("serialize of cNames failed.\n");
789 if (debugout
) TRACE_(olerelay
)("rgszNames=[");
790 for (i
=0;i
<cNames
;i
++) {
791 DWORD len
= 2*(lstrlenW(rgszNames
[i
])+1);
793 if (debugout
) TRACE_(olerelay
)("%s,",relaystr(rgszNames
[i
]));
794 hres
= xbuf_add(buf
, (LPBYTE
)&len
, sizeof(DWORD
));
796 FIXME("serialize of len failed.\n");
799 hres
= xbuf_add(buf
, (LPBYTE
)rgszNames
[i
], len
);
801 FIXME("serialize of rgszNames[i] failed.\n");
805 if (debugout
) TRACE_(olerelay
)("],lcid=%04lx)",args
[3]);
806 hres
= xbuf_add(buf
, (LPBYTE
)&args
[3], sizeof(DWORD
));
808 FIXME("serialize of lcid failed.\n");
812 DISPID
*rgDispId
= (DISPID
*)args
[4];
814 hres
= xbuf_add(buf
, (LPBYTE
)rgDispId
, sizeof(DISPID
) * cNames
);
816 FIXME("serialize of rgDispId failed.\n");
820 TRACE_(olerelay
)("riid=[in],rgszNames=[in],cNames=[in],rgDispId=[");
821 for (i
=0;i
<cNames
;i
++)
822 TRACE_(olerelay
)("%08lx,",rgDispId
[i
]);
823 TRACE_(olerelay
)("])");
825 HeapFree(GetProcessHeap(),0,(IID
*)args
[0]);
826 rgszNames
= (LPOLESTR
*)args
[1];
827 for (i
=0;i
<cNames
;i
++) HeapFree(GetProcessHeap(),0,rgszNames
[i
]);
828 HeapFree(GetProcessHeap(),0,rgszNames
);
829 HeapFree(GetProcessHeap(),0,rgDispId
);
835 deserialize_IDispatch_GetIDsOfNames(
847 args
[0] = (DWORD
)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IID
));
848 if (!args
[0]) return E_FAIL
;
849 hres
= xbuf_get(buf
, (LPBYTE
)args
[0], sizeof(IID
));
851 FIXME("deserialize of IID failed.\n");
854 if (debugout
) TRACE_(olerelay
)("riid=%s,",debugstr_guid((REFIID
)args
[0]));
856 hres
= xbuf_get(buf
, (LPBYTE
)&cNames
, sizeof(DWORD
));
858 FIXME("deserialize of cNames failed.\n");
862 if (debugout
) TRACE_(olerelay
)("cNames=%ld,",cNames
);
863 if (debugout
) TRACE_(olerelay
)("rgszNames=[");
864 rgszNames
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(LPOLESTR
) * cNames
);
865 if (!rgszNames
) return E_FAIL
;
866 args
[1] = (DWORD
)rgszNames
;
867 for (i
=0;i
<cNames
;i
++) {
870 hres
= xbuf_get(buf
, (LPBYTE
)&len
, sizeof(DWORD
));
872 FIXME("serialize of len failed.\n");
875 rgszNames
[i
] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
877 FIXME("heapalloc of %ld bytes failed\n", len
);
880 hres
= xbuf_get(buf
, (LPBYTE
)rgszNames
[i
], len
);
882 FIXME("serialize of rgszNames[i] failed.\n");
885 if (debugout
) TRACE_(olerelay
)("%s,",relaystr(rgszNames
[i
]));
887 hres
= xbuf_get(buf
, (LPBYTE
)&args
[3], sizeof(DWORD
));
889 FIXME("deserialize of lcid failed.\n");
892 if (debugout
) TRACE_(olerelay
)("],lcid=%04lx,rgDispId=[out])",args
[3]);
893 args
[4] = (DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DISPID
) * cNames
);
895 hres
= xbuf_get(buf
, (LPBYTE
)args
[4], sizeof(DISPID
) * args
[2]);
897 FIXME("serialize of rgDispId failed.\n");
901 TRACE_(olerelay
)("dispid=[");
902 for (i
=0;i
<args
[2];i
++)
903 TRACE_(olerelay
)("%08lx,",((DISPID
*)args
[4])[i
]);
904 TRACE_(olerelay
)("])");
911 serialize_LPVOID_ptr(
923 if ((tdesc
->vt
!= VT_PTR
) ||
924 (tdesc
->u
.lptdesc
->vt
!= VT_PTR
) ||
925 (tdesc
->u
.lptdesc
->u
.lptdesc
->vt
!= VT_VOID
)
927 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
930 cookie
= (*(DWORD
*)*arg
) ? 0x42424242: 0x0;
932 hres
= xbuf_add(buf
, (LPVOID
)&cookie
, sizeof(cookie
));
936 if (!*(DWORD
*)*arg
) {
937 if (debugout
) TRACE_(olerelay
)("<lpvoid NULL>");
941 TRACE_(olerelay
)("ppv(%p)",*(LPUNKNOWN
*)*arg
);
943 hres
= _marshal_interface(buf
,&(buf
->iid
),*(LPUNKNOWN
*)*arg
);
948 HeapFree(GetProcessHeap(),0,(LPVOID
)*arg
);
953 serialize_DISPPARAM_ptr(
967 if ((tdesc
->vt
!= VT_PTR
) || (tdesc
->u
.lptdesc
->vt
!= VT_USERDEFINED
)) {
968 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
972 cookie
= *arg
? 0x42424242 : 0x0;
974 hres
= xbuf_add(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
979 if (debugout
) TRACE_(olerelay
)("<DISPPARAMS NULL>");
982 disp
= (DISPPARAMS
*)*arg
;
984 hres
= xbuf_add(buf
,(LPBYTE
)&disp
->cArgs
,sizeof(disp
->cArgs
));
988 if (debugout
) TRACE_(olerelay
)("D{");
989 for (i
=0;i
<disp
->cArgs
;i
++) {
992 vtdesc
.vt
= VT_VARIANT
;
999 (DWORD
*)(disp
->rgvarg
+i
),
1002 if (debugout
&& (i
<disp
->cArgs
-1))
1003 TRACE_(olerelay
)(",");
1006 HeapFree(GetProcessHeap(),0,disp
->rgvarg
);
1008 hres
= xbuf_add(buf
,(LPBYTE
)&disp
->cNamedArgs
,sizeof(disp
->cNamedArgs
));
1012 if (debugout
) TRACE_(olerelay
)("}{");
1013 for (i
=0;i
<disp
->cNamedArgs
;i
++) {
1016 vtdesc
.vt
= VT_UINT
;
1023 (DWORD
*)(disp
->rgdispidNamedArgs
+i
),
1026 if (debugout
&& (i
<disp
->cNamedArgs
-1))
1027 TRACE_(olerelay
)(",");
1029 if (debugout
) TRACE_(olerelay
)("}");
1031 HeapFree(GetProcessHeap(),0,disp
->rgdispidNamedArgs
);
1032 HeapFree(GetProcessHeap(),0,disp
);
1047 HRESULT hres
= S_OK
;
1049 TRACE("vt %d at %p\n",tdesc
->vt
,arg
);
1052 switch (tdesc
->vt
) {
1054 if (debugout
) TRACE_(olerelay
)("<empty>");
1057 if (debugout
) TRACE_(olerelay
)("<null>");
1060 VARIANT
*vt
= (VARIANT
*)arg
;
1065 hres
= xbuf_get(buf
,(LPBYTE
)&vttype
,sizeof(vttype
));
1067 FIXME("vt type not read?\n");
1070 memset(&tdesc2
,0,sizeof(tdesc2
));
1073 if (debugout
) TRACE_(olerelay
)("Vt(%ld)(",vttype
);
1074 hres
= deserialize_param(tinfo
, readit
, debugout
, alloc
, &tdesc2
, (DWORD
*)&(V_I4(vt
)), buf
);
1075 TRACE_(olerelay
)(")");
1089 hres
= xbuf_get(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
1090 if (hres
) ERR("Failed to read integer 4 byte\n");
1092 if (debugout
) TRACE_(olerelay
)("%lx",*arg
);
1098 hres
= xbuf_get(buf
,(LPBYTE
)&x
,sizeof(DWORD
));
1099 if (hres
) ERR("Failed to read integer 4 byte\n");
1102 if (debugout
) TRACE_(olerelay
)("%04lx",*arg
& 0xffff);
1108 hres
= xbuf_get(buf
,(LPBYTE
)&x
,sizeof(DWORD
));
1109 if (hres
) ERR("Failed to read integer 4 byte\n");
1112 if (debugout
) TRACE_(olerelay
)("%02lx",*arg
& 0xff);
1114 case VT_I4
|VT_BYREF
:
1117 *arg
= (DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DWORD
));
1119 hres
= xbuf_get(buf
,(LPBYTE
)*arg
,sizeof(DWORD
));
1120 if (hres
) ERR("Failed to read integer 4 byte\n");
1122 if (debugout
) TRACE_(olerelay
)("&0x%lx",*(DWORD
*)*arg
);
1124 case VT_BSTR
|VT_BYREF
: {
1125 BSTR
**bstr
= (BSTR
**)arg
;
1130 hres
= xbuf_get(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
1132 ERR("failed to read bstr klen\n");
1136 *bstr
= CoTaskMemAlloc(sizeof(BSTR
*));
1138 if (debugout
) TRACE_(olerelay
)("<bstr NULL>");
1140 str
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,(len
+1)*sizeof(WCHAR
));
1141 hres
= xbuf_get(buf
,(LPBYTE
)str
,len
*sizeof(WCHAR
));
1143 ERR("Failed to read BSTR.\n");
1146 *bstr
= CoTaskMemAlloc(sizeof(BSTR
*));
1147 **bstr
= SysAllocStringLen(str
,len
);
1148 if (debugout
) TRACE_(olerelay
)("%s",relaystr(str
));
1149 HeapFree(GetProcessHeap(),0,str
);
1161 hres
= xbuf_get(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
1163 ERR("failed to read bstr klen\n");
1168 if (debugout
) TRACE_(olerelay
)("<bstr NULL>");
1170 str
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,(len
+1)*sizeof(WCHAR
));
1171 hres
= xbuf_get(buf
,(LPBYTE
)str
,len
*sizeof(WCHAR
));
1173 ERR("Failed to read BSTR.\n");
1176 *arg
= (DWORD
)SysAllocStringLen(str
,len
);
1177 if (debugout
) TRACE_(olerelay
)("%s",relaystr(str
));
1178 HeapFree(GetProcessHeap(),0,str
);
1189 derefhere
= (tdesc
->u
.lptdesc
->vt
!= VT_USERDEFINED
);
1190 /* read it in all cases, we need to know if we have
1191 * NULL pointer or not.
1193 hres
= xbuf_get(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
1195 ERR("Failed to load pointer cookie.\n");
1198 if (cookie
!= 0x42424242) {
1199 /* we read a NULL ptr from the remote side */
1200 if (debugout
) TRACE_(olerelay
)("NULL");
1204 if (debugout
) TRACE_(olerelay
)("*");
1206 /* Allocate space for the referenced struct */
1208 *arg
=(DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,_xsize(tdesc
->u
.lptdesc
));
1211 return deserialize_param(tinfo
, readit
, debugout
, alloc
, tdesc
->u
.lptdesc
, (LPDWORD
)*arg
, buf
);
1213 return deserialize_param(tinfo
, readit
, debugout
, alloc
, tdesc
->u
.lptdesc
, arg
, buf
);
1216 /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
1218 *arg
=(DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DWORD
));
1221 hres
= _unmarshal_interface(buf
,&IID_IUnknown
,(LPUNKNOWN
*)arg
);
1223 TRACE_(olerelay
)("unk(%p)",arg
);
1228 hres
= _unmarshal_interface(buf
,&IID_IDispatch
,(LPUNKNOWN
*)arg
);
1230 TRACE_(olerelay
)("idisp(%p)",arg
);
1233 if (debugout
) TRACE_(olerelay
)("<void>");
1235 case VT_USERDEFINED
: {
1239 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.hreftype
,&tinfo2
);
1241 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc
->u
.hreftype
);
1244 hres
= ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
1246 ERR("Could not get typeattr in VT_USERDEFINED.\n");
1248 switch (tattr
->typekind
) {
1249 case TKIND_DISPATCH
:
1250 case TKIND_INTERFACE
:
1252 hres
= _unmarshal_interface(buf
,&(tattr
->guid
),(LPUNKNOWN
*)arg
);
1254 case TKIND_RECORD
: {
1258 *arg
= (DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,tattr
->cbSizeInstance
);
1260 if (debugout
) TRACE_(olerelay
)("{");
1261 for (i
=0;i
<tattr
->cVars
;i
++) {
1264 hres
= ITypeInfo2_GetVarDesc(tinfo2
, i
, &vdesc
);
1266 ERR("Could not get vardesc of %d\n",i
);
1269 hres
= deserialize_param(
1274 &vdesc
->elemdescVar
.tdesc
,
1275 (DWORD
*)(((LPBYTE
)*arg
)+vdesc
->u
.oInst
),
1278 if (debugout
&& (i
<tattr
->cVars
-1)) TRACE_(olerelay
)(",");
1280 if (buf
->thisisiid
&& (tattr
->cbSizeInstance
==sizeof(GUID
)))
1281 memcpy(&(buf
->iid
),(LPBYTE
)*arg
,sizeof(buf
->iid
));
1282 if (debugout
) TRACE_(olerelay
)("}");
1286 return deserialize_param(tinfo2
,readit
,debugout
,alloc
,&tattr
->tdescAlias
,arg
,buf
);
1289 hres
= xbuf_get(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
1290 if (hres
) ERR("Failed to read enum (4 byte)\n");
1292 if (debugout
) TRACE_(olerelay
)("%lx",*arg
);
1295 ERR("Unhandled typekind %d\n",tattr
->typekind
);
1301 ERR("failed to stuballoc in TKIND_RECORD.\n");
1302 ITypeInfo_Release(tinfo2
);
1306 /* arg is pointing to the start of the array. */
1307 ARRAYDESC
*adesc
= tdesc
->u
.lpadesc
;
1310 if (adesc
->cDims
> 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
1311 for (i
=0;i
<adesc
->cDims
;i
++)
1312 arrsize
*= adesc
->rgbounds
[i
].cElements
;
1313 for (i
=0;i
<arrsize
;i
++)
1320 (DWORD
*)((LPBYTE
)(arg
)+i
*_xsize(&adesc
->tdescElem
)),
1326 ERR("No handler for VT type %d!\n",tdesc
->vt
);
1333 deserialize_LPVOID_ptr(
1345 if ((tdesc
->vt
!= VT_PTR
) ||
1346 (tdesc
->u
.lptdesc
->vt
!= VT_PTR
) ||
1347 (tdesc
->u
.lptdesc
->u
.lptdesc
->vt
!= VT_VOID
)
1349 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
1353 *arg
=(DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(LPVOID
));
1355 hres
= xbuf_get(buf
, (LPVOID
)&cookie
, sizeof(cookie
));
1358 if (cookie
!= 0x42424242) {
1360 if (debugout
) TRACE_(olerelay
)("<lpvoid NULL>");
1365 hres
= _unmarshal_interface(buf
,&buf
->iid
,(LPUNKNOWN
*)*arg
);
1367 FIXME("_unmarshal_interface of %s , %p failed with %lx\n", debugstr_guid(&buf
->iid
), (LPUNKNOWN
*)*arg
, hres
);
1371 if (debugout
) TRACE_(olerelay
)("ppv(%p)",(LPVOID
)*arg
);
1376 deserialize_DISPPARAM_ptr(
1390 if ((tdesc
->vt
!= VT_PTR
) || (tdesc
->u
.lptdesc
->vt
!= VT_USERDEFINED
)) {
1391 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
1395 hres
= xbuf_get(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
1400 if (debugout
) TRACE_(olerelay
)("<DISPPARAMS NULL>");
1405 *arg
= (DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DISPPARAMS
));
1406 disps
= (DISPPARAMS
*)*arg
;
1409 hres
= xbuf_get(buf
, (LPBYTE
)&disps
->cArgs
, sizeof(disps
->cArgs
));
1413 disps
->rgvarg
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(VARIANT
)*disps
->cArgs
);
1414 if (debugout
) TRACE_(olerelay
)("D{");
1415 for (i
=0; i
< disps
->cArgs
; i
++) {
1418 vdesc
.vt
= VT_VARIANT
;
1419 hres
= deserialize_param(
1425 (DWORD
*)(disps
->rgvarg
+i
),
1429 if (debugout
) TRACE_(olerelay
)("}{");
1430 hres
= xbuf_get(buf
, (LPBYTE
)&disps
->cNamedArgs
, sizeof(disps
->cNamedArgs
));
1433 if (disps
->cNamedArgs
) {
1435 disps
->rgdispidNamedArgs
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DISPID
)*disps
->cNamedArgs
);
1436 for (i
=0; i
< disps
->cNamedArgs
; i
++) {
1440 hres
= deserialize_param(
1446 (DWORD
*)(disps
->rgdispidNamedArgs
+i
),
1449 if (debugout
&& i
<(disps
->cNamedArgs
-1)) TRACE_(olerelay
)(",");
1452 if (debugout
) TRACE_(olerelay
)("}");
1456 /* Searches function, also in inherited interfaces */
1459 ITypeInfo
*tinfo
, int iMethod
, ITypeInfo
**tactual
, FUNCDESC
**fdesc
, BSTR
*iname
, BSTR
*fname
)
1464 if (fname
) *fname
= NULL
;
1465 if (iname
) *iname
= NULL
;
1468 ITypeInfo_AddRef(*tactual
);
1471 hres
= ITypeInfo_GetFuncDesc(tinfo
, i
, fdesc
);
1477 hres
= ITypeInfo_GetTypeAttr(tinfo
, &attr
);
1479 ERR("GetTypeAttr failed with %lx\n",hres
);
1482 /* Not found, so look in inherited ifaces. */
1483 for (j
=0;j
<attr
->cImplTypes
;j
++) {
1484 hres
= ITypeInfo_GetRefTypeOfImplType(tinfo
, j
, &href
);
1486 ERR("Did not find a reftype for interface offset %d?\n",j
);
1489 hres
= ITypeInfo_GetRefTypeInfo(tinfo
, href
, &tinfo2
);
1491 ERR("Did not find a typeinfo for reftype %ld?\n",href
);
1494 hres
= _get_funcdesc(tinfo2
,iMethod
,tactual
,fdesc
,iname
,fname
);
1495 ITypeInfo_Release(tinfo2
);
1496 if (!hres
) return S_OK
;
1500 if (((*fdesc
)->oVft
/4) == iMethod
) {
1502 ITypeInfo_GetDocumentation(tinfo
,(*fdesc
)->memid
,fname
,NULL
,NULL
,NULL
);
1504 ITypeInfo_GetDocumentation(tinfo
,-1,iname
,NULL
,NULL
,NULL
);
1512 xCall(LPVOID retptr
, int method
, TMProxyImpl
*tpinfo
/*, args */)
1514 DWORD
*args
= ((DWORD
*)&tpinfo
)+1, *xargs
;
1517 int i
, relaydeb
= TRACE_ON(olerelay
);
1524 int is_idispatch_getidsofnames
= 0;
1525 DWORD remoteresult
= 0;
1528 EnterCriticalSection(&tpinfo
->crit
);
1530 hres
= _get_funcdesc(tpinfo
->tinfo
,method
,&tinfo
,&fdesc
,&iname
,&fname
);
1532 ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method
);
1533 ITypeInfo_Release(tinfo
);
1534 LeaveCriticalSection(&tpinfo
->crit
);
1538 if (!tpinfo
->chanbuf
)
1540 WARN("Tried to use disconnected proxy\n");
1541 ITypeInfo_Release(tinfo
);
1542 LeaveCriticalSection(&tpinfo
->crit
);
1543 return RPC_E_DISCONNECTED
;
1547 TRACE_(olerelay
)("->");
1549 TRACE_(olerelay
)("%s:",relaystr(iname
));
1551 TRACE_(olerelay
)("%s(%d)",relaystr(fname
),method
);
1553 TRACE_(olerelay
)("%d",method
);
1554 TRACE_(olerelay
)("(");
1556 if (iname
&& fname
&& !lstrcmpW(iname
,IDispatchW
) && !lstrcmpW(fname
,GetIDsOfNamesW
))
1557 is_idispatch_getidsofnames
= 1;
1559 if (iname
) SysFreeString(iname
);
1560 if (fname
) SysFreeString(fname
);
1562 memset(&buf
,0,sizeof(buf
));
1563 buf
.iid
= IID_IUnknown
;
1565 /* Special IDispatch::GetIDsOfNames() serializer */
1566 if (is_idispatch_getidsofnames
) {
1567 hres
= serialize_IDispatch_GetIDsOfNames(TRUE
,relaydeb
,args
,&buf
);
1569 FIXME("serialize of IDispatch::GetIDsOfNames failed!\n");
1570 ITypeInfo_Release(tinfo
);
1571 LeaveCriticalSection(&tpinfo
->crit
);
1574 goto afterserialize
;
1577 /* special QueryInterface serialize */
1579 xbuf_add(&buf
,(LPBYTE
)args
[0],sizeof(IID
));
1580 if (relaydeb
) TRACE_(olerelay
)("riid=%s,[out])",debugstr_guid((REFIID
)args
[0]));
1581 goto afterserialize
;
1584 /* normal typelib driven serializing */
1586 /* Need them for hack below */
1587 memset(names
,0,sizeof(names
));
1588 if (ITypeInfo_GetNames(tinfo
,fdesc
->memid
,names
,sizeof(names
)/sizeof(names
[0]),&nrofnames
))
1590 if (nrofnames
> sizeof(names
)/sizeof(names
[0]))
1591 ERR("Need more names!\n");
1594 for (i
=0;i
<fdesc
->cParams
;i
++) {
1595 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1596 BOOL isserialized
= FALSE
;
1598 if (i
) TRACE_(olerelay
)(",");
1599 if (i
+1<nrofnames
&& names
[i
+1])
1600 TRACE_(olerelay
)("%s=",relaystr(names
[i
+1]));
1602 /* No need to marshal other data than FIN and any VT_PTR. */
1603 if (!(elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
) && (elem
->tdesc
.vt
!= VT_PTR
)) {
1604 xargs
+=_argsize(elem
->tdesc
.vt
);
1605 if (relaydeb
) TRACE_(olerelay
)("[out]");
1608 if (((i
+1)<nrofnames
) && !IsBadStringPtrW(names
[i
+1],1)) {
1609 /* If the parameter is 'riid', we use it as interface IID
1610 * for a later ppvObject serialization.
1612 buf
.thisisiid
= !lstrcmpW(names
[i
+1],riidW
);
1614 /* DISPPARAMS* needs special serializer */
1615 if (!lstrcmpW(names
[i
+1],pdispparamsW
)) {
1616 hres
= serialize_DISPPARAM_ptr(
1618 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
1625 isserialized
= TRUE
;
1627 if (!lstrcmpW(names
[i
+1],ppvObjectW
)) {
1628 hres
= serialize_LPVOID_ptr(
1630 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
1638 isserialized
= TRUE
;
1642 hres
= serialize_param(
1644 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
1653 ERR("Failed to serialize param, hres %lx\n",hres
);
1656 xargs
+=_argsize(elem
->tdesc
.vt
);
1658 if (relaydeb
) TRACE_(olerelay
)(")");
1661 memset(&msg
,0,sizeof(msg
));
1662 msg
.cbBuffer
= buf
.curoff
;
1663 msg
.iMethod
= method
;
1664 hres
= IRpcChannelBuffer_GetBuffer(tpinfo
->chanbuf
,&msg
,&(tpinfo
->iid
));
1666 ERR("RpcChannelBuffer GetBuffer failed, %lx\n",hres
);
1667 LeaveCriticalSection(&tpinfo
->crit
);
1670 memcpy(msg
.Buffer
,buf
.base
,buf
.curoff
);
1671 if (relaydeb
) TRACE_(olerelay
)("\n");
1672 hres
= IRpcChannelBuffer_SendReceive(tpinfo
->chanbuf
,&msg
,&status
);
1674 ERR("RpcChannelBuffer SendReceive failed, %lx\n",hres
);
1675 LeaveCriticalSection(&tpinfo
->crit
);
1679 if (relaydeb
) TRACE_(olerelay
)(" status = %08lx (",status
);
1681 buf
.base
= HeapReAlloc(GetProcessHeap(),0,buf
.base
,msg
.cbBuffer
);
1683 buf
.base
= HeapAlloc(GetProcessHeap(),0,msg
.cbBuffer
);
1684 buf
.size
= msg
.cbBuffer
;
1685 memcpy(buf
.base
,msg
.Buffer
,buf
.size
);
1688 /* Special IDispatch::GetIDsOfNames() deserializer */
1689 if (is_idispatch_getidsofnames
) {
1690 hres
= deserialize_IDispatch_GetIDsOfNames(FALSE
,relaydeb
,args
,&buf
);
1692 FIXME("deserialize of IDispatch::GetIDsOfNames failed!\n");
1695 goto after_deserialize
;
1697 /* Special QueryInterface deserializer */
1699 _unmarshal_interface(&buf
,(REFIID
)args
[0],(LPUNKNOWN
*)args
[1]);
1700 if (relaydeb
) TRACE_(olerelay
)("[in],%p",*((DWORD
**)args
[1]));
1701 goto after_deserialize
;
1704 /* generic deserializer using typelib description */
1707 for (i
=0;i
<fdesc
->cParams
;i
++) {
1708 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1709 BOOL isdeserialized
= FALSE
;
1712 if (i
) TRACE_(olerelay
)(",");
1713 if (i
+1<nrofnames
&& names
[i
+1]) TRACE_(olerelay
)("%s=",relaystr(names
[i
+1]));
1715 /* No need to marshal other data than FOUT and any VT_PTR */
1716 if (!(elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
) && (elem
->tdesc
.vt
!= VT_PTR
)) {
1717 xargs
+= _argsize(elem
->tdesc
.vt
);
1718 if (relaydeb
) TRACE_(olerelay
)("[in]");
1721 if (((i
+1)<nrofnames
) && !IsBadStringPtrW(names
[i
+1],1)) {
1722 /* If the parameter is 'riid', we use it as interface IID
1723 * for a later ppvObject serialization.
1725 buf
.thisisiid
= !lstrcmpW(names
[i
+1],riidW
);
1727 /* deserialize DISPPARAM */
1728 if (!lstrcmpW(names
[i
+1],pdispparamsW
)) {
1729 hres
= deserialize_DISPPARAM_ptr(
1731 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
1739 ERR("Failed to deserialize DISPPARAM*, hres %lx\n",hres
);
1742 isdeserialized
= TRUE
;
1744 if (!lstrcmpW(names
[i
+1],ppvObjectW
)) {
1745 hres
= deserialize_LPVOID_ptr(
1747 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
1755 isdeserialized
= TRUE
;
1758 if (!isdeserialized
)
1759 hres
= deserialize_param(
1761 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
1769 ERR("Failed to unmarshall param, hres %lx\n",hres
);
1773 xargs
+= _argsize(elem
->tdesc
.vt
);
1776 hres
= xbuf_get(&buf
, (LPBYTE
)&remoteresult
, sizeof(DWORD
));
1779 if (relaydeb
) TRACE_(olerelay
)(") = %08lx\n", remoteresult
);
1781 if (status
!= S_OK
) /* OLE/COM internal error */
1784 HeapFree(GetProcessHeap(),0,buf
.base
);
1785 ITypeInfo_Release(tinfo
);
1786 LeaveCriticalSection(&tpinfo
->crit
);
1787 return remoteresult
;
1790 HRESULT WINAPI
ProxyIUnknown_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
1792 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1794 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
1796 if (proxy
->outerunknown
)
1797 return IUnknown_QueryInterface(proxy
->outerunknown
, riid
, ppv
);
1799 FIXME("No interface\n");
1800 return E_NOINTERFACE
;
1803 ULONG WINAPI
ProxyIUnknown_AddRef(IUnknown
*iface
)
1805 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1809 if (proxy
->outerunknown
)
1810 return IUnknown_AddRef(proxy
->outerunknown
);
1812 return 2; /* FIXME */
1815 ULONG WINAPI
ProxyIUnknown_Release(IUnknown
*iface
)
1817 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1821 if (proxy
->outerunknown
)
1822 return IUnknown_Release(proxy
->outerunknown
);
1824 return 1; /* FIXME */
1827 static HRESULT WINAPI
1828 PSFacBuf_CreateProxy(
1829 LPPSFACTORYBUFFER iface
, IUnknown
* pUnkOuter
, REFIID riid
,
1830 IRpcProxyBuffer
**ppProxy
, LPVOID
*ppv
)
1838 TRACE("(...%s...)\n",debugstr_guid(riid
));
1839 hres
= _get_typeinfo_for_iid(riid
,&tinfo
);
1841 ERR("No typeinfo for %s?\n",debugstr_guid(riid
));
1844 nroffuncs
= _nroffuncs(tinfo
);
1845 proxy
= CoTaskMemAlloc(sizeof(TMProxyImpl
));
1846 if (!proxy
) return E_OUTOFMEMORY
;
1848 assert(sizeof(TMAsmProxy
) == 12);
1850 proxy
->outerunknown
= pUnkOuter
;
1851 proxy
->asmstubs
= VirtualAlloc(NULL
, sizeof(TMAsmProxy
) * nroffuncs
, MEM_COMMIT
, PAGE_EXECUTE_READWRITE
);
1852 if (!proxy
->asmstubs
) {
1853 ERR("Could not commit pages for proxy thunks\n");
1854 CoTaskMemFree(proxy
);
1855 return E_OUTOFMEMORY
;
1858 InitializeCriticalSection(&proxy
->crit
);
1860 proxy
->lpvtbl
= HeapAlloc(GetProcessHeap(),0,sizeof(LPBYTE
)*nroffuncs
);
1861 for (i
=0;i
<nroffuncs
;i
++) {
1862 TMAsmProxy
*xasm
= proxy
->asmstubs
+i
;
1866 proxy
->lpvtbl
[i
] = ProxyIUnknown_QueryInterface
;
1869 proxy
->lpvtbl
[i
] = ProxyIUnknown_AddRef
;
1872 proxy
->lpvtbl
[i
] = ProxyIUnknown_Release
;
1876 /* nrofargs without This */
1879 hres
= _get_funcdesc(tinfo
,i
,&tinfo2
,&fdesc
,NULL
,NULL
);
1880 ITypeInfo_Release(tinfo2
);
1882 ERR("GetFuncDesc %lx should not fail here.\n",hres
);
1885 /* some args take more than 4 byte on the stack */
1887 for (j
=0;j
<fdesc
->cParams
;j
++)
1888 nrofargs
+= _argsize(fdesc
->lprgelemdescParam
[j
].tdesc
.vt
);
1890 if (fdesc
->callconv
!= CC_STDCALL
) {
1891 ERR("calling convention is not stdcall????\n");
1894 /* popl %eax - return ptr
1901 * arg3 arg2 arg1 <method> <returnptr>
1903 xasm
->popleax
= 0x58;
1904 xasm
->pushlval
= 0x6a;
1906 xasm
->pushleax
= 0x50;
1907 xasm
->lcall
= 0xe8; /* relative jump */
1908 xasm
->xcall
= (DWORD
)xCall
;
1909 xasm
->xcall
-= (DWORD
)&(xasm
->lret
);
1911 xasm
->bytestopop
= (nrofargs
+2)*4; /* pop args, This, iMethod */
1912 proxy
->lpvtbl
[i
] = xasm
;
1917 proxy
->lpvtbl2
= &tmproxyvtable
;
1918 /* 1 reference for the proxy and 1 for the object */
1920 proxy
->tinfo
= tinfo
;
1921 memcpy(&proxy
->iid
,riid
,sizeof(*riid
));
1923 *ppv
= (LPVOID
)proxy
;
1924 *ppProxy
= (IRpcProxyBuffer
*)&(proxy
->lpvtbl2
);
1928 typedef struct _TMStubImpl
{
1929 const IRpcStubBufferVtbl
*lpvtbl
;
1937 static HRESULT WINAPI
1938 TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface
, REFIID riid
, LPVOID
*ppv
)
1940 if (IsEqualIID(riid
,&IID_IRpcStubBuffer
)||IsEqualIID(riid
,&IID_IUnknown
)){
1941 *ppv
= (LPVOID
)iface
;
1942 IRpcStubBuffer_AddRef(iface
);
1945 FIXME("%s, not supported IID.\n",debugstr_guid(riid
));
1946 return E_NOINTERFACE
;
1950 TMStubImpl_AddRef(LPRPCSTUBBUFFER iface
)
1952 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1953 ULONG refCount
= InterlockedIncrement(&This
->ref
);
1955 TRACE("(%p)->(ref before=%lu)\n", This
, refCount
- 1);
1961 TMStubImpl_Release(LPRPCSTUBBUFFER iface
)
1963 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1964 ULONG refCount
= InterlockedDecrement(&This
->ref
);
1966 TRACE("(%p)->(ref before=%lu)\n", This
, refCount
+ 1);
1970 IRpcStubBuffer_Disconnect(iface
);
1971 ITypeInfo_Release(This
->tinfo
);
1972 CoTaskMemFree(This
);
1977 static HRESULT WINAPI
1978 TMStubImpl_Connect(LPRPCSTUBBUFFER iface
, LPUNKNOWN pUnkServer
)
1980 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1982 TRACE("(%p)->(%p)\n", This
, pUnkServer
);
1984 IUnknown_AddRef(pUnkServer
);
1985 This
->pUnk
= pUnkServer
;
1990 TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface
)
1992 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1994 TRACE("(%p)->()\n", This
);
1998 IUnknown_Release(This
->pUnk
);
2003 static HRESULT WINAPI
2005 LPRPCSTUBBUFFER iface
, RPCOLEMESSAGE
* xmsg
,IRpcChannelBuffer
*rpcchanbuf
)
2009 TMStubImpl
*This
= (TMStubImpl
*)iface
;
2011 DWORD
*args
, res
, *xargs
, nrofargs
;
2015 BSTR fname
= NULL
,iname
= NULL
;
2016 BOOL is_idispatch_getidsofnames
= 0;
2019 memset(&buf
,0,sizeof(buf
));
2020 buf
.size
= xmsg
->cbBuffer
;
2021 buf
.base
= HeapAlloc(GetProcessHeap(), 0, xmsg
->cbBuffer
);
2022 memcpy(buf
.base
, xmsg
->Buffer
, xmsg
->cbBuffer
);
2024 buf
.iid
= IID_IUnknown
;
2027 if (xmsg
->iMethod
== 0) { /* QI */
2029 /* in: IID, out: <iface> */
2031 xbuf_get(&buf
,(LPBYTE
)&xiid
,sizeof(xiid
));
2033 hres
= _marshal_interface(&buf
,&xiid
,This
->pUnk
);
2034 xmsg
->Buffer
= buf
.base
; /* Might have been reallocated */
2035 xmsg
->cbBuffer
= buf
.size
;
2038 hres
= _get_funcdesc(This
->tinfo
,xmsg
->iMethod
,&tinfo
,&fdesc
,&iname
,&fname
);
2040 ERR("GetFuncDesc on method %ld failed with %lx\n",xmsg
->iMethod
,hres
);
2044 if (iname
&& fname
&& !lstrcmpW(iname
, IDispatchW
) && !lstrcmpW(fname
, GetIDsOfNamesW
))
2045 is_idispatch_getidsofnames
= 1;
2047 if (iname
) SysFreeString (iname
);
2048 if (fname
) SysFreeString (fname
);
2050 /* Need them for hack below */
2051 memset(names
,0,sizeof(names
));
2052 ITypeInfo_GetNames(tinfo
,fdesc
->memid
,names
,sizeof(names
)/sizeof(names
[0]),&nrofnames
);
2053 if (nrofnames
> sizeof(names
)/sizeof(names
[0])) {
2054 ERR("Need more names!\n");
2057 /*dump_FUNCDESC(fdesc);*/
2059 for (i
=0;i
<fdesc
->cParams
;i
++)
2060 nrofargs
+= _argsize(fdesc
->lprgelemdescParam
[i
].tdesc
.vt
);
2061 args
= HeapAlloc(GetProcessHeap(),0,(nrofargs
+1)*sizeof(DWORD
));
2062 if (!args
) return E_OUTOFMEMORY
;
2064 if (is_idispatch_getidsofnames
) {
2065 hres
= deserialize_IDispatch_GetIDsOfNames(TRUE
,FALSE
,args
+1,&buf
);
2067 FIXME("deserialize_IDispatch_GetIDsOfNames failed!\n");
2071 goto afterdeserialize
;
2074 /* Allocate all stuff used by call. */
2076 for (i
=0;i
<fdesc
->cParams
;i
++) {
2077 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
2078 BOOL isdeserialized
= FALSE
;
2080 if (((i
+1)<nrofnames
) && !IsBadStringPtrW(names
[i
+1],1)) {
2081 /* If the parameter is 'riid', we use it as interface IID
2082 * for a later ppvObject serialization.
2084 buf
.thisisiid
= !lstrcmpW(names
[i
+1],riidW
);
2086 /* deserialize DISPPARAM */
2087 if (!lstrcmpW(names
[i
+1],pdispparamsW
)) {
2088 hres
= deserialize_DISPPARAM_ptr(
2090 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
2098 ERR("Failed to deserialize DISPPARAM*, hres %lx\n",hres
);
2101 isdeserialized
= TRUE
;
2103 if (!lstrcmpW(names
[i
+1],ppvObjectW
)) {
2104 hres
= deserialize_LPVOID_ptr(
2106 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
2114 isdeserialized
= TRUE
;
2117 if (!isdeserialized
)
2118 hres
= deserialize_param(
2120 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
2127 xargs
+= _argsize(elem
->tdesc
.vt
);
2129 ERR("Failed to deserialize param %s, hres %lx\n",relaystr(names
[i
+1]),hres
);
2134 hres
= IUnknown_QueryInterface(This
->pUnk
,&(This
->iid
),(LPVOID
*)&(args
[0]));
2136 ERR("Does not support iface %s, returning %lx\n",debugstr_guid(&(This
->iid
)), hres
);
2140 (*((FARPROC
**)args
[0]))[fdesc
->oVft
/4],
2145 IUnknown_Release((LPUNKNOWN
)args
[0]);
2148 /* special IDispatch::GetIDsOfNames serializer */
2149 if (is_idispatch_getidsofnames
) {
2150 hres
= serialize_IDispatch_GetIDsOfNames(FALSE
,FALSE
,args
+1,&buf
);
2152 FIXME("serialize of IDispatch::GetIDsOfNames failed!\n");
2155 goto afterserialize
;
2158 for (i
=0;i
<fdesc
->cParams
;i
++) {
2159 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
2160 BOOL isserialized
= FALSE
;
2162 if (((i
+1)<nrofnames
) && !IsBadStringPtrW(names
[i
+1],1)) {
2163 /* If the parameter is 'riid', we use it as interface IID
2164 * for a later ppvObject serialization.
2166 buf
.thisisiid
= !lstrcmpW(names
[i
+1],riidW
);
2168 /* DISPPARAMS* needs special serializer */
2169 if (!lstrcmpW(names
[i
+1],pdispparamsW
)) {
2170 hres
= serialize_DISPPARAM_ptr(
2172 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
2179 isserialized
= TRUE
;
2181 if (!lstrcmpW(names
[i
+1],ppvObjectW
)) {
2182 hres
= serialize_LPVOID_ptr(
2184 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
2192 isserialized
= TRUE
;
2196 hres
= serialize_param(
2198 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
2205 xargs
+= _argsize(elem
->tdesc
.vt
);
2207 ERR("Failed to stuballoc param, hres %lx\n",hres
);
2212 hres
= xbuf_add (&buf
, (LPBYTE
)&res
, sizeof(DWORD
));
2216 ITypeInfo_Release(tinfo
);
2217 xmsg
->cbBuffer
= buf
.curoff
;
2218 I_RpcGetBuffer((RPC_MESSAGE
*)xmsg
);
2219 memcpy(xmsg
->Buffer
, buf
.base
, buf
.curoff
);
2220 HeapFree(GetProcessHeap(),0,args
);
2224 static LPRPCSTUBBUFFER WINAPI
2225 TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface
, REFIID riid
) {
2226 FIXME("Huh (%s)?\n",debugstr_guid(riid
));
2231 TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface
) {
2232 TMStubImpl
*This
= (TMStubImpl
*)iface
;
2234 return This
->ref
; /*FIXME? */
2237 static HRESULT WINAPI
2238 TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface
, LPVOID
*ppv
) {
2243 TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface
, LPVOID ppv
) {
2247 static const IRpcStubBufferVtbl tmstubvtbl
= {
2248 TMStubImpl_QueryInterface
,
2252 TMStubImpl_Disconnect
,
2254 TMStubImpl_IsIIDSupported
,
2255 TMStubImpl_CountRefs
,
2256 TMStubImpl_DebugServerQueryInterface
,
2257 TMStubImpl_DebugServerRelease
2260 static HRESULT WINAPI
2261 PSFacBuf_CreateStub(
2262 LPPSFACTORYBUFFER iface
, REFIID riid
,IUnknown
*pUnkServer
,
2263 IRpcStubBuffer
** ppStub
2269 TRACE("(%s,%p,%p)\n",debugstr_guid(riid
),pUnkServer
,ppStub
);
2270 hres
= _get_typeinfo_for_iid(riid
,&tinfo
);
2272 ERR("No typeinfo for %s?\n",debugstr_guid(riid
));
2275 stub
= CoTaskMemAlloc(sizeof(TMStubImpl
));
2277 return E_OUTOFMEMORY
;
2278 stub
->lpvtbl
= &tmstubvtbl
;
2280 stub
->tinfo
= tinfo
;
2281 memcpy(&(stub
->iid
),riid
,sizeof(*riid
));
2282 hres
= IRpcStubBuffer_Connect((LPRPCSTUBBUFFER
)stub
,pUnkServer
);
2283 *ppStub
= (LPRPCSTUBBUFFER
)stub
;
2284 TRACE("IRpcStubBuffer: %p\n", stub
);
2286 ERR("Connect to pUnkServer failed?\n");
2290 static const IPSFactoryBufferVtbl psfacbufvtbl
= {
2291 PSFacBuf_QueryInterface
,
2294 PSFacBuf_CreateProxy
,
2298 /* This is the whole PSFactoryBuffer object, just the vtableptr */
2299 static const IPSFactoryBufferVtbl
*lppsfac
= &psfacbufvtbl
;
2301 /***********************************************************************
2302 * TMARSHAL_DllGetClassObject
2304 HRESULT
TMARSHAL_DllGetClassObject(REFCLSID rclsid
, REFIID iid
,LPVOID
*ppv
)
2306 if (IsEqualIID(iid
,&IID_IPSFactoryBuffer
)) {
2310 return E_NOINTERFACE
;