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
, tlfnlen
;
268 sprintf( interfacekey
, "Interface\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\Typelib",
269 riid
->Data1
, riid
->Data2
, riid
->Data3
,
270 riid
->Data4
[0], riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3],
271 riid
->Data4
[4], riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]
274 if (RegOpenKeyA(HKEY_CLASSES_ROOT
,interfacekey
,&ikey
)) {
275 ERR("No %s key found.\n",interfacekey
);
279 tlguidlen
= sizeof(tlguid
);
280 if (RegQueryValueExA(ikey
,NULL
,NULL
,&type
,tlguid
,&tlguidlen
)) {
281 ERR("Getting typelib guid failed.\n");
286 verlen
= sizeof(ver
);
287 if (RegQueryValueExA(ikey
,"Version",NULL
,&type
,ver
,&verlen
)) {
288 ERR("Could not get version value?\n");
293 sprintf(typelibkey
,"Typelib\\%s\\%s\\0\\win32",tlguid
,ver
);
294 tlfnlen
= sizeof(tlfn
);
295 if (RegQueryValueA(HKEY_CLASSES_ROOT
,typelibkey
,tlfn
,&tlfnlen
)) {
296 ERR("Could not get typelib fn?\n");
299 MultiByteToWideChar(CP_ACP
, 0, tlfn
, -1, tlfnW
, -1);
300 hres
= LoadTypeLib(tlfnW
,&tl
);
302 ERR("Failed to load typelib for %s, but it should be there.\n",debugstr_guid(riid
));
305 hres
= ITypeLib_GetTypeInfoOfGuid(tl
,riid
,ti
);
307 ERR("typelib does not contain info for %s?\n",debugstr_guid(riid
));
308 ITypeLib_Release(tl
);
311 /* FIXME: do this? ITypeLib_Release(tl); */
315 /* Determine nr of functions. Since we use the toplevel interface and all
316 * inherited ones have lower numbers, we are ok to not to descent into
317 * the inheritance tree I think.
319 static int _nroffuncs(ITypeInfo
*tinfo
) {
326 hres
= ITypeInfo_GetFuncDesc(tinfo
,n
,&fdesc
);
329 if (fdesc
->oVft
/4 > max
)
338 #include "pshpack1.h"
340 typedef struct _TMAsmProxy
{
354 # error You need to implement stubless proxies for your architecture
357 typedef struct _TMProxyImpl
{
359 IRpcProxyBufferVtbl
*lpvtbl2
;
362 TMAsmProxy
*asmstubs
;
364 IRpcChannelBuffer
* chanbuf
;
366 CRITICAL_SECTION crit
;
367 IUnknown
*outerunknown
;
370 static HRESULT WINAPI
371 TMProxyImpl_QueryInterface(LPRPCPROXYBUFFER iface
, REFIID riid
, LPVOID
*ppv
)
374 if (IsEqualIID(riid
,&IID_IUnknown
)||IsEqualIID(riid
,&IID_IRpcProxyBuffer
)) {
375 *ppv
= (LPVOID
)iface
;
376 IRpcProxyBuffer_AddRef(iface
);
379 FIXME("no interface for %s\n",debugstr_guid(riid
));
380 return E_NOINTERFACE
;
384 TMProxyImpl_AddRef(LPRPCPROXYBUFFER iface
)
386 ICOM_THIS_MULTI(TMProxyImpl
,lpvtbl2
,iface
);
387 ULONG refCount
= InterlockedIncrement(&This
->ref
);
389 TRACE("(%p)->(ref before=%lu)\n",This
, refCount
- 1);
395 TMProxyImpl_Release(LPRPCPROXYBUFFER iface
)
397 ICOM_THIS_MULTI(TMProxyImpl
,lpvtbl2
,iface
);
398 ULONG refCount
= InterlockedDecrement(&This
->ref
);
400 TRACE("(%p)->(ref before=%lu)\n",This
, refCount
+ 1);
404 DeleteCriticalSection(&This
->crit
);
405 if (This
->chanbuf
) IRpcChannelBuffer_Release(This
->chanbuf
);
406 VirtualFree(This
->asmstubs
, 0, MEM_RELEASE
);
412 static HRESULT WINAPI
414 LPRPCPROXYBUFFER iface
,IRpcChannelBuffer
* pRpcChannelBuffer
)
416 ICOM_THIS_MULTI(TMProxyImpl
, lpvtbl2
, iface
);
418 TRACE("(%p)\n", pRpcChannelBuffer
);
420 EnterCriticalSection(&This
->crit
);
422 IRpcChannelBuffer_AddRef(pRpcChannelBuffer
);
423 This
->chanbuf
= pRpcChannelBuffer
;
425 LeaveCriticalSection(&This
->crit
);
431 TMProxyImpl_Disconnect(LPRPCPROXYBUFFER iface
)
433 ICOM_THIS_MULTI(TMProxyImpl
, lpvtbl2
, iface
);
437 EnterCriticalSection(&This
->crit
);
439 IRpcChannelBuffer_Release(This
->chanbuf
);
440 This
->chanbuf
= NULL
;
442 LeaveCriticalSection(&This
->crit
);
446 static IRpcProxyBufferVtbl tmproxyvtable
= {
447 TMProxyImpl_QueryInterface
,
451 TMProxyImpl_Disconnect
454 /* how much space do we use on stack in DWORD steps. */
459 return sizeof(DATE
)/sizeof(DWORD
);
461 return (sizeof(VARIANT
)+3)/sizeof(DWORD
);
468 _xsize(TYPEDESC
*td
) {
473 return sizeof(VARIANT
)+3;
476 ARRAYDESC
*adesc
= td
->u
.lpadesc
;
478 for (i
=0;i
<adesc
->cDims
;i
++)
479 arrsize
*= adesc
->rgbounds
[i
].cElements
;
480 return arrsize
*_xsize(&adesc
->tdescElem
);
505 TRACE("(tdesc.vt %d)\n",tdesc
->vt
);
508 case VT_EMPTY
: /* nothing. empty variant for instance */
517 if (debugout
) TRACE_(olerelay
)("%lx",*arg
);
519 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
524 if (debugout
) TRACE_(olerelay
)("%04lx",*arg
& 0xffff);
526 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
531 if (debugout
) TRACE_(olerelay
)("%02lx",*arg
& 0xff);
533 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
537 if (debugout
) TRACE_(olerelay
)("&0x%lx",*arg
);
539 hres
= xbuf_add(buf
,(LPBYTE
)(DWORD
*)*arg
,sizeof(DWORD
));
540 /* do not dealloc at this time */
544 VARIANT
*vt
= (VARIANT
*)arg
;
545 DWORD vttype
= V_VT(vt
);
547 if (debugout
) TRACE_(olerelay
)("Vt(%ld)(",vttype
);
550 hres
= xbuf_add(buf
,(LPBYTE
)&vttype
,sizeof(vttype
));
551 if (hres
) return hres
;
553 /* need to recurse since we need to free the stuff */
554 hres
= serialize_param(tinfo
,writeit
,debugout
,dealloc
,&tdesc2
,&(V_I4(vt
)),buf
);
555 if (debugout
) TRACE_(olerelay
)(")");
558 case VT_BSTR
|VT_BYREF
: {
559 if (debugout
) TRACE_(olerelay
)("[byref]'%s'", *(BSTR
*)*arg
? relaystr(*((BSTR
*)*arg
)) : "<bstr NULL>");
561 /* ptr to ptr to magic widestring, basically */
562 BSTR
*bstr
= (BSTR
*) *arg
;
564 /* -1 means "null string" which is equivalent to empty string */
566 xbuf_add(buf
, (LPBYTE
)&fakelen
,4);
568 /* BSTRs store the length behind the first character */
569 DWORD
*len
= ((DWORD
*)(*bstr
))-1;
570 hres
= xbuf_add(buf
, (LPBYTE
) len
, *len
+ 4);
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>");
592 hres
= xbuf_add(buf
,(LPBYTE
)&fakelen
,4);
596 DWORD
*bstr
= ((DWORD
*)(*arg
))-1;
598 hres
= xbuf_add(buf
,(LPBYTE
)bstr
,bstr
[0]+4);
605 SysFreeString((BSTR
)*arg
);
611 if (debugout
) TRACE_(olerelay
)("*");
612 /* Write always, so the other side knows when it gets a NULL pointer.
614 cookie
= *arg
? 0x42424242 : 0;
615 hres
= xbuf_add(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
619 if (debugout
) TRACE_(olerelay
)("NULL");
622 hres
= serialize_param(tinfo
,writeit
,debugout
,dealloc
,tdesc
->u
.lptdesc
,(DWORD
*)*arg
,buf
);
623 if (dealloc
) HeapFree(GetProcessHeap(),0,(LPVOID
)arg
);
627 if (debugout
) TRACE_(olerelay
)("unk(0x%lx)",*arg
);
629 hres
= _marshal_interface(buf
,&IID_IUnknown
,(LPUNKNOWN
)*arg
);
632 if (debugout
) TRACE_(olerelay
)("idisp(0x%lx)",*arg
);
634 hres
= _marshal_interface(buf
,&IID_IDispatch
,(LPUNKNOWN
)*arg
);
637 if (debugout
) TRACE_(olerelay
)("<void>");
639 case VT_USERDEFINED
: {
643 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.hreftype
,&tinfo2
);
645 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc
->u
.hreftype
);
648 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
649 switch (tattr
->typekind
) {
651 case TKIND_INTERFACE
:
653 hres
=_marshal_interface(buf
,&(tattr
->guid
),(LPUNKNOWN
)arg
);
657 if (debugout
) TRACE_(olerelay
)("{");
658 for (i
=0;i
<tattr
->cVars
;i
++) {
663 hres
= ITypeInfo2_GetVarDesc(tinfo2
, i
, &vdesc
);
665 ERR("Could not get vardesc of %d\n",i
);
668 /* Need them for hack below */
670 memset(names,0,sizeof(names));
671 hres = ITypeInfo_GetNames(tinfo2,vdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
672 if (nrofnames > sizeof(names)/sizeof(names[0])) {
673 ERR("Need more names!\n");
675 if (!hres && debugout)
676 TRACE_(olerelay)("%s=",relaystr(names[0]));
678 elem2
= &vdesc
->elemdescVar
;
679 tdesc2
= &elem2
->tdesc
;
680 hres
= serialize_param(
686 (DWORD
*)(((LPBYTE
)arg
)+vdesc
->u
.oInst
),
691 if (debugout
&& (i
<(tattr
->cVars
-1)))
692 TRACE_(olerelay
)(",");
694 if (buf
->thisisiid
&& (tattr
->cbSizeInstance
==sizeof(GUID
)))
695 memcpy(&(buf
->iid
),arg
,sizeof(buf
->iid
));
696 if (debugout
) TRACE_(olerelay
)("}");
700 FIXME("Unhandled typekind %d\n",tattr
->typekind
);
704 ITypeInfo_Release(tinfo2
);
708 ARRAYDESC
*adesc
= tdesc
->u
.lpadesc
;
711 if (debugout
) TRACE_(olerelay
)("carr");
712 for (i
=0;i
<adesc
->cDims
;i
++) {
713 if (debugout
) TRACE_(olerelay
)("[%ld]",adesc
->rgbounds
[i
].cElements
);
714 arrsize
*= adesc
->rgbounds
[i
].cElements
;
716 if (debugout
) TRACE_(olerelay
)("(vt %d)",adesc
->tdescElem
.vt
);
717 if (debugout
) TRACE_(olerelay
)("[");
718 for (i
=0;i
<arrsize
;i
++) {
719 hres
= serialize_param(tinfo
, writeit
, debugout
, dealloc
, &adesc
->tdescElem
, (DWORD
*)((LPBYTE
)arg
+i
*_xsize(&adesc
->tdescElem
)), buf
);
722 if (debugout
&& (i
<arrsize
-1)) TRACE_(olerelay
)(",");
724 if (debugout
) TRACE_(olerelay
)("]");
728 ERR("Unhandled marshal type %d.\n",tdesc
->vt
);
734 * HRESULT GetIDsOfNames(
735 * [in] REFIID riid, args[1]
736 * [in, size_is(cNames)] LPOLESTR *rgszNames, args[2]
737 * [in] UINT cNames, args[3]
738 * [in] LCID lcid, args[4]
739 * [out, size_is(cNames)] DISPID *rgDispId); args[5]
744 * LPOLESTR rgszNames[cNames];
745 * DWORD bytestrlen (incl 0)
746 * BYTE data[bytestrlen] (incl 0)
750 serialize_IDispatch_GetIDsOfNames(
757 DWORD cNames
= args
[2];
758 LPOLESTR
*rgszNames
= (LPOLESTR
*)args
[1];
762 if (debugout
) TRACE_(olerelay
)("riid=%s,",debugstr_guid((REFIID
)args
[0]));
763 hres
= xbuf_add(buf
, (LPBYTE
)args
[0], sizeof(IID
));
765 FIXME("serialize of IID failed.\n");
768 if (debugout
) TRACE_(olerelay
)("cNames=%ld,",cNames
);
769 hres
= xbuf_add(buf
, (LPBYTE
)&cNames
, sizeof(DWORD
));
771 FIXME("serialize of cNames failed.\n");
774 if (debugout
) TRACE_(olerelay
)("rgszNames=[");
775 for (i
=0;i
<cNames
;i
++) {
776 DWORD len
= 2*(lstrlenW(rgszNames
[i
])+1);
778 if (debugout
) TRACE_(olerelay
)("%s,",relaystr(rgszNames
[i
]));
779 hres
= xbuf_add(buf
, (LPBYTE
)&len
, sizeof(DWORD
));
781 FIXME("serialize of len failed.\n");
784 hres
= xbuf_add(buf
, (LPBYTE
)rgszNames
[i
], len
);
786 FIXME("serialize of rgszNames[i] failed.\n");
790 if (debugout
) TRACE_(olerelay
)("],lcid=%04lx)",args
[3]);
791 hres
= xbuf_add(buf
, (LPBYTE
)&args
[3], sizeof(DWORD
));
793 FIXME("serialize of lcid failed.\n");
797 DISPID
*rgDispId
= (DISPID
*)args
[4];
799 hres
= xbuf_add(buf
, (LPBYTE
)rgDispId
, sizeof(DISPID
) * cNames
);
801 FIXME("serialize of rgDispId failed.\n");
805 TRACE_(olerelay
)("riid=[in],rgszNames=[in],cNames=[in],rgDispId=[");
806 for (i
=0;i
<cNames
;i
++)
807 TRACE_(olerelay
)("%08lx,",rgDispId
[i
]);
808 TRACE_(olerelay
)("])");
810 HeapFree(GetProcessHeap(),0,(IID
*)args
[0]);
811 rgszNames
= (LPOLESTR
*)args
[1];
812 for (i
=0;i
<cNames
;i
++) HeapFree(GetProcessHeap(),0,rgszNames
[i
]);
813 HeapFree(GetProcessHeap(),0,rgszNames
);
814 HeapFree(GetProcessHeap(),0,rgDispId
);
820 deserialize_IDispatch_GetIDsOfNames(
832 args
[0] = (DWORD
)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IID
));
833 if (!args
[0]) return E_FAIL
;
834 hres
= xbuf_get(buf
, (LPBYTE
)args
[0], sizeof(IID
));
836 FIXME("deserialize of IID failed.\n");
839 if (debugout
) TRACE_(olerelay
)("riid=%s,",debugstr_guid((REFIID
)args
[0]));
841 hres
= xbuf_get(buf
, (LPBYTE
)&cNames
, sizeof(DWORD
));
843 FIXME("deserialize of cNames failed.\n");
847 if (debugout
) TRACE_(olerelay
)("cNames=%ld,",cNames
);
848 if (debugout
) TRACE_(olerelay
)("rgszNames=[");
849 rgszNames
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(LPOLESTR
) * cNames
);
850 if (!rgszNames
) return E_FAIL
;
851 args
[1] = (DWORD
)rgszNames
;
852 for (i
=0;i
<cNames
;i
++) {
855 hres
= xbuf_get(buf
, (LPBYTE
)&len
, sizeof(DWORD
));
857 FIXME("serialize of len failed.\n");
860 rgszNames
[i
] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
862 FIXME("heapalloc of %ld bytes failed\n", len
);
865 hres
= xbuf_get(buf
, (LPBYTE
)rgszNames
[i
], len
);
867 FIXME("serialize of rgszNames[i] failed.\n");
870 if (debugout
) TRACE_(olerelay
)("%s,",relaystr(rgszNames
[i
]));
872 hres
= xbuf_get(buf
, (LPBYTE
)&args
[3], sizeof(DWORD
));
874 FIXME("deserialize of lcid failed.\n");
877 if (debugout
) TRACE_(olerelay
)("],lcid=%04lx,rgDispId=[out])",args
[3]);
878 args
[4] = (DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DISPID
) * cNames
);
880 hres
= xbuf_get(buf
, (LPBYTE
)args
[4], sizeof(DISPID
) * args
[2]);
882 FIXME("serialize of rgDispId failed.\n");
886 TRACE_(olerelay
)("dispid=[");
887 for (i
=0;i
<args
[2];i
++)
888 TRACE_(olerelay
)("%08lx,",((DISPID
*)args
[4])[i
]);
889 TRACE_(olerelay
)("])");
896 serialize_LPVOID_ptr(
908 if ((tdesc
->vt
!= VT_PTR
) ||
909 (tdesc
->u
.lptdesc
->vt
!= VT_PTR
) ||
910 (tdesc
->u
.lptdesc
->u
.lptdesc
->vt
!= VT_VOID
)
912 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
915 cookie
= (*(DWORD
*)*arg
) ? 0x42424242: 0x0;
917 hres
= xbuf_add(buf
, (LPVOID
)&cookie
, sizeof(cookie
));
921 if (!*(DWORD
*)*arg
) {
922 if (debugout
) TRACE_(olerelay
)("<lpvoid NULL>");
926 TRACE_(olerelay
)("ppv(%p)",*(LPUNKNOWN
*)*arg
);
928 hres
= _marshal_interface(buf
,&(buf
->iid
),*(LPUNKNOWN
*)*arg
);
933 HeapFree(GetProcessHeap(),0,(LPVOID
)*arg
);
938 serialize_DISPPARAM_ptr(
952 if ((tdesc
->vt
!= VT_PTR
) || (tdesc
->u
.lptdesc
->vt
!= VT_USERDEFINED
)) {
953 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
957 cookie
= *arg
? 0x42424242 : 0x0;
959 hres
= xbuf_add(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
964 if (debugout
) TRACE_(olerelay
)("<DISPPARAMS NULL>");
967 disp
= (DISPPARAMS
*)*arg
;
969 hres
= xbuf_add(buf
,(LPBYTE
)&disp
->cArgs
,sizeof(disp
->cArgs
));
973 if (debugout
) TRACE_(olerelay
)("D{");
974 for (i
=0;i
<disp
->cArgs
;i
++) {
977 vtdesc
.vt
= VT_VARIANT
;
984 (DWORD
*)(disp
->rgvarg
+i
),
987 if (debugout
&& (i
<disp
->cArgs
-1))
988 TRACE_(olerelay
)(",");
991 HeapFree(GetProcessHeap(),0,disp
->rgvarg
);
993 hres
= xbuf_add(buf
,(LPBYTE
)&disp
->cNamedArgs
,sizeof(disp
->cNamedArgs
));
997 if (debugout
) TRACE_(olerelay
)("}{");
998 for (i
=0;i
<disp
->cNamedArgs
;i
++) {
1001 vtdesc
.vt
= VT_UINT
;
1008 (DWORD
*)(disp
->rgdispidNamedArgs
+i
),
1011 if (debugout
&& (i
<disp
->cNamedArgs
-1))
1012 TRACE_(olerelay
)(",");
1014 if (debugout
) TRACE_(olerelay
)("}");
1016 HeapFree(GetProcessHeap(),0,disp
->rgdispidNamedArgs
);
1017 HeapFree(GetProcessHeap(),0,disp
);
1032 HRESULT hres
= S_OK
;
1034 TRACE("vt %d at %p\n",tdesc
->vt
,arg
);
1037 switch (tdesc
->vt
) {
1039 if (debugout
) TRACE_(olerelay
)("<empty>");
1042 if (debugout
) TRACE_(olerelay
)("<null>");
1045 VARIANT
*vt
= (VARIANT
*)arg
;
1050 hres
= xbuf_get(buf
,(LPBYTE
)&vttype
,sizeof(vttype
));
1052 FIXME("vt type not read?\n");
1055 memset(&tdesc2
,0,sizeof(tdesc2
));
1058 if (debugout
) TRACE_(olerelay
)("Vt(%ld)(",vttype
);
1059 hres
= deserialize_param(tinfo
, readit
, debugout
, alloc
, &tdesc2
, &(V_I4(vt
)), buf
);
1060 TRACE_(olerelay
)(")");
1074 hres
= xbuf_get(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
1075 if (hres
) ERR("Failed to read integer 4 byte\n");
1077 if (debugout
) TRACE_(olerelay
)("%lx",*arg
);
1083 hres
= xbuf_get(buf
,(LPBYTE
)&x
,sizeof(DWORD
));
1084 if (hres
) ERR("Failed to read integer 4 byte\n");
1087 if (debugout
) TRACE_(olerelay
)("%04lx",*arg
& 0xffff);
1093 hres
= xbuf_get(buf
,(LPBYTE
)&x
,sizeof(DWORD
));
1094 if (hres
) ERR("Failed to read integer 4 byte\n");
1097 if (debugout
) TRACE_(olerelay
)("%02lx",*arg
& 0xff);
1099 case VT_I4
|VT_BYREF
:
1102 *arg
= (DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DWORD
));
1104 hres
= xbuf_get(buf
,(LPBYTE
)*arg
,sizeof(DWORD
));
1105 if (hres
) ERR("Failed to read integer 4 byte\n");
1107 if (debugout
) TRACE_(olerelay
)("&0x%lx",*(DWORD
*)*arg
);
1109 case VT_BSTR
|VT_BYREF
: {
1110 BSTR
**bstr
= (BSTR
**)arg
;
1115 hres
= xbuf_get(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
1117 ERR("failed to read bstr klen\n");
1121 *bstr
= CoTaskMemAlloc(sizeof(BSTR
*));
1123 if (debugout
) TRACE_(olerelay
)("<bstr NULL>");
1125 str
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,len
+sizeof(WCHAR
));
1126 hres
= xbuf_get(buf
,(LPBYTE
)str
,len
);
1128 ERR("Failed to read BSTR.\n");
1131 *bstr
= CoTaskMemAlloc(sizeof(BSTR
*));
1132 **bstr
= SysAllocStringLen(str
,len
);
1133 if (debugout
) TRACE_(olerelay
)("%s",relaystr(str
));
1134 HeapFree(GetProcessHeap(),0,str
);
1146 hres
= xbuf_get(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
1148 ERR("failed to read bstr klen\n");
1153 if (debugout
) TRACE_(olerelay
)("<bstr NULL>");
1155 str
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,len
+sizeof(WCHAR
));
1156 hres
= xbuf_get(buf
,(LPBYTE
)str
,len
);
1158 ERR("Failed to read BSTR.\n");
1161 *arg
= (DWORD
)SysAllocStringLen(str
,len
);
1162 if (debugout
) TRACE_(olerelay
)("%s",relaystr(str
));
1163 HeapFree(GetProcessHeap(),0,str
);
1174 derefhere
= (tdesc
->u
.lptdesc
->vt
!= VT_USERDEFINED
);
1175 /* read it in all cases, we need to know if we have
1176 * NULL pointer or not.
1178 hres
= xbuf_get(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
1180 ERR("Failed to load pointer cookie.\n");
1183 if (cookie
!= 0x42424242) {
1184 /* we read a NULL ptr from the remote side */
1185 if (debugout
) TRACE_(olerelay
)("NULL");
1189 if (debugout
) TRACE_(olerelay
)("*");
1191 /* Allocate space for the referenced struct */
1193 *arg
=(DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,_xsize(tdesc
->u
.lptdesc
));
1196 return deserialize_param(tinfo
, readit
, debugout
, alloc
, tdesc
->u
.lptdesc
, (LPDWORD
)*arg
, buf
);
1198 return deserialize_param(tinfo
, readit
, debugout
, alloc
, tdesc
->u
.lptdesc
, arg
, buf
);
1201 /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
1203 *arg
=(DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DWORD
));
1206 hres
= _unmarshal_interface(buf
,&IID_IUnknown
,(LPUNKNOWN
*)arg
);
1208 TRACE_(olerelay
)("unk(%p)",arg
);
1213 hres
= _unmarshal_interface(buf
,&IID_IDispatch
,(LPUNKNOWN
*)arg
);
1215 TRACE_(olerelay
)("idisp(%p)",arg
);
1218 if (debugout
) TRACE_(olerelay
)("<void>");
1220 case VT_USERDEFINED
: {
1224 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.hreftype
,&tinfo2
);
1226 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc
->u
.hreftype
);
1229 hres
= ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
1231 ERR("Could not get typeattr in VT_USERDEFINED.\n");
1233 switch (tattr
->typekind
) {
1234 case TKIND_DISPATCH
:
1235 case TKIND_INTERFACE
:
1237 hres
= _unmarshal_interface(buf
,&(tattr
->guid
),(LPUNKNOWN
*)arg
);
1239 case TKIND_RECORD
: {
1243 *arg
= (DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,tattr
->cbSizeInstance
);
1245 if (debugout
) TRACE_(olerelay
)("{");
1246 for (i
=0;i
<tattr
->cVars
;i
++) {
1249 hres
= ITypeInfo2_GetVarDesc(tinfo2
, i
, &vdesc
);
1251 ERR("Could not get vardesc of %d\n",i
);
1254 hres
= deserialize_param(
1259 &vdesc
->elemdescVar
.tdesc
,
1260 (DWORD
*)(((LPBYTE
)*arg
)+vdesc
->u
.oInst
),
1263 if (debugout
&& (i
<tattr
->cVars
-1)) TRACE_(olerelay
)(",");
1265 if (buf
->thisisiid
&& (tattr
->cbSizeInstance
==sizeof(GUID
)))
1266 memcpy(&(buf
->iid
),(LPBYTE
)*arg
,sizeof(buf
->iid
));
1267 if (debugout
) TRACE_(olerelay
)("}");
1271 ERR("Unhandled typekind %d\n",tattr
->typekind
);
1277 ERR("failed to stuballoc in TKIND_RECORD.\n");
1278 ITypeInfo_Release(tinfo2
);
1282 /* arg is pointing to the start of the array. */
1283 ARRAYDESC
*adesc
= tdesc
->u
.lpadesc
;
1286 if (adesc
->cDims
> 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
1287 for (i
=0;i
<adesc
->cDims
;i
++)
1288 arrsize
*= adesc
->rgbounds
[i
].cElements
;
1289 for (i
=0;i
<arrsize
;i
++)
1296 (DWORD
*)((LPBYTE
)(arg
)+i
*_xsize(&adesc
->tdescElem
)),
1302 ERR("No handler for VT type %d!\n",tdesc
->vt
);
1309 deserialize_LPVOID_ptr(
1321 if ((tdesc
->vt
!= VT_PTR
) ||
1322 (tdesc
->u
.lptdesc
->vt
!= VT_PTR
) ||
1323 (tdesc
->u
.lptdesc
->u
.lptdesc
->vt
!= VT_VOID
)
1325 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
1329 *arg
=(DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(LPVOID
));
1331 hres
= xbuf_get(buf
, (LPVOID
)&cookie
, sizeof(cookie
));
1334 if (cookie
!= 0x42424242) {
1336 if (debugout
) TRACE_(olerelay
)("<lpvoid NULL>");
1341 hres
= _unmarshal_interface(buf
,&buf
->iid
,(LPUNKNOWN
*)*arg
);
1343 FIXME("_unmarshal_interface of %s , %p failed with %lx\n", debugstr_guid(&buf
->iid
), (LPUNKNOWN
*)*arg
, hres
);
1347 if (debugout
) TRACE_(olerelay
)("ppv(%p)",(LPVOID
)*arg
);
1352 deserialize_DISPPARAM_ptr(
1366 if ((tdesc
->vt
!= VT_PTR
) || (tdesc
->u
.lptdesc
->vt
!= VT_USERDEFINED
)) {
1367 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
1371 hres
= xbuf_get(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
1376 if (debugout
) TRACE_(olerelay
)("<DISPPARAMS NULL>");
1381 *arg
= (DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DISPPARAMS
));
1382 disps
= (DISPPARAMS
*)*arg
;
1385 hres
= xbuf_get(buf
, (LPBYTE
)&disps
->cArgs
, sizeof(disps
->cArgs
));
1389 disps
->rgvarg
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(VARIANT
)*disps
->cArgs
);
1390 if (debugout
) TRACE_(olerelay
)("D{");
1391 for (i
=0; i
< disps
->cArgs
; i
++) {
1394 vdesc
.vt
= VT_VARIANT
;
1395 hres
= deserialize_param(
1401 (DWORD
*)(disps
->rgvarg
+i
),
1405 if (debugout
) TRACE_(olerelay
)("}{");
1406 hres
= xbuf_get(buf
, (LPBYTE
)&disps
->cNamedArgs
, sizeof(disps
->cNamedArgs
));
1409 if (disps
->cNamedArgs
) {
1411 disps
->rgdispidNamedArgs
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DISPID
)*disps
->cNamedArgs
);
1412 for (i
=0; i
< disps
->cNamedArgs
; i
++) {
1416 hres
= deserialize_param(
1422 (DWORD
*)(disps
->rgdispidNamedArgs
+i
),
1425 if (debugout
&& i
<(disps
->cNamedArgs
-1)) TRACE_(olerelay
)(",");
1428 if (debugout
) TRACE_(olerelay
)("}");
1432 /* Searches function, also in inherited interfaces */
1435 ITypeInfo
*tinfo
, int iMethod
, FUNCDESC
**fdesc
, BSTR
*iname
, BSTR
*fname
)
1440 if (fname
) *fname
= NULL
;
1441 if (iname
) *iname
= NULL
;
1444 hres
= ITypeInfo_GetFuncDesc(tinfo
, i
, fdesc
);
1450 hres
= ITypeInfo_GetTypeAttr(tinfo
, &attr
);
1452 ERR("GetTypeAttr failed with %lx\n",hres
);
1455 /* Not found, so look in inherited ifaces. */
1456 for (j
=0;j
<attr
->cImplTypes
;j
++) {
1457 hres
= ITypeInfo_GetRefTypeOfImplType(tinfo
, j
, &href
);
1459 ERR("Did not find a reftype for interface offset %d?\n",j
);
1462 hres
= ITypeInfo_GetRefTypeInfo(tinfo
, href
, &tinfo2
);
1464 ERR("Did not find a typeinfo for reftype %ld?\n",href
);
1467 hres
= _get_funcdesc(tinfo2
,iMethod
,fdesc
,iname
,fname
);
1468 ITypeInfo_Release(tinfo2
);
1469 if (!hres
) return S_OK
;
1473 if (((*fdesc
)->oVft
/4) == iMethod
) {
1475 ITypeInfo_GetDocumentation(tinfo
,(*fdesc
)->memid
,fname
,NULL
,NULL
,NULL
);
1477 ITypeInfo_GetDocumentation(tinfo
,-1,iname
,NULL
,NULL
,NULL
);
1485 xCall(LPVOID retptr
, int method
, TMProxyImpl
*tpinfo
/*, args */)
1487 DWORD
*args
= ((DWORD
*)&tpinfo
)+1, *xargs
;
1490 int i
, relaydeb
= TRACE_ON(olerelay
);
1497 int is_idispatch_getidsofnames
= 0;
1498 DWORD remoteresult
= 0;
1500 EnterCriticalSection(&tpinfo
->crit
);
1502 hres
= _get_funcdesc(tpinfo
->tinfo
,method
,&fdesc
,&iname
,&fname
);
1504 ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method
);
1505 LeaveCriticalSection(&tpinfo
->crit
);
1509 if (!tpinfo
->chanbuf
)
1511 WARN("Tried to use disconnected proxy\n");
1512 LeaveCriticalSection(&tpinfo
->crit
);
1513 return RPC_E_DISCONNECTED
;
1517 TRACE_(olerelay
)("->");
1519 TRACE_(olerelay
)("%s:",relaystr(iname
));
1521 TRACE_(olerelay
)("%s(%d)",relaystr(fname
),method
);
1523 TRACE_(olerelay
)("%d",method
);
1524 TRACE_(olerelay
)("(");
1526 if (iname
&& fname
&& !lstrcmpW(iname
,IDispatchW
) && !lstrcmpW(fname
,GetIDsOfNamesW
))
1527 is_idispatch_getidsofnames
= 1;
1529 if (iname
) SysFreeString(iname
);
1530 if (fname
) SysFreeString(fname
);
1532 memset(&buf
,0,sizeof(buf
));
1533 buf
.iid
= IID_IUnknown
;
1535 /* Special IDispatch::GetIDsOfNames() serializer */
1536 if (is_idispatch_getidsofnames
) {
1537 hres
= serialize_IDispatch_GetIDsOfNames(TRUE
,relaydeb
,args
,&buf
);
1539 FIXME("serialize of IDispatch::GetIDsOfNames failed!\n");
1542 goto afterserialize
;
1545 /* special QueryInterface serialize */
1547 xbuf_add(&buf
,(LPBYTE
)args
[0],sizeof(IID
));
1548 if (relaydeb
) TRACE_(olerelay
)("riid=%s,[out])",debugstr_guid((REFIID
)args
[0]));
1549 goto afterserialize
;
1552 /* normal typelib driven serializing */
1554 /* Need them for hack below */
1555 memset(names
,0,sizeof(names
));
1556 if (ITypeInfo_GetNames(tpinfo
->tinfo
,fdesc
->memid
,names
,sizeof(names
)/sizeof(names
[0]),&nrofnames
))
1558 if (nrofnames
> sizeof(names
)/sizeof(names
[0]))
1559 ERR("Need more names!\n");
1562 for (i
=0;i
<fdesc
->cParams
;i
++) {
1563 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1564 BOOL isserialized
= FALSE
;
1566 if (i
) TRACE_(olerelay
)(",");
1567 if (i
+1<nrofnames
&& names
[i
+1])
1568 TRACE_(olerelay
)("%s=",relaystr(names
[i
+1]));
1570 /* No need to marshal other data than FIN and any VT_PTR. */
1571 if (!(elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
) && (elem
->tdesc
.vt
!= VT_PTR
)) {
1572 xargs
+=_argsize(elem
->tdesc
.vt
);
1573 if (relaydeb
) TRACE_(olerelay
)("[out]");
1576 if (((i
+1)<nrofnames
) && !IsBadStringPtrW(names
[i
+1],1)) {
1577 /* If the parameter is 'riid', we use it as interface IID
1578 * for a later ppvObject serialization.
1580 buf
.thisisiid
= !lstrcmpW(names
[i
+1],riidW
);
1582 /* DISPPARAMS* needs special serializer */
1583 if (!lstrcmpW(names
[i
+1],pdispparamsW
)) {
1584 hres
= serialize_DISPPARAM_ptr(
1586 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
1593 isserialized
= TRUE
;
1595 if (!lstrcmpW(names
[i
+1],ppvObjectW
)) {
1596 hres
= serialize_LPVOID_ptr(
1598 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
1606 isserialized
= TRUE
;
1610 hres
= serialize_param(
1612 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
1621 ERR("Failed to serialize param, hres %lx\n",hres
);
1624 xargs
+=_argsize(elem
->tdesc
.vt
);
1626 if (relaydeb
) TRACE_(olerelay
)(")");
1629 memset(&msg
,0,sizeof(msg
));
1630 msg
.cbBuffer
= buf
.curoff
;
1631 msg
.iMethod
= method
;
1632 hres
= IRpcChannelBuffer_GetBuffer(tpinfo
->chanbuf
,&msg
,&(tpinfo
->iid
));
1634 ERR("RpcChannelBuffer GetBuffer failed, %lx\n",hres
);
1635 LeaveCriticalSection(&tpinfo
->crit
);
1638 memcpy(msg
.Buffer
,buf
.base
,buf
.curoff
);
1639 if (relaydeb
) TRACE_(olerelay
)("\n");
1640 hres
= IRpcChannelBuffer_SendReceive(tpinfo
->chanbuf
,&msg
,&status
);
1642 ERR("RpcChannelBuffer SendReceive failed, %lx\n",hres
);
1643 LeaveCriticalSection(&tpinfo
->crit
);
1647 if (relaydeb
) TRACE_(olerelay
)(" status = %08lx (",status
);
1649 buf
.base
= HeapReAlloc(GetProcessHeap(),0,buf
.base
,msg
.cbBuffer
);
1651 buf
.base
= HeapAlloc(GetProcessHeap(),0,msg
.cbBuffer
);
1652 buf
.size
= msg
.cbBuffer
;
1653 memcpy(buf
.base
,msg
.Buffer
,buf
.size
);
1656 /* Special IDispatch::GetIDsOfNames() deserializer */
1657 if (is_idispatch_getidsofnames
) {
1658 hres
= deserialize_IDispatch_GetIDsOfNames(FALSE
,relaydeb
,args
,&buf
);
1660 FIXME("deserialize of IDispatch::GetIDsOfNames failed!\n");
1663 goto after_deserialize
;
1665 /* Special QueryInterface deserializer */
1667 _unmarshal_interface(&buf
,(REFIID
)args
[0],(LPUNKNOWN
*)args
[1]);
1668 if (relaydeb
) TRACE_(olerelay
)("[in],%p",*((DWORD
**)args
[1]));
1669 goto after_deserialize
;
1672 /* generic deserializer using typelib description */
1675 for (i
=0;i
<fdesc
->cParams
;i
++) {
1676 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1677 BOOL isdeserialized
= FALSE
;
1680 if (i
) TRACE_(olerelay
)(",");
1681 if (i
+1<nrofnames
&& names
[i
+1]) TRACE_(olerelay
)("%s=",relaystr(names
[i
+1]));
1683 /* No need to marshal other data than FOUT and any VT_PTR */
1684 if (!(elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
) && (elem
->tdesc
.vt
!= VT_PTR
)) {
1685 xargs
+= _argsize(elem
->tdesc
.vt
);
1686 if (relaydeb
) TRACE_(olerelay
)("[in]");
1689 if (((i
+1)<nrofnames
) && !IsBadStringPtrW(names
[i
+1],1)) {
1690 /* If the parameter is 'riid', we use it as interface IID
1691 * for a later ppvObject serialization.
1693 buf
.thisisiid
= !lstrcmpW(names
[i
+1],riidW
);
1695 /* deserialize DISPPARAM */
1696 if (!lstrcmpW(names
[i
+1],pdispparamsW
)) {
1697 hres
= deserialize_DISPPARAM_ptr(
1699 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
1707 ERR("Failed to deserialize DISPPARAM*, hres %lx\n",hres
);
1710 isdeserialized
= TRUE
;
1712 if (!lstrcmpW(names
[i
+1],ppvObjectW
)) {
1713 hres
= deserialize_LPVOID_ptr(
1715 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
1723 isdeserialized
= TRUE
;
1726 if (!isdeserialized
)
1727 hres
= deserialize_param(
1729 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
1737 ERR("Failed to unmarshall param, hres %lx\n",hres
);
1741 xargs
+= _argsize(elem
->tdesc
.vt
);
1744 hres
= xbuf_get(&buf
, (LPBYTE
)&remoteresult
, sizeof(DWORD
));
1747 if (relaydeb
) TRACE_(olerelay
)(") = %08lx\n", remoteresult
);
1749 if (status
!= S_OK
) /* OLE/COM internal error */
1752 HeapFree(GetProcessHeap(),0,buf
.base
);
1753 LeaveCriticalSection(&tpinfo
->crit
);
1754 return remoteresult
;
1757 HRESULT WINAPI
ProxyIUnknown_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
1759 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1761 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
1763 if (proxy
->outerunknown
)
1764 return IUnknown_QueryInterface(proxy
->outerunknown
, riid
, ppv
);
1766 FIXME("No interface\n");
1767 return E_NOINTERFACE
;
1770 ULONG WINAPI
ProxyIUnknown_AddRef(IUnknown
*iface
)
1772 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1776 if (proxy
->outerunknown
)
1777 return IUnknown_AddRef(proxy
->outerunknown
);
1779 return 2; /* FIXME */
1782 ULONG WINAPI
ProxyIUnknown_Release(IUnknown
*iface
)
1784 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1788 if (proxy
->outerunknown
)
1789 return IUnknown_Release(proxy
->outerunknown
);
1791 return 1; /* FIXME */
1794 static HRESULT WINAPI
1795 PSFacBuf_CreateProxy(
1796 LPPSFACTORYBUFFER iface
, IUnknown
* pUnkOuter
, REFIID riid
,
1797 IRpcProxyBuffer
**ppProxy
, LPVOID
*ppv
)
1805 TRACE("(...%s...)\n",debugstr_guid(riid
));
1806 hres
= _get_typeinfo_for_iid(riid
,&tinfo
);
1808 ERR("No typeinfo for %s?\n",debugstr_guid(riid
));
1811 nroffuncs
= _nroffuncs(tinfo
);
1812 proxy
= CoTaskMemAlloc(sizeof(TMProxyImpl
));
1813 if (!proxy
) return E_OUTOFMEMORY
;
1815 assert(sizeof(TMAsmProxy
) == 12);
1817 proxy
->outerunknown
= pUnkOuter
;
1818 proxy
->asmstubs
= VirtualAlloc(NULL
, sizeof(TMAsmProxy
) * nroffuncs
, MEM_COMMIT
, PAGE_EXECUTE_READWRITE
);
1819 if (!proxy
->asmstubs
) {
1820 ERR("Could not commit pages for proxy thunks\n");
1821 CoTaskMemFree(proxy
);
1822 return E_OUTOFMEMORY
;
1825 InitializeCriticalSection(&proxy
->crit
);
1827 proxy
->lpvtbl
= HeapAlloc(GetProcessHeap(),0,sizeof(LPBYTE
)*nroffuncs
);
1828 for (i
=0;i
<nroffuncs
;i
++) {
1829 TMAsmProxy
*xasm
= proxy
->asmstubs
+i
;
1833 proxy
->lpvtbl
[i
] = ProxyIUnknown_QueryInterface
;
1836 proxy
->lpvtbl
[i
] = ProxyIUnknown_AddRef
;
1839 proxy
->lpvtbl
[i
] = ProxyIUnknown_Release
;
1843 /* nrofargs without This */
1845 hres
= _get_funcdesc(tinfo
,i
,&fdesc
,NULL
,NULL
);
1847 ERR("GetFuncDesc %lx should not fail here.\n",hres
);
1850 /* some args take more than 4 byte on the stack */
1852 for (j
=0;j
<fdesc
->cParams
;j
++)
1853 nrofargs
+= _argsize(fdesc
->lprgelemdescParam
[j
].tdesc
.vt
);
1855 if (fdesc
->callconv
!= CC_STDCALL
) {
1856 ERR("calling convention is not stdcall????\n");
1859 /* popl %eax - return ptr
1866 * arg3 arg2 arg1 <method> <returnptr>
1868 xasm
->popleax
= 0x58;
1869 xasm
->pushlval
= 0x6a;
1871 xasm
->pushleax
= 0x50;
1872 xasm
->lcall
= 0xe8; /* relative jump */
1873 xasm
->xcall
= (DWORD
)xCall
;
1874 xasm
->xcall
-= (DWORD
)&(xasm
->lret
);
1876 xasm
->bytestopop
= (nrofargs
+2)*4; /* pop args, This, iMethod */
1877 proxy
->lpvtbl
[i
] = xasm
;
1882 proxy
->lpvtbl2
= &tmproxyvtable
;
1883 /* 1 reference for the proxy and 1 for the object */
1885 proxy
->tinfo
= tinfo
;
1886 memcpy(&proxy
->iid
,riid
,sizeof(*riid
));
1888 *ppv
= (LPVOID
)proxy
;
1889 *ppProxy
= (IRpcProxyBuffer
*)&(proxy
->lpvtbl2
);
1893 typedef struct _TMStubImpl
{
1894 IRpcStubBufferVtbl
*lpvtbl
;
1902 static HRESULT WINAPI
1903 TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface
, REFIID riid
, LPVOID
*ppv
)
1905 if (IsEqualIID(riid
,&IID_IRpcStubBuffer
)||IsEqualIID(riid
,&IID_IUnknown
)){
1906 *ppv
= (LPVOID
)iface
;
1907 IRpcStubBuffer_AddRef(iface
);
1910 FIXME("%s, not supported IID.\n",debugstr_guid(riid
));
1911 return E_NOINTERFACE
;
1915 TMStubImpl_AddRef(LPRPCSTUBBUFFER iface
)
1917 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1918 ULONG refCount
= InterlockedIncrement(&This
->ref
);
1920 TRACE("(%p)->(ref before=%lu)\n", This
, refCount
- 1);
1926 TMStubImpl_Release(LPRPCSTUBBUFFER iface
)
1928 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1929 ULONG refCount
= InterlockedDecrement(&This
->ref
);
1931 TRACE("(%p)->(ref before=%lu)\n", This
, refCount
+ 1);
1935 IRpcStubBuffer_Disconnect(iface
);
1936 CoTaskMemFree(This
);
1941 static HRESULT WINAPI
1942 TMStubImpl_Connect(LPRPCSTUBBUFFER iface
, LPUNKNOWN pUnkServer
)
1944 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1946 TRACE("(%p)->(%p)\n", This
, pUnkServer
);
1948 IUnknown_AddRef(pUnkServer
);
1949 This
->pUnk
= pUnkServer
;
1954 TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface
)
1956 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1958 TRACE("(%p)->()\n", This
);
1960 IUnknown_Release(This
->pUnk
);
1965 static HRESULT WINAPI
1967 LPRPCSTUBBUFFER iface
, RPCOLEMESSAGE
* xmsg
,IRpcChannelBuffer
*rpcchanbuf
)
1971 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1973 DWORD
*args
, res
, *xargs
, nrofargs
;
1977 BSTR fname
= NULL
,iname
= NULL
;
1978 BOOL is_idispatch_getidsofnames
= 0;
1980 memset(&buf
,0,sizeof(buf
));
1981 buf
.size
= xmsg
->cbBuffer
;
1982 buf
.base
= HeapAlloc(GetProcessHeap(), 0, xmsg
->cbBuffer
);
1983 memcpy(buf
.base
, xmsg
->Buffer
, xmsg
->cbBuffer
);
1985 buf
.iid
= IID_IUnknown
;
1988 if (xmsg
->iMethod
== 0) { /* QI */
1990 /* in: IID, out: <iface> */
1992 xbuf_get(&buf
,(LPBYTE
)&xiid
,sizeof(xiid
));
1994 hres
= _marshal_interface(&buf
,&xiid
,This
->pUnk
);
1995 xmsg
->Buffer
= buf
.base
; /* Might have been reallocated */
1996 xmsg
->cbBuffer
= buf
.size
;
1999 hres
= _get_funcdesc(This
->tinfo
,xmsg
->iMethod
,&fdesc
,&iname
,&fname
);
2001 ERR("GetFuncDesc on method %ld failed with %lx\n",xmsg
->iMethod
,hres
);
2005 if (iname
&& fname
&& !lstrcmpW(iname
, IDispatchW
) && !lstrcmpW(fname
, GetIDsOfNamesW
))
2006 is_idispatch_getidsofnames
= 1;
2008 if (iname
) SysFreeString (iname
);
2009 if (fname
) SysFreeString (fname
);
2011 /* Need them for hack below */
2012 memset(names
,0,sizeof(names
));
2013 ITypeInfo_GetNames(This
->tinfo
,fdesc
->memid
,names
,sizeof(names
)/sizeof(names
[0]),&nrofnames
);
2014 if (nrofnames
> sizeof(names
)/sizeof(names
[0])) {
2015 ERR("Need more names!\n");
2018 /*dump_FUNCDESC(fdesc);*/
2020 for (i
=0;i
<fdesc
->cParams
;i
++)
2021 nrofargs
+= _argsize(fdesc
->lprgelemdescParam
[i
].tdesc
.vt
);
2022 args
= HeapAlloc(GetProcessHeap(),0,(nrofargs
+1)*sizeof(DWORD
));
2023 if (!args
) return E_OUTOFMEMORY
;
2025 if (is_idispatch_getidsofnames
) {
2026 hres
= deserialize_IDispatch_GetIDsOfNames(TRUE
,FALSE
,args
+1,&buf
);
2028 FIXME("deserialize_IDispatch_GetIDsOfNames failed!\n");
2032 goto afterdeserialize
;
2035 /* Allocate all stuff used by call. */
2037 for (i
=0;i
<fdesc
->cParams
;i
++) {
2038 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
2039 BOOL isdeserialized
= FALSE
;
2041 if (((i
+1)<nrofnames
) && !IsBadStringPtrW(names
[i
+1],1)) {
2042 /* If the parameter is 'riid', we use it as interface IID
2043 * for a later ppvObject serialization.
2045 buf
.thisisiid
= !lstrcmpW(names
[i
+1],riidW
);
2047 /* deserialize DISPPARAM */
2048 if (!lstrcmpW(names
[i
+1],pdispparamsW
)) {
2049 hres
= deserialize_DISPPARAM_ptr(
2051 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
2059 ERR("Failed to deserialize DISPPARAM*, hres %lx\n",hres
);
2062 isdeserialized
= TRUE
;
2064 if (!lstrcmpW(names
[i
+1],ppvObjectW
)) {
2065 hres
= deserialize_LPVOID_ptr(
2067 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
2075 isdeserialized
= TRUE
;
2078 if (!isdeserialized
)
2079 hres
= deserialize_param(
2081 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
2088 xargs
+= _argsize(elem
->tdesc
.vt
);
2090 ERR("Failed to deserialize param %s, hres %lx\n",relaystr(names
[i
+1]),hres
);
2095 hres
= IUnknown_QueryInterface(This
->pUnk
,&(This
->iid
),(LPVOID
*)&(args
[0]));
2097 ERR("Does not support iface %s, returning %lx\n",debugstr_guid(&(This
->iid
)), hres
);
2101 (*((FARPROC
**)args
[0]))[fdesc
->oVft
/4],
2106 IUnknown_Release((LPUNKNOWN
)args
[0]);
2109 /* special IDispatch::GetIDsOfNames serializer */
2110 if (is_idispatch_getidsofnames
) {
2111 hres
= serialize_IDispatch_GetIDsOfNames(FALSE
,FALSE
,args
+1,&buf
);
2113 FIXME("serialize of IDispatch::GetIDsOfNames failed!\n");
2116 goto afterserialize
;
2119 for (i
=0;i
<fdesc
->cParams
;i
++) {
2120 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
2121 BOOL isserialized
= FALSE
;
2123 if (((i
+1)<nrofnames
) && !IsBadStringPtrW(names
[i
+1],1)) {
2124 /* If the parameter is 'riid', we use it as interface IID
2125 * for a later ppvObject serialization.
2127 buf
.thisisiid
= !lstrcmpW(names
[i
+1],riidW
);
2129 /* DISPPARAMS* needs special serializer */
2130 if (!lstrcmpW(names
[i
+1],pdispparamsW
)) {
2131 hres
= serialize_DISPPARAM_ptr(
2133 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
2140 isserialized
= TRUE
;
2142 if (!lstrcmpW(names
[i
+1],ppvObjectW
)) {
2143 hres
= serialize_LPVOID_ptr(
2145 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
2153 isserialized
= TRUE
;
2157 hres
= serialize_param(
2159 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
2166 xargs
+= _argsize(elem
->tdesc
.vt
);
2168 ERR("Failed to stuballoc param, hres %lx\n",hres
);
2173 hres
= xbuf_add (&buf
, (LPBYTE
)&res
, sizeof(DWORD
));
2177 xmsg
->cbBuffer
= buf
.curoff
;
2178 I_RpcGetBuffer((RPC_MESSAGE
*)xmsg
);
2179 memcpy(xmsg
->Buffer
, buf
.base
, buf
.curoff
);
2180 HeapFree(GetProcessHeap(),0,args
);
2184 static LPRPCSTUBBUFFER WINAPI
2185 TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface
, REFIID riid
) {
2186 FIXME("Huh (%s)?\n",debugstr_guid(riid
));
2191 TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface
) {
2192 TMStubImpl
*This
= (TMStubImpl
*)iface
;
2194 return This
->ref
; /*FIXME? */
2197 static HRESULT WINAPI
2198 TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface
, LPVOID
*ppv
) {
2203 TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface
, LPVOID ppv
) {
2207 IRpcStubBufferVtbl tmstubvtbl
= {
2208 TMStubImpl_QueryInterface
,
2212 TMStubImpl_Disconnect
,
2214 TMStubImpl_IsIIDSupported
,
2215 TMStubImpl_CountRefs
,
2216 TMStubImpl_DebugServerQueryInterface
,
2217 TMStubImpl_DebugServerRelease
2220 static HRESULT WINAPI
2221 PSFacBuf_CreateStub(
2222 LPPSFACTORYBUFFER iface
, REFIID riid
,IUnknown
*pUnkServer
,
2223 IRpcStubBuffer
** ppStub
2229 TRACE("(%s,%p,%p)\n",debugstr_guid(riid
),pUnkServer
,ppStub
);
2230 hres
= _get_typeinfo_for_iid(riid
,&tinfo
);
2232 ERR("No typeinfo for %s?\n",debugstr_guid(riid
));
2235 stub
= CoTaskMemAlloc(sizeof(TMStubImpl
));
2237 return E_OUTOFMEMORY
;
2238 stub
->lpvtbl
= &tmstubvtbl
;
2240 stub
->tinfo
= tinfo
;
2241 memcpy(&(stub
->iid
),riid
,sizeof(*riid
));
2242 hres
= IRpcStubBuffer_Connect((LPRPCSTUBBUFFER
)stub
,pUnkServer
);
2243 *ppStub
= (LPRPCSTUBBUFFER
)stub
;
2244 TRACE("IRpcStubBuffer: %p\n", stub
);
2246 ERR("Connect to pUnkServer failed?\n");
2250 static IPSFactoryBufferVtbl psfacbufvtbl
= {
2251 PSFacBuf_QueryInterface
,
2254 PSFacBuf_CreateProxy
,
2258 /* This is the whole PSFactoryBuffer object, just the vtableptr */
2259 static IPSFactoryBufferVtbl
*lppsfac
= &psfacbufvtbl
;
2261 /***********************************************************************
2262 * DllGetClassObject [OLE32.63]
2265 TypeLibFac_DllGetClassObject(REFCLSID rclsid
, REFIID iid
,LPVOID
*ppv
)
2267 if (IsEqualIID(iid
,&IID_IPSFactoryBuffer
)) {
2271 return E_NOINTERFACE
;