Source code of Windows XP (NT5)
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.

1612 lines
43 KiB

  1. #include "pch.h"
  2. #pragma hdrstop
  3. #include "nceh.h"
  4. #include "wizard.h"
  5. #include "ncnetcfg.h"
  6. #include "lancmn.h"
  7. #include "cfg.h"
  8. #include "wgenericpage.h"
  9. //
  10. // Function: CWizProvider::CWizProvider
  11. //
  12. // Purpose: ctor for the CWizProvider class
  13. //
  14. // Parameters: pPL - Info corresponding to a Connection UI Object
  15. //
  16. // Returns: nothing
  17. //
  18. CWizProvider::CWizProvider(ProviderList *pPL, BOOL fDeferLoad)
  19. {
  20. TraceFileFunc(ttidGuiModeSetup);
  21. memcpy(&m_guidUiObject, pPL->pguidProvider, sizeof(GUID));
  22. m_ulMaxPageCount = 0xFFFFFFFF;
  23. m_ulPageCnt = 0;
  24. m_ulPageBufferLen = 0;
  25. m_rghPages = NULL;
  26. m_pWizardUi = NULL;
  27. m_fDeletePages = TRUE;
  28. m_nBtnIdc = pPL->nBtnIdc;
  29. m_fDeferLoad = fDeferLoad;
  30. }
  31. //
  32. // Function: CWizProvider::~CWizProvider
  33. //
  34. // Purpose: dtor for the CWizProvider class
  35. //
  36. // Parameters: none
  37. //
  38. // Returns: nothing
  39. //
  40. CWizProvider::~CWizProvider()
  41. {
  42. TraceFileFunc(ttidGuiModeSetup);
  43. if (m_fDeletePages)
  44. {
  45. DeleteHPages();
  46. }
  47. MemFree(m_rghPages);
  48. ReleaseObj(m_pWizardUi);
  49. }
  50. //
  51. // Function: CWizProvider::HrCreate
  52. //
  53. // Purpose: Two phase constructor for the CWizProvider class
  54. //
  55. // Parameters: pPL [IN] - Provider info from which to query the
  56. // INetConnectionWizardUi interface.
  57. // pProvider [OUT] - If this function succeeds this pointer
  58. // will contain the constructed and
  59. // initialized CWizProvider instance.
  60. // fDeferLoad [IN] - Request the provider defer actual load
  61. //
  62. // Returns: HRESULT, S_OK on success
  63. //
  64. NOTHROW
  65. HRESULT CWizProvider::HrCreate(ProviderList *pPL,
  66. CWizProvider ** ppProvider,
  67. BOOL fDeferLoad)
  68. {
  69. TraceFileFunc(ttidGuiModeSetup);
  70. HRESULT hr = S_OK;
  71. CWizProvider *pprov = NULL;
  72. Assert((NULL != pPL) && (NULL != ppProvider));
  73. // Initialize output parameters
  74. *ppProvider = NULL;
  75. // Create the CWizProvider instance
  76. pprov = new CWizProvider(pPL, fDeferLoad);
  77. if ((NULL != pprov) && (FALSE == fDeferLoad))
  78. {
  79. Assert(pPL->pguidProvider);
  80. hr = CoCreateInstance(
  81. reinterpret_cast<REFCLSID>(*pPL->pguidProvider),
  82. NULL,
  83. CLSCTX_INPROC_SERVER | CLSCTX_NO_CODE_DOWNLOAD,
  84. IID_INetConnectionWizardUi,
  85. (LPVOID*)&pprov->m_pWizardUi);
  86. TraceHr(ttidError, FAL, hr, FALSE, "CoCreateInstance");
  87. if (FAILED(hr))
  88. {
  89. delete pprov;
  90. pprov = NULL;
  91. }
  92. }
  93. // Save the new instance
  94. *ppProvider = pprov;
  95. TraceHr(ttidWizard, FAL, hr, (REGDB_E_CLASSNOTREG == hr), "CWizProvider::HrCreate");
  96. return hr;
  97. }
  98. //
  99. // Function: CWizProvider::HrCompleteDeferredLoad
  100. //
  101. // Purpose: Complete the steps necessary to load what was a defer load object
  102. //
  103. // Parameters: none
  104. //
  105. // Returns: HRESULT, S_OK on success
  106. //
  107. HRESULT CWizProvider::HrCompleteDeferredLoad()
  108. {
  109. TraceFileFunc(ttidGuiModeSetup);
  110. HRESULT hr = S_OK;
  111. if (m_fDeferLoad)
  112. {
  113. m_fDeferLoad = FALSE;
  114. // Attempt to create the UI Object
  115. //
  116. hr = CoCreateInstance(
  117. reinterpret_cast<REFCLSID>(m_guidUiObject),
  118. NULL,
  119. CLSCTX_INPROC_SERVER | CLSCTX_NO_CODE_DOWNLOAD,
  120. IID_INetConnectionWizardUi,
  121. (LPVOID*)&m_pWizardUi);
  122. }
  123. TraceHr(ttidWizard, FAL, hr, FALSE, "CWizProvider::HrCompleteDeferredLoad");
  124. return hr;
  125. }
  126. //
  127. // Function: CWizProvider::UlGetMaxPageCount
  128. //
  129. // Purpose: Queries from the provider the maximum number of pages
  130. // that it will return. Subsequent calls to this routine
  131. // return the cached count without requerying the provider.
  132. //
  133. // Parameters: pContext [IN] - Context information, supplied either by
  134. // Setup or by the wizard itself (when not
  135. // launched from Setup).
  136. //
  137. // Returns: ULONG, Maximum number of pages provider will return.
  138. //
  139. NOTHROW
  140. ULONG
  141. CWizProvider::UlGetMaxPageCount(INetConnectionWizardUiContext *pContext)
  142. {
  143. TraceFileFunc(ttidGuiModeSetup);
  144. HRESULT hr = S_OK;
  145. if (NULL == m_pWizardUi)
  146. {
  147. m_ulMaxPageCount = 0;
  148. }
  149. else if (0xFFFFFFFF == m_ulMaxPageCount)
  150. {
  151. // Query the provider only once
  152. m_ulMaxPageCount = 0L;
  153. COM_PROTECT_TRY
  154. {
  155. Assert(NULL != m_pWizardUi);
  156. Assert(NULL != pContext);
  157. DWORD dwCount = 0L;
  158. hr = m_pWizardUi->QueryMaxPageCount(pContext, &dwCount);
  159. if (S_OK == hr)
  160. {
  161. m_ulMaxPageCount = dwCount;
  162. }
  163. }
  164. COM_PROTECT_CATCH
  165. }
  166. TraceHr(ttidWizard, FAL, hr, FALSE, "CWizProvider::GetMaxPageCount");
  167. return m_ulMaxPageCount;
  168. }
  169. //
  170. // Function: CWizProvider::DeleteHPages
  171. //
  172. // Purpose: Call DestroyPropertySheetPage for each cached page
  173. //
  174. // Parameters: none
  175. //
  176. // Returns: nothing
  177. //
  178. VOID CWizProvider::DeleteHPages()
  179. {
  180. TraceFileFunc(ttidGuiModeSetup);
  181. for (ULONG ulIdx=0; ulIdx < ULPageCount(); ulIdx++)
  182. {
  183. DestroyPropertySheetPage(m_rghPages[ulIdx]);
  184. }
  185. m_ulPageCnt=0;
  186. }
  187. //
  188. // Function: CWizProvider::HrAddPages
  189. //
  190. // Purpose: Calls the AddPages method of a provider's
  191. // INetConnectionWizardUi interface to allow for the
  192. // supply of Wizard Pages
  193. //
  194. // Parameters: pContext [IN] - Context information, supplied either by
  195. // Setup or by the wizard itself (when not
  196. // launched from Setup).
  197. //
  198. // Returns: HRESULT, S_OK on success
  199. //
  200. NOTHROW
  201. HRESULT
  202. CWizProvider::HrAddPages(INetConnectionWizardUiContext *pContext)
  203. {
  204. TraceFileFunc(ttidGuiModeSetup);
  205. HRESULT hr = S_OK;
  206. if (m_pWizardUi)
  207. {
  208. COM_PROTECT_TRY
  209. {
  210. // Ensure input params are valid
  211. Assert(NULL != m_pWizardUi);
  212. Assert(NULL != pContext);
  213. hr = m_pWizardUi->AddPages(pContext, CWizProvider::FAddPropSheet,
  214. reinterpret_cast<LPARAM>(this));
  215. }
  216. COM_PROTECT_CATCH
  217. }
  218. else
  219. {
  220. hr = E_NOINTERFACE;
  221. }
  222. TraceHr(ttidWizard, FAL, hr, FALSE, "CWizProvider::HrAddPages");
  223. return hr;
  224. }
  225. //
  226. // Function: CWizProvider::FAddPropSheet
  227. //
  228. // Purpose: Callback function for the AddPages API used to accept
  229. // wizard pages handed back from a provider.
  230. //
  231. // Parameters: hPage [IN] - The page to add
  232. // lParam [IN] - 'this' casted to an LPARAM
  233. //
  234. // Returns: BOOL, TRUE if the page was successfully added.
  235. //
  236. BOOL
  237. CWizProvider::FAddPropSheet(HPROPSHEETPAGE hPage, LPARAM lParam)
  238. {
  239. TraceFileFunc(ttidGuiModeSetup);
  240. CWizProvider * pProvider;
  241. // Validate the input parameters
  242. if ((0L == lParam) || (NULL == hPage))
  243. {
  244. Assert(lParam);
  245. Assert(hPage);
  246. TraceHr(ttidWizard, FAL, E_INVALIDARG, FALSE, "CWizProvider::FAddPropSheet");
  247. return FALSE;
  248. }
  249. pProvider = reinterpret_cast<CWizProvider*>(lParam);
  250. // Grow the buffer if necessary
  251. if (pProvider->m_ulPageCnt == pProvider->m_ulPageBufferLen)
  252. {
  253. HPROPSHEETPAGE* rghPages = reinterpret_cast<HPROPSHEETPAGE*>(
  254. MemAlloc(sizeof(HPROPSHEETPAGE) * (pProvider->m_ulPageBufferLen + 10)));
  255. if (NULL == rghPages)
  256. {
  257. TraceHr(ttidWizard, FAL, E_OUTOFMEMORY, FALSE, "CWizProvider::FAddPropSheet");
  258. return FALSE;
  259. }
  260. // Copy the existing pages to the new buffer
  261. if (NULL != pProvider->m_rghPages)
  262. {
  263. memcpy(rghPages, pProvider->m_rghPages,
  264. sizeof(HPROPSHEETPAGE) * pProvider->m_ulPageBufferLen);
  265. MemFree(pProvider->m_rghPages);
  266. }
  267. pProvider->m_rghPages = rghPages;
  268. pProvider->m_ulPageBufferLen += 10;
  269. }
  270. // Retain the new page
  271. pProvider->m_rghPages[pProvider->m_ulPageCnt++] = hPage;
  272. return TRUE;
  273. }
  274. //
  275. // Function: CWizProvider::HrGetLanInterface
  276. //
  277. // Purpose: Get the special LAN interface
  278. //
  279. // Parameters: ppIntr [OUT] - The special LAN specific interface
  280. //
  281. // Returns: HRESULT, S_OK on success
  282. //
  283. HRESULT CWizProvider::HrGetLanInterface(INetLanConnectionWizardUi ** ppIntr)
  284. {
  285. TraceFileFunc(ttidGuiModeSetup);
  286. HRESULT hr;
  287. Assert(NULL != ppIntr);
  288. Assert(NULL != m_pWizardUi);
  289. *ppIntr = NULL;
  290. hr = m_pWizardUi->QueryInterface(IID_INetLanConnectionWizardUi,
  291. (LPVOID *)ppIntr);
  292. TraceHr(ttidWizard, FAL, hr, FALSE, "CWizProvider::HrGetLanInterface");
  293. return hr;
  294. }
  295. //
  296. // Function: CWizProvider::HrSpecifyAdapterGuid
  297. //
  298. // Purpose: To notify the provider of the adapter guid to process
  299. //
  300. // Parameters: pguid [IN] - The adapter guid to process
  301. //
  302. // Returns: HRESULT, S_OK on success
  303. //
  304. HRESULT CWizProvider::HrSpecifyAdapterGuid(GUID *pguid)
  305. {
  306. TraceFileFunc(ttidGuiModeSetup);
  307. HRESULT hr;
  308. INetLanConnectionWizardUi *pIntr = NULL;
  309. hr = HrGetLanInterface(&pIntr);
  310. if (SUCCEEDED(hr))
  311. {
  312. hr = pIntr->SetDeviceComponent(pguid);
  313. ReleaseObj(pIntr);
  314. }
  315. TraceHr(ttidWizard, FAL, hr, FALSE, "CWizProvider::HrSpecifyAdapterGuid");
  316. return hr;
  317. }
  318. CAdapterList::CAdapterList()
  319. {
  320. m_prgAdapters = NULL; // Adapter array
  321. m_clAdapters = 0; // Count of adapters in the array
  322. m_lBufSize = 0; // Total available slots in the array
  323. m_lIdx = -1; // Current adapter index
  324. // Range is -1 to m_clAdapters
  325. m_fAdaptersInstalled = FALSE; // No adapters on the machine
  326. }
  327. AdapterEntry * CAdapterList::PAE_Current()
  328. {
  329. TraceFileFunc(ttidGuiModeSetup);
  330. if ((m_lIdx > -1) && (m_lIdx < m_clAdapters))
  331. {
  332. Assert(NULL != m_prgAdapters);
  333. return &m_prgAdapters[m_lIdx];
  334. }
  335. else
  336. {
  337. return NULL;
  338. }
  339. }
  340. AdapterEntry * CAdapterList::PAE_Next()
  341. {
  342. // Find the next, not hidden adapter
  343. //
  344. // Hidden adapters are those which were processed by a previous
  345. // run of setup
  346. //
  347. // Increment the index even if the count is zero
  348. // m_lIdx == -1 means before the first adapter
  349. // m_lIdx == m_clAdapters means after the last adapter
  350. while (m_lIdx < m_clAdapters)
  351. {
  352. m_lIdx++;
  353. if ((m_lIdx < m_clAdapters) && (!m_prgAdapters[m_lIdx].fHide))
  354. break;
  355. }
  356. Assert(m_lIdx >= -1);
  357. return PAE_Current();
  358. }
  359. AdapterEntry * CAdapterList::PAE_Prev()
  360. {
  361. // Find the previous, not hidden adapter
  362. //
  363. // Hidden adapters are those which were processed by a previous
  364. // run of setup
  365. //
  366. // Decrement the index even if the count is zero
  367. // m_lIdx == -1 means before the first adapter
  368. // m_lIdx == m_clAdapters means after the last adapter
  369. while (-1 < m_lIdx)
  370. {
  371. m_lIdx--;
  372. if ((-1 < m_lIdx) && (!m_prgAdapters[m_lIdx].fHide))
  373. break;
  374. }
  375. Assert(m_lIdx < m_clAdapters);
  376. return PAE_Current();
  377. }
  378. GUID * CAdapterList::NextAdapter()
  379. {
  380. AdapterEntry * pae = PAE_Next();
  381. if (NULL != pae)
  382. return &(pae->guidAdapter);
  383. else
  384. return NULL;
  385. }
  386. GUID * CAdapterList::PrevAdapter()
  387. {
  388. AdapterEntry * pae = PAE_Prev();
  389. if (NULL != pae)
  390. return &(pae->guidAdapter);
  391. else
  392. return NULL;
  393. }
  394. GUID * CAdapterList::CurrentAdapter()
  395. {
  396. AdapterEntry * pae = PAE_Current();
  397. if (NULL != pae)
  398. return &(pae->guidAdapter);
  399. else
  400. return NULL;
  401. }
  402. VOID CAdapterList::EmptyList()
  403. {
  404. if (NULL != m_prgAdapters)
  405. {
  406. MemFree(m_prgAdapters);
  407. m_prgAdapters = NULL;
  408. m_clAdapters = 0; // Count of adapters in the array
  409. m_lBufSize = 0; // Total available slots in the array
  410. m_lIdx = -1;
  411. }
  412. }
  413. VOID CAdapterList::HideAllAdapters()
  414. {
  415. for (LONG lIdx=0; lIdx < m_clAdapters; lIdx++)
  416. m_prgAdapters[lIdx].fHide = TRUE;
  417. }
  418. VOID CAdapterList::UnhideNewAdapters()
  419. {
  420. for (LONG lIdx=0; lIdx < m_clAdapters; lIdx++)
  421. if (m_prgAdapters[lIdx].fNew)
  422. {
  423. m_prgAdapters[lIdx].fHide = FALSE;
  424. }
  425. }
  426. HRESULT CAdapterList::HrAppendEntries(AdapterEntry * pae, ULONG cae)
  427. {
  428. if (0 == cae)
  429. {
  430. return S_OK;
  431. }
  432. if (m_clAdapters + (LONG)cae > m_lBufSize)
  433. {
  434. // Grow the buffer
  435. AdapterEntry * prg = reinterpret_cast<AdapterEntry *>(
  436. MemAlloc(sizeof(AdapterEntry) * (m_lBufSize + cae + 10)));
  437. if (NULL == prg)
  438. {
  439. TraceHr(ttidWizard, FAL, E_OUTOFMEMORY, FALSE, "CAdapterList::HrAppendEntries");
  440. return E_OUTOFMEMORY;
  441. }
  442. // Copy the existing pages to the new buffer
  443. if (NULL != m_prgAdapters)
  444. {
  445. memcpy(prg, m_prgAdapters, sizeof(AdapterEntry) * m_lBufSize);
  446. MemFree(m_prgAdapters);
  447. }
  448. m_prgAdapters = prg;
  449. m_lBufSize += (cae + 10);
  450. }
  451. memcpy(&m_prgAdapters[m_clAdapters], pae, cae * sizeof(AdapterEntry));
  452. m_clAdapters += cae;
  453. return S_OK;
  454. }
  455. //
  456. // Function: CAdapterList::HrQueryLanAdapters
  457. //
  458. // Purpose: Query the available LAN adapters.
  459. //
  460. // Parameters: pnc [IN] - An INetCfg interface
  461. // pAL [IN,OUT] - Receives the list of LAN adapters
  462. //
  463. // Returns: HRESULT, S_OK on success
  464. //
  465. HRESULT CAdapterList::HrQueryLanAdapters(INetCfg * pnc, CAdapterList * pAL)
  466. {
  467. HRESULT hr = S_OK;
  468. CAdapterList ALphys;
  469. CAdapterList ALvirt;
  470. TraceTag(ttidWizard, "CAdapterList::HrQueryLanAdapters - Querying available adapters");
  471. // Enumerate the available adapters
  472. Assert(NULL != pnc);
  473. CIterNetCfgComponent nccIter(pnc, &GUID_DEVCLASS_NET);
  474. INetCfgComponent* pncc;
  475. while (SUCCEEDED(hr) && (S_OK == (hr = nccIter.HrNext(&pncc))))
  476. {
  477. hr = HrIsLanCapableAdapter(pncc);
  478. if (S_OK == hr)
  479. {
  480. DWORD dw;
  481. AdapterEntry ae;
  482. ae.fHide = FALSE;
  483. // Get the adapter instance guid
  484. hr = pncc->GetInstanceGuid(&ae.guidAdapter);
  485. if (FAILED(hr))
  486. goto NextAdapter;
  487. // Is it in used in a connection?
  488. hr = HrIsConnection(pncc);
  489. if (FAILED(hr))
  490. goto NextAdapter;
  491. ae.fProcessed = (S_OK == hr);
  492. ae.fNew = !ae.fProcessed; // It's new if it has not been processed
  493. // Check device, if not present skip it
  494. //
  495. hr = pncc->GetDeviceStatus(&dw);
  496. if (FAILED(hr) || (CM_PROB_DEVICE_NOT_THERE == dw))
  497. {
  498. goto NextAdapter;
  499. }
  500. // Is this a virtual adapter?
  501. hr = pncc->GetCharacteristics(&dw);
  502. if (FAILED(hr))
  503. goto NextAdapter;
  504. ae.fVirtual = ((dw & NCF_VIRTUAL) ? TRUE : FALSE);
  505. // Add the entry to the appropriate list
  506. if (ae.fVirtual)
  507. {
  508. hr = ALvirt.HrAppendEntries(&ae, 1);
  509. }
  510. else
  511. {
  512. hr = ALphys.HrAppendEntries(&ae, 1);
  513. }
  514. if (FAILED(hr))
  515. goto NextAdapter;
  516. // Note the fact that LAN capable adapters exist.
  517. // Because in setup we will show the join page.
  518. pAL->m_fAdaptersInstalled = TRUE;
  519. }
  520. NextAdapter:
  521. ReleaseObj(pncc);
  522. hr = S_OK;
  523. }
  524. if (SUCCEEDED(hr))
  525. {
  526. // Merge the physical and virtual lists into the pAL input variable
  527. pAL->EmptyList();
  528. hr = pAL->HrAppendEntries(ALphys.m_prgAdapters, ALphys.m_clAdapters);
  529. if (SUCCEEDED(hr))
  530. {
  531. hr = pAL->HrAppendEntries(ALvirt.m_prgAdapters, ALvirt.m_clAdapters);
  532. }
  533. }
  534. TraceHr(ttidWizard, FAL, hr, FALSE, "CAdapterList::HrQueryUnboundAdapters");
  535. return hr;
  536. }
  537. HRESULT CAdapterList::HrCreateTypicalConnections(CWizard * pWizard)
  538. {
  539. HRESULT hr = S_OK;
  540. // If there are no adapters in the queue or we have no LAN provider...
  541. if (0 == pWizard->UlProviderCount())
  542. {
  543. return S_OK;
  544. }
  545. // Set the current provider
  546. pWizard->SetCurrentProvider(0);
  547. CWizProvider * pWizProvider = pWizard->GetCurrentProvider();
  548. Assert(NULL != pWizProvider);
  549. TraceTag(ttidWizard, "CAdapterList::HrCreateTypicalConnections - Creating any new LAN connections.");
  550. // For each adapter in the list create a connection
  551. for (LONG lIdx=0; lIdx<m_clAdapters; lIdx++)
  552. {
  553. AdapterEntry * pae = &m_prgAdapters[lIdx];
  554. if (!pae->fProcessed)
  555. {
  556. #if DBG
  557. WCHAR szGuid[c_cchGuidWithTerm];
  558. szGuid[0] = 0;
  559. StringFromGUID2(pae->guidAdapter, szGuid, c_cchGuidWithTerm);
  560. TraceTag(ttidWizard, " Guid: %S",szGuid);
  561. #endif
  562. pae->fProcessed = TRUE;
  563. // Push the adapter guid onto the provider
  564. hr = pWizProvider->HrSpecifyAdapterGuid(&(pae->guidAdapter));
  565. if (SUCCEEDED(hr))
  566. {
  567. tstring str;
  568. INetConnection * pConn = NULL;
  569. GenerateUniqueConnectionName(pae->guidAdapter, &str, pWizProvider);
  570. TraceTag(ttidWizard, " Name: %S", str.c_str());
  571. hr = (pWizProvider->PWizardUi())->GetNewConnection(&pConn);
  572. ReleaseObj(pConn);
  573. }
  574. // If we failed to create a connection we need to mark it as hidden
  575. // so it will be skipped in the future. Eat the error or otherwise
  576. // setup will just stop.
  577. //
  578. if (FAILED(hr))
  579. {
  580. TraceHr(ttidWizard, FAL, hr, FALSE, "CAdapterList::HrCreateTypicalConnections - failed creating the connection");
  581. pae->fHide = TRUE;
  582. hr = S_OK;
  583. }
  584. }
  585. }
  586. // Ask the LAN provider to release any cached pointers.
  587. //
  588. (VOID)pWizProvider->HrSpecifyAdapterGuid(NULL);
  589. TraceHr(ttidWizard, FAL, hr, FALSE, "CAdapterList::HrCreateTypicalConnections");
  590. return hr;
  591. }
  592. HRESULT CAdapterList::HrQueryUnboundAdapters(CWizard * pWizard)
  593. {
  594. HRESULT hr = S_OK;
  595. LONG lIdx;
  596. Assert(NULL != pWizard->PNetCfg());
  597. // Handle the first time the adapters are queried
  598. if (0 == m_clAdapters)
  599. {
  600. hr = HrQueryLanAdapters(pWizard->PNetCfg(), this);
  601. if (SUCCEEDED(hr))
  602. {
  603. // Mark all already bound adapters as hidden so they
  604. // won't be displayed in the UI
  605. for (lIdx=0; lIdx<m_clAdapters; lIdx++)
  606. {
  607. m_prgAdapters[lIdx].fHide = m_prgAdapters[lIdx].fProcessed;
  608. }
  609. // Create connections for all unbound adapters
  610. hr = HrCreateTypicalConnections(pWizard);
  611. }
  612. }
  613. else
  614. {
  615. CAdapterList AL;
  616. // Query the current adapters
  617. hr = HrQueryLanAdapters(pWizard->PNetCfg(), &AL);
  618. if (FAILED(hr))
  619. goto Error;
  620. // Eliminate adapters in the original set which are not
  621. // present in new list
  622. for (lIdx=0; lIdx<m_clAdapters; lIdx++)
  623. {
  624. BOOL fFound = FALSE;
  625. LONG lIdxTemp;
  626. for (lIdxTemp=0; lIdxTemp<AL.m_clAdapters; lIdxTemp++)
  627. {
  628. if (m_prgAdapters[lIdx].guidAdapter ==
  629. AL.m_prgAdapters[lIdxTemp].guidAdapter)
  630. {
  631. fFound = TRUE;
  632. break;
  633. }
  634. }
  635. if (fFound)
  636. {
  637. // Compress the located adapter from the new set
  638. if (lIdxTemp + 1 < AL.m_clAdapters)
  639. {
  640. memcpy(&AL.m_prgAdapters[lIdxTemp],
  641. &AL.m_prgAdapters[lIdxTemp+1],
  642. sizeof(AdapterEntry) *
  643. (AL.m_clAdapters - (lIdxTemp + 1)));
  644. }
  645. AL.m_clAdapters--;
  646. }
  647. else
  648. {
  649. // The source adapter is no longer in the set
  650. if (lIdx < m_lIdx)
  651. m_lIdx--;
  652. }
  653. }
  654. Assert(m_lIdx <= m_clAdapters);
  655. if (m_lIdx == m_clAdapters)
  656. m_lIdx = m_clAdapters-1;
  657. // Create connections for the new adapters
  658. hr = AL.HrCreateTypicalConnections(pWizard);
  659. if (FAILED(hr))
  660. goto Error;
  661. // Append new adapters to the original list
  662. hr = HrAppendEntries(AL.m_prgAdapters, AL.m_clAdapters);
  663. }
  664. Error:
  665. TraceHr(ttidWizard, FAL, hr, FALSE, "CAdapterList::HrQueryUnboundAdapters");
  666. return hr;
  667. }
  668. //
  669. // Function: CWizard::CWizard
  670. //
  671. // Purpose: ctor for the CWizard class
  672. //
  673. // Parameters: fLanPages [IN] - Processing LAN pages
  674. // pdata [IN] - Wizard context info
  675. // fDeferred [IN] - Defered loading of providers
  676. //
  677. // Returns: nothing
  678. //
  679. CWizard::CWizard(BOOL fLanPages, PINTERNAL_SETUP_DATA pData, BOOL fDeferred)
  680. {
  681. TraceFileFunc(ttidGuiModeSetup);
  682. m_fLanPages = fLanPages;
  683. m_fExitNoReturn = FALSE;
  684. m_fCoUninit = FALSE;
  685. m_fDeferredProviderLoad = fDeferred;
  686. m_fProviderChanged = FALSE;
  687. m_dwFirstPage = 0;
  688. m_pConn = NULL;
  689. m_pNetCfg = NULL;
  690. m_pUiContext = NULL;
  691. Assert(NULL != pData);
  692. m_pSetupData = pData;
  693. m_dwOperationFlags = pData->OperationFlags;
  694. m_UMMode = UM_DEFAULTHIDE;
  695. m_ulCurProvider = 0;
  696. m_ulPageDataCnt = 0;
  697. ZeroMemory(m_rgPageData, sizeof(m_rgPageData));
  698. m_ulWizProviderCnt = 0;
  699. m_ulPageDataMRU = 0;
  700. ZeroMemory(m_rgpWizProviders, sizeof(m_rgpWizProviders));
  701. }
  702. //
  703. // Function: CWizard::~CWizard
  704. //
  705. // Purpose: dtor for the CWizProvider class
  706. //
  707. // Parameters: none
  708. //
  709. // Returns: nothing
  710. //
  711. // Note: Remove CWizard member re-init from dtor. Present only
  712. // to ensure complete appropriate release of all members
  713. CWizard::~CWizard()
  714. {
  715. TraceFileFunc(ttidGuiModeSetup);
  716. ULONG ulIdx;
  717. // Call the cleanup callback for all registered wizard internal pages
  718. for (ulIdx = 0; ulIdx < m_ulPageDataCnt; ulIdx++)
  719. {
  720. if (m_rgPageData[ulIdx].pfn)
  721. {
  722. m_rgPageData[ulIdx].pfn(this, m_rgPageData[ulIdx].lParam);
  723. }
  724. }
  725. m_ulPageDataCnt = 0L;
  726. // Note: Do not release m_pSetupData, it's only a reference
  727. m_pSetupData = NULL;
  728. // Release any providers that had been retained
  729. for (ulIdx = 0; ulIdx < m_ulWizProviderCnt; ulIdx++)
  730. {
  731. Assert(0 != m_rgpWizProviders[ulIdx]);
  732. delete m_rgpWizProviders[ulIdx];
  733. m_rgpWizProviders[ulIdx] = NULL;
  734. }
  735. m_ulWizProviderCnt = 0L;
  736. m_ulCurProvider = 0;
  737. ReleaseObj(m_pUiContext);
  738. m_pUiContext = NULL;
  739. ReleaseObj(m_pConn);
  740. m_pConn = NULL;
  741. if (m_pNetCfg)
  742. {
  743. (VOID)HrUninitializeAndReleaseINetCfg(FCoUninit(), m_pNetCfg, TRUE);
  744. }
  745. m_pNetCfg = NULL;
  746. }
  747. //
  748. // Function: CWizard::HrCreate
  749. //
  750. // Purpose: Two phase constructor for the CWizard class
  751. //
  752. // Parameters: ppWizard [OUT] - If this function succeeds this pointer
  753. // will contain the constructed and
  754. // fLanPages [IN] - Processing LAN pages
  755. // initialized CWizard instance.
  756. // pdata [IN] - Wizard Context info
  757. // fDeferred [IN] - Providers are defer loaded
  758. //
  759. // Returns: HRESULT, S_OK on success
  760. //
  761. NOTHROW
  762. HRESULT CWizard::HrCreate(CWizard ** ppWizard,
  763. BOOL fLanPages,
  764. PINTERNAL_SETUP_DATA pData,
  765. BOOL fDeferred)
  766. {
  767. TraceFileFunc(ttidGuiModeSetup);
  768. HRESULT hr = S_OK;
  769. CWizardUiContext * pContext = NULL;
  770. CWizard * pWiz = NULL;
  771. Assert(NULL != ppWizard);
  772. // Initialize output parameters
  773. *ppWizard = NULL;
  774. // Create the CWizard instance
  775. pWiz = new CWizard(fLanPages, pData, fDeferred);
  776. pContext = new CWizardUiContext(pData);
  777. if ((NULL != pWiz) && (NULL != pContext))
  778. {
  779. // Save the new instance
  780. pWiz->m_pUiContext = pContext;
  781. *ppWizard = pWiz;
  782. }
  783. else
  784. {
  785. hr = E_OUTOFMEMORY;
  786. }
  787. TraceHr(ttidWizard, FAL, hr, FALSE, "CWizard::HrCreate");
  788. return hr;
  789. }
  790. //
  791. // Function: CWizard::HrAddProvider
  792. //
  793. // Purpose: To add a connection provider to list of currently loaded
  794. // connection providers
  795. //
  796. // Parameters: pPL [IN] - GUID of conection provider which implements the
  797. // INetConnectionWizardUi interface.
  798. //
  799. // Returns: HRESULT, S_OK on success
  800. //
  801. NOTHROW
  802. HRESULT CWizard::HrAddProvider(ProviderList *pPL)
  803. {
  804. TraceFileFunc(ttidGuiModeSetup);
  805. HRESULT hr = E_OUTOFMEMORY;
  806. CWizProvider * pProvider = NULL;
  807. Assert(NULL != pPL);
  808. Assert(m_eMaxProviders > m_ulWizProviderCnt);
  809. // Restrict the total number of providers managed
  810. if (m_eMaxProviders > m_ulWizProviderCnt)
  811. {
  812. // Instantiate a provider
  813. hr = CWizProvider::HrCreate(pPL, &pProvider,
  814. FDeferredProviderLoad());
  815. if (SUCCEEDED(hr))
  816. {
  817. m_rgpWizProviders[m_ulWizProviderCnt++] = pProvider;
  818. }
  819. }
  820. TraceHr(ttidWizard, FAL, hr, (REGDB_E_CLASSNOTREG == hr), "CWizard::HrAddProvider");
  821. return hr;
  822. }
  823. //
  824. // Function: CWizard::LoadWizProviders
  825. //
  826. // Purpose: Load the requested wizard providers
  827. //
  828. // Parameters: ulCntProviders [IN] - Count of guids in rgpguidProviders
  829. // rgProviders [IN] - Guids of the providers to load
  830. //
  831. // Returns: none
  832. //
  833. VOID CWizard::LoadWizProviders( ULONG ulCntProviders,
  834. ProviderList * rgProviders)
  835. {
  836. if (0 == m_ulWizProviderCnt)
  837. {
  838. TraceTag(ttidWizard, "Loading requested providers");
  839. // Load the connections providers used during Setup
  840. for (UINT nIdx=0; nIdx < ulCntProviders; nIdx++)
  841. {
  842. HRESULT hr = HrAddProvider(&rgProviders[nIdx]);
  843. TraceHr(ttidWizard, FAL, hr, FALSE,
  844. "FSetupRequestWizardPages - Failed to load provider #%d",nIdx);
  845. }
  846. }
  847. }
  848. //
  849. // Function: CWizard::HrCreateWizProviderPages
  850. //
  851. // Purpose: Load the requested wizard provider's pages, if requested.
  852. // Otherwise return the expected page count.
  853. //
  854. // Parameters: fCountOnly [IN] - If True, only the maximum number of
  855. // pages this routine will create need
  856. // be determined.
  857. // pnPages [IN] - Increment by the number of pages
  858. // to create/created
  859. //
  860. // Returns: HRESULT, S_OK on success
  861. //
  862. HRESULT CWizard::HrCreateWizProviderPages(BOOL fCountOnly, UINT *pcPages)
  863. {
  864. TraceFileFunc(ttidGuiModeSetup);
  865. HRESULT hr = S_OK;
  866. ULONG ulCnt = 0;
  867. ULONG ulIdx;
  868. Assert(NULL != m_pSetupData);
  869. Assert(NULL != m_pUiContext);
  870. // If provider loading was deferred, load them now
  871. //
  872. if (FDeferredProviderLoad())
  873. {
  874. // Count the maximum number of pages
  875. for (ulIdx=0; ulIdx<m_ulWizProviderCnt; ulIdx++)
  876. {
  877. HRESULT hrTmp = m_rgpWizProviders[ulIdx]->HrCompleteDeferredLoad();
  878. }
  879. // Deferred Load is no longer true. Reset the state
  880. //
  881. DeferredLoadComplete();
  882. }
  883. if (fCountOnly)
  884. {
  885. // Count the maximum number of pages
  886. for (ulIdx=0; ulIdx<m_ulWizProviderCnt; ulIdx++)
  887. {
  888. Assert(m_rgpWizProviders[ulIdx]);
  889. if (m_rgpWizProviders[ulIdx]->UlGetMaxPageCount(m_pUiContext))
  890. {
  891. ulCnt += m_rgpWizProviders[ulIdx]->UlGetMaxPageCount(m_pUiContext);
  892. ulCnt += 1; // For the guard page
  893. }
  894. }
  895. }
  896. else
  897. {
  898. TraceTag(ttidWizard, "Loading each providers pages");
  899. bCallRasDlgEntry = TRUE;
  900. // Load the pages
  901. for (ulIdx=0; ulIdx<m_ulWizProviderCnt; ulIdx++)
  902. {
  903. Assert(m_rgpWizProviders[ulIdx]);
  904. Assert(0xFFFFFFFF != m_rgpWizProviders[ulIdx]->UlGetMaxPageCount(m_pUiContext));
  905. if (0 != m_rgpWizProviders[ulIdx]->UlGetMaxPageCount(m_pUiContext))
  906. {
  907. HRESULT hrTmp = m_rgpWizProviders[ulIdx]->HrAddPages(m_pUiContext);
  908. TraceHr(ttidWizard, FAL, hrTmp, S_FALSE == hrTmp,
  909. "CWizard::HrCreateWizProviderPages - %d", ulIdx);
  910. // We only care about out of memory errors when adding pages.
  911. // Providers which fail to add pages are removed from the
  912. // provider list m_rgpWizProviders.
  913. //
  914. if (E_OUTOFMEMORY == hrTmp)
  915. {
  916. hr = hrTmp;
  917. goto Error;
  918. }
  919. }
  920. }
  921. // Cull the providers which loaded no pages
  922. ULONG ulNewCnt = 0;
  923. for (ulIdx=0; ulIdx<m_ulWizProviderCnt; ulIdx++)
  924. {
  925. if (0 != m_rgpWizProviders[ulIdx]->ULPageCount())
  926. {
  927. m_rgpWizProviders[ulNewCnt++] = m_rgpWizProviders[ulIdx];
  928. }
  929. else
  930. {
  931. delete m_rgpWizProviders[ulIdx];
  932. }
  933. }
  934. m_ulWizProviderCnt = ulNewCnt;
  935. // Now count how many provider pages were actually loaded, and create
  936. // their associated guard pages
  937. for (ulIdx=0; ulIdx<m_ulWizProviderCnt; ulIdx++)
  938. {
  939. if (m_rgpWizProviders[ulIdx]->ULPageCount())
  940. {
  941. // Create the guard page for this provider
  942. // Note that the guard page's id is (CWizProvider *)
  943. hr = HrCreateGuardPage(this, m_rgpWizProviders[ulIdx]);
  944. if (SUCCEEDED(hr))
  945. {
  946. // Includes the guard page
  947. ulCnt += (m_rgpWizProviders[ulIdx]->ULPageCount() + 1);
  948. }
  949. else
  950. {
  951. m_rgpWizProviders[ulIdx]->DeleteHPages();
  952. TraceHr(ttidWizard, FAL, hr, FALSE,"CWizard::HrCreateWizProviderPages - Guard Page Create Failed");
  953. hr = S_OK;
  954. }
  955. }
  956. }
  957. }
  958. (*pcPages) += ulCnt;
  959. Error:
  960. TraceHr(ttidWizard, FAL, hr, S_FALSE == hr,"CWizard::HrCreateWizProviderPages");
  961. return hr;
  962. }
  963. //
  964. // Function: CWizard:AppendProviderPages
  965. //
  966. // Purpose: Append wizard provider pages and their associated guard pages
  967. // to the HPROPSHEETPAGE array
  968. //
  969. // Parameters: pahpsp [IN,OUT] - Ptr to the HPROPSHEETPAGE array which will
  970. // receive the provider pages.
  971. // pcPages [IN] - Ptr to indicate the number of pages added to
  972. // the pahpsp array
  973. // Returns: nothing
  974. //
  975. VOID CWizard::AppendProviderPages(HPROPSHEETPAGE *pahpsp, UINT *pcPages)
  976. {
  977. TraceFileFunc(ttidGuiModeSetup);
  978. ULONG ulIdx;
  979. // Now count how many provider pages were actually loaded, and create
  980. // their associated guard pages
  981. for (ulIdx=0; ulIdx<m_ulWizProviderCnt; ulIdx++)
  982. {
  983. ULONG ulPageCnt = m_rgpWizProviders[ulIdx]->ULPageCount();
  984. if (ulPageCnt)
  985. {
  986. m_rgpWizProviders[ulIdx]->XFerDeleteResponsibilities();
  987. // Copy the providers pages
  988. memcpy(&pahpsp[*pcPages], m_rgpWizProviders[ulIdx]->PHPropPages(),
  989. sizeof(HPROPSHEETPAGE) * ulPageCnt);
  990. (*pcPages) += ulPageCnt;
  991. // Append the guard page
  992. AppendGuardPage(this, m_rgpWizProviders[ulIdx], pahpsp, pcPages);
  993. }
  994. }
  995. }
  996. //
  997. // Function: CWizard:LoadAndInsertDeferredProviderPages
  998. //
  999. // Purpose: Insert wizard provider pages and their associated guard pages
  1000. // directly into the wizard
  1001. //
  1002. // Parameters: hwndPropSheet [IN] - Handle to the property sheet
  1003. // iddAfterPage [IN] - Page to insert after.
  1004. //
  1005. // Returns: nothing
  1006. //
  1007. VOID CWizard::LoadAndInsertDeferredProviderPages(HWND hwndPropSheet, UINT iddAfterPage)
  1008. {
  1009. TraceFileFunc(ttidGuiModeSetup);
  1010. HRESULT hr;
  1011. UINT cPages = 0;
  1012. // Create the pages
  1013. //
  1014. hr = HrCreateWizProviderPages(FALSE, &cPages);
  1015. if (SUCCEEDED(hr))
  1016. {
  1017. HPROPSHEETPAGE hPage = GetPageHandle(iddAfterPage);
  1018. Assert(hPage);
  1019. for (ULONG ulIdx=0; ulIdx<m_ulWizProviderCnt; ulIdx++)
  1020. {
  1021. ULONG ulPageCnt = m_rgpWizProviders[ulIdx]->ULPageCount();
  1022. Assert(0xFFFFFFFF != ulPageCnt);
  1023. if (ulPageCnt)
  1024. {
  1025. BOOL fRet;
  1026. HPROPSHEETPAGE hpsp = NULL;
  1027. m_rgpWizProviders[ulIdx]->XFerDeleteResponsibilities();
  1028. // Get the guard page and insert
  1029. //
  1030. cPages = 0;
  1031. AppendGuardPage(this, m_rgpWizProviders[ulIdx], &hpsp, &cPages);
  1032. fRet = PropSheet_InsertPage(hwndPropSheet, hPage, hpsp);
  1033. Assert(fRet);
  1034. // Copy the providers pages.
  1035. do
  1036. {
  1037. hpsp = (m_rgpWizProviders[ulIdx]->PHPropPages())[ulPageCnt - 1];
  1038. fRet = PropSheet_InsertPage(hwndPropSheet, hPage, hpsp);
  1039. Assert(fRet);
  1040. }
  1041. while (--ulPageCnt>0);
  1042. }
  1043. }
  1044. }
  1045. TraceHr(ttidWizard, FAL, hr, FALSE,"CWizard::LoadAndInsertDeferredProviderPages");
  1046. }
  1047. //
  1048. // Function: CWizard::RegisterPage
  1049. //
  1050. // Purpose: Allow a wizard internal page to register a callback function
  1051. // and a page specific LPARAM along with the HPROPSHEETPAGE.
  1052. //
  1053. // Parameters: ulId [IN] - A page specific value, must be unique amoung
  1054. // all registering pages
  1055. // hpsp [IN] - Handle to the property page being registered
  1056. // pfnCleanup [IN] - Callback function to call before CWizard
  1057. // is destroyed.
  1058. // lParam [IN] - Page specific parameter.
  1059. //
  1060. // Returns: nothing
  1061. //
  1062. VOID CWizard::RegisterPage(LPARAM ulId, HPROPSHEETPAGE hpsp,
  1063. PFNPAGECLEANPROC pfnCleanup, LPARAM lParam)
  1064. {
  1065. TraceFileFunc(ttidGuiModeSetup);
  1066. #if DBG
  1067. Assert(m_eMaxInternalPages + m_eMaxProviders> m_ulPageDataCnt);
  1068. for (UINT nIdx=0;nIdx<m_ulPageDataCnt; nIdx++)
  1069. {
  1070. Assert(ulId != m_rgPageData[nIdx].ulId);
  1071. }
  1072. #endif
  1073. m_rgPageData[m_ulPageDataCnt].ulId = ulId;
  1074. m_rgPageData[m_ulPageDataCnt].hPage = hpsp;
  1075. m_rgPageData[m_ulPageDataCnt].lParam = lParam;
  1076. m_rgPageData[m_ulPageDataCnt].PageDirection = NWPD_FORWARD;
  1077. m_rgPageData[m_ulPageDataCnt].pfn = pfnCleanup;
  1078. m_ulPageDataCnt++;
  1079. }
  1080. //
  1081. // Function: CWizard::GetPageData
  1082. //
  1083. // Purpose: Retrieve data cached by a page via the RegisterPage
  1084. //
  1085. // Parameters: ulId [IN] - A page specific value, must be unique amoung
  1086. // all registering pages
  1087. //
  1088. // Returns: LPARAM, the data associated with the registered page
  1089. //
  1090. LPARAM CWizard::GetPageData(LPARAM ulId)
  1091. {
  1092. TraceFileFunc(ttidGuiModeSetup);
  1093. Assert(m_ulPageDataMRU < m_ulPageDataCnt);
  1094. if (ulId == m_rgPageData[m_ulPageDataMRU].ulId)
  1095. {
  1096. return (m_rgPageData[m_ulPageDataMRU].lParam);
  1097. }
  1098. for (ULONG ulIdx=0; ulIdx<m_ulPageDataCnt; ulIdx++)
  1099. {
  1100. if (ulId == m_rgPageData[ulIdx].ulId)
  1101. {
  1102. m_ulPageDataMRU = ulIdx;
  1103. return (m_rgPageData[ulIdx].lParam);
  1104. }
  1105. }
  1106. Assert(0); // PageData not found
  1107. return 0L;
  1108. }
  1109. //
  1110. // Function: CWizard::SetPageData
  1111. //
  1112. // Purpose: Set data value for a page registered via the RegisterPage
  1113. //
  1114. // Parameters: ulId [IN] - A page specific value, must be unique amoung
  1115. // all registering pages
  1116. // lParam [IN] - Data to cache with registered page
  1117. //
  1118. // Returns: nothing
  1119. //
  1120. VOID CWizard::SetPageData(LPARAM ulId, LPARAM lParam)
  1121. {
  1122. TraceFileFunc(ttidGuiModeSetup);
  1123. for (ULONG ulIdx=0; ulIdx<m_ulPageDataCnt; ulIdx++)
  1124. {
  1125. if (ulId == m_rgPageData[ulIdx].ulId)
  1126. {
  1127. m_rgPageData[ulIdx].lParam = lParam;
  1128. return;
  1129. }
  1130. }
  1131. Assert(0); // Page not found
  1132. }
  1133. //
  1134. // Function: CWizard::GetPageIndexFromIID
  1135. //
  1136. // Purpose: Set the page index
  1137. //
  1138. // Parameters: ulId [IN] - A page specific value, must be unique amoung
  1139. // all registering pages
  1140. //
  1141. // Returns: nothing
  1142. //
  1143. UINT CWizard::GetPageIndexFromIID(LPARAM ulId)
  1144. {
  1145. TraceFileFunc(ttidGuiModeSetup);
  1146. for (ULONG ulIdx=0; ulIdx<m_ulPageDataCnt; ulIdx++)
  1147. {
  1148. if (ulId == m_rgPageData[ulIdx].ulId)
  1149. {
  1150. return ulIdx;
  1151. }
  1152. }
  1153. AssertSz(0, "GetPageIndexFromIID: Invalid page of the NCW requested"); // Page not found
  1154. return 0;
  1155. }
  1156. // Function: CWizard::GetPageIndexFromHPage
  1157. //
  1158. // Purpose: Set the page index
  1159. //
  1160. // Parameters: hPage [IN] - A PROPSHEETPAGE
  1161. //
  1162. // Returns: nothing
  1163. //
  1164. UINT CWizard::GetPageIndexFromHPage(HPROPSHEETPAGE hPage)
  1165. {
  1166. TraceFileFunc(ttidGuiModeSetup);
  1167. for (ULONG ulIdx = 0; ulIdx < m_ulPageDataCnt; ulIdx++)
  1168. {
  1169. if (hPage == m_rgPageData[ulIdx].hPage)
  1170. {
  1171. return ulIdx;
  1172. }
  1173. }
  1174. AssertSz(0, "GetPageIndexFromHPage: Invalid page of the NCW requested"); // Page not found
  1175. return 0;
  1176. }
  1177. //
  1178. // Function: CWizard::GetPageOrigin
  1179. //
  1180. // Purpose: Retrieve data cached by a page via the RegisterPage
  1181. //
  1182. // Parameters: ulId [IN] - A page specific value, must be unique amoung
  1183. // all registering pages
  1184. //
  1185. // Returns: LPARAM, the data associated with the registered page
  1186. //
  1187. LPARAM CWizard::GetPageOrigin(LPARAM ulId, UINT *pOriginIDC)
  1188. {
  1189. TraceFileFunc(ttidGuiModeSetup);
  1190. Assert(m_ulPageDataMRU < m_ulPageDataCnt);
  1191. if (ulId == m_rgPageData[m_ulPageDataMRU].ulId)
  1192. {
  1193. if (pOriginIDC)
  1194. {
  1195. *pOriginIDC = m_rgPageData[m_ulPageDataMRU].PageOriginIDC;
  1196. }
  1197. return (m_rgPageData[m_ulPageDataMRU].PageOrigin);
  1198. }
  1199. for (ULONG ulIdx=0; ulIdx<m_ulPageDataCnt; ulIdx++)
  1200. {
  1201. if (ulId == m_rgPageData[ulIdx].ulId)
  1202. {
  1203. m_ulPageDataMRU = ulIdx;
  1204. if (pOriginIDC)
  1205. {
  1206. *pOriginIDC = m_rgPageData[ulIdx].PageOriginIDC;
  1207. }
  1208. return (m_rgPageData[ulIdx].PageOrigin);
  1209. }
  1210. }
  1211. Assert(0); // PageData not found
  1212. return 0L;
  1213. }
  1214. //
  1215. // Function: CWizard::SetPageOrigin
  1216. //
  1217. // Purpose: Set data value for a page registered via the RegisterPage
  1218. //
  1219. // Parameters: ulId [IN] - A page specific value, must be unique amoung
  1220. // all registering pages
  1221. // uiOrigin[IN] - Origin of page
  1222. //
  1223. // Returns: nothing
  1224. //
  1225. VOID CWizard::SetPageOrigin(LPARAM ulId, UINT uiOrigin, UINT uiOriginIDC)
  1226. {
  1227. TraceFileFunc(ttidGuiModeSetup);
  1228. for (ULONG ulIdx=0; ulIdx<m_ulPageDataCnt; ulIdx++)
  1229. {
  1230. if (ulId == m_rgPageData[ulIdx].ulId)
  1231. {
  1232. m_rgPageData[ulIdx].PageOrigin = uiOrigin;
  1233. m_rgPageData[ulIdx].PageOriginIDC = uiOriginIDC;
  1234. return;
  1235. }
  1236. }
  1237. Assert(0); // Page not found
  1238. }
  1239. //
  1240. // Function: CWizard::GetPageHandle
  1241. //
  1242. // Purpose: Retrieve PropSheet Page handle cached by a page via the
  1243. // RegisterPage
  1244. //
  1245. // Parameters: ulId [IN] - A page specific value, must be unique amoung
  1246. // all registering pages
  1247. //
  1248. // Returns: HPROPSHEETPAGE, the propsheet handle associated with the
  1249. // registered page
  1250. //
  1251. HPROPSHEETPAGE CWizard::GetPageHandle(LPARAM ulId)
  1252. {
  1253. TraceFileFunc(ttidGuiModeSetup);
  1254. Assert(m_ulPageDataMRU < m_ulPageDataCnt);
  1255. if (ulId == m_rgPageData[m_ulPageDataMRU].ulId)
  1256. {
  1257. return (m_rgPageData[m_ulPageDataMRU].hPage);
  1258. }
  1259. for (ULONG ulIdx=0; ulIdx<m_ulPageDataCnt; ulIdx++)
  1260. {
  1261. if (ulId == m_rgPageData[ulIdx].ulId)
  1262. {
  1263. m_ulPageDataMRU = ulIdx;
  1264. return (m_rgPageData[ulIdx].hPage);
  1265. }
  1266. }
  1267. Assert(0); // Page Handle not found
  1268. return NULL;
  1269. }
  1270. //
  1271. // Function: CWizard::GetPageDirection
  1272. //
  1273. // Purpose: Retrieve page direction associated with a page
  1274. //
  1275. // Parameters: ulId [IN] - A page specific value, must be unique amoung
  1276. // all registering pages
  1277. //
  1278. // Returns: PAGEDIRECTION, the direction of travel associated with the
  1279. // specified page. Note that the meaning of the direction is
  1280. // up to the page. The wizard code initializes all the page
  1281. // directions to NWPD_FORWARD before executing a providers pages.
  1282. //
  1283. PAGEDIRECTION CWizard::GetPageDirection(LPARAM ulId)
  1284. {
  1285. TraceFileFunc(ttidGuiModeSetup);
  1286. Assert(m_ulPageDataMRU < m_ulPageDataCnt);
  1287. if (ulId == m_rgPageData[m_ulPageDataMRU].ulId)
  1288. {
  1289. return (m_rgPageData[m_ulPageDataMRU].PageDirection);
  1290. }
  1291. for (ULONG ulIdx=0; ulIdx<m_ulPageDataCnt; ulIdx++)
  1292. {
  1293. if (ulId == m_rgPageData[ulIdx].ulId)
  1294. {
  1295. m_ulPageDataMRU = ulIdx;
  1296. return (m_rgPageData[ulIdx].PageDirection);
  1297. }
  1298. }
  1299. Assert(0); // PageData not found
  1300. return NWPD_FORWARD;
  1301. }
  1302. //
  1303. // Function: CWizard::SetPageDirection
  1304. //
  1305. // Purpose: Retrieve page direction associated with a page
  1306. //
  1307. // Parameters: ulId [IN] - A page specific value, must be unique amoung
  1308. // all registering pages
  1309. // PageDirection [IN] - the new page direction setting
  1310. //
  1311. // Returns: nothing
  1312. //
  1313. VOID CWizard::SetPageDirection(LPARAM ulId, PAGEDIRECTION PageDirection)
  1314. {
  1315. TraceFileFunc(ttidGuiModeSetup);
  1316. for (ULONG ulIdx=0; ulIdx<m_ulPageDataCnt; ulIdx++)
  1317. {
  1318. if (ulId == m_rgPageData[ulIdx].ulId)
  1319. {
  1320. m_rgPageData[ulIdx].PageDirection = PageDirection;
  1321. return;
  1322. }
  1323. }
  1324. Assert(0); // PageData not found
  1325. }
  1326. //
  1327. // Function: CWizardUiContext::AddRef
  1328. //
  1329. // Purpose: Increment the reference count on this object
  1330. //
  1331. // Parameters: none
  1332. //
  1333. // Returns: ULONG
  1334. //
  1335. STDMETHODIMP_(ULONG) CWizardUiContext::AddRef()
  1336. {
  1337. return ++m_cRef;
  1338. }
  1339. //
  1340. // Function: CWizardUiContext::Release
  1341. //
  1342. // Purpose: Decrement the reference count on this object
  1343. //
  1344. // Parameters: none
  1345. //
  1346. // Returns: ULONG
  1347. //
  1348. STDMETHODIMP_(ULONG) CWizardUiContext::Release()
  1349. {
  1350. ULONG cRef = --m_cRef;
  1351. if (cRef == 0)
  1352. {
  1353. delete this;
  1354. }
  1355. return cRef;
  1356. }
  1357. //
  1358. // Function: CWizardUiContext::QueryInterface
  1359. //
  1360. // Purpose: Allows for the querying of alternate interfaces
  1361. //
  1362. // Parameters: riid [IN] - Interface to retrieve
  1363. // ppvObj [OUT] - Retrieved interface if function succeeds
  1364. //
  1365. // Returns: HRESULT, S_OK on success E_NOINTERFACE on failure
  1366. //
  1367. STDMETHODIMP CWizardUiContext::QueryInterface(REFIID riid, LPVOID FAR *ppvObj)
  1368. {
  1369. HRESULT hr = S_OK;
  1370. *ppvObj = NULL;
  1371. if ((riid == IID_IUnknown) || (riid == IID_INetConnectionWizardUiContext))
  1372. {
  1373. *ppvObj = (LPVOID)this;
  1374. AddRef();
  1375. }
  1376. else
  1377. {
  1378. hr = E_NOINTERFACE;
  1379. }
  1380. return hr;
  1381. }
  1382. STDMETHODIMP CWizardUiContext::GetINetCfg(INetCfg ** ppINetCfg)
  1383. {
  1384. HRESULT hr = E_FAIL;
  1385. if (NULL == ppINetCfg)
  1386. {
  1387. hr = E_INVALIDARG;
  1388. }
  1389. else if (NULL != m_pINetCfg)
  1390. {
  1391. *ppINetCfg = m_pINetCfg;
  1392. AddRefObj(*ppINetCfg);
  1393. hr = S_OK;
  1394. }
  1395. return hr;
  1396. }