comcat: Get rid of the redundant IUnknown vtable for the manager implementation.
[wine/multimedia.git] / dlls / comcat / register.c
blob4fa80de657dc75cc7350d1c4f7cde4b9dca8ce7c
1 /*
2 * ComCatMgr ICatRegister implementation for comcat.dll
4 * Copyright (C) 2002 John K. Hohm
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "comcat_private.h"
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(ole);
27 /**********************************************************************
28 * File-scope string constants
30 static const WCHAR comcat_keyname[21] = {
31 'C', 'o', 'm', 'p', 'o', 'n', 'e', 'n', 't', ' ', 'C', 'a',
32 't', 'e', 'g', 'o', 'r', 'i', 'e', 's', 0 };
33 static const WCHAR impl_keyname[23] = {
34 'I', 'm', 'p', 'l', 'e', 'm', 'e', 'n',
35 't', 'e', 'd', ' ', 'C', 'a', 't', 'e',
36 'g', 'o', 'r', 'i', 'e', 's', 0 };
37 static const WCHAR req_keyname[20] = {
38 'R', 'e', 'q', 'u', 'i', 'r', 'e', 'd',
39 ' ', 'C', 'a', 't', 'e', 'g', 'o', 'r',
40 'i', 'e', 's', 0 };
42 static HRESULT COMCAT_RegisterClassCategories(
43 REFCLSID rclsid, LPCWSTR type,
44 ULONG cCategories, const CATID *rgcatid);
45 static HRESULT COMCAT_UnRegisterClassCategories(
46 REFCLSID rclsid, LPCWSTR type,
47 ULONG cCategories, const CATID *rgcatid);
49 /**********************************************************************
50 * COMCAT_ICatRegister_QueryInterface
52 static HRESULT WINAPI COMCAT_ICatRegister_QueryInterface(
53 LPCATREGISTER iface,
54 REFIID riid,
55 LPVOID *ppvObj)
57 ComCatMgrImpl *This = (ComCatMgrImpl *)iface;
58 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
60 if (ppvObj == NULL) return E_POINTER;
62 if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ICatRegister)) {
63 *ppvObj = iface;
64 IUnknown_AddRef(iface);
65 return S_OK;
68 if (IsEqualGUID(riid, &IID_ICatInformation)) {
69 *ppvObj = &This->infVtbl;
70 IUnknown_AddRef(iface);
71 return S_OK;
74 return E_NOINTERFACE;
77 /**********************************************************************
78 * COMCAT_ICatRegister_AddRef
80 static ULONG WINAPI COMCAT_ICatRegister_AddRef(LPCATREGISTER iface)
82 return 2; /* non-heap based object */
85 /**********************************************************************
86 * COMCAT_ICatRegister_Release
88 static ULONG WINAPI COMCAT_ICatRegister_Release(LPCATREGISTER iface)
90 return 1; /* non-heap based object */
93 /**********************************************************************
94 * COMCAT_ICatRegister_RegisterCategories
96 static HRESULT WINAPI COMCAT_ICatRegister_RegisterCategories(
97 LPCATREGISTER iface,
98 ULONG cCategories,
99 CATEGORYINFO *rgci)
101 HKEY comcat_key;
102 HRESULT res;
104 TRACE("\n");
106 if (cCategories && rgci == NULL)
107 return E_POINTER;
109 /* Create (or open) the component categories key. */
110 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, comcat_keyname, 0, NULL, 0,
111 KEY_READ | KEY_WRITE, NULL, &comcat_key, NULL);
112 if (res != ERROR_SUCCESS) return E_FAIL;
114 for (; cCategories; --cCategories, ++rgci) {
115 static const WCHAR fmt[] = { '%', 'l', 'X', 0 };
116 WCHAR keyname[39];
117 WCHAR valname[9];
118 HKEY cat_key;
120 /* Create (or open) the key for this category. */
121 if (!StringFromGUID2(&rgci->catid, keyname, 39)) continue;
122 res = RegCreateKeyExW(comcat_key, keyname, 0, NULL, 0,
123 KEY_READ | KEY_WRITE, NULL, &cat_key, NULL);
124 if (res != ERROR_SUCCESS) continue;
126 /* Set the value for this locale's description. */
127 wsprintfW(valname, fmt, rgci->lcid);
128 RegSetValueExW(cat_key, valname, 0, REG_SZ,
129 (CONST BYTE*)(rgci->szDescription),
130 (lstrlenW(rgci->szDescription) + 1) * sizeof(WCHAR));
132 RegCloseKey(cat_key);
135 RegCloseKey(comcat_key);
136 return S_OK;
139 /**********************************************************************
140 * COMCAT_ICatRegister_UnRegisterCategories
142 static HRESULT WINAPI COMCAT_ICatRegister_UnRegisterCategories(
143 LPCATREGISTER iface,
144 ULONG cCategories,
145 CATID *rgcatid)
147 HKEY comcat_key;
148 HRESULT res;
150 TRACE("\n");
152 if (cCategories && rgcatid == NULL)
153 return E_POINTER;
155 /* Open the component categories key. */
156 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, comcat_keyname, 0,
157 KEY_READ | KEY_WRITE, &comcat_key);
158 if (res != ERROR_SUCCESS) return E_FAIL;
160 for (; cCategories; --cCategories, ++rgcatid) {
161 WCHAR keyname[39];
163 /* Delete the key for this category. */
164 if (!StringFromGUID2(rgcatid, keyname, 39)) continue;
165 RegDeleteKeyW(comcat_key, keyname);
168 RegCloseKey(comcat_key);
169 return S_OK;
172 /**********************************************************************
173 * COMCAT_ICatRegister_RegisterClassImplCategories
175 static HRESULT WINAPI COMCAT_ICatRegister_RegisterClassImplCategories(
176 LPCATREGISTER iface,
177 REFCLSID rclsid,
178 ULONG cCategories,
179 CATID *rgcatid)
181 TRACE("\n");
183 return COMCAT_RegisterClassCategories(
184 rclsid, impl_keyname, cCategories, rgcatid);
187 /**********************************************************************
188 * COMCAT_ICatRegister_UnRegisterClassImplCategories
190 static HRESULT WINAPI COMCAT_ICatRegister_UnRegisterClassImplCategories(
191 LPCATREGISTER iface,
192 REFCLSID rclsid,
193 ULONG cCategories,
194 CATID *rgcatid)
196 TRACE("\n");
198 return COMCAT_UnRegisterClassCategories(
199 rclsid, impl_keyname, cCategories, rgcatid);
202 /**********************************************************************
203 * COMCAT_ICatRegister_RegisterClassReqCategories
205 static HRESULT WINAPI COMCAT_ICatRegister_RegisterClassReqCategories(
206 LPCATREGISTER iface,
207 REFCLSID rclsid,
208 ULONG cCategories,
209 CATID *rgcatid)
211 TRACE("\n");
213 return COMCAT_RegisterClassCategories(
214 rclsid, req_keyname, cCategories, rgcatid);
217 /**********************************************************************
218 * COMCAT_ICatRegister_UnRegisterClassReqCategories
220 static HRESULT WINAPI COMCAT_ICatRegister_UnRegisterClassReqCategories(
221 LPCATREGISTER iface,
222 REFCLSID rclsid,
223 ULONG cCategories,
224 CATID *rgcatid)
226 TRACE("\n");
228 return COMCAT_UnRegisterClassCategories(
229 rclsid, req_keyname, cCategories, rgcatid);
232 /**********************************************************************
233 * COMCAT_ICatRegister_Vtbl
235 static const ICatRegisterVtbl COMCAT_ICatRegister_Vtbl =
237 COMCAT_ICatRegister_QueryInterface,
238 COMCAT_ICatRegister_AddRef,
239 COMCAT_ICatRegister_Release,
240 COMCAT_ICatRegister_RegisterCategories,
241 COMCAT_ICatRegister_UnRegisterCategories,
242 COMCAT_ICatRegister_RegisterClassImplCategories,
243 COMCAT_ICatRegister_UnRegisterClassImplCategories,
244 COMCAT_ICatRegister_RegisterClassReqCategories,
245 COMCAT_ICatRegister_UnRegisterClassReqCategories
249 /**********************************************************************
250 * static ComCatMgr instance
252 ComCatMgrImpl COMCAT_ComCatMgr =
254 &COMCAT_ICatRegister_Vtbl,
255 &COMCAT_ICatInformation_Vtbl
258 /**********************************************************************
259 * COMCAT_RegisterClassCategories
261 static HRESULT COMCAT_RegisterClassCategories(
262 REFCLSID rclsid,
263 LPCWSTR type,
264 ULONG cCategories,
265 const CATID *rgcatid)
267 WCHAR keyname[39];
268 HRESULT res;
269 HKEY clsid_key, class_key, type_key;
271 if (cCategories && rgcatid == NULL) return E_POINTER;
273 /* Format the class key name. */
274 res = StringFromGUID2(rclsid, keyname, 39);
275 if (FAILED(res)) return res;
277 /* Create (or open) the CLSID key. */
278 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0,
279 KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL);
280 if (res != ERROR_SUCCESS) return E_FAIL;
282 /* Create (or open) the class key. */
283 res = RegCreateKeyExW(clsid_key, keyname, 0, NULL, 0,
284 KEY_READ | KEY_WRITE, NULL, &class_key, NULL);
285 if (res == ERROR_SUCCESS) {
286 /* Create (or open) the category type key. */
287 res = RegCreateKeyExW(class_key, type, 0, NULL, 0,
288 KEY_READ | KEY_WRITE, NULL, &type_key, NULL);
289 if (res == ERROR_SUCCESS) {
290 for (; cCategories; --cCategories, ++rgcatid) {
291 HKEY key;
293 /* Format the category key name. */
294 res = StringFromGUID2(rgcatid, keyname, 39);
295 if (FAILED(res)) continue;
297 /* Do the register. */
298 res = RegCreateKeyExW(type_key, keyname, 0, NULL, 0,
299 KEY_READ | KEY_WRITE, NULL, &key, NULL);
300 if (res == ERROR_SUCCESS) RegCloseKey(key);
302 res = S_OK;
303 } else res = E_FAIL;
304 RegCloseKey(class_key);
305 } else res = E_FAIL;
306 RegCloseKey(clsid_key);
308 return res;
311 /**********************************************************************
312 * COMCAT_UnRegisterClassCategories
314 static HRESULT COMCAT_UnRegisterClassCategories(
315 REFCLSID rclsid,
316 LPCWSTR type,
317 ULONG cCategories,
318 const CATID *rgcatid)
320 WCHAR keyname[68] = { 'C', 'L', 'S', 'I', 'D', '\\' };
321 HRESULT res;
322 HKEY type_key;
324 if (cCategories && rgcatid == NULL) return E_POINTER;
326 /* Format the class category type key name. */
327 res = StringFromGUID2(rclsid, keyname + 6, 39);
328 if (FAILED(res)) return res;
329 keyname[44] = '\\';
330 lstrcpyW(keyname + 45, type);
332 /* Open the class category type key. */
333 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0,
334 KEY_READ | KEY_WRITE, &type_key);
335 if (res != ERROR_SUCCESS) return E_FAIL;
337 for (; cCategories; --cCategories, ++rgcatid) {
338 /* Format the category key name. */
339 res = StringFromGUID2(rgcatid, keyname, 39);
340 if (FAILED(res)) continue;
342 /* Do the unregister. */
343 RegDeleteKeyW(type_key, keyname);
345 RegCloseKey(type_key);
347 return S_OK;