Fixed CoMarshalInterThreadInterfaceInStream and
[wine/multimedia.git] / dlls / ole32 / marshal.c
blobff8403440a3279c1b48f7e2a4d7f010935e45446
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 } mid2stub;
72 static mid2stub *stubs = NULL;
73 static int nrofstubs = 0;
75 static mid2unknown *proxies = NULL;
76 static int nrofproxies = 0;
78 HRESULT
79 MARSHAL_Find_Stub_Server(wine_marshal_id *mid,LPUNKNOWN *punk) {
80 int i;
82 for (i=0;i<nrofstubs;i++) {
83 if (MARSHAL_Compare_Mids_NoInterface(mid,&(stubs[i].mid))) {
84 *punk = stubs[i].pUnkServer;
85 IUnknown_AddRef((*punk));
86 return S_OK;
89 return E_FAIL;
92 HRESULT
93 MARSHAL_Find_Stub_Buffer(wine_marshal_id *mid,IRpcStubBuffer **stub) {
94 int i;
96 for (i=0;i<nrofstubs;i++) {
97 if (MARSHAL_Compare_Mids(mid,&(stubs[i].mid))) {
98 *stub = stubs[i].stub;
99 IUnknown_AddRef((*stub));
100 return S_OK;
103 return E_FAIL;
106 HRESULT
107 MARSHAL_Find_Stub(wine_marshal_id *mid,LPUNKNOWN *pUnk) {
108 int i;
110 for (i=0;i<nrofstubs;i++) {
111 if (MARSHAL_Compare_Mids(mid,&(stubs[i].mid))) {
112 *pUnk = stubs[i].pUnkServer;
113 IUnknown_AddRef((*pUnk));
114 return S_OK;
117 return E_FAIL;
120 HRESULT
121 MARSHAL_Register_Stub(wine_marshal_id *mid,LPUNKNOWN pUnk,IRpcStubBuffer *stub) {
122 LPUNKNOWN xPunk;
123 if (!MARSHAL_Find_Stub(mid,&xPunk)) {
124 FIXME("Already have entry for (%lx/%s)!\n",mid->objectid,debugstr_guid(&(mid->iid)));
125 return S_OK;
127 if (nrofstubs)
128 stubs=HeapReAlloc(GetProcessHeap(),0,stubs,sizeof(stubs[0])*(nrofstubs+1));
129 else
130 stubs=HeapAlloc(GetProcessHeap(),0,sizeof(stubs[0]));
131 if (!stubs) return E_OUTOFMEMORY;
132 stubs[nrofstubs].stub = stub;
133 stubs[nrofstubs].pUnkServer = pUnk;
134 memcpy(&(stubs[nrofstubs].mid),mid,sizeof(*mid));
135 nrofstubs++;
136 return S_OK;
139 HRESULT
140 MARSHAL_Find_Proxy(wine_marshal_id *mid,LPUNKNOWN *punk) {
141 int i;
143 for (i=0;i<nrofproxies;i++)
144 if (MARSHAL_Compare_Mids(mid,&(proxies[i].mid))) {
145 *punk = proxies[i].pUnk;
146 IUnknown_AddRef((*punk));
147 return S_OK;
149 return E_FAIL;
152 HRESULT
153 MARSHAL_Find_Proxy_Object(wine_marshal_id *mid,LPUNKNOWN *punk) {
154 int i;
156 for (i=0;i<nrofproxies;i++)
157 if (MARSHAL_Compare_Mids_NoInterface(mid,&(proxies[i].mid))) {
158 *punk = proxies[i].pUnk;
159 IUnknown_AddRef((*punk));
160 return S_OK;
162 return E_FAIL;
165 HRESULT
166 MARSHAL_Register_Proxy(wine_marshal_id *mid,LPUNKNOWN punk) {
167 int i;
169 for (i=0;i<nrofproxies;i++) {
170 if (MARSHAL_Compare_Mids(mid,&(proxies[i].mid))) {
171 ERR("Already have mid?\n");
172 return E_FAIL;
175 if (nrofproxies)
176 proxies = HeapReAlloc(GetProcessHeap(),0,proxies,sizeof(proxies[0])*(nrofproxies+1));
177 else
178 proxies = HeapAlloc(GetProcessHeap(),0,sizeof(proxies[0]));
179 memcpy(&(proxies[nrofproxies].mid),mid,sizeof(*mid));
180 proxies[nrofproxies].pUnk = punk;
181 nrofproxies++;
182 IUnknown_AddRef(punk);
183 return S_OK;
186 /********************** StdMarshal implementation ****************************/
187 typedef struct _StdMarshalImpl {
188 ICOM_VTABLE(IMarshal) *lpvtbl;
189 DWORD ref;
191 IID iid;
192 DWORD dwDestContext;
193 LPVOID pvDestContext;
194 DWORD mshlflags;
195 } StdMarshalImpl;
197 HRESULT WINAPI
198 StdMarshalImpl_QueryInterface(LPMARSHAL iface,REFIID riid,LPVOID *ppv) {
199 *ppv = NULL;
200 if (IsEqualIID(&IID_IUnknown,riid) || IsEqualIID(&IID_IMarshal,riid)) {
201 *ppv = iface;
202 IUnknown_AddRef(iface);
203 return S_OK;
205 FIXME("No interface for %s.\n",debugstr_guid(riid));
206 return E_NOINTERFACE;
209 ULONG WINAPI
210 StdMarshalImpl_AddRef(LPMARSHAL iface) {
211 ICOM_THIS(StdMarshalImpl,iface);
212 This->ref++;
213 return This->ref;
216 ULONG WINAPI
217 StdMarshalImpl_Release(LPMARSHAL iface) {
218 ICOM_THIS(StdMarshalImpl,iface);
219 This->ref--;
221 if (This->ref)
222 return This->ref;
223 HeapFree(GetProcessHeap(),0,This);
224 return 0;
227 HRESULT WINAPI
228 StdMarshalImpl_GetUnmarshalClass(
229 LPMARSHAL iface, REFIID riid, void* pv, DWORD dwDestContext,
230 void* pvDestContext, DWORD mshlflags, CLSID* pCid
232 memcpy(pCid,&CLSID_DfMarshal,sizeof(CLSID_DfMarshal));
233 return S_OK;
236 HRESULT WINAPI
237 StdMarshalImpl_GetMarshalSizeMax(
238 LPMARSHAL iface, REFIID riid, void* pv, DWORD dwDestContext,
239 void* pvDestContext, DWORD mshlflags, DWORD* pSize
241 *pSize = sizeof(wine_marshal_id)+sizeof(wine_marshal_data);
242 return S_OK;
245 HRESULT WINAPI
246 StdMarshalImpl_MarshalInterface(
247 LPMARSHAL iface, IStream *pStm,REFIID riid, void* pv, DWORD dwDestContext,
248 void* pvDestContext, DWORD mshlflags
250 wine_marshal_id mid;
251 wine_marshal_data md;
252 IUnknown *pUnk;
253 ULONG res;
254 HRESULT hres;
255 IRpcStubBuffer *stub;
256 IPSFactoryBuffer *psfacbuf;
258 TRACE("(...,%s,...)\n",debugstr_guid(riid));
259 IUnknown_QueryInterface((LPUNKNOWN)pv,&IID_IUnknown,(LPVOID*)&pUnk);
260 mid.processid = GetCurrentProcessId();
261 mid.objectid = (DWORD)pUnk; /* FIXME */
262 IUnknown_Release(pUnk);
263 memcpy(&mid.iid,riid,sizeof(mid.iid));
264 md.dwDestContext = dwDestContext;
265 md.mshlflags = mshlflags;
266 hres = IStream_Write(pStm,&mid,sizeof(mid),&res);
267 if (hres) return hres;
268 hres = IStream_Write(pStm,&md,sizeof(md),&res);
269 if (hres) return hres;
271 if (SUCCEEDED(MARSHAL_Find_Stub(&mid,&pUnk))) {
272 IUnknown_Release(pUnk);
273 return S_OK;
275 hres = get_facbuf_for_iid(riid,&psfacbuf);
276 if (hres) return hres;
277 hres = IPSFactoryBuffer_CreateStub(psfacbuf,riid,pv,&stub);
278 IPSFactoryBuffer_Release(psfacbuf);
279 if (hres) {
280 FIXME("Failed to create a stub for %s\n",debugstr_guid(riid));
281 return hres;
283 IUnknown_QueryInterface((LPUNKNOWN)pv,riid,(LPVOID*)&pUnk);
284 MARSHAL_Register_Stub(&mid,pUnk,stub);
285 IUnknown_Release(pUnk);
286 return S_OK;
289 HRESULT WINAPI
290 StdMarshalImpl_UnmarshalInterface(
291 LPMARSHAL iface, IStream *pStm, REFIID riid, void **ppv
293 wine_marshal_id mid;
294 wine_marshal_data md;
295 ULONG res;
296 HRESULT hres;
297 IPSFactoryBuffer *psfacbuf;
298 IRpcProxyBuffer *rpcproxy;
299 IRpcChannelBuffer *chanbuf;
301 TRACE("(...,%s,....)\n",debugstr_guid(riid));
302 hres = IStream_Read(pStm,&mid,sizeof(mid),&res);
303 if (hres) return hres;
304 hres = IStream_Read(pStm,&md,sizeof(md),&res);
305 if (hres) return hres;
306 if (SUCCEEDED(MARSHAL_Find_Stub(&mid,(LPUNKNOWN*)ppv))) {
307 FIXME("Calling back to ourselves for %s!\n",debugstr_guid(riid));
308 return S_OK;
310 hres = get_facbuf_for_iid(riid,&psfacbuf);
311 if (hres) return hres;
312 hres = IPSFactoryBuffer_CreateProxy(psfacbuf,NULL,riid,&rpcproxy,ppv);
313 if (hres) {
314 FIXME("Failed to create a proxy for %s\n",debugstr_guid(riid));
315 return hres;
317 hres = PIPE_GetNewPipeBuf(&mid,&chanbuf);
318 if (hres) {
319 ERR("Failed to get an rpc channel buffer for %s\n",debugstr_guid(riid));
320 } else {
321 IRpcProxyBuffer_Connect(rpcproxy,chanbuf);
322 IRpcProxyBuffer_Release(rpcproxy); /* no need */
324 IPSFactoryBuffer_Release(psfacbuf);
325 return hres;
328 HRESULT WINAPI
329 StdMarshalImpl_ReleaseMarshalData(LPMARSHAL iface, IStream *pStm) {
330 FIXME("(), stub!\n");
331 return S_OK;
334 HRESULT WINAPI
335 StdMarshalImpl_DisconnectObject(LPMARSHAL iface, DWORD dwReserved) {
336 FIXME("(), stub!\n");
337 return S_OK;
340 ICOM_VTABLE(IMarshal) stdmvtbl = {
341 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
342 StdMarshalImpl_QueryInterface,
343 StdMarshalImpl_AddRef,
344 StdMarshalImpl_Release,
345 StdMarshalImpl_GetUnmarshalClass,
346 StdMarshalImpl_GetMarshalSizeMax,
347 StdMarshalImpl_MarshalInterface,
348 StdMarshalImpl_UnmarshalInterface,
349 StdMarshalImpl_ReleaseMarshalData,
350 StdMarshalImpl_DisconnectObject
353 /***********************************************************************
354 * CoGetStandardMarshal [OLE32.@]
356 * When the COM library in the client process receives a marshalled
357 * interface pointer, it looks for a CLSID to be used in creating a proxy
358 * for the purposes of unmarshalling the packet. If the packet does not
359 * contain a CLSID for the proxy, COM calls CoGetStandardMarshal, passing a
360 * NULL pUnk value.
361 * This function creates a standard proxy in the client process and returns
362 * a pointer to that proxy's implementation of IMarshal.
363 * COM uses this pointer to call CoUnmarshalInterface to retrieve the pointer
364 * to the requested interface.
366 HRESULT WINAPI
367 CoGetStandardMarshal(
368 REFIID riid,IUnknown *pUnk,DWORD dwDestContext,LPVOID pvDestContext,
369 DWORD mshlflags, LPMARSHAL *pMarshal
371 StdMarshalImpl *dm;
373 if (pUnk == NULL) {
374 FIXME("(%s,NULL,%lx,%p,%lx,%p), unimplemented yet.\n",
375 debugstr_guid(riid),dwDestContext,pvDestContext,mshlflags,pMarshal
377 return E_FAIL;
379 TRACE("(%s,%p,%lx,%p,%lx,%p)\n",
380 debugstr_guid(riid),pUnk,dwDestContext,pvDestContext,mshlflags,pMarshal
382 *pMarshal = HeapAlloc(GetProcessHeap(),0,sizeof(StdMarshalImpl));
383 dm = (StdMarshalImpl*) *pMarshal;
384 if (!dm) return E_FAIL;
385 dm->lpvtbl = &stdmvtbl;
386 dm->ref = 1;
388 memcpy(&dm->iid,riid,sizeof(dm->iid));
389 dm->dwDestContext = dwDestContext;
390 dm->pvDestContext = pvDestContext;
391 dm->mshlflags = mshlflags;
392 return S_OK;
395 /* Helper function for getting Marshaler */
396 static HRESULT WINAPI
397 _GetMarshaller(REFIID riid, IUnknown *pUnk,DWORD dwDestContext,
398 void *pvDestContext, DWORD mshlFlags, LPMARSHAL *pMarshal
400 HRESULT hres;
402 if (!pUnk)
403 return E_POINTER;
404 hres = IUnknown_QueryInterface(pUnk,&IID_IMarshal,(LPVOID*)pMarshal);
405 if (hres)
406 hres = CoGetStandardMarshal(riid,pUnk,dwDestContext,pvDestContext,mshlFlags,pMarshal);
407 return hres;
410 /***********************************************************************
411 * CoGetMarshalSizeMax [OLE32.@]
413 HRESULT WINAPI
414 CoGetMarshalSizeMax(ULONG *pulSize, REFIID riid, IUnknown *pUnk,
415 DWORD dwDestContext, void *pvDestContext, DWORD mshlFlags
417 HRESULT hres;
418 LPMARSHAL pMarshal;
420 hres = _GetMarshaller(riid,pUnk,dwDestContext,pvDestContext,mshlFlags,&pMarshal);
421 if (hres)
422 return hres;
423 hres = IMarshal_GetMarshalSizeMax(pMarshal,riid,pUnk,dwDestContext,pvDestContext,mshlFlags,pulSize);
424 *pulSize += sizeof(wine_marshal_id)+sizeof(wine_marshal_data)+sizeof(CLSID);
425 IMarshal_Release(pMarshal);
426 return hres;
430 /***********************************************************************
431 * CoMarshalInterface [OLE32.@]
433 HRESULT WINAPI
434 CoMarshalInterface( IStream *pStm, REFIID riid, IUnknown *pUnk,
435 DWORD dwDestContext, void *pvDestContext, DWORD mshlflags
437 HRESULT hres;
438 LPMARSHAL pMarshal;
439 CLSID xclsid;
440 ULONG writeres;
441 wine_marshal_id mid;
442 wine_marshal_data md;
443 ULONG res;
444 IUnknown *pUnknown;
446 TRACE("(%p, %s, %p, %lx, %p, %lx)\n",
447 pStm,debugstr_guid(riid),pUnk,dwDestContext,pvDestContext,mshlflags
449 STUBMGR_Start(); /* Just to be sure we have one running. */
450 mid.processid = GetCurrentProcessId();
451 IUnknown_QueryInterface(pUnk,&IID_IUnknown,(LPVOID*)&pUnknown);
452 mid.objectid = (DWORD)pUnknown;
453 IUnknown_Release(pUnknown);
454 memcpy(&mid.iid,riid,sizeof(mid.iid));
455 md.dwDestContext = dwDestContext;
456 md.mshlflags = mshlflags;
457 hres = IStream_Write(pStm,&mid,sizeof(mid),&res);
458 if (hres) return hres;
459 hres = IStream_Write(pStm,&md,sizeof(md),&res);
460 if (hres) return hres;
461 hres = _GetMarshaller(riid,pUnk,dwDestContext,pvDestContext,mshlflags,&pMarshal);
462 if (hres) {
463 FIXME("Failed to get marshaller, %lx?\n",hres);
464 return hres;
466 hres = IMarshal_GetUnmarshalClass(pMarshal,riid,pUnk,dwDestContext,pvDestContext,mshlflags,&xclsid);
467 if (hres) {
468 FIXME("IMarshal:GetUnmarshalClass failed, %lx\n",hres);
469 goto release_marshal;
471 hres = IStream_Write(pStm,&xclsid,sizeof(xclsid),&writeres);
472 if (hres) {
473 FIXME("Stream write failed, %lx\n",hres);
474 goto release_marshal;
476 hres = IMarshal_MarshalInterface(pMarshal,pStm,riid,pUnk,dwDestContext,pvDestContext,mshlflags);
477 if (hres) {
478 if (IsEqualGUID(riid,&IID_IClassFactory)) {
479 MESSAGE("\nERROR: You need to merge the 'winedefault.reg' file into your\n");
480 MESSAGE(" Wine registry by running: `regedit winedefault.reg'\n\n");
481 } else {
482 if (IsEqualGUID(riid,&IID_IOleObject)) {
483 ERR("WINE currently cannot marshal IOleObject interfaces. This means you cannot embed/link OLE objects between applications.\n");
484 } else {
485 FIXME("Failed to marshal the interface %s, %lx?\n",debugstr_guid(riid),hres);
488 goto release_marshal;
490 release_marshal:
491 IMarshal_Release(pMarshal);
492 return hres;
496 /***********************************************************************
497 * CoUnmarshalInterface [OLE32.@]
499 HRESULT WINAPI
500 CoUnmarshalInterface(IStream *pStm, REFIID riid, LPVOID *ppv) {
501 HRESULT hres;
502 wine_marshal_id mid;
503 wine_marshal_data md;
504 ULONG res;
505 LPMARSHAL pMarshal;
506 LPUNKNOWN pUnk;
507 CLSID xclsid;
509 TRACE("(%p,%s,%p)\n",pStm,debugstr_guid(riid),ppv);
511 hres = IStream_Read(pStm,&mid,sizeof(mid),&res);
512 if (hres) {
513 FIXME("Stream read 1 failed, %lx, (%ld of %d)\n",hres,res,sizeof(mid));
514 return hres;
516 hres = IStream_Read(pStm,&md,sizeof(md),&res);
517 if (hres) {
518 FIXME("Stream read 2 failed, %lx, (%ld of %d)\n",hres,res,sizeof(md));
519 return hres;
521 hres = IStream_Read(pStm,&xclsid,sizeof(xclsid),&res);
522 if (hres) {
523 FIXME("Stream read 3 failed, %lx, (%ld of %d)\n",hres,res,sizeof(xclsid));
524 return hres;
526 hres=CoCreateInstance(&xclsid,NULL,CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER | CLSCTX_LOCAL_SERVER,&IID_IMarshal,(void**)&pUnk);
527 if (hres) {
528 FIXME("Failed to create instance of unmarshaller %s.\n",debugstr_guid(&xclsid));
529 return hres;
531 hres = _GetMarshaller(riid,pUnk,md.dwDestContext,NULL,md.mshlflags,&pMarshal);
532 if (hres) {
533 FIXME("Failed to get unmarshaller, %lx?\n",hres);
534 return hres;
536 hres = IMarshal_UnmarshalInterface(pMarshal,pStm,riid,ppv);
537 if (hres) {
538 FIXME("Failed to Unmarshal the interface, %lx?\n",hres);
539 goto release_marshal;
541 release_marshal:
542 IMarshal_Release(pMarshal);
543 return hres;
546 /***********************************************************************
547 * CoReleaseMarshalData [OLE32.@]
549 HRESULT WINAPI
550 CoReleaseMarshalData(IStream *pStm) {
551 HRESULT hres;
552 wine_marshal_id mid;
553 wine_marshal_data md;
554 ULONG res;
555 LPMARSHAL pMarshal;
556 LPUNKNOWN pUnk;
557 CLSID xclsid;
559 TRACE("(%p)\n",pStm);
561 hres = IStream_Read(pStm,&mid,sizeof(mid),&res);
562 if (hres) {
563 FIXME("Stream read 1 failed, %lx, (%ld of %d)\n",hres,res,sizeof(mid));
564 return hres;
566 hres = IStream_Read(pStm,&md,sizeof(md),&res);
567 if (hres) {
568 FIXME("Stream read 2 failed, %lx, (%ld of %d)\n",hres,res,sizeof(md));
569 return hres;
571 hres = IStream_Read(pStm,&xclsid,sizeof(xclsid),&res);
572 if (hres) {
573 FIXME("Stream read 3 failed, %lx, (%ld of %d)\n",hres,res,sizeof(xclsid));
574 return hres;
576 hres=CoCreateInstance(&xclsid,NULL,CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER | CLSCTX_LOCAL_SERVER,&IID_IMarshal,(void**)(char*)&pUnk);
577 if (hres) {
578 FIXME("Failed to create instance of unmarshaller %s.\n",debugstr_guid(&xclsid));
579 return hres;
581 hres = IUnknown_QueryInterface(pUnk,&IID_IMarshal,(LPVOID*)(char*)&pMarshal);
582 if (hres) {
583 FIXME("Failed to get IMarshal iface, %lx?\n",hres);
584 return hres;
586 hres = IMarshal_ReleaseMarshalData(pMarshal,pStm);
587 if (hres) {
588 FIXME("Failed to releasemarshaldata the interface, %lx?\n",hres);
590 IMarshal_Release(pMarshal);
591 IUnknown_Release(pUnk);
592 return hres;
596 /***********************************************************************
597 * CoMarshalInterThreadInterfaceInStream [OLE32.@]
599 * Marshal an interface across threads in the same process.
601 * PARAMS
602 * riid [I] Identifier of the interface to be marshalled.
603 * pUnk [I] Pointer to IUnknown-derived interface that will be marshalled.
604 * ppStm [O] Pointer to IStream object that is created and then used to store the marshalled inteface.
606 * RETURNS
607 * Success: S_OK
608 * Failure: E_OUTOFMEMORY and other COM error codes
610 * SEE
611 * CoMarshalInterface(), CoUnmarshalInterface() and CoGetInterfaceAndReleaseStream()
613 HRESULT WINAPI
614 CoMarshalInterThreadInterfaceInStream(
615 REFIID riid, LPUNKNOWN pUnk, LPSTREAM * ppStm)
617 ULARGE_INTEGER xpos;
618 LARGE_INTEGER seekto;
619 HRESULT hres;
621 TRACE("(%s, %p, %p)\n",debugstr_guid(riid), pUnk, ppStm);
623 hres = CreateStreamOnHGlobal(0, TRUE, ppStm);
624 if (FAILED(hres)) return hres;
625 hres = CoMarshalInterface(*ppStm, riid, pUnk, MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL);
627 /* FIXME: is this needed? */
628 memset(&seekto,0,sizeof(seekto));
629 IStream_Seek(*ppStm,seekto,SEEK_SET,&xpos);
631 return hres;
634 /***********************************************************************
635 * CoGetInterfaceAndReleaseStream [OLE32.@]
637 * Unmarshalls an inteface from a stream and then releases the stream.
639 * PARAMS
640 * pStm [I] Stream that contains the marshalled inteface.
641 * riid [I] Interface identifier of the object to unmarshall.
642 * ppv [O] Address of pointer where the requested interface object will be stored.
644 * RETURNS
645 * Success: S_OK
646 * Failure: A COM error code
648 * SEE
649 * CoMarshalInterThreadInterfaceInStream() and CoUnmarshalInteface()
651 HRESULT WINAPI
652 CoGetInterfaceAndReleaseStream(LPSTREAM pStm,REFIID riid, LPVOID *ppv)
654 HRESULT hres;
656 TRACE("(%p, %s, %p)\n", pStm, debugstr_guid(riid), ppv);
658 hres = CoUnmarshalInterface(pStm, riid, ppv);
659 IStream_Release(pStm);
660 return hres;
663 static HRESULT WINAPI
664 SMCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid, LPVOID *ppv) {
665 *ppv = NULL;
666 if (IsEqualIID(riid,&IID_IUnknown) || IsEqualIID(riid,&IID_IClassFactory)) {
667 *ppv = (LPVOID)iface;
668 return S_OK;
670 return E_NOINTERFACE;
672 static ULONG WINAPI SMCF_AddRef(LPCLASSFACTORY iface) { return 2; }
673 static ULONG WINAPI SMCF_Release(LPCLASSFACTORY iface) { return 1; }
675 static HRESULT WINAPI
676 SMCF_CreateInstance(
677 LPCLASSFACTORY iface, LPUNKNOWN pUnk, REFIID riid, LPVOID *ppv
679 if (IsEqualIID(riid,&IID_IMarshal)) {
680 StdMarshalImpl *dm;
681 dm=(StdMarshalImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(StdMarshalImpl));
682 if (!dm)
683 return E_FAIL;
684 dm->lpvtbl = &stdmvtbl;
685 dm->ref = 1;
686 *ppv = (LPVOID)dm;
687 return S_OK;
689 FIXME("(%s), not supported.\n",debugstr_guid(riid));
690 return E_NOINTERFACE;
693 static HRESULT WINAPI
694 SMCF_LockServer(LPCLASSFACTORY iface, BOOL fLock) {
695 FIXME("(%d), stub!\n",fLock);
696 return S_OK;
699 static ICOM_VTABLE(IClassFactory) dfmarshalcfvtbl = {
700 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
701 SMCF_QueryInterface,
702 SMCF_AddRef,
703 SMCF_Release,
704 SMCF_CreateInstance,
705 SMCF_LockServer
707 static ICOM_VTABLE(IClassFactory) *pdfmarshalcfvtbl = &dfmarshalcfvtbl;
709 HRESULT
710 MARSHAL_GetStandardMarshalCF(LPVOID *ppv) {
711 *ppv = &pdfmarshalcfvtbl;
712 return S_OK;