2 * ReactOS Device Manager Applet
3 * Copyright (C) 2004 - 2005 ReactOS Team
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * PROJECT: ReactOS devmgr.dll
21 * FILE: lib/devmgr/devprblm.c
22 * PURPOSE: ReactOS Device Manager
23 * PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com>
32 ShowDeviceProblemWizard(IN HWND hWndParent OPTIONAL
,
34 IN PSP_DEVINFO_DATA DevInfoData
,
35 IN HMACHINE hMachine OPTIONAL
)
37 WCHAR szDeviceInstanceId
[256];
39 ULONG Status
, ProblemNumber
;
43 /* Get the device instance id */
44 if (!SetupDiGetDeviceInstanceId(hDevInfo
,
51 cr
= CM_Get_DevNode_Status_Ex(&Status
,
56 if (cr
== CR_SUCCESS
&& (Status
& DN_HAS_PROBLEM
))
58 switch (ProblemNumber
)
60 case CM_PROB_DEVLOADER_FAILED
:
62 /* FIXME - only if it's not a root bus devloader */
63 /* FIXME - display the update driver wizard */
67 case CM_PROB_OUT_OF_MEMORY
:
68 case CM_PROB_ENTRY_IS_WRONG_TYPE
:
69 case CM_PROB_LACKED_ARBITRATOR
:
70 case CM_PROB_FAILED_START
:
72 case CM_PROB_UNKNOWN_RESOURCE
:
74 /* FIXME - display the update driver wizard */
75 InstallDevInst(hWndParent
, szDeviceInstanceId
, TRUE
, &dwReboot
);
79 case CM_PROB_BOOT_CONFIG_CONFLICT
:
80 case CM_PROB_NORMAL_CONFLICT
:
81 case CM_PROB_REENUMERATION
:
83 /* FIXME - display the conflict wizard */
87 case CM_PROB_FAILED_FILTER
:
88 case CM_PROB_REINSTALL
:
89 case CM_PROB_FAILED_INSTALL
:
91 /* FIXME - display the driver (re)installation wizard */
92 InstallDevInst(hWndParent
, szDeviceInstanceId
, TRUE
, &dwReboot
);
96 case CM_PROB_DEVLOADER_NOT_FOUND
:
99 1) if it's a missing system devloader:
101 2) if it's not a system devloader but still missing:
102 - display the driver reinstallation wizard
103 3) if it's not a system devloader but the file can be found:
104 - display the update driver wizard
105 4) if it's a missing or empty software key
106 - display the update driver wizard
111 case CM_PROB_INVALID_DATA
:
112 case CM_PROB_PARTIAL_LOG_CONF
:
113 case CM_PROB_NO_VALID_LOG_CONF
:
114 case CM_PROB_HARDWARE_DISABLED
:
115 case CM_PROB_CANT_SHARE_IRQ
:
116 case CM_PROB_TRANSLATION_FAILED
:
117 case CM_PROB_SYSTEM_SHUTDOWN
:
118 case CM_PROB_PHANTOM
:
119 /* FIXME - do nothing */
122 case CM_PROB_NOT_VERIFIED
:
123 case CM_PROB_DEVICE_NOT_THERE
:
124 /* FIXME - display search hardware wizard */
127 case CM_PROB_NEED_RESTART
:
128 case CM_PROB_WILL_BE_REMOVED
:
130 case CM_PROB_TOO_EARLY
:
131 case CM_PROB_DISABLED_SERVICE
:
132 /* FIXME - reboot computer */
135 case CM_PROB_REGISTRY
:
136 /* FIXME - check registry */
139 case CM_PROB_DISABLED
:
141 /* FIXME - if device was disabled by user display the "Enable Device" wizard,
142 otherwise Troubleshoot because the device was disabled by the system */
146 case CM_PROB_DEVLOADER_NOT_READY
:
148 /* FIXME - if it's a graphics adapter:
149 - if it's a a secondary adapter and the main adapter
151 - do nothing or default action
153 - display the Properties
160 case CM_PROB_FAILED_ADD
:
162 /* FIXME - display the properties of the sub-device */
166 case CM_PROB_NO_SOFTCONFIG
:
167 case CM_PROB_IRQ_TRANSLATION_FAILED
:
168 case CM_PROB_FAILED_DRIVER_ENTRY
:
169 case CM_PROB_DRIVER_FAILED_PRIOR_UNLOAD
:
170 case CM_PROB_DRIVER_FAILED_LOAD
:
171 case CM_PROB_DRIVER_SERVICE_KEY_INVALID
:
172 case CM_PROB_LEGACY_SERVICE_NO_DEVICES
:
173 case CM_PROB_DUPLICATE_DEVICE
:
174 case CM_PROB_FAILED_POST_START
:
176 case CM_PROB_HELD_FOR_EJECT
:
177 case CM_PROB_DRIVER_BLOCKED
:
178 case CM_PROB_REGISTRY_TOO_LARGE
:
181 /* FIXME - troubleshoot the device */
191 /***************************************************************************
193 * DeviceProblemWizardA
196 * Calls the device problem wizard
199 * hWndParent: Handle to the parent window
200 * lpMachineName: Machine Name, NULL is the local machine
201 * lpDeviceID: Specifies the device, also see NOTEs
204 * TRUE: if no errors occured
205 * FALSE: if errors occured
211 DeviceProblemWizardA(IN HWND hWndParent OPTIONAL
,
212 IN LPCSTR lpMachineName OPTIONAL
,
213 IN LPCSTR lpDeviceID
)
215 LPWSTR lpMachineNameW
= NULL
;
216 LPWSTR lpDeviceIDW
= NULL
;
219 if (lpMachineName
!= NULL
)
221 if (!(lpMachineNameW
= ConvertMultiByteToUnicode(lpMachineName
,
227 if (lpDeviceID
!= NULL
)
229 if (!(lpDeviceIDW
= ConvertMultiByteToUnicode(lpDeviceID
,
236 Ret
= DeviceProblemWizardW(hWndParent
,
241 if (lpMachineNameW
!= NULL
)
243 HeapFree(GetProcessHeap(),
247 if (lpDeviceIDW
!= NULL
)
249 HeapFree(GetProcessHeap(),
258 /***************************************************************************
260 * DeviceProblemWizardW
263 * Calls the device problem wizard
266 * hWndParent: Handle to the parent window
267 * lpMachineName: Machine Name, NULL is the local machine
268 * lpDeviceID: Specifies the device, also see NOTEs
271 * TRUE: if no errors occured
272 * FALSE: if errors occured
278 DeviceProblemWizardW(IN HWND hWndParent OPTIONAL
,
279 IN LPCWSTR lpMachineName OPTIONAL
,
280 IN LPCWSTR lpDeviceID
)
283 SP_DEVINFO_DATA DevInfoData
;
289 if (lpDeviceID
== NULL
)
291 SetLastError(ERROR_INVALID_PARAMETER
);
295 /* dynamically load comctl32 */
296 hComCtl32
= LoadAndInitComctl32();
297 if (hComCtl32
!= NULL
)
299 hDevInfo
= SetupDiCreateDeviceInfoListEx(NULL
,
303 if (hDevInfo
!= INVALID_HANDLE_VALUE
)
305 cr
= CM_Connect_Machine(lpMachineName
,
307 if (cr
== CR_SUCCESS
)
309 DevInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
310 if (SetupDiOpenDeviceInfo(hDevInfo
,
316 Ret
= ShowDeviceProblemWizard(hWndParent
,
322 CM_Disconnect_Machine(hMachine
);
325 SetupDiDestroyDeviceInfoList(hDevInfo
);
328 FreeLibrary(hComCtl32
);
335 static const UINT ProblemStringId
[NUM_CM_PROB
] =
338 IDS_DEV_DEVLOADER_FAILED
,
339 IDS_DEV_NOT_CONFIGURED
,
340 IDS_DEV_OUT_OF_MEMORY
,
341 IDS_DEV_ENTRY_IS_WRONG_TYPE
,
342 IDS_DEV_LACKED_ARBITRATOR
,
343 IDS_DEV_BOOT_CONFIG_CONFLICT
,
344 IDS_DEV_FAILED_FILTER
,
345 IDS_DEV_DEVLOADER_NOT_FOUND
,
346 IDS_DEV_INVALID_DATA
,
347 IDS_DEV_FAILED_START
,
349 IDS_DEV_NORMAL_CONFLICT
,
350 IDS_DEV_NOT_VERIFIED
,
351 IDS_DEV_NEED_RESTART
,
352 IDS_DEV_REENUMERATION
,
353 IDS_DEV_PARTIAL_LOG_CONF
,
354 IDS_DEV_UNKNOWN_RESOURCE
,
357 IDS_UNKNOWN
, /* CM_PROB_VXDLDR, not used on NT */
358 IDS_DEV_WILL_BE_REMOVED
,
360 IDS_DEV_DEVLOADER_NOT_READY
,
361 IDS_DEV_DEVICE_NOT_THERE
,
364 IDS_DEV_NO_VALID_LOG_CONF
,
365 IDS_DEV_FAILED_INSTALL
,
366 IDS_DEV_HARDWARE_DISABLED
,
367 IDS_DEV_CANT_SHARE_IRQ
,
369 IDS_DEV_DISABLED_SERVICE
,
370 IDS_DEV_TRANSLATION_FAILED
,
371 IDS_DEV_NO_SOFTCONFIG
,
373 IDS_DEV_IRQ_TRANSLATION_FAILED
,
374 IDS_DEV_FAILED_DRIVER_ENTRY
,
375 IDS_DEV_DRIVER_FAILED_PRIOR_UNLOAD
,
376 IDS_DEV_DRIVER_FAILED_LOAD
,
377 IDS_DEV_DRIVER_SERVICE_KEY_INVALID
,
378 IDS_DEV_LEGACY_SERVICE_NO_DEVICES
,
379 IDS_DEV_DUPLICATE_DEVICE
,
380 IDS_DEV_FAILED_POST_START
,
383 IDS_DEV_SYSTEM_SHUTDOWN
,
384 IDS_DEV_HELD_FOR_EJECT
,
385 IDS_DEV_DRIVER_BLOCKED
,
386 IDS_DEV_REGISTRY_TOO_LARGE
,
387 IDS_DEV_SETPROPERTIES_FAILED
391 /***************************************************************************
396 * Gets the problem text from a problem number displayed in the properties dialog
399 * hMachine: Machine handle or NULL for the local machine
400 * DevInst: Device instance handle
401 * uProblemId: Specifies the problem ID
402 * lpString: Pointer to a buffer where the string is to be copied to. If the buffer
403 * is too small, the return value is the required string length in characters,
404 * excluding the NULL-termination.
405 * uMaxString: Size of the buffer in characters
408 * The return value is the length of the string in characters.
409 * It returns 0 if an error occured.
415 DeviceProblemTextA(IN HMACHINE hMachine OPTIONAL
,
416 IN DEVINST dnDevInst
,
421 LPWSTR lpBuffer
= NULL
;
426 lpBuffer
= HeapAlloc(GetProcessHeap(),
428 (uMaxString
+ 1) * sizeof(WCHAR
));
429 if (lpBuffer
== NULL
)
431 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
436 Ret
= DeviceProblemTextW(hMachine
,
442 if (lpBuffer
!= NULL
)
446 WideCharToMultiByte(CP_ACP
,
456 HeapFree(GetProcessHeap(),
465 /***************************************************************************
470 * Gets the problem text from a problem number displayed in the properties dialog
473 * hMachine: Machine handle or NULL for the local machine
474 * DevInst: Device instance handle
475 * uProblemId: Specifies the problem ID
476 * lpString: Pointer to a buffer where the string is to be copied to. If the buffer
477 * is too small, the return value is the required string length in characters,
478 * excluding the NULL-termination.
479 * uMaxString: Size of the buffer in characters
482 * The return value is the length of the string in characters.
483 * It returns 0 if an error occured.
489 DeviceProblemTextW(IN HMACHINE hMachine OPTIONAL
,
490 IN DEVINST dnDevInst
,
495 UINT MessageId
= IDS_UNKNOWN
;
498 if (uProblemId
< sizeof(ProblemStringId
) / sizeof(ProblemStringId
[0]))
499 MessageId
= ProblemStringId
[uProblemId
];
505 Ret
= LoadString(hDllInstance
,
512 Ret
= (UINT
)LengthOfStrResource(hDllInstance
,
518 LPWSTR szProblem
, szInfo
= L
"FIXME";
520 BOOL AdvFormat
= FALSE
;
529 case CM_PROB_DEVLOADER_FAILED
:
531 /* FIXME - if not a root bus devloader then use IDS_DEV_DEVLOADER_FAILED2 */
532 /* FIXME - get the type string (ie. ISAPNP, PCI or BIOS for root bus devloaders,
533 or FLOP, ESDI, SCSI, etc for others */
538 case CM_PROB_DEVLOADER_NOT_FOUND
:
541 1) if it's a missing system devloader:
542 - get the system devloader name
543 2) if it's not a system devloader but still missing:
544 - get the devloader name (file name?)
545 3) if it's not a system devloader but the file can be found:
546 - use IDS_DEV_DEVLOADER_NOT_FOUND2
547 4) if it's a missing or empty software key
548 - use IDS_DEV_DEVLOADER_NOT_FOUND3
555 case CM_PROB_INVALID_DATA
:
556 /* FIXME - if the device isn't enumerated by the BIOS/ACPI use IDS_DEV_INVALID_DATA2 */
560 case CM_PROB_NORMAL_CONFLICT
:
561 /* FIXME - get resource type (IRQ, DMA, Memory or I/O) */
565 case CM_PROB_UNKNOWN_RESOURCE
:
566 /* FIXME - get the .inf file name */
570 case CM_PROB_DISABLED
:
571 /* FIXME - if the device was disabled by the system use IDS_DEV_DISABLED2 */
574 case CM_PROB_FAILED_ADD
:
575 /* FIXME - get the name of the sub-device with the error */
582 StringIDs
[1] = IDS_DEVCODE2
;
583 dwRet
= LoadAndFormatStringsCat(hDllInstance
,
585 sizeof(StringIDs
) / sizeof(StringIDs
[0]),
592 dwRet
= LoadAndFormatStringsCat(hDllInstance
,
594 sizeof(StringIDs
) / sizeof(StringIDs
[0]),
601 if (uMaxString
!= 0 && uMaxString
>= dwRet
)
607 LocalFree((HLOCAL
)szProblem
);