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"
62 #include "wine/debug.h"
64 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
66 const CLSID CLSID_DfMarshal
= { 0x0000030b, 0, 0, {0xc0, 0, 0, 0, 0, 0, 0, 0x46} };
67 const CLSID CLSID_PSFactoryBuffer
= { 0x00000320, 0, 0, {0xc0, 0, 0, 0, 0, 0, 0, 0x46} };
69 /* From: http://msdn.microsoft.com/library/en-us/com/cmi_m_4lda.asp
71 * The first time a client requests a pointer to an interface on a
72 * particular object, COM loads an IClassFactory stub in the server
73 * process and uses it to marshal the first pointer back to the
74 * client. In the client process, COM loads the generic proxy for the
75 * class factory object and calls its implementation of IMarshal to
76 * unmarshal that first pointer. COM then creates the first interface
77 * proxy and hands it a pointer to the RPC channel. Finally, COM returns
78 * the IClassFactory pointer to the client, which uses it to call
79 * IClassFactory::CreateInstance, passing it a reference to the interface.
81 * Back in the server process, COM now creates a new instance of the
82 * object, along with a stub for the requested interface. This stub marshals
83 * the interface pointer back to the client process, where another object
84 * proxy is created, this time for the object itself. Also created is a
85 * proxy for the requested interface, a pointer to which is returned to
86 * the client. With subsequent calls to other interfaces on the object,
87 * COM will load the appropriate interface stubs and proxies as needed.
89 typedef struct _CFStub
{
90 const IRpcStubBufferVtbl
*lpvtbl
;
97 CFStub_QueryInterface(LPRPCSTUBBUFFER iface
, REFIID riid
, LPVOID
*ppv
) {
98 if (IsEqualIID(&IID_IUnknown
,riid
)||IsEqualIID(&IID_IRpcStubBuffer
,riid
)) {
100 IUnknown_AddRef(iface
);
103 FIXME("(%s), interface not supported.\n",debugstr_guid(riid
));
104 return E_NOINTERFACE
;
108 CFStub_AddRef(LPRPCSTUBBUFFER iface
) {
109 CFStub
*This
= (CFStub
*)iface
;
110 return InterlockedIncrement(&This
->ref
);
114 CFStub_Release(LPRPCSTUBBUFFER iface
) {
115 CFStub
*This
= (CFStub
*)iface
;
118 ref
= InterlockedDecrement(&This
->ref
);
119 if (!ref
) HeapFree(GetProcessHeap(),0,This
);
123 static HRESULT WINAPI
124 CFStub_Connect(LPRPCSTUBBUFFER iface
, IUnknown
*pUnkServer
) {
125 CFStub
*This
= (CFStub
*)iface
;
127 This
->pUnkServer
= pUnkServer
;
128 IUnknown_AddRef(pUnkServer
);
133 CFStub_Disconnect(LPRPCSTUBBUFFER iface
) {
134 CFStub
*This
= (CFStub
*)iface
;
136 IUnknown_Release(This
->pUnkServer
);
137 This
->pUnkServer
= NULL
;
139 static HRESULT WINAPI
141 LPRPCSTUBBUFFER iface
,RPCOLEMESSAGE
* msg
,IRpcChannelBuffer
* chanbuf
143 CFStub
*This
= (CFStub
*)iface
;
146 if (msg
->iMethod
== 3) { /* CreateInstance */
148 IClassFactory
*classfac
;
152 ULARGE_INTEGER newpos
;
153 LARGE_INTEGER seekto
;
156 if (msg
->cbBuffer
< sizeof(IID
)) {
157 FIXME("Not enough bytes in buffer (%ld instead of %d)?\n",msg
->cbBuffer
,sizeof(IID
));
160 memcpy(&iid
,msg
->Buffer
,sizeof(iid
));
161 TRACE("->CreateInstance(%s)\n",debugstr_guid(&iid
));
162 hres
= IUnknown_QueryInterface(This
->pUnkServer
,&IID_IClassFactory
,(LPVOID
*)&classfac
);
164 FIXME("Ole server does not provide an IClassFactory?\n");
167 hres
= IClassFactory_CreateInstance(classfac
,NULL
,&iid
,(LPVOID
*)&ppv
);
168 IClassFactory_Release(classfac
);
171 FIXME("Failed to create an instance of %s\n",debugstr_guid(&iid
));
174 hres
= CreateStreamOnHGlobal(0,TRUE
,&pStm
);
176 FIXME("Failed to create stream on hglobal\n");
179 hres
= CoMarshalInterface(pStm
,&iid
,ppv
,0,NULL
,0);
180 IUnknown_Release((IUnknown
*)ppv
);
182 FIXME("CoMarshalInterface failed, %lx!\n",hres
);
186 hres
= IStream_Stat(pStm
,&ststg
,0);
188 FIXME("Stat failed.\n");
192 msg
->cbBuffer
= ststg
.cbSize
.u
.LowPart
;
194 I_RpcGetBuffer((RPC_MESSAGE
*)msg
);
195 if (hres
) return hres
;
197 seekto
.u
.LowPart
= 0;seekto
.u
.HighPart
= 0;
198 hres
= IStream_Seek(pStm
,seekto
,SEEK_SET
,&newpos
);
200 FIXME("IStream_Seek failed, %lx\n",hres
);
203 hres
= IStream_Read(pStm
,msg
->Buffer
,msg
->cbBuffer
,&res
);
205 FIXME("Stream Read failed, %lx\n",hres
);
208 IStream_Release(pStm
);
211 FIXME("(%p,%p), stub!\n",msg
,chanbuf
);
212 FIXME("iMethod is %ld\n",msg
->iMethod
);
213 FIXME("cbBuffer is %ld\n",msg
->cbBuffer
);
217 static LPRPCSTUBBUFFER WINAPI
218 CFStub_IsIIDSupported(LPRPCSTUBBUFFER iface
,REFIID riid
) {
219 FIXME("(%s), stub!\n",debugstr_guid(riid
));
224 CFStub_CountRefs(LPRPCSTUBBUFFER iface
) {
225 FIXME("(), stub!\n");
229 static HRESULT WINAPI
230 CFStub_DebugServerQueryInterface(LPRPCSTUBBUFFER iface
,void** ppv
) {
231 FIXME("(%p), stub!\n",ppv
);
235 CFStub_DebugServerRelease(LPRPCSTUBBUFFER iface
,void *pv
) {
236 FIXME("(%p), stub!\n",pv
);
239 static const IRpcStubBufferVtbl cfstubvt
= {
240 CFStub_QueryInterface
,
246 CFStub_IsIIDSupported
,
248 CFStub_DebugServerQueryInterface
,
249 CFStub_DebugServerRelease
253 CFStub_Construct(LPRPCSTUBBUFFER
*ppv
) {
255 cfstub
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(CFStub
));
257 return E_OUTOFMEMORY
;
258 *ppv
= (LPRPCSTUBBUFFER
)cfstub
;
259 cfstub
->lpvtbl
= &cfstubvt
;
264 /* Since we create proxy buffers and classfactory in a pair, there is
265 * no need for 2 separate structs. Just put them in one, but remember
268 typedef struct _CFProxy
{
269 const IClassFactoryVtbl
*lpvtbl_cf
;
270 const IRpcProxyBufferVtbl
*lpvtbl_proxy
;
273 IRpcChannelBuffer
*chanbuf
;
274 IUnknown
*outer_unknown
;
277 static HRESULT WINAPI
IRpcProxyBufferImpl_QueryInterface(LPRPCPROXYBUFFER iface
,REFIID riid
,LPVOID
*ppv
) {
279 if (IsEqualIID(riid
,&IID_IRpcProxyBuffer
)||IsEqualIID(riid
,&IID_IUnknown
)) {
280 IRpcProxyBuffer_AddRef(iface
);
281 *ppv
= (LPVOID
)iface
;
284 FIXME("(%s), no interface.\n",debugstr_guid(riid
));
285 return E_NOINTERFACE
;
288 static ULONG WINAPI
IRpcProxyBufferImpl_AddRef(LPRPCPROXYBUFFER iface
) {
289 ICOM_THIS_MULTI(CFProxy
,lpvtbl_proxy
,iface
);
290 return InterlockedIncrement(&This
->ref
);
293 static ULONG WINAPI
IRpcProxyBufferImpl_Release(LPRPCPROXYBUFFER iface
) {
294 ICOM_THIS_MULTI(CFProxy
,lpvtbl_proxy
,iface
);
295 ULONG ref
= InterlockedDecrement(&This
->ref
);
298 IRpcChannelBuffer_Release(This
->chanbuf
);
299 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 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 /* 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 I_RpcGetBuffer((RPC_MESSAGE
*)pMsg
);
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 I_RpcGetBuffer((RPC_MESSAGE
*)pMsg
);
581 memcpy(buf
, pResults
, cIids
* sizeof(HRESULT
));
584 CoTaskMemFree(pResults
);
588 case 5: /* RemRelease */
594 memcpy(&cIids
, buf
, sizeof(USHORT
));
595 buf
+= sizeof(USHORT
);
596 ir
= (REMINTERFACEREF
*)buf
;
598 hr
= IRemUnknown_RemRelease(This
->iface
, cIids
, ir
);
608 static LPRPCSTUBBUFFER WINAPI
RemUnkStub_IsIIDSupported(LPRPCSTUBBUFFER iface
,
611 RemUnkStub
*This
= (RemUnkStub
*)iface
;
612 TRACE("(%p)->IsIIDSupported(%s)\n", This
, debugstr_guid(riid
));
613 return IsEqualGUID(&IID_IRemUnknown
, riid
) ? iface
: NULL
;
616 static ULONG WINAPI
RemUnkStub_CountRefs(LPRPCSTUBBUFFER iface
)
618 RemUnkStub
*This
= (RemUnkStub
*)iface
;
619 FIXME("(%p)->CountRefs()\n", This
);
623 static HRESULT WINAPI
RemUnkStub_DebugServerQueryInterface(LPRPCSTUBBUFFER iface
,
626 RemUnkStub
*This
= (RemUnkStub
*)iface
;
627 FIXME("(%p)->DebugServerQueryInterface(%p)\n",This
,ppv
);
628 return E_NOINTERFACE
;
631 static void WINAPI
RemUnkStub_DebugServerRelease(LPRPCSTUBBUFFER iface
,
634 RemUnkStub
*This
= (RemUnkStub
*)iface
;
635 FIXME("(%p)->DebugServerRelease(%p)\n", This
, pv
);
638 static const IRpcStubBufferVtbl RemUnkStub_VTable
=
640 RemUnkStub_QueryInterface
,
644 RemUnkStub_Disconnect
,
646 RemUnkStub_IsIIDSupported
,
647 RemUnkStub_CountRefs
,
648 RemUnkStub_DebugServerQueryInterface
,
649 RemUnkStub_DebugServerRelease
652 static HRESULT
RemUnkStub_Construct(IRpcStubBuffer
**ppStub
)
654 RemUnkStub
*This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
655 if (!This
) return E_OUTOFMEMORY
;
656 This
->lpVtbl
= &RemUnkStub_VTable
;
659 *ppStub
= (IRpcStubBuffer
*)This
;
664 typedef struct _RemUnkProxy
{
665 const IRemUnknownVtbl
*lpvtbl_remunk
;
666 const IRpcProxyBufferVtbl
*lpvtbl_proxy
;
669 IRpcChannelBuffer
*chan
;
670 IUnknown
*outer_unknown
;
673 static HRESULT WINAPI
RemUnkProxy_QueryInterface(LPREMUNKNOWN iface
, REFIID riid
, void **ppv
)
675 RemUnkProxy
*This
= (RemUnkProxy
*)iface
;
676 if (This
->outer_unknown
)
677 return IUnknown_QueryInterface(This
->outer_unknown
, riid
, ppv
);
678 if (IsEqualIID(riid
, &IID_IUnknown
) ||
679 IsEqualIID(riid
, &IID_IRemUnknown
))
681 IRemUnknown_AddRef(iface
);
682 *ppv
= (LPVOID
)iface
;
685 return E_NOINTERFACE
;
688 static ULONG WINAPI
RemUnkProxy_AddRef(LPREMUNKNOWN iface
)
690 RemUnkProxy
*This
= (RemUnkProxy
*)iface
;
692 TRACE("(%p)->AddRef()\n",This
);
693 return InterlockedIncrement(&This
->refs
);
696 static ULONG WINAPI
RemUnkProxy_Release(LPREMUNKNOWN iface
)
698 RemUnkProxy
*This
= (RemUnkProxy
*)iface
;
701 TRACE("(%p)->Release()\n",This
);
702 if (This
->outer_unknown
)
703 refs
= IUnknown_Release(This
->outer_unknown
);
705 refs
= InterlockedDecrement(&This
->refs
);
708 if (This
->chan
) IRpcChannelBuffer_Release(This
->chan
);
709 HeapFree(GetProcessHeap(),0,This
);
714 static HRESULT WINAPI
RemUnkProxy_RemQueryInterface(LPREMUNKNOWN iface
,
719 REMQIRESULT
** ppQIResults
)
721 RemUnkProxy
*This
= (RemUnkProxy
*)iface
;
726 TRACE("(%p)->(%s,%ld,%d,%p,%p)\n",This
,
727 debugstr_guid(ripid
),cRefs
,cIids
,iids
,ppQIResults
);
730 memset(&msg
, 0, sizeof(msg
));
732 msg
.cbBuffer
= sizeof(IPID
) + sizeof(ULONG
) +
733 sizeof(USHORT
) + cIids
*sizeof(IID
);
734 hr
= IRpcChannelBuffer_GetBuffer(This
->chan
, &msg
, &IID_IRemUnknown
);
736 LPBYTE buf
= msg
.Buffer
;
737 memcpy(buf
, ripid
, sizeof(IPID
));
739 memcpy(buf
, &cRefs
, sizeof(ULONG
));
740 buf
+= sizeof(ULONG
);
741 memcpy(buf
, &cIids
, sizeof(USHORT
));
742 buf
+= sizeof(USHORT
);
743 memcpy(buf
, iids
, cIids
*sizeof(IID
));
745 hr
= IRpcChannelBuffer_SendReceive(This
->chan
, &msg
, &status
);
749 *ppQIResults
= CoTaskMemAlloc(cIids
*sizeof(REMQIRESULT
));
750 memcpy(*ppQIResults
, buf
, cIids
*sizeof(REMQIRESULT
));
753 IRpcChannelBuffer_FreeBuffer(This
->chan
, &msg
);
759 static HRESULT WINAPI
RemUnkProxy_RemAddRef(LPREMUNKNOWN iface
,
760 USHORT cInterfaceRefs
,
761 REMINTERFACEREF
* InterfaceRefs
,
764 RemUnkProxy
*This
= (RemUnkProxy
*)iface
;
769 TRACE("(%p)->(%d,%p,%p)\n",This
,
770 cInterfaceRefs
,InterfaceRefs
,pResults
);
772 memset(&msg
, 0, sizeof(msg
));
774 msg
.cbBuffer
= sizeof(USHORT
) + cInterfaceRefs
*sizeof(REMINTERFACEREF
);
775 hr
= IRpcChannelBuffer_GetBuffer(This
->chan
, &msg
, &IID_IRemUnknown
);
777 LPBYTE buf
= msg
.Buffer
;
778 memcpy(buf
, &cInterfaceRefs
, sizeof(USHORT
));
779 buf
+= sizeof(USHORT
);
780 memcpy(buf
, InterfaceRefs
, cInterfaceRefs
*sizeof(REMINTERFACEREF
));
782 hr
= IRpcChannelBuffer_SendReceive(This
->chan
, &msg
, &status
);
786 memcpy(pResults
, buf
, cInterfaceRefs
*sizeof(HRESULT
));
789 IRpcChannelBuffer_FreeBuffer(This
->chan
, &msg
);
795 static HRESULT WINAPI
RemUnkProxy_RemRelease(LPREMUNKNOWN iface
,
796 USHORT cInterfaceRefs
,
797 REMINTERFACEREF
* InterfaceRefs
)
799 RemUnkProxy
*This
= (RemUnkProxy
*)iface
;
804 TRACE("(%p)->(%d,%p)\n",This
,
805 cInterfaceRefs
,InterfaceRefs
);
807 memset(&msg
, 0, sizeof(msg
));
809 msg
.cbBuffer
= sizeof(USHORT
) + cInterfaceRefs
*sizeof(REMINTERFACEREF
);
810 hr
= IRpcChannelBuffer_GetBuffer(This
->chan
, &msg
, &IID_IRemUnknown
);
812 LPBYTE buf
= msg
.Buffer
;
813 memcpy(buf
, &cInterfaceRefs
, sizeof(USHORT
));
814 buf
+= sizeof(USHORT
);
815 memcpy(buf
, InterfaceRefs
, cInterfaceRefs
*sizeof(REMINTERFACEREF
));
817 hr
= IRpcChannelBuffer_SendReceive(This
->chan
, &msg
, &status
);
819 IRpcChannelBuffer_FreeBuffer(This
->chan
, &msg
);
825 static const IRemUnknownVtbl RemUnkProxy_VTable
=
827 RemUnkProxy_QueryInterface
,
830 RemUnkProxy_RemQueryInterface
,
831 RemUnkProxy_RemAddRef
,
832 RemUnkProxy_RemRelease
836 static HRESULT WINAPI
RURpcProxyBufferImpl_QueryInterface(LPRPCPROXYBUFFER iface
,REFIID riid
,LPVOID
*ppv
) {
838 if (IsEqualIID(riid
,&IID_IRpcProxyBuffer
)||IsEqualIID(riid
,&IID_IUnknown
)) {
839 IRpcProxyBuffer_AddRef(iface
);
840 *ppv
= (LPVOID
)iface
;
843 FIXME("(%s), no interface.\n",debugstr_guid(riid
));
844 return E_NOINTERFACE
;
847 static ULONG WINAPI
RURpcProxyBufferImpl_AddRef(LPRPCPROXYBUFFER iface
) {
848 ICOM_THIS_MULTI(RemUnkProxy
,lpvtbl_proxy
,iface
);
849 TRACE("%p, %ld\n", iface
, This
->refs
+ 1);
850 return InterlockedIncrement(&This
->refs
);
853 static ULONG WINAPI
RURpcProxyBufferImpl_Release(LPRPCPROXYBUFFER iface
) {
854 ICOM_THIS_MULTI(RemUnkProxy
,lpvtbl_proxy
,iface
);
855 ULONG ref
= InterlockedDecrement(&This
->refs
);
856 TRACE("%p, %ld\n", iface
, ref
);
858 IRpcChannelBuffer_Release(This
->chan
);This
->chan
= NULL
;
859 HeapFree(GetProcessHeap(),0,This
);
864 static HRESULT WINAPI
RURpcProxyBufferImpl_Connect(LPRPCPROXYBUFFER iface
,IRpcChannelBuffer
* pRpcChannelBuffer
) {
865 ICOM_THIS_MULTI(RemUnkProxy
,lpvtbl_proxy
,iface
);
867 TRACE("%p, %p\n", iface
, pRpcChannelBuffer
);
868 This
->chan
= pRpcChannelBuffer
;
869 IRpcChannelBuffer_AddRef(This
->chan
);
872 static void WINAPI
RURpcProxyBufferImpl_Disconnect(LPRPCPROXYBUFFER iface
) {
873 ICOM_THIS_MULTI(RemUnkProxy
,lpvtbl_proxy
,iface
);
874 TRACE("%p, %p\n", iface
, This
->chan
);
876 IRpcChannelBuffer_Release(This
->chan
);
882 static const IRpcProxyBufferVtbl RURpcProxyBuffer_VTable
= {
883 RURpcProxyBufferImpl_QueryInterface
,
884 RURpcProxyBufferImpl_AddRef
,
885 RURpcProxyBufferImpl_Release
,
886 RURpcProxyBufferImpl_Connect
,
887 RURpcProxyBufferImpl_Disconnect
891 RemUnkProxy_Construct(IUnknown
*pUnkOuter
, LPVOID
*ppv
,LPVOID
*ppProxy
) {
894 This
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(*This
));
896 return E_OUTOFMEMORY
;
898 This
->lpvtbl_remunk
= &RemUnkProxy_VTable
;
899 This
->lpvtbl_proxy
= &RURpcProxyBuffer_VTable
;
900 /* only one reference for the proxy buffer */
902 This
->outer_unknown
= pUnkOuter
;
903 *ppv
= &(This
->lpvtbl_remunk
);
904 *ppProxy
= &(This
->lpvtbl_proxy
);
909 /********************* OLE Proxy/Stub Factory ********************************/
910 static HRESULT WINAPI
911 PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface
, REFIID iid
, LPVOID
*ppv
) {
912 if (IsEqualIID(iid
,&IID_IPSFactoryBuffer
)||IsEqualIID(iid
,&IID_IUnknown
)) {
913 *ppv
= (LPVOID
)iface
;
914 /* No ref counting, static class */
917 FIXME("(%s) unknown IID?\n",debugstr_guid(iid
));
918 return E_NOINTERFACE
;
921 static ULONG WINAPI
PSFacBuf_AddRef(LPPSFACTORYBUFFER iface
) { return 2; }
922 static ULONG WINAPI
PSFacBuf_Release(LPPSFACTORYBUFFER iface
) { return 1; }
924 static HRESULT WINAPI
925 PSFacBuf_CreateProxy(
926 LPPSFACTORYBUFFER iface
, IUnknown
* pUnkOuter
, REFIID riid
,
927 IRpcProxyBuffer
**ppProxy
, LPVOID
*ppv
929 if (IsEqualIID(&IID_IClassFactory
,riid
))
930 return CFProxy_Construct(pUnkOuter
, ppv
,(LPVOID
*)ppProxy
);
931 else if (IsEqualIID(&IID_IRemUnknown
,riid
))
932 return RemUnkProxy_Construct(pUnkOuter
, ppv
,(LPVOID
*)ppProxy
);
933 FIXME("proxying not implemented for (%s) yet!\n",debugstr_guid(riid
));
937 static HRESULT WINAPI
939 LPPSFACTORYBUFFER iface
, REFIID riid
,IUnknown
*pUnkServer
,
940 IRpcStubBuffer
** ppStub
944 TRACE("(%s,%p,%p)\n",debugstr_guid(riid
),pUnkServer
,ppStub
);
946 if (IsEqualIID(&IID_IClassFactory
, riid
) ||
947 IsEqualIID(&IID_IUnknown
, riid
) /* FIXME: fixup stub manager and remove this*/) {
948 hres
= CFStub_Construct(ppStub
);
950 IRpcStubBuffer_Connect((*ppStub
),pUnkServer
);
952 } else if (IsEqualIID(&IID_IRemUnknown
,riid
)) {
953 hres
= RemUnkStub_Construct(ppStub
);
955 IRpcStubBuffer_Connect((*ppStub
),pUnkServer
);
958 FIXME("stubbing not implemented for (%s) yet!\n",debugstr_guid(riid
));
962 static const IPSFactoryBufferVtbl psfacbufvtbl
= {
963 PSFacBuf_QueryInterface
,
966 PSFacBuf_CreateProxy
,
970 /* This is the whole PSFactoryBuffer object, just the vtableptr */
971 static const IPSFactoryBufferVtbl
*lppsfac
= &psfacbufvtbl
;
973 /***********************************************************************
974 * DllGetClassObject [OLE32.@]
976 HRESULT WINAPI
OLE32_DllGetClassObject(REFCLSID rclsid
, REFIID iid
,LPVOID
*ppv
)
979 if (IsEqualIID(rclsid
, &CLSID_PSFactoryBuffer
))
980 return IPSFactoryBuffer_QueryInterface((IPSFactoryBuffer
*)&lppsfac
, iid
, ppv
);
981 if (IsEqualIID(rclsid
,&CLSID_DfMarshal
)&&(
982 IsEqualIID(iid
,&IID_IClassFactory
) ||
983 IsEqualIID(iid
,&IID_IUnknown
)
986 return MARSHAL_GetStandardMarshalCF(ppv
);
987 if (IsEqualIID(rclsid
,&CLSID_StdGlobalInterfaceTable
) && (IsEqualIID(iid
,&IID_IClassFactory
) || IsEqualIID(iid
,&IID_IUnknown
)))
988 return StdGlobalInterfaceTable_GetFactory(ppv
);
989 if (IsEqualCLSID(rclsid
, &CLSID_FileMoniker
))
990 return FileMonikerCF_Create(iid
, ppv
);
991 if (IsEqualCLSID(rclsid
, &CLSID_ItemMoniker
))
992 return ItemMonikerCF_Create(iid
, ppv
);
994 FIXME("\n\tCLSID:\t%s,\n\tIID:\t%s\n",debugstr_guid(rclsid
),debugstr_guid(iid
));
995 return CLASS_E_CLASSNOTAVAILABLE
;