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
;
1344 ret
= CM_Get_Device_ID_List_Size_ExW(&ulLength
,
1348 if (ret
!= CR_SUCCESS
)
1351 pszBuffer
= (LPWSTR
)HeapAlloc(GetProcessHeap(),
1353 ulLength
* sizeof(WCHAR
));
1354 if (pszBuffer
== NULL
)
1357 ret
= CM_Get_Device_ID_List_ExW(dap
->szDeviceID
,
1362 if (ret
!= CR_SUCCESS
)
1364 HeapFree(GetProcessHeap(), 0, pszBuffer
);
1370 while (*pszStr
!= 0)
1372 len
= wcslen(pszStr
) + 1;
1374 SetListViewText(hwndListView
, index
, pszStr
);
1380 HeapFree(GetProcessHeap(), 0, pszBuffer
);
1385 DisplayDeviceProperties(IN PDEVADVPROP_INFO dap
,
1386 IN HWND hwndComboBox
,
1387 IN HWND hwndListView
)
1391 Index
= (INT
)SendMessage(hwndComboBox
,
1395 if (Index
== CB_ERR
)
1398 (void)ListView_DeleteAllItems(hwndListView
);
1403 SetListViewText(hwndListView
, 0, dap
->szDeviceID
);
1406 case 1: /* Hardware ID */
1407 DisplayDevicePropertyText(dap
,
1412 case 2: /* Compatible IDs */
1413 DisplayDevicePropertyText(dap
,
1415 SPDRP_COMPATIBLEIDS
);
1418 case 3: /* Matching ID */
1419 DisplayMatchingDeviceId(dap
,
1423 case 4: /* Service */
1424 DisplayDevicePropertyText(dap
,
1429 case 5: /* Enumerator */
1430 DisplayDevNodeEnumerator(dap
,
1434 case 6: /* Capabilities */
1435 DisplayDevicePropertyText(dap
,
1437 SPDRP_CAPABILITIES
);
1440 case 7: /* Devnode Flags */
1441 DisplayDevNodeFlags(dap
,
1445 case 8: /* Config Flags */
1446 DisplayDevicePropertyText(dap
,
1451 case 9: /* CSConfig Flags */
1456 case 10: /* Ejection relation */
1457 DisplayDeviceRelations(dap
,
1459 CM_GETIDLIST_FILTER_EJECTRELATIONS
);
1462 case 11: /* Removal relations */
1463 DisplayDeviceRelations(dap
,
1465 CM_GETIDLIST_FILTER_REMOVALRELATIONS
);
1468 case 12: /* Bus relation */
1469 DisplayDeviceRelations(dap
,
1471 CM_GETIDLIST_FILTER_BUSRELATIONS
);
1474 case 13: /* Device Upper Filters */
1475 DisplayDevicePropertyText(dap
,
1477 SPDRP_UPPERFILTERS
);
1480 case 14: /* Device Lower Filters */
1481 DisplayDevicePropertyText(dap
,
1483 SPDRP_LOWERFILTERS
);
1486 case 15: /* Class Upper Filters */
1487 DisplayClassProperties(dap
,
1492 case 16: /* Class Lower Filters */
1493 DisplayClassProperties(dap
,
1498 case 17: /* Class Installer */
1499 DisplayClassProperties(dap
,
1504 case 18: /* Class Coinstaller */
1505 DisplayClassCoinstallers(dap
,
1509 case 19: /* Device Coinstaller */
1510 DisplayDeviceCoinstallers(dap
,
1515 case 20: /* Firmware Revision */
1518 case 21: /* Current Power State */
1521 case 20: /* Power Capabilities */
1524 case 21: /* Power State Mappings */
1529 SetListViewText(hwndListView
, 0, L
"<Not implemented yet>");
1537 AdvProcDetailsDlgProc(IN HWND hwndDlg
,
1542 PDEVADVPROP_INFO dap
;
1543 INT_PTR Ret
= FALSE
;
1545 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
,
1548 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
1554 switch (LOWORD(wParam
))
1556 case IDC_DETAILSPROPNAME
:
1557 if (HIWORD(wParam
) == CBN_SELCHANGE
)
1559 DisplayDeviceProperties(dap
,
1560 GetDlgItem(hwndDlg
, IDC_DETAILSPROPNAME
),
1561 GetDlgItem(hwndDlg
, IDC_DETAILSPROPVALUE
));
1570 NMHDR
*hdr
= (NMHDR
*)lParam
;
1581 dap
= (PDEVADVPROP_INFO
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1584 SetWindowLongPtr(hwndDlg
,
1588 UpdateDetailsDlg(hwndDlg
,
1602 InitDevUsageActions(IN HWND hwndDlg
,
1604 IN PDEVADVPROP_INFO dap
)
1615 i
!= sizeof(Actions
) / sizeof(Actions
[0]);
1618 /* fill in the device usage combo box */
1619 if (LoadString(hDllInstance
,
1622 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1624 Index
= (INT
)SendMessage(hComboBox
,
1627 (LPARAM
)dap
->szTemp
);
1628 if (Index
!= CB_ERR
)
1630 SendMessage(hComboBox
,
1633 (LPARAM
)Actions
[i
]);
1637 case IDS_ENABLEDEVICE
:
1638 if (dap
->DeviceStarted
)
1640 SendMessage(hComboBox
,
1647 case IDS_DISABLEDEVICE
:
1648 if (!dap
->DeviceStarted
)
1650 SendMessage(hComboBox
,
1667 GetSelectedUsageAction(IN HWND hComboBox
)
1672 Index
= (INT
)SendMessage(hComboBox
,
1676 if (Index
!= CB_ERR
)
1678 INT iRet
= (INT
) SendMessage(hComboBox
,
1693 ApplyGeneralSettings(IN HWND hwndDlg
,
1694 IN PDEVADVPROP_INFO dap
)
1698 if (dap
->DeviceUsageChanged
&& dap
->IsAdmin
&& dap
->CanDisable
)
1700 UINT SelectedUsageAction
;
1701 BOOL NeedReboot
= FALSE
;
1703 SelectedUsageAction
= GetSelectedUsageAction(GetDlgItem(hwndDlg
,
1705 switch (SelectedUsageAction
)
1707 case IDS_ENABLEDEVICE
:
1708 if (!dap
->DeviceStarted
)
1710 Ret
= EnableDevice(dap
->DeviceInfoSet
,
1711 &dap
->DeviceInfoData
,
1718 case IDS_DISABLEDEVICE
:
1719 if (dap
->DeviceStarted
)
1721 Ret
= EnableDevice(dap
->DeviceInfoSet
,
1722 &dap
->DeviceInfoData
,
1737 /* make PropertySheet() return PSM_REBOOTSYSTEM */
1738 PropSheet_RebootSystem(hwndDlg
);
1743 /* FIXME - display an error message */
1744 FIXME("Failed to enable/disable device! LastError: %d\n",
1749 Ret
= !dap
->DeviceUsageChanged
;
1751 /* disable the apply button */
1752 PropSheet_UnChanged(GetParent(hwndDlg
),
1754 dap
->DeviceUsageChanged
= FALSE
;
1760 UpdateDevInfo(IN HWND hwndDlg
,
1761 IN PDEVADVPROP_INFO dap
,
1764 HWND hDevUsage
, hPropSheetDlg
, hDevProbBtn
;
1766 ULONG Status
, ProblemNumber
;
1767 SP_DEVINSTALL_PARAMS_W InstallParams
;
1768 UINT TroubleShootStrId
= IDS_TROUBLESHOOTDEV
;
1769 BOOL bFlag
, bDevActionAvailable
= TRUE
;
1770 BOOL bDrvInstalled
= FALSE
;
1772 HDEVINFO DeviceInfoSet
= NULL
;
1773 PSP_DEVINFO_DATA DeviceInfoData
= NULL
;
1774 PROPSHEETHEADER psh
;
1775 DWORD nDriverPages
= 0;
1776 BOOL RecalcPages
= FALSE
;
1778 hPropSheetDlg
= GetParent(hwndDlg
);
1780 if (dap
->PageInitialized
)
1782 /* switch to the General page */
1783 PropSheet_SetCurSelByID(hPropSheetDlg
,
1786 /* remove and destroy the existing device property sheet pages */
1787 if (dap
->DevPropSheets
!= NULL
)
1790 iPage
!= dap
->nDevPropSheets
;
1793 if (dap
->DevPropSheets
[iPage
] != NULL
)
1795 PropSheet_RemovePage(hPropSheetDlg
,
1797 dap
->DevPropSheets
[iPage
]);
1806 if (dap
->FreeDevPropSheets
)
1808 /* don't free the array if it's the one allocated in
1809 DisplayDeviceAdvancedProperties */
1810 HeapFree(GetProcessHeap(),
1812 dap
->DevPropSheets
);
1814 dap
->FreeDevPropSheets
= FALSE
;
1817 dap
->DevPropSheets
= NULL
;
1818 dap
->nDevPropSheets
= 0;
1822 /* create a new device info set and re-open the device */
1823 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1825 SetupDiDestroyDeviceInfoList(dap
->CurrentDeviceInfoSet
);
1828 dap
->ParentDevInst
= 0;
1829 dap
->CurrentDeviceInfoSet
= SetupDiCreateDeviceInfoListEx(NULL
,
1833 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1835 if (SetupDiOpenDeviceInfo(dap
->CurrentDeviceInfoSet
,
1839 &dap
->CurrentDeviceInfoData
))
1841 if (dap
->CloseDevInst
)
1843 SetupDiDestroyDeviceInfoList(dap
->DeviceInfoSet
);
1846 dap
->CloseDevInst
= TRUE
;
1847 dap
->DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1848 dap
->DeviceInfoData
= dap
->CurrentDeviceInfoData
;
1849 dap
->CurrentDeviceInfoSet
= INVALID_HANDLE_VALUE
;
1857 /* get the parent node from the initial devinst */
1858 CM_Get_Parent_Ex(&dap
->ParentDevInst
,
1859 dap
->DeviceInfoData
.DevInst
,
1864 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1866 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1867 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1871 DeviceInfoSet
= dap
->DeviceInfoSet
;
1872 DeviceInfoData
= &dap
->DeviceInfoData
;
1877 DeviceInfoSet
= dap
->DeviceInfoSet
;
1878 DeviceInfoData
= &dap
->DeviceInfoData
;
1881 dap
->HasDriverPage
= FALSE
;
1882 dap
->HasResourcePage
= FALSE
;
1883 dap
->HasPowerPage
= FALSE
;
1884 if (IsDriverInstalled(DeviceInfoData
->DevInst
,
1889 if (SetupDiCallClassInstaller((dap
->ShowRemotePages
?
1890 DIF_ADDREMOTEPROPERTYPAGE_ADVANCED
:
1891 DIF_ADDPROPERTYPAGE_ADVANCED
),
1895 /* get install params */
1896 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
1897 if (!SetupDiGetDeviceInstallParamsW(DeviceInfoSet
,
1901 /* zero the flags */
1902 InstallParams
.Flags
= 0;
1905 dap
->HasDriverPage
= !(InstallParams
.Flags
& DI_DRIVERPAGE_ADDED
);
1906 dap
->HasResourcePage
= !(InstallParams
.Flags
& DI_RESOURCEPAGE_ADDED
);
1907 dap
->HasPowerPage
= !(InstallParams
.Flags
& DI_FLAGSEX_POWERPAGE_ADDED
);
1911 /* get the device icon */
1912 if (dap
->hDevIcon
!= NULL
)
1914 DestroyIcon(dap
->hDevIcon
);
1915 dap
->hDevIcon
= NULL
;
1917 if (!SetupDiLoadClassIcon(&DeviceInfoData
->ClassGuid
,
1921 dap
->hDevIcon
= NULL
;
1924 /* get the device name */
1925 if (GetDeviceDescriptionString(DeviceInfoSet
,
1928 sizeof(dap
->szDevName
) / sizeof(dap
->szDevName
[0])))
1930 PropSheet_SetTitle(hPropSheetDlg
,
1935 /* set the device image */
1936 SendDlgItemMessage(hwndDlg
,
1939 (WPARAM
)dap
->hDevIcon
,
1942 /* set the device name edit control text */
1943 SetDlgItemText(hwndDlg
,
1947 /* set the device type edit control text */
1948 if (GetDeviceTypeString(DeviceInfoData
,
1950 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1952 SetDlgItemText(hwndDlg
,
1957 /* set the device manufacturer edit control text */
1958 if (GetDeviceManufacturerString(DeviceInfoSet
,
1961 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1963 SetDlgItemText(hwndDlg
,
1964 IDC_DEVMANUFACTURER
,
1968 /* set the device location edit control text */
1969 if (GetDeviceLocationString(DeviceInfoSet
,
1973 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1975 SetDlgItemText(hwndDlg
,
1980 /* set the device status edit control text */
1981 if (GetDeviceStatusString(DeviceInfoData
->DevInst
,
1984 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1986 SetDlgItemText(hwndDlg
,
1991 /* set the device troubleshoot button text and disable it if necessary */
1992 hDevProbBtn
= GetDlgItem(hwndDlg
,
1994 cr
= CM_Get_DevNode_Status_Ex(&Status
,
1996 DeviceInfoData
->DevInst
,
1999 if (cr
== CR_SUCCESS
&& (Status
& DN_HAS_PROBLEM
))
2001 switch (ProblemNumber
)
2003 case CM_PROB_DEVLOADER_FAILED
:
2005 /* FIXME - only if it's not a root bus devloader,
2006 disable the button otherwise */
2007 TroubleShootStrId
= IDS_UPDATEDRV
;
2011 case CM_PROB_OUT_OF_MEMORY
:
2012 case CM_PROB_ENTRY_IS_WRONG_TYPE
:
2013 case CM_PROB_LACKED_ARBITRATOR
:
2014 case CM_PROB_FAILED_START
:
2016 case CM_PROB_UNKNOWN_RESOURCE
:
2018 TroubleShootStrId
= IDS_UPDATEDRV
;
2022 case CM_PROB_BOOT_CONFIG_CONFLICT
:
2023 case CM_PROB_NORMAL_CONFLICT
:
2024 case CM_PROB_REENUMERATION
:
2026 /* FIXME - Troubleshoot conflict */
2030 case CM_PROB_FAILED_FILTER
:
2031 case CM_PROB_REINSTALL
:
2032 case CM_PROB_FAILED_INSTALL
:
2034 TroubleShootStrId
= IDS_REINSTALLDRV
;
2038 case CM_PROB_DEVLOADER_NOT_FOUND
:
2041 1) if it's a missing system devloader:
2042 - disable the button (Reinstall Driver)
2043 2) if it's not a system devloader but still missing:
2045 3) if it's not a system devloader but the file can be found:
2047 4) if it's a missing or empty software key
2053 case CM_PROB_INVALID_DATA
:
2054 case CM_PROB_PARTIAL_LOG_CONF
:
2055 case CM_PROB_NO_VALID_LOG_CONF
:
2056 case CM_PROB_HARDWARE_DISABLED
:
2057 case CM_PROB_CANT_SHARE_IRQ
:
2058 case CM_PROB_TRANSLATION_FAILED
:
2059 case CM_PROB_SYSTEM_SHUTDOWN
:
2060 case CM_PROB_PHANTOM
:
2061 bDevActionAvailable
= FALSE
;
2064 case CM_PROB_NOT_VERIFIED
:
2065 case CM_PROB_DEVICE_NOT_THERE
:
2066 /* FIXME - search hardware */
2069 case CM_PROB_NEED_RESTART
:
2070 case CM_PROB_WILL_BE_REMOVED
:
2072 case CM_PROB_TOO_EARLY
:
2073 case CM_PROB_DISABLED_SERVICE
:
2074 TroubleShootStrId
= IDS_REBOOT
;
2077 case CM_PROB_REGISTRY
:
2078 /* FIXME - check registry? */
2081 case CM_PROB_DISABLED
:
2082 /* if device was disabled by the user: */
2083 TroubleShootStrId
= IDS_ENABLEDEV
;
2084 /* FIXME - otherwise disable button because the device was
2085 disabled by the system*/
2088 case CM_PROB_DEVLOADER_NOT_READY
:
2089 /* FIXME - if it's a graphics adapter:
2090 - if it's a a secondary adapter and the main adapter
2100 case CM_PROB_FAILED_ADD
:
2101 TroubleShootStrId
= IDS_PROPERTIES
;
2106 if (LoadString(hDllInstance
,
2109 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])) != 0)
2111 SetWindowText(hDevProbBtn
,
2114 EnableWindow(hDevProbBtn
,
2115 dap
->IsAdmin
&& bDevActionAvailable
);
2117 /* check if the device can be enabled/disabled */
2118 hDevUsage
= GetDlgItem(hwndDlg
,
2121 dap
->CanDisable
= FALSE
;
2122 dap
->DeviceStarted
= FALSE
;
2124 if (CanDisableDevice(DeviceInfoData
->DevInst
,
2128 dap
->CanDisable
= bFlag
;
2131 if (IsDeviceStarted(DeviceInfoData
->DevInst
,
2135 dap
->DeviceStarted
= bFlag
;
2138 /* enable/disable the device usage controls */
2139 EnableWindow(GetDlgItem(hwndDlg
,
2141 dap
->CanDisable
&& dap
->IsAdmin
);
2142 EnableWindow(hDevUsage
,
2143 dap
->CanDisable
&& dap
->IsAdmin
);
2145 /* clear the combobox */
2146 SendMessage(hDevUsage
,
2150 if (dap
->CanDisable
)
2152 InitDevUsageActions(hwndDlg
,
2157 /* find out how many new device property sheets to add.
2158 fake a PROPSHEETHEADER structure, we don't plan to
2159 call PropertySheet again!*/
2160 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
2164 /* get the number of device property sheets for the device */
2165 if (!SetupDiGetClassDevPropertySheets(DeviceInfoSet
,
2170 dap
->PropertySheetType
) &&
2171 nDriverPages
!= 0 && GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
2173 dap
->nDevPropSheets
+= nDriverPages
;
2180 /* include the driver page */
2181 if (dap
->HasDriverPage
)
2182 dap
->nDevPropSheets
++;
2184 /* include the details page */
2186 dap
->nDevPropSheets
++;
2188 if (dap
->HasResourcePage
)
2189 dap
->nDevPropSheets
++;
2191 /* add the device property sheets */
2192 if (dap
->nDevPropSheets
!= 0)
2194 dap
->DevPropSheets
= (HPROPSHEETPAGE
*)HeapAlloc(GetProcessHeap(),
2196 dap
->nDevPropSheets
* sizeof(HPROPSHEETPAGE
));
2197 if (dap
->DevPropSheets
!= NULL
)
2199 if (nDriverPages
!= 0)
2201 psh
.phpage
= dap
->DevPropSheets
;
2203 /* query the device property sheet pages to add */
2204 if (SetupDiGetClassDevPropertySheets(DeviceInfoSet
,
2207 dap
->nDevPropSheets
,
2209 dap
->PropertySheetType
))
2211 /* add the property sheets */
2213 iPage
< nDriverPages
;
2216 if (PropSheet_AddPage(hPropSheetDlg
,
2217 dap
->DevPropSheets
[iPage
]))
2223 dap
->FreeDevPropSheets
= TRUE
;
2227 /* cleanup, we were unable to get the device property sheets */
2228 iPage
= nDriverPages
;
2229 dap
->nDevPropSheets
-= nDriverPages
;
2236 /* add the driver page if necessary */
2237 if (dap
->HasDriverPage
)
2239 PROPSHEETPAGE pspDriver
= {0};
2240 pspDriver
.dwSize
= sizeof(PROPSHEETPAGE
);
2241 pspDriver
.dwFlags
= PSP_DEFAULT
;
2242 pspDriver
.hInstance
= hDllInstance
;
2243 pspDriver
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICEDRIVER
);
2244 pspDriver
.pfnDlgProc
= AdvProcDriverDlgProc
;
2245 pspDriver
.lParam
= (LPARAM
)dap
;
2246 dap
->DevPropSheets
[iPage
] = dap
->pCreatePropertySheetPageW(&pspDriver
);
2247 if (dap
->DevPropSheets
[iPage
] != NULL
)
2249 if (PropSheet_AddPage(hPropSheetDlg
,
2250 dap
->DevPropSheets
[iPage
]))
2257 dap
->pDestroyPropertySheetPage(dap
->DevPropSheets
[iPage
]);
2258 dap
->DevPropSheets
[iPage
] = NULL
;
2265 /* Add the details page */
2266 PROPSHEETPAGE pspDetails
= {0};
2267 pspDetails
.dwSize
= sizeof(PROPSHEETPAGE
);
2268 pspDetails
.dwFlags
= PSP_DEFAULT
;
2269 pspDetails
.hInstance
= hDllInstance
;
2270 pspDetails
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICEDETAILS
);
2271 pspDetails
.pfnDlgProc
= AdvProcDetailsDlgProc
;
2272 pspDetails
.lParam
= (LPARAM
)dap
;
2273 dap
->DevPropSheets
[iPage
] = dap
->pCreatePropertySheetPageW(&pspDetails
);
2274 if (dap
->DevPropSheets
[iPage
] != NULL
)
2276 if (PropSheet_AddPage(hPropSheetDlg
,
2277 dap
->DevPropSheets
[iPage
]))
2284 dap
->pDestroyPropertySheetPage(dap
->DevPropSheets
[iPage
]);
2285 dap
->DevPropSheets
[iPage
] = NULL
;
2290 if (dap
->HasResourcePage
)
2292 PROPSHEETPAGE pspDriver
= {0};
2293 pspDriver
.dwSize
= sizeof(PROPSHEETPAGE
);
2294 pspDriver
.dwFlags
= PSP_DEFAULT
;
2295 pspDriver
.hInstance
= hDllInstance
;
2296 pspDriver
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICERESOURCES
);
2297 pspDriver
.pfnDlgProc
= ResourcesProcDriverDlgProc
;
2298 pspDriver
.lParam
= (LPARAM
)dap
;
2299 dap
->DevPropSheets
[iPage
] = dap
->pCreatePropertySheetPageW(&pspDriver
);
2300 if (dap
->DevPropSheets
[iPage
] != NULL
)
2302 if (PropSheet_AddPage(hPropSheetDlg
,
2303 dap
->DevPropSheets
[iPage
]))
2310 dap
->pDestroyPropertySheetPage(dap
->DevPropSheets
[iPage
]);
2311 dap
->DevPropSheets
[iPage
] = NULL
;
2315 /* FIXME: Add the power page */
2318 dap
->nDevPropSheets
= 0;
2323 PropSheet_RecalcPageSizes(hPropSheetDlg
);
2326 /* finally, disable the apply button */
2327 PropSheet_UnChanged(hPropSheetDlg
,
2329 dap
->DeviceUsageChanged
= FALSE
;
2335 DlgParentSubWndProc(IN HWND hwnd
,
2340 PDEVADVPROP_INFO dap
;
2342 dap
= (PDEVADVPROP_INFO
)GetProp(hwnd
,
2343 L
"DevMgrDevChangeSub");
2346 if (uMsg
== WM_DEVICECHANGE
&& !IsWindowVisible(dap
->hWndGeneralPage
))
2348 SendMessage(dap
->hWndGeneralPage
,
2354 /* pass the message the the old window proc */
2355 return CallWindowProc(dap
->ParentOldWndProc
,
2363 /* this is not a good idea if the subclassed window was an ansi
2364 window, but we failed finding out the previous window proc
2365 so we can't use CallWindowProc. This should rarely - if ever -
2368 return DefWindowProc(hwnd
,
2378 AdvPropGeneralDlgProc(IN HWND hwndDlg
,
2383 PDEVADVPROP_INFO dap
;
2384 INT_PTR Ret
= FALSE
;
2386 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
,
2389 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
2395 switch (LOWORD(wParam
))
2399 if (HIWORD(wParam
) == CBN_SELCHANGE
)
2401 PropSheet_Changed(GetParent(hwndDlg
),
2403 dap
->DeviceUsageChanged
= TRUE
;
2408 case IDC_DEVPROBLEM
:
2412 /* display the device problem wizard */
2413 ShowDeviceProblemWizard(hwndDlg
,
2415 &dap
->DeviceInfoData
,
2426 NMHDR
*hdr
= (NMHDR
*)lParam
;
2430 ApplyGeneralSettings(hwndDlg
,
2439 dap
= (PDEVADVPROP_INFO
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
2444 dap
->hWndGeneralPage
= hwndDlg
;
2446 SetWindowLongPtr(hwndDlg
,
2450 /* subclass the parent window to always receive
2451 WM_DEVICECHANGE messages */
2452 hWndParent
= GetParent(hwndDlg
);
2453 if (hWndParent
!= NULL
)
2455 /* subclass the parent window. This is not safe
2456 if the parent window belongs to another thread! */
2457 dap
->ParentOldWndProc
= (WNDPROC
)SetWindowLongPtr(hWndParent
,
2459 (LONG_PTR
)DlgParentSubWndProc
);
2461 if (dap
->ParentOldWndProc
!= NULL
&&
2463 L
"DevMgrDevChangeSub",
2466 dap
->hWndParent
= hWndParent
;
2470 /* do not call UpdateDevInfo directly in here because it modifies
2471 the pages of the property sheet! */
2472 PostMessage(hwndDlg
,
2481 case WM_DEVICECHANGE
:
2483 /* FIXME - don't call UpdateDevInfo for all events */
2484 UpdateDevInfo(hwndDlg
,
2493 UpdateDevInfo(hwndDlg
,
2496 dap
->PageInitialized
= TRUE
;
2502 /* restore the old window proc of the subclassed parent window */
2503 if (dap
->hWndParent
!= NULL
&& dap
->ParentOldWndProc
!= NULL
)
2505 if (SetWindowLongPtr(dap
->hWndParent
,
2507 (LONG_PTR
)dap
->ParentOldWndProc
) == (LONG_PTR
)DlgParentSubWndProc
)
2509 RemoveProp(dap
->hWndParent
,
2510 L
"DevMgrDevChangeSub");
2523 DisplayDeviceAdvancedProperties(IN HWND hWndParent
,
2524 IN LPCWSTR lpDeviceID OPTIONAL
,
2525 IN HDEVINFO DeviceInfoSet
,
2526 IN PSP_DEVINFO_DATA DeviceInfoData
,
2527 IN HINSTANCE hComCtl32
,
2528 IN LPCWSTR lpMachineName
,
2531 PROPSHEETHEADER psh
= {0};
2532 PROPSHEETPAGE pspGeneral
= {0};
2533 PPROPERTYSHEETW pPropertySheetW
;
2534 PCREATEPROPERTYSHEETPAGEW pCreatePropertySheetPageW
;
2535 PDESTROYPROPERTYSHEETPAGE pDestroyPropertySheetPage
;
2536 PDEVADVPROP_INFO DevAdvPropInfo
;
2537 HMACHINE hMachine
= NULL
;
2538 DWORD DevIdSize
= 0;
2541 /* we don't want to statically link against comctl32, so find the
2542 functions we need dynamically */
2544 (PPROPERTYSHEETW
)GetProcAddress(hComCtl32
,
2546 pCreatePropertySheetPageW
=
2547 (PCREATEPROPERTYSHEETPAGEW
)GetProcAddress(hComCtl32
,
2548 "CreatePropertySheetPageW");
2549 pDestroyPropertySheetPage
=
2550 (PDESTROYPROPERTYSHEETPAGE
)GetProcAddress(hComCtl32
,
2551 "DestroyPropertySheetPage");
2552 if (pPropertySheetW
== NULL
||
2553 pCreatePropertySheetPageW
== NULL
||
2554 pDestroyPropertySheetPage
== NULL
)
2559 if (lpDeviceID
== NULL
)
2561 /* find out how much size is needed for the device id */
2562 if (SetupDiGetDeviceInstanceId(DeviceInfoSet
,
2568 ERR("SetupDiGetDeviceInstanceId unexpectedly returned TRUE!\n");
2572 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
2579 DevIdSize
= (DWORD
)wcslen(lpDeviceID
) + 1;
2582 if (lpMachineName
!= NULL
&& lpMachineName
[0] != L
'\0')
2584 CONFIGRET cr
= CM_Connect_Machine(lpMachineName
,
2586 if (cr
!= CR_SUCCESS
)
2592 /* create the internal structure associated with the "General",
2593 "Driver", ... pages */
2594 DevAdvPropInfo
= (PDEVADVPROP_INFO
)HeapAlloc(GetProcessHeap(),
2596 FIELD_OFFSET(DEVADVPROP_INFO
,
2598 (DevIdSize
* sizeof(WCHAR
)));
2599 if (DevAdvPropInfo
== NULL
)
2601 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2605 if (lpDeviceID
== NULL
)
2607 /* read the device instance id */
2608 if (!SetupDiGetDeviceInstanceId(DeviceInfoSet
,
2610 DevAdvPropInfo
->szDeviceID
,
2619 /* copy the device instance id supplied by the caller */
2620 wcscpy(DevAdvPropInfo
->szDeviceID
,
2624 DevAdvPropInfo
->DeviceInfoSet
= DeviceInfoSet
;
2625 DevAdvPropInfo
->DeviceInfoData
= *DeviceInfoData
;
2626 DevAdvPropInfo
->CurrentDeviceInfoSet
= INVALID_HANDLE_VALUE
;
2627 DevAdvPropInfo
->CurrentDeviceInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
2629 DevAdvPropInfo
->ShowRemotePages
= (lpMachineName
!= NULL
&& lpMachineName
[0] != L
'\0');
2630 DevAdvPropInfo
->hMachine
= hMachine
;
2631 DevAdvPropInfo
->lpMachineName
= lpMachineName
;
2632 DevAdvPropInfo
->szDevName
[0] = L
'\0';
2633 DevAdvPropInfo
->hComCtl32
= hComCtl32
;
2634 DevAdvPropInfo
->pCreatePropertySheetPageW
= pCreatePropertySheetPageW
;
2635 DevAdvPropInfo
->pDestroyPropertySheetPage
= pDestroyPropertySheetPage
;
2637 DevAdvPropInfo
->IsAdmin
= TRUE
;// IsUserAdmin();
2638 DevAdvPropInfo
->DoDefaultDevAction
= ((dwFlags
& DPF_DEVICE_STATUS_ACTION
) != 0);
2639 DevAdvPropInfo
->Extended
= ((dwFlags
& DPF_EXTENDED
) != 0);
2641 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
2642 psh
.dwFlags
= PSH_PROPTITLE
| PSH_NOAPPLYNOW
;
2643 psh
.hwndParent
= hWndParent
;
2644 psh
.pszCaption
= DevAdvPropInfo
->szDevName
;
2646 DevAdvPropInfo
->PropertySheetType
= DevAdvPropInfo
->ShowRemotePages
?
2647 DIGCDP_FLAG_REMOTE_ADVANCED
:
2648 DIGCDP_FLAG_ADVANCED
;
2650 psh
.phpage
= (HPROPSHEETPAGE
*)HeapAlloc(GetProcessHeap(),
2652 1 * sizeof(HPROPSHEETPAGE
));
2653 if (psh
.phpage
== NULL
)
2658 /* add the "General" property sheet */
2659 pspGeneral
.dwSize
= sizeof(PROPSHEETPAGE
);
2660 pspGeneral
.dwFlags
= PSP_DEFAULT
;
2661 pspGeneral
.hInstance
= hDllInstance
;
2662 pspGeneral
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICEGENERAL
);
2663 pspGeneral
.pfnDlgProc
= AdvPropGeneralDlgProc
;
2664 pspGeneral
.lParam
= (LPARAM
)DevAdvPropInfo
;
2665 psh
.phpage
[psh
.nPages
] = pCreatePropertySheetPageW(&pspGeneral
);
2666 if (psh
.phpage
[psh
.nPages
] != NULL
)
2671 DevAdvPropInfo
->nDevPropSheets
= psh
.nPages
;
2673 if (psh
.nPages
!= 0)
2675 Ret
= pPropertySheetW(&psh
);
2677 /* NOTE: no need to destroy the property sheets anymore! */
2684 /* in case of failure the property sheets must be destroyed */
2685 if (psh
.phpage
!= NULL
)
2691 if (psh
.phpage
[i
] != NULL
)
2693 pDestroyPropertySheetPage(psh
.phpage
[i
]);
2699 if (DevAdvPropInfo
!= NULL
)
2701 if (DevAdvPropInfo
->FreeDevPropSheets
)
2703 /* don't free the array if it's the one allocated in
2704 DisplayDeviceAdvancedProperties */
2705 HeapFree(GetProcessHeap(),
2707 DevAdvPropInfo
->DevPropSheets
);
2710 if (DevAdvPropInfo
->CloseDevInst
)
2712 /* close the device info set in case a new one was created */
2713 SetupDiDestroyDeviceInfoList(DevAdvPropInfo
->DeviceInfoSet
);
2716 if (DevAdvPropInfo
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
2718 SetupDiDestroyDeviceInfoList(DevAdvPropInfo
->CurrentDeviceInfoSet
);
2721 if (DevAdvPropInfo
->hDevIcon
!= NULL
)
2723 DestroyIcon(DevAdvPropInfo
->hDevIcon
);
2726 HeapFree(GetProcessHeap(),
2731 if (psh
.phpage
!= NULL
)
2733 HeapFree(GetProcessHeap(),
2738 if (hMachine
!= NULL
)
2740 CM_Disconnect_Machine(hMachine
);