| 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 |
|
|---|
| 47 | WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
|---|
| 48 | WINE_DECLARE_DEBUG_CHANNEL(olerelay);
|
|---|
| 49 |
|
|---|
| 50 | typedef struct _marshal_state {
|
|---|
| 51 | LPBYTE base;
|
|---|
| 52 | int size;
|
|---|
| 53 | int curoff;
|
|---|
| 54 |
|
|---|
| 55 | BOOL thisisiid;
|
|---|
| 56 | IID iid; /* HACK: for VT_VOID */
|
|---|
| 57 | } marshal_state;
|
|---|
| 58 |
|
|---|
| 59 | static HRESULT
|
|---|
| 60 | xbuf_add(marshal_state *buf, LPBYTE stuff, DWORD size) {
|
|---|
| 61 | while (buf->size - buf->curoff < size) {
|
|---|
| 62 | if (buf->base) {
|
|---|
| 63 | buf->size += 100;
|
|---|
| 64 | buf->base = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,buf->base,buf->size);
|
|---|
| 65 | if (!buf->base)
|
|---|
| 66 | return E_OUTOFMEMORY;
|
|---|
| 67 | } else {
|
|---|
| 68 | buf->base = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,32);
|
|---|
| 69 | buf->size = 32;
|
|---|
| 70 | if (!buf->base)
|
|---|
| 71 | return E_OUTOFMEMORY;
|
|---|
| 72 | }
|
|---|
| 73 | }
|
|---|
| 74 | memcpy(buf->base+buf->curoff,stuff,size);
|
|---|
| 75 | buf->curoff += size;
|
|---|
| 76 | return S_OK;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | static HRESULT
|
|---|
| 80 | xbuf_get(marshal_state *buf, LPBYTE stuff, DWORD size) {
|
|---|
| 81 | if (buf->size < buf->curoff+size) return E_FAIL;
|
|---|
| 82 | memcpy(stuff,buf->base+buf->curoff,size);
|
|---|
| 83 | buf->curoff += size;
|
|---|
| 84 | return S_OK;
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | static HRESULT
|
|---|
| 88 | xbuf_skip(marshal_state *buf, DWORD size) {
|
|---|
| 89 | if (buf->size < buf->curoff+size) return E_FAIL;
|
|---|
| 90 | buf->curoff += size;
|
|---|
| 91 | return S_OK;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | static HRESULT
|
|---|
| 95 | _unmarshal_interface(marshal_state *buf, REFIID riid, LPUNKNOWN *pUnk) {
|
|---|
| 96 | IStream *pStm;
|
|---|
| 97 | ULARGE_INTEGER newpos;
|
|---|
| 98 | LARGE_INTEGER seekto;
|
|---|
| 99 | ULONG res;
|
|---|
| 100 | HRESULT hres;
|
|---|
| 101 | DWORD xsize;
|
|---|
| 102 |
|
|---|
| 103 | TRACE("...%s...\n",debugstr_guid(riid));
|
|---|
| 104 | *pUnk = NULL;
|
|---|
| 105 | hres = xbuf_get(buf,(LPBYTE)&xsize,sizeof(xsize));
|
|---|
| 106 | if (hres) return hres;
|
|---|
| 107 | if (xsize == 0) return S_OK;
|
|---|
| 108 | hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
|
|---|
| 109 | if (hres) {
|
|---|
| 110 | FIXME("Stream create failed %lx\n",hres);
|
|---|
| 111 | return hres;
|
|---|
| 112 | }
|
|---|
| 113 | hres = IStream_Write(pStm,buf->base+buf->curoff,xsize,&res);
|
|---|
| 114 | if (hres) { FIXME("stream write %lx\n",hres); return hres; }
|
|---|
| 115 | memset(&seekto,0,sizeof(seekto));
|
|---|
| 116 | hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
|
|---|
| 117 | if (hres) { FIXME("Failed Seek %lx\n",hres); return hres;}
|
|---|
| 118 | hres = CoUnmarshalInterface(pStm,riid,(LPVOID*)pUnk);
|
|---|
| 119 | if (hres) {
|
|---|
| 120 | FIXME("Marshaling interface %s failed with %lx\n",debugstr_guid(riid),hres);
|
|---|
| 121 | return hres;
|
|---|
| 122 | }
|
|---|
| 123 | IStream_Release(pStm);
|
|---|
| 124 | return xbuf_skip(buf,xsize);
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | static HRESULT
|
|---|
| 128 | _marshal_interface(marshal_state *buf, REFIID riid, LPUNKNOWN pUnk) {
|
|---|
| 129 | LPUNKNOWN newiface;
|
|---|
| 130 | LPBYTE tempbuf;
|
|---|
| 131 | IStream *pStm;
|
|---|
| 132 | STATSTG ststg;
|
|---|
| 133 | ULARGE_INTEGER newpos;
|
|---|
| 134 | LARGE_INTEGER seekto;
|
|---|
| 135 | ULONG res;
|
|---|
| 136 | DWORD xsize;
|
|---|
| 137 | HRESULT hres;
|
|---|
| 138 |
|
|---|
| 139 | hres = S_OK;
|
|---|
| 140 | if (!pUnk)
|
|---|
| 141 | goto fail;
|
|---|
| 142 |
|
|---|
| 143 | TRACE("...%s...\n",debugstr_guid(riid));
|
|---|
| 144 | hres=IUnknown_QueryInterface(pUnk,riid,(LPVOID*)&newiface);
|
|---|
| 145 | if (hres) {
|
|---|
| 146 | TRACE("%p does not support iface %s\n",pUnk,debugstr_guid(riid));
|
|---|
| 147 | goto fail;
|
|---|
| 148 | }
|
|---|
| 149 | hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
|
|---|
| 150 | if (hres) {
|
|---|
| 151 | FIXME("Stream create failed %lx\n",hres);
|
|---|
| 152 | goto fail;
|
|---|
| 153 | }
|
|---|
| 154 | hres = CoMarshalInterface(pStm,riid,newiface,0,NULL,0);
|
|---|
| 155 | IUnknown_Release(newiface);
|
|---|
| 156 | if (hres) {
|
|---|
| 157 | FIXME("Marshaling interface %s failed with %lx\n",
|
|---|
| 158 | debugstr_guid(riid),hres
|
|---|
| 159 | );
|
|---|
| 160 | goto fail;
|
|---|
| 161 | }
|
|---|
| 162 | hres = IStream_Stat(pStm,&ststg,0);
|
|---|
| 163 | tempbuf = HeapAlloc(GetProcessHeap(), 0, ststg.cbSize.s.LowPart);
|
|---|
| 164 | memset(&seekto,0,sizeof(seekto));
|
|---|
| 165 | hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
|
|---|
| 166 | if (hres) { FIXME("Failed Seek %lx\n",hres); goto fail;}
|
|---|
| 167 | hres = IStream_Read(pStm,tempbuf,ststg.cbSize.s.LowPart,&res);
|
|---|
| 168 | if (hres) { FIXME("Failed Read %lx\n",hres); goto fail;}
|
|---|
| 169 | IStream_Release(pStm);
|
|---|
| 170 | xsize = ststg.cbSize.s.LowPart;
|
|---|
| 171 | xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
|
|---|
| 172 | hres = xbuf_add(buf,tempbuf,ststg.cbSize.s.LowPart);
|
|---|
| 173 | HeapFree(GetProcessHeap(),0,tempbuf);
|
|---|
| 174 | return hres;
|
|---|
| 175 | fail:
|
|---|
| 176 | xsize = 0;
|
|---|
| 177 | xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
|
|---|
| 178 | return hres;
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | /********************* OLE Proxy/Stub Factory ********************************/
|
|---|
| 182 | static HRESULT WINAPI
|
|---|
| 183 | PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface, REFIID iid, LPVOID *ppv) {
|
|---|
| 184 | if (IsEqualIID(iid,&IID_IPSFactoryBuffer)||IsEqualIID(iid,&IID_IUnknown)) {
|
|---|
| 185 | *ppv = (LPVOID)iface;
|
|---|
| 186 | /* No ref counting, static class */
|
|---|
| 187 | return S_OK;
|
|---|
| 188 | }
|
|---|
| 189 | FIXME("(%s) unknown IID?\n",debugstr_guid(iid));
|
|---|
| 190 | return E_NOINTERFACE;
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | static ULONG WINAPI PSFacBuf_AddRef(LPPSFACTORYBUFFER iface) { return 2; }
|
|---|
| 194 | static ULONG WINAPI PSFacBuf_Release(LPPSFACTORYBUFFER iface) { return 1; }
|
|---|
| 195 |
|
|---|
| 196 | static HRESULT
|
|---|
| 197 | _get_typeinfo_for_iid(REFIID riid, ITypeInfo**ti) {
|
|---|
| 198 | HRESULT hres;
|
|---|
| 199 | HKEY ikey;
|
|---|
| 200 | char tlguid[200],typelibkey[300],interfacekey[300],ver[100];
|
|---|
| 201 | char tlfn[260];
|
|---|
| 202 | OLECHAR tlfnW[260];
|
|---|
| 203 | DWORD tlguidlen, verlen, type, tlfnlen;
|
|---|
| 204 | ITypeLib *tl;
|
|---|
| 205 |
|
|---|
| 206 | sprintf( interfacekey, "Interface\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\Typelib",
|
|---|
| 207 | riid->Data1, riid->Data2, riid->Data3,
|
|---|
| 208 | riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
|
|---|
| 209 | riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7]
|
|---|
| 210 | );
|
|---|
| 211 |
|
|---|
| 212 | if (RegOpenKeyA(HKEY_CLASSES_ROOT,interfacekey,&ikey)) {
|
|---|
| 213 | FIXME("No %s key found.\n",interfacekey);
|
|---|
| 214 | return E_FAIL;
|
|---|
| 215 | }
|
|---|
| 216 | type = (1<<REG_SZ);
|
|---|
| 217 | tlguidlen = sizeof(tlguid);
|
|---|
| 218 | if (RegQueryValueExA(ikey,NULL,NULL,&type,tlguid,&tlguidlen)) {
|
|---|
| 219 | FIXME("Getting typelib guid failed.\n");
|
|---|
| 220 | RegCloseKey(ikey);
|
|---|
| 221 | return E_FAIL;
|
|---|
| 222 | }
|
|---|
| 223 | type = (1<<REG_SZ);
|
|---|
| 224 | verlen = sizeof(ver);
|
|---|
| 225 | if (RegQueryValueExA(ikey,"Version",NULL,&type,ver,&verlen)) {
|
|---|
| 226 | FIXME("Could not get version value?\n");
|
|---|
| 227 | RegCloseKey(ikey);
|
|---|
| 228 | return E_FAIL;
|
|---|
| 229 | }
|
|---|
| 230 | RegCloseKey(ikey);
|
|---|
| 231 | sprintf(typelibkey,"Typelib\\%s\\%s\\0\\win32",tlguid,ver);
|
|---|
| 232 | tlfnlen = sizeof(tlfn);
|
|---|
| 233 | if (RegQueryValueA(HKEY_CLASSES_ROOT,typelibkey,tlfn,&tlfnlen)) {
|
|---|
| 234 | FIXME("Could not get typelib fn?\n");
|
|---|
| 235 | return E_FAIL;
|
|---|
| 236 | }
|
|---|
| 237 | MultiByteToWideChar(CP_ACP, 0, tlfn, -1, tlfnW, -1);
|
|---|
| 238 | hres = LoadTypeLib(tlfnW,&tl);
|
|---|
| 239 | if (hres) {
|
|---|
| 240 | ERR("Failed to load typelib for %s, but it should be there.\n",debugstr_guid(riid));
|
|---|
| 241 | return hres;
|
|---|
| 242 | }
|
|---|
| 243 | hres = ITypeLib_GetTypeInfoOfGuid(tl,riid,ti);
|
|---|
| 244 | if (hres) {
|
|---|
| 245 | ERR("typelib does not contain info for %s?\n",debugstr_guid(riid));
|
|---|
| 246 | ITypeLib_Release(tl);
|
|---|
| 247 | return hres;
|
|---|
| 248 | }
|
|---|
| 249 | /* FIXME: do this? ITypeLib_Release(tl); */
|
|---|
| 250 | return hres;
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | /* Determine nr of functions. Since we use the toplevel interface and all
|
|---|
| 254 | * inherited ones have lower numbers, we are ok to not to descent into
|
|---|
| 255 | * the inheritance tree I think.
|
|---|
| 256 | */
|
|---|
| 257 | static int _nroffuncs(ITypeInfo *tinfo) {
|
|---|
| 258 | int n, max = 0;
|
|---|
| 259 | FUNCDESC *fdesc;
|
|---|
| 260 | HRESULT hres;
|
|---|
| 261 |
|
|---|
| 262 | n=0;
|
|---|
| 263 | while (1) {
|
|---|
| 264 | hres = ITypeInfo_GetFuncDesc(tinfo,n,&fdesc);
|
|---|
| 265 | if (fdesc->oVft/4 > max)
|
|---|
| 266 | max = fdesc->oVft/4;
|
|---|
| 267 | if (hres)
|
|---|
| 268 | return max+1;
|
|---|
| 269 | n++;
|
|---|
| 270 | }
|
|---|
| 271 | /*NOTREACHED*/
|
|---|
| 272 | }
|
|---|
| 273 |
|
|---|
| 274 | #ifdef __WIN32OS2__
|
|---|
| 275 | #include <pshpack1.h>
|
|---|
| 276 | #endif
|
|---|
| 277 |
|
|---|
| 278 | typedef struct _TMAsmProxy {
|
|---|
| 279 | BYTE popleax;
|
|---|
| 280 | BYTE pushlval;
|
|---|
| 281 | BYTE nr;
|
|---|
| 282 | BYTE pushleax;
|
|---|
| 283 | BYTE lcall;
|
|---|
| 284 | DWORD xcall;
|
|---|
| 285 | BYTE lret;
|
|---|
| 286 | WORD bytestopop;
|
|---|
| 287 | } WINE_PACKED TMAsmProxy;
|
|---|
| 288 |
|
|---|
| 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 | static HRESULT
|
|---|
| 369 | marshall_param(
|
|---|
| 370 | ITypeInfo *tinfo, ELEMDESC *elem, TYPEDESC *tdesc, DWORD *arg, marshal_state *buf
|
|---|
| 371 | ) {
|
|---|
| 372 | int relaydeb = TRACE_ON(olerelay);
|
|---|
| 373 | HRESULT hres;
|
|---|
| 374 |
|
|---|
| 375 | if (!tdesc) tdesc = &(elem->tdesc);
|
|---|
| 376 | switch (tdesc->vt) {
|
|---|
| 377 | case VT_NULL:
|
|---|
| 378 | return S_OK;
|
|---|
| 379 | case VT_BSTR: { /* DWORD size, string data */
|
|---|
| 380 |
|
|---|
| 381 | if (*arg) {
|
|---|
| 382 | DWORD *bstr = ((DWORD*)(*arg))-1;
|
|---|
| 383 |
|
|---|
| 384 | if (relaydeb) MESSAGE("%s",debugstr_w((LPWSTR)(bstr+1)));
|
|---|
| 385 | return xbuf_add(buf,(LPBYTE)bstr,bstr[0]+4);
|
|---|
| 386 | } else {
|
|---|
| 387 | DWORD xnull = 0;
|
|---|
| 388 |
|
|---|
| 389 | return xbuf_add(buf,(LPBYTE)&xnull,sizeof(xnull));
|
|---|
| 390 | }
|
|---|
| 391 | }
|
|---|
| 392 | case VT_BOOL:
|
|---|
| 393 | case VT_I4:
|
|---|
| 394 | if (relaydeb) MESSAGE("%ld",*arg);
|
|---|
| 395 | return xbuf_add(buf,(LPBYTE)arg,4);
|
|---|
| 396 | case VT_VARIANT: {
|
|---|
| 397 | /* We use ourselves to marshal the value further */
|
|---|
| 398 | TYPEDESC tdesc2;
|
|---|
| 399 | VARIANT *vt = (VARIANT*)arg;
|
|---|
| 400 | DWORD vttype = V_VT(vt);
|
|---|
| 401 |
|
|---|
| 402 | hres = xbuf_add(buf,(LPBYTE)&vttype,sizeof(vttype));
|
|---|
| 403 | if (hres) return hres;
|
|---|
| 404 | tdesc2.vt = vttype;
|
|---|
| 405 | if (relaydeb) MESSAGE("Vt %ld ",vttype);
|
|---|
| 406 | /* shield your eyes, bad pointer voodoo below */
|
|---|
| 407 | return marshall_param(tinfo,elem,&tdesc2,(DWORD*)&(V_I4(vt)),buf);
|
|---|
| 408 | }
|
|---|
| 409 | case VT_PTR:
|
|---|
| 410 | return marshall_param(tinfo,elem,tdesc->u.lptdesc,(DWORD*)*arg,buf);
|
|---|
| 411 | case VT_VOID:
|
|---|
| 412 | hres = _marshal_interface(buf,&(buf->iid),(LPUNKNOWN)arg);
|
|---|
| 413 | if (hres) {
|
|---|
| 414 | FIXME("Failed unmarshaling VT_VOID with guid %s?\n",debugstr_guid(&(buf->iid)));
|
|---|
| 415 | }
|
|---|
| 416 | return hres;
|
|---|
| 417 | case VT_USERDEFINED: {
|
|---|
| 418 | ITypeInfo *tinfo2;
|
|---|
| 419 | TYPEATTR *tattr;
|
|---|
| 420 |
|
|---|
| 421 | /*FIXME("VT_USERDEFINED arg is %p, *arg is %p\n",arg,*arg);*/
|
|---|
| 422 | hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
|
|---|
| 423 | if (hres) {
|
|---|
| 424 | FIXME("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
|
|---|
| 425 | return hres;
|
|---|
| 426 | }
|
|---|
| 427 | ITypeInfo_GetTypeAttr(tinfo2,&tattr);
|
|---|
| 428 | switch (tattr->typekind) {
|
|---|
| 429 | case TKIND_INTERFACE:
|
|---|
| 430 | if (relaydeb) MESSAGE("if(%p), vtbl %p",arg,(LPVOID)*arg);
|
|---|
| 431 | hres = _marshal_interface(buf,&(tattr->guid),(LPUNKNOWN)arg);
|
|---|
| 432 | break;
|
|---|
| 433 | case TKIND_RECORD:
|
|---|
| 434 | if (relaydeb) MESSAGE("record %p",arg);
|
|---|
| 435 | if (buf->thisisiid)
|
|---|
| 436 | memcpy(&(buf->iid),arg,sizeof(buf->iid));
|
|---|
| 437 | hres = xbuf_add(buf,(LPBYTE)arg,tattr->cbSizeInstance);
|
|---|
| 438 | break;
|
|---|
| 439 | default:
|
|---|
| 440 | FIXME("Don't know how to marshal type kind %d\n",tattr->typekind);
|
|---|
| 441 | hres = E_FAIL;
|
|---|
| 442 | break;
|
|---|
| 443 | }
|
|---|
| 444 | ITypeInfo_Release(tinfo2);
|
|---|
| 445 | return hres;
|
|---|
| 446 | }
|
|---|
| 447 | default:
|
|---|
| 448 | ERR("Cannot marshal type %d\n",tdesc->vt);
|
|---|
| 449 | /*dump_ELEMDESC(elem);*/
|
|---|
| 450 | return E_FAIL;
|
|---|
| 451 | }
|
|---|
| 452 | return S_OK;
|
|---|
| 453 | }
|
|---|
| 454 |
|
|---|
| 455 | static HRESULT
|
|---|
| 456 | unmarshall_param(
|
|---|
| 457 | ITypeInfo *tinfo, ELEMDESC *elem, TYPEDESC *tdesc, DWORD *arg, marshal_state *buf
|
|---|
| 458 | ) {
|
|---|
| 459 | HRESULT hres = S_OK;
|
|---|
| 460 | int relaydeb = TRACE_ON(olerelay);
|
|---|
| 461 |
|
|---|
| 462 | if (!tdesc) tdesc = &(elem->tdesc);
|
|---|
| 463 | switch (tdesc->vt) {
|
|---|
| 464 | case VT_I4: {
|
|---|
| 465 | DWORD x;
|
|---|
| 466 | xbuf_get(buf,(LPBYTE)&x,sizeof(x));
|
|---|
| 467 | *arg = x;
|
|---|
| 468 | if (relaydeb) MESSAGE("%ld ",x);
|
|---|
| 469 | return S_OK;
|
|---|
| 470 | }
|
|---|
| 471 | case VT_PTR:
|
|---|
| 472 | if ((tdesc->u.lptdesc->vt != VT_USERDEFINED) &&
|
|---|
| 473 | (tdesc->u.lptdesc->vt != VT_VOID)
|
|---|
| 474 | )
|
|---|
| 475 | hres = unmarshall_param(tinfo,elem,tdesc->u.lptdesc,(DWORD*)(*arg),buf);
|
|---|
| 476 | else
|
|---|
| 477 | hres = unmarshall_param(tinfo,elem,tdesc->u.lptdesc,arg,buf);
|
|---|
| 478 | if (relaydeb) MESSAGE("%p ",(LPVOID)*arg);
|
|---|
| 479 | return S_OK;
|
|---|
| 480 | case VT_USERDEFINED: {
|
|---|
| 481 | ITypeInfo *tinfo2;
|
|---|
| 482 | TYPEATTR *tattr;
|
|---|
| 483 |
|
|---|
| 484 | if (relaydeb) MESSAGE("%p",arg);
|
|---|
| 485 | hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
|
|---|
| 486 | if (hres) {
|
|---|
| 487 | FIXME("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
|
|---|
| 488 | return hres;
|
|---|
| 489 | }
|
|---|
| 490 | hres = ITypeInfo_GetTypeAttr(tinfo2,&tattr);
|
|---|
| 491 | if (hres) {
|
|---|
| 492 | FIXME("Could not get typeattr in VT_USERDEFINED.\n");
|
|---|
| 493 | return hres;
|
|---|
| 494 | }
|
|---|
| 495 | switch (tattr->typekind) {
|
|---|
| 496 | case TKIND_INTERFACE:
|
|---|
| 497 | hres = _unmarshal_interface(buf,&(tattr->guid),(LPUNKNOWN*)arg);
|
|---|
| 498 | break;
|
|---|
| 499 | case TKIND_RECORD:
|
|---|
| 500 | hres = xbuf_get(buf,(LPBYTE)arg,tattr->cbSizeInstance);
|
|---|
| 501 | break;
|
|---|
| 502 | default:
|
|---|
| 503 | hres = E_FAIL;
|
|---|
| 504 | FIXME("Don't know how to marshal type kind %d\n",tattr->typekind);
|
|---|
| 505 | }
|
|---|
| 506 | ITypeInfo_Release(tinfo2);
|
|---|
| 507 | return hres;
|
|---|
| 508 | }
|
|---|
| 509 | case VT_VOID:
|
|---|
| 510 | /* Hacky. If we are LPVOID* we apparently have to guess the IID
|
|---|
| 511 | * for the interface. This sucks pretty badly. */
|
|---|
| 512 | return _unmarshal_interface(buf,&(buf->iid),(LPUNKNOWN*)arg);
|
|---|
| 513 | default: ERR("Cannot unmarshal type %d\n",tdesc->vt);
|
|---|
| 514 | return E_FAIL;
|
|---|
| 515 | }
|
|---|
| 516 | return S_OK;
|
|---|
| 517 | }
|
|---|
| 518 |
|
|---|
| 519 | /* Searches function, also in inherited interfaces */
|
|---|
| 520 | static HRESULT
|
|---|
| 521 | _get_funcdesc(
|
|---|
| 522 | ITypeInfo *tinfo, int iMethod, FUNCDESC **fdesc,
|
|---|
| 523 | BSTR *iname, BSTR *fname
|
|---|
| 524 | ) {
|
|---|
| 525 | int i = 0, j = 0;
|
|---|
| 526 | HRESULT hres;
|
|---|
| 527 |
|
|---|
| 528 | if (fname) *fname = NULL;
|
|---|
| 529 | if (iname) *iname = NULL;
|
|---|
| 530 |
|
|---|
| 531 | while (1) {
|
|---|
| 532 | hres = ITypeInfo_GetFuncDesc(tinfo, i, fdesc);
|
|---|
| 533 | if (hres) {
|
|---|
| 534 | ITypeInfo *tinfo2;
|
|---|
| 535 | HREFTYPE href;
|
|---|
| 536 | TYPEATTR *attr;
|
|---|
| 537 |
|
|---|
| 538 | hres = ITypeInfo_GetTypeAttr(tinfo, &attr);
|
|---|
| 539 | if (hres) {
|
|---|
| 540 | FIXME("GetTypeAttr failed with %lx\n",hres);
|
|---|
| 541 | return hres;
|
|---|
| 542 | }
|
|---|
| 543 | /* Not found, so look in inherited ifaces. */
|
|---|
| 544 | for (j=0;j<attr->cImplTypes;j++) {
|
|---|
| 545 | hres = ITypeInfo_GetRefTypeOfImplType(tinfo, j, &href);
|
|---|
| 546 | if (hres) {
|
|---|
| 547 | FIXME("Did not find a reftype for interface offset %d?\n",j);
|
|---|
| 548 | break;
|
|---|
| 549 | }
|
|---|
| 550 | hres = ITypeInfo_GetRefTypeInfo(tinfo, href, &tinfo2);
|
|---|
| 551 | if (hres) {
|
|---|
| 552 | FIXME("Did not find a typeinfo for reftype %ld?\n",href);
|
|---|
| 553 | continue;
|
|---|
| 554 | }
|
|---|
| 555 | hres = _get_funcdesc(tinfo2,iMethod,fdesc,iname,fname);
|
|---|
| 556 | ITypeInfo_Release(tinfo2);
|
|---|
| 557 | if (!hres) return S_OK;
|
|---|
| 558 | }
|
|---|
| 559 | return E_FAIL;
|
|---|
| 560 | }
|
|---|
| 561 | if (((*fdesc)->oVft/4) == iMethod) {
|
|---|
| 562 | if (fname)
|
|---|
| 563 | ITypeInfo_GetDocumentation(tinfo,(*fdesc)->memid,fname,NULL,NULL,NULL);
|
|---|
| 564 | if (iname)
|
|---|
| 565 | ITypeInfo_GetDocumentation(tinfo,-1,iname,NULL,NULL,NULL);
|
|---|
| 566 | return S_OK;
|
|---|
| 567 | }
|
|---|
| 568 | i++;
|
|---|
| 569 | }
|
|---|
| 570 | return E_FAIL;
|
|---|
| 571 | }
|
|---|
| 572 |
|
|---|
| 573 | /* how much space do we use on stack in DWORD steps. */
|
|---|
| 574 | static int
|
|---|
| 575 | _argsize(DWORD vt_type) {
|
|---|
| 576 | switch (vt_type) {
|
|---|
| 577 | case VT_VARIANT:
|
|---|
| 578 | return (sizeof(VARIANT)+3)/sizeof(DWORD);
|
|---|
| 579 | default:
|
|---|
| 580 | return 1;
|
|---|
| 581 | }
|
|---|
| 582 | }
|
|---|
| 583 |
|
|---|
| 584 | #ifdef __WIN32OS2__
|
|---|
| 585 | static DWORD CDECL
|
|---|
| 586 | #else
|
|---|
| 587 | static DWORD
|
|---|
| 588 | #endif
|
|---|
| 589 | xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */) {
|
|---|
| 590 | DWORD *args = ((DWORD*)&tpinfo)+1, *xargs;
|
|---|
| 591 | FUNCDESC *fdesc;
|
|---|
| 592 | HRESULT hres;
|
|---|
| 593 | int i, relaydeb = TRACE_ON(olerelay);
|
|---|
| 594 | marshal_state buf;
|
|---|
| 595 | RPCOLEMESSAGE msg;
|
|---|
| 596 | ULONG status;
|
|---|
| 597 | BSTR fname,iname;
|
|---|
| 598 | BSTR names[10];
|
|---|
| 599 | int nrofnames;
|
|---|
| 600 |
|
|---|
| 601 | hres = _get_funcdesc(tpinfo->tinfo,method,&fdesc,&iname,&fname);
|
|---|
| 602 | if (hres) {
|
|---|
| 603 | ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method);
|
|---|
| 604 | return 0;
|
|---|
| 605 | }
|
|---|
| 606 |
|
|---|
| 607 | /*dump_FUNCDESC(fdesc);*/
|
|---|
| 608 | if (relaydeb) {
|
|---|
| 609 | TRACE_(olerelay)("->");
|
|---|
| 610 | if (iname)
|
|---|
| 611 | MESSAGE("%s:",debugstr_w(iname));
|
|---|
| 612 | if (fname)
|
|---|
| 613 | MESSAGE("%s(%d)",debugstr_w(fname),method);
|
|---|
| 614 | else
|
|---|
| 615 | MESSAGE("%d",method);
|
|---|
| 616 | MESSAGE("(");
|
|---|
| 617 | if (iname) SysFreeString(iname);
|
|---|
| 618 | if (fname) SysFreeString(fname);
|
|---|
| 619 | }
|
|---|
| 620 | /* Need them for hack below */
|
|---|
| 621 | memset(names,0,sizeof(names));
|
|---|
| 622 | ITypeInfo_GetNames(tpinfo->tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
|
|---|
| 623 | if (nrofnames > sizeof(names)/sizeof(names[0])) {
|
|---|
| 624 | ERR("Need more names!\n");
|
|---|
| 625 | }
|
|---|
| 626 | memset(&buf,0,sizeof(buf));
|
|---|
| 627 | buf.iid = IID_IUnknown;
|
|---|
| 628 | if (method == 0) {
|
|---|
| 629 | xbuf_add(&buf,(LPBYTE)args[0],sizeof(IID));
|
|---|
| 630 | if (relaydeb) MESSAGE("riid=%s,[out]",debugstr_guid((REFIID)args[0]));
|
|---|
| 631 | } else {
|
|---|
| 632 | xargs = args;
|
|---|
| 633 | for (i=0;i<fdesc->cParams;i++) {
|
|---|
| 634 | ELEMDESC *elem = fdesc->lprgelemdescParam+i;
|
|---|
| 635 | if (relaydeb) {
|
|---|
| 636 | if (i) MESSAGE(",");
|
|---|
| 637 | if (i+1<nrofnames && names[i+1])
|
|---|
| 638 | MESSAGE("%s=",debugstr_w(names[i+1]));
|
|---|
| 639 | }
|
|---|
| 640 | if (((i+1)<nrofnames) && !lstrcmpW(names[i+1],riidW)) {
|
|---|
| 641 | buf.thisisiid = TRUE;
|
|---|
| 642 | } else {
|
|---|
| 643 | buf.thisisiid = FALSE;
|
|---|
| 644 | }
|
|---|
| 645 | /* No need to marshal other data than FIN */
|
|---|
| 646 | if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN)) {
|
|---|
| 647 | xargs+=_argsize(elem->tdesc.vt);
|
|---|
| 648 | if (relaydeb) MESSAGE("[out]");
|
|---|
| 649 | continue;
|
|---|
| 650 | }
|
|---|
| 651 | hres = marshall_param(tpinfo->tinfo,elem,NULL,xargs,&buf);
|
|---|
| 652 | xargs+=_argsize(elem->tdesc.vt);
|
|---|
| 653 | if (hres) {
|
|---|
| 654 | FIXME("Failed to marshall param, hres %lx\n",hres);
|
|---|
| 655 | break;
|
|---|
| 656 | }
|
|---|
| 657 | }
|
|---|
| 658 | }
|
|---|
| 659 | if (relaydeb) MESSAGE(")");
|
|---|
| 660 | memset(&msg,0,sizeof(msg));
|
|---|
| 661 | msg.cbBuffer = buf.curoff;
|
|---|
| 662 | msg.iMethod = method;
|
|---|
| 663 | hres = IRpcChannelBuffer_GetBuffer(tpinfo->chanbuf,&msg,&(tpinfo->iid));
|
|---|
| 664 | if (hres) {
|
|---|
| 665 | FIXME("RpcChannelBuffer GetBuffer failed, %lx\n",hres);
|
|---|
| 666 | return hres;
|
|---|
| 667 | }
|
|---|
| 668 | memcpy(msg.Buffer,buf.base,buf.curoff);
|
|---|
| 669 | hres = IRpcChannelBuffer_SendReceive(tpinfo->chanbuf,&msg,&status);
|
|---|
| 670 | if (hres) {
|
|---|
| 671 | FIXME("RpcChannelBuffer SendReceive failed, %lx\n",hres);
|
|---|
| 672 | return hres;
|
|---|
| 673 | }
|
|---|
| 674 | if (relaydeb) MESSAGE(" = %08lx (",status);
|
|---|
| 675 | if (buf.base)
|
|---|
| 676 | buf.base = HeapReAlloc(GetProcessHeap(),0,buf.base,msg.cbBuffer);
|
|---|
| 677 | else
|
|---|
| 678 | buf.base = HeapAlloc(GetProcessHeap(),0,msg.cbBuffer);
|
|---|
| 679 | buf.size = msg.cbBuffer;
|
|---|
| 680 | memcpy(buf.base,msg.Buffer,buf.size);
|
|---|
| 681 | buf.curoff = 0;
|
|---|
| 682 | if (method == 0) {
|
|---|
| 683 | _unmarshal_interface(&buf,(REFIID)args[0],(LPUNKNOWN*)args[1]);
|
|---|
| 684 | if (relaydeb) MESSAGE("[in],%p",*((DWORD**)args[1]));
|
|---|
| 685 | } else {
|
|---|
| 686 | xargs = args;
|
|---|
| 687 | for (i=0;i<fdesc->cParams;i++) {
|
|---|
| 688 | ELEMDESC *elem = fdesc->lprgelemdescParam+i;
|
|---|
| 689 |
|
|---|
| 690 | if (relaydeb) {
|
|---|
| 691 | if (i) MESSAGE(",");
|
|---|
| 692 | if (i+1<nrofnames && names[i+1]) MESSAGE("%s=",debugstr_w(names[i+1]));
|
|---|
| 693 | }
|
|---|
| 694 | /* No need to marshal other data than FOUT I think */
|
|---|
| 695 | if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT)) {
|
|---|
| 696 | xargs += _argsize(elem->tdesc.vt);
|
|---|
| 697 | if (relaydeb) MESSAGE("[in]");
|
|---|
| 698 | continue;
|
|---|
| 699 | }
|
|---|
| 700 | hres = unmarshall_param(tpinfo->tinfo,elem,&(elem->tdesc),xargs,&buf);
|
|---|
| 701 | xargs += _argsize(elem->tdesc.vt);
|
|---|
| 702 | if (hres) {
|
|---|
| 703 | FIXME("Failed to unmarshall param, hres %lx\n",hres);
|
|---|
| 704 | break;
|
|---|
| 705 | }
|
|---|
| 706 | }
|
|---|
| 707 | }
|
|---|
| 708 | if (relaydeb) MESSAGE(")\n");
|
|---|
| 709 | HeapFree(GetProcessHeap(),0,buf.base);
|
|---|
| 710 | return status;
|
|---|
| 711 | }
|
|---|
| 712 |
|
|---|
| 713 | static HRESULT WINAPI
|
|---|
| 714 | PSFacBuf_CreateProxy(
|
|---|
| 715 | LPPSFACTORYBUFFER iface, IUnknown* pUnkOuter, REFIID riid,
|
|---|
| 716 | IRpcProxyBuffer **ppProxy, LPVOID *ppv
|
|---|
| 717 | ) {
|
|---|
| 718 | HRESULT hres;
|
|---|
| 719 | ITypeInfo *tinfo;
|
|---|
| 720 | int i, nroffuncs;
|
|---|
| 721 | FUNCDESC *fdesc;
|
|---|
| 722 | TMProxyImpl *proxy;
|
|---|
| 723 |
|
|---|
| 724 | TRACE("(...%s...)\n",debugstr_guid(riid));
|
|---|
| 725 | hres = _get_typeinfo_for_iid(riid,&tinfo);
|
|---|
| 726 | if (hres) {
|
|---|
| 727 | FIXME("No typeinfo for %s?\n",debugstr_guid(riid));
|
|---|
| 728 | return hres;
|
|---|
| 729 | }
|
|---|
| 730 | nroffuncs = _nroffuncs(tinfo);
|
|---|
| 731 | proxy = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TMProxyImpl));
|
|---|
| 732 | if (!proxy) return E_OUTOFMEMORY;
|
|---|
| 733 | proxy->asmstubs=HeapAlloc(GetProcessHeap(),0,sizeof(TMAsmProxy)*nroffuncs);
|
|---|
| 734 |
|
|---|
| 735 | assert(sizeof(TMAsmProxy) == 12);
|
|---|
| 736 |
|
|---|
| 737 | proxy->lpvtbl = HeapAlloc(GetProcessHeap(),0,sizeof(LPBYTE)*nroffuncs);
|
|---|
| 738 | for (i=0;i<nroffuncs;i++) {
|
|---|
| 739 | int nrofargs;
|
|---|
| 740 | TMAsmProxy *xasm = proxy->asmstubs+i;
|
|---|
| 741 |
|
|---|
| 742 | /* nrofargs without This */
|
|---|
| 743 | switch (i) {
|
|---|
| 744 | case 0: nrofargs = 2;
|
|---|
| 745 | break;
|
|---|
| 746 | case 1: case 2: nrofargs = 0;
|
|---|
| 747 | break;
|
|---|
| 748 | default: {
|
|---|
| 749 | int j;
|
|---|
| 750 | hres = _get_funcdesc(tinfo,i,&fdesc,NULL,NULL);
|
|---|
| 751 | if (hres) {
|
|---|
| 752 | FIXME("GetFuncDesc %lx should not fail here.\n",hres);
|
|---|
| 753 | return hres;
|
|---|
| 754 | }
|
|---|
| 755 | /* some args take more than 4 byte on the stack */
|
|---|
| 756 | nrofargs = 0;
|
|---|
| 757 | for (j=0;j<fdesc->cParams;j++)
|
|---|
| 758 | nrofargs += _argsize(fdesc->lprgelemdescParam[j].tdesc.vt);
|
|---|
| 759 |
|
|---|
| 760 | if (fdesc->callconv != CC_STDCALL) {
|
|---|
| 761 | ERR("calling convention is not stdcall????\n");
|
|---|
| 762 | return E_FAIL;
|
|---|
| 763 | }
|
|---|
| 764 | break;
|
|---|
| 765 | }
|
|---|
| 766 | }
|
|---|
| 767 | /* popl %eax - return ptr
|
|---|
| 768 | * pushl <nr>
|
|---|
| 769 | * pushl %eax
|
|---|
| 770 | * call xCall
|
|---|
| 771 | * lret <nr> (+4)
|
|---|
| 772 | *
|
|---|
| 773 | *
|
|---|
| 774 | * arg3 arg2 arg1 <method> <returnptr>
|
|---|
| 775 | */
|
|---|
| 776 | xasm->popleax = 0x58;
|
|---|
| 777 | xasm->pushlval = 0x6a;
|
|---|
| 778 | xasm->nr = i;
|
|---|
| 779 | xasm->pushleax = 0x50;
|
|---|
| 780 | xasm->lcall = 0xe8; /* relative jump */
|
|---|
| 781 | xasm->xcall = (DWORD)xCall;
|
|---|
| 782 | xasm->xcall -= (DWORD)&(xasm->lret);
|
|---|
| 783 | xasm->lret = 0xc2;
|
|---|
| 784 | xasm->bytestopop= (nrofargs+2)*4; /* pop args, This, iMethod */
|
|---|
| 785 | proxy->lpvtbl[i] = (DWORD)xasm;
|
|---|
| 786 | }
|
|---|
| 787 | proxy->lpvtbl2 = &tmproxyvtable;
|
|---|
| 788 | proxy->ref = 2;
|
|---|
| 789 | proxy->tinfo = tinfo;
|
|---|
| 790 | memcpy(&proxy->iid,riid,sizeof(*riid));
|
|---|
| 791 | *ppv = (LPVOID)proxy;
|
|---|
| 792 | *ppProxy = (IRpcProxyBuffer *)&(proxy->lpvtbl2);
|
|---|
| 793 | return S_OK;
|
|---|
| 794 | }
|
|---|
| 795 |
|
|---|
| 796 | typedef struct _TMStubImpl {
|
|---|
| 797 | ICOM_VTABLE(IRpcStubBuffer) *lpvtbl;
|
|---|
| 798 | DWORD ref;
|
|---|
| 799 |
|
|---|
| 800 | LPUNKNOWN pUnk;
|
|---|
| 801 | ITypeInfo *tinfo;
|
|---|
| 802 | IID iid;
|
|---|
| 803 | } TMStubImpl;
|
|---|
| 804 |
|
|---|
| 805 | static HRESULT WINAPI
|
|---|
| 806 | TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface, REFIID riid, LPVOID *ppv) {
|
|---|
| 807 | if (IsEqualIID(riid,&IID_IRpcStubBuffer)||IsEqualIID(riid,&IID_IUnknown)){
|
|---|
| 808 | *ppv = (LPVOID)iface;
|
|---|
| 809 | IRpcStubBuffer_AddRef(iface);
|
|---|
| 810 | return S_OK;
|
|---|
| 811 | }
|
|---|
| 812 | FIXME("%s, not supported IID.\n",debugstr_guid(riid));
|
|---|
| 813 | return E_NOINTERFACE;
|
|---|
| 814 | }
|
|---|
| 815 |
|
|---|
| 816 | static ULONG WINAPI
|
|---|
| 817 | TMStubImpl_AddRef(LPRPCSTUBBUFFER iface) {
|
|---|
| 818 | ICOM_THIS(TMStubImpl,iface);
|
|---|
| 819 |
|
|---|
| 820 | This->ref++;
|
|---|
| 821 | return This->ref;
|
|---|
| 822 | }
|
|---|
| 823 |
|
|---|
| 824 | static ULONG WINAPI
|
|---|
| 825 | TMStubImpl_Release(LPRPCSTUBBUFFER iface) {
|
|---|
| 826 | ICOM_THIS(TMStubImpl,iface);
|
|---|
| 827 |
|
|---|
| 828 | This->ref--;
|
|---|
| 829 | if (This->ref)
|
|---|
| 830 | return This->ref;
|
|---|
| 831 | HeapFree(GetProcessHeap(),0,This);
|
|---|
| 832 | return 0;
|
|---|
| 833 | }
|
|---|
| 834 |
|
|---|
| 835 | static HRESULT WINAPI
|
|---|
| 836 | TMStubImpl_Connect(LPRPCSTUBBUFFER iface, LPUNKNOWN pUnkServer) {
|
|---|
| 837 | ICOM_THIS(TMStubImpl,iface);
|
|---|
| 838 |
|
|---|
| 839 | IUnknown_AddRef(pUnkServer);
|
|---|
| 840 | This->pUnk = pUnkServer;
|
|---|
| 841 | return S_OK;
|
|---|
| 842 | }
|
|---|
| 843 |
|
|---|
| 844 | static void WINAPI
|
|---|
| 845 | TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface) {
|
|---|
| 846 | ICOM_THIS(TMStubImpl,iface);
|
|---|
| 847 |
|
|---|
| 848 | IUnknown_Release(This->pUnk);
|
|---|
| 849 | This->pUnk = NULL;
|
|---|
| 850 | return;
|
|---|
| 851 | }
|
|---|
| 852 |
|
|---|
| 853 | static HRESULT
|
|---|
| 854 | stuballoc_param(
|
|---|
| 855 | ITypeInfo *tinfo, ELEMDESC *elem, TYPEDESC *tdesc, DWORD *arg, marshal_state *buf
|
|---|
| 856 | ) {
|
|---|
| 857 | HRESULT hres;
|
|---|
| 858 |
|
|---|
| 859 | while (1) {
|
|---|
| 860 | switch (tdesc->vt) {
|
|---|
| 861 | case VT_VARIANT: {
|
|---|
| 862 | DWORD vttype;
|
|---|
| 863 | VARIANT *vt = (VARIANT*)arg;
|
|---|
| 864 | TYPEDESC tdesc2;
|
|---|
| 865 |
|
|---|
| 866 | hres = xbuf_get(buf,(LPBYTE)&vttype,sizeof(vttype));
|
|---|
| 867 | if (hres) return hres;
|
|---|
| 868 | memset(&tdesc2,0,sizeof(tdesc));
|
|---|
| 869 | tdesc2.vt = vttype;
|
|---|
| 870 | V_VT(vt) = vttype;
|
|---|
| 871 | return stuballoc_param(tinfo,elem,&tdesc2,&(V_I4(vt)),buf);
|
|---|
| 872 | }
|
|---|
| 873 | case VT_BOOL: case VT_I4:
|
|---|
| 874 | xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
|
|---|
| 875 | return S_OK;
|
|---|
| 876 | case VT_BSTR: {
|
|---|
| 877 | WCHAR *str;
|
|---|
| 878 | DWORD len;
|
|---|
| 879 |
|
|---|
| 880 | hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
|
|---|
| 881 | if (hres)
|
|---|
| 882 | return hres;
|
|---|
| 883 | str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len+sizeof(WCHAR));
|
|---|
| 884 | hres = xbuf_get(buf,(LPBYTE)str,len);
|
|---|
| 885 | if (hres) return hres;
|
|---|
| 886 | *arg = (DWORD)SysAllocStringLen(str,len);
|
|---|
| 887 | HeapFree(GetProcessHeap(),0,str);
|
|---|
| 888 | return S_OK;
|
|---|
| 889 | }
|
|---|
| 890 | case VT_PTR:
|
|---|
| 891 | if ((tdesc->u.lptdesc->vt != VT_USERDEFINED) &&
|
|---|
| 892 | (tdesc->u.lptdesc->vt != VT_VOID)
|
|---|
| 893 | ) {
|
|---|
| 894 | *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(LPVOID));
|
|---|
| 895 | arg = (DWORD*)*arg;
|
|---|
| 896 | }
|
|---|
| 897 | tdesc = tdesc->u.lptdesc;
|
|---|
| 898 | break;
|
|---|
| 899 | case VT_UNKNOWN:
|
|---|
| 900 | /* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
|
|---|
| 901 | *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
|
|---|
| 902 | return S_OK;
|
|---|
| 903 | case VT_VOID:
|
|---|
| 904 | *arg = (DWORD)HeapAlloc(GetProcessHeap(),0,sizeof(LPVOID));
|
|---|
| 905 | hres = S_OK;
|
|---|
| 906 | if (elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN)
|
|---|
| 907 | hres = _unmarshal_interface(buf,&(buf->iid),(LPUNKNOWN*)arg);
|
|---|
| 908 | return hres;
|
|---|
| 909 | case VT_USERDEFINED: {
|
|---|
| 910 | if (elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN) {
|
|---|
| 911 | ITypeInfo *tinfo2;
|
|---|
| 912 | TYPEATTR *tattr;
|
|---|
| 913 |
|
|---|
| 914 | hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
|
|---|
| 915 | if (hres) {
|
|---|
| 916 | FIXME("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
|
|---|
| 917 | return hres;
|
|---|
| 918 | }
|
|---|
| 919 | hres = ITypeInfo_GetTypeAttr(tinfo2,&tattr);
|
|---|
| 920 | if (hres) {
|
|---|
| 921 | FIXME("Could not get typeattr in VT_USERDEFINED.\n");
|
|---|
| 922 | return hres;
|
|---|
| 923 | }
|
|---|
| 924 | switch (tattr->typekind) {
|
|---|
| 925 | case TKIND_INTERFACE:
|
|---|
| 926 | hres = _unmarshal_interface(buf,&(tattr->guid),(LPUNKNOWN*)arg);
|
|---|
| 927 | break;
|
|---|
| 928 | case TKIND_RECORD:
|
|---|
| 929 | *arg = (DWORD)HeapAlloc(GetProcessHeap(),0,tattr->cbSizeInstance);
|
|---|
| 930 | hres = xbuf_get(buf,(LPBYTE)*arg,tattr->cbSizeInstance);
|
|---|
| 931 | if (buf->thisisiid)
|
|---|
| 932 | memcpy(&(buf->iid),(LPBYTE)*arg,sizeof(buf->iid));
|
|---|
| 933 | break;
|
|---|
| 934 | default:
|
|---|
| 935 | FIXME("Don't know how to marshal type kind %d\n",tattr->typekind);
|
|---|
| 936 | hres = E_FAIL;
|
|---|
| 937 | break;
|
|---|
| 938 | }
|
|---|
| 939 | ITypeInfo_Release(tinfo2);
|
|---|
| 940 | return hres;
|
|---|
| 941 | } else {
|
|---|
| 942 | *arg = (DWORD)HeapAlloc(GetProcessHeap(),0,sizeof(LPVOID));
|
|---|
| 943 | return S_OK;
|
|---|
| 944 | }
|
|---|
| 945 | }
|
|---|
| 946 | default:
|
|---|
| 947 | ERR("No handler for VT type %d, just allocating 4 bytes.\n",tdesc->vt);
|
|---|
| 948 | *arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
|
|---|
| 949 | return S_OK;
|
|---|
| 950 | }
|
|---|
| 951 | }
|
|---|
| 952 | }
|
|---|
| 953 |
|
|---|
| 954 | static HRESULT
|
|---|
| 955 | stubunalloc_param(
|
|---|
| 956 | ITypeInfo *tinfo, ELEMDESC *elem, TYPEDESC *tdesc, DWORD *arg, marshal_state *buf
|
|---|
| 957 | ) {
|
|---|
| 958 | HRESULT hres = S_OK;
|
|---|
| 959 |
|
|---|
| 960 | if (!tdesc) tdesc = &(elem->tdesc);
|
|---|
| 961 |
|
|---|
| 962 | switch (tdesc->vt) {
|
|---|
| 963 | case VT_BOOL:
|
|---|
| 964 | case VT_I4:
|
|---|
| 965 | hres = S_OK;
|
|---|
| 966 | if (elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT)
|
|---|
| 967 | hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
|
|---|
| 968 | return hres;
|
|---|
| 969 | case VT_VARIANT: {
|
|---|
| 970 | TYPEDESC tdesc2;
|
|---|
| 971 | VARIANT *vt = (VARIANT*)arg;
|
|---|
| 972 | DWORD vttype = V_VT(vt);
|
|---|
| 973 |
|
|---|
| 974 | tdesc2.vt = vttype;
|
|---|
| 975 | if (elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT) {
|
|---|
| 976 | hres = xbuf_add(buf,(LPBYTE)&vttype,sizeof(vttype));
|
|---|
| 977 | if (hres) return hres;
|
|---|
| 978 | }
|
|---|
| 979 | /* need to recurse since we need to free the stuff */
|
|---|
| 980 | hres = stubunalloc_param(tinfo,elem,&tdesc2,&(V_I4(vt)),buf);
|
|---|
| 981 | return hres;
|
|---|
| 982 | }
|
|---|
| 983 | case VT_BSTR: {
|
|---|
| 984 | if (elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT) {
|
|---|
| 985 | DWORD *bstr = ((DWORD*)(*arg))-1;
|
|---|
| 986 |
|
|---|
| 987 | hres = xbuf_add(buf,(LPBYTE)bstr,bstr[0]+4);
|
|---|
| 988 | if (hres)
|
|---|
| 989 | return hres;
|
|---|
| 990 | }
|
|---|
| 991 | SysFreeString((BSTR)*arg);
|
|---|
| 992 | return S_OK;
|
|---|
| 993 | }
|
|---|
| 994 | case VT_PTR:
|
|---|
| 995 | /*FIXME("VT_PTR *arg is %p\n",(LPVOID)*arg);*/
|
|---|
| 996 | if ((tdesc->u.lptdesc->vt != VT_USERDEFINED) &&
|
|---|
| 997 | (tdesc->u.lptdesc->vt != VT_VOID)
|
|---|
| 998 | ) {
|
|---|
| 999 | hres = stubunalloc_param(tinfo,elem,tdesc->u.lptdesc,arg,buf);
|
|---|
| 1000 | } else {
|
|---|
| 1001 | hres = stubunalloc_param(tinfo,elem,tdesc->u.lptdesc,(DWORD*)*arg,buf);
|
|---|
| 1002 | HeapFree(GetProcessHeap(),0,(LPVOID)*arg);
|
|---|
| 1003 | }
|
|---|
| 1004 | return hres;
|
|---|
| 1005 | case VT_UNKNOWN:
|
|---|
| 1006 | if (elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT) {
|
|---|
| 1007 | FIXME("Marshaling back VT_UNKNOWN %lx\n",*arg);
|
|---|
| 1008 | hres = xbuf_add(buf,(LPBYTE)*arg,sizeof(DWORD));
|
|---|
| 1009 | }
|
|---|
| 1010 | HeapFree(GetProcessHeap(),0,(LPVOID)*arg);
|
|---|
| 1011 | return hres;
|
|---|
| 1012 | case VT_VOID:
|
|---|
| 1013 | hres = S_OK;
|
|---|
| 1014 | if (elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT)
|
|---|
| 1015 | hres = _marshal_interface(buf,&(buf->iid),(LPUNKNOWN)*arg);
|
|---|
| 1016 | return hres;
|
|---|
| 1017 | case VT_USERDEFINED: {
|
|---|
| 1018 | ITypeInfo *tinfo2;
|
|---|
| 1019 | TYPEATTR *tattr;
|
|---|
| 1020 |
|
|---|
| 1021 | if (elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT) {
|
|---|
| 1022 | /*FIXME("VT_USERDEFINED arg is %p, *arg is %p\n",arg,*arg);*/
|
|---|
| 1023 | hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
|
|---|
| 1024 | if (hres) {
|
|---|
| 1025 | FIXME("Could not get typeinfo of hreftype %lx for VT_USERDEFINED.\n",tdesc->u.hreftype);
|
|---|
| 1026 | return hres;
|
|---|
| 1027 | }
|
|---|
| 1028 | ITypeInfo_GetTypeAttr(tinfo2,&tattr);
|
|---|
| 1029 | switch (tattr->typekind) {
|
|---|
| 1030 | case TKIND_INTERFACE:
|
|---|
| 1031 | hres = _marshal_interface(buf,&(tattr->guid),(LPUNKNOWN)*arg);
|
|---|
| 1032 | break;
|
|---|
| 1033 | case TKIND_RECORD:
|
|---|
| 1034 | hres = xbuf_add(buf,(LPBYTE)arg,tattr->cbSizeInstance);
|
|---|
| 1035 | break;
|
|---|
| 1036 | default:
|
|---|
| 1037 | FIXME("Don't know how to marshal type kind %d\n",tattr->typekind);
|
|---|
| 1038 | hres = E_FAIL;
|
|---|
| 1039 | break;
|
|---|
| 1040 | }
|
|---|
| 1041 | ITypeInfo_Release(tinfo2);
|
|---|
| 1042 | }
|
|---|
| 1043 | return hres;
|
|---|
| 1044 | }
|
|---|
| 1045 | default:
|
|---|
| 1046 | ERR("Unhandled marshal type %d.\n",tdesc->vt);
|
|---|
| 1047 | HeapFree(GetProcessHeap(),0,(LPVOID)*arg);
|
|---|
| 1048 | return S_OK;
|
|---|
| 1049 | }
|
|---|
| 1050 | }
|
|---|
| 1051 |
|
|---|
| 1052 | static HRESULT WINAPI
|
|---|
| 1053 | TMStubImpl_Invoke(
|
|---|
| 1054 | LPRPCSTUBBUFFER iface, RPCOLEMESSAGE* xmsg,IRpcChannelBuffer*rpcchanbuf
|
|---|
| 1055 | ) {
|
|---|
| 1056 | int i;
|
|---|
| 1057 | FUNCDESC *fdesc;
|
|---|
| 1058 | ICOM_THIS(TMStubImpl,iface);
|
|---|
| 1059 | HRESULT hres;
|
|---|
| 1060 | DWORD *args, res, *xargs, nrofargs;
|
|---|
| 1061 | marshal_state buf;
|
|---|
| 1062 | int nrofnames;
|
|---|
| 1063 | BSTR names[10];
|
|---|
| 1064 |
|
|---|
| 1065 | memset(&buf,0,sizeof(buf));
|
|---|
| 1066 | buf.size = xmsg->cbBuffer;
|
|---|
| 1067 | buf.base = xmsg->Buffer;
|
|---|
| 1068 | buf.curoff = 0;
|
|---|
| 1069 | buf.iid = IID_IUnknown;
|
|---|
| 1070 |
|
|---|
| 1071 | TRACE("...\n");
|
|---|
| 1072 | if (xmsg->iMethod == 0) { /* QI */
|
|---|
| 1073 | IID xiid;
|
|---|
| 1074 | /* in: IID, out: <iface> */
|
|---|
| 1075 |
|
|---|
| 1076 | xbuf_get(&buf,(LPBYTE)&xiid,sizeof(xiid));
|
|---|
| 1077 | buf.curoff = 0;
|
|---|
| 1078 | hres = _marshal_interface(&buf,&xiid,This->pUnk);
|
|---|
| 1079 | xmsg->Buffer = buf.base; /* Might have been reallocated */
|
|---|
| 1080 | xmsg->cbBuffer = buf.size;
|
|---|
| 1081 | return hres;
|
|---|
| 1082 | }
|
|---|
| 1083 | hres = _get_funcdesc(This->tinfo,xmsg->iMethod,&fdesc,NULL,NULL);
|
|---|
| 1084 | if (hres) {
|
|---|
| 1085 | FIXME("GetFuncDesc on method %ld failed with %lx\n",xmsg->iMethod,hres);
|
|---|
| 1086 | return hres;
|
|---|
| 1087 | }
|
|---|
| 1088 | /* Need them for hack below */
|
|---|
| 1089 | memset(names,0,sizeof(names));
|
|---|
| 1090 | ITypeInfo_GetNames(This->tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
|
|---|
| 1091 | if (nrofnames > sizeof(names)/sizeof(names[0])) {
|
|---|
| 1092 | ERR("Need more names!\n");
|
|---|
| 1093 | }
|
|---|
| 1094 |
|
|---|
| 1095 | /*dump_FUNCDESC(fdesc);*/
|
|---|
| 1096 | nrofargs = 0;
|
|---|
| 1097 | for (i=0;i<fdesc->cParams;i++)
|
|---|
| 1098 | nrofargs += _argsize(fdesc->lprgelemdescParam[i].tdesc.vt);
|
|---|
| 1099 | args = HeapAlloc(GetProcessHeap(),0,(nrofargs+1)*sizeof(DWORD));
|
|---|
| 1100 | if (!args) return E_OUTOFMEMORY;
|
|---|
| 1101 |
|
|---|
| 1102 | /* Allocate all stuff used by call. */
|
|---|
| 1103 | xargs = args+1;
|
|---|
| 1104 | for (i=0;i<fdesc->cParams;i++) {
|
|---|
| 1105 | ELEMDESC *elem = fdesc->lprgelemdescParam+i;
|
|---|
| 1106 |
|
|---|
| 1107 | if (((i+1)<nrofnames) && !lstrcmpW(names[i+1],riidW))
|
|---|
| 1108 | buf.thisisiid = TRUE;
|
|---|
| 1109 | else
|
|---|
| 1110 | buf.thisisiid = FALSE;
|
|---|
| 1111 | hres = stuballoc_param(This->tinfo,elem,&(elem->tdesc),xargs,&buf);
|
|---|
| 1112 | xargs += _argsize(elem->tdesc.vt);
|
|---|
| 1113 | if (hres) {
|
|---|
| 1114 | FIXME("Failed to stuballoc param %s, hres %lx\n",debugstr_w(names[i+1]),hres);
|
|---|
| 1115 | break;
|
|---|
| 1116 | }
|
|---|
| 1117 | }
|
|---|
| 1118 | hres = IUnknown_QueryInterface(This->pUnk,&(This->iid),(LPVOID*)&(args[0]));
|
|---|
| 1119 | if (hres) {
|
|---|
| 1120 | ERR("Does not support iface %s\n",debugstr_guid(&(This->iid)));
|
|---|
| 1121 | return hres;
|
|---|
| 1122 | }
|
|---|
| 1123 | res = _invoke(
|
|---|
| 1124 | (*((LPVOID**)args[0]))[fdesc->oVft/4],
|
|---|
| 1125 | fdesc->callconv,
|
|---|
| 1126 | (xargs-args),
|
|---|
| 1127 | args
|
|---|
| 1128 | );
|
|---|
| 1129 | IUnknown_Release((LPUNKNOWN)args[0]);
|
|---|
| 1130 | buf.curoff = 0;
|
|---|
| 1131 | xargs = args+1;
|
|---|
| 1132 | for (i=0;i<fdesc->cParams;i++) {
|
|---|
| 1133 | ELEMDESC *elem = fdesc->lprgelemdescParam+i;
|
|---|
| 1134 | hres = stubunalloc_param(This->tinfo,elem,NULL,xargs,&buf);
|
|---|
| 1135 | xargs += _argsize(elem->tdesc.vt);
|
|---|
| 1136 | if (hres) {
|
|---|
| 1137 | FIXME("Failed to stuballoc param, hres %lx\n",hres);
|
|---|
| 1138 | break;
|
|---|
| 1139 | }
|
|---|
| 1140 | }
|
|---|
| 1141 | /* might need to use IRpcChannelBuffer_GetBuffer ? */
|
|---|
| 1142 | xmsg->cbBuffer = buf.curoff;
|
|---|
| 1143 | xmsg->Buffer = buf.base;
|
|---|
| 1144 | HeapFree(GetProcessHeap(),0,args);
|
|---|
| 1145 | return res;
|
|---|
| 1146 | }
|
|---|
| 1147 |
|
|---|
| 1148 | static LPRPCSTUBBUFFER WINAPI
|
|---|
| 1149 | TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface, REFIID riid) {
|
|---|
| 1150 | FIXME("Huh (%s)?\n",debugstr_guid(riid));
|
|---|
| 1151 | return NULL;
|
|---|
| 1152 | }
|
|---|
| 1153 |
|
|---|
| 1154 | static ULONG WINAPI
|
|---|
| 1155 | TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface) {
|
|---|
| 1156 | ICOM_THIS(TMStubImpl,iface);
|
|---|
| 1157 |
|
|---|
| 1158 | return This->ref; /*FIXME? */
|
|---|
| 1159 | }
|
|---|
| 1160 |
|
|---|
| 1161 | static HRESULT WINAPI
|
|---|
| 1162 | TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface, LPVOID *ppv) {
|
|---|
| 1163 | return E_NOTIMPL;
|
|---|
| 1164 | }
|
|---|
| 1165 |
|
|---|
| 1166 | static void WINAPI
|
|---|
| 1167 | TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface, LPVOID ppv) {
|
|---|
| 1168 | return;
|
|---|
| 1169 | }
|
|---|
| 1170 |
|
|---|
| 1171 | ICOM_VTABLE(IRpcStubBuffer) tmstubvtbl = {
|
|---|
| 1172 | ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
|---|
| 1173 | TMStubImpl_QueryInterface,
|
|---|
| 1174 | TMStubImpl_AddRef,
|
|---|
| 1175 | TMStubImpl_Release,
|
|---|
| 1176 | TMStubImpl_Connect,
|
|---|
| 1177 | TMStubImpl_Disconnect,
|
|---|
| 1178 | TMStubImpl_Invoke,
|
|---|
| 1179 | TMStubImpl_IsIIDSupported,
|
|---|
| 1180 | TMStubImpl_CountRefs,
|
|---|
| 1181 | TMStubImpl_DebugServerQueryInterface,
|
|---|
| 1182 | TMStubImpl_DebugServerRelease
|
|---|
| 1183 | };
|
|---|
| 1184 |
|
|---|
| 1185 | static HRESULT WINAPI
|
|---|
| 1186 | PSFacBuf_CreateStub(
|
|---|
| 1187 | LPPSFACTORYBUFFER iface, REFIID riid,IUnknown *pUnkServer,
|
|---|
| 1188 | IRpcStubBuffer** ppStub
|
|---|
| 1189 | ) {
|
|---|
| 1190 | HRESULT hres;
|
|---|
| 1191 | ITypeInfo *tinfo;
|
|---|
| 1192 | TMStubImpl *stub;
|
|---|
| 1193 |
|
|---|
| 1194 | TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub);
|
|---|
| 1195 | hres = _get_typeinfo_for_iid(riid,&tinfo);
|
|---|
| 1196 | if (hres) {
|
|---|
| 1197 | FIXME("No typeinfo for %s?\n",debugstr_guid(riid));
|
|---|
| 1198 | return hres;
|
|---|
| 1199 | }
|
|---|
| 1200 | stub = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TMStubImpl));
|
|---|
| 1201 | if (!stub)
|
|---|
| 1202 | return E_OUTOFMEMORY;
|
|---|
| 1203 | stub->lpvtbl = &tmstubvtbl;
|
|---|
| 1204 | stub->ref = 1;
|
|---|
| 1205 | stub->tinfo = tinfo;
|
|---|
| 1206 | memcpy(&(stub->iid),riid,sizeof(*riid));
|
|---|
| 1207 | hres = IRpcStubBuffer_Connect((LPRPCSTUBBUFFER)stub,pUnkServer);
|
|---|
| 1208 | *ppStub = (LPRPCSTUBBUFFER)stub;
|
|---|
| 1209 | if (hres)
|
|---|
| 1210 | FIXME("Connect to pUnkServer failed?\n");
|
|---|
| 1211 | return hres;
|
|---|
| 1212 | }
|
|---|
| 1213 |
|
|---|
| 1214 | static ICOM_VTABLE(IPSFactoryBuffer) psfacbufvtbl = {
|
|---|
| 1215 | ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
|---|
| 1216 | PSFacBuf_QueryInterface,
|
|---|
| 1217 | PSFacBuf_AddRef,
|
|---|
| 1218 | PSFacBuf_Release,
|
|---|
| 1219 | PSFacBuf_CreateProxy,
|
|---|
| 1220 | PSFacBuf_CreateStub
|
|---|
| 1221 | };
|
|---|
| 1222 |
|
|---|
| 1223 | /* This is the whole PSFactoryBuffer object, just the vtableptr */
|
|---|
| 1224 | static ICOM_VTABLE(IPSFactoryBuffer) *lppsfac = &psfacbufvtbl;
|
|---|
| 1225 |
|
|---|
| 1226 | /***********************************************************************
|
|---|
| 1227 | * DllGetClassObject [OLE32.63]
|
|---|
| 1228 | */
|
|---|
| 1229 | HRESULT WINAPI
|
|---|
| 1230 | TypeLibFac_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
|
|---|
| 1231 | {
|
|---|
| 1232 | if (IsEqualIID(iid,&IID_IPSFactoryBuffer)) {
|
|---|
| 1233 | *ppv = &lppsfac;
|
|---|
| 1234 | return S_OK;
|
|---|
| 1235 | }
|
|---|
| 1236 | return E_NOINTERFACE;
|
|---|
| 1237 | }
|
|---|