2 * DirectX DLL registration and unregistration
4 * Copyright (C) 2005 Rolf Kalbermatter
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
26 #define NONAMELESSSTRUCT
27 #define NONAMELESSUNION
39 #include "wine/unicode.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(qcap);
45 * defines and constants
47 #define MAX_KEY_LEN 260
49 static WCHAR const clsid_keyname[6] =
50 {'C','L','S','I','D',0 };
51 static WCHAR const ips32_keyname[15] =
52 {'I','n','P','r','o','c','S','e','r','v','e','r','3','2',0};
53 static WCHAR const tmodel_keyname[15] =
54 {'T','h','r','e','a','d','i','n','g','M','o','d','e','l',0};
55 static WCHAR const tmodel_both[] =
59 * SetupRegisterClass()
61 static HRESULT SetupRegisterClass(HKEY clsid, LPCWSTR szCLSID,
62 LPCWSTR szDescription,
65 LPCWSTR szThreadingModel)
67 HKEY hkey, hsubkey = NULL;
68 LONG ret = RegCreateKeyW(clsid, szCLSID, &hkey);
69 if (ERROR_SUCCESS != ret)
70 return HRESULT_FROM_WIN32(ret);
72 /* set description string */
73 ret = RegSetValueW(hkey, NULL, REG_SZ, szDescription,
74 sizeof(WCHAR) * (lstrlenW(szDescription) + 1));
75 if (ERROR_SUCCESS != ret)
78 /* create CLSID\\{"CLSID"}\\"ServerType" key, using key to CLSID\\{"CLSID"}
79 passed back by last call to RegCreateKeyW(). */
80 ret = RegCreateKeyW(hkey, szServerType, &hsubkey);
81 if (ERROR_SUCCESS != ret)
85 ret = RegSetValueW(hsubkey, NULL, REG_SZ, szFileName,
86 sizeof(WCHAR) * (lstrlenW(szFileName) + 1));
87 if (ERROR_SUCCESS != ret)
90 /* set threading model */
91 ret = RegSetValueExW(hsubkey, tmodel_keyname, 0L, REG_SZ,
92 (const BYTE*)szThreadingModel,
93 sizeof(WCHAR) * (lstrlenW(szThreadingModel) + 1));
98 return HRESULT_FROM_WIN32(ret);
102 * SetupRegisterFilter through IFilterMapper2
104 static HRESULT SetupRegisterFilter2(const AMOVIESETUP_FILTER * const pSetup,
105 IFilterMapper2 * pIFM2, BOOL bRegister)
112 /* unregister filter */
113 hr = IFilterMapper2_UnregisterFilter(pIFM2, 0, 0, pSetup->clsID);
119 rf2.dwMerit = pSetup->dwMerit;
120 rf2.u.s.cPins = pSetup->nPins;
121 rf2.u.s.rgPins = pSetup->lpPin;
123 /* register filter */
124 hr = IFilterMapper2_RegisterFilter(pIFM2, pSetup->clsID,
125 pSetup->strName, 0, 0, NULL, &rf2);
129 /* filter not found is ignored here,
130 but there is no #define for 0x80070002 */
131 if (HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr)
138 * SetupRegisterFilter through IFilterMapper
140 static HRESULT SetupRegisterFilter(const AMOVIESETUP_FILTER * const pSetup,
141 IFilterMapper * pIFM, BOOL bRegister)
148 /* unregister filter */
149 hr = IFilterMapper_UnregisterFilter(pIFM, *pSetup->clsID);
153 /* register filter */
154 hr = IFilterMapper_RegisterFilter(pIFM, *pSetup->clsID,
155 pSetup->strName, pSetup->dwMerit);
158 const AMOVIESETUP_PIN *lpPin = pSetup->lpPin;
159 const AMOVIESETUP_MEDIATYPE *lpType;
162 for (i = 0; i < pSetup->nPins; i++, lpPin++)
164 hr = IFilterMapper_RegisterPin(pIFM, *(pSetup->clsID),
170 *(lpPin->clsConnectsToFilter),
171 lpPin->strConnectsToPin);
175 lpType = lpPin->lpMediaType;
177 /* and each pin's media types */
178 for (j = 0; j < lpPin->nMediaTypes; j++, lpType++)
180 hr = IFilterMapper_RegisterPinType(pIFM, *(pSetup->clsID),
182 *(lpType->clsMajorType),
183 *(lpType->clsMinorType));
184 if (FAILED(hr)) break;
186 if (FAILED(hr)) break;
188 if (FAILED(hr)) break;
194 /* filter not registered is ignored here, there is no definition for 0x80070002 */
195 if (HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr)
202 * RegisterAllClasses()
204 static HRESULT SetupRegisterAllClasses(const CFactoryTemplate * pList, int num,
205 LPCWSTR szFileName, BOOL bRegister)
207 HRESULT hr = NOERROR;
209 OLECHAR szCLSID[CHARS_IN_GUID];
210 LONG i, ret = RegCreateKeyW(HKEY_CLASSES_ROOT, clsid_keyname, &hkey);
211 if (ERROR_SUCCESS != ret)
212 return HRESULT_FROM_WIN32(ret);
214 for (i = 0; i < num; i++, pList++)
216 /* (un)register CLSID and InprocServer32 */
217 hr = StringFromGUID2(pList->m_ClsID, szCLSID, CHARS_IN_GUID);
221 hr = SetupRegisterClass(hkey, szCLSID,
222 pList->m_Name, szFileName,
223 ips32_keyname, tmodel_both);
225 hr = RegDeleteTreeW(hkey, szCLSID);
233 /****************************************************************************
234 * SetupRegisterServers
236 * This function is table driven using the static members of the
237 * CFactoryTemplate class defined in the Dll.
239 * It registers the Dll as the InprocServer32 for all the classes in
242 ****************************************************************************/
243 HRESULT SetupRegisterServers(const CFactoryTemplate * pList, int num,
246 static const WCHAR szFileName[] = {'q','c','a','p','.','d','l','l',0};
247 HRESULT hr = NOERROR;
248 IFilterMapper2 *pIFM2 = NULL;
249 IFilterMapper *pIFM = NULL;
251 /* first register all server classes, just to make sure */
253 hr = SetupRegisterAllClasses(pList, num, szFileName, TRUE );
255 /* next, register/unregister all filters */
258 hr = CoInitialize(NULL);
260 TRACE("Getting IFilterMapper2\r\n");
261 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER,
262 &IID_IFilterMapper2, (void **)&pIFM2);
265 TRACE("- trying IFilterMapper instead\r\n");
267 hr = CoCreateInstance(&CLSID_FilterMapper, NULL, CLSCTX_INPROC_SERVER,
268 &IID_IFilterMapper, (void **)&pIFM);
275 /* scan through array of CFactoryTemplates registering all filters */
276 for (i = 0; i < num; i++, pList++)
278 if (NULL != pList->m_pAMovieSetup_Filter)
281 hr = SetupRegisterFilter2(pList->m_pAMovieSetup_Filter,
284 hr = SetupRegisterFilter(pList->m_pAMovieSetup_Filter,
288 /* check final error for this pass and break loop if we failed */
293 /* release interface */
295 IFilterMapper2_Release(pIFM2);
297 IFilterMapper_Release(pIFM);
301 CoFreeUnusedLibraries();
305 /* if unregistering, unregister all OLE servers */
306 if (SUCCEEDED(hr) && !bRegister)
307 hr = SetupRegisterAllClasses(pList, num, szFileName, FALSE);
311 /****************************************************************************
312 * SetupInitializeServers
314 * This function is table driven using the static members of the
315 * CFactoryTemplate class defined in the Dll.
317 * It calls the initialize function for any class in CFactoryTemplate with
320 ****************************************************************************/
321 void SetupInitializeServers(const CFactoryTemplate * pList, int num,
326 for (i = 0; i < num; i++, pList++)
328 if (pList->m_lpfnInit)
329 pList->m_lpfnInit(bLoading, pList->m_ClsID);