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
;
36 if (InstallFunction
!= DIF_INSTALLDEVICE
)
37 return ERROR_DI_DO_DEFAULT
;
39 /* Set DI_DONOTCALLCONFIGMG flag */
40 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS
);
41 result
= SetupDiGetDeviceInstallParams(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
45 DPRINT("SetupDiGetDeviceInstallParams() failed with error 0x%lx\n", rc
);
49 InstallParams
.Flags
|= DI_DONOTCALLCONFIGMG
;
51 result
= SetupDiSetDeviceInstallParams(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
55 DPRINT("SetupDiSetDeviceInstallParams() failed with error 0x%lx\n", rc
);
59 /* Do normal install */
60 result
= SetupDiInstallDevice(DeviceInfoSet
, DeviceInfoData
);
64 DPRINT("SetupDiInstallDevice() failed with error 0x%lx\n", rc
);
68 /* Get .inf file name and section name */
69 DriverInfoData
.cbSize
= sizeof(SP_DRVINFO_DATA
);
70 result
= SetupDiGetSelectedDriver(DeviceInfoSet
, DeviceInfoData
, &DriverInfoData
);
74 DPRINT("SetupDiGetSelectedDriver() failed with error 0x%lx\n", rc
);
78 DriverInfoDetailData
.cbSize
= sizeof(SP_DRVINFO_DETAIL_DATA
);
79 result
= SetupDiGetDriverInfoDetail(
80 DeviceInfoSet
, DeviceInfoData
,
81 &DriverInfoData
, &DriverInfoDetailData
,
82 sizeof(SP_DRVINFO_DETAIL_DATA
), 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 result
= SetupDiGetActualSectionToInstall(
99 hInf
, DriverInfoDetailData
.SectionName
,
100 SectionName
, MAX_PATH
- _tcslen(_T(".SoftwareSettings")), NULL
, NULL
);
104 DPRINT("SetupDiGetActualSectionToInstall() failed with error 0x%lx\n", rc
);
107 _tcscat(SectionName
, _T(".SoftwareSettings"));
109 /* Open driver registry key and create Settings subkey */
110 hDriverKey
= SetupDiOpenDevRegKey(
111 DeviceInfoSet
, DeviceInfoData
,
112 DICS_FLAG_GLOBAL
, 0, DIREG_DRV
,
114 if (hDriverKey
== INVALID_HANDLE_VALUE
)
117 DPRINT("SetupDiOpenDevRegKey() failed with error 0x%lx\n", rc
);
121 hDriverKey
, L
"Settings",
122 0, NULL
, REG_OPTION_NON_VOLATILE
,
123 #if _WIN32_WINNT >= 0x502
124 KEY_READ
| KEY_WRITE
,
128 NULL
, &hSettingsKey
, &disposition
);
129 if (rc
!= ERROR_SUCCESS
)
131 DPRINT("RegCreateKeyEx() failed with error 0x%lx\n", rc
);
135 /* Install .SoftwareSettings to Settings subkey */
136 result
= SetupInstallFromInfSection(
137 InstallParams
.hwndParent
, hInf
, SectionName
,
138 SPINST_REGISTRY
, hSettingsKey
,
144 DPRINT("SetupInstallFromInfSection() failed with error 0x%lx\n", rc
);
148 /* Get service name and open service registry key */
149 result
= SetupDiGetDeviceRegistryProperty(
150 DeviceInfoSet
, DeviceInfoData
,
152 (PBYTE
)ServiceName
, MAX_SERVICE_NAME_LEN
* sizeof(TCHAR
), NULL
);
156 DPRINT("SetupDiGetDeviceRegistryProperty() failed with error 0x%lx\n", rc
);
161 HKEY_LOCAL_MACHINE
, _T("SYSTEM\\CurrentControlSet\\Services"),
162 0, KEY_ENUMERATE_SUB_KEYS
, &hServicesKey
);
163 if (rc
!= ERROR_SUCCESS
)
165 DPRINT("RegOpenKeyEx() failed with error 0x%lx\n", rc
);
169 hServicesKey
, ServiceName
,
170 0, KEY_CREATE_SUB_KEY
, &hServiceKey
);
171 if (rc
!= ERROR_SUCCESS
)
173 DPRINT("RegOpenKeyEx() failed with error 0x%lx\n", rc
);
177 /* Create a Device0 subkey (FIXME: do a loop to find a free number?) */
179 hServiceKey
, _T("Device0"), 0, NULL
,
180 REG_OPTION_NON_VOLATILE
, KEY_SET_VALUE
, NULL
,
181 &hDeviceSubKey
, &disposition
);
182 if (rc
!= ERROR_SUCCESS
)
184 DPRINT("RegCreateKeyEx() failed with error 0x%lx\n", rc
);
187 if (disposition
!= REG_CREATED_NEW_KEY
)
189 rc
= ERROR_GEN_FAILURE
;
190 DPRINT("RegCreateKeyEx() failed\n");
194 /* Install SoftwareSettings section */
195 /* Yes, we're installing this section for the second time.
196 * We don't want to create a link to Settings subkey */
197 result
= SetupInstallFromInfSection(
198 InstallParams
.hwndParent
, hInf
, SectionName
,
199 SPINST_REGISTRY
, hDeviceSubKey
,
205 DPRINT("SetupInstallFromInfSection() failed with error 0x%lx\n", rc
);
209 /* FIXME: install OpenGLSoftwareSettings section */
214 if (hInf
!= INVALID_HANDLE_VALUE
)
215 SetupCloseInfFile(hInf
);
216 if (hDriverKey
!= INVALID_HANDLE_VALUE
)
218 /* SetupDiOpenDevRegKey returns INVALID_HANDLE_VALUE in case of error! */
219 RegCloseKey(hDriverKey
);
221 if (hSettingsKey
!= NULL
)
222 RegCloseKey(hSettingsKey
);
223 if (hServicesKey
!= NULL
)
224 RegCloseKey(hServicesKey
);
225 if (hServiceKey
!= NULL
)
226 RegCloseKey(hServiceKey
);
227 if (hDeviceSubKey
!= NULL
)
228 RegCloseKey(hDeviceSubKey
);