ReactOS 0.4.16-dev-205-g7b2bb7e
classinst.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Display Control Panel
4 * FILE: dll/cpl/desk/classinst.c
5 * PURPOSE: Class installers
6 *
7 * PROGRAMMERS: Hervé Poussineau (hpoussin@reactos.org)
8 */
9
10#include "desk.h"
11
12//#define NDEBUG
13#include <debug.h>
14
17 IN DI_FUNCTION InstallFunction,
20{
21 SP_DEVINSTALL_PARAMS InstallParams;
22 SP_DRVINFO_DATA DriverInfoData;
24 TCHAR SectionName[MAX_PATH];
26 TCHAR DeviceName[12];
27 SP_DRVINFO_DETAIL_DATA DriverInfoDetailData;
28 DISPLAY_DEVICE DisplayDevice;
29 HKEY hDriverKey = INVALID_HANDLE_VALUE; /* SetupDiOpenDevRegKey returns INVALID_HANDLE_VALUE in case of error! */
30 HKEY hSettingsKey = NULL;
32 HKEY hServiceKey = NULL;
33 HKEY hDeviceSubKey = NULL;
34 DWORD disposition, cchMax, cbData;
35 WORD wIndex;
37 LONG rc;
38 HRESULT hr;
39
40 if (InstallFunction != DIF_INSTALLDEVICE)
42
43 /* Set DI_DONOTCALLCONFIGMG flag */
44 InstallParams.cbSize = sizeof(InstallParams);
46 if (!result)
47 {
48 rc = GetLastError();
49 DPRINT("SetupDiGetDeviceInstallParams() failed with error 0x%lx\n", rc);
50 goto cleanup;
51 }
52
53 InstallParams.Flags |= DI_DONOTCALLCONFIGMG;
54
56 if (!result)
57 {
58 rc = GetLastError();
59 DPRINT("SetupDiSetDeviceInstallParams() failed with error 0x%lx\n", rc);
60 goto cleanup;
61 }
62
63 /* Do normal install */
65 if (!result)
66 {
67 rc = GetLastError();
68 DPRINT("SetupDiInstallDevice() failed with error 0x%lx\n", rc);
69 goto cleanup;
70 }
71
72 /* Get .inf file name and section name */
73 DriverInfoData.cbSize = sizeof(DriverInfoData);
75 if (!result)
76 {
77 rc = GetLastError();
78 DPRINT("SetupDiGetSelectedDriver() failed with error 0x%lx\n", rc);
79 goto cleanup;
80 }
81
82 DriverInfoDetailData.cbSize = sizeof(DriverInfoDetailData);
84 &DriverInfoData, &DriverInfoDetailData,
85 sizeof(DriverInfoDetailData), NULL);
87 {
88 rc = GetLastError();
89 DPRINT("SetupDiGetDriverInfoDetail() failed with error 0x%lx\n", rc);
90 goto cleanup;
91 }
92
93 hInf = SetupOpenInfFile(DriverInfoDetailData.InfFileName, NULL, INF_STYLE_WIN4, NULL);
94 if (hInf == INVALID_HANDLE_VALUE)
95 {
96 rc = GetLastError();
97 DPRINT("SetupOpenInfFile() failed with error 0x%lx\n", rc);
98 goto cleanup;
99 }
100
101 cchMax = MAX_PATH - (sizeof(_T(".SoftwareSettings")) / sizeof(TCHAR));
103 DriverInfoDetailData.SectionName,
104 SectionName,
105 cchMax,
106 NULL,
107 NULL);
108 if (!result)
109 {
110 rc = GetLastError();
111 DPRINT("SetupDiGetActualSectionToInstall() failed with error 0x%lx\n", rc);
112 goto cleanup;
113 }
114 hr = StringCbCat(SectionName, sizeof(SectionName), _T(".SoftwareSettings"));
115 if (FAILED(hr))
116 {
118 goto cleanup;
119 }
120
121 /* Open driver registry key and create Settings subkey */
122 hDriverKey = SetupDiOpenDevRegKey(
126 if (hDriverKey == INVALID_HANDLE_VALUE)
127 {
128 rc = GetLastError();
129 DPRINT("SetupDiOpenDevRegKey() failed with error 0x%lx\n", rc);
130 goto cleanup;
131 }
132 rc = RegCreateKeyEx(
133 hDriverKey, L"Settings",
135#if _WIN32_WINNT >= 0x502
137#else
139#endif
140 NULL, &hSettingsKey, &disposition);
141 if (rc != ERROR_SUCCESS)
142 {
143 DPRINT("RegCreateKeyEx() failed with error 0x%lx\n", rc);
144 goto cleanup;
145 }
146
147 /* Install .SoftwareSettings to Settings subkey */
149 InstallParams.hwndParent, hInf, SectionName,
150 SPINST_REGISTRY, hSettingsKey,
151 NULL, 0, NULL, NULL,
152 NULL, NULL);
153 if (!result)
154 {
155 rc = GetLastError();
156 DPRINT("SetupInstallFromInfSection() failed with error 0x%lx\n", rc);
157 goto cleanup;
158 }
159
160 /* Get service name and open service registry key */
165 if (!result)
166 {
167 rc = GetLastError();
168 DPRINT("SetupDiGetDeviceRegistryProperty() failed with error 0x%lx\n", rc);
169 goto cleanup;
170 }
171
172 rc = RegOpenKeyEx(
173 HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Services"),
175 if (rc != ERROR_SUCCESS)
176 {
177 DPRINT("RegOpenKeyEx() failed with error 0x%lx\n", rc);
178 goto cleanup;
179 }
180 rc = RegOpenKeyEx(
182 0, KEY_CREATE_SUB_KEY, &hServiceKey);
183 if (rc != ERROR_SUCCESS)
184 {
185 DPRINT("RegOpenKeyEx() failed with error 0x%lx\n", rc);
186 goto cleanup;
187 }
188
189 /* Create a new DeviceX subkey */
190 for (wIndex = 0; wIndex < 9999; wIndex++)
191 {
192 _stprintf(DeviceName, _T("Device%hu"), wIndex);
193
194 rc = RegCreateKeyEx(
195 hServiceKey, DeviceName, 0, NULL,
197 &hDeviceSubKey, &disposition);
198 if (rc != ERROR_SUCCESS)
199 {
200 DPRINT("RegCreateKeyEx() failed with error 0x%lx\n", rc);
201 goto cleanup;
202 }
203
204 if (disposition == REG_CREATED_NEW_KEY)
205 break;
206
207 if (wIndex == 9999)
208 {
210 DPRINT("RegCreateKeyEx() failed\n");
211 goto cleanup;
212 }
213
214 RegCloseKey(hDeviceSubKey);
215 hDeviceSubKey = NULL;
216 }
217
218 /* Install SoftwareSettings section */
219 /* Yes, we're installing this section for the second time.
220 * We don't want to create a link to Settings subkey */
222 InstallParams.hwndParent, hInf, SectionName,
223 SPINST_REGISTRY, hDeviceSubKey,
224 NULL, 0, NULL, NULL,
225 NULL, NULL);
226 if (!result)
227 {
228 rc = GetLastError();
229 DPRINT("SetupInstallFromInfSection() failed with error 0x%lx\n", rc);
230 goto cleanup;
231 }
232
233 /* Add Device Description string */
234 cbData = (DWORD)(_tcslen(DriverInfoData.Description) + 1) * sizeof(TCHAR);
235 rc = RegSetValueEx(hDeviceSubKey,
236 _T("Device Description"),
237 0,
238 REG_SZ,
239 (const BYTE*)DriverInfoData.Description,
240 cbData);
241 if (rc != ERROR_SUCCESS)
242 {
243 DPRINT("RegSetValueEx() failed with error 0x%lx\n", rc);
244 goto cleanup;
245 }
246
247 /* FIXME: install OpenGLSoftwareSettings section */
248
249 /* Reenumerate display devices ; this will rescan for potential new devices */
250 DisplayDevice.cb = sizeof(DISPLAY_DEVICE);
251 EnumDisplayDevices(NULL, 0, &DisplayDevice, 0);
252
253 rc = ERROR_SUCCESS;
254
255cleanup:
256 if (hInf != INVALID_HANDLE_VALUE)
257 SetupCloseInfFile(hInf);
258 if (hDriverKey != INVALID_HANDLE_VALUE)
259 {
260 /* SetupDiOpenDevRegKey returns INVALID_HANDLE_VALUE in case of error! */
261 RegCloseKey(hDriverKey);
262 }
263 if (hSettingsKey != NULL)
264 RegCloseKey(hSettingsKey);
265 if (hServicesKey != NULL)
267 if (hServiceKey != NULL)
268 RegCloseKey(hServiceKey);
269 if (hDeviceSubKey != NULL)
270 RegCloseKey(hDeviceSubKey);
271
272 return rc;
273}
274
277 IN DI_FUNCTION InstallFunction,
280{
281 return ERROR_DI_DO_DEFAULT;
282}
UINT cchMax
#define _WIN32_WINNT
Definition: precomp.h:14
static WCHAR ServiceName[]
Definition: browser.c:19
static HANDLE hServicesKey
Definition: devinst.c:21
#define RegCloseKey(hKey)
Definition: registry.h:49
DWORD WINAPI DisplayClassInstaller(IN DI_FUNCTION InstallFunction, IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL)
Definition: classinst.c:16
DWORD WINAPI MonitorClassInstaller(IN DI_FUNCTION InstallFunction, IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL)
Definition: classinst.c:276
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define MAX_PATH
Definition: compat.h:34
static void cleanup(void)
Definition: main.c:1335
BOOL WINAPI SetupDiInstallDevice(IN HDEVINFO DeviceInfoSet, IN OUT PSP_DEVINFO_DATA DeviceInfoData)
Definition: devinst.c:5365
HKEY WINAPI SetupDiOpenDevRegKey(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, DWORD Scope, DWORD HwProfile, DWORD KeyType, REGSAM samDesired)
Definition: devinst.c:5934
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
GLuint64EXT * result
Definition: glext.h:11304
#define INF_STYLE_WIN4
Definition: infsupp.h:41
#define FAILED(hr)
Definition: intsafe.h:51
#define REG_SZ
Definition: layer.c:22
#define _stprintf
Definition: utility.h:124
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define KEY_READ
Definition: nt_native.h:1023
#define KEY_CREATE_SUB_KEY
Definition: nt_native.h:1018
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define REG_CREATED_NEW_KEY
Definition: nt_native.h:1084
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019
#define KEY_WRITE
Definition: nt_native.h:1031
#define DWORD
Definition: nt_native.h:44
#define KEY_SET_VALUE
Definition: nt_native.h:1017
#define L(x)
Definition: ntvdm.h:50
BYTE * PBYTE
Definition: pedump.c:66
long LONG
Definition: pedump.c:60
#define MAX_SERVICE_NAME_LEN
Definition: setupapi.h:25
#define SetupDiGetActualSectionToInstall
Definition: setupapi.h:2588
#define SetupDiGetDriverInfoDetail
Definition: setupapi.h:2604
#define SetupInstallFromInfSection
Definition: setupapi.h:2645
#define SetupOpenInfFile
Definition: setupapi.h:2652
#define SetupDiGetDeviceInstallParams
Definition: setupapi.h:2599
#define SetupDiGetDeviceRegistryProperty
Definition: setupapi.h:2603
#define SPINST_REGISTRY
Definition: setupapi.h:590
#define DIREG_DRV
Definition: setupapi.h:182
#define SetupDiSetDeviceInstallParams
Definition: setupapi.h:2619
_In_opt_ PSP_DEVINFO_DATA DeviceInfoData
Definition: setupapi.h:1528
#define ERROR_DI_DO_DEFAULT
Definition: setupapi.h:310
UINT DI_FUNCTION
Definition: setupapi.h:672
#define SetupDiGetSelectedDriver
Definition: setupapi.h:2610
#define SPDRP_SERVICE
Definition: setupapi.h:511
#define DIF_INSTALLDEVICE
Definition: setupapi.h:121
#define DICS_FLAG_GLOBAL
Definition: setupapi.h:113
#define DI_DONOTCALLCONFIGMG
Definition: setupapi.h:63
HRESULT hr
Definition: shlfolder.c:183
#define DPRINT
Definition: sndvol32.h:73
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
#define StringCbCat
Definition: strsafe.h:334
CHAR Description[LINE_LEN]
Definition: setupapi.h:1006
CHAR InfFileName[MAX_PATH]
Definition: setupapi.h:1066
CHAR SectionName[LINE_LEN]
Definition: setupapi.h:1065
#define IN
Definition: typedefs.h:39
VOID WINAPI SetupCloseInfFile(IN HINF InfHandle)
Definition: infsupp.c:45
#define _T(x)
Definition: vfdio.h:22
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WINAPI
Definition: msvc.h:6
#define ERROR_GEN_FAILURE
Definition: winerror.h:134
DISPLAY_DEVICEA DISPLAY_DEVICE
Definition: wingdi.h:4434
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define RegOpenKeyEx
Definition: winreg.h:520
#define RegSetValueEx
Definition: winreg.h:533
#define RegCreateKeyEx
Definition: winreg.h:501
char TCHAR
Definition: xmlstorage.h:189
#define _tcslen
Definition: xmlstorage.h:198
unsigned char BYTE
Definition: xxhash.c:193