ReactOS 0.4.16-dev-258-g81860b4
classinst.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS system libraries
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/win32/syssetup/classinst.c
5 * PURPOSE: Class installers
6 * PROGRAMMERS: Copyright 2006 Hervé Poussineau (hpoussin@reactos.org)
7 */
8
9#include "precomp.h"
10
11#define NDEBUG
12#include <debug.h>
13
14/*
15 * @unimplemented
16 */
20 IN DI_FUNCTION InstallFunction,
23{
24 switch (InstallFunction)
25 {
26 default:
27 DPRINT1("Install function %u ignored\n", InstallFunction);
29 }
30}
31
32
33/*
34 * @implemented
35 */
39 IN DI_FUNCTION InstallFunction,
43{
44 WCHAR szDeviceId[256];
45 WCHAR szServiceName[256];
46 WCHAR szClassGUID[64];
47 DWORD dwRequiredSize;
48 HKEY hDriverKey = NULL;
49 HKEY hDatabaseKey = NULL, hDeviceKey = NULL;
50 DWORD dwDisposition;
51 PWSTR Ptr;
52 DWORD dwError = ERROR_SUCCESS;
53
54 DPRINT("CriticalDeviceCoInstaller(%lu %p %p %p)\n",
55 InstallFunction, DeviceInfoSet, DeviceInfoData, Context);
56
57 if (InstallFunction != DIF_INSTALLDEVICE)
58 return ERROR_SUCCESS;
59
60 /* Get the MatchingDeviceId property */
64 0,
66 KEY_READ);
67 if (hDriverKey == INVALID_HANDLE_VALUE)
68 {
69 if (Context->PostProcessing)
70 {
71 dwError = GetLastError();
72 DPRINT1("Failed to open the driver key! (Error %lu)\n", dwError);
73 goto done;
74 }
75 else
76 {
77 DPRINT("Failed to open the driver key! Postprocessing required!\n");
79 }
80 }
81
82 dwRequiredSize = sizeof(szDeviceId);
83 dwError = RegQueryValueExW(hDriverKey,
84 L"MatchingDeviceId",
85 NULL,
86 NULL,
88 &dwRequiredSize);
89 RegCloseKey(hDriverKey);
90 if (dwError != ERROR_SUCCESS)
91 {
92 if (Context->PostProcessing)
93 {
94 dwError = GetLastError();
95 DPRINT1("Failed to read the MatchingDeviceId value! (Error %lu)\n", dwError);
96 goto done;
97 }
98 else
99 {
100 DPRINT("Failed to read the MatchingDeviceId value! Postprocessing required!\n");
102 }
103 }
104
105 DPRINT("MatchingDeviceId: %S\n", szDeviceId);
106
107 /* Get the ClassGUID property */
108 dwRequiredSize = 0;
112 NULL,
113 (PBYTE)szClassGUID,
114 sizeof(szClassGUID),
115 &dwRequiredSize))
116 {
117 if (Context->PostProcessing)
118 {
119 dwError = GetLastError();
120 DPRINT1("Failed to read the ClassGUID! (Error %lu)\n", dwError);
121 goto done;
122 }
123 else
124 {
125 DPRINT("Failed to read the ClassGUID! Postprocessing required!\n");
127 }
128 }
129
130 DPRINT("ClassGUID %S\n", szClassGUID);
131
132 /* Get the Service property (optional) */
133 dwRequiredSize = 0;
137 NULL,
138 (PBYTE)szServiceName,
139 sizeof(szServiceName),
140 &dwRequiredSize))
141 {
142 if (Context->PostProcessing)
143 {
144 dwError = GetLastError();
145 if (dwError != ERROR_FILE_NOT_FOUND)
146 {
147 DPRINT1("Failed to read the Service name! (Error %lu)\n", dwError);
148 goto done;
149 }
150 else
151 {
152 szServiceName[0] = UNICODE_NULL;
153 dwError = ERROR_SUCCESS;
154 }
155 }
156 else
157 {
158 DPRINT("Failed to read the Service name! Postprocessing required!\n");
160 }
161 }
162
163 DPRINT("Service %S\n", szServiceName);
164
165 /* Replace the first backslash by a number sign */
166 Ptr = wcschr(szDeviceId, L'\\');
167 if (Ptr != NULL)
168 {
169 *Ptr = L'#';
170
171 /* Terminate the device id at the second backslash */
172 Ptr = wcschr(Ptr, L'\\');
173 if (Ptr != NULL)
174 *Ptr = UNICODE_NULL;
175 }
176
177 DPRINT("DeviceId: %S\n", szDeviceId);
178
179 /* Open the critical device database key */
181 L"SYSTEM\\CurrentControlSet\\Control\\CriticalDeviceDatabase",
182 0,
183 KEY_WRITE,
184 &hDatabaseKey);
185 if (dwError != ERROR_SUCCESS)
186 {
187 DPRINT1("RegOpenKeyExW failed (Error %lu)\n", dwError);
188 goto done;
189 }
190
191 /* Create a new key for the device */
192 dwError = RegCreateKeyExW(hDatabaseKey,
194 0,
195 NULL,
197 KEY_WRITE,
198 NULL,
199 &hDeviceKey,
200 &dwDisposition);
201 if (dwError != ERROR_SUCCESS)
202 {
203 DPRINT1("RegCreateKeyExW failed (Error %lu)\n", dwError);
204 goto done;
205 }
206
207 /* Set the ClassGUID value */
208 dwError = RegSetValueExW(hDeviceKey,
209 L"ClassGUID",
210 0,
211 REG_SZ,
212 (PBYTE)szClassGUID,
213 (wcslen(szClassGUID) + 1) * sizeof(WCHAR));
214 if (dwError != ERROR_SUCCESS)
215 {
216 DPRINT1("RegSetValueExW failed (Error %lu)\n", dwError);
217 goto done;
218 }
219
220 /* If available, set the Service value */
221 if (szServiceName[0] != UNICODE_NULL)
222 {
223 dwError = RegSetValueExW(hDeviceKey,
224 L"Service",
225 0,
226 REG_SZ,
227 (PBYTE)szServiceName,
228 (wcslen(szServiceName) + 1) * sizeof(WCHAR));
229 if (dwError != ERROR_SUCCESS)
230 {
231 DPRINT1("RegSetValueExW failed (Error %lu)\n", dwError);
232 goto done;
233 }
234 }
235
236done:
237 if (hDeviceKey != NULL)
238 RegCloseKey(hDeviceKey);
239
240 if (hDatabaseKey != NULL)
241 RegCloseKey(hDatabaseKey);
242
243 DPRINT("CriticalDeviceCoInstaller() done (Error %lu)\n", dwError);
244
245 return dwError;
246}
247
248
249/*
250 * @unimplemented
251 */
252DWORD
253WINAPI
255 IN DI_FUNCTION InstallFunction,
258{
259 switch (InstallFunction)
260 {
261 default:
262 DPRINT("Install function %u ignored\n", InstallFunction);
263 return ERROR_DI_DO_DEFAULT;
264 }
265}
266
267
268/*
269 * @unimplemented
270 */
271DWORD
272WINAPI
274 IN DI_FUNCTION InstallFunction,
278{
279 switch (InstallFunction)
280 {
281 default:
282 DPRINT1("Install function %u ignored\n", InstallFunction);
283 return ERROR_SUCCESS;
284 }
285}
286
287
288/*
289 * @implemented
290 */
291DWORD
292WINAPI
294 IN DI_FUNCTION InstallFunction,
297{
298 DPRINT("HdcClassInstaller()\n");
299 return ERROR_DI_DO_DEFAULT;
300}
301
302
303/*
304 * @unimplemented
305 */
306DWORD
307WINAPI
309 IN DI_FUNCTION InstallFunction,
312{
313 switch (InstallFunction)
314 {
315 default:
316 DPRINT("Install function %u ignored\n", InstallFunction);
317 return ERROR_DI_DO_DEFAULT;
318 }
319}
320
321
322/*
323 * @unimplemented
324 */
325DWORD
326WINAPI
328 IN DI_FUNCTION InstallFunction,
331{
332 switch (InstallFunction)
333 {
334 default:
335 DPRINT("Install function %u ignored\n", InstallFunction);
336 return ERROR_DI_DO_DEFAULT;
337 }
338}
339
340
341/*
342 * @unimplemented
343 */
344DWORD
345WINAPI
347 IN DI_FUNCTION InstallFunction,
350{
351 switch (InstallFunction)
352 {
353 default:
354 DPRINT("Install function %u ignored\n", InstallFunction);
355 return ERROR_DI_DO_DEFAULT;
356 }
357}
358
359
360/*
361 * @unimplemented
362 */
363DWORD
364WINAPI
366 IN DI_FUNCTION InstallFunction,
369{
370 switch (InstallFunction)
371 {
372 default:
373 DPRINT("Install function %u ignored\n", InstallFunction);
374 return ERROR_DI_DO_DEFAULT;
375 }
376}
377
378
379/*
380 * @implemented
381 */
382DWORD
383WINAPI
385 IN DI_FUNCTION InstallFunction,
389{
390 ULONG ulStatus, ulProblem;
391 DWORD dwBufferSize = 0;
392 PWSTR pszDeviceDescription;
394
395 DPRINT("StorageCoInstaller(%u %p %p %p)\n",
396 InstallFunction, DeviceInfoSet, DeviceInfoData, Context);
397
398 if (InstallFunction != DIF_INSTALLDEVICE)
399 return ERROR_SUCCESS;
400
401 if (Context->PostProcessing)
402 {
403 if (Context->PrivateData != NULL)
404 {
405 pszDeviceDescription = (PWSTR)Context->PrivateData;
406
407 /* Store the device description as the friendly name */
411 (PBYTE)pszDeviceDescription,
412 (wcslen(pszDeviceDescription) + 1) * sizeof(WCHAR));
413
414 /* Free the device description */
415 HeapFree(GetProcessHeap(), 0, Context->PrivateData);
416 Context->PrivateData = NULL;
417 }
418 }
419 else
420 {
421 if (DeviceInfoData == NULL)
422 return ERROR_SUCCESS;
423
424 ret = CM_Get_DevNode_Status(&ulStatus, &ulProblem, DeviceInfoData->DevInst, 0);
425 if (ret != CR_SUCCESS)
426 return ERROR_SUCCESS;
427
428 if (ulStatus & DN_ROOT_ENUMERATED)
429 return ERROR_SUCCESS;
430
431 /* Get the device description size */
435 NULL,
436 NULL,
437 0,
438 &dwBufferSize);
439 if (dwBufferSize == 0)
440 return ERROR_SUCCESS;
441
442 /* Allocate the device description buffer */
443 pszDeviceDescription = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwBufferSize);
444 if (pszDeviceDescription == NULL)
445 return ERROR_SUCCESS;
446
447 /* Get the device description */
451 NULL,
452 (PBYTE)pszDeviceDescription,
453 dwBufferSize,
454 &dwBufferSize);
455
456 Context->PrivateData = (PVOID)pszDeviceDescription;
458 }
459
460 return ERROR_SUCCESS;
461}
462
463
464/*
465 * @implemented
466 */
467DWORD
468WINAPI
470 IN DI_FUNCTION InstallFunction,
473{
474 DPRINT("TapeClassInstaller()\n");
475 return ERROR_DI_DO_DEFAULT;
476}
477
478
479/*
480 * @implemented
481 */
482DWORD
483WINAPI
485 IN DI_FUNCTION InstallFunction,
488{
489 DPRINT("VolumeClassInstaller()\n");
490 return ERROR_DI_DO_DEFAULT;
491}
492
493/* EOF */
#define DPRINT1
Definition: precomp.h:8
#define RegCloseKey(hKey)
Definition: registry.h:49
#define DN_ROOT_ENUMERATED
Definition: cfg.h:118
RETURN_TYPE CONFIGRET
Definition: cfgmgr32.h:74
#define CR_SUCCESS
Definition: cfgmgr32.h:842
CONFIGRET WINAPI CM_Get_DevNode_Status(_Out_ PULONG pulStatus, _Out_ PULONG pulProblemNumber, _In_ DEVINST dnDevInst, _In_ ULONG ulFlags)
Definition: cfgmgr.c:3671
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
static const WCHAR szDeviceId[]
Definition: provider.c:60
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1096
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4882
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#define wcschr
Definition: compat.h:17
#define GetProcessHeap()
Definition: compat.h:736
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
BOOL WINAPI SetupDiGetDeviceRegistryPropertyW(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, DWORD Property, PDWORD PropertyRegDataType, PBYTE PropertyBuffer, DWORD PropertyBufferSize, PDWORD RequiredSize)
Definition: devinst.c:3224
HKEY WINAPI SetupDiOpenDevRegKey(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, DWORD Scope, DWORD HwProfile, DWORD KeyType, REGSAM samDesired)
Definition: devinst.c:5934
BOOL WINAPI SetupDiSetDeviceRegistryPropertyW(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, DWORD Property, const BYTE *PropertyBuffer, DWORD PropertyBufferSize)
Definition: devinst.c:3452
unsigned long DWORD
Definition: ntddk_ex.h:95
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define REG_SZ
Definition: layer.c:22
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define KEY_READ
Definition: nt_native.h:1023
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WRITE
Definition: nt_native.h:1031
#define UNICODE_NULL
#define L(x)
Definition: ntvdm.h:50
BYTE * PBYTE
Definition: pedump.c:66
#define ERROR_DI_POSTPROCESSING_REQUIRED
Definition: setupapi.h:334
#define SPDRP_DEVICEDESC
Definition: setupapi.h:507
#define SPDRP_CLASSGUID
Definition: setupapi.h:515
#define DIREG_DRV
Definition: setupapi.h:182
_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 SPDRP_SERVICE
Definition: setupapi.h:511
#define DIF_INSTALLDEVICE
Definition: setupapi.h:121
#define DICS_FLAG_GLOBAL
Definition: setupapi.h:113
#define SPDRP_FRIENDLYNAME
Definition: setupapi.h:519
#define DPRINT
Definition: sndvol32.h:73
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
uint16_t * PWSTR
Definition: typedefs.h:56
void * PVOID
Definition: typedefs.h:50
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
int ret
DWORD WINAPI ComputerClassInstaller(IN DI_FUNCTION InstallFunction, IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL)
Definition: classinst.c:19
DWORD WINAPI CriticalDeviceCoInstaller(IN DI_FUNCTION InstallFunction, IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL, IN OUT PCOINSTALLER_CONTEXT_DATA Context)
Definition: classinst.c:38
DWORD WINAPI NtApmClassInstaller(IN DI_FUNCTION InstallFunction, IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL)
Definition: classinst.c:346
DWORD WINAPI TapeClassInstaller(IN DI_FUNCTION InstallFunction, IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL)
Definition: classinst.c:469
DWORD WINAPI DeviceBayClassInstaller(IN DI_FUNCTION InstallFunction, IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL)
Definition: classinst.c:254
DWORD WINAPI VolumeClassInstaller(IN DI_FUNCTION InstallFunction, IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL)
Definition: classinst.c:484
DWORD WINAPI KeyboardClassInstaller(IN DI_FUNCTION InstallFunction, IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL)
Definition: classinst.c:308
DWORD WINAPI EisaUpHalCoInstaller(IN DI_FUNCTION InstallFunction, IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL, IN OUT PCOINSTALLER_CONTEXT_DATA Context)
Definition: classinst.c:273
DWORD WINAPI StorageCoInstaller(IN DI_FUNCTION InstallFunction, IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL, IN OUT PCOINSTALLER_CONTEXT_DATA Context)
Definition: classinst.c:384
DWORD WINAPI MouseClassInstaller(IN DI_FUNCTION InstallFunction, IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL)
Definition: classinst.c:327
DWORD WINAPI HdcClassInstaller(IN DI_FUNCTION InstallFunction, IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL)
Definition: classinst.c:293
DWORD WINAPI ScsiClassInstaller(IN DI_FUNCTION InstallFunction, IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL)
Definition: classinst.c:365
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WINAPI
Definition: msvc.h:6
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
__wchar_t WCHAR
Definition: xmlstorage.h:180