Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

992 lines
28 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation
  3. Module Name:
  4. devdetpg.cpp
  5. Abstract:
  6. This module implements CDeviceDetailsPage -- device details
  7. property page
  8. Author:
  9. Jason Cobb (JasonC) created
  10. Revision History:
  11. --*/
  12. #include "devmgr.h"
  13. #include "devdetpg.h"
  14. #include <wmidata.h>
  15. extern "C" {
  16. #include <initguid.h>
  17. #include <wdmguid.h>
  18. }
  19. //
  20. // help topic ids
  21. //
  22. const DWORD g_a15HelpIDs[]=
  23. {
  24. IDC_DEVDETAILS_DESC, IDH_DISABLEHELP,
  25. IDC_DEVDETAILS_ICON, IDH_DISABLEHELP,
  26. 0,0
  27. };
  28. BOOL
  29. CDeviceDetailsPage::OnInitDialog(
  30. LPPROPSHEETPAGE ppsp
  31. )
  32. {
  33. UNREFERENCED_PARAMETER(ppsp);
  34. try {
  35. m_hwndDetailsList = GetDlgItem(m_hDlg, IDC_DEVDETAILS_LIST);
  36. String DetailsType;
  37. for (int i = DETAILS_DEVICEINSTANCEID; i < DETAILS_MAX; i++) {
  38. DetailsType.LoadString(g_hInstance, IDS_DETAILS_DEVICEINSTANCEID + i);
  39. SendDlgItemMessage(m_hDlg, IDC_DEVDETAILS_COMBO, CB_ADDSTRING, 0, (LPARAM)(LPTSTR)DetailsType);
  40. }
  41. SendDlgItemMessage(m_hDlg, IDC_DEVDETAILS_COMBO, CB_SETCURSEL, 0, 0);
  42. LV_COLUMN lvcCol;
  43. lvcCol.mask = LVCF_FMT | LVCF_WIDTH;
  44. lvcCol.fmt = LVCFMT_LEFT;
  45. lvcCol.iSubItem = 0;
  46. ListView_InsertColumn(m_hwndDetailsList, 0, &lvcCol);
  47. ListView_SetExtendedListViewStyle(m_hwndDetailsList, LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP);
  48. UpdateDetailsText();
  49. }
  50. catch (CMemoryException* e)
  51. {
  52. e->Delete();
  53. // report memory error
  54. MsgBoxParam(m_hDlg, 0, 0, 0);
  55. }
  56. return TRUE;
  57. }
  58. BOOL
  59. CDeviceDetailsPage::OnCommand(
  60. WPARAM wParam,
  61. LPARAM lParam
  62. )
  63. {
  64. UNREFERENCED_PARAMETER(lParam);
  65. switch (LOWORD(wParam)) {
  66. case IDC_DEVDETAILS_COMBO:
  67. if (CBN_SELCHANGE == HIWORD(wParam)) {
  68. UpdateDetailsText();
  69. }
  70. break;
  71. }
  72. return FALSE;
  73. }
  74. BOOL
  75. CDeviceDetailsPage::OnNotify(
  76. LPNMHDR pnmhdr
  77. )
  78. {
  79. if (pnmhdr->idFrom == IDC_DEVDETAILS_LIST) {
  80. if (pnmhdr->code == LVN_KEYDOWN) {
  81. LPNMLVKEYDOWN pnmlvKeyDown = (LPNMLVKEYDOWN)pnmhdr;
  82. if (::GetKeyState(VK_CONTROL)) {
  83. switch (pnmlvKeyDown->wVKey) {
  84. case 'C':
  85. case 'c':
  86. case VK_INSERT:
  87. CopyToClipboard();
  88. break;
  89. case 'A':
  90. case 'a':
  91. ListView_SetSelectionMark(m_hwndDetailsList, 0);
  92. ListView_SetItemState(m_hwndDetailsList, -1, LVIS_SELECTED, LVIS_SELECTED);
  93. break;
  94. }
  95. }
  96. }
  97. }
  98. return FALSE;
  99. }
  100. //
  101. // This function refreshes every control in the dialog. It may be called
  102. // when the dialog is being initialized
  103. //
  104. void
  105. CDeviceDetailsPage::UpdateControls(
  106. LPARAM lParam
  107. )
  108. {
  109. if (lParam) {
  110. m_pDevice = (CDevice*)lParam;
  111. }
  112. try {
  113. HICON hIconOld;
  114. m_IDCicon = IDC_DEVDETAILS_ICON; // Save for cleanup in OnDestroy.
  115. hIconOld = (HICON)SendDlgItemMessage(m_hDlg, IDC_DEVDETAILS_ICON, STM_SETICON,
  116. (WPARAM)(m_pDevice->LoadClassIcon()),
  117. 0
  118. );
  119. if (hIconOld)
  120. {
  121. DestroyIcon(hIconOld);
  122. }
  123. SetDlgItemText(m_hDlg, IDC_DEVDETAILS_DESC, m_pDevice->GetDisplayName());
  124. }
  125. catch (CMemoryException* e)
  126. {
  127. e->Delete();
  128. // report memory error
  129. MsgBoxParam(m_hDlg, 0, 0, 0);
  130. }
  131. }
  132. BOOL
  133. CDeviceDetailsPage::OnHelp(
  134. LPHELPINFO pHelpInfo
  135. )
  136. {
  137. WinHelp((HWND)pHelpInfo->hItemHandle, DEVMGR_HELP_FILE_NAME, HELP_WM_HELP,
  138. (ULONG_PTR)g_a15HelpIDs);
  139. return FALSE;
  140. }
  141. BOOL
  142. CDeviceDetailsPage::OnContextMenu(
  143. HWND hWnd,
  144. WORD xPos,
  145. WORD yPos
  146. )
  147. {
  148. UNREFERENCED_PARAMETER(xPos);
  149. UNREFERENCED_PARAMETER(yPos);
  150. WinHelp(hWnd, DEVMGR_HELP_FILE_NAME, HELP_CONTEXTMENU,
  151. (ULONG_PTR)g_a15HelpIDs);
  152. return FALSE;
  153. }
  154. void
  155. CDeviceDetailsPage::UpdateDetailsText()
  156. {
  157. int CurSel = (int)SendDlgItemMessage(m_hDlg, IDC_DEVDETAILS_COMBO, CB_GETCURSEL, 0, 0);
  158. if (CurSel != CB_ERR) {
  159. ListView_DeleteAllItems(m_hwndDetailsList);
  160. switch(CurSel) {
  161. case DETAILS_DEVICEINSTANCEID:
  162. LVITEM lv;
  163. ZeroMemory(&lv, sizeof(LVITEM));
  164. lv.mask = LVIF_TEXT;
  165. lv.pszText = (LPTSTR)m_pDevice->GetDeviceID();
  166. ListView_InsertItem(m_hwndDetailsList, &lv);
  167. ListView_SetItemState(m_hwndDetailsList, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  168. break;
  169. case DETAILS_HARDWAREIDS:
  170. DisplayMultiSzString(SPDRP_HARDWAREID);
  171. break;
  172. case DETAILS_COMPATIDS:
  173. DisplayMultiSzString(SPDRP_COMPATIBLEIDS);
  174. break;
  175. case DETAILS_DEVICEUPPERFILTERS:
  176. DisplayMultiSzString(SPDRP_UPPERFILTERS);
  177. break;
  178. case DETAILS_DEVICELOWERFILTERS:
  179. DisplayMultiSzString(SPDRP_LOWERFILTERS);
  180. break;
  181. case DETAILS_CLASSUPPERFILTERS:
  182. case DETAILS_CLASSLOWERFILTERS:
  183. DisplayClassFilters(CurSel);
  184. break;
  185. case DETAILS_ENUMERATOR:
  186. DisplayString(SPDRP_ENUMERATOR_NAME);
  187. break;
  188. case DETAILS_SERVICE:
  189. DisplayString(SPDRP_SERVICE);
  190. break;
  191. case DETAILS_DEVNODE_FLAGS:
  192. case DETAILS_CAPABILITIES:
  193. case DETAILS_CONFIGFLAGS:
  194. case DETAILS_CSCONFIGFLAGS:
  195. case DETAILS_POWERCAPABILITIES:
  196. DisplayDevnodeFlags(CurSel);
  197. break;
  198. case DETAILS_EJECTIONRELATIONS:
  199. case DETAILS_REMOVALRELATIONS:
  200. case DETAILS_BUSRELATIONS:
  201. DisplayRelations(CurSel);
  202. break;
  203. case DETAILS_MATCHINGID:
  204. DisplayMatchingId();
  205. break;
  206. case DETAILS_CLASSINSTALLER:
  207. DisplayClassInstaller();
  208. break;
  209. case DETAILS_CLASSCOINSTALLERS:
  210. DisplayClassCoInstallers();
  211. break;
  212. case DETAILS_DEVICECOINSTALLERS:
  213. DisplayDeviceCoInstallers();
  214. break;
  215. case DETAILS_FIRMWAREREVISION:
  216. DisplayFirmwareRevision();
  217. break;
  218. case DETAILS_CURRENTPOWERSTATE:
  219. DisplayCurrentPowerState();
  220. break;
  221. case DETAILS_POWERSTATEMAPPINGS:
  222. DisplayPowerStateMappings();
  223. break;
  224. default:
  225. ASSERT(FALSE);
  226. break;
  227. }
  228. ListView_SetColumnWidth(m_hwndDetailsList, 0, LVSCW_AUTOSIZE_USEHEADER);
  229. }
  230. }
  231. void
  232. CDeviceDetailsPage::DisplayMultiSzString(
  233. DWORD Property
  234. )
  235. {
  236. TCHAR TempBuffer[REGSTR_VAL_MAX_HCID_LEN];
  237. ULONG TempBufferLen;
  238. LPTSTR SingleItem = NULL;
  239. LVITEM lv;
  240. TempBufferLen = sizeof(TempBuffer);
  241. if (m_pDevice->m_pMachine->DiGetDeviceRegistryProperty(
  242. *m_pDevice,
  243. Property,
  244. NULL,
  245. (PBYTE)TempBuffer,
  246. TempBufferLen,
  247. &TempBufferLen
  248. ) &&
  249. (TempBufferLen > 2 * sizeof(TCHAR))) {
  250. ZeroMemory(&lv, sizeof(LVITEM));
  251. lv.mask = LVIF_TEXT;
  252. lv.iItem = 0;
  253. for (SingleItem = TempBuffer; *SingleItem; SingleItem += (lstrlen(SingleItem) + 1)) {
  254. lv.pszText = SingleItem;
  255. ListView_InsertItem(m_hwndDetailsList, &lv);
  256. lv.iItem++;
  257. }
  258. ListView_SetItemState(m_hwndDetailsList, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  259. }
  260. }
  261. void
  262. CDeviceDetailsPage::DisplayString(
  263. DWORD Property
  264. )
  265. {
  266. TCHAR TempBuffer[MAX_PATH];
  267. ULONG TempBufferLen;
  268. LVITEM lv;
  269. TempBufferLen = sizeof(TempBuffer);
  270. if (m_pDevice->m_pMachine->DiGetDeviceRegistryProperty(
  271. *m_pDevice,
  272. Property,
  273. NULL,
  274. (PBYTE)TempBuffer,
  275. TempBufferLen,
  276. &TempBufferLen
  277. ) &&
  278. (TempBufferLen > 2 * sizeof(TCHAR))) {
  279. ZeroMemory(&lv, sizeof(LVITEM));
  280. lv.mask = LVIF_TEXT;
  281. lv.iItem = 0;
  282. lv.pszText = TempBuffer;
  283. ListView_InsertItem(m_hwndDetailsList, &lv);
  284. ListView_SetItemState(m_hwndDetailsList, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  285. }
  286. }
  287. void
  288. CDeviceDetailsPage::DisplayDevnodeFlags(
  289. DWORD StatusType
  290. )
  291. {
  292. DWORD Flags, Problem;
  293. LVITEM lv;
  294. UINT StatusStringId;
  295. int NumFlags;
  296. String stringDevnodeFlags;
  297. ZeroMemory(&lv, sizeof(LVITEM));
  298. lv.mask = LVIF_TEXT;
  299. lv.iItem = 0;
  300. Flags = NumFlags = 0;
  301. switch(StatusType) {
  302. case DETAILS_CAPABILITIES:
  303. m_pDevice->GetCapabilities(&Flags);
  304. StatusStringId = IDS_CM_DEVCAP_LOCKSUPPORTED;
  305. NumFlags = NUM_CM_DEVCAP_FLAGS;
  306. break;
  307. case DETAILS_DEVNODE_FLAGS:
  308. m_pDevice->GetStatus(&Flags, &Problem);
  309. StatusStringId = IDS_DN_ROOT_ENUMERATED;
  310. NumFlags = NUM_DN_STATUS_FLAGS;
  311. break;
  312. case DETAILS_CONFIGFLAGS:
  313. m_pDevice->GetConfigFlags(&Flags);
  314. StatusStringId = IDS_CONFIGFLAG_DISABLED;
  315. NumFlags = NUM_CONFIGFLAGS;
  316. break;
  317. case DETAILS_CSCONFIGFLAGS:
  318. m_pDevice->GetConfigSpecificConfigFlags(&Flags);
  319. StatusStringId = IDS_CSCONFIGFLAG_DISABLED;
  320. NumFlags = NUM_CSCONFIGFLAGS;
  321. break;
  322. case DETAILS_POWERCAPABILITIES:
  323. m_pDevice->GetPowerCapabilities(&Flags);
  324. StatusStringId = IDS_PDCAP_D0_SUPPORTED;
  325. NumFlags = NUM_POWERCAPABILITIES;
  326. break;
  327. default:
  328. StatusStringId = 0;
  329. ASSERT(StatusStringId == 0);
  330. break;
  331. }
  332. if (StatusStringId != 0) {
  333. for (int i = 0; i < NumFlags; i++) {
  334. if (Flags & 1<<i) {
  335. stringDevnodeFlags.LoadString(g_hInstance, StatusStringId + i);
  336. lv.pszText = (LPTSTR)stringDevnodeFlags;
  337. ListView_InsertItem(m_hwndDetailsList, &lv);
  338. lv.iItem++;
  339. }
  340. }
  341. ListView_SetItemState(m_hwndDetailsList, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  342. }
  343. }
  344. void
  345. CDeviceDetailsPage::DisplayRelations(
  346. DWORD RelationType
  347. )
  348. {
  349. DWORD FilterFlags = 0;
  350. ULONG RelationsSize = 0;
  351. LVITEM lv;
  352. LPTSTR DeviceIdRelations, CurrDevId;
  353. switch(RelationType) {
  354. case DETAILS_EJECTIONRELATIONS:
  355. FilterFlags = CM_GETIDLIST_FILTER_EJECTRELATIONS;
  356. break;
  357. case DETAILS_REMOVALRELATIONS:
  358. FilterFlags = CM_GETIDLIST_FILTER_REMOVALRELATIONS;
  359. break;
  360. case DETAILS_BUSRELATIONS:
  361. FilterFlags = CM_GETIDLIST_FILTER_BUSRELATIONS;
  362. break;
  363. default:
  364. FilterFlags = 0;
  365. ASSERT(FilterFlags == 0);
  366. break;
  367. }
  368. if (FilterFlags != 0) {
  369. if ((CM_Get_Device_ID_List_Size_Ex(&RelationsSize,
  370. m_pDevice->GetDeviceID(),
  371. FilterFlags,
  372. m_pDevice->m_pMachine->GetHMachine()
  373. ) == CR_SUCCESS) &&
  374. (RelationsSize > 2 * sizeof(TCHAR))) {
  375. if ((DeviceIdRelations = (LPTSTR)LocalAlloc(LPTR, RelationsSize * sizeof(TCHAR))) != NULL) {
  376. if ((CM_Get_Device_ID_List_Ex(m_pDevice->GetDeviceID(),
  377. DeviceIdRelations,
  378. RelationsSize,
  379. FilterFlags,
  380. m_pDevice->m_pMachine->GetHMachine()
  381. ) == CR_SUCCESS) &&
  382. (*DeviceIdRelations)) {
  383. ZeroMemory(&lv, sizeof(LVITEM));
  384. lv.mask = LVIF_TEXT;
  385. lv.iItem = 0;
  386. for (CurrDevId = DeviceIdRelations; *CurrDevId; CurrDevId += lstrlen(CurrDevId) + 1) {
  387. lv.pszText = CurrDevId;
  388. ListView_InsertItem(m_hwndDetailsList, &lv);
  389. lv.iItem++;
  390. }
  391. ListView_SetItemState(m_hwndDetailsList, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  392. }
  393. LocalFree(DeviceIdRelations);
  394. }
  395. }
  396. }
  397. }
  398. void
  399. CDeviceDetailsPage::DisplayMatchingId(
  400. VOID
  401. )
  402. {
  403. HKEY hKey;
  404. TCHAR TempBuffer[MAX_PATH];
  405. ULONG TempBufferLen;
  406. DWORD regType;
  407. LVITEM lv;
  408. //
  409. // Open drvice's driver registry key to get the MatchingDeviceId string
  410. //
  411. hKey = m_pDevice->m_pMachine->DiOpenDevRegKey(*m_pDevice, DICS_FLAG_GLOBAL,
  412. 0, DIREG_DRV, KEY_READ);
  413. if (INVALID_HANDLE_VALUE != hKey) {
  414. CSafeRegistry regDrv(hKey);
  415. TempBufferLen = sizeof(TempBuffer);
  416. //
  417. // Get the MatchingDeviceId from the driver key
  418. //
  419. if (regDrv.GetValue(REGSTR_VAL_MATCHINGDEVID,
  420. &regType,
  421. (PBYTE)TempBuffer,
  422. &TempBufferLen) &&
  423. (TempBufferLen > 2 * sizeof(TCHAR))) {
  424. ZeroMemory(&lv, sizeof(LVITEM));
  425. lv.mask = LVIF_TEXT;
  426. lv.iItem = 0;
  427. lv.pszText = TempBuffer;
  428. ListView_InsertItem(m_hwndDetailsList, &lv);
  429. ListView_SetItemState(m_hwndDetailsList, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  430. }
  431. }
  432. }
  433. void
  434. CDeviceDetailsPage::CopyToClipboard(
  435. void
  436. )
  437. {
  438. String stringClipboardData;
  439. TCHAR singleItem[REGSTR_VAL_MAX_HCID_LEN];
  440. stringClipboardData.Empty();
  441. //
  442. // Enumerate through all of the items and add the selected ones to the clipboard.
  443. //
  444. for (int index = 0;
  445. index != -1, index < ListView_GetItemCount(m_hwndDetailsList);
  446. index ++) {
  447. //
  448. // If this item is selected then add it to the clipboard.
  449. //
  450. if (ListView_GetItemState(m_hwndDetailsList, index, LVIS_SELECTED) & LVIS_SELECTED) {
  451. ListView_GetItemText(m_hwndDetailsList, index, 0, singleItem, sizeof(singleItem));
  452. if (stringClipboardData.IsEmpty()) {
  453. stringClipboardData = (LPCTSTR)singleItem;
  454. } else {
  455. stringClipboardData += (LPCTSTR)singleItem;
  456. }
  457. stringClipboardData += (LPCTSTR)TEXT("\r\n");
  458. }
  459. }
  460. if (!stringClipboardData.IsEmpty()) {
  461. HGLOBAL hMem = GlobalAlloc(GPTR, (stringClipboardData.GetLength() + 1) * sizeof(TCHAR));
  462. if (hMem) {
  463. memcpy(hMem, (LPTSTR)stringClipboardData, (stringClipboardData.GetLength() + 1) * sizeof(TCHAR));
  464. if (OpenClipboard(m_hDlg)) {
  465. EmptyClipboard();
  466. SetClipboardData(CF_UNICODETEXT, hMem);
  467. CloseClipboard();
  468. } else {
  469. GlobalFree(hMem);
  470. }
  471. }
  472. }
  473. }
  474. void
  475. CDeviceDetailsPage::DisplayClassInstaller(
  476. VOID
  477. )
  478. {
  479. HKEY hKey;
  480. TCHAR TempBuffer[MAX_PATH];
  481. ULONG TempBufferLen;
  482. DWORD regType;
  483. LVITEM lv;
  484. GUID ClassGuid;
  485. m_pDevice->ClassGuid(ClassGuid);
  486. //
  487. // Open Classes registry key
  488. //
  489. hKey = m_pDevice->m_pMachine->DiOpenClassRegKey(&ClassGuid, KEY_READ, DIOCR_INSTALLER);
  490. if (INVALID_HANDLE_VALUE != hKey) {
  491. CSafeRegistry regClass(hKey);
  492. TempBufferLen = sizeof(TempBuffer);
  493. //
  494. // Get the Installer32 from the driver key
  495. //
  496. if (regClass.GetValue(REGSTR_VAL_INSTALLER_32,
  497. &regType,
  498. (PBYTE)TempBuffer,
  499. &TempBufferLen) &&
  500. (TempBufferLen > 2 * sizeof(TCHAR))) {
  501. ZeroMemory(&lv, sizeof(LVITEM));
  502. lv.mask = LVIF_TEXT;
  503. lv.iItem = 0;
  504. lv.pszText = TempBuffer;
  505. ListView_InsertItem(m_hwndDetailsList, &lv);
  506. ListView_SetItemState(m_hwndDetailsList, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  507. }
  508. }
  509. }
  510. void
  511. CDeviceDetailsPage::DisplayClassCoInstallers(
  512. VOID
  513. )
  514. {
  515. TCHAR GuidString[MAX_GUID_STRING_LEN];
  516. DWORD regType, cbSize;
  517. LVITEM lv;
  518. CSafeRegistry regCoDeviceInstallers;
  519. PTSTR coinstallers;
  520. //
  521. // Get the string form of the class GUID, because that will be the name of
  522. // the multi-sz value entry under HKLM\System\CCS\Control\CoDeviceInstallers
  523. // where class-specific co-installers will be registered
  524. //
  525. GUID ClassGuid;
  526. m_pDevice->ClassGuid(ClassGuid);
  527. if (GuidToString(&ClassGuid, GuidString, ARRAYLEN(GuidString))) {
  528. if (regCoDeviceInstallers.Open(HKEY_LOCAL_MACHINE, REGSTR_PATH_CODEVICEINSTALLERS)) {
  529. //
  530. // Get the size of the coinstaller value
  531. //
  532. cbSize = 0;
  533. if (regCoDeviceInstallers.GetValue(GuidString, &regType, NULL, &cbSize) &&
  534. (cbSize > (2 * sizeof(TCHAR))) &&
  535. (regType == REG_MULTI_SZ)) {
  536. //
  537. // Allocate memory to hold the coinstaller values. First we will tack on some extra
  538. // space at the end of the buffer in case someone forgot to double NULL terminate
  539. // the multi_sz string.
  540. //
  541. coinstallers = (LPTSTR)LocalAlloc(LPTR, (cbSize + (2 * sizeof(TCHAR))));
  542. if (coinstallers) {
  543. if (regCoDeviceInstallers.GetValue(GuidString,
  544. &regType,
  545. (PBYTE)coinstallers,
  546. &cbSize
  547. )) {
  548. ZeroMemory(&lv, sizeof(LVITEM));
  549. lv.mask = LVIF_TEXT;
  550. lv.iItem = 0;
  551. for (PTSTR p = coinstallers; *p; p += (lstrlen(p) + 1)) {
  552. lv.pszText = p;
  553. ListView_InsertItem(m_hwndDetailsList, &lv);
  554. lv.iItem++;
  555. }
  556. ListView_SetItemState(m_hwndDetailsList, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  557. }
  558. LocalFree(coinstallers);
  559. }
  560. }
  561. }
  562. }
  563. }
  564. void
  565. CDeviceDetailsPage::DisplayDeviceCoInstallers(
  566. VOID
  567. )
  568. {
  569. DWORD regType, cbSize;
  570. LVITEM lv;
  571. HKEY hKey;
  572. PTSTR coinstallers;
  573. //
  574. // Open drvice's driver registry key to get the Installer32 string
  575. //
  576. hKey = m_pDevice->m_pMachine->DiOpenDevRegKey(*m_pDevice, DICS_FLAG_GLOBAL,
  577. 0, DIREG_DRV, KEY_READ);
  578. if (INVALID_HANDLE_VALUE != hKey) {
  579. CSafeRegistry regCoDeviceInstallers(hKey);
  580. //
  581. // Get the size of the coinstaller value
  582. //
  583. cbSize = 0;
  584. if (regCoDeviceInstallers.GetValue(REGSTR_VAL_COINSTALLERS_32, &regType, NULL, &cbSize) &&
  585. (cbSize > (2 * sizeof(TCHAR))) &&
  586. (regType == REG_MULTI_SZ)) {
  587. //
  588. // Allocate memory to hold the coinstaller values. First we will tack on some extra
  589. // space at the end of the buffer in case someone forgot to double NULL terminate
  590. // the multi_sz string.
  591. //
  592. coinstallers = (LPTSTR)LocalAlloc(LPTR, (cbSize + (2 * sizeof(TCHAR))));
  593. if (coinstallers) {
  594. if (regCoDeviceInstallers.GetValue(REGSTR_VAL_COINSTALLERS_32,
  595. &regType,
  596. (PBYTE)coinstallers,
  597. &cbSize
  598. )) {
  599. ZeroMemory(&lv, sizeof(LVITEM));
  600. lv.mask = LVIF_TEXT;
  601. lv.iItem = 0;
  602. for (PTSTR p = coinstallers; *p; p += (lstrlen(p) + 1)) {
  603. lv.pszText = p;
  604. ListView_InsertItem(m_hwndDetailsList, &lv);
  605. lv.iItem++;
  606. }
  607. ListView_SetItemState(m_hwndDetailsList, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  608. }
  609. LocalFree(coinstallers);
  610. }
  611. }
  612. }
  613. }
  614. void
  615. CDeviceDetailsPage::DisplayFirmwareRevision(
  616. VOID
  617. )
  618. {
  619. WMIHANDLE hWmiBlock;
  620. TCHAR DevInstId[MAX_DEVICE_ID_LEN + 2];
  621. LVITEM lv;
  622. WmiDevInstToInstanceName(DevInstId, ARRAYLEN(DevInstId), (PTCHAR)m_pDevice->GetDeviceID(), 0);
  623. ULONG Error;
  624. GUID Guid = DEVICE_UI_FIRMWARE_REVISION_GUID;
  625. Error = WmiOpenBlock(&Guid, 0, &hWmiBlock);
  626. if (ERROR_SUCCESS == Error) {
  627. ULONG BufferSize = 0;
  628. Error = WmiQuerySingleInstance(hWmiBlock,
  629. DevInstId,
  630. &BufferSize,
  631. NULL
  632. );
  633. if (BufferSize && (ERROR_INSUFFICIENT_BUFFER == Error)) {
  634. BYTE* pWmiInstData = new BYTE[BufferSize];
  635. if (pWmiInstData) {
  636. Error = WmiQuerySingleInstance(hWmiBlock,
  637. DevInstId,
  638. &BufferSize,
  639. pWmiInstData
  640. );
  641. if (ERROR_SUCCESS == Error &&
  642. ((PWNODE_SINGLE_INSTANCE)pWmiInstData)->SizeDataBlock) {
  643. //
  644. // The buffer that is returned using the fine UNICODE_STRING format
  645. // where the first ULONG is the length of the string and the string
  646. // is NOT NULL terminated.
  647. //
  648. TCHAR FirmwareRevision[MAX_PATH];
  649. PTCHAR WmiBuffer = ((LPTSTR)(pWmiInstData + ((PWNODE_SINGLE_INSTANCE)pWmiInstData)->DataBlockOffset));
  650. ZeroMemory(FirmwareRevision, MAX_PATH);
  651. ULONG Len = *WmiBuffer++;
  652. memcpy(FirmwareRevision, WmiBuffer, Len);
  653. ZeroMemory(&lv, sizeof(LVITEM));
  654. lv.mask = LVIF_TEXT;
  655. lv.iItem = 0;
  656. lv.pszText = FirmwareRevision;
  657. ListView_InsertItem(m_hwndDetailsList, &lv);
  658. ListView_SetItemState(m_hwndDetailsList, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  659. }
  660. delete [] pWmiInstData;
  661. }
  662. }
  663. WmiCloseBlock(hWmiBlock);
  664. }
  665. }
  666. void
  667. CDeviceDetailsPage::DisplayCurrentPowerState(
  668. VOID
  669. )
  670. {
  671. CM_POWER_DATA CmPowerData;
  672. ULONG ulSize;
  673. INT PowerStringId;
  674. LVITEM lv;
  675. String stringCurrentPowerState;
  676. ulSize = sizeof(CmPowerData);
  677. if (m_pDevice->m_pMachine->CmGetRegistryProperty(m_pDevice->GetDevNode(),
  678. CM_DRP_DEVICE_POWER_DATA,
  679. &CmPowerData,
  680. &ulSize
  681. ) == CR_SUCCESS) {
  682. PowerStringId = IDS_POWERSTATE_UNSPECIFIED + CmPowerData.PD_MostRecentPowerState;
  683. if (CmPowerData.PD_MostRecentPowerState > PowerDeviceD3) {
  684. PowerStringId = IDS_POWERSTATE_UNSPECIFIED;
  685. }
  686. stringCurrentPowerState.LoadString(g_hInstance, PowerStringId);
  687. ZeroMemory(&lv, sizeof(LVITEM));
  688. lv.mask = LVIF_TEXT;
  689. lv.iItem = 0;
  690. lv.pszText = (LPTSTR)stringCurrentPowerState;
  691. ListView_InsertItem(m_hwndDetailsList, &lv);
  692. ListView_SetItemState(m_hwndDetailsList, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  693. }
  694. }
  695. void
  696. CDeviceDetailsPage::DisplayPowerStateMappings(
  697. VOID
  698. )
  699. {
  700. CM_POWER_DATA CmPowerData;
  701. ULONG ulSize;
  702. LVITEM lv;
  703. INT PowerStringId;
  704. String stringPowerStateMapping;
  705. String stringPowerState;
  706. ulSize = sizeof(CmPowerData);
  707. if (m_pDevice->m_pMachine->CmGetRegistryProperty(m_pDevice->GetDevNode(),
  708. CM_DRP_DEVICE_POWER_DATA,
  709. &CmPowerData,
  710. &ulSize
  711. ) == CR_SUCCESS) {
  712. for (int i=PowerSystemWorking; i<=PowerSystemShutdown; i++) {
  713. stringPowerStateMapping.Format(TEXT("S%d -> "), (i-1));
  714. PowerStringId = IDS_POWERSTATE_UNSPECIFIED + CmPowerData.PD_PowerStateMapping[i];
  715. if (CmPowerData.PD_PowerStateMapping[i] > PowerDeviceD3) {
  716. PowerStringId = IDS_POWERSTATE_UNSPECIFIED;
  717. }
  718. stringPowerState.LoadString(g_hInstance, PowerStringId);
  719. stringPowerStateMapping+=stringPowerState;
  720. ZeroMemory(&lv, sizeof(LVITEM));
  721. lv.mask = LVIF_TEXT;
  722. lv.iItem = ListView_GetItemCount(m_hwndDetailsList);
  723. lv.pszText = (LPTSTR)stringPowerStateMapping;
  724. ListView_InsertItem(m_hwndDetailsList, &lv);
  725. }
  726. ListView_SetItemState(m_hwndDetailsList, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  727. }
  728. }
  729. void
  730. CDeviceDetailsPage::DisplayClassFilters(
  731. DWORD ClassFilter
  732. )
  733. {
  734. HKEY hKey;
  735. ULONG BufferLen;
  736. DWORD regType;
  737. LVITEM lv;
  738. GUID ClassGuid;
  739. m_pDevice->ClassGuid(ClassGuid);
  740. //
  741. // Open Classes registry key
  742. //
  743. hKey = m_pDevice->m_pMachine->DiOpenClassRegKey(&ClassGuid, KEY_READ, DIOCR_INSTALLER);
  744. if (INVALID_HANDLE_VALUE != hKey) {
  745. CSafeRegistry regClass(hKey);
  746. //
  747. // Determine how much space we need.
  748. //
  749. BufferLen = 0;
  750. regClass.GetValue((ClassFilter == DETAILS_CLASSLOWERFILTERS)
  751. ? REGSTR_VAL_LOWERFILTERS
  752. : REGSTR_VAL_UPPERFILTERS,
  753. &regType,
  754. NULL,
  755. &BufferLen);
  756. if (BufferLen != 0) {
  757. PBYTE Buffer = new BYTE[BufferLen + (2 * sizeof(TCHAR))];
  758. if (Buffer) {
  759. ZeroMemory(Buffer, BufferLen + (2 * sizeof(TCHAR)));
  760. if (regClass.GetValue((ClassFilter == DETAILS_CLASSLOWERFILTERS)
  761. ? REGSTR_VAL_LOWERFILTERS
  762. : REGSTR_VAL_UPPERFILTERS,
  763. &regType,
  764. (PBYTE)Buffer,
  765. &BufferLen)) {
  766. ZeroMemory(&lv, sizeof(LVITEM));
  767. lv.mask = LVIF_TEXT;
  768. lv.iItem = 0;
  769. for (PTSTR SingleItem = (PTSTR)Buffer; *SingleItem; SingleItem += (lstrlen(SingleItem) + 1)) {
  770. lv.pszText = SingleItem;
  771. ListView_InsertItem(m_hwndDetailsList, &lv);
  772. lv.iItem++;
  773. }
  774. ListView_SetItemState(m_hwndDetailsList, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  775. }
  776. delete [] Buffer;
  777. }
  778. }
  779. }
  780. }