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
19 /* $Id: hwpage.c 19599 2005-11-26 02:12:58Z weiden $
21 * PROJECT: ReactOS devmgr.dll
22 * FILE: lib/devmgr/devprblm.c
23 * PURPOSE: ReactOS Device Manager
24 * PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com>
35 ShowDeviceProblemWizard(IN HWND hWndParent OPTIONAL
,
37 IN PSP_DEVINFO_DATA DevInfoData
,
38 IN HMACHINE hMachine OPTIONAL
)
41 ULONG Status
, ProblemNumber
;
44 cr
= CM_Get_DevNode_Status_Ex(&Status
,
49 if (cr
== CR_SUCCESS
&& (Status
& DN_HAS_PROBLEM
))
51 switch (ProblemNumber
)
53 case CM_PROB_DEVLOADER_FAILED
:
55 /* FIXME - only if it's not a root bus devloader */
56 /* FIXME - display the update driver wizard */
60 case CM_PROB_OUT_OF_MEMORY
:
61 case CM_PROB_ENTRY_IS_WRONG_TYPE
:
62 case CM_PROB_LACKED_ARBITRATOR
:
63 case CM_PROB_FAILED_START
:
65 case CM_PROB_UNKNOWN_RESOURCE
:
67 /* FIXME - display the update driver wizard */
71 case CM_PROB_BOOT_CONFIG_CONFLICT
:
72 case CM_PROB_NORMAL_CONFLICT
:
73 case CM_PROB_REENUMERATION
:
75 /* FIXME - display the conflict wizard */
79 case CM_PROB_FAILED_FILTER
:
80 case CM_PROB_REINSTALL
:
81 case CM_PROB_FAILED_INSTALL
:
83 /* FIXME - display the driver (re)installation wizard */
87 case CM_PROB_DEVLOADER_NOT_FOUND
:
90 1) if it's a missing system devloader:
92 2) if it's not a system devloader but still missing:
93 - display the driver reinstallation wizard
94 3) if it's not a system devloader but the file can be found:
95 - display the update driver wizard
96 4) if it's a missing or empty software key
97 - display the update driver wizard
102 case CM_PROB_INVALID_DATA
:
103 case CM_PROB_PARTIAL_LOG_CONF
:
104 case CM_PROB_NO_VALID_LOG_CONF
:
105 case CM_PROB_HARDWARE_DISABLED
:
106 case CM_PROB_CANT_SHARE_IRQ
:
107 case CM_PROB_TRANSLATION_FAILED
:
108 case CM_PROB_SYSTEM_SHUTDOWN
:
109 case CM_PROB_PHANTOM
:
110 /* FIXME - do nothing */
113 case CM_PROB_NOT_VERIFIED
:
114 case CM_PROB_DEVICE_NOT_THERE
:
115 /* FIXME - display search hardware wizard */
118 case CM_PROB_NEED_RESTART
:
119 case CM_PROB_WILL_BE_REMOVED
:
121 case CM_PROB_TOO_EARLY
:
122 case CM_PROB_DISABLED_SERVICE
:
123 /* FIXME - reboot computer */
126 case CM_PROB_REGISTRY
:
127 /* FIXME - check registry */
130 case CM_PROB_DISABLED
:
132 /* FIXME - if device was disabled by user display the "Enable Device" wizard,
133 otherwise Troubleshoot because the device was disabled by the system */
137 case CM_PROB_DEVLOADER_NOT_READY
:
139 /* FIXME - if it's a graphics adapter:
140 - if it's a a secondary adapter and the main adapter
142 - do nothing or default action
144 - display the Properties
151 case CM_PROB_FAILED_ADD
:
153 /* FIXME - display the properties of the sub-device */
157 case CM_PROB_NO_SOFTCONFIG
:
158 case CM_PROB_IRQ_TRANSLATION_FAILED
:
159 case CM_PROB_FAILED_DRIVER_ENTRY
:
160 case CM_PROB_DRIVER_FAILED_PRIOR_UNLOAD
:
161 case CM_PROB_DRIVER_FAILED_LOAD
:
162 case CM_PROB_DRIVER_SERVICE_KEY_INVALID
:
163 case CM_PROB_LEGACY_SERVICE_NO_DEVICES
:
164 case CM_PROB_DUPLICATE_DEVICE
:
165 case CM_PROB_FAILED_POST_START
:
167 case CM_PROB_HELD_FOR_EJECT
:
168 case CM_PROB_DRIVER_BLOCKED
:
169 case CM_PROB_REGISTRY_TOO_LARGE
:
172 /* FIXME - troubleshoot the device */
182 /***************************************************************************
184 * DeviceProblemWizardA
187 * Calls the device problem wizard
190 * hWndParent: Handle to the parent window
191 * lpMachineName: Machine Name, NULL is the local machine
192 * lpDeviceID: Specifies the device, also see NOTEs
195 * TRUE: if no errors occured
196 * FALSE: if errors occured
202 DeviceProblemWizardA(IN HWND hWndParent OPTIONAL
,
203 IN LPCSTR lpMachineName OPTIONAL
,
204 IN LPCSTR lpDeviceID
)
206 LPWSTR lpMachineNameW
= NULL
;
207 LPWSTR lpDeviceIDW
= NULL
;
210 if (lpMachineName
!= NULL
)
212 if (!(lpMachineNameW
= ConvertMultiByteToUnicode(lpMachineName
,
218 if (lpDeviceID
!= NULL
)
220 if (!(lpDeviceIDW
= ConvertMultiByteToUnicode(lpDeviceID
,
227 Ret
= DeviceProblemWizardW(hWndParent
,
232 if (lpMachineNameW
!= NULL
)
234 HeapFree(GetProcessHeap(),
238 if (lpDeviceIDW
!= NULL
)
240 HeapFree(GetProcessHeap(),
249 /***************************************************************************
251 * DeviceProblemWizardW
254 * Calls the device problem wizard
257 * hWndParent: Handle to the parent window
258 * lpMachineName: Machine Name, NULL is the local machine
259 * lpDeviceID: Specifies the device, also see NOTEs
262 * TRUE: if no errors occured
263 * FALSE: if errors occured
269 DeviceProblemWizardW(IN HWND hWndParent OPTIONAL
,
270 IN LPCWSTR lpMachineName OPTIONAL
,
271 IN LPCWSTR lpDeviceID
)
274 SP_DEVINFO_DATA DevInfoData
;
280 if (lpDeviceID
== NULL
)
282 SetLastError(ERROR_INVALID_PARAMETER
);
286 /* dynamically load comctl32 */
287 hComCtl32
= LoadAndInitComctl32();
288 if (hComCtl32
!= NULL
)
290 hDevInfo
= SetupDiCreateDeviceInfoListEx(NULL
,
294 if (hDevInfo
!= INVALID_HANDLE_VALUE
)
296 cr
= CM_Connect_Machine(lpMachineName
,
298 if (cr
== CR_SUCCESS
)
300 DevInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
301 if (SetupDiOpenDeviceInfo(hDevInfo
,
307 Ret
= ShowDeviceProblemWizard(hWndParent
,
313 CM_Disconnect_Machine(hMachine
);
316 SetupDiDestroyDeviceInfoList(hDevInfo
);
319 FreeLibrary(hComCtl32
);
326 static const UINT ProblemStringId
[NUM_CM_PROB
] =
329 IDS_DEV_DEVLOADER_FAILED
,
330 IDS_DEV_NOT_CONFIGURED
,
331 IDS_DEV_OUT_OF_MEMORY
,
332 IDS_DEV_ENTRY_IS_WRONG_TYPE
,
333 IDS_DEV_LACKED_ARBITRATOR
,
334 IDS_DEV_BOOT_CONFIG_CONFLICT
,
335 IDS_DEV_FAILED_FILTER
,
336 IDS_DEV_DEVLOADER_NOT_FOUND
,
337 IDS_DEV_INVALID_DATA
,
338 IDS_DEV_FAILED_START
,
340 IDS_DEV_NORMAL_CONFLICT
,
341 IDS_DEV_NOT_VERIFIED
,
342 IDS_DEV_NEED_RESTART
,
343 IDS_DEV_REENUMERATION
,
344 IDS_DEV_PARTIAL_LOG_CONF
,
345 IDS_DEV_UNKNOWN_RESOURCE
,
348 IDS_UNKNOWN
, /* CM_PROB_VXDLDR, not used on NT */
349 IDS_DEV_WILL_BE_REMOVED
,
351 IDS_DEV_DEVLOADER_NOT_READY
,
352 IDS_DEV_DEVICE_NOT_THERE
,
355 IDS_DEV_NO_VALID_LOG_CONF
,
356 IDS_DEV_FAILED_INSTALL
,
357 IDS_DEV_HARDWARE_DISABLED
,
358 IDS_DEV_CANT_SHARE_IRQ
,
360 IDS_DEV_DISABLED_SERVICE
,
361 IDS_DEV_TRANSLATION_FAILED
,
362 IDS_DEV_NO_SOFTCONFIG
,
364 IDS_DEV_IRQ_TRANSLATION_FAILED
,
365 IDS_DEV_FAILED_DRIVER_ENTRY
,
366 IDS_DEV_DRIVER_FAILED_PRIOR_UNLOAD
,
367 IDS_DEV_DRIVER_FAILED_LOAD
,
368 IDS_DEV_DRIVER_SERVICE_KEY_INVALID
,
369 IDS_DEV_LEGACY_SERVICE_NO_DEVICES
,
370 IDS_DEV_DUPLICATE_DEVICE
,
371 IDS_DEV_FAILED_POST_START
,
374 IDS_DEV_SYSTEM_SHUTDOWN
,
375 IDS_DEV_HELD_FOR_EJECT
,
376 IDS_DEV_DRIVER_BLOCKED
,
377 IDS_DEV_REGISTRY_TOO_LARGE
,
378 IDS_DEV_SETPROPERTIES_FAILED
382 /***************************************************************************
387 * Gets the problem text from a problem number displayed in the properties dialog
390 * hMachine: Machine handle or NULL for the local machine
391 * DevInst: Device instance handle
392 * uProblemId: Specifies the problem ID
393 * lpString: Pointer to a buffer where the string is to be copied to. If the buffer
394 * is too small, the return value is the required string length in characters,
395 * excluding the NULL-termination.
396 * uMaxString: Size of the buffer in characters
399 * The return value is the length of the string in characters.
400 * It returns 0 if an error occured.
406 DeviceProblemTextA(IN HMACHINE hMachine OPTIONAL
,
407 IN DEVINST dnDevInst
,
412 LPWSTR lpBuffer
= NULL
;
417 lpBuffer
= HeapAlloc(GetProcessHeap(),
419 (uMaxString
+ 1) * sizeof(WCHAR
));
420 if (lpBuffer
== NULL
)
422 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
427 Ret
= DeviceProblemTextW(hMachine
,
433 if (lpBuffer
!= NULL
)
437 WideCharToMultiByte(CP_ACP
,
447 HeapFree(GetProcessHeap(),
456 /***************************************************************************
461 * Gets the problem text from a problem number displayed in the properties dialog
464 * hMachine: Machine handle or NULL for the local machine
465 * DevInst: Device instance handle
466 * uProblemId: Specifies the problem ID
467 * lpString: Pointer to a buffer where the string is to be copied to. If the buffer
468 * is too small, the return value is the required string length in characters,
469 * excluding the NULL-termination.
470 * uMaxString: Size of the buffer in characters
473 * The return value is the length of the string in characters.
474 * It returns 0 if an error occured.
480 DeviceProblemTextW(IN HMACHINE hMachine OPTIONAL
,
481 IN DEVINST dnDevInst
,
486 UINT MessageId
= IDS_UNKNOWN
;
489 if (uProblemId
< sizeof(ProblemStringId
) / sizeof(ProblemStringId
[0]))
490 MessageId
= ProblemStringId
[uProblemId
];
496 Ret
= LoadString(hDllInstance
,
503 Ret
= (UINT
)LengthOfStrResource(hDllInstance
,
509 LPWSTR szProblem
, szInfo
= NULL
;
511 BOOL AdvFormat
= FALSE
;
520 case CM_PROB_DEVLOADER_FAILED
:
522 /* FIXME - if not a root bus devloader then use IDS_DEV_DEVLOADER_FAILED2 */
523 /* FIXME - get the type string (ie. ISAPNP, PCI or BIOS for root bus devloaders,
524 or FLOP, ESDI, SCSI, etc for others */
525 AdvFormat
= (szInfo
!= NULL
);
529 case CM_PROB_DEVLOADER_NOT_FOUND
:
532 1) if it's a missing system devloader:
533 - get the system devloader name
534 2) if it's not a system devloader but still missing:
535 - get the devloader name (file name?)
536 3) if it's not a system devloader but the file can be found:
537 - use IDS_DEV_DEVLOADER_NOT_FOUND2
538 4) if it's a missing or empty software key
539 - use IDS_DEV_DEVLOADER_NOT_FOUND3
542 AdvFormat
= (szInfo
!= NULL
);
546 case CM_PROB_INVALID_DATA
:
547 /* FIXME - if the device isn't enumerated by the BIOS/ACPI use IDS_DEV_INVALID_DATA2 */
551 case CM_PROB_NORMAL_CONFLICT
:
552 /* FIXME - get resource type (IRQ, DMA, Memory or I/O) */
553 AdvFormat
= (szInfo
!= NULL
);
556 case CM_PROB_UNKNOWN_RESOURCE
:
557 /* FIXME - get the .inf file name */
558 AdvFormat
= (szInfo
!= NULL
);
561 case CM_PROB_DISABLED
:
562 /* FIXME - if the device was disabled by the system use IDS_DEV_DISABLED2 */
565 case CM_PROB_FAILED_ADD
:
566 /* FIXME - get the name of the sub-device with the error */
567 AdvFormat
= (szInfo
!= NULL
);
573 StringIDs
[1] = IDS_DEVCODE2
;
574 dwRet
= LoadAndFormatStringsCat(hDllInstance
,
576 sizeof(StringIDs
) / sizeof(StringIDs
[0]),
580 LocalFree((HLOCAL
)szInfo
);
584 dwRet
= LoadAndFormatStringsCat(hDllInstance
,
586 sizeof(StringIDs
) / sizeof(StringIDs
[0]),
593 if (uMaxString
!= 0 && uMaxString
>= dwRet
)
599 LocalFree((HLOCAL
)szProblem
);