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>
34 ShowDeviceProblemWizard(IN HWND hWndParent OPTIONAL
,
36 IN PSP_DEVINFO_DATA DevInfoData
,
37 IN HMACHINE hMachine OPTIONAL
)
40 ULONG Status
, ProblemNumber
;
43 cr
= CM_Get_DevNode_Status_Ex(&Status
,
48 if (cr
== CR_SUCCESS
&& (Status
& DN_HAS_PROBLEM
))
50 switch (ProblemNumber
)
52 case CM_PROB_DEVLOADER_FAILED
:
54 /* FIXME - only if it's not a root bus devloader */
55 /* FIXME - display the update driver wizard */
59 case CM_PROB_OUT_OF_MEMORY
:
60 case CM_PROB_ENTRY_IS_WRONG_TYPE
:
61 case CM_PROB_LACKED_ARBITRATOR
:
62 case CM_PROB_FAILED_START
:
64 case CM_PROB_UNKNOWN_RESOURCE
:
66 /* FIXME - display the update driver wizard */
70 case CM_PROB_BOOT_CONFIG_CONFLICT
:
71 case CM_PROB_NORMAL_CONFLICT
:
72 case CM_PROB_REENUMERATION
:
74 /* FIXME - display the conflict wizard */
78 case CM_PROB_FAILED_FILTER
:
79 case CM_PROB_REINSTALL
:
80 case CM_PROB_FAILED_INSTALL
:
82 /* FIXME - display the driver (re)installation wizard */
86 case CM_PROB_DEVLOADER_NOT_FOUND
:
89 1) if it's a missing system devloader:
91 2) if it's not a system devloader but still missing:
92 - display the driver reinstallation wizard
93 3) if it's not a system devloader but the file can be found:
94 - display the update driver wizard
95 4) if it's a missing or empty software key
96 - display the update driver wizard
101 case CM_PROB_INVALID_DATA
:
102 case CM_PROB_PARTIAL_LOG_CONF
:
103 case CM_PROB_NO_VALID_LOG_CONF
:
104 case CM_PROB_HARDWARE_DISABLED
:
105 case CM_PROB_CANT_SHARE_IRQ
:
106 case CM_PROB_TRANSLATION_FAILED
:
107 case CM_PROB_SYSTEM_SHUTDOWN
:
108 case CM_PROB_PHANTOM
:
109 /* FIXME - do nothing */
112 case CM_PROB_NOT_VERIFIED
:
113 case CM_PROB_DEVICE_NOT_THERE
:
114 /* FIXME - display search hardware wizard */
117 case CM_PROB_NEED_RESTART
:
118 case CM_PROB_WILL_BE_REMOVED
:
120 case CM_PROB_TOO_EARLY
:
121 case CM_PROB_DISABLED_SERVICE
:
122 /* FIXME - reboot computer */
125 case CM_PROB_REGISTRY
:
126 /* FIXME - check registry */
129 case CM_PROB_DISABLED
:
131 /* FIXME - if device was disabled by user display the "Enable Device" wizard,
132 otherwise Troubleshoot because the device was disabled by the system */
136 case CM_PROB_DEVLOADER_NOT_READY
:
138 /* FIXME - if it's a graphics adapter:
139 - if it's a a secondary adapter and the main adapter
141 - do nothing or default action
143 - display the Properties
150 case CM_PROB_FAILED_ADD
:
152 /* FIXME - display the properties of the sub-device */
156 case CM_PROB_NO_SOFTCONFIG
:
157 case CM_PROB_IRQ_TRANSLATION_FAILED
:
158 case CM_PROB_FAILED_DRIVER_ENTRY
:
159 case CM_PROB_DRIVER_FAILED_PRIOR_UNLOAD
:
160 case CM_PROB_DRIVER_FAILED_LOAD
:
161 case CM_PROB_DRIVER_SERVICE_KEY_INVALID
:
162 case CM_PROB_LEGACY_SERVICE_NO_DEVICES
:
163 case CM_PROB_DUPLICATE_DEVICE
:
164 case CM_PROB_FAILED_POST_START
:
166 case CM_PROB_HELD_FOR_EJECT
:
167 case CM_PROB_DRIVER_BLOCKED
:
168 case CM_PROB_REGISTRY_TOO_LARGE
:
171 /* FIXME - troubleshoot the device */
181 /***************************************************************************
183 * DeviceProblemWizardA
186 * Calls the device problem wizard
189 * hWndParent: Handle to the parent window
190 * lpMachineName: Machine Name, NULL is the local machine
191 * lpDeviceID: Specifies the device, also see NOTEs
194 * TRUE: if no errors occured
195 * FALSE: if errors occured
201 DeviceProblemWizardA(IN HWND hWndParent OPTIONAL
,
202 IN LPCSTR lpMachineName OPTIONAL
,
203 IN LPCSTR lpDeviceID
)
205 LPWSTR lpMachineNameW
= NULL
;
206 LPWSTR lpDeviceIDW
= NULL
;
209 if (lpMachineName
!= NULL
)
211 if (!(lpMachineNameW
= ConvertMultiByteToUnicode(lpMachineName
,
217 if (lpDeviceID
!= NULL
)
219 if (!(lpDeviceIDW
= ConvertMultiByteToUnicode(lpDeviceID
,
226 Ret
= DeviceProblemWizardW(hWndParent
,
231 if (lpMachineNameW
!= NULL
)
233 HeapFree(GetProcessHeap(),
237 if (lpDeviceIDW
!= NULL
)
239 HeapFree(GetProcessHeap(),
248 /***************************************************************************
250 * DeviceProblemWizardW
253 * Calls the device problem wizard
256 * hWndParent: Handle to the parent window
257 * lpMachineName: Machine Name, NULL is the local machine
258 * lpDeviceID: Specifies the device, also see NOTEs
261 * TRUE: if no errors occured
262 * FALSE: if errors occured
268 DeviceProblemWizardW(IN HWND hWndParent OPTIONAL
,
269 IN LPCWSTR lpMachineName OPTIONAL
,
270 IN LPCWSTR lpDeviceID
)
273 SP_DEVINFO_DATA DevInfoData
;
279 if (lpDeviceID
== NULL
)
281 SetLastError(ERROR_INVALID_PARAMETER
);
285 /* dynamically load comctl32 */
286 hComCtl32
= LoadAndInitComctl32();
287 if (hComCtl32
!= NULL
)
289 hDevInfo
= SetupDiCreateDeviceInfoListEx(NULL
,
293 if (hDevInfo
!= INVALID_HANDLE_VALUE
)
295 cr
= CM_Connect_Machine(lpMachineName
,
297 if (cr
== CR_SUCCESS
)
299 DevInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
300 if (SetupDiOpenDeviceInfo(hDevInfo
,
306 Ret
= ShowDeviceProblemWizard(hWndParent
,
312 CM_Disconnect_Machine(hMachine
);
315 SetupDiDestroyDeviceInfoList(hDevInfo
);
318 FreeLibrary(hComCtl32
);
325 static const UINT ProblemStringId
[NUM_CM_PROB
] =
328 IDS_DEV_DEVLOADER_FAILED
,
329 IDS_DEV_NOT_CONFIGURED
,
330 IDS_DEV_OUT_OF_MEMORY
,
331 IDS_DEV_ENTRY_IS_WRONG_TYPE
,
332 IDS_DEV_LACKED_ARBITRATOR
,
333 IDS_DEV_BOOT_CONFIG_CONFLICT
,
334 IDS_DEV_FAILED_FILTER
,
335 IDS_DEV_DEVLOADER_NOT_FOUND
,
336 IDS_DEV_INVALID_DATA
,
337 IDS_DEV_FAILED_START
,
339 IDS_DEV_NORMAL_CONFLICT
,
340 IDS_DEV_NOT_VERIFIED
,
341 IDS_DEV_NEED_RESTART
,
342 IDS_DEV_REENUMERATION
,
343 IDS_DEV_PARTIAL_LOG_CONF
,
344 IDS_DEV_UNKNOWN_RESOURCE
,
347 IDS_UNKNOWN
, /* CM_PROB_VXDLDR, not used on NT */
348 IDS_DEV_WILL_BE_REMOVED
,
350 IDS_DEV_DEVLOADER_NOT_READY
,
351 IDS_DEV_DEVICE_NOT_THERE
,
354 IDS_DEV_NO_VALID_LOG_CONF
,
355 IDS_DEV_FAILED_INSTALL
,
356 IDS_DEV_HARDWARE_DISABLED
,
357 IDS_DEV_CANT_SHARE_IRQ
,
359 IDS_DEV_DISABLED_SERVICE
,
360 IDS_DEV_TRANSLATION_FAILED
,
361 IDS_DEV_NO_SOFTCONFIG
,
363 IDS_DEV_IRQ_TRANSLATION_FAILED
,
364 IDS_DEV_FAILED_DRIVER_ENTRY
,
365 IDS_DEV_DRIVER_FAILED_PRIOR_UNLOAD
,
366 IDS_DEV_DRIVER_FAILED_LOAD
,
367 IDS_DEV_DRIVER_SERVICE_KEY_INVALID
,
368 IDS_DEV_LEGACY_SERVICE_NO_DEVICES
,
369 IDS_DEV_DUPLICATE_DEVICE
,
370 IDS_DEV_FAILED_POST_START
,
373 IDS_DEV_SYSTEM_SHUTDOWN
,
374 IDS_DEV_HELD_FOR_EJECT
,
375 IDS_DEV_DRIVER_BLOCKED
,
376 IDS_DEV_REGISTRY_TOO_LARGE
,
377 IDS_DEV_SETPROPERTIES_FAILED
381 /***************************************************************************
386 * Gets the problem text from a problem number displayed in the properties dialog
389 * hMachine: Machine handle or NULL for the local machine
390 * DevInst: Device instance handle
391 * uProblemId: Specifies the problem ID
392 * lpString: Pointer to a buffer where the string is to be copied to. If the buffer
393 * is too small, the return value is the required string length in characters,
394 * excluding the NULL-termination.
395 * uMaxString: Size of the buffer in characters
398 * The return value is the length of the string in characters.
399 * It returns 0 if an error occured.
405 DeviceProblemTextA(IN HMACHINE hMachine OPTIONAL
,
406 IN DEVINST dnDevInst
,
411 LPWSTR lpBuffer
= NULL
;
416 lpBuffer
= HeapAlloc(GetProcessHeap(),
418 (uMaxString
+ 1) * sizeof(WCHAR
));
419 if (lpBuffer
== NULL
)
421 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
426 Ret
= DeviceProblemTextW(hMachine
,
432 if (lpBuffer
!= NULL
)
436 WideCharToMultiByte(CP_ACP
,
446 HeapFree(GetProcessHeap(),
455 /***************************************************************************
460 * Gets the problem text from a problem number displayed in the properties dialog
463 * hMachine: Machine handle or NULL for the local machine
464 * DevInst: Device instance handle
465 * uProblemId: Specifies the problem ID
466 * lpString: Pointer to a buffer where the string is to be copied to. If the buffer
467 * is too small, the return value is the required string length in characters,
468 * excluding the NULL-termination.
469 * uMaxString: Size of the buffer in characters
472 * The return value is the length of the string in characters.
473 * It returns 0 if an error occured.
479 DeviceProblemTextW(IN HMACHINE hMachine OPTIONAL
,
480 IN DEVINST dnDevInst
,
485 UINT MessageId
= IDS_UNKNOWN
;
488 if (uProblemId
< sizeof(ProblemStringId
) / sizeof(ProblemStringId
[0]))
489 MessageId
= ProblemStringId
[uProblemId
];
495 Ret
= LoadString(hDllInstance
,
502 Ret
= (UINT
)LengthOfStrResource(hDllInstance
,
508 LPWSTR szProblem
, szInfo
= L
"FIXME";
510 BOOL AdvFormat
= FALSE
;
519 case CM_PROB_DEVLOADER_FAILED
:
521 /* FIXME - if not a root bus devloader then use IDS_DEV_DEVLOADER_FAILED2 */
522 /* FIXME - get the type string (ie. ISAPNP, PCI or BIOS for root bus devloaders,
523 or FLOP, ESDI, SCSI, etc for others */
528 case CM_PROB_DEVLOADER_NOT_FOUND
:
531 1) if it's a missing system devloader:
532 - get the system devloader name
533 2) if it's not a system devloader but still missing:
534 - get the devloader name (file name?)
535 3) if it's not a system devloader but the file can be found:
536 - use IDS_DEV_DEVLOADER_NOT_FOUND2
537 4) if it's a missing or empty software key
538 - use IDS_DEV_DEVLOADER_NOT_FOUND3
545 case CM_PROB_INVALID_DATA
:
546 /* FIXME - if the device isn't enumerated by the BIOS/ACPI use IDS_DEV_INVALID_DATA2 */
550 case CM_PROB_NORMAL_CONFLICT
:
551 /* FIXME - get resource type (IRQ, DMA, Memory or I/O) */
555 case CM_PROB_UNKNOWN_RESOURCE
:
556 /* FIXME - get the .inf file name */
560 case CM_PROB_DISABLED
:
561 /* FIXME - if the device was disabled by the system use IDS_DEV_DISABLED2 */
564 case CM_PROB_FAILED_ADD
:
565 /* FIXME - get the name of the sub-device with the error */
572 StringIDs
[1] = IDS_DEVCODE2
;
573 dwRet
= LoadAndFormatStringsCat(hDllInstance
,
575 sizeof(StringIDs
) / sizeof(StringIDs
[0]),
579 LocalFree((HLOCAL
)szInfo
);
583 dwRet
= LoadAndFormatStringsCat(hDllInstance
,
585 sizeof(StringIDs
) / sizeof(StringIDs
[0]),
592 if (uMaxString
!= 0 && uMaxString
>= dwRet
)
598 LocalFree((HLOCAL
)szProblem
);