2 * free threaded marshaller
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
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(ole);
39 typedef struct _FTMarshalImpl {
42 IMarshalVtbl *lpvtblFTM;
47 #define _IFTMUnknown_(This)(IUnknown*)&(This->lpVtbl)
48 #define _IFTMarshal_(This) (IMarshal*)&(This->lpvtblFTM)
50 #define _IFTMarshall_Offset ((int)(&(((FTMarshalImpl*)0)->lpvtblFTM)))
51 #define _ICOM_THIS_From_IFTMarshal(class, name) class* This = (class*)(((char*)name)-_IFTMarshall_Offset);
53 /* inner IUnknown to handle aggregation */
54 HRESULT WINAPI IiFTMUnknown_fnQueryInterface (IUnknown * iface, REFIID riid, LPVOID * ppv)
57 FTMarshalImpl *This = (FTMarshalImpl *)iface;
62 if (IsEqualIID (&IID_IUnknown, riid))
63 *ppv = _IFTMUnknown_ (This);
64 else if (IsEqualIID (&IID_IMarshal, riid))
65 *ppv = _IFTMarshal_ (This);
67 FIXME ("No interface for %s.\n", debugstr_guid (riid));
70 IUnknown_AddRef ((IUnknown *) * ppv);
74 ULONG WINAPI IiFTMUnknown_fnAddRef (IUnknown * iface)
77 FTMarshalImpl *This = (FTMarshalImpl *)iface;
80 return InterlockedIncrement (&This->ref);
83 ULONG WINAPI IiFTMUnknown_fnRelease (IUnknown * iface)
86 FTMarshalImpl *This = (FTMarshalImpl *)iface;
89 if (InterlockedDecrement (&This->ref))
91 HeapFree (GetProcessHeap (), 0, This);
95 static IUnknownVtbl iunkvt =
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 marshalling happens inside the same process the interface pointer is
148 copied between the apartments */
149 if (dwDestContext == MSHCTX_INPROC || dwDestContext == MSHCTX_CROSSCTX) {
150 *pSize = sizeof (This);
154 /* use the standard marshaller 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 marshalling happens inside the same process the interface pointer is
175 copied between the apartments */
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 IMarshalVtbl ftmvtbl =
207 FTMarshalImpl_QueryInterface,
208 FTMarshalImpl_AddRef,
209 FTMarshalImpl_Release,
210 FTMarshalImpl_GetUnmarshalClass,
211 FTMarshalImpl_GetMarshalSizeMax,
212 FTMarshalImpl_MarshalInterface,
213 FTMarshalImpl_UnmarshalInterface,
214 FTMarshalImpl_ReleaseMarshalData,
215 FTMarshalImpl_DisconnectObject
218 /***********************************************************************
219 * CoCreateFreeThreadedMarshaler [OLE32.@]
222 HRESULT WINAPI CoCreateFreeThreadedMarshaler (LPUNKNOWN punkOuter, LPUNKNOWN * ppunkMarshal)
227 TRACE ("(%p %p)\n", punkOuter, ppunkMarshal);
229 ftm = (FTMarshalImpl *) HeapAlloc (GetProcessHeap (), 0, sizeof (FTMarshalImpl));
231 return E_OUTOFMEMORY;
233 ftm->lpVtbl = &iunkvt;
234 ftm->lpvtblFTM = &ftmvtbl;
236 ftm->pUnkOuter = punkOuter;
238 *ppunkMarshal = _IFTMUnknown_ (ftm);