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 LPUNKNOWN newiface
= NULL
;
163 LPBYTE tempbuf
= NULL
;
164 IStream
*pStm
= NULL
;
166 ULARGE_INTEGER newpos
;
167 LARGE_INTEGER seekto
;
173 /* this is valid, if for instance we serialize
174 * a VT_DISPATCH with NULL ptr which apparently
175 * can happen. S_OK to make sure we continue
178 ERR("pUnk is NULL?\n");
180 return xbuf_add(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
185 TRACE("...%s...\n",debugstr_guid(riid
));
186 hres
= IUnknown_QueryInterface(pUnk
,riid
,(LPVOID
*)&newiface
);
188 WARN("%p does not support iface %s\n",pUnk
,debugstr_guid(riid
));
192 hres
= CreateStreamOnHGlobal(0,TRUE
,&pStm
);
194 ERR("Stream create failed %lx\n",hres
);
198 hres
= CoMarshalInterface(pStm
,riid
,newiface
,0,NULL
,0);
200 ERR("Marshalling interface %s failed with %lx\n", debugstr_guid(riid
), hres
);
204 hres
= IStream_Stat(pStm
,&ststg
,0);
206 ERR("Stream stat failed\n");
210 tempbuf
= HeapAlloc(GetProcessHeap(), 0, ststg
.cbSize
.u
.LowPart
);
211 memset(&seekto
,0,sizeof(seekto
));
212 hres
= IStream_Seek(pStm
,seekto
,SEEK_SET
,&newpos
);
214 ERR("Failed Seek %lx\n",hres
);
218 hres
= IStream_Read(pStm
,tempbuf
,ststg
.cbSize
.u
.LowPart
,&res
);
220 ERR("Failed Read %lx\n",hres
);
224 xsize
= ststg
.cbSize
.u
.LowPart
;
225 xbuf_add(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
226 hres
= xbuf_add(buf
,tempbuf
,ststg
.cbSize
.u
.LowPart
);
228 HeapFree(GetProcessHeap(),0,tempbuf
);
229 IUnknown_Release(newiface
);
230 IStream_Release(pStm
);
236 xbuf_add(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
237 if (pStm
) IUnknown_Release(pStm
);
238 if (newiface
) IUnknown_Release(newiface
);
239 HeapFree(GetProcessHeap(), 0, tempbuf
);
243 /********************* OLE Proxy/Stub Factory ********************************/
244 static HRESULT WINAPI
245 PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface
, REFIID iid
, LPVOID
*ppv
) {
246 if (IsEqualIID(iid
,&IID_IPSFactoryBuffer
)||IsEqualIID(iid
,&IID_IUnknown
)) {
247 *ppv
= (LPVOID
)iface
;
248 /* No ref counting, static class */
251 FIXME("(%s) unknown IID?\n",debugstr_guid(iid
));
252 return E_NOINTERFACE
;
255 static ULONG WINAPI
PSFacBuf_AddRef(LPPSFACTORYBUFFER iface
) { return 2; }
256 static ULONG WINAPI
PSFacBuf_Release(LPPSFACTORYBUFFER iface
) { return 1; }
259 _get_typeinfo_for_iid(REFIID riid
, ITypeInfo
**ti
) {
262 char tlguid
[200],typelibkey
[300],interfacekey
[300],ver
[100];
265 DWORD tlguidlen
, verlen
, type
;
269 sprintf( interfacekey
, "Interface\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\Typelib",
270 riid
->Data1
, riid
->Data2
, riid
->Data3
,
271 riid
->Data4
[0], riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3],
272 riid
->Data4
[4], riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]
275 if (RegOpenKeyA(HKEY_CLASSES_ROOT
,interfacekey
,&ikey
)) {
276 ERR("No %s key found.\n",interfacekey
);
280 tlguidlen
= sizeof(tlguid
);
281 if (RegQueryValueExA(ikey
,NULL
,NULL
,&type
,(LPBYTE
)tlguid
,&tlguidlen
)) {
282 ERR("Getting typelib guid failed.\n");
287 verlen
= sizeof(ver
);
288 if (RegQueryValueExA(ikey
,"Version",NULL
,&type
,(LPBYTE
)ver
,&verlen
)) {
289 ERR("Could not get version value?\n");
294 sprintf(typelibkey
,"Typelib\\%s\\%s\\0\\win32",tlguid
,ver
);
295 tlfnlen
= sizeof(tlfn
);
296 if (RegQueryValueA(HKEY_CLASSES_ROOT
,typelibkey
,tlfn
,&tlfnlen
)) {
297 ERR("Could not get typelib fn?\n");
300 MultiByteToWideChar(CP_ACP
, 0, tlfn
, -1, tlfnW
, -1);
301 hres
= LoadTypeLib(tlfnW
,&tl
);
303 ERR("Failed to load typelib for %s, but it should be there.\n",debugstr_guid(riid
));
306 hres
= ITypeLib_GetTypeInfoOfGuid(tl
,riid
,ti
);
308 ERR("typelib does not contain info for %s?\n",debugstr_guid(riid
));
309 ITypeLib_Release(tl
);
312 /* FIXME: do this? ITypeLib_Release(tl); */
316 /* Determine nr of functions. Since we use the toplevel interface and all
317 * inherited ones have lower numbers, we are ok to not to descent into
318 * the inheritance tree I think.
320 static int _nroffuncs(ITypeInfo
*tinfo
) {
327 hres
= ITypeInfo_GetFuncDesc(tinfo
,n
,&fdesc
);
330 if (fdesc
->oVft
/4 > max
)
339 #include "pshpack1.h"
341 typedef struct _TMAsmProxy
{
355 # error You need to implement stubless proxies for your architecture
358 typedef struct _TMProxyImpl
{
360 const IRpcProxyBufferVtbl
*lpvtbl2
;
363 TMAsmProxy
*asmstubs
;
365 IRpcChannelBuffer
* chanbuf
;
367 CRITICAL_SECTION crit
;
368 IUnknown
*outerunknown
;
371 static HRESULT WINAPI
372 TMProxyImpl_QueryInterface(LPRPCPROXYBUFFER iface
, REFIID riid
, LPVOID
*ppv
)
375 if (IsEqualIID(riid
,&IID_IUnknown
)||IsEqualIID(riid
,&IID_IRpcProxyBuffer
)) {
376 *ppv
= (LPVOID
)iface
;
377 IRpcProxyBuffer_AddRef(iface
);
380 FIXME("no interface for %s\n",debugstr_guid(riid
));
381 return E_NOINTERFACE
;
385 TMProxyImpl_AddRef(LPRPCPROXYBUFFER iface
)
387 ICOM_THIS_MULTI(TMProxyImpl
,lpvtbl2
,iface
);
388 ULONG refCount
= InterlockedIncrement(&This
->ref
);
390 TRACE("(%p)->(ref before=%lu)\n",This
, refCount
- 1);
396 TMProxyImpl_Release(LPRPCPROXYBUFFER iface
)
398 ICOM_THIS_MULTI(TMProxyImpl
,lpvtbl2
,iface
);
399 ULONG refCount
= InterlockedDecrement(&This
->ref
);
401 TRACE("(%p)->(ref before=%lu)\n",This
, refCount
+ 1);
405 DeleteCriticalSection(&This
->crit
);
406 if (This
->chanbuf
) IRpcChannelBuffer_Release(This
->chanbuf
);
407 VirtualFree(This
->asmstubs
, 0, MEM_RELEASE
);
413 static HRESULT WINAPI
415 LPRPCPROXYBUFFER iface
,IRpcChannelBuffer
* pRpcChannelBuffer
)
417 ICOM_THIS_MULTI(TMProxyImpl
, lpvtbl2
, iface
);
419 TRACE("(%p)\n", pRpcChannelBuffer
);
421 EnterCriticalSection(&This
->crit
);
423 IRpcChannelBuffer_AddRef(pRpcChannelBuffer
);
424 This
->chanbuf
= pRpcChannelBuffer
;
426 LeaveCriticalSection(&This
->crit
);
432 TMProxyImpl_Disconnect(LPRPCPROXYBUFFER iface
)
434 ICOM_THIS_MULTI(TMProxyImpl
, lpvtbl2
, iface
);
438 EnterCriticalSection(&This
->crit
);
440 IRpcChannelBuffer_Release(This
->chanbuf
);
441 This
->chanbuf
= NULL
;
443 LeaveCriticalSection(&This
->crit
);
447 static const IRpcProxyBufferVtbl tmproxyvtable
= {
448 TMProxyImpl_QueryInterface
,
452 TMProxyImpl_Disconnect
455 /* how much space do we use on stack in DWORD steps. */
460 return sizeof(double)/sizeof(DWORD
);
462 return sizeof(CY
)/sizeof(DWORD
);
464 return sizeof(DATE
)/sizeof(DWORD
);
466 return (sizeof(VARIANT
)+3)/sizeof(DWORD
);
473 _xsize(TYPEDESC
*td
) {
478 return sizeof(VARIANT
)+3;
481 ARRAYDESC
*adesc
= td
->u
.lpadesc
;
483 for (i
=0;i
<adesc
->cDims
;i
++)
484 arrsize
*= adesc
->rgbounds
[i
].cElements
;
485 return arrsize
*_xsize(&adesc
->tdescElem
);
510 TRACE("(tdesc.vt %d)\n",tdesc
->vt
);
513 case VT_EMPTY
: /* nothing. empty variant for instance */
522 if (debugout
) TRACE_(olerelay
)("%lx",*arg
);
524 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
529 if (debugout
) TRACE_(olerelay
)("%04lx",*arg
& 0xffff);
531 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
536 if (debugout
) TRACE_(olerelay
)("%02lx",*arg
& 0xff);
538 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
542 if (debugout
) TRACE_(olerelay
)("&0x%lx",*arg
);
544 hres
= xbuf_add(buf
,(LPBYTE
)(DWORD
*)*arg
,sizeof(DWORD
));
545 /* do not dealloc at this time */
549 VARIANT
*vt
= (VARIANT
*)arg
;
550 DWORD vttype
= V_VT(vt
);
552 if (debugout
) TRACE_(olerelay
)("Vt(%ld)(",vttype
);
555 hres
= xbuf_add(buf
,(LPBYTE
)&vttype
,sizeof(vttype
));
556 if (hres
) return hres
;
558 /* need to recurse since we need to free the stuff */
559 hres
= serialize_param(tinfo
,writeit
,debugout
,dealloc
,&tdesc2
,&(V_I4(vt
)),buf
);
560 if (debugout
) TRACE_(olerelay
)(")");
563 case VT_BSTR
|VT_BYREF
: {
564 if (debugout
) TRACE_(olerelay
)("[byref]'%s'", *(BSTR
*)*arg
? relaystr(*((BSTR
*)*arg
)) : "<bstr NULL>");
566 /* ptr to ptr to magic widestring, basically */
567 BSTR
*bstr
= (BSTR
*) *arg
;
569 /* -1 means "null string" which is equivalent to empty string */
571 xbuf_add(buf
, (LPBYTE
)&fakelen
,4);
573 /* BSTRs store the length behind the first character */
574 DWORD
*len
= ((DWORD
*)(*bstr
))-1;
575 hres
= xbuf_add(buf
, (LPBYTE
) len
, *len
+ 4);
576 if (hres
) return hres
;
580 if (dealloc
&& arg
) {
581 BSTR
*str
= *((BSTR
**)arg
);
590 TRACE_(olerelay
)("%s",relaystr((WCHAR
*)*arg
));
592 TRACE_(olerelay
)("<bstr NULL>");
597 hres
= xbuf_add(buf
,(LPBYTE
)&fakelen
,4);
601 DWORD
*bstr
= ((DWORD
*)(*arg
))-1;
603 hres
= xbuf_add(buf
,(LPBYTE
)bstr
,bstr
[0]+4);
610 SysFreeString((BSTR
)*arg
);
617 derefhere
= (tdesc
->u
.lptdesc
->vt
!= VT_USERDEFINED
);
619 if (debugout
) TRACE_(olerelay
)("*");
620 /* Write always, so the other side knows when it gets a NULL pointer.
622 cookie
= *arg
? 0x42424242 : 0;
623 hres
= xbuf_add(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
627 if (debugout
) TRACE_(olerelay
)("NULL");
630 hres
= serialize_param(tinfo
,writeit
,debugout
,dealloc
,tdesc
->u
.lptdesc
,(DWORD
*)*arg
,buf
);
631 if (derefhere
&& dealloc
) HeapFree(GetProcessHeap(),0,(LPVOID
)*arg
);
635 if (debugout
) TRACE_(olerelay
)("unk(0x%lx)",*arg
);
637 hres
= _marshal_interface(buf
,&IID_IUnknown
,(LPUNKNOWN
)*arg
);
640 if (debugout
) TRACE_(olerelay
)("idisp(0x%lx)",*arg
);
642 hres
= _marshal_interface(buf
,&IID_IDispatch
,(LPUNKNOWN
)*arg
);
645 if (debugout
) TRACE_(olerelay
)("<void>");
647 case VT_USERDEFINED
: {
651 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.hreftype
,&tinfo2
);
653 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc
->u
.hreftype
);
656 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
657 switch (tattr
->typekind
) {
659 case TKIND_INTERFACE
:
661 hres
=_marshal_interface(buf
,&(tattr
->guid
),(LPUNKNOWN
)arg
);
665 if (debugout
) TRACE_(olerelay
)("{");
666 for (i
=0;i
<tattr
->cVars
;i
++) {
671 hres
= ITypeInfo2_GetVarDesc(tinfo2
, i
, &vdesc
);
673 ERR("Could not get vardesc of %d\n",i
);
676 /* Need them for hack below */
678 memset(names,0,sizeof(names));
679 hres = ITypeInfo_GetNames(tinfo2,vdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
680 if (nrofnames > sizeof(names)/sizeof(names[0])) {
681 ERR("Need more names!\n");
683 if (!hres && debugout)
684 TRACE_(olerelay)("%s=",relaystr(names[0]));
686 elem2
= &vdesc
->elemdescVar
;
687 tdesc2
= &elem2
->tdesc
;
688 hres
= serialize_param(
694 (DWORD
*)(((LPBYTE
)arg
)+vdesc
->u
.oInst
),
697 ITypeInfo_ReleaseVarDesc(tinfo2
, vdesc
);
700 if (debugout
&& (i
<(tattr
->cVars
-1)))
701 TRACE_(olerelay
)(",");
703 if (buf
->thisisiid
&& (tattr
->cbSizeInstance
==sizeof(GUID
)))
704 memcpy(&(buf
->iid
),arg
,sizeof(buf
->iid
));
705 if (debugout
) TRACE_(olerelay
)("}");
709 return serialize_param(tinfo2
,writeit
,debugout
,dealloc
,&tattr
->tdescAlias
,arg
,buf
);
712 if (debugout
) TRACE_(olerelay
)("%lx",*arg
);
714 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
717 FIXME("Unhandled typekind %d\n",tattr
->typekind
);
721 ITypeInfo_Release(tinfo2
);
725 ARRAYDESC
*adesc
= tdesc
->u
.lpadesc
;
728 if (debugout
) TRACE_(olerelay
)("carr");
729 for (i
=0;i
<adesc
->cDims
;i
++) {
730 if (debugout
) TRACE_(olerelay
)("[%ld]",adesc
->rgbounds
[i
].cElements
);
731 arrsize
*= adesc
->rgbounds
[i
].cElements
;
733 if (debugout
) TRACE_(olerelay
)("(vt %d)",adesc
->tdescElem
.vt
);
734 if (debugout
) TRACE_(olerelay
)("[");
735 for (i
=0;i
<arrsize
;i
++) {
736 hres
= serialize_param(tinfo
, writeit
, debugout
, dealloc
, &adesc
->tdescElem
, (DWORD
*)((LPBYTE
)arg
+i
*_xsize(&adesc
->tdescElem
)), buf
);
739 if (debugout
&& (i
<arrsize
-1)) TRACE_(olerelay
)(",");
741 if (debugout
) TRACE_(olerelay
)("]");
745 ERR("Unhandled marshal type %d.\n",tdesc
->vt
);
751 * HRESULT GetIDsOfNames(
752 * [in] REFIID riid, args[1]
753 * [in, size_is(cNames)] LPOLESTR *rgszNames, args[2]
754 * [in] UINT cNames, args[3]
755 * [in] LCID lcid, args[4]
756 * [out, size_is(cNames)] DISPID *rgDispId); args[5]
761 * LPOLESTR rgszNames[cNames];
762 * DWORD bytestrlen (incl 0)
763 * BYTE data[bytestrlen] (incl 0)
767 serialize_IDispatch_GetIDsOfNames(
774 DWORD cNames
= args
[2];
775 LPOLESTR
*rgszNames
= (LPOLESTR
*)args
[1];
779 if (debugout
) TRACE_(olerelay
)("riid=%s,",debugstr_guid((REFIID
)args
[0]));
780 hres
= xbuf_add(buf
, (LPBYTE
)args
[0], sizeof(IID
));
782 FIXME("serialize of IID failed.\n");
785 if (debugout
) TRACE_(olerelay
)("cNames=%ld,",cNames
);
786 hres
= xbuf_add(buf
, (LPBYTE
)&cNames
, sizeof(DWORD
));
788 FIXME("serialize of cNames failed.\n");
791 if (debugout
) TRACE_(olerelay
)("rgszNames=[");
792 for (i
=0;i
<cNames
;i
++) {
793 DWORD len
= 2*(lstrlenW(rgszNames
[i
])+1);
795 if (debugout
) TRACE_(olerelay
)("%s,",relaystr(rgszNames
[i
]));
796 hres
= xbuf_add(buf
, (LPBYTE
)&len
, sizeof(DWORD
));
798 FIXME("serialize of len failed.\n");
801 hres
= xbuf_add(buf
, (LPBYTE
)rgszNames
[i
], len
);
803 FIXME("serialize of rgszNames[i] failed.\n");
807 if (debugout
) TRACE_(olerelay
)("],lcid=%04lx)",args
[3]);
808 hres
= xbuf_add(buf
, (LPBYTE
)&args
[3], sizeof(DWORD
));
810 FIXME("serialize of lcid failed.\n");
814 DISPID
*rgDispId
= (DISPID
*)args
[4];
816 hres
= xbuf_add(buf
, (LPBYTE
)rgDispId
, sizeof(DISPID
) * cNames
);
818 FIXME("serialize of rgDispId failed.\n");
822 TRACE_(olerelay
)("riid=[in],rgszNames=[in],cNames=[in],rgDispId=[");
823 for (i
=0;i
<cNames
;i
++)
824 TRACE_(olerelay
)("%08lx,",rgDispId
[i
]);
825 TRACE_(olerelay
)("])");
827 HeapFree(GetProcessHeap(),0,(IID
*)args
[0]);
828 rgszNames
= (LPOLESTR
*)args
[1];
829 for (i
=0;i
<cNames
;i
++) HeapFree(GetProcessHeap(),0,rgszNames
[i
]);
830 HeapFree(GetProcessHeap(),0,rgszNames
);
831 HeapFree(GetProcessHeap(),0,rgDispId
);
837 deserialize_IDispatch_GetIDsOfNames(
849 args
[0] = (DWORD
)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IID
));
850 if (!args
[0]) return E_FAIL
;
851 hres
= xbuf_get(buf
, (LPBYTE
)args
[0], sizeof(IID
));
853 FIXME("deserialize of IID failed.\n");
856 if (debugout
) TRACE_(olerelay
)("riid=%s,",debugstr_guid((REFIID
)args
[0]));
858 hres
= xbuf_get(buf
, (LPBYTE
)&cNames
, sizeof(DWORD
));
860 FIXME("deserialize of cNames failed.\n");
864 if (debugout
) TRACE_(olerelay
)("cNames=%ld,",cNames
);
865 if (debugout
) TRACE_(olerelay
)("rgszNames=[");
866 rgszNames
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(LPOLESTR
) * cNames
);
867 if (!rgszNames
) return E_FAIL
;
868 args
[1] = (DWORD
)rgszNames
;
869 for (i
=0;i
<cNames
;i
++) {
872 hres
= xbuf_get(buf
, (LPBYTE
)&len
, sizeof(DWORD
));
874 FIXME("serialize of len failed.\n");
877 rgszNames
[i
] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
879 FIXME("heapalloc of %ld bytes failed\n", len
);
882 hres
= xbuf_get(buf
, (LPBYTE
)rgszNames
[i
], len
);
884 FIXME("serialize of rgszNames[i] failed.\n");
887 if (debugout
) TRACE_(olerelay
)("%s,",relaystr(rgszNames
[i
]));
889 hres
= xbuf_get(buf
, (LPBYTE
)&args
[3], sizeof(DWORD
));
891 FIXME("deserialize of lcid failed.\n");
894 if (debugout
) TRACE_(olerelay
)("],lcid=%04lx,rgDispId=[out])",args
[3]);
895 args
[4] = (DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DISPID
) * cNames
);
897 hres
= xbuf_get(buf
, (LPBYTE
)args
[4], sizeof(DISPID
) * args
[2]);
899 FIXME("serialize of rgDispId failed.\n");
903 TRACE_(olerelay
)("dispid=[");
904 for (i
=0;i
<args
[2];i
++)
905 TRACE_(olerelay
)("%08lx,",((DISPID
*)args
[4])[i
]);
906 TRACE_(olerelay
)("])");
913 serialize_LPVOID_ptr(
925 if ((tdesc
->vt
!= VT_PTR
) ||
926 (tdesc
->u
.lptdesc
->vt
!= VT_PTR
) ||
927 (tdesc
->u
.lptdesc
->u
.lptdesc
->vt
!= VT_VOID
)
929 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
932 cookie
= (*(DWORD
*)*arg
) ? 0x42424242: 0x0;
934 hres
= xbuf_add(buf
, (LPVOID
)&cookie
, sizeof(cookie
));
938 if (!*(DWORD
*)*arg
) {
939 if (debugout
) TRACE_(olerelay
)("<lpvoid NULL>");
943 TRACE_(olerelay
)("ppv(%p)",*(LPUNKNOWN
*)*arg
);
945 hres
= _marshal_interface(buf
,&(buf
->iid
),*(LPUNKNOWN
*)*arg
);
950 HeapFree(GetProcessHeap(),0,(LPVOID
)*arg
);
955 serialize_DISPPARAM_ptr(
969 if ((tdesc
->vt
!= VT_PTR
) || (tdesc
->u
.lptdesc
->vt
!= VT_USERDEFINED
)) {
970 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
974 cookie
= *arg
? 0x42424242 : 0x0;
976 hres
= xbuf_add(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
981 if (debugout
) TRACE_(olerelay
)("<DISPPARAMS NULL>");
984 disp
= (DISPPARAMS
*)*arg
;
986 hres
= xbuf_add(buf
,(LPBYTE
)&disp
->cArgs
,sizeof(disp
->cArgs
));
990 if (debugout
) TRACE_(olerelay
)("D{");
991 for (i
=0;i
<disp
->cArgs
;i
++) {
994 vtdesc
.vt
= VT_VARIANT
;
1001 (DWORD
*)(disp
->rgvarg
+i
),
1004 if (debugout
&& (i
<disp
->cArgs
-1))
1005 TRACE_(olerelay
)(",");
1008 HeapFree(GetProcessHeap(),0,disp
->rgvarg
);
1010 hres
= xbuf_add(buf
,(LPBYTE
)&disp
->cNamedArgs
,sizeof(disp
->cNamedArgs
));
1014 if (debugout
) TRACE_(olerelay
)("}{");
1015 for (i
=0;i
<disp
->cNamedArgs
;i
++) {
1018 vtdesc
.vt
= VT_UINT
;
1025 (DWORD
*)(disp
->rgdispidNamedArgs
+i
),
1028 if (debugout
&& (i
<disp
->cNamedArgs
-1))
1029 TRACE_(olerelay
)(",");
1031 if (debugout
) TRACE_(olerelay
)("}");
1033 HeapFree(GetProcessHeap(),0,disp
->rgdispidNamedArgs
);
1034 HeapFree(GetProcessHeap(),0,disp
);
1049 HRESULT hres
= S_OK
;
1051 TRACE("vt %d at %p\n",tdesc
->vt
,arg
);
1054 switch (tdesc
->vt
) {
1056 if (debugout
) TRACE_(olerelay
)("<empty>");
1059 if (debugout
) TRACE_(olerelay
)("<null>");
1062 VARIANT
*vt
= (VARIANT
*)arg
;
1067 hres
= xbuf_get(buf
,(LPBYTE
)&vttype
,sizeof(vttype
));
1069 FIXME("vt type not read?\n");
1072 memset(&tdesc2
,0,sizeof(tdesc2
));
1075 if (debugout
) TRACE_(olerelay
)("Vt(%ld)(",vttype
);
1076 hres
= deserialize_param(tinfo
, readit
, debugout
, alloc
, &tdesc2
, &(V_I4(vt
)), buf
);
1077 TRACE_(olerelay
)(")");
1091 hres
= xbuf_get(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
1092 if (hres
) ERR("Failed to read integer 4 byte\n");
1094 if (debugout
) TRACE_(olerelay
)("%lx",*arg
);
1100 hres
= xbuf_get(buf
,(LPBYTE
)&x
,sizeof(DWORD
));
1101 if (hres
) ERR("Failed to read integer 4 byte\n");
1104 if (debugout
) TRACE_(olerelay
)("%04lx",*arg
& 0xffff);
1110 hres
= xbuf_get(buf
,(LPBYTE
)&x
,sizeof(DWORD
));
1111 if (hres
) ERR("Failed to read integer 4 byte\n");
1114 if (debugout
) TRACE_(olerelay
)("%02lx",*arg
& 0xff);
1116 case VT_I4
|VT_BYREF
:
1119 *arg
= (DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DWORD
));
1121 hres
= xbuf_get(buf
,(LPBYTE
)*arg
,sizeof(DWORD
));
1122 if (hres
) ERR("Failed to read integer 4 byte\n");
1124 if (debugout
) TRACE_(olerelay
)("&0x%lx",*(DWORD
*)*arg
);
1126 case VT_BSTR
|VT_BYREF
: {
1127 BSTR
**bstr
= (BSTR
**)arg
;
1132 hres
= xbuf_get(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
1134 ERR("failed to read bstr klen\n");
1138 *bstr
= CoTaskMemAlloc(sizeof(BSTR
*));
1140 if (debugout
) TRACE_(olerelay
)("<bstr NULL>");
1142 str
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,len
+sizeof(WCHAR
));
1143 hres
= xbuf_get(buf
,(LPBYTE
)str
,len
);
1145 ERR("Failed to read BSTR.\n");
1148 *bstr
= CoTaskMemAlloc(sizeof(BSTR
*));
1149 **bstr
= SysAllocStringLen(str
,len
);
1150 if (debugout
) TRACE_(olerelay
)("%s",relaystr(str
));
1151 HeapFree(GetProcessHeap(),0,str
);
1163 hres
= xbuf_get(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
1165 ERR("failed to read bstr klen\n");
1170 if (debugout
) TRACE_(olerelay
)("<bstr NULL>");
1172 str
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,len
+sizeof(WCHAR
));
1173 hres
= xbuf_get(buf
,(LPBYTE
)str
,len
);
1175 ERR("Failed to read BSTR.\n");
1178 *arg
= (DWORD
)SysAllocStringLen(str
,len
);
1179 if (debugout
) TRACE_(olerelay
)("%s",relaystr(str
));
1180 HeapFree(GetProcessHeap(),0,str
);
1191 derefhere
= (tdesc
->u
.lptdesc
->vt
!= VT_USERDEFINED
);
1192 /* read it in all cases, we need to know if we have
1193 * NULL pointer or not.
1195 hres
= xbuf_get(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
1197 ERR("Failed to load pointer cookie.\n");
1200 if (cookie
!= 0x42424242) {
1201 /* we read a NULL ptr from the remote side */
1202 if (debugout
) TRACE_(olerelay
)("NULL");
1206 if (debugout
) TRACE_(olerelay
)("*");
1208 /* Allocate space for the referenced struct */
1210 *arg
=(DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,_xsize(tdesc
->u
.lptdesc
));
1213 return deserialize_param(tinfo
, readit
, debugout
, alloc
, tdesc
->u
.lptdesc
, (LPDWORD
)*arg
, buf
);
1215 return deserialize_param(tinfo
, readit
, debugout
, alloc
, tdesc
->u
.lptdesc
, arg
, buf
);
1218 /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
1220 *arg
=(DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DWORD
));
1223 hres
= _unmarshal_interface(buf
,&IID_IUnknown
,(LPUNKNOWN
*)arg
);
1225 TRACE_(olerelay
)("unk(%p)",arg
);
1230 hres
= _unmarshal_interface(buf
,&IID_IDispatch
,(LPUNKNOWN
*)arg
);
1232 TRACE_(olerelay
)("idisp(%p)",arg
);
1235 if (debugout
) TRACE_(olerelay
)("<void>");
1237 case VT_USERDEFINED
: {
1241 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.hreftype
,&tinfo2
);
1243 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc
->u
.hreftype
);
1246 hres
= ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
1248 ERR("Could not get typeattr in VT_USERDEFINED.\n");
1250 switch (tattr
->typekind
) {
1251 case TKIND_DISPATCH
:
1252 case TKIND_INTERFACE
:
1254 hres
= _unmarshal_interface(buf
,&(tattr
->guid
),(LPUNKNOWN
*)arg
);
1256 case TKIND_RECORD
: {
1260 *arg
= (DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,tattr
->cbSizeInstance
);
1262 if (debugout
) TRACE_(olerelay
)("{");
1263 for (i
=0;i
<tattr
->cVars
;i
++) {
1266 hres
= ITypeInfo2_GetVarDesc(tinfo2
, i
, &vdesc
);
1268 ERR("Could not get vardesc of %d\n",i
);
1271 hres
= deserialize_param(
1276 &vdesc
->elemdescVar
.tdesc
,
1277 (DWORD
*)(((LPBYTE
)*arg
)+vdesc
->u
.oInst
),
1280 if (debugout
&& (i
<tattr
->cVars
-1)) TRACE_(olerelay
)(",");
1282 if (buf
->thisisiid
&& (tattr
->cbSizeInstance
==sizeof(GUID
)))
1283 memcpy(&(buf
->iid
),(LPBYTE
)*arg
,sizeof(buf
->iid
));
1284 if (debugout
) TRACE_(olerelay
)("}");
1288 return deserialize_param(tinfo2
,readit
,debugout
,alloc
,&tattr
->tdescAlias
,arg
,buf
);
1291 hres
= xbuf_get(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
1292 if (hres
) ERR("Failed to read enum (4 byte)\n");
1294 if (debugout
) TRACE_(olerelay
)("%lx",*arg
);
1297 ERR("Unhandled typekind %d\n",tattr
->typekind
);
1303 ERR("failed to stuballoc in TKIND_RECORD.\n");
1304 ITypeInfo_Release(tinfo2
);
1308 /* arg is pointing to the start of the array. */
1309 ARRAYDESC
*adesc
= tdesc
->u
.lpadesc
;
1312 if (adesc
->cDims
> 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
1313 for (i
=0;i
<adesc
->cDims
;i
++)
1314 arrsize
*= adesc
->rgbounds
[i
].cElements
;
1315 for (i
=0;i
<arrsize
;i
++)
1322 (DWORD
*)((LPBYTE
)(arg
)+i
*_xsize(&adesc
->tdescElem
)),
1328 ERR("No handler for VT type %d!\n",tdesc
->vt
);
1335 deserialize_LPVOID_ptr(
1347 if ((tdesc
->vt
!= VT_PTR
) ||
1348 (tdesc
->u
.lptdesc
->vt
!= VT_PTR
) ||
1349 (tdesc
->u
.lptdesc
->u
.lptdesc
->vt
!= VT_VOID
)
1351 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
1355 *arg
=(DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(LPVOID
));
1357 hres
= xbuf_get(buf
, (LPVOID
)&cookie
, sizeof(cookie
));
1360 if (cookie
!= 0x42424242) {
1362 if (debugout
) TRACE_(olerelay
)("<lpvoid NULL>");
1367 hres
= _unmarshal_interface(buf
,&buf
->iid
,(LPUNKNOWN
*)*arg
);
1369 FIXME("_unmarshal_interface of %s , %p failed with %lx\n", debugstr_guid(&buf
->iid
), (LPUNKNOWN
*)*arg
, hres
);
1373 if (debugout
) TRACE_(olerelay
)("ppv(%p)",(LPVOID
)*arg
);
1378 deserialize_DISPPARAM_ptr(
1392 if ((tdesc
->vt
!= VT_PTR
) || (tdesc
->u
.lptdesc
->vt
!= VT_USERDEFINED
)) {
1393 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
1397 hres
= xbuf_get(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
1402 if (debugout
) TRACE_(olerelay
)("<DISPPARAMS NULL>");
1407 *arg
= (DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DISPPARAMS
));
1408 disps
= (DISPPARAMS
*)*arg
;
1411 hres
= xbuf_get(buf
, (LPBYTE
)&disps
->cArgs
, sizeof(disps
->cArgs
));
1415 disps
->rgvarg
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(VARIANT
)*disps
->cArgs
);
1416 if (debugout
) TRACE_(olerelay
)("D{");
1417 for (i
=0; i
< disps
->cArgs
; i
++) {
1420 vdesc
.vt
= VT_VARIANT
;
1421 hres
= deserialize_param(
1427 (DWORD
*)(disps
->rgvarg
+i
),
1431 if (debugout
) TRACE_(olerelay
)("}{");
1432 hres
= xbuf_get(buf
, (LPBYTE
)&disps
->cNamedArgs
, sizeof(disps
->cNamedArgs
));
1435 if (disps
->cNamedArgs
) {
1437 disps
->rgdispidNamedArgs
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DISPID
)*disps
->cNamedArgs
);
1438 for (i
=0; i
< disps
->cNamedArgs
; i
++) {
1442 hres
= deserialize_param(
1448 (DWORD
*)(disps
->rgdispidNamedArgs
+i
),
1451 if (debugout
&& i
<(disps
->cNamedArgs
-1)) TRACE_(olerelay
)(",");
1454 if (debugout
) TRACE_(olerelay
)("}");
1458 /* Searches function, also in inherited interfaces */
1461 ITypeInfo
*tinfo
, int iMethod
, ITypeInfo
**tactual
, FUNCDESC
**fdesc
, BSTR
*iname
, BSTR
*fname
)
1466 if (fname
) *fname
= NULL
;
1467 if (iname
) *iname
= NULL
;
1470 ITypeInfo_AddRef(*tactual
);
1473 hres
= ITypeInfo_GetFuncDesc(tinfo
, i
, fdesc
);
1479 hres
= ITypeInfo_GetTypeAttr(tinfo
, &attr
);
1481 ERR("GetTypeAttr failed with %lx\n",hres
);
1484 /* Not found, so look in inherited ifaces. */
1485 for (j
=0;j
<attr
->cImplTypes
;j
++) {
1486 hres
= ITypeInfo_GetRefTypeOfImplType(tinfo
, j
, &href
);
1488 ERR("Did not find a reftype for interface offset %d?\n",j
);
1491 hres
= ITypeInfo_GetRefTypeInfo(tinfo
, href
, &tinfo2
);
1493 ERR("Did not find a typeinfo for reftype %ld?\n",href
);
1496 hres
= _get_funcdesc(tinfo2
,iMethod
,tactual
,fdesc
,iname
,fname
);
1497 ITypeInfo_Release(tinfo2
);
1498 if (!hres
) return S_OK
;
1502 if (((*fdesc
)->oVft
/4) == iMethod
) {
1504 ITypeInfo_GetDocumentation(tinfo
,(*fdesc
)->memid
,fname
,NULL
,NULL
,NULL
);
1506 ITypeInfo_GetDocumentation(tinfo
,-1,iname
,NULL
,NULL
,NULL
);
1514 xCall(LPVOID retptr
, int method
, TMProxyImpl
*tpinfo
/*, args */)
1516 DWORD
*args
= ((DWORD
*)&tpinfo
)+1, *xargs
;
1519 int i
, relaydeb
= TRACE_ON(olerelay
);
1526 int is_idispatch_getidsofnames
= 0;
1527 DWORD remoteresult
= 0;
1530 EnterCriticalSection(&tpinfo
->crit
);
1532 hres
= _get_funcdesc(tpinfo
->tinfo
,method
,&tinfo
,&fdesc
,&iname
,&fname
);
1534 ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method
);
1535 ITypeInfo_Release(tinfo
);
1536 LeaveCriticalSection(&tpinfo
->crit
);
1540 if (!tpinfo
->chanbuf
)
1542 WARN("Tried to use disconnected proxy\n");
1543 ITypeInfo_Release(tinfo
);
1544 LeaveCriticalSection(&tpinfo
->crit
);
1545 return RPC_E_DISCONNECTED
;
1549 TRACE_(olerelay
)("->");
1551 TRACE_(olerelay
)("%s:",relaystr(iname
));
1553 TRACE_(olerelay
)("%s(%d)",relaystr(fname
),method
);
1555 TRACE_(olerelay
)("%d",method
);
1556 TRACE_(olerelay
)("(");
1558 if (iname
&& fname
&& !lstrcmpW(iname
,IDispatchW
) && !lstrcmpW(fname
,GetIDsOfNamesW
))
1559 is_idispatch_getidsofnames
= 1;
1561 if (iname
) SysFreeString(iname
);
1562 if (fname
) SysFreeString(fname
);
1564 memset(&buf
,0,sizeof(buf
));
1565 buf
.iid
= IID_IUnknown
;
1567 /* Special IDispatch::GetIDsOfNames() serializer */
1568 if (is_idispatch_getidsofnames
) {
1569 hres
= serialize_IDispatch_GetIDsOfNames(TRUE
,relaydeb
,args
,&buf
);
1571 FIXME("serialize of IDispatch::GetIDsOfNames failed!\n");
1572 ITypeInfo_Release(tinfo
);
1573 LeaveCriticalSection(&tpinfo
->crit
);
1576 goto afterserialize
;
1579 /* special QueryInterface serialize */
1581 xbuf_add(&buf
,(LPBYTE
)args
[0],sizeof(IID
));
1582 if (relaydeb
) TRACE_(olerelay
)("riid=%s,[out])",debugstr_guid((REFIID
)args
[0]));
1583 goto afterserialize
;
1586 /* normal typelib driven serializing */
1588 /* Need them for hack below */
1589 memset(names
,0,sizeof(names
));
1590 if (ITypeInfo_GetNames(tinfo
,fdesc
->memid
,names
,sizeof(names
)/sizeof(names
[0]),&nrofnames
))
1592 if (nrofnames
> sizeof(names
)/sizeof(names
[0]))
1593 ERR("Need more names!\n");
1596 for (i
=0;i
<fdesc
->cParams
;i
++) {
1597 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1598 BOOL isserialized
= FALSE
;
1600 if (i
) TRACE_(olerelay
)(",");
1601 if (i
+1<nrofnames
&& names
[i
+1])
1602 TRACE_(olerelay
)("%s=",relaystr(names
[i
+1]));
1604 /* No need to marshal other data than FIN and any VT_PTR. */
1605 if (!(elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
) && (elem
->tdesc
.vt
!= VT_PTR
)) {
1606 xargs
+=_argsize(elem
->tdesc
.vt
);
1607 if (relaydeb
) TRACE_(olerelay
)("[out]");
1610 if (((i
+1)<nrofnames
) && !IsBadStringPtrW(names
[i
+1],1)) {
1611 /* If the parameter is 'riid', we use it as interface IID
1612 * for a later ppvObject serialization.
1614 buf
.thisisiid
= !lstrcmpW(names
[i
+1],riidW
);
1616 /* DISPPARAMS* needs special serializer */
1617 if (!lstrcmpW(names
[i
+1],pdispparamsW
)) {
1618 hres
= serialize_DISPPARAM_ptr(
1620 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
1627 isserialized
= TRUE
;
1629 if (!lstrcmpW(names
[i
+1],ppvObjectW
)) {
1630 hres
= serialize_LPVOID_ptr(
1632 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
1640 isserialized
= TRUE
;
1644 hres
= serialize_param(
1646 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
1655 ERR("Failed to serialize param, hres %lx\n",hres
);
1658 xargs
+=_argsize(elem
->tdesc
.vt
);
1660 if (relaydeb
) TRACE_(olerelay
)(")");
1663 memset(&msg
,0,sizeof(msg
));
1664 msg
.cbBuffer
= buf
.curoff
;
1665 msg
.iMethod
= method
;
1666 hres
= IRpcChannelBuffer_GetBuffer(tpinfo
->chanbuf
,&msg
,&(tpinfo
->iid
));
1668 ERR("RpcChannelBuffer GetBuffer failed, %lx\n",hres
);
1669 LeaveCriticalSection(&tpinfo
->crit
);
1672 memcpy(msg
.Buffer
,buf
.base
,buf
.curoff
);
1673 if (relaydeb
) TRACE_(olerelay
)("\n");
1674 hres
= IRpcChannelBuffer_SendReceive(tpinfo
->chanbuf
,&msg
,&status
);
1676 ERR("RpcChannelBuffer SendReceive failed, %lx\n",hres
);
1677 LeaveCriticalSection(&tpinfo
->crit
);
1681 if (relaydeb
) TRACE_(olerelay
)(" status = %08lx (",status
);
1683 buf
.base
= HeapReAlloc(GetProcessHeap(),0,buf
.base
,msg
.cbBuffer
);
1685 buf
.base
= HeapAlloc(GetProcessHeap(),0,msg
.cbBuffer
);
1686 buf
.size
= msg
.cbBuffer
;
1687 memcpy(buf
.base
,msg
.Buffer
,buf
.size
);
1690 /* Special IDispatch::GetIDsOfNames() deserializer */
1691 if (is_idispatch_getidsofnames
) {
1692 hres
= deserialize_IDispatch_GetIDsOfNames(FALSE
,relaydeb
,args
,&buf
);
1694 FIXME("deserialize of IDispatch::GetIDsOfNames failed!\n");
1697 goto after_deserialize
;
1699 /* Special QueryInterface deserializer */
1701 _unmarshal_interface(&buf
,(REFIID
)args
[0],(LPUNKNOWN
*)args
[1]);
1702 if (relaydeb
) TRACE_(olerelay
)("[in],%p",*((DWORD
**)args
[1]));
1703 goto after_deserialize
;
1706 /* generic deserializer using typelib description */
1709 for (i
=0;i
<fdesc
->cParams
;i
++) {
1710 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1711 BOOL isdeserialized
= FALSE
;
1714 if (i
) TRACE_(olerelay
)(",");
1715 if (i
+1<nrofnames
&& names
[i
+1]) TRACE_(olerelay
)("%s=",relaystr(names
[i
+1]));
1717 /* No need to marshal other data than FOUT and any VT_PTR */
1718 if (!(elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
) && (elem
->tdesc
.vt
!= VT_PTR
)) {
1719 xargs
+= _argsize(elem
->tdesc
.vt
);
1720 if (relaydeb
) TRACE_(olerelay
)("[in]");
1723 if (((i
+1)<nrofnames
) && !IsBadStringPtrW(names
[i
+1],1)) {
1724 /* If the parameter is 'riid', we use it as interface IID
1725 * for a later ppvObject serialization.
1727 buf
.thisisiid
= !lstrcmpW(names
[i
+1],riidW
);
1729 /* deserialize DISPPARAM */
1730 if (!lstrcmpW(names
[i
+1],pdispparamsW
)) {
1731 hres
= deserialize_DISPPARAM_ptr(
1733 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
1741 ERR("Failed to deserialize DISPPARAM*, hres %lx\n",hres
);
1744 isdeserialized
= TRUE
;
1746 if (!lstrcmpW(names
[i
+1],ppvObjectW
)) {
1747 hres
= deserialize_LPVOID_ptr(
1749 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
1757 isdeserialized
= TRUE
;
1760 if (!isdeserialized
)
1761 hres
= deserialize_param(
1763 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
1771 ERR("Failed to unmarshall param, hres %lx\n",hres
);
1775 xargs
+= _argsize(elem
->tdesc
.vt
);
1778 hres
= xbuf_get(&buf
, (LPBYTE
)&remoteresult
, sizeof(DWORD
));
1781 if (relaydeb
) TRACE_(olerelay
)(") = %08lx\n", remoteresult
);
1783 if (status
!= S_OK
) /* OLE/COM internal error */
1786 HeapFree(GetProcessHeap(),0,buf
.base
);
1787 ITypeInfo_Release(tinfo
);
1788 LeaveCriticalSection(&tpinfo
->crit
);
1789 return remoteresult
;
1792 HRESULT WINAPI
ProxyIUnknown_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
1794 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1796 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
1798 if (proxy
->outerunknown
)
1799 return IUnknown_QueryInterface(proxy
->outerunknown
, riid
, ppv
);
1801 FIXME("No interface\n");
1802 return E_NOINTERFACE
;
1805 ULONG WINAPI
ProxyIUnknown_AddRef(IUnknown
*iface
)
1807 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1811 if (proxy
->outerunknown
)
1812 return IUnknown_AddRef(proxy
->outerunknown
);
1814 return 2; /* FIXME */
1817 ULONG WINAPI
ProxyIUnknown_Release(IUnknown
*iface
)
1819 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1823 if (proxy
->outerunknown
)
1824 return IUnknown_Release(proxy
->outerunknown
);
1826 return 1; /* FIXME */
1829 static HRESULT WINAPI
1830 PSFacBuf_CreateProxy(
1831 LPPSFACTORYBUFFER iface
, IUnknown
* pUnkOuter
, REFIID riid
,
1832 IRpcProxyBuffer
**ppProxy
, LPVOID
*ppv
)
1840 TRACE("(...%s...)\n",debugstr_guid(riid
));
1841 hres
= _get_typeinfo_for_iid(riid
,&tinfo
);
1843 ERR("No typeinfo for %s?\n",debugstr_guid(riid
));
1846 nroffuncs
= _nroffuncs(tinfo
);
1847 proxy
= CoTaskMemAlloc(sizeof(TMProxyImpl
));
1848 if (!proxy
) return E_OUTOFMEMORY
;
1850 assert(sizeof(TMAsmProxy
) == 12);
1852 proxy
->outerunknown
= pUnkOuter
;
1853 proxy
->asmstubs
= VirtualAlloc(NULL
, sizeof(TMAsmProxy
) * nroffuncs
, MEM_COMMIT
, PAGE_EXECUTE_READWRITE
);
1854 if (!proxy
->asmstubs
) {
1855 ERR("Could not commit pages for proxy thunks\n");
1856 CoTaskMemFree(proxy
);
1857 return E_OUTOFMEMORY
;
1860 InitializeCriticalSection(&proxy
->crit
);
1862 proxy
->lpvtbl
= HeapAlloc(GetProcessHeap(),0,sizeof(LPBYTE
)*nroffuncs
);
1863 for (i
=0;i
<nroffuncs
;i
++) {
1864 TMAsmProxy
*xasm
= proxy
->asmstubs
+i
;
1868 proxy
->lpvtbl
[i
] = ProxyIUnknown_QueryInterface
;
1871 proxy
->lpvtbl
[i
] = ProxyIUnknown_AddRef
;
1874 proxy
->lpvtbl
[i
] = ProxyIUnknown_Release
;
1878 /* nrofargs without This */
1881 hres
= _get_funcdesc(tinfo
,i
,&tinfo2
,&fdesc
,NULL
,NULL
);
1882 ITypeInfo_Release(tinfo2
);
1884 ERR("GetFuncDesc %lx should not fail here.\n",hres
);
1887 /* some args take more than 4 byte on the stack */
1889 for (j
=0;j
<fdesc
->cParams
;j
++)
1890 nrofargs
+= _argsize(fdesc
->lprgelemdescParam
[j
].tdesc
.vt
);
1892 if (fdesc
->callconv
!= CC_STDCALL
) {
1893 ERR("calling convention is not stdcall????\n");
1896 /* popl %eax - return ptr
1903 * arg3 arg2 arg1 <method> <returnptr>
1905 xasm
->popleax
= 0x58;
1906 xasm
->pushlval
= 0x6a;
1908 xasm
->pushleax
= 0x50;
1909 xasm
->lcall
= 0xe8; /* relative jump */
1910 xasm
->xcall
= (DWORD
)xCall
;
1911 xasm
->xcall
-= (DWORD
)&(xasm
->lret
);
1913 xasm
->bytestopop
= (nrofargs
+2)*4; /* pop args, This, iMethod */
1914 proxy
->lpvtbl
[i
] = xasm
;
1919 proxy
->lpvtbl2
= &tmproxyvtable
;
1920 /* 1 reference for the proxy and 1 for the object */
1922 proxy
->tinfo
= tinfo
;
1923 memcpy(&proxy
->iid
,riid
,sizeof(*riid
));
1925 *ppv
= (LPVOID
)proxy
;
1926 *ppProxy
= (IRpcProxyBuffer
*)&(proxy
->lpvtbl2
);
1930 typedef struct _TMStubImpl
{
1931 const IRpcStubBufferVtbl
*lpvtbl
;
1939 static HRESULT WINAPI
1940 TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface
, REFIID riid
, LPVOID
*ppv
)
1942 if (IsEqualIID(riid
,&IID_IRpcStubBuffer
)||IsEqualIID(riid
,&IID_IUnknown
)){
1943 *ppv
= (LPVOID
)iface
;
1944 IRpcStubBuffer_AddRef(iface
);
1947 FIXME("%s, not supported IID.\n",debugstr_guid(riid
));
1948 return E_NOINTERFACE
;
1952 TMStubImpl_AddRef(LPRPCSTUBBUFFER iface
)
1954 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1955 ULONG refCount
= InterlockedIncrement(&This
->ref
);
1957 TRACE("(%p)->(ref before=%lu)\n", This
, refCount
- 1);
1963 TMStubImpl_Release(LPRPCSTUBBUFFER iface
)
1965 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1966 ULONG refCount
= InterlockedDecrement(&This
->ref
);
1968 TRACE("(%p)->(ref before=%lu)\n", This
, refCount
+ 1);
1972 IRpcStubBuffer_Disconnect(iface
);
1973 CoTaskMemFree(This
);
1978 static HRESULT WINAPI
1979 TMStubImpl_Connect(LPRPCSTUBBUFFER iface
, LPUNKNOWN pUnkServer
)
1981 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1983 TRACE("(%p)->(%p)\n", This
, pUnkServer
);
1985 IUnknown_AddRef(pUnkServer
);
1986 This
->pUnk
= pUnkServer
;
1991 TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface
)
1993 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1995 TRACE("(%p)->()\n", This
);
1997 IUnknown_Release(This
->pUnk
);
2002 static HRESULT WINAPI
2004 LPRPCSTUBBUFFER iface
, RPCOLEMESSAGE
* xmsg
,IRpcChannelBuffer
*rpcchanbuf
)
2008 TMStubImpl
*This
= (TMStubImpl
*)iface
;
2010 DWORD
*args
, res
, *xargs
, nrofargs
;
2014 BSTR fname
= NULL
,iname
= NULL
;
2015 BOOL is_idispatch_getidsofnames
= 0;
2018 memset(&buf
,0,sizeof(buf
));
2019 buf
.size
= xmsg
->cbBuffer
;
2020 buf
.base
= HeapAlloc(GetProcessHeap(), 0, xmsg
->cbBuffer
);
2021 memcpy(buf
.base
, xmsg
->Buffer
, xmsg
->cbBuffer
);
2023 buf
.iid
= IID_IUnknown
;
2026 if (xmsg
->iMethod
== 0) { /* QI */
2028 /* in: IID, out: <iface> */
2030 xbuf_get(&buf
,(LPBYTE
)&xiid
,sizeof(xiid
));
2032 hres
= _marshal_interface(&buf
,&xiid
,This
->pUnk
);
2033 xmsg
->Buffer
= buf
.base
; /* Might have been reallocated */
2034 xmsg
->cbBuffer
= buf
.size
;
2037 hres
= _get_funcdesc(This
->tinfo
,xmsg
->iMethod
,&tinfo
,&fdesc
,&iname
,&fname
);
2039 ERR("GetFuncDesc on method %ld failed with %lx\n",xmsg
->iMethod
,hres
);
2043 if (iname
&& fname
&& !lstrcmpW(iname
, IDispatchW
) && !lstrcmpW(fname
, GetIDsOfNamesW
))
2044 is_idispatch_getidsofnames
= 1;
2046 if (iname
) SysFreeString (iname
);
2047 if (fname
) SysFreeString (fname
);
2049 /* Need them for hack below */
2050 memset(names
,0,sizeof(names
));
2051 ITypeInfo_GetNames(tinfo
,fdesc
->memid
,names
,sizeof(names
)/sizeof(names
[0]),&nrofnames
);
2052 if (nrofnames
> sizeof(names
)/sizeof(names
[0])) {
2053 ERR("Need more names!\n");
2056 /*dump_FUNCDESC(fdesc);*/
2058 for (i
=0;i
<fdesc
->cParams
;i
++)
2059 nrofargs
+= _argsize(fdesc
->lprgelemdescParam
[i
].tdesc
.vt
);
2060 args
= HeapAlloc(GetProcessHeap(),0,(nrofargs
+1)*sizeof(DWORD
));
2061 if (!args
) return E_OUTOFMEMORY
;
2063 if (is_idispatch_getidsofnames
) {
2064 hres
= deserialize_IDispatch_GetIDsOfNames(TRUE
,FALSE
,args
+1,&buf
);
2066 FIXME("deserialize_IDispatch_GetIDsOfNames failed!\n");
2070 goto afterdeserialize
;
2073 /* Allocate all stuff used by call. */
2075 for (i
=0;i
<fdesc
->cParams
;i
++) {
2076 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
2077 BOOL isdeserialized
= FALSE
;
2079 if (((i
+1)<nrofnames
) && !IsBadStringPtrW(names
[i
+1],1)) {
2080 /* If the parameter is 'riid', we use it as interface IID
2081 * for a later ppvObject serialization.
2083 buf
.thisisiid
= !lstrcmpW(names
[i
+1],riidW
);
2085 /* deserialize DISPPARAM */
2086 if (!lstrcmpW(names
[i
+1],pdispparamsW
)) {
2087 hres
= deserialize_DISPPARAM_ptr(
2089 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
2097 ERR("Failed to deserialize DISPPARAM*, hres %lx\n",hres
);
2100 isdeserialized
= TRUE
;
2102 if (!lstrcmpW(names
[i
+1],ppvObjectW
)) {
2103 hres
= deserialize_LPVOID_ptr(
2105 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
2113 isdeserialized
= TRUE
;
2116 if (!isdeserialized
)
2117 hres
= deserialize_param(
2119 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
2126 xargs
+= _argsize(elem
->tdesc
.vt
);
2128 ERR("Failed to deserialize param %s, hres %lx\n",relaystr(names
[i
+1]),hres
);
2133 hres
= IUnknown_QueryInterface(This
->pUnk
,&(This
->iid
),(LPVOID
*)&(args
[0]));
2135 ERR("Does not support iface %s, returning %lx\n",debugstr_guid(&(This
->iid
)), hres
);
2139 (*((FARPROC
**)args
[0]))[fdesc
->oVft
/4],
2144 IUnknown_Release((LPUNKNOWN
)args
[0]);
2147 /* special IDispatch::GetIDsOfNames serializer */
2148 if (is_idispatch_getidsofnames
) {
2149 hres
= serialize_IDispatch_GetIDsOfNames(FALSE
,FALSE
,args
+1,&buf
);
2151 FIXME("serialize of IDispatch::GetIDsOfNames failed!\n");
2154 goto afterserialize
;
2157 for (i
=0;i
<fdesc
->cParams
;i
++) {
2158 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
2159 BOOL isserialized
= FALSE
;
2161 if (((i
+1)<nrofnames
) && !IsBadStringPtrW(names
[i
+1],1)) {
2162 /* If the parameter is 'riid', we use it as interface IID
2163 * for a later ppvObject serialization.
2165 buf
.thisisiid
= !lstrcmpW(names
[i
+1],riidW
);
2167 /* DISPPARAMS* needs special serializer */
2168 if (!lstrcmpW(names
[i
+1],pdispparamsW
)) {
2169 hres
= serialize_DISPPARAM_ptr(
2171 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
2178 isserialized
= TRUE
;
2180 if (!lstrcmpW(names
[i
+1],ppvObjectW
)) {
2181 hres
= serialize_LPVOID_ptr(
2183 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
2191 isserialized
= TRUE
;
2195 hres
= serialize_param(
2197 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
2204 xargs
+= _argsize(elem
->tdesc
.vt
);
2206 ERR("Failed to stuballoc param, hres %lx\n",hres
);
2211 hres
= xbuf_add (&buf
, (LPBYTE
)&res
, sizeof(DWORD
));
2215 ITypeInfo_Release(tinfo
);
2216 xmsg
->cbBuffer
= buf
.curoff
;
2217 I_RpcGetBuffer((RPC_MESSAGE
*)xmsg
);
2218 memcpy(xmsg
->Buffer
, buf
.base
, buf
.curoff
);
2219 HeapFree(GetProcessHeap(),0,args
);
2223 static LPRPCSTUBBUFFER WINAPI
2224 TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface
, REFIID riid
) {
2225 FIXME("Huh (%s)?\n",debugstr_guid(riid
));
2230 TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface
) {
2231 TMStubImpl
*This
= (TMStubImpl
*)iface
;
2233 return This
->ref
; /*FIXME? */
2236 static HRESULT WINAPI
2237 TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface
, LPVOID
*ppv
) {
2242 TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface
, LPVOID ppv
) {
2246 static const IRpcStubBufferVtbl tmstubvtbl
= {
2247 TMStubImpl_QueryInterface
,
2251 TMStubImpl_Disconnect
,
2253 TMStubImpl_IsIIDSupported
,
2254 TMStubImpl_CountRefs
,
2255 TMStubImpl_DebugServerQueryInterface
,
2256 TMStubImpl_DebugServerRelease
2259 static HRESULT WINAPI
2260 PSFacBuf_CreateStub(
2261 LPPSFACTORYBUFFER iface
, REFIID riid
,IUnknown
*pUnkServer
,
2262 IRpcStubBuffer
** ppStub
2268 TRACE("(%s,%p,%p)\n",debugstr_guid(riid
),pUnkServer
,ppStub
);
2269 hres
= _get_typeinfo_for_iid(riid
,&tinfo
);
2271 ERR("No typeinfo for %s?\n",debugstr_guid(riid
));
2274 stub
= CoTaskMemAlloc(sizeof(TMStubImpl
));
2276 return E_OUTOFMEMORY
;
2277 stub
->lpvtbl
= &tmstubvtbl
;
2279 stub
->tinfo
= tinfo
;
2280 memcpy(&(stub
->iid
),riid
,sizeof(*riid
));
2281 hres
= IRpcStubBuffer_Connect((LPRPCSTUBBUFFER
)stub
,pUnkServer
);
2282 *ppStub
= (LPRPCSTUBBUFFER
)stub
;
2283 TRACE("IRpcStubBuffer: %p\n", stub
);
2285 ERR("Connect to pUnkServer failed?\n");
2289 static const IPSFactoryBufferVtbl psfacbufvtbl
= {
2290 PSFacBuf_QueryInterface
,
2293 PSFacBuf_CreateProxy
,
2297 /* This is the whole PSFactoryBuffer object, just the vtableptr */
2298 static const IPSFactoryBufferVtbl
*lppsfac
= &psfacbufvtbl
;
2300 /***********************************************************************
2301 * DllGetClassObject [OLE32.63]
2304 TypeLibFac_DllGetClassObject(REFCLSID rclsid
, REFIID iid
,LPVOID
*ppv
)
2306 if (IsEqualIID(iid
,&IID_IPSFactoryBuffer
)) {
2310 return E_NOINTERFACE
;