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
38 #include "wine/strmbase.h"
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(qcap);
47 * defines and constants
49 #define MAX_KEY_LEN 260
51 static WCHAR const clsid_keyname[6] =
52 {'C','L','S','I','D',0 };
53 static WCHAR const ips32_keyname[15] =
54 {'I','n','P','r','o','c','S','e','r','v','e','r','3','2',0};
55 static WCHAR const tmodel_keyname[15] =
56 {'T','h','r','e','a','d','i','n','g','M','o','d','e','l',0};
57 static WCHAR const tmodel_both[] =
61 * SetupRegisterClass()
63 static HRESULT SetupRegisterClass(HKEY clsid, LPCWSTR szCLSID,
64 LPCWSTR szDescription,
67 LPCWSTR szThreadingModel)
69 HKEY hkey, hsubkey = NULL;
70 LONG ret = RegCreateKeyW(clsid, szCLSID, &hkey);
71 if (ERROR_SUCCESS != ret)
72 return HRESULT_FROM_WIN32(ret);
74 /* set description string */
75 ret = RegSetValueW(hkey, NULL, REG_SZ, szDescription,
76 sizeof(WCHAR) * (lstrlenW(szDescription) + 1));
77 if (ERROR_SUCCESS != ret)
80 /* create CLSID\\{"CLSID"}\\"ServerType" key, using key to CLSID\\{"CLSID"}
81 passed back by last call to RegCreateKeyW(). */
82 ret = RegCreateKeyW(hkey, szServerType, &hsubkey);
83 if (ERROR_SUCCESS != ret)
87 ret = RegSetValueW(hsubkey, NULL, REG_SZ, szFileName,
88 sizeof(WCHAR) * (lstrlenW(szFileName) + 1));
89 if (ERROR_SUCCESS != ret)
92 /* set threading model */
93 ret = RegSetValueExW(hsubkey, tmodel_keyname, 0L, REG_SZ,
94 (const BYTE*)szThreadingModel,
95 sizeof(WCHAR) * (lstrlenW(szThreadingModel) + 1));
100 return HRESULT_FROM_WIN32(ret);
104 * RegisterAllClasses()
106 static HRESULT SetupRegisterAllClasses(const FactoryTemplate * pList, int num,
107 LPCWSTR szFileName, BOOL bRegister)
109 HRESULT hr = NOERROR;
111 OLECHAR szCLSID[CHARS_IN_GUID];
112 LONG i, ret = RegCreateKeyW(HKEY_CLASSES_ROOT, clsid_keyname, &hkey);
113 if (ERROR_SUCCESS != ret)
114 return HRESULT_FROM_WIN32(ret);
116 for (i = 0; i < num; i++, pList++)
118 /* (un)register CLSID and InprocServer32 */
119 hr = StringFromGUID2(pList->m_ClsID, szCLSID, CHARS_IN_GUID);
123 hr = SetupRegisterClass(hkey, szCLSID,
124 pList->m_Name, szFileName,
125 ips32_keyname, tmodel_both);
127 hr = RegDeleteTreeW(hkey, szCLSID);
135 /****************************************************************************
136 * SetupRegisterServers
138 * This function is table driven using the static members of the
139 * CFactoryTemplate class defined in the Dll.
141 * It registers the Dll as the InprocServer32 for all the classes in
144 ****************************************************************************/
145 HRESULT SetupRegisterServers(const FactoryTemplate * pList, int num,
148 static const WCHAR szFileName[] = {'q','c','a','p','.','d','l','l',0};
149 HRESULT hr = NOERROR;
151 /* first register all server classes, just to make sure */
153 hr = SetupRegisterAllClasses(pList, num, szFileName, TRUE );
155 hr = AMovieDllRegisterServer2(bRegister);
157 /* if unregistering, unregister all OLE servers */
158 if (SUCCEEDED(hr) && !bRegister)
159 hr = SetupRegisterAllClasses(pList, num, szFileName, FALSE);