2 * free threaded marshaler
4 * Copyright 2002 Juergen Schmied
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "wine/obj_base.h"
31 #include "wine/obj_storage.h"
32 #include "wine/obj_marshal.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(ole);
38 typedef struct _FTMarshalImpl {
39 ICOM_VFIELD (IUnknown);
41 ICOM_VTABLE (IMarshal) * lpvtblFTM;
46 #define _IFTMUnknown_(This)(IUnknown*)&(This->lpVtbl)
47 #define _IFTMarshal_(This) (IMarshal*)&(This->lpvtblFTM)
49 #define _IFTMarshall_Offset ((int)(&(((FTMarshalImpl*)0)->lpvtblFTM)))
50 #define _ICOM_THIS_From_IFTMarshal(class, name) class* This = (class*)(((char*)name)-_IFTMarshall_Offset);
52 /* inner IUnknown to handle aggregation */
53 HRESULT WINAPI IiFTMUnknown_fnQueryInterface (IUnknown * iface, REFIID riid, LPVOID * ppv)
56 ICOM_THIS (FTMarshalImpl, iface);
61 if (IsEqualIID (&IID_IUnknown, riid))
62 *ppv = _IFTMUnknown_ (This);
63 else if (IsEqualIID (&IID_IMarshal, riid))
64 *ppv = _IFTMarshal_ (This);
66 FIXME ("No interface for %s.\n", debugstr_guid (riid));
69 IUnknown_AddRef ((IUnknown *) * ppv);
73 ULONG WINAPI IiFTMUnknown_fnAddRef (IUnknown * iface)
76 ICOM_THIS (FTMarshalImpl, iface);
79 return InterlockedIncrement (&This->ref);
82 ULONG WINAPI IiFTMUnknown_fnRelease (IUnknown * iface)
85 ICOM_THIS (FTMarshalImpl, iface);
88 if (InterlockedDecrement (&This->ref))
90 HeapFree (GetProcessHeap (), 0, This);
94 static ICOM_VTABLE (IUnknown) iunkvt =
96 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
97 IiFTMUnknown_fnQueryInterface,
98 IiFTMUnknown_fnAddRef,
99 IiFTMUnknown_fnRelease
102 HRESULT WINAPI FTMarshalImpl_QueryInterface (LPMARSHAL iface, REFIID riid, LPVOID * ppv)
105 _ICOM_THIS_From_IFTMarshal (FTMarshalImpl, iface);
107 TRACE ("(%p)->(\n\tIID:\t%s,%p)\n", This, debugstr_guid (riid), ppv);
108 return IUnknown_QueryInterface (This->pUnkOuter, riid, ppv);
111 ULONG WINAPI FTMarshalImpl_AddRef (LPMARSHAL iface)
114 _ICOM_THIS_From_IFTMarshal (FTMarshalImpl, iface);
117 return IUnknown_AddRef (This->pUnkOuter);
120 ULONG WINAPI FTMarshalImpl_Release (LPMARSHAL iface)
123 _ICOM_THIS_From_IFTMarshal (FTMarshalImpl, iface);
126 return IUnknown_Release (This->pUnkOuter);
129 HRESULT WINAPI FTMarshalImpl_GetUnmarshalClass (LPMARSHAL iface, REFIID riid, void *pv, DWORD dwDestContext,
130 void *pvDestContext, DWORD mshlflags, CLSID * pCid)
132 FIXME ("(), stub!\n");
136 HRESULT WINAPI FTMarshalImpl_GetMarshalSizeMax (LPMARSHAL iface, REFIID riid, void *pv, DWORD dwDestContext,
137 void *pvDestContext, DWORD mshlflags, DWORD * pSize)
140 IMarshal *pMarshal = NULL;
143 _ICOM_THIS_From_IFTMarshal (FTMarshalImpl, iface);
145 FIXME ("(), stub!\n");
147 /* if the marshaling happends inside the same process the interface pointer is
148 copied between the appartments */
149 if (dwDestContext == MSHCTX_INPROC || dwDestContext == MSHCTX_CROSSCTX) {
150 *pSize = sizeof (This);
154 /* use the standard marshaler to handle all other cases */
155 CoGetStandardMarshal (riid, pv, dwDestContext, pvDestContext, mshlflags, &pMarshal);
156 hres = IMarshal_GetMarshalSizeMax (pMarshal, riid, pv, dwDestContext, pvDestContext, mshlflags, pSize);
157 IMarshal_Release (pMarshal);
163 HRESULT WINAPI FTMarshalImpl_MarshalInterface (LPMARSHAL iface, IStream * pStm, REFIID riid, void *pv,
164 DWORD dwDestContext, void *pvDestContext, DWORD mshlflags)
167 IMarshal *pMarshal = NULL;
170 _ICOM_THIS_From_IFTMarshal (FTMarshalImpl, iface);
172 FIXME ("(), stub!\n");
174 /* if the marshaling happends inside the same process the interface pointer is
175 copied between the appartments */
176 if (dwDestContext == MSHCTX_INPROC || dwDestContext == MSHCTX_CROSSCTX) {
177 return IStream_Write (pStm, This, sizeof (This), 0);
180 /* use the standard marshaler to handle all other cases */
181 CoGetStandardMarshal (riid, pv, dwDestContext, pvDestContext, mshlflags, &pMarshal);
182 hres = IMarshal_MarshalInterface (pMarshal, pStm, riid, pv, dwDestContext, pvDestContext, mshlflags);
183 IMarshal_Release (pMarshal);
187 HRESULT WINAPI FTMarshalImpl_UnmarshalInterface (LPMARSHAL iface, IStream * pStm, REFIID riid, void **ppv)
189 FIXME ("(), stub!\n");
193 HRESULT WINAPI FTMarshalImpl_ReleaseMarshalData (LPMARSHAL iface, IStream * pStm)
195 FIXME ("(), stub!\n");
199 HRESULT WINAPI FTMarshalImpl_DisconnectObject (LPMARSHAL iface, DWORD dwReserved)
201 FIXME ("(), stub!\n");
205 ICOM_VTABLE (IMarshal) ftmvtbl =
207 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
208 FTMarshalImpl_QueryInterface,
209 FTMarshalImpl_AddRef,
210 FTMarshalImpl_Release,
211 FTMarshalImpl_GetUnmarshalClass,
212 FTMarshalImpl_GetMarshalSizeMax,
213 FTMarshalImpl_MarshalInterface,
214 FTMarshalImpl_UnmarshalInterface,
215 FTMarshalImpl_ReleaseMarshalData,
216 FTMarshalImpl_DisconnectObject
219 /***********************************************************************
220 * CoCreateFreeThreadedMarshaler [OLE32.5]
223 HRESULT WINAPI CoCreateFreeThreadedMarshaler (LPUNKNOWN punkOuter, LPUNKNOWN * ppunkMarshal)
228 TRACE ("(%p %p)\n", punkOuter, ppunkMarshal);
230 ftm = (FTMarshalImpl *) HeapAlloc (GetProcessHeap (), 0, sizeof (FTMarshalImpl));
232 return E_OUTOFMEMORY;
234 ICOM_VTBL (ftm) = &iunkvt;
235 ftm->lpvtblFTM = &ftmvtbl;
237 ftm->pUnkOuter = punkOuter;
239 *ppunkMarshal = _IFTMUnknown_ (ftm);