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);
797 DisplayDeviceProperties(IN PDEVADVPROP_INFO dap
,
798 IN HWND hwndComboBox
,
799 IN HWND hwndListView
)
803 Index
= (INT
)SendMessage(hwndComboBox
,
810 (void)ListView_DeleteAllItems(hwndListView
);
815 SetListViewText(hwndListView
, 0, dap
->szDeviceID
);
819 case 1: /* Hardware ID */
820 DisplayDevicePropertyText(dap
,
825 case 2: /* Compatible IDs */
826 DisplayDevicePropertyText(dap
,
828 SPDRP_COMPATIBLEIDS
);
832 case 3: /* Matching ID */
836 case 4: /* Service */
837 DisplayDevicePropertyText(dap
,
842 case 5: /* Enumerator */
843 DisplayDevicePropertyText(dap
,
845 SPDRP_ENUMERATOR_NAME
);
848 case 6: /* Capabilities */
849 DisplayDevicePropertyText(dap
,
854 case 7: /* Devnode Flags */
855 DisplayDevNodeFlags(dap
,
859 case 8: /* Config Flags */
860 DisplayDevicePropertyText(dap
,
866 case 9: /* CSConfig Flags */
870 case 13: /* Upper Filters */
871 DisplayDevicePropertyText(dap
,
876 case 14: /* Lower Filters */
877 DisplayDevicePropertyText(dap
,
883 SetListViewText(hwndListView
, 0, L
"<Not implemented yet>");
891 AdvProcDetailsDlgProc(IN HWND hwndDlg
,
896 PDEVADVPROP_INFO dap
;
899 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
,
902 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
908 switch (LOWORD(wParam
))
910 case IDC_DETAILSPROPNAME
:
911 if (HIWORD(wParam
) == CBN_SELCHANGE
)
913 DisplayDeviceProperties(dap
,
914 GetDlgItem(hwndDlg
, IDC_DETAILSPROPNAME
),
915 GetDlgItem(hwndDlg
, IDC_DETAILSPROPVALUE
));
924 NMHDR
*hdr
= (NMHDR
*)lParam
;
935 dap
= (PDEVADVPROP_INFO
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
938 SetWindowLongPtr(hwndDlg
,
942 UpdateDetailsDlg(hwndDlg
,
956 InitDevUsageActions(IN HWND hwndDlg
,
958 IN PDEVADVPROP_INFO dap
)
969 i
!= sizeof(Actions
) / sizeof(Actions
[0]);
972 /* fill in the device usage combo box */
973 if (LoadString(hDllInstance
,
976 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
978 Index
= (INT
)SendMessage(hComboBox
,
981 (LPARAM
)dap
->szTemp
);
984 SendMessage(hComboBox
,
991 case IDS_ENABLEDEVICE
:
992 if (dap
->DeviceStarted
)
994 SendMessage(hComboBox
,
1001 case IDS_DISABLEDEVICE
:
1002 if (!dap
->DeviceStarted
)
1004 SendMessage(hComboBox
,
1021 GetSelectedUsageAction(IN HWND hComboBox
)
1026 Index
= (INT
)SendMessage(hComboBox
,
1030 if (Index
!= CB_ERR
)
1032 INT iRet
= (INT
) SendMessage(hComboBox
,
1047 ApplyGeneralSettings(IN HWND hwndDlg
,
1048 IN PDEVADVPROP_INFO dap
)
1052 if (dap
->DeviceUsageChanged
&& dap
->IsAdmin
&& dap
->CanDisable
)
1054 UINT SelectedUsageAction
;
1055 BOOL NeedReboot
= FALSE
;
1057 SelectedUsageAction
= GetSelectedUsageAction(GetDlgItem(hwndDlg
,
1059 switch (SelectedUsageAction
)
1061 case IDS_ENABLEDEVICE
:
1062 if (!dap
->DeviceStarted
)
1064 Ret
= EnableDevice(dap
->DeviceInfoSet
,
1065 &dap
->DeviceInfoData
,
1072 case IDS_DISABLEDEVICE
:
1073 if (dap
->DeviceStarted
)
1075 Ret
= EnableDevice(dap
->DeviceInfoSet
,
1076 &dap
->DeviceInfoData
,
1091 /* make PropertySheet() return PSM_REBOOTSYSTEM */
1092 PropSheet_RebootSystem(hwndDlg
);
1097 /* FIXME - display an error message */
1098 DPRINT1("Failed to enable/disable device! LastError: %d\n",
1103 Ret
= !dap
->DeviceUsageChanged
;
1105 /* disable the apply button */
1106 PropSheet_UnChanged(GetParent(hwndDlg
),
1108 dap
->DeviceUsageChanged
= FALSE
;
1114 UpdateDevInfo(IN HWND hwndDlg
,
1115 IN PDEVADVPROP_INFO dap
,
1118 HWND hDevUsage
, hPropSheetDlg
, hDevProbBtn
;
1120 ULONG Status
, ProblemNumber
;
1121 SP_DEVINSTALL_PARAMS_W InstallParams
;
1122 UINT TroubleShootStrId
= IDS_TROUBLESHOOTDEV
;
1123 BOOL bFlag
, bDevActionAvailable
= TRUE
;
1124 BOOL bDrvInstalled
= FALSE
;
1126 HDEVINFO DeviceInfoSet
= NULL
;
1127 PSP_DEVINFO_DATA DeviceInfoData
= NULL
;
1128 PROPSHEETHEADER psh
;
1129 DWORD nDriverPages
= 0;
1130 BOOL RecalcPages
= FALSE
;
1132 hPropSheetDlg
= GetParent(hwndDlg
);
1134 if (dap
->PageInitialized
)
1136 /* switch to the General page */
1137 PropSheet_SetCurSelByID(hPropSheetDlg
,
1140 /* remove and destroy the existing device property sheet pages */
1141 if (dap
->DevPropSheets
!= NULL
)
1144 iPage
!= dap
->nDevPropSheets
;
1147 if (dap
->DevPropSheets
[iPage
] != NULL
)
1149 PropSheet_RemovePage(hPropSheetDlg
,
1151 dap
->DevPropSheets
[iPage
]);
1160 if (dap
->FreeDevPropSheets
)
1162 /* don't free the array if it's the one allocated in
1163 DisplayDeviceAdvancedProperties */
1164 HeapFree(GetProcessHeap(),
1166 dap
->DevPropSheets
);
1168 dap
->FreeDevPropSheets
= FALSE
;
1171 dap
->DevPropSheets
= NULL
;
1172 dap
->nDevPropSheets
= 0;
1176 /* create a new device info set and re-open the device */
1177 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1179 SetupDiDestroyDeviceInfoList(dap
->CurrentDeviceInfoSet
);
1182 dap
->ParentDevInst
= 0;
1183 dap
->CurrentDeviceInfoSet
= SetupDiCreateDeviceInfoListEx(NULL
,
1187 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1189 if (SetupDiOpenDeviceInfo(dap
->CurrentDeviceInfoSet
,
1193 &dap
->CurrentDeviceInfoData
))
1195 if (dap
->CloseDevInst
)
1197 SetupDiDestroyDeviceInfoList(dap
->DeviceInfoSet
);
1200 dap
->CloseDevInst
= TRUE
;
1201 dap
->DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1202 dap
->DeviceInfoData
= dap
->CurrentDeviceInfoData
;
1203 dap
->CurrentDeviceInfoSet
= INVALID_HANDLE_VALUE
;
1211 /* get the parent node from the initial devinst */
1212 CM_Get_Parent_Ex(&dap
->ParentDevInst
,
1213 dap
->DeviceInfoData
.DevInst
,
1218 if (dap
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
1220 DeviceInfoSet
= dap
->CurrentDeviceInfoSet
;
1221 DeviceInfoData
= &dap
->CurrentDeviceInfoData
;
1225 DeviceInfoSet
= dap
->DeviceInfoSet
;
1226 DeviceInfoData
= &dap
->DeviceInfoData
;
1231 DeviceInfoSet
= dap
->DeviceInfoSet
;
1232 DeviceInfoData
= &dap
->DeviceInfoData
;
1235 dap
->HasDriverPage
= FALSE
;
1236 dap
->HasResourcePage
= FALSE
;
1237 dap
->HasPowerPage
= FALSE
;
1238 if (IsDriverInstalled(DeviceInfoData
->DevInst
,
1243 if (SetupDiCallClassInstaller((dap
->ShowRemotePages
?
1244 DIF_ADDREMOTEPROPERTYPAGE_ADVANCED
:
1245 DIF_ADDPROPERTYPAGE_ADVANCED
),
1249 /* get install params */
1250 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS_W
);
1251 if (!SetupDiGetDeviceInstallParamsW(DeviceInfoSet
,
1255 /* zero the flags */
1256 InstallParams
.Flags
= 0;
1259 dap
->HasDriverPage
= !(InstallParams
.Flags
& DI_DRIVERPAGE_ADDED
);
1260 dap
->HasResourcePage
= !(InstallParams
.Flags
& DI_RESOURCEPAGE_ADDED
);
1261 dap
->HasPowerPage
= !(InstallParams
.Flags
& DI_FLAGSEX_POWERPAGE_ADDED
);
1265 /* get the device icon */
1266 if (dap
->hDevIcon
!= NULL
)
1268 DestroyIcon(dap
->hDevIcon
);
1269 dap
->hDevIcon
= NULL
;
1271 if (!SetupDiLoadClassIcon(&DeviceInfoData
->ClassGuid
,
1275 dap
->hDevIcon
= NULL
;
1278 /* get the device name */
1279 if (GetDeviceDescriptionString(DeviceInfoSet
,
1282 sizeof(dap
->szDevName
) / sizeof(dap
->szDevName
[0])))
1284 PropSheet_SetTitle(hPropSheetDlg
,
1289 /* set the device image */
1290 SendDlgItemMessage(hwndDlg
,
1293 (WPARAM
)dap
->hDevIcon
,
1296 /* set the device name edit control text */
1297 SetDlgItemText(hwndDlg
,
1301 /* set the device type edit control text */
1302 if (GetDeviceTypeString(DeviceInfoData
,
1304 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1306 SetDlgItemText(hwndDlg
,
1311 /* set the device manufacturer edit control text */
1312 if (GetDeviceManufacturerString(DeviceInfoSet
,
1315 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1317 SetDlgItemText(hwndDlg
,
1318 IDC_DEVMANUFACTURER
,
1322 /* set the device location edit control text */
1323 if (GetDeviceLocationString(DeviceInfoData
->DevInst
,
1326 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1328 SetDlgItemText(hwndDlg
,
1333 /* set the device status edit control text */
1334 if (GetDeviceStatusString(DeviceInfoData
->DevInst
,
1337 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
1339 SetDlgItemText(hwndDlg
,
1344 /* set the device troubleshoot button text and disable it if necessary */
1345 hDevProbBtn
= GetDlgItem(hwndDlg
,
1347 cr
= CM_Get_DevNode_Status_Ex(&Status
,
1349 DeviceInfoData
->DevInst
,
1352 if (cr
== CR_SUCCESS
&& (Status
& DN_HAS_PROBLEM
))
1354 switch (ProblemNumber
)
1356 case CM_PROB_DEVLOADER_FAILED
:
1358 /* FIXME - only if it's not a root bus devloader,
1359 disable the button otherwise */
1360 TroubleShootStrId
= IDS_UPDATEDRV
;
1364 case CM_PROB_OUT_OF_MEMORY
:
1365 case CM_PROB_ENTRY_IS_WRONG_TYPE
:
1366 case CM_PROB_LACKED_ARBITRATOR
:
1367 case CM_PROB_FAILED_START
:
1369 case CM_PROB_UNKNOWN_RESOURCE
:
1371 TroubleShootStrId
= IDS_UPDATEDRV
;
1375 case CM_PROB_BOOT_CONFIG_CONFLICT
:
1376 case CM_PROB_NORMAL_CONFLICT
:
1377 case CM_PROB_REENUMERATION
:
1379 /* FIXME - Troubleshoot conflict */
1383 case CM_PROB_FAILED_FILTER
:
1384 case CM_PROB_REINSTALL
:
1385 case CM_PROB_FAILED_INSTALL
:
1387 TroubleShootStrId
= IDS_REINSTALLDRV
;
1391 case CM_PROB_DEVLOADER_NOT_FOUND
:
1394 1) if it's a missing system devloader:
1395 - disable the button (Reinstall Driver)
1396 2) if it's not a system devloader but still missing:
1398 3) if it's not a system devloader but the file can be found:
1400 4) if it's a missing or empty software key
1406 case CM_PROB_INVALID_DATA
:
1407 case CM_PROB_PARTIAL_LOG_CONF
:
1408 case CM_PROB_NO_VALID_LOG_CONF
:
1409 case CM_PROB_HARDWARE_DISABLED
:
1410 case CM_PROB_CANT_SHARE_IRQ
:
1411 case CM_PROB_TRANSLATION_FAILED
:
1412 case CM_PROB_SYSTEM_SHUTDOWN
:
1413 case CM_PROB_PHANTOM
:
1414 bDevActionAvailable
= FALSE
;
1417 case CM_PROB_NOT_VERIFIED
:
1418 case CM_PROB_DEVICE_NOT_THERE
:
1419 /* FIXME - search hardware */
1422 case CM_PROB_NEED_RESTART
:
1423 case CM_PROB_WILL_BE_REMOVED
:
1425 case CM_PROB_TOO_EARLY
:
1426 case CM_PROB_DISABLED_SERVICE
:
1427 TroubleShootStrId
= IDS_REBOOT
;
1430 case CM_PROB_REGISTRY
:
1431 /* FIXME - check registry? */
1434 case CM_PROB_DISABLED
:
1435 /* if device was disabled by the user: */
1436 TroubleShootStrId
= IDS_ENABLEDEV
;
1437 /* FIXME - otherwise disable button because the device was
1438 disabled by the system*/
1441 case CM_PROB_DEVLOADER_NOT_READY
:
1442 /* FIXME - if it's a graphics adapter:
1443 - if it's a a secondary adapter and the main adapter
1453 case CM_PROB_FAILED_ADD
:
1454 TroubleShootStrId
= IDS_PROPERTIES
;
1459 if (LoadString(hDllInstance
,
1462 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])) != 0)
1464 SetWindowText(hDevProbBtn
,
1467 EnableWindow(hDevProbBtn
,
1468 dap
->IsAdmin
&& bDevActionAvailable
);
1470 /* check if the device can be enabled/disabled */
1471 hDevUsage
= GetDlgItem(hwndDlg
,
1474 dap
->CanDisable
= FALSE
;
1475 dap
->DeviceStarted
= FALSE
;
1477 if (CanDisableDevice(DeviceInfoData
->DevInst
,
1481 dap
->CanDisable
= bFlag
;
1484 if (IsDeviceStarted(DeviceInfoData
->DevInst
,
1488 dap
->DeviceStarted
= bFlag
;
1491 /* enable/disable the device usage controls */
1492 EnableWindow(GetDlgItem(hwndDlg
,
1494 dap
->CanDisable
&& dap
->IsAdmin
);
1495 EnableWindow(hDevUsage
,
1496 dap
->CanDisable
&& dap
->IsAdmin
);
1498 /* clear the combobox */
1499 SendMessage(hDevUsage
,
1503 if (dap
->CanDisable
)
1505 InitDevUsageActions(hwndDlg
,
1510 /* find out how many new device property sheets to add.
1511 fake a PROPSHEETHEADER structure, we don't plan to
1512 call PropertySheet again!*/
1513 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
1517 /* get the number of device property sheets for the device */
1518 if (!SetupDiGetClassDevPropertySheets(DeviceInfoSet
,
1523 dap
->PropertySheetType
) &&
1524 nDriverPages
!= 0 && GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
1526 dap
->nDevPropSheets
+= nDriverPages
;
1533 /* include the driver page */
1534 if (dap
->HasDriverPage
)
1535 dap
->nDevPropSheets
++;
1537 /* include the details page */
1538 dap
->nDevPropSheets
++;
1540 /* add the device property sheets */
1541 if (dap
->nDevPropSheets
!= 0)
1543 dap
->DevPropSheets
= HeapAlloc(GetProcessHeap(),
1545 dap
->nDevPropSheets
* sizeof(HPROPSHEETPAGE
));
1546 if (dap
->DevPropSheets
!= NULL
)
1548 if (nDriverPages
!= 0)
1550 psh
.phpage
= dap
->DevPropSheets
;
1552 /* query the device property sheet pages to add */
1553 if (SetupDiGetClassDevPropertySheets(DeviceInfoSet
,
1556 dap
->nDevPropSheets
,
1558 dap
->PropertySheetType
))
1560 /* add the property sheets */
1562 iPage
!= nDriverPages
;
1565 if (PropSheet_AddPage(hPropSheetDlg
,
1566 dap
->DevPropSheets
[iPage
]))
1572 dap
->FreeDevPropSheets
= TRUE
;
1576 /* cleanup, we were unable to get the device property sheets */
1577 iPage
= nDriverPages
;
1578 dap
->nDevPropSheets
-= nDriverPages
;
1585 /* add the driver page if necessary */
1586 if (dap
->HasDriverPage
)
1588 PROPSHEETPAGE pspDriver
= {0};
1589 pspDriver
.dwSize
= sizeof(PROPSHEETPAGE
);
1590 pspDriver
.dwFlags
= PSP_DEFAULT
;
1591 pspDriver
.hInstance
= hDllInstance
;
1592 pspDriver
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICEDRIVER
);
1593 pspDriver
.pfnDlgProc
= AdvProcDriverDlgProc
;
1594 pspDriver
.lParam
= (LPARAM
)dap
;
1595 dap
->DevPropSheets
[iPage
] = dap
->pCreatePropertySheetPageW(&pspDriver
);
1596 if (dap
->DevPropSheets
[iPage
] != NULL
)
1598 if (PropSheet_AddPage(hPropSheetDlg
,
1599 dap
->DevPropSheets
[iPage
]))
1606 dap
->pDestroyPropertySheetPage(dap
->DevPropSheets
[iPage
]);
1607 dap
->DevPropSheets
[iPage
] = NULL
;
1614 PROPSHEETPAGE pspDetails
= {0};
1615 pspDetails
.dwSize
= sizeof(PROPSHEETPAGE
);
1616 pspDetails
.dwFlags
= PSP_DEFAULT
;
1617 pspDetails
.hInstance
= hDllInstance
;
1618 pspDetails
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICEDETAILS
);
1619 pspDetails
.pfnDlgProc
= AdvProcDetailsDlgProc
;
1620 pspDetails
.lParam
= (LPARAM
)dap
;
1621 dap
->DevPropSheets
[iPage
] = dap
->pCreatePropertySheetPageW(&pspDetails
);
1622 if (dap
->DevPropSheets
[iPage
] != NULL
)
1624 if (PropSheet_AddPage(hPropSheetDlg
,
1625 dap
->DevPropSheets
[iPage
]))
1632 dap
->pDestroyPropertySheetPage(dap
->DevPropSheets
[iPage
]);
1633 dap
->DevPropSheets
[iPage
] = NULL
;
1638 /* FIXME: Add the resources page */
1640 /* FIXME: Add the power page */
1643 dap
->nDevPropSheets
= 0;
1648 PropSheet_RecalcPageSizes(hPropSheetDlg
);
1651 /* finally, disable the apply button */
1652 PropSheet_UnChanged(hPropSheetDlg
,
1654 dap
->DeviceUsageChanged
= FALSE
;
1660 DlgParentSubWndProc(IN HWND hwnd
,
1665 PDEVADVPROP_INFO dap
;
1667 dap
= (PDEVADVPROP_INFO
)GetProp(hwnd
,
1668 L
"DevMgrDevChangeSub");
1671 if (uMsg
== WM_DEVICECHANGE
&& !IsWindowVisible(dap
->hWndGeneralPage
))
1673 SendMessage(dap
->hWndGeneralPage
,
1679 /* pass the message the the old window proc */
1680 return CallWindowProc(dap
->ParentOldWndProc
,
1688 /* this is not a good idea if the subclassed window was an ansi
1689 window, but we failed finding out the previous window proc
1690 so we can't use CallWindowProc. This should rarely - if ever -
1693 return DefWindowProc(hwnd
,
1703 AdvPropGeneralDlgProc(IN HWND hwndDlg
,
1708 PDEVADVPROP_INFO dap
;
1709 INT_PTR Ret
= FALSE
;
1711 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
,
1714 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
1720 switch (LOWORD(wParam
))
1724 if (HIWORD(wParam
) == CBN_SELCHANGE
)
1726 PropSheet_Changed(GetParent(hwndDlg
),
1728 dap
->DeviceUsageChanged
= TRUE
;
1733 case IDC_DEVPROBLEM
:
1737 /* display the device problem wizard */
1738 ShowDeviceProblemWizard(hwndDlg
,
1740 &dap
->DeviceInfoData
,
1751 NMHDR
*hdr
= (NMHDR
*)lParam
;
1755 ApplyGeneralSettings(hwndDlg
,
1764 dap
= (PDEVADVPROP_INFO
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1769 dap
->hWndGeneralPage
= hwndDlg
;
1771 SetWindowLongPtr(hwndDlg
,
1775 /* subclass the parent window to always receive
1776 WM_DEVICECHANGE messages */
1777 hWndParent
= GetParent(hwndDlg
);
1778 if (hWndParent
!= NULL
)
1780 /* subclass the parent window. This is not safe
1781 if the parent window belongs to another thread! */
1782 dap
->ParentOldWndProc
= (WNDPROC
)SetWindowLongPtr(hWndParent
,
1784 (LONG_PTR
)DlgParentSubWndProc
);
1786 if (dap
->ParentOldWndProc
!= NULL
&&
1788 L
"DevMgrDevChangeSub",
1791 dap
->hWndParent
= hWndParent
;
1795 /* do not call UpdateDevInfo directly in here because it modifies
1796 the pages of the property sheet! */
1797 PostMessage(hwndDlg
,
1806 case WM_DEVICECHANGE
:
1808 /* FIXME - don't call UpdateDevInfo for all events */
1809 UpdateDevInfo(hwndDlg
,
1818 UpdateDevInfo(hwndDlg
,
1821 dap
->PageInitialized
= TRUE
;
1827 /* restore the old window proc of the subclassed parent window */
1828 if (dap
->hWndParent
!= NULL
&& dap
->ParentOldWndProc
!= NULL
)
1830 if (SetWindowLongPtr(dap
->hWndParent
,
1832 (LONG_PTR
)dap
->ParentOldWndProc
) == (LONG_PTR
)DlgParentSubWndProc
)
1834 RemoveProp(dap
->hWndParent
,
1835 L
"DevMgrDevChangeSub");
1848 DisplayDeviceAdvancedProperties(IN HWND hWndParent
,
1849 IN LPCWSTR lpDeviceID OPTIONAL
,
1850 IN HDEVINFO DeviceInfoSet
,
1851 IN PSP_DEVINFO_DATA DeviceInfoData
,
1852 IN HINSTANCE hComCtl32
,
1853 IN LPCWSTR lpMachineName
,
1856 PROPSHEETHEADER psh
= {0};
1857 PROPSHEETPAGE pspGeneral
= {0};
1858 PPROPERTYSHEETW pPropertySheetW
;
1859 PCREATEPROPERTYSHEETPAGEW pCreatePropertySheetPageW
;
1860 PDESTROYPROPERTYSHEETPAGE pDestroyPropertySheetPage
;
1861 PDEVADVPROP_INFO DevAdvPropInfo
;
1862 HMACHINE hMachine
= NULL
;
1863 DWORD DevIdSize
= 0;
1866 /* we don't want to statically link against comctl32, so find the
1867 functions we need dynamically */
1869 (PPROPERTYSHEETW
)GetProcAddress(hComCtl32
,
1871 pCreatePropertySheetPageW
=
1872 (PCREATEPROPERTYSHEETPAGEW
)GetProcAddress(hComCtl32
,
1873 "CreatePropertySheetPageW");
1874 pDestroyPropertySheetPage
=
1875 (PDESTROYPROPERTYSHEETPAGE
)GetProcAddress(hComCtl32
,
1876 "DestroyPropertySheetPage");
1877 if (pPropertySheetW
== NULL
||
1878 pCreatePropertySheetPageW
== NULL
||
1879 pDestroyPropertySheetPage
== NULL
)
1884 if (lpDeviceID
== NULL
)
1886 /* find out how much size is needed for the device id */
1887 if (SetupDiGetDeviceInstanceId(DeviceInfoSet
,
1893 DPRINT1("SetupDiGetDeviceInstanceId unexpectedly returned TRUE!\n");
1897 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
1904 DevIdSize
= (DWORD
)wcslen(lpDeviceID
) + 1;
1907 if (lpMachineName
!= NULL
&& lpMachineName
[0] != L
'\0')
1909 CONFIGRET cr
= CM_Connect_Machine(lpMachineName
,
1911 if (cr
!= CR_SUCCESS
)
1917 /* create the internal structure associated with the "General",
1918 "Driver", ... pages */
1919 DevAdvPropInfo
= HeapAlloc(GetProcessHeap(),
1921 FIELD_OFFSET(DEVADVPROP_INFO
,
1923 (DevIdSize
* sizeof(WCHAR
)));
1924 if (DevAdvPropInfo
== NULL
)
1926 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1930 if (lpDeviceID
== NULL
)
1932 /* read the device instance id */
1933 if (!SetupDiGetDeviceInstanceId(DeviceInfoSet
,
1935 DevAdvPropInfo
->szDeviceID
,
1944 /* copy the device instance id supplied by the caller */
1945 wcscpy(DevAdvPropInfo
->szDeviceID
,
1949 DevAdvPropInfo
->DeviceInfoSet
= DeviceInfoSet
;
1950 DevAdvPropInfo
->DeviceInfoData
= *DeviceInfoData
;
1951 DevAdvPropInfo
->CurrentDeviceInfoSet
= INVALID_HANDLE_VALUE
;
1952 DevAdvPropInfo
->CurrentDeviceInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
1954 DevAdvPropInfo
->ShowRemotePages
= (lpMachineName
!= NULL
&& lpMachineName
[0] != L
'\0');
1955 DevAdvPropInfo
->hMachine
= hMachine
;
1956 DevAdvPropInfo
->lpMachineName
= lpMachineName
;
1957 DevAdvPropInfo
->szDevName
[0] = L
'\0';
1958 DevAdvPropInfo
->hComCtl32
= hComCtl32
;
1959 DevAdvPropInfo
->pCreatePropertySheetPageW
= pCreatePropertySheetPageW
;
1960 DevAdvPropInfo
->pDestroyPropertySheetPage
= pDestroyPropertySheetPage
;
1962 DevAdvPropInfo
->IsAdmin
= IsUserAdmin();
1963 DevAdvPropInfo
->DoDefaultDevAction
= ((dwFlags
& DPF_DEVICE_STATUS_ACTION
) != 0);
1965 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
1966 psh
.dwFlags
= PSH_PROPTITLE
| PSH_NOAPPLYNOW
;
1967 psh
.hwndParent
= hWndParent
;
1968 psh
.pszCaption
= DevAdvPropInfo
->szDevName
;
1970 DevAdvPropInfo
->PropertySheetType
= DevAdvPropInfo
->ShowRemotePages
?
1971 DIGCDP_FLAG_REMOTE_ADVANCED
:
1972 DIGCDP_FLAG_ADVANCED
;
1974 psh
.phpage
= HeapAlloc(GetProcessHeap(),
1976 1 * sizeof(HPROPSHEETPAGE
));
1977 if (psh
.phpage
== NULL
)
1982 /* add the "General" property sheet */
1983 pspGeneral
.dwSize
= sizeof(PROPSHEETPAGE
);
1984 pspGeneral
.dwFlags
= PSP_DEFAULT
;
1985 pspGeneral
.hInstance
= hDllInstance
;
1986 pspGeneral
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICEGENERAL
);
1987 pspGeneral
.pfnDlgProc
= AdvPropGeneralDlgProc
;
1988 pspGeneral
.lParam
= (LPARAM
)DevAdvPropInfo
;
1989 psh
.phpage
[psh
.nPages
] = pCreatePropertySheetPageW(&pspGeneral
);
1990 if (psh
.phpage
[psh
.nPages
] != NULL
)
1995 DevAdvPropInfo
->nDevPropSheets
= psh
.nPages
;
1997 if (psh
.nPages
!= 0)
1999 Ret
= pPropertySheetW(&psh
);
2001 /* NOTE: no need to destroy the property sheets anymore! */
2008 /* in case of failure the property sheets must be destroyed */
2009 if (psh
.phpage
!= NULL
)
2015 if (psh
.phpage
[i
] != NULL
)
2017 pDestroyPropertySheetPage(psh
.phpage
[i
]);
2023 if (DevAdvPropInfo
!= NULL
)
2025 if (DevAdvPropInfo
->FreeDevPropSheets
)
2027 /* don't free the array if it's the one allocated in
2028 DisplayDeviceAdvancedProperties */
2029 HeapFree(GetProcessHeap(),
2031 DevAdvPropInfo
->DevPropSheets
);
2034 if (DevAdvPropInfo
->CloseDevInst
)
2036 /* close the device info set in case a new one was created */
2037 SetupDiDestroyDeviceInfoList(DevAdvPropInfo
->DeviceInfoSet
);
2040 if (DevAdvPropInfo
->CurrentDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
2042 SetupDiDestroyDeviceInfoList(DevAdvPropInfo
->CurrentDeviceInfoSet
);
2045 if (DevAdvPropInfo
->hDevIcon
!= NULL
)
2047 DestroyIcon(DevAdvPropInfo
->hDevIcon
);
2050 HeapFree(GetProcessHeap(),
2055 if (psh
.phpage
!= NULL
)
2057 HeapFree(GetProcessHeap(),
2062 if (hMachine
!= NULL
)
2064 CM_Disconnect_Machine(hMachine
);
2072 GetDeviceAndComputerName(LPWSTR lpString
,
2074 WCHAR szMachineName
[])
2078 szDeviceID
[0] = L
'\0';
2079 szMachineName
[0] = L
'\0';
2081 while (*lpString
!= L
'\0')
2083 if (*lpString
== L
'/')
2086 if(!_wcsnicmp(lpString
, L
"DeviceID", 8))
2089 if (*lpString
!= L
'\0')
2092 while ((*lpString
!= L
' ') &&
2093 (*lpString
!= L
'\0') &&
2094 (i
<= MAX_DEVICE_ID_LEN
))
2096 szDeviceID
[i
++] = *lpString
++;
2098 szDeviceID
[i
] = L
'\0';
2102 else if (!_wcsnicmp(lpString
, L
"MachineName", 11))
2105 if (*lpString
!= L
'\0')
2108 while ((*lpString
!= L
' ') &&
2109 (*lpString
!= L
'\0') &&
2110 (i
<= MAX_COMPUTERNAME_LENGTH
))
2112 szMachineName
[i
++] = *lpString
++;
2114 szMachineName
[i
] = L
'\0';
2117 /* knock the pointer back one and let the next
2118 * pointer deal with incrementing, otherwise we
2119 * go past the end of the string */
2129 /***************************************************************************
2131 * DeviceAdvancedPropertiesW
2134 * Invokes the device properties dialog, this version may add some property pages
2138 * hWndParent: Handle to the parent window
2139 * lpMachineName: Machine Name, NULL is the local machine
2140 * lpDeviceID: Specifies the device whose properties are to be shown
2143 * Always returns -1, a call to GetLastError returns 0 if successful
2149 DeviceAdvancedPropertiesW(IN HWND hWndParent OPTIONAL
,
2150 IN LPCWSTR lpMachineName OPTIONAL
,
2151 IN LPCWSTR lpDeviceID
)
2154 SP_DEVINFO_DATA DevInfoData
;
2155 HINSTANCE hComCtl32
;
2158 if (lpDeviceID
== NULL
)
2160 SetLastError(ERROR_INVALID_PARAMETER
);
2164 /* dynamically load comctl32 */
2165 hComCtl32
= LoadAndInitComctl32();
2166 if (hComCtl32
!= NULL
)
2168 hDevInfo
= SetupDiCreateDeviceInfoListEx(NULL
,
2172 if (hDevInfo
!= INVALID_HANDLE_VALUE
)
2174 DevInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
2175 if (SetupDiOpenDeviceInfo(hDevInfo
,
2181 Ret
= DisplayDeviceAdvancedProperties(hWndParent
,
2190 SetupDiDestroyDeviceInfoList(hDevInfo
);
2193 FreeLibrary(hComCtl32
);
2200 /***************************************************************************
2202 * DeviceAdvancedPropertiesA
2205 * Invokes the device properties dialog, this version may add some property pages
2209 * hWndParent: Handle to the parent window
2210 * lpMachineName: Machine Name, NULL is the local machine
2211 * lpDeviceID: Specifies the device whose properties are to be shown
2214 * Always returns -1, a call to GetLastError returns 0 if successful
2220 DeviceAdvancedPropertiesA(IN HWND hWndParent OPTIONAL
,
2221 IN LPCSTR lpMachineName OPTIONAL
,
2222 IN LPCSTR lpDeviceID
)
2224 LPWSTR lpMachineNameW
= NULL
;
2225 LPWSTR lpDeviceIDW
= NULL
;
2228 if (lpMachineName
!= NULL
)
2230 if (!(lpMachineNameW
= ConvertMultiByteToUnicode(lpMachineName
,
2236 if (lpDeviceID
!= NULL
)
2238 if (!(lpDeviceIDW
= ConvertMultiByteToUnicode(lpDeviceID
,
2245 Ret
= DeviceAdvancedPropertiesW(hWndParent
,
2250 if (lpMachineNameW
!= NULL
)
2252 HeapFree(GetProcessHeap(),
2256 if (lpDeviceIDW
!= NULL
)
2258 HeapFree(GetProcessHeap(),
2267 /***************************************************************************
2269 * DevicePropertiesExA
2272 * Invokes the extended device properties dialog
2275 * hWndParent: Handle to the parent window
2276 * lpMachineName: Machine Name, NULL is the local machine
2277 * lpDeviceID: Specifies the device whose properties are to be shown, optional if
2278 * bShowDevMgr is nonzero
2279 * dwFlags: This parameter can be a combination of the following flags:
2280 * * DPF_DEVICE_STATUS_ACTION: Only valid if bShowDevMgr, causes
2281 * the default device status action button
2282 * to be clicked (Troubleshoot, Enable
2284 * bShowDevMgr: If non-zero it displays the device manager instead of
2285 * the advanced device property dialog
2288 * 1: if bShowDevMgr is non-zero and no error occured
2289 * -1: a call to GetLastError returns 0 if successful
2295 DevicePropertiesExA(IN HWND hWndParent OPTIONAL
,
2296 IN LPCSTR lpMachineName OPTIONAL
,
2297 IN LPCSTR lpDeviceID OPTIONAL
,
2298 IN DWORD dwFlags OPTIONAL
,
2299 IN BOOL bShowDevMgr
)
2301 LPWSTR lpMachineNameW
= NULL
;
2302 LPWSTR lpDeviceIDW
= NULL
;
2305 if (lpMachineName
!= NULL
)
2307 if (!(lpMachineNameW
= ConvertMultiByteToUnicode(lpMachineName
,
2313 if (lpDeviceID
!= NULL
)
2315 if (!(lpDeviceIDW
= ConvertMultiByteToUnicode(lpDeviceID
,
2322 Ret
= DevicePropertiesExW(hWndParent
,
2329 if (lpMachineNameW
!= NULL
)
2331 HeapFree(GetProcessHeap(),
2335 if (lpDeviceIDW
!= NULL
)
2337 HeapFree(GetProcessHeap(),
2346 /***************************************************************************
2348 * DevicePropertiesExW
2351 * Invokes the extended device properties dialog
2354 * hWndParent: Handle to the parent window
2355 * lpMachineName: Machine Name, NULL is the local machine
2356 * lpDeviceID: Specifies the device whose properties are to be shown, optional if
2357 * bShowDevMgr is nonzero
2358 * dwFlags: This parameter can be a combination of the following flags:
2359 * * DPF_DEVICE_STATUS_ACTION: Only valid if bShowDevMgr, causes
2360 * the default device status action button
2361 * to be clicked (Troubleshoot, Enable
2363 * bShowDevMgr: If non-zero it displays the device manager instead of
2364 * the advanced device property dialog
2367 * 1: if bShowDevMgr is non-zero and no error occured
2368 * -1: a call to GetLastError returns 0 if successful
2374 DevicePropertiesExW(IN HWND hWndParent OPTIONAL
,
2375 IN LPCWSTR lpMachineName OPTIONAL
,
2376 IN LPCWSTR lpDeviceID OPTIONAL
,
2377 IN DWORD dwFlags OPTIONAL
,
2378 IN BOOL bShowDevMgr
)
2382 if (dwFlags
& ~(DPF_EXTENDED
| DPF_DEVICE_STATUS_ACTION
))
2384 DPRINT1("DevPropertiesExW: Invalid flags: 0x%x\n",
2385 dwFlags
& ~(DPF_EXTENDED
| DPF_DEVICE_STATUS_ACTION
));
2386 SetLastError(ERROR_INVALID_FLAGS
);
2392 DPRINT("DevPropertiesExW doesn't support bShowDevMgr!\n");
2393 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2398 SP_DEVINFO_DATA DevInfoData
;
2399 HINSTANCE hComCtl32
;
2401 if (lpDeviceID
== NULL
)
2403 SetLastError(ERROR_INVALID_PARAMETER
);
2407 /* dynamically load comctl32 */
2408 hComCtl32
= LoadAndInitComctl32();
2409 if (hComCtl32
!= NULL
)
2411 hDevInfo
= SetupDiCreateDeviceInfoListEx(NULL
,
2415 if (hDevInfo
!= INVALID_HANDLE_VALUE
)
2417 DevInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
2418 if (SetupDiOpenDeviceInfo(hDevInfo
,
2424 Ret
= DisplayDeviceAdvancedProperties(hWndParent
,
2433 SetupDiDestroyDeviceInfoList(hDevInfo
);
2436 FreeLibrary(hComCtl32
);
2444 /***************************************************************************
2449 * Invokes the device properties dialog directly
2452 * hWndParent: Handle to the parent window
2453 * lpMachineName: Machine Name, NULL is the local machine
2454 * lpDeviceID: Specifies the device whose properties are to be shown
2455 * bShowDevMgr: If non-zero it displays the device manager instead of
2456 * the device property dialog
2459 * >=0: if no errors occured
2460 * -1: if errors occured
2468 DevicePropertiesA(HWND hWndParent
,
2469 LPCSTR lpMachineName
,
2473 return DevicePropertiesExA(hWndParent
,
2481 /***************************************************************************
2486 * Invokes the device properties dialog directly
2489 * hWndParent: Handle to the parent window
2490 * lpMachineName: Machine Name, NULL is the local machine
2491 * lpDeviceID: Specifies the device whose properties are to be shown
2492 * bShowDevMgr: If non-zero it displays the device manager instead of
2493 * the device property dialog
2496 * >=0: if no errors occured
2497 * -1: if errors occured
2505 DevicePropertiesW(HWND hWndParent
,
2506 LPCWSTR lpMachineName
,
2510 return DevicePropertiesExW(hWndParent
,
2518 /***************************************************************************
2520 * DeviceProperties_RunDLLA
2523 * Invokes the device properties dialog
2526 * hWndParent: Handle to the parent window
2527 * hInst: Handle to the application instance
2528 * lpDeviceCmd: A command that includes the DeviceID of the properties to be shown,
2530 * nCmdShow: Specifies how the window should be shown
2537 * - lpDeviceCmd is a string in the form of "/MachineName MACHINE /DeviceID DEVICEPATH"
2538 * (/MachineName is optional). This function only parses this string and eventually
2539 * calls DeviceProperties().
2545 DeviceProperties_RunDLLA(HWND hWndParent
,
2550 LPWSTR lpDeviceCmdW
= NULL
;
2552 if (lpDeviceCmd
!= NULL
)
2554 if ((lpDeviceCmdW
= ConvertMultiByteToUnicode(lpDeviceCmd
,
2557 DeviceProperties_RunDLLW(hWndParent
,
2564 if (lpDeviceCmdW
!= NULL
)
2566 HeapFree(GetProcessHeap(),
2573 /***************************************************************************
2575 * DeviceProperties_RunDLLW
2578 * Invokes the device properties dialog
2581 * hWndParent: Handle to the parent window
2582 * hInst: Handle to the application instance
2583 * lpDeviceCmd: A command that includes the DeviceID of the properties to be shown,
2585 * nCmdShow: Specifies how the window should be shown
2592 * - lpDeviceCmd is a string in the form of "/MachineName MACHINE /DeviceID DEVICEPATH"
2593 * (/MachineName is optional). This function only parses this string and eventually
2594 * calls DeviceProperties().
2600 DeviceProperties_RunDLLW(HWND hWndParent
,
2602 LPCWSTR lpDeviceCmd
,
2605 WCHAR szDeviceID
[MAX_DEVICE_ID_LEN
+1];
2606 WCHAR szMachineName
[MAX_COMPUTERNAME_LENGTH
+1];
2607 LPWSTR lpString
= (LPWSTR
)lpDeviceCmd
;
2609 if (!GetDeviceAndComputerName(lpString
,
2613 DPRINT1("DeviceProperties_RunDLLW DeviceID: %S, MachineName: %S\n", szDeviceID
, szMachineName
);
2617 DevicePropertiesW(hWndParent
,