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
;
37 if (InstallFunction
!= DIF_INSTALLDEVICE
)
38 return ERROR_DI_DO_DEFAULT
;
40 /* Set DI_DONOTCALLCONFIGMG flag */
41 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS
);
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(SP_DRVINFO_DATA
);
71 result
= SetupDiGetSelectedDriver(DeviceInfoSet
, DeviceInfoData
, &DriverInfoData
);
75 DPRINT("SetupDiGetSelectedDriver() failed with error 0x%lx\n", rc
);
79 DriverInfoDetailData
.cbSize
= sizeof(SP_DRVINFO_DETAIL_DATA
);
80 result
= SetupDiGetDriverInfoDetail(
81 DeviceInfoSet
, DeviceInfoData
,
82 &DriverInfoData
, &DriverInfoDetailData
,
83 sizeof(SP_DRVINFO_DETAIL_DATA
), NULL
);
84 if (!result
&& GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
87 DPRINT("SetupDiGetDriverInfoDetail() failed with error 0x%lx\n", rc
);
91 hInf
= SetupOpenInfFile(DriverInfoDetailData
.InfFileName
, NULL
, INF_STYLE_WIN4
, NULL
);
92 if (hInf
== INVALID_HANDLE_VALUE
)
95 DPRINT("SetupOpenInfFile() failed with error 0x%lx\n", rc
);
99 result
= SetupDiGetActualSectionToInstall(
100 hInf
, DriverInfoDetailData
.SectionName
,
101 SectionName
, MAX_PATH
- _tcslen(_T(".SoftwareSettings")), NULL
, NULL
);
105 DPRINT("SetupDiGetActualSectionToInstall() failed with error 0x%lx\n", rc
);
108 hr
= StringCbCat(SectionName
, sizeof(SectionName
), _T(".SoftwareSettings"));
111 rc
= ERROR_INSUFFICIENT_BUFFER
;
115 /* Open driver registry key and create Settings subkey */
116 hDriverKey
= SetupDiOpenDevRegKey(
117 DeviceInfoSet
, DeviceInfoData
,
118 DICS_FLAG_GLOBAL
, 0, DIREG_DRV
,
120 if (hDriverKey
== INVALID_HANDLE_VALUE
)
123 DPRINT("SetupDiOpenDevRegKey() failed with error 0x%lx\n", rc
);
127 hDriverKey
, L
"Settings",
128 0, NULL
, REG_OPTION_NON_VOLATILE
,
129 #if _WIN32_WINNT >= 0x502
130 KEY_READ
| KEY_WRITE
,
134 NULL
, &hSettingsKey
, &disposition
);
135 if (rc
!= ERROR_SUCCESS
)
137 DPRINT("RegCreateKeyEx() failed with error 0x%lx\n", rc
);
141 /* Install .SoftwareSettings to Settings subkey */
142 result
= SetupInstallFromInfSection(
143 InstallParams
.hwndParent
, hInf
, SectionName
,
144 SPINST_REGISTRY
, hSettingsKey
,
150 DPRINT("SetupInstallFromInfSection() failed with error 0x%lx\n", rc
);
154 /* Get service name and open service registry key */
155 result
= SetupDiGetDeviceRegistryProperty(
156 DeviceInfoSet
, DeviceInfoData
,
158 (PBYTE
)ServiceName
, MAX_SERVICE_NAME_LEN
* sizeof(TCHAR
), NULL
);
162 DPRINT("SetupDiGetDeviceRegistryProperty() failed with error 0x%lx\n", rc
);
167 HKEY_LOCAL_MACHINE
, _T("SYSTEM\\CurrentControlSet\\Services"),
168 0, KEY_ENUMERATE_SUB_KEYS
, &hServicesKey
);
169 if (rc
!= ERROR_SUCCESS
)
171 DPRINT("RegOpenKeyEx() failed with error 0x%lx\n", rc
);
175 hServicesKey
, ServiceName
,
176 0, KEY_CREATE_SUB_KEY
, &hServiceKey
);
177 if (rc
!= ERROR_SUCCESS
)
179 DPRINT("RegOpenKeyEx() failed with error 0x%lx\n", rc
);
183 /* Create a Device0 subkey (FIXME: do a loop to find a free number?) */
185 hServiceKey
, _T("Device0"), 0, NULL
,
186 REG_OPTION_NON_VOLATILE
, KEY_SET_VALUE
, NULL
,
187 &hDeviceSubKey
, &disposition
);
188 if (rc
!= ERROR_SUCCESS
)
190 DPRINT("RegCreateKeyEx() failed with error 0x%lx\n", rc
);
193 if (disposition
!= REG_CREATED_NEW_KEY
)
195 rc
= ERROR_GEN_FAILURE
;
196 DPRINT("RegCreateKeyEx() failed\n");
200 /* Install SoftwareSettings section */
201 /* Yes, we're installing this section for the second time.
202 * We don't want to create a link to Settings subkey */
203 result
= SetupInstallFromInfSection(
204 InstallParams
.hwndParent
, hInf
, SectionName
,
205 SPINST_REGISTRY
, hDeviceSubKey
,
211 DPRINT("SetupInstallFromInfSection() failed with error 0x%lx\n", rc
);
214 /* Add Device Description string */
215 rc
= RegSetValueEx(hDeviceSubKey
, _T("Device Description"), 0,
216 REG_SZ
, (const BYTE
*)DriverInfoData
.Description
,
217 (_tcslen(DriverInfoData
.Description
) + 1) * sizeof(TCHAR
));
218 if (rc
!= ERROR_SUCCESS
)
220 DPRINT("RegSetValueEx() failed with error 0x%lx\n", rc
);
224 /* FIXME: install OpenGLSoftwareSettings section */
229 if (hInf
!= INVALID_HANDLE_VALUE
)
230 SetupCloseInfFile(hInf
);
231 if (hDriverKey
!= INVALID_HANDLE_VALUE
)
233 /* SetupDiOpenDevRegKey returns INVALID_HANDLE_VALUE in case of error! */
234 RegCloseKey(hDriverKey
);
236 if (hSettingsKey
!= NULL
)
237 RegCloseKey(hSettingsKey
);
238 if (hServicesKey
!= NULL
)
239 RegCloseKey(hServicesKey
);
240 if (hServiceKey
!= NULL
)
241 RegCloseKey(hServiceKey
);
242 if (hDeviceSubKey
!= NULL
)
243 RegCloseKey(hDeviceSubKey
);