2002-10-10 23:36:52 +00:00
|
|
|
|
/*
|
|
|
|
|
* COM proxy/stub factory (CStdPSFactory) implementation
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2001 Ove K<EFBFBD>ven, TransGaming Technologies
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*/
|
|
|
|
|
|
2003-09-05 23:08:26 +00:00
|
|
|
|
#include <stdarg.h>
|
2002-10-10 23:36:52 +00:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
|
#include "winbase.h"
|
|
|
|
|
#include "winerror.h"
|
|
|
|
|
#include "winreg.h"
|
|
|
|
|
|
2002-12-05 20:33:07 +00:00
|
|
|
|
#include "objbase.h"
|
2002-10-10 23:36:52 +00:00
|
|
|
|
|
|
|
|
|
#include "rpcproxy.h"
|
|
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
|
|
#include "cpsf.h"
|
|
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
|
|
|
|
|
|
|
|
|
static BOOL FindProxyInfo(const ProxyFileInfo **pProxyFileList, REFIID riid, const ProxyFileInfo **pProxyInfo, int *pIndex)
|
|
|
|
|
{
|
|
|
|
|
while (*pProxyFileList) {
|
|
|
|
|
if ((*pProxyFileList)->pIIDLookupRtn(riid, pIndex)) {
|
|
|
|
|
*pProxyInfo = *pProxyFileList;
|
|
|
|
|
TRACE("found: ProxyInfo %p Index %d\n", *pProxyInfo, *pIndex);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
pProxyFileList++;
|
|
|
|
|
}
|
|
|
|
|
TRACE("not found\n");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI CStdPSFactory_QueryInterface(LPPSFACTORYBUFFER iface,
|
|
|
|
|
REFIID riid,
|
|
|
|
|
LPVOID *obj)
|
|
|
|
|
{
|
2004-09-06 20:34:29 +00:00
|
|
|
|
CStdPSFactoryBuffer *This = (CStdPSFactoryBuffer *)iface;
|
2002-10-10 23:36:52 +00:00
|
|
|
|
TRACE("(%p)->QueryInterface(%s,%p)\n",iface,debugstr_guid(riid),obj);
|
|
|
|
|
if (IsEqualGUID(&IID_IUnknown,riid) ||
|
|
|
|
|
IsEqualGUID(&IID_IPSFactoryBuffer,riid)) {
|
|
|
|
|
*obj = This;
|
|
|
|
|
This->RefCount++;
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ULONG WINAPI CStdPSFactory_AddRef(LPPSFACTORYBUFFER iface)
|
|
|
|
|
{
|
2004-09-06 20:34:29 +00:00
|
|
|
|
CStdPSFactoryBuffer *This = (CStdPSFactoryBuffer *)iface;
|
2002-10-10 23:36:52 +00:00
|
|
|
|
TRACE("(%p)->AddRef()\n",iface);
|
|
|
|
|
return ++(This->RefCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ULONG WINAPI CStdPSFactory_Release(LPPSFACTORYBUFFER iface)
|
|
|
|
|
{
|
2004-09-06 20:34:29 +00:00
|
|
|
|
CStdPSFactoryBuffer *This = (CStdPSFactoryBuffer *)iface;
|
2002-10-10 23:36:52 +00:00
|
|
|
|
TRACE("(%p)->Release()\n",iface);
|
|
|
|
|
return --(This->RefCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI CStdPSFactory_CreateProxy(LPPSFACTORYBUFFER iface,
|
|
|
|
|
LPUNKNOWN pUnkOuter,
|
|
|
|
|
REFIID riid,
|
|
|
|
|
LPRPCPROXYBUFFER *ppProxy,
|
|
|
|
|
LPVOID *ppv)
|
|
|
|
|
{
|
2004-09-06 20:34:29 +00:00
|
|
|
|
CStdPSFactoryBuffer *This = (CStdPSFactoryBuffer *)iface;
|
2002-10-10 23:36:52 +00:00
|
|
|
|
const ProxyFileInfo *ProxyInfo;
|
|
|
|
|
int Index;
|
|
|
|
|
TRACE("(%p)->CreateProxy(%p,%s,%p,%p)\n",iface,pUnkOuter,
|
|
|
|
|
debugstr_guid(riid),ppProxy,ppv);
|
|
|
|
|
if (!FindProxyInfo(This->pProxyFileList,riid,&ProxyInfo,&Index))
|
|
|
|
|
return E_NOINTERFACE;
|
2003-05-20 04:13:44 +00:00
|
|
|
|
return StdProxy_Construct(riid, pUnkOuter, ProxyInfo->pNamesArray[Index],
|
|
|
|
|
ProxyInfo->pProxyVtblList[Index],
|
|
|
|
|
ProxyInfo->pStubVtblList[Index], iface, ppProxy, ppv);
|
2002-10-10 23:36:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI CStdPSFactory_CreateStub(LPPSFACTORYBUFFER iface,
|
|
|
|
|
REFIID riid,
|
|
|
|
|
LPUNKNOWN pUnkServer,
|
|
|
|
|
LPRPCSTUBBUFFER *ppStub)
|
|
|
|
|
{
|
2004-09-06 20:34:29 +00:00
|
|
|
|
CStdPSFactoryBuffer *This = (CStdPSFactoryBuffer *)iface;
|
2002-10-10 23:36:52 +00:00
|
|
|
|
const ProxyFileInfo *ProxyInfo;
|
|
|
|
|
int Index;
|
|
|
|
|
TRACE("(%p)->CreateStub(%s,%p,%p)\n",iface,debugstr_guid(riid),
|
|
|
|
|
pUnkServer,ppStub);
|
|
|
|
|
if (!FindProxyInfo(This->pProxyFileList,riid,&ProxyInfo,&Index))
|
|
|
|
|
return E_NOINTERFACE;
|
2003-05-20 04:13:44 +00:00
|
|
|
|
return CStdStubBuffer_Construct(riid, pUnkServer, ProxyInfo->pNamesArray[Index],
|
|
|
|
|
ProxyInfo->pStubVtblList[Index], iface, ppStub);
|
2002-10-10 23:36:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-08-12 23:00:51 +00:00
|
|
|
|
static IPSFactoryBufferVtbl CStdPSFactory_Vtbl =
|
2002-10-10 23:36:52 +00:00
|
|
|
|
{
|
|
|
|
|
CStdPSFactory_QueryInterface,
|
|
|
|
|
CStdPSFactory_AddRef,
|
|
|
|
|
CStdPSFactory_Release,
|
|
|
|
|
CStdPSFactory_CreateProxy,
|
|
|
|
|
CStdPSFactory_CreateStub
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* NdrDllGetClassObject [RPCRT4.@]
|
|
|
|
|
*/
|
|
|
|
|
HRESULT WINAPI NdrDllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv,
|
|
|
|
|
const ProxyFileInfo **pProxyFileList,
|
|
|
|
|
const CLSID *pclsid,
|
|
|
|
|
CStdPSFactoryBuffer *pPSFactoryBuffer)
|
|
|
|
|
{
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
if (!pPSFactoryBuffer->lpVtbl) {
|
|
|
|
|
pPSFactoryBuffer->lpVtbl = &CStdPSFactory_Vtbl;
|
|
|
|
|
pPSFactoryBuffer->RefCount = 0;
|
|
|
|
|
pPSFactoryBuffer->pProxyFileList = pProxyFileList;
|
|
|
|
|
}
|
|
|
|
|
if (IsEqualGUID(rclsid, pclsid))
|
|
|
|
|
return IPSFactoryBuffer_QueryInterface((LPPSFACTORYBUFFER)pPSFactoryBuffer, iid, ppv);
|
|
|
|
|
return CLASS_E_CLASSNOTAVAILABLE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* NdrDllCanUnloadNow [RPCRT4.@]
|
|
|
|
|
*/
|
|
|
|
|
HRESULT WINAPI NdrDllCanUnloadNow(CStdPSFactoryBuffer *pPSFactoryBuffer)
|
|
|
|
|
{
|
|
|
|
|
return !(pPSFactoryBuffer->RefCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* NdrDllRegisterProxy [RPCRT4.@]
|
|
|
|
|
*/
|
|
|
|
|
HRESULT WINAPI NdrDllRegisterProxy(HMODULE hDll,
|
|
|
|
|
const ProxyFileInfo **pProxyFileList,
|
|
|
|
|
const CLSID *pclsid)
|
|
|
|
|
{
|
|
|
|
|
LPSTR clsid;
|
2004-05-19 03:22:55 +00:00
|
|
|
|
char keyname[120], module[MAX_PATH];
|
2002-10-10 23:36:52 +00:00
|
|
|
|
HKEY key, subkey;
|
2004-05-19 03:22:55 +00:00
|
|
|
|
DWORD len;
|
2002-10-10 23:36:52 +00:00
|
|
|
|
|
2002-10-18 23:48:57 +00:00
|
|
|
|
TRACE("(%p,%p,%s)\n", hDll, pProxyFileList, debugstr_guid(pclsid));
|
2002-12-24 00:26:55 +00:00
|
|
|
|
UuidToStringA((UUID*)pclsid, (unsigned char**)&clsid);
|
2002-10-10 23:36:52 +00:00
|
|
|
|
|
|
|
|
|
/* register interfaces to point to clsid */
|
|
|
|
|
while (*pProxyFileList) {
|
|
|
|
|
unsigned u;
|
|
|
|
|
for (u=0; u<(*pProxyFileList)->TableSize; u++) {
|
2003-02-17 01:47:54 +00:00
|
|
|
|
CInterfaceStubVtbl *proxy = (*pProxyFileList)->pStubVtblList[u];
|
2002-10-10 23:36:52 +00:00
|
|
|
|
PCInterfaceName name = (*pProxyFileList)->pNamesArray[u];
|
|
|
|
|
LPSTR iid;
|
|
|
|
|
|
|
|
|
|
TRACE("registering %s %s => %s\n", name, debugstr_guid(proxy->header.piid), clsid);
|
|
|
|
|
|
2002-12-24 00:26:55 +00:00
|
|
|
|
UuidToStringA((UUID*)proxy->header.piid, (unsigned char**)&iid);
|
2003-05-20 04:13:44 +00:00
|
|
|
|
snprintf(keyname, sizeof(keyname), "Interface\\{%s}", iid);
|
2002-12-24 00:26:55 +00:00
|
|
|
|
RpcStringFreeA((unsigned char**)&iid);
|
2002-10-10 23:36:52 +00:00
|
|
|
|
if (RegCreateKeyExA(HKEY_CLASSES_ROOT, keyname, 0, NULL, 0,
|
|
|
|
|
KEY_WRITE, NULL, &key, NULL) == ERROR_SUCCESS) {
|
|
|
|
|
if (name)
|
|
|
|
|
RegSetValueExA(key, NULL, 0, REG_SZ, name, strlen(name));
|
|
|
|
|
if (RegCreateKeyExA(key, "ProxyStubClsid32", 0, NULL, 0,
|
|
|
|
|
KEY_WRITE, NULL, &subkey, NULL) == ERROR_SUCCESS) {
|
2003-05-20 04:13:44 +00:00
|
|
|
|
snprintf(module, sizeof(module), "{%s}", clsid);
|
|
|
|
|
RegSetValueExA(subkey, NULL, 0, REG_SZ, module, strlen(module));
|
2002-10-10 23:36:52 +00:00
|
|
|
|
RegCloseKey(subkey);
|
|
|
|
|
}
|
|
|
|
|
RegCloseKey(key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pProxyFileList++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* register clsid to point to module */
|
2003-05-20 04:13:44 +00:00
|
|
|
|
snprintf(keyname, sizeof(keyname), "CLSID\\{%s}", clsid);
|
2004-05-19 03:22:55 +00:00
|
|
|
|
len = GetModuleFileNameA(hDll, module, sizeof(module));
|
|
|
|
|
if (len && len < sizeof(module)) {
|
|
|
|
|
TRACE("registering CLSID %s => %s\n", clsid, module);
|
|
|
|
|
if (RegCreateKeyExA(HKEY_CLASSES_ROOT, keyname, 0, NULL, 0,
|
|
|
|
|
KEY_WRITE, NULL, &key, NULL) == ERROR_SUCCESS) {
|
|
|
|
|
if (RegCreateKeyExA(key, "InProcServer32", 0, NULL, 0,
|
|
|
|
|
KEY_WRITE, NULL, &subkey, NULL) == ERROR_SUCCESS) {
|
|
|
|
|
RegSetValueExA(subkey, NULL, 0, REG_SZ, module, strlen(module));
|
|
|
|
|
RegCloseKey(subkey);
|
|
|
|
|
}
|
|
|
|
|
RegCloseKey(key);
|
|
|
|
|
}
|
2002-10-10 23:36:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* done */
|
2002-12-24 00:26:55 +00:00
|
|
|
|
RpcStringFreeA((unsigned char**)&clsid);
|
2002-10-10 23:36:52 +00:00
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* NdrDllUnregisterProxy [RPCRT4.@]
|
|
|
|
|
*/
|
|
|
|
|
HRESULT WINAPI NdrDllUnregisterProxy(HMODULE hDll,
|
|
|
|
|
const ProxyFileInfo **pProxyFileList,
|
|
|
|
|
const CLSID *pclsid)
|
|
|
|
|
{
|
|
|
|
|
LPSTR clsid;
|
2004-05-19 03:22:55 +00:00
|
|
|
|
char keyname[120], module[MAX_PATH];
|
|
|
|
|
DWORD len;
|
2002-10-10 23:36:52 +00:00
|
|
|
|
|
2002-10-18 23:48:57 +00:00
|
|
|
|
TRACE("(%p,%p,%s)\n", hDll, pProxyFileList, debugstr_guid(pclsid));
|
2002-12-24 00:26:55 +00:00
|
|
|
|
UuidToStringA((UUID*)pclsid, (unsigned char**)&clsid);
|
2002-10-10 23:36:52 +00:00
|
|
|
|
|
|
|
|
|
/* unregister interfaces */
|
|
|
|
|
while (*pProxyFileList) {
|
|
|
|
|
unsigned u;
|
|
|
|
|
for (u=0; u<(*pProxyFileList)->TableSize; u++) {
|
2003-02-17 01:47:54 +00:00
|
|
|
|
CInterfaceStubVtbl *proxy = (*pProxyFileList)->pStubVtblList[u];
|
2002-10-10 23:36:52 +00:00
|
|
|
|
PCInterfaceName name = (*pProxyFileList)->pNamesArray[u];
|
|
|
|
|
LPSTR iid;
|
|
|
|
|
|
|
|
|
|
TRACE("unregistering %s %s <= %s\n", name, debugstr_guid(proxy->header.piid), clsid);
|
|
|
|
|
|
2002-12-24 00:26:55 +00:00
|
|
|
|
UuidToStringA((UUID*)proxy->header.piid, (unsigned char**)&iid);
|
2003-05-20 04:13:44 +00:00
|
|
|
|
snprintf(keyname, sizeof(keyname), "Interface\\{%s}", iid);
|
2002-12-24 00:26:55 +00:00
|
|
|
|
RpcStringFreeA((unsigned char**)&iid);
|
2002-10-10 23:36:52 +00:00
|
|
|
|
RegDeleteKeyA(HKEY_CLASSES_ROOT, keyname);
|
|
|
|
|
}
|
|
|
|
|
pProxyFileList++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* unregister clsid */
|
2003-05-20 04:13:44 +00:00
|
|
|
|
snprintf(keyname, sizeof(keyname), "CLSID\\{%s}", clsid);
|
2004-05-19 03:22:55 +00:00
|
|
|
|
len = GetModuleFileNameA(hDll, module, sizeof(module));
|
|
|
|
|
if (len && len < sizeof(module)) {
|
|
|
|
|
TRACE("unregistering CLSID %s <= %s\n", clsid, module);
|
|
|
|
|
RegDeleteKeyA(HKEY_CLASSES_ROOT, keyname);
|
|
|
|
|
}
|
2002-10-10 23:36:52 +00:00
|
|
|
|
|
|
|
|
|
/* done */
|
2002-12-24 00:26:55 +00:00
|
|
|
|
RpcStringFreeA((unsigned char**)&clsid);
|
2002-10-10 23:36:52 +00:00
|
|
|
|
return S_OK;
|
|
|
|
|
}
|