Get rid of the ICOM_MSVTABLE_COMPAT support, g++ no longer requires
[wine/multimedia.git] / dlls / rpcrt4 / cpsf.c
blob136232073e32060c8e36d6437dce4b39b24a7e47
1 /*
2 * COM proxy/stub factory (CStdPSFactory) implementation
4 * Copyright 2001 Ove Kåven, TransGaming Technologies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include <string.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winerror.h"
28 #include "winreg.h"
30 #include "objbase.h"
32 #include "rpcproxy.h"
34 #include "wine/debug.h"
36 #include "cpsf.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(ole);
40 static BOOL FindProxyInfo(const ProxyFileInfo **pProxyFileList, REFIID riid, const ProxyFileInfo **pProxyInfo, int *pIndex)
42 while (*pProxyFileList) {
43 if ((*pProxyFileList)->pIIDLookupRtn(riid, pIndex)) {
44 *pProxyInfo = *pProxyFileList;
45 TRACE("found: ProxyInfo %p Index %d\n", *pProxyInfo, *pIndex);
46 return TRUE;
48 pProxyFileList++;
50 TRACE("not found\n");
51 return FALSE;
54 static HRESULT WINAPI CStdPSFactory_QueryInterface(LPPSFACTORYBUFFER iface,
55 REFIID riid,
56 LPVOID *obj)
58 ICOM_THIS(CStdPSFactoryBuffer,iface);
59 TRACE("(%p)->QueryInterface(%s,%p)\n",iface,debugstr_guid(riid),obj);
60 if (IsEqualGUID(&IID_IUnknown,riid) ||
61 IsEqualGUID(&IID_IPSFactoryBuffer,riid)) {
62 *obj = This;
63 This->RefCount++;
64 return S_OK;
66 return E_NOINTERFACE;
69 static ULONG WINAPI CStdPSFactory_AddRef(LPPSFACTORYBUFFER iface)
71 ICOM_THIS(CStdPSFactoryBuffer,iface);
72 TRACE("(%p)->AddRef()\n",iface);
73 return ++(This->RefCount);
76 static ULONG WINAPI CStdPSFactory_Release(LPPSFACTORYBUFFER iface)
78 ICOM_THIS(CStdPSFactoryBuffer,iface);
79 TRACE("(%p)->Release()\n",iface);
80 return --(This->RefCount);
83 static HRESULT WINAPI CStdPSFactory_CreateProxy(LPPSFACTORYBUFFER iface,
84 LPUNKNOWN pUnkOuter,
85 REFIID riid,
86 LPRPCPROXYBUFFER *ppProxy,
87 LPVOID *ppv)
89 ICOM_THIS(CStdPSFactoryBuffer,iface);
90 const ProxyFileInfo *ProxyInfo;
91 int Index;
92 TRACE("(%p)->CreateProxy(%p,%s,%p,%p)\n",iface,pUnkOuter,
93 debugstr_guid(riid),ppProxy,ppv);
94 if (!FindProxyInfo(This->pProxyFileList,riid,&ProxyInfo,&Index))
95 return E_NOINTERFACE;
96 return StdProxy_Construct(riid, pUnkOuter, ProxyInfo->pNamesArray[Index],
97 ProxyInfo->pProxyVtblList[Index],
98 ProxyInfo->pStubVtblList[Index], iface, ppProxy, ppv);
101 static HRESULT WINAPI CStdPSFactory_CreateStub(LPPSFACTORYBUFFER iface,
102 REFIID riid,
103 LPUNKNOWN pUnkServer,
104 LPRPCSTUBBUFFER *ppStub)
106 ICOM_THIS(CStdPSFactoryBuffer,iface);
107 const ProxyFileInfo *ProxyInfo;
108 int Index;
109 TRACE("(%p)->CreateStub(%s,%p,%p)\n",iface,debugstr_guid(riid),
110 pUnkServer,ppStub);
111 if (!FindProxyInfo(This->pProxyFileList,riid,&ProxyInfo,&Index))
112 return E_NOINTERFACE;
113 return CStdStubBuffer_Construct(riid, pUnkServer, ProxyInfo->pNamesArray[Index],
114 ProxyInfo->pStubVtblList[Index], iface, ppStub);
117 static IPSFactoryBufferVtbl CStdPSFactory_Vtbl =
119 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
120 CStdPSFactory_QueryInterface,
121 CStdPSFactory_AddRef,
122 CStdPSFactory_Release,
123 CStdPSFactory_CreateProxy,
124 CStdPSFactory_CreateStub
127 /***********************************************************************
128 * NdrDllGetClassObject [RPCRT4.@]
130 HRESULT WINAPI NdrDllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv,
131 const ProxyFileInfo **pProxyFileList,
132 const CLSID *pclsid,
133 CStdPSFactoryBuffer *pPSFactoryBuffer)
135 *ppv = NULL;
136 if (!pPSFactoryBuffer->lpVtbl) {
137 pPSFactoryBuffer->lpVtbl = &CStdPSFactory_Vtbl;
138 pPSFactoryBuffer->RefCount = 0;
139 pPSFactoryBuffer->pProxyFileList = pProxyFileList;
141 if (IsEqualGUID(rclsid, pclsid))
142 return IPSFactoryBuffer_QueryInterface((LPPSFACTORYBUFFER)pPSFactoryBuffer, iid, ppv);
143 return CLASS_E_CLASSNOTAVAILABLE;
146 /***********************************************************************
147 * NdrDllCanUnloadNow [RPCRT4.@]
149 HRESULT WINAPI NdrDllCanUnloadNow(CStdPSFactoryBuffer *pPSFactoryBuffer)
151 return !(pPSFactoryBuffer->RefCount);
154 /***********************************************************************
155 * NdrDllRegisterProxy [RPCRT4.@]
157 HRESULT WINAPI NdrDllRegisterProxy(HMODULE hDll,
158 const ProxyFileInfo **pProxyFileList,
159 const CLSID *pclsid)
161 LPSTR clsid;
162 char keyname[120], module[MAX_PATH];
163 HKEY key, subkey;
164 DWORD len;
166 TRACE("(%p,%p,%s)\n", hDll, pProxyFileList, debugstr_guid(pclsid));
167 UuidToStringA((UUID*)pclsid, (unsigned char**)&clsid);
169 /* register interfaces to point to clsid */
170 while (*pProxyFileList) {
171 unsigned u;
172 for (u=0; u<(*pProxyFileList)->TableSize; u++) {
173 CInterfaceStubVtbl *proxy = (*pProxyFileList)->pStubVtblList[u];
174 PCInterfaceName name = (*pProxyFileList)->pNamesArray[u];
175 LPSTR iid;
177 TRACE("registering %s %s => %s\n", name, debugstr_guid(proxy->header.piid), clsid);
179 UuidToStringA((UUID*)proxy->header.piid, (unsigned char**)&iid);
180 snprintf(keyname, sizeof(keyname), "Interface\\{%s}", iid);
181 RpcStringFreeA((unsigned char**)&iid);
182 if (RegCreateKeyExA(HKEY_CLASSES_ROOT, keyname, 0, NULL, 0,
183 KEY_WRITE, NULL, &key, NULL) == ERROR_SUCCESS) {
184 if (name)
185 RegSetValueExA(key, NULL, 0, REG_SZ, name, strlen(name));
186 if (RegCreateKeyExA(key, "ProxyStubClsid32", 0, NULL, 0,
187 KEY_WRITE, NULL, &subkey, NULL) == ERROR_SUCCESS) {
188 snprintf(module, sizeof(module), "{%s}", clsid);
189 RegSetValueExA(subkey, NULL, 0, REG_SZ, module, strlen(module));
190 RegCloseKey(subkey);
192 RegCloseKey(key);
195 pProxyFileList++;
198 /* register clsid to point to module */
199 snprintf(keyname, sizeof(keyname), "CLSID\\{%s}", clsid);
200 len = GetModuleFileNameA(hDll, module, sizeof(module));
201 if (len && len < sizeof(module)) {
202 TRACE("registering CLSID %s => %s\n", clsid, module);
203 if (RegCreateKeyExA(HKEY_CLASSES_ROOT, keyname, 0, NULL, 0,
204 KEY_WRITE, NULL, &key, NULL) == ERROR_SUCCESS) {
205 if (RegCreateKeyExA(key, "InProcServer32", 0, NULL, 0,
206 KEY_WRITE, NULL, &subkey, NULL) == ERROR_SUCCESS) {
207 RegSetValueExA(subkey, NULL, 0, REG_SZ, module, strlen(module));
208 RegCloseKey(subkey);
210 RegCloseKey(key);
214 /* done */
215 RpcStringFreeA((unsigned char**)&clsid);
216 return S_OK;
219 /***********************************************************************
220 * NdrDllUnregisterProxy [RPCRT4.@]
222 HRESULT WINAPI NdrDllUnregisterProxy(HMODULE hDll,
223 const ProxyFileInfo **pProxyFileList,
224 const CLSID *pclsid)
226 LPSTR clsid;
227 char keyname[120], module[MAX_PATH];
228 DWORD len;
230 TRACE("(%p,%p,%s)\n", hDll, pProxyFileList, debugstr_guid(pclsid));
231 UuidToStringA((UUID*)pclsid, (unsigned char**)&clsid);
233 /* unregister interfaces */
234 while (*pProxyFileList) {
235 unsigned u;
236 for (u=0; u<(*pProxyFileList)->TableSize; u++) {
237 CInterfaceStubVtbl *proxy = (*pProxyFileList)->pStubVtblList[u];
238 PCInterfaceName name = (*pProxyFileList)->pNamesArray[u];
239 LPSTR iid;
241 TRACE("unregistering %s %s <= %s\n", name, debugstr_guid(proxy->header.piid), clsid);
243 UuidToStringA((UUID*)proxy->header.piid, (unsigned char**)&iid);
244 snprintf(keyname, sizeof(keyname), "Interface\\{%s}", iid);
245 RpcStringFreeA((unsigned char**)&iid);
246 RegDeleteKeyA(HKEY_CLASSES_ROOT, keyname);
248 pProxyFileList++;
251 /* unregister clsid */
252 snprintf(keyname, sizeof(keyname), "CLSID\\{%s}", clsid);
253 len = GetModuleFileNameA(hDll, module, sizeof(module));
254 if (len && len < sizeof(module)) {
255 TRACE("unregistering CLSID %s <= %s\n", clsid, module);
256 RegDeleteKeyA(HKEY_CLASSES_ROOT, keyname);
259 /* done */
260 RpcStringFreeA((unsigned char**)&clsid);
261 return S_OK;