1 | /*
|
---|
2 | * TYPELIB Marshaler
|
---|
3 | *
|
---|
4 | * Copyright 2002 Marcus Meissner
|
---|
5 | *
|
---|
6 | * This library is free software; you can redistribute it and/or
|
---|
7 | * modify it under the terms of the GNU Lesser General Public
|
---|
8 | * License as published by the Free Software Foundation; either
|
---|
9 | * version 2.1 of the License, or (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This library is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
14 | * Lesser General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU Lesser General Public
|
---|
17 | * License along with this library; if not, write to the Free Software
|
---|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
19 | */
|
---|
20 |
|
---|
21 | #include "config.h"
|
---|
22 |
|
---|
23 | #include <assert.h>
|
---|
24 | #include <stdlib.h>
|
---|
25 | #include <string.h>
|
---|
26 | #include <stdio.h>
|
---|
27 | #include <ctype.h>
|
---|
28 |
|
---|
29 | #include "winerror.h"
|
---|
30 | #include "winnls.h"
|
---|
31 | #include "winreg.h"
|
---|
32 | #include "winuser.h"
|
---|
33 |
|
---|
34 | #include "ole2.h"
|
---|
35 | #include "wine/unicode.h"
|
---|
36 | #include "wine/obj_base.h"
|
---|
37 | #include "wine/obj_channel.h"
|
---|
38 | #include "wine/obj_storage.h"
|
---|
39 | #include "heap.h"
|
---|
40 | #include "ole2disp.h"
|
---|
41 | #include "typelib.h"
|
---|
42 | #include "wine/debug.h"
|
---|
43 | #include "ntddk.h"
|
---|
44 |
|
---|
45 | static const WCHAR riidW[5] = {'r','i','i','d',0};
|
---|
46 | static const WCHAR pdispparamsW[] = {'p','d','i','s','p','p','a','r','a','m','s',0};
|
---|
47 | static const WCHAR ppvObjectW[] = {'p','p','v','O','b','j','e','c','t',0};
|
---|
48 |
|
---|
49 | WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
---|
50 | WINE_DECLARE_DEBUG_CHANNEL(olerelay);
|
---|
51 |
|
---|
52 | typedef struct _marshal_state {
|
---|
53 | LPBYTE base;
|
---|
54 | int size;
|
---|
55 | int curoff;
|
---|
56 |
|
---|
57 | BOOL thisisiid;
|
---|
58 | IID iid; /* HACK: for VT_VOID */
|
---|
59 | } marshal_state;
|
---|
60 |
|
---|
61 | static HRESULT
|
---|
62 | xbuf_add(marshal_state *buf, LPBYTE stuff, DWORD size) {
|
---|
63 | while (buf->size - buf->curoff < size) {
|
---|
64 | if (buf->base) {
|
---|
65 | buf->size += 100;
|
---|
66 | buf->base = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,buf->base,buf->size);
|
---|
67 | if (!buf->base)
|
---|
68 | return E_OUTOFMEMORY;
|
---|
69 | } else {
|
---|
70 | buf->base = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,32);
|
---|
71 | buf->size = 32;
|
---|
72 | if (!buf->base)
|
---|
73 | return E_OUTOFMEMORY;
|
---|
74 | }
|
---|
75 | }
|
---|
76 | memcpy(buf->base+buf->curoff,stuff,size);
|
---|
77 | buf->curoff += size;
|
---|
78 | return S_OK;
|
---|
79 | }
|
---|
80 |
|
---|
81 | static HRESULT
|
---|
82 | xbuf_get(marshal_state *buf, LPBYTE stuff, DWORD size) {
|
---|
83 | if (buf->size < buf->curoff+size) return E_FAIL;
|
---|
84 | memcpy(stuff,buf->base+buf->curoff,size);
|
---|
85 | buf->curoff += size;
|
---|
86 | return S_OK;
|
---|
87 | }
|
---|
88 |
|
---|
89 | static HRESULT
|
---|
90 | xbuf_skip(marshal_state *buf, DWORD size) {
|
---|
91 | if (buf->size < buf->curoff+size) return E_FAIL;
|
---|
92 | buf->curoff += size;
|
---|
93 | return S_OK;
|
---|
94 | }
|
---|
95 |
|
---|
96 | static HRESULT
|
---|
97 | _unmarshal_interface(marshal_state *buf, REFIID riid, LPUNKNOWN *pUnk) {
|
---|
98 | IStream *pStm;
|
---|
99 | ULARGE_INTEGER newpos;
|
---|
100 | LARGE_INTEGER seekto;
|
---|
101 | ULONG res;
|
---|
102 | HRESULT hres;
|
---|
103 | DWORD xsize;
|
---|
104 |
|
---|
105 | TRACE("...%s...\n",debugstr_guid(riid));
|
---|
106 | *pUnk = NULL;
|
---|
107 | hres = xbuf_get(buf,(LPBYTE)&xsize,sizeof(xsize));
|
---|
108 | if (hres) return hres;
|
---|
109 | if (xsize == 0) return S_OK;
|
---|
110 | hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
|
---|
111 | if (hres) {
|
---|
112 | FIXME("Stream create failed %lx\n",hres);
|
---|
113 | return hres;
|
---|
114 | }
|
---|
115 | hres = IStream_Write(pStm,buf->base+buf->curoff,xsize,&res);
|
---|
116 | if (hres) { FIXME("stream write %lx\n",hres); return hres; }
|
---|
117 | memset(&seekto,0,sizeof(seekto));
|
---|
118 | hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
|
---|
119 | if (hres) { FIXME("Failed Seek %lx\n",hres); return hres;}
|
---|
120 | hres = CoUnmarshalInterface(pStm,riid,(LPVOID*)pUnk);
|
---|
121 | if (hres) {
|
---|
122 | FIXME("Marshaling interface %s failed with %lx\n",debugstr_guid(riid),hres);
|
---|
123 | return hres;
|
---|
124 | }
|
---|
125 | IStream_Release(pStm);
|
---|
126 | return xbuf_skip(buf,xsize);
|
---|
127 | }
|
---|
128 |
|
---|
129 | static HRESULT
|
---|
130 | _marshal_interface(marshal_state *buf, REFIID riid, LPUNKNOWN pUnk) {
|
---|
131 | LPUNKNOWN newiface;
|
---|
132 | LPBYTE tempbuf;
|
---|
133 | IStream *pStm;
|
---|
134 | STATSTG ststg;
|
---|
135 | ULARGE_INTEGER newpos;
|
---|
136 | LARGE_INTEGER seekto;
|
---|
137 | ULONG res;
|
---|
138 | DWORD xsize;
|
---|
139 | HRESULT hres;
|
---|
140 |
|
---|
141 | hres = S_OK;
|
---|
142 | if (!pUnk)
|
---|
143 | goto fail;
|
---|
144 |
|
---|
145 | TRACE("...%s...\n",debugstr_guid(riid));
|
---|
146 | hres=IUnknown_QueryInterface(pUnk,riid,(LPVOID*)&newiface);
|
---|
147 | if (hres) {
|
---|
148 | TRACE("%p does not support iface %s\n",pUnk,debugstr_guid(riid));
|
---|
149 | goto fail;
|
---|
150 | }
|
---|
151 | hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
|
---|
152 | if (hres) {
|
---|
153 | FIXME("Stream create failed %lx\n",hres);
|
---|
154 | goto fail;
|
---|
155 | }
|
---|
156 | hres = CoMarshalInterface(pStm,riid,newiface,0,NULL,0);
|
---|
157 | IUnknown_Release(newiface);
|
---|
158 | if (hres) {
|
---|
159 | FIXME("Marshaling interface %s failed with %lx\n",
|
---|
160 | debugstr_guid(riid),hres
|
---|
161 | );
|
---|
162 | goto fail;
|
---|
163 | }
|
---|
164 | hres = IStream_Stat(pStm,&ststg,0);
|
---|
165 | tempbuf = HeapAlloc(GetProcessHeap(), 0, ststg.cbSize.s.LowPart);
|
---|
166 | memset(&seekto,0,sizeof(seekto));
|
---|
167 | hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
|
---|
168 | if (hres) { FIXME("Failed Seek %lx\n",hres); goto fail;}
|
---|
169 | hres = IStream_Read(pStm,tempbuf,ststg.cbSize.s.LowPart,&res);
|
---|
170 | if (hres) { FIXME("Failed Read %lx\n",hres); goto fail;}
|
---|
171 | IStream_Release(pStm);
|
---|
172 | xsize = ststg.cbSize.s.LowPart;
|
---|
173 | xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
|
---|
174 | hres = xbuf_add(buf,tempbuf,ststg.cbSize.s.LowPart);
|
---|
175 | HeapFree(GetProcessHeap(),0,tempbuf);
|
---|
176 | return hres;
|
---|
177 | fail:
|
---|
178 | xsize = 0;
|
---|
179 | xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
|
---|
180 | return hres;
|
---|
181 | }
|
---|
182 |
|
---|
183 | /********************* OLE Proxy/Stub Factory ********************************/
|
---|
184 | static HRESULT WINAPI
|
---|
185 | PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface, REFIID iid, LPVOID *ppv) {
|
---|
186 | if (IsEqualIID(iid,&IID_IPSFactoryBuffer)||IsEqualIID(iid,&IID_IUnknown)) {
|
---|
187 | *ppv = (LPVOID)iface;
|
---|
188 | /* No ref counting, static class */
|
---|
189 | return S_OK;
|
---|
190 | }
|
---|
191 | FIXME("(%s) unknown IID?\n",debugstr_guid(iid));
|
---|
192 | return E_NOINTERFACE;
|
---|
193 | }
|
---|
194 |
|
---|
195 | static ULONG WINAPI PSFacBuf_AddRef(LPPSFACTORYBUFFER iface) { return 2; }
|
---|
196 | static ULONG WINAPI PSFacBuf_Release(LPPSFACTORYBUFFER iface) { return 1; }
|
---|
197 |
|
---|
198 | static HRESULT
|
---|
199 | _get_typeinfo_for_iid(REFIID riid, ITypeInfo**ti) {
|
---|
200 | HRESULT hres;
|
---|
201 | HKEY ikey;
|
---|
202 | char tlguid[200],typelibkey[300],interfacekey[300],ver[100];
|
---|
203 | char tlfn[260];
|
---|
204 | OLECHAR tlfnW[260];
|
---|
205 | DWORD tlguidlen, verlen, type, tlfnlen;
|
---|
206 | ITypeLib *tl;
|
---|
207 |
|
---|
208 | sprintf( interfacekey, "Interface\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\Typelib",
|
---|
209 | riid->Data1, riid->Data2, riid->Data3,
|
---|
210 | riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
|
---|
211 | riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7]
|
---|
212 | );
|
---|
213 |
|
---|
214 | if (RegOpenKeyA(HKEY_CLASSES_ROOT,interfacekey,&ikey)) {
|
---|
215 | FIXME("No %s key found.\n",interfacekey);
|
---|
216 | return E_FAIL;
|
---|
217 | }
|
---|
218 | type = (1<<REG_SZ);
|
---|
219 | tlguidlen = sizeof(tlguid);
|
---|
220 | if (RegQueryValueExA(ikey,NULL,NULL,&type,tlguid,&tlguidlen)) {
|
---|
221 | FIXME("Getting typelib guid failed.\n");
|
---|
222 | RegCloseKey(ikey);
|
---|
223 | return E_FAIL;
|
---|
224 | }
|
---|
225 | type = (1<<REG_SZ);
|
---|
226 | verlen = sizeof(ver);
|
---|
227 | if (RegQueryValueExA(ikey,"Version",NULL,&type,ver,&verlen)) {
|
---|
228 | FIXME("Could not get version value?\n");
|
---|
229 | RegCloseKey(ikey);
|
---|
230 | return E_FAIL;
|
---|
231 | }
|
---|
232 | RegCloseKey(ikey);
|
---|
233 | sprintf(typelibkey,"Typelib\\%s\\%s\\0\\win32",tlguid,ver);
|
---|
234 | tlfnlen = sizeof(tlfn);
|
---|
235 | if (RegQueryValueA(HKEY_CLASSES_ROOT,typelibkey,tlfn,&tlfnlen)) {
|
---|
236 | FIXME("Could not get typelib fn?\n");
|
---|
237 | return E_FAIL;
|
---|
238 | }
|
---|
239 | MultiByteToWideChar(CP_ACP, 0, tlfn, -1, tlfnW, -1);
|
---|
240 | hres = LoadTypeLib(tlfnW,&tl);
|
---|
241 | if (hres) {
|
---|
242 | ERR("Failed to load typelib for %s, but it should be there.\n",debugstr_guid(riid));
|
---|
243 | return hres;
|
---|
244 | }
|
---|
245 | hres = ITypeLib_GetTypeInfoOfGuid(tl,riid,ti);
|
---|
246 | if (hres) {
|
---|
247 | ERR("typelib does not contain info for %s?\n",debugstr_guid(riid));
|
---|
248 | ITypeLib_Release(tl);
|
---|
249 | return hres;
|
---|
250 | }
|
---|
251 | /* FIXME: do this? ITypeLib_Release(tl); */
|
---|
252 | return hres;
|
---|
253 | }
|
---|
254 |
|
---|
255 | /* Determine nr of functions. Since we use the toplevel interface and all
|
---|
256 | * inherited ones have lower numbers, we are ok to not to descent into
|
---|
257 | * the inheritance tree I think.
|
---|
258 | */
|
---|
259 | static int _nroffuncs(ITypeInfo *tinfo) {
|
---|
260 | int n, max = 0;
|
---|
261 | FUNCDESC *fdesc;
|
---|
262 | HRESULT hres;
|
---|
263 |
|
---|
264 | n=0;
|
---|
265 | while (1) {
|
---|
266 | hres = ITypeInfo_GetFuncDesc(tinfo,n,&fdesc);
|
---|
267 | if (fdesc->oVft/4 > max)
|
---|
268 | max = fdesc->oVft/4;
|
---|
269 | if (hres)
|
---|
270 | return max+1;
|
---|
271 | n++;
|
---|
272 | }
|
---|
273 | /*NOTREACHED*/
|
---|
274 | }
|
---|
275 |
|
---|
276 | #ifdef __WIN32OS2__
|
---|
277 | #include <pshpack1.h>
|
---|
278 | #endif
|
---|
279 | typedef struct _TMAsmProxy {
|
---|
280 | BYTE popleax;
|
---|
281 | BYTE pushlval;
|
---|
282 | BYTE nr;
|
---|
283 | BYTE pushleax;
|
---|
284 | BYTE lcall;
|
---|
285 | DWORD xcall;
|
---|
286 | BYTE lret;
|
---|
287 | WORD bytestopop;
|
---|
288 | } WINE_PACKED TMAsmProxy;
|
---|
289 | #ifdef __WIN32OS2__
|
---|
290 | #include <poppack.h>
|
---|
291 | #endif
|
---|
292 |
|
---|
293 | typedef struct _TMProxyImpl {
|
---|
294 | DWORD *lpvtbl;
|
---|
295 | ICOM_VTABLE(IRpcProxyBuffer) *lpvtbl2;
|
---|
296 | DWORD ref;
|
---|
297 |
|
---|
298 | TMAsmProxy *asmstubs;
|
---|
299 | ITypeInfo* tinfo;
|
---|
300 | IRpcChannelBuffer* chanbuf;
|
---|
301 | IID iid;
|
---|
302 | } TMProxyImpl;
|
---|
303 |
|
---|
304 | static HRESULT WINAPI
|
---|
305 | TMProxyImpl_QueryInterface(LPRPCPROXYBUFFER iface, REFIID riid, LPVOID *ppv) {
|
---|
306 | TRACE("()\n");
|
---|
307 | if (IsEqualIID(riid,&IID_IUnknown)||IsEqualIID(riid,&IID_IRpcProxyBuffer)) {
|
---|
308 | *ppv = (LPVOID)iface;
|
---|
309 | IRpcProxyBuffer_AddRef(iface);
|
---|
310 | return S_OK;
|
---|
311 | }
|
---|
312 | FIXME("no interface for %s\n",debugstr_guid(riid));
|
---|
313 | return E_NOINTERFACE;
|
---|
314 | }
|
---|
315 |
|
---|
316 | static ULONG WINAPI
|
---|
317 | TMProxyImpl_AddRef(LPRPCPROXYBUFFER iface) {
|
---|
318 | ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
|
---|
319 |
|
---|
320 | TRACE("()\n");
|
---|
321 | This->ref++;
|
---|
322 | return This->ref;
|
---|
323 | }
|
---|
324 |
|
---|
325 | static ULONG WINAPI
|
---|
326 | TMProxyImpl_Release(LPRPCPROXYBUFFER iface) {
|
---|
327 | ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
|
---|
328 |
|
---|
329 | TRACE("()\n");
|
---|
330 | This->ref--;
|
---|
331 | if (This->ref) return This->ref;
|
---|
332 | if (This->chanbuf) IRpcChannelBuffer_Release(This->chanbuf);
|
---|
333 | HeapFree(GetProcessHeap(),0,This);
|
---|
334 | return 0;
|
---|
335 | }
|
---|
336 |
|
---|
337 | static HRESULT WINAPI
|
---|
338 | TMProxyImpl_Connect(
|
---|
339 | LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer
|
---|
340 | ) {
|
---|
341 | ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
|
---|
342 |
|
---|
343 | TRACE("(%p)\n",pRpcChannelBuffer);
|
---|
344 | This->chanbuf = pRpcChannelBuffer;
|
---|
345 | IRpcChannelBuffer_AddRef(This->chanbuf);
|
---|
346 | return S_OK;
|
---|
347 | }
|
---|
348 |
|
---|
349 | static void WINAPI
|
---|
350 | TMProxyImpl_Disconnect(LPRPCPROXYBUFFER iface) {
|
---|
351 | ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
|
---|
352 |
|
---|
353 | FIXME("()\n");
|
---|
354 | IRpcChannelBuffer_Release(This->chanbuf);
|
---|
355 | This->chanbuf = NULL;
|
---|
356 | }
|
---|
357 |
|
---|
358 |
|
---|
359 | static ICOM_VTABLE(IRpcProxyBuffer) tmproxyvtable = {
|
---|
360 | ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
---|
361 | TMProxyImpl_QueryInterface,
|
---|
362 | TMProxyImpl_AddRef,
|
---|
363 | TMProxyImpl_Release,
|
---|
364 | TMProxyImpl_Connect,
|
---|
365 | TMProxyImpl_Disconnect
|
---|
366 | };
|
---|
367 |
|
---|
368 | /* how much space do we use on stack in DWORD steps. */
|
---|
369 | static int const
|
---|
370 | _argsize(DWORD vt) {
|
---|
371 | switch (vt) {
|
---|
372 | case VT_VARIANT:
|
---|
373 | return (sizeof(VARIANT)+3)/sizeof(DWORD);
|
---|
374 | default:
|
---|
375 | return 1;
|
---|
376 | }
|
---|
377 | }
|
---|
378 |
|
---|
379 | static int
|
---|
380 | _xsize(TYPEDESC *td) {
|
---|
381 | switch (td->vt) {
|
---|
382 | case VT_VARIANT:
|
---|
383 | return sizeof(VARIANT)+3;
|
---|
384 | case VT_CARRAY: {
|
---|
385 | int i, arrsize = 1;
|
---|
386 | ARRAYDESC *adesc = td->u.lpadesc;
|
---|
387 |
|
---|
388 | for (i=0;i<adesc->cDims;i++)
|
---|
389 | arrsize *= adesc->rgbounds[i].cElements;
|
---|
390 | return arrsize*_xsize(&adesc->tdescElem);
|
---|
391 | }
|
---|
392 | case VT_UI2:
|
---|
393 | case VT_I2:
|
---|
394 | return 2;
|
---|
395 | case VT_UI1:
|
---|
396 | case VT_I1:
|
---|
397 | return 1;
|
---|
398 | default:
|
---|
399 | return 4;
|
---|
400 | }
|
---|
401 | }
|
---|
402 |
|
---|
403 | static HRESULT
|
---|
404 | serialize_param(
|
---|
405 | ITypeInfo *tinfo,
|
---|
406 | BOOL writeit,
|
---|
407 | BOOL debugout,
|
---|
408 | BOOL dealloc,
|
---|
409 | TYPEDESC *tdesc,
|
---|
410 | DWORD *arg,
|
---|
411 | marshal_state *buf
|
---|
412 | ) {
|
---|
413 | HRESULT hres = S_OK;
|
---|
414 |
|
---|
415 | TRACE("(tdesc.vt %d)\n",tdesc->vt);
|
---|
416 |
|
---|
417 | switch (tdesc->vt) {
|
---|
418 | case VT_EMPTY: /* nothing. empty variant for instance */
|
---|
419 | return S_OK;
|
---|
420 | case VT_BOOL:
|
---|
421 | case VT_ERROR:
|
---|
422 | case VT_UI4:
|
---|
423 | case VT_UINT:
|
---|
424 | case VT_I4:
|
---|
425 | case VT_UI2:
|
---|
426 | case VT_UI1:
|
---|
427 | hres = S_OK;
|
---|
428 | if (debugout) MESSAGE("%lx",*arg);
|
---|
429 | if (writeit)
|
---|
430 | hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
|
---|
431 | return hres;
|
---|
432 | case VT_VARIANT: {
|
---|
433 | TYPEDESC tdesc2;
|
---|
434 | VARIANT *vt = (VARIANT*)arg;
|
---|
435 | DWORD vttype = V_VT(vt);
|
---|
436 |
|
---|
437 | if (debugout) MESSAGE("Vt(%ld)(",vttype);
|
---|
438 | tdesc2.vt = vttype;
|
---|
439 | if (writeit) {
|
---|
440 | hres = xbuf_add(buf,(LPBYTE)&vttype,sizeof(vttype));
|
---|
441 | if (hres) return hres;
|
---|
442 | }
|
---|
443 | /* need to recurse since we need to free the stuff */
|
---|
444 | hres = serialize_param(tinfo,writeit,debugout,dealloc,&tdesc2,&(V_I4(vt)),buf);
|
---|
445 | if (debugout) MESSAGE(")");
|
---|
446 | return hres;
|
---|
447 | }
|
---|
448 | case VT_BSTR: {
|
---|
449 | if (debugout) {
|
---|
450 | if (arg)
|
---|
451 | MESSAGE("%s",debugstr_w((BSTR)*arg));
|
---|
452 | else
|
---|
453 | MESSAGE("<bstr NULL>");
|
---|
454 | }
|
---|
455 | if (writeit) {
|
---|
456 | if (!*arg) {
|
---|
457 | DWORD fakelen = -1;
|
---|
458 | hres = xbuf_add(buf,(LPBYTE)&fakelen,4);
|
---|
459 | if (hres)
|
---|
460 | return hres;
|
---|
461 | } else {
|
---|
462 | DWORD *bstr = ((DWORD*)(*arg))-1;
|
---|
463 |
|
---|
464 | hres = xbuf_add(buf,(LPBYTE)bstr,bstr[0]+4);
|
---|
465 | if (hres)
|
---|
466 | return hres;
|
---|
467 | }
|
---|
468 | }
|
---|
469 | if (dealloc && arg)
|
---|
470 | SysFreeString((BSTR)arg);
|
---|
471 | return S_OK;
|
---|
472 | }
|
---|
473 | case VT_PTR: {
|
---|
474 | DWORD cookie;
|
---|
475 |
|
---|
476 | if (debugout) MESSAGE("*");
|
---|
477 | if (writeit) {
|
---|
478 | cookie = *arg ? 0x42424242 : 0;
|
---|
479 | hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
|
---|
480 | if (hres)
|
---|
481 | return hres;
|
---|
482 | }
|
---|
483 | if (!*arg) {
|
---|
484 | if (debugout) MESSAGE("NULL");
|
---|
485 | return S_OK;
|
---|
486 | }
|
---|
487 | hres = serialize_param(tinfo,writeit,debugout,dealloc,tdesc->u.lptdesc,(DWORD*)*arg,buf);
|
---|
488 | if (dealloc) HeapFree(GetProcessHeap(),0,(LPVOID)arg);
|
---|
489 | return hres;
|
---|
490 | }
|
---|
491 | case VT_UNKNOWN:
|
---|
492 | if (debugout) MESSAGE("unk(0x%lx)",*arg);
|
---|
493 | if (writeit)
|
---|
494 | hres = _marshal_interface(buf,&IID_IUnknown,(LPUNKNOWN)*arg);
|
---|
495 | return hres;
|
---|
496 | case VT_DISPATCH:
|
---|
497 | if (debugout) MESSAGE("idisp(0x%lx)",*arg);
|
---|
498 | if (writeit)
|
---|
499 | hres = _marshal_interface(buf,&IID_IDispatch,(LPUNKNOWN)*arg);
|
---|
500 | return hres;
|
---|
501 | case VT_VOID:
|
---|
502 | if (debugout) MESSAGE("<void>");
|
---|
503 | return S_OK;
|
---|
504 | case VT_USERDEFINED: {
|
---|
505 | ITypeInfo *tinfo2;
|
---|
506 | TYPEATTR *tattr;
|
---|
507 |
|
---|
508 | hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
|
---|
509 | if (hres) {
|
---|
510 | FIXME("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
|
---|
511 | return hres;
|
---|
512 | }
|
---|
513 | ITypeInfo_GetTypeAttr(tinfo2,&tattr);
|
---|
514 | switch (tattr->typekind) {
|
---|
515 | case TKIND_INTERFACE:
|
---|
516 | if (writeit)
|
---|
517 | hres=_marshal_interface(buf,&(tattr->guid),(LPUNKNOWN)arg);
|
---|
518 | break;
|
---|
519 | case TKIND_RECORD: {
|
---|
520 | int i;
|
---|
521 | if (debugout) MESSAGE("{");
|
---|
522 | for (i=0;i<tattr->cVars;i++) {
|
---|
523 | VARDESC *vdesc;
|
---|
524 | ELEMDESC *elem2;
|
---|
525 | TYPEDESC *tdesc2;
|
---|
526 |
|
---|
527 | hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
|
---|
528 | if (hres) {
|
---|
529 | FIXME("Could not get vardesc of %d\n",i);
|
---|
530 | return hres;
|
---|
531 | }
|
---|
532 | /* Need them for hack below */
|
---|
533 | /*
|
---|
534 | memset(names,0,sizeof(names));
|
---|
535 | hres = ITypeInfo_GetNames(tinfo2,vdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
|
---|
536 | if (nrofnames > sizeof(names)/sizeof(names[0])) {
|
---|
537 | ERR("Need more names!\n");
|
---|
538 | }
|
---|
539 | if (!hres && debugout)
|
---|
540 | MESSAGE("%s=",debugstr_w(names[0]));
|
---|
541 | */
|
---|
542 | elem2 = &vdesc->elemdescVar;
|
---|
543 | tdesc2 = &elem2->tdesc;
|
---|
544 | hres = serialize_param(
|
---|
545 | tinfo2,
|
---|
546 | writeit,
|
---|
547 | debugout,
|
---|
548 | dealloc,
|
---|
549 | tdesc2,
|
---|
550 | (DWORD*)(((LPBYTE)arg)+vdesc->u.oInst),
|
---|
551 | buf
|
---|
552 | );
|
---|
553 | if (hres!=S_OK)
|
---|
554 | return hres;
|
---|
555 | if (debugout && (i<(tattr->cVars-1)))
|
---|
556 | MESSAGE(",");
|
---|
557 | }
|
---|
558 | if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
|
---|
559 | memcpy(&(buf->iid),arg,sizeof(buf->iid));
|
---|
560 | if (debugout) MESSAGE("}");
|
---|
561 | break;
|
---|
562 | }
|
---|
563 | default:
|
---|
564 | FIXME("Don't know how to marshal type kind %d\n",tattr->typekind);
|
---|
565 | hres = E_FAIL;
|
---|
566 | break;
|
---|
567 | }
|
---|
568 | ITypeInfo_Release(tinfo2);
|
---|
569 | return hres;
|
---|
570 | }
|
---|
571 | case VT_CARRAY: {
|
---|
572 | ARRAYDESC *adesc = tdesc->u.lpadesc;
|
---|
573 | int i, arrsize = 1;
|
---|
574 |
|
---|
575 | if (debugout) MESSAGE("carr");
|
---|
576 | for (i=0;i<adesc->cDims;i++) {
|
---|
577 | if (debugout) MESSAGE("[%ld]",adesc->rgbounds[i].cElements);
|
---|
578 | arrsize *= adesc->rgbounds[i].cElements;
|
---|
579 | }
|
---|
580 | if (debugout) MESSAGE("[");
|
---|
581 | for (i=0;i<arrsize;i++) {
|
---|
582 | hres = serialize_param(tinfo, writeit, debugout, dealloc, &adesc->tdescElem, (DWORD*)((LPBYTE)arg+i*_xsize(&adesc->tdescElem)), buf);
|
---|
583 | if (hres)
|
---|
584 | return hres;
|
---|
585 | if (debugout && (i<arrsize-1)) MESSAGE(",");
|
---|
586 | }
|
---|
587 | if (debugout) MESSAGE("]");
|
---|
588 | return S_OK;
|
---|
589 | }
|
---|
590 | default:
|
---|
591 | ERR("Unhandled marshal type %d.\n",tdesc->vt);
|
---|
592 | return S_OK;
|
---|
593 | }
|
---|
594 | }
|
---|
595 |
|
---|
596 | static HRESULT
|
---|
597 | serialize_LPVOID_ptr(
|
---|
598 | ITypeInfo *tinfo,
|
---|
599 | BOOL writeit,
|
---|
600 | BOOL debugout,
|
---|
601 | BOOL dealloc,
|
---|
602 | TYPEDESC *tdesc,
|
---|
603 | DWORD *arg,
|
---|
604 | marshal_state *buf
|
---|
605 | ) {
|
---|
606 | HRESULT hres;
|
---|
607 | DWORD cookie;
|
---|
608 |
|
---|
609 | if ((tdesc->vt != VT_PTR) ||
|
---|
610 | (tdesc->u.lptdesc->vt != VT_PTR) ||
|
---|
611 | (tdesc->u.lptdesc->u.lptdesc->vt != VT_VOID)
|
---|
612 | ) {
|
---|
613 | FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
|
---|
614 | return E_FAIL;
|
---|
615 | }
|
---|
616 | cookie = (*arg) ? 0x42424242: 0x0;
|
---|
617 | if (writeit) {
|
---|
618 | hres = xbuf_add(buf, (LPVOID)&cookie, sizeof(cookie));
|
---|
619 | if (hres)
|
---|
620 | return hres;
|
---|
621 | }
|
---|
622 | if (!*arg) {
|
---|
623 | if (debugout) MESSAGE("<lpvoid NULL>");
|
---|
624 | return S_OK;
|
---|
625 | }
|
---|
626 | if (debugout)
|
---|
627 | MESSAGE("ppv(%p)",*(LPUNKNOWN*)*arg);
|
---|
628 | if (writeit) {
|
---|
629 | hres = _marshal_interface(buf,&(buf->iid),*(LPUNKNOWN*)*arg);
|
---|
630 | if (hres)
|
---|
631 | return hres;
|
---|
632 | }
|
---|
633 | if (dealloc)
|
---|
634 | HeapFree(GetProcessHeap(),0,(LPVOID)*arg);
|
---|
635 | return S_OK;
|
---|
636 | }
|
---|
637 |
|
---|
638 | static HRESULT
|
---|
639 | serialize_DISPPARAM_ptr(
|
---|
640 | ITypeInfo *tinfo,
|
---|
641 | BOOL writeit,
|
---|
642 | BOOL debugout,
|
---|
643 | BOOL dealloc,
|
---|
644 | TYPEDESC *tdesc,
|
---|
645 | DWORD *arg,
|
---|
646 | marshal_state *buf
|
---|
647 | ) {
|
---|
648 | DWORD cookie;
|
---|
649 | HRESULT hres;
|
---|
650 | DISPPARAMS *disp;
|
---|
651 | int i;
|
---|
652 |
|
---|
653 | if ((tdesc->vt != VT_PTR) || (tdesc->u.lptdesc->vt != VT_USERDEFINED)) {
|
---|
654 | FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
|
---|
655 | return E_FAIL;
|
---|
656 | }
|
---|
657 |
|
---|
658 | cookie = *arg ? 0x42424242 : 0x0;
|
---|
659 | if (writeit) {
|
---|
660 | hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
|
---|
661 | if (hres)
|
---|
662 | return hres;
|
---|
663 | }
|
---|
664 | if (!*arg) {
|
---|
665 | if (debugout) MESSAGE("<DISPPARAMS NULL>");
|
---|
666 | return S_OK;
|
---|
667 | }
|
---|
668 | disp = (DISPPARAMS*)*arg;
|
---|
669 | if (writeit) {
|
---|
670 | hres = xbuf_add(buf,(LPBYTE)&disp->cArgs,sizeof(disp->cArgs));
|
---|
671 | if (hres)
|
---|
672 | return hres;
|
---|
673 | }
|
---|
674 | if (debugout) MESSAGE("D{");
|
---|
675 | for (i=0;i<disp->cArgs;i++) {
|
---|
676 | TYPEDESC vtdesc;
|
---|
677 |
|
---|
678 | vtdesc.vt = VT_VARIANT;
|
---|
679 | serialize_param(
|
---|
680 | tinfo,
|
---|
681 | writeit,
|
---|
682 | debugout,
|
---|
683 | dealloc,
|
---|
684 | &vtdesc,
|
---|
685 | (DWORD*)(disp->rgvarg+i),
|
---|
686 | buf
|
---|
687 | );
|
---|
688 | if (debugout && (i<disp->cArgs-1))
|
---|
689 | MESSAGE(",");
|
---|
690 | }
|
---|
691 | if (dealloc)
|
---|
692 | HeapFree(GetProcessHeap(),0,disp->rgvarg);
|
---|
693 | if (writeit) {
|
---|
694 | hres = xbuf_add(buf,(LPBYTE)&disp->cNamedArgs,sizeof(disp->cNamedArgs));
|
---|
695 | if (hres)
|
---|
696 | return hres;
|
---|
697 | }
|
---|
698 | if (debugout) MESSAGE("}{");
|
---|
699 | for (i=0;i<disp->cNamedArgs;i++) {
|
---|
700 | TYPEDESC vtdesc;
|
---|
701 |
|
---|
702 | vtdesc.vt = VT_UINT;
|
---|
703 | serialize_param(
|
---|
704 | tinfo,
|
---|
705 | writeit,
|
---|
706 | debugout,
|
---|
707 | dealloc,
|
---|
708 | &vtdesc,
|
---|
709 | (DWORD*)(disp->rgdispidNamedArgs+i),
|
---|
710 | buf
|
---|
711 | );
|
---|
712 | if (debugout && (i<disp->cNamedArgs-1))
|
---|
713 | MESSAGE(",");
|
---|
714 | }
|
---|
715 | if (debugout) MESSAGE("}");
|
---|
716 | if (dealloc) {
|
---|
717 | HeapFree(GetProcessHeap(),0,disp->rgdispidNamedArgs);
|
---|
718 | HeapFree(GetProcessHeap(),0,disp);
|
---|
719 | }
|
---|
720 | return S_OK;
|
---|
721 | }
|
---|
722 |
|
---|
723 | static HRESULT
|
---|
724 | deserialize_param(
|
---|
725 | ITypeInfo *tinfo,
|
---|
726 | BOOL readit,
|
---|
727 | BOOL debugout,
|
---|
728 | BOOL alloc,
|
---|
729 | TYPEDESC *tdesc,
|
---|
730 | DWORD *arg,
|
---|
731 | marshal_state *buf
|
---|
732 | ) {
|
---|
733 | HRESULT hres = S_OK;
|
---|
734 |
|
---|
735 | TRACE("vt %d at %p\n",tdesc->vt,arg);
|
---|
736 |
|
---|
737 | while (1) {
|
---|
738 | switch (tdesc->vt) {
|
---|
739 | case VT_EMPTY:
|
---|
740 | if (debugout) MESSAGE("<empty>");
|
---|
741 | return S_OK;
|
---|
742 | case VT_NULL:
|
---|
743 | if (debugout) MESSAGE("<null>");
|
---|
744 | return S_OK;
|
---|
745 | case VT_VARIANT: {
|
---|
746 | VARIANT *vt = (VARIANT*)arg;
|
---|
747 |
|
---|
748 | if (readit) {
|
---|
749 | DWORD vttype;
|
---|
750 | TYPEDESC tdesc2;
|
---|
751 | hres = xbuf_get(buf,(LPBYTE)&vttype,sizeof(vttype));
|
---|
752 | if (hres) {
|
---|
753 | FIXME("vt type not read?\n");
|
---|
754 | return hres;
|
---|
755 | }
|
---|
756 | memset(&tdesc2,0,sizeof(tdesc2));
|
---|
757 | tdesc2.vt = vttype;
|
---|
758 | V_VT(vt) = vttype;
|
---|
759 | if (debugout) MESSAGE("Vt(%ld)(",vttype);
|
---|
760 | hres = deserialize_param(tinfo, readit, debugout, alloc, &tdesc2, &(V_I4(vt)), buf);
|
---|
761 | MESSAGE(")");
|
---|
762 | return hres;
|
---|
763 | } else {
|
---|
764 | VariantInit(vt);
|
---|
765 | return S_OK;
|
---|
766 | }
|
---|
767 | }
|
---|
768 | case VT_ERROR:
|
---|
769 | case VT_BOOL: case VT_I4: case VT_UI4: case VT_UINT:
|
---|
770 | case VT_UI2:
|
---|
771 | case VT_UI1:
|
---|
772 | if (readit) {
|
---|
773 | hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
|
---|
774 | if (hres) FIXME("Failed to read integer 4 byte\n");
|
---|
775 | }
|
---|
776 | if (debugout) MESSAGE("%lx",*arg);
|
---|
777 | return hres;
|
---|
778 | case VT_BSTR: {
|
---|
779 | WCHAR *str;
|
---|
780 | DWORD len;
|
---|
781 |
|
---|
782 | if (readit) {
|
---|
783 | hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
|
---|
784 | if (hres) {
|
---|
785 | FIXME("failed to read bstr klen\n");
|
---|
786 | return hres;
|
---|
787 | }
|
---|
788 | if (len == -1) {
|
---|
789 | *arg = 0;
|
---|
790 | if (debugout) MESSAGE("<bstr NULL>");
|
---|
791 | } else {
|
---|
792 | str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len+sizeof(WCHAR));
|
---|
793 | hres = xbuf_get(buf,(LPBYTE)str,len);
|
---|
794 | if (hres) {
|
---|
795 | FIXME("Failed to read BSTR.\n");
|
---|
796 | return hres;
|
---|
797 | }
|
---|
798 | *arg = (DWORD)SysAllocStringLen(str,len);
|
---|
799 | if (debugout) MESSAGE("%s",debugstr_w(str));
|
---|
800 | HeapFree(GetProcessHeap(),0,str);
|
---|
801 | }
|
---|
802 | } else {
|
---|
803 | *arg = 0;
|
---|
804 | }
|
---|
805 | return S_OK;
|
---|
806 | }
|
---|
807 | case VT_PTR: {
|
---|
808 | DWORD cookie;
|
---|
809 | BOOL derefhere = 0;
|
---|
810 |
|
---|
811 | derefhere = (tdesc->u.lptdesc->vt != VT_USERDEFINED);
|
---|
812 |
|
---|
813 | if (readit) {
|
---|
814 | hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
|
---|
815 | if (hres) {
|
---|
816 | FIXME("Failed to load pointer cookie.\n");
|
---|
817 | return hres;
|
---|
818 | }
|
---|
819 | if (cookie != 0x42424242) {
|
---|
820 | if (debugout) MESSAGE("NULL");
|
---|
821 | *arg = 0;
|
---|
822 | return S_OK;
|
---|
823 | }
|
---|
824 | if (debugout) MESSAGE("*");
|
---|
825 | }
|
---|
826 | if (alloc) {
|
---|
827 | if (derefhere)
|
---|
828 | *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,_xsize(tdesc->u.lptdesc));
|
---|
829 | }
|
---|
830 | if (derefhere)
|
---|
831 | return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, (LPDWORD)*arg, buf);
|
---|
832 | else
|
---|
833 | return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, arg, buf);
|
---|
834 | }
|
---|
835 | case VT_UNKNOWN:
|
---|
836 | /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
|
---|
837 | if (alloc)
|
---|
838 | *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
|
---|
839 | hres = S_OK;
|
---|
840 | if (readit)
|
---|
841 | hres = _unmarshal_interface(buf,&IID_IUnknown,(LPUNKNOWN*)arg);
|
---|
842 | if (debugout)
|
---|
843 | MESSAGE("unk(%p)",arg);
|
---|
844 | return hres;
|
---|
845 | case VT_DISPATCH:
|
---|
846 | hres = S_OK;
|
---|
847 | if (readit)
|
---|
848 | hres = _unmarshal_interface(buf,&IID_IDispatch,(LPUNKNOWN*)arg);
|
---|
849 | if (debugout)
|
---|
850 | MESSAGE("idisp(%p)",arg);
|
---|
851 | return hres;
|
---|
852 | case VT_VOID:
|
---|
853 | if (debugout) MESSAGE("<void>");
|
---|
854 | return S_OK;
|
---|
855 | case VT_USERDEFINED: {
|
---|
856 | ITypeInfo *tinfo2;
|
---|
857 | TYPEATTR *tattr;
|
---|
858 |
|
---|
859 | hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
|
---|
860 | if (hres) {
|
---|
861 | FIXME("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
|
---|
862 | return hres;
|
---|
863 | }
|
---|
864 | hres = ITypeInfo_GetTypeAttr(tinfo2,&tattr);
|
---|
865 | if (hres) {
|
---|
866 | FIXME("Could not get typeattr in VT_USERDEFINED.\n");
|
---|
867 | } else {
|
---|
868 | if (alloc)
|
---|
869 | *arg = (DWORD)HeapAlloc(GetProcessHeap(),0,tattr->cbSizeInstance);
|
---|
870 | switch (tattr->typekind) {
|
---|
871 | case TKIND_INTERFACE:
|
---|
872 | if (readit)
|
---|
873 | hres = _unmarshal_interface(buf,&(tattr->guid),(LPUNKNOWN*)arg);
|
---|
874 | break;
|
---|
875 | case TKIND_RECORD: {
|
---|
876 | int i;
|
---|
877 |
|
---|
878 | if (debugout) MESSAGE("{");
|
---|
879 | for (i=0;i<tattr->cVars;i++) {
|
---|
880 | VARDESC *vdesc;
|
---|
881 |
|
---|
882 | hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
|
---|
883 | if (hres) {
|
---|
884 | FIXME("Could not get vardesc of %d\n",i);
|
---|
885 | return hres;
|
---|
886 | }
|
---|
887 | hres = deserialize_param(
|
---|
888 | tinfo2,
|
---|
889 | readit,
|
---|
890 | debugout,
|
---|
891 | alloc,
|
---|
892 | &vdesc->elemdescVar.tdesc,
|
---|
893 | (DWORD*)(((LPBYTE)*arg)+vdesc->u.oInst),
|
---|
894 | buf
|
---|
895 | );
|
---|
896 | if (debugout && (i<tattr->cVars-1)) MESSAGE(",");
|
---|
897 | }
|
---|
898 | if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
|
---|
899 | memcpy(&(buf->iid),(LPBYTE)*arg,sizeof(buf->iid));
|
---|
900 | if (debugout) MESSAGE("}");
|
---|
901 | break;
|
---|
902 | }
|
---|
903 | default:
|
---|
904 | FIXME("Don't know how to marshal type kind %d\n",tattr->typekind);
|
---|
905 | hres = E_FAIL;
|
---|
906 | break;
|
---|
907 | }
|
---|
908 | }
|
---|
909 | if (hres)
|
---|
910 | FIXME("failed to stuballoc in TKIND_RECORD.\n");
|
---|
911 | ITypeInfo_Release(tinfo2);
|
---|
912 | return hres;
|
---|
913 | }
|
---|
914 | case VT_CARRAY: {
|
---|
915 | /* arg is pointing to the start of the array. */
|
---|
916 | ARRAYDESC *adesc = tdesc->u.lpadesc;
|
---|
917 | int arrsize,i;
|
---|
918 | arrsize = 1;
|
---|
919 | if (adesc->cDims > 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
|
---|
920 | for (i=0;i<adesc->cDims;i++)
|
---|
921 | arrsize *= adesc->rgbounds[i].cElements;
|
---|
922 | for (i=0;i<arrsize;i++)
|
---|
923 | deserialize_param(
|
---|
924 | tinfo,
|
---|
925 | readit,
|
---|
926 | debugout,
|
---|
927 | alloc,
|
---|
928 | &adesc->tdescElem,
|
---|
929 | (DWORD*)((LPBYTE)(arg)+i*_xsize(&adesc->tdescElem)),
|
---|
930 | buf
|
---|
931 | );
|
---|
932 | return S_OK;
|
---|
933 | }
|
---|
934 | default:
|
---|
935 | ERR("No handler for VT type %d!\n",tdesc->vt);
|
---|
936 | return S_OK;
|
---|
937 | }
|
---|
938 | }
|
---|
939 | }
|
---|
940 |
|
---|
941 | static HRESULT
|
---|
942 | deserialize_LPVOID_ptr(
|
---|
943 | ITypeInfo *tinfo,
|
---|
944 | BOOL readit,
|
---|
945 | BOOL debugout,
|
---|
946 | BOOL alloc,
|
---|
947 | TYPEDESC *tdesc,
|
---|
948 | DWORD *arg,
|
---|
949 | marshal_state *buf
|
---|
950 | ) {
|
---|
951 | HRESULT hres;
|
---|
952 | DWORD cookie;
|
---|
953 |
|
---|
954 | if ((tdesc->vt != VT_PTR) ||
|
---|
955 | (tdesc->u.lptdesc->vt != VT_PTR) ||
|
---|
956 | (tdesc->u.lptdesc->u.lptdesc->vt != VT_VOID)
|
---|
957 | ) {
|
---|
958 | FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
|
---|
959 | return E_FAIL;
|
---|
960 | }
|
---|
961 | if (alloc)
|
---|
962 | *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(LPVOID));
|
---|
963 | if (readit) {
|
---|
964 | hres = xbuf_get(buf, (LPVOID)&cookie, sizeof(cookie));
|
---|
965 | if (hres)
|
---|
966 | return hres;
|
---|
967 | if (cookie != 0x42424242) {
|
---|
968 | *(DWORD*)*arg = 0;
|
---|
969 | if (debugout) MESSAGE("<lpvoid NULL>");
|
---|
970 | return S_OK;
|
---|
971 | }
|
---|
972 | }
|
---|
973 | if (readit) {
|
---|
974 | hres = _unmarshal_interface(buf,&buf->iid,(LPUNKNOWN*)*arg);
|
---|
975 | if (hres)
|
---|
976 | return hres;
|
---|
977 | }
|
---|
978 | if (debugout) MESSAGE("ppv(%p)",(LPVOID)*arg);
|
---|
979 | return S_OK;
|
---|
980 | }
|
---|
981 |
|
---|
982 | static HRESULT
|
---|
983 | deserialize_DISPPARAM_ptr(
|
---|
984 | ITypeInfo *tinfo,
|
---|
985 | BOOL readit,
|
---|
986 | BOOL debugout,
|
---|
987 | BOOL alloc,
|
---|
988 | TYPEDESC *tdesc,
|
---|
989 | DWORD *arg,
|
---|
990 | marshal_state *buf
|
---|
991 | ) {
|
---|
992 | DWORD cookie;
|
---|
993 | DISPPARAMS *disps;
|
---|
994 | HRESULT hres;
|
---|
995 | int i;
|
---|
996 |
|
---|
997 | if ((tdesc->vt != VT_PTR) || (tdesc->u.lptdesc->vt != VT_USERDEFINED)) {
|
---|
998 | FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
|
---|
999 | return E_FAIL;
|
---|
1000 | }
|
---|
1001 | if (readit) {
|
---|
1002 | hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
|
---|
1003 | if (hres)
|
---|
1004 | return hres;
|
---|
1005 | if (cookie == 0) {
|
---|
1006 | *arg = 0;
|
---|
1007 | if (debugout) MESSAGE("<DISPPARAMS NULL>");
|
---|
1008 | return S_OK;
|
---|
1009 | }
|
---|
1010 | }
|
---|
1011 | if (alloc)
|
---|
1012 | *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPPARAMS));
|
---|
1013 | disps = (DISPPARAMS*)*arg;
|
---|
1014 | if (!readit)
|
---|
1015 | return S_OK;
|
---|
1016 | hres = xbuf_get(buf, (LPBYTE)&disps->cArgs, sizeof(disps->cArgs));
|
---|
1017 | if (hres)
|
---|
1018 | return hres;
|
---|
1019 | if (alloc)
|
---|
1020 | disps->rgvarg = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(VARIANT)*disps->cArgs);
|
---|
1021 | if (debugout) MESSAGE("D{");
|
---|
1022 | for (i=0; i< disps->cArgs; i++) {
|
---|
1023 | TYPEDESC vdesc;
|
---|
1024 |
|
---|
1025 | vdesc.vt = VT_VARIANT;
|
---|
1026 | hres = deserialize_param(
|
---|
1027 | tinfo,
|
---|
1028 | readit,
|
---|
1029 | debugout,
|
---|
1030 | alloc,
|
---|
1031 | &vdesc,
|
---|
1032 | (DWORD*)(disps->rgvarg+i),
|
---|
1033 | buf
|
---|
1034 | );
|
---|
1035 | }
|
---|
1036 | if (debugout) MESSAGE("}{");
|
---|
1037 | hres = xbuf_get(buf, (LPBYTE)&disps->cNamedArgs, sizeof(disps->cNamedArgs));
|
---|
1038 | if (hres)
|
---|
1039 | return hres;
|
---|
1040 | if (disps->cNamedArgs) {
|
---|
1041 | if (alloc)
|
---|
1042 | disps->rgdispidNamedArgs = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPID)*disps->cNamedArgs);
|
---|
1043 | for (i=0; i< disps->cNamedArgs; i++) {
|
---|
1044 | TYPEDESC vdesc;
|
---|
1045 |
|
---|
1046 | vdesc.vt = VT_UINT;
|
---|
1047 | hres = deserialize_param(
|
---|
1048 | tinfo,
|
---|
1049 | readit,
|
---|
1050 | debugout,
|
---|
1051 | alloc,
|
---|
1052 | &vdesc,
|
---|
1053 | (DWORD*)(disps->rgdispidNamedArgs+i),
|
---|
1054 | buf
|
---|
1055 | );
|
---|
1056 | if (debugout && i<(disps->cNamedArgs-1)) MESSAGE(",");
|
---|
1057 | }
|
---|
1058 | }
|
---|
1059 | if (debugout) MESSAGE("}");
|
---|
1060 | return S_OK;
|
---|
1061 | }
|
---|
1062 |
|
---|
1063 | /* Searches function, also in inherited interfaces */
|
---|
1064 | static HRESULT
|
---|
1065 | _get_funcdesc(
|
---|
1066 | ITypeInfo *tinfo, int iMethod, FUNCDESC **fdesc, BSTR *iname, BSTR *fname
|
---|
1067 | ) {
|
---|
1068 | int i = 0, j = 0;
|
---|
1069 | HRESULT hres;
|
---|
1070 |
|
---|
1071 | if (fname) *fname = NULL;
|
---|
1072 | if (iname) *iname = NULL;
|
---|
1073 |
|
---|
1074 | while (1) {
|
---|
1075 | hres = ITypeInfo_GetFuncDesc(tinfo, i, fdesc);
|
---|
1076 | if (hres) {
|
---|
1077 | ITypeInfo *tinfo2;
|
---|
1078 | HREFTYPE href;
|
---|
1079 | TYPEATTR *attr;
|
---|
1080 |
|
---|
1081 | hres = ITypeInfo_GetTypeAttr(tinfo, &attr);
|
---|
1082 | if (hres) {
|
---|
1083 | FIXME("GetTypeAttr failed with %lx\n",hres);
|
---|
1084 | return hres;
|
---|
1085 | }
|
---|
1086 | /* Not found, so look in inherited ifaces. */
|
---|
1087 | for (j=0;j<attr->cImplTypes;j++) {
|
---|
1088 | hres = ITypeInfo_GetRefTypeOfImplType(tinfo, j, &href);
|
---|
1089 | if (hres) {
|
---|
1090 | FIXME("Did not find a reftype for interface offset %d?\n",j);
|
---|
1091 | break;
|
---|
1092 | }
|
---|
1093 | hres = ITypeInfo_GetRefTypeInfo(tinfo, href, &tinfo2);
|
---|
1094 | if (hres) {
|
---|
1095 | FIXME("Did not find a typeinfo for reftype %ld?\n",href);
|
---|
1096 | continue;
|
---|
1097 | }
|
---|
1098 | hres = _get_funcdesc(tinfo2,iMethod,fdesc,iname,fname);
|
---|
1099 | ITypeInfo_Release(tinfo2);
|
---|
1100 | if (!hres) return S_OK;
|
---|
1101 | }
|
---|
1102 | return E_FAIL;
|
---|
1103 | }
|
---|
1104 | if (((*fdesc)->oVft/4) == iMethod) {
|
---|
1105 | if (fname)
|
---|
1106 | ITypeInfo_GetDocumentation(tinfo,(*fdesc)->memid,fname,NULL,NULL,NULL);
|
---|
1107 | if (iname)
|
---|
1108 | ITypeInfo_GetDocumentation(tinfo,-1,iname,NULL,NULL,NULL);
|
---|
1109 | return S_OK;
|
---|
1110 | }
|
---|
1111 | i++;
|
---|
1112 | }
|
---|
1113 | return E_FAIL;
|
---|
1114 | }
|
---|
1115 |
|
---|
1116 | #ifdef __WIN32OS2__
|
---|
1117 | static DWORD CDECL
|
---|
1118 | #else
|
---|
1119 | static DWORD
|
---|
1120 | #endif
|
---|
1121 | xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */) {
|
---|
1122 | DWORD *args = ((DWORD*)&tpinfo)+1, *xargs;
|
---|
1123 | FUNCDESC *fdesc;
|
---|
1124 | HRESULT hres;
|
---|
1125 | int i, relaydeb = TRACE_ON(olerelay);
|
---|
1126 | marshal_state buf;
|
---|
1127 | RPCOLEMESSAGE msg;
|
---|
1128 | ULONG status;
|
---|
1129 | BSTR fname,iname;
|
---|
1130 | BSTR names[10];
|
---|
1131 | int nrofnames;
|
---|
1132 |
|
---|
1133 | hres = _get_funcdesc(tpinfo->tinfo,method,&fdesc,&iname,&fname);
|
---|
1134 | if (hres) {
|
---|
1135 | ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method);
|
---|
1136 | return 0;
|
---|
1137 | }
|
---|
1138 |
|
---|
1139 | /*dump_FUNCDESC(fdesc);*/
|
---|
1140 | if (relaydeb) {
|
---|
1141 | TRACE_(olerelay)("->");
|
---|
1142 | if (iname)
|
---|
1143 | MESSAGE("%s:",debugstr_w(iname));
|
---|
1144 | if (fname)
|
---|
1145 | MESSAGE("%s(%d)",debugstr_w(fname),method);
|
---|
1146 | else
|
---|
1147 | MESSAGE("%d",method);
|
---|
1148 | MESSAGE("(");
|
---|
1149 | if (iname) SysFreeString(iname);
|
---|
1150 | if (fname) SysFreeString(fname);
|
---|
1151 | }
|
---|
1152 | /* Need them for hack below */
|
---|
1153 | memset(names,0,sizeof(names));
|
---|
1154 | if (ITypeInfo_GetNames(tpinfo->tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames))
|
---|
1155 | nrofnames = 0;
|
---|
1156 | if (nrofnames > sizeof(names)/sizeof(names[0]))
|
---|
1157 | ERR("Need more names!\n");
|
---|
1158 |
|
---|
1159 | memset(&buf,0,sizeof(buf));
|
---|
1160 | buf.iid = IID_IUnknown;
|
---|
1161 | if (method == 0) {
|
---|
1162 | xbuf_add(&buf,(LPBYTE)args[0],sizeof(IID));
|
---|
1163 | if (relaydeb) MESSAGE("riid=%s,[out]",debugstr_guid((REFIID)args[0]));
|
---|
1164 | } else {
|
---|
1165 | xargs = args;
|
---|
1166 | for (i=0;i<fdesc->cParams;i++) {
|
---|
1167 | ELEMDESC *elem = fdesc->lprgelemdescParam+i;
|
---|
1168 | BOOL isserialized = FALSE;
|
---|
1169 | if (relaydeb) {
|
---|
1170 | if (i) MESSAGE(",");
|
---|
1171 | if (i+1<nrofnames && names[i+1])
|
---|
1172 | MESSAGE("%s=",debugstr_w(names[i+1]));
|
---|
1173 | }
|
---|
1174 | /* No need to marshal other data than FIN */
|
---|
1175 | if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN)) {
|
---|
1176 | xargs+=_argsize(elem->tdesc.vt);
|
---|
1177 | if (relaydeb) MESSAGE("[out]");
|
---|
1178 | continue;
|
---|
1179 | }
|
---|
1180 | if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
|
---|
1181 | /* If the parameter is 'riid', we use it as interface IID
|
---|
1182 | * for a later ppvObject serialization.
|
---|
1183 | */
|
---|
1184 | buf.thisisiid = !lstrcmpW(names[i+1],riidW);
|
---|
1185 |
|
---|
1186 | /* DISPPARAMS* needs special serializer */
|
---|
1187 | if (!lstrcmpW(names[i+1],pdispparamsW)) {
|
---|
1188 | hres = serialize_DISPPARAM_ptr(
|
---|
1189 | tpinfo->tinfo,
|
---|
1190 | elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
|
---|
1191 | relaydeb,
|
---|
1192 | FALSE,
|
---|
1193 | &elem->tdesc,
|
---|
1194 | xargs,
|
---|
1195 | &buf
|
---|
1196 | );
|
---|
1197 | isserialized = TRUE;
|
---|
1198 | }
|
---|
1199 | if (!lstrcmpW(names[i+1],ppvObjectW)) {
|
---|
1200 | hres = serialize_LPVOID_ptr(
|
---|
1201 | tpinfo->tinfo,
|
---|
1202 | elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
|
---|
1203 | relaydeb,
|
---|
1204 | FALSE,
|
---|
1205 | &elem->tdesc,
|
---|
1206 | xargs,
|
---|
1207 | &buf
|
---|
1208 | );
|
---|
1209 | if (hres == S_OK)
|
---|
1210 | isserialized = TRUE;
|
---|
1211 | }
|
---|
1212 | }
|
---|
1213 | if (!isserialized)
|
---|
1214 | hres = serialize_param(
|
---|
1215 | tpinfo->tinfo,
|
---|
1216 | elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
|
---|
1217 | relaydeb,
|
---|
1218 | FALSE,
|
---|
1219 | &elem->tdesc,
|
---|
1220 | xargs,
|
---|
1221 | &buf
|
---|
1222 | );
|
---|
1223 |
|
---|
1224 | if (hres) {
|
---|
1225 | FIXME("Failed to serialize param, hres %lx\n",hres);
|
---|
1226 | break;
|
---|
1227 | }
|
---|
1228 | xargs+=_argsize(elem->tdesc.vt);
|
---|
1229 | }
|
---|
1230 | }
|
---|
1231 | if (relaydeb) MESSAGE(")");
|
---|
1232 | memset(&msg,0,sizeof(msg));
|
---|
1233 | msg.cbBuffer = buf.curoff;
|
---|
1234 | msg.iMethod = method;
|
---|
1235 | hres = IRpcChannelBuffer_GetBuffer(tpinfo->chanbuf,&msg,&(tpinfo->iid));
|
---|
1236 | if (hres) {
|
---|
1237 | FIXME("RpcChannelBuffer GetBuffer failed, %lx\n",hres);
|
---|
1238 | return hres;
|
---|
1239 | }
|
---|
1240 | memcpy(msg.Buffer,buf.base,buf.curoff);
|
---|
1241 | if (relaydeb) MESSAGE("\n");
|
---|
1242 | hres = IRpcChannelBuffer_SendReceive(tpinfo->chanbuf,&msg,&status);
|
---|
1243 | if (hres) {
|
---|
1244 | FIXME("RpcChannelBuffer SendReceive failed, %lx\n",hres);
|
---|
1245 | return hres;
|
---|
1246 | }
|
---|
1247 | relaydeb = TRACE_ON(olerelay);
|
---|
1248 | if (relaydeb) MESSAGE(" = %08lx (",status);
|
---|
1249 | if (buf.base)
|
---|
1250 | buf.base = HeapReAlloc(GetProcessHeap(),0,buf.base,msg.cbBuffer);
|
---|
1251 | else
|
---|
1252 | buf.base = HeapAlloc(GetProcessHeap(),0,msg.cbBuffer);
|
---|
1253 | buf.size = msg.cbBuffer;
|
---|
1254 | memcpy(buf.base,msg.Buffer,buf.size);
|
---|
1255 | buf.curoff = 0;
|
---|
1256 | if (method == 0) {
|
---|
1257 | _unmarshal_interface(&buf,(REFIID)args[0],(LPUNKNOWN*)args[1]);
|
---|
1258 | if (relaydeb) MESSAGE("[in],%p",*((DWORD**)args[1]));
|
---|
1259 | } else {
|
---|
1260 | xargs = args;
|
---|
1261 | for (i=0;i<fdesc->cParams;i++) {
|
---|
1262 | ELEMDESC *elem = fdesc->lprgelemdescParam+i;
|
---|
1263 | BOOL isdeserialized = FALSE;
|
---|
1264 |
|
---|
1265 | if (relaydeb) {
|
---|
1266 | if (i) MESSAGE(",");
|
---|
1267 | if (i+1<nrofnames && names[i+1]) MESSAGE("%s=",debugstr_w(names[i+1]));
|
---|
1268 | }
|
---|
1269 | /* No need to marshal other data than FOUT I think */
|
---|
1270 | if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT)) {
|
---|
1271 | xargs += _argsize(elem->tdesc.vt);
|
---|
1272 | if (relaydeb) MESSAGE("[in]");
|
---|
1273 | continue;
|
---|
1274 | }
|
---|
1275 | if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
|
---|
1276 | /* If the parameter is 'riid', we use it as interface IID
|
---|
1277 | * for a later ppvObject serialization.
|
---|
1278 | */
|
---|
1279 | buf.thisisiid = !lstrcmpW(names[i+1],riidW);
|
---|
1280 |
|
---|
1281 | /* deserialize DISPPARAM */
|
---|
1282 | if (!lstrcmpW(names[i+1],pdispparamsW)) {
|
---|
1283 | hres = deserialize_DISPPARAM_ptr(
|
---|
1284 | tpinfo->tinfo,
|
---|
1285 | elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
|
---|
1286 | relaydeb,
|
---|
1287 | FALSE,
|
---|
1288 | &(elem->tdesc),
|
---|
1289 | xargs,
|
---|
1290 | &buf
|
---|
1291 | );
|
---|
1292 | if (hres) {
|
---|
1293 | FIXME("Failed to deserialize DISPPARAM*, hres %lx\n",hres);
|
---|
1294 | break;
|
---|
1295 | }
|
---|
1296 | isdeserialized = TRUE;
|
---|
1297 | }
|
---|
1298 | if (!lstrcmpW(names[i+1],ppvObjectW)) {
|
---|
1299 | hres = deserialize_LPVOID_ptr(
|
---|
1300 | tpinfo->tinfo,
|
---|
1301 | elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
|
---|
1302 | relaydeb,
|
---|
1303 | FALSE,
|
---|
1304 | &elem->tdesc,
|
---|
1305 | xargs,
|
---|
1306 | &buf
|
---|
1307 | );
|
---|
1308 | if (hres == S_OK)
|
---|
1309 | isdeserialized = TRUE;
|
---|
1310 | }
|
---|
1311 | }
|
---|
1312 | if (!isdeserialized)
|
---|
1313 | hres = deserialize_param(
|
---|
1314 | tpinfo->tinfo,
|
---|
1315 | elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
|
---|
1316 | relaydeb,
|
---|
1317 | FALSE,
|
---|
1318 | &(elem->tdesc),
|
---|
1319 | xargs,
|
---|
1320 | &buf
|
---|
1321 | );
|
---|
1322 | if (hres) {
|
---|
1323 | FIXME("Failed to unmarshall param, hres %lx\n",hres);
|
---|
1324 | break;
|
---|
1325 | }
|
---|
1326 | xargs += _argsize(elem->tdesc.vt);
|
---|
1327 | }
|
---|
1328 | }
|
---|
1329 | if (relaydeb) MESSAGE(")\n\n");
|
---|
1330 | HeapFree(GetProcessHeap(),0,buf.base);
|
---|
1331 | return status;
|
---|
1332 | }
|
---|
1333 |
|
---|
1334 | static HRESULT WINAPI
|
---|
1335 | PSFacBuf_CreateProxy(
|
---|
1336 | LPPSFACTORYBUFFER iface, IUnknown* pUnkOuter, REFIID riid,
|
---|
1337 | IRpcProxyBuffer **ppProxy, LPVOID *ppv
|
---|
1338 | ) {
|
---|
1339 | HRESULT hres;
|
---|
1340 | ITypeInfo *tinfo;
|
---|
1341 | int i, nroffuncs;
|
---|
1342 | FUNCDESC *fdesc;
|
---|
1343 | TMProxyImpl *proxy;
|
---|
1344 |
|
---|
1345 | TRACE("(...%s...)\n",debugstr_guid(riid));
|
---|
1346 | hres = _get_typeinfo_for_iid(riid,&tinfo);
|
---|
1347 | if (hres) {
|
---|
1348 | FIXME("No typeinfo for %s?\n",debugstr_guid(riid));
|
---|
1349 | return hres;
|
---|
1350 | }
|
---|
1351 | nroffuncs = _nroffuncs(tinfo);
|
---|
1352 | proxy = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TMProxyImpl));
|
---|
1353 | if (!proxy) return E_OUTOFMEMORY;
|
---|
1354 | proxy->asmstubs=HeapAlloc(GetProcessHeap(),0,sizeof(TMAsmProxy)*nroffuncs);
|
---|
1355 |
|
---|
1356 | assert(sizeof(TMAsmProxy) == 12);
|
---|
1357 |
|
---|
1358 | proxy->lpvtbl = HeapAlloc(GetProcessHeap(),0,sizeof(LPBYTE)*nroffuncs);
|
---|
1359 | for (i=0;i<nroffuncs;i++) {
|
---|
1360 | int nrofargs;
|
---|
1361 | TMAsmProxy *xasm = proxy->asmstubs+i;
|
---|
1362 |
|
---|
1363 | /* nrofargs without This */
|
---|
1364 | switch (i) {
|
---|
1365 | case 0: nrofargs = 2;
|
---|
1366 | break;
|
---|
1367 | case 1: case 2: nrofargs = 0;
|
---|
1368 | break;
|
---|
1369 | default: {
|
---|
1370 | int j;
|
---|
1371 | hres = _get_funcdesc(tinfo,i,&fdesc,NULL,NULL);
|
---|
1372 | if (hres) {
|
---|
1373 | FIXME("GetFuncDesc %lx should not fail here.\n",hres);
|
---|
1374 | return hres;
|
---|
1375 | }
|
---|
1376 | /* some args take more than 4 byte on the stack */
|
---|
1377 | nrofargs = 0;
|
---|
1378 | for (j=0;j<fdesc->cParams;j++)
|
---|
1379 | nrofargs += _argsize(fdesc->lprgelemdescParam[j].tdesc.vt);
|
---|
1380 |
|
---|
1381 | if (fdesc->callconv != CC_STDCALL) {
|
---|
1382 | ERR("calling convention is not stdcall????\n");
|
---|
1383 | return E_FAIL;
|
---|
1384 | }
|
---|
1385 | break;
|
---|
1386 | }
|
---|
1387 | }
|
---|
1388 | /* popl %eax - return ptr
|
---|
1389 | * pushl <nr>
|
---|
1390 | * pushl %eax
|
---|
1391 | * call xCall
|
---|
1392 | * lret <nr> (+4)
|
---|
1393 | *
|
---|
1394 | *
|
---|
1395 | * arg3 arg2 arg1 <method> <returnptr>
|
---|
1396 | */
|
---|
1397 | xasm->popleax = 0x58;
|
---|
1398 | xasm->pushlval = 0x6a;
|
---|
1399 | xasm->nr = i;
|
---|
1400 | xasm->pushleax = 0x50;
|
---|
1401 | xasm->lcall = 0xe8; /* relative jump */
|
---|
1402 | xasm->xcall = (DWORD)xCall;
|
---|
1403 | xasm->xcall -= (DWORD)&(xasm->lret);
|
---|
1404 | xasm->lret = 0xc2;
|
---|
1405 | xasm->bytestopop= (nrofargs+2)*4; /* pop args, This, iMethod */
|
---|
1406 | proxy->lpvtbl[i] = (DWORD)xasm;
|
---|
1407 | }
|
---|
1408 | proxy->lpvtbl2 = &tmproxyvtable;
|
---|
1409 | proxy->ref = 2;
|
---|
1410 | proxy->tinfo = tinfo;
|
---|
1411 | memcpy(&proxy->iid,riid,sizeof(*riid));
|
---|
1412 | *ppv = (LPVOID)proxy;
|
---|
1413 | *ppProxy = (IRpcProxyBuffer *)&(proxy->lpvtbl2);
|
---|
1414 | return S_OK;
|
---|
1415 | }
|
---|
1416 |
|
---|
1417 | typedef struct _TMStubImpl {
|
---|
1418 | ICOM_VTABLE(IRpcStubBuffer) *lpvtbl;
|
---|
1419 | DWORD ref;
|
---|
1420 |
|
---|
1421 | LPUNKNOWN pUnk;
|
---|
1422 | ITypeInfo *tinfo;
|
---|
1423 | IID iid;
|
---|
1424 | } TMStubImpl;
|
---|
1425 |
|
---|
1426 | static HRESULT WINAPI
|
---|
1427 | TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface, REFIID riid, LPVOID *ppv) {
|
---|
1428 | if (IsEqualIID(riid,&IID_IRpcStubBuffer)||IsEqualIID(riid,&IID_IUnknown)){
|
---|
1429 | *ppv = (LPVOID)iface;
|
---|
1430 | IRpcStubBuffer_AddRef(iface);
|
---|
1431 | return S_OK;
|
---|
1432 | }
|
---|
1433 | FIXME("%s, not supported IID.\n",debugstr_guid(riid));
|
---|
1434 | return E_NOINTERFACE;
|
---|
1435 | }
|
---|
1436 |
|
---|
1437 | static ULONG WINAPI
|
---|
1438 | TMStubImpl_AddRef(LPRPCSTUBBUFFER iface) {
|
---|
1439 | ICOM_THIS(TMStubImpl,iface);
|
---|
1440 |
|
---|
1441 | This->ref++;
|
---|
1442 | return This->ref;
|
---|
1443 | }
|
---|
1444 |
|
---|
1445 | static ULONG WINAPI
|
---|
1446 | TMStubImpl_Release(LPRPCSTUBBUFFER iface) {
|
---|
1447 | ICOM_THIS(TMStubImpl,iface);
|
---|
1448 |
|
---|
1449 | This->ref--;
|
---|
1450 | if (This->ref)
|
---|
1451 | return This->ref;
|
---|
1452 | HeapFree(GetProcessHeap(),0,This);
|
---|
1453 | return 0;
|
---|
1454 | }
|
---|
1455 |
|
---|
1456 | static HRESULT WINAPI
|
---|
1457 | TMStubImpl_Connect(LPRPCSTUBBUFFER iface, LPUNKNOWN pUnkServer) {
|
---|
1458 | ICOM_THIS(TMStubImpl,iface);
|
---|
1459 |
|
---|
1460 | IUnknown_AddRef(pUnkServer);
|
---|
1461 | This->pUnk = pUnkServer;
|
---|
1462 | return S_OK;
|
---|
1463 | }
|
---|
1464 |
|
---|
1465 | static void WINAPI
|
---|
1466 | TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface) {
|
---|
1467 | ICOM_THIS(TMStubImpl,iface);
|
---|
1468 |
|
---|
1469 | IUnknown_Release(This->pUnk);
|
---|
1470 | This->pUnk = NULL;
|
---|
1471 | return;
|
---|
1472 | }
|
---|
1473 |
|
---|
1474 | static HRESULT WINAPI
|
---|
1475 | TMStubImpl_Invoke(
|
---|
1476 | LPRPCSTUBBUFFER iface, RPCOLEMESSAGE* xmsg,IRpcChannelBuffer*rpcchanbuf
|
---|
1477 | ) {
|
---|
1478 | int i;
|
---|
1479 | FUNCDESC *fdesc;
|
---|
1480 | ICOM_THIS(TMStubImpl,iface);
|
---|
1481 | HRESULT hres;
|
---|
1482 | DWORD *args, res, *xargs, nrofargs;
|
---|
1483 | marshal_state buf;
|
---|
1484 | int nrofnames;
|
---|
1485 | BSTR names[10];
|
---|
1486 |
|
---|
1487 | memset(&buf,0,sizeof(buf));
|
---|
1488 | buf.size = xmsg->cbBuffer;
|
---|
1489 | buf.base = xmsg->Buffer;
|
---|
1490 | buf.curoff = 0;
|
---|
1491 | buf.iid = IID_IUnknown;
|
---|
1492 |
|
---|
1493 | TRACE("...\n");
|
---|
1494 | if (xmsg->iMethod == 0) { /* QI */
|
---|
1495 | IID xiid;
|
---|
1496 | /* in: IID, out: <iface> */
|
---|
1497 |
|
---|
1498 | xbuf_get(&buf,(LPBYTE)&xiid,sizeof(xiid));
|
---|
1499 | buf.curoff = 0;
|
---|
1500 | hres = _marshal_interface(&buf,&xiid,This->pUnk);
|
---|
1501 | xmsg->Buffer = buf.base; /* Might have been reallocated */
|
---|
1502 | xmsg->cbBuffer = buf.size;
|
---|
1503 | return hres;
|
---|
1504 | }
|
---|
1505 | hres = _get_funcdesc(This->tinfo,xmsg->iMethod,&fdesc,NULL,NULL);
|
---|
1506 | if (hres) {
|
---|
1507 | FIXME("GetFuncDesc on method %ld failed with %lx\n",xmsg->iMethod,hres);
|
---|
1508 | return hres;
|
---|
1509 | }
|
---|
1510 | /* Need them for hack below */
|
---|
1511 | memset(names,0,sizeof(names));
|
---|
1512 | ITypeInfo_GetNames(This->tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
|
---|
1513 | if (nrofnames > sizeof(names)/sizeof(names[0])) {
|
---|
1514 | ERR("Need more names!\n");
|
---|
1515 | }
|
---|
1516 |
|
---|
1517 | /*dump_FUNCDESC(fdesc);*/
|
---|
1518 | nrofargs = 0;
|
---|
1519 | for (i=0;i<fdesc->cParams;i++)
|
---|
1520 | nrofargs += _argsize(fdesc->lprgelemdescParam[i].tdesc.vt);
|
---|
1521 | args = HeapAlloc(GetProcessHeap(),0,(nrofargs+1)*sizeof(DWORD));
|
---|
1522 | if (!args) return E_OUTOFMEMORY;
|
---|
1523 |
|
---|
1524 | /* Allocate all stuff used by call. */
|
---|
1525 | xargs = args+1;
|
---|
1526 | for (i=0;i<fdesc->cParams;i++) {
|
---|
1527 | ELEMDESC *elem = fdesc->lprgelemdescParam+i;
|
---|
1528 | BOOL isdeserialized = FALSE;
|
---|
1529 |
|
---|
1530 | if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
|
---|
1531 | /* If the parameter is 'riid', we use it as interface IID
|
---|
1532 | * for a later ppvObject serialization.
|
---|
1533 | */
|
---|
1534 | buf.thisisiid = !lstrcmpW(names[i+1],riidW);
|
---|
1535 |
|
---|
1536 | /* deserialize DISPPARAM */
|
---|
1537 | if (!lstrcmpW(names[i+1],pdispparamsW)) {
|
---|
1538 | hres = deserialize_DISPPARAM_ptr(
|
---|
1539 | This->tinfo,
|
---|
1540 | elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
|
---|
1541 | FALSE,
|
---|
1542 | TRUE,
|
---|
1543 | &(elem->tdesc),
|
---|
1544 | xargs,
|
---|
1545 | &buf
|
---|
1546 | );
|
---|
1547 | if (hres) {
|
---|
1548 | FIXME("Failed to deserialize DISPPARAM*, hres %lx\n",hres);
|
---|
1549 | break;
|
---|
1550 | }
|
---|
1551 | isdeserialized = TRUE;
|
---|
1552 | }
|
---|
1553 | if (!lstrcmpW(names[i+1],ppvObjectW)) {
|
---|
1554 | hres = deserialize_LPVOID_ptr(
|
---|
1555 | This->tinfo,
|
---|
1556 | elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
|
---|
1557 | FALSE,
|
---|
1558 | TRUE,
|
---|
1559 | &elem->tdesc,
|
---|
1560 | xargs,
|
---|
1561 | &buf
|
---|
1562 | );
|
---|
1563 | if (hres == S_OK)
|
---|
1564 | isdeserialized = TRUE;
|
---|
1565 | }
|
---|
1566 | }
|
---|
1567 | if (!isdeserialized)
|
---|
1568 | hres = deserialize_param(
|
---|
1569 | This->tinfo,
|
---|
1570 | elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
|
---|
1571 | FALSE,
|
---|
1572 | TRUE,
|
---|
1573 | &(elem->tdesc),
|
---|
1574 | xargs,
|
---|
1575 | &buf
|
---|
1576 | );
|
---|
1577 | xargs += _argsize(elem->tdesc.vt);
|
---|
1578 | if (hres) {
|
---|
1579 | FIXME("Failed to deserialize param %s, hres %lx\n",debugstr_w(names[i+1]),hres);
|
---|
1580 | break;
|
---|
1581 | }
|
---|
1582 | }
|
---|
1583 | hres = IUnknown_QueryInterface(This->pUnk,&(This->iid),(LPVOID*)&(args[0]));
|
---|
1584 | if (hres) {
|
---|
1585 | ERR("Does not support iface %s\n",debugstr_guid(&(This->iid)));
|
---|
1586 | return hres;
|
---|
1587 | }
|
---|
1588 | res = _invoke(
|
---|
1589 | (*((LPVOID**)args[0]))[fdesc->oVft/4],
|
---|
1590 | fdesc->callconv,
|
---|
1591 | (xargs-args),
|
---|
1592 | args
|
---|
1593 | );
|
---|
1594 | IUnknown_Release((LPUNKNOWN)args[0]);
|
---|
1595 | buf.curoff = 0;
|
---|
1596 | xargs = args+1;
|
---|
1597 | for (i=0;i<fdesc->cParams;i++) {
|
---|
1598 | ELEMDESC *elem = fdesc->lprgelemdescParam+i;
|
---|
1599 | BOOL isserialized = FALSE;
|
---|
1600 |
|
---|
1601 | if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
|
---|
1602 | /* If the parameter is 'riid', we use it as interface IID
|
---|
1603 | * for a later ppvObject serialization.
|
---|
1604 | */
|
---|
1605 | buf.thisisiid = !lstrcmpW(names[i+1],riidW);
|
---|
1606 |
|
---|
1607 | /* DISPPARAMS* needs special serializer */
|
---|
1608 | if (!lstrcmpW(names[i+1],pdispparamsW)) {
|
---|
1609 | hres = serialize_DISPPARAM_ptr(
|
---|
1610 | This->tinfo,
|
---|
1611 | elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
|
---|
1612 | FALSE,
|
---|
1613 | TRUE,
|
---|
1614 | &elem->tdesc,
|
---|
1615 | xargs,
|
---|
1616 | &buf
|
---|
1617 | );
|
---|
1618 | isserialized = TRUE;
|
---|
1619 | }
|
---|
1620 | if (!lstrcmpW(names[i+1],ppvObjectW)) {
|
---|
1621 | hres = serialize_LPVOID_ptr(
|
---|
1622 | This->tinfo,
|
---|
1623 | elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
|
---|
1624 | FALSE,
|
---|
1625 | TRUE,
|
---|
1626 | &elem->tdesc,
|
---|
1627 | xargs,
|
---|
1628 | &buf
|
---|
1629 | );
|
---|
1630 | if (hres == S_OK)
|
---|
1631 | isserialized = TRUE;
|
---|
1632 | }
|
---|
1633 | }
|
---|
1634 | if (!isserialized)
|
---|
1635 | hres = serialize_param(
|
---|
1636 | This->tinfo,
|
---|
1637 | elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
|
---|
1638 | FALSE,
|
---|
1639 | TRUE,
|
---|
1640 | &elem->tdesc,
|
---|
1641 | xargs,
|
---|
1642 | &buf
|
---|
1643 | );
|
---|
1644 | xargs += _argsize(elem->tdesc.vt);
|
---|
1645 | if (hres) {
|
---|
1646 | FIXME("Failed to stuballoc param, hres %lx\n",hres);
|
---|
1647 | break;
|
---|
1648 | }
|
---|
1649 | }
|
---|
1650 | /* might need to use IRpcChannelBuffer_GetBuffer ? */
|
---|
1651 | xmsg->cbBuffer = buf.curoff;
|
---|
1652 | xmsg->Buffer = buf.base;
|
---|
1653 | HeapFree(GetProcessHeap(),0,args);
|
---|
1654 | return res;
|
---|
1655 | }
|
---|
1656 |
|
---|
1657 | static LPRPCSTUBBUFFER WINAPI
|
---|
1658 | TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface, REFIID riid) {
|
---|
1659 | FIXME("Huh (%s)?\n",debugstr_guid(riid));
|
---|
1660 | return NULL;
|
---|
1661 | }
|
---|
1662 |
|
---|
1663 | static ULONG WINAPI
|
---|
1664 | TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface) {
|
---|
1665 | ICOM_THIS(TMStubImpl,iface);
|
---|
1666 |
|
---|
1667 | return This->ref; /*FIXME? */
|
---|
1668 | }
|
---|
1669 |
|
---|
1670 | static HRESULT WINAPI
|
---|
1671 | TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface, LPVOID *ppv) {
|
---|
1672 | return E_NOTIMPL;
|
---|
1673 | }
|
---|
1674 |
|
---|
1675 | static void WINAPI
|
---|
1676 | TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface, LPVOID ppv) {
|
---|
1677 | return;
|
---|
1678 | }
|
---|
1679 |
|
---|
1680 | ICOM_VTABLE(IRpcStubBuffer) tmstubvtbl = {
|
---|
1681 | ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
---|
1682 | TMStubImpl_QueryInterface,
|
---|
1683 | TMStubImpl_AddRef,
|
---|
1684 | TMStubImpl_Release,
|
---|
1685 | TMStubImpl_Connect,
|
---|
1686 | TMStubImpl_Disconnect,
|
---|
1687 | TMStubImpl_Invoke,
|
---|
1688 | TMStubImpl_IsIIDSupported,
|
---|
1689 | TMStubImpl_CountRefs,
|
---|
1690 | TMStubImpl_DebugServerQueryInterface,
|
---|
1691 | TMStubImpl_DebugServerRelease
|
---|
1692 | };
|
---|
1693 |
|
---|
1694 | static HRESULT WINAPI
|
---|
1695 | PSFacBuf_CreateStub(
|
---|
1696 | LPPSFACTORYBUFFER iface, REFIID riid,IUnknown *pUnkServer,
|
---|
1697 | IRpcStubBuffer** ppStub
|
---|
1698 | ) {
|
---|
1699 | HRESULT hres;
|
---|
1700 | ITypeInfo *tinfo;
|
---|
1701 | TMStubImpl *stub;
|
---|
1702 |
|
---|
1703 | TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub);
|
---|
1704 | hres = _get_typeinfo_for_iid(riid,&tinfo);
|
---|
1705 | if (hres) {
|
---|
1706 | FIXME("No typeinfo for %s?\n",debugstr_guid(riid));
|
---|
1707 | return hres;
|
---|
1708 | }
|
---|
1709 | stub = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TMStubImpl));
|
---|
1710 | if (!stub)
|
---|
1711 | return E_OUTOFMEMORY;
|
---|
1712 | stub->lpvtbl = &tmstubvtbl;
|
---|
1713 | stub->ref = 1;
|
---|
1714 | stub->tinfo = tinfo;
|
---|
1715 | memcpy(&(stub->iid),riid,sizeof(*riid));
|
---|
1716 | hres = IRpcStubBuffer_Connect((LPRPCSTUBBUFFER)stub,pUnkServer);
|
---|
1717 | *ppStub = (LPRPCSTUBBUFFER)stub;
|
---|
1718 | if (hres)
|
---|
1719 | FIXME("Connect to pUnkServer failed?\n");
|
---|
1720 | return hres;
|
---|
1721 | }
|
---|
1722 |
|
---|
1723 | static ICOM_VTABLE(IPSFactoryBuffer) psfacbufvtbl = {
|
---|
1724 | ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
---|
1725 | PSFacBuf_QueryInterface,
|
---|
1726 | PSFacBuf_AddRef,
|
---|
1727 | PSFacBuf_Release,
|
---|
1728 | PSFacBuf_CreateProxy,
|
---|
1729 | PSFacBuf_CreateStub
|
---|
1730 | };
|
---|
1731 |
|
---|
1732 | /* This is the whole PSFactoryBuffer object, just the vtableptr */
|
---|
1733 | static ICOM_VTABLE(IPSFactoryBuffer) *lppsfac = &psfacbufvtbl;
|
---|
1734 |
|
---|
1735 | /***********************************************************************
|
---|
1736 | * DllGetClassObject [OLE32.63]
|
---|
1737 | */
|
---|
1738 | HRESULT WINAPI
|
---|
1739 | TypeLibFac_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
|
---|
1740 | {
|
---|
1741 | if (IsEqualIID(iid,&IID_IPSFactoryBuffer)) {
|
---|
1742 | *ppv = &lppsfac;
|
---|
1743 | return S_OK;
|
---|
1744 | }
|
---|
1745 | return E_NOINTERFACE;
|
---|
1746 | }
|
---|