2002-02-05 19:11:17 +01:00
|
|
|
|
/*
|
|
|
|
|
* OLE32 proxy/stub handler
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2002 Marcus Meissner
|
2005-01-25 20:02:54 +01:00
|
|
|
|
* Copyright 2001 Ove K<EFBFBD>ven, TransGaming Technologies
|
2002-03-10 00:29:33 +01:00
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-02-05 19:11:17 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* Documentation on MSDN:
|
2004-07-30 02:03:02 +02:00
|
|
|
|
*
|
|
|
|
|
* (Top level COM documentation)
|
|
|
|
|
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/componentdevelopmentank.asp
|
2002-02-05 19:11:17 +01:00
|
|
|
|
*
|
|
|
|
|
* (COM Proxy)
|
2004-07-30 02:03:02 +02:00
|
|
|
|
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/htm/comext_1q0p.asp
|
2002-02-05 19:11:17 +01:00
|
|
|
|
*
|
|
|
|
|
* (COM Stub)
|
2004-07-30 02:03:02 +02:00
|
|
|
|
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/htm/comext_1lia.asp
|
2002-02-05 19:11:17 +01:00
|
|
|
|
*
|
|
|
|
|
* (Marshal)
|
2004-07-30 02:03:02 +02:00
|
|
|
|
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/htm/comext_1gfn.asp
|
2002-02-05 19:11:17 +01:00
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
|
#include <stdarg.h>
|
2002-02-05 19:11:17 +01:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2004-10-07 05:06:48 +02:00
|
|
|
|
#define COBJMACROS
|
2003-01-07 21:36:20 +01:00
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
|
#define NONAMELESSSTRUCT
|
2004-10-07 05:06:48 +02:00
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
|
#include "windef.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
|
#include "winbase.h"
|
2003-09-09 21:39:31 +02:00
|
|
|
|
#include "winuser.h"
|
2002-02-05 19:11:17 +01:00
|
|
|
|
#include "objbase.h"
|
|
|
|
|
#include "ole2.h"
|
|
|
|
|
#include "rpc.h"
|
|
|
|
|
#include "winerror.h"
|
|
|
|
|
#include "wtypes.h"
|
|
|
|
|
|
|
|
|
|
#include "compobj_private.h"
|
2005-05-19 16:22:14 +02:00
|
|
|
|
#include "moniker.h"
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
|
#include "wine/debug.h"
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
2006-05-22 23:17:13 +02:00
|
|
|
|
static ULONG WINAPI RURpcProxyBufferImpl_Release(LPRPCPROXYBUFFER iface);
|
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
|
/* From: http://msdn.microsoft.com/library/en-us/com/cmi_m_4lda.asp
|
|
|
|
|
*
|
|
|
|
|
* The first time a client requests a pointer to an interface on a
|
|
|
|
|
* particular object, COM loads an IClassFactory stub in the server
|
|
|
|
|
* process and uses it to marshal the first pointer back to the
|
|
|
|
|
* client. In the client process, COM loads the generic proxy for the
|
|
|
|
|
* class factory object and calls its implementation of IMarshal to
|
|
|
|
|
* unmarshal that first pointer. COM then creates the first interface
|
|
|
|
|
* proxy and hands it a pointer to the RPC channel. Finally, COM returns
|
|
|
|
|
* the IClassFactory pointer to the client, which uses it to call
|
|
|
|
|
* IClassFactory::CreateInstance, passing it a reference to the interface.
|
|
|
|
|
*
|
|
|
|
|
* Back in the server process, COM now creates a new instance of the
|
|
|
|
|
* object, along with a stub for the requested interface. This stub marshals
|
|
|
|
|
* the interface pointer back to the client process, where another object
|
|
|
|
|
* proxy is created, this time for the object itself. Also created is a
|
|
|
|
|
* proxy for the requested interface, a pointer to which is returned to
|
|
|
|
|
* the client. With subsequent calls to other interfaces on the object,
|
|
|
|
|
* COM will load the appropriate interface stubs and proxies as needed.
|
|
|
|
|
*/
|
|
|
|
|
typedef struct _CFStub {
|
2005-06-06 21:50:35 +02:00
|
|
|
|
const IRpcStubBufferVtbl *lpvtbl;
|
2005-07-05 13:02:54 +02:00
|
|
|
|
LONG ref;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
|
|
|
|
LPUNKNOWN pUnkServer;
|
|
|
|
|
} CFStub;
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI
|
|
|
|
|
CFStub_QueryInterface(LPRPCSTUBBUFFER iface, REFIID riid, LPVOID *ppv) {
|
|
|
|
|
if (IsEqualIID(&IID_IUnknown,riid)||IsEqualIID(&IID_IRpcStubBuffer,riid)) {
|
|
|
|
|
*ppv = (LPVOID)iface;
|
|
|
|
|
IUnknown_AddRef(iface);
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
FIXME("(%s), interface not supported.\n",debugstr_guid(riid));
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ULONG WINAPI
|
|
|
|
|
CFStub_AddRef(LPRPCSTUBBUFFER iface) {
|
2004-09-09 23:03:58 +02:00
|
|
|
|
CFStub *This = (CFStub *)iface;
|
2004-09-24 03:16:53 +02:00
|
|
|
|
return InterlockedIncrement(&This->ref);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ULONG WINAPI
|
|
|
|
|
CFStub_Release(LPRPCSTUBBUFFER iface) {
|
2004-09-09 23:03:58 +02:00
|
|
|
|
CFStub *This = (CFStub *)iface;
|
2004-09-24 03:16:53 +02:00
|
|
|
|
ULONG ref;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
2004-09-24 03:16:53 +02:00
|
|
|
|
ref = InterlockedDecrement(&This->ref);
|
2005-07-19 21:13:11 +02:00
|
|
|
|
if (!ref) {
|
|
|
|
|
IRpcStubBuffer_Disconnect(iface);
|
|
|
|
|
HeapFree(GetProcessHeap(),0,This);
|
|
|
|
|
}
|
2004-09-24 03:16:53 +02:00
|
|
|
|
return ref;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI
|
|
|
|
|
CFStub_Connect(LPRPCSTUBBUFFER iface, IUnknown *pUnkServer) {
|
2004-09-09 23:03:58 +02:00
|
|
|
|
CFStub *This = (CFStub *)iface;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
|
|
|
|
This->pUnkServer = pUnkServer;
|
|
|
|
|
IUnknown_AddRef(pUnkServer);
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void WINAPI
|
|
|
|
|
CFStub_Disconnect(LPRPCSTUBBUFFER iface) {
|
2004-09-09 23:03:58 +02:00
|
|
|
|
CFStub *This = (CFStub *)iface;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
2005-07-19 21:13:11 +02:00
|
|
|
|
if (This->pUnkServer) {
|
|
|
|
|
IUnknown_Release(This->pUnkServer);
|
|
|
|
|
This->pUnkServer = NULL;
|
|
|
|
|
}
|
2002-02-05 19:11:17 +01:00
|
|
|
|
}
|
2005-07-19 21:13:11 +02:00
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
|
static HRESULT WINAPI
|
|
|
|
|
CFStub_Invoke(
|
|
|
|
|
LPRPCSTUBBUFFER iface,RPCOLEMESSAGE* msg,IRpcChannelBuffer* chanbuf
|
|
|
|
|
) {
|
2004-09-09 23:03:58 +02:00
|
|
|
|
CFStub *This = (CFStub *)iface;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
|
|
if (msg->iMethod == 3) { /* CreateInstance */
|
|
|
|
|
IID iid;
|
|
|
|
|
IClassFactory *classfac;
|
|
|
|
|
IUnknown *ppv;
|
|
|
|
|
IStream *pStm;
|
|
|
|
|
STATSTG ststg;
|
|
|
|
|
ULARGE_INTEGER newpos;
|
|
|
|
|
LARGE_INTEGER seekto;
|
|
|
|
|
ULONG res;
|
|
|
|
|
|
|
|
|
|
if (msg->cbBuffer < sizeof(IID)) {
|
2006-10-15 12:28:08 +02:00
|
|
|
|
FIXME("Not enough bytes in buffer (%d)?\n",msg->cbBuffer);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
return E_FAIL;
|
|
|
|
|
}
|
|
|
|
|
memcpy(&iid,msg->Buffer,sizeof(iid));
|
|
|
|
|
TRACE("->CreateInstance(%s)\n",debugstr_guid(&iid));
|
2004-05-21 22:52:57 +02:00
|
|
|
|
hres = IUnknown_QueryInterface(This->pUnkServer,&IID_IClassFactory,(LPVOID*)&classfac);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
if (hres) {
|
2005-03-23 14:15:18 +01:00
|
|
|
|
FIXME("Ole server does not provide an IClassFactory?\n");
|
2002-02-05 19:11:17 +01:00
|
|
|
|
return hres;
|
|
|
|
|
}
|
2004-05-21 22:52:57 +02:00
|
|
|
|
hres = IClassFactory_CreateInstance(classfac,NULL,&iid,(LPVOID*)&ppv);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
IClassFactory_Release(classfac);
|
2006-10-26 13:38:09 +02:00
|
|
|
|
msg->cbBuffer = 0;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
if (hres) {
|
|
|
|
|
FIXME("Failed to create an instance of %s\n",debugstr_guid(&iid));
|
2006-10-26 13:38:09 +02:00
|
|
|
|
goto getbuffer;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
}
|
|
|
|
|
hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
|
|
|
|
|
if (hres) {
|
|
|
|
|
FIXME("Failed to create stream on hglobal\n");
|
2006-10-26 13:38:09 +02:00
|
|
|
|
goto getbuffer;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
}
|
2006-12-23 16:50:22 +01:00
|
|
|
|
hres = IStream_Write(pStm, &ppv, sizeof(ppv), NULL);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
if (hres) {
|
2006-12-23 16:50:22 +01:00
|
|
|
|
ERR("IStream_Write failed, 0x%08x\n", hres);
|
|
|
|
|
goto getbuffer;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
}
|
2006-12-23 16:50:22 +01:00
|
|
|
|
if (ppv) {
|
|
|
|
|
hres = CoMarshalInterface(pStm,&iid,ppv,0,NULL,0);
|
|
|
|
|
IUnknown_Release(ppv);
|
|
|
|
|
if (hres) {
|
|
|
|
|
FIXME("CoMarshalInterface failed, %x!\n",hres);
|
|
|
|
|
goto getbuffer;
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-02-05 19:11:17 +01:00
|
|
|
|
hres = IStream_Stat(pStm,&ststg,0);
|
|
|
|
|
if (hres) {
|
|
|
|
|
FIXME("Stat failed.\n");
|
2006-10-26 13:38:09 +02:00
|
|
|
|
goto getbuffer;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
|
msg->cbBuffer = ststg.cbSize.u.LowPart;
|
2003-10-14 07:24:20 +02:00
|
|
|
|
|
2006-10-26 13:38:09 +02:00
|
|
|
|
getbuffer:
|
2006-08-26 13:05:13 +02:00
|
|
|
|
IRpcChannelBuffer_GetBuffer(chanbuf, msg, &IID_IClassFactory);
|
2005-02-15 22:48:09 +01:00
|
|
|
|
if (hres) return hres;
|
2003-10-14 07:24:20 +02:00
|
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
|
seekto.u.LowPart = 0;seekto.u.HighPart = 0;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
|
|
|
|
|
if (hres) {
|
2006-10-15 12:28:08 +02:00
|
|
|
|
FIXME("IStream_Seek failed, %x\n",hres);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
return hres;
|
|
|
|
|
}
|
|
|
|
|
hres = IStream_Read(pStm,msg->Buffer,msg->cbBuffer,&res);
|
|
|
|
|
if (hres) {
|
2006-10-15 12:28:08 +02:00
|
|
|
|
FIXME("Stream Read failed, %x\n",hres);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
return hres;
|
|
|
|
|
}
|
|
|
|
|
IStream_Release(pStm);
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
FIXME("(%p,%p), stub!\n",msg,chanbuf);
|
2006-10-15 12:28:08 +02:00
|
|
|
|
FIXME("iMethod is %d\n",msg->iMethod);
|
|
|
|
|
FIXME("cbBuffer is %d\n",msg->cbBuffer);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
return E_FAIL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static LPRPCSTUBBUFFER WINAPI
|
|
|
|
|
CFStub_IsIIDSupported(LPRPCSTUBBUFFER iface,REFIID riid) {
|
|
|
|
|
FIXME("(%s), stub!\n",debugstr_guid(riid));
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ULONG WINAPI
|
|
|
|
|
CFStub_CountRefs(LPRPCSTUBBUFFER iface) {
|
|
|
|
|
FIXME("(), stub!\n");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI
|
|
|
|
|
CFStub_DebugServerQueryInterface(LPRPCSTUBBUFFER iface,void** ppv) {
|
|
|
|
|
FIXME("(%p), stub!\n",ppv);
|
|
|
|
|
return E_FAIL;
|
|
|
|
|
}
|
|
|
|
|
static void WINAPI
|
|
|
|
|
CFStub_DebugServerRelease(LPRPCSTUBBUFFER iface,void *pv) {
|
|
|
|
|
FIXME("(%p), stub!\n",pv);
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
|
static const IRpcStubBufferVtbl cfstubvt = {
|
2002-02-05 19:11:17 +01:00
|
|
|
|
CFStub_QueryInterface,
|
|
|
|
|
CFStub_AddRef,
|
|
|
|
|
CFStub_Release,
|
|
|
|
|
CFStub_Connect,
|
|
|
|
|
CFStub_Disconnect,
|
|
|
|
|
CFStub_Invoke,
|
|
|
|
|
CFStub_IsIIDSupported,
|
|
|
|
|
CFStub_CountRefs,
|
|
|
|
|
CFStub_DebugServerQueryInterface,
|
|
|
|
|
CFStub_DebugServerRelease
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static HRESULT
|
|
|
|
|
CFStub_Construct(LPRPCSTUBBUFFER *ppv) {
|
|
|
|
|
CFStub *cfstub;
|
|
|
|
|
cfstub = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(CFStub));
|
|
|
|
|
if (!cfstub)
|
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
*ppv = (LPRPCSTUBBUFFER)cfstub;
|
|
|
|
|
cfstub->lpvtbl = &cfstubvt;
|
|
|
|
|
cfstub->ref = 1;
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
|
/* Since we create proxy buffers and classfactory in a pair, there is
|
2003-05-13 02:41:57 +02:00
|
|
|
|
* no need for 2 separate structs. Just put them in one, but remember
|
2002-02-05 19:11:17 +01:00
|
|
|
|
* the refcount.
|
|
|
|
|
*/
|
|
|
|
|
typedef struct _CFProxy {
|
2005-01-25 20:02:54 +01:00
|
|
|
|
const IClassFactoryVtbl *lpvtbl_cf;
|
|
|
|
|
const IRpcProxyBufferVtbl *lpvtbl_proxy;
|
2005-07-05 13:02:54 +02:00
|
|
|
|
LONG ref;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
|
|
|
|
IRpcChannelBuffer *chanbuf;
|
2005-01-04 12:47:52 +01:00
|
|
|
|
IUnknown *outer_unknown;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
} CFProxy;
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI IRpcProxyBufferImpl_QueryInterface(LPRPCPROXYBUFFER iface,REFIID riid,LPVOID *ppv) {
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
if (IsEqualIID(riid,&IID_IRpcProxyBuffer)||IsEqualIID(riid,&IID_IUnknown)) {
|
|
|
|
|
IRpcProxyBuffer_AddRef(iface);
|
|
|
|
|
*ppv = (LPVOID)iface;
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
FIXME("(%s), no interface.\n",debugstr_guid(riid));
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ULONG WINAPI IRpcProxyBufferImpl_AddRef(LPRPCPROXYBUFFER iface) {
|
|
|
|
|
ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
|
2004-09-24 03:16:53 +02:00
|
|
|
|
return InterlockedIncrement(&This->ref);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ULONG WINAPI IRpcProxyBufferImpl_Release(LPRPCPROXYBUFFER iface) {
|
|
|
|
|
ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
|
2004-09-24 03:16:53 +02:00
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
2004-09-24 03:16:53 +02:00
|
|
|
|
if (!ref) {
|
2005-09-18 13:10:37 +02:00
|
|
|
|
IRpcProxyBuffer_Disconnect(iface);
|
|
|
|
|
HeapFree(GetProcessHeap(),0,This);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
}
|
2004-09-24 03:16:53 +02:00
|
|
|
|
return ref;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI IRpcProxyBufferImpl_Connect(LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer) {
|
|
|
|
|
ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
|
|
|
|
|
|
|
|
|
|
This->chanbuf = pRpcChannelBuffer;
|
|
|
|
|
IRpcChannelBuffer_AddRef(This->chanbuf);
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
static void WINAPI IRpcProxyBufferImpl_Disconnect(LPRPCPROXYBUFFER iface) {
|
|
|
|
|
ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
|
|
|
|
|
if (This->chanbuf) {
|
|
|
|
|
IRpcChannelBuffer_Release(This->chanbuf);
|
|
|
|
|
This->chanbuf = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI
|
|
|
|
|
CFProxy_QueryInterface(LPCLASSFACTORY iface,REFIID riid, LPVOID *ppv) {
|
2005-01-26 22:07:05 +01:00
|
|
|
|
ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
|
2005-01-04 12:47:52 +01:00
|
|
|
|
if (This->outer_unknown) return IUnknown_QueryInterface(This->outer_unknown, riid, ppv);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
*ppv = NULL;
|
|
|
|
|
if (IsEqualIID(&IID_IClassFactory,riid) || IsEqualIID(&IID_IUnknown,riid)) {
|
|
|
|
|
*ppv = (LPVOID)iface;
|
|
|
|
|
IClassFactory_AddRef(iface);
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
2003-05-13 02:41:57 +02:00
|
|
|
|
if (IsEqualIID(riid,&IID_IMarshal)) /* just to avoid debug output */
|
2002-02-05 19:11:17 +01:00
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
FIXME("Unhandled interface: %s\n",debugstr_guid(riid));
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ULONG WINAPI CFProxy_AddRef(LPCLASSFACTORY iface) {
|
|
|
|
|
ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
|
2005-01-04 12:47:52 +01:00
|
|
|
|
if (This->outer_unknown) return IUnknown_AddRef(This->outer_unknown);
|
2004-09-24 03:16:53 +02:00
|
|
|
|
return InterlockedIncrement(&This->ref);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ULONG WINAPI CFProxy_Release(LPCLASSFACTORY iface) {
|
|
|
|
|
ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
|
2005-01-04 12:47:52 +01:00
|
|
|
|
if (This->outer_unknown)
|
2006-05-22 23:17:13 +02:00
|
|
|
|
return IUnknown_Release(This->outer_unknown);
|
|
|
|
|
else
|
|
|
|
|
return IRpcProxyBufferImpl_Release((IRpcProxyBuffer *)&This->lpvtbl_proxy);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI CFProxy_CreateInstance(
|
|
|
|
|
LPCLASSFACTORY iface,
|
|
|
|
|
LPUNKNOWN pUnkOuter,/* [in] */
|
|
|
|
|
REFIID riid, /* [in] */
|
|
|
|
|
LPVOID *ppv /* [out] */
|
|
|
|
|
) {
|
|
|
|
|
ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
|
|
|
|
|
HRESULT hres;
|
|
|
|
|
LPSTREAM pStream;
|
|
|
|
|
HGLOBAL hGlobal;
|
|
|
|
|
ULONG srstatus;
|
|
|
|
|
RPCOLEMESSAGE msg;
|
|
|
|
|
|
|
|
|
|
TRACE("(%p,%s,%p)\n",pUnkOuter,debugstr_guid(riid),ppv);
|
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
|
/* Send CreateInstance to the remote classfactory.
|
2002-02-05 19:11:17 +01:00
|
|
|
|
*
|
|
|
|
|
* Data: Only the 'IID'.
|
|
|
|
|
*/
|
|
|
|
|
msg.iMethod = 3;
|
|
|
|
|
msg.cbBuffer = sizeof(*riid);
|
|
|
|
|
msg.Buffer = NULL;
|
|
|
|
|
hres = IRpcChannelBuffer_GetBuffer(This->chanbuf,&msg,&IID_IClassFactory);
|
|
|
|
|
if (hres) {
|
2006-10-15 12:28:08 +02:00
|
|
|
|
FIXME("IRpcChannelBuffer_GetBuffer failed with %x?\n",hres);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
return hres;
|
|
|
|
|
}
|
|
|
|
|
memcpy(msg.Buffer,riid,sizeof(*riid));
|
|
|
|
|
hres = IRpcChannelBuffer_SendReceive(This->chanbuf,&msg,&srstatus);
|
|
|
|
|
if (hres) {
|
2006-10-15 12:28:08 +02:00
|
|
|
|
FIXME("IRpcChannelBuffer_SendReceive failed with %x?\n",hres);
|
2006-10-26 13:38:27 +02:00
|
|
|
|
IRpcChannelBuffer_FreeBuffer(This->chanbuf,&msg);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
return hres;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-26 13:38:27 +02:00
|
|
|
|
if (!msg.cbBuffer) { /* interface not found on remote */
|
|
|
|
|
IRpcChannelBuffer_FreeBuffer(This->chanbuf,&msg);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
return srstatus;
|
2006-10-26 13:38:27 +02:00
|
|
|
|
}
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
2003-05-13 02:41:57 +02:00
|
|
|
|
/* We got back: [Marshalled Interface data] */
|
2006-10-15 12:28:08 +02:00
|
|
|
|
TRACE("got %d bytes data.\n",msg.cbBuffer);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
hGlobal = GlobalAlloc(GMEM_MOVEABLE|GMEM_NODISCARD|GMEM_SHARE,msg.cbBuffer);
|
|
|
|
|
memcpy(GlobalLock(hGlobal),msg.Buffer,msg.cbBuffer);
|
|
|
|
|
hres = CreateStreamOnHGlobal(hGlobal,TRUE,&pStream);
|
2007-09-25 01:15:07 +02:00
|
|
|
|
if (hres != S_OK) {
|
2006-10-15 12:28:08 +02:00
|
|
|
|
FIXME("CreateStreamOnHGlobal failed with %x\n",hres);
|
2006-10-26 13:38:27 +02:00
|
|
|
|
IRpcChannelBuffer_FreeBuffer(This->chanbuf,&msg);
|
2007-09-25 01:15:07 +02:00
|
|
|
|
GlobalFree(hGlobal);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
return hres;
|
|
|
|
|
}
|
2006-12-23 16:50:22 +01:00
|
|
|
|
hres = IStream_Read(pStream, ppv, sizeof(*ppv), NULL);
|
|
|
|
|
if (hres != S_OK)
|
|
|
|
|
hres = E_FAIL;
|
|
|
|
|
else if (*ppv) {
|
|
|
|
|
hres = CoUnmarshalInterface(
|
|
|
|
|
pStream,
|
|
|
|
|
riid,
|
|
|
|
|
ppv
|
|
|
|
|
);
|
|
|
|
|
}
|
2002-02-05 19:11:17 +01:00
|
|
|
|
IStream_Release(pStream); /* Does GlobalFree hGlobal too. */
|
2006-10-26 13:38:27 +02:00
|
|
|
|
|
|
|
|
|
IRpcChannelBuffer_FreeBuffer(This->chanbuf,&msg);
|
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
|
if (hres) {
|
2006-10-15 12:28:08 +02:00
|
|
|
|
FIXME("CoMarshalInterface failed, %x\n",hres);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
return hres;
|
|
|
|
|
}
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI CFProxy_LockServer(LPCLASSFACTORY iface,BOOL fLock) {
|
|
|
|
|
/*ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);*/
|
|
|
|
|
FIXME("(%d), stub!\n",fLock);
|
|
|
|
|
/* basically: write BOOL, read empty */
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
|
static const IRpcProxyBufferVtbl pspbvtbl = {
|
2002-02-05 19:11:17 +01:00
|
|
|
|
IRpcProxyBufferImpl_QueryInterface,
|
|
|
|
|
IRpcProxyBufferImpl_AddRef,
|
|
|
|
|
IRpcProxyBufferImpl_Release,
|
|
|
|
|
IRpcProxyBufferImpl_Connect,
|
|
|
|
|
IRpcProxyBufferImpl_Disconnect
|
|
|
|
|
};
|
2005-06-06 21:50:35 +02:00
|
|
|
|
static const IClassFactoryVtbl cfproxyvt = {
|
2002-02-05 19:11:17 +01:00
|
|
|
|
CFProxy_QueryInterface,
|
|
|
|
|
CFProxy_AddRef,
|
|
|
|
|
CFProxy_Release,
|
|
|
|
|
CFProxy_CreateInstance,
|
|
|
|
|
CFProxy_LockServer
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static HRESULT
|
2005-01-04 12:47:52 +01:00
|
|
|
|
CFProxy_Construct(IUnknown *pUnkOuter, LPVOID *ppv,LPVOID *ppProxy) {
|
2002-02-05 19:11:17 +01:00
|
|
|
|
CFProxy *cf;
|
|
|
|
|
|
|
|
|
|
cf = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(CFProxy));
|
|
|
|
|
if (!cf)
|
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
|
|
cf->lpvtbl_cf = &cfproxyvt;
|
|
|
|
|
cf->lpvtbl_proxy = &pspbvtbl;
|
2005-09-18 13:10:37 +02:00
|
|
|
|
/* one reference for the proxy buffer */
|
2005-01-04 12:47:52 +01:00
|
|
|
|
cf->ref = 1;
|
|
|
|
|
cf->outer_unknown = pUnkOuter;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
*ppv = &(cf->lpvtbl_cf);
|
|
|
|
|
*ppProxy = &(cf->lpvtbl_proxy);
|
2005-09-18 13:10:37 +02:00
|
|
|
|
/* and one reference for the object */
|
|
|
|
|
IUnknown_AddRef((IUnknown *)*ppv);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-01-25 20:02:54 +01:00
|
|
|
|
/********************* IRemUnknown Proxy/Stub ********************************/
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
const IRpcStubBufferVtbl *lpVtbl;
|
2005-07-05 13:02:54 +02:00
|
|
|
|
LONG refs;
|
2005-01-25 20:02:54 +01:00
|
|
|
|
IRemUnknown *iface;
|
|
|
|
|
} RemUnkStub;
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI RemUnkStub_QueryInterface(LPRPCSTUBBUFFER iface,
|
|
|
|
|
REFIID riid,
|
|
|
|
|
LPVOID *obj)
|
|
|
|
|
{
|
|
|
|
|
RemUnkStub *This = (RemUnkStub *)iface;
|
|
|
|
|
TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(riid),obj);
|
|
|
|
|
if (IsEqualGUID(&IID_IUnknown,riid) ||
|
|
|
|
|
IsEqualGUID(&IID_IRpcStubBuffer,riid)) {
|
|
|
|
|
*obj = This;
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ULONG WINAPI RemUnkStub_AddRef(LPRPCSTUBBUFFER iface)
|
|
|
|
|
{
|
|
|
|
|
RemUnkStub *This = (RemUnkStub *)iface;
|
|
|
|
|
TRACE("(%p)->AddRef()\n",This);
|
|
|
|
|
return InterlockedIncrement(&This->refs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ULONG WINAPI RemUnkStub_Release(LPRPCSTUBBUFFER iface)
|
|
|
|
|
{
|
|
|
|
|
RemUnkStub *This = (RemUnkStub *)iface;
|
|
|
|
|
ULONG refs;
|
|
|
|
|
TRACE("(%p)->Release()\n",This);
|
|
|
|
|
refs = InterlockedDecrement(&This->refs);
|
|
|
|
|
if (!refs)
|
2007-11-11 13:28:46 +01:00
|
|
|
|
{
|
|
|
|
|
IRpcStubBuffer_Disconnect(iface);
|
2005-01-25 20:02:54 +01:00
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
2007-11-11 13:28:46 +01:00
|
|
|
|
}
|
2005-01-25 20:02:54 +01:00
|
|
|
|
return refs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI RemUnkStub_Connect(LPRPCSTUBBUFFER iface,
|
|
|
|
|
LPUNKNOWN lpUnkServer)
|
|
|
|
|
{
|
|
|
|
|
RemUnkStub *This = (RemUnkStub *)iface;
|
|
|
|
|
TRACE("(%p)->Connect(%p)\n",This,lpUnkServer);
|
|
|
|
|
This->iface = (IRemUnknown*)lpUnkServer;
|
|
|
|
|
IRemUnknown_AddRef(This->iface);
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void WINAPI RemUnkStub_Disconnect(LPRPCSTUBBUFFER iface)
|
|
|
|
|
{
|
|
|
|
|
RemUnkStub *This = (RemUnkStub *)iface;
|
|
|
|
|
TRACE("(%p)->Disconnect()\n",This);
|
2005-01-26 21:53:06 +01:00
|
|
|
|
IUnknown_Release(This->iface);
|
|
|
|
|
This->iface = NULL;
|
2005-01-25 20:02:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI RemUnkStub_Invoke(LPRPCSTUBBUFFER iface,
|
|
|
|
|
PRPCOLEMESSAGE pMsg,
|
|
|
|
|
LPRPCCHANNELBUFFER pChannel)
|
|
|
|
|
{
|
|
|
|
|
RemUnkStub *This = (RemUnkStub *)iface;
|
|
|
|
|
ULONG iMethod = pMsg->iMethod;
|
|
|
|
|
LPBYTE buf = pMsg->Buffer;
|
|
|
|
|
HRESULT hr = RPC_E_INVALIDMETHOD;
|
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
|
TRACE("(%p)->Invoke(%p,%p) method %d\n", This, pMsg, pChannel, iMethod);
|
2005-01-25 20:02:54 +01:00
|
|
|
|
switch (iMethod)
|
|
|
|
|
{
|
|
|
|
|
case 3: /* RemQueryInterface */
|
|
|
|
|
{
|
|
|
|
|
IPID ipid;
|
|
|
|
|
ULONG cRefs;
|
|
|
|
|
USHORT cIids;
|
|
|
|
|
IID *iids;
|
|
|
|
|
REMQIRESULT *pQIResults = NULL;
|
|
|
|
|
|
|
|
|
|
/* in */
|
|
|
|
|
memcpy(&ipid, buf, sizeof(ipid));
|
|
|
|
|
buf += sizeof(ipid);
|
|
|
|
|
memcpy(&cRefs, buf, sizeof(cRefs));
|
|
|
|
|
buf += sizeof(cRefs);
|
|
|
|
|
memcpy(&cIids, buf, sizeof(cIids));
|
|
|
|
|
buf += sizeof(cIids);
|
|
|
|
|
iids = (IID *)buf;
|
|
|
|
|
|
|
|
|
|
hr = IRemUnknown_RemQueryInterface(This->iface, &ipid, cRefs, cIids, iids, &pQIResults);
|
|
|
|
|
|
|
|
|
|
/* out */
|
2005-07-19 21:43:05 +02:00
|
|
|
|
pMsg->cbBuffer = cIids * sizeof(REMQIRESULT) + sizeof(HRESULT);
|
2005-02-15 22:48:09 +01:00
|
|
|
|
|
2006-08-26 13:05:13 +02:00
|
|
|
|
IRpcChannelBuffer_GetBuffer(pChannel, pMsg, &IID_IRemUnknown);
|
2005-02-15 22:48:09 +01:00
|
|
|
|
|
2005-01-25 20:02:54 +01:00
|
|
|
|
buf = pMsg->Buffer;
|
2005-07-19 21:43:05 +02:00
|
|
|
|
*(HRESULT *)buf = hr;
|
|
|
|
|
buf += sizeof(HRESULT);
|
|
|
|
|
|
|
|
|
|
if (hr) return hr;
|
2005-01-25 20:02:54 +01:00
|
|
|
|
/* FIXME: pQIResults is a unique pointer so pQIResults can be NULL! */
|
|
|
|
|
memcpy(buf, pQIResults, cIids * sizeof(REMQIRESULT));
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 4: /* RemAddRef */
|
|
|
|
|
{
|
|
|
|
|
USHORT cIids;
|
|
|
|
|
REMINTERFACEREF *ir;
|
|
|
|
|
HRESULT *pResults;
|
|
|
|
|
|
|
|
|
|
/* in */
|
|
|
|
|
memcpy(&cIids, buf, sizeof(USHORT));
|
|
|
|
|
buf += sizeof(USHORT);
|
|
|
|
|
ir = (REMINTERFACEREF*)buf;
|
|
|
|
|
pResults = CoTaskMemAlloc(cIids * sizeof(HRESULT));
|
|
|
|
|
if (!pResults) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
|
|
hr = IRemUnknown_RemAddRef(This->iface, cIids, ir, pResults);
|
|
|
|
|
|
|
|
|
|
/* out */
|
|
|
|
|
pMsg->cbBuffer = cIids * sizeof(HRESULT);
|
2005-02-15 22:48:09 +01:00
|
|
|
|
|
2006-08-26 13:05:13 +02:00
|
|
|
|
IRpcChannelBuffer_GetBuffer(pChannel, pMsg, &IID_IRemUnknown);
|
2005-02-15 22:48:09 +01:00
|
|
|
|
if (!hr)
|
|
|
|
|
{
|
|
|
|
|
buf = pMsg->Buffer;
|
|
|
|
|
memcpy(buf, pResults, cIids * sizeof(HRESULT));
|
|
|
|
|
}
|
2005-01-25 20:02:54 +01:00
|
|
|
|
|
|
|
|
|
CoTaskMemFree(pResults);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 5: /* RemRelease */
|
|
|
|
|
{
|
|
|
|
|
USHORT cIids;
|
|
|
|
|
REMINTERFACEREF *ir;
|
|
|
|
|
|
|
|
|
|
/* in */
|
|
|
|
|
memcpy(&cIids, buf, sizeof(USHORT));
|
|
|
|
|
buf += sizeof(USHORT);
|
|
|
|
|
ir = (REMINTERFACEREF*)buf;
|
|
|
|
|
|
|
|
|
|
hr = IRemUnknown_RemRelease(This->iface, cIids, ir);
|
|
|
|
|
|
|
|
|
|
/* out */
|
|
|
|
|
pMsg->cbBuffer = 0;
|
2006-08-26 13:07:18 +02:00
|
|
|
|
IRpcChannelBuffer_GetBuffer(pChannel, pMsg, &IID_IRemUnknown);
|
2005-01-25 20:02:54 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return hr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static LPRPCSTUBBUFFER WINAPI RemUnkStub_IsIIDSupported(LPRPCSTUBBUFFER iface,
|
|
|
|
|
REFIID riid)
|
|
|
|
|
{
|
|
|
|
|
RemUnkStub *This = (RemUnkStub *)iface;
|
|
|
|
|
TRACE("(%p)->IsIIDSupported(%s)\n", This, debugstr_guid(riid));
|
|
|
|
|
return IsEqualGUID(&IID_IRemUnknown, riid) ? iface : NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ULONG WINAPI RemUnkStub_CountRefs(LPRPCSTUBBUFFER iface)
|
|
|
|
|
{
|
|
|
|
|
RemUnkStub *This = (RemUnkStub *)iface;
|
|
|
|
|
FIXME("(%p)->CountRefs()\n", This);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI RemUnkStub_DebugServerQueryInterface(LPRPCSTUBBUFFER iface,
|
|
|
|
|
LPVOID *ppv)
|
|
|
|
|
{
|
|
|
|
|
RemUnkStub *This = (RemUnkStub *)iface;
|
|
|
|
|
FIXME("(%p)->DebugServerQueryInterface(%p)\n",This,ppv);
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void WINAPI RemUnkStub_DebugServerRelease(LPRPCSTUBBUFFER iface,
|
|
|
|
|
LPVOID pv)
|
|
|
|
|
{
|
|
|
|
|
RemUnkStub *This = (RemUnkStub *)iface;
|
|
|
|
|
FIXME("(%p)->DebugServerRelease(%p)\n", This, pv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const IRpcStubBufferVtbl RemUnkStub_VTable =
|
|
|
|
|
{
|
|
|
|
|
RemUnkStub_QueryInterface,
|
|
|
|
|
RemUnkStub_AddRef,
|
|
|
|
|
RemUnkStub_Release,
|
|
|
|
|
RemUnkStub_Connect,
|
|
|
|
|
RemUnkStub_Disconnect,
|
|
|
|
|
RemUnkStub_Invoke,
|
|
|
|
|
RemUnkStub_IsIIDSupported,
|
|
|
|
|
RemUnkStub_CountRefs,
|
|
|
|
|
RemUnkStub_DebugServerQueryInterface,
|
|
|
|
|
RemUnkStub_DebugServerRelease
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static HRESULT RemUnkStub_Construct(IRpcStubBuffer **ppStub)
|
|
|
|
|
{
|
|
|
|
|
RemUnkStub *This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
|
|
|
|
|
if (!This) return E_OUTOFMEMORY;
|
|
|
|
|
This->lpVtbl = &RemUnkStub_VTable;
|
2005-07-19 21:13:11 +02:00
|
|
|
|
This->refs = 1;
|
2005-01-25 20:02:54 +01:00
|
|
|
|
This->iface = NULL;
|
|
|
|
|
*ppStub = (IRpcStubBuffer*)This;
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _RemUnkProxy {
|
|
|
|
|
const IRemUnknownVtbl *lpvtbl_remunk;
|
|
|
|
|
const IRpcProxyBufferVtbl *lpvtbl_proxy;
|
2005-07-05 13:02:54 +02:00
|
|
|
|
LONG refs;
|
2005-01-25 20:02:54 +01:00
|
|
|
|
|
|
|
|
|
IRpcChannelBuffer *chan;
|
|
|
|
|
IUnknown *outer_unknown;
|
|
|
|
|
} RemUnkProxy;
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI RemUnkProxy_QueryInterface(LPREMUNKNOWN iface, REFIID riid, void **ppv)
|
|
|
|
|
{
|
|
|
|
|
RemUnkProxy *This = (RemUnkProxy *)iface;
|
|
|
|
|
if (This->outer_unknown)
|
|
|
|
|
return IUnknown_QueryInterface(This->outer_unknown, riid, ppv);
|
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
|
IsEqualIID(riid, &IID_IRemUnknown))
|
|
|
|
|
{
|
|
|
|
|
IRemUnknown_AddRef(iface);
|
|
|
|
|
*ppv = (LPVOID)iface;
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ULONG WINAPI RemUnkProxy_AddRef(LPREMUNKNOWN iface)
|
|
|
|
|
{
|
|
|
|
|
RemUnkProxy *This = (RemUnkProxy *)iface;
|
2005-09-18 13:10:37 +02:00
|
|
|
|
ULONG refs;
|
2005-01-25 20:02:54 +01:00
|
|
|
|
|
|
|
|
|
TRACE("(%p)->AddRef()\n",This);
|
2005-09-18 13:10:37 +02:00
|
|
|
|
|
|
|
|
|
if (This->outer_unknown)
|
|
|
|
|
refs = IUnknown_AddRef(This->outer_unknown);
|
|
|
|
|
else
|
|
|
|
|
refs = InterlockedIncrement(&This->refs);
|
|
|
|
|
return refs;
|
2005-01-25 20:02:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ULONG WINAPI RemUnkProxy_Release(LPREMUNKNOWN iface)
|
|
|
|
|
{
|
|
|
|
|
RemUnkProxy *This = (RemUnkProxy *)iface;
|
|
|
|
|
|
|
|
|
|
TRACE("(%p)->Release()\n",This);
|
|
|
|
|
if (This->outer_unknown)
|
2006-05-22 23:17:13 +02:00
|
|
|
|
return IUnknown_Release(This->outer_unknown);
|
|
|
|
|
else
|
|
|
|
|
return IRpcProxyBufferImpl_Release((IRpcProxyBuffer *)&This->lpvtbl_proxy);
|
2005-01-25 20:02:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI RemUnkProxy_RemQueryInterface(LPREMUNKNOWN iface,
|
|
|
|
|
REFIPID ripid,
|
|
|
|
|
ULONG cRefs,
|
|
|
|
|
USHORT cIids,
|
|
|
|
|
IID* iids,
|
|
|
|
|
REMQIRESULT** ppQIResults)
|
|
|
|
|
{
|
|
|
|
|
RemUnkProxy *This = (RemUnkProxy *)iface;
|
|
|
|
|
RPCOLEMESSAGE msg;
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
ULONG status;
|
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
|
TRACE("(%p)->(%s,%d,%d,%p,%p)\n",This,
|
2005-01-25 20:02:54 +01:00
|
|
|
|
debugstr_guid(ripid),cRefs,cIids,iids,ppQIResults);
|
|
|
|
|
|
|
|
|
|
*ppQIResults = NULL;
|
|
|
|
|
memset(&msg, 0, sizeof(msg));
|
|
|
|
|
msg.iMethod = 3;
|
|
|
|
|
msg.cbBuffer = sizeof(IPID) + sizeof(ULONG) +
|
|
|
|
|
sizeof(USHORT) + cIids*sizeof(IID);
|
|
|
|
|
hr = IRpcChannelBuffer_GetBuffer(This->chan, &msg, &IID_IRemUnknown);
|
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
|
LPBYTE buf = msg.Buffer;
|
|
|
|
|
memcpy(buf, ripid, sizeof(IPID));
|
|
|
|
|
buf += sizeof(IPID);
|
|
|
|
|
memcpy(buf, &cRefs, sizeof(ULONG));
|
|
|
|
|
buf += sizeof(ULONG);
|
|
|
|
|
memcpy(buf, &cIids, sizeof(USHORT));
|
|
|
|
|
buf += sizeof(USHORT);
|
|
|
|
|
memcpy(buf, iids, cIids*sizeof(IID));
|
|
|
|
|
|
|
|
|
|
hr = IRpcChannelBuffer_SendReceive(This->chan, &msg, &status);
|
|
|
|
|
|
2005-07-19 21:43:05 +02:00
|
|
|
|
buf = msg.Buffer;
|
|
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
|
hr = *(HRESULT *)buf;
|
|
|
|
|
buf += sizeof(HRESULT);
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-25 20:02:54 +01:00
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
|
*ppQIResults = CoTaskMemAlloc(cIids*sizeof(REMQIRESULT));
|
|
|
|
|
memcpy(*ppQIResults, buf, cIids*sizeof(REMQIRESULT));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IRpcChannelBuffer_FreeBuffer(This->chan, &msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI RemUnkProxy_RemAddRef(LPREMUNKNOWN iface,
|
|
|
|
|
USHORT cInterfaceRefs,
|
|
|
|
|
REMINTERFACEREF* InterfaceRefs,
|
|
|
|
|
HRESULT* pResults)
|
|
|
|
|
{
|
|
|
|
|
RemUnkProxy *This = (RemUnkProxy *)iface;
|
|
|
|
|
RPCOLEMESSAGE msg;
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
ULONG status;
|
|
|
|
|
|
|
|
|
|
TRACE("(%p)->(%d,%p,%p)\n",This,
|
|
|
|
|
cInterfaceRefs,InterfaceRefs,pResults);
|
|
|
|
|
|
|
|
|
|
memset(&msg, 0, sizeof(msg));
|
|
|
|
|
msg.iMethod = 4;
|
|
|
|
|
msg.cbBuffer = sizeof(USHORT) + cInterfaceRefs*sizeof(REMINTERFACEREF);
|
|
|
|
|
hr = IRpcChannelBuffer_GetBuffer(This->chan, &msg, &IID_IRemUnknown);
|
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
|
LPBYTE buf = msg.Buffer;
|
|
|
|
|
memcpy(buf, &cInterfaceRefs, sizeof(USHORT));
|
|
|
|
|
buf += sizeof(USHORT);
|
|
|
|
|
memcpy(buf, InterfaceRefs, cInterfaceRefs*sizeof(REMINTERFACEREF));
|
|
|
|
|
|
|
|
|
|
hr = IRpcChannelBuffer_SendReceive(This->chan, &msg, &status);
|
|
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
|
buf = msg.Buffer;
|
|
|
|
|
memcpy(pResults, buf, cInterfaceRefs*sizeof(HRESULT));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IRpcChannelBuffer_FreeBuffer(This->chan, &msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI RemUnkProxy_RemRelease(LPREMUNKNOWN iface,
|
|
|
|
|
USHORT cInterfaceRefs,
|
|
|
|
|
REMINTERFACEREF* InterfaceRefs)
|
|
|
|
|
{
|
|
|
|
|
RemUnkProxy *This = (RemUnkProxy *)iface;
|
|
|
|
|
RPCOLEMESSAGE msg;
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
ULONG status;
|
|
|
|
|
|
|
|
|
|
TRACE("(%p)->(%d,%p)\n",This,
|
|
|
|
|
cInterfaceRefs,InterfaceRefs);
|
|
|
|
|
|
|
|
|
|
memset(&msg, 0, sizeof(msg));
|
|
|
|
|
msg.iMethod = 5;
|
|
|
|
|
msg.cbBuffer = sizeof(USHORT) + cInterfaceRefs*sizeof(REMINTERFACEREF);
|
|
|
|
|
hr = IRpcChannelBuffer_GetBuffer(This->chan, &msg, &IID_IRemUnknown);
|
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
|
LPBYTE buf = msg.Buffer;
|
|
|
|
|
memcpy(buf, &cInterfaceRefs, sizeof(USHORT));
|
|
|
|
|
buf += sizeof(USHORT);
|
|
|
|
|
memcpy(buf, InterfaceRefs, cInterfaceRefs*sizeof(REMINTERFACEREF));
|
|
|
|
|
|
|
|
|
|
hr = IRpcChannelBuffer_SendReceive(This->chan, &msg, &status);
|
|
|
|
|
|
|
|
|
|
IRpcChannelBuffer_FreeBuffer(This->chan, &msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const IRemUnknownVtbl RemUnkProxy_VTable =
|
|
|
|
|
{
|
|
|
|
|
RemUnkProxy_QueryInterface,
|
|
|
|
|
RemUnkProxy_AddRef,
|
|
|
|
|
RemUnkProxy_Release,
|
|
|
|
|
RemUnkProxy_RemQueryInterface,
|
|
|
|
|
RemUnkProxy_RemAddRef,
|
|
|
|
|
RemUnkProxy_RemRelease
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI RURpcProxyBufferImpl_QueryInterface(LPRPCPROXYBUFFER iface,REFIID riid,LPVOID *ppv) {
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
if (IsEqualIID(riid,&IID_IRpcProxyBuffer)||IsEqualIID(riid,&IID_IUnknown)) {
|
|
|
|
|
IRpcProxyBuffer_AddRef(iface);
|
|
|
|
|
*ppv = (LPVOID)iface;
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
FIXME("(%s), no interface.\n",debugstr_guid(riid));
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ULONG WINAPI RURpcProxyBufferImpl_AddRef(LPRPCPROXYBUFFER iface) {
|
|
|
|
|
ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
|
2006-10-15 12:28:08 +02:00
|
|
|
|
TRACE("%p, %d\n", iface, This->refs + 1);
|
2005-01-25 20:02:54 +01:00
|
|
|
|
return InterlockedIncrement(&This->refs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ULONG WINAPI RURpcProxyBufferImpl_Release(LPRPCPROXYBUFFER iface) {
|
|
|
|
|
ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
|
|
|
|
|
ULONG ref = InterlockedDecrement(&This->refs);
|
2006-10-15 12:28:08 +02:00
|
|
|
|
TRACE("%p, %d\n", iface, ref);
|
2005-01-25 20:02:54 +01:00
|
|
|
|
if (!ref) {
|
2005-09-18 13:10:37 +02:00
|
|
|
|
IRpcProxyBuffer_Disconnect(iface);
|
|
|
|
|
HeapFree(GetProcessHeap(),0,This);
|
2005-01-25 20:02:54 +01:00
|
|
|
|
}
|
|
|
|
|
return ref;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI RURpcProxyBufferImpl_Connect(LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer) {
|
|
|
|
|
ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
|
|
|
|
|
|
2005-06-05 20:13:47 +02:00
|
|
|
|
TRACE("%p, %p\n", iface, pRpcChannelBuffer);
|
2005-01-25 20:02:54 +01:00
|
|
|
|
This->chan = pRpcChannelBuffer;
|
|
|
|
|
IRpcChannelBuffer_AddRef(This->chan);
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
static void WINAPI RURpcProxyBufferImpl_Disconnect(LPRPCPROXYBUFFER iface) {
|
|
|
|
|
ICOM_THIS_MULTI(RemUnkProxy,lpvtbl_proxy,iface);
|
2005-06-05 20:13:47 +02:00
|
|
|
|
TRACE("%p, %p\n", iface, This->chan);
|
2005-01-25 20:02:54 +01:00
|
|
|
|
if (This->chan) {
|
|
|
|
|
IRpcChannelBuffer_Release(This->chan);
|
|
|
|
|
This->chan = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const IRpcProxyBufferVtbl RURpcProxyBuffer_VTable = {
|
|
|
|
|
RURpcProxyBufferImpl_QueryInterface,
|
|
|
|
|
RURpcProxyBufferImpl_AddRef,
|
|
|
|
|
RURpcProxyBufferImpl_Release,
|
|
|
|
|
RURpcProxyBufferImpl_Connect,
|
|
|
|
|
RURpcProxyBufferImpl_Disconnect
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static HRESULT
|
|
|
|
|
RemUnkProxy_Construct(IUnknown *pUnkOuter, LPVOID *ppv,LPVOID *ppProxy) {
|
|
|
|
|
RemUnkProxy *This;
|
|
|
|
|
|
|
|
|
|
This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*This));
|
|
|
|
|
if (!This)
|
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
|
|
This->lpvtbl_remunk = &RemUnkProxy_VTable;
|
|
|
|
|
This->lpvtbl_proxy = &RURpcProxyBuffer_VTable;
|
|
|
|
|
/* only one reference for the proxy buffer */
|
|
|
|
|
This->refs = 1;
|
|
|
|
|
This->outer_unknown = pUnkOuter;
|
|
|
|
|
*ppv = &(This->lpvtbl_remunk);
|
|
|
|
|
*ppProxy = &(This->lpvtbl_proxy);
|
2005-09-18 13:10:37 +02:00
|
|
|
|
/* and one reference for the object */
|
|
|
|
|
IUnknown_AddRef((IUnknown *)*ppv);
|
2005-01-25 20:02:54 +01:00
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
|
/********************* OLE Proxy/Stub Factory ********************************/
|
|
|
|
|
static HRESULT WINAPI
|
|
|
|
|
PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface, REFIID iid, LPVOID *ppv) {
|
|
|
|
|
if (IsEqualIID(iid,&IID_IPSFactoryBuffer)||IsEqualIID(iid,&IID_IUnknown)) {
|
2002-06-01 01:06:46 +02:00
|
|
|
|
*ppv = (LPVOID)iface;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
/* No ref counting, static class */
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
FIXME("(%s) unknown IID?\n",debugstr_guid(iid));
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ULONG WINAPI PSFacBuf_AddRef(LPPSFACTORYBUFFER iface) { return 2; }
|
|
|
|
|
static ULONG WINAPI PSFacBuf_Release(LPPSFACTORYBUFFER iface) { return 1; }
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI
|
|
|
|
|
PSFacBuf_CreateProxy(
|
|
|
|
|
LPPSFACTORYBUFFER iface, IUnknown* pUnkOuter, REFIID riid,
|
|
|
|
|
IRpcProxyBuffer **ppProxy, LPVOID *ppv
|
|
|
|
|
) {
|
2005-01-25 20:02:54 +01:00
|
|
|
|
if (IsEqualIID(&IID_IClassFactory,riid))
|
2005-01-04 12:47:52 +01:00
|
|
|
|
return CFProxy_Construct(pUnkOuter, ppv,(LPVOID*)ppProxy);
|
2005-01-25 20:02:54 +01:00
|
|
|
|
else if (IsEqualIID(&IID_IRemUnknown,riid))
|
|
|
|
|
return RemUnkProxy_Construct(pUnkOuter, ppv,(LPVOID*)ppProxy);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
FIXME("proxying not implemented for (%s) yet!\n",debugstr_guid(riid));
|
|
|
|
|
return E_FAIL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI
|
|
|
|
|
PSFacBuf_CreateStub(
|
|
|
|
|
LPPSFACTORYBUFFER iface, REFIID riid,IUnknown *pUnkServer,
|
|
|
|
|
IRpcStubBuffer** ppStub
|
|
|
|
|
) {
|
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
|
|
TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub);
|
|
|
|
|
|
2005-01-25 20:02:54 +01:00
|
|
|
|
if (IsEqualIID(&IID_IClassFactory, riid) ||
|
|
|
|
|
IsEqualIID(&IID_IUnknown, riid) /* FIXME: fixup stub manager and remove this*/) {
|
2002-02-05 19:11:17 +01:00
|
|
|
|
hres = CFStub_Construct(ppStub);
|
|
|
|
|
if (!hres)
|
|
|
|
|
IRpcStubBuffer_Connect((*ppStub),pUnkServer);
|
|
|
|
|
return hres;
|
2005-01-25 20:02:54 +01:00
|
|
|
|
} else if (IsEqualIID(&IID_IRemUnknown,riid)) {
|
|
|
|
|
hres = RemUnkStub_Construct(ppStub);
|
|
|
|
|
if (!hres)
|
|
|
|
|
IRpcStubBuffer_Connect((*ppStub),pUnkServer);
|
|
|
|
|
return hres;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
}
|
|
|
|
|
FIXME("stubbing not implemented for (%s) yet!\n",debugstr_guid(riid));
|
|
|
|
|
return E_FAIL;
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
|
static const IPSFactoryBufferVtbl psfacbufvtbl = {
|
2002-02-05 19:11:17 +01:00
|
|
|
|
PSFacBuf_QueryInterface,
|
|
|
|
|
PSFacBuf_AddRef,
|
|
|
|
|
PSFacBuf_Release,
|
|
|
|
|
PSFacBuf_CreateProxy,
|
|
|
|
|
PSFacBuf_CreateStub
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* This is the whole PSFactoryBuffer object, just the vtableptr */
|
2005-06-06 21:50:35 +02:00
|
|
|
|
static const IPSFactoryBufferVtbl *lppsfac = &psfacbufvtbl;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
|
* DllGetClassObject [OLE32.@]
|
2002-02-05 19:11:17 +01:00
|
|
|
|
*/
|
2005-08-08 19:35:28 +02:00
|
|
|
|
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
|
2002-02-05 19:11:17 +01:00
|
|
|
|
{
|
|
|
|
|
*ppv = NULL;
|
2005-05-19 16:22:14 +02:00
|
|
|
|
if (IsEqualIID(rclsid, &CLSID_PSFactoryBuffer))
|
|
|
|
|
return IPSFactoryBuffer_QueryInterface((IPSFactoryBuffer *)&lppsfac, iid, ppv);
|
2002-06-05 00:14:06 +02:00
|
|
|
|
if (IsEqualIID(rclsid,&CLSID_DfMarshal)&&(
|
|
|
|
|
IsEqualIID(iid,&IID_IClassFactory) ||
|
|
|
|
|
IsEqualIID(iid,&IID_IUnknown)
|
|
|
|
|
)
|
|
|
|
|
)
|
2002-02-05 19:11:17 +01:00
|
|
|
|
return MARSHAL_GetStandardMarshalCF(ppv);
|
2003-06-17 05:57:18 +02:00
|
|
|
|
if (IsEqualIID(rclsid,&CLSID_StdGlobalInterfaceTable) && (IsEqualIID(iid,&IID_IClassFactory) || IsEqualIID(iid,&IID_IUnknown)))
|
|
|
|
|
return StdGlobalInterfaceTable_GetFactory(ppv);
|
2005-05-19 16:22:14 +02:00
|
|
|
|
if (IsEqualCLSID(rclsid, &CLSID_FileMoniker))
|
|
|
|
|
return FileMonikerCF_Create(iid, ppv);
|
|
|
|
|
if (IsEqualCLSID(rclsid, &CLSID_ItemMoniker))
|
|
|
|
|
return ItemMonikerCF_Create(iid, ppv);
|
2006-05-08 13:36:13 +02:00
|
|
|
|
if (IsEqualCLSID(rclsid, &CLSID_AntiMoniker))
|
|
|
|
|
return AntiMonikerCF_Create(iid, ppv);
|
2006-05-08 13:41:06 +02:00
|
|
|
|
if (IsEqualCLSID(rclsid, &CLSID_CompositeMoniker))
|
|
|
|
|
return CompositeMonikerCF_Create(iid, ppv);
|
2006-05-08 16:55:14 +02:00
|
|
|
|
if (IsEqualCLSID(rclsid, &CLSID_ClassMoniker))
|
|
|
|
|
return ClassMonikerCF_Create(iid, ppv);
|
2003-06-17 05:57:18 +02:00
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
|
FIXME("\n\tCLSID:\t%s,\n\tIID:\t%s\n",debugstr_guid(rclsid),debugstr_guid(iid));
|
|
|
|
|
return CLASS_E_CLASSNOTAVAILABLE;
|
|
|
|
|
}
|