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>
34 typedef INT_PTR (WINAPI
*PPROPERTYSHEETW
)(LPCPROPSHEETHEADERW
);
35 typedef HPROPSHEETPAGE (WINAPI
*PCREATEPROPERTYSHEETPAGEW
)(LPCPROPSHEETPAGEW
);
36 typedef BOOL (WINAPI
*PDESTROYPROPERTYSHEETPAGE
)(HPROPSHEETPAGE
);
38 typedef struct _DEVADVPROP_INFO
42 WNDPROC ParentOldWndProc
;
45 HDEVINFO DeviceInfoSet
;
46 SP_DEVINFO_DATA DeviceInfoData
;
47 HDEVINFO CurrentDeviceInfoSet
;
48 SP_DEVINFO_DATA CurrentDeviceInfoData
;
49 DEVINST ParentDevInst
;
51 LPCWSTR lpMachineName
;
54 PCREATEPROPERTYSHEETPAGEW pCreatePropertySheetPageW
;
55 PDESTROYPROPERTYSHEETPAGE pDestroyPropertySheetPage
;
57 DWORD PropertySheetType
;
59 HPROPSHEETPAGE
*DevPropSheets
;
66 UINT FreeDevPropSheets
: 1;
68 UINT DeviceStarted
: 1;
69 UINT DeviceUsageChanged
: 1;
70 UINT CloseDevInst
: 1;
72 UINT DoDefaultDevAction
: 1;
73 UINT PageInitialized
: 1;
74 UINT ShowRemotePages
: 1;
75 UINT HasDriverPage
: 1;
76 UINT HasResourcePage
: 1;
77 UINT HasPowerPage
: 1;
84 /* struct may be dynamically expanded here! */
85 } DEVADVPROP_INFO
, *PDEVADVPROP_INFO
;
88 typedef struct _ENUMDRIVERFILES_CONTEXT
90 HWND hDriversListView
;
92 } ENUMDRIVERFILES_CONTEXT
, *PENUMDRIVERFILES_CONTEXT
;
94 #define PM_INITIALIZE (WM_APP + 0x101)
98 EnumDeviceDriverFilesCallback(IN PVOID Context
,
104 PENUMDRIVERFILES_CONTEXT EnumDriverFilesContext
= (PENUMDRIVERFILES_CONTEXT
)Context
;
106 li
.mask
= LVIF_TEXT
| LVIF_STATE
;
107 li
.iItem
= EnumDriverFilesContext
->nCount
++;
109 li
.state
= (li
.iItem
== 0 ? LVIS_SELECTED
: 0);
110 li
.stateMask
= LVIS_SELECTED
;
111 li
.pszText
= (LPWSTR
)Param1
;
112 (void)ListView_InsertItem(EnumDriverFilesContext
->hDriversListView
,
119 UpdateDriverDetailsDlg(IN HWND hwndDlg
,
120 IN HWND hDriversListView
,
121 IN PDEVADVPROP_INFO dap
)
123 HDEVINFO DeviceInfoSet
;
124 PSP_DEVINFO_DATA DeviceInfoData
;
125 SP_DRVINFO_DATA DriverInfoData
;
126 ENUMDRIVERFILES_CONTEXT EnumDriverFilesContext
;
128 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
130 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
131 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
135 DeviceInfoSet
= dap
->DeviceInfoSet
;
136 DeviceInfoData
= &dap
->DeviceInfoData
;
139 /* set the device image */
140 SendDlgItemMessage(hwndDlg
,
143 (WPARAM
)dap
->hDevIcon
,
146 /* set the device name edit control text */
147 SetDlgItemText(hwndDlg
,
151 /* fill the driver files list view */
152 EnumDriverFilesContext
.hDriversListView
= hDriversListView
;
153 EnumDriverFilesContext
.nCount
= 0;
155 (void)ListView_DeleteAllItems(EnumDriverFilesContext
.hDriversListView
);
156 DriverInfoData
.cbSize
= sizeof(SP_DRVINFO_DATA
);
157 if (FindCurrentDriver(DeviceInfoSet
,
160 SetupDiSetSelectedDriver(DeviceInfoSet
,
164 HSPFILEQ queueHandle
;
168 HiVal
= (DriverInfoData
.DriverVersion
>> 32);
171 swprintf (szTime
, L
"%d.%d", HIWORD(HiVal
), LOWORD(HiVal
));
172 LoVal
= (DriverInfoData
.DriverVersion
& 0xFFFFFFFF);
175 swprintf(&szTime
[wcslen(szTime
)], L
".%d", HIWORD(LoVal
));
178 swprintf(&szTime
[wcslen(szTime
)], L
".%d", LOWORD(LoVal
));
181 SetDlgItemTextW(hwndDlg
, IDC_FILEVERSION
, szTime
);
183 SetDlgItemText(hwndDlg
, IDC_FILEPROVIDER
, DriverInfoData
.ProviderName
);
186 queueHandle
= SetupOpenFileQueue();
187 if (queueHandle
!= (HSPFILEQ
)INVALID_HANDLE_VALUE
)
189 SP_DEVINSTALL_PARAMS DeviceInstallParams
= {0};
190 DeviceInstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS
);
191 if (SetupDiGetDeviceInstallParams(DeviceInfoSet
,
193 &DeviceInstallParams
))
195 DeviceInstallParams
.FileQueue
= queueHandle
;
196 DeviceInstallParams
.Flags
|= DI_NOVCP
;
198 if (SetupDiSetDeviceInstallParams(DeviceInfoSet
,
200 &DeviceInstallParams
) &&
201 SetupDiCallClassInstaller(DIF_INSTALLDEVICEFILES
,
209 /* enumerate the driver files */
210 SetupScanFileQueue(queueHandle
,
211 SPQ_SCAN_USE_CALLBACK
,
213 EnumDeviceDriverFilesCallback
,
214 &EnumDriverFilesContext
,
217 /* update the list view column width */
218 GetClientRect(hDriversListView
,
220 lvc
.mask
= LVCF_WIDTH
;
221 lvc
.cx
= rcClient
.right
;
222 (void)ListView_SetColumn(hDriversListView
,
228 SetupCloseFileQueue(queueHandle
);
236 DriverDetailsDlgProc(IN HWND hwndDlg
,
241 PDEVADVPROP_INFO dap
;
244 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
,
247 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
253 switch (LOWORD(wParam
))
275 HWND hDriversListView
;
277 dap
= (PDEVADVPROP_INFO
)lParam
;
280 SetWindowLongPtr(hwndDlg
,
284 hDriversListView
= GetDlgItem(hwndDlg
,
287 /* add a column to the list view control */
288 lvc
.mask
= LVCF_FMT
| LVCF_WIDTH
;
289 lvc
.fmt
= LVCFMT_LEFT
;
291 (void)ListView_InsertColumn(hDriversListView
,
295 UpdateDriverDetailsDlg(hwndDlg
,
311 UpdateDriverDlg(IN HWND hwndDlg
,
312 IN PDEVADVPROP_INFO dap
)
314 HDEVINFO DeviceInfoSet
;
315 PSP_DEVINFO_DATA DeviceInfoData
;
317 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
319 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
320 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
324 DeviceInfoSet
= dap
->DeviceInfoSet
;
325 DeviceInfoData
= &dap
->DeviceInfoData
;
328 /* set the device image */
329 SendDlgItemMessage(hwndDlg
,
332 (WPARAM
)dap
->hDevIcon
,
335 /* set the device name edit control text */
336 SetDlgItemText(hwndDlg
,
340 /* query the driver provider */
341 if (GetDriverProviderString(DeviceInfoSet
,
344 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
346 SetDlgItemText(hwndDlg
,
351 /* query the driver date */
352 if (GetDriverDateString(DeviceInfoSet
,
355 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
357 SetDlgItemText(hwndDlg
,
362 /* query the driver version */
363 if (GetDriverVersionString(DeviceInfoSet
,
366 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
368 SetDlgItemText(hwndDlg
,
377 AdvProcDriverDlgProc(IN HWND hwndDlg
,
382 PDEVADVPROP_INFO dap
;
385 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
,
388 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
394 switch (LOWORD(wParam
))
396 case IDC_DRIVERDETAILS
:
398 DialogBoxParam(hDllInstance
,
399 MAKEINTRESOURCE(IDD_DRIVERDETAILS
),
401 DriverDetailsDlgProc
,
411 NMHDR
*hdr
= (NMHDR
*)lParam
;
422 dap
= (PDEVADVPROP_INFO
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
425 SetWindowLongPtr(hwndDlg
,
429 UpdateDriverDlg(hwndDlg
,
443 SetListViewText(HWND hwnd
,
449 li
.mask
= LVIF_TEXT
| LVIF_STATE
;
452 li
.state
= 0; //(li.iItem == 0 ? LVIS_SELECTED : 0);
453 li
.stateMask
= LVIS_SELECTED
;
455 (void)ListView_InsertItem(hwnd
,
461 UpdateDetailsDlg(IN HWND hwndDlg
,
462 IN PDEVADVPROP_INFO dap
)
473 IDS_PROP_HARDWAREIDS
,
474 IDS_PROP_COMPATIBLEIDS
,
475 IDS_PROP_MATCHINGDEVICEID
,
478 IDS_PROP_CAPABILITIES
,
479 IDS_PROP_DEVNODEFLAGS
,
480 IDS_PROP_CONFIGFLAGS
,
481 IDS_PROP_CSCONFIGFLAGS
,
482 IDS_PROP_EJECTIONRELATIONS
,
483 IDS_PROP_REMOVALRELATIONS
,
484 IDS_PROP_BUSRELATIONS
,
485 IDS_PROP_DEVUPPERFILTERS
,
486 IDS_PROP_DEVLOWERFILTERS
,
487 IDS_PROP_CLASSUPPERFILTERS
,
488 IDS_PROP_CLASSLOWERFILTERS
,
489 IDS_PROP_CLASSINSTALLER
,
490 IDS_PROP_CLASSCOINSTALLER
,
491 IDS_PROP_DEVICECOINSTALLER
,
492 IDS_PROP_FIRMWAREREVISION
,
493 IDS_PROP_CURRENTPOWERSTATE
,
494 IDS_PROP_POWERCAPABILITIES
,
495 IDS_PROP_POWERSTATEMAPPINGS
499 /* set the device image */
500 SendDlgItemMessage(hwndDlg
,
503 (WPARAM
)dap
->hDevIcon
,
506 /* set the device name edit control text */
507 SetDlgItemText(hwndDlg
,
512 hwndComboBox
= GetDlgItem(hwndDlg
,
513 IDC_DETAILSPROPNAME
);
515 hwndListView
= GetDlgItem(hwndDlg
,
516 IDC_DETAILSPROPVALUE
);
518 for (i
= 0; i
!= sizeof(Properties
) / sizeof(Properties
[0]); i
++)
520 /* fill in the device usage combo box */
521 if (LoadString(hDllInstance
,
524 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
526 SendMessage(hwndComboBox
,
529 (LPARAM
)dap
->szTemp
);
534 GetClientRect(hwndListView
,
537 /* add a column to the list view control */
538 lvc
.mask
= LVCF_FMT
| LVCF_WIDTH
;
539 lvc
.fmt
= LVCFMT_LEFT
;
540 lvc
.cx
= rcClient
.right
;
541 (void)ListView_InsertColumn(hwndListView
,
545 SendMessage(hwndComboBox
,
550 SetListViewText(hwndListView
, 0, dap
->szDeviceID
);
552 SetFocus(hwndComboBox
);
557 DisplayDevicePropertyText(IN PDEVADVPROP_INFO dap
,
558 IN HWND hwndListView
,
561 HDEVINFO DeviceInfoSet
;
562 PSP_DEVINFO_DATA DeviceInfoData
;
570 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
572 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
573 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
577 DeviceInfoSet
= dap
->DeviceInfoSet
;
578 DeviceInfoData
= &dap
->DeviceInfoData
;
582 SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
591 if (GetLastError() != ERROR_FILE_NOT_FOUND
)
593 swprintf(dap
->szTemp
, L
"Error: Getting the size failed! (Error: %ld)", GetLastError());
594 SetListViewText(hwndListView
, 0, dap
->szTemp
);
599 lpBuffer
= HeapAlloc(GetProcessHeap(),
602 if (lpBuffer
== NULL
)
604 SetListViewText(hwndListView
, 0, L
"Error: Allocating the buffer failed!");
608 if (SetupDiGetDeviceRegistryProperty(DeviceInfoSet
,
616 if (dwType
== REG_SZ
)
618 SetListViewText(hwndListView
, 0, (LPWSTR
)lpBuffer
);
620 else if (dwType
== REG_MULTI_SZ
)
622 lpStr
= (LPWSTR
)lpBuffer
;
626 len
= wcslen(lpStr
) + 1;
628 SetListViewText(hwndListView
, index
, lpStr
);
634 else if (dwType
== REG_DWORD
)
638 case SPDRP_CAPABILITIES
:
640 if (*lpBuffer
& CM_DEVCAP_LOCKSUPPORTED
)
641 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_LOCKSUPPORTED");
642 if (*lpBuffer
& CM_DEVCAP_EJECTSUPPORTED
)
643 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_EJECTSUPPORTED");
644 if (*lpBuffer
& CM_DEVCAP_REMOVABLE
)
645 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_REMOVABLE");
646 if (*lpBuffer
& CM_DEVCAP_DOCKDEVICE
)
647 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_DOCKDEVICE");
648 if (*lpBuffer
& CM_DEVCAP_UNIQUEID
)
649 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_UNIQUEID");
650 if (*lpBuffer
& CM_DEVCAP_SILENTINSTALL
)
651 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_SILENTINSTALL");
652 if (*lpBuffer
& CM_DEVCAP_RAWDEVICEOK
)
653 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_RAWDEVICEOK");
654 if (*lpBuffer
& CM_DEVCAP_SURPRISEREMOVALOK
)
655 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_SURPRISEREMOVALOK");
656 if (*lpBuffer
& CM_DEVCAP_HARDWAREDISABLED
)
657 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_HARDWAREDISABLED");
658 if (*lpBuffer
& CM_DEVCAP_NONDYNAMIC
)
659 SetListViewText(hwndListView
, index
++, L
"CM_DEVCAP_NONDYNAMIC");
662 case SPDRP_CONFIGFLAGS
:
664 if (*lpBuffer
& CONFIGFLAG_DISABLED
)
665 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_DISABLED");
666 if (*lpBuffer
& CONFIGFLAG_REMOVED
)
667 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_REMOVED");
668 if (*lpBuffer
& CONFIGFLAG_MANUAL_INSTALL
)
669 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_MANUAL_INSTALL");
670 if (*lpBuffer
& CONFIGFLAG_IGNORE_BOOT_LC
)
671 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_IGNORE_BOOT_LC");
672 if (*lpBuffer
& CONFIGFLAG_NET_BOOT
)
673 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_NET_BOOT");
674 if (*lpBuffer
& CONFIGFLAG_REINSTALL
)
675 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_REINSTALL");
676 if (*lpBuffer
& CONFIGFLAG_FAILEDINSTALL
)
677 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_FAILEDINSTALL");
678 if (*lpBuffer
& CONFIGFLAG_CANTSTOPACHILD
)
679 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_CANTSTOPACHILD");
680 if (*lpBuffer
& CONFIGFLAG_OKREMOVEROM
)
681 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_OKREMOVEROM");
682 if (*lpBuffer
& CONFIGFLAG_NOREMOVEEXIT
)
683 SetListViewText(hwndListView
, index
++, L
"CONFIGFLAG_NOREMOVEEXIT");
687 swprintf(dap
->szTemp
, L
"0x%08x", *lpBuffer
);
688 SetListViewText(hwndListView
, 0, dap
->szTemp
);
694 SetListViewText(hwndListView
, 0, L
"Error: Unsupported value type!");
700 SetListViewText(hwndListView
, 0, L
"Error: Retrieving the value failed!");
703 HeapFree(GetProcessHeap(),
709 DisplayDevNodeFlags(IN PDEVADVPROP_INFO dap
,
710 IN HWND hwndListView
)
716 CM_Get_DevNode_Status_Ex(&dwStatus
,
718 dap
->DeviceInfoData
.DevInst
,
723 if (dwStatus
& DN_ROOT_ENUMERATED
)
724 SetListViewText(hwndListView
, index
++, L
"DN_ROOT_ENUMERATED");
725 if (dwStatus
& DN_DRIVER_LOADED
)
726 SetListViewText(hwndListView
, index
++, L
"DN_DRIVER_LOADED");
727 if (dwStatus
& DN_ENUM_LOADED
)
728 SetListViewText(hwndListView
, index
++, L
"DN_ENUM_LOADED");
729 if (dwStatus
& DN_STARTED
)
730 SetListViewText(hwndListView
, index
++, L
"DN_STARTED");
731 if (dwStatus
& DN_MANUAL
)
732 SetListViewText(hwndListView
, index
++, L
"DN_MANUAL");
733 if (dwStatus
& DN_NEED_TO_ENUM
)
734 SetListViewText(hwndListView
, index
++, L
"DN_NEED_TO_ENUM");
735 if (dwStatus
& DN_DRIVER_BLOCKED
)
736 SetListViewText(hwndListView
, index
++, L
"DN_DRIVER_BLOCKED");
737 if (dwStatus
& DN_HARDWARE_ENUM
)
738 SetListViewText(hwndListView
, index
++, L
"DN_HARDWARE_ENUM");
739 if (dwStatus
& DN_NEED_RESTART
)
740 SetListViewText(hwndListView
, index
++, L
"DN_NEED_RESTART");
741 if (dwStatus
& DN_CHILD_WITH_INVALID_ID
)
742 SetListViewText(hwndListView
, index
++, L
"DN_CHILD_WITH_INVALID_ID");
743 if (dwStatus
& DN_HAS_PROBLEM
)
744 SetListViewText(hwndListView
, index
++, L
"DN_HAS_PROBLEM");
745 if (dwStatus
& DN_FILTERED
)
746 SetListViewText(hwndListView
, index
++, L
"DN_FILTERED");
747 if (dwStatus
& DN_LEGACY_DRIVER
)
748 SetListViewText(hwndListView
, index
++, L
"DN_LEGACY_DRIVER");
749 if (dwStatus
& DN_DISABLEABLE
)
750 SetListViewText(hwndListView
, index
++, L
"DN_DISABLEABLE");
751 if (dwStatus
& DN_REMOVABLE
)
752 SetListViewText(hwndListView
, index
++, L
"DN_REMOVABLE");
753 if (dwStatus
& DN_PRIVATE_PROBLEM
)
754 SetListViewText(hwndListView
, index
++, L
"DN_PRIVATE_PROBLEM");
755 if (dwStatus
& DN_MF_PARENT
)
756 SetListViewText(hwndListView
, index
++, L
"DN_MF_PARENT");
757 if (dwStatus
& DN_MF_CHILD
)
758 SetListViewText(hwndListView
, index
++, L
"DN_MF_CHILD");
759 if (dwStatus
& DN_WILL_BE_REMOVED
)
760 SetListViewText(hwndListView
, index
++, L
"DN_WILL_BE_REMOVED");
762 if (dwStatus
& DN_NOT_FIRST_TIMEE
)
763 SetListViewText(hwndListView
, index
++, L
"DN_NOT_FIRST_TIMEE");
764 if (dwStatus
& DN_STOP_FREE_RES
)
765 SetListViewText(hwndListView
, index
++, L
"DN_STOP_FREE_RES");
766 if (dwStatus
& DN_REBAL_CANDIDATE
)
767 SetListViewText(hwndListView
, index
++, L
"DN_REBAL_CANDIDATE");
768 if (dwStatus
& DN_BAD_PARTIAL
)
769 SetListViewText(hwndListView
, index
++, L
"DN_BAD_PARTIAL");
770 if (dwStatus
& DN_NT_ENUMERATOR
)
771 SetListViewText(hwndListView
, index
++, L
"DN_NT_ENUMERATOR");
772 if (dwStatus
& DN_NT_DRIVER
)
773 SetListViewText(hwndListView
, index
++, L
"DN_NT_DRIVER");
775 if (dwStatus
& DN_NEEDS_LOCKING
)
776 SetListViewText(hwndListView
, index
++, L
"DN_NEEDS_LOCKING");
777 if (dwStatus
& DN_ARM_WAKEUP
)
778 SetListViewText(hwndListView
, index
++, L
"DN_ARM_WAKEUP");
779 if (dwStatus
& DN_APM_ENUMERATOR
)
780 SetListViewText(hwndListView
, index
++, L
"DN_APM_ENUMERATOR");
781 if (dwStatus
& DN_APM_DRIVER
)
782 SetListViewText(hwndListView
, index
++, L
"DN_APM_DRIVER");
783 if (dwStatus
& DN_SILENT_INSTALL
)
784 SetListViewText(hwndListView
, index
++, L
"DN_SILENT_INSTALL");
785 if (dwStatus
& DN_NO_SHOW_IN_DM
)
786 SetListViewText(hwndListView
, index
++, L
"DN_NO_SHOW_IN_DM");
787 if (dwStatus
& DN_BOOT_LOG_PROB
)
788 SetListViewText(hwndListView
, index
++, L
"DN_BOOT_LOG_PROB");
790 // swprintf(dap->szTemp, L"0x%08x", dwStatus);
791 // SetListViewText(hwndListView, 0, dap->szTemp);
795 DisplayDevNodeEnumerator(IN PDEVADVPROP_INFO dap
,
796 IN HWND hwndListView
)
798 HDEVINFO DeviceInfoSet
;
799 PSP_DEVINFO_DATA DeviceInfoData
;
803 DWORD dwSize
= 256 * sizeof(WCHAR
);
805 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
807 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
808 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
812 DeviceInfoSet
= dap
->DeviceInfoSet
;
813 DeviceInfoData
= &dap
->DeviceInfoData
;
816 CM_Get_DevNode_Registry_Property_ExW(DeviceInfoData
->DevInst
,
817 CM_DRP_ENUMERATOR_NAME
,
824 SetListViewText(hwndListView
, 0, szBuffer
);
830 DisplayDeviceProperties(IN PDEVADVPROP_INFO dap
,
831 IN HWND hwndComboBox
,
832 IN HWND hwndListView
)
836 Index
= (INT
)SendMessage(hwndComboBox
,
843 (void)ListView_DeleteAllItems(hwndListView
);
848 SetListViewText(hwndListView
, 0, dap
->szDeviceID
);
852 case 1: /* Hardware ID */
853 DisplayDevicePropertyText(dap
,
858 case 2: /* Compatible IDs */
859 DisplayDevicePropertyText(dap
,
861 SPDRP_COMPATIBLEIDS
);
865 case 3: /* Matching ID */
869 case 4: /* Service */
870 DisplayDevicePropertyText(dap
,
875 case 5: /* Enumerator */
876 DisplayDevNodeEnumerator(dap
,
878 // DisplayDevicePropertyText(dap,
880 // SPDRP_ENUMERATOR_NAME);
883 case 6: /* Capabilities */
884 DisplayDevicePropertyText(dap
,
889 case 7: /* Devnode Flags */
890 DisplayDevNodeFlags(dap
,
894 case 8: /* Config Flags */
895 DisplayDevicePropertyText(dap
,
901 case 9: /* CSConfig Flags */
905 case 13: /* Upper Filters */
906 DisplayDevicePropertyText(dap
,
911 case 14: /* Lower Filters */
912 DisplayDevicePropertyText(dap
,
918 SetListViewText(hwndListView
, 0, L
"<Not implemented yet>");
926 AdvProcDetailsDlgProc(IN HWND hwndDlg
,
931 PDEVADVPROP_INFO dap
;
934 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
,
937 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
943 switch (LOWORD(wParam
))
945 case IDC_DETAILSPROPNAME
:
946 if (HIWORD(wParam
) == CBN_SELCHANGE
)
948 DisplayDeviceProperties(dap
,
949 GetDlgItem(hwndDlg
, IDC_DETAILSPROPNAME
),
950 GetDlgItem(hwndDlg
, IDC_DETAILSPROPVALUE
));
959 NMHDR
*hdr
= (NMHDR
*)lParam
;
970 dap
= (PDEVADVPROP_INFO
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
973 SetWindowLongPtr(hwndDlg
,
977 UpdateDetailsDlg(hwndDlg
,
991 InitDevUsageActions(IN HWND hwndDlg
,
993 IN PDEVADVPROP_INFO dap
)
1004 i
!= sizeof(Actions
) / sizeof(Actions
[0]);
1007 /* fill in the device usage combo box */
1008 if (LoadString(hDllInstance
,
1011 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1013 Index
= (INT
)SendMessage(hComboBox
,
1016 (LPARAM
)dap
->szTemp
);
1017 if (Index
!= CB_ERR
)
1019 SendMessage(hComboBox
,
1022 (LPARAM
)Actions
[i
]);
1026 case IDS_ENABLEDEVICE
:
1027 if (dap
->DeviceStarted
)
1029 SendMessage(hComboBox
,
1036 case IDS_DISABLEDEVICE
:
1037 if (!dap
->DeviceStarted
)
1039 SendMessage(hComboBox
,
1056 GetSelectedUsageAction(IN HWND hComboBox
)
1061 Index
= (INT
)SendMessage(hComboBox
,
1065 if (Index
!= CB_ERR
)
1067 INT iRet
= (INT
) SendMessage(hComboBox
,
1082 ApplyGeneralSettings(IN HWND hwndDlg
,
1083 IN PDEVADVPROP_INFO dap
)
1087 if (dap
->DeviceUsageChanged
&& dap
->IsAdmin
&& dap
->CanDisable
)
1089 UINT SelectedUsageAction
;
1090 BOOL NeedReboot
= FALSE
;
1092 SelectedUsageAction
= GetSelectedUsageAction(GetDlgItem(hwndDlg
,
1094 switch (SelectedUsageAction
)
1096 case IDS_ENABLEDEVICE
:
1097 if (!dap
->DeviceStarted
)
1099 Ret
= EnableDevice(dap
->DeviceInfoSet
,
1100 &dap
->DeviceInfoData
,
1107 case IDS_DISABLEDEVICE
:
1108 if (dap
->DeviceStarted
)
1110 Ret
= EnableDevice(dap
->DeviceInfoSet
,
1111 &dap
->DeviceInfoData
,
1126 /* make PropertySheet() return PSM_REBOOTSYSTEM */
1127 PropSheet_RebootSystem(hwndDlg
);
1132 /* FIXME - display an error message */
1133 DPRINT1("Failed to enable/disable device! LastError: %d\n",
1138 Ret
= !dap
->DeviceUsageChanged
;
1140 /* disable the apply button */
1141 PropSheet_UnChanged(GetParent(hwndDlg
),
1143 dap
->DeviceUsageChanged
= FALSE
;
1149 UpdateDevInfo(IN HWND hwndDlg
,
1150 IN PDEVADVPROP_INFO dap
,
1153 HWND hDevUsage
, hPropSheetDlg
, hDevProbBtn
;
1155 ULONG Status
, ProblemNumber
;
1156 SP_DEVINSTALL_PARAMS_W InstallParams
;
1157 UINT TroubleShootStrId
= IDS_TROUBLESHOOTDEV
;
1158 BOOL bFlag
, bDevActionAvailable
= TRUE
;
1159 BOOL bDrvInstalled
= FALSE
;
1161 HDEVINFO DeviceInfoSet
= NULL
;
1162 PSP_DEVINFO_DATA DeviceInfoData
= NULL
;
1163 PROPSHEETHEADER psh
;
1164 DWORD nDriverPages
= 0;
1165 BOOL RecalcPages
= FALSE
;
1167 hPropSheetDlg
= GetParent(hwndDlg
);
1169 if (dap
->PageInitialized
)
1171 /* switch to the General page */
1172 PropSheet_SetCurSelByID(hPropSheetDlg
,
1175 /* remove and destroy the existing device property sheet pages */
1176 if (dap
->DevPropSheets
!= NULL
)
1179 iPage
!= dap
->nDevPropSheets
;
1182 if (dap
->DevPropSheets
[iPage
] != NULL
)
1184 PropSheet_RemovePage(hPropSheetDlg
,
1186 dap
->DevPropSheets
[iPage
]);
1195 if (dap
->FreeDevPropSheets
)
1197 /* don't free the array if it's the one allocated in
1198 DisplayDeviceAdvancedProperties */
1199 HeapFree(GetProcessHeap(),
1201 dap
->DevPropSheets
);
1203 dap
->FreeDevPropSheets
= FALSE
;
1206 dap
->DevPropSheets
= NULL
;
1207 dap
->nDevPropSheets
= 0;
1211 /* create a new device info set and re-open the device */
1212 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1214 SetupDiDestroyDeviceInfoList(dap
->CurrentDeviceInfoSet
);
1217 dap
->ParentDevInst
= 0;
1218 dap
->CurrentDeviceInfoSet
= SetupDiCreateDeviceInfoListEx(NULL
,
1222 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1224 if (SetupDiOpenDeviceInfo(dap
->CurrentDeviceInfoSet
,
1228 &dap
->CurrentDeviceInfoData
))
1230 if (dap
->CloseDevInst
)
1232 SetupDiDestroyDeviceInfoList(dap
->DeviceInfoSet
);
1235 dap
->CloseDevInst
= TRUE
;
1236 dap
->DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1237 dap
->DeviceInfoData
= dap
->CurrentDeviceInfoData
;
1238 dap
->CurrentDeviceInfoSet
= INVALID_HANDLE_VALUE
;
1246 /* get the parent node from the initial devinst */
1247 CM_Get_Parent_Ex(&dap
->ParentDevInst
,
1248 dap
->DeviceInfoData
.DevInst
,
1253 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1255 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1256 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1260 DeviceInfoSet
= dap
->DeviceInfoSet
;
1261 DeviceInfoData
= &dap
->DeviceInfoData
;
1266 DeviceInfoSet
= dap
->DeviceInfoSet
;
1267 DeviceInfoData
= &dap
->DeviceInfoData
;
1270 dap
->HasDriverPage
= FALSE
;
1271 dap
->HasResourcePage
= FALSE
;
1272 dap
->HasPowerPage
= FALSE
;
1273 if (IsDriverInstalled(DeviceInfoData
->DevInst
,
1278 if (SetupDiCallClassInstaller((dap
->ShowRemotePages
?
1279 DIF_ADDREMOTEPROPERTYPAGE_ADVANCED
:
1280 DIF_ADDPROPERTYPAGE_ADVANCED
),
1284 /* get install params */
1285 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
1286 if (!SetupDiGetDeviceInstallParamsW(DeviceInfoSet
,
1290 /* zero the flags */
1291 InstallParams
.Flags
= 0;
1294 dap
->HasDriverPage
= !(InstallParams
.Flags
& DI_DRIVERPAGE_ADDED
);
1295 dap
->HasResourcePage
= !(InstallParams
.Flags
& DI_RESOURCEPAGE_ADDED
);
1296 dap
->HasPowerPage
= !(InstallParams
.Flags
& DI_FLAGSEX_POWERPAGE_ADDED
);
1300 /* get the device icon */
1301 if (dap
->hDevIcon
!= NULL
)
1303 DestroyIcon(dap
->hDevIcon
);
1304 dap
->hDevIcon
= NULL
;
1306 if (!SetupDiLoadClassIcon(&DeviceInfoData
->ClassGuid
,
1310 dap
->hDevIcon
= NULL
;
1313 /* get the device name */
1314 if (GetDeviceDescriptionString(DeviceInfoSet
,
1317 sizeof(dap
->szDevName
) / sizeof(dap
->szDevName
[0])))
1319 PropSheet_SetTitle(hPropSheetDlg
,
1324 /* set the device image */
1325 SendDlgItemMessage(hwndDlg
,
1328 (WPARAM
)dap
->hDevIcon
,
1331 /* set the device name edit control text */
1332 SetDlgItemText(hwndDlg
,
1336 /* set the device type edit control text */
1337 if (GetDeviceTypeString(DeviceInfoData
,
1339 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1341 SetDlgItemText(hwndDlg
,
1346 /* set the device manufacturer edit control text */
1347 if (GetDeviceManufacturerString(DeviceInfoSet
,
1350 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1352 SetDlgItemText(hwndDlg
,
1353 IDC_DEVMANUFACTURER
,
1357 /* set the device location edit control text */
1358 if (GetDeviceLocationString(DeviceInfoData
->DevInst
,
1361 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1363 SetDlgItemText(hwndDlg
,
1368 /* set the device status edit control text */
1369 if (GetDeviceStatusString(DeviceInfoData
->DevInst
,
1372 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1374 SetDlgItemText(hwndDlg
,
1379 /* set the device troubleshoot button text and disable it if necessary */
1380 hDevProbBtn
= GetDlgItem(hwndDlg
,
1382 cr
= CM_Get_DevNode_Status_Ex(&Status
,
1384 DeviceInfoData
->DevInst
,
1387 if (cr
== CR_SUCCESS
&& (Status
& DN_HAS_PROBLEM
))
1389 switch (ProblemNumber
)
1391 case CM_PROB_DEVLOADER_FAILED
:
1393 /* FIXME - only if it's not a root bus devloader,
1394 disable the button otherwise */
1395 TroubleShootStrId
= IDS_UPDATEDRV
;
1399 case CM_PROB_OUT_OF_MEMORY
:
1400 case CM_PROB_ENTRY_IS_WRONG_TYPE
:
1401 case CM_PROB_LACKED_ARBITRATOR
:
1402 case CM_PROB_FAILED_START
:
1404 case CM_PROB_UNKNOWN_RESOURCE
:
1406 TroubleShootStrId
= IDS_UPDATEDRV
;
1410 case CM_PROB_BOOT_CONFIG_CONFLICT
:
1411 case CM_PROB_NORMAL_CONFLICT
:
1412 case CM_PROB_REENUMERATION
:
1414 /* FIXME - Troubleshoot conflict */
1418 case CM_PROB_FAILED_FILTER
:
1419 case CM_PROB_REINSTALL
:
1420 case CM_PROB_FAILED_INSTALL
:
1422 TroubleShootStrId
= IDS_REINSTALLDRV
;
1426 case CM_PROB_DEVLOADER_NOT_FOUND
:
1429 1) if it's a missing system devloader:
1430 - disable the button (Reinstall Driver)
1431 2) if it's not a system devloader but still missing:
1433 3) if it's not a system devloader but the file can be found:
1435 4) if it's a missing or empty software key
1441 case CM_PROB_INVALID_DATA
:
1442 case CM_PROB_PARTIAL_LOG_CONF
:
1443 case CM_PROB_NO_VALID_LOG_CONF
:
1444 case CM_PROB_HARDWARE_DISABLED
:
1445 case CM_PROB_CANT_SHARE_IRQ
:
1446 case CM_PROB_TRANSLATION_FAILED
:
1447 case CM_PROB_SYSTEM_SHUTDOWN
:
1448 case CM_PROB_PHANTOM
:
1449 bDevActionAvailable
= FALSE
;
1452 case CM_PROB_NOT_VERIFIED
:
1453 case CM_PROB_DEVICE_NOT_THERE
:
1454 /* FIXME - search hardware */
1457 case CM_PROB_NEED_RESTART
:
1458 case CM_PROB_WILL_BE_REMOVED
:
1460 case CM_PROB_TOO_EARLY
:
1461 case CM_PROB_DISABLED_SERVICE
:
1462 TroubleShootStrId
= IDS_REBOOT
;
1465 case CM_PROB_REGISTRY
:
1466 /* FIXME - check registry? */
1469 case CM_PROB_DISABLED
:
1470 /* if device was disabled by the user: */
1471 TroubleShootStrId
= IDS_ENABLEDEV
;
1472 /* FIXME - otherwise disable button because the device was
1473 disabled by the system*/
1476 case CM_PROB_DEVLOADER_NOT_READY
:
1477 /* FIXME - if it's a graphics adapter:
1478 - if it's a a secondary adapter and the main adapter
1488 case CM_PROB_FAILED_ADD
:
1489 TroubleShootStrId
= IDS_PROPERTIES
;
1494 if (LoadString(hDllInstance
,
1497 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])) != 0)
1499 SetWindowText(hDevProbBtn
,
1502 EnableWindow(hDevProbBtn
,
1503 dap
->IsAdmin
&& bDevActionAvailable
);
1505 /* check if the device can be enabled/disabled */
1506 hDevUsage
= GetDlgItem(hwndDlg
,
1509 dap
->CanDisable
= FALSE
;
1510 dap
->DeviceStarted
= FALSE
;
1512 if (CanDisableDevice(DeviceInfoData
->DevInst
,
1516 dap
->CanDisable
= bFlag
;
1519 if (IsDeviceStarted(DeviceInfoData
->DevInst
,
1523 dap
->DeviceStarted
= bFlag
;
1526 /* enable/disable the device usage controls */
1527 EnableWindow(GetDlgItem(hwndDlg
,
1529 dap
->CanDisable
&& dap
->IsAdmin
);
1530 EnableWindow(hDevUsage
,
1531 dap
->CanDisable
&& dap
->IsAdmin
);
1533 /* clear the combobox */
1534 SendMessage(hDevUsage
,
1538 if (dap
->CanDisable
)
1540 InitDevUsageActions(hwndDlg
,
1545 /* find out how many new device property sheets to add.
1546 fake a PROPSHEETHEADER structure, we don't plan to
1547 call PropertySheet again!*/
1548 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
1552 /* get the number of device property sheets for the device */
1553 if (!SetupDiGetClassDevPropertySheets(DeviceInfoSet
,
1558 dap
->PropertySheetType
) &&
1559 nDriverPages
!= 0 && GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
1561 dap
->nDevPropSheets
+= nDriverPages
;
1568 /* include the driver page */
1569 if (dap
->HasDriverPage
)
1570 dap
->nDevPropSheets
++;
1572 /* include the details page */
1573 dap
->nDevPropSheets
++;
1575 /* add the device property sheets */
1576 if (dap
->nDevPropSheets
!= 0)
1578 dap
->DevPropSheets
= HeapAlloc(GetProcessHeap(),
1580 dap
->nDevPropSheets
* sizeof(HPROPSHEETPAGE
));
1581 if (dap
->DevPropSheets
!= NULL
)
1583 if (nDriverPages
!= 0)
1585 psh
.phpage
= dap
->DevPropSheets
;
1587 /* query the device property sheet pages to add */
1588 if (SetupDiGetClassDevPropertySheets(DeviceInfoSet
,
1591 dap
->nDevPropSheets
,
1593 dap
->PropertySheetType
))
1595 /* add the property sheets */
1597 iPage
!= nDriverPages
;
1600 if (PropSheet_AddPage(hPropSheetDlg
,
1601 dap
->DevPropSheets
[iPage
]))
1607 dap
->FreeDevPropSheets
= TRUE
;
1611 /* cleanup, we were unable to get the device property sheets */
1612 iPage
= nDriverPages
;
1613 dap
->nDevPropSheets
-= nDriverPages
;
1620 /* add the driver page if necessary */
1621 if (dap
->HasDriverPage
)
1623 PROPSHEETPAGE pspDriver
= {0};
1624 pspDriver
.dwSize
= sizeof(PROPSHEETPAGE
);
1625 pspDriver
.dwFlags
= PSP_DEFAULT
;
1626 pspDriver
.hInstance
= hDllInstance
;
1627 pspDriver
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICEDRIVER
);
1628 pspDriver
.pfnDlgProc
= AdvProcDriverDlgProc
;
1629 pspDriver
.lParam
= (LPARAM
)dap
;
1630 dap
->DevPropSheets
[iPage
] = dap
->pCreatePropertySheetPageW(&pspDriver
);
1631 if (dap
->DevPropSheets
[iPage
] != NULL
)
1633 if (PropSheet_AddPage(hPropSheetDlg
,
1634 dap
->DevPropSheets
[iPage
]))
1641 dap
->pDestroyPropertySheetPage(dap
->DevPropSheets
[iPage
]);
1642 dap
->DevPropSheets
[iPage
] = NULL
;
1649 PROPSHEETPAGE pspDetails
= {0};
1650 pspDetails
.dwSize
= sizeof(PROPSHEETPAGE
);
1651 pspDetails
.dwFlags
= PSP_DEFAULT
;
1652 pspDetails
.hInstance
= hDllInstance
;
1653 pspDetails
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICEDETAILS
);
1654 pspDetails
.pfnDlgProc
= AdvProcDetailsDlgProc
;
1655 pspDetails
.lParam
= (LPARAM
)dap
;
1656 dap
->DevPropSheets
[iPage
] = dap
->pCreatePropertySheetPageW(&pspDetails
);
1657 if (dap
->DevPropSheets
[iPage
] != NULL
)
1659 if (PropSheet_AddPage(hPropSheetDlg
,
1660 dap
->DevPropSheets
[iPage
]))
1667 dap
->pDestroyPropertySheetPage(dap
->DevPropSheets
[iPage
]);
1668 dap
->DevPropSheets
[iPage
] = NULL
;
1673 /* FIXME: Add the resources page */
1675 /* FIXME: Add the power page */
1678 dap
->nDevPropSheets
= 0;
1683 PropSheet_RecalcPageSizes(hPropSheetDlg
);
1686 /* finally, disable the apply button */
1687 PropSheet_UnChanged(hPropSheetDlg
,
1689 dap
->DeviceUsageChanged
= FALSE
;
1695 DlgParentSubWndProc(IN HWND hwnd
,
1700 PDEVADVPROP_INFO dap
;
1702 dap
= (PDEVADVPROP_INFO
)GetProp(hwnd
,
1703 L
"DevMgrDevChangeSub");
1706 if (uMsg
== WM_DEVICECHANGE
&& !IsWindowVisible(dap
->hWndGeneralPage
))
1708 SendMessage(dap
->hWndGeneralPage
,
1714 /* pass the message the the old window proc */
1715 return CallWindowProc(dap
->ParentOldWndProc
,
1723 /* this is not a good idea if the subclassed window was an ansi
1724 window, but we failed finding out the previous window proc
1725 so we can't use CallWindowProc. This should rarely - if ever -
1728 return DefWindowProc(hwnd
,
1738 AdvPropGeneralDlgProc(IN HWND hwndDlg
,
1743 PDEVADVPROP_INFO dap
;
1744 INT_PTR Ret
= FALSE
;
1746 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
,
1749 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
1755 switch (LOWORD(wParam
))
1759 if (HIWORD(wParam
) == CBN_SELCHANGE
)
1761 PropSheet_Changed(GetParent(hwndDlg
),
1763 dap
->DeviceUsageChanged
= TRUE
;
1768 case IDC_DEVPROBLEM
:
1772 /* display the device problem wizard */
1773 ShowDeviceProblemWizard(hwndDlg
,
1775 &dap
->DeviceInfoData
,
1786 NMHDR
*hdr
= (NMHDR
*)lParam
;
1790 ApplyGeneralSettings(hwndDlg
,
1799 dap
= (PDEVADVPROP_INFO
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1804 dap
->hWndGeneralPage
= hwndDlg
;
1806 SetWindowLongPtr(hwndDlg
,
1810 /* subclass the parent window to always receive
1811 WM_DEVICECHANGE messages */
1812 hWndParent
= GetParent(hwndDlg
);
1813 if (hWndParent
!= NULL
)
1815 /* subclass the parent window. This is not safe
1816 if the parent window belongs to another thread! */
1817 dap
->ParentOldWndProc
= (WNDPROC
)SetWindowLongPtr(hWndParent
,
1819 (LONG_PTR
)DlgParentSubWndProc
);
1821 if (dap
->ParentOldWndProc
!= NULL
&&
1823 L
"DevMgrDevChangeSub",
1826 dap
->hWndParent
= hWndParent
;
1830 /* do not call UpdateDevInfo directly in here because it modifies
1831 the pages of the property sheet! */
1832 PostMessage(hwndDlg
,
1841 case WM_DEVICECHANGE
:
1843 /* FIXME - don't call UpdateDevInfo for all events */
1844 UpdateDevInfo(hwndDlg
,
1853 UpdateDevInfo(hwndDlg
,
1856 dap
->PageInitialized
= TRUE
;
1862 /* restore the old window proc of the subclassed parent window */
1863 if (dap
->hWndParent
!= NULL
&& dap
->ParentOldWndProc
!= NULL
)
1865 if (SetWindowLongPtr(dap
->hWndParent
,
1867 (LONG_PTR
)dap
->ParentOldWndProc
) == (LONG_PTR
)DlgParentSubWndProc
)
1869 RemoveProp(dap
->hWndParent
,
1870 L
"DevMgrDevChangeSub");
1883 DisplayDeviceAdvancedProperties(IN HWND hWndParent
,
1884 IN LPCWSTR lpDeviceID OPTIONAL
,
1885 IN HDEVINFO DeviceInfoSet
,
1886 IN PSP_DEVINFO_DATA DeviceInfoData
,
1887 IN HINSTANCE hComCtl32
,
1888 IN LPCWSTR lpMachineName
,
1891 PROPSHEETHEADER psh
= {0};
1892 PROPSHEETPAGE pspGeneral
= {0};
1893 PPROPERTYSHEETW pPropertySheetW
;
1894 PCREATEPROPERTYSHEETPAGEW pCreatePropertySheetPageW
;
1895 PDESTROYPROPERTYSHEETPAGE pDestroyPropertySheetPage
;
1896 PDEVADVPROP_INFO DevAdvPropInfo
;
1897 HMACHINE hMachine
= NULL
;
1898 DWORD DevIdSize
= 0;
1901 /* we don't want to statically link against comctl32, so find the
1902 functions we need dynamically */
1904 (PPROPERTYSHEETW
)GetProcAddress(hComCtl32
,
1906 pCreatePropertySheetPageW
=
1907 (PCREATEPROPERTYSHEETPAGEW
)GetProcAddress(hComCtl32
,
1908 "CreatePropertySheetPageW");
1909 pDestroyPropertySheetPage
=
1910 (PDESTROYPROPERTYSHEETPAGE
)GetProcAddress(hComCtl32
,
1911 "DestroyPropertySheetPage");
1912 if (pPropertySheetW
== NULL
||
1913 pCreatePropertySheetPageW
== NULL
||
1914 pDestroyPropertySheetPage
== NULL
)
1919 if (lpDeviceID
== NULL
)
1921 /* find out how much size is needed for the device id */
1922 if (SetupDiGetDeviceInstanceId(DeviceInfoSet
,
1928 DPRINT1("SetupDiGetDeviceInstanceId unexpectedly returned TRUE!\n");
1932 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
1939 DevIdSize
= (DWORD
)wcslen(lpDeviceID
) + 1;
1942 if (lpMachineName
!= NULL
&& lpMachineName
[0] != L
'\0')
1944 CONFIGRET cr
= CM_Connect_Machine(lpMachineName
,
1946 if (cr
!= CR_SUCCESS
)
1952 /* create the internal structure associated with the "General",
1953 "Driver", ... pages */
1954 DevAdvPropInfo
= HeapAlloc(GetProcessHeap(),
1956 FIELD_OFFSET(DEVADVPROP_INFO
,
1958 (DevIdSize
* sizeof(WCHAR
)));
1959 if (DevAdvPropInfo
== NULL
)
1961 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1965 if (lpDeviceID
== NULL
)
1967 /* read the device instance id */
1968 if (!SetupDiGetDeviceInstanceId(DeviceInfoSet
,
1970 DevAdvPropInfo
->szDeviceID
,
1979 /* copy the device instance id supplied by the caller */
1980 wcscpy(DevAdvPropInfo
->szDeviceID
,
1984 DevAdvPropInfo
->DeviceInfoSet
= DeviceInfoSet
;
1985 DevAdvPropInfo
->DeviceInfoData
= *DeviceInfoData
;
1986 DevAdvPropInfo
->CurrentDeviceInfoSet
= INVALID_HANDLE_VALUE
;
1987 DevAdvPropInfo
->CurrentDeviceInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
1989 DevAdvPropInfo
->ShowRemotePages
= (lpMachineName
!= NULL
&& lpMachineName
[0] != L
'\0');
1990 DevAdvPropInfo
->hMachine
= hMachine
;
1991 DevAdvPropInfo
->lpMachineName
= lpMachineName
;
1992 DevAdvPropInfo
->szDevName
[0] = L
'\0';
1993 DevAdvPropInfo
->hComCtl32
= hComCtl32
;
1994 DevAdvPropInfo
->pCreatePropertySheetPageW
= pCreatePropertySheetPageW
;
1995 DevAdvPropInfo
->pDestroyPropertySheetPage
= pDestroyPropertySheetPage
;
1997 DevAdvPropInfo
->IsAdmin
= IsUserAdmin();
1998 DevAdvPropInfo
->DoDefaultDevAction
= ((dwFlags
& DPF_DEVICE_STATUS_ACTION
) != 0);
2000 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
2001 psh
.dwFlags
= PSH_PROPTITLE
| PSH_NOAPPLYNOW
;
2002 psh
.hwndParent
= hWndParent
;
2003 psh
.pszCaption
= DevAdvPropInfo
->szDevName
;
2005 DevAdvPropInfo
->PropertySheetType
= DevAdvPropInfo
->ShowRemotePages
?
2006 DIGCDP_FLAG_REMOTE_ADVANCED
:
2007 DIGCDP_FLAG_ADVANCED
;
2009 psh
.phpage
= HeapAlloc(GetProcessHeap(),
2011 1 * sizeof(HPROPSHEETPAGE
));
2012 if (psh
.phpage
== NULL
)
2017 /* add the "General" property sheet */
2018 pspGeneral
.dwSize
= sizeof(PROPSHEETPAGE
);
2019 pspGeneral
.dwFlags
= PSP_DEFAULT
;
2020 pspGeneral
.hInstance
= hDllInstance
;
2021 pspGeneral
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICEGENERAL
);
2022 pspGeneral
.pfnDlgProc
= AdvPropGeneralDlgProc
;
2023 pspGeneral
.lParam
= (LPARAM
)DevAdvPropInfo
;
2024 psh
.phpage
[psh
.nPages
] = pCreatePropertySheetPageW(&pspGeneral
);
2025 if (psh
.phpage
[psh
.nPages
] != NULL
)
2030 DevAdvPropInfo
->nDevPropSheets
= psh
.nPages
;
2032 if (psh
.nPages
!= 0)
2034 Ret
= pPropertySheetW(&psh
);
2036 /* NOTE: no need to destroy the property sheets anymore! */
2043 /* in case of failure the property sheets must be destroyed */
2044 if (psh
.phpage
!= NULL
)
2050 if (psh
.phpage
[i
] != NULL
)
2052 pDestroyPropertySheetPage(psh
.phpage
[i
]);
2058 if (DevAdvPropInfo
!= NULL
)
2060 if (DevAdvPropInfo
->FreeDevPropSheets
)
2062 /* don't free the array if it's the one allocated in
2063 DisplayDeviceAdvancedProperties */
2064 HeapFree(GetProcessHeap(),
2066 DevAdvPropInfo
->DevPropSheets
);
2069 if (DevAdvPropInfo
->CloseDevInst
)
2071 /* close the device info set in case a new one was created */
2072 SetupDiDestroyDeviceInfoList(DevAdvPropInfo
->DeviceInfoSet
);
2075 if (DevAdvPropInfo
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
2077 SetupDiDestroyDeviceInfoList(DevAdvPropInfo
->CurrentDeviceInfoSet
);
2080 if (DevAdvPropInfo
->hDevIcon
!= NULL
)
2082 DestroyIcon(DevAdvPropInfo
->hDevIcon
);
2085 HeapFree(GetProcessHeap(),
2090 if (psh
.phpage
!= NULL
)
2092 HeapFree(GetProcessHeap(),
2097 if (hMachine
!= NULL
)
2099 CM_Disconnect_Machine(hMachine
);
2107 GetDeviceAndComputerName(LPWSTR lpString
,
2109 WCHAR szMachineName
[])
2113 szDeviceID
[0] = L
'\0';
2114 szMachineName
[0] = L
'\0';
2116 while (*lpString
!= L
'\0')
2118 if (*lpString
== L
'/')
2121 if(!_wcsnicmp(lpString
, L
"DeviceID", 8))
2124 if (*lpString
!= L
'\0')
2127 while ((*lpString
!= L
' ') &&
2128 (*lpString
!= L
'\0') &&
2129 (i
<= MAX_DEVICE_ID_LEN
))
2131 szDeviceID
[i
++] = *lpString
++;
2133 szDeviceID
[i
] = L
'\0';
2137 else if (!_wcsnicmp(lpString
, L
"MachineName", 11))
2140 if (*lpString
!= L
'\0')
2143 while ((*lpString
!= L
' ') &&
2144 (*lpString
!= L
'\0') &&
2145 (i
<= MAX_COMPUTERNAME_LENGTH
))
2147 szMachineName
[i
++] = *lpString
++;
2149 szMachineName
[i
] = L
'\0';
2152 /* knock the pointer back one and let the next
2153 * pointer deal with incrementing, otherwise we
2154 * go past the end of the string */
2164 /***************************************************************************
2166 * DeviceAdvancedPropertiesW
2169 * Invokes the device properties dialog, this version may add some property pages
2173 * hWndParent: Handle to the parent window
2174 * lpMachineName: Machine Name, NULL is the local machine
2175 * lpDeviceID: Specifies the device whose properties are to be shown
2178 * Always returns -1, a call to GetLastError returns 0 if successful
2184 DeviceAdvancedPropertiesW(IN HWND hWndParent OPTIONAL
,
2185 IN LPCWSTR lpMachineName OPTIONAL
,
2186 IN LPCWSTR lpDeviceID
)
2189 SP_DEVINFO_DATA DevInfoData
;
2190 HINSTANCE hComCtl32
;
2193 if (lpDeviceID
== NULL
)
2195 SetLastError(ERROR_INVALID_PARAMETER
);
2199 /* dynamically load comctl32 */
2200 hComCtl32
= LoadAndInitComctl32();
2201 if (hComCtl32
!= NULL
)
2203 hDevInfo
= SetupDiCreateDeviceInfoListEx(NULL
,
2207 if (hDevInfo
!= INVALID_HANDLE_VALUE
)
2209 DevInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
2210 if (SetupDiOpenDeviceInfo(hDevInfo
,
2216 Ret
= DisplayDeviceAdvancedProperties(hWndParent
,
2225 SetupDiDestroyDeviceInfoList(hDevInfo
);
2228 FreeLibrary(hComCtl32
);
2235 /***************************************************************************
2237 * DeviceAdvancedPropertiesA
2240 * Invokes the device properties dialog, this version may add some property pages
2244 * hWndParent: Handle to the parent window
2245 * lpMachineName: Machine Name, NULL is the local machine
2246 * lpDeviceID: Specifies the device whose properties are to be shown
2249 * Always returns -1, a call to GetLastError returns 0 if successful
2255 DeviceAdvancedPropertiesA(IN HWND hWndParent OPTIONAL
,
2256 IN LPCSTR lpMachineName OPTIONAL
,
2257 IN LPCSTR lpDeviceID
)
2259 LPWSTR lpMachineNameW
= NULL
;
2260 LPWSTR lpDeviceIDW
= NULL
;
2263 if (lpMachineName
!= NULL
)
2265 if (!(lpMachineNameW
= ConvertMultiByteToUnicode(lpMachineName
,
2271 if (lpDeviceID
!= NULL
)
2273 if (!(lpDeviceIDW
= ConvertMultiByteToUnicode(lpDeviceID
,
2280 Ret
= DeviceAdvancedPropertiesW(hWndParent
,
2285 if (lpMachineNameW
!= NULL
)
2287 HeapFree(GetProcessHeap(),
2291 if (lpDeviceIDW
!= NULL
)
2293 HeapFree(GetProcessHeap(),
2302 /***************************************************************************
2304 * DevicePropertiesExA
2307 * Invokes the extended device properties dialog
2310 * hWndParent: Handle to the parent window
2311 * lpMachineName: Machine Name, NULL is the local machine
2312 * lpDeviceID: Specifies the device whose properties are to be shown, optional if
2313 * bShowDevMgr is nonzero
2314 * dwFlags: This parameter can be a combination of the following flags:
2315 * * DPF_DEVICE_STATUS_ACTION: Only valid if bShowDevMgr, causes
2316 * the default device status action button
2317 * to be clicked (Troubleshoot, Enable
2319 * bShowDevMgr: If non-zero it displays the device manager instead of
2320 * the advanced device property dialog
2323 * 1: if bShowDevMgr is non-zero and no error occured
2324 * -1: a call to GetLastError returns 0 if successful
2330 DevicePropertiesExA(IN HWND hWndParent OPTIONAL
,
2331 IN LPCSTR lpMachineName OPTIONAL
,
2332 IN LPCSTR lpDeviceID OPTIONAL
,
2333 IN DWORD dwFlags OPTIONAL
,
2334 IN BOOL bShowDevMgr
)
2336 LPWSTR lpMachineNameW
= NULL
;
2337 LPWSTR lpDeviceIDW
= NULL
;
2340 if (lpMachineName
!= NULL
)
2342 if (!(lpMachineNameW
= ConvertMultiByteToUnicode(lpMachineName
,
2348 if (lpDeviceID
!= NULL
)
2350 if (!(lpDeviceIDW
= ConvertMultiByteToUnicode(lpDeviceID
,
2357 Ret
= DevicePropertiesExW(hWndParent
,
2364 if (lpMachineNameW
!= NULL
)
2366 HeapFree(GetProcessHeap(),
2370 if (lpDeviceIDW
!= NULL
)
2372 HeapFree(GetProcessHeap(),
2381 /***************************************************************************
2383 * DevicePropertiesExW
2386 * Invokes the extended device properties dialog
2389 * hWndParent: Handle to the parent window
2390 * lpMachineName: Machine Name, NULL is the local machine
2391 * lpDeviceID: Specifies the device whose properties are to be shown, optional if
2392 * bShowDevMgr is nonzero
2393 * dwFlags: This parameter can be a combination of the following flags:
2394 * * DPF_DEVICE_STATUS_ACTION: Only valid if bShowDevMgr, causes
2395 * the default device status action button
2396 * to be clicked (Troubleshoot, Enable
2398 * bShowDevMgr: If non-zero it displays the device manager instead of
2399 * the advanced device property dialog
2402 * 1: if bShowDevMgr is non-zero and no error occured
2403 * -1: a call to GetLastError returns 0 if successful
2409 DevicePropertiesExW(IN HWND hWndParent OPTIONAL
,
2410 IN LPCWSTR lpMachineName OPTIONAL
,
2411 IN LPCWSTR lpDeviceID OPTIONAL
,
2412 IN DWORD dwFlags OPTIONAL
,
2413 IN BOOL bShowDevMgr
)
2417 if (dwFlags
& ~(DPF_EXTENDED
| DPF_DEVICE_STATUS_ACTION
))
2419 DPRINT1("DevPropertiesExW: Invalid flags: 0x%x\n",
2420 dwFlags
& ~(DPF_EXTENDED
| DPF_DEVICE_STATUS_ACTION
));
2421 SetLastError(ERROR_INVALID_FLAGS
);
2427 DPRINT("DevPropertiesExW doesn't support bShowDevMgr!\n");
2428 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2433 SP_DEVINFO_DATA DevInfoData
;
2434 HINSTANCE hComCtl32
;
2436 if (lpDeviceID
== NULL
)
2438 SetLastError(ERROR_INVALID_PARAMETER
);
2442 /* dynamically load comctl32 */
2443 hComCtl32
= LoadAndInitComctl32();
2444 if (hComCtl32
!= NULL
)
2446 hDevInfo
= SetupDiCreateDeviceInfoListEx(NULL
,
2450 if (hDevInfo
!= INVALID_HANDLE_VALUE
)
2452 DevInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
2453 if (SetupDiOpenDeviceInfo(hDevInfo
,
2459 Ret
= DisplayDeviceAdvancedProperties(hWndParent
,
2468 SetupDiDestroyDeviceInfoList(hDevInfo
);
2471 FreeLibrary(hComCtl32
);
2479 /***************************************************************************
2484 * Invokes the device properties dialog directly
2487 * hWndParent: Handle to the parent window
2488 * lpMachineName: Machine Name, NULL is the local machine
2489 * lpDeviceID: Specifies the device whose properties are to be shown
2490 * bShowDevMgr: If non-zero it displays the device manager instead of
2491 * the device property dialog
2494 * >=0: if no errors occured
2495 * -1: if errors occured
2503 DevicePropertiesA(HWND hWndParent
,
2504 LPCSTR lpMachineName
,
2508 return DevicePropertiesExA(hWndParent
,
2516 /***************************************************************************
2521 * Invokes the device properties dialog directly
2524 * hWndParent: Handle to the parent window
2525 * lpMachineName: Machine Name, NULL is the local machine
2526 * lpDeviceID: Specifies the device whose properties are to be shown
2527 * bShowDevMgr: If non-zero it displays the device manager instead of
2528 * the device property dialog
2531 * >=0: if no errors occured
2532 * -1: if errors occured
2540 DevicePropertiesW(HWND hWndParent
,
2541 LPCWSTR lpMachineName
,
2545 return DevicePropertiesExW(hWndParent
,
2553 /***************************************************************************
2555 * DeviceProperties_RunDLLA
2558 * Invokes the device properties dialog
2561 * hWndParent: Handle to the parent window
2562 * hInst: Handle to the application instance
2563 * lpDeviceCmd: A command that includes the DeviceID of the properties to be shown,
2565 * nCmdShow: Specifies how the window should be shown
2572 * - lpDeviceCmd is a string in the form of "/MachineName MACHINE /DeviceID DEVICEPATH"
2573 * (/MachineName is optional). This function only parses this string and eventually
2574 * calls DeviceProperties().
2580 DeviceProperties_RunDLLA(HWND hWndParent
,
2585 LPWSTR lpDeviceCmdW
= NULL
;
2587 if (lpDeviceCmd
!= NULL
)
2589 if ((lpDeviceCmdW
= ConvertMultiByteToUnicode(lpDeviceCmd
,
2592 DeviceProperties_RunDLLW(hWndParent
,
2599 if (lpDeviceCmdW
!= NULL
)
2601 HeapFree(GetProcessHeap(),
2608 /***************************************************************************
2610 * DeviceProperties_RunDLLW
2613 * Invokes the device properties dialog
2616 * hWndParent: Handle to the parent window
2617 * hInst: Handle to the application instance
2618 * lpDeviceCmd: A command that includes the DeviceID of the properties to be shown,
2620 * nCmdShow: Specifies how the window should be shown
2627 * - lpDeviceCmd is a string in the form of "/MachineName MACHINE /DeviceID DEVICEPATH"
2628 * (/MachineName is optional). This function only parses this string and eventually
2629 * calls DeviceProperties().
2635 DeviceProperties_RunDLLW(HWND hWndParent
,
2637 LPCWSTR lpDeviceCmd
,
2640 WCHAR szDeviceID
[MAX_DEVICE_ID_LEN
+1];
2641 WCHAR szMachineName
[MAX_COMPUTERNAME_LENGTH
+1];
2642 LPWSTR lpString
= (LPWSTR
)lpDeviceCmd
;
2644 if (!GetDeviceAndComputerName(lpString
,
2648 DPRINT1("DeviceProperties_RunDLLW DeviceID: %S, MachineName: %S\n", szDeviceID
, szMachineName
);
2652 DevicePropertiesW(hWndParent
,