msxml3: Properly free namespace structure pointer.
[wine/testsucceed.git] / dlls / qcap / dllsetup.c
bloba732b73a9eff68f8c7805be589cb5df7a127bae9
1 /*
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
20 #include "config.h"
22 #include <stdarg.h>
23 #include <assert.h>
25 #define COBJMACROS
26 #define NONAMELESSSTRUCT
27 #define NONAMELESSUNION
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winerror.h"
33 #include "winreg.h"
34 #include "objbase.h"
35 #include "uuids.h"
37 #include "dllsetup.h"
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[] =
56 {'B','o','t','h',0};
59 * SetupRegisterClass()
61 static HRESULT SetupRegisterClass(HKEY clsid, LPCWSTR szCLSID,
62 LPCWSTR szDescription,
63 LPCWSTR szFileName,
64 LPCWSTR szServerType,
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)
76 goto err_out;
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)
82 goto err_out;
84 /* set server path */
85 ret = RegSetValueW(hsubkey, NULL, REG_SZ, szFileName,
86 sizeof(WCHAR) * (lstrlenW(szFileName) + 1));
87 if (ERROR_SUCCESS != ret)
88 goto err_out;
90 /* set threading model */
91 ret = RegSetValueExW(hsubkey, tmodel_keyname, 0L, REG_SZ,
92 (const BYTE*)szThreadingModel,
93 sizeof(WCHAR) * (lstrlenW(szThreadingModel) + 1));
94 err_out:
95 if (hsubkey)
96 RegCloseKey(hsubkey);
97 RegCloseKey(hkey);
98 return HRESULT_FROM_WIN32(ret);
102 * RegisterAllClasses()
104 static HRESULT SetupRegisterAllClasses(const CFactoryTemplate * pList, int num,
105 LPCWSTR szFileName, BOOL bRegister)
107 HRESULT hr = NOERROR;
108 HKEY hkey;
109 OLECHAR szCLSID[CHARS_IN_GUID];
110 LONG i, ret = RegCreateKeyW(HKEY_CLASSES_ROOT, clsid_keyname, &hkey);
111 if (ERROR_SUCCESS != ret)
112 return HRESULT_FROM_WIN32(ret);
114 for (i = 0; i < num; i++, pList++)
116 /* (un)register CLSID and InprocServer32 */
117 hr = StringFromGUID2(pList->m_ClsID, szCLSID, CHARS_IN_GUID);
118 if (SUCCEEDED(hr))
120 if (bRegister )
121 hr = SetupRegisterClass(hkey, szCLSID,
122 pList->m_Name, szFileName,
123 ips32_keyname, tmodel_both);
124 else
125 hr = RegDeleteTreeW(hkey, szCLSID);
128 RegCloseKey(hkey);
129 return hr;
133 /****************************************************************************
134 * SetupRegisterServers
136 * This function is table driven using the static members of the
137 * CFactoryTemplate class defined in the Dll.
139 * It registers the Dll as the InprocServer32 for all the classes in
140 * CFactoryTemplate
142 ****************************************************************************/
143 HRESULT SetupRegisterServers(const CFactoryTemplate * pList, int num,
144 BOOL bRegister)
146 static const WCHAR szFileName[] = {'q','c','a','p','.','d','l','l',0};
147 HRESULT hr = NOERROR;
148 IFilterMapper2 *pIFM2 = NULL;
150 /* first register all server classes, just to make sure */
151 if (bRegister)
152 hr = SetupRegisterAllClasses(pList, num, szFileName, TRUE );
154 /* next, register/unregister all filters */
155 if (SUCCEEDED(hr))
157 hr = CoInitialize(NULL);
159 TRACE("Getting IFilterMapper2\r\n");
160 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER,
161 &IID_IFilterMapper2, (void **)&pIFM2);
163 if (SUCCEEDED(hr))
165 int i;
167 /* scan through array of CFactoryTemplates registering all filters */
168 for (i = 0; i < num; i++, pList++)
170 if (pList->m_pAMovieSetup_Filter.dwVersion)
172 hr = IFilterMapper2_RegisterFilter(pIFM2, pList->m_ClsID, pList->m_Name, NULL, &CLSID_LegacyAmFilterCategory, NULL, &pList->m_pAMovieSetup_Filter);
175 /* check final error for this pass and break loop if we failed */
176 if (FAILED(hr))
177 break;
180 /* release interface */
181 IFilterMapper2_Release(pIFM2);
184 /* and clear up */
185 CoFreeUnusedLibraries();
186 CoUninitialize();
189 /* if unregistering, unregister all OLE servers */
190 if (SUCCEEDED(hr) && !bRegister)
191 hr = SetupRegisterAllClasses(pList, num, szFileName, FALSE);
192 return hr;
195 /****************************************************************************
196 * SetupInitializeServers
198 * This function is table driven using the static members of the
199 * CFactoryTemplate class defined in the Dll.
201 * It calls the initialize function for any class in CFactoryTemplate with
202 * one defined.
204 ****************************************************************************/
205 void SetupInitializeServers(const CFactoryTemplate * pList, int num,
206 BOOL bLoading)
208 int i;
210 for (i = 0; i < num; i++, pList++)
212 if (pList->m_lpfnInit)
213 pList->m_lpfnInit(bLoading, pList->m_ClsID);