4 * Copyright 2002 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
;
174 ERR("pUnk is NULL?\n");
178 TRACE("...%s...\n",debugstr_guid(riid
));
179 hres
= IUnknown_QueryInterface(pUnk
,riid
,(LPVOID
*)&newiface
);
181 WARN("%p does not support iface %s\n",pUnk
,debugstr_guid(riid
));
185 hres
= CreateStreamOnHGlobal(0,TRUE
,&pStm
);
187 ERR("Stream create failed %lx\n",hres
);
191 hres
= CoMarshalInterface(pStm
,riid
,newiface
,0,NULL
,0);
193 ERR("Marshalling interface %s failed with %lx\n", debugstr_guid(riid
), hres
);
197 hres
= IStream_Stat(pStm
,&ststg
,0);
199 ERR("Stream stat failed\n");
203 tempbuf
= HeapAlloc(GetProcessHeap(), 0, ststg
.cbSize
.u
.LowPart
);
204 memset(&seekto
,0,sizeof(seekto
));
205 hres
= IStream_Seek(pStm
,seekto
,SEEK_SET
,&newpos
);
207 ERR("Failed Seek %lx\n",hres
);
211 hres
= IStream_Read(pStm
,tempbuf
,ststg
.cbSize
.u
.LowPart
,&res
);
213 ERR("Failed Read %lx\n",hres
);
217 xsize
= ststg
.cbSize
.u
.LowPart
;
218 xbuf_add(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
219 hres
= xbuf_add(buf
,tempbuf
,ststg
.cbSize
.u
.LowPart
);
221 HeapFree(GetProcessHeap(),0,tempbuf
);
222 IUnknown_Release(newiface
);
223 IStream_Release(pStm
);
229 xbuf_add(buf
,(LPBYTE
)&xsize
,sizeof(xsize
));
230 if (pStm
) IUnknown_Release(pStm
);
231 if (newiface
) IUnknown_Release(newiface
);
232 HeapFree(GetProcessHeap(), 0, tempbuf
);
236 /********************* OLE Proxy/Stub Factory ********************************/
237 static HRESULT WINAPI
238 PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface
, REFIID iid
, LPVOID
*ppv
) {
239 if (IsEqualIID(iid
,&IID_IPSFactoryBuffer
)||IsEqualIID(iid
,&IID_IUnknown
)) {
240 *ppv
= (LPVOID
)iface
;
241 /* No ref counting, static class */
244 FIXME("(%s) unknown IID?\n",debugstr_guid(iid
));
245 return E_NOINTERFACE
;
248 static ULONG WINAPI
PSFacBuf_AddRef(LPPSFACTORYBUFFER iface
) { return 2; }
249 static ULONG WINAPI
PSFacBuf_Release(LPPSFACTORYBUFFER iface
) { return 1; }
252 _get_typeinfo_for_iid(REFIID riid
, ITypeInfo
**ti
) {
255 char tlguid
[200],typelibkey
[300],interfacekey
[300],ver
[100];
258 DWORD tlguidlen
, verlen
, type
, tlfnlen
;
261 sprintf( interfacekey
, "Interface\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\Typelib",
262 riid
->Data1
, riid
->Data2
, riid
->Data3
,
263 riid
->Data4
[0], riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3],
264 riid
->Data4
[4], riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]
267 if (RegOpenKeyA(HKEY_CLASSES_ROOT
,interfacekey
,&ikey
)) {
268 ERR("No %s key found.\n",interfacekey
);
272 tlguidlen
= sizeof(tlguid
);
273 if (RegQueryValueExA(ikey
,NULL
,NULL
,&type
,tlguid
,&tlguidlen
)) {
274 ERR("Getting typelib guid failed.\n");
279 verlen
= sizeof(ver
);
280 if (RegQueryValueExA(ikey
,"Version",NULL
,&type
,ver
,&verlen
)) {
281 ERR("Could not get version value?\n");
286 sprintf(typelibkey
,"Typelib\\%s\\%s\\0\\win32",tlguid
,ver
);
287 tlfnlen
= sizeof(tlfn
);
288 if (RegQueryValueA(HKEY_CLASSES_ROOT
,typelibkey
,tlfn
,&tlfnlen
)) {
289 ERR("Could not get typelib fn?\n");
292 MultiByteToWideChar(CP_ACP
, 0, tlfn
, -1, tlfnW
, -1);
293 hres
= LoadTypeLib(tlfnW
,&tl
);
295 ERR("Failed to load typelib for %s, but it should be there.\n",debugstr_guid(riid
));
298 hres
= ITypeLib_GetTypeInfoOfGuid(tl
,riid
,ti
);
300 ERR("typelib does not contain info for %s?\n",debugstr_guid(riid
));
301 ITypeLib_Release(tl
);
304 /* FIXME: do this? ITypeLib_Release(tl); */
308 /* Determine nr of functions. Since we use the toplevel interface and all
309 * inherited ones have lower numbers, we are ok to not to descent into
310 * the inheritance tree I think.
312 static int _nroffuncs(ITypeInfo
*tinfo
) {
319 hres
= ITypeInfo_GetFuncDesc(tinfo
,n
,&fdesc
);
322 if (fdesc
->oVft
/4 > max
)
331 #include "pshpack1.h"
333 typedef struct _TMAsmProxy
{
347 # error You need to implement stubless proxies for your architecture
350 typedef struct _TMProxyImpl
{
352 IRpcProxyBufferVtbl
*lpvtbl2
;
355 TMAsmProxy
*asmstubs
;
357 IRpcChannelBuffer
* chanbuf
;
359 CRITICAL_SECTION crit
;
360 IUnknown
*outerunknown
;
363 static HRESULT WINAPI
364 TMProxyImpl_QueryInterface(LPRPCPROXYBUFFER iface
, REFIID riid
, LPVOID
*ppv
)
367 if (IsEqualIID(riid
,&IID_IUnknown
)||IsEqualIID(riid
,&IID_IRpcProxyBuffer
)) {
368 *ppv
= (LPVOID
)iface
;
369 IRpcProxyBuffer_AddRef(iface
);
372 FIXME("no interface for %s\n",debugstr_guid(riid
));
373 return E_NOINTERFACE
;
377 TMProxyImpl_AddRef(LPRPCPROXYBUFFER iface
)
379 ICOM_THIS_MULTI(TMProxyImpl
,lpvtbl2
,iface
);
380 ULONG refCount
= InterlockedIncrement(&This
->ref
);
382 TRACE("(%p)->(ref before=%lu)\n",This
, refCount
- 1);
388 TMProxyImpl_Release(LPRPCPROXYBUFFER iface
)
390 ICOM_THIS_MULTI(TMProxyImpl
,lpvtbl2
,iface
);
391 ULONG refCount
= InterlockedDecrement(&This
->ref
);
393 TRACE("(%p)->(ref before=%lu)\n",This
, refCount
+ 1);
397 DeleteCriticalSection(&This
->crit
);
398 if (This
->chanbuf
) IRpcChannelBuffer_Release(This
->chanbuf
);
399 VirtualFree(This
->asmstubs
, 0, MEM_RELEASE
);
405 static HRESULT WINAPI
407 LPRPCPROXYBUFFER iface
,IRpcChannelBuffer
* pRpcChannelBuffer
)
409 ICOM_THIS_MULTI(TMProxyImpl
, lpvtbl2
, iface
);
411 TRACE("(%p)\n", pRpcChannelBuffer
);
413 EnterCriticalSection(&This
->crit
);
415 IRpcChannelBuffer_AddRef(pRpcChannelBuffer
);
416 This
->chanbuf
= pRpcChannelBuffer
;
418 LeaveCriticalSection(&This
->crit
);
424 TMProxyImpl_Disconnect(LPRPCPROXYBUFFER iface
)
426 ICOM_THIS_MULTI(TMProxyImpl
, lpvtbl2
, iface
);
430 EnterCriticalSection(&This
->crit
);
432 IRpcChannelBuffer_Release(This
->chanbuf
);
433 This
->chanbuf
= NULL
;
435 LeaveCriticalSection(&This
->crit
);
439 static IRpcProxyBufferVtbl tmproxyvtable
= {
440 TMProxyImpl_QueryInterface
,
444 TMProxyImpl_Disconnect
447 /* how much space do we use on stack in DWORD steps. */
452 return sizeof(DATE
)/sizeof(DWORD
);
454 return (sizeof(VARIANT
)+3)/sizeof(DWORD
);
461 _xsize(TYPEDESC
*td
) {
466 return sizeof(VARIANT
)+3;
469 ARRAYDESC
*adesc
= td
->u
.lpadesc
;
471 for (i
=0;i
<adesc
->cDims
;i
++)
472 arrsize
*= adesc
->rgbounds
[i
].cElements
;
473 return arrsize
*_xsize(&adesc
->tdescElem
);
498 TRACE("(tdesc.vt %d)\n",tdesc
->vt
);
501 case VT_EMPTY
: /* nothing. empty variant for instance */
514 if (debugout
) TRACE_(olerelay
)("%lx",*arg
);
516 hres
= xbuf_add(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
520 VARIANT
*vt
= (VARIANT
*)arg
;
521 DWORD vttype
= V_VT(vt
);
523 if (debugout
) TRACE_(olerelay
)("Vt(%ld)(",vttype
);
526 hres
= xbuf_add(buf
,(LPBYTE
)&vttype
,sizeof(vttype
));
527 if (hres
) return hres
;
529 /* need to recurse since we need to free the stuff */
530 hres
= serialize_param(tinfo
,writeit
,debugout
,dealloc
,&tdesc2
,&(V_I4(vt
)),buf
);
531 if (debugout
) TRACE_(olerelay
)(")");
534 case VT_BSTR
|VT_BYREF
: {
535 if (debugout
) TRACE_(olerelay
)("[byref]'%s'", *arg
? relaystr(*((BSTR
*)*arg
)) : "<bstr NULL>");
537 /* ptr to ptr to magic widestring, basically */
538 BSTR
*bstr
= (BSTR
*) *arg
;
540 /* -1 means "null string" which is equivalent to empty string */
542 xbuf_add(buf
, (LPBYTE
)&fakelen
,4);
544 /* BSTRs store the length behind the first character */
545 DWORD
*len
= ((DWORD
*)(*bstr
))-1;
546 hres
= xbuf_add(buf
, (LPBYTE
) len
, *len
+ 4);
547 if (hres
) return hres
;
551 if (dealloc
&& arg
) {
552 BSTR
*str
= *((BSTR
**)arg
);
561 TRACE_(olerelay
)("%s",relaystr((BSTR
)*arg
));
563 TRACE_(olerelay
)("<bstr NULL>");
568 hres
= xbuf_add(buf
,(LPBYTE
)&fakelen
,4);
572 DWORD
*bstr
= ((DWORD
*)(*arg
))-1;
574 hres
= xbuf_add(buf
,(LPBYTE
)bstr
,bstr
[0]+4);
581 SysFreeString((BSTR
)*arg
);
587 if (debugout
) TRACE_(olerelay
)("*");
588 /* Write always, so the other side knows when it gets a NULL pointer.
590 cookie
= *arg
? 0x42424242 : 0;
591 hres
= xbuf_add(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
595 if (debugout
) TRACE_(olerelay
)("NULL");
598 hres
= serialize_param(tinfo
,writeit
,debugout
,dealloc
,tdesc
->u
.lptdesc
,(DWORD
*)*arg
,buf
);
599 if (dealloc
) HeapFree(GetProcessHeap(),0,(LPVOID
)arg
);
603 if (debugout
) TRACE_(olerelay
)("unk(0x%lx)",*arg
);
605 hres
= _marshal_interface(buf
,&IID_IUnknown
,(LPUNKNOWN
)*arg
);
608 if (debugout
) TRACE_(olerelay
)("idisp(0x%lx)",*arg
);
610 hres
= _marshal_interface(buf
,&IID_IDispatch
,(LPUNKNOWN
)*arg
);
613 if (debugout
) TRACE_(olerelay
)("<void>");
615 case VT_USERDEFINED
: {
619 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.hreftype
,&tinfo2
);
621 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc
->u
.hreftype
);
624 ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
625 switch (tattr
->typekind
) {
627 case TKIND_INTERFACE
:
629 hres
=_marshal_interface(buf
,&(tattr
->guid
),(LPUNKNOWN
)arg
);
633 if (debugout
) TRACE_(olerelay
)("{");
634 for (i
=0;i
<tattr
->cVars
;i
++) {
639 hres
= ITypeInfo2_GetVarDesc(tinfo2
, i
, &vdesc
);
641 ERR("Could not get vardesc of %d\n",i
);
644 /* Need them for hack below */
646 memset(names,0,sizeof(names));
647 hres = ITypeInfo_GetNames(tinfo2,vdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
648 if (nrofnames > sizeof(names)/sizeof(names[0])) {
649 ERR("Need more names!\n");
651 if (!hres && debugout)
652 TRACE_(olerelay)("%s=",relaystr(names[0]));
654 elem2
= &vdesc
->elemdescVar
;
655 tdesc2
= &elem2
->tdesc
;
656 hres
= serialize_param(
662 (DWORD
*)(((LPBYTE
)arg
)+vdesc
->u
.oInst
),
667 if (debugout
&& (i
<(tattr
->cVars
-1)))
668 TRACE_(olerelay
)(",");
670 if (buf
->thisisiid
&& (tattr
->cbSizeInstance
==sizeof(GUID
)))
671 memcpy(&(buf
->iid
),arg
,sizeof(buf
->iid
));
672 if (debugout
) TRACE_(olerelay
)("}");
676 FIXME("Unhandled typekind %d\n",tattr
->typekind
);
680 ITypeInfo_Release(tinfo2
);
684 ARRAYDESC
*adesc
= tdesc
->u
.lpadesc
;
687 if (debugout
) TRACE_(olerelay
)("carr");
688 for (i
=0;i
<adesc
->cDims
;i
++) {
689 if (debugout
) TRACE_(olerelay
)("[%ld]",adesc
->rgbounds
[i
].cElements
);
690 arrsize
*= adesc
->rgbounds
[i
].cElements
;
692 if (debugout
) TRACE_(olerelay
)("(vt %d)",adesc
->tdescElem
.vt
);
693 if (debugout
) TRACE_(olerelay
)("[");
694 for (i
=0;i
<arrsize
;i
++) {
695 hres
= serialize_param(tinfo
, writeit
, debugout
, dealloc
, &adesc
->tdescElem
, (DWORD
*)((LPBYTE
)arg
+i
*_xsize(&adesc
->tdescElem
)), buf
);
698 if (debugout
&& (i
<arrsize
-1)) TRACE_(olerelay
)(",");
700 if (debugout
) TRACE_(olerelay
)("]");
704 ERR("Unhandled marshal type %d.\n",tdesc
->vt
);
710 * HRESULT GetIDsOfNames(
711 * [in] REFIID riid, args[1]
712 * [in, size_is(cNames)] LPOLESTR *rgszNames, args[2]
713 * [in] UINT cNames, args[3]
714 * [in] LCID lcid, args[4]
715 * [out, size_is(cNames)] DISPID *rgDispId); args[5]
720 * LPOLESTR rgszNames[cNames];
721 * DWORD bytestrlen (incl 0)
722 * BYTE data[bytestrlen] (incl 0)
726 serialize_IDispatch_GetIDsOfNames(
733 DWORD cNames
= args
[2];
734 LPOLESTR
*rgszNames
= (LPOLESTR
*)args
[1];
738 if (debugout
) TRACE_(olerelay
)("riid=%s,",debugstr_guid((REFIID
)args
[0]));
739 hres
= xbuf_add(buf
, (LPBYTE
)args
[0], sizeof(IID
));
741 FIXME("serialize of IID failed.\n");
744 if (debugout
) TRACE_(olerelay
)("cNames=%ld,",cNames
);
745 hres
= xbuf_add(buf
, (LPBYTE
)&cNames
, sizeof(DWORD
));
747 FIXME("serialize of cNames failed.\n");
750 if (debugout
) TRACE_(olerelay
)("rgszNames=[");
751 for (i
=0;i
<cNames
;i
++) {
752 DWORD len
= 2*(lstrlenW(rgszNames
[i
])+1);
754 if (debugout
) TRACE_(olerelay
)("%s,",relaystr(rgszNames
[i
]));
755 hres
= xbuf_add(buf
, (LPBYTE
)&len
, sizeof(DWORD
));
757 FIXME("serialize of len failed.\n");
760 hres
= xbuf_add(buf
, (LPBYTE
)rgszNames
[i
], len
);
762 FIXME("serialize of rgszNames[i] failed.\n");
766 if (debugout
) TRACE_(olerelay
)("],lcid=%04lx)",args
[3]);
767 hres
= xbuf_add(buf
, (LPBYTE
)&args
[3], sizeof(DWORD
));
769 FIXME("serialize of lcid failed.\n");
773 DISPID
*rgDispId
= (DISPID
*)args
[4];
775 hres
= xbuf_add(buf
, (LPBYTE
)rgDispId
, sizeof(DISPID
) * cNames
);
777 FIXME("serialize of rgDispId failed.\n");
781 TRACE_(olerelay
)("riid=[in],rgszNames=[in],cNames=[in],rgDispId=[");
782 for (i
=0;i
<cNames
;i
++)
783 TRACE_(olerelay
)("%08lx,",rgDispId
[i
]);
784 TRACE_(olerelay
)("])");
786 HeapFree(GetProcessHeap(),0,(IID
*)args
[0]);
787 rgszNames
= (LPOLESTR
*)args
[1];
788 for (i
=0;i
<cNames
;i
++) HeapFree(GetProcessHeap(),0,rgszNames
[i
]);
789 HeapFree(GetProcessHeap(),0,rgszNames
);
790 HeapFree(GetProcessHeap(),0,rgDispId
);
796 deserialize_IDispatch_GetIDsOfNames(
808 args
[0] = (DWORD
)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IID
));
809 if (!args
[0]) return E_FAIL
;
810 hres
= xbuf_get(buf
, (LPBYTE
)args
[0], sizeof(IID
));
812 FIXME("deserialize of IID failed.\n");
815 if (debugout
) TRACE_(olerelay
)("riid=%s,",debugstr_guid((REFIID
)args
[0]));
817 hres
= xbuf_get(buf
, (LPBYTE
)&cNames
, sizeof(DWORD
));
819 FIXME("deserialize of cNames failed.\n");
823 if (debugout
) TRACE_(olerelay
)("cNames=%ld,",cNames
);
824 if (debugout
) TRACE_(olerelay
)("rgszNames=[");
825 rgszNames
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(LPOLESTR
) * cNames
);
826 if (!rgszNames
) return E_FAIL
;
827 args
[1] = (DWORD
)rgszNames
;
828 for (i
=0;i
<cNames
;i
++) {
831 hres
= xbuf_get(buf
, (LPBYTE
)&len
, sizeof(DWORD
));
833 FIXME("serialize of len failed.\n");
836 rgszNames
[i
] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
838 FIXME("heapalloc of %ld bytes failed\n", len
);
841 hres
= xbuf_get(buf
, (LPBYTE
)rgszNames
[i
], len
);
843 FIXME("serialize of rgszNames[i] failed.\n");
846 if (debugout
) TRACE_(olerelay
)("%s,",relaystr(rgszNames
[i
]));
848 hres
= xbuf_get(buf
, (LPBYTE
)&args
[3], sizeof(DWORD
));
850 FIXME("deserialize of lcid failed.\n");
853 if (debugout
) TRACE_(olerelay
)("],lcid=%04lx,rgDispId=[out])",args
[3]);
854 args
[4] = (DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DISPID
) * cNames
);
856 hres
= xbuf_get(buf
, (LPBYTE
)args
[4], sizeof(DISPID
) * args
[2]);
858 FIXME("serialize of rgDispId failed.\n");
862 TRACE_(olerelay
)("dispid=[");
863 for (i
=0;i
<args
[2];i
++)
864 TRACE_(olerelay
)("%08lx,",((DISPID
*)args
[4])[i
]);
865 TRACE_(olerelay
)("])");
872 serialize_LPVOID_ptr(
884 if ((tdesc
->vt
!= VT_PTR
) ||
885 (tdesc
->u
.lptdesc
->vt
!= VT_PTR
) ||
886 (tdesc
->u
.lptdesc
->u
.lptdesc
->vt
!= VT_VOID
)
888 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
891 cookie
= (*arg
) ? 0x42424242: 0x0;
893 hres
= xbuf_add(buf
, (LPVOID
)&cookie
, sizeof(cookie
));
898 if (debugout
) TRACE_(olerelay
)("<lpvoid NULL>");
902 TRACE_(olerelay
)("ppv(%p)",*(LPUNKNOWN
*)*arg
);
904 hres
= _marshal_interface(buf
,&(buf
->iid
),*(LPUNKNOWN
*)*arg
);
909 HeapFree(GetProcessHeap(),0,(LPVOID
)*arg
);
914 serialize_DISPPARAM_ptr(
928 if ((tdesc
->vt
!= VT_PTR
) || (tdesc
->u
.lptdesc
->vt
!= VT_USERDEFINED
)) {
929 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
933 cookie
= *arg
? 0x42424242 : 0x0;
935 hres
= xbuf_add(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
940 if (debugout
) TRACE_(olerelay
)("<DISPPARAMS NULL>");
943 disp
= (DISPPARAMS
*)*arg
;
945 hres
= xbuf_add(buf
,(LPBYTE
)&disp
->cArgs
,sizeof(disp
->cArgs
));
949 if (debugout
) TRACE_(olerelay
)("D{");
950 for (i
=0;i
<disp
->cArgs
;i
++) {
953 vtdesc
.vt
= VT_VARIANT
;
960 (DWORD
*)(disp
->rgvarg
+i
),
963 if (debugout
&& (i
<disp
->cArgs
-1))
964 TRACE_(olerelay
)(",");
967 HeapFree(GetProcessHeap(),0,disp
->rgvarg
);
969 hres
= xbuf_add(buf
,(LPBYTE
)&disp
->cNamedArgs
,sizeof(disp
->cNamedArgs
));
973 if (debugout
) TRACE_(olerelay
)("}{");
974 for (i
=0;i
<disp
->cNamedArgs
;i
++) {
984 (DWORD
*)(disp
->rgdispidNamedArgs
+i
),
987 if (debugout
&& (i
<disp
->cNamedArgs
-1))
988 TRACE_(olerelay
)(",");
990 if (debugout
) TRACE_(olerelay
)("}");
992 HeapFree(GetProcessHeap(),0,disp
->rgdispidNamedArgs
);
993 HeapFree(GetProcessHeap(),0,disp
);
1008 HRESULT hres
= S_OK
;
1010 TRACE("vt %d at %p\n",tdesc
->vt
,arg
);
1013 switch (tdesc
->vt
) {
1015 if (debugout
) TRACE_(olerelay
)("<empty>");
1018 if (debugout
) TRACE_(olerelay
)("<null>");
1021 VARIANT
*vt
= (VARIANT
*)arg
;
1026 hres
= xbuf_get(buf
,(LPBYTE
)&vttype
,sizeof(vttype
));
1028 FIXME("vt type not read?\n");
1031 memset(&tdesc2
,0,sizeof(tdesc2
));
1034 if (debugout
) TRACE_(olerelay
)("Vt(%ld)(",vttype
);
1035 hres
= deserialize_param(tinfo
, readit
, debugout
, alloc
, &tdesc2
, &(V_I4(vt
)), buf
);
1036 TRACE_(olerelay
)(")");
1054 hres
= xbuf_get(buf
,(LPBYTE
)arg
,sizeof(DWORD
));
1055 if (hres
) ERR("Failed to read integer 4 byte\n");
1057 if (debugout
) TRACE_(olerelay
)("%lx",*arg
);
1059 case VT_BSTR
|VT_BYREF
: {
1060 BSTR
**bstr
= (BSTR
**)arg
;
1065 hres
= xbuf_get(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
1067 ERR("failed to read bstr klen\n");
1072 if (debugout
) TRACE_(olerelay
)("<bstr NULL>");
1074 str
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,len
+sizeof(WCHAR
));
1075 hres
= xbuf_get(buf
,(LPBYTE
)str
,len
);
1077 ERR("Failed to read BSTR.\n");
1080 *bstr
= CoTaskMemAlloc(sizeof(BSTR
*));
1081 **bstr
= SysAllocStringLen(str
,len
);
1082 if (debugout
) TRACE_(olerelay
)("%s",relaystr(str
));
1083 HeapFree(GetProcessHeap(),0,str
);
1095 hres
= xbuf_get(buf
,(LPBYTE
)&len
,sizeof(DWORD
));
1097 ERR("failed to read bstr klen\n");
1102 if (debugout
) TRACE_(olerelay
)("<bstr NULL>");
1104 str
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,len
+sizeof(WCHAR
));
1105 hres
= xbuf_get(buf
,(LPBYTE
)str
,len
);
1107 ERR("Failed to read BSTR.\n");
1110 *arg
= (DWORD
)SysAllocStringLen(str
,len
);
1111 if (debugout
) TRACE_(olerelay
)("%s",relaystr(str
));
1112 HeapFree(GetProcessHeap(),0,str
);
1123 derefhere
= (tdesc
->u
.lptdesc
->vt
!= VT_USERDEFINED
);
1124 /* read it in all cases, we need to know if we have
1125 * NULL pointer or not.
1127 hres
= xbuf_get(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
1129 ERR("Failed to load pointer cookie.\n");
1132 if (cookie
!= 0x42424242) {
1133 /* we read a NULL ptr from the remote side */
1134 if (debugout
) TRACE_(olerelay
)("NULL");
1138 if (debugout
) TRACE_(olerelay
)("*");
1140 /* Allocate space for the referenced struct */
1142 *arg
=(DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,_xsize(tdesc
->u
.lptdesc
));
1145 return deserialize_param(tinfo
, readit
, debugout
, alloc
, tdesc
->u
.lptdesc
, (LPDWORD
)*arg
, buf
);
1147 return deserialize_param(tinfo
, readit
, debugout
, alloc
, tdesc
->u
.lptdesc
, arg
, buf
);
1150 /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
1152 *arg
=(DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DWORD
));
1155 hres
= _unmarshal_interface(buf
,&IID_IUnknown
,(LPUNKNOWN
*)arg
);
1157 TRACE_(olerelay
)("unk(%p)",arg
);
1162 hres
= _unmarshal_interface(buf
,&IID_IDispatch
,(LPUNKNOWN
*)arg
);
1164 TRACE_(olerelay
)("idisp(%p)",arg
);
1167 if (debugout
) TRACE_(olerelay
)("<void>");
1169 case VT_USERDEFINED
: {
1173 hres
= ITypeInfo_GetRefTypeInfo(tinfo
,tdesc
->u
.hreftype
,&tinfo2
);
1175 ERR("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc
->u
.hreftype
);
1178 hres
= ITypeInfo_GetTypeAttr(tinfo2
,&tattr
);
1180 ERR("Could not get typeattr in VT_USERDEFINED.\n");
1182 switch (tattr
->typekind
) {
1183 case TKIND_DISPATCH
:
1184 case TKIND_INTERFACE
:
1186 hres
= _unmarshal_interface(buf
,&(tattr
->guid
),(LPUNKNOWN
*)arg
);
1188 case TKIND_RECORD
: {
1192 *arg
= (DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,tattr
->cbSizeInstance
);
1194 if (debugout
) TRACE_(olerelay
)("{");
1195 for (i
=0;i
<tattr
->cVars
;i
++) {
1198 hres
= ITypeInfo2_GetVarDesc(tinfo2
, i
, &vdesc
);
1200 ERR("Could not get vardesc of %d\n",i
);
1203 hres
= deserialize_param(
1208 &vdesc
->elemdescVar
.tdesc
,
1209 (DWORD
*)(((LPBYTE
)*arg
)+vdesc
->u
.oInst
),
1212 if (debugout
&& (i
<tattr
->cVars
-1)) TRACE_(olerelay
)(",");
1214 if (buf
->thisisiid
&& (tattr
->cbSizeInstance
==sizeof(GUID
)))
1215 memcpy(&(buf
->iid
),(LPBYTE
)*arg
,sizeof(buf
->iid
));
1216 if (debugout
) TRACE_(olerelay
)("}");
1220 ERR("Unhandled typekind %d\n",tattr
->typekind
);
1226 ERR("failed to stuballoc in TKIND_RECORD.\n");
1227 ITypeInfo_Release(tinfo2
);
1231 /* arg is pointing to the start of the array. */
1232 ARRAYDESC
*adesc
= tdesc
->u
.lpadesc
;
1235 if (adesc
->cDims
> 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
1236 for (i
=0;i
<adesc
->cDims
;i
++)
1237 arrsize
*= adesc
->rgbounds
[i
].cElements
;
1238 for (i
=0;i
<arrsize
;i
++)
1245 (DWORD
*)((LPBYTE
)(arg
)+i
*_xsize(&adesc
->tdescElem
)),
1251 ERR("No handler for VT type %d!\n",tdesc
->vt
);
1258 deserialize_LPVOID_ptr(
1270 if ((tdesc
->vt
!= VT_PTR
) ||
1271 (tdesc
->u
.lptdesc
->vt
!= VT_PTR
) ||
1272 (tdesc
->u
.lptdesc
->u
.lptdesc
->vt
!= VT_VOID
)
1274 FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
1278 *arg
=(DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(LPVOID
));
1280 hres
= xbuf_get(buf
, (LPVOID
)&cookie
, sizeof(cookie
));
1283 if (cookie
!= 0x42424242) {
1285 if (debugout
) TRACE_(olerelay
)("<lpvoid NULL>");
1290 hres
= _unmarshal_interface(buf
,&buf
->iid
,(LPUNKNOWN
*)*arg
);
1292 FIXME("_unmarshal_interface of %s , %p failed with %lx\n", debugstr_guid(&buf
->iid
), (LPUNKNOWN
*)*arg
, hres
);
1296 if (debugout
) TRACE_(olerelay
)("ppv(%p)",(LPVOID
)*arg
);
1301 deserialize_DISPPARAM_ptr(
1315 if ((tdesc
->vt
!= VT_PTR
) || (tdesc
->u
.lptdesc
->vt
!= VT_USERDEFINED
)) {
1316 FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
1320 hres
= xbuf_get(buf
,(LPBYTE
)&cookie
,sizeof(cookie
));
1325 if (debugout
) TRACE_(olerelay
)("<DISPPARAMS NULL>");
1330 *arg
= (DWORD
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DISPPARAMS
));
1331 disps
= (DISPPARAMS
*)*arg
;
1334 hres
= xbuf_get(buf
, (LPBYTE
)&disps
->cArgs
, sizeof(disps
->cArgs
));
1338 disps
->rgvarg
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(VARIANT
)*disps
->cArgs
);
1339 if (debugout
) TRACE_(olerelay
)("D{");
1340 for (i
=0; i
< disps
->cArgs
; i
++) {
1343 vdesc
.vt
= VT_VARIANT
;
1344 hres
= deserialize_param(
1350 (DWORD
*)(disps
->rgvarg
+i
),
1354 if (debugout
) TRACE_(olerelay
)("}{");
1355 hres
= xbuf_get(buf
, (LPBYTE
)&disps
->cNamedArgs
, sizeof(disps
->cNamedArgs
));
1358 if (disps
->cNamedArgs
) {
1360 disps
->rgdispidNamedArgs
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DISPID
)*disps
->cNamedArgs
);
1361 for (i
=0; i
< disps
->cNamedArgs
; i
++) {
1365 hres
= deserialize_param(
1371 (DWORD
*)(disps
->rgdispidNamedArgs
+i
),
1374 if (debugout
&& i
<(disps
->cNamedArgs
-1)) TRACE_(olerelay
)(",");
1377 if (debugout
) TRACE_(olerelay
)("}");
1381 /* Searches function, also in inherited interfaces */
1384 ITypeInfo
*tinfo
, int iMethod
, FUNCDESC
**fdesc
, BSTR
*iname
, BSTR
*fname
)
1389 if (fname
) *fname
= NULL
;
1390 if (iname
) *iname
= NULL
;
1393 hres
= ITypeInfo_GetFuncDesc(tinfo
, i
, fdesc
);
1399 hres
= ITypeInfo_GetTypeAttr(tinfo
, &attr
);
1401 ERR("GetTypeAttr failed with %lx\n",hres
);
1404 /* Not found, so look in inherited ifaces. */
1405 for (j
=0;j
<attr
->cImplTypes
;j
++) {
1406 hres
= ITypeInfo_GetRefTypeOfImplType(tinfo
, j
, &href
);
1408 ERR("Did not find a reftype for interface offset %d?\n",j
);
1411 hres
= ITypeInfo_GetRefTypeInfo(tinfo
, href
, &tinfo2
);
1413 ERR("Did not find a typeinfo for reftype %ld?\n",href
);
1416 hres
= _get_funcdesc(tinfo2
,iMethod
,fdesc
,iname
,fname
);
1417 ITypeInfo_Release(tinfo2
);
1418 if (!hres
) return S_OK
;
1422 if (((*fdesc
)->oVft
/4) == iMethod
) {
1424 ITypeInfo_GetDocumentation(tinfo
,(*fdesc
)->memid
,fname
,NULL
,NULL
,NULL
);
1426 ITypeInfo_GetDocumentation(tinfo
,-1,iname
,NULL
,NULL
,NULL
);
1434 xCall(LPVOID retptr
, int method
, TMProxyImpl
*tpinfo
/*, args */)
1436 DWORD
*args
= ((DWORD
*)&tpinfo
)+1, *xargs
;
1439 int i
, relaydeb
= TRACE_ON(olerelay
);
1446 int is_idispatch_getidsofnames
= 0;
1448 EnterCriticalSection(&tpinfo
->crit
);
1450 hres
= _get_funcdesc(tpinfo
->tinfo
,method
,&fdesc
,&iname
,&fname
);
1452 ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method
);
1453 LeaveCriticalSection(&tpinfo
->crit
);
1457 if (!tpinfo
->chanbuf
)
1459 WARN("Tried to use disconnected proxy\n");
1460 LeaveCriticalSection(&tpinfo
->crit
);
1461 return RPC_E_DISCONNECTED
;
1465 TRACE_(olerelay
)("->");
1467 TRACE_(olerelay
)("%s:",relaystr(iname
));
1469 TRACE_(olerelay
)("%s(%d)",relaystr(fname
),method
);
1471 TRACE_(olerelay
)("%d",method
);
1472 TRACE_(olerelay
)("(");
1474 if (iname
&& fname
&& !lstrcmpW(iname
,IDispatchW
) && !lstrcmpW(fname
,GetIDsOfNamesW
))
1475 is_idispatch_getidsofnames
= 1;
1477 if (iname
) SysFreeString(iname
);
1478 if (fname
) SysFreeString(fname
);
1480 memset(&buf
,0,sizeof(buf
));
1481 buf
.iid
= IID_IUnknown
;
1483 /* Special IDispatch::GetIDsOfNames() serializer */
1484 if (is_idispatch_getidsofnames
) {
1485 hres
= serialize_IDispatch_GetIDsOfNames(TRUE
,relaydeb
,args
,&buf
);
1487 FIXME("serialize of IDispatch::GetIDsOfNames failed!\n");
1490 goto afterserialize
;
1493 /* special QueryInterface serialize */
1495 xbuf_add(&buf
,(LPBYTE
)args
[0],sizeof(IID
));
1496 if (relaydeb
) TRACE_(olerelay
)("riid=%s,[out])",debugstr_guid((REFIID
)args
[0]));
1497 goto afterserialize
;
1500 /* normal typelib driven serializing */
1502 /* Need them for hack below */
1503 memset(names
,0,sizeof(names
));
1504 if (ITypeInfo_GetNames(tpinfo
->tinfo
,fdesc
->memid
,names
,sizeof(names
)/sizeof(names
[0]),&nrofnames
))
1506 if (nrofnames
> sizeof(names
)/sizeof(names
[0]))
1507 ERR("Need more names!\n");
1510 for (i
=0;i
<fdesc
->cParams
;i
++) {
1511 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1512 BOOL isserialized
= FALSE
;
1514 if (i
) TRACE_(olerelay
)(",");
1515 if (i
+1<nrofnames
&& names
[i
+1])
1516 TRACE_(olerelay
)("%s=",relaystr(names
[i
+1]));
1518 /* No need to marshal other data than FIN and any VT_PTR. */
1519 if (!(elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
) && (elem
->tdesc
.vt
!= VT_PTR
)) {
1520 xargs
+=_argsize(elem
->tdesc
.vt
);
1521 if (relaydeb
) TRACE_(olerelay
)("[out]");
1524 if (((i
+1)<nrofnames
) && !IsBadStringPtrW(names
[i
+1],1)) {
1525 /* If the parameter is 'riid', we use it as interface IID
1526 * for a later ppvObject serialization.
1528 buf
.thisisiid
= !lstrcmpW(names
[i
+1],riidW
);
1530 /* DISPPARAMS* needs special serializer */
1531 if (!lstrcmpW(names
[i
+1],pdispparamsW
)) {
1532 hres
= serialize_DISPPARAM_ptr(
1534 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
1541 isserialized
= TRUE
;
1543 if (!lstrcmpW(names
[i
+1],ppvObjectW
)) {
1544 hres
= serialize_LPVOID_ptr(
1546 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
1554 isserialized
= TRUE
;
1558 hres
= serialize_param(
1560 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
1569 ERR("Failed to serialize param, hres %lx\n",hres
);
1572 xargs
+=_argsize(elem
->tdesc
.vt
);
1574 if (relaydeb
) TRACE_(olerelay
)(")");
1577 memset(&msg
,0,sizeof(msg
));
1578 msg
.cbBuffer
= buf
.curoff
;
1579 msg
.iMethod
= method
;
1580 hres
= IRpcChannelBuffer_GetBuffer(tpinfo
->chanbuf
,&msg
,&(tpinfo
->iid
));
1582 ERR("RpcChannelBuffer GetBuffer failed, %lx\n",hres
);
1583 LeaveCriticalSection(&tpinfo
->crit
);
1586 memcpy(msg
.Buffer
,buf
.base
,buf
.curoff
);
1587 if (relaydeb
) TRACE_(olerelay
)("\n");
1588 hres
= IRpcChannelBuffer_SendReceive(tpinfo
->chanbuf
,&msg
,&status
);
1590 ERR("RpcChannelBuffer SendReceive failed, %lx\n",hres
);
1591 LeaveCriticalSection(&tpinfo
->crit
);
1595 if (relaydeb
) TRACE_(olerelay
)(" = %08lx (",status
);
1597 buf
.base
= HeapReAlloc(GetProcessHeap(),0,buf
.base
,msg
.cbBuffer
);
1599 buf
.base
= HeapAlloc(GetProcessHeap(),0,msg
.cbBuffer
);
1600 buf
.size
= msg
.cbBuffer
;
1601 memcpy(buf
.base
,msg
.Buffer
,buf
.size
);
1604 /* Special IDispatch::GetIDsOfNames() deserializer */
1605 if (is_idispatch_getidsofnames
) {
1606 hres
= deserialize_IDispatch_GetIDsOfNames(FALSE
,relaydeb
,args
,&buf
);
1608 FIXME("deserialize of IDispatch::GetIDsOfNames failed!\n");
1611 goto after_deserialize
;
1613 /* Special QueryInterface deserializer */
1615 _unmarshal_interface(&buf
,(REFIID
)args
[0],(LPUNKNOWN
*)args
[1]);
1616 if (relaydeb
) TRACE_(olerelay
)("[in],%p",*((DWORD
**)args
[1]));
1617 goto after_deserialize
;
1620 /* generic deserializer using typelib description */
1622 for (i
=0;i
<fdesc
->cParams
;i
++) {
1623 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1624 BOOL isdeserialized
= FALSE
;
1627 if (i
) TRACE_(olerelay
)(",");
1628 if (i
+1<nrofnames
&& names
[i
+1]) TRACE_(olerelay
)("%s=",relaystr(names
[i
+1]));
1630 /* No need to marshal other data than FOUT and any VT_PTR */
1631 if (!(elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
) && (elem
->tdesc
.vt
!= VT_PTR
)) {
1632 xargs
+= _argsize(elem
->tdesc
.vt
);
1633 if (relaydeb
) TRACE_(olerelay
)("[in]");
1636 if (((i
+1)<nrofnames
) && !IsBadStringPtrW(names
[i
+1],1)) {
1637 /* If the parameter is 'riid', we use it as interface IID
1638 * for a later ppvObject serialization.
1640 buf
.thisisiid
= !lstrcmpW(names
[i
+1],riidW
);
1642 /* deserialize DISPPARAM */
1643 if (!lstrcmpW(names
[i
+1],pdispparamsW
)) {
1644 hres
= deserialize_DISPPARAM_ptr(
1646 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
1654 ERR("Failed to deserialize DISPPARAM*, hres %lx\n",hres
);
1657 isdeserialized
= TRUE
;
1659 if (!lstrcmpW(names
[i
+1],ppvObjectW
)) {
1660 hres
= deserialize_LPVOID_ptr(
1662 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
1670 isdeserialized
= TRUE
;
1673 if (!isdeserialized
)
1674 hres
= deserialize_param(
1676 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
1684 ERR("Failed to unmarshall param, hres %lx\n",hres
);
1688 xargs
+= _argsize(elem
->tdesc
.vt
);
1691 if (relaydeb
) TRACE_(olerelay
)(")\n");
1692 HeapFree(GetProcessHeap(),0,buf
.base
);
1694 LeaveCriticalSection(&tpinfo
->crit
);
1699 HRESULT WINAPI
ProxyIUnknown_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
1701 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1703 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
1705 if (proxy
->outerunknown
)
1706 return IUnknown_QueryInterface(proxy
->outerunknown
, riid
, ppv
);
1708 FIXME("No interface\n");
1709 return E_NOINTERFACE
;
1712 ULONG WINAPI
ProxyIUnknown_AddRef(IUnknown
*iface
)
1714 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1718 if (proxy
->outerunknown
)
1719 return IUnknown_AddRef(proxy
->outerunknown
);
1721 return 2; /* FIXME */
1724 ULONG WINAPI
ProxyIUnknown_Release(IUnknown
*iface
)
1726 TMProxyImpl
*proxy
= (TMProxyImpl
*)iface
;
1730 if (proxy
->outerunknown
)
1731 return IUnknown_Release(proxy
->outerunknown
);
1733 return 1; /* FIXME */
1736 static HRESULT WINAPI
1737 PSFacBuf_CreateProxy(
1738 LPPSFACTORYBUFFER iface
, IUnknown
* pUnkOuter
, REFIID riid
,
1739 IRpcProxyBuffer
**ppProxy
, LPVOID
*ppv
)
1747 TRACE("(...%s...)\n",debugstr_guid(riid
));
1748 hres
= _get_typeinfo_for_iid(riid
,&tinfo
);
1750 ERR("No typeinfo for %s?\n",debugstr_guid(riid
));
1753 nroffuncs
= _nroffuncs(tinfo
);
1754 proxy
= CoTaskMemAlloc(sizeof(TMProxyImpl
));
1755 if (!proxy
) return E_OUTOFMEMORY
;
1757 assert(sizeof(TMAsmProxy
) == 12);
1759 proxy
->outerunknown
= pUnkOuter
;
1760 proxy
->asmstubs
= VirtualAlloc(NULL
, sizeof(TMAsmProxy
) * nroffuncs
, MEM_COMMIT
, PAGE_EXECUTE_READWRITE
);
1761 if (!proxy
->asmstubs
) {
1762 ERR("Could not commit pages for proxy thunks\n");
1763 CoTaskMemFree(proxy
);
1764 return E_OUTOFMEMORY
;
1767 InitializeCriticalSection(&proxy
->crit
);
1769 proxy
->lpvtbl
= HeapAlloc(GetProcessHeap(),0,sizeof(LPBYTE
)*nroffuncs
);
1770 for (i
=0;i
<nroffuncs
;i
++) {
1771 TMAsmProxy
*xasm
= proxy
->asmstubs
+i
;
1775 proxy
->lpvtbl
[i
] = ProxyIUnknown_QueryInterface
;
1778 proxy
->lpvtbl
[i
] = ProxyIUnknown_AddRef
;
1781 proxy
->lpvtbl
[i
] = ProxyIUnknown_Release
;
1785 /* nrofargs without This */
1787 hres
= _get_funcdesc(tinfo
,i
,&fdesc
,NULL
,NULL
);
1789 ERR("GetFuncDesc %lx should not fail here.\n",hres
);
1792 /* some args take more than 4 byte on the stack */
1794 for (j
=0;j
<fdesc
->cParams
;j
++)
1795 nrofargs
+= _argsize(fdesc
->lprgelemdescParam
[j
].tdesc
.vt
);
1797 if (fdesc
->callconv
!= CC_STDCALL
) {
1798 ERR("calling convention is not stdcall????\n");
1801 /* popl %eax - return ptr
1808 * arg3 arg2 arg1 <method> <returnptr>
1810 xasm
->popleax
= 0x58;
1811 xasm
->pushlval
= 0x6a;
1813 xasm
->pushleax
= 0x50;
1814 xasm
->lcall
= 0xe8; /* relative jump */
1815 xasm
->xcall
= (DWORD
)xCall
;
1816 xasm
->xcall
-= (DWORD
)&(xasm
->lret
);
1818 xasm
->bytestopop
= (nrofargs
+2)*4; /* pop args, This, iMethod */
1819 proxy
->lpvtbl
[i
] = xasm
;
1824 proxy
->lpvtbl2
= &tmproxyvtable
;
1825 /* 1 reference for the proxy and 1 for the object */
1827 proxy
->tinfo
= tinfo
;
1828 memcpy(&proxy
->iid
,riid
,sizeof(*riid
));
1830 *ppv
= (LPVOID
)proxy
;
1831 *ppProxy
= (IRpcProxyBuffer
*)&(proxy
->lpvtbl2
);
1835 typedef struct _TMStubImpl
{
1836 IRpcStubBufferVtbl
*lpvtbl
;
1844 static HRESULT WINAPI
1845 TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface
, REFIID riid
, LPVOID
*ppv
)
1847 if (IsEqualIID(riid
,&IID_IRpcStubBuffer
)||IsEqualIID(riid
,&IID_IUnknown
)){
1848 *ppv
= (LPVOID
)iface
;
1849 IRpcStubBuffer_AddRef(iface
);
1852 FIXME("%s, not supported IID.\n",debugstr_guid(riid
));
1853 return E_NOINTERFACE
;
1857 TMStubImpl_AddRef(LPRPCSTUBBUFFER iface
)
1859 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1860 ULONG refCount
= InterlockedIncrement(&This
->ref
);
1862 TRACE("(%p)->(ref before=%lu)\n", This
, refCount
- 1);
1868 TMStubImpl_Release(LPRPCSTUBBUFFER iface
)
1870 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1871 ULONG refCount
= InterlockedDecrement(&This
->ref
);
1873 TRACE("(%p)->(ref before=%lu)\n", This
, refCount
+ 1);
1877 IRpcStubBuffer_Disconnect(iface
);
1878 CoTaskMemFree(This
);
1883 static HRESULT WINAPI
1884 TMStubImpl_Connect(LPRPCSTUBBUFFER iface
, LPUNKNOWN pUnkServer
)
1886 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1888 TRACE("(%p)->(%p)\n", This
, pUnkServer
);
1890 IUnknown_AddRef(pUnkServer
);
1891 This
->pUnk
= pUnkServer
;
1896 TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface
)
1898 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1900 TRACE("(%p)->()\n", This
);
1902 IUnknown_Release(This
->pUnk
);
1907 static HRESULT WINAPI
1909 LPRPCSTUBBUFFER iface
, RPCOLEMESSAGE
* xmsg
,IRpcChannelBuffer
*rpcchanbuf
)
1913 TMStubImpl
*This
= (TMStubImpl
*)iface
;
1915 DWORD
*args
, res
, *xargs
, nrofargs
;
1919 BSTR fname
= NULL
,iname
= NULL
;
1920 BOOL is_idispatch_getidsofnames
= 0;
1922 memset(&buf
,0,sizeof(buf
));
1923 buf
.size
= xmsg
->cbBuffer
;
1924 buf
.base
= xmsg
->Buffer
;
1926 buf
.iid
= IID_IUnknown
;
1929 if (xmsg
->iMethod
== 0) { /* QI */
1931 /* in: IID, out: <iface> */
1933 xbuf_get(&buf
,(LPBYTE
)&xiid
,sizeof(xiid
));
1935 hres
= _marshal_interface(&buf
,&xiid
,This
->pUnk
);
1936 xmsg
->Buffer
= buf
.base
; /* Might have been reallocated */
1937 xmsg
->cbBuffer
= buf
.size
;
1940 hres
= _get_funcdesc(This
->tinfo
,xmsg
->iMethod
,&fdesc
,&iname
,&fname
);
1942 ERR("GetFuncDesc on method %ld failed with %lx\n",xmsg
->iMethod
,hres
);
1946 if (iname
&& fname
&& !lstrcmpW(iname
, IDispatchW
) && !lstrcmpW(fname
, GetIDsOfNamesW
))
1947 is_idispatch_getidsofnames
= 1;
1949 if (iname
) SysFreeString (iname
);
1950 if (fname
) SysFreeString (fname
);
1952 /* Need them for hack below */
1953 memset(names
,0,sizeof(names
));
1954 ITypeInfo_GetNames(This
->tinfo
,fdesc
->memid
,names
,sizeof(names
)/sizeof(names
[0]),&nrofnames
);
1955 if (nrofnames
> sizeof(names
)/sizeof(names
[0])) {
1956 ERR("Need more names!\n");
1959 /*dump_FUNCDESC(fdesc);*/
1961 for (i
=0;i
<fdesc
->cParams
;i
++)
1962 nrofargs
+= _argsize(fdesc
->lprgelemdescParam
[i
].tdesc
.vt
);
1963 args
= HeapAlloc(GetProcessHeap(),0,(nrofargs
+1)*sizeof(DWORD
));
1964 if (!args
) return E_OUTOFMEMORY
;
1966 if (is_idispatch_getidsofnames
) {
1967 hres
= deserialize_IDispatch_GetIDsOfNames(TRUE
,FALSE
,args
+1,&buf
);
1969 FIXME("deserialize_IDispatch_GetIDsOfNames failed!\n");
1973 goto afterdeserialize
;
1976 /* Allocate all stuff used by call. */
1978 for (i
=0;i
<fdesc
->cParams
;i
++) {
1979 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
1980 BOOL isdeserialized
= FALSE
;
1982 if (((i
+1)<nrofnames
) && !IsBadStringPtrW(names
[i
+1],1)) {
1983 /* If the parameter is 'riid', we use it as interface IID
1984 * for a later ppvObject serialization.
1986 buf
.thisisiid
= !lstrcmpW(names
[i
+1],riidW
);
1988 /* deserialize DISPPARAM */
1989 if (!lstrcmpW(names
[i
+1],pdispparamsW
)) {
1990 hres
= deserialize_DISPPARAM_ptr(
1992 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
2000 ERR("Failed to deserialize DISPPARAM*, hres %lx\n",hres
);
2003 isdeserialized
= TRUE
;
2005 if (!lstrcmpW(names
[i
+1],ppvObjectW
)) {
2006 hres
= deserialize_LPVOID_ptr(
2008 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
2016 isdeserialized
= TRUE
;
2019 if (!isdeserialized
)
2020 hres
= deserialize_param(
2022 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FIN
,
2029 xargs
+= _argsize(elem
->tdesc
.vt
);
2031 ERR("Failed to deserialize param %s, hres %lx\n",relaystr(names
[i
+1]),hres
);
2036 hres
= IUnknown_QueryInterface(This
->pUnk
,&(This
->iid
),(LPVOID
*)&(args
[0]));
2038 ERR("Does not support iface %s, returning %lx\n",debugstr_guid(&(This
->iid
)), hres
);
2042 (*((FARPROC
**)args
[0]))[fdesc
->oVft
/4],
2047 IUnknown_Release((LPUNKNOWN
)args
[0]);
2050 /* special IDispatch::GetIDsOfNames serializer */
2051 if (is_idispatch_getidsofnames
) {
2052 hres
= serialize_IDispatch_GetIDsOfNames(FALSE
,FALSE
,args
+1,&buf
);
2054 FIXME("serialize of IDispatch::GetIDsOfNames failed!\n");
2057 goto afterserialize
;
2060 for (i
=0;i
<fdesc
->cParams
;i
++) {
2061 ELEMDESC
*elem
= fdesc
->lprgelemdescParam
+i
;
2062 BOOL isserialized
= FALSE
;
2064 if (((i
+1)<nrofnames
) && !IsBadStringPtrW(names
[i
+1],1)) {
2065 /* If the parameter is 'riid', we use it as interface IID
2066 * for a later ppvObject serialization.
2068 buf
.thisisiid
= !lstrcmpW(names
[i
+1],riidW
);
2070 /* DISPPARAMS* needs special serializer */
2071 if (!lstrcmpW(names
[i
+1],pdispparamsW
)) {
2072 hres
= serialize_DISPPARAM_ptr(
2074 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
2081 isserialized
= TRUE
;
2083 if (!lstrcmpW(names
[i
+1],ppvObjectW
)) {
2084 hres
= serialize_LPVOID_ptr(
2086 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
2094 isserialized
= TRUE
;
2098 hres
= serialize_param(
2100 elem
->u
.paramdesc
.wParamFlags
& PARAMFLAG_FOUT
,
2107 xargs
+= _argsize(elem
->tdesc
.vt
);
2109 ERR("Failed to stuballoc param, hres %lx\n",hres
);
2114 /* might need to use IRpcChannelBuffer_GetBuffer ? */
2115 xmsg
->cbBuffer
= buf
.curoff
;
2116 xmsg
->Buffer
= buf
.base
;
2117 HeapFree(GetProcessHeap(),0,args
);
2121 static LPRPCSTUBBUFFER WINAPI
2122 TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface
, REFIID riid
) {
2123 FIXME("Huh (%s)?\n",debugstr_guid(riid
));
2128 TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface
) {
2129 TMStubImpl
*This
= (TMStubImpl
*)iface
;
2131 return This
->ref
; /*FIXME? */
2134 static HRESULT WINAPI
2135 TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface
, LPVOID
*ppv
) {
2140 TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface
, LPVOID ppv
) {
2144 IRpcStubBufferVtbl tmstubvtbl
= {
2145 TMStubImpl_QueryInterface
,
2149 TMStubImpl_Disconnect
,
2151 TMStubImpl_IsIIDSupported
,
2152 TMStubImpl_CountRefs
,
2153 TMStubImpl_DebugServerQueryInterface
,
2154 TMStubImpl_DebugServerRelease
2157 static HRESULT WINAPI
2158 PSFacBuf_CreateStub(
2159 LPPSFACTORYBUFFER iface
, REFIID riid
,IUnknown
*pUnkServer
,
2160 IRpcStubBuffer
** ppStub
2166 TRACE("(%s,%p,%p)\n",debugstr_guid(riid
),pUnkServer
,ppStub
);
2167 hres
= _get_typeinfo_for_iid(riid
,&tinfo
);
2169 ERR("No typeinfo for %s?\n",debugstr_guid(riid
));
2172 stub
= CoTaskMemAlloc(sizeof(TMStubImpl
));
2174 return E_OUTOFMEMORY
;
2175 stub
->lpvtbl
= &tmstubvtbl
;
2177 stub
->tinfo
= tinfo
;
2178 memcpy(&(stub
->iid
),riid
,sizeof(*riid
));
2179 hres
= IRpcStubBuffer_Connect((LPRPCSTUBBUFFER
)stub
,pUnkServer
);
2180 *ppStub
= (LPRPCSTUBBUFFER
)stub
;
2181 TRACE("IRpcStubBuffer: %p\n", stub
);
2183 ERR("Connect to pUnkServer failed?\n");
2187 static IPSFactoryBufferVtbl psfacbufvtbl
= {
2188 PSFacBuf_QueryInterface
,
2191 PSFacBuf_CreateProxy
,
2195 /* This is the whole PSFactoryBuffer object, just the vtableptr */
2196 static IPSFactoryBufferVtbl
*lppsfac
= &psfacbufvtbl
;
2198 /***********************************************************************
2199 * DllGetClassObject [OLE32.63]
2202 TypeLibFac_DllGetClassObject(REFCLSID rclsid
, REFIID iid
,LPVOID
*ppv
)
2204 if (IsEqualIID(iid
,&IID_IPSFactoryBuffer
)) {
2208 return E_NOINTERFACE
;