Authors: Mike Hearn <mh@codeweavers.com>, Rob Shearman <rob@codeweavers.com>
[wine/multimedia.git] / dlls / ole32 / marshal.c
blobb8837171759a2ebd554c0ec34c29e863b89c1255
1 /*
2 * Marshalling library
4 * Copyright 2002 Marcus Meissner
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 "winuser.h"
32 #include "objbase.h"
33 #include "ole2.h"
34 #include "ole2ver.h"
35 #include "rpc.h"
36 #include "winerror.h"
37 #include "winreg.h"
38 #include "wownt32.h"
39 #include "wtypes.h"
40 #include "wine/unicode.h"
41 #include "wine/winbase16.h"
42 #include "compobj_private.h"
43 #include "ifs.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(ole);
49 extern const CLSID CLSID_DfMarshal;
51 /* Marshalling just passes a unique identifier to the remote client,
52 * that makes it possible to find the passed interface again.
54 * So basically we need a set of values that make it unique.
56 * Process Identifier, Object IUnknown ptr, IID
58 * Note that the IUnknown_QI(ob,xiid,&ppv) always returns the SAME ppv value!
61 typedef struct _mid2unknown {
62 wine_marshal_id mid;
63 LPUNKNOWN pUnk;
64 } mid2unknown;
66 typedef struct _mid2stub {
67 wine_marshal_id mid;
68 IRpcStubBuffer *stub;
69 LPUNKNOWN pUnkServer;
70 BOOL valid;
71 } mid2stub;
73 static mid2stub *stubs = NULL;
74 static int nrofstubs = 0;
76 static mid2unknown *proxies = NULL;
77 static int nrofproxies = 0;
79 HRESULT
80 MARSHAL_Find_Stub_Server(wine_marshal_id *mid,LPUNKNOWN *punk) {
81 int i;
83 for (i=0;i<nrofstubs;i++) {
84 if (!stubs[i].valid) continue;
86 if (MARSHAL_Compare_Mids_NoInterface(mid,&(stubs[i].mid))) {
87 *punk = stubs[i].pUnkServer;
88 IUnknown_AddRef((*punk));
89 return S_OK;
92 return E_FAIL;
95 HRESULT
96 MARSHAL_Find_Stub_Buffer(wine_marshal_id *mid,IRpcStubBuffer **stub) {
97 int i;
99 for (i=0;i<nrofstubs;i++) {
100 if (!stubs[i].valid) continue;
102 if (MARSHAL_Compare_Mids(mid,&(stubs[i].mid))) {
103 *stub = stubs[i].stub;
104 IUnknown_AddRef((*stub));
105 return S_OK;
108 return E_FAIL;
111 HRESULT
112 MARSHAL_Find_Stub(wine_marshal_id *mid,LPUNKNOWN *pUnk) {
113 int i;
115 for (i=0;i<nrofstubs;i++) {
116 if (!stubs[i].valid) continue;
118 if (MARSHAL_Compare_Mids(mid,&(stubs[i].mid))) {
119 *pUnk = stubs[i].pUnkServer;
120 IUnknown_AddRef((*pUnk));
121 return S_OK;
124 return E_FAIL;
127 HRESULT
128 MARSHAL_Register_Stub(wine_marshal_id *mid,LPUNKNOWN pUnk,IRpcStubBuffer *stub) {
129 LPUNKNOWN xPunk;
130 if (!MARSHAL_Find_Stub(mid,&xPunk)) {
131 FIXME("Already have entry for (%lx/%s)!\n",mid->objectid,debugstr_guid(&(mid->iid)));
132 return S_OK;
134 if (nrofstubs)
135 stubs=HeapReAlloc(GetProcessHeap(),0,stubs,sizeof(stubs[0])*(nrofstubs+1));
136 else
137 stubs=HeapAlloc(GetProcessHeap(),0,sizeof(stubs[0]));
138 if (!stubs) return E_OUTOFMEMORY;
139 stubs[nrofstubs].stub = stub;
140 stubs[nrofstubs].pUnkServer = pUnk;
141 memcpy(&(stubs[nrofstubs].mid),mid,sizeof(*mid));
142 stubs[nrofstubs].valid = TRUE; /* set to false when released by ReleaseMarshalData */
143 nrofstubs++;
144 return S_OK;
147 HRESULT
148 MARSHAL_Find_Proxy(wine_marshal_id *mid,LPUNKNOWN *punk) {
149 int i;
151 for (i=0;i<nrofproxies;i++)
152 if (MARSHAL_Compare_Mids(mid,&(proxies[i].mid))) {
153 *punk = proxies[i].pUnk;
154 IUnknown_AddRef((*punk));
155 return S_OK;
157 return E_FAIL;
160 HRESULT
161 MARSHAL_Find_Proxy_Object(wine_marshal_id *mid,LPUNKNOWN *punk) {
162 int i;
164 for (i=0;i<nrofproxies;i++)
165 if (MARSHAL_Compare_Mids_NoInterface(mid,&(proxies[i].mid))) {
166 *punk = proxies[i].pUnk;
167 IUnknown_AddRef((*punk));
168 return S_OK;
170 return E_FAIL;
173 HRESULT
174 MARSHAL_Register_Proxy(wine_marshal_id *mid,LPUNKNOWN punk) {
175 int i;
177 for (i=0;i<nrofproxies;i++) {
178 if (MARSHAL_Compare_Mids(mid,&(proxies[i].mid))) {
179 ERR("Already have mid?\n");
180 return E_FAIL;
183 if (nrofproxies)
184 proxies = HeapReAlloc(GetProcessHeap(),0,proxies,sizeof(proxies[0])*(nrofproxies+1));
185 else
186 proxies = HeapAlloc(GetProcessHeap(),0,sizeof(proxies[0]));
187 memcpy(&(proxies[nrofproxies].mid),mid,sizeof(*mid));
188 proxies[nrofproxies].pUnk = punk;
189 nrofproxies++;
190 IUnknown_AddRef(punk);
191 return S_OK;
194 /********************** StdMarshal implementation ****************************/
195 typedef struct _StdMarshalImpl {
196 ICOM_VTABLE(IMarshal) *lpvtbl;
197 DWORD ref;
199 IID iid;
200 DWORD dwDestContext;
201 LPVOID pvDestContext;
202 DWORD mshlflags;
203 } StdMarshalImpl;
205 HRESULT WINAPI
206 StdMarshalImpl_QueryInterface(LPMARSHAL iface,REFIID riid,LPVOID *ppv) {
207 *ppv = NULL;
208 if (IsEqualIID(&IID_IUnknown,riid) || IsEqualIID(&IID_IMarshal,riid)) {
209 *ppv = iface;
210 IUnknown_AddRef(iface);
211 return S_OK;
213 FIXME("No interface for %s.\n",debugstr_guid(riid));
214 return E_NOINTERFACE;
217 ULONG WINAPI
218 StdMarshalImpl_AddRef(LPMARSHAL iface) {
219 ICOM_THIS(StdMarshalImpl,iface);
220 This->ref++;
221 return This->ref;
224 ULONG WINAPI
225 StdMarshalImpl_Release(LPMARSHAL iface) {
226 ICOM_THIS(StdMarshalImpl,iface);
227 This->ref--;
229 if (This->ref)
230 return This->ref;
231 HeapFree(GetProcessHeap(),0,This);
232 return 0;
235 HRESULT WINAPI
236 StdMarshalImpl_GetUnmarshalClass(
237 LPMARSHAL iface, REFIID riid, void* pv, DWORD dwDestContext,
238 void* pvDestContext, DWORD mshlflags, CLSID* pCid
240 memcpy(pCid,&CLSID_DfMarshal,sizeof(CLSID_DfMarshal));
241 return S_OK;
244 HRESULT WINAPI
245 StdMarshalImpl_GetMarshalSizeMax(
246 LPMARSHAL iface, REFIID riid, void* pv, DWORD dwDestContext,
247 void* pvDestContext, DWORD mshlflags, DWORD* pSize
249 *pSize = sizeof(wine_marshal_id)+sizeof(wine_marshal_data);
250 return S_OK;
253 HRESULT WINAPI
254 StdMarshalImpl_MarshalInterface(
255 LPMARSHAL iface, IStream *pStm,REFIID riid, void* pv, DWORD dwDestContext,
256 void* pvDestContext, DWORD mshlflags
258 wine_marshal_id mid;
259 wine_marshal_data md;
260 IUnknown *pUnk;
261 ULONG res;
262 HRESULT hres;
263 IRpcStubBuffer *stub;
264 IPSFactoryBuffer *psfacbuf;
266 TRACE("(...,%s,...)\n",debugstr_guid(riid));
267 IUnknown_QueryInterface((LPUNKNOWN)pv,&IID_IUnknown,(LPVOID*)&pUnk);
268 mid.processid = GetCurrentProcessId();
269 mid.objectid = (DWORD)pUnk; /* FIXME */
270 IUnknown_Release(pUnk);
271 memcpy(&mid.iid,riid,sizeof(mid.iid));
272 md.dwDestContext = dwDestContext;
273 md.mshlflags = mshlflags;
274 hres = IStream_Write(pStm,&mid,sizeof(mid),&res);
275 if (hres) return hres;
276 hres = IStream_Write(pStm,&md,sizeof(md),&res);
277 if (hres) return hres;
279 if (SUCCEEDED(MARSHAL_Find_Stub(&mid,&pUnk))) {
280 IUnknown_Release(pUnk);
281 return S_OK;
283 hres = get_facbuf_for_iid(riid,&psfacbuf);
284 if (hres) return hres;
286 hres = IPSFactoryBuffer_CreateStub(psfacbuf,riid,pv,&stub);
287 IPSFactoryBuffer_Release(psfacbuf);
288 if (hres) {
289 FIXME("Failed to create a stub for %s\n",debugstr_guid(riid));
290 return hres;
292 IUnknown_QueryInterface((LPUNKNOWN)pv,riid,(LPVOID*)&pUnk);
293 MARSHAL_Register_Stub(&mid,pUnk,stub);
294 IUnknown_Release(pUnk);
295 return S_OK;
298 HRESULT WINAPI
299 StdMarshalImpl_UnmarshalInterface(
300 LPMARSHAL iface, IStream *pStm, REFIID riid, void **ppv
302 wine_marshal_id mid;
303 wine_marshal_data md;
304 ULONG res;
305 HRESULT hres;
306 IPSFactoryBuffer *psfacbuf;
307 IRpcProxyBuffer *rpcproxy;
308 IRpcChannelBuffer *chanbuf;
310 TRACE("(...,%s,....)\n",debugstr_guid(riid));
311 hres = IStream_Read(pStm,&mid,sizeof(mid),&res);
312 if (hres) return hres;
313 hres = IStream_Read(pStm,&md,sizeof(md),&res);
314 if (hres) return hres;
315 if (SUCCEEDED(MARSHAL_Find_Stub(&mid,(LPUNKNOWN*)ppv))) {
316 FIXME("Calling back to ourselves for %s!\n",debugstr_guid(riid));
317 return S_OK;
319 hres = get_facbuf_for_iid(riid,&psfacbuf);
320 if (hres) return hres;
321 hres = IPSFactoryBuffer_CreateProxy(psfacbuf,NULL,riid,&rpcproxy,ppv);
322 if (hres) {
323 FIXME("Failed to create a proxy for %s\n",debugstr_guid(riid));
324 return hres;
326 hres = PIPE_GetNewPipeBuf(&mid,&chanbuf);
327 IPSFactoryBuffer_Release(psfacbuf);
328 if (hres) {
329 ERR("Failed to get an rpc channel buffer for %s\n",debugstr_guid(riid));
330 } else {
331 /* Connect the channel buffer to the proxy and release the no longer
332 * needed proxy.
333 * NOTE: The proxy should have taken an extra reference because it also
334 * aggregates the object, so we can safely release our reference to it. */
335 IRpcProxyBuffer_Connect(rpcproxy,chanbuf);
336 IRpcProxyBuffer_Release(rpcproxy);
337 /* IRpcProxyBuffer takes a reference on the channel buffer and
338 * we no longer need it, so release it */
339 IRpcChannelBuffer_Release(chanbuf);
341 return hres;
344 HRESULT WINAPI
345 StdMarshalImpl_ReleaseMarshalData(LPMARSHAL iface, IStream *pStm) {
346 wine_marshal_id mid;
347 ULONG res;
348 HRESULT hres;
349 IRpcStubBuffer *stub = NULL;
350 int i;
352 hres = IStream_Read(pStm,&mid,sizeof(mid),&res);
353 if (hres) return hres;
355 for (i=0; i < nrofstubs; i++)
357 if (!stubs[i].valid) continue;
359 if (MARSHAL_Compare_Mids(&mid, &(stubs[i].mid)))
361 stub = stubs[i].stub;
362 break;
366 if (!stub)
368 FIXME("Could not map MID to stub??\n");
369 return E_FAIL;
372 res = IRpcStubBuffer_Release(stub);
373 stubs[i].valid = FALSE;
374 TRACE("stub refcount of %p is %ld\n", stub, res);
376 return S_OK;
379 HRESULT WINAPI
380 StdMarshalImpl_DisconnectObject(LPMARSHAL iface, DWORD dwReserved) {
381 FIXME("(), stub!\n");
382 return S_OK;
385 ICOM_VTABLE(IMarshal) stdmvtbl = {
386 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
387 StdMarshalImpl_QueryInterface,
388 StdMarshalImpl_AddRef,
389 StdMarshalImpl_Release,
390 StdMarshalImpl_GetUnmarshalClass,
391 StdMarshalImpl_GetMarshalSizeMax,
392 StdMarshalImpl_MarshalInterface,
393 StdMarshalImpl_UnmarshalInterface,
394 StdMarshalImpl_ReleaseMarshalData,
395 StdMarshalImpl_DisconnectObject
398 /***********************************************************************
399 * CoGetStandardMarshal [OLE32.@]
401 * When the COM library in the client process receives a marshalled
402 * interface pointer, it looks for a CLSID to be used in creating a proxy
403 * for the purposes of unmarshalling the packet. If the packet does not
404 * contain a CLSID for the proxy, COM calls CoGetStandardMarshal, passing a
405 * NULL pUnk value.
406 * This function creates a standard proxy in the client process and returns
407 * a pointer to that proxy's implementation of IMarshal.
408 * COM uses this pointer to call CoUnmarshalInterface to retrieve the pointer
409 * to the requested interface.
411 HRESULT WINAPI
412 CoGetStandardMarshal(
413 REFIID riid,IUnknown *pUnk,DWORD dwDestContext,LPVOID pvDestContext,
414 DWORD mshlflags, LPMARSHAL *pMarshal
416 StdMarshalImpl *dm;
418 if (pUnk == NULL) {
419 FIXME("(%s,NULL,%lx,%p,%lx,%p), unimplemented yet.\n",
420 debugstr_guid(riid),dwDestContext,pvDestContext,mshlflags,pMarshal
422 return E_FAIL;
424 TRACE("(%s,%p,%lx,%p,%lx,%p)\n",
425 debugstr_guid(riid),pUnk,dwDestContext,pvDestContext,mshlflags,pMarshal
427 *pMarshal = HeapAlloc(GetProcessHeap(),0,sizeof(StdMarshalImpl));
428 dm = (StdMarshalImpl*) *pMarshal;
429 if (!dm) return E_FAIL;
430 dm->lpvtbl = &stdmvtbl;
431 dm->ref = 1;
433 memcpy(&dm->iid,riid,sizeof(dm->iid));
434 dm->dwDestContext = dwDestContext;
435 dm->pvDestContext = pvDestContext;
436 dm->mshlflags = mshlflags;
437 return S_OK;
440 /* Helper function for getting Marshaler */
441 static HRESULT WINAPI
442 _GetMarshaller(REFIID riid, IUnknown *pUnk,DWORD dwDestContext,
443 void *pvDestContext, DWORD mshlFlags, LPMARSHAL *pMarshal
445 HRESULT hres;
447 if (!pUnk)
448 return E_POINTER;
449 hres = IUnknown_QueryInterface(pUnk,&IID_IMarshal,(LPVOID*)pMarshal);
450 if (hres)
451 hres = CoGetStandardMarshal(riid,pUnk,dwDestContext,pvDestContext,mshlFlags,pMarshal);
452 return hres;
455 /***********************************************************************
456 * CoGetMarshalSizeMax [OLE32.@]
458 HRESULT WINAPI
459 CoGetMarshalSizeMax(ULONG *pulSize, REFIID riid, IUnknown *pUnk,
460 DWORD dwDestContext, void *pvDestContext, DWORD mshlFlags
462 HRESULT hres;
463 LPMARSHAL pMarshal;
465 hres = _GetMarshaller(riid,pUnk,dwDestContext,pvDestContext,mshlFlags,&pMarshal);
466 if (hres)
467 return hres;
468 hres = IMarshal_GetMarshalSizeMax(pMarshal,riid,pUnk,dwDestContext,pvDestContext,mshlFlags,pulSize);
469 *pulSize += sizeof(wine_marshal_id)+sizeof(wine_marshal_data)+sizeof(CLSID);
470 IMarshal_Release(pMarshal);
471 return hres;
475 /***********************************************************************
476 * CoMarshalInterface [OLE32.@]
478 HRESULT WINAPI
479 CoMarshalInterface( IStream *pStm, REFIID riid, IUnknown *pUnk,
480 DWORD dwDestContext, void *pvDestContext, DWORD mshlflags
482 HRESULT hres;
483 LPMARSHAL pMarshal;
484 CLSID xclsid;
485 ULONG writeres;
486 wine_marshal_id mid;
487 wine_marshal_data md;
488 ULONG res;
489 IUnknown *pUnknown;
491 TRACE("(%p, %s, %p, %lx, %p, %lx)\n",
492 pStm,debugstr_guid(riid),pUnk,dwDestContext,pvDestContext,mshlflags
495 if (pUnk == NULL)
496 return E_INVALIDARG;
498 STUBMGR_Start(); /* Just to be sure we have one running. */
499 mid.processid = GetCurrentProcessId();
500 IUnknown_QueryInterface(pUnk,&IID_IUnknown,(LPVOID*)&pUnknown);
501 mid.objectid = (DWORD)pUnknown;
502 IUnknown_Release(pUnknown);
503 memcpy(&mid.iid,riid,sizeof(mid.iid));
504 md.dwDestContext = dwDestContext;
505 md.mshlflags = mshlflags;
506 hres = IStream_Write(pStm,&mid,sizeof(mid),&res);
507 if (hres) return hres;
508 hres = IStream_Write(pStm,&md,sizeof(md),&res);
509 if (hres) return hres;
510 hres = _GetMarshaller(riid,pUnk,dwDestContext,pvDestContext,mshlflags,&pMarshal);
511 if (hres) {
512 FIXME("Failed to get marshaller, %lx?\n",hres);
513 return hres;
515 hres = IMarshal_GetUnmarshalClass(pMarshal,riid,pUnk,dwDestContext,pvDestContext,mshlflags,&xclsid);
516 if (hres) {
517 FIXME("IMarshal:GetUnmarshalClass failed, %lx\n",hres);
518 goto release_marshal;
520 hres = IStream_Write(pStm,&xclsid,sizeof(xclsid),&writeres);
521 if (hres) {
522 FIXME("Stream write failed, %lx\n",hres);
523 goto release_marshal;
525 hres = IMarshal_MarshalInterface(pMarshal,pStm,riid,pUnk,dwDestContext,pvDestContext,mshlflags);
526 if (hres) {
527 if (IsEqualGUID(riid,&IID_IOleObject)) {
528 ERR("WINE currently cannot marshal IOleObject interfaces. This means you cannot embed/link OLE objects between applications.\n");
529 } else {
530 FIXME("Failed to marshal the interface %s, %lx?\n",debugstr_guid(riid),hres);
533 release_marshal:
534 IMarshal_Release(pMarshal);
535 return hres;
539 /***********************************************************************
540 * CoUnmarshalInterface [OLE32.@]
542 HRESULT WINAPI
543 CoUnmarshalInterface(IStream *pStm, REFIID riid, LPVOID *ppv) {
544 HRESULT hres;
545 wine_marshal_id mid;
546 wine_marshal_data md;
547 ULONG res;
548 LPMARSHAL pMarshal;
549 LPUNKNOWN pUnk;
550 CLSID xclsid;
552 TRACE("(%p,%s,%p)\n",pStm,debugstr_guid(riid),ppv);
554 hres = IStream_Read(pStm,&mid,sizeof(mid),&res);
555 if (hres) {
556 FIXME("Stream read 1 failed, %lx, (%ld of %d)\n",hres,res,sizeof(mid));
557 return hres;
559 hres = IStream_Read(pStm,&md,sizeof(md),&res);
560 if (hres) {
561 FIXME("Stream read 2 failed, %lx, (%ld of %d)\n",hres,res,sizeof(md));
562 return hres;
564 hres = IStream_Read(pStm,&xclsid,sizeof(xclsid),&res);
565 if (hres) {
566 FIXME("Stream read 3 failed, %lx, (%ld of %d)\n",hres,res,sizeof(xclsid));
567 return hres;
569 hres=CoCreateInstance(&xclsid,NULL,CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER | CLSCTX_LOCAL_SERVER,&IID_IMarshal,(void**)&pUnk);
570 if (hres) {
571 FIXME("Failed to create instance of unmarshaller %s.\n",debugstr_guid(&xclsid));
572 return hres;
574 hres = _GetMarshaller(riid,pUnk,md.dwDestContext,NULL,md.mshlflags,&pMarshal);
575 if (hres) {
576 FIXME("Failed to get unmarshaller, %lx?\n",hres);
577 return hres;
579 hres = IMarshal_UnmarshalInterface(pMarshal,pStm,riid,ppv);
580 if (hres) {
581 FIXME("Failed to Unmarshal the interface, %lx?\n",hres);
582 goto release_marshal;
584 release_marshal:
585 IMarshal_Release(pMarshal);
586 return hres;
589 /***********************************************************************
590 * CoReleaseMarshalData [OLE32.@]
592 HRESULT WINAPI
593 CoReleaseMarshalData(IStream *pStm) {
594 HRESULT hres;
595 wine_marshal_id mid;
596 wine_marshal_data md;
597 ULONG res;
598 LPMARSHAL pMarshal;
599 LPUNKNOWN pUnk;
600 CLSID xclsid;
602 TRACE("(%p)\n",pStm);
604 hres = IStream_Read(pStm,&mid,sizeof(mid),&res);
605 if (hres) {
606 FIXME("Stream read 1 failed, %lx, (%ld of %d)\n",hres,res,sizeof(mid));
607 return hres;
609 hres = IStream_Read(pStm,&md,sizeof(md),&res);
610 if (hres) {
611 FIXME("Stream read 2 failed, %lx, (%ld of %d)\n",hres,res,sizeof(md));
612 return hres;
614 hres = IStream_Read(pStm,&xclsid,sizeof(xclsid),&res);
615 if (hres) {
616 FIXME("Stream read 3 failed, %lx, (%ld of %d)\n",hres,res,sizeof(xclsid));
617 return hres;
619 hres=CoCreateInstance(&xclsid,NULL,CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER | CLSCTX_LOCAL_SERVER,&IID_IMarshal,(void**)(char*)&pUnk);
620 if (hres) {
621 FIXME("Failed to create instance of unmarshaller %s.\n",debugstr_guid(&xclsid));
622 return hres;
624 hres = IUnknown_QueryInterface(pUnk,&IID_IMarshal,(LPVOID*)(char*)&pMarshal);
625 if (hres) {
626 FIXME("Failed to get IMarshal iface, %lx?\n",hres);
627 return hres;
629 hres = IMarshal_ReleaseMarshalData(pMarshal,pStm);
630 if (hres) {
631 FIXME("Failed to releasemarshaldata the interface, %lx?\n",hres);
633 IMarshal_Release(pMarshal);
634 IUnknown_Release(pUnk);
635 return hres;
639 /***********************************************************************
640 * CoMarshalInterThreadInterfaceInStream [OLE32.@]
642 * Marshal an interface across threads in the same process.
644 * PARAMS
645 * riid [I] Identifier of the interface to be marshalled.
646 * pUnk [I] Pointer to IUnknown-derived interface that will be marshalled.
647 * ppStm [O] Pointer to IStream object that is created and then used to store the marshalled inteface.
649 * RETURNS
650 * Success: S_OK
651 * Failure: E_OUTOFMEMORY and other COM error codes
653 * SEE
654 * CoMarshalInterface(), CoUnmarshalInterface() and CoGetInterfaceAndReleaseStream()
656 HRESULT WINAPI
657 CoMarshalInterThreadInterfaceInStream(
658 REFIID riid, LPUNKNOWN pUnk, LPSTREAM * ppStm)
660 ULARGE_INTEGER xpos;
661 LARGE_INTEGER seekto;
662 HRESULT hres;
664 TRACE("(%s, %p, %p)\n",debugstr_guid(riid), pUnk, ppStm);
666 hres = CreateStreamOnHGlobal(0, TRUE, ppStm);
667 if (FAILED(hres)) return hres;
668 hres = CoMarshalInterface(*ppStm, riid, pUnk, MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL);
670 /* FIXME: is this needed? */
671 memset(&seekto,0,sizeof(seekto));
672 IStream_Seek(*ppStm,seekto,SEEK_SET,&xpos);
674 return hres;
677 /***********************************************************************
678 * CoGetInterfaceAndReleaseStream [OLE32.@]
680 * Unmarshalls an inteface from a stream and then releases the stream.
682 * PARAMS
683 * pStm [I] Stream that contains the marshalled inteface.
684 * riid [I] Interface identifier of the object to unmarshall.
685 * ppv [O] Address of pointer where the requested interface object will be stored.
687 * RETURNS
688 * Success: S_OK
689 * Failure: A COM error code
691 * SEE
692 * CoMarshalInterThreadInterfaceInStream() and CoUnmarshalInteface()
694 HRESULT WINAPI
695 CoGetInterfaceAndReleaseStream(LPSTREAM pStm,REFIID riid, LPVOID *ppv)
697 HRESULT hres;
699 TRACE("(%p, %s, %p)\n", pStm, debugstr_guid(riid), ppv);
701 hres = CoUnmarshalInterface(pStm, riid, ppv);
702 IStream_Release(pStm);
703 return hres;
706 static HRESULT WINAPI
707 SMCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid, LPVOID *ppv) {
708 *ppv = NULL;
709 if (IsEqualIID(riid,&IID_IUnknown) || IsEqualIID(riid,&IID_IClassFactory)) {
710 *ppv = (LPVOID)iface;
711 return S_OK;
713 return E_NOINTERFACE;
715 static ULONG WINAPI SMCF_AddRef(LPCLASSFACTORY iface) { return 2; }
716 static ULONG WINAPI SMCF_Release(LPCLASSFACTORY iface) { return 1; }
718 static HRESULT WINAPI
719 SMCF_CreateInstance(
720 LPCLASSFACTORY iface, LPUNKNOWN pUnk, REFIID riid, LPVOID *ppv
722 if (IsEqualIID(riid,&IID_IMarshal)) {
723 StdMarshalImpl *dm;
724 dm=(StdMarshalImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(StdMarshalImpl));
725 if (!dm)
726 return E_FAIL;
727 dm->lpvtbl = &stdmvtbl;
728 dm->ref = 1;
729 *ppv = (LPVOID)dm;
730 return S_OK;
732 FIXME("(%s), not supported.\n",debugstr_guid(riid));
733 return E_NOINTERFACE;
736 static HRESULT WINAPI
737 SMCF_LockServer(LPCLASSFACTORY iface, BOOL fLock) {
738 FIXME("(%d), stub!\n",fLock);
739 return S_OK;
742 static ICOM_VTABLE(IClassFactory) dfmarshalcfvtbl = {
743 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
744 SMCF_QueryInterface,
745 SMCF_AddRef,
746 SMCF_Release,
747 SMCF_CreateInstance,
748 SMCF_LockServer
750 static ICOM_VTABLE(IClassFactory) *pdfmarshalcfvtbl = &dfmarshalcfvtbl;
752 HRESULT
753 MARSHAL_GetStandardMarshalCF(LPVOID *ppv) {
754 *ppv = &pdfmarshalcfvtbl;
755 return S_OK;