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;
194 msg->Buffer = HeapReAlloc(GetProcessHeap(),0,msg->Buffer,ststg.cbSize.u.LowPart);
196 msg->Buffer = HeapAlloc(GetProcessHeap(),0,ststg.cbSize.u.LowPart);
198 seekto.u.LowPart = 0;seekto.u.HighPart = 0;
199 hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
201 FIXME("IStream_Seek failed, %lx\n",hres);
204 hres = IStream_Read(pStm,msg->Buffer,msg->cbBuffer,&res);
206 FIXME("Stream Read failed, %lx\n",hres);
209 IStream_Release(pStm);
212 FIXME("(%p,%p), stub!\n",msg,chanbuf);
213 FIXME("iMethod is %ld\n",msg->iMethod);
214 FIXME("cbBuffer is %ld\n",msg->cbBuffer);
218 static LPRPCSTUBBUFFER WINAPI
219 CFStub_IsIIDSupported(LPRPCSTUBBUFFER iface,REFIID riid) {
220 FIXME("(%s), stub!\n",debugstr_guid(riid));
225 CFStub_CountRefs(LPRPCSTUBBUFFER iface) {
226 FIXME("(), stub!\n");
230 static HRESULT WINAPI
231 CFStub_DebugServerQueryInterface(LPRPCSTUBBUFFER iface,void** ppv) {
232 FIXME("(%p), stub!\n",ppv);
236 CFStub_DebugServerRelease(LPRPCSTUBBUFFER iface,void *pv) {
237 FIXME("(%p), stub!\n",pv);
240 static IRpcStubBufferVtbl cfstubvt = {
241 CFStub_QueryInterface,
247 CFStub_IsIIDSupported,
249 CFStub_DebugServerQueryInterface,
250 CFStub_DebugServerRelease
254 CFStub_Construct(LPRPCSTUBBUFFER *ppv) {
256 cfstub = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(CFStub));
258 return E_OUTOFMEMORY;
259 *ppv = (LPRPCSTUBBUFFER)cfstub;
260 cfstub->lpvtbl = &cfstubvt;
265 /* Since we create proxy buffers and classfactory in a pair, there is
266 * no need for 2 separate structs. Just put them in one, but remember
269 typedef struct _CFProxy {
270 const IClassFactoryVtbl *lpvtbl_cf;
271 const IRpcProxyBufferVtbl *lpvtbl_proxy;
274 IRpcChannelBuffer *chanbuf;
275 IUnknown *outer_unknown;
278 static HRESULT WINAPI IRpcProxyBufferImpl_QueryInterface(LPRPCPROXYBUFFER iface,REFIID riid,LPVOID *ppv) {
280 if (IsEqualIID(riid,&IID_IRpcProxyBuffer)||IsEqualIID(riid,&IID_IUnknown)) {
281 IRpcProxyBuffer_AddRef(iface);
282 *ppv = (LPVOID)iface;
285 FIXME("(%s), no interface.\n",debugstr_guid(riid));
286 return E_NOINTERFACE;
289 static ULONG WINAPI IRpcProxyBufferImpl_AddRef(LPRPCPROXYBUFFER iface) {
290 ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
291 return InterlockedIncrement(&This->ref);
294 static ULONG WINAPI IRpcProxyBufferImpl_Release(LPRPCPROXYBUFFER iface) {
295 ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
296 ULONG ref = InterlockedDecrement(&This->ref);
299 IRpcChannelBuffer_Release(This->chanbuf);This->chanbuf = NULL;
300 HeapFree(GetProcessHeap(),0,This);
305 static HRESULT WINAPI IRpcProxyBufferImpl_Connect(LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer) {
306 ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
308 This->chanbuf = pRpcChannelBuffer;
309 IRpcChannelBuffer_AddRef(This->chanbuf);
312 static void WINAPI IRpcProxyBufferImpl_Disconnect(LPRPCPROXYBUFFER iface) {
313 ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
315 IRpcChannelBuffer_Release(This->chanbuf);
316 This->chanbuf = NULL;
320 static HRESULT WINAPI
321 CFProxy_QueryInterface(LPCLASSFACTORY iface,REFIID riid, LPVOID *ppv) {
322 ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
323 if (This->outer_unknown) return IUnknown_QueryInterface(This->outer_unknown, riid, ppv);
325 if (IsEqualIID(&IID_IClassFactory,riid) || IsEqualIID(&IID_IUnknown,riid)) {
326 *ppv = (LPVOID)iface;
327 IClassFactory_AddRef(iface);
330 if (IsEqualIID(riid,&IID_IMarshal)) /* just to avoid debug output */
331 return E_NOINTERFACE;
332 FIXME("Unhandled interface: %s\n",debugstr_guid(riid));
333 return E_NOINTERFACE;
336 static ULONG WINAPI CFProxy_AddRef(LPCLASSFACTORY iface) {
337 ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
338 if (This->outer_unknown) return IUnknown_AddRef(This->outer_unknown);
339 return InterlockedIncrement(&This->ref);
342 static ULONG WINAPI CFProxy_Release(LPCLASSFACTORY iface) {
344 ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
345 if (This->outer_unknown)
346 ref = IUnknown_Release(This->outer_unknown);
348 ref = InterlockedDecrement(&This->ref);
351 if (This->chanbuf) IRpcChannelBuffer_Release(This->chanbuf);
352 HeapFree(GetProcessHeap(),0,This);
357 static HRESULT WINAPI CFProxy_CreateInstance(
358 LPCLASSFACTORY iface,
359 LPUNKNOWN pUnkOuter,/* [in] */
360 REFIID riid, /* [in] */
361 LPVOID *ppv /* [out] */
363 ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
370 TRACE("(%p,%s,%p)\n",pUnkOuter,debugstr_guid(riid),ppv);
372 /* Send CreateInstance to the remote classfactory.
374 * Data: Only the 'IID'.
377 msg.cbBuffer = sizeof(*riid);
379 hres = IRpcChannelBuffer_GetBuffer(This->chanbuf,&msg,&IID_IClassFactory);
381 FIXME("IRpcChannelBuffer_GetBuffer failed with %lx?\n",hres);
384 memcpy(msg.Buffer,riid,sizeof(*riid));
385 hres = IRpcChannelBuffer_SendReceive(This->chanbuf,&msg,&srstatus);
387 FIXME("IRpcChannelBuffer_SendReceive failed with %lx?\n",hres);
391 if (!msg.cbBuffer) /* interface not found on remote */
394 /* We got back: [Marshalled Interface data] */
395 TRACE("got %ld bytes data.\n",msg.cbBuffer);
396 hGlobal = GlobalAlloc(GMEM_MOVEABLE|GMEM_NODISCARD|GMEM_SHARE,msg.cbBuffer);
397 memcpy(GlobalLock(hGlobal),msg.Buffer,msg.cbBuffer);
398 hres = CreateStreamOnHGlobal(hGlobal,TRUE,&pStream);
400 FIXME("CreateStreamOnHGlobal failed with %lx\n",hres);
403 hres = CoUnmarshalInterface(
408 IStream_Release(pStream); /* Does GlobalFree hGlobal too. */
410 FIXME("CoMarshalInterface failed, %lx\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 IRpcProxyBufferVtbl pspbvtbl = {
424 IRpcProxyBufferImpl_QueryInterface,
425 IRpcProxyBufferImpl_AddRef,
426 IRpcProxyBufferImpl_Release,
427 IRpcProxyBufferImpl_Connect,
428 IRpcProxyBufferImpl_Disconnect
430 static 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 /* only one reference for the proxy buffer */
450 cf->outer_unknown = pUnkOuter;
451 *ppv = &(cf->lpvtbl_cf);
452 *ppProxy = &(cf->lpvtbl_proxy);
457 /********************* IRemUnknown Proxy/Stub ********************************/
461 const IRpcStubBufferVtbl *lpVtbl;
466 static HRESULT WINAPI RemUnkStub_QueryInterface(LPRPCSTUBBUFFER iface,
470 RemUnkStub *This = (RemUnkStub *)iface;
471 TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(riid),obj);
472 if (IsEqualGUID(&IID_IUnknown,riid) ||
473 IsEqualGUID(&IID_IRpcStubBuffer,riid)) {
477 return E_NOINTERFACE;
480 static ULONG WINAPI RemUnkStub_AddRef(LPRPCSTUBBUFFER iface)
482 RemUnkStub *This = (RemUnkStub *)iface;
483 TRACE("(%p)->AddRef()\n",This);
484 return InterlockedIncrement(&This->refs);
487 static ULONG WINAPI RemUnkStub_Release(LPRPCSTUBBUFFER iface)
489 RemUnkStub *This = (RemUnkStub *)iface;
491 TRACE("(%p)->Release()\n",This);
492 refs = InterlockedDecrement(&This->refs);
494 HeapFree(GetProcessHeap(), 0, This);
498 static HRESULT WINAPI RemUnkStub_Connect(LPRPCSTUBBUFFER iface,
499 LPUNKNOWN lpUnkServer)
501 RemUnkStub *This = (RemUnkStub *)iface;
502 TRACE("(%p)->Connect(%p)\n",This,lpUnkServer);
503 This->iface = (IRemUnknown*)lpUnkServer;
504 IRemUnknown_AddRef(This->iface);
508 static void WINAPI RemUnkStub_Disconnect(LPRPCSTUBBUFFER iface)
510 RemUnkStub *This = (RemUnkStub *)iface;
511 TRACE("(%p)->Disconnect()\n",This);
512 IUnknown_Release(This->iface);
516 static HRESULT WINAPI RemUnkStub_Invoke(LPRPCSTUBBUFFER iface,
518 LPRPCCHANNELBUFFER pChannel)
520 RemUnkStub *This = (RemUnkStub *)iface;
521 ULONG iMethod = pMsg->iMethod;
522 LPBYTE buf = pMsg->Buffer;
523 HRESULT hr = RPC_E_INVALIDMETHOD;
525 TRACE("(%p)->Invoke(%p,%p) method %ld\n", This, pMsg, pChannel, iMethod);
528 case 3: /* RemQueryInterface */
534 REMQIRESULT *pQIResults = NULL;
537 memcpy(&ipid, buf, sizeof(ipid));
539 memcpy(&cRefs, buf, sizeof(cRefs));
540 buf += sizeof(cRefs);
541 memcpy(&cIids, buf, sizeof(cIids));
542 buf += sizeof(cIids);
545 hr = IRemUnknown_RemQueryInterface(This->iface, &ipid, cRefs, cIids, iids, &pQIResults);
548 pMsg->cbBuffer = cIids * sizeof(REMQIRESULT);
550 pMsg->Buffer = HeapReAlloc(GetProcessHeap(), 0, pMsg->Buffer, pMsg->cbBuffer);
552 pMsg->Buffer = HeapAlloc(GetProcessHeap(), 0, pMsg->cbBuffer);
554 /* FIXME: pQIResults is a unique pointer so pQIResults can be NULL! */
555 memcpy(buf, pQIResults, cIids * sizeof(REMQIRESULT));
559 case 4: /* RemAddRef */
566 memcpy(&cIids, buf, sizeof(USHORT));
567 buf += sizeof(USHORT);
568 ir = (REMINTERFACEREF*)buf;
569 pResults = CoTaskMemAlloc(cIids * sizeof(HRESULT));
570 if (!pResults) return E_OUTOFMEMORY;
572 hr = IRemUnknown_RemAddRef(This->iface, cIids, ir, pResults);
575 pMsg->cbBuffer = cIids * sizeof(HRESULT);
577 pMsg->Buffer = HeapReAlloc(GetProcessHeap(), 0, pMsg->Buffer, pMsg->cbBuffer);
579 pMsg->Buffer = HeapAlloc(GetProcessHeap(), 0, pMsg->cbBuffer);
581 memcpy(buf, pResults, cIids * sizeof(HRESULT));
583 CoTaskMemFree(pResults);
587 case 5: /* RemRelease */
593 memcpy(&cIids, buf, sizeof(USHORT));
594 buf += sizeof(USHORT);
595 ir = (REMINTERFACEREF*)buf;
597 hr = IRemUnknown_RemRelease(This->iface, cIids, ir);
607 static LPRPCSTUBBUFFER WINAPI RemUnkStub_IsIIDSupported(LPRPCSTUBBUFFER iface,
610 RemUnkStub *This = (RemUnkStub *)iface;
611 TRACE("(%p)->IsIIDSupported(%s)\n", This, debugstr_guid(riid));
612 return IsEqualGUID(&IID_IRemUnknown, riid) ? iface : NULL;
615 static ULONG WINAPI RemUnkStub_CountRefs(LPRPCSTUBBUFFER iface)
617 RemUnkStub *This = (RemUnkStub *)iface;
618 FIXME("(%p)->CountRefs()\n", This);
622 static HRESULT WINAPI RemUnkStub_DebugServerQueryInterface(LPRPCSTUBBUFFER iface,
625 RemUnkStub *This = (RemUnkStub *)iface;
626 FIXME("(%p)->DebugServerQueryInterface(%p)\n",This,ppv);
627 return E_NOINTERFACE;
630 static void WINAPI RemUnkStub_DebugServerRelease(LPRPCSTUBBUFFER iface,
633 RemUnkStub *This = (RemUnkStub *)iface;
634 FIXME("(%p)->DebugServerRelease(%p)\n", This, pv);
637 static const IRpcStubBufferVtbl RemUnkStub_VTable =
639 RemUnkStub_QueryInterface,
643 RemUnkStub_Disconnect,
645 RemUnkStub_IsIIDSupported,
646 RemUnkStub_CountRefs,
647 RemUnkStub_DebugServerQueryInterface,
648 RemUnkStub_DebugServerRelease
651 static HRESULT RemUnkStub_Construct(IRpcStubBuffer **ppStub)
653 RemUnkStub *This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
654 if (!This) return E_OUTOFMEMORY;
655 This->lpVtbl = &RemUnkStub_VTable;
658 *ppStub = (IRpcStubBuffer*)This;
663 typedef struct _RemUnkProxy {
664 const IRemUnknownVtbl *lpvtbl_remunk;
665 const IRpcProxyBufferVtbl *lpvtbl_proxy;
668 IRpcChannelBuffer *chan;
669 IUnknown *outer_unknown;
672 static HRESULT WINAPI RemUnkProxy_QueryInterface(LPREMUNKNOWN iface, REFIID riid, void **ppv)
674 RemUnkProxy *This = (RemUnkProxy *)iface;
675 if (This->outer_unknown)
676 return IUnknown_QueryInterface(This->outer_unknown, riid, ppv);
677 if (IsEqualIID(riid, &IID_IUnknown) ||
678 IsEqualIID(riid, &IID_IRemUnknown))
680 IRemUnknown_AddRef(iface);
681 *ppv = (LPVOID)iface;
684 return E_NOINTERFACE;
687 static ULONG WINAPI RemUnkProxy_AddRef(LPREMUNKNOWN iface)
689 RemUnkProxy *This = (RemUnkProxy *)iface;
691 TRACE("(%p)->AddRef()\n",This);
692 return InterlockedIncrement(&This->refs);
695 static ULONG WINAPI RemUnkProxy_Release(LPREMUNKNOWN iface)
697 RemUnkProxy *This = (RemUnkProxy *)iface;
700 TRACE("(%p)->Release()\n",This);
701 if (This->outer_unknown)
702 refs = IUnknown_Release(This->outer_unknown);
704 refs = InterlockedDecrement(&This->refs);
707 if (This->chan) IRpcChannelBuffer_Release(This->chan);
708 HeapFree(GetProcessHeap(),0,This);
713 static HRESULT WINAPI RemUnkProxy_RemQueryInterface(LPREMUNKNOWN iface,
718 REMQIRESULT** ppQIResults)
720 RemUnkProxy *This = (RemUnkProxy *)iface;
725 TRACE("(%p)->(%s,%ld,%d,%p,%p)\n",This,
726 debugstr_guid(ripid),cRefs,cIids,iids,ppQIResults);
729 memset(&msg, 0, sizeof(msg));
731 msg.cbBuffer = sizeof(IPID) + sizeof(ULONG) +
732 sizeof(USHORT) + cIids*sizeof(IID);
733 hr = IRpcChannelBuffer_GetBuffer(This->chan, &msg, &IID_IRemUnknown);
735 LPBYTE buf = msg.Buffer;
736 memcpy(buf, ripid, sizeof(IPID));
738 memcpy(buf, &cRefs, sizeof(ULONG));
739 buf += sizeof(ULONG);
740 memcpy(buf, &cIids, sizeof(USHORT));
741 buf += sizeof(USHORT);
742 memcpy(buf, iids, cIids*sizeof(IID));
744 hr = IRpcChannelBuffer_SendReceive(This->chan, &msg, &status);
748 *ppQIResults = CoTaskMemAlloc(cIids*sizeof(REMQIRESULT));
749 memcpy(*ppQIResults, buf, cIids*sizeof(REMQIRESULT));
752 IRpcChannelBuffer_FreeBuffer(This->chan, &msg);
758 static HRESULT WINAPI RemUnkProxy_RemAddRef(LPREMUNKNOWN iface,
759 USHORT cInterfaceRefs,
760 REMINTERFACEREF* InterfaceRefs,
763 RemUnkProxy *This = (RemUnkProxy *)iface;
768 TRACE("(%p)->(%d,%p,%p)\n",This,
769 cInterfaceRefs,InterfaceRefs,pResults);
771 memset(&msg, 0, sizeof(msg));
773 msg.cbBuffer = sizeof(USHORT) + cInterfaceRefs*sizeof(REMINTERFACEREF);
774 hr = IRpcChannelBuffer_GetBuffer(This->chan, &msg, &IID_IRemUnknown);
776 LPBYTE buf = msg.Buffer;
777 memcpy(buf, &cInterfaceRefs, sizeof(USHORT));
778 buf += sizeof(USHORT);
779 memcpy(buf, InterfaceRefs, cInterfaceRefs*sizeof(REMINTERFACEREF));
781 hr = IRpcChannelBuffer_SendReceive(This->chan, &msg, &status);
785 memcpy(pResults, buf, cInterfaceRefs*sizeof(HRESULT));
788 IRpcChannelBuffer_FreeBuffer(This->chan, &msg);
794 static HRESULT WINAPI RemUnkProxy_RemRelease(LPREMUNKNOWN iface,
795 USHORT cInterfaceRefs,
796 REMINTERFACEREF* InterfaceRefs)
798 RemUnkProxy *This = (RemUnkProxy *)iface;
803 TRACE("(%p)->(%d,%p)\n",This,
804 cInterfaceRefs,InterfaceRefs);
806 memset(&msg, 0, sizeof(msg));
808 msg.cbBuffer = sizeof(USHORT) + cInterfaceRefs*sizeof(REMINTERFACEREF);
809 hr = IRpcChannelBuffer_GetBuffer(This->chan, &msg, &IID_IRemUnknown);
811 LPBYTE buf = msg.Buffer;
812 memcpy(buf, &cInterfaceRefs, sizeof(USHORT));
813 buf += sizeof(USHORT);
814 memcpy(buf, InterfaceRefs, cInterfaceRefs*sizeof(REMINTERFACEREF));
816 hr = IRpcChannelBuffer_SendReceive(This->chan, &msg, &status);
818 IRpcChannelBuffer_FreeBuffer(This->chan, &msg);
824 static const IRemUnknownVtbl RemUnkProxy_VTable =
826 RemUnkProxy_QueryInterface,
829 RemUnkProxy_RemQueryInterface,
830 RemUnkProxy_RemAddRef,
831 RemUnkProxy_RemRelease
835 static HRESULT WINAPI RURpcProxyBufferImpl_QueryInterface(LPRPCPROXYBUFFER iface,REFIID riid,LPVOID *ppv) {
837 if (IsEqualIID(riid,&IID_IRpcProxyBuffer)||IsEqualIID(riid,&IID_IUnknown)) {
838 IRpcProxyBuffer_AddRef(iface);
839 *ppv = (LPVOID)iface;
842 FIXME("(%s), no interface.\n",debugstr_guid(riid));
843 return E_NOINTERFACE;
846 static ULONG WINAPI RURpcProxyBufferImpl_AddRef(LPRPCPROXYBUFFER iface) {
847 ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
848 return InterlockedIncrement(&This->refs);
851 static ULONG WINAPI RURpcProxyBufferImpl_Release(LPRPCPROXYBUFFER iface) {
852 ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
853 ULONG ref = InterlockedDecrement(&This->refs);
856 IRpcChannelBuffer_Release(This->chan);This->chan = NULL;
857 HeapFree(GetProcessHeap(),0,This);
862 static HRESULT WINAPI RURpcProxyBufferImpl_Connect(LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer) {
863 ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
865 This->chan = pRpcChannelBuffer;
866 IRpcChannelBuffer_AddRef(This->chan);
869 static void WINAPI RURpcProxyBufferImpl_Disconnect(LPRPCPROXYBUFFER iface) {
870 ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
872 IRpcChannelBuffer_Release(This->chan);
878 static const IRpcProxyBufferVtbl RURpcProxyBuffer_VTable = {
879 RURpcProxyBufferImpl_QueryInterface,
880 RURpcProxyBufferImpl_AddRef,
881 RURpcProxyBufferImpl_Release,
882 RURpcProxyBufferImpl_Connect,
883 RURpcProxyBufferImpl_Disconnect
887 RemUnkProxy_Construct(IUnknown *pUnkOuter, LPVOID *ppv,LPVOID *ppProxy) {
890 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*This));
892 return E_OUTOFMEMORY;
894 This->lpvtbl_remunk = &RemUnkProxy_VTable;
895 This->lpvtbl_proxy = &RURpcProxyBuffer_VTable;
896 /* only one reference for the proxy buffer */
898 This->outer_unknown = pUnkOuter;
899 *ppv = &(This->lpvtbl_remunk);
900 *ppProxy = &(This->lpvtbl_proxy);
905 /********************* OLE Proxy/Stub Factory ********************************/
906 static HRESULT WINAPI
907 PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface, REFIID iid, LPVOID *ppv) {
908 if (IsEqualIID(iid,&IID_IPSFactoryBuffer)||IsEqualIID(iid,&IID_IUnknown)) {
909 *ppv = (LPVOID)iface;
910 /* No ref counting, static class */
913 FIXME("(%s) unknown IID?\n",debugstr_guid(iid));
914 return E_NOINTERFACE;
917 static ULONG WINAPI PSFacBuf_AddRef(LPPSFACTORYBUFFER iface) { return 2; }
918 static ULONG WINAPI PSFacBuf_Release(LPPSFACTORYBUFFER iface) { return 1; }
920 static HRESULT WINAPI
921 PSFacBuf_CreateProxy(
922 LPPSFACTORYBUFFER iface, IUnknown* pUnkOuter, REFIID riid,
923 IRpcProxyBuffer **ppProxy, LPVOID *ppv
925 if (IsEqualIID(&IID_IClassFactory,riid))
926 return CFProxy_Construct(pUnkOuter, ppv,(LPVOID*)ppProxy);
927 else if (IsEqualIID(&IID_IRemUnknown,riid))
928 return RemUnkProxy_Construct(pUnkOuter, ppv,(LPVOID*)ppProxy);
929 FIXME("proxying not implemented for (%s) yet!\n",debugstr_guid(riid));
933 static HRESULT WINAPI
935 LPPSFACTORYBUFFER iface, REFIID riid,IUnknown *pUnkServer,
936 IRpcStubBuffer** ppStub
940 TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub);
942 if (IsEqualIID(&IID_IClassFactory, riid) ||
943 IsEqualIID(&IID_IUnknown, riid) /* FIXME: fixup stub manager and remove this*/) {
944 hres = CFStub_Construct(ppStub);
946 IRpcStubBuffer_Connect((*ppStub),pUnkServer);
948 } else if (IsEqualIID(&IID_IRemUnknown,riid)) {
949 hres = RemUnkStub_Construct(ppStub);
951 IRpcStubBuffer_Connect((*ppStub),pUnkServer);
954 FIXME("stubbing not implemented for (%s) yet!\n",debugstr_guid(riid));
958 static IPSFactoryBufferVtbl psfacbufvtbl = {
959 PSFacBuf_QueryInterface,
962 PSFacBuf_CreateProxy,
966 /* This is the whole PSFactoryBuffer object, just the vtableptr */
967 static IPSFactoryBufferVtbl *lppsfac = &psfacbufvtbl;
969 /***********************************************************************
970 * DllGetClassObject [OLE32.@]
972 HRESULT WINAPI OLE32_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
975 if (IsEqualIID(rclsid,&CLSID_PSFactoryBuffer)) {
979 if (IsEqualIID(rclsid,&CLSID_DfMarshal)&&(
980 IsEqualIID(iid,&IID_IClassFactory) ||
981 IsEqualIID(iid,&IID_IUnknown)
984 return MARSHAL_GetStandardMarshalCF(ppv);
985 if (IsEqualIID(rclsid,&CLSID_StdGlobalInterfaceTable) && (IsEqualIID(iid,&IID_IClassFactory) || IsEqualIID(iid,&IID_IUnknown)))
986 return StdGlobalInterfaceTable_GetFactory(ppv);
988 FIXME("\n\tCLSID:\t%s,\n\tIID:\t%s\n",debugstr_guid(rclsid),debugstr_guid(iid));
989 return CLASS_E_CLASSNOTAVAILABLE;