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
, DWLP_USER
);
315 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
321 switch (LOWORD(wParam
))
344 HWND hDriversListView
;
347 dap
= (PDEVADVPROP_INFO
)lParam
;
350 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (DWORD_PTR
)dap
);
352 hDriversListView
= GetDlgItem(hwndDlg
,
355 /* add a column to the list view control */
356 lvc
.mask
= LVCF_FMT
| LVCF_WIDTH
;
357 lvc
.fmt
= LVCFMT_LEFT
;
359 (void)ListView_InsertColumn(hDriversListView
,
363 UpdateDriverDetailsDlg(hwndDlg
,
367 if (ListView_GetItemCount(hDriversListView
) == 0)
369 if (LoadStringW(hDllInstance
, IDS_NODRIVERS
, szBuffer
, _countof(szBuffer
)))
370 MessageBoxW(hwndDlg
, szBuffer
, dap
->szDevName
, MB_OK
);
371 EndDialog(hwndDlg
, IDCANCEL
);
381 LPNMHDR pnmhdr
= (LPNMHDR
)lParam
;
383 switch (pnmhdr
->code
)
385 case LVN_ITEMCHANGED
:
387 LPNMLISTVIEW pnmv
= (LPNMLISTVIEW
)lParam
;
388 HWND hDriversListView
= GetDlgItem(hwndDlg
,
391 if (ListView_GetSelectedCount(hDriversListView
) == 0)
393 /* nothing is selected - empty the labels */
394 SetDlgItemText(hwndDlg
,
397 SetDlgItemText(hwndDlg
,
400 SetDlgItemText(hwndDlg
,
403 SetDlgItemText(hwndDlg
,
407 else if (pnmv
->uNewState
!= 0)
409 /* extract version info and update the labels */
410 WCHAR szDriverPath
[MAX_PATH
];
412 ListView_GetItemText(hDriversListView
,
418 UpdateDriverVersionInfoDetails(hwndDlg
,
436 IN PDEVADVPROP_INFO dap
)
438 TOKEN_PRIVILEGES Privileges
;
441 BOOL NeedReboot
= FALSE
;
443 // Better use InstallDevInst:
448 // LPWSTR wszDeviceId,
451 // See: http://comp.os.ms-windows.programmer.win32.narkive.com/J8FTd4KK/signature-of-undocumented-installdevinstex
453 if (!InstallDevInst(hwndDlg
, dap
->szDeviceID
, TRUE
, &dwReboot
))
456 if (NeedReboot
== FALSE
)
459 //FIXME: load text from resource file
460 if (MessageBoxW(hwndDlg
, L
"Reboot now?", L
"Reboot required", MB_YESNO
| MB_ICONQUESTION
) != IDYES
)
463 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
465 ERR("OpenProcessToken failed\n");
469 /* Get the LUID for the Shutdown privilege */
470 if (!LookupPrivilegeValueW(NULL
, SE_SHUTDOWN_NAME
, &Privileges
.Privileges
[0].Luid
))
472 ERR("LookupPrivilegeValue failed\n");
477 /* Assign the Shutdown privilege to our process */
478 Privileges
.PrivilegeCount
= 1;
479 Privileges
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
481 if (!AdjustTokenPrivileges(hToken
, FALSE
, &Privileges
, 0, NULL
, NULL
))
483 ERR("AdjustTokenPrivileges failed\n");
488 /* Finally shut down the system */
489 if (!ExitWindowsEx(EWX_REBOOT
, SHTDN_REASON_MAJOR_OTHER
| SHTDN_REASON_MINOR_OTHER
| SHTDN_REASON_FLAG_PLANNED
))
491 ERR("ExitWindowsEx failed\n");
498 UpdateDriverDlg(IN HWND hwndDlg
,
499 IN PDEVADVPROP_INFO dap
)
501 HDEVINFO DeviceInfoSet
;
502 PSP_DEVINFO_DATA DeviceInfoData
;
504 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
506 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
507 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
511 DeviceInfoSet
= dap
->DeviceInfoSet
;
512 DeviceInfoData
= &dap
->DeviceInfoData
;
515 /* set the device image */
516 SendDlgItemMessage(hwndDlg
,
519 (WPARAM
)dap
->hDevIcon
,
522 /* set the device name edit control text */
523 SetDlgItemText(hwndDlg
,
527 /* query the driver provider */
528 if (GetDriverProviderString(DeviceInfoSet
,
531 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
533 SetDlgItemText(hwndDlg
,
538 /* query the driver date */
539 if (GetDriverDateString(DeviceInfoSet
,
542 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
544 SetDlgItemText(hwndDlg
,
549 /* query the driver version */
550 if (GetDriverVersionString(DeviceInfoSet
,
553 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
555 SetDlgItemText(hwndDlg
,
564 AdvProcDriverDlgProc(IN HWND hwndDlg
,
569 PDEVADVPROP_INFO dap
;
572 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
574 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
580 switch (LOWORD(wParam
))
582 case IDC_DRIVERDETAILS
:
583 DialogBoxParam(hDllInstance
,
584 MAKEINTRESOURCE(IDD_DRIVERDETAILS
),
586 DriverDetailsDlgProc
,
590 case IDC_UPDATEDRIVER
:
591 UpdateDriver(hwndDlg
, dap
);
594 case IDC_ROLLBACKDRIVER
:
598 case IDC_UNINSTALLDRIVER
:
607 NMHDR
*hdr
= (NMHDR
*)lParam
;
618 dap
= (PDEVADVPROP_INFO
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
621 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (DWORD_PTR
)dap
);
623 UpdateDriverDlg(hwndDlg
,
626 EnableWindow(GetDlgItem(hwndDlg
, IDC_ROLLBACKDRIVER
), FALSE
);
627 EnableWindow(GetDlgItem(hwndDlg
, IDC_UNINSTALLDRIVER
), FALSE
);
639 SetListViewText(HWND hwnd
,
645 li
.mask
= LVIF_TEXT
| LVIF_STATE
;
648 li
.state
= 0; //(li.iItem == 0 ? LVIS_SELECTED : 0);
649 li
.stateMask
= LVIS_SELECTED
;
650 li
.pszText
= (LPWSTR
)lpText
;
651 (void)ListView_InsertItem(hwnd
,
657 UpdateDetailsDlg(IN HWND hwndDlg
,
658 IN PDEVADVPROP_INFO dap
)
669 IDS_PROP_HARDWAREIDS
,
670 IDS_PROP_COMPATIBLEIDS
,
671 IDS_PROP_MATCHINGDEVICEID
,
674 IDS_PROP_CAPABILITIES
,
675 IDS_PROP_DEVNODEFLAGS
,
676 IDS_PROP_CONFIGFLAGS
,
677 IDS_PROP_CSCONFIGFLAGS
,
678 IDS_PROP_EJECTIONRELATIONS
,
679 IDS_PROP_REMOVALRELATIONS
,
680 IDS_PROP_BUSRELATIONS
,
681 IDS_PROP_DEVUPPERFILTERS
,
682 IDS_PROP_DEVLOWERFILTERS
,
683 IDS_PROP_CLASSUPPERFILTERS
,
684 IDS_PROP_CLASSLOWERFILTERS
,
685 IDS_PROP_CLASSINSTALLER
,
686 IDS_PROP_CLASSCOINSTALLER
,
687 IDS_PROP_DEVICECOINSTALLER
,
688 IDS_PROP_FIRMWAREREVISION
,
689 IDS_PROP_CURRENTPOWERSTATE
,
690 IDS_PROP_POWERCAPABILITIES
,
691 IDS_PROP_POWERSTATEMAPPINGS
695 /* set the device image */
696 SendDlgItemMessage(hwndDlg
,
699 (WPARAM
)dap
->hDevIcon
,
702 /* set the device name edit control text */
703 SetDlgItemText(hwndDlg
,
708 hwndComboBox
= GetDlgItem(hwndDlg
,
709 IDC_DETAILSPROPNAME
);
711 hwndListView
= GetDlgItem(hwndDlg
,
712 IDC_DETAILSPROPVALUE
);
714 for (i
= 0; i
!= sizeof(Properties
) / sizeof(Properties
[0]); i
++)
716 /* fill in the device usage combo box */
717 if (LoadString(hDllInstance
,
720 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
722 SendMessage(hwndComboBox
,
725 (LPARAM
)dap
->szTemp
);
730 GetClientRect(hwndListView
,
733 /* add a column to the list view control */
734 lvc
.mask
= LVCF_FMT
| LVCF_WIDTH
;
735 lvc
.fmt
= LVCFMT_LEFT
;
736 lvc
.cx
= rcClient
.right
;
737 (void)ListView_InsertColumn(hwndListView
,
741 SendMessage(hwndComboBox
,
746 SetListViewText(hwndListView
, 0, dap
->szDeviceID
);
748 SetFocus(hwndComboBox
);
753 DisplayDevicePropertyText(IN PDEVADVPROP_INFO dap
,
754 IN HWND hwndListView
,
757 HDEVINFO DeviceInfoSet
;
758 PSP_DEVINFO_DATA DeviceInfoData
;
767 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
769 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
770 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
774 DeviceInfoSet
= dap
->DeviceInfoSet
;
775 DeviceInfoData
= &dap
->DeviceInfoData
;
779 SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
788 if (GetLastError() != ERROR_FILE_NOT_FOUND
)
790 swprintf(dap
->szTemp
, L
"Error: Getting the size failed! (Error: %ld)", GetLastError());
791 SetListViewText(hwndListView
, 0, dap
->szTemp
);
796 if (dwType
== REG_SZ
)
797 dwSize
+= sizeof(WCHAR
);
799 lpBuffer
= (LPBYTE
)HeapAlloc(GetProcessHeap(),
802 if (lpBuffer
== NULL
)
804 SetListViewText(hwndListView
, 0, L
"Error: Allocating the buffer failed!");
808 if (SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
816 if (dwType
== REG_SZ
)
818 SetListViewText(hwndListView
, 0, (LPWSTR
)lpBuffer
);
820 else if (dwType
== REG_MULTI_SZ
)
822 lpStr
= (LPWSTR
)lpBuffer
;
826 len
= wcslen(lpStr
) + 1;
828 SetListViewText(hwndListView
, index
, lpStr
);
834 else if (dwType
== REG_DWORD
)
836 dwValue
= *(DWORD
*) lpBuffer
;
840 case SPDRP_CAPABILITIES
:
842 if (dwValue
& CM_DEVCAP_LOCKSUPPORTED
)
843 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_LOCKSUPPORTED");
844 if (dwValue
& CM_DEVCAP_EJECTSUPPORTED
)
845 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_EJECTSUPPORTED");
846 if (dwValue
& CM_DEVCAP_REMOVABLE
)
847 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_REMOVABLE");
848 if (dwValue
& CM_DEVCAP_DOCKDEVICE
)
849 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_DOCKDEVICE");
850 if (dwValue
& CM_DEVCAP_UNIQUEID
)
851 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_UNIQUEID");
852 if (dwValue
& CM_DEVCAP_SILENTINSTALL
)
853 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_SILENTINSTALL");
854 if (dwValue
& CM_DEVCAP_RAWDEVICEOK
)
855 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_RAWDEVICEOK");
856 if (dwValue
& CM_DEVCAP_SURPRISEREMOVALOK
)
857 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_SURPRISEREMOVALOK");
858 if (dwValue
& CM_DEVCAP_HARDWAREDISABLED
)
859 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_HARDWAREDISABLED");
860 if (dwValue
& CM_DEVCAP_NONDYNAMIC
)
861 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_NONDYNAMIC");
864 case SPDRP_CONFIGFLAGS
:
866 if (dwValue
& CONFIGFLAG_DISABLED
)
867 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_DISABLED");
868 if (dwValue
& CONFIGFLAG_REMOVED
)
869 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_REMOVED");
870 if (dwValue
& CONFIGFLAG_MANUAL_INSTALL
)
871 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_MANUAL_INSTALL");
872 if (dwValue
& CONFIGFLAG_IGNORE_BOOT_LC
)
873 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_IGNORE_BOOT_LC");
874 if (dwValue
& CONFIGFLAG_NET_BOOT
)
875 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_NET_BOOT");
876 if (dwValue
& CONFIGFLAG_REINSTALL
)
877 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_REINSTALL");
878 if (dwValue
& CONFIGFLAG_FAILEDINSTALL
)
879 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_FAILEDINSTALL");
880 if (dwValue
& CONFIGFLAG_CANTSTOPACHILD
)
881 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_CANTSTOPACHILD");
882 if (dwValue
& CONFIGFLAG_OKREMOVEROM
)
883 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_OKREMOVEROM");
884 if (dwValue
& CONFIGFLAG_NOREMOVEEXIT
)
885 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_NOREMOVEEXIT");
889 swprintf(dap
->szTemp
, L
"0x%08lx", dwValue
);
890 SetListViewText(hwndListView
, 0, dap
->szTemp
);
896 SetListViewText(hwndListView
, 0, L
"Error: Unsupported value type!");
902 SetListViewText(hwndListView
, 0, L
"Error: Retrieving the value failed!");
905 HeapFree(GetProcessHeap(),
911 DisplayDevNodeFlags(IN PDEVADVPROP_INFO dap
,
912 IN HWND hwndListView
)
918 CM_Get_DevNode_Status_Ex(&dwStatus
,
920 dap
->DeviceInfoData
.DevInst
,
925 if (dwStatus
& DN_ROOT_ENUMERATED
)
926 SetListViewText(hwndListView
, index
++, L
"DN_ROOT_ENUMERATED");
927 if (dwStatus
& DN_DRIVER_LOADED
)
928 SetListViewText(hwndListView
, index
++, L
"DN_DRIVER_LOADED");
929 if (dwStatus
& DN_ENUM_LOADED
)
930 SetListViewText(hwndListView
, index
++, L
"DN_ENUM_LOADED");
931 if (dwStatus
& DN_STARTED
)
932 SetListViewText(hwndListView
, index
++, L
"DN_STARTED");
933 if (dwStatus
& DN_MANUAL
)
934 SetListViewText(hwndListView
, index
++, L
"DN_MANUAL");
935 if (dwStatus
& DN_NEED_TO_ENUM
)
936 SetListViewText(hwndListView
, index
++, L
"DN_NEED_TO_ENUM");
937 if (dwStatus
& DN_DRIVER_BLOCKED
)
938 SetListViewText(hwndListView
, index
++, L
"DN_DRIVER_BLOCKED");
939 if (dwStatus
& DN_HARDWARE_ENUM
)
940 SetListViewText(hwndListView
, index
++, L
"DN_HARDWARE_ENUM");
941 if (dwStatus
& DN_NEED_RESTART
)
942 SetListViewText(hwndListView
, index
++, L
"DN_NEED_RESTART");
943 if (dwStatus
& DN_CHILD_WITH_INVALID_ID
)
944 SetListViewText(hwndListView
, index
++, L
"DN_CHILD_WITH_INVALID_ID");
945 if (dwStatus
& DN_HAS_PROBLEM
)
946 SetListViewText(hwndListView
, index
++, L
"DN_HAS_PROBLEM");
947 if (dwStatus
& DN_FILTERED
)
948 SetListViewText(hwndListView
, index
++, L
"DN_FILTERED");
949 if (dwStatus
& DN_LEGACY_DRIVER
)
950 SetListViewText(hwndListView
, index
++, L
"DN_LEGACY_DRIVER");
951 if (dwStatus
& DN_DISABLEABLE
)
952 SetListViewText(hwndListView
, index
++, L
"DN_DISABLEABLE");
953 if (dwStatus
& DN_REMOVABLE
)
954 SetListViewText(hwndListView
, index
++, L
"DN_REMOVABLE");
955 if (dwStatus
& DN_PRIVATE_PROBLEM
)
956 SetListViewText(hwndListView
, index
++, L
"DN_PRIVATE_PROBLEM");
957 if (dwStatus
& DN_MF_PARENT
)
958 SetListViewText(hwndListView
, index
++, L
"DN_MF_PARENT");
959 if (dwStatus
& DN_MF_CHILD
)
960 SetListViewText(hwndListView
, index
++, L
"DN_MF_CHILD");
961 if (dwStatus
& DN_WILL_BE_REMOVED
)
962 SetListViewText(hwndListView
, index
++, L
"DN_WILL_BE_REMOVED");
964 if (dwStatus
& DN_NOT_FIRST_TIMEE
)
965 SetListViewText(hwndListView
, index
++, L
"DN_NOT_FIRST_TIMEE");
966 if (dwStatus
& DN_STOP_FREE_RES
)
967 SetListViewText(hwndListView
, index
++, L
"DN_STOP_FREE_RES");
968 if (dwStatus
& DN_REBAL_CANDIDATE
)
969 SetListViewText(hwndListView
, index
++, L
"DN_REBAL_CANDIDATE");
970 if (dwStatus
& DN_BAD_PARTIAL
)
971 SetListViewText(hwndListView
, index
++, L
"DN_BAD_PARTIAL");
972 if (dwStatus
& DN_NT_ENUMERATOR
)
973 SetListViewText(hwndListView
, index
++, L
"DN_NT_ENUMERATOR");
974 if (dwStatus
& DN_NT_DRIVER
)
975 SetListViewText(hwndListView
, index
++, L
"DN_NT_DRIVER");
977 if (dwStatus
& DN_NEEDS_LOCKING
)
978 SetListViewText(hwndListView
, index
++, L
"DN_NEEDS_LOCKING");
979 if (dwStatus
& DN_ARM_WAKEUP
)
980 SetListViewText(hwndListView
, index
++, L
"DN_ARM_WAKEUP");
981 if (dwStatus
& DN_APM_ENUMERATOR
)
982 SetListViewText(hwndListView
, index
++, L
"DN_APM_ENUMERATOR");
983 if (dwStatus
& DN_APM_DRIVER
)
984 SetListViewText(hwndListView
, index
++, L
"DN_APM_DRIVER");
985 if (dwStatus
& DN_SILENT_INSTALL
)
986 SetListViewText(hwndListView
, index
++, L
"DN_SILENT_INSTALL");
987 if (dwStatus
& DN_NO_SHOW_IN_DM
)
988 SetListViewText(hwndListView
, index
++, L
"DN_NO_SHOW_IN_DM");
989 if (dwStatus
& DN_BOOT_LOG_PROB
)
990 SetListViewText(hwndListView
, index
++, L
"DN_BOOT_LOG_PROB");
992 // swprintf(dap->szTemp, L"0x%08x", dwStatus);
993 // SetListViewText(hwndListView, 0, dap->szTemp);
998 DisplayDevNodeEnumerator(IN PDEVADVPROP_INFO dap
,
999 IN HWND hwndListView
)
1001 PSP_DEVINFO_DATA DeviceInfoData
;
1004 WCHAR szBuffer
[256];
1005 DWORD dwSize
= 256 * sizeof(WCHAR
);
1007 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1009 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1013 DeviceInfoData
= &dap
->DeviceInfoData
;
1016 CM_Get_DevNode_Registry_Property_ExW(DeviceInfoData
->DevInst
,
1017 CM_DRP_ENUMERATOR_NAME
,
1024 SetListViewText(hwndListView
, 0, szBuffer
);
1029 DisplayCsFlags(IN PDEVADVPROP_INFO dap
,
1030 IN HWND hwndListView
)
1035 CM_Get_HW_Prof_Flags_Ex(dap
->szDevName
,
1036 0, /* current hardware profile */
1042 if (dwValue
& CSCONFIGFLAG_DISABLED
)
1043 SetListViewText(hwndListView
, index
++, L
"CSCONFIGFLAG_DISABLED");
1045 if (dwValue
& CSCONFIGFLAG_DO_NOT_CREATE
)
1046 SetListViewText(hwndListView
, index
++, L
"CSCONFIGFLAG_DO_NOT_CREATE");
1048 if (dwValue
& CSCONFIGFLAG_DO_NOT_START
)
1049 SetListViewText(hwndListView
, index
++, L
"CSCONFIGFLAG_DO_NOT_START");
1054 DisplayMatchingDeviceId(IN PDEVADVPROP_INFO dap
,
1055 IN HWND hwndListView
)
1057 HDEVINFO DeviceInfoSet
;
1058 PSP_DEVINFO_DATA DeviceInfoData
;
1059 WCHAR szBuffer
[256];
1064 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1066 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1067 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1071 DeviceInfoSet
= dap
->DeviceInfoSet
;
1072 DeviceInfoData
= &dap
->DeviceInfoData
;
1075 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
,
1081 if (hKey
!= INVALID_HANDLE_VALUE
)
1083 dwSize
= 256 * sizeof(WCHAR
);
1084 if (RegQueryValueEx(hKey
,
1085 L
"MatchingDeviceId",
1089 &dwSize
) == ERROR_SUCCESS
)
1091 SetListViewText(hwndListView
, 0, szBuffer
);
1100 DisplayClassCoinstallers(IN PDEVADVPROP_INFO dap
,
1101 IN HWND hwndListView
)
1103 HDEVINFO DeviceInfoSet
;
1104 PSP_DEVINFO_DATA DeviceInfoData
;
1105 WCHAR szClassGuid
[45];
1106 HKEY hKey
= (HKEY
)INVALID_HANDLE_VALUE
;
1109 LPBYTE lpBuffer
= NULL
;
1115 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1117 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1118 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1122 DeviceInfoSet
= dap
->DeviceInfoSet
;
1123 DeviceInfoData
= &dap
->DeviceInfoData
;
1126 dwSize
= 45 * sizeof(WCHAR
);
1127 if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
1131 (LPBYTE
)szClassGuid
,
1136 lError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1137 L
"SYSTEM\\CurrentControlSet\\Control\\CoDeviceInstallers",
1141 if (lError
!= ERROR_SUCCESS
)
1145 lError
= RegQueryValueEx(hKey
,
1151 if (lError
!= ERROR_SUCCESS
)
1157 lpBuffer
= (LPBYTE
)HeapAlloc(GetProcessHeap(),
1161 RegQueryValueEx(hKey
,
1168 lpStr
= (LPWSTR
)lpBuffer
;
1172 len
= wcslen(lpStr
) + 1;
1174 SetListViewText(hwndListView
, index
, lpStr
);
1181 if (lpBuffer
!= NULL
)
1182 HeapFree(GetProcessHeap(), 0, lpBuffer
);
1184 if (hKey
!= INVALID_HANDLE_VALUE
)
1190 DisplayDeviceCoinstallers(IN PDEVADVPROP_INFO dap
,
1191 IN HWND hwndListView
)
1193 HDEVINFO DeviceInfoSet
;
1194 PSP_DEVINFO_DATA DeviceInfoData
;
1203 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1205 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1206 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1210 DeviceInfoSet
= dap
->DeviceInfoSet
;
1211 DeviceInfoData
= &dap
->DeviceInfoData
;
1214 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
,
1220 if (hKey
!= INVALID_HANDLE_VALUE
)
1223 if (RegQueryValueEx(hKey
,
1228 &dwSize
) == ERROR_SUCCESS
&&
1232 lpBuffer
= (LPBYTE
)HeapAlloc(GetProcessHeap(),
1236 RegQueryValueEx(hKey
,
1243 lpStr
= (LPWSTR
)lpBuffer
;
1247 len
= wcslen(lpStr
) + 1;
1249 SetListViewText(hwndListView
, index
, lpStr
);
1255 HeapFree(GetProcessHeap(),
1266 DisplayClassProperties(IN PDEVADVPROP_INFO dap
,
1267 IN HWND hwndListView
,
1268 IN LPCWSTR lpProperty
)
1270 HDEVINFO DeviceInfoSet
;
1271 PSP_DEVINFO_DATA DeviceInfoData
;
1272 WCHAR szClassGuid
[45];
1282 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1284 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1285 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1289 DeviceInfoSet
= dap
->DeviceInfoSet
;
1290 DeviceInfoData
= &dap
->DeviceInfoData
;
1293 dwSize
= 45 * sizeof(WCHAR
);
1294 if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
1298 (LPBYTE
)szClassGuid
,
1303 pSetupGuidFromString(szClassGuid
,
1306 hKey
= SetupDiOpenClassRegKey(&ClassGuid
,
1308 if (hKey
!= INVALID_HANDLE_VALUE
)
1311 if (RegQueryValueEx(hKey
,
1316 &dwSize
) == ERROR_SUCCESS
&&
1319 lpBuffer
= (LPBYTE
)HeapAlloc(GetProcessHeap(),
1323 RegQueryValueEx(hKey
,
1330 if (dwType
== REG_SZ
)
1332 SetListViewText(hwndListView
, 0, (LPWSTR
)lpBuffer
);
1334 else if (dwType
== REG_MULTI_SZ
)
1336 lpStr
= (LPWSTR
)lpBuffer
;
1340 len
= wcslen(lpStr
) + 1;
1342 SetListViewText(hwndListView
, index
, lpStr
);
1349 HeapFree(GetProcessHeap(),
1360 DisplayDeviceRelations(
1361 IN PDEVADVPROP_INFO dap
,
1362 IN HWND hwndListView
,
1366 LPWSTR pszBuffer
= NULL
, pszStr
;
1370 ret
= CM_Get_Device_ID_List_Size_ExW(&ulLength
,
1374 if (ret
!= CR_SUCCESS
)
1377 pszBuffer
= (LPWSTR
)HeapAlloc(GetProcessHeap(),
1379 ulLength
* sizeof(WCHAR
));
1380 if (pszBuffer
== NULL
)
1383 ret
= CM_Get_Device_ID_List_ExW(dap
->szDeviceID
,
1388 if (ret
!= CR_SUCCESS
)
1390 HeapFree(GetProcessHeap(), 0, pszBuffer
);
1396 while (*pszStr
!= 0)
1398 len
= wcslen(pszStr
) + 1;
1400 SetListViewText(hwndListView
, index
, pszStr
);
1406 HeapFree(GetProcessHeap(), 0, pszBuffer
);
1411 DisplayCurrentPowerState(
1412 IN PDEVADVPROP_INFO dap
,
1413 IN HWND hwndListView
)
1415 HDEVINFO DeviceInfoSet
;
1416 PSP_DEVINFO_DATA DeviceInfoData
;
1417 CM_POWER_DATA PowerData
;
1418 DWORD dwSize
, dwType
;
1419 PCWSTR lpText
= NULL
;
1421 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1423 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1424 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1428 DeviceInfoSet
= dap
->DeviceInfoSet
;
1429 DeviceInfoData
= &dap
->DeviceInfoData
;
1432 dwSize
= sizeof(CM_POWER_DATA
);
1433 if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
1435 SPDRP_DEVICE_POWER_DATA
,
1442 switch (PowerData
.PD_MostRecentPowerState
)
1444 // case PowerDeviceUnspecified:
1467 SetListViewText(hwndListView
, 0, lpText
);
1472 DisplayPowerCapabilities(
1473 IN PDEVADVPROP_INFO dap
,
1474 IN HWND hwndListView
)
1476 HDEVINFO DeviceInfoSet
;
1477 PSP_DEVINFO_DATA DeviceInfoData
;
1478 CM_POWER_DATA PowerData
;
1479 DWORD dwSize
, dwType
;
1482 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1484 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1485 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1489 DeviceInfoSet
= dap
->DeviceInfoSet
;
1490 DeviceInfoData
= &dap
->DeviceInfoData
;
1493 dwSize
= sizeof(CM_POWER_DATA
);
1494 if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
1496 SPDRP_DEVICE_POWER_DATA
,
1503 if (PowerData
.PD_Capabilities
& PDCAP_D0_SUPPORTED
)
1504 SetListViewText(hwndListView
, index
++, L
"PDCAP_D0_SUPPORTED");
1506 if (PowerData
.PD_Capabilities
& PDCAP_D1_SUPPORTED
)
1507 SetListViewText(hwndListView
, index
++, L
"PDCAP_D1_SUPPORTED");
1509 if (PowerData
.PD_Capabilities
& PDCAP_D2_SUPPORTED
)
1510 SetListViewText(hwndListView
, index
++, L
"PDCAP_D2_SUPPORTED");
1512 if (PowerData
.PD_Capabilities
& PDCAP_D3_SUPPORTED
)
1513 SetListViewText(hwndListView
, index
++, L
"PDCAP_D3_SUPPORTED");
1515 if (PowerData
.PD_Capabilities
& PDCAP_WAKE_FROM_D0_SUPPORTED
)
1516 SetListViewText(hwndListView
, index
++, L
"PDCAP_WAKE_FROM_D0_SUPPORTED");
1518 if (PowerData
.PD_Capabilities
& PDCAP_WAKE_FROM_D1_SUPPORTED
)
1519 SetListViewText(hwndListView
, index
++, L
"PDCAP_WAKE_FROM_D1_SUPPORTED");
1521 if (PowerData
.PD_Capabilities
& PDCAP_WAKE_FROM_D2_SUPPORTED
)
1522 SetListViewText(hwndListView
, index
++, L
"PDCAP_WAKE_FROM_D2_SUPPORTED");
1524 if (PowerData
.PD_Capabilities
& PDCAP_WAKE_FROM_D3_SUPPORTED
)
1525 SetListViewText(hwndListView
, index
++, L
"PDCAP_WAKE_FROM_D3_SUPPORTED");
1527 if (PowerData
.PD_Capabilities
& PDCAP_WARM_EJECT_SUPPORTED
)
1528 SetListViewText(hwndListView
, index
++, L
"PDCAP_WARM_EJECT_SUPPORTED");
1533 DisplayPowerStateMappings(
1534 IN PDEVADVPROP_INFO dap
,
1535 IN HWND hwndListView
)
1537 HDEVINFO DeviceInfoSet
;
1538 PSP_DEVINFO_DATA DeviceInfoData
;
1539 CM_POWER_DATA PowerData
;
1540 DWORD dwSize
, dwType
;
1542 DEVICE_POWER_STATE PowerState
;
1543 WCHAR szSystemStateBuffer
[40];
1544 WCHAR szDeviceStateBuffer
[40];
1545 WCHAR szOutBuffer
[100];
1547 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1549 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1550 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1554 DeviceInfoSet
= dap
->DeviceInfoSet
;
1555 DeviceInfoData
= &dap
->DeviceInfoData
;
1558 dwSize
= sizeof(CM_POWER_DATA
);
1559 if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
1561 SPDRP_DEVICE_POWER_DATA
,
1568 for (i
= PowerSystemWorking
; i
< PowerSystemMaximum
; i
++)
1570 PowerState
= PowerData
.PD_PowerStateMapping
[i
];
1571 if ((PowerState
>= PowerDeviceUnspecified
) && (PowerState
<= PowerDeviceD3
))
1573 swprintf(szSystemStateBuffer
, L
"S%u", i
- 1);
1577 case PowerDeviceUnspecified
:
1578 wcscpy(szDeviceStateBuffer
, L
"Not specified");
1582 wcscpy(szDeviceStateBuffer
, L
"D0");
1586 wcscpy(szDeviceStateBuffer
, L
"D1");
1590 wcscpy(szDeviceStateBuffer
, L
"D2");
1594 wcscpy(szDeviceStateBuffer
, L
"D3");
1601 swprintf(szOutBuffer
, L
"%s -> %s", szSystemStateBuffer
, szDeviceStateBuffer
);
1602 SetListViewText(hwndListView
, i
, szOutBuffer
);
1609 DisplayDeviceProperties(IN PDEVADVPROP_INFO dap
,
1610 IN HWND hwndComboBox
,
1611 IN HWND hwndListView
)
1615 Index
= (INT
)SendMessage(hwndComboBox
,
1619 if (Index
== CB_ERR
)
1622 (void)ListView_DeleteAllItems(hwndListView
);
1626 case 0: /* Device ID */
1627 SetListViewText(hwndListView
, 0, dap
->szDeviceID
);
1630 case 1: /* Hardware ID */
1631 DisplayDevicePropertyText(dap
,
1636 case 2: /* Compatible IDs */
1637 DisplayDevicePropertyText(dap
,
1639 SPDRP_COMPATIBLEIDS
);
1642 case 3: /* Matching ID */
1643 DisplayMatchingDeviceId(dap
,
1647 case 4: /* Service */
1648 DisplayDevicePropertyText(dap
,
1653 case 5: /* Enumerator */
1654 DisplayDevNodeEnumerator(dap
,
1658 case 6: /* Capabilities */
1659 DisplayDevicePropertyText(dap
,
1661 SPDRP_CAPABILITIES
);
1664 case 7: /* Devnode Flags */
1665 DisplayDevNodeFlags(dap
,
1669 case 8: /* Config Flags */
1670 DisplayDevicePropertyText(dap
,
1675 case 9: /* CSConfig Flags */
1680 case 10: /* Ejection relation */
1681 DisplayDeviceRelations(dap
,
1683 CM_GETIDLIST_FILTER_EJECTRELATIONS
);
1686 case 11: /* Removal relations */
1687 DisplayDeviceRelations(dap
,
1689 CM_GETIDLIST_FILTER_REMOVALRELATIONS
);
1692 case 12: /* Bus relation */
1693 DisplayDeviceRelations(dap
,
1695 CM_GETIDLIST_FILTER_BUSRELATIONS
);
1698 case 13: /* Device Upper Filters */
1699 DisplayDevicePropertyText(dap
,
1701 SPDRP_UPPERFILTERS
);
1704 case 14: /* Device Lower Filters */
1705 DisplayDevicePropertyText(dap
,
1707 SPDRP_LOWERFILTERS
);
1710 case 15: /* Class Upper Filters */
1711 DisplayClassProperties(dap
,
1716 case 16: /* Class Lower Filters */
1717 DisplayClassProperties(dap
,
1722 case 17: /* Class Installer */
1723 DisplayClassProperties(dap
,
1728 case 18: /* Class Coinstaller */
1729 DisplayClassCoinstallers(dap
,
1733 case 19: /* Device Coinstaller */
1734 DisplayDeviceCoinstallers(dap
,
1739 case 20: /* Firmware Revision */
1743 case 21: /* Current Power State */
1744 DisplayCurrentPowerState(dap
,
1748 case 22: /* Power Capabilities */
1749 DisplayPowerCapabilities(dap
,
1753 case 23: /* Power State Mappings */
1754 DisplayPowerStateMappings(dap
,
1759 SetListViewText(hwndListView
, 0, L
"<Not implemented yet>");
1767 AdvProcDetailsDlgProc(IN HWND hwndDlg
,
1772 PDEVADVPROP_INFO dap
;
1773 INT_PTR Ret
= FALSE
;
1775 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
1777 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
1783 switch (LOWORD(wParam
))
1785 case IDC_DETAILSPROPNAME
:
1786 if (HIWORD(wParam
) == CBN_SELCHANGE
)
1788 DisplayDeviceProperties(dap
,
1789 GetDlgItem(hwndDlg
, IDC_DETAILSPROPNAME
),
1790 GetDlgItem(hwndDlg
, IDC_DETAILSPROPVALUE
));
1799 NMHDR
*hdr
= (NMHDR
*)lParam
;
1810 dap
= (PDEVADVPROP_INFO
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1813 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (DWORD_PTR
)dap
);
1815 UpdateDetailsDlg(hwndDlg
,
1829 InitDevUsageActions(IN HWND hwndDlg
,
1831 IN PDEVADVPROP_INFO dap
)
1842 i
!= sizeof(Actions
) / sizeof(Actions
[0]);
1845 /* fill in the device usage combo box */
1846 if (LoadString(hDllInstance
,
1849 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1851 Index
= (INT
)SendMessage(hComboBox
,
1854 (LPARAM
)dap
->szTemp
);
1855 if (Index
!= CB_ERR
)
1857 SendMessage(hComboBox
,
1860 (LPARAM
)Actions
[i
]);
1864 case IDS_ENABLEDEVICE
:
1865 if (dap
->DeviceStarted
)
1867 SendMessage(hComboBox
,
1874 case IDS_DISABLEDEVICE
:
1875 if (!dap
->DeviceStarted
)
1877 SendMessage(hComboBox
,
1894 GetSelectedUsageAction(IN HWND hComboBox
)
1899 Index
= (INT
)SendMessage(hComboBox
,
1903 if (Index
!= CB_ERR
)
1905 INT iRet
= (INT
) SendMessage(hComboBox
,
1920 ApplyGeneralSettings(IN HWND hwndDlg
,
1921 IN PDEVADVPROP_INFO dap
)
1925 if (dap
->DeviceUsageChanged
&& dap
->IsAdmin
&& dap
->CanDisable
)
1927 UINT SelectedUsageAction
;
1928 BOOL NeedReboot
= FALSE
;
1930 SelectedUsageAction
= GetSelectedUsageAction(GetDlgItem(hwndDlg
,
1932 switch (SelectedUsageAction
)
1934 case IDS_ENABLEDEVICE
:
1935 if (!dap
->DeviceStarted
)
1937 Ret
= EnableDevice(dap
->DeviceInfoSet
,
1938 &dap
->DeviceInfoData
,
1945 case IDS_DISABLEDEVICE
:
1946 if (dap
->DeviceStarted
)
1948 Ret
= EnableDevice(dap
->DeviceInfoSet
,
1949 &dap
->DeviceInfoData
,
1964 /* make PropertySheet() return PSM_REBOOTSYSTEM */
1965 PropSheet_RebootSystem(hwndDlg
);
1970 /* FIXME - display an error message */
1971 FIXME("Failed to enable/disable device! LastError: %d\n",
1976 Ret
= !dap
->DeviceUsageChanged
;
1978 /* disable the apply button */
1979 PropSheet_UnChanged(GetParent(hwndDlg
),
1981 dap
->DeviceUsageChanged
= FALSE
;
1987 UpdateDevInfo(IN HWND hwndDlg
,
1988 IN PDEVADVPROP_INFO dap
,
1991 HWND hDevUsage
, hPropSheetDlg
, hDevProbBtn
;
1993 ULONG Status
, ProblemNumber
;
1994 SP_DEVINSTALL_PARAMS_W InstallParams
;
1995 UINT TroubleShootStrId
= IDS_TROUBLESHOOTDEV
;
1996 BOOL bFlag
, bDevActionAvailable
= TRUE
;
1997 BOOL bDrvInstalled
= FALSE
;
1999 HDEVINFO DeviceInfoSet
= NULL
;
2000 PSP_DEVINFO_DATA DeviceInfoData
= NULL
;
2001 PROPSHEETHEADER psh
;
2002 DWORD nDriverPages
= 0;
2003 BOOL RecalcPages
= FALSE
;
2005 hPropSheetDlg
= GetParent(hwndDlg
);
2007 if (dap
->PageInitialized
)
2009 /* switch to the General page */
2010 PropSheet_SetCurSelByID(hPropSheetDlg
,
2013 /* remove and destroy the existing device property sheet pages */
2014 if (dap
->DevPropSheets
!= NULL
)
2017 iPage
!= dap
->nDevPropSheets
;
2020 if (dap
->DevPropSheets
[iPage
] != NULL
)
2022 PropSheet_RemovePage(hPropSheetDlg
,
2024 dap
->DevPropSheets
[iPage
]);
2033 if (dap
->FreeDevPropSheets
)
2035 /* don't free the array if it's the one allocated in
2036 DisplayDeviceAdvancedProperties */
2037 HeapFree(GetProcessHeap(),
2039 dap
->DevPropSheets
);
2041 dap
->FreeDevPropSheets
= FALSE
;
2044 dap
->DevPropSheets
= NULL
;
2045 dap
->nDevPropSheets
= 0;
2049 /* create a new device info set and re-open the device */
2050 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
2052 SetupDiDestroyDeviceInfoList(dap
->CurrentDeviceInfoSet
);
2055 dap
->ParentDevInst
= 0;
2056 dap
->CurrentDeviceInfoSet
= SetupDiCreateDeviceInfoListEx(NULL
,
2060 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
2062 if (SetupDiOpenDeviceInfo(dap
->CurrentDeviceInfoSet
,
2066 &dap
->CurrentDeviceInfoData
))
2068 if (dap
->CloseDevInst
)
2070 SetupDiDestroyDeviceInfoList(dap
->DeviceInfoSet
);
2073 dap
->CloseDevInst
= TRUE
;
2074 dap
->DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
2075 dap
->DeviceInfoData
= dap
->CurrentDeviceInfoData
;
2076 dap
->CurrentDeviceInfoSet
= INVALID_HANDLE_VALUE
;
2084 /* get the parent node from the initial devinst */
2085 CM_Get_Parent_Ex(&dap
->ParentDevInst
,
2086 dap
->DeviceInfoData
.DevInst
,
2091 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
2093 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
2094 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
2098 DeviceInfoSet
= dap
->DeviceInfoSet
;
2099 DeviceInfoData
= &dap
->DeviceInfoData
;
2104 DeviceInfoSet
= dap
->DeviceInfoSet
;
2105 DeviceInfoData
= &dap
->DeviceInfoData
;
2108 dap
->HasDriverPage
= FALSE
;
2109 dap
->HasResourcePage
= FALSE
;
2110 dap
->HasPowerPage
= FALSE
;
2111 if (IsDriverInstalled(DeviceInfoData
->DevInst
,
2116 if (SetupDiCallClassInstaller((dap
->ShowRemotePages
?
2117 DIF_ADDREMOTEPROPERTYPAGE_ADVANCED
:
2118 DIF_ADDPROPERTYPAGE_ADVANCED
),
2122 /* get install params */
2123 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
2124 if (!SetupDiGetDeviceInstallParamsW(DeviceInfoSet
,
2128 /* zero the flags */
2129 InstallParams
.Flags
= 0;
2132 dap
->HasDriverPage
= !(InstallParams
.Flags
& DI_DRIVERPAGE_ADDED
);
2133 dap
->HasResourcePage
= !(InstallParams
.Flags
& DI_RESOURCEPAGE_ADDED
);
2134 dap
->HasPowerPage
= !(InstallParams
.Flags
& DI_FLAGSEX_POWERPAGE_ADDED
);
2138 /* get the device icon */
2139 if (dap
->hDevIcon
!= NULL
)
2141 DestroyIcon(dap
->hDevIcon
);
2142 dap
->hDevIcon
= NULL
;
2144 if (!SetupDiLoadClassIcon(&DeviceInfoData
->ClassGuid
,
2148 dap
->hDevIcon
= NULL
;
2151 /* get the device name */
2152 if (GetDeviceDescriptionString(DeviceInfoSet
,
2155 sizeof(dap
->szDevName
) / sizeof(dap
->szDevName
[0])))
2157 PropSheet_SetTitle(hPropSheetDlg
,
2162 /* set the device image */
2163 SendDlgItemMessage(hwndDlg
,
2166 (WPARAM
)dap
->hDevIcon
,
2169 /* set the device name edit control text */
2170 SetDlgItemText(hwndDlg
,
2174 /* set the device type edit control text */
2175 if (GetDeviceTypeString(DeviceInfoData
,
2177 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
2179 SetDlgItemText(hwndDlg
,
2184 /* set the device manufacturer edit control text */
2185 if (GetDeviceManufacturerString(DeviceInfoSet
,
2188 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
2190 SetDlgItemText(hwndDlg
,
2191 IDC_DEVMANUFACTURER
,
2195 /* set the device location edit control text */
2196 if (GetDeviceLocationString(DeviceInfoSet
,
2200 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
2202 SetDlgItemText(hwndDlg
,
2207 /* set the device status edit control text */
2208 if (GetDeviceStatusString(DeviceInfoData
->DevInst
,
2211 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
2213 SetDlgItemText(hwndDlg
,
2218 /* set the device troubleshoot button text and disable it if necessary */
2219 hDevProbBtn
= GetDlgItem(hwndDlg
,
2221 cr
= CM_Get_DevNode_Status_Ex(&Status
,
2223 DeviceInfoData
->DevInst
,
2226 if (cr
== CR_SUCCESS
&& (Status
& DN_HAS_PROBLEM
))
2228 switch (ProblemNumber
)
2230 case CM_PROB_DEVLOADER_FAILED
:
2232 /* FIXME - only if it's not a root bus devloader,
2233 disable the button otherwise */
2234 TroubleShootStrId
= IDS_UPDATEDRV
;
2238 case CM_PROB_OUT_OF_MEMORY
:
2239 case CM_PROB_ENTRY_IS_WRONG_TYPE
:
2240 case CM_PROB_LACKED_ARBITRATOR
:
2241 case CM_PROB_FAILED_START
:
2243 case CM_PROB_UNKNOWN_RESOURCE
:
2245 TroubleShootStrId
= IDS_UPDATEDRV
;
2249 case CM_PROB_BOOT_CONFIG_CONFLICT
:
2250 case CM_PROB_NORMAL_CONFLICT
:
2251 case CM_PROB_REENUMERATION
:
2253 /* FIXME - Troubleshoot conflict */
2257 case CM_PROB_FAILED_FILTER
:
2258 case CM_PROB_REINSTALL
:
2259 case CM_PROB_FAILED_INSTALL
:
2261 TroubleShootStrId
= IDS_REINSTALLDRV
;
2265 case CM_PROB_DEVLOADER_NOT_FOUND
:
2268 1) if it's a missing system devloader:
2269 - disable the button (Reinstall Driver)
2270 2) if it's not a system devloader but still missing:
2272 3) if it's not a system devloader but the file can be found:
2274 4) if it's a missing or empty software key
2280 case CM_PROB_INVALID_DATA
:
2281 case CM_PROB_PARTIAL_LOG_CONF
:
2282 case CM_PROB_NO_VALID_LOG_CONF
:
2283 case CM_PROB_HARDWARE_DISABLED
:
2284 case CM_PROB_CANT_SHARE_IRQ
:
2285 case CM_PROB_TRANSLATION_FAILED
:
2286 case CM_PROB_SYSTEM_SHUTDOWN
:
2287 case CM_PROB_PHANTOM
:
2288 bDevActionAvailable
= FALSE
;
2291 case CM_PROB_NOT_VERIFIED
:
2292 case CM_PROB_DEVICE_NOT_THERE
:
2293 /* FIXME - search hardware */
2296 case CM_PROB_NEED_RESTART
:
2297 case CM_PROB_WILL_BE_REMOVED
:
2299 case CM_PROB_TOO_EARLY
:
2300 case CM_PROB_DISABLED_SERVICE
:
2301 TroubleShootStrId
= IDS_REBOOT
;
2304 case CM_PROB_REGISTRY
:
2305 /* FIXME - check registry? */
2308 case CM_PROB_DISABLED
:
2309 /* if device was disabled by the user: */
2310 TroubleShootStrId
= IDS_ENABLEDEV
;
2311 /* FIXME - otherwise disable button because the device was
2312 disabled by the system*/
2315 case CM_PROB_DEVLOADER_NOT_READY
:
2316 /* FIXME - if it's a graphics adapter:
2317 - if it's a a secondary adapter and the main adapter
2327 case CM_PROB_FAILED_ADD
:
2328 TroubleShootStrId
= IDS_PROPERTIES
;
2333 if (LoadString(hDllInstance
,
2336 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])) != 0)
2338 SetWindowText(hDevProbBtn
,
2341 EnableWindow(hDevProbBtn
,
2342 dap
->IsAdmin
&& bDevActionAvailable
);
2344 /* check if the device can be enabled/disabled */
2345 hDevUsage
= GetDlgItem(hwndDlg
,
2348 dap
->CanDisable
= FALSE
;
2349 dap
->DeviceStarted
= FALSE
;
2351 if (CanDisableDevice(DeviceInfoData
->DevInst
,
2355 dap
->CanDisable
= bFlag
;
2358 if (IsDeviceStarted(DeviceInfoData
->DevInst
,
2362 dap
->DeviceStarted
= bFlag
;
2365 /* enable/disable the device usage controls */
2366 EnableWindow(GetDlgItem(hwndDlg
,
2368 dap
->CanDisable
&& dap
->IsAdmin
);
2369 EnableWindow(hDevUsage
,
2370 dap
->CanDisable
&& dap
->IsAdmin
);
2372 /* clear the combobox */
2373 SendMessage(hDevUsage
,
2377 if (dap
->CanDisable
)
2379 InitDevUsageActions(hwndDlg
,
2384 /* find out how many new device property sheets to add.
2385 fake a PROPSHEETHEADER structure, we don't plan to
2386 call PropertySheet again!*/
2387 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
2391 /* get the number of device property sheets for the device */
2392 if (!SetupDiGetClassDevPropertySheets(DeviceInfoSet
,
2397 dap
->PropertySheetType
) &&
2398 nDriverPages
!= 0 && GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
2400 dap
->nDevPropSheets
+= nDriverPages
;
2407 /* include the driver page */
2408 if (dap
->HasDriverPage
)
2409 dap
->nDevPropSheets
++;
2411 /* include the details page */
2413 dap
->nDevPropSheets
++;
2415 if (dap
->HasResourcePage
)
2416 dap
->nDevPropSheets
++;
2418 /* add the device property sheets */
2419 if (dap
->nDevPropSheets
!= 0)
2421 dap
->DevPropSheets
= (HPROPSHEETPAGE
*)HeapAlloc(GetProcessHeap(),
2423 dap
->nDevPropSheets
* sizeof(HPROPSHEETPAGE
));
2424 if (dap
->DevPropSheets
!= NULL
)
2426 if (nDriverPages
!= 0)
2428 psh
.phpage
= dap
->DevPropSheets
;
2430 /* query the device property sheet pages to add */
2431 if (SetupDiGetClassDevPropertySheets(DeviceInfoSet
,
2434 dap
->nDevPropSheets
,
2436 dap
->PropertySheetType
))
2438 /* add the property sheets */
2440 iPage
< nDriverPages
;
2443 if (PropSheet_AddPage(hPropSheetDlg
,
2444 dap
->DevPropSheets
[iPage
]))
2450 dap
->FreeDevPropSheets
= TRUE
;
2454 /* cleanup, we were unable to get the device property sheets */
2455 iPage
= nDriverPages
;
2456 dap
->nDevPropSheets
-= nDriverPages
;
2463 /* add the driver page if necessary */
2464 if (dap
->HasDriverPage
)
2466 PROPSHEETPAGE pspDriver
= {0};
2467 pspDriver
.dwSize
= sizeof(PROPSHEETPAGE
);
2468 pspDriver
.dwFlags
= PSP_DEFAULT
;
2469 pspDriver
.hInstance
= hDllInstance
;
2470 pspDriver
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICEDRIVER
);
2471 pspDriver
.pfnDlgProc
= AdvProcDriverDlgProc
;
2472 pspDriver
.lParam
= (LPARAM
)dap
;
2473 dap
->DevPropSheets
[iPage
] = dap
->pCreatePropertySheetPageW(&pspDriver
);
2474 if (dap
->DevPropSheets
[iPage
] != NULL
)
2476 if (PropSheet_AddPage(hPropSheetDlg
,
2477 dap
->DevPropSheets
[iPage
]))
2484 dap
->pDestroyPropertySheetPage(dap
->DevPropSheets
[iPage
]);
2485 dap
->DevPropSheets
[iPage
] = NULL
;
2492 /* Add the details page */
2493 PROPSHEETPAGE pspDetails
= {0};
2494 pspDetails
.dwSize
= sizeof(PROPSHEETPAGE
);
2495 pspDetails
.dwFlags
= PSP_DEFAULT
;
2496 pspDetails
.hInstance
= hDllInstance
;
2497 pspDetails
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICEDETAILS
);
2498 pspDetails
.pfnDlgProc
= AdvProcDetailsDlgProc
;
2499 pspDetails
.lParam
= (LPARAM
)dap
;
2500 dap
->DevPropSheets
[iPage
] = dap
->pCreatePropertySheetPageW(&pspDetails
);
2501 if (dap
->DevPropSheets
[iPage
] != NULL
)
2503 if (PropSheet_AddPage(hPropSheetDlg
,
2504 dap
->DevPropSheets
[iPage
]))
2511 dap
->pDestroyPropertySheetPage(dap
->DevPropSheets
[iPage
]);
2512 dap
->DevPropSheets
[iPage
] = NULL
;
2517 if (dap
->HasResourcePage
)
2519 PROPSHEETPAGE pspDriver
= {0};
2520 pspDriver
.dwSize
= sizeof(PROPSHEETPAGE
);
2521 pspDriver
.dwFlags
= PSP_DEFAULT
;
2522 pspDriver
.hInstance
= hDllInstance
;
2523 pspDriver
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICERESOURCES
);
2524 pspDriver
.pfnDlgProc
= ResourcesProcDriverDlgProc
;
2525 pspDriver
.lParam
= (LPARAM
)dap
;
2526 dap
->DevPropSheets
[iPage
] = dap
->pCreatePropertySheetPageW(&pspDriver
);
2527 if (dap
->DevPropSheets
[iPage
] != NULL
)
2529 if (PropSheet_AddPage(hPropSheetDlg
,
2530 dap
->DevPropSheets
[iPage
]))
2537 dap
->pDestroyPropertySheetPage(dap
->DevPropSheets
[iPage
]);
2538 dap
->DevPropSheets
[iPage
] = NULL
;
2542 /* FIXME: Add the power page */
2545 dap
->nDevPropSheets
= 0;
2550 PropSheet_RecalcPageSizes(hPropSheetDlg
);
2553 /* finally, disable the apply button */
2554 PropSheet_UnChanged(hPropSheetDlg
,
2556 dap
->DeviceUsageChanged
= FALSE
;
2562 DlgParentSubWndProc(IN HWND hwnd
,
2567 PDEVADVPROP_INFO dap
;
2569 dap
= (PDEVADVPROP_INFO
)GetProp(hwnd
,
2570 L
"DevMgrDevChangeSub");
2573 if (uMsg
== WM_DEVICECHANGE
&& !IsWindowVisible(dap
->hWndGeneralPage
))
2575 SendMessage(dap
->hWndGeneralPage
,
2581 /* pass the message the the old window proc */
2582 return CallWindowProc(dap
->ParentOldWndProc
,
2590 /* this is not a good idea if the subclassed window was an ansi
2591 window, but we failed finding out the previous window proc
2592 so we can't use CallWindowProc. This should rarely - if ever -
2595 return DefWindowProc(hwnd
,
2605 AdvPropGeneralDlgProc(IN HWND hwndDlg
,
2610 PDEVADVPROP_INFO dap
;
2611 INT_PTR Ret
= FALSE
;
2613 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
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
, DWLP_USER
, (DWORD_PTR
)dap
);
2674 /* subclass the parent window to always receive
2675 WM_DEVICECHANGE messages */
2676 hWndParent
= GetParent(hwndDlg
);
2677 if (hWndParent
!= NULL
)
2679 /* subclass the parent window. This is not safe
2680 if the parent window belongs to another thread! */
2681 dap
->ParentOldWndProc
= (WNDPROC
)SetWindowLongPtr(hWndParent
,
2683 (LONG_PTR
)DlgParentSubWndProc
);
2685 if (dap
->ParentOldWndProc
!= NULL
&&
2687 L
"DevMgrDevChangeSub",
2690 dap
->hWndParent
= hWndParent
;
2694 /* do not call UpdateDevInfo directly in here because it modifies
2695 the pages of the property sheet! */
2696 PostMessage(hwndDlg
,
2705 case WM_DEVICECHANGE
:
2707 /* FIXME - don't call UpdateDevInfo for all events */
2708 UpdateDevInfo(hwndDlg
,
2717 UpdateDevInfo(hwndDlg
,
2720 dap
->PageInitialized
= TRUE
;
2726 /* restore the old window proc of the subclassed parent window */
2727 if (dap
->hWndParent
!= NULL
&& dap
->ParentOldWndProc
!= NULL
)
2729 if (SetWindowLongPtr(dap
->hWndParent
,
2731 (LONG_PTR
)dap
->ParentOldWndProc
) == (LONG_PTR
)DlgParentSubWndProc
)
2733 RemoveProp(dap
->hWndParent
,
2734 L
"DevMgrDevChangeSub");
2747 DisplayDeviceAdvancedProperties(IN HWND hWndParent
,
2748 IN LPCWSTR lpDeviceID OPTIONAL
,
2749 IN HDEVINFO DeviceInfoSet
,
2750 IN PSP_DEVINFO_DATA DeviceInfoData
,
2751 IN HINSTANCE hComCtl32
,
2752 IN LPCWSTR lpMachineName
,
2755 PROPSHEETHEADER psh
= {0};
2756 PROPSHEETPAGE pspGeneral
= {0};
2757 PPROPERTYSHEETW pPropertySheetW
;
2758 PCREATEPROPERTYSHEETPAGEW pCreatePropertySheetPageW
;
2759 PDESTROYPROPERTYSHEETPAGE pDestroyPropertySheetPage
;
2760 PDEVADVPROP_INFO DevAdvPropInfo
;
2761 HMACHINE hMachine
= NULL
;
2762 DWORD DevIdSize
= 0;
2765 /* we don't want to statically link against comctl32, so find the
2766 functions we need dynamically */
2768 (PPROPERTYSHEETW
)GetProcAddress(hComCtl32
,
2770 pCreatePropertySheetPageW
=
2771 (PCREATEPROPERTYSHEETPAGEW
)GetProcAddress(hComCtl32
,
2772 "CreatePropertySheetPageW");
2773 pDestroyPropertySheetPage
=
2774 (PDESTROYPROPERTYSHEETPAGE
)GetProcAddress(hComCtl32
,
2775 "DestroyPropertySheetPage");
2776 if (pPropertySheetW
== NULL
||
2777 pCreatePropertySheetPageW
== NULL
||
2778 pDestroyPropertySheetPage
== NULL
)
2783 if (lpDeviceID
== NULL
)
2785 /* find out how much size is needed for the device id */
2786 if (SetupDiGetDeviceInstanceId(DeviceInfoSet
,
2792 ERR("SetupDiGetDeviceInstanceId unexpectedly returned TRUE!\n");
2796 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
2803 DevIdSize
= (DWORD
)wcslen(lpDeviceID
) + 1;
2806 if (lpMachineName
!= NULL
&& lpMachineName
[0] != L
'\0')
2808 CONFIGRET cr
= CM_Connect_Machine(lpMachineName
,
2810 if (cr
!= CR_SUCCESS
)
2816 /* create the internal structure associated with the "General",
2817 "Driver", ... pages */
2818 DevAdvPropInfo
= (PDEVADVPROP_INFO
)HeapAlloc(GetProcessHeap(),
2820 FIELD_OFFSET(DEVADVPROP_INFO
,
2822 (DevIdSize
* sizeof(WCHAR
)));
2823 if (DevAdvPropInfo
== NULL
)
2825 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2829 if (lpDeviceID
== NULL
)
2831 /* read the device instance id */
2832 if (!SetupDiGetDeviceInstanceId(DeviceInfoSet
,
2834 DevAdvPropInfo
->szDeviceID
,
2843 /* copy the device instance id supplied by the caller */
2844 wcscpy(DevAdvPropInfo
->szDeviceID
,
2848 DevAdvPropInfo
->DeviceInfoSet
= DeviceInfoSet
;
2849 DevAdvPropInfo
->DeviceInfoData
= *DeviceInfoData
;
2850 DevAdvPropInfo
->CurrentDeviceInfoSet
= INVALID_HANDLE_VALUE
;
2851 DevAdvPropInfo
->CurrentDeviceInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
2853 DevAdvPropInfo
->ShowRemotePages
= (lpMachineName
!= NULL
&& lpMachineName
[0] != L
'\0');
2854 DevAdvPropInfo
->hMachine
= hMachine
;
2855 DevAdvPropInfo
->lpMachineName
= lpMachineName
;
2856 DevAdvPropInfo
->szDevName
[0] = L
'\0';
2857 DevAdvPropInfo
->hComCtl32
= hComCtl32
;
2858 DevAdvPropInfo
->pCreatePropertySheetPageW
= pCreatePropertySheetPageW
;
2859 DevAdvPropInfo
->pDestroyPropertySheetPage
= pDestroyPropertySheetPage
;
2861 DevAdvPropInfo
->IsAdmin
= TRUE
;// IsUserAdmin();
2862 DevAdvPropInfo
->DoDefaultDevAction
= ((dwFlags
& DPF_DEVICE_STATUS_ACTION
) != 0);
2863 DevAdvPropInfo
->Extended
= ((dwFlags
& DPF_EXTENDED
) != 0);
2865 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
2866 psh
.dwFlags
= PSH_PROPTITLE
| PSH_NOAPPLYNOW
;
2867 psh
.hwndParent
= hWndParent
;
2868 psh
.pszCaption
= DevAdvPropInfo
->szDevName
;
2870 DevAdvPropInfo
->PropertySheetType
= DevAdvPropInfo
->ShowRemotePages
?
2871 DIGCDP_FLAG_REMOTE_ADVANCED
:
2872 DIGCDP_FLAG_ADVANCED
;
2874 psh
.phpage
= (HPROPSHEETPAGE
*)HeapAlloc(GetProcessHeap(),
2876 1 * sizeof(HPROPSHEETPAGE
));
2877 if (psh
.phpage
== NULL
)
2882 /* add the "General" property sheet */
2883 pspGeneral
.dwSize
= sizeof(PROPSHEETPAGE
);
2884 pspGeneral
.dwFlags
= PSP_DEFAULT
;
2885 pspGeneral
.hInstance
= hDllInstance
;
2886 pspGeneral
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICEGENERAL
);
2887 pspGeneral
.pfnDlgProc
= AdvPropGeneralDlgProc
;
2888 pspGeneral
.lParam
= (LPARAM
)DevAdvPropInfo
;
2889 psh
.phpage
[psh
.nPages
] = pCreatePropertySheetPageW(&pspGeneral
);
2890 if (psh
.phpage
[psh
.nPages
] != NULL
)
2895 DevAdvPropInfo
->nDevPropSheets
= psh
.nPages
;
2897 if (psh
.nPages
!= 0)
2899 Ret
= pPropertySheetW(&psh
);
2901 /* NOTE: no need to destroy the property sheets anymore! */
2908 /* in case of failure the property sheets must be destroyed */
2909 if (psh
.phpage
!= NULL
)
2915 if (psh
.phpage
[i
] != NULL
)
2917 pDestroyPropertySheetPage(psh
.phpage
[i
]);
2923 if (DevAdvPropInfo
!= NULL
)
2925 if (DevAdvPropInfo
->FreeDevPropSheets
)
2927 /* don't free the array if it's the one allocated in
2928 DisplayDeviceAdvancedProperties */
2929 HeapFree(GetProcessHeap(),
2931 DevAdvPropInfo
->DevPropSheets
);
2934 if (DevAdvPropInfo
->CloseDevInst
)
2936 /* close the device info set in case a new one was created */
2937 SetupDiDestroyDeviceInfoList(DevAdvPropInfo
->DeviceInfoSet
);
2940 if (DevAdvPropInfo
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
2942 SetupDiDestroyDeviceInfoList(DevAdvPropInfo
->CurrentDeviceInfoSet
);
2945 if (DevAdvPropInfo
->hDevIcon
!= NULL
)
2947 DestroyIcon(DevAdvPropInfo
->hDevIcon
);
2950 HeapFree(GetProcessHeap(),
2955 if (psh
.phpage
!= NULL
)
2957 HeapFree(GetProcessHeap(),
2962 if (hMachine
!= NULL
)
2964 CM_Disconnect_Machine(hMachine
);