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"
61 #include "wine/debug.h"
63 WINE_DEFAULT_DEBUG_CHANNEL(ole);
65 const CLSID CLSID_DfMarshal = { 0x0000030b, 0, 0, {0xc0, 0, 0, 0, 0, 0, 0, 0x46} };
66 const CLSID CLSID_PSFactoryBuffer = { 0x00000320, 0, 0, {0xc0, 0, 0, 0, 0, 0, 0, 0x46} };
68 /* From: http://msdn.microsoft.com/library/en-us/com/cmi_m_4lda.asp
70 * The first time a client requests a pointer to an interface on a
71 * particular object, COM loads an IClassFactory stub in the server
72 * process and uses it to marshal the first pointer back to the
73 * client. In the client process, COM loads the generic proxy for the
74 * class factory object and calls its implementation of IMarshal to
75 * unmarshal that first pointer. COM then creates the first interface
76 * proxy and hands it a pointer to the RPC channel. Finally, COM returns
77 * the IClassFactory pointer to the client, which uses it to call
78 * IClassFactory::CreateInstance, passing it a reference to the interface.
80 * Back in the server process, COM now creates a new instance of the
81 * object, along with a stub for the requested interface. This stub marshals
82 * the interface pointer back to the client process, where another object
83 * proxy is created, this time for the object itself. Also created is a
84 * proxy for the requested interface, a pointer to which is returned to
85 * the client. With subsequent calls to other interfaces on the object,
86 * COM will load the appropriate interface stubs and proxies as needed.
88 typedef struct _CFStub {
89 IRpcStubBufferVtbl *lpvtbl;
96 CFStub_QueryInterface(LPRPCSTUBBUFFER iface, REFIID riid, LPVOID *ppv) {
97 if (IsEqualIID(&IID_IUnknown,riid)||IsEqualIID(&IID_IRpcStubBuffer,riid)) {
99 IUnknown_AddRef(iface);
102 FIXME("(%s), interface not supported.\n",debugstr_guid(riid));
103 return E_NOINTERFACE;
107 CFStub_AddRef(LPRPCSTUBBUFFER iface) {
108 CFStub *This = (CFStub *)iface;
109 return InterlockedIncrement(&This->ref);
113 CFStub_Release(LPRPCSTUBBUFFER iface) {
114 CFStub *This = (CFStub *)iface;
117 ref = InterlockedDecrement(&This->ref);
118 if (!ref) HeapFree(GetProcessHeap(),0,This);
122 static HRESULT WINAPI
123 CFStub_Connect(LPRPCSTUBBUFFER iface, IUnknown *pUnkServer) {
124 CFStub *This = (CFStub *)iface;
126 This->pUnkServer = pUnkServer;
127 IUnknown_AddRef(pUnkServer);
132 CFStub_Disconnect(LPRPCSTUBBUFFER iface) {
133 CFStub *This = (CFStub *)iface;
135 IUnknown_Release(This->pUnkServer);
136 This->pUnkServer = NULL;
138 static HRESULT WINAPI
140 LPRPCSTUBBUFFER iface,RPCOLEMESSAGE* msg,IRpcChannelBuffer* chanbuf
142 CFStub *This = (CFStub *)iface;
145 if (msg->iMethod == 3) { /* CreateInstance */
147 IClassFactory *classfac;
151 ULARGE_INTEGER newpos;
152 LARGE_INTEGER seekto;
155 if (msg->cbBuffer < sizeof(IID)) {
156 FIXME("Not enough bytes in buffer (%ld instead of %d)?\n",msg->cbBuffer,sizeof(IID));
159 memcpy(&iid,msg->Buffer,sizeof(iid));
160 TRACE("->CreateInstance(%s)\n",debugstr_guid(&iid));
161 hres = IUnknown_QueryInterface(This->pUnkServer,&IID_IClassFactory,(LPVOID*)&classfac);
163 FIXME("Ole server does not provide a IClassFactory?\n");
166 hres = IClassFactory_CreateInstance(classfac,NULL,&iid,(LPVOID*)&ppv);
167 IClassFactory_Release(classfac);
170 FIXME("Failed to create an instance of %s\n",debugstr_guid(&iid));
173 hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
175 FIXME("Failed to create stream on hglobal\n");
178 hres = CoMarshalInterface(pStm,&iid,ppv,0,NULL,0);
179 IUnknown_Release((IUnknown*)ppv);
181 FIXME("CoMarshalInterface failed, %lx!\n",hres);
185 hres = IStream_Stat(pStm,&ststg,0);
187 FIXME("Stat failed.\n");
191 msg->cbBuffer = ststg.cbSize.u.LowPart;
193 I_RpcGetBuffer((RPC_MESSAGE *)msg);
194 if (hres) return hres;
196 seekto.u.LowPart = 0;seekto.u.HighPart = 0;
197 hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
199 FIXME("IStream_Seek failed, %lx\n",hres);
202 hres = IStream_Read(pStm,msg->Buffer,msg->cbBuffer,&res);
204 FIXME("Stream Read failed, %lx\n",hres);
207 IStream_Release(pStm);
210 FIXME("(%p,%p), stub!\n",msg,chanbuf);
211 FIXME("iMethod is %ld\n",msg->iMethod);
212 FIXME("cbBuffer is %ld\n",msg->cbBuffer);
216 static LPRPCSTUBBUFFER WINAPI
217 CFStub_IsIIDSupported(LPRPCSTUBBUFFER iface,REFIID riid) {
218 FIXME("(%s), stub!\n",debugstr_guid(riid));
223 CFStub_CountRefs(LPRPCSTUBBUFFER iface) {
224 FIXME("(), stub!\n");
228 static HRESULT WINAPI
229 CFStub_DebugServerQueryInterface(LPRPCSTUBBUFFER iface,void** ppv) {
230 FIXME("(%p), stub!\n",ppv);
234 CFStub_DebugServerRelease(LPRPCSTUBBUFFER iface,void *pv) {
235 FIXME("(%p), stub!\n",pv);
238 static IRpcStubBufferVtbl cfstubvt = {
239 CFStub_QueryInterface,
245 CFStub_IsIIDSupported,
247 CFStub_DebugServerQueryInterface,
248 CFStub_DebugServerRelease
252 CFStub_Construct(LPRPCSTUBBUFFER *ppv) {
254 cfstub = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(CFStub));
256 return E_OUTOFMEMORY;
257 *ppv = (LPRPCSTUBBUFFER)cfstub;
258 cfstub->lpvtbl = &cfstubvt;
263 /* Since we create proxy buffers and classfactory in a pair, there is
264 * no need for 2 separate structs. Just put them in one, but remember
267 typedef struct _CFProxy {
268 const IClassFactoryVtbl *lpvtbl_cf;
269 const IRpcProxyBufferVtbl *lpvtbl_proxy;
272 IRpcChannelBuffer *chanbuf;
273 IUnknown *outer_unknown;
276 static HRESULT WINAPI IRpcProxyBufferImpl_QueryInterface(LPRPCPROXYBUFFER iface,REFIID riid,LPVOID *ppv) {
278 if (IsEqualIID(riid,&IID_IRpcProxyBuffer)||IsEqualIID(riid,&IID_IUnknown)) {
279 IRpcProxyBuffer_AddRef(iface);
280 *ppv = (LPVOID)iface;
283 FIXME("(%s), no interface.\n",debugstr_guid(riid));
284 return E_NOINTERFACE;
287 static ULONG WINAPI IRpcProxyBufferImpl_AddRef(LPRPCPROXYBUFFER iface) {
288 ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
289 return InterlockedIncrement(&This->ref);
292 static ULONG WINAPI IRpcProxyBufferImpl_Release(LPRPCPROXYBUFFER iface) {
293 ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
294 ULONG ref = InterlockedDecrement(&This->ref);
297 IRpcChannelBuffer_Release(This->chanbuf);This->chanbuf = NULL;
298 HeapFree(GetProcessHeap(),0,This);
303 static HRESULT WINAPI IRpcProxyBufferImpl_Connect(LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer) {
304 ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
306 This->chanbuf = pRpcChannelBuffer;
307 IRpcChannelBuffer_AddRef(This->chanbuf);
310 static void WINAPI IRpcProxyBufferImpl_Disconnect(LPRPCPROXYBUFFER iface) {
311 ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
313 IRpcChannelBuffer_Release(This->chanbuf);
314 This->chanbuf = NULL;
318 static HRESULT WINAPI
319 CFProxy_QueryInterface(LPCLASSFACTORY iface,REFIID riid, LPVOID *ppv) {
320 ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
321 if (This->outer_unknown) return IUnknown_QueryInterface(This->outer_unknown, riid, ppv);
323 if (IsEqualIID(&IID_IClassFactory,riid) || IsEqualIID(&IID_IUnknown,riid)) {
324 *ppv = (LPVOID)iface;
325 IClassFactory_AddRef(iface);
328 if (IsEqualIID(riid,&IID_IMarshal)) /* just to avoid debug output */
329 return E_NOINTERFACE;
330 FIXME("Unhandled interface: %s\n",debugstr_guid(riid));
331 return E_NOINTERFACE;
334 static ULONG WINAPI CFProxy_AddRef(LPCLASSFACTORY iface) {
335 ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
336 if (This->outer_unknown) return IUnknown_AddRef(This->outer_unknown);
337 return InterlockedIncrement(&This->ref);
340 static ULONG WINAPI CFProxy_Release(LPCLASSFACTORY iface) {
342 ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
343 if (This->outer_unknown)
344 ref = IUnknown_Release(This->outer_unknown);
346 ref = InterlockedDecrement(&This->ref);
349 if (This->chanbuf) IRpcChannelBuffer_Release(This->chanbuf);
350 HeapFree(GetProcessHeap(),0,This);
355 static HRESULT WINAPI CFProxy_CreateInstance(
356 LPCLASSFACTORY iface,
357 LPUNKNOWN pUnkOuter,/* [in] */
358 REFIID riid, /* [in] */
359 LPVOID *ppv /* [out] */
361 ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
368 TRACE("(%p,%s,%p)\n",pUnkOuter,debugstr_guid(riid),ppv);
370 /* Send CreateInstance to the remote classfactory.
372 * Data: Only the 'IID'.
375 msg.cbBuffer = sizeof(*riid);
377 hres = IRpcChannelBuffer_GetBuffer(This->chanbuf,&msg,&IID_IClassFactory);
379 FIXME("IRpcChannelBuffer_GetBuffer failed with %lx?\n",hres);
382 memcpy(msg.Buffer,riid,sizeof(*riid));
383 hres = IRpcChannelBuffer_SendReceive(This->chanbuf,&msg,&srstatus);
385 FIXME("IRpcChannelBuffer_SendReceive failed with %lx?\n",hres);
389 if (!msg.cbBuffer) /* interface not found on remote */
392 /* We got back: [Marshalled Interface data] */
393 TRACE("got %ld bytes data.\n",msg.cbBuffer);
394 hGlobal = GlobalAlloc(GMEM_MOVEABLE|GMEM_NODISCARD|GMEM_SHARE,msg.cbBuffer);
395 memcpy(GlobalLock(hGlobal),msg.Buffer,msg.cbBuffer);
396 hres = CreateStreamOnHGlobal(hGlobal,TRUE,&pStream);
398 FIXME("CreateStreamOnHGlobal failed with %lx\n",hres);
401 hres = CoUnmarshalInterface(
406 IStream_Release(pStream); /* Does GlobalFree hGlobal too. */
408 FIXME("CoMarshalInterface failed, %lx\n",hres);
414 static HRESULT WINAPI CFProxy_LockServer(LPCLASSFACTORY iface,BOOL fLock) {
415 /*ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);*/
416 FIXME("(%d), stub!\n",fLock);
417 /* basically: write BOOL, read empty */
421 static IRpcProxyBufferVtbl pspbvtbl = {
422 IRpcProxyBufferImpl_QueryInterface,
423 IRpcProxyBufferImpl_AddRef,
424 IRpcProxyBufferImpl_Release,
425 IRpcProxyBufferImpl_Connect,
426 IRpcProxyBufferImpl_Disconnect
428 static IClassFactoryVtbl cfproxyvt = {
429 CFProxy_QueryInterface,
432 CFProxy_CreateInstance,
437 CFProxy_Construct(IUnknown *pUnkOuter, LPVOID *ppv,LPVOID *ppProxy) {
440 cf = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(CFProxy));
442 return E_OUTOFMEMORY;
444 cf->lpvtbl_cf = &cfproxyvt;
445 cf->lpvtbl_proxy = &pspbvtbl;
446 /* only one reference for the proxy buffer */
448 cf->outer_unknown = pUnkOuter;
449 *ppv = &(cf->lpvtbl_cf);
450 *ppProxy = &(cf->lpvtbl_proxy);
455 /********************* IRemUnknown Proxy/Stub ********************************/
459 const IRpcStubBufferVtbl *lpVtbl;
464 static HRESULT WINAPI RemUnkStub_QueryInterface(LPRPCSTUBBUFFER iface,
468 RemUnkStub *This = (RemUnkStub *)iface;
469 TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(riid),obj);
470 if (IsEqualGUID(&IID_IUnknown,riid) ||
471 IsEqualGUID(&IID_IRpcStubBuffer,riid)) {
475 return E_NOINTERFACE;
478 static ULONG WINAPI RemUnkStub_AddRef(LPRPCSTUBBUFFER iface)
480 RemUnkStub *This = (RemUnkStub *)iface;
481 TRACE("(%p)->AddRef()\n",This);
482 return InterlockedIncrement(&This->refs);
485 static ULONG WINAPI RemUnkStub_Release(LPRPCSTUBBUFFER iface)
487 RemUnkStub *This = (RemUnkStub *)iface;
489 TRACE("(%p)->Release()\n",This);
490 refs = InterlockedDecrement(&This->refs);
492 HeapFree(GetProcessHeap(), 0, This);
496 static HRESULT WINAPI RemUnkStub_Connect(LPRPCSTUBBUFFER iface,
497 LPUNKNOWN lpUnkServer)
499 RemUnkStub *This = (RemUnkStub *)iface;
500 TRACE("(%p)->Connect(%p)\n",This,lpUnkServer);
501 This->iface = (IRemUnknown*)lpUnkServer;
502 IRemUnknown_AddRef(This->iface);
506 static void WINAPI RemUnkStub_Disconnect(LPRPCSTUBBUFFER iface)
508 RemUnkStub *This = (RemUnkStub *)iface;
509 TRACE("(%p)->Disconnect()\n",This);
510 IUnknown_Release(This->iface);
514 static HRESULT WINAPI RemUnkStub_Invoke(LPRPCSTUBBUFFER iface,
516 LPRPCCHANNELBUFFER pChannel)
518 RemUnkStub *This = (RemUnkStub *)iface;
519 ULONG iMethod = pMsg->iMethod;
520 LPBYTE buf = pMsg->Buffer;
521 HRESULT hr = RPC_E_INVALIDMETHOD;
523 TRACE("(%p)->Invoke(%p,%p) method %ld\n", This, pMsg, pChannel, iMethod);
526 case 3: /* RemQueryInterface */
532 REMQIRESULT *pQIResults = NULL;
535 memcpy(&ipid, buf, sizeof(ipid));
537 memcpy(&cRefs, buf, sizeof(cRefs));
538 buf += sizeof(cRefs);
539 memcpy(&cIids, buf, sizeof(cIids));
540 buf += sizeof(cIids);
543 hr = IRemUnknown_RemQueryInterface(This->iface, &ipid, cRefs, cIids, iids, &pQIResults);
546 pMsg->cbBuffer = cIids * sizeof(REMQIRESULT);
548 I_RpcGetBuffer((RPC_MESSAGE *)pMsg);
552 /* FIXME: pQIResults is a unique pointer so pQIResults can be NULL! */
553 memcpy(buf, pQIResults, cIids * sizeof(REMQIRESULT));
557 case 4: /* RemAddRef */
564 memcpy(&cIids, buf, sizeof(USHORT));
565 buf += sizeof(USHORT);
566 ir = (REMINTERFACEREF*)buf;
567 pResults = CoTaskMemAlloc(cIids * sizeof(HRESULT));
568 if (!pResults) return E_OUTOFMEMORY;
570 hr = IRemUnknown_RemAddRef(This->iface, cIids, ir, pResults);
573 pMsg->cbBuffer = cIids * sizeof(HRESULT);
575 I_RpcGetBuffer((RPC_MESSAGE *)pMsg);
579 memcpy(buf, pResults, cIids * sizeof(HRESULT));
582 CoTaskMemFree(pResults);
586 case 5: /* RemRelease */
592 memcpy(&cIids, buf, sizeof(USHORT));
593 buf += sizeof(USHORT);
594 ir = (REMINTERFACEREF*)buf;
596 hr = IRemUnknown_RemRelease(This->iface, cIids, ir);
606 static LPRPCSTUBBUFFER WINAPI RemUnkStub_IsIIDSupported(LPRPCSTUBBUFFER iface,
609 RemUnkStub *This = (RemUnkStub *)iface;
610 TRACE("(%p)->IsIIDSupported(%s)\n", This, debugstr_guid(riid));
611 return IsEqualGUID(&IID_IRemUnknown, riid) ? iface : NULL;
614 static ULONG WINAPI RemUnkStub_CountRefs(LPRPCSTUBBUFFER iface)
616 RemUnkStub *This = (RemUnkStub *)iface;
617 FIXME("(%p)->CountRefs()\n", This);
621 static HRESULT WINAPI RemUnkStub_DebugServerQueryInterface(LPRPCSTUBBUFFER iface,
624 RemUnkStub *This = (RemUnkStub *)iface;
625 FIXME("(%p)->DebugServerQueryInterface(%p)\n",This,ppv);
626 return E_NOINTERFACE;
629 static void WINAPI RemUnkStub_DebugServerRelease(LPRPCSTUBBUFFER iface,
632 RemUnkStub *This = (RemUnkStub *)iface;
633 FIXME("(%p)->DebugServerRelease(%p)\n", This, pv);
636 static const IRpcStubBufferVtbl RemUnkStub_VTable =
638 RemUnkStub_QueryInterface,
642 RemUnkStub_Disconnect,
644 RemUnkStub_IsIIDSupported,
645 RemUnkStub_CountRefs,
646 RemUnkStub_DebugServerQueryInterface,
647 RemUnkStub_DebugServerRelease
650 static HRESULT RemUnkStub_Construct(IRpcStubBuffer **ppStub)
652 RemUnkStub *This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
653 if (!This) return E_OUTOFMEMORY;
654 This->lpVtbl = &RemUnkStub_VTable;
657 *ppStub = (IRpcStubBuffer*)This;
662 typedef struct _RemUnkProxy {
663 const IRemUnknownVtbl *lpvtbl_remunk;
664 const IRpcProxyBufferVtbl *lpvtbl_proxy;
667 IRpcChannelBuffer *chan;
668 IUnknown *outer_unknown;
671 static HRESULT WINAPI RemUnkProxy_QueryInterface(LPREMUNKNOWN iface, REFIID riid, void **ppv)
673 RemUnkProxy *This = (RemUnkProxy *)iface;
674 if (This->outer_unknown)
675 return IUnknown_QueryInterface(This->outer_unknown, riid, ppv);
676 if (IsEqualIID(riid, &IID_IUnknown) ||
677 IsEqualIID(riid, &IID_IRemUnknown))
679 IRemUnknown_AddRef(iface);
680 *ppv = (LPVOID)iface;
683 return E_NOINTERFACE;
686 static ULONG WINAPI RemUnkProxy_AddRef(LPREMUNKNOWN iface)
688 RemUnkProxy *This = (RemUnkProxy *)iface;
690 TRACE("(%p)->AddRef()\n",This);
691 return InterlockedIncrement(&This->refs);
694 static ULONG WINAPI RemUnkProxy_Release(LPREMUNKNOWN iface)
696 RemUnkProxy *This = (RemUnkProxy *)iface;
699 TRACE("(%p)->Release()\n",This);
700 if (This->outer_unknown)
701 refs = IUnknown_Release(This->outer_unknown);
703 refs = InterlockedDecrement(&This->refs);
706 if (This->chan) IRpcChannelBuffer_Release(This->chan);
707 HeapFree(GetProcessHeap(),0,This);
712 static HRESULT WINAPI RemUnkProxy_RemQueryInterface(LPREMUNKNOWN iface,
717 REMQIRESULT** ppQIResults)
719 RemUnkProxy *This = (RemUnkProxy *)iface;
724 TRACE("(%p)->(%s,%ld,%d,%p,%p)\n",This,
725 debugstr_guid(ripid),cRefs,cIids,iids,ppQIResults);
728 memset(&msg, 0, sizeof(msg));
730 msg.cbBuffer = sizeof(IPID) + sizeof(ULONG) +
731 sizeof(USHORT) + cIids*sizeof(IID);
732 hr = IRpcChannelBuffer_GetBuffer(This->chan, &msg, &IID_IRemUnknown);
734 LPBYTE buf = msg.Buffer;
735 memcpy(buf, ripid, sizeof(IPID));
737 memcpy(buf, &cRefs, sizeof(ULONG));
738 buf += sizeof(ULONG);
739 memcpy(buf, &cIids, sizeof(USHORT));
740 buf += sizeof(USHORT);
741 memcpy(buf, iids, cIids*sizeof(IID));
743 hr = IRpcChannelBuffer_SendReceive(This->chan, &msg, &status);
747 *ppQIResults = CoTaskMemAlloc(cIids*sizeof(REMQIRESULT));
748 memcpy(*ppQIResults, buf, cIids*sizeof(REMQIRESULT));
751 IRpcChannelBuffer_FreeBuffer(This->chan, &msg);
757 static HRESULT WINAPI RemUnkProxy_RemAddRef(LPREMUNKNOWN iface,
758 USHORT cInterfaceRefs,
759 REMINTERFACEREF* InterfaceRefs,
762 RemUnkProxy *This = (RemUnkProxy *)iface;
767 TRACE("(%p)->(%d,%p,%p)\n",This,
768 cInterfaceRefs,InterfaceRefs,pResults);
770 memset(&msg, 0, sizeof(msg));
772 msg.cbBuffer = sizeof(USHORT) + cInterfaceRefs*sizeof(REMINTERFACEREF);
773 hr = IRpcChannelBuffer_GetBuffer(This->chan, &msg, &IID_IRemUnknown);
775 LPBYTE buf = msg.Buffer;
776 memcpy(buf, &cInterfaceRefs, sizeof(USHORT));
777 buf += sizeof(USHORT);
778 memcpy(buf, InterfaceRefs, cInterfaceRefs*sizeof(REMINTERFACEREF));
780 hr = IRpcChannelBuffer_SendReceive(This->chan, &msg, &status);
784 memcpy(pResults, buf, cInterfaceRefs*sizeof(HRESULT));
787 IRpcChannelBuffer_FreeBuffer(This->chan, &msg);
793 static HRESULT WINAPI RemUnkProxy_RemRelease(LPREMUNKNOWN iface,
794 USHORT cInterfaceRefs,
795 REMINTERFACEREF* InterfaceRefs)
797 RemUnkProxy *This = (RemUnkProxy *)iface;
802 TRACE("(%p)->(%d,%p)\n",This,
803 cInterfaceRefs,InterfaceRefs);
805 memset(&msg, 0, sizeof(msg));
807 msg.cbBuffer = sizeof(USHORT) + cInterfaceRefs*sizeof(REMINTERFACEREF);
808 hr = IRpcChannelBuffer_GetBuffer(This->chan, &msg, &IID_IRemUnknown);
810 LPBYTE buf = msg.Buffer;
811 memcpy(buf, &cInterfaceRefs, sizeof(USHORT));
812 buf += sizeof(USHORT);
813 memcpy(buf, InterfaceRefs, cInterfaceRefs*sizeof(REMINTERFACEREF));
815 hr = IRpcChannelBuffer_SendReceive(This->chan, &msg, &status);
817 IRpcChannelBuffer_FreeBuffer(This->chan, &msg);
823 static const IRemUnknownVtbl RemUnkProxy_VTable =
825 RemUnkProxy_QueryInterface,
828 RemUnkProxy_RemQueryInterface,
829 RemUnkProxy_RemAddRef,
830 RemUnkProxy_RemRelease
834 static HRESULT WINAPI RURpcProxyBufferImpl_QueryInterface(LPRPCPROXYBUFFER iface,REFIID riid,LPVOID *ppv) {
836 if (IsEqualIID(riid,&IID_IRpcProxyBuffer)||IsEqualIID(riid,&IID_IUnknown)) {
837 IRpcProxyBuffer_AddRef(iface);
838 *ppv = (LPVOID)iface;
841 FIXME("(%s), no interface.\n",debugstr_guid(riid));
842 return E_NOINTERFACE;
845 static ULONG WINAPI RURpcProxyBufferImpl_AddRef(LPRPCPROXYBUFFER iface) {
846 ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
847 return InterlockedIncrement(&This->refs);
850 static ULONG WINAPI RURpcProxyBufferImpl_Release(LPRPCPROXYBUFFER iface) {
851 ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
852 ULONG ref = InterlockedDecrement(&This->refs);
855 IRpcChannelBuffer_Release(This->chan);This->chan = NULL;
856 HeapFree(GetProcessHeap(),0,This);
861 static HRESULT WINAPI RURpcProxyBufferImpl_Connect(LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer) {
862 ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
864 This->chan = pRpcChannelBuffer;
865 IRpcChannelBuffer_AddRef(This->chan);
868 static void WINAPI RURpcProxyBufferImpl_Disconnect(LPRPCPROXYBUFFER iface) {
869 ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
871 IRpcChannelBuffer_Release(This->chan);
877 static const IRpcProxyBufferVtbl RURpcProxyBuffer_VTable = {
878 RURpcProxyBufferImpl_QueryInterface,
879 RURpcProxyBufferImpl_AddRef,
880 RURpcProxyBufferImpl_Release,
881 RURpcProxyBufferImpl_Connect,
882 RURpcProxyBufferImpl_Disconnect
886 RemUnkProxy_Construct(IUnknown *pUnkOuter, LPVOID *ppv,LPVOID *ppProxy) {
889 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*This));
891 return E_OUTOFMEMORY;
893 This->lpvtbl_remunk = &RemUnkProxy_VTable;
894 This->lpvtbl_proxy = &RURpcProxyBuffer_VTable;
895 /* only one reference for the proxy buffer */
897 This->outer_unknown = pUnkOuter;
898 *ppv = &(This->lpvtbl_remunk);
899 *ppProxy = &(This->lpvtbl_proxy);
904 /********************* OLE Proxy/Stub Factory ********************************/
905 static HRESULT WINAPI
906 PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface, REFIID iid, LPVOID *ppv) {
907 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)||IsEqualIID(iid,&IID_IUnknown)) {
908 *ppv = (LPVOID)iface;
909 /* No ref counting, static class */
912 FIXME("(%s) unknown IID?\n",debugstr_guid(iid));
913 return E_NOINTERFACE;
916 static ULONG WINAPI PSFacBuf_AddRef(LPPSFACTORYBUFFER iface) { return 2; }
917 static ULONG WINAPI PSFacBuf_Release(LPPSFACTORYBUFFER iface) { return 1; }
919 static HRESULT WINAPI
920 PSFacBuf_CreateProxy(
921 LPPSFACTORYBUFFER iface, IUnknown* pUnkOuter, REFIID riid,
922 IRpcProxyBuffer **ppProxy, LPVOID *ppv
924 if (IsEqualIID(&IID_IClassFactory,riid))
925 return CFProxy_Construct(pUnkOuter, ppv,(LPVOID*)ppProxy);
926 else if (IsEqualIID(&IID_IRemUnknown,riid))
927 return RemUnkProxy_Construct(pUnkOuter, ppv,(LPVOID*)ppProxy);
928 FIXME("proxying not implemented for (%s) yet!\n",debugstr_guid(riid));
932 static HRESULT WINAPI
934 LPPSFACTORYBUFFER iface, REFIID riid,IUnknown *pUnkServer,
935 IRpcStubBuffer** ppStub
939 TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub);
941 if (IsEqualIID(&IID_IClassFactory, riid) ||
942 IsEqualIID(&IID_IUnknown, riid) /* FIXME: fixup stub manager and remove this*/) {
943 hres = CFStub_Construct(ppStub);
945 IRpcStubBuffer_Connect((*ppStub),pUnkServer);
947 } else if (IsEqualIID(&IID_IRemUnknown,riid)) {
948 hres = RemUnkStub_Construct(ppStub);
950 IRpcStubBuffer_Connect((*ppStub),pUnkServer);
953 FIXME("stubbing not implemented for (%s) yet!\n",debugstr_guid(riid));
957 static IPSFactoryBufferVtbl psfacbufvtbl = {
958 PSFacBuf_QueryInterface,
961 PSFacBuf_CreateProxy,
965 /* This is the whole PSFactoryBuffer object, just the vtableptr */
966 static IPSFactoryBufferVtbl *lppsfac = &psfacbufvtbl;
968 /***********************************************************************
969 * DllGetClassObject [OLE32.@]
971 HRESULT WINAPI OLE32_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
974 if (IsEqualIID(rclsid,&CLSID_PSFactoryBuffer)) {
978 if (IsEqualIID(rclsid,&CLSID_DfMarshal)&&(
979 IsEqualIID(iid,&IID_IClassFactory) ||
980 IsEqualIID(iid,&IID_IUnknown)
983 return MARSHAL_GetStandardMarshalCF(ppv);
984 if (IsEqualIID(rclsid,&CLSID_StdGlobalInterfaceTable) && (IsEqualIID(iid,&IID_IClassFactory) || IsEqualIID(iid,&IID_IUnknown)))
985 return StdGlobalInterfaceTable_GetFactory(ppv);
987 FIXME("\n\tCLSID:\t%s,\n\tIID:\t%s\n",debugstr_guid(rclsid),debugstr_guid(iid));
988 return CLASS_E_CLASSNOTAVAILABLE;