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
)
38 ULONG Status
, ProblemNumber
;
41 cr
= CM_Get_DevNode_Status_Ex(&Status
,
46 if (cr
== CR_SUCCESS
&& (Status
& DN_HAS_PROBLEM
))
48 switch (ProblemNumber
)
50 case CM_PROB_DEVLOADER_FAILED
:
52 /* FIXME - only if it's not a root bus devloader */
53 /* FIXME - display the update driver wizard */
57 case CM_PROB_OUT_OF_MEMORY
:
58 case CM_PROB_ENTRY_IS_WRONG_TYPE
:
59 case CM_PROB_LACKED_ARBITRATOR
:
60 case CM_PROB_FAILED_START
:
62 case CM_PROB_UNKNOWN_RESOURCE
:
64 /* FIXME - display the update driver wizard */
68 case CM_PROB_BOOT_CONFIG_CONFLICT
:
69 case CM_PROB_NORMAL_CONFLICT
:
70 case CM_PROB_REENUMERATION
:
72 /* FIXME - display the conflict wizard */
76 case CM_PROB_FAILED_FILTER
:
77 case CM_PROB_REINSTALL
:
78 case CM_PROB_FAILED_INSTALL
:
80 /* FIXME - display the driver (re)installation wizard */
84 case CM_PROB_DEVLOADER_NOT_FOUND
:
87 1) if it's a missing system devloader:
89 2) if it's not a system devloader but still missing:
90 - display the driver reinstallation wizard
91 3) if it's not a system devloader but the file can be found:
92 - display the update driver wizard
93 4) if it's a missing or empty software key
94 - display the update driver wizard
99 case CM_PROB_INVALID_DATA
:
100 case CM_PROB_PARTIAL_LOG_CONF
:
101 case CM_PROB_NO_VALID_LOG_CONF
:
102 case CM_PROB_HARDWARE_DISABLED
:
103 case CM_PROB_CANT_SHARE_IRQ
:
104 case CM_PROB_TRANSLATION_FAILED
:
105 case CM_PROB_SYSTEM_SHUTDOWN
:
106 case CM_PROB_PHANTOM
:
107 /* FIXME - do nothing */
110 case CM_PROB_NOT_VERIFIED
:
111 case CM_PROB_DEVICE_NOT_THERE
:
112 /* FIXME - display search hardware wizard */
115 case CM_PROB_NEED_RESTART
:
116 case CM_PROB_WILL_BE_REMOVED
:
118 case CM_PROB_TOO_EARLY
:
119 case CM_PROB_DISABLED_SERVICE
:
120 /* FIXME - reboot computer */
123 case CM_PROB_REGISTRY
:
124 /* FIXME - check registry */
127 case CM_PROB_DISABLED
:
129 /* FIXME - if device was disabled by user display the "Enable Device" wizard,
130 otherwise Troubleshoot because the device was disabled by the system */
134 case CM_PROB_DEVLOADER_NOT_READY
:
136 /* FIXME - if it's a graphics adapter:
137 - if it's a a secondary adapter and the main adapter
139 - do nothing or default action
141 - display the Properties
148 case CM_PROB_FAILED_ADD
:
150 /* FIXME - display the properties of the sub-device */
154 case CM_PROB_NO_SOFTCONFIG
:
155 case CM_PROB_IRQ_TRANSLATION_FAILED
:
156 case CM_PROB_FAILED_DRIVER_ENTRY
:
157 case CM_PROB_DRIVER_FAILED_PRIOR_UNLOAD
:
158 case CM_PROB_DRIVER_FAILED_LOAD
:
159 case CM_PROB_DRIVER_SERVICE_KEY_INVALID
:
160 case CM_PROB_LEGACY_SERVICE_NO_DEVICES
:
161 case CM_PROB_DUPLICATE_DEVICE
:
162 case CM_PROB_FAILED_POST_START
:
164 case CM_PROB_HELD_FOR_EJECT
:
165 case CM_PROB_DRIVER_BLOCKED
:
166 case CM_PROB_REGISTRY_TOO_LARGE
:
169 /* FIXME - troubleshoot the device */
179 /***************************************************************************
181 * DeviceProblemWizardA
184 * Calls the device problem wizard
187 * hWndParent: Handle to the parent window
188 * lpMachineName: Machine Name, NULL is the local machine
189 * lpDeviceID: Specifies the device, also see NOTEs
192 * TRUE: if no errors occured
193 * FALSE: if errors occured
199 DeviceProblemWizardA(IN HWND hWndParent OPTIONAL
,
200 IN LPCSTR lpMachineName OPTIONAL
,
201 IN LPCSTR lpDeviceID
)
203 LPWSTR lpMachineNameW
= NULL
;
204 LPWSTR lpDeviceIDW
= NULL
;
207 if (lpMachineName
!= NULL
)
209 if (!(lpMachineNameW
= ConvertMultiByteToUnicode(lpMachineName
,
215 if (lpDeviceID
!= NULL
)
217 if (!(lpDeviceIDW
= ConvertMultiByteToUnicode(lpDeviceID
,
224 Ret
= DeviceProblemWizardW(hWndParent
,
229 if (lpMachineNameW
!= NULL
)
231 HeapFree(GetProcessHeap(),
235 if (lpDeviceIDW
!= NULL
)
237 HeapFree(GetProcessHeap(),
246 /***************************************************************************
248 * DeviceProblemWizardW
251 * Calls the device problem wizard
254 * hWndParent: Handle to the parent window
255 * lpMachineName: Machine Name, NULL is the local machine
256 * lpDeviceID: Specifies the device, also see NOTEs
259 * TRUE: if no errors occured
260 * FALSE: if errors occured
266 DeviceProblemWizardW(IN HWND hWndParent OPTIONAL
,
267 IN LPCWSTR lpMachineName OPTIONAL
,
268 IN LPCWSTR lpDeviceID
)
271 SP_DEVINFO_DATA DevInfoData
;
277 if (lpDeviceID
== NULL
)
279 SetLastError(ERROR_INVALID_PARAMETER
);
283 /* dynamically load comctl32 */
284 hComCtl32
= LoadAndInitComctl32();
285 if (hComCtl32
!= NULL
)
287 hDevInfo
= SetupDiCreateDeviceInfoListEx(NULL
,
291 if (hDevInfo
!= INVALID_HANDLE_VALUE
)
293 cr
= CM_Connect_Machine(lpMachineName
,
295 if (cr
== CR_SUCCESS
)
297 DevInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
298 if (SetupDiOpenDeviceInfo(hDevInfo
,
304 Ret
= ShowDeviceProblemWizard(hWndParent
,
310 CM_Disconnect_Machine(hMachine
);
313 SetupDiDestroyDeviceInfoList(hDevInfo
);
316 FreeLibrary(hComCtl32
);
323 static const UINT ProblemStringId
[NUM_CM_PROB
] =
326 IDS_DEV_DEVLOADER_FAILED
,
327 IDS_DEV_NOT_CONFIGURED
,
328 IDS_DEV_OUT_OF_MEMORY
,
329 IDS_DEV_ENTRY_IS_WRONG_TYPE
,
330 IDS_DEV_LACKED_ARBITRATOR
,
331 IDS_DEV_BOOT_CONFIG_CONFLICT
,
332 IDS_DEV_FAILED_FILTER
,
333 IDS_DEV_DEVLOADER_NOT_FOUND
,
334 IDS_DEV_INVALID_DATA
,
335 IDS_DEV_FAILED_START
,
337 IDS_DEV_NORMAL_CONFLICT
,
338 IDS_DEV_NOT_VERIFIED
,
339 IDS_DEV_NEED_RESTART
,
340 IDS_DEV_REENUMERATION
,
341 IDS_DEV_PARTIAL_LOG_CONF
,
342 IDS_DEV_UNKNOWN_RESOURCE
,
345 IDS_UNKNOWN
, /* CM_PROB_VXDLDR, not used on NT */
346 IDS_DEV_WILL_BE_REMOVED
,
348 IDS_DEV_DEVLOADER_NOT_READY
,
349 IDS_DEV_DEVICE_NOT_THERE
,
352 IDS_DEV_NO_VALID_LOG_CONF
,
353 IDS_DEV_FAILED_INSTALL
,
354 IDS_DEV_HARDWARE_DISABLED
,
355 IDS_DEV_CANT_SHARE_IRQ
,
357 IDS_DEV_DISABLED_SERVICE
,
358 IDS_DEV_TRANSLATION_FAILED
,
359 IDS_DEV_NO_SOFTCONFIG
,
361 IDS_DEV_IRQ_TRANSLATION_FAILED
,
362 IDS_DEV_FAILED_DRIVER_ENTRY
,
363 IDS_DEV_DRIVER_FAILED_PRIOR_UNLOAD
,
364 IDS_DEV_DRIVER_FAILED_LOAD
,
365 IDS_DEV_DRIVER_SERVICE_KEY_INVALID
,
366 IDS_DEV_LEGACY_SERVICE_NO_DEVICES
,
367 IDS_DEV_DUPLICATE_DEVICE
,
368 IDS_DEV_FAILED_POST_START
,
371 IDS_DEV_SYSTEM_SHUTDOWN
,
372 IDS_DEV_HELD_FOR_EJECT
,
373 IDS_DEV_DRIVER_BLOCKED
,
374 IDS_DEV_REGISTRY_TOO_LARGE
,
375 IDS_DEV_SETPROPERTIES_FAILED
379 /***************************************************************************
384 * Gets the problem text from a problem number displayed in the properties dialog
387 * hMachine: Machine handle or NULL for the local machine
388 * DevInst: Device instance handle
389 * uProblemId: Specifies the problem ID
390 * lpString: Pointer to a buffer where the string is to be copied to. If the buffer
391 * is too small, the return value is the required string length in characters,
392 * excluding the NULL-termination.
393 * uMaxString: Size of the buffer in characters
396 * The return value is the length of the string in characters.
397 * It returns 0 if an error occured.
403 DeviceProblemTextA(IN HMACHINE hMachine OPTIONAL
,
404 IN DEVINST dnDevInst
,
409 LPWSTR lpBuffer
= NULL
;
414 lpBuffer
= HeapAlloc(GetProcessHeap(),
416 (uMaxString
+ 1) * sizeof(WCHAR
));
417 if (lpBuffer
== NULL
)
419 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
424 Ret
= DeviceProblemTextW(hMachine
,
430 if (lpBuffer
!= NULL
)
434 WideCharToMultiByte(CP_ACP
,
444 HeapFree(GetProcessHeap(),
453 /***************************************************************************
458 * Gets the problem text from a problem number displayed in the properties dialog
461 * hMachine: Machine handle or NULL for the local machine
462 * DevInst: Device instance handle
463 * uProblemId: Specifies the problem ID
464 * lpString: Pointer to a buffer where the string is to be copied to. If the buffer
465 * is too small, the return value is the required string length in characters,
466 * excluding the NULL-termination.
467 * uMaxString: Size of the buffer in characters
470 * The return value is the length of the string in characters.
471 * It returns 0 if an error occured.
477 DeviceProblemTextW(IN HMACHINE hMachine OPTIONAL
,
478 IN DEVINST dnDevInst
,
483 UINT MessageId
= IDS_UNKNOWN
;
486 if (uProblemId
< sizeof(ProblemStringId
) / sizeof(ProblemStringId
[0]))
487 MessageId
= ProblemStringId
[uProblemId
];
493 Ret
= LoadString(hDllInstance
,
500 Ret
= (UINT
)LengthOfStrResource(hDllInstance
,
506 LPWSTR szProblem
, szInfo
= L
"FIXME";
508 BOOL AdvFormat
= FALSE
;
517 case CM_PROB_DEVLOADER_FAILED
:
519 /* FIXME - if not a root bus devloader then use IDS_DEV_DEVLOADER_FAILED2 */
520 /* FIXME - get the type string (ie. ISAPNP, PCI or BIOS for root bus devloaders,
521 or FLOP, ESDI, SCSI, etc for others */
526 case CM_PROB_DEVLOADER_NOT_FOUND
:
529 1) if it's a missing system devloader:
530 - get the system devloader name
531 2) if it's not a system devloader but still missing:
532 - get the devloader name (file name?)
533 3) if it's not a system devloader but the file can be found:
534 - use IDS_DEV_DEVLOADER_NOT_FOUND2
535 4) if it's a missing or empty software key
536 - use IDS_DEV_DEVLOADER_NOT_FOUND3
543 case CM_PROB_INVALID_DATA
:
544 /* FIXME - if the device isn't enumerated by the BIOS/ACPI use IDS_DEV_INVALID_DATA2 */
548 case CM_PROB_NORMAL_CONFLICT
:
549 /* FIXME - get resource type (IRQ, DMA, Memory or I/O) */
553 case CM_PROB_UNKNOWN_RESOURCE
:
554 /* FIXME - get the .inf file name */
558 case CM_PROB_DISABLED
:
559 /* FIXME - if the device was disabled by the system use IDS_DEV_DISABLED2 */
562 case CM_PROB_FAILED_ADD
:
563 /* FIXME - get the name of the sub-device with the error */
570 StringIDs
[1] = IDS_DEVCODE2
;
571 dwRet
= LoadAndFormatStringsCat(hDllInstance
,
573 sizeof(StringIDs
) / sizeof(StringIDs
[0]),
577 LocalFree((HLOCAL
)szInfo
);
581 dwRet
= LoadAndFormatStringsCat(hDllInstance
,
583 sizeof(StringIDs
) / sizeof(StringIDs
[0]),
590 if (uMaxString
!= 0 && uMaxString
>= dwRet
)
596 LocalFree((HLOCAL
)szProblem
);