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
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
58 #include "compobj_private.h"
61 #include "wine/debug.h"
63 WINE_DEFAULT_DEBUG_CHANNEL(ole);
65 static ULONG WINAPI RURpcProxyBufferImpl_Release(LPRPCPROXYBUFFER iface);
67 /* From: http://msdn.microsoft.com/library/en-us/com/cmi_m_4lda.asp
69 * The first time a client requests a pointer to an interface on a
70 * particular object, COM loads an IClassFactory stub in the server
71 * process and uses it to marshal the first pointer back to the
72 * client. In the client process, COM loads the generic proxy for the
73 * class factory object and calls its implementation of IMarshal to
74 * unmarshal that first pointer. COM then creates the first interface
75 * proxy and hands it a pointer to the RPC channel. Finally, COM returns
76 * the IClassFactory pointer to the client, which uses it to call
77 * IClassFactory::CreateInstance, passing it a reference to the interface.
79 * Back in the server process, COM now creates a new instance of the
80 * object, along with a stub for the requested interface. This stub marshals
81 * the interface pointer back to the client process, where another object
82 * proxy is created, this time for the object itself. Also created is a
83 * proxy for the requested interface, a pointer to which is returned to
84 * the client. With subsequent calls to other interfaces on the object,
85 * COM will load the appropriate interface stubs and proxies as needed.
87 typedef struct _CFStub {
88 const IRpcStubBufferVtbl *lpvtbl;
95 CFStub_QueryInterface(LPRPCSTUBBUFFER iface, REFIID riid, LPVOID *ppv) {
96 if (IsEqualIID(&IID_IUnknown,riid)||IsEqualIID(&IID_IRpcStubBuffer,riid)) {
98 IUnknown_AddRef(iface);
101 FIXME("(%s), interface not supported.\n",debugstr_guid(riid));
102 return E_NOINTERFACE;
106 CFStub_AddRef(LPRPCSTUBBUFFER iface) {
107 CFStub *This = (CFStub *)iface;
108 return InterlockedIncrement(&This->ref);
112 CFStub_Release(LPRPCSTUBBUFFER iface) {
113 CFStub *This = (CFStub *)iface;
116 ref = InterlockedDecrement(&This->ref);
118 IRpcStubBuffer_Disconnect(iface);
119 HeapFree(GetProcessHeap(),0,This);
124 static HRESULT WINAPI
125 CFStub_Connect(LPRPCSTUBBUFFER iface, IUnknown *pUnkServer) {
126 CFStub *This = (CFStub *)iface;
128 This->pUnkServer = pUnkServer;
129 IUnknown_AddRef(pUnkServer);
134 CFStub_Disconnect(LPRPCSTUBBUFFER iface) {
135 CFStub *This = (CFStub *)iface;
137 if (This->pUnkServer) {
138 IUnknown_Release(This->pUnkServer);
139 This->pUnkServer = NULL;
143 static HRESULT WINAPI
145 LPRPCSTUBBUFFER iface,RPCOLEMESSAGE* msg,IRpcChannelBuffer* chanbuf
147 CFStub *This = (CFStub *)iface;
150 if (msg->iMethod == 3) { /* CreateInstance */
152 IClassFactory *classfac;
156 ULARGE_INTEGER newpos;
157 LARGE_INTEGER seekto;
160 if (msg->cbBuffer < sizeof(IID)) {
161 FIXME("Not enough bytes in buffer (%d)?\n",msg->cbBuffer);
164 memcpy(&iid,msg->Buffer,sizeof(iid));
165 TRACE("->CreateInstance(%s)\n",debugstr_guid(&iid));
166 hres = IUnknown_QueryInterface(This->pUnkServer,&IID_IClassFactory,(LPVOID*)&classfac);
168 FIXME("Ole server does not provide an IClassFactory?\n");
171 hres = IClassFactory_CreateInstance(classfac,NULL,&iid,(LPVOID*)&ppv);
172 IClassFactory_Release(classfac);
175 FIXME("Failed to create an instance of %s\n",debugstr_guid(&iid));
178 hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
180 FIXME("Failed to create stream on hglobal\n");
183 hres = IStream_Write(pStm, &ppv, sizeof(ppv), NULL);
185 ERR("IStream_Write failed, 0x%08x\n", hres);
189 hres = CoMarshalInterface(pStm,&iid,ppv,0,NULL,0);
190 IUnknown_Release(ppv);
192 FIXME("CoMarshalInterface failed, %x!\n",hres);
196 hres = IStream_Stat(pStm,&ststg,0);
198 FIXME("Stat failed.\n");
202 msg->cbBuffer = ststg.cbSize.u.LowPart;
205 IRpcChannelBuffer_GetBuffer(chanbuf, msg, &IID_IClassFactory);
206 if (hres) return hres;
208 seekto.u.LowPart = 0;seekto.u.HighPart = 0;
209 hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
211 FIXME("IStream_Seek failed, %x\n",hres);
214 hres = IStream_Read(pStm,msg->Buffer,msg->cbBuffer,&res);
216 FIXME("Stream Read failed, %x\n",hres);
219 IStream_Release(pStm);
222 FIXME("(%p,%p), stub!\n",msg,chanbuf);
223 FIXME("iMethod is %d\n",msg->iMethod);
224 FIXME("cbBuffer is %d\n",msg->cbBuffer);
228 static LPRPCSTUBBUFFER WINAPI
229 CFStub_IsIIDSupported(LPRPCSTUBBUFFER iface,REFIID riid) {
230 FIXME("(%s), stub!\n",debugstr_guid(riid));
235 CFStub_CountRefs(LPRPCSTUBBUFFER iface) {
236 FIXME("(), stub!\n");
240 static HRESULT WINAPI
241 CFStub_DebugServerQueryInterface(LPRPCSTUBBUFFER iface,void** ppv) {
242 FIXME("(%p), stub!\n",ppv);
246 CFStub_DebugServerRelease(LPRPCSTUBBUFFER iface,void *pv) {
247 FIXME("(%p), stub!\n",pv);
250 static const IRpcStubBufferVtbl cfstubvt = {
251 CFStub_QueryInterface,
257 CFStub_IsIIDSupported,
259 CFStub_DebugServerQueryInterface,
260 CFStub_DebugServerRelease
264 CFStub_Construct(LPRPCSTUBBUFFER *ppv) {
266 cfstub = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(CFStub));
268 return E_OUTOFMEMORY;
269 *ppv = (LPRPCSTUBBUFFER)cfstub;
270 cfstub->lpvtbl = &cfstubvt;
275 /* Since we create proxy buffers and classfactory in a pair, there is
276 * no need for 2 separate structs. Just put them in one, but remember
279 typedef struct _CFProxy {
280 const IClassFactoryVtbl *lpvtbl_cf;
281 const IRpcProxyBufferVtbl *lpvtbl_proxy;
284 IRpcChannelBuffer *chanbuf;
285 IUnknown *outer_unknown;
288 static HRESULT WINAPI IRpcProxyBufferImpl_QueryInterface(LPRPCPROXYBUFFER iface,REFIID riid,LPVOID *ppv) {
290 if (IsEqualIID(riid,&IID_IRpcProxyBuffer)||IsEqualIID(riid,&IID_IUnknown)) {
291 IRpcProxyBuffer_AddRef(iface);
292 *ppv = (LPVOID)iface;
295 FIXME("(%s), no interface.\n",debugstr_guid(riid));
296 return E_NOINTERFACE;
299 static ULONG WINAPI IRpcProxyBufferImpl_AddRef(LPRPCPROXYBUFFER iface) {
300 ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
301 return InterlockedIncrement(&This->ref);
304 static ULONG WINAPI IRpcProxyBufferImpl_Release(LPRPCPROXYBUFFER iface) {
305 ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
306 ULONG ref = InterlockedDecrement(&This->ref);
309 IRpcProxyBuffer_Disconnect(iface);
310 HeapFree(GetProcessHeap(),0,This);
315 static HRESULT WINAPI IRpcProxyBufferImpl_Connect(LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer) {
316 ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
318 This->chanbuf = pRpcChannelBuffer;
319 IRpcChannelBuffer_AddRef(This->chanbuf);
322 static void WINAPI IRpcProxyBufferImpl_Disconnect(LPRPCPROXYBUFFER iface) {
323 ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
325 IRpcChannelBuffer_Release(This->chanbuf);
326 This->chanbuf = NULL;
330 static HRESULT WINAPI
331 CFProxy_QueryInterface(LPCLASSFACTORY iface,REFIID riid, LPVOID *ppv) {
332 ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
333 if (This->outer_unknown) return IUnknown_QueryInterface(This->outer_unknown, riid, ppv);
335 if (IsEqualIID(&IID_IClassFactory,riid) || IsEqualIID(&IID_IUnknown,riid)) {
336 *ppv = (LPVOID)iface;
337 IClassFactory_AddRef(iface);
340 if (IsEqualIID(riid,&IID_IMarshal)) /* just to avoid debug output */
341 return E_NOINTERFACE;
342 FIXME("Unhandled interface: %s\n",debugstr_guid(riid));
343 return E_NOINTERFACE;
346 static ULONG WINAPI CFProxy_AddRef(LPCLASSFACTORY iface) {
347 ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
348 if (This->outer_unknown) return IUnknown_AddRef(This->outer_unknown);
349 return InterlockedIncrement(&This->ref);
352 static ULONG WINAPI CFProxy_Release(LPCLASSFACTORY iface) {
353 ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
354 if (This->outer_unknown)
355 return IUnknown_Release(This->outer_unknown);
357 return IRpcProxyBufferImpl_Release((IRpcProxyBuffer *)&This->lpvtbl_proxy);
360 static HRESULT WINAPI CFProxy_CreateInstance(
361 LPCLASSFACTORY iface,
362 LPUNKNOWN pUnkOuter,/* [in] */
363 REFIID riid, /* [in] */
364 LPVOID *ppv /* [out] */
366 ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
373 TRACE("(%p,%s,%p)\n",pUnkOuter,debugstr_guid(riid),ppv);
375 /* Send CreateInstance to the remote classfactory.
377 * Data: Only the 'IID'.
380 msg.cbBuffer = sizeof(*riid);
382 hres = IRpcChannelBuffer_GetBuffer(This->chanbuf,&msg,&IID_IClassFactory);
384 FIXME("IRpcChannelBuffer_GetBuffer failed with %x?\n",hres);
387 memcpy(msg.Buffer,riid,sizeof(*riid));
388 hres = IRpcChannelBuffer_SendReceive(This->chanbuf,&msg,&srstatus);
390 FIXME("IRpcChannelBuffer_SendReceive failed with %x?\n",hres);
391 IRpcChannelBuffer_FreeBuffer(This->chanbuf,&msg);
395 if (!msg.cbBuffer) { /* interface not found on remote */
396 IRpcChannelBuffer_FreeBuffer(This->chanbuf,&msg);
400 /* We got back: [Marshalled Interface data] */
401 TRACE("got %d 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 %x\n",hres);
407 IRpcChannelBuffer_FreeBuffer(This->chanbuf,&msg);
411 hres = IStream_Read(pStream, ppv, sizeof(*ppv), NULL);
415 hres = CoUnmarshalInterface(
421 IStream_Release(pStream); /* Does GlobalFree hGlobal too. */
423 IRpcChannelBuffer_FreeBuffer(This->chanbuf,&msg);
426 FIXME("CoMarshalInterface failed, %x\n",hres);
432 static HRESULT WINAPI CFProxy_LockServer(LPCLASSFACTORY iface,BOOL fLock) {
433 /*ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);*/
434 FIXME("(%d), stub!\n",fLock);
435 /* basically: write BOOL, read empty */
439 static const IRpcProxyBufferVtbl pspbvtbl = {
440 IRpcProxyBufferImpl_QueryInterface,
441 IRpcProxyBufferImpl_AddRef,
442 IRpcProxyBufferImpl_Release,
443 IRpcProxyBufferImpl_Connect,
444 IRpcProxyBufferImpl_Disconnect
446 static const IClassFactoryVtbl cfproxyvt = {
447 CFProxy_QueryInterface,
450 CFProxy_CreateInstance,
455 CFProxy_Construct(IUnknown *pUnkOuter, LPVOID *ppv,LPVOID *ppProxy) {
458 cf = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(CFProxy));
460 return E_OUTOFMEMORY;
462 cf->lpvtbl_cf = &cfproxyvt;
463 cf->lpvtbl_proxy = &pspbvtbl;
464 /* one reference for the proxy buffer */
466 cf->outer_unknown = pUnkOuter;
467 *ppv = &(cf->lpvtbl_cf);
468 *ppProxy = &(cf->lpvtbl_proxy);
469 /* and one reference for the object */
470 IUnknown_AddRef((IUnknown *)*ppv);
475 /********************* IRemUnknown Proxy/Stub ********************************/
479 const IRpcStubBufferVtbl *lpVtbl;
484 static HRESULT WINAPI RemUnkStub_QueryInterface(LPRPCSTUBBUFFER iface,
488 RemUnkStub *This = (RemUnkStub *)iface;
489 TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(riid),obj);
490 if (IsEqualGUID(&IID_IUnknown,riid) ||
491 IsEqualGUID(&IID_IRpcStubBuffer,riid)) {
495 return E_NOINTERFACE;
498 static ULONG WINAPI RemUnkStub_AddRef(LPRPCSTUBBUFFER iface)
500 RemUnkStub *This = (RemUnkStub *)iface;
501 TRACE("(%p)->AddRef()\n",This);
502 return InterlockedIncrement(&This->refs);
505 static ULONG WINAPI RemUnkStub_Release(LPRPCSTUBBUFFER iface)
507 RemUnkStub *This = (RemUnkStub *)iface;
509 TRACE("(%p)->Release()\n",This);
510 refs = InterlockedDecrement(&This->refs);
513 IRpcStubBuffer_Disconnect(iface);
514 HeapFree(GetProcessHeap(), 0, This);
519 static HRESULT WINAPI RemUnkStub_Connect(LPRPCSTUBBUFFER iface,
520 LPUNKNOWN lpUnkServer)
522 RemUnkStub *This = (RemUnkStub *)iface;
523 TRACE("(%p)->Connect(%p)\n",This,lpUnkServer);
524 This->iface = (IRemUnknown*)lpUnkServer;
525 IRemUnknown_AddRef(This->iface);
529 static void WINAPI RemUnkStub_Disconnect(LPRPCSTUBBUFFER iface)
531 RemUnkStub *This = (RemUnkStub *)iface;
532 TRACE("(%p)->Disconnect()\n",This);
533 IUnknown_Release(This->iface);
537 static HRESULT WINAPI RemUnkStub_Invoke(LPRPCSTUBBUFFER iface,
539 LPRPCCHANNELBUFFER pChannel)
541 RemUnkStub *This = (RemUnkStub *)iface;
542 ULONG iMethod = pMsg->iMethod;
543 LPBYTE buf = pMsg->Buffer;
544 HRESULT hr = RPC_E_INVALIDMETHOD;
546 TRACE("(%p)->Invoke(%p,%p) method %d\n", This, pMsg, pChannel, iMethod);
549 case 3: /* RemQueryInterface */
555 REMQIRESULT *pQIResults = NULL;
558 memcpy(&ipid, buf, sizeof(ipid));
560 memcpy(&cRefs, buf, sizeof(cRefs));
561 buf += sizeof(cRefs);
562 memcpy(&cIids, buf, sizeof(cIids));
563 buf += sizeof(cIids);
566 hr = IRemUnknown_RemQueryInterface(This->iface, &ipid, cRefs, cIids, iids, &pQIResults);
569 pMsg->cbBuffer = cIids * sizeof(REMQIRESULT) + sizeof(HRESULT);
571 IRpcChannelBuffer_GetBuffer(pChannel, pMsg, &IID_IRemUnknown);
574 *(HRESULT *)buf = hr;
575 buf += sizeof(HRESULT);
578 /* FIXME: pQIResults is a unique pointer so pQIResults can be NULL! */
579 memcpy(buf, pQIResults, cIids * sizeof(REMQIRESULT));
583 case 4: /* RemAddRef */
590 memcpy(&cIids, buf, sizeof(USHORT));
591 buf += sizeof(USHORT);
592 ir = (REMINTERFACEREF*)buf;
593 pResults = CoTaskMemAlloc(cIids * sizeof(HRESULT));
594 if (!pResults) return E_OUTOFMEMORY;
596 hr = IRemUnknown_RemAddRef(This->iface, cIids, ir, pResults);
599 pMsg->cbBuffer = cIids * sizeof(HRESULT);
601 IRpcChannelBuffer_GetBuffer(pChannel, pMsg, &IID_IRemUnknown);
605 memcpy(buf, pResults, cIids * sizeof(HRESULT));
608 CoTaskMemFree(pResults);
612 case 5: /* RemRelease */
618 memcpy(&cIids, buf, sizeof(USHORT));
619 buf += sizeof(USHORT);
620 ir = (REMINTERFACEREF*)buf;
622 hr = IRemUnknown_RemRelease(This->iface, cIids, ir);
626 IRpcChannelBuffer_GetBuffer(pChannel, pMsg, &IID_IRemUnknown);
633 static LPRPCSTUBBUFFER WINAPI RemUnkStub_IsIIDSupported(LPRPCSTUBBUFFER iface,
636 RemUnkStub *This = (RemUnkStub *)iface;
637 TRACE("(%p)->IsIIDSupported(%s)\n", This, debugstr_guid(riid));
638 return IsEqualGUID(&IID_IRemUnknown, riid) ? iface : NULL;
641 static ULONG WINAPI RemUnkStub_CountRefs(LPRPCSTUBBUFFER iface)
643 RemUnkStub *This = (RemUnkStub *)iface;
644 FIXME("(%p)->CountRefs()\n", This);
648 static HRESULT WINAPI RemUnkStub_DebugServerQueryInterface(LPRPCSTUBBUFFER iface,
651 RemUnkStub *This = (RemUnkStub *)iface;
652 FIXME("(%p)->DebugServerQueryInterface(%p)\n",This,ppv);
653 return E_NOINTERFACE;
656 static void WINAPI RemUnkStub_DebugServerRelease(LPRPCSTUBBUFFER iface,
659 RemUnkStub *This = (RemUnkStub *)iface;
660 FIXME("(%p)->DebugServerRelease(%p)\n", This, pv);
663 static const IRpcStubBufferVtbl RemUnkStub_VTable =
665 RemUnkStub_QueryInterface,
669 RemUnkStub_Disconnect,
671 RemUnkStub_IsIIDSupported,
672 RemUnkStub_CountRefs,
673 RemUnkStub_DebugServerQueryInterface,
674 RemUnkStub_DebugServerRelease
677 static HRESULT RemUnkStub_Construct(IRpcStubBuffer **ppStub)
679 RemUnkStub *This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
680 if (!This) return E_OUTOFMEMORY;
681 This->lpVtbl = &RemUnkStub_VTable;
684 *ppStub = (IRpcStubBuffer*)This;
689 typedef struct _RemUnkProxy {
690 const IRemUnknownVtbl *lpvtbl_remunk;
691 const IRpcProxyBufferVtbl *lpvtbl_proxy;
694 IRpcChannelBuffer *chan;
695 IUnknown *outer_unknown;
698 static HRESULT WINAPI RemUnkProxy_QueryInterface(LPREMUNKNOWN iface, REFIID riid, void **ppv)
700 RemUnkProxy *This = (RemUnkProxy *)iface;
701 if (This->outer_unknown)
702 return IUnknown_QueryInterface(This->outer_unknown, riid, ppv);
703 if (IsEqualIID(riid, &IID_IUnknown) ||
704 IsEqualIID(riid, &IID_IRemUnknown))
706 IRemUnknown_AddRef(iface);
707 *ppv = (LPVOID)iface;
710 return E_NOINTERFACE;
713 static ULONG WINAPI RemUnkProxy_AddRef(LPREMUNKNOWN iface)
715 RemUnkProxy *This = (RemUnkProxy *)iface;
718 TRACE("(%p)->AddRef()\n",This);
720 if (This->outer_unknown)
721 refs = IUnknown_AddRef(This->outer_unknown);
723 refs = InterlockedIncrement(&This->refs);
727 static ULONG WINAPI RemUnkProxy_Release(LPREMUNKNOWN iface)
729 RemUnkProxy *This = (RemUnkProxy *)iface;
731 TRACE("(%p)->Release()\n",This);
732 if (This->outer_unknown)
733 return IUnknown_Release(This->outer_unknown);
735 return IRpcProxyBufferImpl_Release((IRpcProxyBuffer *)&This->lpvtbl_proxy);
738 static HRESULT WINAPI RemUnkProxy_RemQueryInterface(LPREMUNKNOWN iface,
743 REMQIRESULT** ppQIResults)
745 RemUnkProxy *This = (RemUnkProxy *)iface;
750 TRACE("(%p)->(%s,%d,%d,%p,%p)\n",This,
751 debugstr_guid(ripid),cRefs,cIids,iids,ppQIResults);
754 memset(&msg, 0, sizeof(msg));
756 msg.cbBuffer = sizeof(IPID) + sizeof(ULONG) +
757 sizeof(USHORT) + cIids*sizeof(IID);
758 hr = IRpcChannelBuffer_GetBuffer(This->chan, &msg, &IID_IRemUnknown);
760 LPBYTE buf = msg.Buffer;
761 memcpy(buf, ripid, sizeof(IPID));
763 memcpy(buf, &cRefs, sizeof(ULONG));
764 buf += sizeof(ULONG);
765 memcpy(buf, &cIids, sizeof(USHORT));
766 buf += sizeof(USHORT);
767 memcpy(buf, iids, cIids*sizeof(IID));
769 hr = IRpcChannelBuffer_SendReceive(This->chan, &msg, &status);
774 hr = *(HRESULT *)buf;
775 buf += sizeof(HRESULT);
779 *ppQIResults = CoTaskMemAlloc(cIids*sizeof(REMQIRESULT));
780 memcpy(*ppQIResults, buf, cIids*sizeof(REMQIRESULT));
783 IRpcChannelBuffer_FreeBuffer(This->chan, &msg);
789 static HRESULT WINAPI RemUnkProxy_RemAddRef(LPREMUNKNOWN iface,
790 USHORT cInterfaceRefs,
791 REMINTERFACEREF* InterfaceRefs,
794 RemUnkProxy *This = (RemUnkProxy *)iface;
799 TRACE("(%p)->(%d,%p,%p)\n",This,
800 cInterfaceRefs,InterfaceRefs,pResults);
802 memset(&msg, 0, sizeof(msg));
804 msg.cbBuffer = sizeof(USHORT) + cInterfaceRefs*sizeof(REMINTERFACEREF);
805 hr = IRpcChannelBuffer_GetBuffer(This->chan, &msg, &IID_IRemUnknown);
807 LPBYTE buf = msg.Buffer;
808 memcpy(buf, &cInterfaceRefs, sizeof(USHORT));
809 buf += sizeof(USHORT);
810 memcpy(buf, InterfaceRefs, cInterfaceRefs*sizeof(REMINTERFACEREF));
812 hr = IRpcChannelBuffer_SendReceive(This->chan, &msg, &status);
816 memcpy(pResults, buf, cInterfaceRefs*sizeof(HRESULT));
819 IRpcChannelBuffer_FreeBuffer(This->chan, &msg);
825 static HRESULT WINAPI RemUnkProxy_RemRelease(LPREMUNKNOWN iface,
826 USHORT cInterfaceRefs,
827 REMINTERFACEREF* InterfaceRefs)
829 RemUnkProxy *This = (RemUnkProxy *)iface;
834 TRACE("(%p)->(%d,%p)\n",This,
835 cInterfaceRefs,InterfaceRefs);
837 memset(&msg, 0, sizeof(msg));
839 msg.cbBuffer = sizeof(USHORT) + cInterfaceRefs*sizeof(REMINTERFACEREF);
840 hr = IRpcChannelBuffer_GetBuffer(This->chan, &msg, &IID_IRemUnknown);
842 LPBYTE buf = msg.Buffer;
843 memcpy(buf, &cInterfaceRefs, sizeof(USHORT));
844 buf += sizeof(USHORT);
845 memcpy(buf, InterfaceRefs, cInterfaceRefs*sizeof(REMINTERFACEREF));
847 hr = IRpcChannelBuffer_SendReceive(This->chan, &msg, &status);
849 IRpcChannelBuffer_FreeBuffer(This->chan, &msg);
855 static const IRemUnknownVtbl RemUnkProxy_VTable =
857 RemUnkProxy_QueryInterface,
860 RemUnkProxy_RemQueryInterface,
861 RemUnkProxy_RemAddRef,
862 RemUnkProxy_RemRelease
866 static HRESULT WINAPI RURpcProxyBufferImpl_QueryInterface(LPRPCPROXYBUFFER iface,REFIID riid,LPVOID *ppv) {
868 if (IsEqualIID(riid,&IID_IRpcProxyBuffer)||IsEqualIID(riid,&IID_IUnknown)) {
869 IRpcProxyBuffer_AddRef(iface);
870 *ppv = (LPVOID)iface;
873 FIXME("(%s), no interface.\n",debugstr_guid(riid));
874 return E_NOINTERFACE;
877 static ULONG WINAPI RURpcProxyBufferImpl_AddRef(LPRPCPROXYBUFFER iface) {
878 ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
879 TRACE("%p, %d\n", iface, This->refs + 1);
880 return InterlockedIncrement(&This->refs);
883 static ULONG WINAPI RURpcProxyBufferImpl_Release(LPRPCPROXYBUFFER iface) {
884 ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
885 ULONG ref = InterlockedDecrement(&This->refs);
886 TRACE("%p, %d\n", iface, ref);
888 IRpcProxyBuffer_Disconnect(iface);
889 HeapFree(GetProcessHeap(),0,This);
894 static HRESULT WINAPI RURpcProxyBufferImpl_Connect(LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer) {
895 ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
897 TRACE("%p, %p\n", iface, pRpcChannelBuffer);
898 This->chan = pRpcChannelBuffer;
899 IRpcChannelBuffer_AddRef(This->chan);
902 static void WINAPI RURpcProxyBufferImpl_Disconnect(LPRPCPROXYBUFFER iface) {
903 ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
904 TRACE("%p, %p\n", iface, This->chan);
906 IRpcChannelBuffer_Release(This->chan);
912 static const IRpcProxyBufferVtbl RURpcProxyBuffer_VTable = {
913 RURpcProxyBufferImpl_QueryInterface,
914 RURpcProxyBufferImpl_AddRef,
915 RURpcProxyBufferImpl_Release,
916 RURpcProxyBufferImpl_Connect,
917 RURpcProxyBufferImpl_Disconnect
921 RemUnkProxy_Construct(IUnknown *pUnkOuter, LPVOID *ppv,LPVOID *ppProxy) {
924 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*This));
926 return E_OUTOFMEMORY;
928 This->lpvtbl_remunk = &RemUnkProxy_VTable;
929 This->lpvtbl_proxy = &RURpcProxyBuffer_VTable;
930 /* only one reference for the proxy buffer */
932 This->outer_unknown = pUnkOuter;
933 *ppv = &(This->lpvtbl_remunk);
934 *ppProxy = &(This->lpvtbl_proxy);
935 /* and one reference for the object */
936 IUnknown_AddRef((IUnknown *)*ppv);
941 /********************* OLE Proxy/Stub Factory ********************************/
942 static HRESULT WINAPI
943 PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface, REFIID iid, LPVOID *ppv) {
944 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)||IsEqualIID(iid,&IID_IUnknown)) {
945 *ppv = (LPVOID)iface;
946 /* No ref counting, static class */
949 FIXME("(%s) unknown IID?\n",debugstr_guid(iid));
950 return E_NOINTERFACE;
953 static ULONG WINAPI PSFacBuf_AddRef(LPPSFACTORYBUFFER iface) { return 2; }
954 static ULONG WINAPI PSFacBuf_Release(LPPSFACTORYBUFFER iface) { return 1; }
956 static HRESULT WINAPI
957 PSFacBuf_CreateProxy(
958 LPPSFACTORYBUFFER iface, IUnknown* pUnkOuter, REFIID riid,
959 IRpcProxyBuffer **ppProxy, LPVOID *ppv
961 if (IsEqualIID(&IID_IClassFactory,riid))
962 return CFProxy_Construct(pUnkOuter, ppv,(LPVOID*)ppProxy);
963 else if (IsEqualIID(&IID_IRemUnknown,riid))
964 return RemUnkProxy_Construct(pUnkOuter, ppv,(LPVOID*)ppProxy);
965 FIXME("proxying not implemented for (%s) yet!\n",debugstr_guid(riid));
969 static HRESULT WINAPI
971 LPPSFACTORYBUFFER iface, REFIID riid,IUnknown *pUnkServer,
972 IRpcStubBuffer** ppStub
976 TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub);
978 if (IsEqualIID(&IID_IClassFactory, riid) ||
979 IsEqualIID(&IID_IUnknown, riid) /* FIXME: fixup stub manager and remove this*/) {
980 hres = CFStub_Construct(ppStub);
982 IRpcStubBuffer_Connect((*ppStub),pUnkServer);
984 } else if (IsEqualIID(&IID_IRemUnknown,riid)) {
985 hres = RemUnkStub_Construct(ppStub);
987 IRpcStubBuffer_Connect((*ppStub),pUnkServer);
990 FIXME("stubbing not implemented for (%s) yet!\n",debugstr_guid(riid));
994 static const IPSFactoryBufferVtbl psfacbufvtbl = {
995 PSFacBuf_QueryInterface,
998 PSFacBuf_CreateProxy,
1002 /* This is the whole PSFactoryBuffer object, just the vtableptr */
1003 static const IPSFactoryBufferVtbl *lppsfac = &psfacbufvtbl;
1005 /***********************************************************************
1006 * DllGetClassObject [OLE32.@]
1008 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
1011 if (IsEqualIID(rclsid, &CLSID_PSFactoryBuffer))
1012 return IPSFactoryBuffer_QueryInterface((IPSFactoryBuffer *)&lppsfac, iid, ppv);
1013 if (IsEqualIID(rclsid,&CLSID_DfMarshal)&&(
1014 IsEqualIID(iid,&IID_IClassFactory) ||
1015 IsEqualIID(iid,&IID_IUnknown)
1018 return MARSHAL_GetStandardMarshalCF(ppv);
1019 if (IsEqualIID(rclsid,&CLSID_StdGlobalInterfaceTable) && (IsEqualIID(iid,&IID_IClassFactory) || IsEqualIID(iid,&IID_IUnknown)))
1020 return StdGlobalInterfaceTable_GetFactory(ppv);
1021 if (IsEqualCLSID(rclsid, &CLSID_FileMoniker))
1022 return FileMonikerCF_Create(iid, ppv);
1023 if (IsEqualCLSID(rclsid, &CLSID_ItemMoniker))
1024 return ItemMonikerCF_Create(iid, ppv);
1025 if (IsEqualCLSID(rclsid, &CLSID_AntiMoniker))
1026 return AntiMonikerCF_Create(iid, ppv);
1027 if (IsEqualCLSID(rclsid, &CLSID_CompositeMoniker))
1028 return CompositeMonikerCF_Create(iid, ppv);
1029 if (IsEqualCLSID(rclsid, &CLSID_ClassMoniker))
1030 return ClassMonikerCF_Create(iid, ppv);
1032 FIXME("\n\tCLSID:\t%s,\n\tIID:\t%s\n",debugstr_guid(rclsid),debugstr_guid(iid));
1033 return CLASS_E_CLASSNOTAVAILABLE;