1 | /*
|
---|
2 | * free threaded marshaler
|
---|
3 | *
|
---|
4 | * Copyright 2002 Juergen Schmied
|
---|
5 | *
|
---|
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.
|
---|
10 | *
|
---|
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.
|
---|
15 | *
|
---|
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
|
---|
19 | */
|
---|
20 |
|
---|
21 | #include "config.h"
|
---|
22 |
|
---|
23 | #include <stdlib.h>
|
---|
24 | #include <stdio.h>
|
---|
25 | #include <string.h>
|
---|
26 | #include <assert.h>
|
---|
27 |
|
---|
28 | #include "winbase.h"
|
---|
29 |
|
---|
30 | #include "wine/obj_base.h"
|
---|
31 | #include "wine/obj_storage.h"
|
---|
32 | #include "wine/obj_marshal.h"
|
---|
33 |
|
---|
34 | #include "wine/debug.h"
|
---|
35 |
|
---|
36 | #ifdef __WIN32OS2__
|
---|
37 | #include <winerror.h>
|
---|
38 | #endif
|
---|
39 |
|
---|
40 | WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
---|
41 |
|
---|
42 | typedef struct _FTMarshalImpl {
|
---|
43 | ICOM_VFIELD (IUnknown);
|
---|
44 | DWORD ref;
|
---|
45 | ICOM_VTABLE (IMarshal) * lpvtblFTM;
|
---|
46 |
|
---|
47 | IUnknown *pUnkOuter;
|
---|
48 | } FTMarshalImpl;
|
---|
49 |
|
---|
50 | #define _IFTMUnknown_(This)(IUnknown*)&(This->lpVtbl)
|
---|
51 | #define _IFTMarshal_(This) (IMarshal*)&(This->lpvtblFTM)
|
---|
52 |
|
---|
53 | #define _IFTMarshall_Offset ((int)(&(((FTMarshalImpl*)0)->lpvtblFTM)))
|
---|
54 | #define _ICOM_THIS_From_IFTMarshal(class, name) class* This = (class*)(((char*)name)-_IFTMarshall_Offset);
|
---|
55 |
|
---|
56 | /* inner IUnknown to handle aggregation */
|
---|
57 | HRESULT WINAPI IiFTMUnknown_fnQueryInterface (IUnknown * iface, REFIID riid, LPVOID * ppv)
|
---|
58 | {
|
---|
59 |
|
---|
60 | ICOM_THIS (FTMarshalImpl, iface);
|
---|
61 |
|
---|
62 | TRACE ("\n");
|
---|
63 | *ppv = NULL;
|
---|
64 |
|
---|
65 | if (IsEqualIID (&IID_IUnknown, riid))
|
---|
66 | *ppv = _IFTMUnknown_ (This);
|
---|
67 | else if (IsEqualIID (&IID_IMarshal, riid))
|
---|
68 | *ppv = _IFTMarshal_ (This);
|
---|
69 | else {
|
---|
70 | FIXME ("No interface for %s.\n", debugstr_guid (riid));
|
---|
71 | return E_NOINTERFACE;
|
---|
72 | }
|
---|
73 | IUnknown_AddRef ((IUnknown *) * ppv);
|
---|
74 | return S_OK;
|
---|
75 | }
|
---|
76 |
|
---|
77 | ULONG WINAPI IiFTMUnknown_fnAddRef (IUnknown * iface)
|
---|
78 | {
|
---|
79 |
|
---|
80 | ICOM_THIS (FTMarshalImpl, iface);
|
---|
81 |
|
---|
82 | TRACE ("\n");
|
---|
83 | return InterlockedIncrement (&This->ref);
|
---|
84 | }
|
---|
85 |
|
---|
86 | ULONG WINAPI IiFTMUnknown_fnRelease (IUnknown * iface)
|
---|
87 | {
|
---|
88 |
|
---|
89 | ICOM_THIS (FTMarshalImpl, iface);
|
---|
90 |
|
---|
91 | TRACE ("\n");
|
---|
92 | if (InterlockedDecrement (&This->ref))
|
---|
93 | return This->ref;
|
---|
94 | HeapFree (GetProcessHeap (), 0, This);
|
---|
95 | return 0;
|
---|
96 | }
|
---|
97 |
|
---|
98 | static ICOM_VTABLE (IUnknown) iunkvt =
|
---|
99 | {
|
---|
100 | ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
---|
101 | IiFTMUnknown_fnQueryInterface,
|
---|
102 | IiFTMUnknown_fnAddRef,
|
---|
103 | IiFTMUnknown_fnRelease
|
---|
104 | };
|
---|
105 |
|
---|
106 | HRESULT WINAPI FTMarshalImpl_QueryInterface (LPMARSHAL iface, REFIID riid, LPVOID * ppv)
|
---|
107 | {
|
---|
108 |
|
---|
109 | _ICOM_THIS_From_IFTMarshal (FTMarshalImpl, iface);
|
---|
110 |
|
---|
111 | TRACE ("(%p)->(\n\tIID:\t%s,%p)\n", This, debugstr_guid (riid), ppv);
|
---|
112 | return IUnknown_QueryInterface (This->pUnkOuter, riid, ppv);
|
---|
113 | }
|
---|
114 |
|
---|
115 | ULONG WINAPI FTMarshalImpl_AddRef (LPMARSHAL iface)
|
---|
116 | {
|
---|
117 |
|
---|
118 | _ICOM_THIS_From_IFTMarshal (FTMarshalImpl, iface);
|
---|
119 |
|
---|
120 | TRACE ("\n");
|
---|
121 | return IUnknown_AddRef (This->pUnkOuter);
|
---|
122 | }
|
---|
123 |
|
---|
124 | ULONG WINAPI FTMarshalImpl_Release (LPMARSHAL iface)
|
---|
125 | {
|
---|
126 |
|
---|
127 | _ICOM_THIS_From_IFTMarshal (FTMarshalImpl, iface);
|
---|
128 |
|
---|
129 | TRACE ("\n");
|
---|
130 | return IUnknown_Release (This->pUnkOuter);
|
---|
131 | }
|
---|
132 |
|
---|
133 | HRESULT WINAPI FTMarshalImpl_GetUnmarshalClass (LPMARSHAL iface, REFIID riid, void *pv, DWORD dwDestContext,
|
---|
134 | void *pvDestContext, DWORD mshlflags, CLSID * pCid)
|
---|
135 | {
|
---|
136 | FIXME ("(), stub!\n");
|
---|
137 | return S_OK;
|
---|
138 | }
|
---|
139 |
|
---|
140 | HRESULT WINAPI FTMarshalImpl_GetMarshalSizeMax (LPMARSHAL iface, REFIID riid, void *pv, DWORD dwDestContext,
|
---|
141 | void *pvDestContext, DWORD mshlflags, DWORD * pSize)
|
---|
142 | {
|
---|
143 |
|
---|
144 | IMarshal *pMarshal = NULL;
|
---|
145 | HRESULT hres;
|
---|
146 |
|
---|
147 | _ICOM_THIS_From_IFTMarshal (FTMarshalImpl, iface);
|
---|
148 |
|
---|
149 | FIXME ("(), stub!\n");
|
---|
150 |
|
---|
151 | /* if the marshaling happends inside the same process the interface pointer is
|
---|
152 | copied between the appartments */
|
---|
153 | if (dwDestContext == MSHCTX_INPROC || dwDestContext == MSHCTX_CROSSCTX) {
|
---|
154 | *pSize = sizeof (This);
|
---|
155 | return S_OK;
|
---|
156 | }
|
---|
157 |
|
---|
158 | /* use the standard marshaler to handle all other cases */
|
---|
159 | CoGetStandardMarshal (riid, pv, dwDestContext, pvDestContext, mshlflags, &pMarshal);
|
---|
160 | hres = IMarshal_GetMarshalSizeMax (pMarshal, riid, pv, dwDestContext, pvDestContext, mshlflags, pSize);
|
---|
161 | IMarshal_Release (pMarshal);
|
---|
162 | return hres;
|
---|
163 |
|
---|
164 | return S_OK;
|
---|
165 | }
|
---|
166 |
|
---|
167 | HRESULT WINAPI FTMarshalImpl_MarshalInterface (LPMARSHAL iface, IStream * pStm, REFIID riid, void *pv,
|
---|
168 | DWORD dwDestContext, void *pvDestContext, DWORD mshlflags)
|
---|
169 | {
|
---|
170 |
|
---|
171 | IMarshal *pMarshal = NULL;
|
---|
172 | HRESULT hres;
|
---|
173 |
|
---|
174 | _ICOM_THIS_From_IFTMarshal (FTMarshalImpl, iface);
|
---|
175 |
|
---|
176 | FIXME ("(), stub!\n");
|
---|
177 |
|
---|
178 | /* if the marshaling happends inside the same process the interface pointer is
|
---|
179 | copied between the appartments */
|
---|
180 | if (dwDestContext == MSHCTX_INPROC || dwDestContext == MSHCTX_CROSSCTX) {
|
---|
181 | return IStream_Write (pStm, This, sizeof (This), 0);
|
---|
182 | }
|
---|
183 |
|
---|
184 | /* use the standard marshaler to handle all other cases */
|
---|
185 | CoGetStandardMarshal (riid, pv, dwDestContext, pvDestContext, mshlflags, &pMarshal);
|
---|
186 | hres = IMarshal_MarshalInterface (pMarshal, pStm, riid, pv, dwDestContext, pvDestContext, mshlflags);
|
---|
187 | IMarshal_Release (pMarshal);
|
---|
188 | return hres;
|
---|
189 | }
|
---|
190 |
|
---|
191 | HRESULT WINAPI FTMarshalImpl_UnmarshalInterface (LPMARSHAL iface, IStream * pStm, REFIID riid, void **ppv)
|
---|
192 | {
|
---|
193 | FIXME ("(), stub!\n");
|
---|
194 | return S_OK;
|
---|
195 | }
|
---|
196 |
|
---|
197 | HRESULT WINAPI FTMarshalImpl_ReleaseMarshalData (LPMARSHAL iface, IStream * pStm)
|
---|
198 | {
|
---|
199 | FIXME ("(), stub!\n");
|
---|
200 | return S_OK;
|
---|
201 | }
|
---|
202 |
|
---|
203 | HRESULT WINAPI FTMarshalImpl_DisconnectObject (LPMARSHAL iface, DWORD dwReserved)
|
---|
204 | {
|
---|
205 | FIXME ("(), stub!\n");
|
---|
206 | return S_OK;
|
---|
207 | }
|
---|
208 |
|
---|
209 | ICOM_VTABLE (IMarshal) ftmvtbl =
|
---|
210 | {
|
---|
211 | ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
---|
212 | FTMarshalImpl_QueryInterface,
|
---|
213 | FTMarshalImpl_AddRef,
|
---|
214 | FTMarshalImpl_Release,
|
---|
215 | FTMarshalImpl_GetUnmarshalClass,
|
---|
216 | FTMarshalImpl_GetMarshalSizeMax,
|
---|
217 | FTMarshalImpl_MarshalInterface,
|
---|
218 | FTMarshalImpl_UnmarshalInterface,
|
---|
219 | FTMarshalImpl_ReleaseMarshalData,
|
---|
220 | FTMarshalImpl_DisconnectObject
|
---|
221 | };
|
---|
222 |
|
---|
223 | /***********************************************************************
|
---|
224 | * CoCreateFreeThreadedMarshaler [OLE32.5]
|
---|
225 | *
|
---|
226 | */
|
---|
227 | HRESULT WINAPI CoCreateFreeThreadedMarshaler (LPUNKNOWN punkOuter, LPUNKNOWN * ppunkMarshal)
|
---|
228 | {
|
---|
229 |
|
---|
230 | FTMarshalImpl *ftm;
|
---|
231 |
|
---|
232 | TRACE ("(%p %p)\n", punkOuter, ppunkMarshal);
|
---|
233 |
|
---|
234 | ftm = (FTMarshalImpl *) HeapAlloc (GetProcessHeap (), 0, sizeof (FTMarshalImpl));
|
---|
235 | if (!ftm)
|
---|
236 | return E_OUTOFMEMORY;
|
---|
237 |
|
---|
238 | ICOM_VTBL (ftm) = &iunkvt;
|
---|
239 | ftm->lpvtblFTM = &ftmvtbl;
|
---|
240 | ftm->ref = 1;
|
---|
241 | ftm->pUnkOuter = punkOuter;
|
---|
242 |
|
---|
243 | *ppunkMarshal = _IFTMUnknown_ (ftm);
|
---|
244 | return S_OK;
|
---|
245 | }
|
---|