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
59 #include "compobj_private.h"
62 #include "wine/debug.h"
64 WINE_DEFAULT_DEBUG_CHANNEL(ole);
66 static ULONG WINAPI RURpcProxyBufferImpl_Release(LPRPCPROXYBUFFER iface);
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 const 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);
119 IRpcStubBuffer_Disconnect(iface);
120 HeapFree(GetProcessHeap(),0,This);
125 static HRESULT WINAPI
126 CFStub_Connect(LPRPCSTUBBUFFER iface, IUnknown *pUnkServer) {
127 CFStub *This = (CFStub *)iface;
129 This->pUnkServer = pUnkServer;
130 IUnknown_AddRef(pUnkServer);
135 CFStub_Disconnect(LPRPCSTUBBUFFER iface) {
136 CFStub *This = (CFStub *)iface;
138 if (This->pUnkServer) {
139 IUnknown_Release(This->pUnkServer);
140 This->pUnkServer = NULL;
144 static HRESULT WINAPI
146 LPRPCSTUBBUFFER iface,RPCOLEMESSAGE* msg,IRpcChannelBuffer* chanbuf
148 CFStub *This = (CFStub *)iface;
151 if (msg->iMethod == 3) { /* CreateInstance */
153 IClassFactory *classfac;
157 ULARGE_INTEGER newpos;
158 LARGE_INTEGER seekto;
161 if (msg->cbBuffer < sizeof(IID)) {
162 FIXME("Not enough bytes in buffer (%ld)?\n",msg->cbBuffer);
165 memcpy(&iid,msg->Buffer,sizeof(iid));
166 TRACE("->CreateInstance(%s)\n",debugstr_guid(&iid));
167 hres = IUnknown_QueryInterface(This->pUnkServer,&IID_IClassFactory,(LPVOID*)&classfac);
169 FIXME("Ole server does not provide an IClassFactory?\n");
172 hres = IClassFactory_CreateInstance(classfac,NULL,&iid,(LPVOID*)&ppv);
173 IClassFactory_Release(classfac);
176 FIXME("Failed to create an instance of %s\n",debugstr_guid(&iid));
179 hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
181 FIXME("Failed to create stream on hglobal\n");
184 hres = CoMarshalInterface(pStm,&iid,ppv,0,NULL,0);
185 IUnknown_Release((IUnknown*)ppv);
187 FIXME("CoMarshalInterface failed, %lx!\n",hres);
191 hres = IStream_Stat(pStm,&ststg,0);
193 FIXME("Stat failed.\n");
197 msg->cbBuffer = ststg.cbSize.u.LowPart;
199 I_RpcGetBuffer((RPC_MESSAGE *)msg);
200 if (hres) return hres;
202 seekto.u.LowPart = 0;seekto.u.HighPart = 0;
203 hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
205 FIXME("IStream_Seek failed, %lx\n",hres);
208 hres = IStream_Read(pStm,msg->Buffer,msg->cbBuffer,&res);
210 FIXME("Stream Read failed, %lx\n",hres);
213 IStream_Release(pStm);
216 FIXME("(%p,%p), stub!\n",msg,chanbuf);
217 FIXME("iMethod is %ld\n",msg->iMethod);
218 FIXME("cbBuffer is %ld\n",msg->cbBuffer);
222 static LPRPCSTUBBUFFER WINAPI
223 CFStub_IsIIDSupported(LPRPCSTUBBUFFER iface,REFIID riid) {
224 FIXME("(%s), stub!\n",debugstr_guid(riid));
229 CFStub_CountRefs(LPRPCSTUBBUFFER iface) {
230 FIXME("(), stub!\n");
234 static HRESULT WINAPI
235 CFStub_DebugServerQueryInterface(LPRPCSTUBBUFFER iface,void** ppv) {
236 FIXME("(%p), stub!\n",ppv);
240 CFStub_DebugServerRelease(LPRPCSTUBBUFFER iface,void *pv) {
241 FIXME("(%p), stub!\n",pv);
244 static const IRpcStubBufferVtbl cfstubvt = {
245 CFStub_QueryInterface,
251 CFStub_IsIIDSupported,
253 CFStub_DebugServerQueryInterface,
254 CFStub_DebugServerRelease
258 CFStub_Construct(LPRPCSTUBBUFFER *ppv) {
260 cfstub = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(CFStub));
262 return E_OUTOFMEMORY;
263 *ppv = (LPRPCSTUBBUFFER)cfstub;
264 cfstub->lpvtbl = &cfstubvt;
269 /* Since we create proxy buffers and classfactory in a pair, there is
270 * no need for 2 separate structs. Just put them in one, but remember
273 typedef struct _CFProxy {
274 const IClassFactoryVtbl *lpvtbl_cf;
275 const IRpcProxyBufferVtbl *lpvtbl_proxy;
278 IRpcChannelBuffer *chanbuf;
279 IUnknown *outer_unknown;
282 static HRESULT WINAPI IRpcProxyBufferImpl_QueryInterface(LPRPCPROXYBUFFER iface,REFIID riid,LPVOID *ppv) {
284 if (IsEqualIID(riid,&IID_IRpcProxyBuffer)||IsEqualIID(riid,&IID_IUnknown)) {
285 IRpcProxyBuffer_AddRef(iface);
286 *ppv = (LPVOID)iface;
289 FIXME("(%s), no interface.\n",debugstr_guid(riid));
290 return E_NOINTERFACE;
293 static ULONG WINAPI IRpcProxyBufferImpl_AddRef(LPRPCPROXYBUFFER iface) {
294 ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
295 return InterlockedIncrement(&This->ref);
298 static ULONG WINAPI IRpcProxyBufferImpl_Release(LPRPCPROXYBUFFER iface) {
299 ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
300 ULONG ref = InterlockedDecrement(&This->ref);
303 IRpcProxyBuffer_Disconnect(iface);
304 HeapFree(GetProcessHeap(),0,This);
309 static HRESULT WINAPI IRpcProxyBufferImpl_Connect(LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer) {
310 ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
312 This->chanbuf = pRpcChannelBuffer;
313 IRpcChannelBuffer_AddRef(This->chanbuf);
316 static void WINAPI IRpcProxyBufferImpl_Disconnect(LPRPCPROXYBUFFER iface) {
317 ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
319 IRpcChannelBuffer_Release(This->chanbuf);
320 This->chanbuf = NULL;
324 static HRESULT WINAPI
325 CFProxy_QueryInterface(LPCLASSFACTORY iface,REFIID riid, LPVOID *ppv) {
326 ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
327 if (This->outer_unknown) return IUnknown_QueryInterface(This->outer_unknown, riid, ppv);
329 if (IsEqualIID(&IID_IClassFactory,riid) || IsEqualIID(&IID_IUnknown,riid)) {
330 *ppv = (LPVOID)iface;
331 IClassFactory_AddRef(iface);
334 if (IsEqualIID(riid,&IID_IMarshal)) /* just to avoid debug output */
335 return E_NOINTERFACE;
336 FIXME("Unhandled interface: %s\n",debugstr_guid(riid));
337 return E_NOINTERFACE;
340 static ULONG WINAPI CFProxy_AddRef(LPCLASSFACTORY iface) {
341 ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
342 if (This->outer_unknown) return IUnknown_AddRef(This->outer_unknown);
343 return InterlockedIncrement(&This->ref);
346 static ULONG WINAPI CFProxy_Release(LPCLASSFACTORY iface) {
347 ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
348 if (This->outer_unknown)
349 return IUnknown_Release(This->outer_unknown);
351 return IRpcProxyBufferImpl_Release((IRpcProxyBuffer *)&This->lpvtbl_proxy);
354 static HRESULT WINAPI CFProxy_CreateInstance(
355 LPCLASSFACTORY iface,
356 LPUNKNOWN pUnkOuter,/* [in] */
357 REFIID riid, /* [in] */
358 LPVOID *ppv /* [out] */
360 ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
367 TRACE("(%p,%s,%p)\n",pUnkOuter,debugstr_guid(riid),ppv);
369 /* Send CreateInstance to the remote classfactory.
371 * Data: Only the 'IID'.
374 msg.cbBuffer = sizeof(*riid);
376 hres = IRpcChannelBuffer_GetBuffer(This->chanbuf,&msg,&IID_IClassFactory);
378 FIXME("IRpcChannelBuffer_GetBuffer failed with %lx?\n",hres);
381 memcpy(msg.Buffer,riid,sizeof(*riid));
382 hres = IRpcChannelBuffer_SendReceive(This->chanbuf,&msg,&srstatus);
384 FIXME("IRpcChannelBuffer_SendReceive failed with %lx?\n",hres);
388 if (!msg.cbBuffer) /* interface not found on remote */
391 /* We got back: [Marshalled Interface data] */
392 TRACE("got %ld bytes data.\n",msg.cbBuffer);
393 hGlobal = GlobalAlloc(GMEM_MOVEABLE|GMEM_NODISCARD|GMEM_SHARE,msg.cbBuffer);
394 memcpy(GlobalLock(hGlobal),msg.Buffer,msg.cbBuffer);
395 hres = CreateStreamOnHGlobal(hGlobal,TRUE,&pStream);
397 FIXME("CreateStreamOnHGlobal failed with %lx\n",hres);
400 hres = CoUnmarshalInterface(
405 IStream_Release(pStream); /* Does GlobalFree hGlobal too. */
407 FIXME("CoMarshalInterface failed, %lx\n",hres);
413 static HRESULT WINAPI CFProxy_LockServer(LPCLASSFACTORY iface,BOOL fLock) {
414 /*ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);*/
415 FIXME("(%d), stub!\n",fLock);
416 /* basically: write BOOL, read empty */
420 static const IRpcProxyBufferVtbl pspbvtbl = {
421 IRpcProxyBufferImpl_QueryInterface,
422 IRpcProxyBufferImpl_AddRef,
423 IRpcProxyBufferImpl_Release,
424 IRpcProxyBufferImpl_Connect,
425 IRpcProxyBufferImpl_Disconnect
427 static const IClassFactoryVtbl cfproxyvt = {
428 CFProxy_QueryInterface,
431 CFProxy_CreateInstance,
436 CFProxy_Construct(IUnknown *pUnkOuter, LPVOID *ppv,LPVOID *ppProxy) {
439 cf = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(CFProxy));
441 return E_OUTOFMEMORY;
443 cf->lpvtbl_cf = &cfproxyvt;
444 cf->lpvtbl_proxy = &pspbvtbl;
445 /* one reference for the proxy buffer */
447 cf->outer_unknown = pUnkOuter;
448 *ppv = &(cf->lpvtbl_cf);
449 *ppProxy = &(cf->lpvtbl_proxy);
450 /* and one reference for the object */
451 IUnknown_AddRef((IUnknown *)*ppv);
456 /********************* IRemUnknown Proxy/Stub ********************************/
460 const IRpcStubBufferVtbl *lpVtbl;
465 static HRESULT WINAPI RemUnkStub_QueryInterface(LPRPCSTUBBUFFER iface,
469 RemUnkStub *This = (RemUnkStub *)iface;
470 TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(riid),obj);
471 if (IsEqualGUID(&IID_IUnknown,riid) ||
472 IsEqualGUID(&IID_IRpcStubBuffer,riid)) {
476 return E_NOINTERFACE;
479 static ULONG WINAPI RemUnkStub_AddRef(LPRPCSTUBBUFFER iface)
481 RemUnkStub *This = (RemUnkStub *)iface;
482 TRACE("(%p)->AddRef()\n",This);
483 return InterlockedIncrement(&This->refs);
486 static ULONG WINAPI RemUnkStub_Release(LPRPCSTUBBUFFER iface)
488 RemUnkStub *This = (RemUnkStub *)iface;
490 TRACE("(%p)->Release()\n",This);
491 refs = InterlockedDecrement(&This->refs);
493 HeapFree(GetProcessHeap(), 0, This);
497 static HRESULT WINAPI RemUnkStub_Connect(LPRPCSTUBBUFFER iface,
498 LPUNKNOWN lpUnkServer)
500 RemUnkStub *This = (RemUnkStub *)iface;
501 TRACE("(%p)->Connect(%p)\n",This,lpUnkServer);
502 This->iface = (IRemUnknown*)lpUnkServer;
503 IRemUnknown_AddRef(This->iface);
507 static void WINAPI RemUnkStub_Disconnect(LPRPCSTUBBUFFER iface)
509 RemUnkStub *This = (RemUnkStub *)iface;
510 TRACE("(%p)->Disconnect()\n",This);
511 IUnknown_Release(This->iface);
515 static HRESULT WINAPI RemUnkStub_Invoke(LPRPCSTUBBUFFER iface,
517 LPRPCCHANNELBUFFER pChannel)
519 RemUnkStub *This = (RemUnkStub *)iface;
520 ULONG iMethod = pMsg->iMethod;
521 LPBYTE buf = pMsg->Buffer;
522 HRESULT hr = RPC_E_INVALIDMETHOD;
524 TRACE("(%p)->Invoke(%p,%p) method %ld\n", This, pMsg, pChannel, iMethod);
527 case 3: /* RemQueryInterface */
533 REMQIRESULT *pQIResults = NULL;
536 memcpy(&ipid, buf, sizeof(ipid));
538 memcpy(&cRefs, buf, sizeof(cRefs));
539 buf += sizeof(cRefs);
540 memcpy(&cIids, buf, sizeof(cIids));
541 buf += sizeof(cIids);
544 hr = IRemUnknown_RemQueryInterface(This->iface, &ipid, cRefs, cIids, iids, &pQIResults);
547 pMsg->cbBuffer = cIids * sizeof(REMQIRESULT) + sizeof(HRESULT);
549 I_RpcGetBuffer((RPC_MESSAGE *)pMsg);
552 *(HRESULT *)buf = hr;
553 buf += sizeof(HRESULT);
556 /* FIXME: pQIResults is a unique pointer so pQIResults can be NULL! */
557 memcpy(buf, pQIResults, cIids * sizeof(REMQIRESULT));
561 case 4: /* RemAddRef */
568 memcpy(&cIids, buf, sizeof(USHORT));
569 buf += sizeof(USHORT);
570 ir = (REMINTERFACEREF*)buf;
571 pResults = CoTaskMemAlloc(cIids * sizeof(HRESULT));
572 if (!pResults) return E_OUTOFMEMORY;
574 hr = IRemUnknown_RemAddRef(This->iface, cIids, ir, pResults);
577 pMsg->cbBuffer = cIids * sizeof(HRESULT);
579 I_RpcGetBuffer((RPC_MESSAGE *)pMsg);
583 memcpy(buf, pResults, cIids * sizeof(HRESULT));
586 CoTaskMemFree(pResults);
590 case 5: /* RemRelease */
596 memcpy(&cIids, buf, sizeof(USHORT));
597 buf += sizeof(USHORT);
598 ir = (REMINTERFACEREF*)buf;
600 hr = IRemUnknown_RemRelease(This->iface, cIids, ir);
610 static LPRPCSTUBBUFFER WINAPI RemUnkStub_IsIIDSupported(LPRPCSTUBBUFFER iface,
613 RemUnkStub *This = (RemUnkStub *)iface;
614 TRACE("(%p)->IsIIDSupported(%s)\n", This, debugstr_guid(riid));
615 return IsEqualGUID(&IID_IRemUnknown, riid) ? iface : NULL;
618 static ULONG WINAPI RemUnkStub_CountRefs(LPRPCSTUBBUFFER iface)
620 RemUnkStub *This = (RemUnkStub *)iface;
621 FIXME("(%p)->CountRefs()\n", This);
625 static HRESULT WINAPI RemUnkStub_DebugServerQueryInterface(LPRPCSTUBBUFFER iface,
628 RemUnkStub *This = (RemUnkStub *)iface;
629 FIXME("(%p)->DebugServerQueryInterface(%p)\n",This,ppv);
630 return E_NOINTERFACE;
633 static void WINAPI RemUnkStub_DebugServerRelease(LPRPCSTUBBUFFER iface,
636 RemUnkStub *This = (RemUnkStub *)iface;
637 FIXME("(%p)->DebugServerRelease(%p)\n", This, pv);
640 static const IRpcStubBufferVtbl RemUnkStub_VTable =
642 RemUnkStub_QueryInterface,
646 RemUnkStub_Disconnect,
648 RemUnkStub_IsIIDSupported,
649 RemUnkStub_CountRefs,
650 RemUnkStub_DebugServerQueryInterface,
651 RemUnkStub_DebugServerRelease
654 static HRESULT RemUnkStub_Construct(IRpcStubBuffer **ppStub)
656 RemUnkStub *This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
657 if (!This) return E_OUTOFMEMORY;
658 This->lpVtbl = &RemUnkStub_VTable;
661 *ppStub = (IRpcStubBuffer*)This;
666 typedef struct _RemUnkProxy {
667 const IRemUnknownVtbl *lpvtbl_remunk;
668 const IRpcProxyBufferVtbl *lpvtbl_proxy;
671 IRpcChannelBuffer *chan;
672 IUnknown *outer_unknown;
675 static HRESULT WINAPI RemUnkProxy_QueryInterface(LPREMUNKNOWN iface, REFIID riid, void **ppv)
677 RemUnkProxy *This = (RemUnkProxy *)iface;
678 if (This->outer_unknown)
679 return IUnknown_QueryInterface(This->outer_unknown, riid, ppv);
680 if (IsEqualIID(riid, &IID_IUnknown) ||
681 IsEqualIID(riid, &IID_IRemUnknown))
683 IRemUnknown_AddRef(iface);
684 *ppv = (LPVOID)iface;
687 return E_NOINTERFACE;
690 static ULONG WINAPI RemUnkProxy_AddRef(LPREMUNKNOWN iface)
692 RemUnkProxy *This = (RemUnkProxy *)iface;
695 TRACE("(%p)->AddRef()\n",This);
697 if (This->outer_unknown)
698 refs = IUnknown_AddRef(This->outer_unknown);
700 refs = InterlockedIncrement(&This->refs);
704 static ULONG WINAPI RemUnkProxy_Release(LPREMUNKNOWN iface)
706 RemUnkProxy *This = (RemUnkProxy *)iface;
708 TRACE("(%p)->Release()\n",This);
709 if (This->outer_unknown)
710 return IUnknown_Release(This->outer_unknown);
712 return IRpcProxyBufferImpl_Release((IRpcProxyBuffer *)&This->lpvtbl_proxy);
715 static HRESULT WINAPI RemUnkProxy_RemQueryInterface(LPREMUNKNOWN iface,
720 REMQIRESULT** ppQIResults)
722 RemUnkProxy *This = (RemUnkProxy *)iface;
727 TRACE("(%p)->(%s,%ld,%d,%p,%p)\n",This,
728 debugstr_guid(ripid),cRefs,cIids,iids,ppQIResults);
731 memset(&msg, 0, sizeof(msg));
733 msg.cbBuffer = sizeof(IPID) + sizeof(ULONG) +
734 sizeof(USHORT) + cIids*sizeof(IID);
735 hr = IRpcChannelBuffer_GetBuffer(This->chan, &msg, &IID_IRemUnknown);
737 LPBYTE buf = msg.Buffer;
738 memcpy(buf, ripid, sizeof(IPID));
740 memcpy(buf, &cRefs, sizeof(ULONG));
741 buf += sizeof(ULONG);
742 memcpy(buf, &cIids, sizeof(USHORT));
743 buf += sizeof(USHORT);
744 memcpy(buf, iids, cIids*sizeof(IID));
746 hr = IRpcChannelBuffer_SendReceive(This->chan, &msg, &status);
751 hr = *(HRESULT *)buf;
752 buf += sizeof(HRESULT);
756 *ppQIResults = CoTaskMemAlloc(cIids*sizeof(REMQIRESULT));
757 memcpy(*ppQIResults, buf, cIids*sizeof(REMQIRESULT));
760 IRpcChannelBuffer_FreeBuffer(This->chan, &msg);
766 static HRESULT WINAPI RemUnkProxy_RemAddRef(LPREMUNKNOWN iface,
767 USHORT cInterfaceRefs,
768 REMINTERFACEREF* InterfaceRefs,
771 RemUnkProxy *This = (RemUnkProxy *)iface;
776 TRACE("(%p)->(%d,%p,%p)\n",This,
777 cInterfaceRefs,InterfaceRefs,pResults);
779 memset(&msg, 0, sizeof(msg));
781 msg.cbBuffer = sizeof(USHORT) + cInterfaceRefs*sizeof(REMINTERFACEREF);
782 hr = IRpcChannelBuffer_GetBuffer(This->chan, &msg, &IID_IRemUnknown);
784 LPBYTE buf = msg.Buffer;
785 memcpy(buf, &cInterfaceRefs, sizeof(USHORT));
786 buf += sizeof(USHORT);
787 memcpy(buf, InterfaceRefs, cInterfaceRefs*sizeof(REMINTERFACEREF));
789 hr = IRpcChannelBuffer_SendReceive(This->chan, &msg, &status);
793 memcpy(pResults, buf, cInterfaceRefs*sizeof(HRESULT));
796 IRpcChannelBuffer_FreeBuffer(This->chan, &msg);
802 static HRESULT WINAPI RemUnkProxy_RemRelease(LPREMUNKNOWN iface,
803 USHORT cInterfaceRefs,
804 REMINTERFACEREF* InterfaceRefs)
806 RemUnkProxy *This = (RemUnkProxy *)iface;
811 TRACE("(%p)->(%d,%p)\n",This,
812 cInterfaceRefs,InterfaceRefs);
814 memset(&msg, 0, sizeof(msg));
816 msg.cbBuffer = sizeof(USHORT) + cInterfaceRefs*sizeof(REMINTERFACEREF);
817 hr = IRpcChannelBuffer_GetBuffer(This->chan, &msg, &IID_IRemUnknown);
819 LPBYTE buf = msg.Buffer;
820 memcpy(buf, &cInterfaceRefs, sizeof(USHORT));
821 buf += sizeof(USHORT);
822 memcpy(buf, InterfaceRefs, cInterfaceRefs*sizeof(REMINTERFACEREF));
824 hr = IRpcChannelBuffer_SendReceive(This->chan, &msg, &status);
826 IRpcChannelBuffer_FreeBuffer(This->chan, &msg);
832 static const IRemUnknownVtbl RemUnkProxy_VTable =
834 RemUnkProxy_QueryInterface,
837 RemUnkProxy_RemQueryInterface,
838 RemUnkProxy_RemAddRef,
839 RemUnkProxy_RemRelease
843 static HRESULT WINAPI RURpcProxyBufferImpl_QueryInterface(LPRPCPROXYBUFFER iface,REFIID riid,LPVOID *ppv) {
845 if (IsEqualIID(riid,&IID_IRpcProxyBuffer)||IsEqualIID(riid,&IID_IUnknown)) {
846 IRpcProxyBuffer_AddRef(iface);
847 *ppv = (LPVOID)iface;
850 FIXME("(%s), no interface.\n",debugstr_guid(riid));
851 return E_NOINTERFACE;
854 static ULONG WINAPI RURpcProxyBufferImpl_AddRef(LPRPCPROXYBUFFER iface) {
855 ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
856 TRACE("%p, %ld\n", iface, This->refs + 1);
857 return InterlockedIncrement(&This->refs);
860 static ULONG WINAPI RURpcProxyBufferImpl_Release(LPRPCPROXYBUFFER iface) {
861 ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
862 ULONG ref = InterlockedDecrement(&This->refs);
863 TRACE("%p, %ld\n", iface, ref);
865 IRpcProxyBuffer_Disconnect(iface);
866 HeapFree(GetProcessHeap(),0,This);
871 static HRESULT WINAPI RURpcProxyBufferImpl_Connect(LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer) {
872 ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
874 TRACE("%p, %p\n", iface, pRpcChannelBuffer);
875 This->chan = pRpcChannelBuffer;
876 IRpcChannelBuffer_AddRef(This->chan);
879 static void WINAPI RURpcProxyBufferImpl_Disconnect(LPRPCPROXYBUFFER iface) {
880 ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
881 TRACE("%p, %p\n", iface, This->chan);
883 IRpcChannelBuffer_Release(This->chan);
889 static const IRpcProxyBufferVtbl RURpcProxyBuffer_VTable = {
890 RURpcProxyBufferImpl_QueryInterface,
891 RURpcProxyBufferImpl_AddRef,
892 RURpcProxyBufferImpl_Release,
893 RURpcProxyBufferImpl_Connect,
894 RURpcProxyBufferImpl_Disconnect
898 RemUnkProxy_Construct(IUnknown *pUnkOuter, LPVOID *ppv,LPVOID *ppProxy) {
901 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*This));
903 return E_OUTOFMEMORY;
905 This->lpvtbl_remunk = &RemUnkProxy_VTable;
906 This->lpvtbl_proxy = &RURpcProxyBuffer_VTable;
907 /* only one reference for the proxy buffer */
909 This->outer_unknown = pUnkOuter;
910 *ppv = &(This->lpvtbl_remunk);
911 *ppProxy = &(This->lpvtbl_proxy);
912 /* and one reference for the object */
913 IUnknown_AddRef((IUnknown *)*ppv);
918 /********************* OLE Proxy/Stub Factory ********************************/
919 static HRESULT WINAPI
920 PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface, REFIID iid, LPVOID *ppv) {
921 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)||IsEqualIID(iid,&IID_IUnknown)) {
922 *ppv = (LPVOID)iface;
923 /* No ref counting, static class */
926 FIXME("(%s) unknown IID?\n",debugstr_guid(iid));
927 return E_NOINTERFACE;
930 static ULONG WINAPI PSFacBuf_AddRef(LPPSFACTORYBUFFER iface) { return 2; }
931 static ULONG WINAPI PSFacBuf_Release(LPPSFACTORYBUFFER iface) { return 1; }
933 static HRESULT WINAPI
934 PSFacBuf_CreateProxy(
935 LPPSFACTORYBUFFER iface, IUnknown* pUnkOuter, REFIID riid,
936 IRpcProxyBuffer **ppProxy, LPVOID *ppv
938 if (IsEqualIID(&IID_IClassFactory,riid))
939 return CFProxy_Construct(pUnkOuter, ppv,(LPVOID*)ppProxy);
940 else if (IsEqualIID(&IID_IRemUnknown,riid))
941 return RemUnkProxy_Construct(pUnkOuter, ppv,(LPVOID*)ppProxy);
942 FIXME("proxying not implemented for (%s) yet!\n",debugstr_guid(riid));
946 static HRESULT WINAPI
948 LPPSFACTORYBUFFER iface, REFIID riid,IUnknown *pUnkServer,
949 IRpcStubBuffer** ppStub
953 TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub);
955 if (IsEqualIID(&IID_IClassFactory, riid) ||
956 IsEqualIID(&IID_IUnknown, riid) /* FIXME: fixup stub manager and remove this*/) {
957 hres = CFStub_Construct(ppStub);
959 IRpcStubBuffer_Connect((*ppStub),pUnkServer);
961 } else if (IsEqualIID(&IID_IRemUnknown,riid)) {
962 hres = RemUnkStub_Construct(ppStub);
964 IRpcStubBuffer_Connect((*ppStub),pUnkServer);
967 FIXME("stubbing not implemented for (%s) yet!\n",debugstr_guid(riid));
971 static const IPSFactoryBufferVtbl psfacbufvtbl = {
972 PSFacBuf_QueryInterface,
975 PSFacBuf_CreateProxy,
979 /* This is the whole PSFactoryBuffer object, just the vtableptr */
980 static const IPSFactoryBufferVtbl *lppsfac = &psfacbufvtbl;
982 /***********************************************************************
983 * DllGetClassObject [OLE32.@]
985 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
988 if (IsEqualIID(rclsid, &CLSID_PSFactoryBuffer))
989 return IPSFactoryBuffer_QueryInterface((IPSFactoryBuffer *)&lppsfac, iid, ppv);
990 if (IsEqualIID(rclsid,&CLSID_DfMarshal)&&(
991 IsEqualIID(iid,&IID_IClassFactory) ||
992 IsEqualIID(iid,&IID_IUnknown)
995 return MARSHAL_GetStandardMarshalCF(ppv);
996 if (IsEqualIID(rclsid,&CLSID_StdGlobalInterfaceTable) && (IsEqualIID(iid,&IID_IClassFactory) || IsEqualIID(iid,&IID_IUnknown)))
997 return StdGlobalInterfaceTable_GetFactory(ppv);
998 if (IsEqualCLSID(rclsid, &CLSID_FileMoniker))
999 return FileMonikerCF_Create(iid, ppv);
1000 if (IsEqualCLSID(rclsid, &CLSID_ItemMoniker))
1001 return ItemMonikerCF_Create(iid, ppv);
1002 if (IsEqualCLSID(rclsid, &CLSID_AntiMoniker))
1003 return AntiMonikerCF_Create(iid, ppv);
1004 if (IsEqualCLSID(rclsid, &CLSID_CompositeMoniker))
1005 return CompositeMonikerCF_Create(iid, ppv);
1006 if (IsEqualCLSID(rclsid, &CLSID_ClassMoniker))
1007 return ClassMonikerCF_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;