2 * OLE32 proxy/stub handler
4 * Copyright 2002 Marcus Meissner
5 * Copyright 2001 Ove Kåven, TransGaming Technologies
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 /* Documentation on MSDN:
24 * (Top level COM documentation)
25 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/componentdevelopmentank.asp
28 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/htm/comext_1q0p.asp
31 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/htm/comext_1lia.asp
34 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/htm/comext_1gfn.asp
46 #define NONAMELESSUNION
47 #define NONAMELESSSTRUCT
59 #include "compobj_private.h"
62 #include "wine/debug.h"
64 WINE_DEFAULT_DEBUG_CHANNEL(ole);
66 const CLSID CLSID_DfMarshal = { 0x0000030b, 0, 0, {0xc0, 0, 0, 0, 0, 0, 0, 0x46} };
67 const CLSID CLSID_PSFactoryBuffer = { 0x00000320, 0, 0, {0xc0, 0, 0, 0, 0, 0, 0, 0x46} };
69 /* From: http://msdn.microsoft.com/library/en-us/com/cmi_m_4lda.asp
71 * The first time a client requests a pointer to an interface on a
72 * particular object, COM loads an IClassFactory stub in the server
73 * process and uses it to marshal the first pointer back to the
74 * client. In the client process, COM loads the generic proxy for the
75 * class factory object and calls its implementation of IMarshal to
76 * unmarshal that first pointer. COM then creates the first interface
77 * proxy and hands it a pointer to the RPC channel. Finally, COM returns
78 * the IClassFactory pointer to the client, which uses it to call
79 * IClassFactory::CreateInstance, passing it a reference to the interface.
81 * Back in the server process, COM now creates a new instance of the
82 * object, along with a stub for the requested interface. This stub marshals
83 * the interface pointer back to the client process, where another object
84 * proxy is created, this time for the object itself. Also created is a
85 * proxy for the requested interface, a pointer to which is returned to
86 * the client. With subsequent calls to other interfaces on the object,
87 * COM will load the appropriate interface stubs and proxies as needed.
89 typedef struct _CFStub {
90 const IRpcStubBufferVtbl *lpvtbl;
97 CFStub_QueryInterface(LPRPCSTUBBUFFER iface, REFIID riid, LPVOID *ppv) {
98 if (IsEqualIID(&IID_IUnknown,riid)||IsEqualIID(&IID_IRpcStubBuffer,riid)) {
100 IUnknown_AddRef(iface);
103 FIXME("(%s), interface not supported.\n",debugstr_guid(riid));
104 return E_NOINTERFACE;
108 CFStub_AddRef(LPRPCSTUBBUFFER iface) {
109 CFStub *This = (CFStub *)iface;
110 return InterlockedIncrement(&This->ref);
114 CFStub_Release(LPRPCSTUBBUFFER iface) {
115 CFStub *This = (CFStub *)iface;
118 ref = InterlockedDecrement(&This->ref);
120 IRpcStubBuffer_Disconnect(iface);
121 HeapFree(GetProcessHeap(),0,This);
126 static HRESULT WINAPI
127 CFStub_Connect(LPRPCSTUBBUFFER iface, IUnknown *pUnkServer) {
128 CFStub *This = (CFStub *)iface;
130 This->pUnkServer = pUnkServer;
131 IUnknown_AddRef(pUnkServer);
136 CFStub_Disconnect(LPRPCSTUBBUFFER iface) {
137 CFStub *This = (CFStub *)iface;
139 if (This->pUnkServer) {
140 IUnknown_Release(This->pUnkServer);
141 This->pUnkServer = NULL;
145 static HRESULT WINAPI
147 LPRPCSTUBBUFFER iface,RPCOLEMESSAGE* msg,IRpcChannelBuffer* chanbuf
149 CFStub *This = (CFStub *)iface;
152 if (msg->iMethod == 3) { /* CreateInstance */
154 IClassFactory *classfac;
158 ULARGE_INTEGER newpos;
159 LARGE_INTEGER seekto;
162 if (msg->cbBuffer < sizeof(IID)) {
163 FIXME("Not enough bytes in buffer (%ld instead of %d)?\n",msg->cbBuffer,sizeof(IID));
166 memcpy(&iid,msg->Buffer,sizeof(iid));
167 TRACE("->CreateInstance(%s)\n",debugstr_guid(&iid));
168 hres = IUnknown_QueryInterface(This->pUnkServer,&IID_IClassFactory,(LPVOID*)&classfac);
170 FIXME("Ole server does not provide an IClassFactory?\n");
173 hres = IClassFactory_CreateInstance(classfac,NULL,&iid,(LPVOID*)&ppv);
174 IClassFactory_Release(classfac);
177 FIXME("Failed to create an instance of %s\n",debugstr_guid(&iid));
180 hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
182 FIXME("Failed to create stream on hglobal\n");
185 hres = CoMarshalInterface(pStm,&iid,ppv,0,NULL,0);
186 IUnknown_Release((IUnknown*)ppv);
188 FIXME("CoMarshalInterface failed, %lx!\n",hres);
192 hres = IStream_Stat(pStm,&ststg,0);
194 FIXME("Stat failed.\n");
198 msg->cbBuffer = ststg.cbSize.u.LowPart;
200 I_RpcGetBuffer((RPC_MESSAGE *)msg);
201 if (hres) return hres;
203 seekto.u.LowPart = 0;seekto.u.HighPart = 0;
204 hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
206 FIXME("IStream_Seek failed, %lx\n",hres);
209 hres = IStream_Read(pStm,msg->Buffer,msg->cbBuffer,&res);
211 FIXME("Stream Read failed, %lx\n",hres);
214 IStream_Release(pStm);
217 FIXME("(%p,%p), stub!\n",msg,chanbuf);
218 FIXME("iMethod is %ld\n",msg->iMethod);
219 FIXME("cbBuffer is %ld\n",msg->cbBuffer);
223 static LPRPCSTUBBUFFER WINAPI
224 CFStub_IsIIDSupported(LPRPCSTUBBUFFER iface,REFIID riid) {
225 FIXME("(%s), stub!\n",debugstr_guid(riid));
230 CFStub_CountRefs(LPRPCSTUBBUFFER iface) {
231 FIXME("(), stub!\n");
235 static HRESULT WINAPI
236 CFStub_DebugServerQueryInterface(LPRPCSTUBBUFFER iface,void** ppv) {
237 FIXME("(%p), stub!\n",ppv);
241 CFStub_DebugServerRelease(LPRPCSTUBBUFFER iface,void *pv) {
242 FIXME("(%p), stub!\n",pv);
245 static const IRpcStubBufferVtbl cfstubvt = {
246 CFStub_QueryInterface,
252 CFStub_IsIIDSupported,
254 CFStub_DebugServerQueryInterface,
255 CFStub_DebugServerRelease
259 CFStub_Construct(LPRPCSTUBBUFFER *ppv) {
261 cfstub = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(CFStub));
263 return E_OUTOFMEMORY;
264 *ppv = (LPRPCSTUBBUFFER)cfstub;
265 cfstub->lpvtbl = &cfstubvt;
270 /* Since we create proxy buffers and classfactory in a pair, there is
271 * no need for 2 separate structs. Just put them in one, but remember
274 typedef struct _CFProxy {
275 const IClassFactoryVtbl *lpvtbl_cf;
276 const IRpcProxyBufferVtbl *lpvtbl_proxy;
279 IRpcChannelBuffer *chanbuf;
280 IUnknown *outer_unknown;
283 static HRESULT WINAPI IRpcProxyBufferImpl_QueryInterface(LPRPCPROXYBUFFER iface,REFIID riid,LPVOID *ppv) {
285 if (IsEqualIID(riid,&IID_IRpcProxyBuffer)||IsEqualIID(riid,&IID_IUnknown)) {
286 IRpcProxyBuffer_AddRef(iface);
287 *ppv = (LPVOID)iface;
290 FIXME("(%s), no interface.\n",debugstr_guid(riid));
291 return E_NOINTERFACE;
294 static ULONG WINAPI IRpcProxyBufferImpl_AddRef(LPRPCPROXYBUFFER iface) {
295 ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
296 return InterlockedIncrement(&This->ref);
299 static ULONG WINAPI IRpcProxyBufferImpl_Release(LPRPCPROXYBUFFER iface) {
300 ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
301 ULONG ref = InterlockedDecrement(&This->ref);
304 IRpcChannelBuffer_Release(This->chanbuf);
305 This->chanbuf = NULL;
306 HeapFree(GetProcessHeap(),0,This);
311 static HRESULT WINAPI IRpcProxyBufferImpl_Connect(LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer) {
312 ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
314 This->chanbuf = pRpcChannelBuffer;
315 IRpcChannelBuffer_AddRef(This->chanbuf);
318 static void WINAPI IRpcProxyBufferImpl_Disconnect(LPRPCPROXYBUFFER iface) {
319 ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
321 IRpcChannelBuffer_Release(This->chanbuf);
322 This->chanbuf = NULL;
326 static HRESULT WINAPI
327 CFProxy_QueryInterface(LPCLASSFACTORY iface,REFIID riid, LPVOID *ppv) {
328 ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
329 if (This->outer_unknown) return IUnknown_QueryInterface(This->outer_unknown, riid, ppv);
331 if (IsEqualIID(&IID_IClassFactory,riid) || IsEqualIID(&IID_IUnknown,riid)) {
332 *ppv = (LPVOID)iface;
333 IClassFactory_AddRef(iface);
336 if (IsEqualIID(riid,&IID_IMarshal)) /* just to avoid debug output */
337 return E_NOINTERFACE;
338 FIXME("Unhandled interface: %s\n",debugstr_guid(riid));
339 return E_NOINTERFACE;
342 static ULONG WINAPI CFProxy_AddRef(LPCLASSFACTORY iface) {
343 ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
344 if (This->outer_unknown) return IUnknown_AddRef(This->outer_unknown);
345 return InterlockedIncrement(&This->ref);
348 static ULONG WINAPI CFProxy_Release(LPCLASSFACTORY iface) {
350 ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
351 if (This->outer_unknown)
352 ref = IUnknown_Release(This->outer_unknown);
354 ref = InterlockedDecrement(&This->ref);
357 if (This->chanbuf) IRpcChannelBuffer_Release(This->chanbuf);
358 HeapFree(GetProcessHeap(),0,This);
363 static HRESULT WINAPI CFProxy_CreateInstance(
364 LPCLASSFACTORY iface,
365 LPUNKNOWN pUnkOuter,/* [in] */
366 REFIID riid, /* [in] */
367 LPVOID *ppv /* [out] */
369 ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
376 TRACE("(%p,%s,%p)\n",pUnkOuter,debugstr_guid(riid),ppv);
378 /* Send CreateInstance to the remote classfactory.
380 * Data: Only the 'IID'.
383 msg.cbBuffer = sizeof(*riid);
385 hres = IRpcChannelBuffer_GetBuffer(This->chanbuf,&msg,&IID_IClassFactory);
387 FIXME("IRpcChannelBuffer_GetBuffer failed with %lx?\n",hres);
390 memcpy(msg.Buffer,riid,sizeof(*riid));
391 hres = IRpcChannelBuffer_SendReceive(This->chanbuf,&msg,&srstatus);
393 FIXME("IRpcChannelBuffer_SendReceive failed with %lx?\n",hres);
397 if (!msg.cbBuffer) /* interface not found on remote */
400 /* We got back: [Marshalled Interface data] */
401 TRACE("got %ld bytes data.\n",msg.cbBuffer);
402 hGlobal = GlobalAlloc(GMEM_MOVEABLE|GMEM_NODISCARD|GMEM_SHARE,msg.cbBuffer);
403 memcpy(GlobalLock(hGlobal),msg.Buffer,msg.cbBuffer);
404 hres = CreateStreamOnHGlobal(hGlobal,TRUE,&pStream);
406 FIXME("CreateStreamOnHGlobal failed with %lx\n",hres);
409 hres = CoUnmarshalInterface(
414 IStream_Release(pStream); /* Does GlobalFree hGlobal too. */
416 FIXME("CoMarshalInterface failed, %lx\n",hres);
422 static HRESULT WINAPI CFProxy_LockServer(LPCLASSFACTORY iface,BOOL fLock) {
423 /*ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);*/
424 FIXME("(%d), stub!\n",fLock);
425 /* basically: write BOOL, read empty */
429 static const IRpcProxyBufferVtbl pspbvtbl = {
430 IRpcProxyBufferImpl_QueryInterface,
431 IRpcProxyBufferImpl_AddRef,
432 IRpcProxyBufferImpl_Release,
433 IRpcProxyBufferImpl_Connect,
434 IRpcProxyBufferImpl_Disconnect
436 static const IClassFactoryVtbl cfproxyvt = {
437 CFProxy_QueryInterface,
440 CFProxy_CreateInstance,
445 CFProxy_Construct(IUnknown *pUnkOuter, LPVOID *ppv,LPVOID *ppProxy) {
448 cf = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(CFProxy));
450 return E_OUTOFMEMORY;
452 cf->lpvtbl_cf = &cfproxyvt;
453 cf->lpvtbl_proxy = &pspbvtbl;
454 /* only one reference for the proxy buffer */
456 cf->outer_unknown = pUnkOuter;
457 *ppv = &(cf->lpvtbl_cf);
458 *ppProxy = &(cf->lpvtbl_proxy);
463 /********************* IRemUnknown Proxy/Stub ********************************/
467 const IRpcStubBufferVtbl *lpVtbl;
472 static HRESULT WINAPI RemUnkStub_QueryInterface(LPRPCSTUBBUFFER iface,
476 RemUnkStub *This = (RemUnkStub *)iface;
477 TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(riid),obj);
478 if (IsEqualGUID(&IID_IUnknown,riid) ||
479 IsEqualGUID(&IID_IRpcStubBuffer,riid)) {
483 return E_NOINTERFACE;
486 static ULONG WINAPI RemUnkStub_AddRef(LPRPCSTUBBUFFER iface)
488 RemUnkStub *This = (RemUnkStub *)iface;
489 TRACE("(%p)->AddRef()\n",This);
490 return InterlockedIncrement(&This->refs);
493 static ULONG WINAPI RemUnkStub_Release(LPRPCSTUBBUFFER iface)
495 RemUnkStub *This = (RemUnkStub *)iface;
497 TRACE("(%p)->Release()\n",This);
498 refs = InterlockedDecrement(&This->refs);
500 HeapFree(GetProcessHeap(), 0, This);
504 static HRESULT WINAPI RemUnkStub_Connect(LPRPCSTUBBUFFER iface,
505 LPUNKNOWN lpUnkServer)
507 RemUnkStub *This = (RemUnkStub *)iface;
508 TRACE("(%p)->Connect(%p)\n",This,lpUnkServer);
509 This->iface = (IRemUnknown*)lpUnkServer;
510 IRemUnknown_AddRef(This->iface);
514 static void WINAPI RemUnkStub_Disconnect(LPRPCSTUBBUFFER iface)
516 RemUnkStub *This = (RemUnkStub *)iface;
517 TRACE("(%p)->Disconnect()\n",This);
518 IUnknown_Release(This->iface);
522 static HRESULT WINAPI RemUnkStub_Invoke(LPRPCSTUBBUFFER iface,
524 LPRPCCHANNELBUFFER pChannel)
526 RemUnkStub *This = (RemUnkStub *)iface;
527 ULONG iMethod = pMsg->iMethod;
528 LPBYTE buf = pMsg->Buffer;
529 HRESULT hr = RPC_E_INVALIDMETHOD;
531 TRACE("(%p)->Invoke(%p,%p) method %ld\n", This, pMsg, pChannel, iMethod);
534 case 3: /* RemQueryInterface */
540 REMQIRESULT *pQIResults = NULL;
543 memcpy(&ipid, buf, sizeof(ipid));
545 memcpy(&cRefs, buf, sizeof(cRefs));
546 buf += sizeof(cRefs);
547 memcpy(&cIids, buf, sizeof(cIids));
548 buf += sizeof(cIids);
551 hr = IRemUnknown_RemQueryInterface(This->iface, &ipid, cRefs, cIids, iids, &pQIResults);
554 pMsg->cbBuffer = cIids * sizeof(REMQIRESULT) + sizeof(HRESULT);
556 I_RpcGetBuffer((RPC_MESSAGE *)pMsg);
559 *(HRESULT *)buf = hr;
560 buf += sizeof(HRESULT);
563 /* FIXME: pQIResults is a unique pointer so pQIResults can be NULL! */
564 memcpy(buf, pQIResults, cIids * sizeof(REMQIRESULT));
568 case 4: /* RemAddRef */
575 memcpy(&cIids, buf, sizeof(USHORT));
576 buf += sizeof(USHORT);
577 ir = (REMINTERFACEREF*)buf;
578 pResults = CoTaskMemAlloc(cIids * sizeof(HRESULT));
579 if (!pResults) return E_OUTOFMEMORY;
581 hr = IRemUnknown_RemAddRef(This->iface, cIids, ir, pResults);
584 pMsg->cbBuffer = cIids * sizeof(HRESULT);
586 I_RpcGetBuffer((RPC_MESSAGE *)pMsg);
590 memcpy(buf, pResults, cIids * sizeof(HRESULT));
593 CoTaskMemFree(pResults);
597 case 5: /* RemRelease */
603 memcpy(&cIids, buf, sizeof(USHORT));
604 buf += sizeof(USHORT);
605 ir = (REMINTERFACEREF*)buf;
607 hr = IRemUnknown_RemRelease(This->iface, cIids, ir);
617 static LPRPCSTUBBUFFER WINAPI RemUnkStub_IsIIDSupported(LPRPCSTUBBUFFER iface,
620 RemUnkStub *This = (RemUnkStub *)iface;
621 TRACE("(%p)->IsIIDSupported(%s)\n", This, debugstr_guid(riid));
622 return IsEqualGUID(&IID_IRemUnknown, riid) ? iface : NULL;
625 static ULONG WINAPI RemUnkStub_CountRefs(LPRPCSTUBBUFFER iface)
627 RemUnkStub *This = (RemUnkStub *)iface;
628 FIXME("(%p)->CountRefs()\n", This);
632 static HRESULT WINAPI RemUnkStub_DebugServerQueryInterface(LPRPCSTUBBUFFER iface,
635 RemUnkStub *This = (RemUnkStub *)iface;
636 FIXME("(%p)->DebugServerQueryInterface(%p)\n",This,ppv);
637 return E_NOINTERFACE;
640 static void WINAPI RemUnkStub_DebugServerRelease(LPRPCSTUBBUFFER iface,
643 RemUnkStub *This = (RemUnkStub *)iface;
644 FIXME("(%p)->DebugServerRelease(%p)\n", This, pv);
647 static const IRpcStubBufferVtbl RemUnkStub_VTable =
649 RemUnkStub_QueryInterface,
653 RemUnkStub_Disconnect,
655 RemUnkStub_IsIIDSupported,
656 RemUnkStub_CountRefs,
657 RemUnkStub_DebugServerQueryInterface,
658 RemUnkStub_DebugServerRelease
661 static HRESULT RemUnkStub_Construct(IRpcStubBuffer **ppStub)
663 RemUnkStub *This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
664 if (!This) return E_OUTOFMEMORY;
665 This->lpVtbl = &RemUnkStub_VTable;
668 *ppStub = (IRpcStubBuffer*)This;
673 typedef struct _RemUnkProxy {
674 const IRemUnknownVtbl *lpvtbl_remunk;
675 const IRpcProxyBufferVtbl *lpvtbl_proxy;
678 IRpcChannelBuffer *chan;
679 IUnknown *outer_unknown;
682 static HRESULT WINAPI RemUnkProxy_QueryInterface(LPREMUNKNOWN iface, REFIID riid, void **ppv)
684 RemUnkProxy *This = (RemUnkProxy *)iface;
685 if (This->outer_unknown)
686 return IUnknown_QueryInterface(This->outer_unknown, riid, ppv);
687 if (IsEqualIID(riid, &IID_IUnknown) ||
688 IsEqualIID(riid, &IID_IRemUnknown))
690 IRemUnknown_AddRef(iface);
691 *ppv = (LPVOID)iface;
694 return E_NOINTERFACE;
697 static ULONG WINAPI RemUnkProxy_AddRef(LPREMUNKNOWN iface)
699 RemUnkProxy *This = (RemUnkProxy *)iface;
701 TRACE("(%p)->AddRef()\n",This);
702 return InterlockedIncrement(&This->refs);
705 static ULONG WINAPI RemUnkProxy_Release(LPREMUNKNOWN iface)
707 RemUnkProxy *This = (RemUnkProxy *)iface;
710 TRACE("(%p)->Release()\n",This);
711 if (This->outer_unknown)
712 refs = IUnknown_Release(This->outer_unknown);
714 refs = InterlockedDecrement(&This->refs);
717 if (This->chan) IRpcChannelBuffer_Release(This->chan);
718 HeapFree(GetProcessHeap(),0,This);
723 static HRESULT WINAPI RemUnkProxy_RemQueryInterface(LPREMUNKNOWN iface,
728 REMQIRESULT** ppQIResults)
730 RemUnkProxy *This = (RemUnkProxy *)iface;
735 TRACE("(%p)->(%s,%ld,%d,%p,%p)\n",This,
736 debugstr_guid(ripid),cRefs,cIids,iids,ppQIResults);
739 memset(&msg, 0, sizeof(msg));
741 msg.cbBuffer = sizeof(IPID) + sizeof(ULONG) +
742 sizeof(USHORT) + cIids*sizeof(IID);
743 hr = IRpcChannelBuffer_GetBuffer(This->chan, &msg, &IID_IRemUnknown);
745 LPBYTE buf = msg.Buffer;
746 memcpy(buf, ripid, sizeof(IPID));
748 memcpy(buf, &cRefs, sizeof(ULONG));
749 buf += sizeof(ULONG);
750 memcpy(buf, &cIids, sizeof(USHORT));
751 buf += sizeof(USHORT);
752 memcpy(buf, iids, cIids*sizeof(IID));
754 hr = IRpcChannelBuffer_SendReceive(This->chan, &msg, &status);
759 hr = *(HRESULT *)buf;
760 buf += sizeof(HRESULT);
764 *ppQIResults = CoTaskMemAlloc(cIids*sizeof(REMQIRESULT));
765 memcpy(*ppQIResults, buf, cIids*sizeof(REMQIRESULT));
768 IRpcChannelBuffer_FreeBuffer(This->chan, &msg);
774 static HRESULT WINAPI RemUnkProxy_RemAddRef(LPREMUNKNOWN iface,
775 USHORT cInterfaceRefs,
776 REMINTERFACEREF* InterfaceRefs,
779 RemUnkProxy *This = (RemUnkProxy *)iface;
784 TRACE("(%p)->(%d,%p,%p)\n",This,
785 cInterfaceRefs,InterfaceRefs,pResults);
787 memset(&msg, 0, sizeof(msg));
789 msg.cbBuffer = sizeof(USHORT) + cInterfaceRefs*sizeof(REMINTERFACEREF);
790 hr = IRpcChannelBuffer_GetBuffer(This->chan, &msg, &IID_IRemUnknown);
792 LPBYTE buf = msg.Buffer;
793 memcpy(buf, &cInterfaceRefs, sizeof(USHORT));
794 buf += sizeof(USHORT);
795 memcpy(buf, InterfaceRefs, cInterfaceRefs*sizeof(REMINTERFACEREF));
797 hr = IRpcChannelBuffer_SendReceive(This->chan, &msg, &status);
801 memcpy(pResults, buf, cInterfaceRefs*sizeof(HRESULT));
804 IRpcChannelBuffer_FreeBuffer(This->chan, &msg);
810 static HRESULT WINAPI RemUnkProxy_RemRelease(LPREMUNKNOWN iface,
811 USHORT cInterfaceRefs,
812 REMINTERFACEREF* InterfaceRefs)
814 RemUnkProxy *This = (RemUnkProxy *)iface;
819 TRACE("(%p)->(%d,%p)\n",This,
820 cInterfaceRefs,InterfaceRefs);
822 memset(&msg, 0, sizeof(msg));
824 msg.cbBuffer = sizeof(USHORT) + cInterfaceRefs*sizeof(REMINTERFACEREF);
825 hr = IRpcChannelBuffer_GetBuffer(This->chan, &msg, &IID_IRemUnknown);
827 LPBYTE buf = msg.Buffer;
828 memcpy(buf, &cInterfaceRefs, sizeof(USHORT));
829 buf += sizeof(USHORT);
830 memcpy(buf, InterfaceRefs, cInterfaceRefs*sizeof(REMINTERFACEREF));
832 hr = IRpcChannelBuffer_SendReceive(This->chan, &msg, &status);
834 IRpcChannelBuffer_FreeBuffer(This->chan, &msg);
840 static const IRemUnknownVtbl RemUnkProxy_VTable =
842 RemUnkProxy_QueryInterface,
845 RemUnkProxy_RemQueryInterface,
846 RemUnkProxy_RemAddRef,
847 RemUnkProxy_RemRelease
851 static HRESULT WINAPI RURpcProxyBufferImpl_QueryInterface(LPRPCPROXYBUFFER iface,REFIID riid,LPVOID *ppv) {
853 if (IsEqualIID(riid,&IID_IRpcProxyBuffer)||IsEqualIID(riid,&IID_IUnknown)) {
854 IRpcProxyBuffer_AddRef(iface);
855 *ppv = (LPVOID)iface;
858 FIXME("(%s), no interface.\n",debugstr_guid(riid));
859 return E_NOINTERFACE;
862 static ULONG WINAPI RURpcProxyBufferImpl_AddRef(LPRPCPROXYBUFFER iface) {
863 ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
864 TRACE("%p, %ld\n", iface, This->refs + 1);
865 return InterlockedIncrement(&This->refs);
868 static ULONG WINAPI RURpcProxyBufferImpl_Release(LPRPCPROXYBUFFER iface) {
869 ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
870 ULONG ref = InterlockedDecrement(&This->refs);
871 TRACE("%p, %ld\n", iface, ref);
873 IRpcChannelBuffer_Release(This->chan);This->chan = NULL;
874 HeapFree(GetProcessHeap(),0,This);
879 static HRESULT WINAPI RURpcProxyBufferImpl_Connect(LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer) {
880 ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
882 TRACE("%p, %p\n", iface, pRpcChannelBuffer);
883 This->chan = pRpcChannelBuffer;
884 IRpcChannelBuffer_AddRef(This->chan);
887 static void WINAPI RURpcProxyBufferImpl_Disconnect(LPRPCPROXYBUFFER iface) {
888 ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
889 TRACE("%p, %p\n", iface, This->chan);
891 IRpcChannelBuffer_Release(This->chan);
897 static const IRpcProxyBufferVtbl RURpcProxyBuffer_VTable = {
898 RURpcProxyBufferImpl_QueryInterface,
899 RURpcProxyBufferImpl_AddRef,
900 RURpcProxyBufferImpl_Release,
901 RURpcProxyBufferImpl_Connect,
902 RURpcProxyBufferImpl_Disconnect
906 RemUnkProxy_Construct(IUnknown *pUnkOuter, LPVOID *ppv,LPVOID *ppProxy) {
909 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*This));
911 return E_OUTOFMEMORY;
913 This->lpvtbl_remunk = &RemUnkProxy_VTable;
914 This->lpvtbl_proxy = &RURpcProxyBuffer_VTable;
915 /* only one reference for the proxy buffer */
917 This->outer_unknown = pUnkOuter;
918 *ppv = &(This->lpvtbl_remunk);
919 *ppProxy = &(This->lpvtbl_proxy);
924 /********************* OLE Proxy/Stub Factory ********************************/
925 static HRESULT WINAPI
926 PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface, REFIID iid, LPVOID *ppv) {
927 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)||IsEqualIID(iid,&IID_IUnknown)) {
928 *ppv = (LPVOID)iface;
929 /* No ref counting, static class */
932 FIXME("(%s) unknown IID?\n",debugstr_guid(iid));
933 return E_NOINTERFACE;
936 static ULONG WINAPI PSFacBuf_AddRef(LPPSFACTORYBUFFER iface) { return 2; }
937 static ULONG WINAPI PSFacBuf_Release(LPPSFACTORYBUFFER iface) { return 1; }
939 static HRESULT WINAPI
940 PSFacBuf_CreateProxy(
941 LPPSFACTORYBUFFER iface, IUnknown* pUnkOuter, REFIID riid,
942 IRpcProxyBuffer **ppProxy, LPVOID *ppv
944 if (IsEqualIID(&IID_IClassFactory,riid))
945 return CFProxy_Construct(pUnkOuter, ppv,(LPVOID*)ppProxy);
946 else if (IsEqualIID(&IID_IRemUnknown,riid))
947 return RemUnkProxy_Construct(pUnkOuter, ppv,(LPVOID*)ppProxy);
948 FIXME("proxying not implemented for (%s) yet!\n",debugstr_guid(riid));
952 static HRESULT WINAPI
954 LPPSFACTORYBUFFER iface, REFIID riid,IUnknown *pUnkServer,
955 IRpcStubBuffer** ppStub
959 TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub);
961 if (IsEqualIID(&IID_IClassFactory, riid) ||
962 IsEqualIID(&IID_IUnknown, riid) /* FIXME: fixup stub manager and remove this*/) {
963 hres = CFStub_Construct(ppStub);
965 IRpcStubBuffer_Connect((*ppStub),pUnkServer);
967 } else if (IsEqualIID(&IID_IRemUnknown,riid)) {
968 hres = RemUnkStub_Construct(ppStub);
970 IRpcStubBuffer_Connect((*ppStub),pUnkServer);
973 FIXME("stubbing not implemented for (%s) yet!\n",debugstr_guid(riid));
977 static const IPSFactoryBufferVtbl psfacbufvtbl = {
978 PSFacBuf_QueryInterface,
981 PSFacBuf_CreateProxy,
985 /* This is the whole PSFactoryBuffer object, just the vtableptr */
986 static const IPSFactoryBufferVtbl *lppsfac = &psfacbufvtbl;
988 /***********************************************************************
989 * DllGetClassObject [OLE32.@]
991 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
994 if (IsEqualIID(rclsid, &CLSID_PSFactoryBuffer))
995 return IPSFactoryBuffer_QueryInterface((IPSFactoryBuffer *)&lppsfac, iid, ppv);
996 if (IsEqualIID(rclsid,&CLSID_DfMarshal)&&(
997 IsEqualIID(iid,&IID_IClassFactory) ||
998 IsEqualIID(iid,&IID_IUnknown)
1001 return MARSHAL_GetStandardMarshalCF(ppv);
1002 if (IsEqualIID(rclsid,&CLSID_StdGlobalInterfaceTable) && (IsEqualIID(iid,&IID_IClassFactory) || IsEqualIID(iid,&IID_IUnknown)))
1003 return StdGlobalInterfaceTable_GetFactory(ppv);
1004 if (IsEqualCLSID(rclsid, &CLSID_FileMoniker))
1005 return FileMonikerCF_Create(iid, ppv);
1006 if (IsEqualCLSID(rclsid, &CLSID_ItemMoniker))
1007 return ItemMonikerCF_Create(iid, ppv);
1009 FIXME("\n\tCLSID:\t%s,\n\tIID:\t%s\n",debugstr_guid(rclsid),debugstr_guid(iid));
1010 return CLASS_E_CLASSNOTAVAILABLE;