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
;
324 dap
= (PDEVADVPROP_INFO
)lParam
;
327 SetWindowLongPtr(hwndDlg
,
331 hDriversListView
= GetDlgItem(hwndDlg
,
334 /* add a column to the list view control */
335 lvc
.mask
= LVCF_FMT
| LVCF_WIDTH
;
336 lvc
.fmt
= LVCFMT_LEFT
;
338 (void)ListView_InsertColumn(hDriversListView
,
342 UpdateDriverDetailsDlg(hwndDlg
,
346 if (ListView_GetItemCount(hDriversListView
) == 0)
348 if(LoadStringW(hDllInstance
, IDS_NODRIVERS
, szBuffer
, _countof(szBuffer
)))
349 MessageBoxW(hwndDlg
, szBuffer
, dap
->szDevName
, MB_OK
);
350 EndDialog(hwndDlg
, IDCANCEL
);
360 LPNMHDR pnmhdr
= (LPNMHDR
)lParam
;
362 switch (pnmhdr
->code
)
364 case LVN_ITEMCHANGED
:
366 LPNMLISTVIEW pnmv
= (LPNMLISTVIEW
)lParam
;
367 HWND hDriversListView
= GetDlgItem(hwndDlg
,
370 if (ListView_GetSelectedCount(hDriversListView
) == 0)
372 /* nothing is selected - empty the labels */
373 SetDlgItemText(hwndDlg
,
376 SetDlgItemText(hwndDlg
,
379 SetDlgItemText(hwndDlg
,
382 SetDlgItemText(hwndDlg
,
386 else if (pnmv
->uNewState
!= 0)
388 /* extract version info and update the labels */
389 WCHAR szDriverPath
[MAX_PATH
];
391 ListView_GetItemText(hDriversListView
,
397 UpdateDriverVersionInfoDetails(hwndDlg
,
415 IN PDEVADVPROP_INFO dap
)
417 TOKEN_PRIVILEGES Privileges
;
420 BOOL NeedReboot
= FALSE
;
422 // Better use InstallDevInst:
427 // LPWSTR wszDeviceId,
430 // See: http://comp.os.ms-windows.programmer.win32.narkive.com/J8FTd4KK/signature-of-undocumented-installdevinstex
432 if (!InstallDevInst(hwndDlg
, dap
->szDeviceID
, TRUE
, &dwReboot
))
435 if (NeedReboot
== FALSE
)
438 //FIXME: load text from resource file
439 if (MessageBoxW(hwndDlg
, L
"Reboot now?", L
"Reboot required", MB_YESNO
| MB_ICONQUESTION
) != IDYES
)
442 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
444 ERR("OpenProcessToken failed\n");
448 /* Get the LUID for the Shutdown privilege */
449 if (!LookupPrivilegeValueW(NULL
, SE_SHUTDOWN_NAME
, &Privileges
.Privileges
[0].Luid
))
451 ERR("LookupPrivilegeValue failed\n");
456 /* Assign the Shutdown privilege to our process */
457 Privileges
.PrivilegeCount
= 1;
458 Privileges
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
460 if (!AdjustTokenPrivileges(hToken
, FALSE
, &Privileges
, 0, NULL
, NULL
))
462 ERR("AdjustTokenPrivileges failed\n");
467 /* Finally shut down the system */
468 if (!ExitWindowsEx(EWX_REBOOT
, SHTDN_REASON_MAJOR_OTHER
| SHTDN_REASON_MINOR_OTHER
| SHTDN_REASON_FLAG_PLANNED
))
470 ERR("ExitWindowsEx failed\n");
477 UpdateDriverDlg(IN HWND hwndDlg
,
478 IN PDEVADVPROP_INFO dap
)
480 HDEVINFO DeviceInfoSet
;
481 PSP_DEVINFO_DATA DeviceInfoData
;
483 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
485 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
486 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
490 DeviceInfoSet
= dap
->DeviceInfoSet
;
491 DeviceInfoData
= &dap
->DeviceInfoData
;
494 /* set the device image */
495 SendDlgItemMessage(hwndDlg
,
498 (WPARAM
)dap
->hDevIcon
,
501 /* set the device name edit control text */
502 SetDlgItemText(hwndDlg
,
506 /* query the driver provider */
507 if (GetDriverProviderString(DeviceInfoSet
,
510 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
512 SetDlgItemText(hwndDlg
,
517 /* query the driver date */
518 if (GetDriverDateString(DeviceInfoSet
,
521 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
523 SetDlgItemText(hwndDlg
,
528 /* query the driver version */
529 if (GetDriverVersionString(DeviceInfoSet
,
532 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
534 SetDlgItemText(hwndDlg
,
543 AdvProcDriverDlgProc(IN HWND hwndDlg
,
548 PDEVADVPROP_INFO dap
;
551 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
,
554 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
560 switch (LOWORD(wParam
))
562 case IDC_DRIVERDETAILS
:
563 DialogBoxParam(hDllInstance
,
564 MAKEINTRESOURCE(IDD_DRIVERDETAILS
),
566 DriverDetailsDlgProc
,
570 case IDC_UPDATEDRIVER
:
571 UpdateDriver(hwndDlg
, dap
);
579 NMHDR
*hdr
= (NMHDR
*)lParam
;
590 dap
= (PDEVADVPROP_INFO
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
593 SetWindowLongPtr(hwndDlg
,
597 UpdateDriverDlg(hwndDlg
,
611 SetListViewText(HWND hwnd
,
617 li
.mask
= LVIF_TEXT
| LVIF_STATE
;
620 li
.state
= 0; //(li.iItem == 0 ? LVIS_SELECTED : 0);
621 li
.stateMask
= LVIS_SELECTED
;
623 (void)ListView_InsertItem(hwnd
,
629 UpdateDetailsDlg(IN HWND hwndDlg
,
630 IN PDEVADVPROP_INFO dap
)
641 IDS_PROP_HARDWAREIDS
,
642 IDS_PROP_COMPATIBLEIDS
,
643 IDS_PROP_MATCHINGDEVICEID
,
646 IDS_PROP_CAPABILITIES
,
647 IDS_PROP_DEVNODEFLAGS
,
648 IDS_PROP_CONFIGFLAGS
,
649 IDS_PROP_CSCONFIGFLAGS
,
650 IDS_PROP_EJECTIONRELATIONS
,
651 IDS_PROP_REMOVALRELATIONS
,
652 IDS_PROP_BUSRELATIONS
,
653 IDS_PROP_DEVUPPERFILTERS
,
654 IDS_PROP_DEVLOWERFILTERS
,
655 IDS_PROP_CLASSUPPERFILTERS
,
656 IDS_PROP_CLASSLOWERFILTERS
,
657 IDS_PROP_CLASSINSTALLER
,
658 IDS_PROP_CLASSCOINSTALLER
,
659 IDS_PROP_DEVICECOINSTALLER
,
660 IDS_PROP_FIRMWAREREVISION
,
661 IDS_PROP_CURRENTPOWERSTATE
,
662 IDS_PROP_POWERCAPABILITIES
,
663 IDS_PROP_POWERSTATEMAPPINGS
667 /* set the device image */
668 SendDlgItemMessage(hwndDlg
,
671 (WPARAM
)dap
->hDevIcon
,
674 /* set the device name edit control text */
675 SetDlgItemText(hwndDlg
,
680 hwndComboBox
= GetDlgItem(hwndDlg
,
681 IDC_DETAILSPROPNAME
);
683 hwndListView
= GetDlgItem(hwndDlg
,
684 IDC_DETAILSPROPVALUE
);
686 for (i
= 0; i
!= sizeof(Properties
) / sizeof(Properties
[0]); i
++)
688 /* fill in the device usage combo box */
689 if (LoadString(hDllInstance
,
692 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
694 SendMessage(hwndComboBox
,
697 (LPARAM
)dap
->szTemp
);
702 GetClientRect(hwndListView
,
705 /* add a column to the list view control */
706 lvc
.mask
= LVCF_FMT
| LVCF_WIDTH
;
707 lvc
.fmt
= LVCFMT_LEFT
;
708 lvc
.cx
= rcClient
.right
;
709 (void)ListView_InsertColumn(hwndListView
,
713 SendMessage(hwndComboBox
,
718 SetListViewText(hwndListView
, 0, dap
->szDeviceID
);
720 SetFocus(hwndComboBox
);
725 DisplayDevicePropertyText(IN PDEVADVPROP_INFO dap
,
726 IN HWND hwndListView
,
729 HDEVINFO DeviceInfoSet
;
730 PSP_DEVINFO_DATA DeviceInfoData
;
739 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
741 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
742 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
746 DeviceInfoSet
= dap
->DeviceInfoSet
;
747 DeviceInfoData
= &dap
->DeviceInfoData
;
751 SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
760 if (GetLastError() != ERROR_FILE_NOT_FOUND
)
762 swprintf(dap
->szTemp
, L
"Error: Getting the size failed! (Error: %ld)", GetLastError());
763 SetListViewText(hwndListView
, 0, dap
->szTemp
);
768 if (dwType
== REG_SZ
)
769 dwSize
+= sizeof(WCHAR
);
771 lpBuffer
= HeapAlloc(GetProcessHeap(),
774 if (lpBuffer
== NULL
)
776 SetListViewText(hwndListView
, 0, L
"Error: Allocating the buffer failed!");
780 if (SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
788 if (dwType
== REG_SZ
)
790 SetListViewText(hwndListView
, 0, (LPWSTR
)lpBuffer
);
792 else if (dwType
== REG_MULTI_SZ
)
794 lpStr
= (LPWSTR
)lpBuffer
;
798 len
= wcslen(lpStr
) + 1;
800 SetListViewText(hwndListView
, index
, lpStr
);
806 else if (dwType
== REG_DWORD
)
808 dwValue
= *(DWORD
*) lpBuffer
;
812 case SPDRP_CAPABILITIES
:
814 if (dwValue
& CM_DEVCAP_LOCKSUPPORTED
)
815 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_LOCKSUPPORTED");
816 if (dwValue
& CM_DEVCAP_EJECTSUPPORTED
)
817 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_EJECTSUPPORTED");
818 if (dwValue
& CM_DEVCAP_REMOVABLE
)
819 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_REMOVABLE");
820 if (dwValue
& CM_DEVCAP_DOCKDEVICE
)
821 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_DOCKDEVICE");
822 if (dwValue
& CM_DEVCAP_UNIQUEID
)
823 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_UNIQUEID");
824 if (dwValue
& CM_DEVCAP_SILENTINSTALL
)
825 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_SILENTINSTALL");
826 if (dwValue
& CM_DEVCAP_RAWDEVICEOK
)
827 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_RAWDEVICEOK");
828 if (dwValue
& CM_DEVCAP_SURPRISEREMOVALOK
)
829 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_SURPRISEREMOVALOK");
830 if (dwValue
& CM_DEVCAP_HARDWAREDISABLED
)
831 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_HARDWAREDISABLED");
832 if (dwValue
& CM_DEVCAP_NONDYNAMIC
)
833 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_NONDYNAMIC");
836 case SPDRP_CONFIGFLAGS
:
838 if (dwValue
& CONFIGFLAG_DISABLED
)
839 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_DISABLED");
840 if (dwValue
& CONFIGFLAG_REMOVED
)
841 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_REMOVED");
842 if (dwValue
& CONFIGFLAG_MANUAL_INSTALL
)
843 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_MANUAL_INSTALL");
844 if (dwValue
& CONFIGFLAG_IGNORE_BOOT_LC
)
845 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_IGNORE_BOOT_LC");
846 if (dwValue
& CONFIGFLAG_NET_BOOT
)
847 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_NET_BOOT");
848 if (dwValue
& CONFIGFLAG_REINSTALL
)
849 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_REINSTALL");
850 if (dwValue
& CONFIGFLAG_FAILEDINSTALL
)
851 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_FAILEDINSTALL");
852 if (dwValue
& CONFIGFLAG_CANTSTOPACHILD
)
853 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_CANTSTOPACHILD");
854 if (dwValue
& CONFIGFLAG_OKREMOVEROM
)
855 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_OKREMOVEROM");
856 if (dwValue
& CONFIGFLAG_NOREMOVEEXIT
)
857 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_NOREMOVEEXIT");
861 swprintf(dap
->szTemp
, L
"0x%08lx", dwValue
);
862 SetListViewText(hwndListView
, 0, dap
->szTemp
);
868 SetListViewText(hwndListView
, 0, L
"Error: Unsupported value type!");
874 SetListViewText(hwndListView
, 0, L
"Error: Retrieving the value failed!");
877 HeapFree(GetProcessHeap(),
883 DisplayDevNodeFlags(IN PDEVADVPROP_INFO dap
,
884 IN HWND hwndListView
)
890 CM_Get_DevNode_Status_Ex(&dwStatus
,
892 dap
->DeviceInfoData
.DevInst
,
897 if (dwStatus
& DN_ROOT_ENUMERATED
)
898 SetListViewText(hwndListView
, index
++, L
"DN_ROOT_ENUMERATED");
899 if (dwStatus
& DN_DRIVER_LOADED
)
900 SetListViewText(hwndListView
, index
++, L
"DN_DRIVER_LOADED");
901 if (dwStatus
& DN_ENUM_LOADED
)
902 SetListViewText(hwndListView
, index
++, L
"DN_ENUM_LOADED");
903 if (dwStatus
& DN_STARTED
)
904 SetListViewText(hwndListView
, index
++, L
"DN_STARTED");
905 if (dwStatus
& DN_MANUAL
)
906 SetListViewText(hwndListView
, index
++, L
"DN_MANUAL");
907 if (dwStatus
& DN_NEED_TO_ENUM
)
908 SetListViewText(hwndListView
, index
++, L
"DN_NEED_TO_ENUM");
909 if (dwStatus
& DN_DRIVER_BLOCKED
)
910 SetListViewText(hwndListView
, index
++, L
"DN_DRIVER_BLOCKED");
911 if (dwStatus
& DN_HARDWARE_ENUM
)
912 SetListViewText(hwndListView
, index
++, L
"DN_HARDWARE_ENUM");
913 if (dwStatus
& DN_NEED_RESTART
)
914 SetListViewText(hwndListView
, index
++, L
"DN_NEED_RESTART");
915 if (dwStatus
& DN_CHILD_WITH_INVALID_ID
)
916 SetListViewText(hwndListView
, index
++, L
"DN_CHILD_WITH_INVALID_ID");
917 if (dwStatus
& DN_HAS_PROBLEM
)
918 SetListViewText(hwndListView
, index
++, L
"DN_HAS_PROBLEM");
919 if (dwStatus
& DN_FILTERED
)
920 SetListViewText(hwndListView
, index
++, L
"DN_FILTERED");
921 if (dwStatus
& DN_LEGACY_DRIVER
)
922 SetListViewText(hwndListView
, index
++, L
"DN_LEGACY_DRIVER");
923 if (dwStatus
& DN_DISABLEABLE
)
924 SetListViewText(hwndListView
, index
++, L
"DN_DISABLEABLE");
925 if (dwStatus
& DN_REMOVABLE
)
926 SetListViewText(hwndListView
, index
++, L
"DN_REMOVABLE");
927 if (dwStatus
& DN_PRIVATE_PROBLEM
)
928 SetListViewText(hwndListView
, index
++, L
"DN_PRIVATE_PROBLEM");
929 if (dwStatus
& DN_MF_PARENT
)
930 SetListViewText(hwndListView
, index
++, L
"DN_MF_PARENT");
931 if (dwStatus
& DN_MF_CHILD
)
932 SetListViewText(hwndListView
, index
++, L
"DN_MF_CHILD");
933 if (dwStatus
& DN_WILL_BE_REMOVED
)
934 SetListViewText(hwndListView
, index
++, L
"DN_WILL_BE_REMOVED");
936 if (dwStatus
& DN_NOT_FIRST_TIMEE
)
937 SetListViewText(hwndListView
, index
++, L
"DN_NOT_FIRST_TIMEE");
938 if (dwStatus
& DN_STOP_FREE_RES
)
939 SetListViewText(hwndListView
, index
++, L
"DN_STOP_FREE_RES");
940 if (dwStatus
& DN_REBAL_CANDIDATE
)
941 SetListViewText(hwndListView
, index
++, L
"DN_REBAL_CANDIDATE");
942 if (dwStatus
& DN_BAD_PARTIAL
)
943 SetListViewText(hwndListView
, index
++, L
"DN_BAD_PARTIAL");
944 if (dwStatus
& DN_NT_ENUMERATOR
)
945 SetListViewText(hwndListView
, index
++, L
"DN_NT_ENUMERATOR");
946 if (dwStatus
& DN_NT_DRIVER
)
947 SetListViewText(hwndListView
, index
++, L
"DN_NT_DRIVER");
949 if (dwStatus
& DN_NEEDS_LOCKING
)
950 SetListViewText(hwndListView
, index
++, L
"DN_NEEDS_LOCKING");
951 if (dwStatus
& DN_ARM_WAKEUP
)
952 SetListViewText(hwndListView
, index
++, L
"DN_ARM_WAKEUP");
953 if (dwStatus
& DN_APM_ENUMERATOR
)
954 SetListViewText(hwndListView
, index
++, L
"DN_APM_ENUMERATOR");
955 if (dwStatus
& DN_APM_DRIVER
)
956 SetListViewText(hwndListView
, index
++, L
"DN_APM_DRIVER");
957 if (dwStatus
& DN_SILENT_INSTALL
)
958 SetListViewText(hwndListView
, index
++, L
"DN_SILENT_INSTALL");
959 if (dwStatus
& DN_NO_SHOW_IN_DM
)
960 SetListViewText(hwndListView
, index
++, L
"DN_NO_SHOW_IN_DM");
961 if (dwStatus
& DN_BOOT_LOG_PROB
)
962 SetListViewText(hwndListView
, index
++, L
"DN_BOOT_LOG_PROB");
964 // swprintf(dap->szTemp, L"0x%08x", dwStatus);
965 // SetListViewText(hwndListView, 0, dap->szTemp);
970 DisplayDevNodeEnumerator(IN PDEVADVPROP_INFO dap
,
971 IN HWND hwndListView
)
973 PSP_DEVINFO_DATA DeviceInfoData
;
977 DWORD dwSize
= 256 * sizeof(WCHAR
);
979 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
981 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
985 DeviceInfoData
= &dap
->DeviceInfoData
;
988 CM_Get_DevNode_Registry_Property_ExW(DeviceInfoData
->DevInst
,
989 CM_DRP_ENUMERATOR_NAME
,
996 SetListViewText(hwndListView
, 0, szBuffer
);
1001 DisplayCsFlags(IN PDEVADVPROP_INFO dap
,
1002 IN HWND hwndListView
)
1007 CM_Get_HW_Prof_Flags_Ex(dap
->szDevName
,
1008 0, /* current hardware profile */
1014 if (dwValue
& CSCONFIGFLAG_DISABLED
)
1015 SetListViewText(hwndListView
, index
++, L
"CSCONFIGFLAG_DISABLED");
1017 if (dwValue
& CSCONFIGFLAG_DO_NOT_CREATE
)
1018 SetListViewText(hwndListView
, index
++, L
"CSCONFIGFLAG_DO_NOT_CREATE");
1020 if (dwValue
& CSCONFIGFLAG_DO_NOT_START
)
1021 SetListViewText(hwndListView
, index
++, L
"CSCONFIGFLAG_DO_NOT_START");
1026 DisplayMatchingDeviceId(IN PDEVADVPROP_INFO dap
,
1027 IN HWND hwndListView
)
1029 HDEVINFO DeviceInfoSet
;
1030 PSP_DEVINFO_DATA DeviceInfoData
;
1031 WCHAR szBuffer
[256];
1036 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1038 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1039 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1043 DeviceInfoSet
= dap
->DeviceInfoSet
;
1044 DeviceInfoData
= &dap
->DeviceInfoData
;
1047 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
,
1053 if (hKey
!= INVALID_HANDLE_VALUE
)
1055 dwSize
= 256 * sizeof(WCHAR
);
1056 if (RegQueryValueEx(hKey
,
1057 L
"MatchingDeviceId",
1061 &dwSize
) == ERROR_SUCCESS
)
1063 SetListViewText(hwndListView
, 0, szBuffer
);
1072 DisplayClassCoinstallers(IN PDEVADVPROP_INFO dap
,
1073 IN HWND hwndListView
)
1075 HDEVINFO DeviceInfoSet
;
1076 PSP_DEVINFO_DATA DeviceInfoData
;
1077 WCHAR szClassGuid
[45];
1078 HKEY hKey
= INVALID_HANDLE_VALUE
;
1081 LPBYTE lpBuffer
= NULL
;
1087 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1089 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1090 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1094 DeviceInfoSet
= dap
->DeviceInfoSet
;
1095 DeviceInfoData
= &dap
->DeviceInfoData
;
1098 dwSize
= 45 * sizeof(WCHAR
);
1099 if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
1103 (LPBYTE
)szClassGuid
,
1108 lError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1109 L
"SYSTEM\\CurrentControlSet\\Control\\CoDeviceInstallers",
1113 if (lError
!= ERROR_SUCCESS
)
1117 lError
= RegQueryValueEx(hKey
,
1123 if (lError
!= ERROR_SUCCESS
)
1129 lpBuffer
= HeapAlloc(GetProcessHeap(),
1133 RegQueryValueEx(hKey
,
1140 lpStr
= (LPWSTR
)lpBuffer
;
1144 len
= wcslen(lpStr
) + 1;
1146 SetListViewText(hwndListView
, index
, lpStr
);
1153 if (lpBuffer
!= NULL
)
1154 HeapFree(GetProcessHeap(), 0, lpBuffer
);
1156 if (hKey
!= INVALID_HANDLE_VALUE
)
1162 DisplayDeviceCoinstallers(IN PDEVADVPROP_INFO dap
,
1163 IN HWND hwndListView
)
1165 HDEVINFO DeviceInfoSet
;
1166 PSP_DEVINFO_DATA DeviceInfoData
;
1175 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1177 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1178 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1182 DeviceInfoSet
= dap
->DeviceInfoSet
;
1183 DeviceInfoData
= &dap
->DeviceInfoData
;
1186 hKey
= SetupDiOpenDevRegKey(DeviceInfoSet
,
1192 if (hKey
!= INVALID_HANDLE_VALUE
)
1195 if (RegQueryValueEx(hKey
,
1200 &dwSize
) == ERROR_SUCCESS
&&
1204 lpBuffer
= HeapAlloc(GetProcessHeap(),
1208 RegQueryValueEx(hKey
,
1215 lpStr
= (LPWSTR
)lpBuffer
;
1219 len
= wcslen(lpStr
) + 1;
1221 SetListViewText(hwndListView
, index
, lpStr
);
1227 HeapFree(GetProcessHeap(),
1238 DisplayClassProperties(IN PDEVADVPROP_INFO dap
,
1239 IN HWND hwndListView
,
1240 IN LPWSTR lpProperty
)
1242 HDEVINFO DeviceInfoSet
;
1243 PSP_DEVINFO_DATA DeviceInfoData
;
1244 WCHAR szClassGuid
[45];
1254 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1256 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1257 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1261 DeviceInfoSet
= dap
->DeviceInfoSet
;
1262 DeviceInfoData
= &dap
->DeviceInfoData
;
1265 dwSize
= 45 * sizeof(WCHAR
);
1266 if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
1270 (LPBYTE
)szClassGuid
,
1275 pSetupGuidFromString(szClassGuid
,
1278 hKey
= SetupDiOpenClassRegKey(&ClassGuid
,
1280 if (hKey
!= INVALID_HANDLE_VALUE
)
1283 if (RegQueryValueEx(hKey
,
1288 &dwSize
) == ERROR_SUCCESS
&&
1291 lpBuffer
= HeapAlloc(GetProcessHeap(),
1295 RegQueryValueEx(hKey
,
1302 if (dwType
== REG_SZ
)
1304 SetListViewText(hwndListView
, 0, (LPWSTR
)lpBuffer
);
1306 else if (dwType
== REG_MULTI_SZ
)
1308 lpStr
= (LPWSTR
)lpBuffer
;
1312 len
= wcslen(lpStr
) + 1;
1314 SetListViewText(hwndListView
, index
, lpStr
);
1321 HeapFree(GetProcessHeap(),
1332 DisplayDeviceProperties(IN PDEVADVPROP_INFO dap
,
1333 IN HWND hwndComboBox
,
1334 IN HWND hwndListView
)
1338 Index
= (INT
)SendMessage(hwndComboBox
,
1342 if (Index
== CB_ERR
)
1345 (void)ListView_DeleteAllItems(hwndListView
);
1350 SetListViewText(hwndListView
, 0, dap
->szDeviceID
);
1353 case 1: /* Hardware ID */
1354 DisplayDevicePropertyText(dap
,
1359 case 2: /* Compatible IDs */
1360 DisplayDevicePropertyText(dap
,
1362 SPDRP_COMPATIBLEIDS
);
1365 case 3: /* Matching ID */
1366 DisplayMatchingDeviceId(dap
,
1370 case 4: /* Service */
1371 DisplayDevicePropertyText(dap
,
1376 case 5: /* Enumerator */
1377 DisplayDevNodeEnumerator(dap
,
1381 case 6: /* Capabilities */
1382 DisplayDevicePropertyText(dap
,
1384 SPDRP_CAPABILITIES
);
1387 case 7: /* Devnode Flags */
1388 DisplayDevNodeFlags(dap
,
1392 case 8: /* Config Flags */
1393 DisplayDevicePropertyText(dap
,
1398 case 9: /* CSConfig Flags */
1404 case 10: /* Ejection relation */
1407 case 11: /* Removal relations */
1410 case 12: /* Bus relation */
1414 case 13: /* Device Upper Filters */
1415 DisplayDevicePropertyText(dap
,
1417 SPDRP_UPPERFILTERS
);
1420 case 14: /* Device Lower Filters */
1421 DisplayDevicePropertyText(dap
,
1423 SPDRP_LOWERFILTERS
);
1426 case 15: /* Class Upper Filters */
1427 DisplayClassProperties(dap
,
1432 case 16: /* Class Lower Filters */
1433 DisplayClassProperties(dap
,
1438 case 17: /* Class Installer */
1439 DisplayClassProperties(dap
,
1444 case 18: /* Class Coinstaller */
1445 DisplayClassCoinstallers(dap
,
1449 case 19: /* Device Coinstaller */
1450 DisplayDeviceCoinstallers(dap
,
1455 case 20: /* Firmware Revision */
1458 case 21: /* Current Power State */
1461 case 20: /* Power Capabilities */
1464 case 21: /* Power State Mappings */
1469 SetListViewText(hwndListView
, 0, L
"<Not implemented yet>");
1477 AdvProcDetailsDlgProc(IN HWND hwndDlg
,
1482 PDEVADVPROP_INFO dap
;
1483 INT_PTR Ret
= FALSE
;
1485 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
,
1488 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
1494 switch (LOWORD(wParam
))
1496 case IDC_DETAILSPROPNAME
:
1497 if (HIWORD(wParam
) == CBN_SELCHANGE
)
1499 DisplayDeviceProperties(dap
,
1500 GetDlgItem(hwndDlg
, IDC_DETAILSPROPNAME
),
1501 GetDlgItem(hwndDlg
, IDC_DETAILSPROPVALUE
));
1510 NMHDR
*hdr
= (NMHDR
*)lParam
;
1521 dap
= (PDEVADVPROP_INFO
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1524 SetWindowLongPtr(hwndDlg
,
1528 UpdateDetailsDlg(hwndDlg
,
1542 InitDevUsageActions(IN HWND hwndDlg
,
1544 IN PDEVADVPROP_INFO dap
)
1555 i
!= sizeof(Actions
) / sizeof(Actions
[0]);
1558 /* fill in the device usage combo box */
1559 if (LoadString(hDllInstance
,
1562 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1564 Index
= (INT
)SendMessage(hComboBox
,
1567 (LPARAM
)dap
->szTemp
);
1568 if (Index
!= CB_ERR
)
1570 SendMessage(hComboBox
,
1573 (LPARAM
)Actions
[i
]);
1577 case IDS_ENABLEDEVICE
:
1578 if (dap
->DeviceStarted
)
1580 SendMessage(hComboBox
,
1587 case IDS_DISABLEDEVICE
:
1588 if (!dap
->DeviceStarted
)
1590 SendMessage(hComboBox
,
1607 GetSelectedUsageAction(IN HWND hComboBox
)
1612 Index
= (INT
)SendMessage(hComboBox
,
1616 if (Index
!= CB_ERR
)
1618 INT iRet
= (INT
) SendMessage(hComboBox
,
1633 ApplyGeneralSettings(IN HWND hwndDlg
,
1634 IN PDEVADVPROP_INFO dap
)
1638 if (dap
->DeviceUsageChanged
&& dap
->IsAdmin
&& dap
->CanDisable
)
1640 UINT SelectedUsageAction
;
1641 BOOL NeedReboot
= FALSE
;
1643 SelectedUsageAction
= GetSelectedUsageAction(GetDlgItem(hwndDlg
,
1645 switch (SelectedUsageAction
)
1647 case IDS_ENABLEDEVICE
:
1648 if (!dap
->DeviceStarted
)
1650 Ret
= EnableDevice(dap
->DeviceInfoSet
,
1651 &dap
->DeviceInfoData
,
1658 case IDS_DISABLEDEVICE
:
1659 if (dap
->DeviceStarted
)
1661 Ret
= EnableDevice(dap
->DeviceInfoSet
,
1662 &dap
->DeviceInfoData
,
1677 /* make PropertySheet() return PSM_REBOOTSYSTEM */
1678 PropSheet_RebootSystem(hwndDlg
);
1683 /* FIXME - display an error message */
1684 FIXME("Failed to enable/disable device! LastError: %d\n",
1689 Ret
= !dap
->DeviceUsageChanged
;
1691 /* disable the apply button */
1692 PropSheet_UnChanged(GetParent(hwndDlg
),
1694 dap
->DeviceUsageChanged
= FALSE
;
1700 UpdateDevInfo(IN HWND hwndDlg
,
1701 IN PDEVADVPROP_INFO dap
,
1704 HWND hDevUsage
, hPropSheetDlg
, hDevProbBtn
;
1706 ULONG Status
, ProblemNumber
;
1707 SP_DEVINSTALL_PARAMS_W InstallParams
;
1708 UINT TroubleShootStrId
= IDS_TROUBLESHOOTDEV
;
1709 BOOL bFlag
, bDevActionAvailable
= TRUE
;
1710 BOOL bDrvInstalled
= FALSE
;
1712 HDEVINFO DeviceInfoSet
= NULL
;
1713 PSP_DEVINFO_DATA DeviceInfoData
= NULL
;
1714 PROPSHEETHEADER psh
;
1715 DWORD nDriverPages
= 0;
1716 BOOL RecalcPages
= FALSE
;
1718 TRACE("UpdateDevInfo()\n");
1720 hPropSheetDlg
= GetParent(hwndDlg
);
1722 if (dap
->PageInitialized
)
1724 /* switch to the General page */
1725 PropSheet_SetCurSelByID(hPropSheetDlg
,
1728 /* remove and destroy the existing device property sheet pages */
1729 if (dap
->DevPropSheets
!= NULL
)
1732 iPage
!= dap
->nDevPropSheets
;
1735 if (dap
->DevPropSheets
[iPage
] != NULL
)
1737 PropSheet_RemovePage(hPropSheetDlg
,
1739 dap
->DevPropSheets
[iPage
]);
1748 if (dap
->FreeDevPropSheets
)
1750 /* don't free the array if it's the one allocated in
1751 DisplayDeviceAdvancedProperties */
1752 HeapFree(GetProcessHeap(),
1754 dap
->DevPropSheets
);
1756 dap
->FreeDevPropSheets
= FALSE
;
1759 dap
->DevPropSheets
= NULL
;
1760 dap
->nDevPropSheets
= 0;
1764 /* create a new device info set and re-open the device */
1765 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1767 SetupDiDestroyDeviceInfoList(dap
->CurrentDeviceInfoSet
);
1770 dap
->ParentDevInst
= 0;
1771 dap
->CurrentDeviceInfoSet
= SetupDiCreateDeviceInfoListEx(NULL
,
1775 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1777 if (SetupDiOpenDeviceInfo(dap
->CurrentDeviceInfoSet
,
1781 &dap
->CurrentDeviceInfoData
))
1783 if (dap
->CloseDevInst
)
1785 SetupDiDestroyDeviceInfoList(dap
->DeviceInfoSet
);
1788 dap
->CloseDevInst
= TRUE
;
1789 dap
->DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1790 dap
->DeviceInfoData
= dap
->CurrentDeviceInfoData
;
1791 dap
->CurrentDeviceInfoSet
= INVALID_HANDLE_VALUE
;
1799 /* get the parent node from the initial devinst */
1800 CM_Get_Parent_Ex(&dap
->ParentDevInst
,
1801 dap
->DeviceInfoData
.DevInst
,
1806 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1808 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1809 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1813 DeviceInfoSet
= dap
->DeviceInfoSet
;
1814 DeviceInfoData
= &dap
->DeviceInfoData
;
1819 DeviceInfoSet
= dap
->DeviceInfoSet
;
1820 DeviceInfoData
= &dap
->DeviceInfoData
;
1823 dap
->HasDriverPage
= FALSE
;
1824 dap
->HasResourcePage
= FALSE
;
1825 dap
->HasPowerPage
= FALSE
;
1826 if (IsDriverInstalled(DeviceInfoData
->DevInst
,
1831 if (SetupDiCallClassInstaller((dap
->ShowRemotePages
?
1832 DIF_ADDREMOTEPROPERTYPAGE_ADVANCED
:
1833 DIF_ADDPROPERTYPAGE_ADVANCED
),
1837 /* get install params */
1838 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
1839 if (!SetupDiGetDeviceInstallParamsW(DeviceInfoSet
,
1843 /* zero the flags */
1844 InstallParams
.Flags
= 0;
1847 dap
->HasDriverPage
= !(InstallParams
.Flags
& DI_DRIVERPAGE_ADDED
);
1848 dap
->HasResourcePage
= !(InstallParams
.Flags
& DI_RESOURCEPAGE_ADDED
);
1849 dap
->HasPowerPage
= !(InstallParams
.Flags
& DI_FLAGSEX_POWERPAGE_ADDED
);
1853 /* get the device icon */
1854 if (dap
->hDevIcon
!= NULL
)
1856 DestroyIcon(dap
->hDevIcon
);
1857 dap
->hDevIcon
= NULL
;
1859 if (!SetupDiLoadClassIcon(&DeviceInfoData
->ClassGuid
,
1863 dap
->hDevIcon
= NULL
;
1866 /* get the device name */
1867 if (GetDeviceDescriptionString(DeviceInfoSet
,
1870 sizeof(dap
->szDevName
) / sizeof(dap
->szDevName
[0])))
1872 PropSheet_SetTitle(hPropSheetDlg
,
1877 /* set the device image */
1878 SendDlgItemMessage(hwndDlg
,
1881 (WPARAM
)dap
->hDevIcon
,
1884 /* set the device name edit control text */
1885 SetDlgItemText(hwndDlg
,
1889 /* set the device type edit control text */
1890 if (GetDeviceTypeString(DeviceInfoData
,
1892 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1894 SetDlgItemText(hwndDlg
,
1899 /* set the device manufacturer edit control text */
1900 if (GetDeviceManufacturerString(DeviceInfoSet
,
1903 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1905 SetDlgItemText(hwndDlg
,
1906 IDC_DEVMANUFACTURER
,
1910 /* set the device location edit control text */
1911 if (GetDeviceLocationString(DeviceInfoSet
,
1915 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1917 SetDlgItemText(hwndDlg
,
1922 /* set the device status edit control text */
1923 if (GetDeviceStatusString(DeviceInfoData
->DevInst
,
1926 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1928 SetDlgItemText(hwndDlg
,
1933 /* set the device troubleshoot button text and disable it if necessary */
1934 hDevProbBtn
= GetDlgItem(hwndDlg
,
1936 cr
= CM_Get_DevNode_Status_Ex(&Status
,
1938 DeviceInfoData
->DevInst
,
1941 if (cr
== CR_SUCCESS
&& (Status
& DN_HAS_PROBLEM
))
1943 switch (ProblemNumber
)
1945 case CM_PROB_DEVLOADER_FAILED
:
1947 /* FIXME - only if it's not a root bus devloader,
1948 disable the button otherwise */
1949 TroubleShootStrId
= IDS_UPDATEDRV
;
1953 case CM_PROB_OUT_OF_MEMORY
:
1954 case CM_PROB_ENTRY_IS_WRONG_TYPE
:
1955 case CM_PROB_LACKED_ARBITRATOR
:
1956 case CM_PROB_FAILED_START
:
1958 case CM_PROB_UNKNOWN_RESOURCE
:
1960 TroubleShootStrId
= IDS_UPDATEDRV
;
1964 case CM_PROB_BOOT_CONFIG_CONFLICT
:
1965 case CM_PROB_NORMAL_CONFLICT
:
1966 case CM_PROB_REENUMERATION
:
1968 /* FIXME - Troubleshoot conflict */
1972 case CM_PROB_FAILED_FILTER
:
1973 case CM_PROB_REINSTALL
:
1974 case CM_PROB_FAILED_INSTALL
:
1976 TroubleShootStrId
= IDS_REINSTALLDRV
;
1980 case CM_PROB_DEVLOADER_NOT_FOUND
:
1983 1) if it's a missing system devloader:
1984 - disable the button (Reinstall Driver)
1985 2) if it's not a system devloader but still missing:
1987 3) if it's not a system devloader but the file can be found:
1989 4) if it's a missing or empty software key
1995 case CM_PROB_INVALID_DATA
:
1996 case CM_PROB_PARTIAL_LOG_CONF
:
1997 case CM_PROB_NO_VALID_LOG_CONF
:
1998 case CM_PROB_HARDWARE_DISABLED
:
1999 case CM_PROB_CANT_SHARE_IRQ
:
2000 case CM_PROB_TRANSLATION_FAILED
:
2001 case CM_PROB_SYSTEM_SHUTDOWN
:
2002 case CM_PROB_PHANTOM
:
2003 bDevActionAvailable
= FALSE
;
2006 case CM_PROB_NOT_VERIFIED
:
2007 case CM_PROB_DEVICE_NOT_THERE
:
2008 /* FIXME - search hardware */
2011 case CM_PROB_NEED_RESTART
:
2012 case CM_PROB_WILL_BE_REMOVED
:
2014 case CM_PROB_TOO_EARLY
:
2015 case CM_PROB_DISABLED_SERVICE
:
2016 TroubleShootStrId
= IDS_REBOOT
;
2019 case CM_PROB_REGISTRY
:
2020 /* FIXME - check registry? */
2023 case CM_PROB_DISABLED
:
2024 /* if device was disabled by the user: */
2025 TroubleShootStrId
= IDS_ENABLEDEV
;
2026 /* FIXME - otherwise disable button because the device was
2027 disabled by the system*/
2030 case CM_PROB_DEVLOADER_NOT_READY
:
2031 /* FIXME - if it's a graphics adapter:
2032 - if it's a a secondary adapter and the main adapter
2042 case CM_PROB_FAILED_ADD
:
2043 TroubleShootStrId
= IDS_PROPERTIES
;
2048 if (LoadString(hDllInstance
,
2051 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])) != 0)
2053 SetWindowText(hDevProbBtn
,
2056 EnableWindow(hDevProbBtn
,
2057 dap
->IsAdmin
&& bDevActionAvailable
);
2059 /* check if the device can be enabled/disabled */
2060 hDevUsage
= GetDlgItem(hwndDlg
,
2063 dap
->CanDisable
= FALSE
;
2064 dap
->DeviceStarted
= FALSE
;
2066 if (CanDisableDevice(DeviceInfoData
->DevInst
,
2070 dap
->CanDisable
= bFlag
;
2073 if (IsDeviceStarted(DeviceInfoData
->DevInst
,
2077 dap
->DeviceStarted
= bFlag
;
2080 /* enable/disable the device usage controls */
2081 EnableWindow(GetDlgItem(hwndDlg
,
2083 dap
->CanDisable
&& dap
->IsAdmin
);
2084 EnableWindow(hDevUsage
,
2085 dap
->CanDisable
&& dap
->IsAdmin
);
2087 /* clear the combobox */
2088 SendMessage(hDevUsage
,
2092 if (dap
->CanDisable
)
2094 InitDevUsageActions(hwndDlg
,
2099 /* find out how many new device property sheets to add.
2100 fake a PROPSHEETHEADER structure, we don't plan to
2101 call PropertySheet again!*/
2102 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
2106 /* get the number of device property sheets for the device */
2107 if (!SetupDiGetClassDevPropertySheets(DeviceInfoSet
,
2112 dap
->PropertySheetType
) &&
2113 nDriverPages
!= 0 && GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
2115 TRACE("Count %d additional pages!\n", nDriverPages
);
2116 dap
->nDevPropSheets
+= nDriverPages
;
2123 /* include the driver page */
2124 if (dap
->HasDriverPage
)
2125 dap
->nDevPropSheets
++;
2127 /* include the details page */
2129 dap
->nDevPropSheets
++;
2131 if (dap
->HasResourcePage
)
2132 dap
->nDevPropSheets
++;
2134 /* add the device property sheets */
2135 if (dap
->nDevPropSheets
!= 0)
2137 TRACE("Show %d pages!\n", dap
->nDevPropSheets
);
2138 dap
->DevPropSheets
= HeapAlloc(GetProcessHeap(),
2140 dap
->nDevPropSheets
* sizeof(HPROPSHEETPAGE
));
2141 if (dap
->DevPropSheets
!= NULL
)
2143 if (nDriverPages
!= 0)
2145 psh
.phpage
= dap
->DevPropSheets
;
2147 /* query the device property sheet pages to add */
2148 if (SetupDiGetClassDevPropertySheets(DeviceInfoSet
,
2151 dap
->nDevPropSheets
,
2153 dap
->PropertySheetType
))
2155 /* add the property sheets */
2157 iPage
< nDriverPages
;
2160 TRACE("Add page %d\n", iPage
);
2161 TRACE("Sheet %p\n", dap
->DevPropSheets
[iPage
]);
2163 if (PropSheet_AddPage(hPropSheetDlg
,
2164 dap
->DevPropSheets
[iPage
]))
2170 TRACE("PropSheet_AddPage() failed\n");
2174 dap
->FreeDevPropSheets
= TRUE
;
2178 TRACE("SetupDiGetClassDevPropertySheets() failed\n");
2179 /* cleanup, we were unable to get the device property sheets */
2180 iPage
= nDriverPages
;
2181 dap
->nDevPropSheets
-= nDriverPages
;
2188 /* add the driver page if necessary */
2189 if (dap
->HasDriverPage
)
2191 PROPSHEETPAGE pspDriver
= {0};
2192 pspDriver
.dwSize
= sizeof(PROPSHEETPAGE
);
2193 pspDriver
.dwFlags
= PSP_DEFAULT
;
2194 pspDriver
.hInstance
= hDllInstance
;
2195 pspDriver
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICEDRIVER
);
2196 pspDriver
.pfnDlgProc
= AdvProcDriverDlgProc
;
2197 pspDriver
.lParam
= (LPARAM
)dap
;
2198 dap
->DevPropSheets
[iPage
] = dap
->pCreatePropertySheetPageW(&pspDriver
);
2199 if (dap
->DevPropSheets
[iPage
] != NULL
)
2201 if (PropSheet_AddPage(hPropSheetDlg
,
2202 dap
->DevPropSheets
[iPage
]))
2209 dap
->pDestroyPropertySheetPage(dap
->DevPropSheets
[iPage
]);
2210 dap
->DevPropSheets
[iPage
] = NULL
;
2217 /* Add the details page */
2218 PROPSHEETPAGE pspDetails
= {0};
2219 pspDetails
.dwSize
= sizeof(PROPSHEETPAGE
);
2220 pspDetails
.dwFlags
= PSP_DEFAULT
;
2221 pspDetails
.hInstance
= hDllInstance
;
2222 pspDetails
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICEDETAILS
);
2223 pspDetails
.pfnDlgProc
= AdvProcDetailsDlgProc
;
2224 pspDetails
.lParam
= (LPARAM
)dap
;
2225 dap
->DevPropSheets
[iPage
] = dap
->pCreatePropertySheetPageW(&pspDetails
);
2226 if (dap
->DevPropSheets
[iPage
] != NULL
)
2228 if (PropSheet_AddPage(hPropSheetDlg
,
2229 dap
->DevPropSheets
[iPage
]))
2236 dap
->pDestroyPropertySheetPage(dap
->DevPropSheets
[iPage
]);
2237 dap
->DevPropSheets
[iPage
] = NULL
;
2242 if (dap
->HasResourcePage
)
2244 PROPSHEETPAGE pspDriver
= {0};
2245 pspDriver
.dwSize
= sizeof(PROPSHEETPAGE
);
2246 pspDriver
.dwFlags
= PSP_DEFAULT
;
2247 pspDriver
.hInstance
= hDllInstance
;
2248 pspDriver
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICERESOURCES
);
2249 pspDriver
.pfnDlgProc
= ResourcesProcDriverDlgProc
;
2250 pspDriver
.lParam
= (LPARAM
)dap
;
2251 dap
->DevPropSheets
[iPage
] = dap
->pCreatePropertySheetPageW(&pspDriver
);
2252 if (dap
->DevPropSheets
[iPage
] != NULL
)
2254 if (PropSheet_AddPage(hPropSheetDlg
,
2255 dap
->DevPropSheets
[iPage
]))
2262 dap
->pDestroyPropertySheetPage(dap
->DevPropSheets
[iPage
]);
2263 dap
->DevPropSheets
[iPage
] = NULL
;
2267 /* FIXME: Add the power page */
2270 dap
->nDevPropSheets
= 0;
2275 PropSheet_RecalcPageSizes(hPropSheetDlg
);
2278 /* finally, disable the apply button */
2279 PropSheet_UnChanged(hPropSheetDlg
,
2281 dap
->DeviceUsageChanged
= FALSE
;
2287 DlgParentSubWndProc(IN HWND hwnd
,
2292 PDEVADVPROP_INFO dap
;
2294 dap
= (PDEVADVPROP_INFO
)GetProp(hwnd
,
2295 L
"DevMgrDevChangeSub");
2298 if (uMsg
== WM_DEVICECHANGE
&& !IsWindowVisible(dap
->hWndGeneralPage
))
2300 SendMessage(dap
->hWndGeneralPage
,
2306 /* pass the message the the old window proc */
2307 return CallWindowProc(dap
->ParentOldWndProc
,
2315 /* this is not a good idea if the subclassed window was an ansi
2316 window, but we failed finding out the previous window proc
2317 so we can't use CallWindowProc. This should rarely - if ever -
2320 return DefWindowProc(hwnd
,
2330 AdvPropGeneralDlgProc(IN HWND hwndDlg
,
2335 PDEVADVPROP_INFO dap
;
2336 INT_PTR Ret
= FALSE
;
2338 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
,
2341 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
2347 switch (LOWORD(wParam
))
2351 if (HIWORD(wParam
) == CBN_SELCHANGE
)
2353 PropSheet_Changed(GetParent(hwndDlg
),
2355 dap
->DeviceUsageChanged
= TRUE
;
2360 case IDC_DEVPROBLEM
:
2364 /* display the device problem wizard */
2365 ShowDeviceProblemWizard(hwndDlg
,
2367 &dap
->DeviceInfoData
,
2378 NMHDR
*hdr
= (NMHDR
*)lParam
;
2382 ApplyGeneralSettings(hwndDlg
,
2391 dap
= (PDEVADVPROP_INFO
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
2396 dap
->hWndGeneralPage
= hwndDlg
;
2398 SetWindowLongPtr(hwndDlg
,
2402 /* subclass the parent window to always receive
2403 WM_DEVICECHANGE messages */
2404 hWndParent
= GetParent(hwndDlg
);
2405 if (hWndParent
!= NULL
)
2407 /* subclass the parent window. This is not safe
2408 if the parent window belongs to another thread! */
2409 dap
->ParentOldWndProc
= (WNDPROC
)SetWindowLongPtr(hWndParent
,
2411 (LONG_PTR
)DlgParentSubWndProc
);
2413 if (dap
->ParentOldWndProc
!= NULL
&&
2415 L
"DevMgrDevChangeSub",
2418 dap
->hWndParent
= hWndParent
;
2422 /* do not call UpdateDevInfo directly in here because it modifies
2423 the pages of the property sheet! */
2424 PostMessage(hwndDlg
,
2433 case WM_DEVICECHANGE
:
2435 /* FIXME - don't call UpdateDevInfo for all events */
2436 UpdateDevInfo(hwndDlg
,
2445 UpdateDevInfo(hwndDlg
,
2448 dap
->PageInitialized
= TRUE
;
2454 /* restore the old window proc of the subclassed parent window */
2455 if (dap
->hWndParent
!= NULL
&& dap
->ParentOldWndProc
!= NULL
)
2457 if (SetWindowLongPtr(dap
->hWndParent
,
2459 (LONG_PTR
)dap
->ParentOldWndProc
) == (LONG_PTR
)DlgParentSubWndProc
)
2461 RemoveProp(dap
->hWndParent
,
2462 L
"DevMgrDevChangeSub");
2475 DisplayDeviceAdvancedProperties(IN HWND hWndParent
,
2476 IN LPCWSTR lpDeviceID OPTIONAL
,
2477 IN HDEVINFO DeviceInfoSet
,
2478 IN PSP_DEVINFO_DATA DeviceInfoData
,
2479 IN HINSTANCE hComCtl32
,
2480 IN LPCWSTR lpMachineName
,
2483 PROPSHEETHEADER psh
= {0};
2484 PROPSHEETPAGE pspGeneral
= {0};
2485 PPROPERTYSHEETW pPropertySheetW
;
2486 PCREATEPROPERTYSHEETPAGEW pCreatePropertySheetPageW
;
2487 PDESTROYPROPERTYSHEETPAGE pDestroyPropertySheetPage
;
2488 PDEVADVPROP_INFO DevAdvPropInfo
;
2489 HMACHINE hMachine
= NULL
;
2490 DWORD DevIdSize
= 0;
2493 /* we don't want to statically link against comctl32, so find the
2494 functions we need dynamically */
2496 (PPROPERTYSHEETW
)GetProcAddress(hComCtl32
,
2498 pCreatePropertySheetPageW
=
2499 (PCREATEPROPERTYSHEETPAGEW
)GetProcAddress(hComCtl32
,
2500 "CreatePropertySheetPageW");
2501 pDestroyPropertySheetPage
=
2502 (PDESTROYPROPERTYSHEETPAGE
)GetProcAddress(hComCtl32
,
2503 "DestroyPropertySheetPage");
2504 if (pPropertySheetW
== NULL
||
2505 pCreatePropertySheetPageW
== NULL
||
2506 pDestroyPropertySheetPage
== NULL
)
2511 if (lpDeviceID
== NULL
)
2513 /* find out how much size is needed for the device id */
2514 if (SetupDiGetDeviceInstanceId(DeviceInfoSet
,
2520 ERR("SetupDiGetDeviceInstanceId unexpectedly returned TRUE!\n");
2524 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
2531 DevIdSize
= (DWORD
)wcslen(lpDeviceID
) + 1;
2534 if (lpMachineName
!= NULL
&& lpMachineName
[0] != L
'\0')
2536 CONFIGRET cr
= CM_Connect_Machine(lpMachineName
,
2538 if (cr
!= CR_SUCCESS
)
2544 /* create the internal structure associated with the "General",
2545 "Driver", ... pages */
2546 DevAdvPropInfo
= HeapAlloc(GetProcessHeap(),
2548 FIELD_OFFSET(DEVADVPROP_INFO
,
2550 (DevIdSize
* sizeof(WCHAR
)));
2551 if (DevAdvPropInfo
== NULL
)
2553 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2557 if (lpDeviceID
== NULL
)
2559 /* read the device instance id */
2560 if (!SetupDiGetDeviceInstanceId(DeviceInfoSet
,
2562 DevAdvPropInfo
->szDeviceID
,
2571 /* copy the device instance id supplied by the caller */
2572 wcscpy(DevAdvPropInfo
->szDeviceID
,
2576 DevAdvPropInfo
->DeviceInfoSet
= DeviceInfoSet
;
2577 DevAdvPropInfo
->DeviceInfoData
= *DeviceInfoData
;
2578 DevAdvPropInfo
->CurrentDeviceInfoSet
= INVALID_HANDLE_VALUE
;
2579 DevAdvPropInfo
->CurrentDeviceInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
2581 DevAdvPropInfo
->ShowRemotePages
= (lpMachineName
!= NULL
&& lpMachineName
[0] != L
'\0');
2582 DevAdvPropInfo
->hMachine
= hMachine
;
2583 DevAdvPropInfo
->lpMachineName
= lpMachineName
;
2584 DevAdvPropInfo
->szDevName
[0] = L
'\0';
2585 DevAdvPropInfo
->hComCtl32
= hComCtl32
;
2586 DevAdvPropInfo
->pCreatePropertySheetPageW
= pCreatePropertySheetPageW
;
2587 DevAdvPropInfo
->pDestroyPropertySheetPage
= pDestroyPropertySheetPage
;
2589 DevAdvPropInfo
->IsAdmin
= IsUserAdmin();
2590 DevAdvPropInfo
->DoDefaultDevAction
= ((dwFlags
& DPF_DEVICE_STATUS_ACTION
) != 0);
2591 DevAdvPropInfo
->Extended
= ((dwFlags
& DPF_EXTENDED
) != 0);
2593 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
2594 psh
.dwFlags
= PSH_PROPTITLE
| PSH_NOAPPLYNOW
;
2595 psh
.hwndParent
= hWndParent
;
2596 psh
.pszCaption
= DevAdvPropInfo
->szDevName
;
2598 DevAdvPropInfo
->PropertySheetType
= DevAdvPropInfo
->ShowRemotePages
?
2599 DIGCDP_FLAG_REMOTE_ADVANCED
:
2600 DIGCDP_FLAG_ADVANCED
;
2602 psh
.phpage
= HeapAlloc(GetProcessHeap(),
2604 1 * sizeof(HPROPSHEETPAGE
));
2605 if (psh
.phpage
== NULL
)
2610 /* add the "General" property sheet */
2611 pspGeneral
.dwSize
= sizeof(PROPSHEETPAGE
);
2612 pspGeneral
.dwFlags
= PSP_DEFAULT
;
2613 pspGeneral
.hInstance
= hDllInstance
;
2614 pspGeneral
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICEGENERAL
);
2615 pspGeneral
.pfnDlgProc
= AdvPropGeneralDlgProc
;
2616 pspGeneral
.lParam
= (LPARAM
)DevAdvPropInfo
;
2617 psh
.phpage
[psh
.nPages
] = pCreatePropertySheetPageW(&pspGeneral
);
2618 if (psh
.phpage
[psh
.nPages
] != NULL
)
2623 DevAdvPropInfo
->nDevPropSheets
= psh
.nPages
;
2625 if (psh
.nPages
!= 0)
2627 Ret
= pPropertySheetW(&psh
);
2629 /* NOTE: no need to destroy the property sheets anymore! */
2636 /* in case of failure the property sheets must be destroyed */
2637 if (psh
.phpage
!= NULL
)
2643 if (psh
.phpage
[i
] != NULL
)
2645 pDestroyPropertySheetPage(psh
.phpage
[i
]);
2651 if (DevAdvPropInfo
!= NULL
)
2653 if (DevAdvPropInfo
->FreeDevPropSheets
)
2655 /* don't free the array if it's the one allocated in
2656 DisplayDeviceAdvancedProperties */
2657 HeapFree(GetProcessHeap(),
2659 DevAdvPropInfo
->DevPropSheets
);
2662 if (DevAdvPropInfo
->CloseDevInst
)
2664 /* close the device info set in case a new one was created */
2665 SetupDiDestroyDeviceInfoList(DevAdvPropInfo
->DeviceInfoSet
);
2668 if (DevAdvPropInfo
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
2670 SetupDiDestroyDeviceInfoList(DevAdvPropInfo
->CurrentDeviceInfoSet
);
2673 if (DevAdvPropInfo
->hDevIcon
!= NULL
)
2675 DestroyIcon(DevAdvPropInfo
->hDevIcon
);
2678 HeapFree(GetProcessHeap(),
2683 if (psh
.phpage
!= NULL
)
2685 HeapFree(GetProcessHeap(),
2690 if (hMachine
!= NULL
)
2692 CM_Disconnect_Machine(hMachine
);
2700 GetDeviceAndComputerName(LPWSTR lpString
,
2702 WCHAR szMachineName
[])
2706 szDeviceID
[0] = L
'\0';
2707 szMachineName
[0] = L
'\0';
2709 while (*lpString
!= L
'\0')
2711 if (*lpString
== L
'/')
2714 if(!_wcsnicmp(lpString
, L
"DeviceID", 8))
2717 if (*lpString
!= L
'\0')
2720 while ((*lpString
!= L
' ') &&
2721 (*lpString
!= L
'\0') &&
2722 (i
<= MAX_DEVICE_ID_LEN
))
2724 szDeviceID
[i
++] = *lpString
++;
2726 szDeviceID
[i
] = L
'\0';
2730 else if (!_wcsnicmp(lpString
, L
"MachineName", 11))
2733 if (*lpString
!= L
'\0')
2736 while ((*lpString
!= L
' ') &&
2737 (*lpString
!= L
'\0') &&
2738 (i
<= MAX_COMPUTERNAME_LENGTH
))
2740 szMachineName
[i
++] = *lpString
++;
2742 szMachineName
[i
] = L
'\0';
2745 /* knock the pointer back one and let the next
2746 * pointer deal with incrementing, otherwise we
2747 * go past the end of the string */
2757 /***************************************************************************
2759 * DeviceAdvancedPropertiesW
2762 * Invokes the device properties dialog, this version may add some property pages
2766 * hWndParent: Handle to the parent window
2767 * lpMachineName: Machine Name, NULL is the local machine
2768 * lpDeviceID: Specifies the device whose properties are to be shown
2771 * Always returns -1, a call to GetLastError returns 0 if successful
2777 DeviceAdvancedPropertiesW(IN HWND hWndParent OPTIONAL
,
2778 IN LPCWSTR lpMachineName OPTIONAL
,
2779 IN LPCWSTR lpDeviceID
)
2782 SP_DEVINFO_DATA DevInfoData
;
2783 HINSTANCE hComCtl32
;
2786 if (lpDeviceID
== NULL
)
2788 SetLastError(ERROR_INVALID_PARAMETER
);
2792 /* dynamically load comctl32 */
2793 hComCtl32
= LoadAndInitComctl32();
2794 if (hComCtl32
!= NULL
)
2796 hDevInfo
= SetupDiCreateDeviceInfoListEx(NULL
,
2800 if (hDevInfo
!= INVALID_HANDLE_VALUE
)
2802 DevInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
2803 if (SetupDiOpenDeviceInfo(hDevInfo
,
2809 Ret
= DisplayDeviceAdvancedProperties(hWndParent
,
2818 SetupDiDestroyDeviceInfoList(hDevInfo
);
2821 FreeLibrary(hComCtl32
);
2828 /***************************************************************************
2830 * DeviceAdvancedPropertiesA
2833 * Invokes the device properties dialog, this version may add some property pages
2837 * hWndParent: Handle to the parent window
2838 * lpMachineName: Machine Name, NULL is the local machine
2839 * lpDeviceID: Specifies the device whose properties are to be shown
2842 * Always returns -1, a call to GetLastError returns 0 if successful
2848 DeviceAdvancedPropertiesA(IN HWND hWndParent OPTIONAL
,
2849 IN LPCSTR lpMachineName OPTIONAL
,
2850 IN LPCSTR lpDeviceID
)
2852 LPWSTR lpMachineNameW
= NULL
;
2853 LPWSTR lpDeviceIDW
= NULL
;
2856 if (lpMachineName
!= NULL
)
2858 if (!(lpMachineNameW
= ConvertMultiByteToUnicode(lpMachineName
,
2864 if (lpDeviceID
!= NULL
)
2866 if (!(lpDeviceIDW
= ConvertMultiByteToUnicode(lpDeviceID
,
2873 Ret
= DeviceAdvancedPropertiesW(hWndParent
,
2878 if (lpMachineNameW
!= NULL
)
2880 HeapFree(GetProcessHeap(),
2884 if (lpDeviceIDW
!= NULL
)
2886 HeapFree(GetProcessHeap(),
2895 /***************************************************************************
2897 * DevicePropertiesExA
2900 * Invokes the extended device properties dialog
2903 * hWndParent: Handle to the parent window
2904 * lpMachineName: Machine Name, NULL is the local machine
2905 * lpDeviceID: Specifies the device whose properties are to be shown, optional if
2906 * bShowDevMgr is nonzero
2907 * dwFlags: This parameter can be a combination of the following flags:
2908 * * DPF_DEVICE_STATUS_ACTION: Only valid if bShowDevMgr, causes
2909 * the default device status action button
2910 * to be clicked (Troubleshoot, Enable
2912 * bShowDevMgr: If non-zero it displays the device manager instead of
2913 * the advanced device property dialog
2916 * 1: if bShowDevMgr is non-zero and no error occured
2917 * -1: a call to GetLastError returns 0 if successful
2923 DevicePropertiesExA(IN HWND hWndParent OPTIONAL
,
2924 IN LPCSTR lpMachineName OPTIONAL
,
2925 IN LPCSTR lpDeviceID OPTIONAL
,
2926 IN DWORD dwFlags OPTIONAL
,
2927 IN BOOL bShowDevMgr
)
2929 LPWSTR lpMachineNameW
= NULL
;
2930 LPWSTR lpDeviceIDW
= NULL
;
2933 if (lpMachineName
!= NULL
)
2935 if (!(lpMachineNameW
= ConvertMultiByteToUnicode(lpMachineName
,
2941 if (lpDeviceID
!= NULL
)
2943 if (!(lpDeviceIDW
= ConvertMultiByteToUnicode(lpDeviceID
,
2950 Ret
= DevicePropertiesExW(hWndParent
,
2957 if (lpMachineNameW
!= NULL
)
2959 HeapFree(GetProcessHeap(),
2963 if (lpDeviceIDW
!= NULL
)
2965 HeapFree(GetProcessHeap(),
2974 /***************************************************************************
2976 * DevicePropertiesExW
2979 * Invokes the extended device properties dialog
2982 * hWndParent: Handle to the parent window
2983 * lpMachineName: Machine Name, NULL is the local machine
2984 * lpDeviceID: Specifies the device whose properties are to be shown, optional if
2985 * bShowDevMgr is nonzero
2986 * dwFlags: This parameter can be a combination of the following flags:
2987 * * DPF_DEVICE_STATUS_ACTION: Only valid if bShowDevMgr, causes
2988 * the default device status action button
2989 * to be clicked (Troubleshoot, Enable
2991 * bShowDevMgr: If non-zero it displays the device manager instead of
2992 * the advanced device property dialog
2995 * 1: if bShowDevMgr is non-zero and no error occured
2996 * -1: a call to GetLastError returns 0 if successful
3002 DevicePropertiesExW(IN HWND hWndParent OPTIONAL
,
3003 IN LPCWSTR lpMachineName OPTIONAL
,
3004 IN LPCWSTR lpDeviceID OPTIONAL
,
3005 IN DWORD dwFlags OPTIONAL
,
3006 IN BOOL bShowDevMgr
)
3010 if (dwFlags
& ~(DPF_EXTENDED
| DPF_DEVICE_STATUS_ACTION
))
3012 FIXME("DevPropertiesExW: Invalid flags: 0x%x\n",
3013 dwFlags
& ~(DPF_EXTENDED
| DPF_DEVICE_STATUS_ACTION
));
3014 SetLastError(ERROR_INVALID_FLAGS
);
3020 FIXME("DevPropertiesExW doesn't support bShowDevMgr!\n");
3021 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3026 SP_DEVINFO_DATA DevInfoData
;
3027 HINSTANCE hComCtl32
;
3029 if (lpDeviceID
== NULL
)
3031 SetLastError(ERROR_INVALID_PARAMETER
);
3035 /* dynamically load comctl32 */
3036 hComCtl32
= LoadAndInitComctl32();
3037 if (hComCtl32
!= NULL
)
3039 hDevInfo
= SetupDiCreateDeviceInfoListEx(NULL
,
3043 if (hDevInfo
!= INVALID_HANDLE_VALUE
)
3045 DevInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
3046 if (SetupDiOpenDeviceInfo(hDevInfo
,
3052 Ret
= DisplayDeviceAdvancedProperties(hWndParent
,
3061 SetupDiDestroyDeviceInfoList(hDevInfo
);
3064 FreeLibrary(hComCtl32
);
3072 /***************************************************************************
3077 * Invokes the device properties dialog directly
3080 * hWndParent: Handle to the parent window
3081 * lpMachineName: Machine Name, NULL is the local machine
3082 * lpDeviceID: Specifies the device whose properties are to be shown
3083 * bShowDevMgr: If non-zero it displays the device manager instead of
3084 * the device property dialog
3087 * >=0: if no errors occured
3088 * -1: if errors occured
3096 DevicePropertiesA(HWND hWndParent
,
3097 LPCSTR lpMachineName
,
3101 return DevicePropertiesExA(hWndParent
,
3109 /***************************************************************************
3114 * Invokes the device properties dialog directly
3117 * hWndParent: Handle to the parent window
3118 * lpMachineName: Machine Name, NULL is the local machine
3119 * lpDeviceID: Specifies the device whose properties are to be shown
3120 * bShowDevMgr: If non-zero it displays the device manager instead of
3121 * the device property dialog
3124 * >=0: if no errors occured
3125 * -1: if errors occured
3133 DevicePropertiesW(HWND hWndParent
,
3134 LPCWSTR lpMachineName
,
3138 return DevicePropertiesExW(hWndParent
,
3146 /***************************************************************************
3148 * DeviceProperties_RunDLLA
3151 * Invokes the device properties dialog
3154 * hWndParent: Handle to the parent window
3155 * hInst: Handle to the application instance
3156 * lpDeviceCmd: A command that includes the DeviceID of the properties to be shown,
3158 * nCmdShow: Specifies how the window should be shown
3165 * - lpDeviceCmd is a string in the form of "/MachineName MACHINE /DeviceID DEVICEPATH"
3166 * (/MachineName is optional). This function only parses this string and eventually
3167 * calls DeviceProperties().
3173 DeviceProperties_RunDLLA(HWND hWndParent
,
3178 LPWSTR lpDeviceCmdW
= NULL
;
3180 if (lpDeviceCmd
!= NULL
)
3182 if ((lpDeviceCmdW
= ConvertMultiByteToUnicode(lpDeviceCmd
,
3185 DeviceProperties_RunDLLW(hWndParent
,
3192 if (lpDeviceCmdW
!= NULL
)
3194 HeapFree(GetProcessHeap(),
3201 /***************************************************************************
3203 * DeviceProperties_RunDLLW
3206 * Invokes the device properties dialog
3209 * hWndParent: Handle to the parent window
3210 * hInst: Handle to the application instance
3211 * lpDeviceCmd: A command that includes the DeviceID of the properties to be shown,
3213 * nCmdShow: Specifies how the window should be shown
3220 * - lpDeviceCmd is a string in the form of "/MachineName MACHINE /DeviceID DEVICEPATH"
3221 * (/MachineName is optional). This function only parses this string and eventually
3222 * calls DeviceProperties().
3228 DeviceProperties_RunDLLW(HWND hWndParent
,
3230 LPCWSTR lpDeviceCmd
,
3233 WCHAR szDeviceID
[MAX_DEVICE_ID_LEN
+1];
3234 WCHAR szMachineName
[MAX_COMPUTERNAME_LENGTH
+1];
3235 LPWSTR lpString
= (LPWSTR
)lpDeviceCmd
;
3237 if (!GetDeviceAndComputerName(lpString
,
3241 ERR("DeviceProperties_RunDLLW DeviceID: %S, MachineName: %S\n", szDeviceID
, szMachineName
);
3245 DevicePropertiesW(hWndParent
,