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
21 * PROJECT: ReactOS devmgr.dll
22 * FILE: lib/devmgr/advprop.c
23 * PURPOSE: ReactOS Device Manager
24 * PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com>
25 * Ged Murphy <gedmurphy@reactos.org>
31 #include "properties.h"
38 EnumDeviceDriverFilesCallback(IN PVOID Context
,
44 PENUMDRIVERFILES_CONTEXT EnumDriverFilesContext
= (PENUMDRIVERFILES_CONTEXT
)Context
;
46 li
.mask
= LVIF_TEXT
| LVIF_STATE
;
47 li
.iItem
= EnumDriverFilesContext
->nCount
++;
49 li
.state
= (li
.iItem
== 0 ? LVIS_SELECTED
: 0);
50 li
.stateMask
= LVIS_SELECTED
;
51 li
.pszText
= (LPWSTR
)Param1
;
52 (void)ListView_InsertItem(EnumDriverFilesContext
->hDriversListView
,
59 UpdateDriverDetailsDlg(IN HWND hwndDlg
,
60 IN HWND hDriversListView
,
61 IN PDEVADVPROP_INFO dap
)
63 HDEVINFO DeviceInfoSet
;
64 PSP_DEVINFO_DATA DeviceInfoData
;
65 SP_DRVINFO_DATA DriverInfoData
;
66 ENUMDRIVERFILES_CONTEXT EnumDriverFilesContext
;
68 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
70 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
71 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
75 DeviceInfoSet
= dap
->DeviceInfoSet
;
76 DeviceInfoData
= &dap
->DeviceInfoData
;
79 /* set the device image */
80 SendDlgItemMessage(hwndDlg
,
83 (WPARAM
)dap
->hDevIcon
,
86 /* set the device name edit control text */
87 SetDlgItemText(hwndDlg
,
91 /* fill the driver files list view */
92 EnumDriverFilesContext
.hDriversListView
= hDriversListView
;
93 EnumDriverFilesContext
.nCount
= 0;
95 (void)ListView_DeleteAllItems(EnumDriverFilesContext
.hDriversListView
);
96 DriverInfoData
.cbSize
= sizeof(SP_DRVINFO_DATA
);
97 if (FindCurrentDriver(DeviceInfoSet
,
100 SetupDiSetSelectedDriver(DeviceInfoSet
,
104 HSPFILEQ queueHandle
;
106 queueHandle
= SetupOpenFileQueue();
107 if (queueHandle
!= (HSPFILEQ
)INVALID_HANDLE_VALUE
)
109 SP_DEVINSTALL_PARAMS DeviceInstallParams
= {0};
110 DeviceInstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS
);
111 if (SetupDiGetDeviceInstallParams(DeviceInfoSet
,
113 &DeviceInstallParams
))
115 DeviceInstallParams
.FileQueue
= queueHandle
;
116 DeviceInstallParams
.Flags
|= DI_NOVCP
;
118 if (SetupDiSetDeviceInstallParams(DeviceInfoSet
,
120 &DeviceInstallParams
) &&
121 SetupDiCallClassInstaller(DIF_INSTALLDEVICEFILES
,
129 /* enumerate the driver files */
130 SetupScanFileQueue(queueHandle
,
131 SPQ_SCAN_USE_CALLBACK
,
133 EnumDeviceDriverFilesCallback
,
134 &EnumDriverFilesContext
,
137 /* update the list view column width */
138 GetClientRect(hDriversListView
,
140 lvc
.mask
= LVCF_WIDTH
;
141 lvc
.cx
= rcClient
.right
;
142 (void)ListView_SetColumn(hDriversListView
,
146 /* highlight the first item from list */
147 if (ListView_GetSelectedCount(hDriversListView
) != 0)
149 ListView_SetItemState(hDriversListView
,
151 LVIS_FOCUSED
| LVIS_SELECTED
,
152 LVIS_FOCUSED
| LVIS_SELECTED
);
157 SetupCloseFileQueue(queueHandle
);
164 UpdateDriverVersionInfoDetails(IN HWND hwndDlg
,
165 IN LPCWSTR lpszDriverPath
)
169 LPVOID lpData
= NULL
;
173 WCHAR szLangInfo
[255];
174 WCHAR szLangPath
[MAX_PATH
];
175 LPWSTR lpCompanyName
= NULL
;
176 LPWSTR lpFileVersion
= NULL
;
177 LPWSTR lpLegalCopyright
= NULL
;
178 LPWSTR lpDigitalSigner
= NULL
;
180 WCHAR szNotAvailable
[255];
182 /* extract version info from selected file */
183 dwVerInfoSize
= GetFileVersionInfoSize(lpszDriverPath
,
188 lpData
= HeapAlloc(GetProcessHeap(),
194 if (!GetFileVersionInfo(lpszDriverPath
,
200 if (!VerQueryValue(lpData
,
201 L
"\\VarFileInfo\\Translation",
206 dwLangId
= *(LPDWORD
)lpInfo
;
207 swprintf(szLangInfo
, L
"\\StringFileInfo\\%04x%04x\\",
208 LOWORD(dwLangId
), HIWORD(dwLangId
));
210 /* read CompanyName */
211 wcscpy(szLangPath
, szLangInfo
);
212 wcscat(szLangPath
, L
"CompanyName");
214 VerQueryValue(lpData
,
216 (void **)&lpCompanyName
,
219 /* read FileVersion */
220 wcscpy(szLangPath
, szLangInfo
);
221 wcscat(szLangPath
, L
"FileVersion");
223 VerQueryValue(lpData
,
225 (void **)&lpFileVersion
,
228 /* read LegalTrademarks */
229 wcscpy(szLangPath
, szLangInfo
);
230 wcscat(szLangPath
, L
"LegalCopyright");
232 VerQueryValue(lpData
,
234 (void **)&lpLegalCopyright
,
237 /* TODO: read digital signer info */
240 if (!LoadString(hDllInstance
,
243 sizeof(szNotAvailable
) / sizeof(WCHAR
)))
245 wcscpy(szNotAvailable
, L
"n/a");
250 lpCompanyName
= szNotAvailable
;
251 SetDlgItemText(hwndDlg
,
256 lpFileVersion
= szNotAvailable
;
257 SetDlgItemText(hwndDlg
,
261 if (!lpLegalCopyright
)
262 lpLegalCopyright
= szNotAvailable
;
263 SetDlgItemText(hwndDlg
,
267 if (!lpDigitalSigner
)
268 lpDigitalSigner
= szNotAvailable
;
269 SetDlgItemText(hwndDlg
,
273 /* release version info */
275 HeapFree(GetProcessHeap(),
283 DriverDetailsDlgProc(IN HWND hwndDlg
,
288 PDEVADVPROP_INFO dap
;
291 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
,
294 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
300 switch (LOWORD(wParam
))
323 HWND hDriversListView
;
326 dap
= (PDEVADVPROP_INFO
)lParam
;
329 SetWindowLongPtr(hwndDlg
,
333 hDriversListView
= GetDlgItem(hwndDlg
,
336 /* add a column to the list view control */
337 lvc
.mask
= LVCF_FMT
| LVCF_WIDTH
;
338 lvc
.fmt
= LVCFMT_LEFT
;
340 (void)ListView_InsertColumn(hDriversListView
,
344 UpdateDriverDetailsDlg(hwndDlg
,
348 if (ListView_GetItemCount(hDriversListView
) == 0)
350 if(LoadStringW(hDllInstance
, IDS_NODRIVERS
, szBuffer
, _countof(szBuffer
)))
351 MessageBoxW(hwndDlg
, szBuffer
, dap
->szDevName
, MB_OK
);
352 EndDialog(hwndDlg
, IDCANCEL
);
362 LPNMHDR pnmhdr
= (LPNMHDR
)lParam
;
364 switch (pnmhdr
->code
)
366 case LVN_ITEMCHANGED
:
368 LPNMLISTVIEW pnmv
= (LPNMLISTVIEW
)lParam
;
369 HWND hDriversListView
= GetDlgItem(hwndDlg
,
372 if (ListView_GetSelectedCount(hDriversListView
) == 0)
374 /* nothing is selected - empty the labels */
375 SetDlgItemText(hwndDlg
,
378 SetDlgItemText(hwndDlg
,
381 SetDlgItemText(hwndDlg
,
384 SetDlgItemText(hwndDlg
,
388 else if (pnmv
->uNewState
!= 0)
390 /* extract version info and update the labels */
391 WCHAR szDriverPath
[MAX_PATH
];
393 ListView_GetItemText(hDriversListView
,
399 UpdateDriverVersionInfoDetails(hwndDlg
,
417 IN PDEVADVPROP_INFO dap
)
419 TOKEN_PRIVILEGES Privileges
;
422 BOOL NeedReboot
= FALSE
;
424 // Better use InstallDevInst:
429 // LPWSTR wszDeviceId,
432 // See: http://comp.os.ms-windows.programmer.win32.narkive.com/J8FTd4KK/signature-of-undocumented-installdevinstex
434 if (!InstallDevInst(hwndDlg
, dap
->szDeviceID
, TRUE
, &dwReboot
))
437 if (NeedReboot
== FALSE
)
440 //FIXME: load text from resource file
441 if (MessageBoxW(hwndDlg
, L
"Reboot now?", L
"Reboot required", MB_YESNO
| MB_ICONQUESTION
) != IDYES
)
444 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
446 ERR("OpenProcessToken failed\n");
450 /* Get the LUID for the Shutdown privilege */
451 if (!LookupPrivilegeValueW(NULL
, SE_SHUTDOWN_NAME
, &Privileges
.Privileges
[0].Luid
))
453 ERR("LookupPrivilegeValue failed\n");
458 /* Assign the Shutdown privilege to our process */
459 Privileges
.PrivilegeCount
= 1;
460 Privileges
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
462 if (!AdjustTokenPrivileges(hToken
, FALSE
, &Privileges
, 0, NULL
, NULL
))
464 ERR("AdjustTokenPrivileges failed\n");
469 /* Finally shut down the system */
470 if (!ExitWindowsEx(EWX_REBOOT
, SHTDN_REASON_MAJOR_OTHER
| SHTDN_REASON_MINOR_OTHER
| SHTDN_REASON_FLAG_PLANNED
))
472 ERR("ExitWindowsEx failed\n");
479 UpdateDriverDlg(IN HWND hwndDlg
,
480 IN PDEVADVPROP_INFO dap
)
482 HDEVINFO DeviceInfoSet
;
483 PSP_DEVINFO_DATA DeviceInfoData
;
485 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
487 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
488 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
492 DeviceInfoSet
= dap
->DeviceInfoSet
;
493 DeviceInfoData
= &dap
->DeviceInfoData
;
496 /* set the device image */
497 SendDlgItemMessage(hwndDlg
,
500 (WPARAM
)dap
->hDevIcon
,
503 /* set the device name edit control text */
504 SetDlgItemText(hwndDlg
,
508 /* query the driver provider */
509 if (GetDriverProviderString(DeviceInfoSet
,
512 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
514 SetDlgItemText(hwndDlg
,
519 /* query the driver date */
520 if (GetDriverDateString(DeviceInfoSet
,
523 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
525 SetDlgItemText(hwndDlg
,
530 /* query the driver version */
531 if (GetDriverVersionString(DeviceInfoSet
,
534 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
536 SetDlgItemText(hwndDlg
,
545 AdvProcDriverDlgProc(IN HWND hwndDlg
,
550 PDEVADVPROP_INFO dap
;
553 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
,
556 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
562 switch (LOWORD(wParam
))
564 case IDC_DRIVERDETAILS
:
565 DialogBoxParam(hDllInstance
,
566 MAKEINTRESOURCE(IDD_DRIVERDETAILS
),
568 DriverDetailsDlgProc
,
572 case IDC_UPDATEDRIVER
:
573 UpdateDriver(hwndDlg
, dap
);
581 NMHDR
*hdr
= (NMHDR
*)lParam
;
592 dap
= (PDEVADVPROP_INFO
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
595 SetWindowLongPtr(hwndDlg
,
599 UpdateDriverDlg(hwndDlg
,
613 SetListViewText(HWND hwnd
,
619 li
.mask
= LVIF_TEXT
| LVIF_STATE
;
622 li
.state
= 0; //(li.iItem == 0 ? LVIS_SELECTED : 0);
623 li
.stateMask
= LVIS_SELECTED
;
624 li
.pszText
= (LPWSTR
)lpText
;
625 (void)ListView_InsertItem(hwnd
,
631 UpdateDetailsDlg(IN HWND hwndDlg
,
632 IN PDEVADVPROP_INFO dap
)
643 IDS_PROP_HARDWAREIDS
,
644 IDS_PROP_COMPATIBLEIDS
,
645 IDS_PROP_MATCHINGDEVICEID
,
648 IDS_PROP_CAPABILITIES
,
649 IDS_PROP_DEVNODEFLAGS
,
650 IDS_PROP_CONFIGFLAGS
,
651 IDS_PROP_CSCONFIGFLAGS
,
652 IDS_PROP_EJECTIONRELATIONS
,
653 IDS_PROP_REMOVALRELATIONS
,
654 IDS_PROP_BUSRELATIONS
,
655 IDS_PROP_DEVUPPERFILTERS
,
656 IDS_PROP_DEVLOWERFILTERS
,
657 IDS_PROP_CLASSUPPERFILTERS
,
658 IDS_PROP_CLASSLOWERFILTERS
,
659 IDS_PROP_CLASSINSTALLER
,
660 IDS_PROP_CLASSCOINSTALLER
,
661 IDS_PROP_DEVICECOINSTALLER
,
662 IDS_PROP_FIRMWAREREVISION
,
663 IDS_PROP_CURRENTPOWERSTATE
,
664 IDS_PROP_POWERCAPABILITIES
,
665 IDS_PROP_POWERSTATEMAPPINGS
669 /* set the device image */
670 SendDlgItemMessage(hwndDlg
,
673 (WPARAM
)dap
->hDevIcon
,
676 /* set the device name edit control text */
677 SetDlgItemText(hwndDlg
,
682 hwndComboBox
= GetDlgItem(hwndDlg
,
683 IDC_DETAILSPROPNAME
);
685 hwndListView
= GetDlgItem(hwndDlg
,
686 IDC_DETAILSPROPVALUE
);
688 for (i
= 0; i
!= sizeof(Properties
) / sizeof(Properties
[0]); i
++)
690 /* fill in the device usage combo box */
691 if (LoadString(hDllInstance
,
694 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
696 SendMessage(hwndComboBox
,
699 (LPARAM
)dap
->szTemp
);
704 GetClientRect(hwndListView
,
707 /* add a column to the list view control */
708 lvc
.mask
= LVCF_FMT
| LVCF_WIDTH
;
709 lvc
.fmt
= LVCFMT_LEFT
;
710 lvc
.cx
= rcClient
.right
;
711 (void)ListView_InsertColumn(hwndListView
,
715 SendMessage(hwndComboBox
,
720 SetListViewText(hwndListView
, 0, dap
->szDeviceID
);
722 SetFocus(hwndComboBox
);
727 DisplayDevicePropertyText(IN PDEVADVPROP_INFO dap
,
728 IN HWND hwndListView
,
731 HDEVINFO DeviceInfoSet
;
732 PSP_DEVINFO_DATA DeviceInfoData
;
741 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
743 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
744 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
748 DeviceInfoSet
= dap
->DeviceInfoSet
;
749 DeviceInfoData
= &dap
->DeviceInfoData
;
753 SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
762 if (GetLastError() != ERROR_FILE_NOT_FOUND
)
764 swprintf(dap
->szTemp
, L
"Error: Getting the size failed! (Error: %ld)", GetLastError());
765 SetListViewText(hwndListView
, 0, dap
->szTemp
);
770 if (dwType
== REG_SZ
)
771 dwSize
+= sizeof(WCHAR
);
773 lpBuffer
= (LPBYTE
)HeapAlloc(GetProcessHeap(),
776 if (lpBuffer
== NULL
)
778 SetListViewText(hwndListView
, 0, L
"Error: Allocating the buffer failed!");
782 if (SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
790 if (dwType
== REG_SZ
)
792 SetListViewText(hwndListView
, 0, (LPWSTR
)lpBuffer
);
794 else if (dwType
== REG_MULTI_SZ
)
796 lpStr
= (LPWSTR
)lpBuffer
;
800 len
= wcslen(lpStr
) + 1;
802 SetListViewText(hwndListView
, index
, lpStr
);
808 else if (dwType
== REG_DWORD
)
810 dwValue
= *(DWORD
*) lpBuffer
;
814 case SPDRP_CAPABILITIES
:
816 if (dwValue
& CM_DEVCAP_LOCKSUPPORTED
)
817 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_LOCKSUPPORTED");
818 if (dwValue
& CM_DEVCAP_EJECTSUPPORTED
)
819 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_EJECTSUPPORTED");
820 if (dwValue
& CM_DEVCAP_REMOVABLE
)
821 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_REMOVABLE");
822 if (dwValue
& CM_DEVCAP_DOCKDEVICE
)
823 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_DOCKDEVICE");
824 if (dwValue
& CM_DEVCAP_UNIQUEID
)
825 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_UNIQUEID");
826 if (dwValue
& CM_DEVCAP_SILENTINSTALL
)
827 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_SILENTINSTALL");
828 if (dwValue
& CM_DEVCAP_RAWDEVICEOK
)
829 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_RAWDEVICEOK");
830 if (dwValue
& CM_DEVCAP_SURPRISEREMOVALOK
)
831 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_SURPRISEREMOVALOK");
832 if (dwValue
& CM_DEVCAP_HARDWAREDISABLED
)
833 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_HARDWAREDISABLED");
834 if (dwValue
& CM_DEVCAP_NONDYNAMIC
)
835 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_NONDYNAMIC");
838 case SPDRP_CONFIGFLAGS
:
840 if (dwValue
& CONFIGFLAG_DISABLED
)
841 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_DISABLED");
842 if (dwValue
& CONFIGFLAG_REMOVED
)
843 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_REMOVED");
844 if (dwValue
& CONFIGFLAG_MANUAL_INSTALL
)
845 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_MANUAL_INSTALL");
846 if (dwValue
& CONFIGFLAG_IGNORE_BOOT_LC
)
847 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_IGNORE_BOOT_LC");
848 if (dwValue
& CONFIGFLAG_NET_BOOT
)
849 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_NET_BOOT");
850 if (dwValue
& CONFIGFLAG_REINSTALL
)
851 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_REINSTALL");
852 if (dwValue
& CONFIGFLAG_FAILEDINSTALL
)
853 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_FAILEDINSTALL");
854 if (dwValue
& CONFIGFLAG_CANTSTOPACHILD
)
855 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_CANTSTOPACHILD");
856 if (dwValue
& CONFIGFLAG_OKREMOVEROM
)
857 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_OKREMOVEROM");
858 if (dwValue
& CONFIGFLAG_NOREMOVEEXIT
)
859 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_NOREMOVEEXIT");
863 swprintf(dap
->szTemp
, L
"0x%08lx", dwValue
);
864 SetListViewText(hwndListView
, 0, dap
->szTemp
);
870 SetListViewText(hwndListView
, 0, L
"Error: Unsupported value type!");
876 SetListViewText(hwndListView
, 0, L
"Error: Retrieving the value failed!");
879 HeapFree(GetProcessHeap(),
885 DisplayDevNodeFlags(IN PDEVADVPROP_INFO dap
,
886 IN HWND hwndListView
)
892 CM_Get_DevNode_Status_Ex(&dwStatus
,
894 dap
->DeviceInfoData
.DevInst
,
899 if (dwStatus
& DN_ROOT_ENUMERATED
)
900 SetListViewText(hwndListView
, index
++, L
"DN_ROOT_ENUMERATED");
901 if (dwStatus
& DN_DRIVER_LOADED
)
902 SetListViewText(hwndListView
, index
++, L
"DN_DRIVER_LOADED");
903 if (dwStatus
& DN_ENUM_LOADED
)
904 SetListViewText(hwndListView
, index
++, L
"DN_ENUM_LOADED");
905 if (dwStatus
& DN_STARTED
)
906 SetListViewText(hwndListView
, index
++, L
"DN_STARTED");
907 if (dwStatus
& DN_MANUAL
)
908 SetListViewText(hwndListView
, index
++, L
"DN_MANUAL");
909 if (dwStatus
& DN_NEED_TO_ENUM
)
910 SetListViewText(hwndListView
, index
++, L
"DN_NEED_TO_ENUM");
911 if (dwStatus
& DN_DRIVER_BLOCKED
)
912 SetListViewText(hwndListView
, index
++, L
"DN_DRIVER_BLOCKED");
913 if (dwStatus
& DN_HARDWARE_ENUM
)
914 SetListViewText(hwndListView
, index
++, L
"DN_HARDWARE_ENUM");
915 if (dwStatus
& DN_NEED_RESTART
)
916 SetListViewText(hwndListView
, index
++, L
"DN_NEED_RESTART");
917 if (dwStatus
& DN_CHILD_WITH_INVALID_ID
)
918 SetListViewText(hwndListView
, index
++, L
"DN_CHILD_WITH_INVALID_ID");
919 if (dwStatus
& DN_HAS_PROBLEM
)
920 SetListViewText(hwndListView
, index
++, L
"DN_HAS_PROBLEM");
921 if (dwStatus
& DN_FILTERED
)
922 SetListViewText(hwndListView
, index
++, L
"DN_FILTERED");
923 if (dwStatus
& DN_LEGACY_DRIVER
)
924 SetListViewText(hwndListView
, index
++, L
"DN_LEGACY_DRIVER");
925 if (dwStatus
& DN_DISABLEABLE
)
926 SetListViewText(hwndListView
, index
++, L
"DN_DISABLEABLE");
927 if (dwStatus
& DN_REMOVABLE
)
928 SetListViewText(hwndListView
, index
++, L
"DN_REMOVABLE");
929 if (dwStatus
& DN_PRIVATE_PROBLEM
)
930 SetListViewText(hwndListView
, index
++, L
"DN_PRIVATE_PROBLEM");
931 if (dwStatus
& DN_MF_PARENT
)
932 SetListViewText(hwndListView
, index
++, L
"DN_MF_PARENT");
933 if (dwStatus
& DN_MF_CHILD
)
934 SetListViewText(hwndListView
, index
++, L
"DN_MF_CHILD");
935 if (dwStatus
& DN_WILL_BE_REMOVED
)
936 SetListViewText(hwndListView
, index
++, L
"DN_WILL_BE_REMOVED");
938 if (dwStatus
& DN_NOT_FIRST_TIMEE
)
939 SetListViewText(hwndListView
, index
++, L
"DN_NOT_FIRST_TIMEE");
940 if (dwStatus
& DN_STOP_FREE_RES
)
941 SetListViewText(hwndListView
, index
++, L
"DN_STOP_FREE_RES");
942 if (dwStatus
& DN_REBAL_CANDIDATE
)
943 SetListViewText(hwndListView
, index
++, L
"DN_REBAL_CANDIDATE");
944 if (dwStatus
& DN_BAD_PARTIAL
)
945 SetListViewText(hwndListView
, index
++, L
"DN_BAD_PARTIAL");
946 if (dwStatus
& DN_NT_ENUMERATOR
)
947 SetListViewText(hwndListView
, index
++, L
"DN_NT_ENUMERATOR");
948 if (dwStatus
& DN_NT_DRIVER
)
949 SetListViewText(hwndListView
, index
++, L
"DN_NT_DRIVER");
951 if (dwStatus
& DN_NEEDS_LOCKING
)
952 SetListViewText(hwndListView
, index
++, L
"DN_NEEDS_LOCKING");
953 if (dwStatus
& DN_ARM_WAKEUP
)
954 SetListViewText(hwndListView
, index
++, L
"DN_ARM_WAKEUP");
955 if (dwStatus
& DN_APM_ENUMERATOR
)
956 SetListViewText(hwndListView
, index
++, L
"DN_APM_ENUMERATOR");
957 if (dwStatus
& DN_APM_DRIVER
)
958 SetListViewText(hwndListView
, index
++, L
"DN_APM_DRIVER");
959 if (dwStatus
& DN_SILENT_INSTALL
)
960 SetListViewText(hwndListView
, index
++, L
"DN_SILENT_INSTALL");
961 if (dwStatus
& DN_NO_SHOW_IN_DM
)
962 SetListViewText(hwndListView
, index
++, L
"DN_NO_SHOW_IN_DM");
963 if (dwStatus
& DN_BOOT_LOG_PROB
)
964 SetListViewText(hwndListView
, index
++, L
"DN_BOOT_LOG_PROB");
966 // swprintf(dap->szTemp, L"0x%08x", dwStatus);
967 // SetListViewText(hwndListView, 0, dap->szTemp);
972 DisplayDevNodeEnumerator(IN PDEVADVPROP_INFO dap
,
973 IN HWND hwndListView
)
975 PSP_DEVINFO_DATA DeviceInfoData
;
979 DWORD dwSize
= 256 * sizeof(WCHAR
);
981 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
983 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
987 DeviceInfoData
= &dap
->DeviceInfoData
;
990 CM_Get_DevNode_Registry_Property_ExW(DeviceInfoData
->DevInst
,
991 CM_DRP_ENUMERATOR_NAME
,
998 SetListViewText(hwndListView
, 0, szBuffer
);
1003 DisplayCsFlags(IN PDEVADVPROP_INFO dap
,
1004 IN HWND hwndListView
)
1009 CM_Get_HW_Prof_Flags_Ex(dap
->szDevName
,
1010 0, /* current hardware profile */
1016 if (dwValue
& CSCONFIGFLAG_DISABLED
)
1017 SetListViewText(hwndListView
, index
++, L
"CSCONFIGFLAG_DISABLED");
1019 if (dwValue
& CSCONFIGFLAG_DO_NOT_CREATE
)
1020 SetListViewText(hwndListView
, index
++, L
"CSCONFIGFLAG_DO_NOT_CREATE");
1022 if (dwValue
& CSCONFIGFLAG_DO_NOT_START
)
1023 SetListViewText(hwndListView
, index
++, L
"CSCONFIGFLAG_DO_NOT_START");
1028 DisplayMatchingDeviceId(IN PDEVADVPROP_INFO dap
,
1029 IN HWND hwndListView
)
1031 HDEVINFO DeviceInfoSet
;
1032 PSP_DEVINFO_DATA DeviceInfoData
;
1033 WCHAR szBuffer
[256];
1038 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1040 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1041 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1045 DeviceInfoSet
= dap
->DeviceInfoSet
;
1046 DeviceInfoData
= &dap
->DeviceInfoData
;
1049 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
,
1055 if (hKey
!= INVALID_HANDLE_VALUE
)
1057 dwSize
= 256 * sizeof(WCHAR
);
1058 if (RegQueryValueEx(hKey
,
1059 L
"MatchingDeviceId",
1063 &dwSize
) == ERROR_SUCCESS
)
1065 SetListViewText(hwndListView
, 0, szBuffer
);
1074 DisplayClassCoinstallers(IN PDEVADVPROP_INFO dap
,
1075 IN HWND hwndListView
)
1077 HDEVINFO DeviceInfoSet
;
1078 PSP_DEVINFO_DATA DeviceInfoData
;
1079 WCHAR szClassGuid
[45];
1080 HKEY hKey
= (HKEY
)INVALID_HANDLE_VALUE
;
1083 LPBYTE lpBuffer
= NULL
;
1089 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1091 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1092 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1096 DeviceInfoSet
= dap
->DeviceInfoSet
;
1097 DeviceInfoData
= &dap
->DeviceInfoData
;
1100 dwSize
= 45 * sizeof(WCHAR
);
1101 if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
1105 (LPBYTE
)szClassGuid
,
1110 lError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1111 L
"SYSTEM\\CurrentControlSet\\Control\\CoDeviceInstallers",
1115 if (lError
!= ERROR_SUCCESS
)
1119 lError
= RegQueryValueEx(hKey
,
1125 if (lError
!= ERROR_SUCCESS
)
1131 lpBuffer
= (LPBYTE
)HeapAlloc(GetProcessHeap(),
1135 RegQueryValueEx(hKey
,
1142 lpStr
= (LPWSTR
)lpBuffer
;
1146 len
= wcslen(lpStr
) + 1;
1148 SetListViewText(hwndListView
, index
, lpStr
);
1155 if (lpBuffer
!= NULL
)
1156 HeapFree(GetProcessHeap(), 0, lpBuffer
);
1158 if (hKey
!= INVALID_HANDLE_VALUE
)
1164 DisplayDeviceCoinstallers(IN PDEVADVPROP_INFO dap
,
1165 IN HWND hwndListView
)
1167 HDEVINFO DeviceInfoSet
;
1168 PSP_DEVINFO_DATA DeviceInfoData
;
1177 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1179 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1180 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1184 DeviceInfoSet
= dap
->DeviceInfoSet
;
1185 DeviceInfoData
= &dap
->DeviceInfoData
;
1188 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
,
1194 if (hKey
!= INVALID_HANDLE_VALUE
)
1197 if (RegQueryValueEx(hKey
,
1202 &dwSize
) == ERROR_SUCCESS
&&
1206 lpBuffer
= (LPBYTE
)HeapAlloc(GetProcessHeap(),
1210 RegQueryValueEx(hKey
,
1217 lpStr
= (LPWSTR
)lpBuffer
;
1221 len
= wcslen(lpStr
) + 1;
1223 SetListViewText(hwndListView
, index
, lpStr
);
1229 HeapFree(GetProcessHeap(),
1240 DisplayClassProperties(IN PDEVADVPROP_INFO dap
,
1241 IN HWND hwndListView
,
1242 IN LPCWSTR lpProperty
)
1244 HDEVINFO DeviceInfoSet
;
1245 PSP_DEVINFO_DATA DeviceInfoData
;
1246 WCHAR szClassGuid
[45];
1256 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1258 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1259 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1263 DeviceInfoSet
= dap
->DeviceInfoSet
;
1264 DeviceInfoData
= &dap
->DeviceInfoData
;
1267 dwSize
= 45 * sizeof(WCHAR
);
1268 if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
1272 (LPBYTE
)szClassGuid
,
1277 pSetupGuidFromString(szClassGuid
,
1280 hKey
= SetupDiOpenClassRegKey(&ClassGuid
,
1282 if (hKey
!= INVALID_HANDLE_VALUE
)
1285 if (RegQueryValueEx(hKey
,
1290 &dwSize
) == ERROR_SUCCESS
&&
1293 lpBuffer
= (LPBYTE
)HeapAlloc(GetProcessHeap(),
1297 RegQueryValueEx(hKey
,
1304 if (dwType
== REG_SZ
)
1306 SetListViewText(hwndListView
, 0, (LPWSTR
)lpBuffer
);
1308 else if (dwType
== REG_MULTI_SZ
)
1310 lpStr
= (LPWSTR
)lpBuffer
;
1314 len
= wcslen(lpStr
) + 1;
1316 SetListViewText(hwndListView
, index
, lpStr
);
1323 HeapFree(GetProcessHeap(),
1334 DisplayDeviceRelations(
1335 IN PDEVADVPROP_INFO dap
,
1336 IN HWND hwndListView
,
1340 LPWSTR pszBuffer
= NULL
, pszStr
;
1345 ret
= CM_Get_Device_ID_List_Size_ExW(&ulLength
,
1349 if (ret
!= CR_SUCCESS
)
1352 pszBuffer
= (LPWSTR
)HeapAlloc(GetProcessHeap(),
1355 if (pszBuffer
== NULL
)
1358 ret
= CM_Get_Device_ID_List_ExW(dap
->szDeviceID
,
1363 if (ret
!= CR_SUCCESS
)
1365 HeapFree(GetProcessHeap(), 0, pszBuffer
);
1371 while (*pszStr
!= 0)
1373 len
= wcslen(pszStr
) + 1;
1375 SetListViewText(hwndListView
, index
, pszStr
);
1381 HeapFree(GetProcessHeap(), 0, pszBuffer
);
1386 DisplayDeviceProperties(IN PDEVADVPROP_INFO dap
,
1387 IN HWND hwndComboBox
,
1388 IN HWND hwndListView
)
1392 Index
= (INT
)SendMessage(hwndComboBox
,
1396 if (Index
== CB_ERR
)
1399 (void)ListView_DeleteAllItems(hwndListView
);
1404 SetListViewText(hwndListView
, 0, dap
->szDeviceID
);
1407 case 1: /* Hardware ID */
1408 DisplayDevicePropertyText(dap
,
1413 case 2: /* Compatible IDs */
1414 DisplayDevicePropertyText(dap
,
1416 SPDRP_COMPATIBLEIDS
);
1419 case 3: /* Matching ID */
1420 DisplayMatchingDeviceId(dap
,
1424 case 4: /* Service */
1425 DisplayDevicePropertyText(dap
,
1430 case 5: /* Enumerator */
1431 DisplayDevNodeEnumerator(dap
,
1435 case 6: /* Capabilities */
1436 DisplayDevicePropertyText(dap
,
1438 SPDRP_CAPABILITIES
);
1441 case 7: /* Devnode Flags */
1442 DisplayDevNodeFlags(dap
,
1446 case 8: /* Config Flags */
1447 DisplayDevicePropertyText(dap
,
1452 case 9: /* CSConfig Flags */
1457 case 10: /* Ejection relation */
1458 DisplayDeviceRelations(dap
,
1460 CM_GETIDLIST_FILTER_EJECTRELATIONS
);
1463 case 11: /* Removal relations */
1464 DisplayDeviceRelations(dap
,
1466 CM_GETIDLIST_FILTER_REMOVALRELATIONS
);
1469 case 12: /* Bus relation */
1470 DisplayDeviceRelations(dap
,
1472 CM_GETIDLIST_FILTER_BUSRELATIONS
);
1475 case 13: /* Device Upper Filters */
1476 DisplayDevicePropertyText(dap
,
1478 SPDRP_UPPERFILTERS
);
1481 case 14: /* Device Lower Filters */
1482 DisplayDevicePropertyText(dap
,
1484 SPDRP_LOWERFILTERS
);
1487 case 15: /* Class Upper Filters */
1488 DisplayClassProperties(dap
,
1493 case 16: /* Class Lower Filters */
1494 DisplayClassProperties(dap
,
1499 case 17: /* Class Installer */
1500 DisplayClassProperties(dap
,
1505 case 18: /* Class Coinstaller */
1506 DisplayClassCoinstallers(dap
,
1510 case 19: /* Device Coinstaller */
1511 DisplayDeviceCoinstallers(dap
,
1516 case 20: /* Firmware Revision */
1519 case 21: /* Current Power State */
1522 case 20: /* Power Capabilities */
1525 case 21: /* Power State Mappings */
1530 SetListViewText(hwndListView
, 0, L
"<Not implemented yet>");
1538 AdvProcDetailsDlgProc(IN HWND hwndDlg
,
1543 PDEVADVPROP_INFO dap
;
1544 INT_PTR Ret
= FALSE
;
1546 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
,
1549 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
1555 switch (LOWORD(wParam
))
1557 case IDC_DETAILSPROPNAME
:
1558 if (HIWORD(wParam
) == CBN_SELCHANGE
)
1560 DisplayDeviceProperties(dap
,
1561 GetDlgItem(hwndDlg
, IDC_DETAILSPROPNAME
),
1562 GetDlgItem(hwndDlg
, IDC_DETAILSPROPVALUE
));
1571 NMHDR
*hdr
= (NMHDR
*)lParam
;
1582 dap
= (PDEVADVPROP_INFO
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1585 SetWindowLongPtr(hwndDlg
,
1589 UpdateDetailsDlg(hwndDlg
,
1603 InitDevUsageActions(IN HWND hwndDlg
,
1605 IN PDEVADVPROP_INFO dap
)
1616 i
!= sizeof(Actions
) / sizeof(Actions
[0]);
1619 /* fill in the device usage combo box */
1620 if (LoadString(hDllInstance
,
1623 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1625 Index
= (INT
)SendMessage(hComboBox
,
1628 (LPARAM
)dap
->szTemp
);
1629 if (Index
!= CB_ERR
)
1631 SendMessage(hComboBox
,
1634 (LPARAM
)Actions
[i
]);
1638 case IDS_ENABLEDEVICE
:
1639 if (dap
->DeviceStarted
)
1641 SendMessage(hComboBox
,
1648 case IDS_DISABLEDEVICE
:
1649 if (!dap
->DeviceStarted
)
1651 SendMessage(hComboBox
,
1668 GetSelectedUsageAction(IN HWND hComboBox
)
1673 Index
= (INT
)SendMessage(hComboBox
,
1677 if (Index
!= CB_ERR
)
1679 INT iRet
= (INT
) SendMessage(hComboBox
,
1694 ApplyGeneralSettings(IN HWND hwndDlg
,
1695 IN PDEVADVPROP_INFO dap
)
1699 if (dap
->DeviceUsageChanged
&& dap
->IsAdmin
&& dap
->CanDisable
)
1701 UINT SelectedUsageAction
;
1702 BOOL NeedReboot
= FALSE
;
1704 SelectedUsageAction
= GetSelectedUsageAction(GetDlgItem(hwndDlg
,
1706 switch (SelectedUsageAction
)
1708 case IDS_ENABLEDEVICE
:
1709 if (!dap
->DeviceStarted
)
1711 Ret
= EnableDevice(dap
->DeviceInfoSet
,
1712 &dap
->DeviceInfoData
,
1719 case IDS_DISABLEDEVICE
:
1720 if (dap
->DeviceStarted
)
1722 Ret
= EnableDevice(dap
->DeviceInfoSet
,
1723 &dap
->DeviceInfoData
,
1738 /* make PropertySheet() return PSM_REBOOTSYSTEM */
1739 PropSheet_RebootSystem(hwndDlg
);
1744 /* FIXME - display an error message */
1745 FIXME("Failed to enable/disable device! LastError: %d\n",
1750 Ret
= !dap
->DeviceUsageChanged
;
1752 /* disable the apply button */
1753 PropSheet_UnChanged(GetParent(hwndDlg
),
1755 dap
->DeviceUsageChanged
= FALSE
;
1761 UpdateDevInfo(IN HWND hwndDlg
,
1762 IN PDEVADVPROP_INFO dap
,
1765 HWND hDevUsage
, hPropSheetDlg
, hDevProbBtn
;
1767 ULONG Status
, ProblemNumber
;
1768 SP_DEVINSTALL_PARAMS_W InstallParams
;
1769 UINT TroubleShootStrId
= IDS_TROUBLESHOOTDEV
;
1770 BOOL bFlag
, bDevActionAvailable
= TRUE
;
1771 BOOL bDrvInstalled
= FALSE
;
1773 HDEVINFO DeviceInfoSet
= NULL
;
1774 PSP_DEVINFO_DATA DeviceInfoData
= NULL
;
1775 PROPSHEETHEADER psh
;
1776 DWORD nDriverPages
= 0;
1777 BOOL RecalcPages
= FALSE
;
1779 hPropSheetDlg
= GetParent(hwndDlg
);
1781 if (dap
->PageInitialized
)
1783 /* switch to the General page */
1784 PropSheet_SetCurSelByID(hPropSheetDlg
,
1787 /* remove and destroy the existing device property sheet pages */
1788 if (dap
->DevPropSheets
!= NULL
)
1791 iPage
!= dap
->nDevPropSheets
;
1794 if (dap
->DevPropSheets
[iPage
] != NULL
)
1796 PropSheet_RemovePage(hPropSheetDlg
,
1798 dap
->DevPropSheets
[iPage
]);
1807 if (dap
->FreeDevPropSheets
)
1809 /* don't free the array if it's the one allocated in
1810 DisplayDeviceAdvancedProperties */
1811 HeapFree(GetProcessHeap(),
1813 dap
->DevPropSheets
);
1815 dap
->FreeDevPropSheets
= FALSE
;
1818 dap
->DevPropSheets
= NULL
;
1819 dap
->nDevPropSheets
= 0;
1823 /* create a new device info set and re-open the device */
1824 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1826 SetupDiDestroyDeviceInfoList(dap
->CurrentDeviceInfoSet
);
1829 dap
->ParentDevInst
= 0;
1830 dap
->CurrentDeviceInfoSet
= SetupDiCreateDeviceInfoListEx(NULL
,
1834 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1836 if (SetupDiOpenDeviceInfo(dap
->CurrentDeviceInfoSet
,
1840 &dap
->CurrentDeviceInfoData
))
1842 if (dap
->CloseDevInst
)
1844 SetupDiDestroyDeviceInfoList(dap
->DeviceInfoSet
);
1847 dap
->CloseDevInst
= TRUE
;
1848 dap
->DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1849 dap
->DeviceInfoData
= dap
->CurrentDeviceInfoData
;
1850 dap
->CurrentDeviceInfoSet
= INVALID_HANDLE_VALUE
;
1858 /* get the parent node from the initial devinst */
1859 CM_Get_Parent_Ex(&dap
->ParentDevInst
,
1860 dap
->DeviceInfoData
.DevInst
,
1865 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1867 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1868 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1872 DeviceInfoSet
= dap
->DeviceInfoSet
;
1873 DeviceInfoData
= &dap
->DeviceInfoData
;
1878 DeviceInfoSet
= dap
->DeviceInfoSet
;
1879 DeviceInfoData
= &dap
->DeviceInfoData
;
1882 dap
->HasDriverPage
= FALSE
;
1883 dap
->HasResourcePage
= FALSE
;
1884 dap
->HasPowerPage
= FALSE
;
1885 if (IsDriverInstalled(DeviceInfoData
->DevInst
,
1890 if (SetupDiCallClassInstaller((dap
->ShowRemotePages
?
1891 DIF_ADDREMOTEPROPERTYPAGE_ADVANCED
:
1892 DIF_ADDPROPERTYPAGE_ADVANCED
),
1896 /* get install params */
1897 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
1898 if (!SetupDiGetDeviceInstallParamsW(DeviceInfoSet
,
1902 /* zero the flags */
1903 InstallParams
.Flags
= 0;
1906 dap
->HasDriverPage
= !(InstallParams
.Flags
& DI_DRIVERPAGE_ADDED
);
1907 dap
->HasResourcePage
= !(InstallParams
.Flags
& DI_RESOURCEPAGE_ADDED
);
1908 dap
->HasPowerPage
= !(InstallParams
.Flags
& DI_FLAGSEX_POWERPAGE_ADDED
);
1912 /* get the device icon */
1913 if (dap
->hDevIcon
!= NULL
)
1915 DestroyIcon(dap
->hDevIcon
);
1916 dap
->hDevIcon
= NULL
;
1918 if (!SetupDiLoadClassIcon(&DeviceInfoData
->ClassGuid
,
1922 dap
->hDevIcon
= NULL
;
1925 /* get the device name */
1926 if (GetDeviceDescriptionString(DeviceInfoSet
,
1929 sizeof(dap
->szDevName
) / sizeof(dap
->szDevName
[0])))
1931 PropSheet_SetTitle(hPropSheetDlg
,
1936 /* set the device image */
1937 SendDlgItemMessage(hwndDlg
,
1940 (WPARAM
)dap
->hDevIcon
,
1943 /* set the device name edit control text */
1944 SetDlgItemText(hwndDlg
,
1948 /* set the device type edit control text */
1949 if (GetDeviceTypeString(DeviceInfoData
,
1951 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1953 SetDlgItemText(hwndDlg
,
1958 /* set the device manufacturer edit control text */
1959 if (GetDeviceManufacturerString(DeviceInfoSet
,
1962 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1964 SetDlgItemText(hwndDlg
,
1965 IDC_DEVMANUFACTURER
,
1969 /* set the device location edit control text */
1970 if (GetDeviceLocationString(DeviceInfoSet
,
1974 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1976 SetDlgItemText(hwndDlg
,
1981 /* set the device status edit control text */
1982 if (GetDeviceStatusString(DeviceInfoData
->DevInst
,
1985 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1987 SetDlgItemText(hwndDlg
,
1992 /* set the device troubleshoot button text and disable it if necessary */
1993 hDevProbBtn
= GetDlgItem(hwndDlg
,
1995 cr
= CM_Get_DevNode_Status_Ex(&Status
,
1997 DeviceInfoData
->DevInst
,
2000 if (cr
== CR_SUCCESS
&& (Status
& DN_HAS_PROBLEM
))
2002 switch (ProblemNumber
)
2004 case CM_PROB_DEVLOADER_FAILED
:
2006 /* FIXME - only if it's not a root bus devloader,
2007 disable the button otherwise */
2008 TroubleShootStrId
= IDS_UPDATEDRV
;
2012 case CM_PROB_OUT_OF_MEMORY
:
2013 case CM_PROB_ENTRY_IS_WRONG_TYPE
:
2014 case CM_PROB_LACKED_ARBITRATOR
:
2015 case CM_PROB_FAILED_START
:
2017 case CM_PROB_UNKNOWN_RESOURCE
:
2019 TroubleShootStrId
= IDS_UPDATEDRV
;
2023 case CM_PROB_BOOT_CONFIG_CONFLICT
:
2024 case CM_PROB_NORMAL_CONFLICT
:
2025 case CM_PROB_REENUMERATION
:
2027 /* FIXME - Troubleshoot conflict */
2031 case CM_PROB_FAILED_FILTER
:
2032 case CM_PROB_REINSTALL
:
2033 case CM_PROB_FAILED_INSTALL
:
2035 TroubleShootStrId
= IDS_REINSTALLDRV
;
2039 case CM_PROB_DEVLOADER_NOT_FOUND
:
2042 1) if it's a missing system devloader:
2043 - disable the button (Reinstall Driver)
2044 2) if it's not a system devloader but still missing:
2046 3) if it's not a system devloader but the file can be found:
2048 4) if it's a missing or empty software key
2054 case CM_PROB_INVALID_DATA
:
2055 case CM_PROB_PARTIAL_LOG_CONF
:
2056 case CM_PROB_NO_VALID_LOG_CONF
:
2057 case CM_PROB_HARDWARE_DISABLED
:
2058 case CM_PROB_CANT_SHARE_IRQ
:
2059 case CM_PROB_TRANSLATION_FAILED
:
2060 case CM_PROB_SYSTEM_SHUTDOWN
:
2061 case CM_PROB_PHANTOM
:
2062 bDevActionAvailable
= FALSE
;
2065 case CM_PROB_NOT_VERIFIED
:
2066 case CM_PROB_DEVICE_NOT_THERE
:
2067 /* FIXME - search hardware */
2070 case CM_PROB_NEED_RESTART
:
2071 case CM_PROB_WILL_BE_REMOVED
:
2073 case CM_PROB_TOO_EARLY
:
2074 case CM_PROB_DISABLED_SERVICE
:
2075 TroubleShootStrId
= IDS_REBOOT
;
2078 case CM_PROB_REGISTRY
:
2079 /* FIXME - check registry? */
2082 case CM_PROB_DISABLED
:
2083 /* if device was disabled by the user: */
2084 TroubleShootStrId
= IDS_ENABLEDEV
;
2085 /* FIXME - otherwise disable button because the device was
2086 disabled by the system*/
2089 case CM_PROB_DEVLOADER_NOT_READY
:
2090 /* FIXME - if it's a graphics adapter:
2091 - if it's a a secondary adapter and the main adapter
2101 case CM_PROB_FAILED_ADD
:
2102 TroubleShootStrId
= IDS_PROPERTIES
;
2107 if (LoadString(hDllInstance
,
2110 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])) != 0)
2112 SetWindowText(hDevProbBtn
,
2115 EnableWindow(hDevProbBtn
,
2116 dap
->IsAdmin
&& bDevActionAvailable
);
2118 /* check if the device can be enabled/disabled */
2119 hDevUsage
= GetDlgItem(hwndDlg
,
2122 dap
->CanDisable
= FALSE
;
2123 dap
->DeviceStarted
= FALSE
;
2125 if (CanDisableDevice(DeviceInfoData
->DevInst
,
2129 dap
->CanDisable
= bFlag
;
2132 if (IsDeviceStarted(DeviceInfoData
->DevInst
,
2136 dap
->DeviceStarted
= bFlag
;
2139 /* enable/disable the device usage controls */
2140 EnableWindow(GetDlgItem(hwndDlg
,
2142 dap
->CanDisable
&& dap
->IsAdmin
);
2143 EnableWindow(hDevUsage
,
2144 dap
->CanDisable
&& dap
->IsAdmin
);
2146 /* clear the combobox */
2147 SendMessage(hDevUsage
,
2151 if (dap
->CanDisable
)
2153 InitDevUsageActions(hwndDlg
,
2158 /* find out how many new device property sheets to add.
2159 fake a PROPSHEETHEADER structure, we don't plan to
2160 call PropertySheet again!*/
2161 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
2165 /* get the number of device property sheets for the device */
2166 if (!SetupDiGetClassDevPropertySheets(DeviceInfoSet
,
2171 dap
->PropertySheetType
) &&
2172 nDriverPages
!= 0 && GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
2174 dap
->nDevPropSheets
+= nDriverPages
;
2181 /* include the driver page */
2182 if (dap
->HasDriverPage
)
2183 dap
->nDevPropSheets
++;
2185 /* include the details page */
2187 dap
->nDevPropSheets
++;
2189 if (dap
->HasResourcePage
)
2190 dap
->nDevPropSheets
++;
2192 /* add the device property sheets */
2193 if (dap
->nDevPropSheets
!= 0)
2195 dap
->DevPropSheets
= (HPROPSHEETPAGE
*)HeapAlloc(GetProcessHeap(),
2197 dap
->nDevPropSheets
* sizeof(HPROPSHEETPAGE
));
2198 if (dap
->DevPropSheets
!= NULL
)
2200 if (nDriverPages
!= 0)
2202 psh
.phpage
= dap
->DevPropSheets
;
2204 /* query the device property sheet pages to add */
2205 if (SetupDiGetClassDevPropertySheets(DeviceInfoSet
,
2208 dap
->nDevPropSheets
,
2210 dap
->PropertySheetType
))
2212 /* add the property sheets */
2214 iPage
< nDriverPages
;
2217 if (PropSheet_AddPage(hPropSheetDlg
,
2218 dap
->DevPropSheets
[iPage
]))
2224 dap
->FreeDevPropSheets
= TRUE
;
2228 /* cleanup, we were unable to get the device property sheets */
2229 iPage
= nDriverPages
;
2230 dap
->nDevPropSheets
-= nDriverPages
;
2237 /* add the driver page if necessary */
2238 if (dap
->HasDriverPage
)
2240 PROPSHEETPAGE pspDriver
= {0};
2241 pspDriver
.dwSize
= sizeof(PROPSHEETPAGE
);
2242 pspDriver
.dwFlags
= PSP_DEFAULT
;
2243 pspDriver
.hInstance
= hDllInstance
;
2244 pspDriver
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICEDRIVER
);
2245 pspDriver
.pfnDlgProc
= AdvProcDriverDlgProc
;
2246 pspDriver
.lParam
= (LPARAM
)dap
;
2247 dap
->DevPropSheets
[iPage
] = dap
->pCreatePropertySheetPageW(&pspDriver
);
2248 if (dap
->DevPropSheets
[iPage
] != NULL
)
2250 if (PropSheet_AddPage(hPropSheetDlg
,
2251 dap
->DevPropSheets
[iPage
]))
2258 dap
->pDestroyPropertySheetPage(dap
->DevPropSheets
[iPage
]);
2259 dap
->DevPropSheets
[iPage
] = NULL
;
2266 /* Add the details page */
2267 PROPSHEETPAGE pspDetails
= {0};
2268 pspDetails
.dwSize
= sizeof(PROPSHEETPAGE
);
2269 pspDetails
.dwFlags
= PSP_DEFAULT
;
2270 pspDetails
.hInstance
= hDllInstance
;
2271 pspDetails
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICEDETAILS
);
2272 pspDetails
.pfnDlgProc
= AdvProcDetailsDlgProc
;
2273 pspDetails
.lParam
= (LPARAM
)dap
;
2274 dap
->DevPropSheets
[iPage
] = dap
->pCreatePropertySheetPageW(&pspDetails
);
2275 if (dap
->DevPropSheets
[iPage
] != NULL
)
2277 if (PropSheet_AddPage(hPropSheetDlg
,
2278 dap
->DevPropSheets
[iPage
]))
2285 dap
->pDestroyPropertySheetPage(dap
->DevPropSheets
[iPage
]);
2286 dap
->DevPropSheets
[iPage
] = NULL
;
2291 if (dap
->HasResourcePage
)
2293 PROPSHEETPAGE pspDriver
= {0};
2294 pspDriver
.dwSize
= sizeof(PROPSHEETPAGE
);
2295 pspDriver
.dwFlags
= PSP_DEFAULT
;
2296 pspDriver
.hInstance
= hDllInstance
;
2297 pspDriver
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICERESOURCES
);
2298 pspDriver
.pfnDlgProc
= ResourcesProcDriverDlgProc
;
2299 pspDriver
.lParam
= (LPARAM
)dap
;
2300 dap
->DevPropSheets
[iPage
] = dap
->pCreatePropertySheetPageW(&pspDriver
);
2301 if (dap
->DevPropSheets
[iPage
] != NULL
)
2303 if (PropSheet_AddPage(hPropSheetDlg
,
2304 dap
->DevPropSheets
[iPage
]))
2311 dap
->pDestroyPropertySheetPage(dap
->DevPropSheets
[iPage
]);
2312 dap
->DevPropSheets
[iPage
] = NULL
;
2316 /* FIXME: Add the power page */
2319 dap
->nDevPropSheets
= 0;
2324 PropSheet_RecalcPageSizes(hPropSheetDlg
);
2327 /* finally, disable the apply button */
2328 PropSheet_UnChanged(hPropSheetDlg
,
2330 dap
->DeviceUsageChanged
= FALSE
;
2336 DlgParentSubWndProc(IN HWND hwnd
,
2341 PDEVADVPROP_INFO dap
;
2343 dap
= (PDEVADVPROP_INFO
)GetProp(hwnd
,
2344 L
"DevMgrDevChangeSub");
2347 if (uMsg
== WM_DEVICECHANGE
&& !IsWindowVisible(dap
->hWndGeneralPage
))
2349 SendMessage(dap
->hWndGeneralPage
,
2355 /* pass the message the the old window proc */
2356 return CallWindowProc(dap
->ParentOldWndProc
,
2364 /* this is not a good idea if the subclassed window was an ansi
2365 window, but we failed finding out the previous window proc
2366 so we can't use CallWindowProc. This should rarely - if ever -
2369 return DefWindowProc(hwnd
,
2379 AdvPropGeneralDlgProc(IN HWND hwndDlg
,
2384 PDEVADVPROP_INFO dap
;
2385 INT_PTR Ret
= FALSE
;
2387 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
,
2390 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
2396 switch (LOWORD(wParam
))
2400 if (HIWORD(wParam
) == CBN_SELCHANGE
)
2402 PropSheet_Changed(GetParent(hwndDlg
),
2404 dap
->DeviceUsageChanged
= TRUE
;
2409 case IDC_DEVPROBLEM
:
2413 /* display the device problem wizard */
2414 ShowDeviceProblemWizard(hwndDlg
,
2416 &dap
->DeviceInfoData
,
2427 NMHDR
*hdr
= (NMHDR
*)lParam
;
2431 ApplyGeneralSettings(hwndDlg
,
2440 dap
= (PDEVADVPROP_INFO
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
2445 dap
->hWndGeneralPage
= hwndDlg
;
2447 SetWindowLongPtr(hwndDlg
,
2451 /* subclass the parent window to always receive
2452 WM_DEVICECHANGE messages */
2453 hWndParent
= GetParent(hwndDlg
);
2454 if (hWndParent
!= NULL
)
2456 /* subclass the parent window. This is not safe
2457 if the parent window belongs to another thread! */
2458 dap
->ParentOldWndProc
= (WNDPROC
)SetWindowLongPtr(hWndParent
,
2460 (LONG_PTR
)DlgParentSubWndProc
);
2462 if (dap
->ParentOldWndProc
!= NULL
&&
2464 L
"DevMgrDevChangeSub",
2467 dap
->hWndParent
= hWndParent
;
2471 /* do not call UpdateDevInfo directly in here because it modifies
2472 the pages of the property sheet! */
2473 PostMessage(hwndDlg
,
2482 case WM_DEVICECHANGE
:
2484 /* FIXME - don't call UpdateDevInfo for all events */
2485 UpdateDevInfo(hwndDlg
,
2494 UpdateDevInfo(hwndDlg
,
2497 dap
->PageInitialized
= TRUE
;
2503 /* restore the old window proc of the subclassed parent window */
2504 if (dap
->hWndParent
!= NULL
&& dap
->ParentOldWndProc
!= NULL
)
2506 if (SetWindowLongPtr(dap
->hWndParent
,
2508 (LONG_PTR
)dap
->ParentOldWndProc
) == (LONG_PTR
)DlgParentSubWndProc
)
2510 RemoveProp(dap
->hWndParent
,
2511 L
"DevMgrDevChangeSub");
2524 DisplayDeviceAdvancedProperties(IN HWND hWndParent
,
2525 IN LPCWSTR lpDeviceID OPTIONAL
,
2526 IN HDEVINFO DeviceInfoSet
,
2527 IN PSP_DEVINFO_DATA DeviceInfoData
,
2528 IN HINSTANCE hComCtl32
,
2529 IN LPCWSTR lpMachineName
,
2532 PROPSHEETHEADER psh
= {0};
2533 PROPSHEETPAGE pspGeneral
= {0};
2534 PPROPERTYSHEETW pPropertySheetW
;
2535 PCREATEPROPERTYSHEETPAGEW pCreatePropertySheetPageW
;
2536 PDESTROYPROPERTYSHEETPAGE pDestroyPropertySheetPage
;
2537 PDEVADVPROP_INFO DevAdvPropInfo
;
2538 HMACHINE hMachine
= NULL
;
2539 DWORD DevIdSize
= 0;
2542 /* we don't want to statically link against comctl32, so find the
2543 functions we need dynamically */
2545 (PPROPERTYSHEETW
)GetProcAddress(hComCtl32
,
2547 pCreatePropertySheetPageW
=
2548 (PCREATEPROPERTYSHEETPAGEW
)GetProcAddress(hComCtl32
,
2549 "CreatePropertySheetPageW");
2550 pDestroyPropertySheetPage
=
2551 (PDESTROYPROPERTYSHEETPAGE
)GetProcAddress(hComCtl32
,
2552 "DestroyPropertySheetPage");
2553 if (pPropertySheetW
== NULL
||
2554 pCreatePropertySheetPageW
== NULL
||
2555 pDestroyPropertySheetPage
== NULL
)
2560 if (lpDeviceID
== NULL
)
2562 /* find out how much size is needed for the device id */
2563 if (SetupDiGetDeviceInstanceId(DeviceInfoSet
,
2569 ERR("SetupDiGetDeviceInstanceId unexpectedly returned TRUE!\n");
2573 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
2580 DevIdSize
= (DWORD
)wcslen(lpDeviceID
) + 1;
2583 if (lpMachineName
!= NULL
&& lpMachineName
[0] != L
'\0')
2585 CONFIGRET cr
= CM_Connect_Machine(lpMachineName
,
2587 if (cr
!= CR_SUCCESS
)
2593 /* create the internal structure associated with the "General",
2594 "Driver", ... pages */
2595 DevAdvPropInfo
= (PDEVADVPROP_INFO
)HeapAlloc(GetProcessHeap(),
2597 FIELD_OFFSET(DEVADVPROP_INFO
,
2599 (DevIdSize
* sizeof(WCHAR
)));
2600 if (DevAdvPropInfo
== NULL
)
2602 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2606 if (lpDeviceID
== NULL
)
2608 /* read the device instance id */
2609 if (!SetupDiGetDeviceInstanceId(DeviceInfoSet
,
2611 DevAdvPropInfo
->szDeviceID
,
2620 /* copy the device instance id supplied by the caller */
2621 wcscpy(DevAdvPropInfo
->szDeviceID
,
2625 DevAdvPropInfo
->DeviceInfoSet
= DeviceInfoSet
;
2626 DevAdvPropInfo
->DeviceInfoData
= *DeviceInfoData
;
2627 DevAdvPropInfo
->CurrentDeviceInfoSet
= INVALID_HANDLE_VALUE
;
2628 DevAdvPropInfo
->CurrentDeviceInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
2630 DevAdvPropInfo
->ShowRemotePages
= (lpMachineName
!= NULL
&& lpMachineName
[0] != L
'\0');
2631 DevAdvPropInfo
->hMachine
= hMachine
;
2632 DevAdvPropInfo
->lpMachineName
= lpMachineName
;
2633 DevAdvPropInfo
->szDevName
[0] = L
'\0';
2634 DevAdvPropInfo
->hComCtl32
= hComCtl32
;
2635 DevAdvPropInfo
->pCreatePropertySheetPageW
= pCreatePropertySheetPageW
;
2636 DevAdvPropInfo
->pDestroyPropertySheetPage
= pDestroyPropertySheetPage
;
2638 DevAdvPropInfo
->IsAdmin
= TRUE
;// IsUserAdmin();
2639 DevAdvPropInfo
->DoDefaultDevAction
= ((dwFlags
& DPF_DEVICE_STATUS_ACTION
) != 0);
2640 DevAdvPropInfo
->Extended
= ((dwFlags
& DPF_EXTENDED
) != 0);
2642 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
2643 psh
.dwFlags
= PSH_PROPTITLE
| PSH_NOAPPLYNOW
;
2644 psh
.hwndParent
= hWndParent
;
2645 psh
.pszCaption
= DevAdvPropInfo
->szDevName
;
2647 DevAdvPropInfo
->PropertySheetType
= DevAdvPropInfo
->ShowRemotePages
?
2648 DIGCDP_FLAG_REMOTE_ADVANCED
:
2649 DIGCDP_FLAG_ADVANCED
;
2651 psh
.phpage
= (HPROPSHEETPAGE
*)HeapAlloc(GetProcessHeap(),
2653 1 * sizeof(HPROPSHEETPAGE
));
2654 if (psh
.phpage
== NULL
)
2659 /* add the "General" property sheet */
2660 pspGeneral
.dwSize
= sizeof(PROPSHEETPAGE
);
2661 pspGeneral
.dwFlags
= PSP_DEFAULT
;
2662 pspGeneral
.hInstance
= hDllInstance
;
2663 pspGeneral
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICEGENERAL
);
2664 pspGeneral
.pfnDlgProc
= AdvPropGeneralDlgProc
;
2665 pspGeneral
.lParam
= (LPARAM
)DevAdvPropInfo
;
2666 psh
.phpage
[psh
.nPages
] = pCreatePropertySheetPageW(&pspGeneral
);
2667 if (psh
.phpage
[psh
.nPages
] != NULL
)
2672 DevAdvPropInfo
->nDevPropSheets
= psh
.nPages
;
2674 if (psh
.nPages
!= 0)
2676 Ret
= pPropertySheetW(&psh
);
2678 /* NOTE: no need to destroy the property sheets anymore! */
2685 /* in case of failure the property sheets must be destroyed */
2686 if (psh
.phpage
!= NULL
)
2692 if (psh
.phpage
[i
] != NULL
)
2694 pDestroyPropertySheetPage(psh
.phpage
[i
]);
2700 if (DevAdvPropInfo
!= NULL
)
2702 if (DevAdvPropInfo
->FreeDevPropSheets
)
2704 /* don't free the array if it's the one allocated in
2705 DisplayDeviceAdvancedProperties */
2706 HeapFree(GetProcessHeap(),
2708 DevAdvPropInfo
->DevPropSheets
);
2711 if (DevAdvPropInfo
->CloseDevInst
)
2713 /* close the device info set in case a new one was created */
2714 SetupDiDestroyDeviceInfoList(DevAdvPropInfo
->DeviceInfoSet
);
2717 if (DevAdvPropInfo
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
2719 SetupDiDestroyDeviceInfoList(DevAdvPropInfo
->CurrentDeviceInfoSet
);
2722 if (DevAdvPropInfo
->hDevIcon
!= NULL
)
2724 DestroyIcon(DevAdvPropInfo
->hDevIcon
);
2727 HeapFree(GetProcessHeap(),
2732 if (psh
.phpage
!= NULL
)
2734 HeapFree(GetProcessHeap(),
2739 if (hMachine
!= NULL
)
2741 CM_Disconnect_Machine(hMachine
);