2002-02-05 19:11:17 +01:00
|
|
|
/*
|
|
|
|
* TYPELIB Marshaler
|
|
|
|
*
|
2005-03-29 15:06:44 +02:00
|
|
|
* Copyright 2002,2005 Marcus Meissner
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
2004-06-18 01:03:26 +02:00
|
|
|
* The olerelay debug channel allows you to see calls marshalled by
|
|
|
|
* the typelib marshaller. It is not a generic COM relaying system.
|
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-02-05 19:11:17 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2002-02-05 19:11:17 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
2004-10-07 05:06:48 +02:00
|
|
|
#define COBJMACROS
|
2003-01-07 21:36:20 +01:00
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
2004-10-07 05:06:48 +02:00
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
#include "winerror.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2003-08-20 20:22:31 +02:00
|
|
|
#include "winbase.h"
|
2002-02-05 19:11:17 +01:00
|
|
|
#include "winnls.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "winuser.h"
|
2006-07-17 21:19:27 +02:00
|
|
|
#include "excpt.h"
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
|
|
#include "ole2.h"
|
2006-05-10 13:11:22 +02:00
|
|
|
#include "propidl.h" /* for LPSAFEARRAY_User* functions */
|
2002-02-05 19:11:17 +01:00
|
|
|
#include "typelib.h"
|
2006-01-27 12:54:03 +01:00
|
|
|
#include "variant.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2006-07-17 21:19:27 +02:00
|
|
|
#include "wine/exception.h"
|
2002-02-05 19:11:17 +01:00
|
|
|
|
2005-03-27 19:51:59 +02:00
|
|
|
static const WCHAR IDispatchW[] = { 'I','D','i','s','p','a','t','c','h',0};
|
2002-02-05 19:11:17 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(olerelay);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
2004-08-13 02:44:22 +02:00
|
|
|
#define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
typedef struct _marshal_state {
|
|
|
|
LPBYTE base;
|
|
|
|
int size;
|
|
|
|
int curoff;
|
|
|
|
} marshal_state;
|
|
|
|
|
2004-06-18 01:03:26 +02:00
|
|
|
/* used in the olerelay code to avoid having the L"" stuff added by debugstr_w */
|
|
|
|
static char *relaystr(WCHAR *in) {
|
|
|
|
char *tmp = (char *)debugstr_w(in);
|
|
|
|
tmp += 2;
|
|
|
|
tmp[strlen(tmp)-1] = '\0';
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
static HRESULT
|
2006-05-10 12:55:37 +02:00
|
|
|
xbuf_resize(marshal_state *buf, DWORD newsize)
|
|
|
|
{
|
|
|
|
if(buf->size >= newsize)
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
if(buf->base)
|
|
|
|
{
|
|
|
|
buf->base = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, buf->base, newsize);
|
|
|
|
if(!buf->base)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buf->base = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, newsize);
|
|
|
|
if(!buf->base)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2006-05-15 11:02:48 +02:00
|
|
|
buf->size = newsize;
|
2006-05-10 12:55:37 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT
|
|
|
|
xbuf_add(marshal_state *buf, LPBYTE stuff, DWORD size)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if(buf->size - buf->curoff < size)
|
|
|
|
{
|
|
|
|
hr = xbuf_resize(buf, buf->size + size + 100);
|
|
|
|
if(FAILED(hr)) return hr;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
memcpy(buf->base+buf->curoff,stuff,size);
|
|
|
|
buf->curoff += size;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT
|
|
|
|
xbuf_get(marshal_state *buf, LPBYTE stuff, DWORD size) {
|
|
|
|
if (buf->size < buf->curoff+size) return E_FAIL;
|
|
|
|
memcpy(stuff,buf->base+buf->curoff,size);
|
|
|
|
buf->curoff += size;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT
|
|
|
|
xbuf_skip(marshal_state *buf, DWORD size) {
|
|
|
|
if (buf->size < buf->curoff+size) return E_FAIL;
|
|
|
|
buf->curoff += size;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT
|
|
|
|
_unmarshal_interface(marshal_state *buf, REFIID riid, LPUNKNOWN *pUnk) {
|
|
|
|
IStream *pStm;
|
|
|
|
ULARGE_INTEGER newpos;
|
|
|
|
LARGE_INTEGER seekto;
|
|
|
|
ULONG res;
|
|
|
|
HRESULT hres;
|
|
|
|
DWORD xsize;
|
|
|
|
|
|
|
|
TRACE("...%s...\n",debugstr_guid(riid));
|
2005-01-27 12:11:32 +01:00
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
*pUnk = NULL;
|
|
|
|
hres = xbuf_get(buf,(LPBYTE)&xsize,sizeof(xsize));
|
2005-01-27 12:11:32 +01:00
|
|
|
if (hres) {
|
|
|
|
ERR("xbuf_get failed\n");
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
if (xsize == 0) return S_OK;
|
2005-01-27 12:11:32 +01:00
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
|
|
|
|
if (hres) {
|
2006-10-12 20:57:10 +02:00
|
|
|
ERR("Stream create failed %x\n",hres);
|
2002-02-05 19:11:17 +01:00
|
|
|
return hres;
|
|
|
|
}
|
2005-01-27 12:11:32 +01:00
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
hres = IStream_Write(pStm,buf->base+buf->curoff,xsize,&res);
|
2005-01-27 12:11:32 +01:00
|
|
|
if (hres) {
|
2006-10-12 20:57:10 +02:00
|
|
|
ERR("stream write %x\n",hres);
|
2005-01-27 12:11:32 +01:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
memset(&seekto,0,sizeof(seekto));
|
|
|
|
hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
|
2005-01-27 12:11:32 +01:00
|
|
|
if (hres) {
|
2006-10-12 20:57:10 +02:00
|
|
|
ERR("Failed Seek %x\n",hres);
|
2005-01-27 12:11:32 +01:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
hres = CoUnmarshalInterface(pStm,riid,(LPVOID*)pUnk);
|
|
|
|
if (hres) {
|
2006-10-12 20:57:10 +02:00
|
|
|
ERR("Unmarshalling interface %s failed with %x\n",debugstr_guid(riid),hres);
|
2002-02-05 19:11:17 +01:00
|
|
|
return hres;
|
|
|
|
}
|
2005-01-27 12:11:32 +01:00
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
IStream_Release(pStm);
|
|
|
|
return xbuf_skip(buf,xsize);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT
|
|
|
|
_marshal_interface(marshal_state *buf, REFIID riid, LPUNKNOWN pUnk) {
|
2005-01-27 12:11:32 +01:00
|
|
|
LPBYTE tempbuf = NULL;
|
|
|
|
IStream *pStm = NULL;
|
2002-02-05 19:11:17 +01:00
|
|
|
STATSTG ststg;
|
|
|
|
ULARGE_INTEGER newpos;
|
|
|
|
LARGE_INTEGER seekto;
|
|
|
|
ULONG res;
|
|
|
|
DWORD xsize;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2005-01-27 12:11:32 +01:00
|
|
|
if (!pUnk) {
|
2005-03-29 15:06:44 +02:00
|
|
|
/* this is valid, if for instance we serialize
|
|
|
|
* a VT_DISPATCH with NULL ptr which apparently
|
|
|
|
* can happen. S_OK to make sure we continue
|
|
|
|
* serializing.
|
|
|
|
*/
|
2006-01-18 11:29:01 +01:00
|
|
|
WARN("pUnk is NULL\n");
|
2005-03-29 15:06:44 +02:00
|
|
|
xsize = 0;
|
|
|
|
return xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
|
2005-01-27 12:11:32 +01:00
|
|
|
}
|
2002-02-05 19:11:17 +01:00
|
|
|
|
2005-03-29 15:06:44 +02:00
|
|
|
hres = E_FAIL;
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
TRACE("...%s...\n",debugstr_guid(riid));
|
2005-01-27 12:11:32 +01:00
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
|
|
|
|
if (hres) {
|
2006-10-12 20:57:10 +02:00
|
|
|
ERR("Stream create failed %x\n",hres);
|
2002-02-05 19:11:17 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
2005-01-27 12:11:32 +01:00
|
|
|
|
2005-08-24 11:44:41 +02:00
|
|
|
hres = CoMarshalInterface(pStm,riid,pUnk,0,NULL,0);
|
2002-02-05 19:11:17 +01:00
|
|
|
if (hres) {
|
2006-10-12 20:57:10 +02:00
|
|
|
ERR("Marshalling interface %s failed with %x\n", debugstr_guid(riid), hres);
|
2002-02-05 19:11:17 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
2005-01-27 12:11:32 +01:00
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
hres = IStream_Stat(pStm,&ststg,0);
|
2005-01-27 12:11:32 +01:00
|
|
|
if (hres) {
|
|
|
|
ERR("Stream stat failed\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
tempbuf = HeapAlloc(GetProcessHeap(), 0, ststg.cbSize.u.LowPart);
|
2002-02-05 19:11:17 +01:00
|
|
|
memset(&seekto,0,sizeof(seekto));
|
|
|
|
hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
|
2005-01-27 12:11:32 +01:00
|
|
|
if (hres) {
|
2006-10-12 20:57:10 +02:00
|
|
|
ERR("Failed Seek %x\n",hres);
|
2005-01-27 12:11:32 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
hres = IStream_Read(pStm,tempbuf,ststg.cbSize.u.LowPart,&res);
|
2005-01-27 12:11:32 +01:00
|
|
|
if (hres) {
|
2006-10-12 20:57:10 +02:00
|
|
|
ERR("Failed Read %x\n",hres);
|
2005-01-27 12:11:32 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
xsize = ststg.cbSize.u.LowPart;
|
2002-02-05 19:11:17 +01:00
|
|
|
xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
|
2004-01-23 02:51:33 +01:00
|
|
|
hres = xbuf_add(buf,tempbuf,ststg.cbSize.u.LowPart);
|
2005-01-27 12:11:32 +01:00
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
HeapFree(GetProcessHeap(),0,tempbuf);
|
2005-01-27 12:11:32 +01:00
|
|
|
IStream_Release(pStm);
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
return hres;
|
2005-01-27 12:11:32 +01:00
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
fail:
|
|
|
|
xsize = 0;
|
|
|
|
xbuf_add(buf,(LPBYTE)&xsize,sizeof(xsize));
|
2005-01-27 12:11:32 +01:00
|
|
|
if (pStm) IUnknown_Release(pStm);
|
|
|
|
HeapFree(GetProcessHeap(), 0, tempbuf);
|
2002-02-05 19:11:17 +01:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************* OLE Proxy/Stub Factory ********************************/
|
|
|
|
static HRESULT WINAPI
|
|
|
|
PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface, REFIID iid, LPVOID *ppv) {
|
|
|
|
if (IsEqualIID(iid,&IID_IPSFactoryBuffer)||IsEqualIID(iid,&IID_IUnknown)) {
|
2002-06-01 01:06:46 +02:00
|
|
|
*ppv = (LPVOID)iface;
|
2002-02-05 19:11:17 +01:00
|
|
|
/* No ref counting, static class */
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
FIXME("(%s) unknown IID?\n",debugstr_guid(iid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI PSFacBuf_AddRef(LPPSFACTORYBUFFER iface) { return 2; }
|
|
|
|
static ULONG WINAPI PSFacBuf_Release(LPPSFACTORYBUFFER iface) { return 1; }
|
|
|
|
|
|
|
|
static HRESULT
|
|
|
|
_get_typeinfo_for_iid(REFIID riid, ITypeInfo**ti) {
|
|
|
|
HRESULT hres;
|
|
|
|
HKEY ikey;
|
|
|
|
char tlguid[200],typelibkey[300],interfacekey[300],ver[100];
|
|
|
|
char tlfn[260];
|
|
|
|
OLECHAR tlfnW[260];
|
2005-07-06 21:08:05 +02:00
|
|
|
DWORD tlguidlen, verlen, type;
|
|
|
|
LONG tlfnlen;
|
2002-02-05 19:11:17 +01:00
|
|
|
ITypeLib *tl;
|
|
|
|
|
2006-10-15 12:27:34 +02:00
|
|
|
sprintf( interfacekey, "Interface\\{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\Typelib",
|
2002-02-05 19:11:17 +01:00
|
|
|
riid->Data1, riid->Data2, riid->Data3,
|
|
|
|
riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
|
|
|
|
riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7]
|
|
|
|
);
|
|
|
|
|
|
|
|
if (RegOpenKeyA(HKEY_CLASSES_ROOT,interfacekey,&ikey)) {
|
2005-01-27 12:11:32 +01:00
|
|
|
ERR("No %s key found.\n",interfacekey);
|
2002-02-05 19:11:17 +01:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
type = (1<<REG_SZ);
|
|
|
|
tlguidlen = sizeof(tlguid);
|
2005-07-06 21:08:05 +02:00
|
|
|
if (RegQueryValueExA(ikey,NULL,NULL,&type,(LPBYTE)tlguid,&tlguidlen)) {
|
2005-01-27 12:11:32 +01:00
|
|
|
ERR("Getting typelib guid failed.\n");
|
2002-02-05 19:11:17 +01:00
|
|
|
RegCloseKey(ikey);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
type = (1<<REG_SZ);
|
|
|
|
verlen = sizeof(ver);
|
2005-07-06 21:08:05 +02:00
|
|
|
if (RegQueryValueExA(ikey,"Version",NULL,&type,(LPBYTE)ver,&verlen)) {
|
2005-01-27 12:11:32 +01:00
|
|
|
ERR("Could not get version value?\n");
|
2002-02-05 19:11:17 +01:00
|
|
|
RegCloseKey(ikey);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
RegCloseKey(ikey);
|
|
|
|
sprintf(typelibkey,"Typelib\\%s\\%s\\0\\win32",tlguid,ver);
|
|
|
|
tlfnlen = sizeof(tlfn);
|
|
|
|
if (RegQueryValueA(HKEY_CLASSES_ROOT,typelibkey,tlfn,&tlfnlen)) {
|
2005-01-27 12:11:32 +01:00
|
|
|
ERR("Could not get typelib fn?\n");
|
2002-02-05 19:11:17 +01:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
2006-05-12 00:07:59 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, tlfn, -1, tlfnW, sizeof(tlfnW) / sizeof(tlfnW[0]));
|
2002-02-05 19:11:17 +01:00
|
|
|
hres = LoadTypeLib(tlfnW,&tl);
|
|
|
|
if (hres) {
|
|
|
|
ERR("Failed to load typelib for %s, but it should be there.\n",debugstr_guid(riid));
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
hres = ITypeLib_GetTypeInfoOfGuid(tl,riid,ti);
|
|
|
|
if (hres) {
|
|
|
|
ERR("typelib does not contain info for %s?\n",debugstr_guid(riid));
|
|
|
|
ITypeLib_Release(tl);
|
|
|
|
return hres;
|
|
|
|
}
|
2006-10-23 12:38:20 +02:00
|
|
|
ITypeLib_Release(tl);
|
2002-02-05 19:11:17 +01:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine nr of functions. Since we use the toplevel interface and all
|
2002-06-01 01:06:46 +02:00
|
|
|
* inherited ones have lower numbers, we are ok to not to descent into
|
2002-02-05 19:11:17 +01:00
|
|
|
* the inheritance tree I think.
|
|
|
|
*/
|
|
|
|
static int _nroffuncs(ITypeInfo *tinfo) {
|
2007-01-02 16:39:48 +01:00
|
|
|
int n, i, j;
|
2005-12-06 21:24:19 +01:00
|
|
|
const FUNCDESC *fdesc;
|
2002-02-05 19:11:17 +01:00
|
|
|
HRESULT hres;
|
2007-01-02 16:39:48 +01:00
|
|
|
TYPEATTR *attr;
|
|
|
|
ITypeInfo *tinfo2;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
|
|
n=0;
|
2007-01-02 16:39:48 +01:00
|
|
|
hres = ITypeInfo_GetTypeAttr(tinfo, &attr);
|
|
|
|
if (hres) {
|
|
|
|
ERR("GetTypeAttr failed with %x\n",hres);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
/* look in inherited ifaces. */
|
|
|
|
for (j=0;j<attr->cImplTypes;j++) {
|
|
|
|
HREFTYPE href;
|
|
|
|
hres = ITypeInfo_GetRefTypeOfImplType(tinfo, j, &href);
|
|
|
|
if (hres) {
|
|
|
|
ERR("Did not find a reftype for interface offset %d?\n",j);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
hres = ITypeInfo_GetRefTypeInfo(tinfo, href, &tinfo2);
|
|
|
|
if (hres) {
|
|
|
|
ERR("Did not find a typeinfo for reftype %d?\n",href);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
n += _nroffuncs(tinfo2);
|
|
|
|
ITypeInfo_Release(tinfo2);
|
|
|
|
}
|
|
|
|
i = 0;
|
2002-02-05 19:11:17 +01:00
|
|
|
while (1) {
|
2007-01-02 16:39:48 +01:00
|
|
|
hres = ITypeInfoImpl_GetInternalFuncDesc(tinfo,i,&fdesc);
|
2002-02-05 19:11:17 +01:00
|
|
|
if (hres)
|
2007-01-02 16:39:48 +01:00
|
|
|
return n;
|
2002-02-05 19:11:17 +01:00
|
|
|
n++;
|
2007-01-02 16:39:48 +01:00
|
|
|
i++;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
|
|
|
|
2004-09-07 22:42:26 +02:00
|
|
|
#ifdef __i386__
|
|
|
|
|
2004-01-09 23:18:49 +01:00
|
|
|
#include "pshpack1.h"
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
typedef struct _TMAsmProxy {
|
|
|
|
BYTE popleax;
|
|
|
|
BYTE pushlval;
|
|
|
|
BYTE nr;
|
|
|
|
BYTE pushleax;
|
|
|
|
BYTE lcall;
|
|
|
|
DWORD xcall;
|
|
|
|
BYTE lret;
|
|
|
|
WORD bytestopop;
|
2004-01-09 23:18:49 +01:00
|
|
|
} TMAsmProxy;
|
|
|
|
|
|
|
|
#include "poppack.h"
|
2002-02-05 19:11:17 +01:00
|
|
|
|
2004-09-07 22:42:26 +02:00
|
|
|
#else /* __i386__ */
|
2005-10-19 21:06:49 +02:00
|
|
|
# warning You need to implement stubless proxies for your architecture
|
|
|
|
typedef struct _TMAsmProxy {
|
|
|
|
} TMAsmProxy;
|
2004-09-07 22:42:26 +02:00
|
|
|
#endif
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
typedef struct _TMProxyImpl {
|
2005-06-06 21:50:35 +02:00
|
|
|
LPVOID *lpvtbl;
|
|
|
|
const IRpcProxyBufferVtbl *lpvtbl2;
|
2005-07-11 12:25:19 +02:00
|
|
|
LONG ref;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
|
|
TMAsmProxy *asmstubs;
|
|
|
|
ITypeInfo* tinfo;
|
|
|
|
IRpcChannelBuffer* chanbuf;
|
|
|
|
IID iid;
|
2004-09-07 22:42:26 +02:00
|
|
|
CRITICAL_SECTION crit;
|
2005-03-11 11:18:31 +01:00
|
|
|
IUnknown *outerunknown;
|
2005-10-26 12:12:30 +02:00
|
|
|
IDispatch *dispatch;
|
2006-02-07 16:26:23 +01:00
|
|
|
IRpcProxyBuffer *dispatch_proxy;
|
2002-02-05 19:11:17 +01:00
|
|
|
} TMProxyImpl;
|
|
|
|
|
|
|
|
static HRESULT WINAPI
|
2004-09-07 22:42:26 +02:00
|
|
|
TMProxyImpl_QueryInterface(LPRPCPROXYBUFFER iface, REFIID riid, LPVOID *ppv)
|
|
|
|
{
|
2002-02-05 19:11:17 +01:00
|
|
|
TRACE("()\n");
|
|
|
|
if (IsEqualIID(riid,&IID_IUnknown)||IsEqualIID(riid,&IID_IRpcProxyBuffer)) {
|
2004-09-07 22:42:26 +02:00
|
|
|
*ppv = (LPVOID)iface;
|
|
|
|
IRpcProxyBuffer_AddRef(iface);
|
|
|
|
return S_OK;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
FIXME("no interface for %s\n",debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI
|
2004-09-07 22:42:26 +02:00
|
|
|
TMProxyImpl_AddRef(LPRPCPROXYBUFFER iface)
|
|
|
|
{
|
2002-02-05 19:11:17 +01:00
|
|
|
ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
|
2005-01-14 17:02:20 +01:00
|
|
|
ULONG refCount = InterlockedIncrement(&This->ref);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
2006-10-12 20:57:10 +02:00
|
|
|
TRACE("(%p)->(ref before=%u)\n",This, refCount - 1);
|
2004-09-07 22:42:26 +02:00
|
|
|
|
2005-01-14 17:02:20 +01:00
|
|
|
return refCount;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI
|
2004-09-07 22:42:26 +02:00
|
|
|
TMProxyImpl_Release(LPRPCPROXYBUFFER iface)
|
|
|
|
{
|
2002-02-05 19:11:17 +01:00
|
|
|
ICOM_THIS_MULTI(TMProxyImpl,lpvtbl2,iface);
|
2005-01-14 17:02:20 +01:00
|
|
|
ULONG refCount = InterlockedDecrement(&This->ref);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
2006-10-12 20:57:10 +02:00
|
|
|
TRACE("(%p)->(ref before=%u)\n",This, refCount + 1);
|
2004-09-07 22:42:26 +02:00
|
|
|
|
2005-01-14 17:02:20 +01:00
|
|
|
if (!refCount)
|
2004-09-07 22:42:26 +02:00
|
|
|
{
|
2006-02-07 16:26:23 +01:00
|
|
|
if (This->dispatch_proxy) IRpcProxyBuffer_Release(This->dispatch_proxy);
|
2004-09-07 22:42:26 +02:00
|
|
|
DeleteCriticalSection(&This->crit);
|
|
|
|
if (This->chanbuf) IRpcChannelBuffer_Release(This->chanbuf);
|
|
|
|
VirtualFree(This->asmstubs, 0, MEM_RELEASE);
|
2006-09-27 16:51:26 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->lpvtbl);
|
2006-10-23 12:38:20 +02:00
|
|
|
ITypeInfo_Release(This->tinfo);
|
2004-09-07 22:42:26 +02:00
|
|
|
CoTaskMemFree(This);
|
|
|
|
}
|
2005-01-14 17:02:20 +01:00
|
|
|
return refCount;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI
|
|
|
|
TMProxyImpl_Connect(
|
2004-09-07 22:42:26 +02:00
|
|
|
LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer)
|
|
|
|
{
|
|
|
|
ICOM_THIS_MULTI(TMProxyImpl, lpvtbl2, iface);
|
|
|
|
|
|
|
|
TRACE("(%p)\n", pRpcChannelBuffer);
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->crit);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
2004-09-07 22:42:26 +02:00
|
|
|
IRpcChannelBuffer_AddRef(pRpcChannelBuffer);
|
2002-02-05 19:11:17 +01:00
|
|
|
This->chanbuf = pRpcChannelBuffer;
|
2004-09-07 22:42:26 +02:00
|
|
|
|
|
|
|
LeaveCriticalSection(&This->crit);
|
|
|
|
|
2006-02-07 16:26:23 +01:00
|
|
|
if (This->dispatch_proxy)
|
|
|
|
IRpcProxyBuffer_Connect(This->dispatch_proxy, pRpcChannelBuffer);
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI
|
2004-09-07 22:42:26 +02:00
|
|
|
TMProxyImpl_Disconnect(LPRPCPROXYBUFFER iface)
|
|
|
|
{
|
|
|
|
ICOM_THIS_MULTI(TMProxyImpl, lpvtbl2, iface);
|
|
|
|
|
|
|
|
TRACE("()\n");
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->crit);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
|
|
IRpcChannelBuffer_Release(This->chanbuf);
|
|
|
|
This->chanbuf = NULL;
|
2004-09-07 22:42:26 +02:00
|
|
|
|
|
|
|
LeaveCriticalSection(&This->crit);
|
2006-02-07 16:26:23 +01:00
|
|
|
|
|
|
|
if (This->dispatch_proxy)
|
|
|
|
IRpcProxyBuffer_Disconnect(This->dispatch_proxy);
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IRpcProxyBufferVtbl tmproxyvtable = {
|
2002-02-05 19:11:17 +01:00
|
|
|
TMProxyImpl_QueryInterface,
|
|
|
|
TMProxyImpl_AddRef,
|
|
|
|
TMProxyImpl_Release,
|
|
|
|
TMProxyImpl_Connect,
|
|
|
|
TMProxyImpl_Disconnect
|
|
|
|
};
|
|
|
|
|
2002-06-10 04:30:20 +02:00
|
|
|
/* how much space do we use on stack in DWORD steps. */
|
2004-09-27 22:33:27 +02:00
|
|
|
int
|
2002-06-10 04:30:20 +02:00
|
|
|
_argsize(DWORD vt) {
|
|
|
|
switch (vt) {
|
2005-11-04 12:13:55 +01:00
|
|
|
case VT_UI8:
|
|
|
|
return 8/sizeof(DWORD);
|
2005-06-09 11:43:38 +02:00
|
|
|
case VT_R8:
|
|
|
|
return sizeof(double)/sizeof(DWORD);
|
|
|
|
case VT_CY:
|
|
|
|
return sizeof(CY)/sizeof(DWORD);
|
2002-06-14 02:36:42 +02:00
|
|
|
case VT_DATE:
|
|
|
|
return sizeof(DATE)/sizeof(DWORD);
|
2002-06-10 04:30:20 +02:00
|
|
|
case VT_VARIANT:
|
|
|
|
return (sizeof(VARIANT)+3)/sizeof(DWORD);
|
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_xsize(TYPEDESC *td) {
|
|
|
|
switch (td->vt) {
|
2002-06-14 02:36:42 +02:00
|
|
|
case VT_DATE:
|
|
|
|
return sizeof(DATE);
|
2002-06-10 04:30:20 +02:00
|
|
|
case VT_VARIANT:
|
|
|
|
return sizeof(VARIANT)+3;
|
|
|
|
case VT_CARRAY: {
|
|
|
|
int i, arrsize = 1;
|
|
|
|
ARRAYDESC *adesc = td->u.lpadesc;
|
|
|
|
|
|
|
|
for (i=0;i<adesc->cDims;i++)
|
|
|
|
arrsize *= adesc->rgbounds[i].cElements;
|
|
|
|
return arrsize*_xsize(&adesc->tdescElem);
|
|
|
|
}
|
2005-11-04 12:13:55 +01:00
|
|
|
case VT_UI8:
|
|
|
|
case VT_I8:
|
|
|
|
return 8;
|
2002-06-10 04:30:20 +02:00
|
|
|
case VT_UI2:
|
|
|
|
case VT_I2:
|
|
|
|
return 2;
|
|
|
|
case VT_UI1:
|
|
|
|
case VT_I1:
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
static HRESULT
|
2002-06-10 04:30:20 +02:00
|
|
|
serialize_param(
|
|
|
|
ITypeInfo *tinfo,
|
|
|
|
BOOL writeit,
|
|
|
|
BOOL debugout,
|
|
|
|
BOOL dealloc,
|
|
|
|
TYPEDESC *tdesc,
|
|
|
|
DWORD *arg,
|
2004-09-07 22:42:26 +02:00
|
|
|
marshal_state *buf)
|
|
|
|
{
|
2002-06-10 04:30:20 +02:00
|
|
|
HRESULT hres = S_OK;
|
|
|
|
|
2006-01-27 12:54:03 +01:00
|
|
|
TRACE("(tdesc.vt %s)\n",debugstr_vt(tdesc->vt));
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
|
|
switch (tdesc->vt) {
|
2002-06-10 04:30:20 +02:00
|
|
|
case VT_EMPTY: /* nothing. empty variant for instance */
|
2002-02-05 19:11:17 +01:00
|
|
|
return S_OK;
|
2005-11-04 12:13:55 +01:00
|
|
|
case VT_I8:
|
|
|
|
case VT_UI8:
|
2006-01-14 17:47:25 +01:00
|
|
|
case VT_CY:
|
2005-11-04 12:13:55 +01:00
|
|
|
hres = S_OK;
|
2006-10-18 21:21:57 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("%x%x\n",arg[0],arg[1]);
|
2005-11-04 12:13:55 +01:00
|
|
|
if (writeit)
|
|
|
|
hres = xbuf_add(buf,(LPBYTE)arg,8);
|
|
|
|
return hres;
|
2002-02-05 19:11:17 +01:00
|
|
|
case VT_BOOL:
|
2002-06-10 04:30:20 +02:00
|
|
|
case VT_ERROR:
|
2006-02-07 16:26:02 +01:00
|
|
|
case VT_INT:
|
2002-06-10 04:30:20 +02:00
|
|
|
case VT_UINT:
|
2002-02-05 19:11:17 +01:00
|
|
|
case VT_I4:
|
2002-12-05 20:12:50 +01:00
|
|
|
case VT_R4:
|
2005-03-14 11:09:11 +01:00
|
|
|
case VT_UI4:
|
2005-03-27 20:17:19 +02:00
|
|
|
hres = S_OK;
|
2006-10-18 21:21:57 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("%x\n",*arg);
|
2005-03-27 20:17:19 +02:00
|
|
|
if (writeit)
|
|
|
|
hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
|
|
|
|
return hres;
|
|
|
|
case VT_I2:
|
2002-06-10 04:30:20 +02:00
|
|
|
case VT_UI2:
|
2005-03-27 20:17:19 +02:00
|
|
|
hres = S_OK;
|
2006-10-18 21:21:57 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("%04x\n",*arg & 0xffff);
|
2005-03-27 20:17:19 +02:00
|
|
|
if (writeit)
|
|
|
|
hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
|
|
|
|
return hres;
|
|
|
|
case VT_I1:
|
2002-06-10 04:30:20 +02:00
|
|
|
case VT_UI1:
|
|
|
|
hres = S_OK;
|
2006-10-18 21:21:57 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("%02x\n",*arg & 0xff);
|
2002-06-10 04:30:20 +02:00
|
|
|
if (writeit)
|
|
|
|
hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
|
|
|
|
return hres;
|
2005-03-29 13:29:11 +02:00
|
|
|
case VT_I4|VT_BYREF:
|
|
|
|
hres = S_OK;
|
2006-10-18 21:21:57 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("&0x%x\n",*arg);
|
2005-03-29 13:29:11 +02:00
|
|
|
if (writeit)
|
|
|
|
hres = xbuf_add(buf,(LPBYTE)(DWORD*)*arg,sizeof(DWORD));
|
|
|
|
/* do not dealloc at this time */
|
|
|
|
return hres;
|
2002-02-05 19:11:17 +01:00
|
|
|
case VT_VARIANT: {
|
2002-06-10 04:30:20 +02:00
|
|
|
TYPEDESC tdesc2;
|
|
|
|
VARIANT *vt = (VARIANT*)arg;
|
|
|
|
DWORD vttype = V_VT(vt);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
2006-01-27 12:54:03 +01:00
|
|
|
if (debugout) TRACE_(olerelay)("Vt(%s%s)(",debugstr_vt(vttype),debugstr_vf(vttype));
|
2002-02-05 19:11:17 +01:00
|
|
|
tdesc2.vt = vttype;
|
2002-06-10 04:30:20 +02:00
|
|
|
if (writeit) {
|
|
|
|
hres = xbuf_add(buf,(LPBYTE)&vttype,sizeof(vttype));
|
|
|
|
if (hres) return hres;
|
|
|
|
}
|
|
|
|
/* need to recurse since we need to free the stuff */
|
2005-08-08 20:38:29 +02:00
|
|
|
hres = serialize_param(tinfo,writeit,debugout,dealloc,&tdesc2,(DWORD*)&(V_I4(vt)),buf);
|
2004-06-18 01:03:26 +02:00
|
|
|
if (debugout) TRACE_(olerelay)(")");
|
2002-06-10 04:30:20 +02:00
|
|
|
return hres;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
2005-03-14 11:09:11 +01:00
|
|
|
case VT_BSTR|VT_BYREF: {
|
2005-03-29 13:29:11 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("[byref]'%s'", *(BSTR*)*arg ? relaystr(*((BSTR*)*arg)) : "<bstr NULL>");
|
2005-03-14 11:09:11 +01:00
|
|
|
if (writeit) {
|
|
|
|
/* ptr to ptr to magic widestring, basically */
|
|
|
|
BSTR *bstr = (BSTR *) *arg;
|
2005-07-19 21:42:50 +02:00
|
|
|
DWORD len;
|
2005-03-29 13:29:11 +02:00
|
|
|
if (!*bstr) {
|
2005-03-14 11:09:11 +01:00
|
|
|
/* -1 means "null string" which is equivalent to empty string */
|
2005-07-19 21:42:50 +02:00
|
|
|
len = -1;
|
|
|
|
hres = xbuf_add(buf, (LPBYTE)&len,sizeof(DWORD));
|
|
|
|
if (hres) return hres;
|
2005-03-14 11:09:11 +01:00
|
|
|
} else {
|
2005-07-19 21:42:50 +02:00
|
|
|
len = *((DWORD*)*bstr-1)/sizeof(WCHAR);
|
|
|
|
hres = xbuf_add(buf,(LPBYTE)&len,sizeof(DWORD));
|
|
|
|
if (hres) return hres;
|
|
|
|
hres = xbuf_add(buf,(LPBYTE)*bstr,len * sizeof(WCHAR));
|
|
|
|
if (hres) return hres;
|
2005-03-14 11:09:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dealloc && arg) {
|
|
|
|
BSTR *str = *((BSTR **)arg);
|
|
|
|
SysFreeString(*str);
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2002-06-10 04:30:20 +02:00
|
|
|
case VT_BSTR: {
|
|
|
|
if (debugout) {
|
2005-03-27 20:20:10 +02:00
|
|
|
if (*arg)
|
|
|
|
TRACE_(olerelay)("%s",relaystr((WCHAR*)*arg));
|
2002-06-10 04:30:20 +02:00
|
|
|
else
|
2004-06-18 01:03:26 +02:00
|
|
|
TRACE_(olerelay)("<bstr NULL>");
|
2002-06-10 04:30:20 +02:00
|
|
|
}
|
|
|
|
if (writeit) {
|
2005-07-19 21:42:50 +02:00
|
|
|
BSTR bstr = (BSTR)*arg;
|
|
|
|
DWORD len;
|
|
|
|
if (!bstr) {
|
|
|
|
len = -1;
|
|
|
|
hres = xbuf_add(buf,(LPBYTE)&len,sizeof(DWORD));
|
|
|
|
if (hres) return hres;
|
2002-06-10 04:30:20 +02:00
|
|
|
} else {
|
2005-07-19 21:42:50 +02:00
|
|
|
len = *((DWORD*)bstr-1)/sizeof(WCHAR);
|
|
|
|
hres = xbuf_add(buf,(LPBYTE)&len,sizeof(DWORD));
|
|
|
|
if (hres) return hres;
|
|
|
|
hres = xbuf_add(buf,(LPBYTE)bstr,len * sizeof(WCHAR));
|
|
|
|
if (hres) return hres;
|
2002-06-10 04:30:20 +02:00
|
|
|
}
|
|
|
|
}
|
2003-12-01 23:36:49 +01:00
|
|
|
|
2002-06-10 04:30:20 +02:00
|
|
|
if (dealloc && arg)
|
2003-12-01 23:36:49 +01:00
|
|
|
SysFreeString((BSTR)*arg);
|
2002-06-10 04:30:20 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case VT_PTR: {
|
|
|
|
DWORD cookie;
|
2005-09-07 11:23:04 +02:00
|
|
|
BOOL derefhere = TRUE;
|
2005-06-09 11:43:38 +02:00
|
|
|
|
2005-09-07 11:23:04 +02:00
|
|
|
if (tdesc->u.lptdesc->vt == VT_USERDEFINED) {
|
|
|
|
ITypeInfo *tinfo2;
|
|
|
|
TYPEATTR *tattr;
|
|
|
|
|
|
|
|
hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.lptdesc->u.hreftype,&tinfo2);
|
|
|
|
if (hres) {
|
2006-10-12 20:57:10 +02:00
|
|
|
ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc->u.lptdesc->u.hreftype);
|
2005-09-07 11:23:04 +02:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
ITypeInfo_GetTypeAttr(tinfo2,&tattr);
|
|
|
|
switch (tattr->typekind) {
|
|
|
|
case TKIND_ENUM: /* confirmed */
|
|
|
|
case TKIND_RECORD: /* FIXME: mostly untested */
|
|
|
|
derefhere=TRUE;
|
|
|
|
break;
|
|
|
|
case TKIND_ALIAS: /* FIXME: untested */
|
|
|
|
case TKIND_DISPATCH: /* will be done in VT_USERDEFINED case */
|
|
|
|
case TKIND_INTERFACE: /* will be done in VT_USERDEFINED case */
|
|
|
|
derefhere=FALSE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("unhandled switch cases tattr->typekind %d\n", tattr->typekind);
|
|
|
|
derefhere=FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2006-10-23 12:38:20 +02:00
|
|
|
ITypeInfo_ReleaseTypeAttr(tinfo, tattr);
|
2005-09-07 11:23:04 +02:00
|
|
|
ITypeInfo_Release(tinfo2);
|
|
|
|
}
|
2002-06-10 04:30:20 +02:00
|
|
|
|
2004-06-18 01:03:26 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("*");
|
2005-03-27 19:51:59 +02:00
|
|
|
/* Write always, so the other side knows when it gets a NULL pointer.
|
|
|
|
*/
|
|
|
|
cookie = *arg ? 0x42424242 : 0;
|
|
|
|
hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
|
|
|
|
if (hres)
|
|
|
|
return hres;
|
2002-06-10 04:30:20 +02:00
|
|
|
if (!*arg) {
|
2004-06-18 01:03:26 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("NULL");
|
2002-06-10 04:30:20 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
hres = serialize_param(tinfo,writeit,debugout,dealloc,tdesc->u.lptdesc,(DWORD*)*arg,buf);
|
2005-06-09 11:43:38 +02:00
|
|
|
if (derefhere && dealloc) HeapFree(GetProcessHeap(),0,(LPVOID)*arg);
|
2002-02-05 19:11:17 +01:00
|
|
|
return hres;
|
2002-06-10 04:30:20 +02:00
|
|
|
}
|
|
|
|
case VT_UNKNOWN:
|
2006-10-12 20:57:10 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("unk(0x%x)",*arg);
|
2002-06-10 04:30:20 +02:00
|
|
|
if (writeit)
|
|
|
|
hres = _marshal_interface(buf,&IID_IUnknown,(LPUNKNOWN)*arg);
|
2006-02-14 11:33:03 +01:00
|
|
|
if (dealloc && *(IUnknown **)arg)
|
2006-02-07 16:25:42 +01:00
|
|
|
IUnknown_Release((LPUNKNOWN)*arg);
|
2002-06-10 04:30:20 +02:00
|
|
|
return hres;
|
|
|
|
case VT_DISPATCH:
|
2006-10-12 20:57:10 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("idisp(0x%x)",*arg);
|
2002-06-10 04:30:20 +02:00
|
|
|
if (writeit)
|
|
|
|
hres = _marshal_interface(buf,&IID_IDispatch,(LPUNKNOWN)*arg);
|
2006-02-14 11:33:03 +01:00
|
|
|
if (dealloc && *(IUnknown **)arg)
|
2006-02-07 16:25:42 +01:00
|
|
|
IUnknown_Release((LPUNKNOWN)*arg);
|
2002-06-10 04:30:20 +02:00
|
|
|
return hres;
|
|
|
|
case VT_VOID:
|
2004-06-18 01:03:26 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("<void>");
|
2002-06-10 04:30:20 +02:00
|
|
|
return S_OK;
|
2002-02-05 19:11:17 +01:00
|
|
|
case VT_USERDEFINED: {
|
|
|
|
ITypeInfo *tinfo2;
|
|
|
|
TYPEATTR *tattr;
|
|
|
|
|
|
|
|
hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
|
|
|
|
if (hres) {
|
2006-10-12 20:57:10 +02:00
|
|
|
ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc->u.hreftype);
|
2002-02-05 19:11:17 +01:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
ITypeInfo_GetTypeAttr(tinfo2,&tattr);
|
|
|
|
switch (tattr->typekind) {
|
2002-12-12 23:25:07 +01:00
|
|
|
case TKIND_DISPATCH:
|
2002-02-05 19:11:17 +01:00
|
|
|
case TKIND_INTERFACE:
|
2002-06-10 04:30:20 +02:00
|
|
|
if (writeit)
|
|
|
|
hres=_marshal_interface(buf,&(tattr->guid),(LPUNKNOWN)arg);
|
2005-08-24 11:44:41 +02:00
|
|
|
if (dealloc)
|
|
|
|
IUnknown_Release((LPUNKNOWN)arg);
|
2002-02-05 19:11:17 +01:00
|
|
|
break;
|
2002-06-10 04:30:20 +02:00
|
|
|
case TKIND_RECORD: {
|
|
|
|
int i;
|
2004-06-18 01:03:26 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("{");
|
2002-06-10 04:30:20 +02:00
|
|
|
for (i=0;i<tattr->cVars;i++) {
|
|
|
|
VARDESC *vdesc;
|
|
|
|
ELEMDESC *elem2;
|
|
|
|
TYPEDESC *tdesc2;
|
|
|
|
|
|
|
|
hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
|
|
|
|
if (hres) {
|
2005-01-27 12:11:32 +01:00
|
|
|
ERR("Could not get vardesc of %d\n",i);
|
2002-06-10 04:30:20 +02:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
elem2 = &vdesc->elemdescVar;
|
|
|
|
tdesc2 = &elem2->tdesc;
|
|
|
|
hres = serialize_param(
|
|
|
|
tinfo2,
|
|
|
|
writeit,
|
|
|
|
debugout,
|
|
|
|
dealloc,
|
|
|
|
tdesc2,
|
|
|
|
(DWORD*)(((LPBYTE)arg)+vdesc->u.oInst),
|
|
|
|
buf
|
|
|
|
);
|
2005-06-01 13:03:40 +02:00
|
|
|
ITypeInfo_ReleaseVarDesc(tinfo2, vdesc);
|
2002-06-10 04:30:20 +02:00
|
|
|
if (hres!=S_OK)
|
|
|
|
return hres;
|
|
|
|
if (debugout && (i<(tattr->cVars-1)))
|
2004-06-18 01:03:26 +02:00
|
|
|
TRACE_(olerelay)(",");
|
2002-06-10 04:30:20 +02:00
|
|
|
}
|
2004-06-18 01:03:26 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("}");
|
2002-02-05 19:11:17 +01:00
|
|
|
break;
|
2002-06-10 04:30:20 +02:00
|
|
|
}
|
2005-07-19 21:13:23 +02:00
|
|
|
case TKIND_ALIAS:
|
2006-10-23 12:38:20 +02:00
|
|
|
hres = serialize_param(tinfo2,writeit,debugout,dealloc,&tattr->tdescAlias,arg,buf);
|
|
|
|
break;
|
2005-07-19 21:13:23 +02:00
|
|
|
case TKIND_ENUM:
|
|
|
|
hres = S_OK;
|
2006-10-12 20:57:10 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("%x",*arg);
|
2005-07-19 21:13:23 +02:00
|
|
|
if (writeit)
|
|
|
|
hres = xbuf_add(buf,(LPBYTE)arg,sizeof(DWORD));
|
2006-10-23 12:38:20 +02:00
|
|
|
break;
|
2002-12-12 23:25:07 +01:00
|
|
|
default:
|
|
|
|
FIXME("Unhandled typekind %d\n",tattr->typekind);
|
|
|
|
hres = E_FAIL;
|
2002-02-05 19:11:17 +01:00
|
|
|
break;
|
|
|
|
}
|
2006-10-23 12:38:20 +02:00
|
|
|
ITypeInfo_ReleaseTypeAttr(tinfo2, tattr);
|
2002-02-05 19:11:17 +01:00
|
|
|
ITypeInfo_Release(tinfo2);
|
|
|
|
return hres;
|
|
|
|
}
|
2002-06-10 04:30:20 +02:00
|
|
|
case VT_CARRAY: {
|
|
|
|
ARRAYDESC *adesc = tdesc->u.lpadesc;
|
|
|
|
int i, arrsize = 1;
|
|
|
|
|
2004-06-18 01:03:26 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("carr");
|
2002-06-10 04:30:20 +02:00
|
|
|
for (i=0;i<adesc->cDims;i++) {
|
2006-10-12 20:57:10 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("[%d]",adesc->rgbounds[i].cElements);
|
2002-06-10 04:30:20 +02:00
|
|
|
arrsize *= adesc->rgbounds[i].cElements;
|
|
|
|
}
|
2006-01-27 12:54:03 +01:00
|
|
|
if (debugout) TRACE_(olerelay)("(vt %s)",debugstr_vt(adesc->tdescElem.vt));
|
2004-06-18 01:03:26 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("[");
|
2002-06-10 04:30:20 +02:00
|
|
|
for (i=0;i<arrsize;i++) {
|
|
|
|
hres = serialize_param(tinfo, writeit, debugout, dealloc, &adesc->tdescElem, (DWORD*)((LPBYTE)arg+i*_xsize(&adesc->tdescElem)), buf);
|
|
|
|
if (hres)
|
|
|
|
return hres;
|
2004-06-18 01:03:26 +02:00
|
|
|
if (debugout && (i<arrsize-1)) TRACE_(olerelay)(",");
|
2002-06-10 04:30:20 +02:00
|
|
|
}
|
2004-06-18 01:03:26 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("]");
|
2002-06-10 04:30:20 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
2006-05-10 13:11:22 +02:00
|
|
|
case VT_SAFEARRAY: {
|
|
|
|
if (writeit)
|
|
|
|
{
|
2006-11-08 23:46:13 +01:00
|
|
|
ULONG flags = MAKELONG(MSHCTX_DIFFERENTMACHINE, NDR_LOCAL_DATA_REPRESENTATION);
|
|
|
|
ULONG size = LPSAFEARRAY_UserSize(&flags, buf->curoff, (LPSAFEARRAY *)arg);
|
2006-05-10 13:11:22 +02:00
|
|
|
xbuf_resize(buf, size);
|
|
|
|
LPSAFEARRAY_UserMarshal(&flags, buf->base + buf->curoff, (LPSAFEARRAY *)arg);
|
|
|
|
buf->curoff = size;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
2002-02-05 19:11:17 +01:00
|
|
|
default:
|
2002-06-10 04:30:20 +02:00
|
|
|
ERR("Unhandled marshal type %d.\n",tdesc->vt);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT
|
|
|
|
deserialize_param(
|
|
|
|
ITypeInfo *tinfo,
|
|
|
|
BOOL readit,
|
|
|
|
BOOL debugout,
|
|
|
|
BOOL alloc,
|
|
|
|
TYPEDESC *tdesc,
|
|
|
|
DWORD *arg,
|
2004-09-07 22:42:26 +02:00
|
|
|
marshal_state *buf)
|
|
|
|
{
|
2002-06-10 04:30:20 +02:00
|
|
|
HRESULT hres = S_OK;
|
|
|
|
|
2006-01-27 12:54:03 +01:00
|
|
|
TRACE("vt %s at %p\n",debugstr_vt(tdesc->vt),arg);
|
2002-06-10 04:30:20 +02:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
switch (tdesc->vt) {
|
|
|
|
case VT_EMPTY:
|
2006-10-18 21:21:57 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("<empty>\n");
|
2002-06-10 04:30:20 +02:00
|
|
|
return S_OK;
|
|
|
|
case VT_NULL:
|
2006-10-18 21:21:57 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("<null>\n");
|
2002-06-10 04:30:20 +02:00
|
|
|
return S_OK;
|
|
|
|
case VT_VARIANT: {
|
|
|
|
VARIANT *vt = (VARIANT*)arg;
|
|
|
|
|
|
|
|
if (readit) {
|
|
|
|
DWORD vttype;
|
|
|
|
TYPEDESC tdesc2;
|
|
|
|
hres = xbuf_get(buf,(LPBYTE)&vttype,sizeof(vttype));
|
|
|
|
if (hres) {
|
|
|
|
FIXME("vt type not read?\n");
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
memset(&tdesc2,0,sizeof(tdesc2));
|
|
|
|
tdesc2.vt = vttype;
|
|
|
|
V_VT(vt) = vttype;
|
2006-01-27 12:54:03 +01:00
|
|
|
if (debugout) TRACE_(olerelay)("Vt(%s%s)(",debugstr_vt(vttype),debugstr_vf(vttype));
|
2005-08-08 20:38:29 +02:00
|
|
|
hres = deserialize_param(tinfo, readit, debugout, alloc, &tdesc2, (DWORD*)&(V_I4(vt)), buf);
|
2004-06-18 01:03:26 +02:00
|
|
|
TRACE_(olerelay)(")");
|
2002-06-10 04:30:20 +02:00
|
|
|
return hres;
|
|
|
|
} else {
|
|
|
|
VariantInit(vt);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
2005-11-04 12:13:55 +01:00
|
|
|
case VT_I8:
|
|
|
|
case VT_UI8:
|
2006-01-14 17:47:25 +01:00
|
|
|
case VT_CY:
|
2005-11-04 12:13:55 +01:00
|
|
|
if (readit) {
|
|
|
|
hres = xbuf_get(buf,(LPBYTE)arg,8);
|
|
|
|
if (hres) ERR("Failed to read integer 8 byte\n");
|
|
|
|
}
|
2006-10-12 20:57:10 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("%x%x",arg[0],arg[1]);
|
2005-11-04 12:13:55 +01:00
|
|
|
return hres;
|
2002-06-10 04:30:20 +02:00
|
|
|
case VT_ERROR:
|
2005-03-14 11:09:11 +01:00
|
|
|
case VT_BOOL:
|
|
|
|
case VT_I4:
|
2006-02-07 16:26:02 +01:00
|
|
|
case VT_INT:
|
2005-03-14 11:09:11 +01:00
|
|
|
case VT_UINT:
|
|
|
|
case VT_R4:
|
|
|
|
case VT_UI4:
|
2002-06-10 04:30:20 +02:00
|
|
|
if (readit) {
|
|
|
|
hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
|
2005-01-27 12:11:32 +01:00
|
|
|
if (hres) ERR("Failed to read integer 4 byte\n");
|
2002-06-10 04:30:20 +02:00
|
|
|
}
|
2006-10-12 20:57:10 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("%x",*arg);
|
2002-02-05 19:11:17 +01:00
|
|
|
return hres;
|
2005-03-27 20:17:19 +02:00
|
|
|
case VT_I2:
|
|
|
|
case VT_UI2:
|
|
|
|
if (readit) {
|
|
|
|
DWORD x;
|
|
|
|
hres = xbuf_get(buf,(LPBYTE)&x,sizeof(DWORD));
|
|
|
|
if (hres) ERR("Failed to read integer 4 byte\n");
|
|
|
|
memcpy(arg,&x,2);
|
|
|
|
}
|
2006-10-12 20:57:10 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("%04x",*arg & 0xffff);
|
2005-03-27 20:17:19 +02:00
|
|
|
return hres;
|
|
|
|
case VT_I1:
|
|
|
|
case VT_UI1:
|
|
|
|
if (readit) {
|
|
|
|
DWORD x;
|
|
|
|
hres = xbuf_get(buf,(LPBYTE)&x,sizeof(DWORD));
|
|
|
|
if (hres) ERR("Failed to read integer 4 byte\n");
|
|
|
|
memcpy(arg,&x,1);
|
|
|
|
}
|
2006-10-12 20:57:10 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("%02x",*arg & 0xff);
|
2005-03-27 20:17:19 +02:00
|
|
|
return hres;
|
2005-03-29 13:29:11 +02:00
|
|
|
case VT_I4|VT_BYREF:
|
|
|
|
hres = S_OK;
|
|
|
|
if (alloc)
|
|
|
|
*arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
|
|
|
|
if (readit) {
|
|
|
|
hres = xbuf_get(buf,(LPBYTE)*arg,sizeof(DWORD));
|
|
|
|
if (hres) ERR("Failed to read integer 4 byte\n");
|
|
|
|
}
|
2006-10-12 20:57:10 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("&0x%x",*(DWORD*)*arg);
|
2005-03-29 13:29:11 +02:00
|
|
|
return hres;
|
2005-03-14 11:09:11 +01:00
|
|
|
case VT_BSTR|VT_BYREF: {
|
|
|
|
BSTR **bstr = (BSTR **)arg;
|
|
|
|
WCHAR *str;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
if (readit) {
|
|
|
|
hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
|
|
|
|
if (hres) {
|
|
|
|
ERR("failed to read bstr klen\n");
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
if (len == -1) {
|
2005-03-29 13:29:11 +02:00
|
|
|
*bstr = CoTaskMemAlloc(sizeof(BSTR *));
|
|
|
|
**bstr = NULL;
|
2005-03-14 11:09:11 +01:00
|
|
|
if (debugout) TRACE_(olerelay)("<bstr NULL>");
|
|
|
|
} else {
|
2005-07-19 21:42:50 +02:00
|
|
|
str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
|
|
|
|
hres = xbuf_get(buf,(LPBYTE)str,len*sizeof(WCHAR));
|
2005-03-14 11:09:11 +01:00
|
|
|
if (hres) {
|
|
|
|
ERR("Failed to read BSTR.\n");
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
*bstr = CoTaskMemAlloc(sizeof(BSTR *));
|
|
|
|
**bstr = SysAllocStringLen(str,len);
|
|
|
|
if (debugout) TRACE_(olerelay)("%s",relaystr(str));
|
|
|
|
HeapFree(GetProcessHeap(),0,str);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*bstr = NULL;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
2002-06-10 04:30:20 +02:00
|
|
|
case VT_BSTR: {
|
|
|
|
WCHAR *str;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
if (readit) {
|
|
|
|
hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
|
|
|
|
if (hres) {
|
2005-01-27 12:11:32 +01:00
|
|
|
ERR("failed to read bstr klen\n");
|
2002-06-10 04:30:20 +02:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
if (len == -1) {
|
|
|
|
*arg = 0;
|
2004-06-18 01:03:26 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("<bstr NULL>");
|
2002-06-10 04:30:20 +02:00
|
|
|
} else {
|
2005-07-19 21:42:50 +02:00
|
|
|
str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
|
|
|
|
hres = xbuf_get(buf,(LPBYTE)str,len*sizeof(WCHAR));
|
2002-06-10 04:30:20 +02:00
|
|
|
if (hres) {
|
2005-01-27 12:11:32 +01:00
|
|
|
ERR("Failed to read BSTR.\n");
|
2002-06-10 04:30:20 +02:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
*arg = (DWORD)SysAllocStringLen(str,len);
|
2004-06-18 01:03:26 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("%s",relaystr(str));
|
2002-06-10 04:30:20 +02:00
|
|
|
HeapFree(GetProcessHeap(),0,str);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*arg = 0;
|
|
|
|
}
|
|
|
|
return S_OK;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
2002-06-10 04:30:20 +02:00
|
|
|
case VT_PTR: {
|
|
|
|
DWORD cookie;
|
2005-09-07 11:23:04 +02:00
|
|
|
BOOL derefhere = TRUE;
|
2002-06-10 04:30:20 +02:00
|
|
|
|
2005-09-07 11:23:04 +02:00
|
|
|
if (tdesc->u.lptdesc->vt == VT_USERDEFINED) {
|
|
|
|
ITypeInfo *tinfo2;
|
|
|
|
TYPEATTR *tattr;
|
|
|
|
|
|
|
|
hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.lptdesc->u.hreftype,&tinfo2);
|
|
|
|
if (hres) {
|
2006-10-12 20:57:10 +02:00
|
|
|
ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc->u.lptdesc->u.hreftype);
|
2005-09-07 11:23:04 +02:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
ITypeInfo_GetTypeAttr(tinfo2,&tattr);
|
|
|
|
switch (tattr->typekind) {
|
|
|
|
case TKIND_ENUM: /* confirmed */
|
|
|
|
case TKIND_RECORD: /* FIXME: mostly untested */
|
|
|
|
derefhere=TRUE;
|
|
|
|
break;
|
|
|
|
case TKIND_ALIAS: /* FIXME: untested */
|
|
|
|
case TKIND_DISPATCH: /* will be done in VT_USERDEFINED case */
|
|
|
|
case TKIND_INTERFACE: /* will be done in VT_USERDEFINED case */
|
|
|
|
derefhere=FALSE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("unhandled switch cases tattr->typekind %d\n", tattr->typekind);
|
|
|
|
derefhere=FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2006-10-23 12:38:20 +02:00
|
|
|
ITypeInfo_ReleaseTypeAttr(tinfo2, tattr);
|
2005-09-07 11:23:04 +02:00
|
|
|
ITypeInfo_Release(tinfo2);
|
|
|
|
}
|
2005-03-27 19:51:59 +02:00
|
|
|
/* read it in all cases, we need to know if we have
|
|
|
|
* NULL pointer or not.
|
|
|
|
*/
|
|
|
|
hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
|
|
|
|
if (hres) {
|
|
|
|
ERR("Failed to load pointer cookie.\n");
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
if (cookie != 0x42424242) {
|
|
|
|
/* we read a NULL ptr from the remote side */
|
|
|
|
if (debugout) TRACE_(olerelay)("NULL");
|
|
|
|
*arg = 0;
|
|
|
|
return S_OK;
|
2002-06-10 04:30:20 +02:00
|
|
|
}
|
2005-03-27 19:51:59 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("*");
|
2002-06-10 04:30:20 +02:00
|
|
|
if (alloc) {
|
2005-03-27 19:51:59 +02:00
|
|
|
/* Allocate space for the referenced struct */
|
2002-06-10 04:30:20 +02:00
|
|
|
if (derefhere)
|
|
|
|
*arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,_xsize(tdesc->u.lptdesc));
|
|
|
|
}
|
|
|
|
if (derefhere)
|
|
|
|
return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, (LPDWORD)*arg, buf);
|
|
|
|
else
|
|
|
|
return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, arg, buf);
|
|
|
|
}
|
|
|
|
case VT_UNKNOWN:
|
|
|
|
/* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
|
|
|
|
if (alloc)
|
|
|
|
*arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
|
|
|
|
hres = S_OK;
|
|
|
|
if (readit)
|
|
|
|
hres = _unmarshal_interface(buf,&IID_IUnknown,(LPUNKNOWN*)arg);
|
|
|
|
if (debugout)
|
2004-06-18 01:03:26 +02:00
|
|
|
TRACE_(olerelay)("unk(%p)",arg);
|
2002-06-10 04:30:20 +02:00
|
|
|
return hres;
|
|
|
|
case VT_DISPATCH:
|
|
|
|
hres = S_OK;
|
|
|
|
if (readit)
|
|
|
|
hres = _unmarshal_interface(buf,&IID_IDispatch,(LPUNKNOWN*)arg);
|
|
|
|
if (debugout)
|
2004-06-18 01:03:26 +02:00
|
|
|
TRACE_(olerelay)("idisp(%p)",arg);
|
2002-06-10 04:30:20 +02:00
|
|
|
return hres;
|
|
|
|
case VT_VOID:
|
2004-06-18 01:03:26 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("<void>");
|
2002-06-10 04:30:20 +02:00
|
|
|
return S_OK;
|
|
|
|
case VT_USERDEFINED: {
|
|
|
|
ITypeInfo *tinfo2;
|
|
|
|
TYPEATTR *tattr;
|
|
|
|
|
|
|
|
hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
|
|
|
|
if (hres) {
|
2006-10-12 20:57:10 +02:00
|
|
|
ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc->u.hreftype);
|
2002-06-10 04:30:20 +02:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
hres = ITypeInfo_GetTypeAttr(tinfo2,&tattr);
|
|
|
|
if (hres) {
|
2005-01-27 12:11:32 +01:00
|
|
|
ERR("Could not get typeattr in VT_USERDEFINED.\n");
|
2002-06-10 04:30:20 +02:00
|
|
|
} else {
|
|
|
|
switch (tattr->typekind) {
|
2002-12-12 23:25:07 +01:00
|
|
|
case TKIND_DISPATCH:
|
2002-06-10 04:30:20 +02:00
|
|
|
case TKIND_INTERFACE:
|
|
|
|
if (readit)
|
|
|
|
hres = _unmarshal_interface(buf,&(tattr->guid),(LPUNKNOWN*)arg);
|
|
|
|
break;
|
|
|
|
case TKIND_RECORD: {
|
|
|
|
int i;
|
|
|
|
|
2005-03-14 11:09:11 +01:00
|
|
|
if (alloc)
|
|
|
|
*arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,tattr->cbSizeInstance);
|
|
|
|
|
2004-06-18 01:03:26 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("{");
|
2002-06-10 04:30:20 +02:00
|
|
|
for (i=0;i<tattr->cVars;i++) {
|
|
|
|
VARDESC *vdesc;
|
|
|
|
|
|
|
|
hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
|
|
|
|
if (hres) {
|
2005-01-27 12:11:32 +01:00
|
|
|
ERR("Could not get vardesc of %d\n",i);
|
2006-10-23 12:38:20 +02:00
|
|
|
ITypeInfo_ReleaseTypeAttr(tinfo2, tattr);
|
|
|
|
ITypeInfo_Release(tinfo2);
|
2002-06-10 04:30:20 +02:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
hres = deserialize_param(
|
|
|
|
tinfo2,
|
|
|
|
readit,
|
|
|
|
debugout,
|
|
|
|
alloc,
|
|
|
|
&vdesc->elemdescVar.tdesc,
|
|
|
|
(DWORD*)(((LPBYTE)*arg)+vdesc->u.oInst),
|
|
|
|
buf
|
|
|
|
);
|
2005-12-06 21:24:19 +01:00
|
|
|
ITypeInfo2_ReleaseVarDesc(tinfo2, vdesc);
|
2004-06-18 01:03:26 +02:00
|
|
|
if (debugout && (i<tattr->cVars-1)) TRACE_(olerelay)(",");
|
2002-06-10 04:30:20 +02:00
|
|
|
}
|
2004-06-18 01:03:26 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("}");
|
2002-06-10 04:30:20 +02:00
|
|
|
break;
|
|
|
|
}
|
2005-07-19 21:13:23 +02:00
|
|
|
case TKIND_ALIAS:
|
2006-10-23 12:38:20 +02:00
|
|
|
hres = deserialize_param(tinfo2,readit,debugout,alloc,&tattr->tdescAlias,arg,buf);
|
|
|
|
break;
|
2005-07-19 21:13:23 +02:00
|
|
|
case TKIND_ENUM:
|
|
|
|
if (readit) {
|
|
|
|
hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
|
|
|
|
if (hres) ERR("Failed to read enum (4 byte)\n");
|
|
|
|
}
|
2006-10-12 20:57:10 +02:00
|
|
|
if (debugout) TRACE_(olerelay)("%x",*arg);
|
2006-10-23 12:38:20 +02:00
|
|
|
break;
|
2002-12-12 23:25:07 +01:00
|
|
|
default:
|
|
|
|
ERR("Unhandled typekind %d\n",tattr->typekind);
|
|
|
|
hres = E_FAIL;
|
2002-06-10 04:30:20 +02:00
|
|
|
break;
|
|
|
|
}
|
2006-10-23 12:38:20 +02:00
|
|
|
ITypeInfo_ReleaseTypeAttr(tinfo2, tattr);
|
2002-06-10 04:30:20 +02:00
|
|
|
}
|
|
|
|
if (hres)
|
2005-01-27 12:11:32 +01:00
|
|
|
ERR("failed to stuballoc in TKIND_RECORD.\n");
|
2002-06-10 04:30:20 +02:00
|
|
|
ITypeInfo_Release(tinfo2);
|
2002-02-05 19:11:17 +01:00
|
|
|
return hres;
|
|
|
|
}
|
2002-06-10 04:30:20 +02:00
|
|
|
case VT_CARRAY: {
|
|
|
|
/* arg is pointing to the start of the array. */
|
|
|
|
ARRAYDESC *adesc = tdesc->u.lpadesc;
|
|
|
|
int arrsize,i;
|
|
|
|
arrsize = 1;
|
|
|
|
if (adesc->cDims > 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
|
|
|
|
for (i=0;i<adesc->cDims;i++)
|
|
|
|
arrsize *= adesc->rgbounds[i].cElements;
|
|
|
|
for (i=0;i<arrsize;i++)
|
|
|
|
deserialize_param(
|
|
|
|
tinfo,
|
|
|
|
readit,
|
|
|
|
debugout,
|
|
|
|
alloc,
|
|
|
|
&adesc->tdescElem,
|
|
|
|
(DWORD*)((LPBYTE)(arg)+i*_xsize(&adesc->tdescElem)),
|
|
|
|
buf
|
|
|
|
);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2006-05-10 13:11:22 +02:00
|
|
|
case VT_SAFEARRAY: {
|
|
|
|
if (readit)
|
|
|
|
{
|
2006-11-08 23:46:13 +01:00
|
|
|
ULONG flags = MAKELONG(MSHCTX_DIFFERENTMACHINE, NDR_LOCAL_DATA_REPRESENTATION);
|
2006-05-10 13:11:22 +02:00
|
|
|
unsigned char *buffer;
|
|
|
|
buffer = LPSAFEARRAY_UserUnmarshal(&flags, buf->base + buf->curoff, (LPSAFEARRAY *)arg);
|
|
|
|
buf->curoff = buffer - buf->base;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
2002-02-05 19:11:17 +01:00
|
|
|
default:
|
2002-06-10 04:30:20 +02:00
|
|
|
ERR("No handler for VT type %d!\n",tdesc->vt);
|
|
|
|
return S_OK;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
2002-06-10 04:30:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
/* Searches function, also in inherited interfaces */
|
|
|
|
static HRESULT
|
|
|
|
_get_funcdesc(
|
2005-12-06 21:24:19 +01:00
|
|
|
ITypeInfo *tinfo, int iMethod, ITypeInfo **tactual, const FUNCDESC **fdesc, BSTR *iname, BSTR *fname)
|
2004-09-07 22:42:26 +02:00
|
|
|
{
|
2002-02-05 19:11:17 +01:00
|
|
|
int i = 0, j = 0;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
if (fname) *fname = NULL;
|
|
|
|
if (iname) *iname = NULL;
|
|
|
|
|
|
|
|
while (1) {
|
2005-12-06 21:24:19 +01:00
|
|
|
hres = ITypeInfoImpl_GetInternalFuncDesc(tinfo, i, fdesc);
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
if (hres) {
|
|
|
|
ITypeInfo *tinfo2;
|
|
|
|
HREFTYPE href;
|
|
|
|
TYPEATTR *attr;
|
|
|
|
|
|
|
|
hres = ITypeInfo_GetTypeAttr(tinfo, &attr);
|
|
|
|
if (hres) {
|
2006-10-12 20:57:10 +02:00
|
|
|
ERR("GetTypeAttr failed with %x\n",hres);
|
2002-02-05 19:11:17 +01:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
/* Not found, so look in inherited ifaces. */
|
|
|
|
for (j=0;j<attr->cImplTypes;j++) {
|
|
|
|
hres = ITypeInfo_GetRefTypeOfImplType(tinfo, j, &href);
|
|
|
|
if (hres) {
|
2005-01-27 12:11:32 +01:00
|
|
|
ERR("Did not find a reftype for interface offset %d?\n",j);
|
2002-02-05 19:11:17 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
hres = ITypeInfo_GetRefTypeInfo(tinfo, href, &tinfo2);
|
|
|
|
if (hres) {
|
2006-10-12 20:57:10 +02:00
|
|
|
ERR("Did not find a typeinfo for reftype %d?\n",href);
|
2002-02-05 19:11:17 +01:00
|
|
|
continue;
|
|
|
|
}
|
2005-06-01 13:03:40 +02:00
|
|
|
hres = _get_funcdesc(tinfo2,iMethod,tactual,fdesc,iname,fname);
|
2002-02-05 19:11:17 +01:00
|
|
|
ITypeInfo_Release(tinfo2);
|
2006-10-23 12:46:08 +02:00
|
|
|
if (!hres) {
|
|
|
|
ITypeInfo_ReleaseTypeAttr(tinfo, attr);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
2006-10-23 12:46:08 +02:00
|
|
|
ITypeInfo_ReleaseTypeAttr(tinfo, attr);
|
2005-01-26 20:42:17 +01:00
|
|
|
return hres;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
if (((*fdesc)->oVft/4) == iMethod) {
|
|
|
|
if (fname)
|
|
|
|
ITypeInfo_GetDocumentation(tinfo,(*fdesc)->memid,fname,NULL,NULL,NULL);
|
|
|
|
if (iname)
|
|
|
|
ITypeInfo_GetDocumentation(tinfo,-1,iname,NULL,NULL,NULL);
|
2006-10-23 12:38:20 +02:00
|
|
|
*tactual = tinfo;
|
|
|
|
ITypeInfo_AddRef(*tactual);
|
2002-02-05 19:11:17 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD
|
2004-09-07 22:42:26 +02:00
|
|
|
xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */)
|
|
|
|
{
|
2002-02-05 19:11:17 +01:00
|
|
|
DWORD *args = ((DWORD*)&tpinfo)+1, *xargs;
|
2005-12-06 21:24:19 +01:00
|
|
|
const FUNCDESC *fdesc;
|
2002-02-05 19:11:17 +01:00
|
|
|
HRESULT hres;
|
|
|
|
int i, relaydeb = TRACE_ON(olerelay);
|
|
|
|
marshal_state buf;
|
|
|
|
RPCOLEMESSAGE msg;
|
|
|
|
ULONG status;
|
|
|
|
BSTR fname,iname;
|
|
|
|
BSTR names[10];
|
2005-08-08 20:38:29 +02:00
|
|
|
UINT nrofnames;
|
2005-03-28 12:00:49 +02:00
|
|
|
DWORD remoteresult = 0;
|
2005-06-01 13:03:40 +02:00
|
|
|
ITypeInfo *tinfo;
|
2005-11-02 21:00:00 +01:00
|
|
|
IRpcChannelBuffer *chanbuf;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
2004-09-07 22:42:26 +02:00
|
|
|
EnterCriticalSection(&tpinfo->crit);
|
|
|
|
|
2005-06-01 13:03:40 +02:00
|
|
|
hres = _get_funcdesc(tpinfo->tinfo,method,&tinfo,&fdesc,&iname,&fname);
|
2002-02-05 19:11:17 +01:00
|
|
|
if (hres) {
|
2005-11-02 21:00:00 +01:00
|
|
|
ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method);
|
2005-06-01 13:03:40 +02:00
|
|
|
ITypeInfo_Release(tinfo);
|
2004-09-07 22:42:26 +02:00
|
|
|
LeaveCriticalSection(&tpinfo->crit);
|
2005-11-02 21:00:00 +01:00
|
|
|
return E_FAIL;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
2004-12-14 12:44:11 +01:00
|
|
|
if (!tpinfo->chanbuf)
|
|
|
|
{
|
|
|
|
WARN("Tried to use disconnected proxy\n");
|
2005-06-01 13:03:40 +02:00
|
|
|
ITypeInfo_Release(tinfo);
|
2004-12-14 12:44:11 +01:00
|
|
|
LeaveCriticalSection(&tpinfo->crit);
|
|
|
|
return RPC_E_DISCONNECTED;
|
|
|
|
}
|
2005-11-02 21:00:00 +01:00
|
|
|
chanbuf = tpinfo->chanbuf;
|
|
|
|
IRpcChannelBuffer_AddRef(chanbuf);
|
|
|
|
|
|
|
|
LeaveCriticalSection(&tpinfo->crit);
|
2004-12-14 12:44:11 +01:00
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
if (relaydeb) {
|
2004-06-23 02:10:29 +02:00
|
|
|
TRACE_(olerelay)("->");
|
2002-02-05 19:11:17 +01:00
|
|
|
if (iname)
|
2004-06-18 01:03:26 +02:00
|
|
|
TRACE_(olerelay)("%s:",relaystr(iname));
|
2002-02-05 19:11:17 +01:00
|
|
|
if (fname)
|
2004-06-18 01:03:26 +02:00
|
|
|
TRACE_(olerelay)("%s(%d)",relaystr(fname),method);
|
2002-02-05 19:11:17 +01:00
|
|
|
else
|
2004-06-18 01:03:26 +02:00
|
|
|
TRACE_(olerelay)("%d",method);
|
|
|
|
TRACE_(olerelay)("(");
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
2005-03-27 19:51:59 +02:00
|
|
|
|
|
|
|
if (iname) SysFreeString(iname);
|
|
|
|
if (fname) SysFreeString(fname);
|
|
|
|
|
|
|
|
memset(&buf,0,sizeof(buf));
|
|
|
|
|
|
|
|
/* normal typelib driven serializing */
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
/* Need them for hack below */
|
|
|
|
memset(names,0,sizeof(names));
|
2005-06-01 13:03:40 +02:00
|
|
|
if (ITypeInfo_GetNames(tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames))
|
2002-06-10 04:30:20 +02:00
|
|
|
nrofnames = 0;
|
|
|
|
if (nrofnames > sizeof(names)/sizeof(names[0]))
|
2002-02-05 19:11:17 +01:00
|
|
|
ERR("Need more names!\n");
|
2002-06-10 04:30:20 +02:00
|
|
|
|
2005-03-27 19:51:59 +02:00
|
|
|
xargs = args;
|
|
|
|
for (i=0;i<fdesc->cParams;i++) {
|
|
|
|
ELEMDESC *elem = fdesc->lprgelemdescParam+i;
|
|
|
|
if (relaydeb) {
|
|
|
|
if (i) TRACE_(olerelay)(",");
|
|
|
|
if (i+1<nrofnames && names[i+1])
|
|
|
|
TRACE_(olerelay)("%s=",relaystr(names[i+1]));
|
|
|
|
}
|
|
|
|
/* No need to marshal other data than FIN and any VT_PTR. */
|
2005-10-26 14:06:49 +02:00
|
|
|
if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN || !elem->u.paramdesc.wParamFlags) && (elem->tdesc.vt != VT_PTR)) {
|
2005-03-27 19:51:59 +02:00
|
|
|
xargs+=_argsize(elem->tdesc.vt);
|
|
|
|
if (relaydeb) TRACE_(olerelay)("[out]");
|
|
|
|
continue;
|
|
|
|
}
|
2005-10-26 12:12:30 +02:00
|
|
|
hres = serialize_param(
|
|
|
|
tinfo,
|
2005-10-26 14:06:49 +02:00
|
|
|
elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN || !elem->u.paramdesc.wParamFlags,
|
2005-10-26 12:12:30 +02:00
|
|
|
relaydeb,
|
|
|
|
FALSE,
|
|
|
|
&elem->tdesc,
|
|
|
|
xargs,
|
|
|
|
&buf
|
|
|
|
);
|
2005-03-27 19:51:59 +02:00
|
|
|
|
|
|
|
if (hres) {
|
2006-10-12 20:57:10 +02:00
|
|
|
ERR("Failed to serialize param, hres %x\n",hres);
|
2005-03-27 19:51:59 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
xargs+=_argsize(elem->tdesc.vt);
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
2004-06-18 01:03:26 +02:00
|
|
|
if (relaydeb) TRACE_(olerelay)(")");
|
2005-03-27 19:51:59 +02:00
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
memset(&msg,0,sizeof(msg));
|
|
|
|
msg.cbBuffer = buf.curoff;
|
|
|
|
msg.iMethod = method;
|
2005-11-02 21:00:00 +01:00
|
|
|
hres = IRpcChannelBuffer_GetBuffer(chanbuf,&msg,&(tpinfo->iid));
|
2002-02-05 19:11:17 +01:00
|
|
|
if (hres) {
|
2006-10-12 20:57:10 +02:00
|
|
|
ERR("RpcChannelBuffer GetBuffer failed, %x\n",hres);
|
2005-11-02 21:00:00 +01:00
|
|
|
goto exit;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
memcpy(msg.Buffer,buf.base,buf.curoff);
|
2004-06-18 01:03:26 +02:00
|
|
|
if (relaydeb) TRACE_(olerelay)("\n");
|
2005-11-02 21:00:00 +01:00
|
|
|
hres = IRpcChannelBuffer_SendReceive(chanbuf,&msg,&status);
|
2002-02-05 19:11:17 +01:00
|
|
|
if (hres) {
|
2006-10-12 20:57:10 +02:00
|
|
|
ERR("RpcChannelBuffer SendReceive failed, %x\n",hres);
|
2005-11-02 21:00:00 +01:00
|
|
|
goto exit;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
2004-06-18 01:03:26 +02:00
|
|
|
|
2006-10-12 20:57:10 +02:00
|
|
|
if (relaydeb) TRACE_(olerelay)(" status = %08x (",status);
|
2002-02-05 19:11:17 +01:00
|
|
|
if (buf.base)
|
|
|
|
buf.base = HeapReAlloc(GetProcessHeap(),0,buf.base,msg.cbBuffer);
|
|
|
|
else
|
|
|
|
buf.base = HeapAlloc(GetProcessHeap(),0,msg.cbBuffer);
|
|
|
|
buf.size = msg.cbBuffer;
|
|
|
|
memcpy(buf.base,msg.Buffer,buf.size);
|
|
|
|
buf.curoff = 0;
|
2005-03-27 19:51:59 +02:00
|
|
|
|
|
|
|
/* generic deserializer using typelib description */
|
|
|
|
xargs = args;
|
2005-03-28 12:00:49 +02:00
|
|
|
status = S_OK;
|
2005-03-27 19:51:59 +02:00
|
|
|
for (i=0;i<fdesc->cParams;i++) {
|
|
|
|
ELEMDESC *elem = fdesc->lprgelemdescParam+i;
|
|
|
|
|
|
|
|
if (relaydeb) {
|
|
|
|
if (i) TRACE_(olerelay)(",");
|
|
|
|
if (i+1<nrofnames && names[i+1]) TRACE_(olerelay)("%s=",relaystr(names[i+1]));
|
|
|
|
}
|
|
|
|
/* No need to marshal other data than FOUT and any VT_PTR */
|
|
|
|
if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT) && (elem->tdesc.vt != VT_PTR)) {
|
|
|
|
xargs += _argsize(elem->tdesc.vt);
|
|
|
|
if (relaydeb) TRACE_(olerelay)("[in]");
|
|
|
|
continue;
|
|
|
|
}
|
2005-10-26 12:12:30 +02:00
|
|
|
hres = deserialize_param(
|
|
|
|
tinfo,
|
|
|
|
elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
|
|
|
|
relaydeb,
|
|
|
|
FALSE,
|
|
|
|
&(elem->tdesc),
|
|
|
|
xargs,
|
|
|
|
&buf
|
|
|
|
);
|
2005-03-27 19:51:59 +02:00
|
|
|
if (hres) {
|
2006-10-12 20:57:10 +02:00
|
|
|
ERR("Failed to unmarshall param, hres %x\n",hres);
|
2005-03-27 19:51:59 +02:00
|
|
|
status = hres;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
xargs += _argsize(elem->tdesc.vt);
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
2005-10-26 12:12:30 +02:00
|
|
|
|
2005-03-28 12:00:49 +02:00
|
|
|
hres = xbuf_get(&buf, (LPBYTE)&remoteresult, sizeof(DWORD));
|
|
|
|
if (hres != S_OK)
|
2005-11-02 21:00:00 +01:00
|
|
|
goto exit;
|
2006-10-12 20:57:10 +02:00
|
|
|
if (relaydeb) TRACE_(olerelay)(") = %08x\n", remoteresult);
|
2004-09-07 22:42:26 +02:00
|
|
|
|
2005-11-02 21:00:00 +01:00
|
|
|
hres = remoteresult;
|
2004-09-07 22:42:26 +02:00
|
|
|
|
2005-11-02 21:00:00 +01:00
|
|
|
exit:
|
2006-10-23 12:29:09 +02:00
|
|
|
for (i = 0; i < nrofnames; i++)
|
|
|
|
SysFreeString(names[i]);
|
2005-03-28 12:00:49 +02:00
|
|
|
HeapFree(GetProcessHeap(),0,buf.base);
|
2005-11-02 21:00:00 +01:00
|
|
|
IRpcChannelBuffer_Release(chanbuf);
|
2005-06-01 13:03:40 +02:00
|
|
|
ITypeInfo_Release(tinfo);
|
2006-10-12 20:57:10 +02:00
|
|
|
TRACE("-- 0x%08x\n", hres);
|
2005-11-02 21:00:00 +01:00
|
|
|
return hres;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
2006-06-10 11:59:33 +02:00
|
|
|
static HRESULT WINAPI ProxyIUnknown_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
|
2005-03-11 11:18:31 +01:00
|
|
|
{
|
|
|
|
TMProxyImpl *proxy = (TMProxyImpl *)iface;
|
|
|
|
|
|
|
|
TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
|
|
|
|
|
|
|
|
if (proxy->outerunknown)
|
|
|
|
return IUnknown_QueryInterface(proxy->outerunknown, riid, ppv);
|
|
|
|
|
|
|
|
FIXME("No interface\n");
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2006-06-10 11:59:33 +02:00
|
|
|
static ULONG WINAPI ProxyIUnknown_AddRef(IUnknown *iface)
|
2005-03-11 11:18:31 +01:00
|
|
|
{
|
|
|
|
TMProxyImpl *proxy = (TMProxyImpl *)iface;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
if (proxy->outerunknown)
|
|
|
|
return IUnknown_AddRef(proxy->outerunknown);
|
|
|
|
|
|
|
|
return 2; /* FIXME */
|
|
|
|
}
|
|
|
|
|
2006-06-10 11:59:33 +02:00
|
|
|
static ULONG WINAPI ProxyIUnknown_Release(IUnknown *iface)
|
2005-03-11 11:18:31 +01:00
|
|
|
{
|
|
|
|
TMProxyImpl *proxy = (TMProxyImpl *)iface;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
if (proxy->outerunknown)
|
|
|
|
return IUnknown_Release(proxy->outerunknown);
|
|
|
|
|
|
|
|
return 1; /* FIXME */
|
|
|
|
}
|
|
|
|
|
2005-10-26 12:12:30 +02:00
|
|
|
static HRESULT WINAPI ProxyIDispatch_GetTypeInfoCount(LPDISPATCH iface, UINT * pctinfo)
|
|
|
|
{
|
|
|
|
TMProxyImpl *This = (TMProxyImpl *)iface;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", pctinfo);
|
|
|
|
|
2006-02-07 16:26:23 +01:00
|
|
|
return IDispatch_GetTypeInfoCount(This->dispatch, pctinfo);
|
2005-10-26 12:12:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProxyIDispatch_GetTypeInfo(LPDISPATCH iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)
|
|
|
|
{
|
|
|
|
TMProxyImpl *This = (TMProxyImpl *)iface;
|
|
|
|
|
2006-10-12 20:57:10 +02:00
|
|
|
TRACE("(%d, %x, %p)\n", iTInfo, lcid, ppTInfo);
|
2005-10-26 12:12:30 +02:00
|
|
|
|
2006-02-07 16:26:23 +01:00
|
|
|
return IDispatch_GetTypeInfo(This->dispatch, iTInfo, lcid, ppTInfo);
|
2005-10-26 12:12:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProxyIDispatch_GetIDsOfNames(LPDISPATCH iface, REFIID riid, LPOLESTR * rgszNames, UINT cNames, LCID lcid, DISPID * rgDispId)
|
|
|
|
{
|
|
|
|
TMProxyImpl *This = (TMProxyImpl *)iface;
|
|
|
|
|
2006-10-12 20:57:10 +02:00
|
|
|
TRACE("(%s, %p, %d, 0x%x, %p)\n", debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
|
2005-10-26 12:12:30 +02:00
|
|
|
|
2006-02-07 16:26:23 +01:00
|
|
|
return IDispatch_GetIDsOfNames(This->dispatch, riid, rgszNames,
|
|
|
|
cNames, lcid, rgDispId);
|
2005-10-26 12:12:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProxyIDispatch_Invoke(LPDISPATCH iface, DISPID dispIdMember, REFIID riid, LCID lcid,
|
|
|
|
WORD wFlags, DISPPARAMS * pDispParams, VARIANT * pVarResult,
|
|
|
|
EXCEPINFO * pExcepInfo, UINT * puArgErr)
|
|
|
|
{
|
|
|
|
TMProxyImpl *This = (TMProxyImpl *)iface;
|
|
|
|
|
2006-10-12 20:57:10 +02:00
|
|
|
TRACE("(%d, %s, 0x%x, 0x%x, %p, %p, %p, %p)\n", dispIdMember,
|
2006-02-07 16:26:23 +01:00
|
|
|
debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult,
|
|
|
|
pExcepInfo, puArgErr);
|
2005-10-26 12:12:30 +02:00
|
|
|
|
2006-02-07 16:26:23 +01:00
|
|
|
return IDispatch_Invoke(This->dispatch, dispIdMember, riid, lcid,
|
|
|
|
wFlags, pDispParams, pVarResult, pExcepInfo,
|
|
|
|
puArgErr);
|
|
|
|
}
|
2005-10-26 12:12:30 +02:00
|
|
|
|
2006-02-07 16:26:23 +01:00
|
|
|
static inline HRESULT get_facbuf_for_iid(REFIID riid, IPSFactoryBuffer **facbuf)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
CLSID clsid;
|
|
|
|
|
|
|
|
if ((hr = CoGetPSClsid(riid, &clsid)))
|
|
|
|
return hr;
|
|
|
|
return CoGetClassObject(&clsid, CLSCTX_INPROC_SERVER, NULL,
|
|
|
|
&IID_IPSFactoryBuffer, (LPVOID*)facbuf);
|
2005-10-26 12:12:30 +02:00
|
|
|
}
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
static HRESULT WINAPI
|
|
|
|
PSFacBuf_CreateProxy(
|
|
|
|
LPPSFACTORYBUFFER iface, IUnknown* pUnkOuter, REFIID riid,
|
2004-09-07 22:42:26 +02:00
|
|
|
IRpcProxyBuffer **ppProxy, LPVOID *ppv)
|
|
|
|
{
|
2002-02-05 19:11:17 +01:00
|
|
|
HRESULT hres;
|
|
|
|
ITypeInfo *tinfo;
|
|
|
|
int i, nroffuncs;
|
2005-12-06 21:24:19 +01:00
|
|
|
const FUNCDESC *fdesc;
|
2002-02-05 19:11:17 +01:00
|
|
|
TMProxyImpl *proxy;
|
2005-10-26 12:12:30 +02:00
|
|
|
TYPEATTR *typeattr;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
TRACE("(...%s...)\n",debugstr_guid(riid));
|
|
|
|
hres = _get_typeinfo_for_iid(riid,&tinfo);
|
|
|
|
if (hres) {
|
2005-01-27 12:11:32 +01:00
|
|
|
ERR("No typeinfo for %s?\n",debugstr_guid(riid));
|
2002-02-05 19:11:17 +01:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
nroffuncs = _nroffuncs(tinfo);
|
2004-09-07 22:42:26 +02:00
|
|
|
proxy = CoTaskMemAlloc(sizeof(TMProxyImpl));
|
2002-02-05 19:11:17 +01:00
|
|
|
if (!proxy) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
assert(sizeof(TMAsmProxy) == 12);
|
|
|
|
|
2005-10-26 12:12:30 +02:00
|
|
|
proxy->dispatch = NULL;
|
2006-02-07 16:26:23 +01:00
|
|
|
proxy->dispatch_proxy = NULL;
|
2005-03-11 11:18:31 +01:00
|
|
|
proxy->outerunknown = pUnkOuter;
|
2004-06-29 01:51:24 +02:00
|
|
|
proxy->asmstubs = VirtualAlloc(NULL, sizeof(TMAsmProxy) * nroffuncs, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
|
|
|
|
if (!proxy->asmstubs) {
|
|
|
|
ERR("Could not commit pages for proxy thunks\n");
|
2004-09-07 22:42:26 +02:00
|
|
|
CoTaskMemFree(proxy);
|
2004-06-29 01:51:24 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2007-01-02 16:39:48 +01:00
|
|
|
proxy->lpvtbl2 = &tmproxyvtable;
|
|
|
|
/* one reference for the proxy */
|
|
|
|
proxy->ref = 1;
|
|
|
|
proxy->tinfo = tinfo;
|
|
|
|
memcpy(&proxy->iid,riid,sizeof(*riid));
|
|
|
|
proxy->chanbuf = 0;
|
2004-06-29 01:51:24 +02:00
|
|
|
|
2004-09-07 22:42:26 +02:00
|
|
|
InitializeCriticalSection(&proxy->crit);
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
proxy->lpvtbl = HeapAlloc(GetProcessHeap(),0,sizeof(LPBYTE)*nroffuncs);
|
|
|
|
for (i=0;i<nroffuncs;i++) {
|
|
|
|
TMAsmProxy *xasm = proxy->asmstubs+i;
|
|
|
|
|
|
|
|
switch (i) {
|
2005-03-11 11:18:31 +01:00
|
|
|
case 0:
|
|
|
|
proxy->lpvtbl[i] = ProxyIUnknown_QueryInterface;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
proxy->lpvtbl[i] = ProxyIUnknown_AddRef;
|
2002-02-05 19:11:17 +01:00
|
|
|
break;
|
2005-03-11 11:18:31 +01:00
|
|
|
case 2:
|
|
|
|
proxy->lpvtbl[i] = ProxyIUnknown_Release;
|
2002-02-05 19:11:17 +01:00
|
|
|
break;
|
|
|
|
default: {
|
|
|
|
int j;
|
2005-03-11 11:18:31 +01:00
|
|
|
/* nrofargs without This */
|
|
|
|
int nrofargs;
|
2005-06-01 13:03:40 +02:00
|
|
|
ITypeInfo *tinfo2;
|
|
|
|
hres = _get_funcdesc(tinfo,i,&tinfo2,&fdesc,NULL,NULL);
|
|
|
|
ITypeInfo_Release(tinfo2);
|
2002-02-05 19:11:17 +01:00
|
|
|
if (hres) {
|
2006-10-12 20:57:10 +02:00
|
|
|
ERR("GetFuncDesc %x should not fail here.\n",hres);
|
2002-02-05 19:11:17 +01:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
/* some args take more than 4 byte on the stack */
|
|
|
|
nrofargs = 0;
|
|
|
|
for (j=0;j<fdesc->cParams;j++)
|
|
|
|
nrofargs += _argsize(fdesc->lprgelemdescParam[j].tdesc.vt);
|
|
|
|
|
2005-10-19 21:06:49 +02:00
|
|
|
#ifdef __i386__
|
2002-02-05 19:11:17 +01:00
|
|
|
if (fdesc->callconv != CC_STDCALL) {
|
|
|
|
ERR("calling convention is not stdcall????\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
/* popl %eax - return ptr
|
|
|
|
* pushl <nr>
|
|
|
|
* pushl %eax
|
|
|
|
* call xCall
|
|
|
|
* lret <nr> (+4)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* arg3 arg2 arg1 <method> <returnptr>
|
|
|
|
*/
|
2005-03-11 11:18:31 +01:00
|
|
|
xasm->popleax = 0x58;
|
|
|
|
xasm->pushlval = 0x6a;
|
|
|
|
xasm->nr = i;
|
|
|
|
xasm->pushleax = 0x50;
|
|
|
|
xasm->lcall = 0xe8; /* relative jump */
|
|
|
|
xasm->xcall = (DWORD)xCall;
|
|
|
|
xasm->xcall -= (DWORD)&(xasm->lret);
|
|
|
|
xasm->lret = 0xc2;
|
|
|
|
xasm->bytestopop= (nrofargs+2)*4; /* pop args, This, iMethod */
|
|
|
|
proxy->lpvtbl[i] = xasm;
|
|
|
|
break;
|
2005-10-19 21:06:49 +02:00
|
|
|
#else
|
|
|
|
FIXME("not implemented on non i386\n");
|
|
|
|
return E_FAIL;
|
|
|
|
#endif
|
2005-03-11 11:18:31 +01:00
|
|
|
}
|
|
|
|
}
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
2005-10-26 12:12:30 +02:00
|
|
|
|
|
|
|
/* if we derive from IDispatch then defer to its proxy for its methods */
|
|
|
|
hres = ITypeInfo_GetTypeAttr(tinfo, &typeattr);
|
|
|
|
if (hres == S_OK)
|
|
|
|
{
|
|
|
|
if (typeattr->wTypeFlags & TYPEFLAG_FDISPATCHABLE)
|
|
|
|
{
|
2006-02-07 16:26:23 +01:00
|
|
|
IPSFactoryBuffer *factory_buffer;
|
|
|
|
hres = get_facbuf_for_iid(&IID_IDispatch, &factory_buffer);
|
|
|
|
if (hres == S_OK)
|
|
|
|
{
|
|
|
|
hres = IPSFactoryBuffer_CreateProxy(factory_buffer, NULL,
|
|
|
|
&IID_IDispatch, &proxy->dispatch_proxy,
|
|
|
|
(void **)&proxy->dispatch);
|
|
|
|
IPSFactoryBuffer_Release(factory_buffer);
|
|
|
|
}
|
2007-01-02 16:39:48 +01:00
|
|
|
if ((hres == S_OK) && (nroffuncs < 7))
|
|
|
|
{
|
|
|
|
ERR("nroffuncs calculated incorrectly (%d)\n", nroffuncs);
|
|
|
|
hres = E_UNEXPECTED;
|
|
|
|
}
|
2006-02-07 16:26:23 +01:00
|
|
|
if (hres == S_OK)
|
|
|
|
{
|
|
|
|
proxy->lpvtbl[3] = ProxyIDispatch_GetTypeInfoCount;
|
|
|
|
proxy->lpvtbl[4] = ProxyIDispatch_GetTypeInfo;
|
|
|
|
proxy->lpvtbl[5] = ProxyIDispatch_GetIDsOfNames;
|
|
|
|
proxy->lpvtbl[6] = ProxyIDispatch_Invoke;
|
|
|
|
}
|
2005-10-26 12:12:30 +02:00
|
|
|
}
|
|
|
|
ITypeInfo_ReleaseTypeAttr(tinfo, typeattr);
|
|
|
|
}
|
|
|
|
|
2006-02-07 16:26:23 +01:00
|
|
|
if (hres == S_OK)
|
|
|
|
{
|
|
|
|
*ppv = (LPVOID)proxy;
|
|
|
|
*ppProxy = (IRpcProxyBuffer *)&(proxy->lpvtbl2);
|
|
|
|
IUnknown_AddRef((IUnknown *)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
TMProxyImpl_Release((IRpcProxyBuffer *)&proxy->lpvtbl2);
|
|
|
|
return hres;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct _TMStubImpl {
|
2005-06-06 21:50:35 +02:00
|
|
|
const IRpcStubBufferVtbl *lpvtbl;
|
2005-07-11 12:25:19 +02:00
|
|
|
LONG ref;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
|
|
LPUNKNOWN pUnk;
|
|
|
|
ITypeInfo *tinfo;
|
|
|
|
IID iid;
|
2006-02-07 16:26:23 +01:00
|
|
|
IRpcStubBuffer *dispatch_stub;
|
2006-08-29 22:12:16 +02:00
|
|
|
BOOL dispatch_derivative;
|
2002-02-05 19:11:17 +01:00
|
|
|
} TMStubImpl;
|
|
|
|
|
|
|
|
static HRESULT WINAPI
|
2004-09-07 22:42:26 +02:00
|
|
|
TMStubImpl_QueryInterface(LPRPCSTUBBUFFER iface, REFIID riid, LPVOID *ppv)
|
|
|
|
{
|
2002-02-05 19:11:17 +01:00
|
|
|
if (IsEqualIID(riid,&IID_IRpcStubBuffer)||IsEqualIID(riid,&IID_IUnknown)){
|
|
|
|
*ppv = (LPVOID)iface;
|
|
|
|
IRpcStubBuffer_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
FIXME("%s, not supported IID.\n",debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI
|
2004-09-07 22:42:26 +02:00
|
|
|
TMStubImpl_AddRef(LPRPCSTUBBUFFER iface)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
TMStubImpl *This = (TMStubImpl *)iface;
|
2005-01-14 17:02:20 +01:00
|
|
|
ULONG refCount = InterlockedIncrement(&This->ref);
|
2004-07-30 20:43:27 +02:00
|
|
|
|
2006-10-12 20:57:10 +02:00
|
|
|
TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
2005-01-14 17:02:20 +01:00
|
|
|
return refCount;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI
|
2004-09-07 22:42:26 +02:00
|
|
|
TMStubImpl_Release(LPRPCSTUBBUFFER iface)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
TMStubImpl *This = (TMStubImpl *)iface;
|
2005-01-14 17:02:20 +01:00
|
|
|
ULONG refCount = InterlockedDecrement(&This->ref);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
2006-10-12 20:57:10 +02:00
|
|
|
TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
|
2004-07-30 20:43:27 +02:00
|
|
|
|
2005-01-14 17:02:20 +01:00
|
|
|
if (!refCount)
|
2004-09-07 22:42:26 +02:00
|
|
|
{
|
|
|
|
IRpcStubBuffer_Disconnect(iface);
|
2005-07-19 22:00:07 +02:00
|
|
|
ITypeInfo_Release(This->tinfo);
|
2006-08-29 22:12:16 +02:00
|
|
|
if (This->dispatch_stub)
|
|
|
|
IRpcStubBuffer_Release(This->dispatch_stub);
|
2004-09-07 22:42:26 +02:00
|
|
|
CoTaskMemFree(This);
|
|
|
|
}
|
2005-01-14 17:02:20 +01:00
|
|
|
return refCount;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI
|
2004-09-07 22:42:26 +02:00
|
|
|
TMStubImpl_Connect(LPRPCSTUBBUFFER iface, LPUNKNOWN pUnkServer)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
TMStubImpl *This = (TMStubImpl *)iface;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
2004-07-30 20:43:27 +02:00
|
|
|
TRACE("(%p)->(%p)\n", This, pUnkServer);
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
IUnknown_AddRef(pUnkServer);
|
|
|
|
This->pUnk = pUnkServer;
|
2006-02-07 16:26:23 +01:00
|
|
|
|
|
|
|
if (This->dispatch_stub)
|
|
|
|
IRpcStubBuffer_Connect(This->dispatch_stub, pUnkServer);
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI
|
2004-09-07 22:42:26 +02:00
|
|
|
TMStubImpl_Disconnect(LPRPCSTUBBUFFER iface)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
TMStubImpl *This = (TMStubImpl *)iface;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
2004-07-30 20:43:27 +02:00
|
|
|
TRACE("(%p)->()\n", This);
|
|
|
|
|
2005-07-19 22:00:07 +02:00
|
|
|
if (This->pUnk)
|
|
|
|
{
|
|
|
|
IUnknown_Release(This->pUnk);
|
|
|
|
This->pUnk = NULL;
|
|
|
|
}
|
2006-02-07 16:26:23 +01:00
|
|
|
|
|
|
|
if (This->dispatch_stub)
|
|
|
|
IRpcStubBuffer_Disconnect(This->dispatch_stub);
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI
|
|
|
|
TMStubImpl_Invoke(
|
2004-09-07 22:42:26 +02:00
|
|
|
LPRPCSTUBBUFFER iface, RPCOLEMESSAGE* xmsg,IRpcChannelBuffer*rpcchanbuf)
|
|
|
|
{
|
2002-02-05 19:11:17 +01:00
|
|
|
int i;
|
2005-12-06 21:24:19 +01:00
|
|
|
const FUNCDESC *fdesc;
|
2004-09-09 23:03:58 +02:00
|
|
|
TMStubImpl *This = (TMStubImpl *)iface;
|
2002-02-05 19:11:17 +01:00
|
|
|
HRESULT hres;
|
2006-10-23 12:38:20 +02:00
|
|
|
DWORD *args = NULL, res, *xargs, nrofargs;
|
2002-02-05 19:11:17 +01:00
|
|
|
marshal_state buf;
|
2007-01-16 11:15:20 +01:00
|
|
|
UINT nrofnames = 0;
|
2002-02-05 19:11:17 +01:00
|
|
|
BSTR names[10];
|
2005-10-26 12:12:30 +02:00
|
|
|
BSTR iname = NULL;
|
2006-10-23 12:38:20 +02:00
|
|
|
ITypeInfo *tinfo = NULL;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
|
|
TRACE("...\n");
|
2005-10-26 12:12:30 +02:00
|
|
|
|
|
|
|
if (xmsg->iMethod < 3) {
|
|
|
|
ERR("IUnknown methods cannot be marshaled by the typelib marshaler\n");
|
|
|
|
return E_UNEXPECTED;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
2005-10-26 12:12:30 +02:00
|
|
|
|
2006-08-29 22:12:16 +02:00
|
|
|
if (This->dispatch_derivative && xmsg->iMethod < sizeof(IDispatchVtbl)/sizeof(void *))
|
|
|
|
{
|
|
|
|
IPSFactoryBuffer *factory_buffer;
|
|
|
|
hres = get_facbuf_for_iid(&IID_IDispatch, &factory_buffer);
|
|
|
|
if (hres == S_OK)
|
|
|
|
{
|
|
|
|
hres = IPSFactoryBuffer_CreateStub(factory_buffer, &IID_IDispatch,
|
|
|
|
This->pUnk, &This->dispatch_stub);
|
|
|
|
IPSFactoryBuffer_Release(factory_buffer);
|
|
|
|
}
|
|
|
|
if (hres != S_OK)
|
|
|
|
return hres;
|
2006-02-07 16:26:23 +01:00
|
|
|
return IRpcStubBuffer_Invoke(This->dispatch_stub, xmsg, rpcchanbuf);
|
2006-08-29 22:12:16 +02:00
|
|
|
}
|
2006-02-07 16:26:23 +01:00
|
|
|
|
|
|
|
memset(&buf,0,sizeof(buf));
|
|
|
|
buf.size = xmsg->cbBuffer;
|
|
|
|
buf.base = HeapAlloc(GetProcessHeap(), 0, xmsg->cbBuffer);
|
|
|
|
memcpy(buf.base, xmsg->Buffer, xmsg->cbBuffer);
|
|
|
|
buf.curoff = 0;
|
|
|
|
|
2005-10-26 12:12:30 +02:00
|
|
|
hres = _get_funcdesc(This->tinfo,xmsg->iMethod,&tinfo,&fdesc,&iname,NULL);
|
2002-02-05 19:11:17 +01:00
|
|
|
if (hres) {
|
2006-10-12 20:57:10 +02:00
|
|
|
ERR("GetFuncDesc on method %d failed with %x\n",xmsg->iMethod,hres);
|
2002-02-05 19:11:17 +01:00
|
|
|
return hres;
|
|
|
|
}
|
2005-03-27 19:51:59 +02:00
|
|
|
|
2005-10-26 12:12:30 +02:00
|
|
|
if (iname && !lstrcmpW(iname, IDispatchW))
|
|
|
|
{
|
|
|
|
ERR("IDispatch cannot be marshaled by the typelib marshaler\n");
|
2006-10-23 12:38:20 +02:00
|
|
|
hres = E_UNEXPECTED;
|
|
|
|
SysFreeString (iname);
|
|
|
|
goto exit;
|
2005-10-26 12:12:30 +02:00
|
|
|
}
|
2005-03-27 19:51:59 +02:00
|
|
|
|
|
|
|
if (iname) SysFreeString (iname);
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
/* Need them for hack below */
|
|
|
|
memset(names,0,sizeof(names));
|
2005-06-01 13:03:40 +02:00
|
|
|
ITypeInfo_GetNames(tinfo,fdesc->memid,names,sizeof(names)/sizeof(names[0]),&nrofnames);
|
2002-02-05 19:11:17 +01:00
|
|
|
if (nrofnames > sizeof(names)/sizeof(names[0])) {
|
|
|
|
ERR("Need more names!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*dump_FUNCDESC(fdesc);*/
|
|
|
|
nrofargs = 0;
|
|
|
|
for (i=0;i<fdesc->cParams;i++)
|
|
|
|
nrofargs += _argsize(fdesc->lprgelemdescParam[i].tdesc.vt);
|
|
|
|
args = HeapAlloc(GetProcessHeap(),0,(nrofargs+1)*sizeof(DWORD));
|
2006-10-23 12:38:20 +02:00
|
|
|
if (!args)
|
|
|
|
{
|
|
|
|
hres = E_OUTOFMEMORY;
|
|
|
|
goto exit;
|
|
|
|
}
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
|
|
/* Allocate all stuff used by call. */
|
|
|
|
xargs = args+1;
|
|
|
|
for (i=0;i<fdesc->cParams;i++) {
|
|
|
|
ELEMDESC *elem = fdesc->lprgelemdescParam+i;
|
2002-06-10 04:30:20 +02:00
|
|
|
|
2005-10-26 12:12:30 +02:00
|
|
|
hres = deserialize_param(
|
|
|
|
tinfo,
|
2005-10-26 14:06:49 +02:00
|
|
|
elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN || !elem->u.paramdesc.wParamFlags,
|
2005-10-26 12:12:30 +02:00
|
|
|
FALSE,
|
|
|
|
TRUE,
|
|
|
|
&(elem->tdesc),
|
|
|
|
xargs,
|
|
|
|
&buf
|
|
|
|
);
|
2002-02-05 19:11:17 +01:00
|
|
|
xargs += _argsize(elem->tdesc.vt);
|
|
|
|
if (hres) {
|
2006-10-12 20:57:10 +02:00
|
|
|
ERR("Failed to deserialize param %s, hres %x\n",relaystr(names[i+1]),hres);
|
2002-02-05 19:11:17 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-10-26 12:12:30 +02:00
|
|
|
|
2005-10-27 14:08:58 +02:00
|
|
|
args[0] = (DWORD)This->pUnk;
|
2006-07-17 21:19:27 +02:00
|
|
|
|
|
|
|
__TRY
|
|
|
|
{
|
|
|
|
res = _invoke(
|
|
|
|
(*((FARPROC**)args[0]))[fdesc->oVft/4],
|
|
|
|
fdesc->callconv,
|
|
|
|
(xargs-args),
|
|
|
|
args
|
|
|
|
);
|
|
|
|
}
|
|
|
|
__EXCEPT(NULL)
|
|
|
|
{
|
|
|
|
DWORD dwExceptionCode = GetExceptionCode();
|
2006-10-12 20:57:10 +02:00
|
|
|
ERR("invoke call failed with exception 0x%08x (%d)\n", dwExceptionCode, dwExceptionCode);
|
2006-07-17 21:19:27 +02:00
|
|
|
if (FAILED(dwExceptionCode))
|
|
|
|
hres = dwExceptionCode;
|
|
|
|
else
|
|
|
|
hres = HRESULT_FROM_WIN32(dwExceptionCode);
|
|
|
|
}
|
|
|
|
__ENDTRY
|
|
|
|
|
|
|
|
if (hres != S_OK)
|
2006-10-23 12:38:20 +02:00
|
|
|
goto exit;
|
2006-07-17 21:19:27 +02:00
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
buf.curoff = 0;
|
2005-03-27 19:51:59 +02:00
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
xargs = args+1;
|
|
|
|
for (i=0;i<fdesc->cParams;i++) {
|
|
|
|
ELEMDESC *elem = fdesc->lprgelemdescParam+i;
|
2005-10-26 12:12:30 +02:00
|
|
|
hres = serialize_param(
|
|
|
|
tinfo,
|
|
|
|
elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT,
|
|
|
|
FALSE,
|
|
|
|
TRUE,
|
|
|
|
&elem->tdesc,
|
|
|
|
xargs,
|
|
|
|
&buf
|
|
|
|
);
|
2002-02-05 19:11:17 +01:00
|
|
|
xargs += _argsize(elem->tdesc.vt);
|
|
|
|
if (hres) {
|
2006-10-12 20:57:10 +02:00
|
|
|
ERR("Failed to stuballoc param, hres %x\n",hres);
|
2002-02-05 19:11:17 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-10-26 12:12:30 +02:00
|
|
|
|
2005-03-28 12:00:49 +02:00
|
|
|
hres = xbuf_add (&buf, (LPBYTE)&res, sizeof(DWORD));
|
2006-10-23 12:29:09 +02:00
|
|
|
|
2005-03-28 12:00:49 +02:00
|
|
|
if (hres != S_OK)
|
2006-10-23 12:38:20 +02:00
|
|
|
goto exit;
|
2005-08-29 23:46:51 +02:00
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
xmsg->cbBuffer = buf.curoff;
|
2006-06-09 18:25:50 +02:00
|
|
|
hres = IRpcChannelBuffer_GetBuffer(rpcchanbuf, xmsg, &This->iid);
|
|
|
|
if (hres != S_OK)
|
2006-10-12 20:57:10 +02:00
|
|
|
ERR("IRpcChannelBuffer_GetBuffer failed with error 0x%08x\n", hres);
|
2005-08-29 23:46:51 +02:00
|
|
|
|
|
|
|
if (hres == S_OK)
|
|
|
|
memcpy(xmsg->Buffer, buf.base, buf.curoff);
|
|
|
|
|
2006-10-23 12:38:20 +02:00
|
|
|
exit:
|
|
|
|
for (i = 0; i < nrofnames; i++)
|
|
|
|
SysFreeString(names[i]);
|
|
|
|
|
|
|
|
ITypeInfo_Release(tinfo);
|
|
|
|
HeapFree(GetProcessHeap(), 0, args);
|
|
|
|
|
2005-08-29 23:46:51 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, buf.base);
|
|
|
|
|
|
|
|
TRACE("returning\n");
|
|
|
|
return hres;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static LPRPCSTUBBUFFER WINAPI
|
|
|
|
TMStubImpl_IsIIDSupported(LPRPCSTUBBUFFER iface, REFIID riid) {
|
|
|
|
FIXME("Huh (%s)?\n",debugstr_guid(riid));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI
|
|
|
|
TMStubImpl_CountRefs(LPRPCSTUBBUFFER iface) {
|
2004-09-09 23:03:58 +02:00
|
|
|
TMStubImpl *This = (TMStubImpl *)iface;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
2005-08-29 23:46:51 +02:00
|
|
|
FIXME("()\n");
|
2002-02-05 19:11:17 +01:00
|
|
|
return This->ref; /*FIXME? */
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI
|
|
|
|
TMStubImpl_DebugServerQueryInterface(LPRPCSTUBBUFFER iface, LPVOID *ppv) {
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI
|
|
|
|
TMStubImpl_DebugServerRelease(LPRPCSTUBBUFFER iface, LPVOID ppv) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IRpcStubBufferVtbl tmstubvtbl = {
|
2002-02-05 19:11:17 +01:00
|
|
|
TMStubImpl_QueryInterface,
|
|
|
|
TMStubImpl_AddRef,
|
|
|
|
TMStubImpl_Release,
|
|
|
|
TMStubImpl_Connect,
|
|
|
|
TMStubImpl_Disconnect,
|
|
|
|
TMStubImpl_Invoke,
|
|
|
|
TMStubImpl_IsIIDSupported,
|
|
|
|
TMStubImpl_CountRefs,
|
|
|
|
TMStubImpl_DebugServerQueryInterface,
|
|
|
|
TMStubImpl_DebugServerRelease
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT WINAPI
|
|
|
|
PSFacBuf_CreateStub(
|
|
|
|
LPPSFACTORYBUFFER iface, REFIID riid,IUnknown *pUnkServer,
|
|
|
|
IRpcStubBuffer** ppStub
|
|
|
|
) {
|
|
|
|
HRESULT hres;
|
|
|
|
ITypeInfo *tinfo;
|
|
|
|
TMStubImpl *stub;
|
2006-02-07 16:26:23 +01:00
|
|
|
TYPEATTR *typeattr;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
|
|
TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub);
|
2006-02-07 16:26:23 +01:00
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
hres = _get_typeinfo_for_iid(riid,&tinfo);
|
|
|
|
if (hres) {
|
2005-01-27 12:11:32 +01:00
|
|
|
ERR("No typeinfo for %s?\n",debugstr_guid(riid));
|
2002-02-05 19:11:17 +01:00
|
|
|
return hres;
|
|
|
|
}
|
2006-02-07 16:26:23 +01:00
|
|
|
|
2004-09-07 22:42:26 +02:00
|
|
|
stub = CoTaskMemAlloc(sizeof(TMStubImpl));
|
2002-02-05 19:11:17 +01:00
|
|
|
if (!stub)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
stub->lpvtbl = &tmstubvtbl;
|
|
|
|
stub->ref = 1;
|
|
|
|
stub->tinfo = tinfo;
|
2006-02-07 16:26:23 +01:00
|
|
|
stub->dispatch_stub = NULL;
|
2006-08-29 22:12:16 +02:00
|
|
|
stub->dispatch_derivative = FALSE;
|
2002-02-05 19:11:17 +01:00
|
|
|
memcpy(&(stub->iid),riid,sizeof(*riid));
|
|
|
|
hres = IRpcStubBuffer_Connect((LPRPCSTUBBUFFER)stub,pUnkServer);
|
|
|
|
*ppStub = (LPRPCSTUBBUFFER)stub;
|
2004-07-30 20:43:27 +02:00
|
|
|
TRACE("IRpcStubBuffer: %p\n", stub);
|
2002-02-05 19:11:17 +01:00
|
|
|
if (hres)
|
2005-01-27 12:11:32 +01:00
|
|
|
ERR("Connect to pUnkServer failed?\n");
|
2006-02-07 16:26:23 +01:00
|
|
|
|
|
|
|
/* if we derive from IDispatch then defer to its stub for some of its methods */
|
|
|
|
hres = ITypeInfo_GetTypeAttr(tinfo, &typeattr);
|
|
|
|
if (hres == S_OK)
|
|
|
|
{
|
|
|
|
if (typeattr->wTypeFlags & TYPEFLAG_FDISPATCHABLE)
|
2006-08-29 22:12:16 +02:00
|
|
|
stub->dispatch_derivative = TRUE;
|
2006-02-07 16:26:23 +01:00
|
|
|
ITypeInfo_ReleaseTypeAttr(tinfo, typeattr);
|
|
|
|
}
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IPSFactoryBufferVtbl psfacbufvtbl = {
|
2002-02-05 19:11:17 +01:00
|
|
|
PSFacBuf_QueryInterface,
|
|
|
|
PSFacBuf_AddRef,
|
|
|
|
PSFacBuf_Release,
|
|
|
|
PSFacBuf_CreateProxy,
|
|
|
|
PSFacBuf_CreateStub
|
|
|
|
};
|
|
|
|
|
|
|
|
/* This is the whole PSFactoryBuffer object, just the vtableptr */
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IPSFactoryBufferVtbl *lppsfac = &psfacbufvtbl;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
2005-08-09 12:38:54 +02:00
|
|
|
* TMARSHAL_DllGetClassObject
|
2002-02-05 19:11:17 +01:00
|
|
|
*/
|
2005-08-09 12:38:54 +02:00
|
|
|
HRESULT TMARSHAL_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
|
2002-02-05 19:11:17 +01:00
|
|
|
{
|
|
|
|
if (IsEqualIID(iid,&IID_IPSFactoryBuffer)) {
|
|
|
|
*ppv = &lppsfac;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|