2002-08-03 00:17:10 +00:00
|
|
|
/*
|
2003-05-13 00:41:57 +00:00
|
|
|
* free threaded marshaller
|
2002-08-03 00:17:10 +00:00
|
|
|
*
|
|
|
|
* Copyright 2002 Juergen Schmied
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2003-09-05 23:08:26 +00:00
|
|
|
#include <stdarg.h>
|
2002-08-03 00:17:10 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2004-10-07 03:06:48 +00:00
|
|
|
#define COBJMACROS
|
|
|
|
|
2003-09-05 23:08:26 +00:00
|
|
|
#include "windef.h"
|
2002-08-03 00:17:10 +00:00
|
|
|
#include "winbase.h"
|
2002-12-05 20:33:07 +00:00
|
|
|
#include "objbase.h"
|
2002-08-03 00:17:10 +00:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
|
|
|
|
|
|
|
typedef struct _FTMarshalImpl {
|
2005-06-06 19:50:35 +00:00
|
|
|
const IUnknownVtbl *lpVtbl;
|
2005-07-05 11:02:54 +00:00
|
|
|
LONG ref;
|
2005-06-06 19:50:35 +00:00
|
|
|
const IMarshalVtbl *lpvtblFTM;
|
2002-08-03 00:17:10 +00:00
|
|
|
|
|
|
|
IUnknown *pUnkOuter;
|
|
|
|
} FTMarshalImpl;
|
|
|
|
|
|
|
|
#define _IFTMUnknown_(This)(IUnknown*)&(This->lpVtbl)
|
|
|
|
#define _IFTMarshal_(This) (IMarshal*)&(This->lpvtblFTM)
|
|
|
|
|
2005-07-27 11:10:52 +00:00
|
|
|
static inline FTMarshalImpl *impl_from_IMarshal( IMarshal *iface )
|
|
|
|
{
|
|
|
|
return (FTMarshalImpl *)((char*)iface - FIELD_OFFSET(FTMarshalImpl, lpvtblFTM));
|
|
|
|
}
|
2002-08-03 00:17:10 +00:00
|
|
|
|
|
|
|
/* inner IUnknown to handle aggregation */
|
2005-05-16 08:47:26 +00:00
|
|
|
static HRESULT WINAPI
|
|
|
|
IiFTMUnknown_fnQueryInterface (IUnknown * iface, REFIID riid, LPVOID * ppv)
|
2002-08-03 00:17:10 +00:00
|
|
|
{
|
|
|
|
|
2004-09-06 20:34:29 +00:00
|
|
|
FTMarshalImpl *This = (FTMarshalImpl *)iface;
|
2002-08-03 00:17:10 +00:00
|
|
|
|
|
|
|
TRACE ("\n");
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if (IsEqualIID (&IID_IUnknown, riid))
|
|
|
|
*ppv = _IFTMUnknown_ (This);
|
|
|
|
else if (IsEqualIID (&IID_IMarshal, riid))
|
|
|
|
*ppv = _IFTMarshal_ (This);
|
|
|
|
else {
|
|
|
|
FIXME ("No interface for %s.\n", debugstr_guid (riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
IUnknown_AddRef ((IUnknown *) * ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2005-05-16 08:47:26 +00:00
|
|
|
static ULONG WINAPI IiFTMUnknown_fnAddRef (IUnknown * iface)
|
2002-08-03 00:17:10 +00:00
|
|
|
{
|
|
|
|
|
2004-09-06 20:34:29 +00:00
|
|
|
FTMarshalImpl *This = (FTMarshalImpl *)iface;
|
2002-08-03 00:17:10 +00:00
|
|
|
|
|
|
|
TRACE ("\n");
|
|
|
|
return InterlockedIncrement (&This->ref);
|
|
|
|
}
|
|
|
|
|
2005-05-16 08:47:26 +00:00
|
|
|
static ULONG WINAPI IiFTMUnknown_fnRelease (IUnknown * iface)
|
2002-08-03 00:17:10 +00:00
|
|
|
{
|
|
|
|
|
2004-09-06 20:34:29 +00:00
|
|
|
FTMarshalImpl *This = (FTMarshalImpl *)iface;
|
2002-08-03 00:17:10 +00:00
|
|
|
|
|
|
|
TRACE ("\n");
|
|
|
|
if (InterlockedDecrement (&This->ref))
|
|
|
|
return This->ref;
|
|
|
|
HeapFree (GetProcessHeap (), 0, This);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-06 19:50:35 +00:00
|
|
|
static const IUnknownVtbl iunkvt =
|
2002-08-03 00:17:10 +00:00
|
|
|
{
|
|
|
|
IiFTMUnknown_fnQueryInterface,
|
|
|
|
IiFTMUnknown_fnAddRef,
|
|
|
|
IiFTMUnknown_fnRelease
|
|
|
|
};
|
|
|
|
|
2005-05-16 08:47:26 +00:00
|
|
|
static HRESULT WINAPI
|
|
|
|
FTMarshalImpl_QueryInterface (LPMARSHAL iface, REFIID riid, LPVOID * ppv)
|
2002-08-03 00:17:10 +00:00
|
|
|
{
|
|
|
|
|
2005-07-27 11:10:52 +00:00
|
|
|
FTMarshalImpl *This = impl_from_IMarshal(iface);
|
2002-08-03 00:17:10 +00:00
|
|
|
|
|
|
|
TRACE ("(%p)->(\n\tIID:\t%s,%p)\n", This, debugstr_guid (riid), ppv);
|
|
|
|
return IUnknown_QueryInterface (This->pUnkOuter, riid, ppv);
|
|
|
|
}
|
|
|
|
|
2005-05-16 08:47:26 +00:00
|
|
|
static ULONG WINAPI
|
|
|
|
FTMarshalImpl_AddRef (LPMARSHAL iface)
|
2002-08-03 00:17:10 +00:00
|
|
|
{
|
|
|
|
|
2005-07-27 11:10:52 +00:00
|
|
|
FTMarshalImpl *This = impl_from_IMarshal(iface);
|
2002-08-03 00:17:10 +00:00
|
|
|
|
|
|
|
TRACE ("\n");
|
|
|
|
return IUnknown_AddRef (This->pUnkOuter);
|
|
|
|
}
|
|
|
|
|
2005-05-16 08:47:26 +00:00
|
|
|
static ULONG WINAPI
|
|
|
|
FTMarshalImpl_Release (LPMARSHAL iface)
|
2002-08-03 00:17:10 +00:00
|
|
|
{
|
|
|
|
|
2005-07-27 11:10:52 +00:00
|
|
|
FTMarshalImpl *This = impl_from_IMarshal(iface);
|
2002-08-03 00:17:10 +00:00
|
|
|
|
|
|
|
TRACE ("\n");
|
|
|
|
return IUnknown_Release (This->pUnkOuter);
|
|
|
|
}
|
|
|
|
|
2005-05-16 08:47:26 +00:00
|
|
|
static HRESULT WINAPI
|
|
|
|
FTMarshalImpl_GetUnmarshalClass (LPMARSHAL iface, REFIID riid, void *pv, DWORD dwDestContext,
|
2002-08-03 00:17:10 +00:00
|
|
|
void *pvDestContext, DWORD mshlflags, CLSID * pCid)
|
|
|
|
{
|
|
|
|
FIXME ("(), stub!\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2005-05-16 08:47:26 +00:00
|
|
|
static HRESULT WINAPI
|
|
|
|
FTMarshalImpl_GetMarshalSizeMax (LPMARSHAL iface, REFIID riid, void *pv, DWORD dwDestContext,
|
2002-08-03 00:17:10 +00:00
|
|
|
void *pvDestContext, DWORD mshlflags, DWORD * pSize)
|
|
|
|
{
|
|
|
|
|
|
|
|
IMarshal *pMarshal = NULL;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2005-07-27 11:10:52 +00:00
|
|
|
FTMarshalImpl *This = impl_from_IMarshal(iface);
|
2002-08-03 00:17:10 +00:00
|
|
|
|
|
|
|
FIXME ("(), stub!\n");
|
|
|
|
|
2003-05-13 00:41:57 +00:00
|
|
|
/* if the marshalling happens inside the same process the interface pointer is
|
|
|
|
copied between the apartments */
|
2002-08-03 00:17:10 +00:00
|
|
|
if (dwDestContext == MSHCTX_INPROC || dwDestContext == MSHCTX_CROSSCTX) {
|
|
|
|
*pSize = sizeof (This);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2003-05-13 00:41:57 +00:00
|
|
|
/* use the standard marshaller to handle all other cases */
|
2002-08-03 00:17:10 +00:00
|
|
|
CoGetStandardMarshal (riid, pv, dwDestContext, pvDestContext, mshlflags, &pMarshal);
|
|
|
|
hres = IMarshal_GetMarshalSizeMax (pMarshal, riid, pv, dwDestContext, pvDestContext, mshlflags, pSize);
|
|
|
|
IMarshal_Release (pMarshal);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2005-05-16 08:47:26 +00:00
|
|
|
static HRESULT WINAPI
|
|
|
|
FTMarshalImpl_MarshalInterface (LPMARSHAL iface, IStream * pStm, REFIID riid, void *pv,
|
|
|
|
DWORD dwDestContext, void *pvDestContext, DWORD mshlflags)
|
2002-08-03 00:17:10 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
IMarshal *pMarshal = NULL;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2005-07-27 11:10:52 +00:00
|
|
|
FTMarshalImpl *This = impl_from_IMarshal(iface);
|
2002-08-03 00:17:10 +00:00
|
|
|
|
|
|
|
FIXME ("(), stub!\n");
|
|
|
|
|
2003-05-13 00:41:57 +00:00
|
|
|
/* if the marshalling happens inside the same process the interface pointer is
|
|
|
|
copied between the apartments */
|
2002-08-03 00:17:10 +00:00
|
|
|
if (dwDestContext == MSHCTX_INPROC || dwDestContext == MSHCTX_CROSSCTX) {
|
|
|
|
return IStream_Write (pStm, This, sizeof (This), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* use the standard marshaler to handle all other cases */
|
|
|
|
CoGetStandardMarshal (riid, pv, dwDestContext, pvDestContext, mshlflags, &pMarshal);
|
|
|
|
hres = IMarshal_MarshalInterface (pMarshal, pStm, riid, pv, dwDestContext, pvDestContext, mshlflags);
|
|
|
|
IMarshal_Release (pMarshal);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2005-05-16 08:47:26 +00:00
|
|
|
static HRESULT WINAPI
|
|
|
|
FTMarshalImpl_UnmarshalInterface (LPMARSHAL iface, IStream * pStm, REFIID riid, void **ppv)
|
2002-08-03 00:17:10 +00:00
|
|
|
{
|
|
|
|
FIXME ("(), stub!\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2005-05-16 08:47:26 +00:00
|
|
|
static HRESULT WINAPI FTMarshalImpl_ReleaseMarshalData (LPMARSHAL iface, IStream * pStm)
|
2002-08-03 00:17:10 +00:00
|
|
|
{
|
|
|
|
FIXME ("(), stub!\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2005-05-16 08:47:26 +00:00
|
|
|
static HRESULT WINAPI FTMarshalImpl_DisconnectObject (LPMARSHAL iface, DWORD dwReserved)
|
2002-08-03 00:17:10 +00:00
|
|
|
{
|
|
|
|
FIXME ("(), stub!\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2005-06-06 19:50:35 +00:00
|
|
|
static const IMarshalVtbl ftmvtbl =
|
2002-08-03 00:17:10 +00:00
|
|
|
{
|
|
|
|
FTMarshalImpl_QueryInterface,
|
|
|
|
FTMarshalImpl_AddRef,
|
|
|
|
FTMarshalImpl_Release,
|
|
|
|
FTMarshalImpl_GetUnmarshalClass,
|
|
|
|
FTMarshalImpl_GetMarshalSizeMax,
|
|
|
|
FTMarshalImpl_MarshalInterface,
|
|
|
|
FTMarshalImpl_UnmarshalInterface,
|
|
|
|
FTMarshalImpl_ReleaseMarshalData,
|
|
|
|
FTMarshalImpl_DisconnectObject
|
|
|
|
};
|
|
|
|
|
|
|
|
/***********************************************************************
|
2003-09-11 03:06:25 +00:00
|
|
|
* CoCreateFreeThreadedMarshaler [OLE32.@]
|
2002-08-03 00:17:10 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI CoCreateFreeThreadedMarshaler (LPUNKNOWN punkOuter, LPUNKNOWN * ppunkMarshal)
|
|
|
|
{
|
|
|
|
|
|
|
|
FTMarshalImpl *ftm;
|
|
|
|
|
|
|
|
TRACE ("(%p %p)\n", punkOuter, ppunkMarshal);
|
|
|
|
|
2005-03-21 11:25:13 +00:00
|
|
|
ftm = HeapAlloc (GetProcessHeap (), 0, sizeof (FTMarshalImpl));
|
2002-08-03 00:17:10 +00:00
|
|
|
if (!ftm)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2003-04-10 18:17:34 +00:00
|
|
|
ftm->lpVtbl = &iunkvt;
|
2002-08-03 00:17:10 +00:00
|
|
|
ftm->lpvtblFTM = &ftmvtbl;
|
|
|
|
ftm->ref = 1;
|
|
|
|
ftm->pUnkOuter = punkOuter;
|
|
|
|
|
|
|
|
*ppunkMarshal = _IFTMUnknown_ (ftm);
|
|
|
|
return S_OK;
|
|
|
|
}
|