Added handling of SBM_GETSCROLLBARINFO message.
[wine/wine-gecko.git] / dlls / rpcrt4 / cpsf.c
blob55af27c5790e3e3fdedef18a803f71c508b7a9e6
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 #define COBJMACROS
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winerror.h"
30 #include "winreg.h"
32 #include "objbase.h"
34 #include "rpcproxy.h"
36 #include "wine/debug.h"
38 #include "cpsf.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(ole);
42 static BOOL FindProxyInfo(const ProxyFileInfo **pProxyFileList, REFIID riid, const ProxyFileInfo **pProxyInfo, int *pIndex)
44 while (*pProxyFileList) {
45 if ((*pProxyFileList)->pIIDLookupRtn(riid, pIndex)) {
46 *pProxyInfo = *pProxyFileList;
47 TRACE("found: ProxyInfo %p Index %d\n", *pProxyInfo, *pIndex);
48 return TRUE;
50 pProxyFileList++;
52 TRACE("not found\n");
53 return FALSE;
56 static HRESULT WINAPI CStdPSFactory_QueryInterface(LPPSFACTORYBUFFER iface,
57 REFIID riid,
58 LPVOID *obj)
60 CStdPSFactoryBuffer *This = (CStdPSFactoryBuffer *)iface;
61 TRACE("(%p)->QueryInterface(%s,%p)\n",iface,debugstr_guid(riid),obj);
62 if (IsEqualGUID(&IID_IUnknown,riid) ||
63 IsEqualGUID(&IID_IPSFactoryBuffer,riid)) {
64 *obj = This;
65 This->RefCount++;
66 return S_OK;
68 return E_NOINTERFACE;
71 static ULONG WINAPI CStdPSFactory_AddRef(LPPSFACTORYBUFFER iface)
73 CStdPSFactoryBuffer *This = (CStdPSFactoryBuffer *)iface;
74 TRACE("(%p)->AddRef()\n",iface);
75 return ++(This->RefCount);
78 static ULONG WINAPI CStdPSFactory_Release(LPPSFACTORYBUFFER iface)
80 CStdPSFactoryBuffer *This = (CStdPSFactoryBuffer *)iface;
81 TRACE("(%p)->Release()\n",iface);
82 return --(This->RefCount);
85 static HRESULT WINAPI CStdPSFactory_CreateProxy(LPPSFACTORYBUFFER iface,
86 LPUNKNOWN pUnkOuter,
87 REFIID riid,
88 LPRPCPROXYBUFFER *ppProxy,
89 LPVOID *ppv)
91 CStdPSFactoryBuffer *This = (CStdPSFactoryBuffer *)iface;
92 const ProxyFileInfo *ProxyInfo;
93 int Index;
94 TRACE("(%p)->CreateProxy(%p,%s,%p,%p)\n",iface,pUnkOuter,
95 debugstr_guid(riid),ppProxy,ppv);
96 if (!FindProxyInfo(This->pProxyFileList,riid,&ProxyInfo,&Index))
97 return E_NOINTERFACE;
98 return StdProxy_Construct(riid, pUnkOuter, ProxyInfo->pNamesArray[Index],
99 ProxyInfo->pProxyVtblList[Index],
100 ProxyInfo->pStubVtblList[Index], iface, ppProxy, ppv);
103 static HRESULT WINAPI CStdPSFactory_CreateStub(LPPSFACTORYBUFFER iface,
104 REFIID riid,
105 LPUNKNOWN pUnkServer,
106 LPRPCSTUBBUFFER *ppStub)
108 CStdPSFactoryBuffer *This = (CStdPSFactoryBuffer *)iface;
109 const ProxyFileInfo *ProxyInfo;
110 int Index;
111 TRACE("(%p)->CreateStub(%s,%p,%p)\n",iface,debugstr_guid(riid),
112 pUnkServer,ppStub);
113 if (!FindProxyInfo(This->pProxyFileList,riid,&ProxyInfo,&Index))
114 return E_NOINTERFACE;
115 return CStdStubBuffer_Construct(riid, pUnkServer, ProxyInfo->pNamesArray[Index],
116 ProxyInfo->pStubVtblList[Index], iface, ppStub);
119 static IPSFactoryBufferVtbl CStdPSFactory_Vtbl =
121 CStdPSFactory_QueryInterface,
122 CStdPSFactory_AddRef,
123 CStdPSFactory_Release,
124 CStdPSFactory_CreateProxy,
125 CStdPSFactory_CreateStub
128 /***********************************************************************
129 * NdrDllGetClassObject [RPCRT4.@]
131 HRESULT WINAPI NdrDllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv,
132 const ProxyFileInfo **pProxyFileList,
133 const CLSID *pclsid,
134 CStdPSFactoryBuffer *pPSFactoryBuffer)
136 *ppv = NULL;
137 if (!pPSFactoryBuffer->lpVtbl) {
138 pPSFactoryBuffer->lpVtbl = &CStdPSFactory_Vtbl;
139 pPSFactoryBuffer->RefCount = 0;
140 pPSFactoryBuffer->pProxyFileList = pProxyFileList;
142 if (IsEqualGUID(rclsid, pclsid))
143 return IPSFactoryBuffer_QueryInterface((LPPSFACTORYBUFFER)pPSFactoryBuffer, iid, ppv);
144 return CLASS_E_CLASSNOTAVAILABLE;
147 /***********************************************************************
148 * NdrDllCanUnloadNow [RPCRT4.@]
150 HRESULT WINAPI NdrDllCanUnloadNow(CStdPSFactoryBuffer *pPSFactoryBuffer)
152 return !(pPSFactoryBuffer->RefCount);
155 /***********************************************************************
156 * NdrDllRegisterProxy [RPCRT4.@]
158 HRESULT WINAPI NdrDllRegisterProxy(HMODULE hDll,
159 const ProxyFileInfo **pProxyFileList,
160 const CLSID *pclsid)
162 LPSTR clsid;
163 char keyname[120], module[MAX_PATH];
164 HKEY key, subkey;
165 DWORD len;
167 TRACE("(%p,%p,%s)\n", hDll, pProxyFileList, debugstr_guid(pclsid));
168 UuidToStringA((UUID*)pclsid, (unsigned char**)&clsid);
170 /* register interfaces to point to clsid */
171 while (*pProxyFileList) {
172 unsigned u;
173 for (u=0; u<(*pProxyFileList)->TableSize; u++) {
174 CInterfaceStubVtbl *proxy = (*pProxyFileList)->pStubVtblList[u];
175 PCInterfaceName name = (*pProxyFileList)->pNamesArray[u];
176 LPSTR iid;
178 TRACE("registering %s %s => %s\n", name, debugstr_guid(proxy->header.piid), clsid);
180 UuidToStringA((UUID*)proxy->header.piid, (unsigned char**)&iid);
181 snprintf(keyname, sizeof(keyname), "Interface\\{%s}", iid);
182 RpcStringFreeA((unsigned char**)&iid);
183 if (RegCreateKeyExA(HKEY_CLASSES_ROOT, keyname, 0, NULL, 0,
184 KEY_WRITE, NULL, &key, NULL) == ERROR_SUCCESS) {
185 if (name)
186 RegSetValueExA(key, NULL, 0, REG_SZ, name, strlen(name));
187 if (RegCreateKeyExA(key, "ProxyStubClsid32", 0, NULL, 0,
188 KEY_WRITE, NULL, &subkey, NULL) == ERROR_SUCCESS) {
189 snprintf(module, sizeof(module), "{%s}", clsid);
190 RegSetValueExA(subkey, NULL, 0, REG_SZ, module, strlen(module));
191 RegCloseKey(subkey);
193 RegCloseKey(key);
196 pProxyFileList++;
199 /* register clsid to point to module */
200 snprintf(keyname, sizeof(keyname), "CLSID\\{%s}", clsid);
201 len = GetModuleFileNameA(hDll, module, sizeof(module));
202 if (len && len < sizeof(module)) {
203 TRACE("registering CLSID %s => %s\n", clsid, module);
204 if (RegCreateKeyExA(HKEY_CLASSES_ROOT, keyname, 0, NULL, 0,
205 KEY_WRITE, NULL, &key, NULL) == ERROR_SUCCESS) {
206 if (RegCreateKeyExA(key, "InProcServer32", 0, NULL, 0,
207 KEY_WRITE, NULL, &subkey, NULL) == ERROR_SUCCESS) {
208 RegSetValueExA(subkey, NULL, 0, REG_SZ, module, strlen(module));
209 RegCloseKey(subkey);
211 RegCloseKey(key);
215 /* done */
216 RpcStringFreeA((unsigned char**)&clsid);
217 return S_OK;
220 /***********************************************************************
221 * NdrDllUnregisterProxy [RPCRT4.@]
223 HRESULT WINAPI NdrDllUnregisterProxy(HMODULE hDll,
224 const ProxyFileInfo **pProxyFileList,
225 const CLSID *pclsid)
227 LPSTR clsid;
228 char keyname[120], module[MAX_PATH];
229 DWORD len;
231 TRACE("(%p,%p,%s)\n", hDll, pProxyFileList, debugstr_guid(pclsid));
232 UuidToStringA((UUID*)pclsid, (unsigned char**)&clsid);
234 /* unregister interfaces */
235 while (*pProxyFileList) {
236 unsigned u;
237 for (u=0; u<(*pProxyFileList)->TableSize; u++) {
238 CInterfaceStubVtbl *proxy = (*pProxyFileList)->pStubVtblList[u];
239 PCInterfaceName name = (*pProxyFileList)->pNamesArray[u];
240 LPSTR iid;
242 TRACE("unregistering %s %s <= %s\n", name, debugstr_guid(proxy->header.piid), clsid);
244 UuidToStringA((UUID*)proxy->header.piid, (unsigned char**)&iid);
245 snprintf(keyname, sizeof(keyname), "Interface\\{%s}", iid);
246 RpcStringFreeA((unsigned char**)&iid);
247 RegDeleteKeyA(HKEY_CLASSES_ROOT, keyname);
249 pProxyFileList++;
252 /* unregister clsid */
253 snprintf(keyname, sizeof(keyname), "CLSID\\{%s}", clsid);
254 len = GetModuleFileNameA(hDll, module, sizeof(module));
255 if (len && len < sizeof(module)) {
256 TRACE("unregistering CLSID %s <= %s\n", clsid, module);
257 RegDeleteKeyA(HKEY_CLASSES_ROOT, keyname);
260 /* done */
261 RpcStringFreeA((unsigned char**)&clsid);
262 return S_OK;