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.

2289 lines
67 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997-1999.
  5. //
  6. // File: U T I L. C P P
  7. //
  8. // Contents: Utility functions shared within lanui
  9. //
  10. //
  11. //----------------------------------------------------------------------------
  12. #include "pch.h"
  13. #pragma hdrstop
  14. #include "resource.h"
  15. #include "ncreg.h"
  16. #include "ncnetcon.h"
  17. #include "ncnetcfg.h"
  18. #include "ncsetup.h"
  19. #include "lanui.h"
  20. #include "util.h"
  21. #include "chklist.h"
  22. #include "lanuiobj.h"
  23. #include "ncui.h"
  24. #include "ndispnp.h"
  25. #include "ncperms.h"
  26. #include "ncmisc.h"
  27. #include "wzcsapi.h"
  28. #include <raseapif.h>
  29. #include <raserror.h>
  30. #include "connutil.h"
  31. #define INITGUID
  32. #include "ncxclsid.h"
  33. #undef INITGUID
  34. extern const WCHAR c_szBiNdisAtm[];
  35. extern const WCHAR c_szDevice[];
  36. extern const WCHAR c_szInfId_MS_TCPIP[];
  37. //+---------------------------------------------------------------------------
  38. //
  39. // Function Name: HrInitCheckboxListView
  40. //
  41. // Purpose: Initialize the list view for checkboxes.
  42. //
  43. // Arguments:
  44. // hwndList[in]: Handle of the list view
  45. // philStateIcons[out]: Image list for the list view
  46. // pcild [in,optional] Image list data, created if necessary
  47. //
  48. // Returns: HRESULT, Error code.
  49. //
  50. // Notes:
  51. //
  52. HRESULT HrInitCheckboxListView(HWND hwndList, HIMAGELIST* philStateIcons, SP_CLASSIMAGELIST_DATA* pcild)
  53. {
  54. HRESULT hr = S_OK;
  55. RECT rc;
  56. LVCOLUMN lvc = {0};
  57. HWND hwndHeader;
  58. // Create small image lists
  59. //
  60. if(NULL == pcild)
  61. {
  62. pcild = new SP_CLASSIMAGELIST_DATA;
  63. if(pcild)
  64. {
  65. hr = HrSetupDiGetClassImageList(pcild);
  66. if (SUCCEEDED(hr))
  67. {
  68. AssertSz(pcild->ImageList, "No class image list data!");
  69. // Save off image list data for use later
  70. ::SetWindowLongPtr(GetParent(hwndList), GWLP_USERDATA,
  71. reinterpret_cast<LONG_PTR>(pcild));
  72. }
  73. else
  74. {
  75. TraceError("HrSetupDiGetClassImageList returns failure", hr);
  76. hr = S_OK;
  77. // delete this if we couldn't get the structure
  78. delete pcild;
  79. ::SetWindowLongPtr(GetParent(hwndList), GWLP_USERDATA, 0);
  80. }
  81. }
  82. else
  83. {
  84. hr = E_OUTOFMEMORY;
  85. }
  86. }
  87. if(SUCCEEDED(hr))
  88. {
  89. ListView_SetImageList(hwndList, pcild->ImageList, LVSIL_SMALL);
  90. // Set the shared image lists bit so the caller can destroy the class
  91. // image lists itself
  92. //
  93. DWORD dwStyle = GetWindowLong(hwndList, GWL_STYLE);
  94. SetWindowLong(hwndList, GWL_STYLE, (dwStyle | LVS_SHAREIMAGELISTS));
  95. // Create state image lists
  96. *philStateIcons = ImageList_LoadBitmapAndMirror(
  97. _Module.GetResourceInstance(),
  98. MAKEINTRESOURCE(IDB_CHECKSTATE),
  99. 16,
  100. 0,
  101. PALETTEINDEX(6));
  102. ListView_SetImageList(hwndList, *philStateIcons, LVSIL_STATE);
  103. // First determine if we have already added a column before
  104. // adding one.
  105. //
  106. hwndHeader = ListView_GetHeader( hwndList );
  107. Assert( hwndHeader );
  108. if ( (!hwndHeader) ||
  109. (Header_GetItemCount(hwndHeader) == 0) )
  110. {
  111. GetClientRect(hwndList, &rc);
  112. lvc.mask = LVCF_FMT | LVCF_WIDTH;
  113. lvc.fmt = LVCFMT_LEFT;
  114. lvc.cx = rc.right;
  115. // $REVIEW(tongl 12\22\97): Fix for bug#127472
  116. // lvc.cx = rc.right - GetSystemMetrics(SM_CXVSCROLL);
  117. ListView_InsertColumn(hwndList, 0, &lvc);
  118. }
  119. }
  120. return hr;
  121. }
  122. //+---------------------------------------------------------------------------
  123. //
  124. // Function Name: HrInitListView
  125. //
  126. // Purpose: Initialize the list view.
  127. // Iterate through all installed clients, services and protocols,
  128. // insert into the list view with the correct binding state with
  129. // the adapter used in this connection.
  130. //
  131. // Arguments:
  132. // hwndList[in]: Handle of the list view
  133. // pnc[in]: The writable INetcfg pointer
  134. // pnccAdapter[in]: The INetcfgComponent pointer to the adapter used in this connection
  135. //
  136. // Returns: HRESULT, Error code.
  137. //
  138. // Notes:
  139. //
  140. HRESULT HrInitListView(HWND hwndList,
  141. INetCfg* pnc,
  142. INetCfgComponent * pnccAdapter,
  143. ListBPObj * plistBindingPaths,
  144. HIMAGELIST* philStateIcons)
  145. {
  146. HRESULT hr = S_OK;
  147. SP_CLASSIMAGELIST_DATA *pcild;
  148. Assert(hwndList);
  149. Assert(pnc);
  150. Assert(pnccAdapter);
  151. Assert(plistBindingPaths);
  152. Assert(philStateIcons);
  153. pcild = (SP_CLASSIMAGELIST_DATA *)::GetWindowLongPtr(::GetParent(hwndList),
  154. GWLP_USERDATA);
  155. HrInitCheckboxListView(hwndList, philStateIcons, pcild);
  156. hr = HrRefreshAll(hwndList, pnc, pnccAdapter, plistBindingPaths);
  157. if (SUCCEEDED(hr))
  158. {
  159. // Selete the first item
  160. ListView_SetItemState(hwndList, 0, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
  161. }
  162. TraceError("HrInitListView", hr);
  163. return hr;
  164. }
  165. //+---------------------------------------------------------------------------
  166. //
  167. // Function: UninitListView
  168. //
  169. // Purpose: Uninitializes the common component list view
  170. //
  171. // Arguments:
  172. // hwndList [in] HWND of listview
  173. //
  174. // Returns: Nothing
  175. //
  176. // Author: danielwe 2 Feb 1998
  177. //
  178. // Notes:
  179. //
  180. VOID UninitListView(HWND hwndList)
  181. {
  182. SP_CLASSIMAGELIST_DATA * pcild;
  183. Assert(hwndList);
  184. // delete existing items in the list view
  185. ListView_DeleteAllItems( hwndList );
  186. pcild = reinterpret_cast<SP_CLASSIMAGELIST_DATA *>(
  187. ::GetWindowLongPtr(GetParent(hwndList), GWLP_USERDATA));
  188. if (pcild)
  189. {
  190. // Destroy the class image list data
  191. (VOID) HrSetupDiDestroyClassImageList(pcild);
  192. delete pcild;
  193. }
  194. }
  195. //+---------------------------------------------------------------------------
  196. //
  197. // Function Name: HrInsertComponent
  198. //
  199. // Purpose: Insert all installed, non-hidden and bindable components
  200. // of a class to the list view
  201. //
  202. // Arguments:
  203. //
  204. // Returns: HRESULT, Error code.
  205. //
  206. // Notes:
  207. //
  208. HRESULT HrInsertComponent(
  209. IN HWND hwndList,
  210. IN const GUID* pGuidDevClass,
  211. IN INetCfgComponent *pncc,
  212. IN INetCfgComponent *pnccAdapter,
  213. IN DWORD dwFlags,
  214. IN ListBPObj * plistBindingPaths,
  215. IN OUT INT* pnPos)
  216. {
  217. HRESULT hr = S_OK;
  218. SP_CLASSIMAGELIST_DATA * pcild;
  219. Assert(hwndList);
  220. Assert(pGuidDevClass);
  221. pcild = reinterpret_cast<SP_CLASSIMAGELIST_DATA *>
  222. (::GetWindowLongPtr(GetParent(hwndList), GWLP_USERDATA));
  223. // We should only list components that are bindable to the adapter
  224. // Note: bindable means binding path exists, either enabled or disabled
  225. INetCfgComponentBindings * pnccb;
  226. hr = pncc->QueryInterface(IID_INetCfgComponentBindings, (LPVOID *)&pnccb);
  227. if (S_OK == hr)
  228. {
  229. // Do this only for protocols !!
  230. // $REVIEW(TongL 3/28/99), I included the 2 reasons on why we only filter
  231. // non-bindable protocols below, in case someone ask again ..
  232. // 1) (Originally per BillBe) The add component dialog filters out non-bindable
  233. // protocols by matching binding interface names from INF, it can not easily do
  234. // so for services/clients which could be several layers above the adapter.
  235. // The property UI needs to be consistent because it's confusing to users if
  236. // we allow them to add a component from a connection but don't let that
  237. // component show up in the same connection's property UI.
  238. // 2) (Per ShaunCo) After talking with Bill, we show protocols yet not clients
  239. // services not to be consistent with the add component dialog, but because
  240. // you cannot predict based on bindings alone whether a client or service will
  241. // end up being involved with an adapter. example: i can install a service
  242. // that doesn't bind and uses winsock to send data. It may be able to be configured
  243. // differently for each adapter (and hence would need to show up for each adapter's
  244. // connection) but you can't tell by any means whether its going to be invovled with
  245. // that adapter or not. -- So you have to show all services and clients.
  246. // A protocol, on the other hand, binds with adapters by definition. So, we know
  247. // for the protocol's which will use an adapter and which won't.
  248. // Special case: do now show filter components unless it is bindable,
  249. // Raid 358865
  250. DWORD dwFlags;
  251. hr = pncc->GetCharacteristics(&dwFlags);
  252. if ((SUCCEEDED(hr) && (dwFlags & NCF_FILTER)) ||
  253. (GUID_DEVCLASS_NETTRANS == *pGuidDevClass))
  254. {
  255. // $REVIEW(ShaunCo 3/26/99)
  256. // To see if the protocol is involved with the adapter, check the
  257. // owner of each bindpath and see if its equal to the component
  258. // we are considering inserting into the list view.
  259. // Note the special case for ms_nwnb. It won't be involved in a
  260. // direct binding to the adapter because it has NCF_DONTEXPOSELOWER,
  261. // so we can't use IsBindableTo.
  262. BOOL fProtocolIsInvolved = FALSE;
  263. ListBPObj_ITER iter;
  264. for (iter = plistBindingPaths->begin();
  265. (iter != plistBindingPaths->end() && !fProtocolIsInvolved);
  266. iter++)
  267. {
  268. INetCfgComponent* pScan;
  269. hr = (*iter)->m_pncbp->GetOwner(&pScan);
  270. if (S_OK == hr)
  271. {
  272. if (pScan == pncc)
  273. {
  274. fProtocolIsInvolved = TRUE;
  275. }
  276. ReleaseObj(pScan);
  277. }
  278. }
  279. if (!fProtocolIsInvolved)
  280. {
  281. // Don't insert this protocol because it is not involved
  282. // in the binding set for the adpater.
  283. //
  284. hr = S_FALSE;
  285. }
  286. }
  287. if (S_OK == hr) // bindable, add to list
  288. {
  289. PWSTR pszwName;
  290. hr = pncc->GetDisplayName(&pszwName);
  291. if (SUCCEEDED(hr))
  292. {
  293. PWSTR pszwDesc;
  294. // Special Case:
  295. // If this is a Domain Controller,
  296. // disable tcpip removal, Raid 263754
  297. //
  298. if (GUID_DEVCLASS_NETTRANS == *pGuidDevClass)
  299. {
  300. PWSTR pszwId;
  301. hr = pncc->GetId (&pszwId);
  302. if (SUCCEEDED(hr))
  303. {
  304. if (FEqualComponentId (c_szInfId_MS_TCPIP, pszwId))
  305. {
  306. NT_PRODUCT_TYPE pt;
  307. RtlGetNtProductType (&pt);
  308. if (NtProductLanManNt == pt)
  309. {
  310. dwFlags |= NCF_NOT_USER_REMOVABLE;
  311. }
  312. }
  313. CoTaskMemFree (pszwId);
  314. }
  315. }
  316. hr = pncc->GetHelpText(&pszwDesc);
  317. if (SUCCEEDED(hr))
  318. {
  319. LV_ITEM lvi = {0};
  320. lvi.mask = LVIF_TEXT | LVIF_IMAGE |
  321. LVIF_STATE | LVIF_PARAM;
  322. // Get the component's class image list index
  323. if (pcild)
  324. {
  325. INT nIndex = 0;
  326. (VOID) HrSetupDiGetClassImageIndex(pcild,
  327. pGuidDevClass, &nIndex);
  328. lvi.iImage = nIndex;
  329. }
  330. lvi.iItem = *pnPos;
  331. NET_ITEM_DATA * pnid = new NET_ITEM_DATA;
  332. if (pnid)
  333. {
  334. pnid->szwName = SzDupSz(pszwName);
  335. pnid->szwDesc = SzDupSz(pszwDesc);
  336. pnid->dwFlags = dwFlags;
  337. AddRefObj(pnid->pncc = pncc);
  338. pnid->pCompObj = new CComponentObj(pncc);
  339. if (pnid->pCompObj)
  340. {
  341. hr = pnid->pCompObj->HrInit(plistBindingPaths);
  342. if FAILED(hr)
  343. {
  344. TraceError("HrInsertComponent: failed to initialize a component object", hr);
  345. hr = S_OK;
  346. }
  347. }
  348. lvi.lParam = reinterpret_cast<LPARAM>(pnid);
  349. lvi.pszText = pnid->szwName;
  350. // We will refresh the state of the whole list in the end
  351. UINT iChkIndex = SELS_CHECKED;
  352. lvi.state = INDEXTOSTATEIMAGEMASK( iChkIndex );
  353. INT ret;
  354. ret = ListView_InsertItem(hwndList, &lvi);
  355. (*pnPos)++;
  356. CoTaskMemFree(pszwDesc);
  357. }
  358. }
  359. CoTaskMemFree(pszwName);
  360. }
  361. }
  362. ReleaseObj(pnccb);
  363. }
  364. TraceError("HrInsertComponent", S_FALSE == hr ? S_OK : hr);
  365. return hr;
  366. }
  367. //+---------------------------------------------------------------------------
  368. //
  369. // Function Name: HrInsertComponents
  370. //
  371. // Purpose: Insert installed and non-hidden components
  372. // of a class to the list view
  373. //
  374. // Arguments:
  375. //
  376. // Returns: HRESULT, Error code.
  377. //
  378. // Notes:
  379. //
  380. HRESULT HrInsertComponents(
  381. IN HWND hwndList,
  382. IN INetCfg* pnc,
  383. IN const GUID* pGuidDevClass,
  384. IN INetCfgComponent* pnccAdapter,
  385. IN ListBPObj* plistBindingPaths,
  386. IN OUT INT* pnPos)
  387. {
  388. Assert(hwndList);
  389. HRESULT hr = S_OK;
  390. CIterNetCfgComponent iterComp (pnc, pGuidDevClass);
  391. INetCfgComponent* pncc;
  392. while (SUCCEEDED(hr) && S_OK == (hr = iterComp.HrNext(&pncc)))
  393. {
  394. DWORD dwFlags;
  395. hr = pncc->GetCharacteristics(&dwFlags);
  396. // Make sure it's not hidden
  397. if (SUCCEEDED(hr) && !(dwFlags & NCF_HIDDEN))
  398. {
  399. // This will AddRef pncc so the release below can still be
  400. // there
  401. hr = HrInsertComponent(
  402. hwndList, pGuidDevClass, pncc, pnccAdapter,
  403. dwFlags, plistBindingPaths, pnPos);
  404. }
  405. ReleaseObj(pncc);
  406. }
  407. if (SUCCEEDED(hr))
  408. {
  409. // Get rid of FALSE returns
  410. hr = S_OK;
  411. }
  412. TraceError("HrInsertComponents", hr);
  413. return hr;
  414. }
  415. //+---------------------------------------------------------------------------
  416. //
  417. // Function Name: HrRefreshListView
  418. //
  419. // Purpose: Iterate through all installed clients, services and protocols,
  420. // insert into the list view with the correct binding state with
  421. // the adapter used in this connection.
  422. //
  423. // Arguments:
  424. // hwndList[in]: Handle of the list view
  425. // pnc[in]: The writable INetcfg pointer
  426. // pnccAdapter[in]: The INetcfgComponent pointer to the adapter used in this connection
  427. //
  428. // Returns: HRESULT, Error code.
  429. //
  430. // Notes:
  431. //
  432. HRESULT HrRefreshListView(HWND hwndList,
  433. INetCfg* pnc,
  434. INetCfgComponent * pnccAdapter,
  435. ListBPObj * plistBindingPaths)
  436. {
  437. HRESULT hr;
  438. INT nPos = 0;
  439. Assert(hwndList);
  440. // Clients
  441. hr = HrInsertComponents(hwndList, pnc,
  442. &GUID_DEVCLASS_NETCLIENT, pnccAdapter, plistBindingPaths,
  443. &nPos);
  444. if (SUCCEEDED(hr))
  445. {
  446. // Services
  447. hr = HrInsertComponents(hwndList, pnc,
  448. &GUID_DEVCLASS_NETSERVICE, pnccAdapter, plistBindingPaths,
  449. &nPos);
  450. }
  451. if (SUCCEEDED(hr))
  452. {
  453. // Protocols
  454. hr = HrInsertComponents(hwndList, pnc,
  455. &GUID_DEVCLASS_NETTRANS, pnccAdapter, plistBindingPaths,
  456. &nPos);
  457. }
  458. // Now refresh the state of all items
  459. if (SUCCEEDED(hr))
  460. {
  461. hr = HrRefreshCheckListState(hwndList, NULL);
  462. }
  463. TraceError("HrRefreshListView", hr);
  464. return hr;
  465. }
  466. //+---------------------------------------------------------------------------
  467. //
  468. // Function Name: HrLvGetSelectedComponent
  469. //
  470. // Purpose: Return pointer to the INetCfgComponent of the selected
  471. // client, service or protocol
  472. //
  473. // Returns: S_OK if successful,
  474. // S_FALSE if list view Macros returns failure
  475. // (specific error not available).
  476. //
  477. // Notes:
  478. //
  479. HRESULT HrLvGetSelectedComponent(HWND hwndList,
  480. INetCfgComponent ** ppncc)
  481. {
  482. HRESULT hr = S_FALSE;
  483. Assert(hwndList);
  484. *ppncc = NULL;
  485. INT iSelected = ListView_GetNextItem(hwndList, -1, LVNI_SELECTED);
  486. if (iSelected != -1)
  487. {
  488. LV_ITEM lvItem = {0};
  489. lvItem.mask = LVIF_PARAM;
  490. lvItem.iItem = iSelected;
  491. if (ListView_GetItem(hwndList, &lvItem))
  492. {
  493. NET_ITEM_DATA * pnid;
  494. pnid = reinterpret_cast<NET_ITEM_DATA *>(lvItem.lParam);
  495. if (pnid)
  496. {
  497. hr = S_OK;
  498. pnid->pncc->AddRef();
  499. *ppncc = pnid->pncc;
  500. }
  501. }
  502. }
  503. TraceError("HrLvGetSelectedComponent", S_FALSE == hr ? S_OK : hr);
  504. return hr;
  505. }
  506. //+---------------------------------------------------------------------------
  507. //
  508. // Function: LvDeleteItem
  509. //
  510. // Purpose: Handles deletion of the given item from the listview. Should
  511. // be called in response to the LVN_DELETEITEM notification.
  512. //
  513. // Arguments:
  514. // hwndList [in] Listview handle
  515. // iItem [in] item that was deleted
  516. //
  517. // Returns: Nothing
  518. //
  519. // Author: danielwe 3 Nov 1997
  520. //
  521. // Notes:
  522. //
  523. VOID LvDeleteItem(HWND hwndList, int iItem)
  524. {
  525. LV_ITEM lvi = {0};
  526. NET_ITEM_DATA * pnid;
  527. lvi.mask = LVIF_PARAM;
  528. lvi.iItem = iItem;
  529. ListView_GetItem(hwndList, &lvi);
  530. pnid = reinterpret_cast<NET_ITEM_DATA*>(lvi.lParam);
  531. AssertSz(pnid, "No item data!?!?");
  532. ReleaseObj(pnid->pncc);
  533. delete(pnid->pCompObj);
  534. delete pnid->szwName;
  535. delete pnid->szwDesc;
  536. delete pnid;
  537. }
  538. //+---------------------------------------------------------------------------
  539. //
  540. // Function Name: OnListClick
  541. //
  542. // Purpose:
  543. //
  544. // Returns:
  545. //
  546. INT OnListClick(HWND hwndList,
  547. HWND hwndParent,
  548. INetCfg *pnc,
  549. IUnknown *punk,
  550. INetCfgComponent *pnccAdapter,
  551. ListBPObj * plistBindingPaths,
  552. BOOL fDoubleClk,
  553. BOOL fReadOnly)
  554. {
  555. INT iItem;
  556. DWORD dwpts;
  557. LV_HITTESTINFO lvhti;
  558. // we have the location
  559. dwpts = GetMessagePos();
  560. lvhti.pt.x = LOWORD( dwpts );
  561. lvhti.pt.y = HIWORD( dwpts );
  562. MapWindowPoints(NULL , hwndList , (LPPOINT) &(lvhti.pt) , 1);
  563. // get currently selected item
  564. iItem = ListView_HitTest( hwndList, &lvhti );
  565. // if no selection, or click not on state return false
  566. if (-1 != iItem)
  567. {
  568. // set the current selection
  569. ListView_SetItemState(hwndList, iItem, LVIS_SELECTED, LVIS_SELECTED);
  570. if ( fDoubleClk )
  571. {
  572. if ((LVHT_ONITEMICON != (LVHT_ONITEMICON & lvhti.flags)) &&
  573. (LVHT_ONITEMLABEL != (LVHT_ONITEMLABEL & lvhti.flags)) &&
  574. (LVHT_ONITEMSTATEICON != (LVHT_ONITEMSTATEICON & lvhti.flags)) )
  575. {
  576. iItem = -1;
  577. }
  578. }
  579. else // single click
  580. {
  581. if (LVHT_ONITEMSTATEICON != (LVHT_ONITEMSTATEICON & lvhti.flags))
  582. {
  583. iItem = -1;
  584. }
  585. }
  586. if (-1 != iItem)
  587. {
  588. HRESULT hr = S_OK;
  589. if ((fDoubleClk) &&
  590. (LVHT_ONITEMSTATEICON != (LVHT_ONITEMSTATEICON & lvhti.flags)))
  591. {
  592. // only raise properties if the selected component has UI and
  593. // is not disabled, and the current user has the permission to
  594. // change properties.
  595. LV_ITEM lvItem;
  596. lvItem.mask = LVIF_PARAM;
  597. lvItem.iItem = iItem;
  598. lvItem.iSubItem = 0;
  599. if (ListView_GetItem(hwndList, &lvItem))
  600. {
  601. NET_ITEM_DATA * pnid = NULL;
  602. pnid = reinterpret_cast<NET_ITEM_DATA *>(lvItem.lParam);
  603. if (pnid)
  604. {
  605. // is this component checked ?
  606. if ((UNCHECKED != (pnid->pCompObj)->GetChkState()) &&
  607. (pnid->dwFlags & NCF_HAS_UI) &&
  608. FHasPermission(NCPERM_LanChangeProperties))
  609. {
  610. BOOL fShowProperties = TRUE;
  611. if (FIsUserNetworkConfigOps())
  612. {
  613. LPWSTR pszwId;
  614. hr = pnid->pncc->GetId(&pszwId);
  615. if (SUCCEEDED(hr))
  616. {
  617. if (pszwId)
  618. {
  619. if (!FEqualComponentId (c_szInfId_MS_TCPIP, pszwId))
  620. {
  621. fShowProperties = FALSE;
  622. }
  623. else if (FEqualComponentId (c_szInfId_MS_TCPIP, pszwId))
  624. {
  625. fShowProperties = TRUE;
  626. }
  627. CoTaskMemFree(pszwId);
  628. }
  629. else
  630. {
  631. fShowProperties = FALSE;
  632. }
  633. }
  634. else
  635. {
  636. fShowProperties = FALSE;
  637. }
  638. }
  639. if (fShowProperties)
  640. {
  641. hr = HrLvProperties(hwndList, hwndParent, pnc, punk,
  642. pnccAdapter, plistBindingPaths, NULL);
  643. }
  644. }
  645. }
  646. }
  647. }
  648. else
  649. {
  650. if (!fReadOnly)
  651. {
  652. hr = HrToggleLVItemState(hwndList, plistBindingPaths, iItem);
  653. }
  654. }
  655. if FAILED(hr)
  656. iItem = -1;
  657. }
  658. }
  659. return( iItem );
  660. }
  661. //+---------------------------------------------------------------------------
  662. //
  663. // Function Name: HrToggleLVItemState
  664. //
  665. // Purpose:
  666. //
  667. // Returns:
  668. //
  669. HRESULT HrToggleLVItemState(HWND hwndList,
  670. ListBPObj * plistBindingPaths,
  671. INT iItem)
  672. {
  673. HRESULT hr = S_OK;
  674. LV_ITEM lvItem;
  675. NET_ITEM_DATA * pnid;
  676. // we are interested in is the PARAM
  677. lvItem.iItem = iItem;
  678. lvItem.mask = LVIF_PARAM;
  679. lvItem.iSubItem = 0;
  680. ListView_GetItem( hwndList, &lvItem );
  681. // get the item
  682. pnid = (NET_ITEM_DATA *)lvItem.lParam;
  683. // If the binding checkbox is available, then allow the toggle.
  684. //
  685. if (!(pnid->dwFlags & NCF_FIXED_BINDING) &&
  686. FHasPermission(NCPERM_ChangeBindState))
  687. {
  688. if (pnid->pCompObj->GetChkState() == UNCHECKED) // toggle on
  689. {
  690. hr = pnid->pCompObj->HrCheck(plistBindingPaths);
  691. if SUCCEEDED(hr)
  692. {
  693. hr = HrRefreshCheckListState(hwndList, pnid->pCompObj);
  694. }
  695. // "Ding" if the state of this item is still unchecked
  696. if (pnid->pCompObj->GetChkState() == UNCHECKED)
  697. {
  698. #ifdef DBG
  699. TraceTag(ttidLanUi, "Why is this component still disabled ???");
  700. #endif
  701. }
  702. }
  703. else // toggle off
  704. {
  705. hr = pnid->pCompObj->HrUncheck(plistBindingPaths);
  706. if SUCCEEDED(hr)
  707. {
  708. hr = HrRefreshCheckListState(hwndList, pnid->pCompObj);
  709. }
  710. // "Ding" if the state of this item is not unchecked
  711. if (pnid->pCompObj->GetChkState() != UNCHECKED)
  712. {
  713. #ifdef DBG
  714. TraceTag(ttidLanUi, "Why is this component not disabled ???");
  715. #endif
  716. }
  717. }
  718. }
  719. TraceError("HrToggleLVItemState", hr);
  720. return hr;
  721. }
  722. //+---------------------------------------------------------------------------
  723. //
  724. // Function Name: OnListKeyDown
  725. //
  726. // Purpose:
  727. //
  728. // Returns:
  729. //
  730. INT OnListKeyDown(HWND hwndList, ListBPObj * plistBindingPaths, WORD wVKey)
  731. {
  732. INT iItem = -1;
  733. if ((VK_SPACE == wVKey) && (GetAsyncKeyState(VK_MENU)>=0))
  734. {
  735. iItem = ListView_GetNextItem(hwndList, -1, LVNI_FOCUSED | LVNI_SELECTED);
  736. // if no selection
  737. if (-1 != iItem)
  738. {
  739. HRESULT hr = S_OK;
  740. hr = HrToggleLVItemState(hwndList, plistBindingPaths, iItem);
  741. if FAILED(hr)
  742. iItem = -1;
  743. }
  744. }
  745. return( iItem );
  746. }
  747. //+---------------------------------------------------------------------------
  748. //
  749. // Function Name: LvSetButtons
  750. //
  751. // Purpose: Set the correct status of Add, Remove, Property buttons,
  752. // and the description text
  753. //
  754. // Returns:
  755. //
  756. VOID LvSetButtons(HWND hwndParent, HANDLES& h, BOOL fReadOnly, IUnknown * punk)
  757. {
  758. Assert(IsWindow(h.m_hList));
  759. Assert(IsWindow(h.m_hAdd));
  760. Assert(IsWindow(h.m_hRemove));
  761. Assert(IsWindow(h.m_hProperty));
  762. // enable Property button if valid and update description text
  763. INT iSelected = ListView_GetNextItem(h.m_hList, -1, LVNI_SELECTED);
  764. if (iSelected == -1) // Nothing selected or list empty
  765. {
  766. ::EnableWindow(h.m_hAdd, !fReadOnly && FHasPermission(NCPERM_AddRemoveComponents));
  767. if (!fReadOnly)
  768. {
  769. // if list is empty, set focus to the list view
  770. if (0 == ListView_GetItemCount(h.m_hList))
  771. {
  772. // remove the default on the remove button
  773. SendMessage(h.m_hRemove, BM_SETSTYLE, (WPARAM)BS_PUSHBUTTON, TRUE );
  774. // move focus to the Add button
  775. ::SetFocus(h.m_hAdd);
  776. }
  777. }
  778. ::EnableWindow(h.m_hRemove, FALSE);
  779. ::EnableWindow(h.m_hProperty, FALSE);
  780. if(h.m_hDescription)
  781. {
  782. ::SetWindowText(h.m_hDescription, c_szEmpty);
  783. }
  784. }
  785. else
  786. {
  787. // enable Add/Remove buttons
  788. ::EnableWindow(h.m_hAdd, !fReadOnly && FHasPermission(NCPERM_AddRemoveComponents));
  789. LV_ITEM lvItem;
  790. lvItem.mask = LVIF_PARAM;
  791. lvItem.iItem = iSelected;
  792. lvItem.iSubItem = 0;
  793. if (ListView_GetItem(h.m_hList, &lvItem))
  794. {
  795. NET_ITEM_DATA * pnid = NULL;
  796. pnid = reinterpret_cast<NET_ITEM_DATA *>(lvItem.lParam);
  797. if (pnid)
  798. {
  799. if (fReadOnly)
  800. {
  801. ::EnableWindow(h.m_hProperty, FALSE);
  802. ::EnableWindow(h.m_hRemove, FALSE);
  803. }
  804. else
  805. {
  806. // is this component checked ?
  807. if (UNCHECKED != (pnid->pCompObj)->GetChkState())
  808. {
  809. BOOL fHasPropertyUi = FALSE;
  810. HRESULT hr = S_OK;
  811. INetCfgComponent * pncc;
  812. LPWSTR pszwId;
  813. hr = HrLvGetSelectedComponent(h.m_hList, &pncc);
  814. if (S_OK == hr)
  815. {
  816. AssertSz(pncc, "No component selected?!?!");
  817. hr = pncc->RaisePropertyUi(hwndParent, NCRP_QUERY_PROPERTY_UI, punk);
  818. if (S_OK == hr)
  819. {
  820. fHasPropertyUi = TRUE;
  821. }
  822. ReleaseObj(pncc);
  823. }
  824. if (FIsUserNetworkConfigOps() && FHasPermission(NCPERM_LanChangeProperties))
  825. {
  826. hr = pncc->GetId(&pszwId);
  827. if (SUCCEEDED(hr))
  828. {
  829. if (pszwId && !FEqualComponentId (c_szInfId_MS_TCPIP, pszwId))
  830. {
  831. ::EnableWindow(h.m_hProperty, FALSE);
  832. }
  833. else if (pszwId && FEqualComponentId (c_szInfId_MS_TCPIP, pszwId) && fHasPropertyUi)
  834. {
  835. ::EnableWindow(h.m_hProperty, TRUE);
  836. }
  837. }
  838. }
  839. else
  840. {
  841. ::EnableWindow(h.m_hProperty,
  842. fHasPropertyUi &&
  843. FHasPermission(NCPERM_LanChangeProperties));
  844. }
  845. }
  846. else
  847. {
  848. ::EnableWindow(h.m_hProperty, FALSE);
  849. }
  850. // is this component user removable ?
  851. ::EnableWindow(h.m_hRemove,
  852. !(pnid->dwFlags & NCF_NOT_USER_REMOVABLE) &&
  853. FHasPermission(NCPERM_AddRemoveComponents));
  854. }
  855. // set description text
  856. if(h.m_hDescription)
  857. {
  858. ::SetWindowText(h.m_hDescription, (PCWSTR)pnid->szwDesc);
  859. }
  860. }
  861. // Set focus to the list (336050)
  862. SetFocus(h.m_hList);
  863. }
  864. }
  865. return;
  866. }
  867. //+---------------------------------------------------------------------------
  868. //
  869. // Function: HrLvRemove
  870. //
  871. // Purpose: Handles the pressing of the Remove button. Should be called
  872. // in responsed to the PSB_Remove message.
  873. //
  874. // Arguments:
  875. // hwndLV [in] Handle of listview
  876. // hwndParent [in] Handle of parent window
  877. // pnc [in] INetCfg being used
  878. // pnccAdapter [in] INetCfgComponent of adapter for the connection
  879. //
  880. // Returns: S_OK if success, Win32 or OLE error code otherwise
  881. //
  882. // Author: danielwe 3 Nov 1997
  883. //
  884. // Notes:
  885. //
  886. HRESULT HrLvRemove(HWND hwndLV, HWND hwndParent,
  887. INetCfg *pnc, INetCfgComponent *pnccAdapter,
  888. ListBPObj * plistBindingPaths)
  889. {
  890. HRESULT hr = S_OK;
  891. INetCfgComponent * pncc;
  892. hr = HrLvGetSelectedComponent(hwndLV, &pncc);
  893. if (S_OK == hr)
  894. {
  895. hr = HrQueryUserAndRemoveComponent(hwndParent, pnc, pncc);
  896. if (NETCFG_S_STILL_REFERENCED == hr)
  897. {
  898. hr = S_OK;
  899. }
  900. else
  901. {
  902. if (SUCCEEDED(hr))
  903. {
  904. HRESULT hrTmp = HrRefreshAll(hwndLV, pnc, pnccAdapter, plistBindingPaths);
  905. if (S_OK != hrTmp)
  906. hr = hrTmp;
  907. }
  908. }
  909. ReleaseObj(pncc);
  910. }
  911. else
  912. {
  913. TraceTag(ttidLanUi, "HrLvGetSelectedComponent did not get a valid selection.");
  914. }
  915. TraceError("HrLvRemove", hr);
  916. return hr;
  917. }
  918. //+---------------------------------------------------------------------------
  919. //
  920. // Function: HrLvAdd
  921. //
  922. // Purpose: Handles the pressing of the Add button. Should be called in
  923. // response to the PSB_Add message.
  924. //
  925. // Arguments:
  926. // hwndLV [in] Handle of listview
  927. // hwndParent [in] Handle of parent window
  928. // pnc [in] INetCfg being used
  929. // pnccAdapter [in] INetCfgComponent of adapter for the connection
  930. //
  931. // Returns: S_OK if success, Win32 or OLE error code otherwise
  932. //
  933. // Author: danielwe 3 Nov 1997
  934. //
  935. // Notes:
  936. //
  937. HRESULT HrLvAdd(HWND hwndLV, HWND hwndParent, INetCfg *pnc,
  938. INetCfgComponent *pnccAdapter,
  939. ListBPObj * plistBindingPaths)
  940. {
  941. HRESULT hr;
  942. CI_FILTER_INFO cfi;
  943. ZeroMemory(&cfi, sizeof(cfi));
  944. if (!pnccAdapter)
  945. {
  946. return E_INVALIDARG;
  947. }
  948. // We want to filter out any irrelvant protocols (i.e. protocols that
  949. // won't bind to this adapter) so we need to send in a filter info
  950. // struct with our information.
  951. cfi.eFilter = FC_LAN; // Apply lan specific filtering
  952. cfi.pIComp = pnccAdapter; // Filter against this adapter
  953. INetCfgComponentBindings* pnccb;
  954. hr = pnccAdapter->QueryInterface(IID_INetCfgComponentBindings,
  955. reinterpret_cast<LPVOID *>(&pnccb));
  956. if (SUCCEEDED(hr))
  957. {
  958. hr = pnccb->SupportsBindingInterface(NCF_UPPER, c_szBiNdisAtm);
  959. if (S_OK == hr)
  960. {
  961. cfi.eFilter = FC_ATM; // Apply lan specific filtering
  962. }
  963. ReleaseObj(pnccb);
  964. }
  965. hr = HrDisplayAddComponentDialog(hwndParent, pnc, &cfi);
  966. if ((S_OK == hr) || (NETCFG_S_REBOOT == hr))
  967. {
  968. HRESULT hrSave = hr;
  969. // Refresh the list to reflect changes
  970. hr = HrRefreshAll(hwndLV, pnc, pnccAdapter, plistBindingPaths);
  971. if (SUCCEEDED(hr))
  972. hr = hrSave;
  973. }
  974. else if (NETCFG_E_ACTIVE_RAS_CONNECTIONS == hr)
  975. {
  976. LvReportError(IDS_LANUI_REQUIRE_DISCONNECT_ADD, hwndParent, NULL, NULL);
  977. }
  978. else if (NETCFG_E_NEED_REBOOT == hr)
  979. {
  980. LvReportError(IDS_LANUI_REQUIRE_REBOOT_ADD, hwndParent, NULL, NULL);
  981. }
  982. else if (S_FALSE != hr)
  983. {
  984. PWSTR psz = NULL;
  985. if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  986. NULL,
  987. hr,
  988. LANG_NEUTRAL,
  989. (PWSTR)&psz,
  990. 0,
  991. NULL))
  992. {
  993. LvReportError(IDS_LANUI_GENERIC_ADD_ERROR, hwndParent, NULL, psz);
  994. GlobalFree(psz);
  995. }
  996. else
  997. {
  998. LvReportErrorHr(hr, IDS_LANUI_GENERIC_ADD_ERROR, hwndParent, NULL);
  999. }
  1000. }
  1001. TraceError("HrLvAdd", hr);
  1002. return hr;
  1003. }
  1004. //+---------------------------------------------------------------------------
  1005. //
  1006. // Function: LvReportError
  1007. //
  1008. // Purpose: Reports a generic error based on the information passed in
  1009. //
  1010. // Arguments:
  1011. // ids [in] IDS of the string to be used as the text of the
  1012. // message box
  1013. // hwnd [in] Parent HWND
  1014. // szDesc [in] Display name of component
  1015. // szText [in] [Optional] If supplied, provides additional string
  1016. // for replacement. Can be NULL.
  1017. //
  1018. // Returns: Nothing
  1019. //
  1020. // Author: danielwe 6 Jan 1998
  1021. //
  1022. // Notes:
  1023. //
  1024. VOID LvReportError(INT ids, HWND hwnd, PCWSTR szDesc, PCWSTR szText)
  1025. {
  1026. if (szDesc && szText)
  1027. {
  1028. NcMsgBox(_Module.GetResourceInstance(), hwnd,
  1029. IDS_LANUI_ERROR_CAPTION, ids,
  1030. MB_ICONSTOP | MB_OK, szDesc, szText);
  1031. }
  1032. else if (szDesc)
  1033. {
  1034. NcMsgBox(_Module.GetResourceInstance(), hwnd,
  1035. IDS_LANUI_ERROR_CAPTION, ids,
  1036. MB_ICONSTOP | MB_OK, szDesc);
  1037. }
  1038. else if (szText)
  1039. {
  1040. NcMsgBox(_Module.GetResourceInstance(), hwnd,
  1041. IDS_LANUI_ERROR_CAPTION, ids,
  1042. MB_ICONSTOP | MB_OK, szText);
  1043. }
  1044. else
  1045. {
  1046. NcMsgBox(_Module.GetResourceInstance(), hwnd,
  1047. IDS_LANUI_ERROR_CAPTION, ids,
  1048. MB_ICONSTOP | MB_OK);
  1049. }
  1050. }
  1051. //+---------------------------------------------------------------------------
  1052. //
  1053. // Function: LvReportErrorHr
  1054. //
  1055. // Purpose: Reports a generic error based on the information passed in
  1056. //
  1057. // Arguments:
  1058. // hr [in] HRESULT error value to use in reporting the error
  1059. // ids [in] IDS of the string to be used as the text of the
  1060. // message box
  1061. // hwnd [in] Parent HWND
  1062. // szDesc [in] Display name of component
  1063. //
  1064. // Returns: Nothing
  1065. //
  1066. // Author: danielwe 14 Nov 1997
  1067. //
  1068. // Notes:
  1069. //
  1070. VOID LvReportErrorHr(HRESULT hr, INT ids, HWND hwnd, PCWSTR szDesc)
  1071. {
  1072. WCHAR szText[32];
  1073. static const WCHAR c_szFmt[] = L"0x%08X";
  1074. wsprintfW(szText, c_szFmt, hr);
  1075. LvReportError(ids, hwnd, szDesc, szText);
  1076. }
  1077. //+---------------------------------------------------------------------------
  1078. //
  1079. // Function: HrLvProperties
  1080. //
  1081. // Purpose: Handles the pressing of the Add button. Should be called in
  1082. // response to the PSB_Properties message.
  1083. //
  1084. // Arguments:
  1085. // hwndLV [in] Handle of listview
  1086. // hwndParent [in] Handle of parent window
  1087. // pnc [in] INetCfg being used
  1088. // punk [in] IUnknown for interface to query context information
  1089. // bChanged [out] Boolean indicating if something changed.
  1090. //
  1091. // Returns: S_OK if success, Win32 or OLE error code otherwise
  1092. //
  1093. // Author: danielwe 3 Nov 1997
  1094. //
  1095. // Notes:
  1096. //
  1097. HRESULT HrLvProperties(HWND hwndLV, HWND hwndParent, INetCfg *pnc,
  1098. IUnknown *punk, INetCfgComponent *pnccAdapter,
  1099. ListBPObj * plistBindingPaths,
  1100. BOOL *bChanged)
  1101. {
  1102. HRESULT hr = S_OK;
  1103. INetCfgComponent * pncc;
  1104. if ( bChanged )
  1105. {
  1106. *bChanged = FALSE;
  1107. }
  1108. hr = HrLvGetSelectedComponent(hwndLV, &pncc);
  1109. if (S_OK == hr)
  1110. {
  1111. AssertSz(pncc, "No component selected?!?!");
  1112. hr = pncc->RaisePropertyUi(hwndParent, NCRP_SHOW_PROPERTY_UI, punk);
  1113. // if components have been added or removed, we may need
  1114. // to refresh the whole list
  1115. if (S_OK == hr)
  1116. {
  1117. TraceTag(ttidLanUi, "Refreshing component list needed because other components are added or removed.");
  1118. hr = HrRefreshAll(hwndLV, pnc, pnccAdapter, plistBindingPaths);
  1119. if ( bChanged )
  1120. {
  1121. *bChanged = TRUE;
  1122. }
  1123. }
  1124. ReleaseObj(pncc);
  1125. }
  1126. else
  1127. {
  1128. TraceTag(ttidLanUi, "HrLvGetSelectedComponent did not return a valid selection.");
  1129. }
  1130. if (SUCCEEDED(hr))
  1131. {
  1132. // Normalize error result
  1133. hr = S_OK;
  1134. }
  1135. TraceError("HrLvProperties", hr);
  1136. return hr;
  1137. }
  1138. //+---------------------------------------------------------------------------
  1139. //
  1140. // Function: HrRefreshAll
  1141. //
  1142. // Purpose: Rebuilds the collection of BindingPathObj and the list view
  1143. //
  1144. // Arguments:
  1145. // hwndList [in] Handle of listview
  1146. // pnc [in] INetCfg being used
  1147. // pnccAdapter [in] INetCfgComponent of the adapter in this connection
  1148. // plistBindingPaths [in/out] The collection of BindingPathObj
  1149. //
  1150. // Returns: S_OK if success, Win32 or OLE error code otherwise
  1151. //
  1152. // Author: tongl 23 Nov 1997
  1153. //
  1154. // Notes:
  1155. //
  1156. HRESULT HrRefreshAll(HWND hwndList,
  1157. INetCfg* pnc,
  1158. INetCfgComponent * pnccAdapter,
  1159. ListBPObj * plistBindingPaths)
  1160. {
  1161. HRESULT hr = S_OK;
  1162. ReleaseAll(hwndList, plistBindingPaths);
  1163. hr = HrRebuildBindingPathObjCollection( pnccAdapter,
  1164. plistBindingPaths);
  1165. if SUCCEEDED(hr)
  1166. {
  1167. // Set the correct state on the BindingPathObject list
  1168. hr = HrRefreshBindingPathObjCollectionState(plistBindingPaths);
  1169. if SUCCEEDED(hr)
  1170. {
  1171. // Now refresh the list to reflect changes
  1172. hr = HrRefreshListView(hwndList, pnc, pnccAdapter, plistBindingPaths);
  1173. }
  1174. }
  1175. // $REVIEW(tongl 12\16\97): added so we always have a selection.
  1176. // Caller of this function can reset selection if they need to.
  1177. if (SUCCEEDED(hr))
  1178. {
  1179. // Selete the first item
  1180. ListView_SetItemState(hwndList, 0, LVIS_SELECTED, LVIS_SELECTED);
  1181. }
  1182. TraceError("HrRefreshAll", hr);
  1183. return hr;
  1184. }
  1185. //+---------------------------------------------------------------------------
  1186. //
  1187. // Function: ReleaseAll
  1188. //
  1189. // Purpose: Releases the INetCfgComponent and INetCfgBindingPath objects
  1190. //
  1191. // Arguments:
  1192. // hwndList [in] Handle of listview
  1193. // plistBindingPaths [in/out] The collection of BindingPathObj
  1194. //
  1195. // Author: tongl 18 Mar, 1998
  1196. //
  1197. // Notes:
  1198. //
  1199. VOID ReleaseAll(HWND hwndList,
  1200. ListBPObj * plistBindingPaths)
  1201. {
  1202. // first, clean up any existing objects in the list
  1203. FreeCollectionAndItem(*plistBindingPaths);
  1204. // delete existing items in the list view
  1205. ListView_DeleteAllItems( hwndList );
  1206. }
  1207. //+---------------------------------------------------------------------------
  1208. //
  1209. // Function: FValidatePageContents
  1210. //
  1211. // Purpose: Check error conditions before LAN property or wizard page
  1212. // exits
  1213. //
  1214. // Arguments:
  1215. // hwndDlg [in] Handle of dialog
  1216. // hwndList [in] Handle of the list view
  1217. // pnc [in] INetCfg
  1218. // pnccAdapter [in] INetCfgComponent
  1219. // plistBindignPaths [in] List of binding paths to this adater
  1220. //
  1221. // Returns: TRUE if there is a possible error and user wants to fix
  1222. // it before leaving the page. FALSE if no error or user
  1223. // chooses to move on.
  1224. //
  1225. // Author: tongl 17 Sept 1998
  1226. //
  1227. // Notes:
  1228. //
  1229. BOOL FValidatePageContents( HWND hwndDlg,
  1230. HWND hwndList,
  1231. INetCfg * pnc,
  1232. INetCfgComponent * pnccAdapter,
  1233. ListBPObj * plistBindingPaths)
  1234. {
  1235. HRESULT hr = S_OK;
  1236. // 1) Check if any protocol is enabled on this adapter
  1237. BOOL fEnabledProtocolExists = FALSE;
  1238. CIterNetCfgComponent iterProt(pnc, &GUID_DEVCLASS_NETTRANS);
  1239. INetCfgComponent* pnccTrans;
  1240. while (SUCCEEDED(hr) && !fEnabledProtocolExists &&
  1241. S_OK == (hr = iterProt.HrNext(&pnccTrans)))
  1242. {
  1243. HRESULT hrTmp;
  1244. INetCfgComponentBindings * pnccb;
  1245. hrTmp = pnccTrans->QueryInterface (
  1246. IID_INetCfgComponentBindings, (LPVOID*)&pnccb);
  1247. if (S_OK == hrTmp)
  1248. {
  1249. hrTmp = pnccb->IsBindableTo(pnccAdapter);
  1250. if (S_OK == hrTmp)
  1251. {
  1252. fEnabledProtocolExists = TRUE;
  1253. }
  1254. ReleaseObj(pnccb);
  1255. }
  1256. ReleaseObj(pnccTrans);
  1257. }
  1258. if (!fEnabledProtocolExists)
  1259. {
  1260. // warn the user
  1261. int nRet = NcMsgBox(
  1262. _Module.GetResourceInstance(),
  1263. hwndDlg,
  1264. IDS_LANUI_NOPROTOCOL_CAPTION,
  1265. IDS_LANUI_NOPROTOCOL,
  1266. MB_APPLMODAL|MB_ICONINFORMATION|MB_YESNO
  1267. );
  1268. if (nRet == IDYES)
  1269. {
  1270. return TRUE;
  1271. }
  1272. }
  1273. // 2) Check if any component on the display list is in an intent check state
  1274. // If so, it means these components are actually disabled and will not be
  1275. // displayed as checked the next time the UI is refreshed.
  1276. tstring strCompList = c_szEmpty;
  1277. // for each item in the list view
  1278. int nlvCount = ListView_GetItemCount(hwndList);
  1279. LV_ITEM lvItem;
  1280. for (int i=0; i< nlvCount; i++)
  1281. {
  1282. lvItem.iItem = i;
  1283. lvItem.iSubItem = 0;
  1284. lvItem.mask = LVIF_PARAM;
  1285. if (ListView_GetItem(hwndList, &lvItem))
  1286. {
  1287. NET_ITEM_DATA * pnid;
  1288. pnid = reinterpret_cast<NET_ITEM_DATA *>(lvItem.lParam);
  1289. if (pnid)
  1290. {
  1291. // get the component object associated with this item
  1292. CComponentObj * pCompObj = pnid->pCompObj;
  1293. if (pCompObj)
  1294. {
  1295. if (INTENT_CHECKED == pCompObj->m_CheckState)
  1296. {
  1297. PWSTR pszwName;
  1298. hr = pCompObj->m_pncc->GetDisplayName(&pszwName);
  1299. if (SUCCEEDED(hr))
  1300. {
  1301. if (!strCompList.empty())
  1302. strCompList += SzLoadIds(IDS_NEWLINE);
  1303. strCompList += pszwName;
  1304. delete pszwName;
  1305. }
  1306. }
  1307. }
  1308. }
  1309. }
  1310. }
  1311. if (!strCompList.empty())
  1312. {
  1313. // warn the user
  1314. int nRet = NcMsgBox(
  1315. _Module.GetResourceInstance(),
  1316. hwndDlg,
  1317. IDS_LANUI_ERROR_CAPTION,
  1318. IDS_LANUI_INTENTCHECK,
  1319. MB_APPLMODAL|MB_ICONINFORMATION|MB_YESNO,
  1320. strCompList.c_str());
  1321. if (nRet == IDNO)
  1322. {
  1323. // we have to only "undo" the dependent changes made...
  1324. for (int i=0; i< nlvCount; i++)
  1325. {
  1326. lvItem.iItem = i;
  1327. lvItem.iSubItem = 0;
  1328. lvItem.mask = LVIF_PARAM;
  1329. if (ListView_GetItem(hwndList, &lvItem))
  1330. {
  1331. NET_ITEM_DATA * pnid;
  1332. pnid = reinterpret_cast<NET_ITEM_DATA *>(lvItem.lParam);
  1333. if (pnid)
  1334. {
  1335. // get the component object associated with this item
  1336. CComponentObj * pCompObj = pnid->pCompObj;
  1337. // did the dependend state change ?
  1338. if ((pCompObj) &&
  1339. (pCompObj->GetDepStateChanged()))
  1340. {
  1341. // toggle the component state
  1342. hr = HrToggleLVItemState(hwndList,
  1343. plistBindingPaths,
  1344. i);
  1345. if (FAILED(hr))
  1346. {
  1347. TraceError("FValidatePageContents - HrToggleLVItemState", hr);
  1348. }
  1349. }
  1350. }
  1351. }
  1352. }
  1353. hr = HrRefreshAll(hwndList, pnc, pnccAdapter, plistBindingPaths);
  1354. return TRUE;
  1355. }
  1356. }
  1357. return FALSE;
  1358. }
  1359. //+---------------------------------------------------------------------------
  1360. //
  1361. // EAPOL related util functions
  1362. //
  1363. //+---------------------------------------------------------------------------
  1364. // Location of EAPOL Parameters Service
  1365. static WCHAR cszEapKeyEapolServiceParams[] = L"Software\\Microsoft\\EAPOL\\Parameters\\General" ;
  1366. static WCHAR cszInterfaceList[] = L"InterfaceList";
  1367. //+---------------------------------------------------------------------------
  1368. //
  1369. // Function called to retrieve the connection data for an interface for a
  1370. // specific EAP type and SSID (if any). Data is stored in the HKLM hive
  1371. //
  1372. // Input arguments:
  1373. // pwszGUID - GUID string for the interface
  1374. // dwEapTypeId - EAP type for which connection data is to be stored
  1375. // dwSizeOfSSID - Size of Special identifier if any for the EAP blob
  1376. // pwszSSID - Special identifier if any for the EAP blob
  1377. //
  1378. // Return values:
  1379. // pbConnInfo - pointer to binary EAP connection data blob
  1380. // dwInfoSize - pointer to size of EAP connection blob
  1381. //
  1382. //
  1383. HRESULT
  1384. HrElGetCustomAuthData (
  1385. IN WCHAR *pwszGUID,
  1386. IN DWORD dwEapTypeId,
  1387. IN DWORD dwSizeOfSSID,
  1388. IN BYTE *pbSSID,
  1389. IN OUT BYTE *pbConnInfo,
  1390. IN OUT DWORD *pdwInfoSize
  1391. )
  1392. {
  1393. DWORD dwRetCode = ERROR_SUCCESS;
  1394. HRESULT hr = S_OK;
  1395. do
  1396. {
  1397. dwRetCode = WZCEapolGetCustomAuthData (
  1398. NULL,
  1399. pwszGUID,
  1400. dwEapTypeId,
  1401. dwSizeOfSSID,
  1402. pbSSID,
  1403. pbConnInfo,
  1404. pdwInfoSize
  1405. );
  1406. if (dwRetCode == ERROR_BUFFER_TOO_SMALL)
  1407. {
  1408. hr = E_OUTOFMEMORY;
  1409. dwRetCode = ERROR_SUCCESS;
  1410. }
  1411. } while (FALSE);
  1412. if (dwRetCode != ERROR_SUCCESS)
  1413. {
  1414. hr = HRESULT_FROM_WIN32(dwRetCode);
  1415. }
  1416. return hr;
  1417. }
  1418. //+---------------------------------------------------------------------------
  1419. //
  1420. // Function called to set the connection data for an interface for a specific
  1421. // EAP type and SSID (if any). Data will be stored in the HKLM hive
  1422. //
  1423. // Input arguments:
  1424. // pwszGUID - pinter to GUID string for the interface
  1425. // dwEapTypeId - EAP type for which connection data is to be stored
  1426. // dwSizeOfSSID - Size of Special identifier if any for the EAP blob
  1427. // pwszSSID - Special identifier if any for the EAP blob
  1428. // pbConnInfo - pointer to binary EAP connection data blob
  1429. // dwInfoSize - Size of EAP connection blob
  1430. //
  1431. // Return values:
  1432. //
  1433. HRESULT
  1434. HrElSetCustomAuthData (
  1435. IN WCHAR *pwszGUID,
  1436. IN DWORD dwEapTypeId,
  1437. IN DWORD dwSizeOfSSID,
  1438. IN BYTE *pbSSID,
  1439. IN PBYTE pbConnInfo,
  1440. IN DWORD dwInfoSize
  1441. )
  1442. {
  1443. DWORD dwRetCode = ERROR_SUCCESS;
  1444. HRESULT hr = S_OK;
  1445. do
  1446. {
  1447. dwRetCode = WZCEapolSetCustomAuthData (
  1448. NULL,
  1449. pwszGUID,
  1450. dwEapTypeId,
  1451. dwSizeOfSSID,
  1452. pbSSID,
  1453. pbConnInfo,
  1454. dwInfoSize
  1455. );
  1456. } while (FALSE);
  1457. if (dwRetCode != ERROR_SUCCESS)
  1458. {
  1459. hr = HRESULT_FROM_WIN32(dwRetCode);
  1460. }
  1461. return hr;
  1462. }
  1463. //+---------------------------------------------------------------------------
  1464. //
  1465. // Function called to retrieve the EAPOL parameters for an interface
  1466. //
  1467. // Input arguments:
  1468. // pwszGUID - GUID string for the interface
  1469. //
  1470. // Return values:
  1471. // pdwDefaultEAPType - default EAP type for interface
  1472. // pIntfParams - Interface parameters
  1473. //
  1474. HRESULT
  1475. HrElGetInterfaceParams (
  1476. IN WCHAR *pwszGUID,
  1477. IN OUT EAPOL_INTF_PARAMS *pIntfParams
  1478. )
  1479. {
  1480. DWORD dwRetCode = ERROR_SUCCESS;
  1481. HRESULT hr = S_OK;
  1482. do
  1483. {
  1484. dwRetCode = WZCEapolGetInterfaceParams (
  1485. NULL,
  1486. pwszGUID,
  1487. pIntfParams
  1488. );
  1489. } while (FALSE);
  1490. if (dwRetCode != ERROR_SUCCESS)
  1491. {
  1492. hr = HRESULT_FROM_WIN32(dwRetCode);
  1493. }
  1494. return hr;
  1495. }
  1496. //+---------------------------------------------------------------------------
  1497. //
  1498. // Function called to set the EAPOL parameters for an interface
  1499. //
  1500. // Input arguments:
  1501. // pwszGUID - GUID string for the interface
  1502. // pIntfParams - Interface parameters
  1503. //
  1504. // Return values:
  1505. //
  1506. HRESULT
  1507. HrElSetInterfaceParams (
  1508. IN WCHAR *pwszGUID,
  1509. IN EAPOL_INTF_PARAMS *pIntfParams
  1510. )
  1511. {
  1512. DWORD dwRetCode = ERROR_SUCCESS;
  1513. HRESULT hr = S_OK;
  1514. do
  1515. {
  1516. dwRetCode = WZCEapolSetInterfaceParams (
  1517. NULL,
  1518. pwszGUID,
  1519. pIntfParams
  1520. );
  1521. } while (FALSE);
  1522. if (dwRetCode != ERROR_SUCCESS)
  1523. {
  1524. hr = HRESULT_FROM_WIN32(dwRetCode);
  1525. }
  1526. return hr;
  1527. }
  1528. //+---------------------------------------------------------------------------
  1529. //
  1530. // Set selection in listbox 'hwndLb' to 'nIndex' and notify parent as if
  1531. // user had clicked the item which Windows doesn't do for some reason.
  1532. //
  1533. VOID
  1534. ComboBox_SetCurSelNotify (
  1535. IN HWND hwndLb,
  1536. IN INT nIndex
  1537. )
  1538. {
  1539. ComboBox_SetCurSel( hwndLb, nIndex );
  1540. SendMessage(
  1541. GetParent( hwndLb ),
  1542. WM_COMMAND,
  1543. (WPARAM )MAKELONG(
  1544. (WORD )GetDlgCtrlID( hwndLb ), (WORD )CBN_SELCHANGE ),
  1545. (LPARAM )hwndLb );
  1546. }
  1547. //+---------------------------------------------------------------------------
  1548. //
  1549. // Set the width of the drop-down list 'hwndLb' to the width of the
  1550. // longest item (or the width of the list box if that's wider).
  1551. //
  1552. VOID
  1553. ComboBox_AutoSizeDroppedWidth (
  1554. IN HWND hwndLb
  1555. )
  1556. {
  1557. HDC hdc;
  1558. HFONT hfont;
  1559. TCHAR* psz;
  1560. SIZE size;
  1561. DWORD cch;
  1562. DWORD dxNew;
  1563. DWORD i;
  1564. hfont = (HFONT )SendMessage( hwndLb, WM_GETFONT, 0, 0 );
  1565. if (!hfont)
  1566. return;
  1567. hdc = GetDC( hwndLb );
  1568. if (!hdc)
  1569. return;
  1570. SelectObject( hdc, hfont );
  1571. dxNew = 0;
  1572. for (i = 0; psz = ComboBox_GetPsz( hwndLb, i ); ++i)
  1573. {
  1574. cch = lstrlen( psz );
  1575. if (GetTextExtentPoint32( hdc, psz, cch, &size ))
  1576. {
  1577. if (dxNew < (DWORD )size.cx)
  1578. dxNew = (DWORD )size.cx;
  1579. }
  1580. free ( psz );
  1581. }
  1582. ReleaseDC( hwndLb, hdc );
  1583. // Allow for the spacing on left and right added by the control.
  1584. dxNew += 6;
  1585. // Figure out if the vertical scrollbar will be displayed and, if so,
  1586. // allow for it's width.
  1587. {
  1588. RECT rectD;
  1589. RECT rectU;
  1590. DWORD dyItem;
  1591. DWORD cItemsInDrop;
  1592. DWORD cItemsInList;
  1593. GetWindowRect( hwndLb, &rectU );
  1594. SendMessage( hwndLb, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM )&rectD );
  1595. dyItem = (DWORD)SendMessage( hwndLb, CB_GETITEMHEIGHT, 0, 0 );
  1596. cItemsInDrop = (rectD.bottom - rectU.bottom) / dyItem;
  1597. cItemsInList = ComboBox_GetCount( hwndLb );
  1598. if (cItemsInDrop < cItemsInList)
  1599. dxNew += GetSystemMetrics( SM_CXVSCROLL );
  1600. }
  1601. SendMessage( hwndLb, CB_SETDROPPEDWIDTH, dxNew, 0 );
  1602. }
  1603. //+---------------------------------------------------------------------------
  1604. //
  1605. // Adds data item 'pItem' with displayed text 'pszText' to listbox
  1606. // 'hwndLb'. The item is added sorted if the listbox has LBS_SORT style,
  1607. // or to the end of the list otherwise. If the listbox has LB_HASSTRINGS
  1608. // style, 'pItem' is a null terminated string, otherwise it is any user
  1609. // defined data.
  1610. //
  1611. // Returns the index of the item in the list or negative if error.
  1612. //
  1613. INT
  1614. ComboBox_AddItem(
  1615. IN HWND hwndLb,
  1616. IN LPCTSTR pszText,
  1617. IN VOID* pItem
  1618. )
  1619. {
  1620. INT nIndex;
  1621. nIndex = ComboBox_AddString( hwndLb, pszText );
  1622. if (nIndex >= 0)
  1623. ComboBox_SetItemData( hwndLb, nIndex, pItem );
  1624. return nIndex;
  1625. }
  1626. //+---------------------------------------------------------------------------
  1627. //
  1628. // Returns the address of the 'nIndex'th item context in 'hwndLb' or NULL
  1629. // if none.
  1630. //
  1631. VOID*
  1632. ComboBox_GetItemDataPtr (
  1633. IN HWND hwndLb,
  1634. IN INT nIndex
  1635. )
  1636. {
  1637. LRESULT lResult;
  1638. if (nIndex < 0)
  1639. return NULL;
  1640. lResult = ComboBox_GetItemData( hwndLb, nIndex );
  1641. if (lResult < 0)
  1642. return NULL;
  1643. return (VOID* )lResult;
  1644. }
  1645. //+---------------------------------------------------------------------------
  1646. //
  1647. // Returns heap block containing the text contents of the 'nIndex'th item
  1648. // of combo box 'hwnd' or NULL. It is caller's responsibility to Free the
  1649. // returned string.
  1650. //
  1651. TCHAR*
  1652. ComboBox_GetPsz (
  1653. IN HWND hwnd,
  1654. IN INT nIndex
  1655. )
  1656. {
  1657. INT cch;
  1658. TCHAR* psz;
  1659. cch = ComboBox_GetLBTextLen( hwnd, nIndex );
  1660. if (cch < 0)
  1661. return NULL;
  1662. psz = new TCHAR[( cch + 1)];
  1663. if (psz)
  1664. {
  1665. *psz = TEXT('\0');
  1666. ComboBox_GetLBText( hwnd, nIndex, psz );
  1667. }
  1668. return psz;
  1669. }
  1670. static WCHAR WZCSVC_SERVICE_NAME[] = L"WZCSVC";
  1671. //+---------------------------------------------------------------------------
  1672. //
  1673. // ElCanEapolRunOnInterface:
  1674. //
  1675. // Function to verify if EAPOL can ever be started on an interface
  1676. //
  1677. // Returns TRUE if:
  1678. // WZCSVC service is running and WZCSVC has bound to the interface
  1679. //
  1680. //
  1681. BOOL
  1682. ElCanEapolRunOnInterface (
  1683. IN INetConnection *pconn
  1684. )
  1685. {
  1686. SC_HANDLE hServiceCM = NULL;
  1687. SC_HANDLE hWZCSVCService = NULL;
  1688. SERVICE_STATUS WZCSVCServiceStatus;
  1689. WCHAR wszGuid[c_cchGuidWithTerm];
  1690. NETCON_PROPERTIES* pProps = NULL;
  1691. BOOL fIsOK = TRUE;
  1692. DWORD dwType = 0;
  1693. DWORD dwSizeOfList = 0;
  1694. WCHAR *pwszRegInterfaceList = NULL;
  1695. DWORD dwDisposition = 0;
  1696. HKEY hkey = NULL;
  1697. EAPOL_INTF_PARAMS EapolIntfParams;
  1698. LONG lError = ERROR_SUCCESS;
  1699. DWORD dwRetCode = NO_ERROR;
  1700. HRESULT hr = S_OK;
  1701. do
  1702. {
  1703. //
  1704. // Query status of WZCSVC service
  1705. // Do not display tab if WZCSVC service is not running
  1706. //
  1707. if ((hServiceCM = OpenSCManager ( NULL, NULL, GENERIC_READ ))
  1708. == NULL)
  1709. {
  1710. dwRetCode = GetLastError ();
  1711. TraceTag (ttidLanUi, "ElCanEapolRunOnInterface: OpenSCManager failed with error %ld",
  1712. dwRetCode);
  1713. fIsOK = FALSE;
  1714. break;
  1715. }
  1716. if ((hWZCSVCService =
  1717. OpenService ( hServiceCM, WZCSVC_SERVICE_NAME, GENERIC_READ ))
  1718. == NULL)
  1719. {
  1720. dwRetCode = GetLastError ();
  1721. TraceTag (ttidLanUi, "ElCanEapolRunOnInterface: OpenService failed with error %ld",
  1722. dwRetCode);
  1723. fIsOK = FALSE;
  1724. break;
  1725. }
  1726. if (!QueryServiceStatus ( hWZCSVCService, &WZCSVCServiceStatus ))
  1727. {
  1728. dwRetCode = GetLastError ();
  1729. TraceTag (ttidLanUi, "ElCanEapolRunOnInterface: StartService failed with error %ld",
  1730. dwRetCode);
  1731. fIsOK = FALSE;
  1732. break;
  1733. }
  1734. if ( WZCSVCServiceStatus.dwCurrentState != SERVICE_RUNNING )
  1735. {
  1736. TraceTag (ttidLanUi, "ElCanEapolRunOnInterface: WZCSVC service not running !!!");
  1737. fIsOK = FALSE;
  1738. break;
  1739. }
  1740. TraceTag (ttidLanUi, "ElCanEapolRunOnInterface: WZCSVC service is indeed running !!!");
  1741. if (!CloseServiceHandle ( hWZCSVCService ))
  1742. {
  1743. dwRetCode = GetLastError ();
  1744. TraceTag (ttidLanUi, "ElCanEapolRunOnInterface: CloseService failed with error %ld",
  1745. dwRetCode);
  1746. fIsOK = FALSE;
  1747. break;
  1748. }
  1749. hWZCSVCService = NULL;
  1750. if (!CloseServiceHandle ( hServiceCM ))
  1751. {
  1752. dwRetCode = GetLastError ();
  1753. TraceTag (ttidLanUi, "ElCanEapolRunOnInterface: CloseService failed with error %ld",
  1754. dwRetCode);
  1755. fIsOK = FALSE;
  1756. break;
  1757. }
  1758. hServiceCM = NULL;
  1759. //
  1760. // Check if NDISUIO is bound to interface
  1761. //
  1762. hr = pconn->GetProperties (&pProps);
  1763. if (SUCCEEDED(hr))
  1764. {
  1765. if (::StringFromGUID2 (pProps->guidId, wszGuid, c_cchGuidWithTerm)
  1766. == 0)
  1767. {
  1768. TraceTag (ttidLanUi, "ElCanEapolRunOnInterface: StringFromGUID2 failed");
  1769. fIsOK = FALSE;
  1770. FreeNetconProperties(pProps);
  1771. break;
  1772. }
  1773. FreeNetconProperties(pProps);
  1774. }
  1775. else
  1776. {
  1777. break;
  1778. }
  1779. // Fetch InterfaceList from registry
  1780. // Search for GUID string in registry
  1781. // Get handle to
  1782. // HKLM\Software\Microsoft\EAPOL\Parameters\Interfaces\General
  1783. hr = HrRegCreateKeyEx (
  1784. HKEY_LOCAL_MACHINE,
  1785. cszEapKeyEapolServiceParams,
  1786. REG_OPTION_NON_VOLATILE,
  1787. KEY_READ,
  1788. NULL,
  1789. &hkey,
  1790. &dwDisposition);
  1791. if (!SUCCEEDED (hr))
  1792. {
  1793. TraceTag (ttidLanUi, "ElCanEapolRunOnInterface: Error in HrRegCreateKeyEx for base key, %ld",
  1794. LresFromHr(hr));
  1795. fIsOK = FALSE;
  1796. break;
  1797. }
  1798. // Query the value of
  1799. // ...\EAPOL\Parameters\Interfaces\General\InterfaceList key
  1800. dwSizeOfList = 0;
  1801. hr = HrRegQueryValueEx (
  1802. hkey,
  1803. cszInterfaceList,
  1804. &dwType,
  1805. NULL,
  1806. &dwSizeOfList);
  1807. if (SUCCEEDED (hr))
  1808. {
  1809. pwszRegInterfaceList = (WCHAR *) new BYTE [dwSizeOfList];
  1810. if (pwszRegInterfaceList == NULL)
  1811. {
  1812. hr = E_OUTOFMEMORY;
  1813. fIsOK = FALSE;
  1814. break;
  1815. }
  1816. hr = HrRegQueryValueEx (
  1817. hkey,
  1818. cszInterfaceList,
  1819. &dwType,
  1820. (LPBYTE)pwszRegInterfaceList,
  1821. &dwSizeOfList);
  1822. if (!SUCCEEDED(hr))
  1823. {
  1824. TraceTag (ttidLanUi, "ElCanEapolRunOnInterface: Error in HrRegQueryValueEx acquiring value for InterfaceList, %ld",
  1825. LresFromHr(hr));
  1826. break;
  1827. }
  1828. TraceTag (ttidLanUi, "ElCanEapolRunOnInterface: Query value succeeded = %ws, size=%ld, search GUID = %ws",
  1829. pwszRegInterfaceList, dwSizeOfList, wszGuid);
  1830. }
  1831. else
  1832. {
  1833. TraceTag (ttidLanUi, "ElCanEapolRunOnInterface: Error in HrRegQueryValueEx size estimation for InterfaceList, %ld",
  1834. LresFromHr(hr));
  1835. fIsOK = FALSE;
  1836. break;
  1837. }
  1838. if (wcsstr (pwszRegInterfaceList, wszGuid))
  1839. {
  1840. TraceTag (ttidLanUi, "ElCanEapolRunOnInterface interface found in interface list !!!");
  1841. }
  1842. else
  1843. {
  1844. TraceTag (ttidLanUi, "ElCanEapolRunOnInterface interface *not* found in interface list !!!");
  1845. fIsOK = FALSE;
  1846. break;
  1847. }
  1848. } while (FALSE);
  1849. if (hkey != NULL)
  1850. {
  1851. RegSafeCloseKey (hkey);
  1852. }
  1853. if (pwszRegInterfaceList != NULL)
  1854. {
  1855. free (pwszRegInterfaceList);
  1856. }
  1857. if (hWZCSVCService != NULL)
  1858. {
  1859. if (!CloseServiceHandle ( hWZCSVCService ))
  1860. {
  1861. dwRetCode = GetLastError ();
  1862. TraceTag (ttidLanUi, "ElCanEapolRunOnInterface: CloseService failed with error %ld",
  1863. dwRetCode);
  1864. }
  1865. }
  1866. if (hServiceCM != NULL)
  1867. {
  1868. if (!CloseServiceHandle ( hServiceCM ))
  1869. {
  1870. dwRetCode = GetLastError ();
  1871. TraceTag (ttidLanUi, "ElCanEapolRunOnInterface: CloseService failed with error %ld",
  1872. dwRetCode);
  1873. }
  1874. }
  1875. return fIsOK;
  1876. }
  1877. #ifdef ENABLETRACE
  1878. //+---------------------------------------------------------------------------
  1879. //
  1880. // Function: PrintBindingPath
  1881. //
  1882. // Purpose: Prints the binding path ID and a list of component IDs on
  1883. // the path from top down
  1884. //
  1885. // Arguments:
  1886. //
  1887. // Returns:
  1888. //
  1889. // Author: tongl 26 Nov 1997
  1890. //
  1891. // Notes:
  1892. //
  1893. VOID PrintBindingPath (
  1894. TRACETAGID ttidToTrace,
  1895. INetCfgBindingPath* pncbp,
  1896. PCSTR pszaExtraText)
  1897. {
  1898. Assert (pncbp);
  1899. if (!pszaExtraText)
  1900. {
  1901. pszaExtraText = "";
  1902. }
  1903. const WCHAR c_szSept[] = L"->";
  1904. tstring strPath;
  1905. INetCfgComponent * pnccNetComponent;
  1906. PWSTR pszwCompId;
  1907. HRESULT hr;
  1908. // Get the top component
  1909. hr = pncbp->GetOwner(&pnccNetComponent);
  1910. if (SUCCEEDED(hr))
  1911. {
  1912. hr = pnccNetComponent->GetId(&pszwCompId);
  1913. if SUCCEEDED(hr)
  1914. {
  1915. strPath += pszwCompId;
  1916. CoTaskMemFree(pszwCompId);
  1917. }
  1918. }
  1919. ReleaseObj(pnccNetComponent);
  1920. // Get Comp ID for other component on the path
  1921. CIterNetCfgBindingInterface ncbiIter(pncbp);
  1922. INetCfgBindingInterface * pncbi;
  1923. //Go through interfaces of the binding path
  1924. while (SUCCEEDED(hr) && (hr = ncbiIter.HrNext(&pncbi)) == S_OK)
  1925. {
  1926. strPath += c_szSept;
  1927. // Get the lower component
  1928. hr = pncbi->GetLowerComponent(&pnccNetComponent);
  1929. if(SUCCEEDED(hr))
  1930. {
  1931. hr = pnccNetComponent->GetId(&pszwCompId);
  1932. if (SUCCEEDED(hr))
  1933. {
  1934. strPath += pszwCompId;
  1935. CoTaskMemFree(pszwCompId);
  1936. }
  1937. }
  1938. ReleaseObj(pnccNetComponent);
  1939. ReleaseObj(pncbi);
  1940. }
  1941. if (hr == S_FALSE) // We just got to the end of the loop
  1942. hr = S_OK;
  1943. BOOL fEnabled = (S_OK == pncbp->IsEnabled());
  1944. // Now print the path and ID
  1945. char szaBuf[1024];
  1946. wsprintfA (szaBuf, "[%s] %S: %s",
  1947. (fEnabled) ? "x" : " ",
  1948. strPath.c_str(),
  1949. pszaExtraText);
  1950. TraceTag (ttidToTrace, szaBuf);
  1951. TraceError ("PrintBindingPath", hr);
  1952. }
  1953. #endif //ENABLETRACE