| 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 "winternl.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 | int const
|
|---|
| 370 | _argsize(DWORD vt) {
|
|---|
| 371 | switch (vt) {
|
|---|
| 372 | case VT_DATE:
|
|---|
| 373 | return sizeof(DATE)/sizeof(DWORD);
|
|---|
| 374 | case VT_VARIANT:
|
|---|
| 375 | return (sizeof(VARIANT)+3)/sizeof(DWORD);
|
|---|
| 376 | default:
|
|---|
| 377 | return 1;
|
|---|
| 378 | }
|
|---|
| 379 | }
|
|---|
| 380 |
|
|---|
| 381 | static int
|
|---|
| 382 | _xsize(TYPEDESC *td) {
|
|---|
| 383 | switch (td->vt) {
|
|---|
| 384 | case VT_DATE:
|
|---|
| 385 | return sizeof(DATE);
|
|---|
| 386 | case VT_VARIANT:
|
|---|
| 387 | return sizeof(VARIANT)+3;
|
|---|
| 388 | case VT_CARRAY: {
|
|---|
| 389 | int i, arrsize = 1;
|
|---|
| 390 | ARRAYDESC *adesc = td->u.lpadesc;
|
|---|
| 391 |
|
|---|
| 392 | for (i=0;i<adesc->cDims;i++)
|
|---|
| 393 | arrsize *= adesc->rgbounds[i].cElements;
|
|---|
| 394 | return arrsize*_xsize(&adesc->tdescElem);
|
|---|
| 395 | }
|
|---|
| 396 | case VT_UI2:
|
|---|
| 397 | case VT_I2:
|
|---|
| 398 | return 2;
|
|---|
| 399 | case VT_UI1:
|
|---|
| 400 | case VT_I1:
|
|---|
| 401 | return 1;
|
|---|
| 402 | default:
|
|---|
| 403 | return 4;
|
|---|
| 404 | }
|
|---|
| 405 | }
|
|---|
| 406 |
|
|---|
| 407 | static HRESULT
|
|---|
| 408 | serialize_param(
|
|---|
| 409 | ITypeInfo *tinfo,
|
|---|
| 410 | BOOL writeit,
|
|---|
| 411 | BOOL debugout,
|
|---|
| 412 | BOOL dealloc,
|
|---|
| 413 | TYPEDESC *tdesc,
|
|---|
| 414 | DWORD *arg,
|
|---|
| 415 | marshal_state *buf
|
|---|
| 416 | ) {
|
|---|
| 417 | HRESULT hres = S_OK;
|
|---|
| 418 |
|
|---|
| 419 | TRACE("(tdesc.vt %d)\n",tdesc->vt);
|
|---|
| 420 |
|
|---|
| 421 | switch (tdesc->vt) {
|
|---|
| 422 | case VT_EMPTY: /* nothing. empty variant for instance */
|
|---|
| 423 | return S_OK;
|
|---|
| 424 | case VT_BOOL:
|
|---|
| 425 | case VT_ERROR:
|
|---|
| 426 | case VT_UI4:
|
|---|
| 427 | case VT_UINT:
|
|---|
| 428 | case VT_I4:
|
|---|
| 429 | case VT_UI2:
|
|---|
| 430 | case VT_UI1:
|
|---|
| 431 | hres = S_OK;
|
|---|
| 432 | if (debugout) MESSAGE("%lx",*arg);
|
|---|
| 433 | if (writeit)
|
|---|
| 434 | hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
|
|---|
| 435 | return hres;
|
|---|
| 436 | case VT_VARIANT: {
|
|---|
| 437 | TYPEDESC tdesc2;
|
|---|
| 438 | VARIANT *vt = (VARIANT*)arg;
|
|---|
| 439 | DWORD vttype = V_VT(vt);
|
|---|
| 440 |
|
|---|
| 441 | if (debugout) MESSAGE("Vt(%ld)(",vttype);
|
|---|
| 442 | tdesc2.vt = vttype;
|
|---|
| 443 | if (writeit) {
|
|---|
| 444 | hres = xbuf_add(buf,(LPBYTE)&vttype,sizeof(vttype));
|
|---|
| 445 | if (hres) return hres;
|
|---|
| 446 | }
|
|---|
| 447 | /* need to recurse since we need to free the stuff */
|
|---|
| 448 | hres = serialize_param(tinfo,writeit,debugout,dealloc,&tdesc2,&(V_I4(vt)),buf);
|
|---|
| 449 | if (debugout) MESSAGE(")");
|
|---|
| 450 | return hres;
|
|---|
| 451 | }
|
|---|
| 452 | case VT_BSTR: {
|
|---|
| 453 | if (debugout) {
|
|---|
| 454 | if (arg)
|
|---|
| 455 | MESSAGE("%s",debugstr_w((BSTR)*arg));
|
|---|
| 456 | else
|
|---|
| 457 | MESSAGE("<bstr NULL>");
|
|---|
| 458 | }
|
|---|
| 459 | if (writeit) {
|
|---|
| 460 | if (!*arg) {
|
|---|
| 461 | DWORD fakelen = -1;
|
|---|
| 462 | hres = xbuf_add(buf,(LPBYTE)&fakelen,4);
|
|---|
| 463 | if (hres)
|
|---|
| 464 | return hres;
|
|---|
| 465 | } else {
|
|---|
| 466 | DWORD *bstr = ((DWORD*)(*arg))-1;
|
|---|
| 467 |
|
|---|
| 468 | hres = xbuf_add(buf,(LPBYTE)bstr,bstr[0]+4);
|
|---|
| 469 | if (hres)
|
|---|
| 470 | return hres;
|
|---|
| 471 | }
|
|---|
| 472 | }
|
|---|
| 473 | if (dealloc && arg)
|
|---|
| 474 | SysFreeString((BSTR)arg);
|
|---|
| 475 | return S_OK;
|
|---|
| 476 | }
|
|---|
| 477 | case VT_PTR: {
|
|---|
| 478 | DWORD cookie;
|
|---|
| 479 |
|
|---|
| 480 | if (debugout) MESSAGE("*");
|
|---|
| 481 | if (writeit) {
|
|---|
| 482 | cookie = *arg ? 0x42424242 : 0;
|
|---|
| 483 | hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
|
|---|
| 484 | if (hres)
|
|---|
| 485 | return hres;
|
|---|
| 486 | }
|
|---|
| 487 | if (!*arg) {
|
|---|
| 488 | if (debugout) MESSAGE("NULL");
|
|---|
| 489 | return S_OK;
|
|---|
| 490 | }
|
|---|
| 491 | hres = serialize_param(tinfo,writeit,debugout,dealloc,tdesc->u.lptdesc,(DWORD*)*arg,buf);
|
|---|
| 492 | if (dealloc) HeapFree(GetProcessHeap(),0,(LPVOID)arg);
|
|---|
| 493 | return hres;
|
|---|
| 494 | }
|
|---|
| 495 | case VT_UNKNOWN:
|
|---|
| 496 | if (debugout) MESSAGE("unk(0x%lx)",*arg);
|
|---|
| 497 | if (writeit)
|
|---|
| 498 | hres = _marshal_interface(buf,&IID_IUnknown,(LPUNKNOWN)*arg);
|
|---|
| 499 | return hres;
|
|---|
| 500 | case VT_DISPATCH:
|
|---|
| 501 | if (debugout) MESSAGE("idisp(0x%lx)",*arg);
|
|---|
| 502 | if (writeit)
|
|---|
| 503 | hres = _marshal_interface(buf,&IID_IDispatch,(LPUNKNOWN)*arg);
|
|---|
| 504 | return hres;
|
|---|
| 505 | case VT_VOID:
|
|---|
| 506 | if (debugout) MESSAGE("<void>");
|
|---|
| 507 | return S_OK;
|
|---|
| 508 | case VT_USERDEFINED: {
|
|---|
| 509 | ITypeInfo *tinfo2;
|
|---|
| 510 | TYPEATTR *tattr;
|
|---|
| 511 |
|
|---|
| 512 | hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
|
|---|
| 513 | if (hres) {
|
|---|
| 514 | FIXME("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
|
|---|
| 515 | return hres;
|
|---|
| 516 | }
|
|---|
| 517 | ITypeInfo_GetTypeAttr(tinfo2,&tattr);
|
|---|
| 518 | switch (tattr->typekind) {
|
|---|
| 519 | case TKIND_INTERFACE:
|
|---|
| 520 | if (writeit)
|
|---|
| 521 | hres=_marshal_interface(buf,&(tattr->guid),(LPUNKNOWN)arg);
|
|---|
| 522 | break;
|
|---|
| 523 | case TKIND_RECORD: {
|
|---|
| 524 | int i;
|
|---|
| 525 | if (debugout) MESSAGE("{");
|
|---|
| 526 | for (i=0;i<tattr->cVars;i++) {
|
|---|
| 527 | VARDESC *vdesc;
|
|---|
| 528 | ELEMDESC *elem2;
|
|---|
| 529 | TYPEDESC *tdesc2;
|
|---|
| 530 |
|
|---|
| 531 | hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
|
|---|
| 532 | if (hres) {
|
|---|
| 533 | FIXME("Could not get vardesc of %d\n",i);
|
|---|
| 534 | return hres;
|
|---|
| 535 | }
|
|---|
| 536 | /* Need them for hack below */
|
|---|
| 537 | /*
|
|---|
| 538 | memset(names,0,sizeof(names));
|
|---|
| 539 | hres = ITypeInfo_GetNames(tinfo2,vdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
|
|---|
| 540 | if (nrofnames > sizeof(names)/sizeof(names[0])) {
|
|---|
| 541 | ERR("Need more names!\n");
|
|---|
| 542 | }
|
|---|
| 543 | if (!hres && debugout)
|
|---|
| 544 | MESSAGE("%s=",debugstr_w(names[0]));
|
|---|
| 545 | */
|
|---|
| 546 | elem2 = &vdesc->elemdescVar;
|
|---|
| 547 | tdesc2 = &elem2->tdesc;
|
|---|
| 548 | hres = serialize_param(
|
|---|
| 549 | tinfo2,
|
|---|
| 550 | writeit,
|
|---|
| 551 | debugout,
|
|---|
| 552 | dealloc,
|
|---|
| 553 | tdesc2,
|
|---|
| 554 | (DWORD*)(((LPBYTE)arg)+vdesc->u.oInst),
|
|---|
| 555 | buf
|
|---|
| 556 | );
|
|---|
| 557 | if (hres!=S_OK)
|
|---|
| 558 | return hres;
|
|---|
| 559 | if (debugout && (i<(tattr->cVars-1)))
|
|---|
| 560 | MESSAGE(",");
|
|---|
| 561 | }
|
|---|
| 562 | if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
|
|---|
| 563 | memcpy(&(buf->iid),arg,sizeof(buf->iid));
|
|---|
| 564 | if (debugout) MESSAGE("}");
|
|---|
| 565 | break;
|
|---|
| 566 | }
|
|---|
| 567 | default:
|
|---|
| 568 | FIXME("Don't know how to marshal type kind %d\n",tattr->typekind);
|
|---|
| 569 | hres = E_FAIL;
|
|---|
| 570 | break;
|
|---|
| 571 | }
|
|---|
| 572 | ITypeInfo_Release(tinfo2);
|
|---|
| 573 | return hres;
|
|---|
| 574 | }
|
|---|
| 575 | case VT_CARRAY: {
|
|---|
| 576 | ARRAYDESC *adesc = tdesc->u.lpadesc;
|
|---|
| 577 | int i, arrsize = 1;
|
|---|
| 578 |
|
|---|
| 579 | if (debugout) MESSAGE("carr");
|
|---|
| 580 | for (i=0;i<adesc->cDims;i++) {
|
|---|
| 581 | if (debugout) MESSAGE("[%ld]",adesc->rgbounds[i].cElements);
|
|---|
| 582 | arrsize *= adesc->rgbounds[i].cElements;
|
|---|
| 583 | }
|
|---|
| 584 | if (debugout) MESSAGE("[");
|
|---|
| 585 | for (i=0;i<arrsize;i++) {
|
|---|
| 586 | hres = serialize_param(tinfo, writeit, debugout, dealloc, &adesc->tdescElem, (DWORD*)((LPBYTE)arg+i*_xsize(&adesc->tdescElem)), buf);
|
|---|
| 587 | if (hres)
|
|---|
| 588 | return hres;
|
|---|
| 589 | if (debugout && (i<arrsize-1)) MESSAGE(",");
|
|---|
| 590 | }
|
|---|
| 591 | if (debugout) MESSAGE("]");
|
|---|
| 592 | return S_OK;
|
|---|
| 593 | }
|
|---|
| 594 | default:
|
|---|
| 595 | ERR("Unhandled marshal type %d.\n",tdesc->vt);
|
|---|
| 596 | return S_OK;
|
|---|
| 597 | }
|
|---|
| 598 | }
|
|---|
| 599 |
|
|---|
| 600 | static HRESULT
|
|---|
| 601 | serialize_LPVOID_ptr(
|
|---|
| 602 | ITypeInfo *tinfo,
|
|---|
| 603 | BOOL writeit,
|
|---|
| 604 | BOOL debugout,
|
|---|
| 605 | BOOL dealloc,
|
|---|
| 606 | TYPEDESC *tdesc,
|
|---|
| 607 | DWORD *arg,
|
|---|
| 608 | marshal_state *buf
|
|---|
| 609 | ) {
|
|---|
| 610 | HRESULT hres;
|
|---|
| 611 | DWORD cookie;
|
|---|
| 612 |
|
|---|
| 613 | if ((tdesc->vt != VT_PTR) ||
|
|---|
| 614 | (tdesc->u.lptdesc->vt != VT_PTR) ||
|
|---|
| 615 | (tdesc->u.lptdesc->u.lptdesc->vt != VT_VOID)
|
|---|
| 616 | ) {
|
|---|
| 617 | FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
|
|---|
| 618 | return E_FAIL;
|
|---|
| 619 | }
|
|---|
| 620 | cookie = (*arg) ? 0x42424242: 0x0;
|
|---|
| 621 | if (writeit) {
|
|---|
| 622 | hres = xbuf_add(buf, (LPVOID)&cookie, sizeof(cookie));
|
|---|
| 623 | if (hres)
|
|---|
| 624 | return hres;
|
|---|
| 625 | }
|
|---|
| 626 | if (!*arg) {
|
|---|
| 627 | if (debugout) MESSAGE("<lpvoid NULL>");
|
|---|
| 628 | return S_OK;
|
|---|
| 629 | }
|
|---|
| 630 | if (debugout)
|
|---|
| 631 | MESSAGE("ppv(%p)",*(LPUNKNOWN*)*arg);
|
|---|
| 632 | if (writeit) {
|
|---|
| 633 | hres = _marshal_interface(buf,&(buf->iid),*(LPUNKNOWN*)*arg);
|
|---|
| 634 | if (hres)
|
|---|
| 635 | return hres;
|
|---|
| 636 | }
|
|---|
| 637 | if (dealloc)
|
|---|
| 638 | HeapFree(GetProcessHeap(),0,(LPVOID)*arg);
|
|---|
| 639 | return S_OK;
|
|---|
| 640 | }
|
|---|
| 641 |
|
|---|
| 642 | static HRESULT
|
|---|
| 643 | serialize_DISPPARAM_ptr(
|
|---|
| 644 | ITypeInfo *tinfo,
|
|---|
| 645 | BOOL writeit,
|
|---|
| 646 | BOOL debugout,
|
|---|
| 647 | BOOL dealloc,
|
|---|
| 648 | TYPEDESC *tdesc,
|
|---|
| 649 | DWORD *arg,
|
|---|
| 650 | marshal_state *buf
|
|---|
| 651 | ) {
|
|---|
| 652 | DWORD cookie;
|
|---|
| 653 | HRESULT hres;
|
|---|
| 654 | DISPPARAMS *disp;
|
|---|
| 655 | int i;
|
|---|
| 656 |
|
|---|
| 657 | if ((tdesc->vt != VT_PTR) || (tdesc->u.lptdesc->vt != VT_USERDEFINED)) {
|
|---|
| 658 | FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
|
|---|
| 659 | return E_FAIL;
|
|---|
| 660 | }
|
|---|
| 661 |
|
|---|
| 662 | cookie = *arg ? 0x42424242 : 0x0;
|
|---|
| 663 | if (writeit) {
|
|---|
| 664 | hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
|
|---|
| 665 | if (hres)
|
|---|
| 666 | return hres;
|
|---|
| 667 | }
|
|---|
| 668 | if (!*arg) {
|
|---|
| 669 | if (debugout) MESSAGE("<DISPPARAMS NULL>");
|
|---|
| 670 | return S_OK;
|
|---|
| 671 | }
|
|---|
| 672 | disp = (DISPPARAMS*)*arg;
|
|---|
| 673 | if (writeit) {
|
|---|
| 674 | hres = xbuf_add(buf,(LPBYTE)&disp->cArgs,sizeof(disp->cArgs));
|
|---|
| 675 | if (hres)
|
|---|
| 676 | return hres;
|
|---|
| 677 | }
|
|---|
| 678 | if (debugout) MESSAGE("D{");
|
|---|
| 679 | for (i=0;i<disp->cArgs;i++) {
|
|---|
| 680 | TYPEDESC vtdesc;
|
|---|
| 681 |
|
|---|
| 682 | vtdesc.vt = VT_VARIANT;
|
|---|
| 683 | serialize_param(
|
|---|
| 684 | tinfo,
|
|---|
| 685 | writeit,
|
|---|
| 686 | debugout,
|
|---|
| 687 | dealloc,
|
|---|
| 688 | &vtdesc,
|
|---|
| 689 | (DWORD*)(disp->rgvarg+i),
|
|---|
| 690 | buf
|
|---|
| 691 | );
|
|---|
| 692 | if (debugout && (i<disp->cArgs-1))
|
|---|
| 693 | MESSAGE(",");
|
|---|
| 694 | }
|
|---|
| 695 | if (dealloc)
|
|---|
| 696 | HeapFree(GetProcessHeap(),0,disp->rgvarg);
|
|---|
| 697 | if (writeit) {
|
|---|
| 698 | hres = xbuf_add(buf,(LPBYTE)&disp->cNamedArgs,sizeof(disp->cNamedArgs));
|
|---|
| 699 | if (hres)
|
|---|
| 700 | return hres;
|
|---|
| 701 | }
|
|---|
| 702 | if (debugout) MESSAGE("}{");
|
|---|
| 703 | for (i=0;i<disp->cNamedArgs;i++) {
|
|---|
| 704 | TYPEDESC vtdesc;
|
|---|
| 705 |
|
|---|
| 706 | vtdesc.vt = VT_UINT;
|
|---|
| 707 | serialize_param(
|
|---|
| 708 | tinfo,
|
|---|
| 709 | writeit,
|
|---|
| 710 | debugout,
|
|---|
| 711 | dealloc,
|
|---|
| 712 | &vtdesc,
|
|---|
| 713 | (DWORD*)(disp->rgdispidNamedArgs+i),
|
|---|
| 714 | buf
|
|---|
| 715 | );
|
|---|
| 716 | if (debugout && (i<disp->cNamedArgs-1))
|
|---|
| 717 | MESSAGE(",");
|
|---|
| 718 | }
|
|---|
| 719 | if (debugout) MESSAGE("}");
|
|---|
| 720 | if (dealloc) {
|
|---|
| 721 | HeapFree(GetProcessHeap(),0,disp->rgdispidNamedArgs);
|
|---|
| 722 | HeapFree(GetProcessHeap(),0,disp);
|
|---|
| 723 | }
|
|---|
| 724 | return S_OK;
|
|---|
| 725 | }
|
|---|
| 726 |
|
|---|
| 727 | static HRESULT
|
|---|
| 728 | deserialize_param(
|
|---|
| 729 | ITypeInfo *tinfo,
|
|---|
| 730 | BOOL readit,
|
|---|
| 731 | BOOL debugout,
|
|---|
| 732 | BOOL alloc,
|
|---|
| 733 | TYPEDESC *tdesc,
|
|---|
| 734 | DWORD *arg,
|
|---|
| 735 | marshal_state *buf
|
|---|
| 736 | ) {
|
|---|
| 737 | HRESULT hres = S_OK;
|
|---|
| 738 |
|
|---|
| 739 | TRACE("vt %d at %p\n",tdesc->vt,arg);
|
|---|
| 740 |
|
|---|
| 741 | while (1) {
|
|---|
| 742 | switch (tdesc->vt) {
|
|---|
| 743 | case VT_EMPTY:
|
|---|
| 744 | if (debugout) MESSAGE("<empty>");
|
|---|
| 745 | return S_OK;
|
|---|
| 746 | case VT_NULL:
|
|---|
| 747 | if (debugout) MESSAGE("<null>");
|
|---|
| 748 | return S_OK;
|
|---|
| 749 | case VT_VARIANT: {
|
|---|
| 750 | VARIANT *vt = (VARIANT*)arg;
|
|---|
| 751 |
|
|---|
| 752 | if (readit) {
|
|---|
| 753 | DWORD vttype;
|
|---|
| 754 | TYPEDESC tdesc2;
|
|---|
| 755 | hres = xbuf_get(buf,(LPBYTE)&vttype,sizeof(vttype));
|
|---|
| 756 | if (hres) {
|
|---|
| 757 | FIXME("vt type not read?\n");
|
|---|
| 758 | return hres;
|
|---|
| 759 | }
|
|---|
| 760 | memset(&tdesc2,0,sizeof(tdesc2));
|
|---|
| 761 | tdesc2.vt = vttype;
|
|---|
| 762 | V_VT(vt) = vttype;
|
|---|
| 763 | if (debugout) MESSAGE("Vt(%ld)(",vttype);
|
|---|
| 764 | hres = deserialize_param(tinfo, readit, debugout, alloc, &tdesc2, &(V_I4(vt)), buf);
|
|---|
| 765 | MESSAGE(")");
|
|---|
| 766 | return hres;
|
|---|
| 767 | } else {
|
|---|
| 768 | VariantInit(vt);
|
|---|
| 769 | return S_OK;
|
|---|
| 770 | }
|
|---|
| 771 | }
|
|---|
| 772 | case VT_ERROR:
|
|---|
| 773 | case VT_BOOL: case VT_I4: case VT_UI4: case VT_UINT:
|
|---|
| 774 | case VT_UI2:
|
|---|
| 775 | case VT_UI1:
|
|---|
| 776 | if (readit) {
|
|---|
| 777 | hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
|
|---|
| 778 | if (hres) FIXME("Failed to read integer 4 byte\n");
|
|---|
| 779 | }
|
|---|
| 780 | if (debugout) MESSAGE("%lx",*arg);
|
|---|
| 781 | return hres;
|
|---|
| 782 | case VT_BSTR: {
|
|---|
| 783 | WCHAR *str;
|
|---|
| 784 | DWORD len;
|
|---|
| 785 |
|
|---|
| 786 | if (readit) {
|
|---|
| 787 | hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
|
|---|
| 788 | if (hres) {
|
|---|
| 789 | FIXME("failed to read bstr klen\n");
|
|---|
| 790 | return hres;
|
|---|
| 791 | }
|
|---|
| 792 | if (len == -1) {
|
|---|
| 793 | *arg = 0;
|
|---|
| 794 | if (debugout) MESSAGE("<bstr NULL>");
|
|---|
| 795 | } else {
|
|---|
| 796 | str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len+sizeof(WCHAR));
|
|---|
| 797 | hres = xbuf_get(buf,(LPBYTE)str,len);
|
|---|
| 798 | if (hres) {
|
|---|
| 799 | FIXME("Failed to read BSTR.\n");
|
|---|
| 800 | return hres;
|
|---|
| 801 | }
|
|---|
| 802 | *arg = (DWORD)SysAllocStringLen(str,len);
|
|---|
| 803 | if (debugout) MESSAGE("%s",debugstr_w(str));
|
|---|
| 804 | HeapFree(GetProcessHeap(),0,str);
|
|---|
| 805 | }
|
|---|
| 806 | } else {
|
|---|
| 807 | *arg = 0;
|
|---|
| 808 | }
|
|---|
| 809 | return S_OK;
|
|---|
| 810 | }
|
|---|
| 811 | case VT_PTR: {
|
|---|
| 812 | DWORD cookie;
|
|---|
| 813 | BOOL derefhere = 0;
|
|---|
| 814 |
|
|---|
| 815 | derefhere = (tdesc->u.lptdesc->vt != VT_USERDEFINED);
|
|---|
| 816 |
|
|---|
| 817 | if (readit) {
|
|---|
| 818 | hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
|
|---|
| 819 | if (hres) {
|
|---|
| 820 | FIXME("Failed to load pointer cookie.\n");
|
|---|
| 821 | return hres;
|
|---|
| 822 | }
|
|---|
| 823 | if (cookie != 0x42424242) {
|
|---|
| 824 | if (debugout) MESSAGE("NULL");
|
|---|
| 825 | *arg = 0;
|
|---|
| 826 | return S_OK;
|
|---|
| 827 | }
|
|---|
| 828 | if (debugout) MESSAGE("*");
|
|---|
| 829 | }
|
|---|
| 830 | if (alloc) {
|
|---|
| 831 | if (derefhere)
|
|---|
| 832 | *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,_xsize(tdesc->u.lptdesc));
|
|---|
| 833 | }
|
|---|
| 834 | if (derefhere)
|
|---|
| 835 | return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, (LPDWORD)*arg, buf);
|
|---|
| 836 | else
|
|---|
| 837 | return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, arg, buf);
|
|---|
| 838 | }
|
|---|
| 839 | case VT_UNKNOWN:
|
|---|
| 840 | /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
|
|---|
| 841 | if (alloc)
|
|---|
| 842 | *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
|
|---|
| 843 | hres = S_OK;
|
|---|
| 844 | if (readit)
|
|---|
| 845 | hres = _unmarshal_interface(buf,&IID_IUnknown,(LPUNKNOWN*)arg);
|
|---|
| 846 | if (debugout)
|
|---|
| 847 | MESSAGE("unk(%p)",arg);
|
|---|
| 848 | return hres;
|
|---|
| 849 | case VT_DISPATCH:
|
|---|
| 850 | hres = S_OK;
|
|---|
| 851 | if (readit)
|
|---|
| 852 | hres = _unmarshal_interface(buf,&IID_IDispatch,(LPUNKNOWN*)arg);
|
|---|
| 853 | if (debugout)
|
|---|
| 854 | MESSAGE("idisp(%p)",arg);
|
|---|
| 855 | return hres;
|
|---|
| 856 | case VT_VOID:
|
|---|
| 857 | if (debugout) MESSAGE("<void>");
|
|---|
| 858 | return S_OK;
|
|---|
| 859 | case VT_USERDEFINED: {
|
|---|
| 860 | ITypeInfo *tinfo2;
|
|---|
| 861 | TYPEATTR *tattr;
|
|---|
| 862 |
|
|---|
| 863 | hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
|
|---|
| 864 | if (hres) {
|
|---|
| 865 | FIXME("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
|
|---|
| 866 | return hres;
|
|---|
| 867 | }
|
|---|
| 868 | hres = ITypeInfo_GetTypeAttr(tinfo2,&tattr);
|
|---|
| 869 | if (hres) {
|
|---|
| 870 | FIXME("Could not get typeattr in VT_USERDEFINED.\n");
|
|---|
| 871 | } else {
|
|---|
| 872 | if (alloc)
|
|---|
| 873 | *arg = (DWORD)HeapAlloc(GetProcessHeap(),0,tattr->cbSizeInstance);
|
|---|
| 874 | switch (tattr->typekind) {
|
|---|
| 875 | case TKIND_INTERFACE:
|
|---|
| 876 | if (readit)
|
|---|
| 877 | hres = _unmarshal_interface(buf,&(tattr->guid),(LPUNKNOWN*)arg);
|
|---|
| 878 | break;
|
|---|
| 879 | case TKIND_RECORD: {
|
|---|
| 880 | int i;
|
|---|
| 881 |
|
|---|
| 882 | if (debugout) MESSAGE("{");
|
|---|
| 883 | for (i=0;i<tattr->cVars;i++) {
|
|---|
| 884 | VARDESC *vdesc;
|
|---|
| 885 |
|
|---|
| 886 | hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
|
|---|
| 887 | if (hres) {
|
|---|
| 888 | FIXME("Could not get vardesc of %d\n",i);
|
|---|
| 889 | return hres;
|
|---|
| 890 | }
|
|---|
| 891 | hres = deserialize_param(
|
|---|
| 892 | tinfo2,
|
|---|
| 893 | readit,
|
|---|
| 894 | debugout,
|
|---|
| 895 | alloc,
|
|---|
| 896 | &vdesc->elemdescVar.tdesc,
|
|---|
| 897 | (DWORD*)(((LPBYTE)*arg)+vdesc->u.oInst),
|
|---|
| 898 | buf
|
|---|
| 899 | );
|
|---|
| 900 | if (debugout && (i<tattr->cVars-1)) MESSAGE(",");
|
|---|
| 901 | }
|
|---|
| 902 | if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
|
|---|
| 903 | memcpy(&(buf->iid),(LPBYTE)*arg,sizeof(buf->iid));
|
|---|
| 904 | if (debugout) MESSAGE("}");
|
|---|
| 905 | break;
|
|---|
| 906 | }
|
|---|
| 907 | default:
|
|---|
| 908 | FIXME("Don't know how to marshal type kind %d\n",tattr->typekind);
|
|---|
| 909 | hres = E_FAIL;
|
|---|
| 910 | break;
|
|---|
| 911 | }
|
|---|
| 912 | }
|
|---|
| 913 | if (hres)
|
|---|
| 914 | FIXME("failed to stuballoc in TKIND_RECORD.\n");
|
|---|
| 915 | ITypeInfo_Release(tinfo2);
|
|---|
| 916 | return hres;
|
|---|
| 917 | }
|
|---|
| 918 | case VT_CARRAY: {
|
|---|
| 919 | /* arg is pointing to the start of the array. */
|
|---|
| 920 | ARRAYDESC *adesc = tdesc->u.lpadesc;
|
|---|
| 921 | int arrsize,i;
|
|---|
| 922 | arrsize = 1;
|
|---|
| 923 | if (adesc->cDims > 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
|
|---|
| 924 | for (i=0;i<adesc->cDims;i++)
|
|---|
| 925 | arrsize *= adesc->rgbounds[i].cElements;
|
|---|
| 926 | for (i=0;i<arrsize;i++)
|
|---|
| 927 | deserialize_param(
|
|---|
| 928 | tinfo,
|
|---|
| 929 | readit,
|
|---|
| 930 | debugout,
|
|---|
| 931 | alloc,
|
|---|
| 932 | &adesc->tdescElem,
|
|---|
| 933 | (DWORD*)((LPBYTE)(arg)+i*_xsize(&adesc->tdescElem)),
|
|---|
| 934 | buf
|
|---|
| 935 | );
|
|---|
| 936 | return S_OK;
|
|---|
| 937 | }
|
|---|
| 938 | default:
|
|---|
| 939 | ERR("No handler for VT type %d!\n",tdesc->vt);
|
|---|
| 940 | return S_OK;
|
|---|
| 941 | }
|
|---|
| 942 | }
|
|---|
| 943 | }
|
|---|
| 944 |
|
|---|
| 945 | static HRESULT
|
|---|
| 946 | deserialize_LPVOID_ptr(
|
|---|
| 947 | ITypeInfo *tinfo,
|
|---|
| 948 | BOOL readit,
|
|---|
| 949 | BOOL debugout,
|
|---|
| 950 | BOOL alloc,
|
|---|
| 951 | TYPEDESC *tdesc,
|
|---|
| 952 | DWORD *arg,
|
|---|
| 953 | marshal_state *buf
|
|---|
| 954 | ) {
|
|---|
| 955 | HRESULT hres;
|
|---|
| 956 | DWORD cookie;
|
|---|
| 957 |
|
|---|
| 958 | if ((tdesc->vt != VT_PTR) ||
|
|---|
| 959 | (tdesc->u.lptdesc->vt != VT_PTR) ||
|
|---|
| 960 | (tdesc->u.lptdesc->u.lptdesc->vt != VT_VOID)
|
|---|
| 961 | ) {
|
|---|
| 962 | FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
|
|---|
| 963 | return E_FAIL;
|
|---|
| 964 | }
|
|---|
| 965 | if (alloc)
|
|---|
| 966 | *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(LPVOID));
|
|---|
| 967 | if (readit) {
|
|---|
| 968 | hres = xbuf_get(buf, (LPVOID)&cookie, sizeof(cookie));
|
|---|
| 969 | if (hres)
|
|---|
| 970 | return hres;
|
|---|
| 971 | if (cookie != 0x42424242) {
|
|---|
| 972 | *(DWORD*)*arg = 0;
|
|---|
| 973 | if (debugout) MESSAGE("<lpvoid NULL>");
|
|---|
| 974 | return S_OK;
|
|---|
| 975 | }
|
|---|
| 976 | }
|
|---|
| 977 | if (readit) {
|
|---|
| 978 | hres = _unmarshal_interface(buf,&buf->iid,(LPUNKNOWN*)*arg);
|
|---|
| 979 | if (hres)
|
|---|
| 980 | return hres;
|
|---|
| 981 | }
|
|---|
| 982 | if (debugout) MESSAGE("ppv(%p)",(LPVOID)*arg);
|
|---|
| 983 | return S_OK;
|
|---|
| 984 | }
|
|---|
| 985 |
|
|---|
| 986 | static HRESULT
|
|---|
| 987 | deserialize_DISPPARAM_ptr(
|
|---|
| 988 | ITypeInfo *tinfo,
|
|---|
| 989 | BOOL readit,
|
|---|
| 990 | BOOL debugout,
|
|---|
| 991 | BOOL alloc,
|
|---|
| 992 | TYPEDESC *tdesc,
|
|---|
| 993 | DWORD *arg,
|
|---|
| 994 | marshal_state *buf
|
|---|
| 995 | ) {
|
|---|
| 996 | DWORD cookie;
|
|---|
| 997 | DISPPARAMS *disps;
|
|---|
| 998 | HRESULT hres;
|
|---|
| 999 | int i;
|
|---|
| 1000 |
|
|---|
| 1001 | if ((tdesc->vt != VT_PTR) || (tdesc->u.lptdesc->vt != VT_USERDEFINED)) {
|
|---|
| 1002 | FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
|
|---|
| 1003 | return E_FAIL;
|
|---|
| 1004 | }
|
|---|
| 1005 | if (readit) {
|
|---|
| 1006 | hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
|
|---|
| 1007 | if (hres)
|
|---|
| 1008 | return hres;
|
|---|
| 1009 | if (cookie == 0) {
|
|---|
| 1010 | *arg = 0;
|
|---|
| 1011 | if (debugout) MESSAGE("<DISPPARAMS NULL>");
|
|---|
| 1012 | return S_OK;
|
|---|
| 1013 | }
|
|---|
| 1014 | }
|
|---|
| 1015 | if (alloc)
|
|---|
| 1016 | *arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPPARAMS));
|
|---|
| 1017 | disps = (DISPPARAMS*)*arg;
|
|---|
| 1018 | if (!readit)
|
|---|
| 1019 | return S_OK;
|
|---|
| 1020 | hres = xbuf_get(buf, (LPBYTE)&disps->cArgs, sizeof(disps->cArgs));
|
|---|
| 1021 | if (hres)
|
|---|
| 1022 | return hres;
|
|---|
| 1023 | if (alloc)
|
|---|
| 1024 | disps->rgvarg = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(VARIANT)*disps->cArgs);
|
|---|
| 1025 | if (debugout) MESSAGE("D{");
|
|---|
| 1026 | for (i=0; i< disps->cArgs; i++) {
|
|---|
| 1027 | TYPEDESC vdesc;
|
|---|
| 1028 |
|
|---|
| 1029 | vdesc.vt = VT_VARIANT;
|
|---|
| 1030 | hres = deserialize_param(
|
|---|
| 1031 | tinfo,
|
|---|
| 1032 | readit,
|
|---|
| 1033 | debugout,
|
|---|
| 1034 | alloc,
|
|---|
| 1035 | &vdesc,
|
|---|
| 1036 | (DWORD*)(disps->rgvarg+i),
|
|---|
| 1037 | buf
|
|---|
| 1038 | );
|
|---|
| 1039 | }
|
|---|
| 1040 | if (debugout) MESSAGE("}{");
|
|---|
| 1041 | hres = xbuf_get(buf, (LPBYTE)&disps->cNamedArgs, sizeof(disps->cNamedArgs));
|
|---|
| 1042 | if (hres)
|
|---|
| 1043 | return hres;
|
|---|
| 1044 | if (disps->cNamedArgs) {
|
|---|
| 1045 | if (alloc)
|
|---|
| 1046 | disps->rgdispidNamedArgs = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPID)*disps->cNamedArgs);
|
|---|
| 1047 | for (i=0; i< disps->cNamedArgs; i++) {
|
|---|
| 1048 | TYPEDESC vdesc;
|
|---|
| 1049 |
|
|---|
| 1050 | vdesc.vt = VT_UINT;
|
|---|
| 1051 | hres = deserialize_param(
|
|---|
| 1052 | tinfo,
|
|---|
| 1053 | readit,
|
|---|
| 1054 | debugout,
|
|---|
| 1055 | alloc,
|
|---|
| 1056 | &vdesc,
|
|---|
| 1057 | (DWORD*)(disps->rgdispidNamedArgs+i),
|
|---|
| 1058 | buf
|
|---|
| 1059 | );
|
|---|
| 1060 | if (debugout && i<(disps->cNamedArgs-1)) MESSAGE(",");
|
|---|
| 1061 | }
|
|---|
| 1062 | }
|
|---|
| 1063 | if (debugout) MESSAGE("}");
|
|---|
| 1064 | return S_OK;
|
|---|
| 1065 | }
|
|---|
| 1066 |
|
|---|
| 1067 | /* Searches function, also in inherited interfaces */
|
|---|
| 1068 | static HRESULT
|
|---|
| 1069 | _get_funcdesc(
|
|---|
| 1070 | ITypeInfo *tinfo, int iMethod, FUNCDESC **fdesc, BSTR *iname, BSTR *fname
|
|---|
| 1071 | ) {
|
|---|
| 1072 | int i = 0, j = 0;
|
|---|
| 1073 | HRESULT hres;
|
|---|
| 1074 |
|
|---|
| 1075 | if (fname) *fname = NULL;
|
|---|
| 1076 | if (iname) *iname = NULL;
|
|---|
| 1077 |
|
|---|
| 1078 | while (1) {
|
|---|
| 1079 | hres = ITypeInfo_GetFuncDesc(tinfo, i, fdesc);
|
|---|
| 1080 | if (hres) {
|
|---|
| 1081 | ITypeInfo *tinfo2;
|
|---|
| 1082 | HREFTYPE href;
|
|---|
| 1083 | TYPEATTR *attr;
|
|---|
| 1084 |
|
|---|
| 1085 | hres = ITypeInfo_GetTypeAttr(tinfo, &attr);
|
|---|
| 1086 | if (hres) {
|
|---|
| 1087 | FIXME("GetTypeAttr failed with %lx\n",hres);
|
|---|
| 1088 | return hres;
|
|---|
| 1089 | }
|
|---|
| 1090 | /* Not found, so look in inherited ifaces. */
|
|---|
| 1091 | for (j=0;j<attr->cImplTypes;j++) {
|
|---|
| 1092 | hres = ITypeInfo_GetRefTypeOfImplType(tinfo, j, &href);
|
|---|
| 1093 | if (hres) {
|
|---|
| 1094 | FIXME("Did not find a reftype for interface offset %d?\n",j);
|
|---|
| 1095 | break;
|
|---|
| 1096 | }
|
|---|
| 1097 | hres = ITypeInfo_GetRefTypeInfo(tinfo, href, &tinfo2);
|
|---|
| 1098 | if (hres) {
|
|---|
| 1099 | FIXME("Did not find a typeinfo for reftype %ld?\n",href);
|
|---|
| 1100 | continue;
|
|---|
| 1101 | }
|
|---|
| 1102 | hres = _get_funcdesc(tinfo2,iMethod,fdesc,iname,fname);
|
|---|
| 1103 | ITypeInfo_Release(tinfo2);
|
|---|
| 1104 | if (!hres) return S_OK;
|
|---|
| 1105 | }
|
|---|
| 1106 | return E_FAIL;
|
|---|
| 1107 | }
|
|---|
| 1108 | if (((*fdesc)->oVft/4) == iMethod) {
|
|---|
| 1109 | if (fname)
|
|---|
| 1110 | ITypeInfo_GetDocumentation(tinfo,(*fdesc)->memid,fname,NULL,NULL,NULL);
|
|---|
| 1111 | if (iname)
|
|---|
| 1112 | ITypeInfo_GetDocumentation(tinfo,-1,iname,NULL,NULL,NULL);
|
|---|
| 1113 | return S_OK;
|
|---|
| 1114 | }
|
|---|
| 1115 | i++;
|
|---|
| 1116 | }
|
|---|
| 1117 | return E_FAIL;
|
|---|
| 1118 | }
|
|---|
| 1119 |
|
|---|
| 1120 | #ifdef __WIN32OS2__
|
|---|
| 1121 | static DWORD CDECL
|
|---|
| 1122 | #else
|
|---|
| 1123 | static DWORD
|
|---|
| 1124 | #endif
|
|---|
| 1125 | xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */) {
|
|---|
| 1126 | DWORD *args = ((DWORD*)&tpinfo)+1, *xargs;
|
|---|
| 1127 | FUNCDESC *fdesc;
|
|---|
| 1128 | HRESULT hres;
|
|---|
| 1129 | int i, relaydeb = TRACE_ON(olerelay);
|
|---|
| 1130 | marshal_state buf;
|
|---|
| 1131 | RPCOLEMESSAGE msg;
|
|---|
| 1132 | ULONG status;
|
|---|
| 1133 | BSTR fname,iname;
|
|---|
| 1134 | BSTR names[10];
|
|---|
| 1135 | int nrofnames;
|
|---|
| 1136 |
|
|---|
| 1137 | hres = _get_funcdesc(tpinfo->tinfo,method,&fdesc,&iname,&fname);
|
|---|
| 1138 | if (hres) {
|
|---|
| 1139 | ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method);
|
|---|
| 1140 | return 0;
|
|---|
| 1141 | }
|
|---|
| 1142 |
|
|---|
| 1143 | /*dump_FUNCDESC(fdesc);*/
|
|---|
| 1144 | if (relaydeb) {
|
|---|
| 1145 | TRACE_(olerelay)("->");
|
|---|
| 1146 | if (iname)
|
|---|
| 1147 | MESSAGE("%s:",debugstr_w(iname));
|
|---|
| 1148 | if (fname)
|
|---|
| 1149 | MESSAGE("%s(%d)",debugstr_w(fname),method);
|
|---|
| 1150 | else
|
|---|
| 1151 | MESSAGE("%d",method);
|
|---|
| 1152 | MESSAGE("(");
|
|---|
| 1153 | if (iname) SysFreeString(iname);
|
|---|
| 1154 | if (fname) SysFreeString(fname);
|
|---|
| 1155 | }
|
|---|
| 1156 | /* Need them for hack below */
|
|---|
| 1157 | memset(names,0,sizeof(names));
|
|---|
| 1158 | if (ITypeInfo_GetNames(tpinfo->tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames))
|
|---|
| 1159 | nrofnames = 0;
|
|---|
| 1160 | if (nrofnames > sizeof(names)/sizeof(names[0]))
|
|---|
| 1161 | ERR("Need more names!\n");
|
|---|
| 1162 |
|
|---|
| 1163 | memset(&buf,0,sizeof(buf));
|
|---|
| 1164 | buf.iid = IID_IUnknown;
|
|---|
| 1165 | if (method == 0) {
|
|---|
| 1166 | xbuf_add(&buf,(LPBYTE)args[0],sizeof(IID));
|
|---|
| 1167 | if (relaydeb) MESSAGE("riid=%s,[out]",debugstr_guid((REFIID)args[0]));
|
|---|
| 1168 | } else {
|
|---|
| 1169 | xargs = args;
|
|---|
| 1170 | for (i=0;i<fdesc->cParams;i++) {
|
|---|
| 1171 | ELEMDESC *elem = fdesc->lprgelemdescParam+i;
|
|---|
| 1172 | BOOL isserialized = FALSE;
|
|---|
| 1173 | if (relaydeb) {
|
|---|
| 1174 | if (i) MESSAGE(",");
|
|---|
| 1175 | if (i+1<nrofnames && names[i+1])
|
|---|
| 1176 | MESSAGE("%s=",debugstr_w(names[i+1]));
|
|---|
| 1177 | }
|
|---|
| 1178 | /* No need to marshal other data than FIN */
|
|---|
| 1179 | if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN)) {
|
|---|
| 1180 | xargs+=_argsize(elem->tdesc.vt);
|
|---|
| 1181 | if (relaydeb) MESSAGE("[out]");
|
|---|
| 1182 | continue;
|
|---|
| 1183 | }
|
|---|
| 1184 | if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
|
|---|
| 1185 | /* If the parameter is 'riid', we use it as interface IID
|
|---|
| 1186 | * for a later ppvObject serialization.
|
|---|
| 1187 | */
|
|---|
| 1188 | buf.thisisiid = !lstrcmpW(names[i+1],riidW);
|
|---|
| 1189 |
|
|---|
| 1190 | /* DISPPARAMS* needs special serializer */
|
|---|
| 1191 | if (!lstrcmpW(names[i+1],pdispparamsW)) {
|
|---|
| 1192 | hres = serialize_DISPPARAM_ptr(
|
|---|
| 1193 | tpinfo->tinfo,
|
|---|
| 1194 | elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
|
|---|
| 1195 | relaydeb,
|
|---|
| 1196 | FALSE,
|
|---|
| 1197 | &elem->tdesc,
|
|---|
| 1198 | xargs,
|
|---|
| 1199 | &buf
|
|---|
| 1200 | );
|
|---|
| 1201 | isserialized = TRUE;
|
|---|
| 1202 | }
|
|---|
| 1203 | if (!lstrcmpW(names[i+1],ppvObjectW)) {
|
|---|
| 1204 | hres = serialize_LPVOID_ptr(
|
|---|
| 1205 | tpinfo->tinfo,
|
|---|
| 1206 | elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
|
|---|
| 1207 | relaydeb,
|
|---|
| 1208 | FALSE,
|
|---|
| 1209 | &elem->tdesc,
|
|---|
| 1210 | xargs,
|
|---|
| 1211 | &buf
|
|---|
| 1212 | );
|
|---|
| 1213 | if (hres == S_OK)
|
|---|
| 1214 | isserialized = TRUE;
|
|---|
| 1215 | }
|
|---|
| 1216 | }
|
|---|
| 1217 | if (!isserialized)
|
|---|
| 1218 | hres = serialize_param(
|
|---|
| 1219 | tpinfo->tinfo,
|
|---|
| 1220 | elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
|
|---|
| 1221 | relaydeb,
|
|---|
| 1222 | FALSE,
|
|---|
| 1223 | &elem->tdesc,
|
|---|
| 1224 | xargs,
|
|---|
| 1225 | &buf
|
|---|
| 1226 | );
|
|---|
| 1227 |
|
|---|
| 1228 | if (hres) {
|
|---|
| 1229 | FIXME("Failed to serialize param, hres %lx\n",hres);
|
|---|
| 1230 | break;
|
|---|
| 1231 | }
|
|---|
| 1232 | xargs+=_argsize(elem->tdesc.vt);
|
|---|
| 1233 | }
|
|---|
| 1234 | }
|
|---|
| 1235 | if (relaydeb) MESSAGE(")");
|
|---|
| 1236 | memset(&msg,0,sizeof(msg));
|
|---|
| 1237 | msg.cbBuffer = buf.curoff;
|
|---|
| 1238 | msg.iMethod = method;
|
|---|
| 1239 | hres = IRpcChannelBuffer_GetBuffer(tpinfo->chanbuf,&msg,&(tpinfo->iid));
|
|---|
| 1240 | if (hres) {
|
|---|
| 1241 | FIXME("RpcChannelBuffer GetBuffer failed, %lx\n",hres);
|
|---|
| 1242 | return hres;
|
|---|
| 1243 | }
|
|---|
| 1244 | memcpy(msg.Buffer,buf.base,buf.curoff);
|
|---|
| 1245 | if (relaydeb) MESSAGE("\n");
|
|---|
| 1246 | hres = IRpcChannelBuffer_SendReceive(tpinfo->chanbuf,&msg,&status);
|
|---|
| 1247 | if (hres) {
|
|---|
| 1248 | FIXME("RpcChannelBuffer SendReceive failed, %lx\n",hres);
|
|---|
| 1249 | return hres;
|
|---|
| 1250 | }
|
|---|
| 1251 | relaydeb = TRACE_ON(olerelay);
|
|---|
| 1252 | if (relaydeb) MESSAGE(" = %08lx (",status);
|
|---|
| 1253 | if (buf.base)
|
|---|
| 1254 | buf.base = HeapReAlloc(GetProcessHeap(),0,buf.base,msg.cbBuffer);
|
|---|
| 1255 | else
|
|---|
| 1256 | buf.base = HeapAlloc(GetProcessHeap(),0,msg.cbBuffer);
|
|---|
| 1257 | buf.size = msg.cbBuffer;
|
|---|
| 1258 | memcpy(buf.base,msg.Buffer,buf.size);
|
|---|
| 1259 | buf.curoff = 0;
|
|---|
| 1260 | if (method == 0) {
|
|---|
| 1261 | _unmarshal_interface(&buf,(REFIID)args[0],(LPUNKNOWN*)args[1]);
|
|---|
| 1262 | if (relaydeb) MESSAGE("[in],%p",*((DWORD**)args[1]));
|
|---|
| 1263 | } else {
|
|---|
| 1264 | xargs = args;
|
|---|
| 1265 | for (i=0;i<fdesc->cParams;i++) {
|
|---|
| 1266 | ELEMDESC *elem = fdesc->lprgelemdescParam+i;
|
|---|
| 1267 | BOOL isdeserialized = FALSE;
|
|---|
| 1268 |
|
|---|
| 1269 | if (relaydeb) {
|
|---|
| 1270 | if (i) MESSAGE(",");
|
|---|
| 1271 | if (i+1<nrofnames && names[i+1]) MESSAGE("%s=",debugstr_w(names[i+1]));
|
|---|
| 1272 | }
|
|---|
| 1273 | /* No need to marshal other data than FOUT I think */
|
|---|
| 1274 | if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT)) {
|
|---|
| 1275 | xargs += _argsize(elem->tdesc.vt);
|
|---|
| 1276 | if (relaydeb) MESSAGE("[in]");
|
|---|
| 1277 | continue;
|
|---|
| 1278 | }
|
|---|
| 1279 | if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
|
|---|
| 1280 | /* If the parameter is 'riid', we use it as interface IID
|
|---|
| 1281 | * for a later ppvObject serialization.
|
|---|
| 1282 | */
|
|---|
| 1283 | buf.thisisiid = !lstrcmpW(names[i+1],riidW);
|
|---|
| 1284 |
|
|---|
| 1285 | /* deserialize DISPPARAM */
|
|---|
| 1286 | if (!lstrcmpW(names[i+1],pdispparamsW)) {
|
|---|
| 1287 | hres = deserialize_DISPPARAM_ptr(
|
|---|
| 1288 | tpinfo->tinfo,
|
|---|
| 1289 | elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
|
|---|
| 1290 | relaydeb,
|
|---|
| 1291 | FALSE,
|
|---|
| 1292 | &(elem->tdesc),
|
|---|
| 1293 | xargs,
|
|---|
| 1294 | &buf
|
|---|
| 1295 | );
|
|---|
| 1296 | if (hres) {
|
|---|
| 1297 | FIXME("Failed to deserialize DISPPARAM*, hres %lx\n",hres);
|
|---|
| 1298 | break;
|
|---|
| 1299 | }
|
|---|
| 1300 | isdeserialized = TRUE;
|
|---|
| 1301 | }
|
|---|
| 1302 | if (!lstrcmpW(names[i+1],ppvObjectW)) {
|
|---|
| 1303 | hres = deserialize_LPVOID_ptr(
|
|---|
| 1304 | tpinfo->tinfo,
|
|---|
| 1305 | elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
|
|---|
| 1306 | relaydeb,
|
|---|
| 1307 | FALSE,
|
|---|
| 1308 | &elem->tdesc,
|
|---|
| 1309 | xargs,
|
|---|
| 1310 | &buf
|
|---|
| 1311 | );
|
|---|
| 1312 | if (hres == S_OK)
|
|---|
| 1313 | isdeserialized = TRUE;
|
|---|
| 1314 | }
|
|---|
| 1315 | }
|
|---|
| 1316 | if (!isdeserialized)
|
|---|
| 1317 | hres = deserialize_param(
|
|---|
| 1318 | tpinfo->tinfo,
|
|---|
| 1319 | elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
|
|---|
| 1320 | relaydeb,
|
|---|
| 1321 | FALSE,
|
|---|
| 1322 | &(elem->tdesc),
|
|---|
| 1323 | xargs,
|
|---|
| 1324 | &buf
|
|---|
| 1325 | );
|
|---|
| 1326 | if (hres) {
|
|---|
| 1327 | FIXME("Failed to unmarshall param, hres %lx\n",hres);
|
|---|
| 1328 | break;
|
|---|
| 1329 | }
|
|---|
| 1330 | xargs += _argsize(elem->tdesc.vt);
|
|---|
| 1331 | }
|
|---|
| 1332 | }
|
|---|
| 1333 | if (relaydeb) MESSAGE(")\n\n");
|
|---|
| 1334 | HeapFree(GetProcessHeap(),0,buf.base);
|
|---|
| 1335 | return status;
|
|---|
| 1336 | }
|
|---|
| 1337 |
|
|---|
| 1338 | static HRESULT WINAPI
|
|---|
| 1339 | PSFacBuf_CreateProxy(
|
|---|
| 1340 | LPPSFACTORYBUFFER iface, IUnknown* pUnkOuter, REFIID riid,
|
|---|
| 1341 | IRpcProxyBuffer **ppProxy, LPVOID *ppv
|
|---|
| 1342 | ) {
|
|---|
| 1343 | HRESULT hres;
|
|---|
| 1344 | ITypeInfo *tinfo;
|
|---|
| 1345 | int i, nroffuncs;
|
|---|
| 1346 | FUNCDESC *fdesc;
|
|---|
| 1347 | TMProxyImpl *proxy;
|
|---|
| 1348 |
|
|---|
| 1349 | TRACE("(...%s...)\n",debugstr_guid(riid));
|
|---|
| 1350 | hres = _get_typeinfo_for_iid(riid,&tinfo);
|
|---|
| 1351 | if (hres) {
|
|---|
| 1352 | FIXME("No typeinfo for %s?\n",debugstr_guid(riid));
|
|---|
| 1353 | return hres;
|
|---|
| 1354 | }
|
|---|
| 1355 | nroffuncs = _nroffuncs(tinfo);
|
|---|
| 1356 | proxy = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TMProxyImpl));
|
|---|
| 1357 | if (!proxy) return E_OUTOFMEMORY;
|
|---|
| 1358 | proxy->asmstubs=HeapAlloc(GetProcessHeap(),0,sizeof(TMAsmProxy)*nroffuncs);
|
|---|
| 1359 |
|
|---|
| 1360 | assert(sizeof(TMAsmProxy) == 12);
|
|---|
| 1361 |
|
|---|
| 1362 | proxy->lpvtbl = HeapAlloc(GetProcessHeap(),0,sizeof(LPBYTE)*nroffuncs);
|
|---|
| 1363 | for (i=0;i<nroffuncs;i++) {
|
|---|
| 1364 | int nrofargs;
|
|---|
| 1365 | TMAsmProxy *xasm = proxy->asmstubs+i;
|
|---|
| 1366 |
|
|---|
| 1367 | /* nrofargs without This */
|
|---|
| 1368 | switch (i) {
|
|---|
| 1369 | case 0: nrofargs = 2;
|
|---|
| 1370 | break;
|
|---|
| 1371 | case 1: case 2: nrofargs = 0;
|
|---|
| 1372 | break;
|
|---|
| 1373 | default: {
|
|---|
| 1374 | int j;
|
|---|
| 1375 | hres = _get_funcdesc(tinfo,i,&fdesc,NULL,NULL);
|
|---|
| 1376 | if (hres) {
|
|---|
| 1377 | FIXME("GetFuncDesc %lx should not fail here.\n",hres);
|
|---|
| 1378 | return hres;
|
|---|
| 1379 | }
|
|---|
| 1380 | /* some args take more than 4 byte on the stack */
|
|---|
| 1381 | nrofargs = 0;
|
|---|
| 1382 | for (j=0;j<fdesc->cParams;j++)
|
|---|
| 1383 | nrofargs += _argsize(fdesc->lprgelemdescParam[j].tdesc.vt);
|
|---|
| 1384 |
|
|---|
| 1385 | if (fdesc->callconv != CC_STDCALL) {
|
|---|
| 1386 | ERR("calling convention is not stdcall????\n");
|
|---|
| 1387 | return E_FAIL;
|
|---|
| 1388 | }
|
|---|
| 1389 | break;
|
|---|
| 1390 | }
|
|---|
| 1391 | }
|
|---|
| 1392 | /* popl %eax - return ptr
|
|---|
| 1393 | * pushl <nr>
|
|---|
| 1394 | * pushl %eax
|
|---|
| 1395 | * call xCall
|
|---|
| 1396 | * lret <nr> (+4)
|
|---|
| 1397 | *
|
|---|
| 1398 | *
|
|---|
| 1399 | * arg3 arg2 arg1 <method> <returnptr>
|
|---|
| 1400 | */
|
|---|
| 1401 | xasm->popleax = 0x58;
|
|---|
| 1402 | xasm->pushlval = 0x6a;
|
|---|
| 1403 | xasm->nr = i;
|
|---|
| 1404 | xasm->pushleax = 0x50;
|
|---|
| 1405 | xasm->lcall = 0xe8; /* relative jump */
|
|---|
| 1406 | xasm->xcall = (DWORD)xCall;
|
|---|
| 1407 | xasm->xcall -= (DWORD)&(xasm->lret);
|
|---|
| 1408 | xasm->lret = 0xc2;
|
|---|
| 1409 | xasm->bytestopop= (nrofargs+2)*4; /* pop args, This, iMethod */
|
|---|
| 1410 | proxy->lpvtbl[i] = (DWORD)xasm;
|
|---|
| 1411 | }
|
|---|
| 1412 | proxy->lpvtbl2 = &tmproxyvtable;
|
|---|
| 1413 | proxy->ref = 2;
|
|---|
| 1414 | proxy->tinfo = tinfo;
|
|---|
| 1415 | memcpy(&proxy->iid,riid,sizeof(*riid));
|
|---|
| 1416 | *ppv = (LPVOID)proxy;
|
|---|
| 1417 | *ppProxy = (IRpcProxyBuffer *)&(proxy->lpvtbl2);
|
|---|
| 1418 | return S_OK;
|
|---|
| 1419 | }
|
|---|
| 1420 |
|
|---|
| 1421 | typedef struct _TMStubImpl {
|
|---|
| 1422 | ICOM_VTABLE(IRpcStubBuffer) *lpvtbl;
|
|---|
| 1423 | DWORD ref;
|
|---|
| 1424 |
|
|---|
| 1425 | LPUNKNOWN pUnk;
|
|---|
| 1426 | ITypeInfo *tinfo;
|
|---|
| 1427 | IID iid;
|
|---|
| 1428 | } TMStubImpl;
|
|---|
| 1429 |
|
|---|
| 1430 | static HRESULT WINAPI
|
|---|
| 1431 | TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface, REFIID riid, LPVOID *ppv) {
|
|---|
| 1432 | if (IsEqualIID(riid,&IID_IRpcStubBuffer)||IsEqualIID(riid,&IID_IUnknown)){
|
|---|
| 1433 | *ppv = (LPVOID)iface;
|
|---|
| 1434 | IRpcStubBuffer_AddRef(iface);
|
|---|
| 1435 | return S_OK;
|
|---|
| 1436 | }
|
|---|
| 1437 | FIXME("%s, not supported IID.\n",debugstr_guid(riid));
|
|---|
| 1438 | return E_NOINTERFACE;
|
|---|
| 1439 | }
|
|---|
| 1440 |
|
|---|
| 1441 | static ULONG WINAPI
|
|---|
| 1442 | TMStubImpl_AddRef(LPRPCSTUBBUFFER iface) {
|
|---|
| 1443 | ICOM_THIS(TMStubImpl,iface);
|
|---|
| 1444 |
|
|---|
| 1445 | This->ref++;
|
|---|
| 1446 | return This->ref;
|
|---|
| 1447 | }
|
|---|
| 1448 |
|
|---|
| 1449 | static ULONG WINAPI
|
|---|
| 1450 | TMStubImpl_Release(LPRPCSTUBBUFFER iface) {
|
|---|
| 1451 | ICOM_THIS(TMStubImpl,iface);
|
|---|
| 1452 |
|
|---|
| 1453 | This->ref--;
|
|---|
| 1454 | if (This->ref)
|
|---|
| 1455 | return This->ref;
|
|---|
| 1456 | HeapFree(GetProcessHeap(),0,This);
|
|---|
| 1457 | return 0;
|
|---|
| 1458 | }
|
|---|
| 1459 |
|
|---|
| 1460 | static HRESULT WINAPI
|
|---|
| 1461 | TMStubImpl_Connect(LPRPCSTUBBUFFER iface, LPUNKNOWN pUnkServer) {
|
|---|
| 1462 | ICOM_THIS(TMStubImpl,iface);
|
|---|
| 1463 |
|
|---|
| 1464 | IUnknown_AddRef(pUnkServer);
|
|---|
| 1465 | This->pUnk = pUnkServer;
|
|---|
| 1466 | return S_OK;
|
|---|
| 1467 | }
|
|---|
| 1468 |
|
|---|
| 1469 | static void WINAPI
|
|---|
| 1470 | TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface) {
|
|---|
| 1471 | ICOM_THIS(TMStubImpl,iface);
|
|---|
| 1472 |
|
|---|
| 1473 | IUnknown_Release(This->pUnk);
|
|---|
| 1474 | This->pUnk = NULL;
|
|---|
| 1475 | return;
|
|---|
| 1476 | }
|
|---|
| 1477 |
|
|---|
| 1478 | static HRESULT WINAPI
|
|---|
| 1479 | TMStubImpl_Invoke(
|
|---|
| 1480 | LPRPCSTUBBUFFER iface, RPCOLEMESSAGE* xmsg,IRpcChannelBuffer*rpcchanbuf
|
|---|
| 1481 | ) {
|
|---|
| 1482 | int i;
|
|---|
| 1483 | FUNCDESC *fdesc;
|
|---|
| 1484 | ICOM_THIS(TMStubImpl,iface);
|
|---|
| 1485 | HRESULT hres;
|
|---|
| 1486 | DWORD *args, res, *xargs, nrofargs;
|
|---|
| 1487 | marshal_state buf;
|
|---|
| 1488 | int nrofnames;
|
|---|
| 1489 | BSTR names[10];
|
|---|
| 1490 |
|
|---|
| 1491 | memset(&buf,0,sizeof(buf));
|
|---|
| 1492 | buf.size = xmsg->cbBuffer;
|
|---|
| 1493 | buf.base = xmsg->Buffer;
|
|---|
| 1494 | buf.curoff = 0;
|
|---|
| 1495 | buf.iid = IID_IUnknown;
|
|---|
| 1496 |
|
|---|
| 1497 | TRACE("...\n");
|
|---|
| 1498 | if (xmsg->iMethod == 0) { /* QI */
|
|---|
| 1499 | IID xiid;
|
|---|
| 1500 | /* in: IID, out: <iface> */
|
|---|
| 1501 |
|
|---|
| 1502 | xbuf_get(&buf,(LPBYTE)&xiid,sizeof(xiid));
|
|---|
| 1503 | buf.curoff = 0;
|
|---|
| 1504 | hres = _marshal_interface(&buf,&xiid,This->pUnk);
|
|---|
| 1505 | xmsg->Buffer = buf.base; /* Might have been reallocated */
|
|---|
| 1506 | xmsg->cbBuffer = buf.size;
|
|---|
| 1507 | return hres;
|
|---|
| 1508 | }
|
|---|
| 1509 | hres = _get_funcdesc(This->tinfo,xmsg->iMethod,&fdesc,NULL,NULL);
|
|---|
| 1510 | if (hres) {
|
|---|
| 1511 | FIXME("GetFuncDesc on method %ld failed with %lx\n",xmsg->iMethod,hres);
|
|---|
| 1512 | return hres;
|
|---|
| 1513 | }
|
|---|
| 1514 | /* Need them for hack below */
|
|---|
| 1515 | memset(names,0,sizeof(names));
|
|---|
| 1516 | ITypeInfo_GetNames(This->tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
|
|---|
| 1517 | if (nrofnames > sizeof(names)/sizeof(names[0])) {
|
|---|
| 1518 | ERR("Need more names!\n");
|
|---|
| 1519 | }
|
|---|
| 1520 |
|
|---|
| 1521 | /*dump_FUNCDESC(fdesc);*/
|
|---|
| 1522 | nrofargs = 0;
|
|---|
| 1523 | for (i=0;i<fdesc->cParams;i++)
|
|---|
| 1524 | nrofargs += _argsize(fdesc->lprgelemdescParam[i].tdesc.vt);
|
|---|
| 1525 | args = HeapAlloc(GetProcessHeap(),0,(nrofargs+1)*sizeof(DWORD));
|
|---|
| 1526 | if (!args) return E_OUTOFMEMORY;
|
|---|
| 1527 |
|
|---|
| 1528 | /* Allocate all stuff used by call. */
|
|---|
| 1529 | xargs = args+1;
|
|---|
| 1530 | for (i=0;i<fdesc->cParams;i++) {
|
|---|
| 1531 | ELEMDESC *elem = fdesc->lprgelemdescParam+i;
|
|---|
| 1532 | BOOL isdeserialized = FALSE;
|
|---|
| 1533 |
|
|---|
| 1534 | if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
|
|---|
| 1535 | /* If the parameter is 'riid', we use it as interface IID
|
|---|
| 1536 | * for a later ppvObject serialization.
|
|---|
| 1537 | */
|
|---|
| 1538 | buf.thisisiid = !lstrcmpW(names[i+1],riidW);
|
|---|
| 1539 |
|
|---|
| 1540 | /* deserialize DISPPARAM */
|
|---|
| 1541 | if (!lstrcmpW(names[i+1],pdispparamsW)) {
|
|---|
| 1542 | hres = deserialize_DISPPARAM_ptr(
|
|---|
| 1543 | This->tinfo,
|
|---|
| 1544 | elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
|
|---|
| 1545 | FALSE,
|
|---|
| 1546 | TRUE,
|
|---|
| 1547 | &(elem->tdesc),
|
|---|
| 1548 | xargs,
|
|---|
| 1549 | &buf
|
|---|
| 1550 | );
|
|---|
| 1551 | if (hres) {
|
|---|
| 1552 | FIXME("Failed to deserialize DISPPARAM*, hres %lx\n",hres);
|
|---|
| 1553 | break;
|
|---|
| 1554 | }
|
|---|
| 1555 | isdeserialized = TRUE;
|
|---|
| 1556 | }
|
|---|
| 1557 | if (!lstrcmpW(names[i+1],ppvObjectW)) {
|
|---|
| 1558 | hres = deserialize_LPVOID_ptr(
|
|---|
| 1559 | This->tinfo,
|
|---|
| 1560 | elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
|
|---|
| 1561 | FALSE,
|
|---|
| 1562 | TRUE,
|
|---|
| 1563 | &elem->tdesc,
|
|---|
| 1564 | xargs,
|
|---|
| 1565 | &buf
|
|---|
| 1566 | );
|
|---|
| 1567 | if (hres == S_OK)
|
|---|
| 1568 | isdeserialized = TRUE;
|
|---|
| 1569 | }
|
|---|
| 1570 | }
|
|---|
| 1571 | if (!isdeserialized)
|
|---|
| 1572 | hres = deserialize_param(
|
|---|
| 1573 | This->tinfo,
|
|---|
| 1574 | elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
|
|---|
| 1575 | FALSE,
|
|---|
| 1576 | TRUE,
|
|---|
| 1577 | &(elem->tdesc),
|
|---|
| 1578 | xargs,
|
|---|
| 1579 | &buf
|
|---|
| 1580 | );
|
|---|
| 1581 | xargs += _argsize(elem->tdesc.vt);
|
|---|
| 1582 | if (hres) {
|
|---|
| 1583 | FIXME("Failed to deserialize param %s, hres %lx\n",debugstr_w(names[i+1]),hres);
|
|---|
| 1584 | break;
|
|---|
| 1585 | }
|
|---|
| 1586 | }
|
|---|
| 1587 | hres = IUnknown_QueryInterface(This->pUnk,&(This->iid),(LPVOID*)&(args[0]));
|
|---|
| 1588 | if (hres) {
|
|---|
| 1589 | ERR("Does not support iface %s\n",debugstr_guid(&(This->iid)));
|
|---|
| 1590 | return hres;
|
|---|
| 1591 | }
|
|---|
| 1592 | res = _invoke(
|
|---|
| 1593 | (*((LPVOID**)args[0]))[fdesc->oVft/4],
|
|---|
| 1594 | fdesc->callconv,
|
|---|
| 1595 | (xargs-args),
|
|---|
| 1596 | args
|
|---|
| 1597 | );
|
|---|
| 1598 | IUnknown_Release((LPUNKNOWN)args[0]);
|
|---|
| 1599 | buf.curoff = 0;
|
|---|
| 1600 | xargs = args+1;
|
|---|
| 1601 | for (i=0;i<fdesc->cParams;i++) {
|
|---|
| 1602 | ELEMDESC *elem = fdesc->lprgelemdescParam+i;
|
|---|
| 1603 | BOOL isserialized = FALSE;
|
|---|
| 1604 |
|
|---|
| 1605 | if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
|
|---|
| 1606 | /* If the parameter is 'riid', we use it as interface IID
|
|---|
| 1607 | * for a later ppvObject serialization.
|
|---|
| 1608 | */
|
|---|
| 1609 | buf.thisisiid = !lstrcmpW(names[i+1],riidW);
|
|---|
| 1610 |
|
|---|
| 1611 | /* DISPPARAMS* needs special serializer */
|
|---|
| 1612 | if (!lstrcmpW(names[i+1],pdispparamsW)) {
|
|---|
| 1613 | hres = serialize_DISPPARAM_ptr(
|
|---|
| 1614 | This->tinfo,
|
|---|
| 1615 | elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
|
|---|
| 1616 | FALSE,
|
|---|
| 1617 | TRUE,
|
|---|
| 1618 | &elem->tdesc,
|
|---|
| 1619 | xargs,
|
|---|
| 1620 | &buf
|
|---|
| 1621 | );
|
|---|
| 1622 | isserialized = TRUE;
|
|---|
| 1623 | }
|
|---|
| 1624 | if (!lstrcmpW(names[i+1],ppvObjectW)) {
|
|---|
| 1625 | hres = serialize_LPVOID_ptr(
|
|---|
| 1626 | This->tinfo,
|
|---|
| 1627 | elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
|
|---|
| 1628 | FALSE,
|
|---|
| 1629 | TRUE,
|
|---|
| 1630 | &elem->tdesc,
|
|---|
| 1631 | xargs,
|
|---|
| 1632 | &buf
|
|---|
| 1633 | );
|
|---|
| 1634 | if (hres == S_OK)
|
|---|
| 1635 | isserialized = TRUE;
|
|---|
| 1636 | }
|
|---|
| 1637 | }
|
|---|
| 1638 | if (!isserialized)
|
|---|
| 1639 | hres = serialize_param(
|
|---|
| 1640 | This->tinfo,
|
|---|
| 1641 | elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
|
|---|
| 1642 | FALSE,
|
|---|
| 1643 | TRUE,
|
|---|
| 1644 | &elem->tdesc,
|
|---|
| 1645 | xargs,
|
|---|
| 1646 | &buf
|
|---|
| 1647 | );
|
|---|
| 1648 | xargs += _argsize(elem->tdesc.vt);
|
|---|
| 1649 | if (hres) {
|
|---|
| 1650 | FIXME("Failed to stuballoc param, hres %lx\n",hres);
|
|---|
| 1651 | break;
|
|---|
| 1652 | }
|
|---|
| 1653 | }
|
|---|
| 1654 | /* might need to use IRpcChannelBuffer_GetBuffer ? */
|
|---|
| 1655 | xmsg->cbBuffer = buf.curoff;
|
|---|
| 1656 | xmsg->Buffer = buf.base;
|
|---|
| 1657 | HeapFree(GetProcessHeap(),0,args);
|
|---|
| 1658 | return res;
|
|---|
| 1659 | }
|
|---|
| 1660 |
|
|---|
| 1661 | static LPRPCSTUBBUFFER WINAPI
|
|---|
| 1662 | TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface, REFIID riid) {
|
|---|
| 1663 | FIXME("Huh (%s)?\n",debugstr_guid(riid));
|
|---|
| 1664 | return NULL;
|
|---|
| 1665 | }
|
|---|
| 1666 |
|
|---|
| 1667 | static ULONG WINAPI
|
|---|
| 1668 | TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface) {
|
|---|
| 1669 | ICOM_THIS(TMStubImpl,iface);
|
|---|
| 1670 |
|
|---|
| 1671 | return This->ref; /*FIXME? */
|
|---|
| 1672 | }
|
|---|
| 1673 |
|
|---|
| 1674 | static HRESULT WINAPI
|
|---|
| 1675 | TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface, LPVOID *ppv) {
|
|---|
| 1676 | return E_NOTIMPL;
|
|---|
| 1677 | }
|
|---|
| 1678 |
|
|---|
| 1679 | static void WINAPI
|
|---|
| 1680 | TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface, LPVOID ppv) {
|
|---|
| 1681 | return;
|
|---|
| 1682 | }
|
|---|
| 1683 |
|
|---|
| 1684 | ICOM_VTABLE(IRpcStubBuffer) tmstubvtbl = {
|
|---|
| 1685 | ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
|---|
| 1686 | TMStubImpl_QueryInterface,
|
|---|
| 1687 | TMStubImpl_AddRef,
|
|---|
| 1688 | TMStubImpl_Release,
|
|---|
| 1689 | TMStubImpl_Connect,
|
|---|
| 1690 | TMStubImpl_Disconnect,
|
|---|
| 1691 | TMStubImpl_Invoke,
|
|---|
| 1692 | TMStubImpl_IsIIDSupported,
|
|---|
| 1693 | TMStubImpl_CountRefs,
|
|---|
| 1694 | TMStubImpl_DebugServerQueryInterface,
|
|---|
| 1695 | TMStubImpl_DebugServerRelease
|
|---|
| 1696 | };
|
|---|
| 1697 |
|
|---|
| 1698 | static HRESULT WINAPI
|
|---|
| 1699 | PSFacBuf_CreateStub(
|
|---|
| 1700 | LPPSFACTORYBUFFER iface, REFIID riid,IUnknown *pUnkServer,
|
|---|
| 1701 | IRpcStubBuffer** ppStub
|
|---|
| 1702 | ) {
|
|---|
| 1703 | HRESULT hres;
|
|---|
| 1704 | ITypeInfo *tinfo;
|
|---|
| 1705 | TMStubImpl *stub;
|
|---|
| 1706 |
|
|---|
| 1707 | TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub);
|
|---|
| 1708 | hres = _get_typeinfo_for_iid(riid,&tinfo);
|
|---|
| 1709 | if (hres) {
|
|---|
| 1710 | FIXME("No typeinfo for %s?\n",debugstr_guid(riid));
|
|---|
| 1711 | return hres;
|
|---|
| 1712 | }
|
|---|
| 1713 | stub = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TMStubImpl));
|
|---|
| 1714 | if (!stub)
|
|---|
| 1715 | return E_OUTOFMEMORY;
|
|---|
| 1716 | stub->lpvtbl = &tmstubvtbl;
|
|---|
| 1717 | stub->ref = 1;
|
|---|
| 1718 | stub->tinfo = tinfo;
|
|---|
| 1719 | memcpy(&(stub->iid),riid,sizeof(*riid));
|
|---|
| 1720 | hres = IRpcStubBuffer_Connect((LPRPCSTUBBUFFER)stub,pUnkServer);
|
|---|
| 1721 | *ppStub = (LPRPCSTUBBUFFER)stub;
|
|---|
| 1722 | if (hres)
|
|---|
| 1723 | FIXME("Connect to pUnkServer failed?\n");
|
|---|
| 1724 | return hres;
|
|---|
| 1725 | }
|
|---|
| 1726 |
|
|---|
| 1727 | static ICOM_VTABLE(IPSFactoryBuffer) psfacbufvtbl = {
|
|---|
| 1728 | ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
|---|
| 1729 | PSFacBuf_QueryInterface,
|
|---|
| 1730 | PSFacBuf_AddRef,
|
|---|
| 1731 | PSFacBuf_Release,
|
|---|
| 1732 | PSFacBuf_CreateProxy,
|
|---|
| 1733 | PSFacBuf_CreateStub
|
|---|
| 1734 | };
|
|---|
| 1735 |
|
|---|
| 1736 | /* This is the whole PSFactoryBuffer object, just the vtableptr */
|
|---|
| 1737 | static ICOM_VTABLE(IPSFactoryBuffer) *lppsfac = &psfacbufvtbl;
|
|---|
| 1738 |
|
|---|
| 1739 | /***********************************************************************
|
|---|
| 1740 | * DllGetClassObject [OLE32.63]
|
|---|
| 1741 | */
|
|---|
| 1742 | HRESULT WINAPI
|
|---|
| 1743 | TypeLibFac_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
|
|---|
| 1744 | {
|
|---|
| 1745 | if (IsEqualIID(iid,&IID_IPSFactoryBuffer)) {
|
|---|
| 1746 | *ppv = &lppsfac;
|
|---|
| 1747 | return S_OK;
|
|---|
| 1748 | }
|
|---|
| 1749 | return E_NOINTERFACE;
|
|---|
| 1750 | }
|
|---|