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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #define NONAMELESSUNION
31 #define NONAMELESSSTRUCT
42 #include "compobj_private.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(ole);
49 static ULONG WINAPI RURpcProxyBufferImpl_Release(LPRPCPROXYBUFFER iface);
53 * The first time a client requests a pointer to an interface on a
54 * particular object, COM loads an IClassFactory stub in the server
55 * process and uses it to marshal the first pointer back to the
56 * client. In the client process, COM loads the generic proxy for the
57 * class factory object and calls its implementation of IMarshal to
58 * unmarshal that first pointer. COM then creates the first interface
59 * proxy and hands it a pointer to the RPC channel. Finally, COM returns
60 * the IClassFactory pointer to the client, which uses it to call
61 * IClassFactory::CreateInstance, passing it a reference to the interface.
63 * Back in the server process, COM now creates a new instance of the
64 * object, along with a stub for the requested interface. This stub marshals
65 * the interface pointer back to the client process, where another object
66 * proxy is created, this time for the object itself. Also created is a
67 * proxy for the requested interface, a pointer to which is returned to
68 * the client. With subsequent calls to other interfaces on the object,
69 * COM will load the appropriate interface stubs and proxies as needed.
71 typedef struct _CFStub {
72 const IRpcStubBufferVtbl *lpvtbl;
79 CFStub_QueryInterface(LPRPCSTUBBUFFER iface, REFIID riid, LPVOID *ppv) {
80 if (IsEqualIID(&IID_IUnknown,riid)||IsEqualIID(&IID_IRpcStubBuffer,riid)) {
82 IUnknown_AddRef(iface);
85 FIXME("(%s), interface not supported.\n",debugstr_guid(riid));
90 CFStub_AddRef(LPRPCSTUBBUFFER iface) {
91 CFStub *This = (CFStub *)iface;
92 return InterlockedIncrement(&This->ref);
96 CFStub_Release(LPRPCSTUBBUFFER iface) {
97 CFStub *This = (CFStub *)iface;
100 ref = InterlockedDecrement(&This->ref);
102 IRpcStubBuffer_Disconnect(iface);
103 HeapFree(GetProcessHeap(),0,This);
108 static HRESULT WINAPI
109 CFStub_Connect(LPRPCSTUBBUFFER iface, IUnknown *pUnkServer) {
110 CFStub *This = (CFStub *)iface;
112 This->pUnkServer = pUnkServer;
113 IUnknown_AddRef(pUnkServer);
118 CFStub_Disconnect(LPRPCSTUBBUFFER iface) {
119 CFStub *This = (CFStub *)iface;
121 if (This->pUnkServer) {
122 IUnknown_Release(This->pUnkServer);
123 This->pUnkServer = NULL;
127 static HRESULT WINAPI
129 LPRPCSTUBBUFFER iface,RPCOLEMESSAGE* msg,IRpcChannelBuffer* chanbuf
131 CFStub *This = (CFStub *)iface;
134 if (msg->iMethod == 3) { /* CreateInstance */
136 IClassFactory *classfac;
140 ULARGE_INTEGER newpos;
141 LARGE_INTEGER seekto;
144 if (msg->cbBuffer < sizeof(IID)) {
145 FIXME("Not enough bytes in buffer (%d)?\n",msg->cbBuffer);
148 memcpy(&iid,msg->Buffer,sizeof(iid));
149 TRACE("->CreateInstance(%s)\n",debugstr_guid(&iid));
150 hres = IUnknown_QueryInterface(This->pUnkServer,&IID_IClassFactory,(LPVOID*)&classfac);
152 FIXME("Ole server does not provide an IClassFactory?\n");
155 hres = IClassFactory_CreateInstance(classfac,NULL,&iid,(LPVOID*)&ppv);
156 IClassFactory_Release(classfac);
159 FIXME("Failed to create an instance of %s\n",debugstr_guid(&iid));
162 hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
164 FIXME("Failed to create stream on hglobal\n");
167 hres = IStream_Write(pStm, &ppv, sizeof(ppv), NULL);
169 ERR("IStream_Write failed, 0x%08x\n", hres);
173 hres = CoMarshalInterface(pStm,&iid,ppv,0,NULL,0);
174 IUnknown_Release(ppv);
176 FIXME("CoMarshalInterface failed, %x!\n",hres);
180 hres = IStream_Stat(pStm,&ststg,0);
182 FIXME("Stat failed.\n");
186 msg->cbBuffer = ststg.cbSize.u.LowPart;
189 IRpcChannelBuffer_GetBuffer(chanbuf, msg, &IID_IClassFactory);
190 if (hres) return hres;
192 seekto.u.LowPart = 0;seekto.u.HighPart = 0;
193 hres = IStream_Seek(pStm,seekto,STREAM_SEEK_SET,&newpos);
195 FIXME("IStream_Seek failed, %x\n",hres);
198 hres = IStream_Read(pStm,msg->Buffer,msg->cbBuffer,&res);
200 FIXME("Stream Read failed, %x\n",hres);
203 IStream_Release(pStm);
206 FIXME("(%p,%p), stub!\n",msg,chanbuf);
207 FIXME("iMethod is %d\n",msg->iMethod);
208 FIXME("cbBuffer is %d\n",msg->cbBuffer);
212 static LPRPCSTUBBUFFER WINAPI
213 CFStub_IsIIDSupported(LPRPCSTUBBUFFER iface,REFIID riid) {
214 FIXME("(%s), stub!\n",debugstr_guid(riid));
219 CFStub_CountRefs(LPRPCSTUBBUFFER iface) {
220 FIXME("(), stub!\n");
224 static HRESULT WINAPI
225 CFStub_DebugServerQueryInterface(LPRPCSTUBBUFFER iface,void** ppv) {
226 FIXME("(%p), stub!\n",ppv);
230 CFStub_DebugServerRelease(LPRPCSTUBBUFFER iface,void *pv) {
231 FIXME("(%p), stub!\n",pv);
234 static const IRpcStubBufferVtbl cfstubvt = {
235 CFStub_QueryInterface,
241 CFStub_IsIIDSupported,
243 CFStub_DebugServerQueryInterface,
244 CFStub_DebugServerRelease
248 CFStub_Construct(LPRPCSTUBBUFFER *ppv) {
250 cfstub = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(CFStub));
252 return E_OUTOFMEMORY;
253 *ppv = (LPRPCSTUBBUFFER)cfstub;
254 cfstub->lpvtbl = &cfstubvt;
259 /* Since we create proxy buffers and classfactory in a pair, there is
260 * no need for 2 separate structs. Just put them in one, but remember
263 typedef struct _CFProxy {
264 const IClassFactoryVtbl *lpvtbl_cf;
265 const IRpcProxyBufferVtbl *lpvtbl_proxy;
268 IRpcChannelBuffer *chanbuf;
269 IUnknown *outer_unknown;
272 static HRESULT WINAPI IRpcProxyBufferImpl_QueryInterface(LPRPCPROXYBUFFER iface,REFIID riid,LPVOID *ppv) {
274 if (IsEqualIID(riid,&IID_IRpcProxyBuffer)||IsEqualIID(riid,&IID_IUnknown)) {
275 IRpcProxyBuffer_AddRef(iface);
276 *ppv = (LPVOID)iface;
279 FIXME("(%s), no interface.\n",debugstr_guid(riid));
280 return E_NOINTERFACE;
283 static ULONG WINAPI IRpcProxyBufferImpl_AddRef(LPRPCPROXYBUFFER iface) {
284 ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
285 return InterlockedIncrement(&This->ref);
288 static ULONG WINAPI IRpcProxyBufferImpl_Release(LPRPCPROXYBUFFER iface) {
289 ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
290 ULONG ref = InterlockedDecrement(&This->ref);
293 IRpcProxyBuffer_Disconnect(iface);
294 HeapFree(GetProcessHeap(),0,This);
299 static HRESULT WINAPI IRpcProxyBufferImpl_Connect(LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer) {
300 ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
302 This->chanbuf = pRpcChannelBuffer;
303 IRpcChannelBuffer_AddRef(This->chanbuf);
306 static void WINAPI IRpcProxyBufferImpl_Disconnect(LPRPCPROXYBUFFER iface) {
307 ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
309 IRpcChannelBuffer_Release(This->chanbuf);
310 This->chanbuf = NULL;
314 static HRESULT WINAPI
315 CFProxy_QueryInterface(LPCLASSFACTORY iface,REFIID riid, LPVOID *ppv) {
316 ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
317 if (This->outer_unknown) return IUnknown_QueryInterface(This->outer_unknown, riid, ppv);
319 if (IsEqualIID(&IID_IClassFactory,riid) || IsEqualIID(&IID_IUnknown,riid)) {
320 *ppv = (LPVOID)iface;
321 IClassFactory_AddRef(iface);
324 if (IsEqualIID(riid,&IID_IMarshal)) /* just to avoid debug output */
325 return E_NOINTERFACE;
326 FIXME("Unhandled interface: %s\n",debugstr_guid(riid));
327 return E_NOINTERFACE;
330 static ULONG WINAPI CFProxy_AddRef(LPCLASSFACTORY iface) {
331 ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
332 if (This->outer_unknown) return IUnknown_AddRef(This->outer_unknown);
333 return InterlockedIncrement(&This->ref);
336 static ULONG WINAPI CFProxy_Release(LPCLASSFACTORY iface) {
337 ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
338 if (This->outer_unknown)
339 return IUnknown_Release(This->outer_unknown);
341 return IRpcProxyBufferImpl_Release((IRpcProxyBuffer *)&This->lpvtbl_proxy);
344 static HRESULT WINAPI CFProxy_CreateInstance(
345 LPCLASSFACTORY iface,
346 LPUNKNOWN pUnkOuter,/* [in] */
347 REFIID riid, /* [in] */
348 LPVOID *ppv /* [out] */
350 ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
357 TRACE("(%p,%s,%p)\n",pUnkOuter,debugstr_guid(riid),ppv);
359 /* Send CreateInstance to the remote classfactory.
361 * Data: Only the 'IID'.
363 memset(&msg, 0, sizeof(msg));
365 msg.cbBuffer = sizeof(*riid);
366 hres = IRpcChannelBuffer_GetBuffer(This->chanbuf,&msg,&IID_IClassFactory);
368 FIXME("IRpcChannelBuffer_GetBuffer failed with %x?\n",hres);
371 memcpy(msg.Buffer,riid,sizeof(*riid));
372 hres = IRpcChannelBuffer_SendReceive(This->chanbuf,&msg,&srstatus);
374 FIXME("IRpcChannelBuffer_SendReceive failed with %x?\n",hres);
375 IRpcChannelBuffer_FreeBuffer(This->chanbuf,&msg);
379 if (!msg.cbBuffer) { /* interface not found on remote */
380 IRpcChannelBuffer_FreeBuffer(This->chanbuf,&msg);
384 /* We got back: [Marshalled Interface data] */
385 TRACE("got %d bytes data.\n",msg.cbBuffer);
386 hGlobal = GlobalAlloc(GMEM_MOVEABLE|GMEM_NODISCARD|GMEM_SHARE,msg.cbBuffer);
387 memcpy(GlobalLock(hGlobal),msg.Buffer,msg.cbBuffer);
388 hres = CreateStreamOnHGlobal(hGlobal,TRUE,&pStream);
390 FIXME("CreateStreamOnHGlobal failed with %x\n",hres);
391 IRpcChannelBuffer_FreeBuffer(This->chanbuf,&msg);
395 hres = IStream_Read(pStream, ppv, sizeof(*ppv), NULL);
399 hres = CoUnmarshalInterface(
405 IStream_Release(pStream); /* Does GlobalFree hGlobal too. */
407 IRpcChannelBuffer_FreeBuffer(This->chanbuf,&msg);
410 FIXME("CoMarshalInterface failed, %x\n",hres);
416 static HRESULT WINAPI CFProxy_LockServer(LPCLASSFACTORY iface,BOOL fLock) {
417 /*ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);*/
418 FIXME("(%d), stub!\n",fLock);
419 /* basically: write BOOL, read empty */
423 static const IRpcProxyBufferVtbl pspbvtbl = {
424 IRpcProxyBufferImpl_QueryInterface,
425 IRpcProxyBufferImpl_AddRef,
426 IRpcProxyBufferImpl_Release,
427 IRpcProxyBufferImpl_Connect,
428 IRpcProxyBufferImpl_Disconnect
430 static const IClassFactoryVtbl cfproxyvt = {
431 CFProxy_QueryInterface,
434 CFProxy_CreateInstance,
439 CFProxy_Construct(IUnknown *pUnkOuter, LPVOID *ppv,LPVOID *ppProxy) {
442 cf = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(CFProxy));
444 return E_OUTOFMEMORY;
446 cf->lpvtbl_cf = &cfproxyvt;
447 cf->lpvtbl_proxy = &pspbvtbl;
448 /* one reference for the proxy buffer */
450 cf->outer_unknown = pUnkOuter;
451 *ppv = &(cf->lpvtbl_cf);
452 *ppProxy = &(cf->lpvtbl_proxy);
453 /* and one reference for the object */
454 IUnknown_AddRef((IUnknown *)*ppv);
459 /********************* IRemUnknown Proxy/Stub ********************************/
463 const IRpcStubBufferVtbl *lpVtbl;
468 static HRESULT WINAPI RemUnkStub_QueryInterface(LPRPCSTUBBUFFER iface,
472 RemUnkStub *This = (RemUnkStub *)iface;
473 TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(riid),obj);
474 if (IsEqualGUID(&IID_IUnknown,riid) ||
475 IsEqualGUID(&IID_IRpcStubBuffer,riid)) {
479 return E_NOINTERFACE;
482 static ULONG WINAPI RemUnkStub_AddRef(LPRPCSTUBBUFFER iface)
484 RemUnkStub *This = (RemUnkStub *)iface;
485 TRACE("(%p)->AddRef()\n",This);
486 return InterlockedIncrement(&This->refs);
489 static ULONG WINAPI RemUnkStub_Release(LPRPCSTUBBUFFER iface)
491 RemUnkStub *This = (RemUnkStub *)iface;
493 TRACE("(%p)->Release()\n",This);
494 refs = InterlockedDecrement(&This->refs);
497 IRpcStubBuffer_Disconnect(iface);
498 HeapFree(GetProcessHeap(), 0, This);
503 static HRESULT WINAPI RemUnkStub_Connect(LPRPCSTUBBUFFER iface,
504 LPUNKNOWN lpUnkServer)
506 RemUnkStub *This = (RemUnkStub *)iface;
507 TRACE("(%p)->Connect(%p)\n",This,lpUnkServer);
508 This->iface = (IRemUnknown*)lpUnkServer;
509 IRemUnknown_AddRef(This->iface);
513 static void WINAPI RemUnkStub_Disconnect(LPRPCSTUBBUFFER iface)
515 RemUnkStub *This = (RemUnkStub *)iface;
516 TRACE("(%p)->Disconnect()\n",This);
517 IUnknown_Release(This->iface);
521 static HRESULT WINAPI RemUnkStub_Invoke(LPRPCSTUBBUFFER iface,
523 LPRPCCHANNELBUFFER pChannel)
525 RemUnkStub *This = (RemUnkStub *)iface;
526 ULONG iMethod = pMsg->iMethod;
527 LPBYTE buf = pMsg->Buffer;
528 HRESULT hr = RPC_E_INVALIDMETHOD;
530 TRACE("(%p)->Invoke(%p,%p) method %d\n", This, pMsg, pChannel, iMethod);
533 case 3: /* RemQueryInterface */
539 REMQIRESULT *pQIResults = NULL;
542 memcpy(&ipid, buf, sizeof(ipid));
544 memcpy(&cRefs, buf, sizeof(cRefs));
545 buf += sizeof(cRefs);
546 memcpy(&cIids, buf, sizeof(cIids));
547 buf += sizeof(cIids);
550 hr = IRemUnknown_RemQueryInterface(This->iface, &ipid, cRefs, cIids, iids, &pQIResults);
553 pMsg->cbBuffer = cIids * sizeof(REMQIRESULT) + sizeof(HRESULT);
555 IRpcChannelBuffer_GetBuffer(pChannel, pMsg, &IID_IRemUnknown);
558 *(HRESULT *)buf = hr;
559 buf += sizeof(HRESULT);
562 /* FIXME: pQIResults is a unique pointer so pQIResults can be NULL! */
563 memcpy(buf, pQIResults, cIids * sizeof(REMQIRESULT));
565 CoTaskMemFree(pQIResults);
569 case 4: /* RemAddRef */
576 memcpy(&cIids, buf, sizeof(USHORT));
577 buf += sizeof(USHORT);
578 ir = (REMINTERFACEREF*)buf;
579 pResults = CoTaskMemAlloc(cIids * sizeof(HRESULT));
580 if (!pResults) return E_OUTOFMEMORY;
582 hr = IRemUnknown_RemAddRef(This->iface, cIids, ir, pResults);
585 pMsg->cbBuffer = cIids * sizeof(HRESULT);
587 IRpcChannelBuffer_GetBuffer(pChannel, pMsg, &IID_IRemUnknown);
591 memcpy(buf, pResults, cIids * sizeof(HRESULT));
594 CoTaskMemFree(pResults);
598 case 5: /* RemRelease */
604 memcpy(&cIids, buf, sizeof(USHORT));
605 buf += sizeof(USHORT);
606 ir = (REMINTERFACEREF*)buf;
608 hr = IRemUnknown_RemRelease(This->iface, cIids, ir);
612 IRpcChannelBuffer_GetBuffer(pChannel, pMsg, &IID_IRemUnknown);
619 static LPRPCSTUBBUFFER WINAPI RemUnkStub_IsIIDSupported(LPRPCSTUBBUFFER iface,
622 RemUnkStub *This = (RemUnkStub *)iface;
623 TRACE("(%p)->IsIIDSupported(%s)\n", This, debugstr_guid(riid));
624 return IsEqualGUID(&IID_IRemUnknown, riid) ? iface : NULL;
627 static ULONG WINAPI RemUnkStub_CountRefs(LPRPCSTUBBUFFER iface)
629 RemUnkStub *This = (RemUnkStub *)iface;
630 FIXME("(%p)->CountRefs()\n", This);
634 static HRESULT WINAPI RemUnkStub_DebugServerQueryInterface(LPRPCSTUBBUFFER iface,
637 RemUnkStub *This = (RemUnkStub *)iface;
638 FIXME("(%p)->DebugServerQueryInterface(%p)\n",This,ppv);
639 return E_NOINTERFACE;
642 static void WINAPI RemUnkStub_DebugServerRelease(LPRPCSTUBBUFFER iface,
645 RemUnkStub *This = (RemUnkStub *)iface;
646 FIXME("(%p)->DebugServerRelease(%p)\n", This, pv);
649 static const IRpcStubBufferVtbl RemUnkStub_VTable =
651 RemUnkStub_QueryInterface,
655 RemUnkStub_Disconnect,
657 RemUnkStub_IsIIDSupported,
658 RemUnkStub_CountRefs,
659 RemUnkStub_DebugServerQueryInterface,
660 RemUnkStub_DebugServerRelease
663 static HRESULT RemUnkStub_Construct(IRpcStubBuffer **ppStub)
665 RemUnkStub *This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
666 if (!This) return E_OUTOFMEMORY;
667 This->lpVtbl = &RemUnkStub_VTable;
670 *ppStub = (IRpcStubBuffer*)This;
675 typedef struct _RemUnkProxy {
676 const IRemUnknownVtbl *lpvtbl_remunk;
677 const IRpcProxyBufferVtbl *lpvtbl_proxy;
680 IRpcChannelBuffer *chan;
681 IUnknown *outer_unknown;
684 static HRESULT WINAPI RemUnkProxy_QueryInterface(LPREMUNKNOWN iface, REFIID riid, void **ppv)
686 RemUnkProxy *This = (RemUnkProxy *)iface;
687 if (This->outer_unknown)
688 return IUnknown_QueryInterface(This->outer_unknown, riid, ppv);
689 if (IsEqualIID(riid, &IID_IUnknown) ||
690 IsEqualIID(riid, &IID_IRemUnknown))
692 IRemUnknown_AddRef(iface);
693 *ppv = (LPVOID)iface;
696 return E_NOINTERFACE;
699 static ULONG WINAPI RemUnkProxy_AddRef(LPREMUNKNOWN iface)
701 RemUnkProxy *This = (RemUnkProxy *)iface;
704 TRACE("(%p)->AddRef()\n",This);
706 if (This->outer_unknown)
707 refs = IUnknown_AddRef(This->outer_unknown);
709 refs = InterlockedIncrement(&This->refs);
713 static ULONG WINAPI RemUnkProxy_Release(LPREMUNKNOWN iface)
715 RemUnkProxy *This = (RemUnkProxy *)iface;
717 TRACE("(%p)->Release()\n",This);
718 if (This->outer_unknown)
719 return IUnknown_Release(This->outer_unknown);
721 return IRpcProxyBufferImpl_Release((IRpcProxyBuffer *)&This->lpvtbl_proxy);
724 static HRESULT WINAPI RemUnkProxy_RemQueryInterface(LPREMUNKNOWN iface,
729 REMQIRESULT** ppQIResults)
731 RemUnkProxy *This = (RemUnkProxy *)iface;
736 TRACE("(%p)->(%s,%d,%d,%p,%p)\n",This,
737 debugstr_guid(ripid),cRefs,cIids,iids,ppQIResults);
740 memset(&msg, 0, sizeof(msg));
742 msg.cbBuffer = sizeof(IPID) + sizeof(ULONG) +
743 sizeof(USHORT) + cIids*sizeof(IID);
744 hr = IRpcChannelBuffer_GetBuffer(This->chan, &msg, &IID_IRemUnknown);
746 LPBYTE buf = msg.Buffer;
747 memcpy(buf, ripid, sizeof(IPID));
749 memcpy(buf, &cRefs, sizeof(ULONG));
750 buf += sizeof(ULONG);
751 memcpy(buf, &cIids, sizeof(USHORT));
752 buf += sizeof(USHORT);
753 memcpy(buf, iids, cIids*sizeof(IID));
755 hr = IRpcChannelBuffer_SendReceive(This->chan, &msg, &status);
760 hr = *(HRESULT *)buf;
761 buf += sizeof(HRESULT);
765 *ppQIResults = CoTaskMemAlloc(cIids*sizeof(REMQIRESULT));
766 memcpy(*ppQIResults, buf, cIids*sizeof(REMQIRESULT));
769 IRpcChannelBuffer_FreeBuffer(This->chan, &msg);
775 static HRESULT WINAPI RemUnkProxy_RemAddRef(LPREMUNKNOWN iface,
776 USHORT cInterfaceRefs,
777 REMINTERFACEREF* InterfaceRefs,
780 RemUnkProxy *This = (RemUnkProxy *)iface;
785 TRACE("(%p)->(%d,%p,%p)\n",This,
786 cInterfaceRefs,InterfaceRefs,pResults);
788 memset(&msg, 0, sizeof(msg));
790 msg.cbBuffer = sizeof(USHORT) + cInterfaceRefs*sizeof(REMINTERFACEREF);
791 hr = IRpcChannelBuffer_GetBuffer(This->chan, &msg, &IID_IRemUnknown);
793 LPBYTE buf = msg.Buffer;
794 memcpy(buf, &cInterfaceRefs, sizeof(USHORT));
795 buf += sizeof(USHORT);
796 memcpy(buf, InterfaceRefs, cInterfaceRefs*sizeof(REMINTERFACEREF));
798 hr = IRpcChannelBuffer_SendReceive(This->chan, &msg, &status);
802 memcpy(pResults, buf, cInterfaceRefs*sizeof(HRESULT));
805 IRpcChannelBuffer_FreeBuffer(This->chan, &msg);
811 static HRESULT WINAPI RemUnkProxy_RemRelease(LPREMUNKNOWN iface,
812 USHORT cInterfaceRefs,
813 REMINTERFACEREF* InterfaceRefs)
815 RemUnkProxy *This = (RemUnkProxy *)iface;
820 TRACE("(%p)->(%d,%p)\n",This,
821 cInterfaceRefs,InterfaceRefs);
823 memset(&msg, 0, sizeof(msg));
825 msg.cbBuffer = sizeof(USHORT) + cInterfaceRefs*sizeof(REMINTERFACEREF);
826 hr = IRpcChannelBuffer_GetBuffer(This->chan, &msg, &IID_IRemUnknown);
828 LPBYTE buf = msg.Buffer;
829 memcpy(buf, &cInterfaceRefs, sizeof(USHORT));
830 buf += sizeof(USHORT);
831 memcpy(buf, InterfaceRefs, cInterfaceRefs*sizeof(REMINTERFACEREF));
833 hr = IRpcChannelBuffer_SendReceive(This->chan, &msg, &status);
835 IRpcChannelBuffer_FreeBuffer(This->chan, &msg);
841 static const IRemUnknownVtbl RemUnkProxy_VTable =
843 RemUnkProxy_QueryInterface,
846 RemUnkProxy_RemQueryInterface,
847 RemUnkProxy_RemAddRef,
848 RemUnkProxy_RemRelease
852 static HRESULT WINAPI RURpcProxyBufferImpl_QueryInterface(LPRPCPROXYBUFFER iface,REFIID riid,LPVOID *ppv) {
854 if (IsEqualIID(riid,&IID_IRpcProxyBuffer)||IsEqualIID(riid,&IID_IUnknown)) {
855 IRpcProxyBuffer_AddRef(iface);
856 *ppv = (LPVOID)iface;
859 FIXME("(%s), no interface.\n",debugstr_guid(riid));
860 return E_NOINTERFACE;
863 static ULONG WINAPI RURpcProxyBufferImpl_AddRef(LPRPCPROXYBUFFER iface) {
864 ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
865 TRACE("%p, %d\n", iface, This->refs + 1);
866 return InterlockedIncrement(&This->refs);
869 static ULONG WINAPI RURpcProxyBufferImpl_Release(LPRPCPROXYBUFFER iface) {
870 ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
871 ULONG ref = InterlockedDecrement(&This->refs);
872 TRACE("%p, %d\n", iface, ref);
874 IRpcProxyBuffer_Disconnect(iface);
875 HeapFree(GetProcessHeap(),0,This);
880 static HRESULT WINAPI RURpcProxyBufferImpl_Connect(LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer) {
881 ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
883 TRACE("%p, %p\n", iface, pRpcChannelBuffer);
884 This->chan = pRpcChannelBuffer;
885 IRpcChannelBuffer_AddRef(This->chan);
888 static void WINAPI RURpcProxyBufferImpl_Disconnect(LPRPCPROXYBUFFER iface) {
889 ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
890 TRACE("%p, %p\n", iface, This->chan);
892 IRpcChannelBuffer_Release(This->chan);
898 static const IRpcProxyBufferVtbl RURpcProxyBuffer_VTable = {
899 RURpcProxyBufferImpl_QueryInterface,
900 RURpcProxyBufferImpl_AddRef,
901 RURpcProxyBufferImpl_Release,
902 RURpcProxyBufferImpl_Connect,
903 RURpcProxyBufferImpl_Disconnect
907 RemUnkProxy_Construct(IUnknown *pUnkOuter, LPVOID *ppv,LPVOID *ppProxy) {
910 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*This));
912 return E_OUTOFMEMORY;
914 This->lpvtbl_remunk = &RemUnkProxy_VTable;
915 This->lpvtbl_proxy = &RURpcProxyBuffer_VTable;
916 /* only one reference for the proxy buffer */
918 This->outer_unknown = pUnkOuter;
919 *ppv = &(This->lpvtbl_remunk);
920 *ppProxy = &(This->lpvtbl_proxy);
921 /* and one reference for the object */
922 IUnknown_AddRef((IUnknown *)*ppv);
927 /********************* OLE Proxy/Stub Factory ********************************/
928 static HRESULT WINAPI
929 PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface, REFIID iid, LPVOID *ppv) {
930 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)||IsEqualIID(iid,&IID_IUnknown)) {
931 *ppv = (LPVOID)iface;
932 /* No ref counting, static class */
935 FIXME("(%s) unknown IID?\n",debugstr_guid(iid));
936 return E_NOINTERFACE;
939 static ULONG WINAPI PSFacBuf_AddRef(LPPSFACTORYBUFFER iface) { return 2; }
940 static ULONG WINAPI PSFacBuf_Release(LPPSFACTORYBUFFER iface) { return 1; }
942 static HRESULT WINAPI
943 PSFacBuf_CreateProxy(
944 LPPSFACTORYBUFFER iface, IUnknown* pUnkOuter, REFIID riid,
945 IRpcProxyBuffer **ppProxy, LPVOID *ppv
947 if (IsEqualIID(&IID_IClassFactory,riid))
948 return CFProxy_Construct(pUnkOuter, ppv,(LPVOID*)ppProxy);
949 else if (IsEqualIID(&IID_IRemUnknown,riid))
950 return RemUnkProxy_Construct(pUnkOuter, ppv,(LPVOID*)ppProxy);
951 FIXME("proxying not implemented for (%s) yet!\n",debugstr_guid(riid));
955 static HRESULT WINAPI
957 LPPSFACTORYBUFFER iface, REFIID riid,IUnknown *pUnkServer,
958 IRpcStubBuffer** ppStub
962 TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub);
964 if (IsEqualIID(&IID_IClassFactory, riid) ||
965 IsEqualIID(&IID_IUnknown, riid) /* FIXME: fixup stub manager and remove this*/) {
966 hres = CFStub_Construct(ppStub);
968 IRpcStubBuffer_Connect((*ppStub),pUnkServer);
970 } else if (IsEqualIID(&IID_IRemUnknown,riid)) {
971 hres = RemUnkStub_Construct(ppStub);
973 IRpcStubBuffer_Connect((*ppStub),pUnkServer);
976 FIXME("stubbing not implemented for (%s) yet!\n",debugstr_guid(riid));
980 static const IPSFactoryBufferVtbl psfacbufvtbl = {
981 PSFacBuf_QueryInterface,
984 PSFacBuf_CreateProxy,
988 /* This is the whole PSFactoryBuffer object, just the vtableptr */
989 static const IPSFactoryBufferVtbl *lppsfac = &psfacbufvtbl;
991 /***********************************************************************
992 * DllGetClassObject [OLE32.@]
994 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
997 if (IsEqualIID(rclsid, &CLSID_PSFactoryBuffer))
998 return IPSFactoryBuffer_QueryInterface((IPSFactoryBuffer *)&lppsfac, iid, ppv);
999 if (IsEqualIID(rclsid,&CLSID_DfMarshal)&&(
1000 IsEqualIID(iid,&IID_IClassFactory) ||
1001 IsEqualIID(iid,&IID_IUnknown)
1004 return MARSHAL_GetStandardMarshalCF(ppv);
1005 if (IsEqualIID(rclsid,&CLSID_StdGlobalInterfaceTable) && (IsEqualIID(iid,&IID_IClassFactory) || IsEqualIID(iid,&IID_IUnknown)))
1006 return StdGlobalInterfaceTable_GetFactory(ppv);
1007 if (IsEqualCLSID(rclsid, &CLSID_FileMoniker))
1008 return FileMonikerCF_Create(iid, ppv);
1009 if (IsEqualCLSID(rclsid, &CLSID_ItemMoniker))
1010 return ItemMonikerCF_Create(iid, ppv);
1011 if (IsEqualCLSID(rclsid, &CLSID_AntiMoniker))
1012 return AntiMonikerCF_Create(iid, ppv);
1013 if (IsEqualCLSID(rclsid, &CLSID_CompositeMoniker))
1014 return CompositeMonikerCF_Create(iid, ppv);
1015 if (IsEqualCLSID(rclsid, &CLSID_ClassMoniker))
1016 return ClassMonikerCF_Create(iid, ppv);
1017 if (IsEqualCLSID(rclsid, &CLSID_PointerMoniker))
1018 return PointerMonikerCF_Create(iid, ppv);
1020 FIXME("\n\tCLSID:\t%s,\n\tIID:\t%s\n",debugstr_guid(rclsid),debugstr_guid(iid));
1021 return CLASS_E_CLASSNOTAVAILABLE;