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>
36 EnumDeviceDriverFilesCallback(IN PVOID Context
,
42 PENUMDRIVERFILES_CONTEXT EnumDriverFilesContext
= (PENUMDRIVERFILES_CONTEXT
)Context
;
44 li
.mask
= LVIF_TEXT
| LVIF_STATE
;
45 li
.iItem
= EnumDriverFilesContext
->nCount
++;
47 li
.state
= (li
.iItem
== 0 ? LVIS_SELECTED
: 0);
48 li
.stateMask
= LVIS_SELECTED
;
49 li
.pszText
= (LPWSTR
)Param1
;
50 (void)ListView_InsertItem(EnumDriverFilesContext
->hDriversListView
,
57 UpdateDriverDetailsDlg(IN HWND hwndDlg
,
58 IN HWND hDriversListView
,
59 IN PDEVADVPROP_INFO dap
)
61 HDEVINFO DeviceInfoSet
;
62 PSP_DEVINFO_DATA DeviceInfoData
;
63 SP_DRVINFO_DATA DriverInfoData
;
64 ENUMDRIVERFILES_CONTEXT EnumDriverFilesContext
;
66 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
68 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
69 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
73 DeviceInfoSet
= dap
->DeviceInfoSet
;
74 DeviceInfoData
= &dap
->DeviceInfoData
;
77 /* set the device image */
78 SendDlgItemMessage(hwndDlg
,
81 (WPARAM
)dap
->hDevIcon
,
84 /* set the device name edit control text */
85 SetDlgItemText(hwndDlg
,
89 /* fill the driver files list view */
90 EnumDriverFilesContext
.hDriversListView
= hDriversListView
;
91 EnumDriverFilesContext
.nCount
= 0;
93 (void)ListView_DeleteAllItems(EnumDriverFilesContext
.hDriversListView
);
94 DriverInfoData
.cbSize
= sizeof(SP_DRVINFO_DATA
);
95 if (FindCurrentDriver(DeviceInfoSet
,
98 SetupDiSetSelectedDriver(DeviceInfoSet
,
102 HSPFILEQ queueHandle
;
104 queueHandle
= SetupOpenFileQueue();
105 if (queueHandle
!= (HSPFILEQ
)INVALID_HANDLE_VALUE
)
107 SP_DEVINSTALL_PARAMS DeviceInstallParams
= {0};
108 DeviceInstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS
);
109 if (SetupDiGetDeviceInstallParams(DeviceInfoSet
,
111 &DeviceInstallParams
))
113 DeviceInstallParams
.FileQueue
= queueHandle
;
114 DeviceInstallParams
.Flags
|= DI_NOVCP
;
116 if (SetupDiSetDeviceInstallParams(DeviceInfoSet
,
118 &DeviceInstallParams
) &&
119 SetupDiCallClassInstaller(DIF_INSTALLDEVICEFILES
,
127 /* enumerate the driver files */
128 SetupScanFileQueue(queueHandle
,
129 SPQ_SCAN_USE_CALLBACK
,
131 EnumDeviceDriverFilesCallback
,
132 &EnumDriverFilesContext
,
135 /* update the list view column width */
136 GetClientRect(hDriversListView
,
138 lvc
.mask
= LVCF_WIDTH
;
139 lvc
.cx
= rcClient
.right
;
140 (void)ListView_SetColumn(hDriversListView
,
144 /* highlight the first item from list */
145 if (ListView_GetSelectedCount(hDriversListView
) != 0)
147 ListView_SetItemState(hDriversListView
,
149 LVIS_FOCUSED
| LVIS_SELECTED
,
150 LVIS_FOCUSED
| LVIS_SELECTED
);
155 SetupCloseFileQueue(queueHandle
);
162 UpdateDriverVersionInfoDetails(IN HWND hwndDlg
,
163 IN LPCWSTR lpszDriverPath
)
167 LPVOID lpData
= NULL
;
171 WCHAR szLangInfo
[255];
172 WCHAR szLangPath
[MAX_PATH
];
173 LPWSTR lpCompanyName
= NULL
;
174 LPWSTR lpFileVersion
= NULL
;
175 LPWSTR lpLegalCopyright
= NULL
;
176 LPWSTR lpDigitalSigner
= NULL
;
178 WCHAR szNotAvailable
[255];
180 /* extract version info from selected file */
181 dwVerInfoSize
= GetFileVersionInfoSize(lpszDriverPath
,
186 lpData
= HeapAlloc(GetProcessHeap(),
192 if (!GetFileVersionInfo(lpszDriverPath
,
198 if (!VerQueryValue(lpData
,
199 L
"\\VarFileInfo\\Translation",
204 dwLangId
= *(LPDWORD
)lpInfo
;
205 swprintf(szLangInfo
, L
"\\StringFileInfo\\%04x%04x\\",
206 LOWORD(dwLangId
), HIWORD(dwLangId
));
208 /* read CompanyName */
209 wcscpy(szLangPath
, szLangInfo
);
210 wcscat(szLangPath
, L
"CompanyName");
212 VerQueryValue(lpData
,
214 (void **)&lpCompanyName
,
217 /* read FileVersion */
218 wcscpy(szLangPath
, szLangInfo
);
219 wcscat(szLangPath
, L
"FileVersion");
221 VerQueryValue(lpData
,
223 (void **)&lpFileVersion
,
226 /* read LegalTrademarks */
227 wcscpy(szLangPath
, szLangInfo
);
228 wcscat(szLangPath
, L
"LegalCopyright");
230 VerQueryValue(lpData
,
232 (void **)&lpLegalCopyright
,
235 /* TODO: read digital signer info */
238 if (!LoadString(hDllInstance
,
241 sizeof(szNotAvailable
) / sizeof(WCHAR
)))
243 wcscpy(szNotAvailable
, L
"n/a");
248 lpCompanyName
= szNotAvailable
;
249 SetDlgItemText(hwndDlg
,
254 lpFileVersion
= szNotAvailable
;
255 SetDlgItemText(hwndDlg
,
259 if (!lpLegalCopyright
)
260 lpLegalCopyright
= szNotAvailable
;
261 SetDlgItemText(hwndDlg
,
265 if (!lpDigitalSigner
)
266 lpDigitalSigner
= szNotAvailable
;
267 SetDlgItemText(hwndDlg
,
271 /* release version info */
273 HeapFree(GetProcessHeap(),
281 DriverDetailsDlgProc(IN HWND hwndDlg
,
286 PDEVADVPROP_INFO dap
;
289 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
,
292 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
298 switch (LOWORD(wParam
))
321 HWND hDriversListView
;
323 dap
= (PDEVADVPROP_INFO
)lParam
;
326 SetWindowLongPtr(hwndDlg
,
330 hDriversListView
= GetDlgItem(hwndDlg
,
333 /* add a column to the list view control */
334 lvc
.mask
= LVCF_FMT
| LVCF_WIDTH
;
335 lvc
.fmt
= LVCFMT_LEFT
;
337 (void)ListView_InsertColumn(hDriversListView
,
341 UpdateDriverDetailsDlg(hwndDlg
,
352 LPNMHDR pnmhdr
= (LPNMHDR
)lParam
;
354 switch (pnmhdr
->code
)
356 case LVN_ITEMCHANGED
:
358 LPNMLISTVIEW pnmv
= (LPNMLISTVIEW
)lParam
;
359 HWND hDriversListView
= GetDlgItem(hwndDlg
,
362 if (ListView_GetSelectedCount(hDriversListView
) == 0)
364 /* nothing is selected - empty the labels */
365 SetDlgItemText(hwndDlg
,
368 SetDlgItemText(hwndDlg
,
371 SetDlgItemText(hwndDlg
,
374 SetDlgItemText(hwndDlg
,
378 else if (pnmv
->uNewState
!= 0)
380 /* extract version info and update the labels */
381 WCHAR szDriverPath
[MAX_PATH
];
383 ListView_GetItemText(hDriversListView
,
389 UpdateDriverVersionInfoDetails(hwndDlg
,
406 IN HINSTANCE hInstance
,
407 IN LPCWSTR InstanceId
,
414 IN PDEVADVPROP_INFO dap
)
416 TOKEN_PRIVILEGES Privileges
;
418 BOOL NeedReboot
= FALSE
;
420 // Better use InstallDevInst:
425 // LPWSTR wszDeviceId,
428 // See: http://comp.os.ms-windows.programmer.win32.narkive.com/J8FTd4KK/signature-of-undocumented-installdevinstex
429 if (!DevInstallW(hwndDlg
, NULL
, dap
->szDeviceID
, SW_SHOWNOACTIVATE
))
432 if (NeedReboot
== FALSE
)
435 //FIXME: load text from resource file
436 if (MessageBoxW(hwndDlg
, L
"Reboot now?", L
"Reboot required", MB_YESNO
| MB_ICONQUESTION
) != IDYES
)
439 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
441 ERR("OpenProcessToken failed\n");
445 /* Get the LUID for the Shutdown privilege */
446 if (!LookupPrivilegeValueW(NULL
, SE_SHUTDOWN_NAME
, &Privileges
.Privileges
[0].Luid
))
448 ERR("LookupPrivilegeValue failed\n");
453 /* Assign the Shutdown privilege to our process */
454 Privileges
.PrivilegeCount
= 1;
455 Privileges
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
457 if (!AdjustTokenPrivileges(hToken
, FALSE
, &Privileges
, 0, NULL
, NULL
))
459 ERR("AdjustTokenPrivileges failed\n");
464 /* Finally shut down the system */
465 if (!ExitWindowsEx(EWX_REBOOT
, SHTDN_REASON_MAJOR_OTHER
| SHTDN_REASON_MINOR_OTHER
| SHTDN_REASON_FLAG_PLANNED
))
467 ERR("ExitWindowsEx failed\n");
474 UpdateDriverDlg(IN HWND hwndDlg
,
475 IN PDEVADVPROP_INFO dap
)
477 HDEVINFO DeviceInfoSet
;
478 PSP_DEVINFO_DATA DeviceInfoData
;
480 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
482 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
483 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
487 DeviceInfoSet
= dap
->DeviceInfoSet
;
488 DeviceInfoData
= &dap
->DeviceInfoData
;
491 /* set the device image */
492 SendDlgItemMessage(hwndDlg
,
495 (WPARAM
)dap
->hDevIcon
,
498 /* set the device name edit control text */
499 SetDlgItemText(hwndDlg
,
503 /* query the driver provider */
504 if (GetDriverProviderString(DeviceInfoSet
,
507 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
509 SetDlgItemText(hwndDlg
,
514 /* query the driver date */
515 if (GetDriverDateString(DeviceInfoSet
,
518 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
520 SetDlgItemText(hwndDlg
,
525 /* query the driver version */
526 if (GetDriverVersionString(DeviceInfoSet
,
529 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
531 SetDlgItemText(hwndDlg
,
540 AdvProcDriverDlgProc(IN HWND hwndDlg
,
545 PDEVADVPROP_INFO dap
;
548 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
,
551 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
557 switch (LOWORD(wParam
))
559 case IDC_DRIVERDETAILS
:
560 DialogBoxParam(hDllInstance
,
561 MAKEINTRESOURCE(IDD_DRIVERDETAILS
),
563 DriverDetailsDlgProc
,
567 case IDC_UPDATEDRIVER
:
568 UpdateDriver(hwndDlg
, dap
);
576 NMHDR
*hdr
= (NMHDR
*)lParam
;
587 dap
= (PDEVADVPROP_INFO
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
590 SetWindowLongPtr(hwndDlg
,
594 UpdateDriverDlg(hwndDlg
,
608 SetListViewText(HWND hwnd
,
614 li
.mask
= LVIF_TEXT
| LVIF_STATE
;
617 li
.state
= 0; //(li.iItem == 0 ? LVIS_SELECTED : 0);
618 li
.stateMask
= LVIS_SELECTED
;
620 (void)ListView_InsertItem(hwnd
,
626 UpdateDetailsDlg(IN HWND hwndDlg
,
627 IN PDEVADVPROP_INFO dap
)
638 IDS_PROP_HARDWAREIDS
,
639 IDS_PROP_COMPATIBLEIDS
,
640 IDS_PROP_MATCHINGDEVICEID
,
643 IDS_PROP_CAPABILITIES
,
644 IDS_PROP_DEVNODEFLAGS
,
645 IDS_PROP_CONFIGFLAGS
,
646 IDS_PROP_CSCONFIGFLAGS
,
647 IDS_PROP_EJECTIONRELATIONS
,
648 IDS_PROP_REMOVALRELATIONS
,
649 IDS_PROP_BUSRELATIONS
,
650 IDS_PROP_DEVUPPERFILTERS
,
651 IDS_PROP_DEVLOWERFILTERS
,
652 IDS_PROP_CLASSUPPERFILTERS
,
653 IDS_PROP_CLASSLOWERFILTERS
,
654 IDS_PROP_CLASSINSTALLER
,
655 IDS_PROP_CLASSCOINSTALLER
,
656 IDS_PROP_DEVICECOINSTALLER
,
657 IDS_PROP_FIRMWAREREVISION
,
658 IDS_PROP_CURRENTPOWERSTATE
,
659 IDS_PROP_POWERCAPABILITIES
,
660 IDS_PROP_POWERSTATEMAPPINGS
664 /* set the device image */
665 SendDlgItemMessage(hwndDlg
,
668 (WPARAM
)dap
->hDevIcon
,
671 /* set the device name edit control text */
672 SetDlgItemText(hwndDlg
,
677 hwndComboBox
= GetDlgItem(hwndDlg
,
678 IDC_DETAILSPROPNAME
);
680 hwndListView
= GetDlgItem(hwndDlg
,
681 IDC_DETAILSPROPVALUE
);
683 for (i
= 0; i
!= sizeof(Properties
) / sizeof(Properties
[0]); i
++)
685 /* fill in the device usage combo box */
686 if (LoadString(hDllInstance
,
689 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
691 SendMessage(hwndComboBox
,
694 (LPARAM
)dap
->szTemp
);
699 GetClientRect(hwndListView
,
702 /* add a column to the list view control */
703 lvc
.mask
= LVCF_FMT
| LVCF_WIDTH
;
704 lvc
.fmt
= LVCFMT_LEFT
;
705 lvc
.cx
= rcClient
.right
;
706 (void)ListView_InsertColumn(hwndListView
,
710 SendMessage(hwndComboBox
,
715 SetListViewText(hwndListView
, 0, dap
->szDeviceID
);
717 SetFocus(hwndComboBox
);
722 DisplayDevicePropertyText(IN PDEVADVPROP_INFO dap
,
723 IN HWND hwndListView
,
726 HDEVINFO DeviceInfoSet
;
727 PSP_DEVINFO_DATA DeviceInfoData
;
736 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
738 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
739 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
743 DeviceInfoSet
= dap
->DeviceInfoSet
;
744 DeviceInfoData
= &dap
->DeviceInfoData
;
748 SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
757 if (GetLastError() != ERROR_FILE_NOT_FOUND
)
759 swprintf(dap
->szTemp
, L
"Error: Getting the size failed! (Error: %ld)", GetLastError());
760 SetListViewText(hwndListView
, 0, dap
->szTemp
);
765 lpBuffer
= HeapAlloc(GetProcessHeap(),
768 if (lpBuffer
== NULL
)
770 SetListViewText(hwndListView
, 0, L
"Error: Allocating the buffer failed!");
774 if (SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
782 if (dwType
== REG_SZ
)
784 SetListViewText(hwndListView
, 0, (LPWSTR
)lpBuffer
);
786 else if (dwType
== REG_MULTI_SZ
)
788 lpStr
= (LPWSTR
)lpBuffer
;
792 len
= wcslen(lpStr
) + 1;
794 SetListViewText(hwndListView
, index
, lpStr
);
800 else if (dwType
== REG_DWORD
)
802 dwValue
= *(DWORD
*) lpBuffer
;
806 case SPDRP_CAPABILITIES
:
808 if (dwValue
& CM_DEVCAP_LOCKSUPPORTED
)
809 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_LOCKSUPPORTED");
810 if (dwValue
& CM_DEVCAP_EJECTSUPPORTED
)
811 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_EJECTSUPPORTED");
812 if (dwValue
& CM_DEVCAP_REMOVABLE
)
813 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_REMOVABLE");
814 if (dwValue
& CM_DEVCAP_DOCKDEVICE
)
815 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_DOCKDEVICE");
816 if (dwValue
& CM_DEVCAP_UNIQUEID
)
817 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_UNIQUEID");
818 if (dwValue
& CM_DEVCAP_SILENTINSTALL
)
819 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_SILENTINSTALL");
820 if (dwValue
& CM_DEVCAP_RAWDEVICEOK
)
821 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_RAWDEVICEOK");
822 if (dwValue
& CM_DEVCAP_SURPRISEREMOVALOK
)
823 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_SURPRISEREMOVALOK");
824 if (dwValue
& CM_DEVCAP_HARDWAREDISABLED
)
825 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_HARDWAREDISABLED");
826 if (dwValue
& CM_DEVCAP_NONDYNAMIC
)
827 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_NONDYNAMIC");
830 case SPDRP_CONFIGFLAGS
:
832 if (dwValue
& CONFIGFLAG_DISABLED
)
833 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_DISABLED");
834 if (dwValue
& CONFIGFLAG_REMOVED
)
835 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_REMOVED");
836 if (dwValue
& CONFIGFLAG_MANUAL_INSTALL
)
837 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_MANUAL_INSTALL");
838 if (dwValue
& CONFIGFLAG_IGNORE_BOOT_LC
)
839 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_IGNORE_BOOT_LC");
840 if (dwValue
& CONFIGFLAG_NET_BOOT
)
841 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_NET_BOOT");
842 if (dwValue
& CONFIGFLAG_REINSTALL
)
843 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_REINSTALL");
844 if (dwValue
& CONFIGFLAG_FAILEDINSTALL
)
845 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_FAILEDINSTALL");
846 if (dwValue
& CONFIGFLAG_CANTSTOPACHILD
)
847 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_CANTSTOPACHILD");
848 if (dwValue
& CONFIGFLAG_OKREMOVEROM
)
849 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_OKREMOVEROM");
850 if (dwValue
& CONFIGFLAG_NOREMOVEEXIT
)
851 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_NOREMOVEEXIT");
855 swprintf(dap
->szTemp
, L
"0x%08lx", dwValue
);
856 SetListViewText(hwndListView
, 0, dap
->szTemp
);
862 SetListViewText(hwndListView
, 0, L
"Error: Unsupported value type!");
868 SetListViewText(hwndListView
, 0, L
"Error: Retrieving the value failed!");
871 HeapFree(GetProcessHeap(),
877 DisplayDevNodeFlags(IN PDEVADVPROP_INFO dap
,
878 IN HWND hwndListView
)
884 CM_Get_DevNode_Status_Ex(&dwStatus
,
886 dap
->DeviceInfoData
.DevInst
,
891 if (dwStatus
& DN_ROOT_ENUMERATED
)
892 SetListViewText(hwndListView
, index
++, L
"DN_ROOT_ENUMERATED");
893 if (dwStatus
& DN_DRIVER_LOADED
)
894 SetListViewText(hwndListView
, index
++, L
"DN_DRIVER_LOADED");
895 if (dwStatus
& DN_ENUM_LOADED
)
896 SetListViewText(hwndListView
, index
++, L
"DN_ENUM_LOADED");
897 if (dwStatus
& DN_STARTED
)
898 SetListViewText(hwndListView
, index
++, L
"DN_STARTED");
899 if (dwStatus
& DN_MANUAL
)
900 SetListViewText(hwndListView
, index
++, L
"DN_MANUAL");
901 if (dwStatus
& DN_NEED_TO_ENUM
)
902 SetListViewText(hwndListView
, index
++, L
"DN_NEED_TO_ENUM");
903 if (dwStatus
& DN_DRIVER_BLOCKED
)
904 SetListViewText(hwndListView
, index
++, L
"DN_DRIVER_BLOCKED");
905 if (dwStatus
& DN_HARDWARE_ENUM
)
906 SetListViewText(hwndListView
, index
++, L
"DN_HARDWARE_ENUM");
907 if (dwStatus
& DN_NEED_RESTART
)
908 SetListViewText(hwndListView
, index
++, L
"DN_NEED_RESTART");
909 if (dwStatus
& DN_CHILD_WITH_INVALID_ID
)
910 SetListViewText(hwndListView
, index
++, L
"DN_CHILD_WITH_INVALID_ID");
911 if (dwStatus
& DN_HAS_PROBLEM
)
912 SetListViewText(hwndListView
, index
++, L
"DN_HAS_PROBLEM");
913 if (dwStatus
& DN_FILTERED
)
914 SetListViewText(hwndListView
, index
++, L
"DN_FILTERED");
915 if (dwStatus
& DN_LEGACY_DRIVER
)
916 SetListViewText(hwndListView
, index
++, L
"DN_LEGACY_DRIVER");
917 if (dwStatus
& DN_DISABLEABLE
)
918 SetListViewText(hwndListView
, index
++, L
"DN_DISABLEABLE");
919 if (dwStatus
& DN_REMOVABLE
)
920 SetListViewText(hwndListView
, index
++, L
"DN_REMOVABLE");
921 if (dwStatus
& DN_PRIVATE_PROBLEM
)
922 SetListViewText(hwndListView
, index
++, L
"DN_PRIVATE_PROBLEM");
923 if (dwStatus
& DN_MF_PARENT
)
924 SetListViewText(hwndListView
, index
++, L
"DN_MF_PARENT");
925 if (dwStatus
& DN_MF_CHILD
)
926 SetListViewText(hwndListView
, index
++, L
"DN_MF_CHILD");
927 if (dwStatus
& DN_WILL_BE_REMOVED
)
928 SetListViewText(hwndListView
, index
++, L
"DN_WILL_BE_REMOVED");
930 if (dwStatus
& DN_NOT_FIRST_TIMEE
)
931 SetListViewText(hwndListView
, index
++, L
"DN_NOT_FIRST_TIMEE");
932 if (dwStatus
& DN_STOP_FREE_RES
)
933 SetListViewText(hwndListView
, index
++, L
"DN_STOP_FREE_RES");
934 if (dwStatus
& DN_REBAL_CANDIDATE
)
935 SetListViewText(hwndListView
, index
++, L
"DN_REBAL_CANDIDATE");
936 if (dwStatus
& DN_BAD_PARTIAL
)
937 SetListViewText(hwndListView
, index
++, L
"DN_BAD_PARTIAL");
938 if (dwStatus
& DN_NT_ENUMERATOR
)
939 SetListViewText(hwndListView
, index
++, L
"DN_NT_ENUMERATOR");
940 if (dwStatus
& DN_NT_DRIVER
)
941 SetListViewText(hwndListView
, index
++, L
"DN_NT_DRIVER");
943 if (dwStatus
& DN_NEEDS_LOCKING
)
944 SetListViewText(hwndListView
, index
++, L
"DN_NEEDS_LOCKING");
945 if (dwStatus
& DN_ARM_WAKEUP
)
946 SetListViewText(hwndListView
, index
++, L
"DN_ARM_WAKEUP");
947 if (dwStatus
& DN_APM_ENUMERATOR
)
948 SetListViewText(hwndListView
, index
++, L
"DN_APM_ENUMERATOR");
949 if (dwStatus
& DN_APM_DRIVER
)
950 SetListViewText(hwndListView
, index
++, L
"DN_APM_DRIVER");
951 if (dwStatus
& DN_SILENT_INSTALL
)
952 SetListViewText(hwndListView
, index
++, L
"DN_SILENT_INSTALL");
953 if (dwStatus
& DN_NO_SHOW_IN_DM
)
954 SetListViewText(hwndListView
, index
++, L
"DN_NO_SHOW_IN_DM");
955 if (dwStatus
& DN_BOOT_LOG_PROB
)
956 SetListViewText(hwndListView
, index
++, L
"DN_BOOT_LOG_PROB");
958 // swprintf(dap->szTemp, L"0x%08x", dwStatus);
959 // SetListViewText(hwndListView, 0, dap->szTemp);
964 DisplayDevNodeEnumerator(IN PDEVADVPROP_INFO dap
,
965 IN HWND hwndListView
)
967 PSP_DEVINFO_DATA DeviceInfoData
;
971 DWORD dwSize
= 256 * sizeof(WCHAR
);
973 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
975 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
979 DeviceInfoData
= &dap
->DeviceInfoData
;
982 CM_Get_DevNode_Registry_Property_ExW(DeviceInfoData
->DevInst
,
983 CM_DRP_ENUMERATOR_NAME
,
990 SetListViewText(hwndListView
, 0, szBuffer
);
995 DisplayCsFlags(IN PDEVADVPROP_INFO dap
,
996 IN HWND hwndListView
)
1001 CM_Get_HW_Prof_Flags_Ex(dap
->szDevName
,
1002 0, /* current hardware profile */
1008 if (dwValue
& CSCONFIGFLAG_DISABLED
)
1009 SetListViewText(hwndListView
, index
++, L
"CSCONFIGFLAG_DISABLED");
1011 if (dwValue
& CSCONFIGFLAG_DO_NOT_CREATE
)
1012 SetListViewText(hwndListView
, index
++, L
"CSCONFIGFLAG_DO_NOT_CREATE");
1014 if (dwValue
& CSCONFIGFLAG_DO_NOT_START
)
1015 SetListViewText(hwndListView
, index
++, L
"CSCONFIGFLAG_DO_NOT_START");
1020 DisplayMatchingDeviceId(IN PDEVADVPROP_INFO dap
,
1021 IN HWND hwndListView
)
1023 HDEVINFO DeviceInfoSet
;
1024 PSP_DEVINFO_DATA DeviceInfoData
;
1025 WCHAR szBuffer
[256];
1030 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1032 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1033 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1037 DeviceInfoSet
= dap
->DeviceInfoSet
;
1038 DeviceInfoData
= &dap
->DeviceInfoData
;
1041 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
,
1047 if (hKey
!= INVALID_HANDLE_VALUE
)
1049 dwSize
= 256 * sizeof(WCHAR
);
1050 if (RegQueryValueEx(hKey
,
1051 L
"MatchingDeviceId",
1055 &dwSize
) == ERROR_SUCCESS
)
1057 SetListViewText(hwndListView
, 0, szBuffer
);
1066 DisplayDeviceCoinstallers(IN PDEVADVPROP_INFO dap
,
1067 IN HWND hwndListView
)
1069 HDEVINFO DeviceInfoSet
;
1070 PSP_DEVINFO_DATA DeviceInfoData
;
1079 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1081 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1082 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1086 DeviceInfoSet
= dap
->DeviceInfoSet
;
1087 DeviceInfoData
= &dap
->DeviceInfoData
;
1090 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
,
1096 if (hKey
!= INVALID_HANDLE_VALUE
)
1099 if (RegQueryValueEx(hKey
,
1104 &dwSize
) == ERROR_SUCCESS
&&
1108 lpBuffer
= HeapAlloc(GetProcessHeap(),
1112 RegQueryValueEx(hKey
,
1119 lpStr
= (LPWSTR
)lpBuffer
;
1123 len
= wcslen(lpStr
) + 1;
1125 SetListViewText(hwndListView
, index
, lpStr
);
1131 HeapFree(GetProcessHeap(),
1142 DisplayClassProperties(IN PDEVADVPROP_INFO dap
,
1143 IN HWND hwndListView
,
1144 IN LPWSTR lpProperty
)
1146 HDEVINFO DeviceInfoSet
;
1147 PSP_DEVINFO_DATA DeviceInfoData
;
1148 WCHAR szClassGuid
[45];
1158 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1160 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1161 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1165 DeviceInfoSet
= dap
->DeviceInfoSet
;
1166 DeviceInfoData
= &dap
->DeviceInfoData
;
1169 dwSize
= 45 * sizeof(WCHAR
);
1170 if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
1174 (LPBYTE
)szClassGuid
,
1179 pSetupGuidFromString(szClassGuid
,
1182 hKey
= SetupDiOpenClassRegKey(&ClassGuid
,
1184 if (hKey
!= INVALID_HANDLE_VALUE
)
1187 if (RegQueryValueEx(hKey
,
1192 &dwSize
) == ERROR_SUCCESS
&&
1195 lpBuffer
= HeapAlloc(GetProcessHeap(),
1199 RegQueryValueEx(hKey
,
1206 if (dwType
== REG_SZ
)
1208 SetListViewText(hwndListView
, 0, (LPWSTR
)lpBuffer
);
1210 else if (dwType
== REG_MULTI_SZ
)
1212 lpStr
= (LPWSTR
)lpBuffer
;
1216 len
= wcslen(lpStr
) + 1;
1218 SetListViewText(hwndListView
, index
, lpStr
);
1225 HeapFree(GetProcessHeap(),
1236 DisplayDeviceProperties(IN PDEVADVPROP_INFO dap
,
1237 IN HWND hwndComboBox
,
1238 IN HWND hwndListView
)
1242 Index
= (INT
)SendMessage(hwndComboBox
,
1246 if (Index
== CB_ERR
)
1249 (void)ListView_DeleteAllItems(hwndListView
);
1254 SetListViewText(hwndListView
, 0, dap
->szDeviceID
);
1257 case 1: /* Hardware ID */
1258 DisplayDevicePropertyText(dap
,
1263 case 2: /* Compatible IDs */
1264 DisplayDevicePropertyText(dap
,
1266 SPDRP_COMPATIBLEIDS
);
1269 case 3: /* Matching ID */
1270 DisplayMatchingDeviceId(dap
,
1274 case 4: /* Service */
1275 DisplayDevicePropertyText(dap
,
1280 case 5: /* Enumerator */
1281 DisplayDevNodeEnumerator(dap
,
1285 case 6: /* Capabilities */
1286 DisplayDevicePropertyText(dap
,
1288 SPDRP_CAPABILITIES
);
1291 case 7: /* Devnode Flags */
1292 DisplayDevNodeFlags(dap
,
1296 case 8: /* Config Flags */
1297 DisplayDevicePropertyText(dap
,
1302 case 9: /* CSConfig Flags */
1308 case 10: /* Ejection relation */
1311 case 11: /* Removal relations */
1314 case 12: /* Bus relation */
1318 case 13: /* Device Upper Filters */
1319 DisplayDevicePropertyText(dap
,
1321 SPDRP_UPPERFILTERS
);
1324 case 14: /* Device Lower Filters */
1325 DisplayDevicePropertyText(dap
,
1327 SPDRP_LOWERFILTERS
);
1330 case 15: /* Class Upper Filters */
1331 DisplayClassProperties(dap
,
1336 case 16: /* Class Lower Filters */
1337 DisplayClassProperties(dap
,
1342 case 17: /* Class Installer */
1343 DisplayClassProperties(dap
,
1349 case 18: /* Class Coinstaller */
1353 case 19: /* Device Coinstaller */
1354 DisplayDeviceCoinstallers(dap
,
1359 case 20: /* Firmware Revision */
1362 case 21: /* Current Power State */
1365 case 20: /* Power Capabilities */
1368 case 21: /* Power State Mappings */
1373 SetListViewText(hwndListView
, 0, L
"<Not implemented yet>");
1381 AdvProcDetailsDlgProc(IN HWND hwndDlg
,
1386 PDEVADVPROP_INFO dap
;
1387 INT_PTR Ret
= FALSE
;
1389 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
,
1392 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
1398 switch (LOWORD(wParam
))
1400 case IDC_DETAILSPROPNAME
:
1401 if (HIWORD(wParam
) == CBN_SELCHANGE
)
1403 DisplayDeviceProperties(dap
,
1404 GetDlgItem(hwndDlg
, IDC_DETAILSPROPNAME
),
1405 GetDlgItem(hwndDlg
, IDC_DETAILSPROPVALUE
));
1414 NMHDR
*hdr
= (NMHDR
*)lParam
;
1425 dap
= (PDEVADVPROP_INFO
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1428 SetWindowLongPtr(hwndDlg
,
1432 UpdateDetailsDlg(hwndDlg
,
1446 InitDevUsageActions(IN HWND hwndDlg
,
1448 IN PDEVADVPROP_INFO dap
)
1459 i
!= sizeof(Actions
) / sizeof(Actions
[0]);
1462 /* fill in the device usage combo box */
1463 if (LoadString(hDllInstance
,
1466 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1468 Index
= (INT
)SendMessage(hComboBox
,
1471 (LPARAM
)dap
->szTemp
);
1472 if (Index
!= CB_ERR
)
1474 SendMessage(hComboBox
,
1477 (LPARAM
)Actions
[i
]);
1481 case IDS_ENABLEDEVICE
:
1482 if (dap
->DeviceStarted
)
1484 SendMessage(hComboBox
,
1491 case IDS_DISABLEDEVICE
:
1492 if (!dap
->DeviceStarted
)
1494 SendMessage(hComboBox
,
1511 GetSelectedUsageAction(IN HWND hComboBox
)
1516 Index
= (INT
)SendMessage(hComboBox
,
1520 if (Index
!= CB_ERR
)
1522 INT iRet
= (INT
) SendMessage(hComboBox
,
1537 ApplyGeneralSettings(IN HWND hwndDlg
,
1538 IN PDEVADVPROP_INFO dap
)
1542 if (dap
->DeviceUsageChanged
&& dap
->IsAdmin
&& dap
->CanDisable
)
1544 UINT SelectedUsageAction
;
1545 BOOL NeedReboot
= FALSE
;
1547 SelectedUsageAction
= GetSelectedUsageAction(GetDlgItem(hwndDlg
,
1549 switch (SelectedUsageAction
)
1551 case IDS_ENABLEDEVICE
:
1552 if (!dap
->DeviceStarted
)
1554 Ret
= EnableDevice(dap
->DeviceInfoSet
,
1555 &dap
->DeviceInfoData
,
1562 case IDS_DISABLEDEVICE
:
1563 if (dap
->DeviceStarted
)
1565 Ret
= EnableDevice(dap
->DeviceInfoSet
,
1566 &dap
->DeviceInfoData
,
1581 /* make PropertySheet() return PSM_REBOOTSYSTEM */
1582 PropSheet_RebootSystem(hwndDlg
);
1587 /* FIXME - display an error message */
1588 FIXME("Failed to enable/disable device! LastError: %d\n",
1593 Ret
= !dap
->DeviceUsageChanged
;
1595 /* disable the apply button */
1596 PropSheet_UnChanged(GetParent(hwndDlg
),
1598 dap
->DeviceUsageChanged
= FALSE
;
1604 UpdateDevInfo(IN HWND hwndDlg
,
1605 IN PDEVADVPROP_INFO dap
,
1608 HWND hDevUsage
, hPropSheetDlg
, hDevProbBtn
;
1610 ULONG Status
, ProblemNumber
;
1611 SP_DEVINSTALL_PARAMS_W InstallParams
;
1612 UINT TroubleShootStrId
= IDS_TROUBLESHOOTDEV
;
1613 BOOL bFlag
, bDevActionAvailable
= TRUE
;
1614 BOOL bDrvInstalled
= FALSE
;
1616 HDEVINFO DeviceInfoSet
= NULL
;
1617 PSP_DEVINFO_DATA DeviceInfoData
= NULL
;
1618 PROPSHEETHEADER psh
;
1619 DWORD nDriverPages
= 0;
1620 BOOL RecalcPages
= FALSE
;
1622 hPropSheetDlg
= GetParent(hwndDlg
);
1624 if (dap
->PageInitialized
)
1626 /* switch to the General page */
1627 PropSheet_SetCurSelByID(hPropSheetDlg
,
1630 /* remove and destroy the existing device property sheet pages */
1631 if (dap
->DevPropSheets
!= NULL
)
1634 iPage
!= dap
->nDevPropSheets
;
1637 if (dap
->DevPropSheets
[iPage
] != NULL
)
1639 PropSheet_RemovePage(hPropSheetDlg
,
1641 dap
->DevPropSheets
[iPage
]);
1650 if (dap
->FreeDevPropSheets
)
1652 /* don't free the array if it's the one allocated in
1653 DisplayDeviceAdvancedProperties */
1654 HeapFree(GetProcessHeap(),
1656 dap
->DevPropSheets
);
1658 dap
->FreeDevPropSheets
= FALSE
;
1661 dap
->DevPropSheets
= NULL
;
1662 dap
->nDevPropSheets
= 0;
1666 /* create a new device info set and re-open the device */
1667 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1669 SetupDiDestroyDeviceInfoList(dap
->CurrentDeviceInfoSet
);
1672 dap
->ParentDevInst
= 0;
1673 dap
->CurrentDeviceInfoSet
= SetupDiCreateDeviceInfoListEx(NULL
,
1677 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1679 if (SetupDiOpenDeviceInfo(dap
->CurrentDeviceInfoSet
,
1683 &dap
->CurrentDeviceInfoData
))
1685 if (dap
->CloseDevInst
)
1687 SetupDiDestroyDeviceInfoList(dap
->DeviceInfoSet
);
1690 dap
->CloseDevInst
= TRUE
;
1691 dap
->DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1692 dap
->DeviceInfoData
= dap
->CurrentDeviceInfoData
;
1693 dap
->CurrentDeviceInfoSet
= INVALID_HANDLE_VALUE
;
1701 /* get the parent node from the initial devinst */
1702 CM_Get_Parent_Ex(&dap
->ParentDevInst
,
1703 dap
->DeviceInfoData
.DevInst
,
1708 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1710 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1711 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1715 DeviceInfoSet
= dap
->DeviceInfoSet
;
1716 DeviceInfoData
= &dap
->DeviceInfoData
;
1721 DeviceInfoSet
= dap
->DeviceInfoSet
;
1722 DeviceInfoData
= &dap
->DeviceInfoData
;
1725 dap
->HasDriverPage
= FALSE
;
1726 dap
->HasResourcePage
= FALSE
;
1727 dap
->HasPowerPage
= FALSE
;
1728 if (IsDriverInstalled(DeviceInfoData
->DevInst
,
1733 if (SetupDiCallClassInstaller((dap
->ShowRemotePages
?
1734 DIF_ADDREMOTEPROPERTYPAGE_ADVANCED
:
1735 DIF_ADDPROPERTYPAGE_ADVANCED
),
1739 /* get install params */
1740 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
1741 if (!SetupDiGetDeviceInstallParamsW(DeviceInfoSet
,
1745 /* zero the flags */
1746 InstallParams
.Flags
= 0;
1749 dap
->HasDriverPage
= !(InstallParams
.Flags
& DI_DRIVERPAGE_ADDED
);
1750 dap
->HasResourcePage
= !(InstallParams
.Flags
& DI_RESOURCEPAGE_ADDED
);
1751 dap
->HasPowerPage
= !(InstallParams
.Flags
& DI_FLAGSEX_POWERPAGE_ADDED
);
1755 /* get the device icon */
1756 if (dap
->hDevIcon
!= NULL
)
1758 DestroyIcon(dap
->hDevIcon
);
1759 dap
->hDevIcon
= NULL
;
1761 if (!SetupDiLoadClassIcon(&DeviceInfoData
->ClassGuid
,
1765 dap
->hDevIcon
= NULL
;
1768 /* get the device name */
1769 if (GetDeviceDescriptionString(DeviceInfoSet
,
1772 sizeof(dap
->szDevName
) / sizeof(dap
->szDevName
[0])))
1774 PropSheet_SetTitle(hPropSheetDlg
,
1779 /* set the device image */
1780 SendDlgItemMessage(hwndDlg
,
1783 (WPARAM
)dap
->hDevIcon
,
1786 /* set the device name edit control text */
1787 SetDlgItemText(hwndDlg
,
1791 /* set the device type edit control text */
1792 if (GetDeviceTypeString(DeviceInfoData
,
1794 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1796 SetDlgItemText(hwndDlg
,
1801 /* set the device manufacturer edit control text */
1802 if (GetDeviceManufacturerString(DeviceInfoSet
,
1805 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1807 SetDlgItemText(hwndDlg
,
1808 IDC_DEVMANUFACTURER
,
1812 /* set the device location edit control text */
1813 if (GetDeviceLocationString(DeviceInfoSet
,
1817 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1819 SetDlgItemText(hwndDlg
,
1824 /* set the device status edit control text */
1825 if (GetDeviceStatusString(DeviceInfoData
->DevInst
,
1828 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1830 SetDlgItemText(hwndDlg
,
1835 /* set the device troubleshoot button text and disable it if necessary */
1836 hDevProbBtn
= GetDlgItem(hwndDlg
,
1838 cr
= CM_Get_DevNode_Status_Ex(&Status
,
1840 DeviceInfoData
->DevInst
,
1843 if (cr
== CR_SUCCESS
&& (Status
& DN_HAS_PROBLEM
))
1845 switch (ProblemNumber
)
1847 case CM_PROB_DEVLOADER_FAILED
:
1849 /* FIXME - only if it's not a root bus devloader,
1850 disable the button otherwise */
1851 TroubleShootStrId
= IDS_UPDATEDRV
;
1855 case CM_PROB_OUT_OF_MEMORY
:
1856 case CM_PROB_ENTRY_IS_WRONG_TYPE
:
1857 case CM_PROB_LACKED_ARBITRATOR
:
1858 case CM_PROB_FAILED_START
:
1860 case CM_PROB_UNKNOWN_RESOURCE
:
1862 TroubleShootStrId
= IDS_UPDATEDRV
;
1866 case CM_PROB_BOOT_CONFIG_CONFLICT
:
1867 case CM_PROB_NORMAL_CONFLICT
:
1868 case CM_PROB_REENUMERATION
:
1870 /* FIXME - Troubleshoot conflict */
1874 case CM_PROB_FAILED_FILTER
:
1875 case CM_PROB_REINSTALL
:
1876 case CM_PROB_FAILED_INSTALL
:
1878 TroubleShootStrId
= IDS_REINSTALLDRV
;
1882 case CM_PROB_DEVLOADER_NOT_FOUND
:
1885 1) if it's a missing system devloader:
1886 - disable the button (Reinstall Driver)
1887 2) if it's not a system devloader but still missing:
1889 3) if it's not a system devloader but the file can be found:
1891 4) if it's a missing or empty software key
1897 case CM_PROB_INVALID_DATA
:
1898 case CM_PROB_PARTIAL_LOG_CONF
:
1899 case CM_PROB_NO_VALID_LOG_CONF
:
1900 case CM_PROB_HARDWARE_DISABLED
:
1901 case CM_PROB_CANT_SHARE_IRQ
:
1902 case CM_PROB_TRANSLATION_FAILED
:
1903 case CM_PROB_SYSTEM_SHUTDOWN
:
1904 case CM_PROB_PHANTOM
:
1905 bDevActionAvailable
= FALSE
;
1908 case CM_PROB_NOT_VERIFIED
:
1909 case CM_PROB_DEVICE_NOT_THERE
:
1910 /* FIXME - search hardware */
1913 case CM_PROB_NEED_RESTART
:
1914 case CM_PROB_WILL_BE_REMOVED
:
1916 case CM_PROB_TOO_EARLY
:
1917 case CM_PROB_DISABLED_SERVICE
:
1918 TroubleShootStrId
= IDS_REBOOT
;
1921 case CM_PROB_REGISTRY
:
1922 /* FIXME - check registry? */
1925 case CM_PROB_DISABLED
:
1926 /* if device was disabled by the user: */
1927 TroubleShootStrId
= IDS_ENABLEDEV
;
1928 /* FIXME - otherwise disable button because the device was
1929 disabled by the system*/
1932 case CM_PROB_DEVLOADER_NOT_READY
:
1933 /* FIXME - if it's a graphics adapter:
1934 - if it's a a secondary adapter and the main adapter
1944 case CM_PROB_FAILED_ADD
:
1945 TroubleShootStrId
= IDS_PROPERTIES
;
1950 if (LoadString(hDllInstance
,
1953 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])) != 0)
1955 SetWindowText(hDevProbBtn
,
1958 EnableWindow(hDevProbBtn
,
1959 dap
->IsAdmin
&& bDevActionAvailable
);
1961 /* check if the device can be enabled/disabled */
1962 hDevUsage
= GetDlgItem(hwndDlg
,
1965 dap
->CanDisable
= FALSE
;
1966 dap
->DeviceStarted
= FALSE
;
1968 if (CanDisableDevice(DeviceInfoData
->DevInst
,
1972 dap
->CanDisable
= bFlag
;
1975 if (IsDeviceStarted(DeviceInfoData
->DevInst
,
1979 dap
->DeviceStarted
= bFlag
;
1982 /* enable/disable the device usage controls */
1983 EnableWindow(GetDlgItem(hwndDlg
,
1985 dap
->CanDisable
&& dap
->IsAdmin
);
1986 EnableWindow(hDevUsage
,
1987 dap
->CanDisable
&& dap
->IsAdmin
);
1989 /* clear the combobox */
1990 SendMessage(hDevUsage
,
1994 if (dap
->CanDisable
)
1996 InitDevUsageActions(hwndDlg
,
2001 /* find out how many new device property sheets to add.
2002 fake a PROPSHEETHEADER structure, we don't plan to
2003 call PropertySheet again!*/
2004 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
2008 /* get the number of device property sheets for the device */
2009 if (!SetupDiGetClassDevPropertySheets(DeviceInfoSet
,
2014 dap
->PropertySheetType
) &&
2015 nDriverPages
!= 0 && GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
2017 dap
->nDevPropSheets
+= nDriverPages
;
2024 /* include the driver page */
2025 if (dap
->HasDriverPage
)
2026 dap
->nDevPropSheets
++;
2028 /* include the details page */
2030 dap
->nDevPropSheets
++;
2032 if (dap
->HasResourcePage
)
2033 dap
->nDevPropSheets
++;
2035 /* add the device property sheets */
2036 if (dap
->nDevPropSheets
!= 0)
2038 dap
->DevPropSheets
= HeapAlloc(GetProcessHeap(),
2040 dap
->nDevPropSheets
* sizeof(HPROPSHEETPAGE
));
2041 if (dap
->DevPropSheets
!= NULL
)
2043 if (nDriverPages
!= 0)
2045 psh
.phpage
= dap
->DevPropSheets
;
2047 /* query the device property sheet pages to add */
2048 if (SetupDiGetClassDevPropertySheets(DeviceInfoSet
,
2051 dap
->nDevPropSheets
,
2053 dap
->PropertySheetType
))
2055 /* add the property sheets */
2057 iPage
!= nDriverPages
;
2060 if (PropSheet_AddPage(hPropSheetDlg
,
2061 dap
->DevPropSheets
[iPage
]))
2067 dap
->FreeDevPropSheets
= TRUE
;
2071 /* cleanup, we were unable to get the device property sheets */
2072 iPage
= nDriverPages
;
2073 dap
->nDevPropSheets
-= nDriverPages
;
2080 /* add the driver page if necessary */
2081 if (dap
->HasDriverPage
)
2083 PROPSHEETPAGE pspDriver
= {0};
2084 pspDriver
.dwSize
= sizeof(PROPSHEETPAGE
);
2085 pspDriver
.dwFlags
= PSP_DEFAULT
;
2086 pspDriver
.hInstance
= hDllInstance
;
2087 pspDriver
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICEDRIVER
);
2088 pspDriver
.pfnDlgProc
= AdvProcDriverDlgProc
;
2089 pspDriver
.lParam
= (LPARAM
)dap
;
2090 dap
->DevPropSheets
[iPage
] = dap
->pCreatePropertySheetPageW(&pspDriver
);
2091 if (dap
->DevPropSheets
[iPage
] != NULL
)
2093 if (PropSheet_AddPage(hPropSheetDlg
,
2094 dap
->DevPropSheets
[iPage
]))
2101 dap
->pDestroyPropertySheetPage(dap
->DevPropSheets
[iPage
]);
2102 dap
->DevPropSheets
[iPage
] = NULL
;
2109 /* Add the details page */
2110 PROPSHEETPAGE pspDetails
= {0};
2111 pspDetails
.dwSize
= sizeof(PROPSHEETPAGE
);
2112 pspDetails
.dwFlags
= PSP_DEFAULT
;
2113 pspDetails
.hInstance
= hDllInstance
;
2114 pspDetails
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICEDETAILS
);
2115 pspDetails
.pfnDlgProc
= AdvProcDetailsDlgProc
;
2116 pspDetails
.lParam
= (LPARAM
)dap
;
2117 dap
->DevPropSheets
[iPage
] = dap
->pCreatePropertySheetPageW(&pspDetails
);
2118 if (dap
->DevPropSheets
[iPage
] != NULL
)
2120 if (PropSheet_AddPage(hPropSheetDlg
,
2121 dap
->DevPropSheets
[iPage
]))
2128 dap
->pDestroyPropertySheetPage(dap
->DevPropSheets
[iPage
]);
2129 dap
->DevPropSheets
[iPage
] = NULL
;
2134 if (dap
->HasResourcePage
)
2136 PROPSHEETPAGE pspDriver
= {0};
2137 pspDriver
.dwSize
= sizeof(PROPSHEETPAGE
);
2138 pspDriver
.dwFlags
= PSP_DEFAULT
;
2139 pspDriver
.hInstance
= hDllInstance
;
2140 pspDriver
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICERESOURCES
);
2141 pspDriver
.pfnDlgProc
= ResourcesProcDriverDlgProc
;
2142 pspDriver
.lParam
= (LPARAM
)dap
;
2143 dap
->DevPropSheets
[iPage
] = dap
->pCreatePropertySheetPageW(&pspDriver
);
2144 if (dap
->DevPropSheets
[iPage
] != NULL
)
2146 if (PropSheet_AddPage(hPropSheetDlg
,
2147 dap
->DevPropSheets
[iPage
]))
2154 dap
->pDestroyPropertySheetPage(dap
->DevPropSheets
[iPage
]);
2155 dap
->DevPropSheets
[iPage
] = NULL
;
2159 /* FIXME: Add the power page */
2162 dap
->nDevPropSheets
= 0;
2167 PropSheet_RecalcPageSizes(hPropSheetDlg
);
2170 /* finally, disable the apply button */
2171 PropSheet_UnChanged(hPropSheetDlg
,
2173 dap
->DeviceUsageChanged
= FALSE
;
2179 DlgParentSubWndProc(IN HWND hwnd
,
2184 PDEVADVPROP_INFO dap
;
2186 dap
= (PDEVADVPROP_INFO
)GetProp(hwnd
,
2187 L
"DevMgrDevChangeSub");
2190 if (uMsg
== WM_DEVICECHANGE
&& !IsWindowVisible(dap
->hWndGeneralPage
))
2192 SendMessage(dap
->hWndGeneralPage
,
2198 /* pass the message the the old window proc */
2199 return CallWindowProc(dap
->ParentOldWndProc
,
2207 /* this is not a good idea if the subclassed window was an ansi
2208 window, but we failed finding out the previous window proc
2209 so we can't use CallWindowProc. This should rarely - if ever -
2212 return DefWindowProc(hwnd
,
2222 AdvPropGeneralDlgProc(IN HWND hwndDlg
,
2227 PDEVADVPROP_INFO dap
;
2228 INT_PTR Ret
= FALSE
;
2230 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
,
2233 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
2239 switch (LOWORD(wParam
))
2243 if (HIWORD(wParam
) == CBN_SELCHANGE
)
2245 PropSheet_Changed(GetParent(hwndDlg
),
2247 dap
->DeviceUsageChanged
= TRUE
;
2252 case IDC_DEVPROBLEM
:
2256 /* display the device problem wizard */
2257 ShowDeviceProblemWizard(hwndDlg
,
2259 &dap
->DeviceInfoData
,
2270 NMHDR
*hdr
= (NMHDR
*)lParam
;
2274 ApplyGeneralSettings(hwndDlg
,
2283 dap
= (PDEVADVPROP_INFO
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
2288 dap
->hWndGeneralPage
= hwndDlg
;
2290 SetWindowLongPtr(hwndDlg
,
2294 /* subclass the parent window to always receive
2295 WM_DEVICECHANGE messages */
2296 hWndParent
= GetParent(hwndDlg
);
2297 if (hWndParent
!= NULL
)
2299 /* subclass the parent window. This is not safe
2300 if the parent window belongs to another thread! */
2301 dap
->ParentOldWndProc
= (WNDPROC
)SetWindowLongPtr(hWndParent
,
2303 (LONG_PTR
)DlgParentSubWndProc
);
2305 if (dap
->ParentOldWndProc
!= NULL
&&
2307 L
"DevMgrDevChangeSub",
2310 dap
->hWndParent
= hWndParent
;
2314 /* do not call UpdateDevInfo directly in here because it modifies
2315 the pages of the property sheet! */
2316 PostMessage(hwndDlg
,
2325 case WM_DEVICECHANGE
:
2327 /* FIXME - don't call UpdateDevInfo for all events */
2328 UpdateDevInfo(hwndDlg
,
2337 UpdateDevInfo(hwndDlg
,
2340 dap
->PageInitialized
= TRUE
;
2346 /* restore the old window proc of the subclassed parent window */
2347 if (dap
->hWndParent
!= NULL
&& dap
->ParentOldWndProc
!= NULL
)
2349 if (SetWindowLongPtr(dap
->hWndParent
,
2351 (LONG_PTR
)dap
->ParentOldWndProc
) == (LONG_PTR
)DlgParentSubWndProc
)
2353 RemoveProp(dap
->hWndParent
,
2354 L
"DevMgrDevChangeSub");
2367 DisplayDeviceAdvancedProperties(IN HWND hWndParent
,
2368 IN LPCWSTR lpDeviceID OPTIONAL
,
2369 IN HDEVINFO DeviceInfoSet
,
2370 IN PSP_DEVINFO_DATA DeviceInfoData
,
2371 IN HINSTANCE hComCtl32
,
2372 IN LPCWSTR lpMachineName
,
2375 PROPSHEETHEADER psh
= {0};
2376 PROPSHEETPAGE pspGeneral
= {0};
2377 PPROPERTYSHEETW pPropertySheetW
;
2378 PCREATEPROPERTYSHEETPAGEW pCreatePropertySheetPageW
;
2379 PDESTROYPROPERTYSHEETPAGE pDestroyPropertySheetPage
;
2380 PDEVADVPROP_INFO DevAdvPropInfo
;
2381 HMACHINE hMachine
= NULL
;
2382 DWORD DevIdSize
= 0;
2385 /* we don't want to statically link against comctl32, so find the
2386 functions we need dynamically */
2388 (PPROPERTYSHEETW
)GetProcAddress(hComCtl32
,
2390 pCreatePropertySheetPageW
=
2391 (PCREATEPROPERTYSHEETPAGEW
)GetProcAddress(hComCtl32
,
2392 "CreatePropertySheetPageW");
2393 pDestroyPropertySheetPage
=
2394 (PDESTROYPROPERTYSHEETPAGE
)GetProcAddress(hComCtl32
,
2395 "DestroyPropertySheetPage");
2396 if (pPropertySheetW
== NULL
||
2397 pCreatePropertySheetPageW
== NULL
||
2398 pDestroyPropertySheetPage
== NULL
)
2403 if (lpDeviceID
== NULL
)
2405 /* find out how much size is needed for the device id */
2406 if (SetupDiGetDeviceInstanceId(DeviceInfoSet
,
2412 ERR("SetupDiGetDeviceInstanceId unexpectedly returned TRUE!\n");
2416 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
2423 DevIdSize
= (DWORD
)wcslen(lpDeviceID
) + 1;
2426 if (lpMachineName
!= NULL
&& lpMachineName
[0] != L
'\0')
2428 CONFIGRET cr
= CM_Connect_Machine(lpMachineName
,
2430 if (cr
!= CR_SUCCESS
)
2436 /* create the internal structure associated with the "General",
2437 "Driver", ... pages */
2438 DevAdvPropInfo
= HeapAlloc(GetProcessHeap(),
2440 FIELD_OFFSET(DEVADVPROP_INFO
,
2442 (DevIdSize
* sizeof(WCHAR
)));
2443 if (DevAdvPropInfo
== NULL
)
2445 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2449 if (lpDeviceID
== NULL
)
2451 /* read the device instance id */
2452 if (!SetupDiGetDeviceInstanceId(DeviceInfoSet
,
2454 DevAdvPropInfo
->szDeviceID
,
2463 /* copy the device instance id supplied by the caller */
2464 wcscpy(DevAdvPropInfo
->szDeviceID
,
2468 DevAdvPropInfo
->DeviceInfoSet
= DeviceInfoSet
;
2469 DevAdvPropInfo
->DeviceInfoData
= *DeviceInfoData
;
2470 DevAdvPropInfo
->CurrentDeviceInfoSet
= INVALID_HANDLE_VALUE
;
2471 DevAdvPropInfo
->CurrentDeviceInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
2473 DevAdvPropInfo
->ShowRemotePages
= (lpMachineName
!= NULL
&& lpMachineName
[0] != L
'\0');
2474 DevAdvPropInfo
->hMachine
= hMachine
;
2475 DevAdvPropInfo
->lpMachineName
= lpMachineName
;
2476 DevAdvPropInfo
->szDevName
[0] = L
'\0';
2477 DevAdvPropInfo
->hComCtl32
= hComCtl32
;
2478 DevAdvPropInfo
->pCreatePropertySheetPageW
= pCreatePropertySheetPageW
;
2479 DevAdvPropInfo
->pDestroyPropertySheetPage
= pDestroyPropertySheetPage
;
2481 DevAdvPropInfo
->IsAdmin
= IsUserAdmin();
2482 DevAdvPropInfo
->DoDefaultDevAction
= ((dwFlags
& DPF_DEVICE_STATUS_ACTION
) != 0);
2483 DevAdvPropInfo
->Extended
= ((dwFlags
& DPF_EXTENDED
) != 0);
2485 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
2486 psh
.dwFlags
= PSH_PROPTITLE
| PSH_NOAPPLYNOW
;
2487 psh
.hwndParent
= hWndParent
;
2488 psh
.pszCaption
= DevAdvPropInfo
->szDevName
;
2490 DevAdvPropInfo
->PropertySheetType
= DevAdvPropInfo
->ShowRemotePages
?
2491 DIGCDP_FLAG_REMOTE_ADVANCED
:
2492 DIGCDP_FLAG_ADVANCED
;
2494 psh
.phpage
= HeapAlloc(GetProcessHeap(),
2496 1 * sizeof(HPROPSHEETPAGE
));
2497 if (psh
.phpage
== NULL
)
2502 /* add the "General" property sheet */
2503 pspGeneral
.dwSize
= sizeof(PROPSHEETPAGE
);
2504 pspGeneral
.dwFlags
= PSP_DEFAULT
;
2505 pspGeneral
.hInstance
= hDllInstance
;
2506 pspGeneral
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICEGENERAL
);
2507 pspGeneral
.pfnDlgProc
= AdvPropGeneralDlgProc
;
2508 pspGeneral
.lParam
= (LPARAM
)DevAdvPropInfo
;
2509 psh
.phpage
[psh
.nPages
] = pCreatePropertySheetPageW(&pspGeneral
);
2510 if (psh
.phpage
[psh
.nPages
] != NULL
)
2515 DevAdvPropInfo
->nDevPropSheets
= psh
.nPages
;
2517 if (psh
.nPages
!= 0)
2519 Ret
= pPropertySheetW(&psh
);
2521 /* NOTE: no need to destroy the property sheets anymore! */
2528 /* in case of failure the property sheets must be destroyed */
2529 if (psh
.phpage
!= NULL
)
2535 if (psh
.phpage
[i
] != NULL
)
2537 pDestroyPropertySheetPage(psh
.phpage
[i
]);
2543 if (DevAdvPropInfo
!= NULL
)
2545 if (DevAdvPropInfo
->FreeDevPropSheets
)
2547 /* don't free the array if it's the one allocated in
2548 DisplayDeviceAdvancedProperties */
2549 HeapFree(GetProcessHeap(),
2551 DevAdvPropInfo
->DevPropSheets
);
2554 if (DevAdvPropInfo
->CloseDevInst
)
2556 /* close the device info set in case a new one was created */
2557 SetupDiDestroyDeviceInfoList(DevAdvPropInfo
->DeviceInfoSet
);
2560 if (DevAdvPropInfo
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
2562 SetupDiDestroyDeviceInfoList(DevAdvPropInfo
->CurrentDeviceInfoSet
);
2565 if (DevAdvPropInfo
->hDevIcon
!= NULL
)
2567 DestroyIcon(DevAdvPropInfo
->hDevIcon
);
2570 HeapFree(GetProcessHeap(),
2575 if (psh
.phpage
!= NULL
)
2577 HeapFree(GetProcessHeap(),
2582 if (hMachine
!= NULL
)
2584 CM_Disconnect_Machine(hMachine
);
2592 GetDeviceAndComputerName(LPWSTR lpString
,
2594 WCHAR szMachineName
[])
2598 szDeviceID
[0] = L
'\0';
2599 szMachineName
[0] = L
'\0';
2601 while (*lpString
!= L
'\0')
2603 if (*lpString
== L
'/')
2606 if(!_wcsnicmp(lpString
, L
"DeviceID", 8))
2609 if (*lpString
!= L
'\0')
2612 while ((*lpString
!= L
' ') &&
2613 (*lpString
!= L
'\0') &&
2614 (i
<= MAX_DEVICE_ID_LEN
))
2616 szDeviceID
[i
++] = *lpString
++;
2618 szDeviceID
[i
] = L
'\0';
2622 else if (!_wcsnicmp(lpString
, L
"MachineName", 11))
2625 if (*lpString
!= L
'\0')
2628 while ((*lpString
!= L
' ') &&
2629 (*lpString
!= L
'\0') &&
2630 (i
<= MAX_COMPUTERNAME_LENGTH
))
2632 szMachineName
[i
++] = *lpString
++;
2634 szMachineName
[i
] = L
'\0';
2637 /* knock the pointer back one and let the next
2638 * pointer deal with incrementing, otherwise we
2639 * go past the end of the string */
2649 /***************************************************************************
2651 * DeviceAdvancedPropertiesW
2654 * Invokes the device properties dialog, this version may add some property pages
2658 * hWndParent: Handle to the parent window
2659 * lpMachineName: Machine Name, NULL is the local machine
2660 * lpDeviceID: Specifies the device whose properties are to be shown
2663 * Always returns -1, a call to GetLastError returns 0 if successful
2669 DeviceAdvancedPropertiesW(IN HWND hWndParent OPTIONAL
,
2670 IN LPCWSTR lpMachineName OPTIONAL
,
2671 IN LPCWSTR lpDeviceID
)
2674 SP_DEVINFO_DATA DevInfoData
;
2675 HINSTANCE hComCtl32
;
2678 if (lpDeviceID
== NULL
)
2680 SetLastError(ERROR_INVALID_PARAMETER
);
2684 /* dynamically load comctl32 */
2685 hComCtl32
= LoadAndInitComctl32();
2686 if (hComCtl32
!= NULL
)
2688 hDevInfo
= SetupDiCreateDeviceInfoListEx(NULL
,
2692 if (hDevInfo
!= INVALID_HANDLE_VALUE
)
2694 DevInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
2695 if (SetupDiOpenDeviceInfo(hDevInfo
,
2701 Ret
= DisplayDeviceAdvancedProperties(hWndParent
,
2710 SetupDiDestroyDeviceInfoList(hDevInfo
);
2713 FreeLibrary(hComCtl32
);
2720 /***************************************************************************
2722 * DeviceAdvancedPropertiesA
2725 * Invokes the device properties dialog, this version may add some property pages
2729 * hWndParent: Handle to the parent window
2730 * lpMachineName: Machine Name, NULL is the local machine
2731 * lpDeviceID: Specifies the device whose properties are to be shown
2734 * Always returns -1, a call to GetLastError returns 0 if successful
2740 DeviceAdvancedPropertiesA(IN HWND hWndParent OPTIONAL
,
2741 IN LPCSTR lpMachineName OPTIONAL
,
2742 IN LPCSTR lpDeviceID
)
2744 LPWSTR lpMachineNameW
= NULL
;
2745 LPWSTR lpDeviceIDW
= NULL
;
2748 if (lpMachineName
!= NULL
)
2750 if (!(lpMachineNameW
= ConvertMultiByteToUnicode(lpMachineName
,
2756 if (lpDeviceID
!= NULL
)
2758 if (!(lpDeviceIDW
= ConvertMultiByteToUnicode(lpDeviceID
,
2765 Ret
= DeviceAdvancedPropertiesW(hWndParent
,
2770 if (lpMachineNameW
!= NULL
)
2772 HeapFree(GetProcessHeap(),
2776 if (lpDeviceIDW
!= NULL
)
2778 HeapFree(GetProcessHeap(),
2787 /***************************************************************************
2789 * DevicePropertiesExA
2792 * Invokes the extended device properties dialog
2795 * hWndParent: Handle to the parent window
2796 * lpMachineName: Machine Name, NULL is the local machine
2797 * lpDeviceID: Specifies the device whose properties are to be shown, optional if
2798 * bShowDevMgr is nonzero
2799 * dwFlags: This parameter can be a combination of the following flags:
2800 * * DPF_DEVICE_STATUS_ACTION: Only valid if bShowDevMgr, causes
2801 * the default device status action button
2802 * to be clicked (Troubleshoot, Enable
2804 * bShowDevMgr: If non-zero it displays the device manager instead of
2805 * the advanced device property dialog
2808 * 1: if bShowDevMgr is non-zero and no error occured
2809 * -1: a call to GetLastError returns 0 if successful
2815 DevicePropertiesExA(IN HWND hWndParent OPTIONAL
,
2816 IN LPCSTR lpMachineName OPTIONAL
,
2817 IN LPCSTR lpDeviceID OPTIONAL
,
2818 IN DWORD dwFlags OPTIONAL
,
2819 IN BOOL bShowDevMgr
)
2821 LPWSTR lpMachineNameW
= NULL
;
2822 LPWSTR lpDeviceIDW
= NULL
;
2825 if (lpMachineName
!= NULL
)
2827 if (!(lpMachineNameW
= ConvertMultiByteToUnicode(lpMachineName
,
2833 if (lpDeviceID
!= NULL
)
2835 if (!(lpDeviceIDW
= ConvertMultiByteToUnicode(lpDeviceID
,
2842 Ret
= DevicePropertiesExW(hWndParent
,
2849 if (lpMachineNameW
!= NULL
)
2851 HeapFree(GetProcessHeap(),
2855 if (lpDeviceIDW
!= NULL
)
2857 HeapFree(GetProcessHeap(),
2866 /***************************************************************************
2868 * DevicePropertiesExW
2871 * Invokes the extended device properties dialog
2874 * hWndParent: Handle to the parent window
2875 * lpMachineName: Machine Name, NULL is the local machine
2876 * lpDeviceID: Specifies the device whose properties are to be shown, optional if
2877 * bShowDevMgr is nonzero
2878 * dwFlags: This parameter can be a combination of the following flags:
2879 * * DPF_DEVICE_STATUS_ACTION: Only valid if bShowDevMgr, causes
2880 * the default device status action button
2881 * to be clicked (Troubleshoot, Enable
2883 * bShowDevMgr: If non-zero it displays the device manager instead of
2884 * the advanced device property dialog
2887 * 1: if bShowDevMgr is non-zero and no error occured
2888 * -1: a call to GetLastError returns 0 if successful
2894 DevicePropertiesExW(IN HWND hWndParent OPTIONAL
,
2895 IN LPCWSTR lpMachineName OPTIONAL
,
2896 IN LPCWSTR lpDeviceID OPTIONAL
,
2897 IN DWORD dwFlags OPTIONAL
,
2898 IN BOOL bShowDevMgr
)
2902 if (dwFlags
& ~(DPF_EXTENDED
| DPF_DEVICE_STATUS_ACTION
))
2904 FIXME("DevPropertiesExW: Invalid flags: 0x%x\n",
2905 dwFlags
& ~(DPF_EXTENDED
| DPF_DEVICE_STATUS_ACTION
));
2906 SetLastError(ERROR_INVALID_FLAGS
);
2912 FIXME("DevPropertiesExW doesn't support bShowDevMgr!\n");
2913 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2918 SP_DEVINFO_DATA DevInfoData
;
2919 HINSTANCE hComCtl32
;
2921 if (lpDeviceID
== NULL
)
2923 SetLastError(ERROR_INVALID_PARAMETER
);
2927 /* dynamically load comctl32 */
2928 hComCtl32
= LoadAndInitComctl32();
2929 if (hComCtl32
!= NULL
)
2931 hDevInfo
= SetupDiCreateDeviceInfoListEx(NULL
,
2935 if (hDevInfo
!= INVALID_HANDLE_VALUE
)
2937 DevInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
2938 if (SetupDiOpenDeviceInfo(hDevInfo
,
2944 Ret
= DisplayDeviceAdvancedProperties(hWndParent
,
2953 SetupDiDestroyDeviceInfoList(hDevInfo
);
2956 FreeLibrary(hComCtl32
);
2964 /***************************************************************************
2969 * Invokes the device properties dialog directly
2972 * hWndParent: Handle to the parent window
2973 * lpMachineName: Machine Name, NULL is the local machine
2974 * lpDeviceID: Specifies the device whose properties are to be shown
2975 * bShowDevMgr: If non-zero it displays the device manager instead of
2976 * the device property dialog
2979 * >=0: if no errors occured
2980 * -1: if errors occured
2988 DevicePropertiesA(HWND hWndParent
,
2989 LPCSTR lpMachineName
,
2993 return DevicePropertiesExA(hWndParent
,
3001 /***************************************************************************
3006 * Invokes the device properties dialog directly
3009 * hWndParent: Handle to the parent window
3010 * lpMachineName: Machine Name, NULL is the local machine
3011 * lpDeviceID: Specifies the device whose properties are to be shown
3012 * bShowDevMgr: If non-zero it displays the device manager instead of
3013 * the device property dialog
3016 * >=0: if no errors occured
3017 * -1: if errors occured
3025 DevicePropertiesW(HWND hWndParent
,
3026 LPCWSTR lpMachineName
,
3030 return DevicePropertiesExW(hWndParent
,
3038 /***************************************************************************
3040 * DeviceProperties_RunDLLA
3043 * Invokes the device properties dialog
3046 * hWndParent: Handle to the parent window
3047 * hInst: Handle to the application instance
3048 * lpDeviceCmd: A command that includes the DeviceID of the properties to be shown,
3050 * nCmdShow: Specifies how the window should be shown
3057 * - lpDeviceCmd is a string in the form of "/MachineName MACHINE /DeviceID DEVICEPATH"
3058 * (/MachineName is optional). This function only parses this string and eventually
3059 * calls DeviceProperties().
3065 DeviceProperties_RunDLLA(HWND hWndParent
,
3070 LPWSTR lpDeviceCmdW
= NULL
;
3072 if (lpDeviceCmd
!= NULL
)
3074 if ((lpDeviceCmdW
= ConvertMultiByteToUnicode(lpDeviceCmd
,
3077 DeviceProperties_RunDLLW(hWndParent
,
3084 if (lpDeviceCmdW
!= NULL
)
3086 HeapFree(GetProcessHeap(),
3093 /***************************************************************************
3095 * DeviceProperties_RunDLLW
3098 * Invokes the device properties dialog
3101 * hWndParent: Handle to the parent window
3102 * hInst: Handle to the application instance
3103 * lpDeviceCmd: A command that includes the DeviceID of the properties to be shown,
3105 * nCmdShow: Specifies how the window should be shown
3112 * - lpDeviceCmd is a string in the form of "/MachineName MACHINE /DeviceID DEVICEPATH"
3113 * (/MachineName is optional). This function only parses this string and eventually
3114 * calls DeviceProperties().
3120 DeviceProperties_RunDLLW(HWND hWndParent
,
3122 LPCWSTR lpDeviceCmd
,
3125 WCHAR szDeviceID
[MAX_DEVICE_ID_LEN
+1];
3126 WCHAR szMachineName
[MAX_COMPUTERNAME_LENGTH
+1];
3127 LPWSTR lpString
= (LPWSTR
)lpDeviceCmd
;
3129 if (!GetDeviceAndComputerName(lpString
,
3133 ERR("DeviceProperties_RunDLLW DeviceID: %S, MachineName: %S\n", szDeviceID
, szMachineName
);
3137 DevicePropertiesW(hWndParent
,