Make sure __ASM_GLOBAL_FUNC generates code in the text segment.
[wine/wine64.git] / dlls / ole32 / ftmarshal.c
blobd0e39f094440d173c98cb48cc2cec397fc4a8275
1 /*
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
21 #include "config.h"
23 #include <stdlib.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <assert.h>
29 #include "windef.h"
30 #include "winbase.h"
31 #include "objbase.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(ole);
37 typedef struct _FTMarshalImpl {
38 ICOM_VFIELD (IUnknown);
39 DWORD ref;
40 ICOM_VTABLE (IMarshal) * lpvtblFTM;
42 IUnknown *pUnkOuter;
43 } FTMarshalImpl;
45 #define _IFTMUnknown_(This)(IUnknown*)&(This->lpVtbl)
46 #define _IFTMarshal_(This) (IMarshal*)&(This->lpvtblFTM)
48 #define _IFTMarshall_Offset ((int)(&(((FTMarshalImpl*)0)->lpvtblFTM)))
49 #define _ICOM_THIS_From_IFTMarshal(class, name) class* This = (class*)(((char*)name)-_IFTMarshall_Offset);
51 /* inner IUnknown to handle aggregation */
52 HRESULT WINAPI IiFTMUnknown_fnQueryInterface (IUnknown * iface, REFIID riid, LPVOID * ppv)
55 ICOM_THIS (FTMarshalImpl, iface);
57 TRACE ("\n");
58 *ppv = NULL;
60 if (IsEqualIID (&IID_IUnknown, riid))
61 *ppv = _IFTMUnknown_ (This);
62 else if (IsEqualIID (&IID_IMarshal, riid))
63 *ppv = _IFTMarshal_ (This);
64 else {
65 FIXME ("No interface for %s.\n", debugstr_guid (riid));
66 return E_NOINTERFACE;
68 IUnknown_AddRef ((IUnknown *) * ppv);
69 return S_OK;
72 ULONG WINAPI IiFTMUnknown_fnAddRef (IUnknown * iface)
75 ICOM_THIS (FTMarshalImpl, iface);
77 TRACE ("\n");
78 return InterlockedIncrement (&This->ref);
81 ULONG WINAPI IiFTMUnknown_fnRelease (IUnknown * iface)
84 ICOM_THIS (FTMarshalImpl, iface);
86 TRACE ("\n");
87 if (InterlockedDecrement (&This->ref))
88 return This->ref;
89 HeapFree (GetProcessHeap (), 0, This);
90 return 0;
93 static ICOM_VTABLE (IUnknown) iunkvt =
95 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
96 IiFTMUnknown_fnQueryInterface,
97 IiFTMUnknown_fnAddRef,
98 IiFTMUnknown_fnRelease
101 HRESULT WINAPI FTMarshalImpl_QueryInterface (LPMARSHAL iface, REFIID riid, LPVOID * ppv)
104 _ICOM_THIS_From_IFTMarshal (FTMarshalImpl, iface);
106 TRACE ("(%p)->(\n\tIID:\t%s,%p)\n", This, debugstr_guid (riid), ppv);
107 return IUnknown_QueryInterface (This->pUnkOuter, riid, ppv);
110 ULONG WINAPI FTMarshalImpl_AddRef (LPMARSHAL iface)
113 _ICOM_THIS_From_IFTMarshal (FTMarshalImpl, iface);
115 TRACE ("\n");
116 return IUnknown_AddRef (This->pUnkOuter);
119 ULONG WINAPI FTMarshalImpl_Release (LPMARSHAL iface)
122 _ICOM_THIS_From_IFTMarshal (FTMarshalImpl, iface);
124 TRACE ("\n");
125 return IUnknown_Release (This->pUnkOuter);
128 HRESULT WINAPI FTMarshalImpl_GetUnmarshalClass (LPMARSHAL iface, REFIID riid, void *pv, DWORD dwDestContext,
129 void *pvDestContext, DWORD mshlflags, CLSID * pCid)
131 FIXME ("(), stub!\n");
132 return S_OK;
135 HRESULT WINAPI FTMarshalImpl_GetMarshalSizeMax (LPMARSHAL iface, REFIID riid, void *pv, DWORD dwDestContext,
136 void *pvDestContext, DWORD mshlflags, DWORD * pSize)
139 IMarshal *pMarshal = NULL;
140 HRESULT hres;
142 _ICOM_THIS_From_IFTMarshal (FTMarshalImpl, iface);
144 FIXME ("(), stub!\n");
146 /* if the marshalling happens inside the same process the interface pointer is
147 copied between the apartments */
148 if (dwDestContext == MSHCTX_INPROC || dwDestContext == MSHCTX_CROSSCTX) {
149 *pSize = sizeof (This);
150 return S_OK;
153 /* use the standard marshaller to handle all other cases */
154 CoGetStandardMarshal (riid, pv, dwDestContext, pvDestContext, mshlflags, &pMarshal);
155 hres = IMarshal_GetMarshalSizeMax (pMarshal, riid, pv, dwDestContext, pvDestContext, mshlflags, pSize);
156 IMarshal_Release (pMarshal);
157 return hres;
159 return S_OK;
162 HRESULT WINAPI FTMarshalImpl_MarshalInterface (LPMARSHAL iface, IStream * pStm, REFIID riid, void *pv,
163 DWORD dwDestContext, void *pvDestContext, DWORD mshlflags)
166 IMarshal *pMarshal = NULL;
167 HRESULT hres;
169 _ICOM_THIS_From_IFTMarshal (FTMarshalImpl, iface);
171 FIXME ("(), stub!\n");
173 /* if the marshalling happens inside the same process the interface pointer is
174 copied between the apartments */
175 if (dwDestContext == MSHCTX_INPROC || dwDestContext == MSHCTX_CROSSCTX) {
176 return IStream_Write (pStm, This, sizeof (This), 0);
179 /* use the standard marshaler to handle all other cases */
180 CoGetStandardMarshal (riid, pv, dwDestContext, pvDestContext, mshlflags, &pMarshal);
181 hres = IMarshal_MarshalInterface (pMarshal, pStm, riid, pv, dwDestContext, pvDestContext, mshlflags);
182 IMarshal_Release (pMarshal);
183 return hres;
186 HRESULT WINAPI FTMarshalImpl_UnmarshalInterface (LPMARSHAL iface, IStream * pStm, REFIID riid, void **ppv)
188 FIXME ("(), stub!\n");
189 return S_OK;
192 HRESULT WINAPI FTMarshalImpl_ReleaseMarshalData (LPMARSHAL iface, IStream * pStm)
194 FIXME ("(), stub!\n");
195 return S_OK;
198 HRESULT WINAPI FTMarshalImpl_DisconnectObject (LPMARSHAL iface, DWORD dwReserved)
200 FIXME ("(), stub!\n");
201 return S_OK;
204 ICOM_VTABLE (IMarshal) ftmvtbl =
206 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
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)
225 FTMarshalImpl *ftm;
227 TRACE ("(%p %p)\n", punkOuter, ppunkMarshal);
229 ftm = (FTMarshalImpl *) HeapAlloc (GetProcessHeap (), 0, sizeof (FTMarshalImpl));
230 if (!ftm)
231 return E_OUTOFMEMORY;
233 ftm->lpVtbl = &iunkvt;
234 ftm->lpvtblFTM = &ftmvtbl;
235 ftm->ref = 1;
236 ftm->pUnkOuter = punkOuter;
238 *ppunkMarshal = _IFTMUnknown_ (ftm);
239 return S_OK;