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"
36 #define PDCAP_D0_SUPPORTED 0x00000001
37 #define PDCAP_D1_SUPPORTED 0x00000002
38 #define PDCAP_D2_SUPPORTED 0x00000004
39 #define PDCAP_D3_SUPPORTED 0x00000008
40 #define PDCAP_WAKE_FROM_D0_SUPPORTED 0x00000010
41 #define PDCAP_WAKE_FROM_D1_SUPPORTED 0x00000020
42 #define PDCAP_WAKE_FROM_D2_SUPPORTED 0x00000040
43 #define PDCAP_WAKE_FROM_D3_SUPPORTED 0x00000080
44 #define PDCAP_WARM_EJECT_SUPPORTED 0x00000100
46 typedef struct CM_Power_Data_s
49 DEVICE_POWER_STATE PD_MostRecentPowerState
;
50 ULONG PD_Capabilities
;
54 DEVICE_POWER_STATE PD_PowerStateMapping
[PowerSystemMaximum
];
55 SYSTEM_POWER_STATE PD_DeepestSystemWake
;
56 } CM_POWER_DATA
, *PCM_POWER_DATA
;
60 EnumDeviceDriverFilesCallback(IN PVOID Context
,
66 PENUMDRIVERFILES_CONTEXT EnumDriverFilesContext
= (PENUMDRIVERFILES_CONTEXT
)Context
;
68 li
.mask
= LVIF_TEXT
| LVIF_STATE
;
69 li
.iItem
= EnumDriverFilesContext
->nCount
++;
71 li
.state
= (li
.iItem
== 0 ? LVIS_SELECTED
: 0);
72 li
.stateMask
= LVIS_SELECTED
;
73 li
.pszText
= (LPWSTR
)Param1
;
74 (void)ListView_InsertItem(EnumDriverFilesContext
->hDriversListView
,
81 UpdateDriverDetailsDlg(IN HWND hwndDlg
,
82 IN HWND hDriversListView
,
83 IN PDEVADVPROP_INFO dap
)
85 HDEVINFO DeviceInfoSet
;
86 PSP_DEVINFO_DATA DeviceInfoData
;
87 SP_DRVINFO_DATA DriverInfoData
;
88 ENUMDRIVERFILES_CONTEXT EnumDriverFilesContext
;
90 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
92 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
93 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
97 DeviceInfoSet
= dap
->DeviceInfoSet
;
98 DeviceInfoData
= &dap
->DeviceInfoData
;
101 /* set the device image */
102 SendDlgItemMessage(hwndDlg
,
105 (WPARAM
)dap
->hDevIcon
,
108 /* set the device name edit control text */
109 SetDlgItemText(hwndDlg
,
113 /* fill the driver files list view */
114 EnumDriverFilesContext
.hDriversListView
= hDriversListView
;
115 EnumDriverFilesContext
.nCount
= 0;
117 (void)ListView_DeleteAllItems(EnumDriverFilesContext
.hDriversListView
);
118 DriverInfoData
.cbSize
= sizeof(SP_DRVINFO_DATA
);
119 if (FindCurrentDriver(DeviceInfoSet
,
122 SetupDiSetSelectedDriver(DeviceInfoSet
,
126 HSPFILEQ queueHandle
;
128 queueHandle
= SetupOpenFileQueue();
129 if (queueHandle
!= (HSPFILEQ
)INVALID_HANDLE_VALUE
)
131 SP_DEVINSTALL_PARAMS DeviceInstallParams
= {0};
132 DeviceInstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS
);
133 if (SetupDiGetDeviceInstallParams(DeviceInfoSet
,
135 &DeviceInstallParams
))
137 DeviceInstallParams
.FileQueue
= queueHandle
;
138 DeviceInstallParams
.Flags
|= DI_NOVCP
;
140 if (SetupDiSetDeviceInstallParams(DeviceInfoSet
,
142 &DeviceInstallParams
) &&
143 SetupDiCallClassInstaller(DIF_INSTALLDEVICEFILES
,
151 /* enumerate the driver files */
152 SetupScanFileQueue(queueHandle
,
153 SPQ_SCAN_USE_CALLBACK
,
155 EnumDeviceDriverFilesCallback
,
156 &EnumDriverFilesContext
,
159 /* update the list view column width */
160 GetClientRect(hDriversListView
,
162 lvc
.mask
= LVCF_WIDTH
;
163 lvc
.cx
= rcClient
.right
;
164 (void)ListView_SetColumn(hDriversListView
,
168 /* highlight the first item from list */
169 if (ListView_GetSelectedCount(hDriversListView
) != 0)
171 ListView_SetItemState(hDriversListView
,
173 LVIS_FOCUSED
| LVIS_SELECTED
,
174 LVIS_FOCUSED
| LVIS_SELECTED
);
179 SetupCloseFileQueue(queueHandle
);
186 UpdateDriverVersionInfoDetails(IN HWND hwndDlg
,
187 IN LPCWSTR lpszDriverPath
)
191 LPVOID lpData
= NULL
;
195 WCHAR szLangInfo
[255];
196 WCHAR szLangPath
[MAX_PATH
];
197 LPWSTR lpCompanyName
= NULL
;
198 LPWSTR lpFileVersion
= NULL
;
199 LPWSTR lpLegalCopyright
= NULL
;
200 LPWSTR lpDigitalSigner
= NULL
;
202 WCHAR szNotAvailable
[255];
204 /* extract version info from selected file */
205 dwVerInfoSize
= GetFileVersionInfoSize(lpszDriverPath
,
210 lpData
= HeapAlloc(GetProcessHeap(),
216 if (!GetFileVersionInfo(lpszDriverPath
,
222 if (!VerQueryValue(lpData
,
223 L
"\\VarFileInfo\\Translation",
228 dwLangId
= *(LPDWORD
)lpInfo
;
229 swprintf(szLangInfo
, L
"\\StringFileInfo\\%04x%04x\\",
230 LOWORD(dwLangId
), HIWORD(dwLangId
));
232 /* read CompanyName */
233 wcscpy(szLangPath
, szLangInfo
);
234 wcscat(szLangPath
, L
"CompanyName");
236 VerQueryValue(lpData
,
238 (void **)&lpCompanyName
,
241 /* read FileVersion */
242 wcscpy(szLangPath
, szLangInfo
);
243 wcscat(szLangPath
, L
"FileVersion");
245 VerQueryValue(lpData
,
247 (void **)&lpFileVersion
,
250 /* read LegalTrademarks */
251 wcscpy(szLangPath
, szLangInfo
);
252 wcscat(szLangPath
, L
"LegalCopyright");
254 VerQueryValue(lpData
,
256 (void **)&lpLegalCopyright
,
259 /* TODO: read digital signer info */
262 if (!LoadString(hDllInstance
,
265 sizeof(szNotAvailable
) / sizeof(WCHAR
)))
267 wcscpy(szNotAvailable
, L
"n/a");
272 lpCompanyName
= szNotAvailable
;
273 SetDlgItemText(hwndDlg
,
278 lpFileVersion
= szNotAvailable
;
279 SetDlgItemText(hwndDlg
,
283 if (!lpLegalCopyright
)
284 lpLegalCopyright
= szNotAvailable
;
285 SetDlgItemText(hwndDlg
,
289 if (!lpDigitalSigner
)
290 lpDigitalSigner
= szNotAvailable
;
291 SetDlgItemText(hwndDlg
,
295 /* release version info */
297 HeapFree(GetProcessHeap(),
305 DriverDetailsDlgProc(IN HWND hwndDlg
,
310 PDEVADVPROP_INFO dap
;
313 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
,
316 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
322 switch (LOWORD(wParam
))
345 HWND hDriversListView
;
348 dap
= (PDEVADVPROP_INFO
)lParam
;
351 SetWindowLongPtr(hwndDlg
,
355 hDriversListView
= GetDlgItem(hwndDlg
,
358 /* add a column to the list view control */
359 lvc
.mask
= LVCF_FMT
| LVCF_WIDTH
;
360 lvc
.fmt
= LVCFMT_LEFT
;
362 (void)ListView_InsertColumn(hDriversListView
,
366 UpdateDriverDetailsDlg(hwndDlg
,
370 if (ListView_GetItemCount(hDriversListView
) == 0)
372 if (LoadStringW(hDllInstance
, IDS_NODRIVERS
, szBuffer
, _countof(szBuffer
)))
373 MessageBoxW(hwndDlg
, szBuffer
, dap
->szDevName
, MB_OK
);
374 EndDialog(hwndDlg
, IDCANCEL
);
384 LPNMHDR pnmhdr
= (LPNMHDR
)lParam
;
386 switch (pnmhdr
->code
)
388 case LVN_ITEMCHANGED
:
390 LPNMLISTVIEW pnmv
= (LPNMLISTVIEW
)lParam
;
391 HWND hDriversListView
= GetDlgItem(hwndDlg
,
394 if (ListView_GetSelectedCount(hDriversListView
) == 0)
396 /* nothing is selected - empty the labels */
397 SetDlgItemText(hwndDlg
,
400 SetDlgItemText(hwndDlg
,
403 SetDlgItemText(hwndDlg
,
406 SetDlgItemText(hwndDlg
,
410 else if (pnmv
->uNewState
!= 0)
412 /* extract version info and update the labels */
413 WCHAR szDriverPath
[MAX_PATH
];
415 ListView_GetItemText(hDriversListView
,
421 UpdateDriverVersionInfoDetails(hwndDlg
,
439 IN PDEVADVPROP_INFO dap
)
441 TOKEN_PRIVILEGES Privileges
;
444 BOOL NeedReboot
= FALSE
;
446 // Better use InstallDevInst:
451 // LPWSTR wszDeviceId,
454 // See: http://comp.os.ms-windows.programmer.win32.narkive.com/J8FTd4KK/signature-of-undocumented-installdevinstex
456 if (!InstallDevInst(hwndDlg
, dap
->szDeviceID
, TRUE
, &dwReboot
))
459 if (NeedReboot
== FALSE
)
462 //FIXME: load text from resource file
463 if (MessageBoxW(hwndDlg
, L
"Reboot now?", L
"Reboot required", MB_YESNO
| MB_ICONQUESTION
) != IDYES
)
466 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
468 ERR("OpenProcessToken failed\n");
472 /* Get the LUID for the Shutdown privilege */
473 if (!LookupPrivilegeValueW(NULL
, SE_SHUTDOWN_NAME
, &Privileges
.Privileges
[0].Luid
))
475 ERR("LookupPrivilegeValue failed\n");
480 /* Assign the Shutdown privilege to our process */
481 Privileges
.PrivilegeCount
= 1;
482 Privileges
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
484 if (!AdjustTokenPrivileges(hToken
, FALSE
, &Privileges
, 0, NULL
, NULL
))
486 ERR("AdjustTokenPrivileges failed\n");
491 /* Finally shut down the system */
492 if (!ExitWindowsEx(EWX_REBOOT
, SHTDN_REASON_MAJOR_OTHER
| SHTDN_REASON_MINOR_OTHER
| SHTDN_REASON_FLAG_PLANNED
))
494 ERR("ExitWindowsEx failed\n");
501 UpdateDriverDlg(IN HWND hwndDlg
,
502 IN PDEVADVPROP_INFO dap
)
504 HDEVINFO DeviceInfoSet
;
505 PSP_DEVINFO_DATA DeviceInfoData
;
507 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
509 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
510 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
514 DeviceInfoSet
= dap
->DeviceInfoSet
;
515 DeviceInfoData
= &dap
->DeviceInfoData
;
518 /* set the device image */
519 SendDlgItemMessage(hwndDlg
,
522 (WPARAM
)dap
->hDevIcon
,
525 /* set the device name edit control text */
526 SetDlgItemText(hwndDlg
,
530 /* query the driver provider */
531 if (GetDriverProviderString(DeviceInfoSet
,
534 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
536 SetDlgItemText(hwndDlg
,
541 /* query the driver date */
542 if (GetDriverDateString(DeviceInfoSet
,
545 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
547 SetDlgItemText(hwndDlg
,
552 /* query the driver version */
553 if (GetDriverVersionString(DeviceInfoSet
,
556 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
558 SetDlgItemText(hwndDlg
,
567 AdvProcDriverDlgProc(IN HWND hwndDlg
,
572 PDEVADVPROP_INFO dap
;
575 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
,
578 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
584 switch (LOWORD(wParam
))
586 case IDC_DRIVERDETAILS
:
587 DialogBoxParam(hDllInstance
,
588 MAKEINTRESOURCE(IDD_DRIVERDETAILS
),
590 DriverDetailsDlgProc
,
594 case IDC_UPDATEDRIVER
:
595 UpdateDriver(hwndDlg
, dap
);
603 NMHDR
*hdr
= (NMHDR
*)lParam
;
614 dap
= (PDEVADVPROP_INFO
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
617 SetWindowLongPtr(hwndDlg
,
621 UpdateDriverDlg(hwndDlg
,
635 SetListViewText(HWND hwnd
,
641 li
.mask
= LVIF_TEXT
| LVIF_STATE
;
644 li
.state
= 0; //(li.iItem == 0 ? LVIS_SELECTED : 0);
645 li
.stateMask
= LVIS_SELECTED
;
646 li
.pszText
= (LPWSTR
)lpText
;
647 (void)ListView_InsertItem(hwnd
,
653 UpdateDetailsDlg(IN HWND hwndDlg
,
654 IN PDEVADVPROP_INFO dap
)
665 IDS_PROP_HARDWAREIDS
,
666 IDS_PROP_COMPATIBLEIDS
,
667 IDS_PROP_MATCHINGDEVICEID
,
670 IDS_PROP_CAPABILITIES
,
671 IDS_PROP_DEVNODEFLAGS
,
672 IDS_PROP_CONFIGFLAGS
,
673 IDS_PROP_CSCONFIGFLAGS
,
674 IDS_PROP_EJECTIONRELATIONS
,
675 IDS_PROP_REMOVALRELATIONS
,
676 IDS_PROP_BUSRELATIONS
,
677 IDS_PROP_DEVUPPERFILTERS
,
678 IDS_PROP_DEVLOWERFILTERS
,
679 IDS_PROP_CLASSUPPERFILTERS
,
680 IDS_PROP_CLASSLOWERFILTERS
,
681 IDS_PROP_CLASSINSTALLER
,
682 IDS_PROP_CLASSCOINSTALLER
,
683 IDS_PROP_DEVICECOINSTALLER
,
684 IDS_PROP_FIRMWAREREVISION
,
685 IDS_PROP_CURRENTPOWERSTATE
,
686 IDS_PROP_POWERCAPABILITIES
,
687 IDS_PROP_POWERSTATEMAPPINGS
691 /* set the device image */
692 SendDlgItemMessage(hwndDlg
,
695 (WPARAM
)dap
->hDevIcon
,
698 /* set the device name edit control text */
699 SetDlgItemText(hwndDlg
,
704 hwndComboBox
= GetDlgItem(hwndDlg
,
705 IDC_DETAILSPROPNAME
);
707 hwndListView
= GetDlgItem(hwndDlg
,
708 IDC_DETAILSPROPVALUE
);
710 for (i
= 0; i
!= sizeof(Properties
) / sizeof(Properties
[0]); i
++)
712 /* fill in the device usage combo box */
713 if (LoadString(hDllInstance
,
716 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
718 SendMessage(hwndComboBox
,
721 (LPARAM
)dap
->szTemp
);
726 GetClientRect(hwndListView
,
729 /* add a column to the list view control */
730 lvc
.mask
= LVCF_FMT
| LVCF_WIDTH
;
731 lvc
.fmt
= LVCFMT_LEFT
;
732 lvc
.cx
= rcClient
.right
;
733 (void)ListView_InsertColumn(hwndListView
,
737 SendMessage(hwndComboBox
,
742 SetListViewText(hwndListView
, 0, dap
->szDeviceID
);
744 SetFocus(hwndComboBox
);
749 DisplayDevicePropertyText(IN PDEVADVPROP_INFO dap
,
750 IN HWND hwndListView
,
753 HDEVINFO DeviceInfoSet
;
754 PSP_DEVINFO_DATA DeviceInfoData
;
763 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
765 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
766 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
770 DeviceInfoSet
= dap
->DeviceInfoSet
;
771 DeviceInfoData
= &dap
->DeviceInfoData
;
775 SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
784 if (GetLastError() != ERROR_FILE_NOT_FOUND
)
786 swprintf(dap
->szTemp
, L
"Error: Getting the size failed! (Error: %ld)", GetLastError());
787 SetListViewText(hwndListView
, 0, dap
->szTemp
);
792 if (dwType
== REG_SZ
)
793 dwSize
+= sizeof(WCHAR
);
795 lpBuffer
= (LPBYTE
)HeapAlloc(GetProcessHeap(),
798 if (lpBuffer
== NULL
)
800 SetListViewText(hwndListView
, 0, L
"Error: Allocating the buffer failed!");
804 if (SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
812 if (dwType
== REG_SZ
)
814 SetListViewText(hwndListView
, 0, (LPWSTR
)lpBuffer
);
816 else if (dwType
== REG_MULTI_SZ
)
818 lpStr
= (LPWSTR
)lpBuffer
;
822 len
= wcslen(lpStr
) + 1;
824 SetListViewText(hwndListView
, index
, lpStr
);
830 else if (dwType
== REG_DWORD
)
832 dwValue
= *(DWORD
*) lpBuffer
;
836 case SPDRP_CAPABILITIES
:
838 if (dwValue
& CM_DEVCAP_LOCKSUPPORTED
)
839 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_LOCKSUPPORTED");
840 if (dwValue
& CM_DEVCAP_EJECTSUPPORTED
)
841 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_EJECTSUPPORTED");
842 if (dwValue
& CM_DEVCAP_REMOVABLE
)
843 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_REMOVABLE");
844 if (dwValue
& CM_DEVCAP_DOCKDEVICE
)
845 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_DOCKDEVICE");
846 if (dwValue
& CM_DEVCAP_UNIQUEID
)
847 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_UNIQUEID");
848 if (dwValue
& CM_DEVCAP_SILENTINSTALL
)
849 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_SILENTINSTALL");
850 if (dwValue
& CM_DEVCAP_RAWDEVICEOK
)
851 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_RAWDEVICEOK");
852 if (dwValue
& CM_DEVCAP_SURPRISEREMOVALOK
)
853 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_SURPRISEREMOVALOK");
854 if (dwValue
& CM_DEVCAP_HARDWAREDISABLED
)
855 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_HARDWAREDISABLED");
856 if (dwValue
& CM_DEVCAP_NONDYNAMIC
)
857 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_NONDYNAMIC");
860 case SPDRP_CONFIGFLAGS
:
862 if (dwValue
& CONFIGFLAG_DISABLED
)
863 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_DISABLED");
864 if (dwValue
& CONFIGFLAG_REMOVED
)
865 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_REMOVED");
866 if (dwValue
& CONFIGFLAG_MANUAL_INSTALL
)
867 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_MANUAL_INSTALL");
868 if (dwValue
& CONFIGFLAG_IGNORE_BOOT_LC
)
869 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_IGNORE_BOOT_LC");
870 if (dwValue
& CONFIGFLAG_NET_BOOT
)
871 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_NET_BOOT");
872 if (dwValue
& CONFIGFLAG_REINSTALL
)
873 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_REINSTALL");
874 if (dwValue
& CONFIGFLAG_FAILEDINSTALL
)
875 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_FAILEDINSTALL");
876 if (dwValue
& CONFIGFLAG_CANTSTOPACHILD
)
877 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_CANTSTOPACHILD");
878 if (dwValue
& CONFIGFLAG_OKREMOVEROM
)
879 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_OKREMOVEROM");
880 if (dwValue
& CONFIGFLAG_NOREMOVEEXIT
)
881 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_NOREMOVEEXIT");
885 swprintf(dap
->szTemp
, L
"0x%08lx", dwValue
);
886 SetListViewText(hwndListView
, 0, dap
->szTemp
);
892 SetListViewText(hwndListView
, 0, L
"Error: Unsupported value type!");
898 SetListViewText(hwndListView
, 0, L
"Error: Retrieving the value failed!");
901 HeapFree(GetProcessHeap(),
907 DisplayDevNodeFlags(IN PDEVADVPROP_INFO dap
,
908 IN HWND hwndListView
)
914 CM_Get_DevNode_Status_Ex(&dwStatus
,
916 dap
->DeviceInfoData
.DevInst
,
921 if (dwStatus
& DN_ROOT_ENUMERATED
)
922 SetListViewText(hwndListView
, index
++, L
"DN_ROOT_ENUMERATED");
923 if (dwStatus
& DN_DRIVER_LOADED
)
924 SetListViewText(hwndListView
, index
++, L
"DN_DRIVER_LOADED");
925 if (dwStatus
& DN_ENUM_LOADED
)
926 SetListViewText(hwndListView
, index
++, L
"DN_ENUM_LOADED");
927 if (dwStatus
& DN_STARTED
)
928 SetListViewText(hwndListView
, index
++, L
"DN_STARTED");
929 if (dwStatus
& DN_MANUAL
)
930 SetListViewText(hwndListView
, index
++, L
"DN_MANUAL");
931 if (dwStatus
& DN_NEED_TO_ENUM
)
932 SetListViewText(hwndListView
, index
++, L
"DN_NEED_TO_ENUM");
933 if (dwStatus
& DN_DRIVER_BLOCKED
)
934 SetListViewText(hwndListView
, index
++, L
"DN_DRIVER_BLOCKED");
935 if (dwStatus
& DN_HARDWARE_ENUM
)
936 SetListViewText(hwndListView
, index
++, L
"DN_HARDWARE_ENUM");
937 if (dwStatus
& DN_NEED_RESTART
)
938 SetListViewText(hwndListView
, index
++, L
"DN_NEED_RESTART");
939 if (dwStatus
& DN_CHILD_WITH_INVALID_ID
)
940 SetListViewText(hwndListView
, index
++, L
"DN_CHILD_WITH_INVALID_ID");
941 if (dwStatus
& DN_HAS_PROBLEM
)
942 SetListViewText(hwndListView
, index
++, L
"DN_HAS_PROBLEM");
943 if (dwStatus
& DN_FILTERED
)
944 SetListViewText(hwndListView
, index
++, L
"DN_FILTERED");
945 if (dwStatus
& DN_LEGACY_DRIVER
)
946 SetListViewText(hwndListView
, index
++, L
"DN_LEGACY_DRIVER");
947 if (dwStatus
& DN_DISABLEABLE
)
948 SetListViewText(hwndListView
, index
++, L
"DN_DISABLEABLE");
949 if (dwStatus
& DN_REMOVABLE
)
950 SetListViewText(hwndListView
, index
++, L
"DN_REMOVABLE");
951 if (dwStatus
& DN_PRIVATE_PROBLEM
)
952 SetListViewText(hwndListView
, index
++, L
"DN_PRIVATE_PROBLEM");
953 if (dwStatus
& DN_MF_PARENT
)
954 SetListViewText(hwndListView
, index
++, L
"DN_MF_PARENT");
955 if (dwStatus
& DN_MF_CHILD
)
956 SetListViewText(hwndListView
, index
++, L
"DN_MF_CHILD");
957 if (dwStatus
& DN_WILL_BE_REMOVED
)
958 SetListViewText(hwndListView
, index
++, L
"DN_WILL_BE_REMOVED");
960 if (dwStatus
& DN_NOT_FIRST_TIMEE
)
961 SetListViewText(hwndListView
, index
++, L
"DN_NOT_FIRST_TIMEE");
962 if (dwStatus
& DN_STOP_FREE_RES
)
963 SetListViewText(hwndListView
, index
++, L
"DN_STOP_FREE_RES");
964 if (dwStatus
& DN_REBAL_CANDIDATE
)
965 SetListViewText(hwndListView
, index
++, L
"DN_REBAL_CANDIDATE");
966 if (dwStatus
& DN_BAD_PARTIAL
)
967 SetListViewText(hwndListView
, index
++, L
"DN_BAD_PARTIAL");
968 if (dwStatus
& DN_NT_ENUMERATOR
)
969 SetListViewText(hwndListView
, index
++, L
"DN_NT_ENUMERATOR");
970 if (dwStatus
& DN_NT_DRIVER
)
971 SetListViewText(hwndListView
, index
++, L
"DN_NT_DRIVER");
973 if (dwStatus
& DN_NEEDS_LOCKING
)
974 SetListViewText(hwndListView
, index
++, L
"DN_NEEDS_LOCKING");
975 if (dwStatus
& DN_ARM_WAKEUP
)
976 SetListViewText(hwndListView
, index
++, L
"DN_ARM_WAKEUP");
977 if (dwStatus
& DN_APM_ENUMERATOR
)
978 SetListViewText(hwndListView
, index
++, L
"DN_APM_ENUMERATOR");
979 if (dwStatus
& DN_APM_DRIVER
)
980 SetListViewText(hwndListView
, index
++, L
"DN_APM_DRIVER");
981 if (dwStatus
& DN_SILENT_INSTALL
)
982 SetListViewText(hwndListView
, index
++, L
"DN_SILENT_INSTALL");
983 if (dwStatus
& DN_NO_SHOW_IN_DM
)
984 SetListViewText(hwndListView
, index
++, L
"DN_NO_SHOW_IN_DM");
985 if (dwStatus
& DN_BOOT_LOG_PROB
)
986 SetListViewText(hwndListView
, index
++, L
"DN_BOOT_LOG_PROB");
988 // swprintf(dap->szTemp, L"0x%08x", dwStatus);
989 // SetListViewText(hwndListView, 0, dap->szTemp);
994 DisplayDevNodeEnumerator(IN PDEVADVPROP_INFO dap
,
995 IN HWND hwndListView
)
997 PSP_DEVINFO_DATA DeviceInfoData
;
1000 WCHAR szBuffer
[256];
1001 DWORD dwSize
= 256 * sizeof(WCHAR
);
1003 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1005 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1009 DeviceInfoData
= &dap
->DeviceInfoData
;
1012 CM_Get_DevNode_Registry_Property_ExW(DeviceInfoData
->DevInst
,
1013 CM_DRP_ENUMERATOR_NAME
,
1020 SetListViewText(hwndListView
, 0, szBuffer
);
1025 DisplayCsFlags(IN PDEVADVPROP_INFO dap
,
1026 IN HWND hwndListView
)
1031 CM_Get_HW_Prof_Flags_Ex(dap
->szDevName
,
1032 0, /* current hardware profile */
1038 if (dwValue
& CSCONFIGFLAG_DISABLED
)
1039 SetListViewText(hwndListView
, index
++, L
"CSCONFIGFLAG_DISABLED");
1041 if (dwValue
& CSCONFIGFLAG_DO_NOT_CREATE
)
1042 SetListViewText(hwndListView
, index
++, L
"CSCONFIGFLAG_DO_NOT_CREATE");
1044 if (dwValue
& CSCONFIGFLAG_DO_NOT_START
)
1045 SetListViewText(hwndListView
, index
++, L
"CSCONFIGFLAG_DO_NOT_START");
1050 DisplayMatchingDeviceId(IN PDEVADVPROP_INFO dap
,
1051 IN HWND hwndListView
)
1053 HDEVINFO DeviceInfoSet
;
1054 PSP_DEVINFO_DATA DeviceInfoData
;
1055 WCHAR szBuffer
[256];
1060 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1062 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1063 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1067 DeviceInfoSet
= dap
->DeviceInfoSet
;
1068 DeviceInfoData
= &dap
->DeviceInfoData
;
1071 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
,
1077 if (hKey
!= INVALID_HANDLE_VALUE
)
1079 dwSize
= 256 * sizeof(WCHAR
);
1080 if (RegQueryValueEx(hKey
,
1081 L
"MatchingDeviceId",
1085 &dwSize
) == ERROR_SUCCESS
)
1087 SetListViewText(hwndListView
, 0, szBuffer
);
1096 DisplayClassCoinstallers(IN PDEVADVPROP_INFO dap
,
1097 IN HWND hwndListView
)
1099 HDEVINFO DeviceInfoSet
;
1100 PSP_DEVINFO_DATA DeviceInfoData
;
1101 WCHAR szClassGuid
[45];
1102 HKEY hKey
= (HKEY
)INVALID_HANDLE_VALUE
;
1105 LPBYTE lpBuffer
= NULL
;
1111 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1113 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1114 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1118 DeviceInfoSet
= dap
->DeviceInfoSet
;
1119 DeviceInfoData
= &dap
->DeviceInfoData
;
1122 dwSize
= 45 * sizeof(WCHAR
);
1123 if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
1127 (LPBYTE
)szClassGuid
,
1132 lError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1133 L
"SYSTEM\\CurrentControlSet\\Control\\CoDeviceInstallers",
1137 if (lError
!= ERROR_SUCCESS
)
1141 lError
= RegQueryValueEx(hKey
,
1147 if (lError
!= ERROR_SUCCESS
)
1153 lpBuffer
= (LPBYTE
)HeapAlloc(GetProcessHeap(),
1157 RegQueryValueEx(hKey
,
1164 lpStr
= (LPWSTR
)lpBuffer
;
1168 len
= wcslen(lpStr
) + 1;
1170 SetListViewText(hwndListView
, index
, lpStr
);
1177 if (lpBuffer
!= NULL
)
1178 HeapFree(GetProcessHeap(), 0, lpBuffer
);
1180 if (hKey
!= INVALID_HANDLE_VALUE
)
1186 DisplayDeviceCoinstallers(IN PDEVADVPROP_INFO dap
,
1187 IN HWND hwndListView
)
1189 HDEVINFO DeviceInfoSet
;
1190 PSP_DEVINFO_DATA DeviceInfoData
;
1199 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1201 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1202 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1206 DeviceInfoSet
= dap
->DeviceInfoSet
;
1207 DeviceInfoData
= &dap
->DeviceInfoData
;
1210 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
,
1216 if (hKey
!= INVALID_HANDLE_VALUE
)
1219 if (RegQueryValueEx(hKey
,
1224 &dwSize
) == ERROR_SUCCESS
&&
1228 lpBuffer
= (LPBYTE
)HeapAlloc(GetProcessHeap(),
1232 RegQueryValueEx(hKey
,
1239 lpStr
= (LPWSTR
)lpBuffer
;
1243 len
= wcslen(lpStr
) + 1;
1245 SetListViewText(hwndListView
, index
, lpStr
);
1251 HeapFree(GetProcessHeap(),
1262 DisplayClassProperties(IN PDEVADVPROP_INFO dap
,
1263 IN HWND hwndListView
,
1264 IN LPCWSTR lpProperty
)
1266 HDEVINFO DeviceInfoSet
;
1267 PSP_DEVINFO_DATA DeviceInfoData
;
1268 WCHAR szClassGuid
[45];
1278 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1280 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1281 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1285 DeviceInfoSet
= dap
->DeviceInfoSet
;
1286 DeviceInfoData
= &dap
->DeviceInfoData
;
1289 dwSize
= 45 * sizeof(WCHAR
);
1290 if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
1294 (LPBYTE
)szClassGuid
,
1299 pSetupGuidFromString(szClassGuid
,
1302 hKey
= SetupDiOpenClassRegKey(&ClassGuid
,
1304 if (hKey
!= INVALID_HANDLE_VALUE
)
1307 if (RegQueryValueEx(hKey
,
1312 &dwSize
) == ERROR_SUCCESS
&&
1315 lpBuffer
= (LPBYTE
)HeapAlloc(GetProcessHeap(),
1319 RegQueryValueEx(hKey
,
1326 if (dwType
== REG_SZ
)
1328 SetListViewText(hwndListView
, 0, (LPWSTR
)lpBuffer
);
1330 else if (dwType
== REG_MULTI_SZ
)
1332 lpStr
= (LPWSTR
)lpBuffer
;
1336 len
= wcslen(lpStr
) + 1;
1338 SetListViewText(hwndListView
, index
, lpStr
);
1345 HeapFree(GetProcessHeap(),
1356 DisplayDeviceRelations(
1357 IN PDEVADVPROP_INFO dap
,
1358 IN HWND hwndListView
,
1362 LPWSTR pszBuffer
= NULL
, pszStr
;
1366 ret
= CM_Get_Device_ID_List_Size_ExW(&ulLength
,
1370 if (ret
!= CR_SUCCESS
)
1373 pszBuffer
= (LPWSTR
)HeapAlloc(GetProcessHeap(),
1375 ulLength
* sizeof(WCHAR
));
1376 if (pszBuffer
== NULL
)
1379 ret
= CM_Get_Device_ID_List_ExW(dap
->szDeviceID
,
1384 if (ret
!= CR_SUCCESS
)
1386 HeapFree(GetProcessHeap(), 0, pszBuffer
);
1392 while (*pszStr
!= 0)
1394 len
= wcslen(pszStr
) + 1;
1396 SetListViewText(hwndListView
, index
, pszStr
);
1402 HeapFree(GetProcessHeap(), 0, pszBuffer
);
1407 DisplayCurrentPowerState(
1408 IN PDEVADVPROP_INFO dap
,
1409 IN HWND hwndListView
)
1411 HDEVINFO DeviceInfoSet
;
1412 PSP_DEVINFO_DATA DeviceInfoData
;
1413 CM_POWER_DATA PowerData
;
1414 DWORD dwSize
, dwType
;
1415 PCWSTR lpText
= NULL
;
1417 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1419 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1420 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1424 DeviceInfoSet
= dap
->DeviceInfoSet
;
1425 DeviceInfoData
= &dap
->DeviceInfoData
;
1428 dwSize
= sizeof(CM_POWER_DATA
);
1429 if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
1431 SPDRP_DEVICE_POWER_DATA
,
1438 switch (PowerData
.PD_MostRecentPowerState
)
1440 // case PowerDeviceUnspecified:
1463 SetListViewText(hwndListView
, 0, lpText
);
1468 DisplayPowerCapabilities(
1469 IN PDEVADVPROP_INFO dap
,
1470 IN HWND hwndListView
)
1472 HDEVINFO DeviceInfoSet
;
1473 PSP_DEVINFO_DATA DeviceInfoData
;
1474 CM_POWER_DATA PowerData
;
1475 DWORD dwSize
, dwType
;
1478 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1480 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1481 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1485 DeviceInfoSet
= dap
->DeviceInfoSet
;
1486 DeviceInfoData
= &dap
->DeviceInfoData
;
1489 dwSize
= sizeof(CM_POWER_DATA
);
1490 if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
1492 SPDRP_DEVICE_POWER_DATA
,
1499 if (PowerData
.PD_Capabilities
& PDCAP_D0_SUPPORTED
)
1500 SetListViewText(hwndListView
, index
++, L
"PDCAP_D0_SUPPORTED");
1502 if (PowerData
.PD_Capabilities
& PDCAP_D1_SUPPORTED
)
1503 SetListViewText(hwndListView
, index
++, L
"PDCAP_D1_SUPPORTED");
1505 if (PowerData
.PD_Capabilities
& PDCAP_D2_SUPPORTED
)
1506 SetListViewText(hwndListView
, index
++, L
"PDCAP_D2_SUPPORTED");
1508 if (PowerData
.PD_Capabilities
& PDCAP_D3_SUPPORTED
)
1509 SetListViewText(hwndListView
, index
++, L
"PDCAP_D3_SUPPORTED");
1511 if (PowerData
.PD_Capabilities
& PDCAP_WAKE_FROM_D0_SUPPORTED
)
1512 SetListViewText(hwndListView
, index
++, L
"PDCAP_WAKE_FROM_D0_SUPPORTED");
1514 if (PowerData
.PD_Capabilities
& PDCAP_WAKE_FROM_D1_SUPPORTED
)
1515 SetListViewText(hwndListView
, index
++, L
"PDCAP_WAKE_FROM_D1_SUPPORTED");
1517 if (PowerData
.PD_Capabilities
& PDCAP_WAKE_FROM_D2_SUPPORTED
)
1518 SetListViewText(hwndListView
, index
++, L
"PDCAP_WAKE_FROM_D2_SUPPORTED");
1520 if (PowerData
.PD_Capabilities
& PDCAP_WAKE_FROM_D3_SUPPORTED
)
1521 SetListViewText(hwndListView
, index
++, L
"PDCAP_WAKE_FROM_D3_SUPPORTED");
1523 if (PowerData
.PD_Capabilities
& PDCAP_WARM_EJECT_SUPPORTED
)
1524 SetListViewText(hwndListView
, index
++, L
"PDCAP_WARM_EJECT_SUPPORTED");
1529 DisplayPowerStateMappings(
1530 IN PDEVADVPROP_INFO dap
,
1531 IN HWND hwndListView
)
1533 HDEVINFO DeviceInfoSet
;
1534 PSP_DEVINFO_DATA DeviceInfoData
;
1535 CM_POWER_DATA PowerData
;
1536 DWORD dwSize
, dwType
;
1538 DEVICE_POWER_STATE PowerState
;
1539 WCHAR szSystemStateBuffer
[40];
1540 WCHAR szDeviceStateBuffer
[40];
1541 WCHAR szOutBuffer
[100];
1543 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1545 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1546 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1550 DeviceInfoSet
= dap
->DeviceInfoSet
;
1551 DeviceInfoData
= &dap
->DeviceInfoData
;
1554 dwSize
= sizeof(CM_POWER_DATA
);
1555 if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
1557 SPDRP_DEVICE_POWER_DATA
,
1564 for (i
= PowerSystemWorking
; i
< PowerSystemMaximum
; i
++)
1566 PowerState
= PowerData
.PD_PowerStateMapping
[i
];
1567 if ((PowerState
>= PowerDeviceUnspecified
) && (PowerState
<= PowerDeviceD3
))
1569 swprintf(szSystemStateBuffer
, L
"S%u", i
- 1);
1573 case PowerDeviceUnspecified
:
1574 wcscpy(szDeviceStateBuffer
, L
"Not specified");
1578 wcscpy(szDeviceStateBuffer
, L
"D0");
1582 wcscpy(szDeviceStateBuffer
, L
"D1");
1586 wcscpy(szDeviceStateBuffer
, L
"D2");
1590 wcscpy(szDeviceStateBuffer
, L
"D3");
1597 swprintf(szOutBuffer
, L
"%s -> %s", szSystemStateBuffer
, szDeviceStateBuffer
);
1598 SetListViewText(hwndListView
, i
, szOutBuffer
);
1605 DisplayDeviceProperties(IN PDEVADVPROP_INFO dap
,
1606 IN HWND hwndComboBox
,
1607 IN HWND hwndListView
)
1611 Index
= (INT
)SendMessage(hwndComboBox
,
1615 if (Index
== CB_ERR
)
1618 (void)ListView_DeleteAllItems(hwndListView
);
1622 case 0: /* Device ID */
1623 SetListViewText(hwndListView
, 0, dap
->szDeviceID
);
1626 case 1: /* Hardware ID */
1627 DisplayDevicePropertyText(dap
,
1632 case 2: /* Compatible IDs */
1633 DisplayDevicePropertyText(dap
,
1635 SPDRP_COMPATIBLEIDS
);
1638 case 3: /* Matching ID */
1639 DisplayMatchingDeviceId(dap
,
1643 case 4: /* Service */
1644 DisplayDevicePropertyText(dap
,
1649 case 5: /* Enumerator */
1650 DisplayDevNodeEnumerator(dap
,
1654 case 6: /* Capabilities */
1655 DisplayDevicePropertyText(dap
,
1657 SPDRP_CAPABILITIES
);
1660 case 7: /* Devnode Flags */
1661 DisplayDevNodeFlags(dap
,
1665 case 8: /* Config Flags */
1666 DisplayDevicePropertyText(dap
,
1671 case 9: /* CSConfig Flags */
1676 case 10: /* Ejection relation */
1677 DisplayDeviceRelations(dap
,
1679 CM_GETIDLIST_FILTER_EJECTRELATIONS
);
1682 case 11: /* Removal relations */
1683 DisplayDeviceRelations(dap
,
1685 CM_GETIDLIST_FILTER_REMOVALRELATIONS
);
1688 case 12: /* Bus relation */
1689 DisplayDeviceRelations(dap
,
1691 CM_GETIDLIST_FILTER_BUSRELATIONS
);
1694 case 13: /* Device Upper Filters */
1695 DisplayDevicePropertyText(dap
,
1697 SPDRP_UPPERFILTERS
);
1700 case 14: /* Device Lower Filters */
1701 DisplayDevicePropertyText(dap
,
1703 SPDRP_LOWERFILTERS
);
1706 case 15: /* Class Upper Filters */
1707 DisplayClassProperties(dap
,
1712 case 16: /* Class Lower Filters */
1713 DisplayClassProperties(dap
,
1718 case 17: /* Class Installer */
1719 DisplayClassProperties(dap
,
1724 case 18: /* Class Coinstaller */
1725 DisplayClassCoinstallers(dap
,
1729 case 19: /* Device Coinstaller */
1730 DisplayDeviceCoinstallers(dap
,
1735 case 20: /* Firmware Revision */
1739 case 21: /* Current Power State */
1740 DisplayCurrentPowerState(dap
,
1744 case 22: /* Power Capabilities */
1745 DisplayPowerCapabilities(dap
,
1749 case 23: /* Power State Mappings */
1750 DisplayPowerStateMappings(dap
,
1755 SetListViewText(hwndListView
, 0, L
"<Not implemented yet>");
1763 AdvProcDetailsDlgProc(IN HWND hwndDlg
,
1768 PDEVADVPROP_INFO dap
;
1769 INT_PTR Ret
= FALSE
;
1771 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
,
1774 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
1780 switch (LOWORD(wParam
))
1782 case IDC_DETAILSPROPNAME
:
1783 if (HIWORD(wParam
) == CBN_SELCHANGE
)
1785 DisplayDeviceProperties(dap
,
1786 GetDlgItem(hwndDlg
, IDC_DETAILSPROPNAME
),
1787 GetDlgItem(hwndDlg
, IDC_DETAILSPROPVALUE
));
1796 NMHDR
*hdr
= (NMHDR
*)lParam
;
1807 dap
= (PDEVADVPROP_INFO
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1810 SetWindowLongPtr(hwndDlg
,
1814 UpdateDetailsDlg(hwndDlg
,
1828 InitDevUsageActions(IN HWND hwndDlg
,
1830 IN PDEVADVPROP_INFO dap
)
1841 i
!= sizeof(Actions
) / sizeof(Actions
[0]);
1844 /* fill in the device usage combo box */
1845 if (LoadString(hDllInstance
,
1848 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1850 Index
= (INT
)SendMessage(hComboBox
,
1853 (LPARAM
)dap
->szTemp
);
1854 if (Index
!= CB_ERR
)
1856 SendMessage(hComboBox
,
1859 (LPARAM
)Actions
[i
]);
1863 case IDS_ENABLEDEVICE
:
1864 if (dap
->DeviceStarted
)
1866 SendMessage(hComboBox
,
1873 case IDS_DISABLEDEVICE
:
1874 if (!dap
->DeviceStarted
)
1876 SendMessage(hComboBox
,
1893 GetSelectedUsageAction(IN HWND hComboBox
)
1898 Index
= (INT
)SendMessage(hComboBox
,
1902 if (Index
!= CB_ERR
)
1904 INT iRet
= (INT
) SendMessage(hComboBox
,
1919 ApplyGeneralSettings(IN HWND hwndDlg
,
1920 IN PDEVADVPROP_INFO dap
)
1924 if (dap
->DeviceUsageChanged
&& dap
->IsAdmin
&& dap
->CanDisable
)
1926 UINT SelectedUsageAction
;
1927 BOOL NeedReboot
= FALSE
;
1929 SelectedUsageAction
= GetSelectedUsageAction(GetDlgItem(hwndDlg
,
1931 switch (SelectedUsageAction
)
1933 case IDS_ENABLEDEVICE
:
1934 if (!dap
->DeviceStarted
)
1936 Ret
= EnableDevice(dap
->DeviceInfoSet
,
1937 &dap
->DeviceInfoData
,
1944 case IDS_DISABLEDEVICE
:
1945 if (dap
->DeviceStarted
)
1947 Ret
= EnableDevice(dap
->DeviceInfoSet
,
1948 &dap
->DeviceInfoData
,
1963 /* make PropertySheet() return PSM_REBOOTSYSTEM */
1964 PropSheet_RebootSystem(hwndDlg
);
1969 /* FIXME - display an error message */
1970 FIXME("Failed to enable/disable device! LastError: %d\n",
1975 Ret
= !dap
->DeviceUsageChanged
;
1977 /* disable the apply button */
1978 PropSheet_UnChanged(GetParent(hwndDlg
),
1980 dap
->DeviceUsageChanged
= FALSE
;
1986 UpdateDevInfo(IN HWND hwndDlg
,
1987 IN PDEVADVPROP_INFO dap
,
1990 HWND hDevUsage
, hPropSheetDlg
, hDevProbBtn
;
1992 ULONG Status
, ProblemNumber
;
1993 SP_DEVINSTALL_PARAMS_W InstallParams
;
1994 UINT TroubleShootStrId
= IDS_TROUBLESHOOTDEV
;
1995 BOOL bFlag
, bDevActionAvailable
= TRUE
;
1996 BOOL bDrvInstalled
= FALSE
;
1998 HDEVINFO DeviceInfoSet
= NULL
;
1999 PSP_DEVINFO_DATA DeviceInfoData
= NULL
;
2000 PROPSHEETHEADER psh
;
2001 DWORD nDriverPages
= 0;
2002 BOOL RecalcPages
= FALSE
;
2004 hPropSheetDlg
= GetParent(hwndDlg
);
2006 if (dap
->PageInitialized
)
2008 /* switch to the General page */
2009 PropSheet_SetCurSelByID(hPropSheetDlg
,
2012 /* remove and destroy the existing device property sheet pages */
2013 if (dap
->DevPropSheets
!= NULL
)
2016 iPage
!= dap
->nDevPropSheets
;
2019 if (dap
->DevPropSheets
[iPage
] != NULL
)
2021 PropSheet_RemovePage(hPropSheetDlg
,
2023 dap
->DevPropSheets
[iPage
]);
2032 if (dap
->FreeDevPropSheets
)
2034 /* don't free the array if it's the one allocated in
2035 DisplayDeviceAdvancedProperties */
2036 HeapFree(GetProcessHeap(),
2038 dap
->DevPropSheets
);
2040 dap
->FreeDevPropSheets
= FALSE
;
2043 dap
->DevPropSheets
= NULL
;
2044 dap
->nDevPropSheets
= 0;
2048 /* create a new device info set and re-open the device */
2049 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
2051 SetupDiDestroyDeviceInfoList(dap
->CurrentDeviceInfoSet
);
2054 dap
->ParentDevInst
= 0;
2055 dap
->CurrentDeviceInfoSet
= SetupDiCreateDeviceInfoListEx(NULL
,
2059 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
2061 if (SetupDiOpenDeviceInfo(dap
->CurrentDeviceInfoSet
,
2065 &dap
->CurrentDeviceInfoData
))
2067 if (dap
->CloseDevInst
)
2069 SetupDiDestroyDeviceInfoList(dap
->DeviceInfoSet
);
2072 dap
->CloseDevInst
= TRUE
;
2073 dap
->DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
2074 dap
->DeviceInfoData
= dap
->CurrentDeviceInfoData
;
2075 dap
->CurrentDeviceInfoSet
= INVALID_HANDLE_VALUE
;
2083 /* get the parent node from the initial devinst */
2084 CM_Get_Parent_Ex(&dap
->ParentDevInst
,
2085 dap
->DeviceInfoData
.DevInst
,
2090 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
2092 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
2093 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
2097 DeviceInfoSet
= dap
->DeviceInfoSet
;
2098 DeviceInfoData
= &dap
->DeviceInfoData
;
2103 DeviceInfoSet
= dap
->DeviceInfoSet
;
2104 DeviceInfoData
= &dap
->DeviceInfoData
;
2107 dap
->HasDriverPage
= FALSE
;
2108 dap
->HasResourcePage
= FALSE
;
2109 dap
->HasPowerPage
= FALSE
;
2110 if (IsDriverInstalled(DeviceInfoData
->DevInst
,
2115 if (SetupDiCallClassInstaller((dap
->ShowRemotePages
?
2116 DIF_ADDREMOTEPROPERTYPAGE_ADVANCED
:
2117 DIF_ADDPROPERTYPAGE_ADVANCED
),
2121 /* get install params */
2122 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
2123 if (!SetupDiGetDeviceInstallParamsW(DeviceInfoSet
,
2127 /* zero the flags */
2128 InstallParams
.Flags
= 0;
2131 dap
->HasDriverPage
= !(InstallParams
.Flags
& DI_DRIVERPAGE_ADDED
);
2132 dap
->HasResourcePage
= !(InstallParams
.Flags
& DI_RESOURCEPAGE_ADDED
);
2133 dap
->HasPowerPage
= !(InstallParams
.Flags
& DI_FLAGSEX_POWERPAGE_ADDED
);
2137 /* get the device icon */
2138 if (dap
->hDevIcon
!= NULL
)
2140 DestroyIcon(dap
->hDevIcon
);
2141 dap
->hDevIcon
= NULL
;
2143 if (!SetupDiLoadClassIcon(&DeviceInfoData
->ClassGuid
,
2147 dap
->hDevIcon
= NULL
;
2150 /* get the device name */
2151 if (GetDeviceDescriptionString(DeviceInfoSet
,
2154 sizeof(dap
->szDevName
) / sizeof(dap
->szDevName
[0])))
2156 PropSheet_SetTitle(hPropSheetDlg
,
2161 /* set the device image */
2162 SendDlgItemMessage(hwndDlg
,
2165 (WPARAM
)dap
->hDevIcon
,
2168 /* set the device name edit control text */
2169 SetDlgItemText(hwndDlg
,
2173 /* set the device type edit control text */
2174 if (GetDeviceTypeString(DeviceInfoData
,
2176 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
2178 SetDlgItemText(hwndDlg
,
2183 /* set the device manufacturer edit control text */
2184 if (GetDeviceManufacturerString(DeviceInfoSet
,
2187 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
2189 SetDlgItemText(hwndDlg
,
2190 IDC_DEVMANUFACTURER
,
2194 /* set the device location edit control text */
2195 if (GetDeviceLocationString(DeviceInfoSet
,
2199 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
2201 SetDlgItemText(hwndDlg
,
2206 /* set the device status edit control text */
2207 if (GetDeviceStatusString(DeviceInfoData
->DevInst
,
2210 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
2212 SetDlgItemText(hwndDlg
,
2217 /* set the device troubleshoot button text and disable it if necessary */
2218 hDevProbBtn
= GetDlgItem(hwndDlg
,
2220 cr
= CM_Get_DevNode_Status_Ex(&Status
,
2222 DeviceInfoData
->DevInst
,
2225 if (cr
== CR_SUCCESS
&& (Status
& DN_HAS_PROBLEM
))
2227 switch (ProblemNumber
)
2229 case CM_PROB_DEVLOADER_FAILED
:
2231 /* FIXME - only if it's not a root bus devloader,
2232 disable the button otherwise */
2233 TroubleShootStrId
= IDS_UPDATEDRV
;
2237 case CM_PROB_OUT_OF_MEMORY
:
2238 case CM_PROB_ENTRY_IS_WRONG_TYPE
:
2239 case CM_PROB_LACKED_ARBITRATOR
:
2240 case CM_PROB_FAILED_START
:
2242 case CM_PROB_UNKNOWN_RESOURCE
:
2244 TroubleShootStrId
= IDS_UPDATEDRV
;
2248 case CM_PROB_BOOT_CONFIG_CONFLICT
:
2249 case CM_PROB_NORMAL_CONFLICT
:
2250 case CM_PROB_REENUMERATION
:
2252 /* FIXME - Troubleshoot conflict */
2256 case CM_PROB_FAILED_FILTER
:
2257 case CM_PROB_REINSTALL
:
2258 case CM_PROB_FAILED_INSTALL
:
2260 TroubleShootStrId
= IDS_REINSTALLDRV
;
2264 case CM_PROB_DEVLOADER_NOT_FOUND
:
2267 1) if it's a missing system devloader:
2268 - disable the button (Reinstall Driver)
2269 2) if it's not a system devloader but still missing:
2271 3) if it's not a system devloader but the file can be found:
2273 4) if it's a missing or empty software key
2279 case CM_PROB_INVALID_DATA
:
2280 case CM_PROB_PARTIAL_LOG_CONF
:
2281 case CM_PROB_NO_VALID_LOG_CONF
:
2282 case CM_PROB_HARDWARE_DISABLED
:
2283 case CM_PROB_CANT_SHARE_IRQ
:
2284 case CM_PROB_TRANSLATION_FAILED
:
2285 case CM_PROB_SYSTEM_SHUTDOWN
:
2286 case CM_PROB_PHANTOM
:
2287 bDevActionAvailable
= FALSE
;
2290 case CM_PROB_NOT_VERIFIED
:
2291 case CM_PROB_DEVICE_NOT_THERE
:
2292 /* FIXME - search hardware */
2295 case CM_PROB_NEED_RESTART
:
2296 case CM_PROB_WILL_BE_REMOVED
:
2298 case CM_PROB_TOO_EARLY
:
2299 case CM_PROB_DISABLED_SERVICE
:
2300 TroubleShootStrId
= IDS_REBOOT
;
2303 case CM_PROB_REGISTRY
:
2304 /* FIXME - check registry? */
2307 case CM_PROB_DISABLED
:
2308 /* if device was disabled by the user: */
2309 TroubleShootStrId
= IDS_ENABLEDEV
;
2310 /* FIXME - otherwise disable button because the device was
2311 disabled by the system*/
2314 case CM_PROB_DEVLOADER_NOT_READY
:
2315 /* FIXME - if it's a graphics adapter:
2316 - if it's a a secondary adapter and the main adapter
2326 case CM_PROB_FAILED_ADD
:
2327 TroubleShootStrId
= IDS_PROPERTIES
;
2332 if (LoadString(hDllInstance
,
2335 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])) != 0)
2337 SetWindowText(hDevProbBtn
,
2340 EnableWindow(hDevProbBtn
,
2341 dap
->IsAdmin
&& bDevActionAvailable
);
2343 /* check if the device can be enabled/disabled */
2344 hDevUsage
= GetDlgItem(hwndDlg
,
2347 dap
->CanDisable
= FALSE
;
2348 dap
->DeviceStarted
= FALSE
;
2350 if (CanDisableDevice(DeviceInfoData
->DevInst
,
2354 dap
->CanDisable
= bFlag
;
2357 if (IsDeviceStarted(DeviceInfoData
->DevInst
,
2361 dap
->DeviceStarted
= bFlag
;
2364 /* enable/disable the device usage controls */
2365 EnableWindow(GetDlgItem(hwndDlg
,
2367 dap
->CanDisable
&& dap
->IsAdmin
);
2368 EnableWindow(hDevUsage
,
2369 dap
->CanDisable
&& dap
->IsAdmin
);
2371 /* clear the combobox */
2372 SendMessage(hDevUsage
,
2376 if (dap
->CanDisable
)
2378 InitDevUsageActions(hwndDlg
,
2383 /* find out how many new device property sheets to add.
2384 fake a PROPSHEETHEADER structure, we don't plan to
2385 call PropertySheet again!*/
2386 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
2390 /* get the number of device property sheets for the device */
2391 if (!SetupDiGetClassDevPropertySheets(DeviceInfoSet
,
2396 dap
->PropertySheetType
) &&
2397 nDriverPages
!= 0 && GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
2399 dap
->nDevPropSheets
+= nDriverPages
;
2406 /* include the driver page */
2407 if (dap
->HasDriverPage
)
2408 dap
->nDevPropSheets
++;
2410 /* include the details page */
2412 dap
->nDevPropSheets
++;
2414 if (dap
->HasResourcePage
)
2415 dap
->nDevPropSheets
++;
2417 /* add the device property sheets */
2418 if (dap
->nDevPropSheets
!= 0)
2420 dap
->DevPropSheets
= (HPROPSHEETPAGE
*)HeapAlloc(GetProcessHeap(),
2422 dap
->nDevPropSheets
* sizeof(HPROPSHEETPAGE
));
2423 if (dap
->DevPropSheets
!= NULL
)
2425 if (nDriverPages
!= 0)
2427 psh
.phpage
= dap
->DevPropSheets
;
2429 /* query the device property sheet pages to add */
2430 if (SetupDiGetClassDevPropertySheets(DeviceInfoSet
,
2433 dap
->nDevPropSheets
,
2435 dap
->PropertySheetType
))
2437 /* add the property sheets */
2439 iPage
< nDriverPages
;
2442 if (PropSheet_AddPage(hPropSheetDlg
,
2443 dap
->DevPropSheets
[iPage
]))
2449 dap
->FreeDevPropSheets
= TRUE
;
2453 /* cleanup, we were unable to get the device property sheets */
2454 iPage
= nDriverPages
;
2455 dap
->nDevPropSheets
-= nDriverPages
;
2462 /* add the driver page if necessary */
2463 if (dap
->HasDriverPage
)
2465 PROPSHEETPAGE pspDriver
= {0};
2466 pspDriver
.dwSize
= sizeof(PROPSHEETPAGE
);
2467 pspDriver
.dwFlags
= PSP_DEFAULT
;
2468 pspDriver
.hInstance
= hDllInstance
;
2469 pspDriver
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICEDRIVER
);
2470 pspDriver
.pfnDlgProc
= AdvProcDriverDlgProc
;
2471 pspDriver
.lParam
= (LPARAM
)dap
;
2472 dap
->DevPropSheets
[iPage
] = dap
->pCreatePropertySheetPageW(&pspDriver
);
2473 if (dap
->DevPropSheets
[iPage
] != NULL
)
2475 if (PropSheet_AddPage(hPropSheetDlg
,
2476 dap
->DevPropSheets
[iPage
]))
2483 dap
->pDestroyPropertySheetPage(dap
->DevPropSheets
[iPage
]);
2484 dap
->DevPropSheets
[iPage
] = NULL
;
2491 /* Add the details page */
2492 PROPSHEETPAGE pspDetails
= {0};
2493 pspDetails
.dwSize
= sizeof(PROPSHEETPAGE
);
2494 pspDetails
.dwFlags
= PSP_DEFAULT
;
2495 pspDetails
.hInstance
= hDllInstance
;
2496 pspDetails
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICEDETAILS
);
2497 pspDetails
.pfnDlgProc
= AdvProcDetailsDlgProc
;
2498 pspDetails
.lParam
= (LPARAM
)dap
;
2499 dap
->DevPropSheets
[iPage
] = dap
->pCreatePropertySheetPageW(&pspDetails
);
2500 if (dap
->DevPropSheets
[iPage
] != NULL
)
2502 if (PropSheet_AddPage(hPropSheetDlg
,
2503 dap
->DevPropSheets
[iPage
]))
2510 dap
->pDestroyPropertySheetPage(dap
->DevPropSheets
[iPage
]);
2511 dap
->DevPropSheets
[iPage
] = NULL
;
2516 if (dap
->HasResourcePage
)
2518 PROPSHEETPAGE pspDriver
= {0};
2519 pspDriver
.dwSize
= sizeof(PROPSHEETPAGE
);
2520 pspDriver
.dwFlags
= PSP_DEFAULT
;
2521 pspDriver
.hInstance
= hDllInstance
;
2522 pspDriver
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICERESOURCES
);
2523 pspDriver
.pfnDlgProc
= ResourcesProcDriverDlgProc
;
2524 pspDriver
.lParam
= (LPARAM
)dap
;
2525 dap
->DevPropSheets
[iPage
] = dap
->pCreatePropertySheetPageW(&pspDriver
);
2526 if (dap
->DevPropSheets
[iPage
] != NULL
)
2528 if (PropSheet_AddPage(hPropSheetDlg
,
2529 dap
->DevPropSheets
[iPage
]))
2536 dap
->pDestroyPropertySheetPage(dap
->DevPropSheets
[iPage
]);
2537 dap
->DevPropSheets
[iPage
] = NULL
;
2541 /* FIXME: Add the power page */
2544 dap
->nDevPropSheets
= 0;
2549 PropSheet_RecalcPageSizes(hPropSheetDlg
);
2552 /* finally, disable the apply button */
2553 PropSheet_UnChanged(hPropSheetDlg
,
2555 dap
->DeviceUsageChanged
= FALSE
;
2561 DlgParentSubWndProc(IN HWND hwnd
,
2566 PDEVADVPROP_INFO dap
;
2568 dap
= (PDEVADVPROP_INFO
)GetProp(hwnd
,
2569 L
"DevMgrDevChangeSub");
2572 if (uMsg
== WM_DEVICECHANGE
&& !IsWindowVisible(dap
->hWndGeneralPage
))
2574 SendMessage(dap
->hWndGeneralPage
,
2580 /* pass the message the the old window proc */
2581 return CallWindowProc(dap
->ParentOldWndProc
,
2589 /* this is not a good idea if the subclassed window was an ansi
2590 window, but we failed finding out the previous window proc
2591 so we can't use CallWindowProc. This should rarely - if ever -
2594 return DefWindowProc(hwnd
,
2604 AdvPropGeneralDlgProc(IN HWND hwndDlg
,
2609 PDEVADVPROP_INFO dap
;
2610 INT_PTR Ret
= FALSE
;
2612 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
,
2615 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
2621 switch (LOWORD(wParam
))
2625 if (HIWORD(wParam
) == CBN_SELCHANGE
)
2627 PropSheet_Changed(GetParent(hwndDlg
),
2629 dap
->DeviceUsageChanged
= TRUE
;
2634 case IDC_DEVPROBLEM
:
2638 /* display the device problem wizard */
2639 ShowDeviceProblemWizard(hwndDlg
,
2641 &dap
->DeviceInfoData
,
2652 NMHDR
*hdr
= (NMHDR
*)lParam
;
2656 ApplyGeneralSettings(hwndDlg
,
2665 dap
= (PDEVADVPROP_INFO
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
2670 dap
->hWndGeneralPage
= hwndDlg
;
2672 SetWindowLongPtr(hwndDlg
,
2676 /* subclass the parent window to always receive
2677 WM_DEVICECHANGE messages */
2678 hWndParent
= GetParent(hwndDlg
);
2679 if (hWndParent
!= NULL
)
2681 /* subclass the parent window. This is not safe
2682 if the parent window belongs to another thread! */
2683 dap
->ParentOldWndProc
= (WNDPROC
)SetWindowLongPtr(hWndParent
,
2685 (LONG_PTR
)DlgParentSubWndProc
);
2687 if (dap
->ParentOldWndProc
!= NULL
&&
2689 L
"DevMgrDevChangeSub",
2692 dap
->hWndParent
= hWndParent
;
2696 /* do not call UpdateDevInfo directly in here because it modifies
2697 the pages of the property sheet! */
2698 PostMessage(hwndDlg
,
2707 case WM_DEVICECHANGE
:
2709 /* FIXME - don't call UpdateDevInfo for all events */
2710 UpdateDevInfo(hwndDlg
,
2719 UpdateDevInfo(hwndDlg
,
2722 dap
->PageInitialized
= TRUE
;
2728 /* restore the old window proc of the subclassed parent window */
2729 if (dap
->hWndParent
!= NULL
&& dap
->ParentOldWndProc
!= NULL
)
2731 if (SetWindowLongPtr(dap
->hWndParent
,
2733 (LONG_PTR
)dap
->ParentOldWndProc
) == (LONG_PTR
)DlgParentSubWndProc
)
2735 RemoveProp(dap
->hWndParent
,
2736 L
"DevMgrDevChangeSub");
2749 DisplayDeviceAdvancedProperties(IN HWND hWndParent
,
2750 IN LPCWSTR lpDeviceID OPTIONAL
,
2751 IN HDEVINFO DeviceInfoSet
,
2752 IN PSP_DEVINFO_DATA DeviceInfoData
,
2753 IN HINSTANCE hComCtl32
,
2754 IN LPCWSTR lpMachineName
,
2757 PROPSHEETHEADER psh
= {0};
2758 PROPSHEETPAGE pspGeneral
= {0};
2759 PPROPERTYSHEETW pPropertySheetW
;
2760 PCREATEPROPERTYSHEETPAGEW pCreatePropertySheetPageW
;
2761 PDESTROYPROPERTYSHEETPAGE pDestroyPropertySheetPage
;
2762 PDEVADVPROP_INFO DevAdvPropInfo
;
2763 HMACHINE hMachine
= NULL
;
2764 DWORD DevIdSize
= 0;
2767 /* we don't want to statically link against comctl32, so find the
2768 functions we need dynamically */
2770 (PPROPERTYSHEETW
)GetProcAddress(hComCtl32
,
2772 pCreatePropertySheetPageW
=
2773 (PCREATEPROPERTYSHEETPAGEW
)GetProcAddress(hComCtl32
,
2774 "CreatePropertySheetPageW");
2775 pDestroyPropertySheetPage
=
2776 (PDESTROYPROPERTYSHEETPAGE
)GetProcAddress(hComCtl32
,
2777 "DestroyPropertySheetPage");
2778 if (pPropertySheetW
== NULL
||
2779 pCreatePropertySheetPageW
== NULL
||
2780 pDestroyPropertySheetPage
== NULL
)
2785 if (lpDeviceID
== NULL
)
2787 /* find out how much size is needed for the device id */
2788 if (SetupDiGetDeviceInstanceId(DeviceInfoSet
,
2794 ERR("SetupDiGetDeviceInstanceId unexpectedly returned TRUE!\n");
2798 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
2805 DevIdSize
= (DWORD
)wcslen(lpDeviceID
) + 1;
2808 if (lpMachineName
!= NULL
&& lpMachineName
[0] != L
'\0')
2810 CONFIGRET cr
= CM_Connect_Machine(lpMachineName
,
2812 if (cr
!= CR_SUCCESS
)
2818 /* create the internal structure associated with the "General",
2819 "Driver", ... pages */
2820 DevAdvPropInfo
= (PDEVADVPROP_INFO
)HeapAlloc(GetProcessHeap(),
2822 FIELD_OFFSET(DEVADVPROP_INFO
,
2824 (DevIdSize
* sizeof(WCHAR
)));
2825 if (DevAdvPropInfo
== NULL
)
2827 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2831 if (lpDeviceID
== NULL
)
2833 /* read the device instance id */
2834 if (!SetupDiGetDeviceInstanceId(DeviceInfoSet
,
2836 DevAdvPropInfo
->szDeviceID
,
2845 /* copy the device instance id supplied by the caller */
2846 wcscpy(DevAdvPropInfo
->szDeviceID
,
2850 DevAdvPropInfo
->DeviceInfoSet
= DeviceInfoSet
;
2851 DevAdvPropInfo
->DeviceInfoData
= *DeviceInfoData
;
2852 DevAdvPropInfo
->CurrentDeviceInfoSet
= INVALID_HANDLE_VALUE
;
2853 DevAdvPropInfo
->CurrentDeviceInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
2855 DevAdvPropInfo
->ShowRemotePages
= (lpMachineName
!= NULL
&& lpMachineName
[0] != L
'\0');
2856 DevAdvPropInfo
->hMachine
= hMachine
;
2857 DevAdvPropInfo
->lpMachineName
= lpMachineName
;
2858 DevAdvPropInfo
->szDevName
[0] = L
'\0';
2859 DevAdvPropInfo
->hComCtl32
= hComCtl32
;
2860 DevAdvPropInfo
->pCreatePropertySheetPageW
= pCreatePropertySheetPageW
;
2861 DevAdvPropInfo
->pDestroyPropertySheetPage
= pDestroyPropertySheetPage
;
2863 DevAdvPropInfo
->IsAdmin
= TRUE
;// IsUserAdmin();
2864 DevAdvPropInfo
->DoDefaultDevAction
= ((dwFlags
& DPF_DEVICE_STATUS_ACTION
) != 0);
2865 DevAdvPropInfo
->Extended
= ((dwFlags
& DPF_EXTENDED
) != 0);
2867 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
2868 psh
.dwFlags
= PSH_PROPTITLE
| PSH_NOAPPLYNOW
;
2869 psh
.hwndParent
= hWndParent
;
2870 psh
.pszCaption
= DevAdvPropInfo
->szDevName
;
2872 DevAdvPropInfo
->PropertySheetType
= DevAdvPropInfo
->ShowRemotePages
?
2873 DIGCDP_FLAG_REMOTE_ADVANCED
:
2874 DIGCDP_FLAG_ADVANCED
;
2876 psh
.phpage
= (HPROPSHEETPAGE
*)HeapAlloc(GetProcessHeap(),
2878 1 * sizeof(HPROPSHEETPAGE
));
2879 if (psh
.phpage
== NULL
)
2884 /* add the "General" property sheet */
2885 pspGeneral
.dwSize
= sizeof(PROPSHEETPAGE
);
2886 pspGeneral
.dwFlags
= PSP_DEFAULT
;
2887 pspGeneral
.hInstance
= hDllInstance
;
2888 pspGeneral
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICEGENERAL
);
2889 pspGeneral
.pfnDlgProc
= AdvPropGeneralDlgProc
;
2890 pspGeneral
.lParam
= (LPARAM
)DevAdvPropInfo
;
2891 psh
.phpage
[psh
.nPages
] = pCreatePropertySheetPageW(&pspGeneral
);
2892 if (psh
.phpage
[psh
.nPages
] != NULL
)
2897 DevAdvPropInfo
->nDevPropSheets
= psh
.nPages
;
2899 if (psh
.nPages
!= 0)
2901 Ret
= pPropertySheetW(&psh
);
2903 /* NOTE: no need to destroy the property sheets anymore! */
2910 /* in case of failure the property sheets must be destroyed */
2911 if (psh
.phpage
!= NULL
)
2917 if (psh
.phpage
[i
] != NULL
)
2919 pDestroyPropertySheetPage(psh
.phpage
[i
]);
2925 if (DevAdvPropInfo
!= NULL
)
2927 if (DevAdvPropInfo
->FreeDevPropSheets
)
2929 /* don't free the array if it's the one allocated in
2930 DisplayDeviceAdvancedProperties */
2931 HeapFree(GetProcessHeap(),
2933 DevAdvPropInfo
->DevPropSheets
);
2936 if (DevAdvPropInfo
->CloseDevInst
)
2938 /* close the device info set in case a new one was created */
2939 SetupDiDestroyDeviceInfoList(DevAdvPropInfo
->DeviceInfoSet
);
2942 if (DevAdvPropInfo
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
2944 SetupDiDestroyDeviceInfoList(DevAdvPropInfo
->CurrentDeviceInfoSet
);
2947 if (DevAdvPropInfo
->hDevIcon
!= NULL
)
2949 DestroyIcon(DevAdvPropInfo
->hDevIcon
);
2952 HeapFree(GetProcessHeap(),
2957 if (psh
.phpage
!= NULL
)
2959 HeapFree(GetProcessHeap(),
2964 if (hMachine
!= NULL
)
2966 CM_Disconnect_Machine(hMachine
);