2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Display Control Panel
4 * FILE: dll/cpl/desk/classinst.c
5 * PURPOSE: Display class installer
7 * PROGRAMMERS: Hervé Poussineau (hpoussin@reactos.org)
16 DisplayClassInstaller(
17 IN DI_FUNCTION InstallFunction
,
18 IN HDEVINFO DeviceInfoSet
,
19 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
)
21 SP_DEVINSTALL_PARAMS InstallParams
;
22 SP_DRVINFO_DATA DriverInfoData
;
23 HINF hInf
= INVALID_HANDLE_VALUE
;
24 TCHAR SectionName
[MAX_PATH
];
25 TCHAR ServiceName
[MAX_SERVICE_NAME_LEN
];
26 SP_DRVINFO_DETAIL_DATA DriverInfoDetailData
;
27 HKEY hDriverKey
= INVALID_HANDLE_VALUE
; /* SetupDiOpenDevRegKey returns INVALID_HANDLE_VALUE in case of error! */
28 HKEY hSettingsKey
= NULL
;
29 HKEY hServicesKey
= NULL
;
30 HKEY hServiceKey
= NULL
;
31 HKEY hDeviceSubKey
= NULL
;
32 DWORD disposition
, cchMax
, cbData
;
37 if (InstallFunction
!= DIF_INSTALLDEVICE
)
38 return ERROR_DI_DO_DEFAULT
;
40 /* Set DI_DONOTCALLCONFIGMG flag */
41 InstallParams
.cbSize
= sizeof(InstallParams
);
42 result
= SetupDiGetDeviceInstallParams(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
46 DPRINT("SetupDiGetDeviceInstallParams() failed with error 0x%lx\n", rc
);
50 InstallParams
.Flags
|= DI_DONOTCALLCONFIGMG
;
52 result
= SetupDiSetDeviceInstallParams(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
56 DPRINT("SetupDiSetDeviceInstallParams() failed with error 0x%lx\n", rc
);
60 /* Do normal install */
61 result
= SetupDiInstallDevice(DeviceInfoSet
, DeviceInfoData
);
65 DPRINT("SetupDiInstallDevice() failed with error 0x%lx\n", rc
);
69 /* Get .inf file name and section name */
70 DriverInfoData
.cbSize
= sizeof(DriverInfoData
);
71 result
= SetupDiGetSelectedDriver(DeviceInfoSet
, DeviceInfoData
, &DriverInfoData
);
75 DPRINT("SetupDiGetSelectedDriver() failed with error 0x%lx\n", rc
);
79 DriverInfoDetailData
.cbSize
= sizeof(DriverInfoDetailData
);
80 result
= SetupDiGetDriverInfoDetail(DeviceInfoSet
, DeviceInfoData
,
81 &DriverInfoData
, &DriverInfoDetailData
,
82 sizeof(DriverInfoDetailData
), NULL
);
83 if (!result
&& GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
86 DPRINT("SetupDiGetDriverInfoDetail() failed with error 0x%lx\n", rc
);
90 hInf
= SetupOpenInfFile(DriverInfoDetailData
.InfFileName
, NULL
, INF_STYLE_WIN4
, NULL
);
91 if (hInf
== INVALID_HANDLE_VALUE
)
94 DPRINT("SetupOpenInfFile() failed with error 0x%lx\n", rc
);
98 cchMax
= MAX_PATH
- (sizeof(_T(".SoftwareSettings")) / sizeof(TCHAR
));
99 result
= SetupDiGetActualSectionToInstall(hInf
,
100 DriverInfoDetailData
.SectionName
,
108 DPRINT("SetupDiGetActualSectionToInstall() failed with error 0x%lx\n", rc
);
111 hr
= StringCbCat(SectionName
, sizeof(SectionName
), _T(".SoftwareSettings"));
114 rc
= ERROR_INSUFFICIENT_BUFFER
;
118 /* Open driver registry key and create Settings subkey */
119 hDriverKey
= SetupDiOpenDevRegKey(
120 DeviceInfoSet
, DeviceInfoData
,
121 DICS_FLAG_GLOBAL
, 0, DIREG_DRV
,
123 if (hDriverKey
== INVALID_HANDLE_VALUE
)
126 DPRINT("SetupDiOpenDevRegKey() failed with error 0x%lx\n", rc
);
130 hDriverKey
, L
"Settings",
131 0, NULL
, REG_OPTION_NON_VOLATILE
,
132 #if _WIN32_WINNT >= 0x502
133 KEY_READ
| KEY_WRITE
,
137 NULL
, &hSettingsKey
, &disposition
);
138 if (rc
!= ERROR_SUCCESS
)
140 DPRINT("RegCreateKeyEx() failed with error 0x%lx\n", rc
);
144 /* Install .SoftwareSettings to Settings subkey */
145 result
= SetupInstallFromInfSection(
146 InstallParams
.hwndParent
, hInf
, SectionName
,
147 SPINST_REGISTRY
, hSettingsKey
,
153 DPRINT("SetupInstallFromInfSection() failed with error 0x%lx\n", rc
);
157 /* Get service name and open service registry key */
158 result
= SetupDiGetDeviceRegistryProperty(
159 DeviceInfoSet
, DeviceInfoData
,
161 (PBYTE
)ServiceName
, MAX_SERVICE_NAME_LEN
* sizeof(TCHAR
), NULL
);
165 DPRINT("SetupDiGetDeviceRegistryProperty() failed with error 0x%lx\n", rc
);
170 HKEY_LOCAL_MACHINE
, _T("SYSTEM\\CurrentControlSet\\Services"),
171 0, KEY_ENUMERATE_SUB_KEYS
, &hServicesKey
);
172 if (rc
!= ERROR_SUCCESS
)
174 DPRINT("RegOpenKeyEx() failed with error 0x%lx\n", rc
);
178 hServicesKey
, ServiceName
,
179 0, KEY_CREATE_SUB_KEY
, &hServiceKey
);
180 if (rc
!= ERROR_SUCCESS
)
182 DPRINT("RegOpenKeyEx() failed with error 0x%lx\n", rc
);
186 /* Create a Device0 subkey (FIXME: do a loop to find a free number?) */
188 hServiceKey
, _T("Device0"), 0, NULL
,
189 REG_OPTION_NON_VOLATILE
, KEY_SET_VALUE
, NULL
,
190 &hDeviceSubKey
, &disposition
);
191 if (rc
!= ERROR_SUCCESS
)
193 DPRINT("RegCreateKeyEx() failed with error 0x%lx\n", rc
);
196 if (disposition
!= REG_CREATED_NEW_KEY
)
198 rc
= ERROR_GEN_FAILURE
;
199 DPRINT("RegCreateKeyEx() failed\n");
203 /* Install SoftwareSettings section */
204 /* Yes, we're installing this section for the second time.
205 * We don't want to create a link to Settings subkey */
206 result
= SetupInstallFromInfSection(
207 InstallParams
.hwndParent
, hInf
, SectionName
,
208 SPINST_REGISTRY
, hDeviceSubKey
,
214 DPRINT("SetupInstallFromInfSection() failed with error 0x%lx\n", rc
);
218 /* Add Device Description string */
219 cbData
= (DWORD
)(_tcslen(DriverInfoData
.Description
) + 1) * sizeof(TCHAR
);
220 rc
= RegSetValueEx(hDeviceSubKey
,
221 _T("Device Description"),
224 (const BYTE
*)DriverInfoData
.Description
,
226 if (rc
!= ERROR_SUCCESS
)
228 DPRINT("RegSetValueEx() failed with error 0x%lx\n", rc
);
232 /* FIXME: install OpenGLSoftwareSettings section */
237 if (hInf
!= INVALID_HANDLE_VALUE
)
238 SetupCloseInfFile(hInf
);
239 if (hDriverKey
!= INVALID_HANDLE_VALUE
)
241 /* SetupDiOpenDevRegKey returns INVALID_HANDLE_VALUE in case of error! */
242 RegCloseKey(hDriverKey
);
244 if (hSettingsKey
!= NULL
)
245 RegCloseKey(hSettingsKey
);
246 if (hServicesKey
!= NULL
)
247 RegCloseKey(hServicesKey
);
248 if (hServiceKey
!= NULL
)
249 RegCloseKey(hServiceKey
);
250 if (hDeviceSubKey
!= NULL
)
251 RegCloseKey(hDeviceSubKey
);