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.

1624 lines
46 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. // pWizard [IN] - Pointer to wizard manager.
  463. //
  464. // Returns: HRESULT, S_OK on success
  465. //
  466. HRESULT CAdapterList::HrQueryLanAdapters(INetCfg * pnc, CAdapterList * pAL, CWizard *pWizard)
  467. {
  468. HRESULT hr = S_OK;
  469. CAdapterList ALphys;
  470. CAdapterList ALvirt;
  471. TraceTag(ttidWizard, "CAdapterList::HrQueryLanAdapters - Querying available adapters");
  472. // Enumerate the available adapters
  473. Assert(NULL != pnc);
  474. CIterNetCfgComponent nccIter(pnc, &GUID_DEVCLASS_NET);
  475. INetCfgComponent* pncc;
  476. while (SUCCEEDED(hr) && (S_OK == (hr = nccIter.HrNext(&pncc))))
  477. {
  478. hr = HrIsLanCapableAdapter(pncc);
  479. if (S_OK == hr)
  480. {
  481. DWORD dw;
  482. AdapterEntry ae;
  483. ae.fHide = FALSE;
  484. // Get the adapter instance guid
  485. hr = pncc->GetInstanceGuid(&ae.guidAdapter);
  486. if (FAILED(hr))
  487. goto NextAdapter;
  488. if (IsUpgrade(pWizard))
  489. {
  490. // In case of upgrade, determine if the adapter's connection information
  491. // is already created so that it is not overwritten.
  492. hr = HrIsConnection(pncc);
  493. if (FAILED(hr))
  494. goto NextAdapter;
  495. }
  496. else
  497. {
  498. // It's fresh install. Assume the adapter is new and its connection
  499. // information is not created in the registry yet.
  500. hr = S_FALSE;
  501. }
  502. ae.fProcessed = (S_OK == hr);
  503. ae.fNew = !ae.fProcessed; // It's new if it has not been processed
  504. // Check device, if not present skip it
  505. //
  506. hr = pncc->GetDeviceStatus(&dw);
  507. if (FAILED(hr) || (CM_PROB_DEVICE_NOT_THERE == dw))
  508. {
  509. goto NextAdapter;
  510. }
  511. // Is this a virtual adapter?
  512. hr = pncc->GetCharacteristics(&dw);
  513. if (FAILED(hr))
  514. goto NextAdapter;
  515. ae.fVirtual = ((dw & NCF_VIRTUAL) ? TRUE : FALSE);
  516. // Add the entry to the appropriate list
  517. if (ae.fVirtual)
  518. {
  519. hr = ALvirt.HrAppendEntries(&ae, 1);
  520. }
  521. else
  522. {
  523. hr = ALphys.HrAppendEntries(&ae, 1);
  524. }
  525. if (FAILED(hr))
  526. goto NextAdapter;
  527. // Note the fact that LAN capable adapters exist.
  528. // Because in setup we will show the join page.
  529. pAL->m_fAdaptersInstalled = TRUE;
  530. }
  531. NextAdapter:
  532. ReleaseObj(pncc);
  533. hr = S_OK;
  534. }
  535. if (SUCCEEDED(hr))
  536. {
  537. // Merge the physical and virtual lists into the pAL input variable
  538. pAL->EmptyList();
  539. hr = pAL->HrAppendEntries(ALphys.m_prgAdapters, ALphys.m_clAdapters);
  540. if (SUCCEEDED(hr))
  541. {
  542. hr = pAL->HrAppendEntries(ALvirt.m_prgAdapters, ALvirt.m_clAdapters);
  543. }
  544. }
  545. TraceHr(ttidWizard, FAL, hr, FALSE, "CAdapterList::HrQueryUnboundAdapters");
  546. return hr;
  547. }
  548. HRESULT CAdapterList::HrCreateTypicalConnections(CWizard * pWizard)
  549. {
  550. HRESULT hr = S_OK;
  551. // If there are no adapters in the queue or we have no LAN provider...
  552. if (0 == pWizard->UlProviderCount())
  553. {
  554. return S_OK;
  555. }
  556. // Set the current provider
  557. pWizard->SetCurrentProvider(0);
  558. CWizProvider * pWizProvider = pWizard->GetCurrentProvider();
  559. Assert(NULL != pWizProvider);
  560. TraceTag(ttidWizard, "CAdapterList::HrCreateTypicalConnections - Creating any new LAN connections.");
  561. // For each adapter in the list create a connection
  562. for (LONG lIdx=0; lIdx<m_clAdapters; lIdx++)
  563. {
  564. AdapterEntry * pae = &m_prgAdapters[lIdx];
  565. if (!pae->fProcessed)
  566. {
  567. #if DBG
  568. WCHAR szGuid[c_cchGuidWithTerm];
  569. szGuid[0] = 0;
  570. StringFromGUID2(pae->guidAdapter, szGuid, c_cchGuidWithTerm);
  571. TraceTag(ttidWizard, " Guid: %S",szGuid);
  572. #endif
  573. pae->fProcessed = TRUE;
  574. // Push the adapter guid onto the provider
  575. hr = pWizProvider->HrSpecifyAdapterGuid(&(pae->guidAdapter));
  576. if (SUCCEEDED(hr))
  577. {
  578. tstring str;
  579. INetConnection * pConn = NULL;
  580. GenerateUniqueConnectionName(pae->guidAdapter, &str, pWizProvider);
  581. TraceTag(ttidWizard, " Name: %S", str.c_str());
  582. hr = (pWizProvider->PWizardUi())->GetNewConnection(&pConn);
  583. ReleaseObj(pConn);
  584. }
  585. // If we failed to create a connection we need to mark it as hidden
  586. // so it will be skipped in the future. Eat the error or otherwise
  587. // setup will just stop.
  588. //
  589. if (FAILED(hr))
  590. {
  591. TraceHr(ttidWizard, FAL, hr, FALSE, "CAdapterList::HrCreateTypicalConnections - failed creating the connection");
  592. pae->fHide = TRUE;
  593. hr = S_OK;
  594. }
  595. }
  596. }
  597. // Ask the LAN provider to release any cached pointers.
  598. //
  599. (VOID)pWizProvider->HrSpecifyAdapterGuid(NULL);
  600. TraceHr(ttidWizard, FAL, hr, FALSE, "CAdapterList::HrCreateTypicalConnections");
  601. return hr;
  602. }
  603. HRESULT CAdapterList::HrQueryUnboundAdapters(CWizard * pWizard)
  604. {
  605. HRESULT hr = S_OK;
  606. LONG lIdx;
  607. Assert(NULL != pWizard->PNetCfg());
  608. // Handle the first time the adapters are queried
  609. if (0 == m_clAdapters)
  610. {
  611. hr = HrQueryLanAdapters(pWizard->PNetCfg(), this, pWizard);
  612. if (SUCCEEDED(hr))
  613. {
  614. // Mark all already bound adapters as hidden so they
  615. // won't be displayed in the UI
  616. for (lIdx=0; lIdx<m_clAdapters; lIdx++)
  617. {
  618. m_prgAdapters[lIdx].fHide = m_prgAdapters[lIdx].fProcessed;
  619. }
  620. // Create connections for all unbound adapters
  621. hr = HrCreateTypicalConnections(pWizard);
  622. }
  623. }
  624. else
  625. {
  626. CAdapterList AL;
  627. // Query the current adapters
  628. hr = HrQueryLanAdapters(pWizard->PNetCfg(), &AL, pWizard);
  629. if (FAILED(hr))
  630. goto Error;
  631. // Eliminate adapters in the original set which are not
  632. // present in new list
  633. for (lIdx=0; lIdx<m_clAdapters; lIdx++)
  634. {
  635. BOOL fFound = FALSE;
  636. LONG lIdxTemp;
  637. for (lIdxTemp=0; lIdxTemp<AL.m_clAdapters; lIdxTemp++)
  638. {
  639. if (m_prgAdapters[lIdx].guidAdapter ==
  640. AL.m_prgAdapters[lIdxTemp].guidAdapter)
  641. {
  642. fFound = TRUE;
  643. break;
  644. }
  645. }
  646. if (fFound)
  647. {
  648. // Compress the located adapter from the new set
  649. if (lIdxTemp + 1 < AL.m_clAdapters)
  650. {
  651. memcpy(&AL.m_prgAdapters[lIdxTemp],
  652. &AL.m_prgAdapters[lIdxTemp+1],
  653. sizeof(AdapterEntry) *
  654. (AL.m_clAdapters - (lIdxTemp + 1)));
  655. }
  656. AL.m_clAdapters--;
  657. }
  658. else
  659. {
  660. // The source adapter is no longer in the set
  661. if (lIdx < m_lIdx)
  662. m_lIdx--;
  663. }
  664. }
  665. Assert(m_lIdx <= m_clAdapters);
  666. if (m_lIdx == m_clAdapters)
  667. m_lIdx = m_clAdapters-1;
  668. // Create connections for the new adapters
  669. hr = AL.HrCreateTypicalConnections(pWizard);
  670. if (FAILED(hr))
  671. goto Error;
  672. // Append new adapters to the original list
  673. hr = HrAppendEntries(AL.m_prgAdapters, AL.m_clAdapters);
  674. }
  675. Error:
  676. TraceHr(ttidWizard, FAL, hr, FALSE, "CAdapterList::HrQueryUnboundAdapters");
  677. return hr;
  678. }
  679. //
  680. // Function: CWizard::CWizard
  681. //
  682. // Purpose: ctor for the CWizard class
  683. //
  684. // Parameters: fLanPages [IN] - Processing LAN pages
  685. // pdata [IN] - Wizard context info
  686. // fDeferred [IN] - Defered loading of providers
  687. //
  688. // Returns: nothing
  689. //
  690. CWizard::CWizard(BOOL fLanPages, PINTERNAL_SETUP_DATA pData, BOOL fDeferred)
  691. {
  692. TraceFileFunc(ttidGuiModeSetup);
  693. m_fLanPages = fLanPages;
  694. m_fExitNoReturn = FALSE;
  695. m_fCoUninit = FALSE;
  696. m_fDeferredProviderLoad = fDeferred;
  697. m_fProviderChanged = FALSE;
  698. m_dwFirstPage = 0;
  699. m_pConn = NULL;
  700. m_pNetCfg = NULL;
  701. m_pUiContext = NULL;
  702. Assert(NULL != pData);
  703. m_pSetupData = pData;
  704. m_dwOperationFlags = pData->OperationFlags;
  705. m_UMMode = UM_DEFAULTHIDE;
  706. m_ulCurProvider = 0;
  707. m_ulPageDataCnt = 0;
  708. ZeroMemory(m_rgPageData, sizeof(m_rgPageData));
  709. m_ulWizProviderCnt = 0;
  710. m_ulPageDataMRU = 0;
  711. ZeroMemory(m_rgpWizProviders, sizeof(m_rgpWizProviders));
  712. }
  713. //
  714. // Function: CWizard::~CWizard
  715. //
  716. // Purpose: dtor for the CWizProvider class
  717. //
  718. // Parameters: none
  719. //
  720. // Returns: nothing
  721. //
  722. // Note: Remove CWizard member re-init from dtor. Present only
  723. // to ensure complete appropriate release of all members
  724. CWizard::~CWizard()
  725. {
  726. TraceFileFunc(ttidGuiModeSetup);
  727. ULONG ulIdx;
  728. // Call the cleanup callback for all registered wizard internal pages
  729. for (ulIdx = 0; ulIdx < m_ulPageDataCnt; ulIdx++)
  730. {
  731. if (m_rgPageData[ulIdx].pfn)
  732. {
  733. m_rgPageData[ulIdx].pfn(this, m_rgPageData[ulIdx].lParam);
  734. }
  735. }
  736. m_ulPageDataCnt = 0L;
  737. // Note: Do not release m_pSetupData, it's only a reference
  738. m_pSetupData = NULL;
  739. // Release any providers that had been retained
  740. for (ulIdx = 0; ulIdx < m_ulWizProviderCnt; ulIdx++)
  741. {
  742. Assert(0 != m_rgpWizProviders[ulIdx]);
  743. delete m_rgpWizProviders[ulIdx];
  744. m_rgpWizProviders[ulIdx] = NULL;
  745. }
  746. m_ulWizProviderCnt = 0L;
  747. m_ulCurProvider = 0;
  748. ReleaseObj(m_pUiContext);
  749. m_pUiContext = NULL;
  750. ReleaseObj(m_pConn);
  751. m_pConn = NULL;
  752. if (m_pNetCfg)
  753. {
  754. (VOID)HrUninitializeAndReleaseINetCfg(FCoUninit(), m_pNetCfg, TRUE);
  755. }
  756. m_pNetCfg = NULL;
  757. }
  758. //
  759. // Function: CWizard::HrCreate
  760. //
  761. // Purpose: Two phase constructor for the CWizard class
  762. //
  763. // Parameters: ppWizard [OUT] - If this function succeeds this pointer
  764. // will contain the constructed and
  765. // fLanPages [IN] - Processing LAN pages
  766. // initialized CWizard instance.
  767. // pdata [IN] - Wizard Context info
  768. // fDeferred [IN] - Providers are defer loaded
  769. //
  770. // Returns: HRESULT, S_OK on success
  771. //
  772. NOTHROW
  773. HRESULT CWizard::HrCreate(CWizard ** ppWizard,
  774. BOOL fLanPages,
  775. PINTERNAL_SETUP_DATA pData,
  776. BOOL fDeferred)
  777. {
  778. TraceFileFunc(ttidGuiModeSetup);
  779. HRESULT hr = S_OK;
  780. CWizardUiContext * pContext = NULL;
  781. CWizard * pWiz = NULL;
  782. Assert(NULL != ppWizard);
  783. // Initialize output parameters
  784. *ppWizard = NULL;
  785. // Create the CWizard instance
  786. pWiz = new CWizard(fLanPages, pData, fDeferred);
  787. pContext = new CWizardUiContext(pData);
  788. if ((NULL != pWiz) && (NULL != pContext))
  789. {
  790. // Save the new instance
  791. pWiz->m_pUiContext = pContext;
  792. *ppWizard = pWiz;
  793. }
  794. else
  795. {
  796. hr = E_OUTOFMEMORY;
  797. }
  798. TraceHr(ttidWizard, FAL, hr, FALSE, "CWizard::HrCreate");
  799. return hr;
  800. }
  801. //
  802. // Function: CWizard::HrAddProvider
  803. //
  804. // Purpose: To add a connection provider to list of currently loaded
  805. // connection providers
  806. //
  807. // Parameters: pPL [IN] - GUID of conection provider which implements the
  808. // INetConnectionWizardUi interface.
  809. //
  810. // Returns: HRESULT, S_OK on success
  811. //
  812. NOTHROW
  813. HRESULT CWizard::HrAddProvider(ProviderList *pPL)
  814. {
  815. TraceFileFunc(ttidGuiModeSetup);
  816. HRESULT hr = E_OUTOFMEMORY;
  817. CWizProvider * pProvider = NULL;
  818. Assert(NULL != pPL);
  819. Assert(m_eMaxProviders > m_ulWizProviderCnt);
  820. // Restrict the total number of providers managed
  821. if (m_eMaxProviders > m_ulWizProviderCnt)
  822. {
  823. // Instantiate a provider
  824. hr = CWizProvider::HrCreate(pPL, &pProvider,
  825. FDeferredProviderLoad());
  826. if (SUCCEEDED(hr))
  827. {
  828. m_rgpWizProviders[m_ulWizProviderCnt++] = pProvider;
  829. }
  830. }
  831. TraceHr(ttidWizard, FAL, hr, (REGDB_E_CLASSNOTREG == hr), "CWizard::HrAddProvider");
  832. return hr;
  833. }
  834. //
  835. // Function: CWizard::LoadWizProviders
  836. //
  837. // Purpose: Load the requested wizard providers
  838. //
  839. // Parameters: ulCntProviders [IN] - Count of guids in rgpguidProviders
  840. // rgProviders [IN] - Guids of the providers to load
  841. //
  842. // Returns: none
  843. //
  844. VOID CWizard::LoadWizProviders( ULONG ulCntProviders,
  845. ProviderList * rgProviders)
  846. {
  847. if (0 == m_ulWizProviderCnt)
  848. {
  849. TraceTag(ttidWizard, "Loading requested providers");
  850. // Load the connections providers used during Setup
  851. for (UINT nIdx=0; nIdx < ulCntProviders; nIdx++)
  852. {
  853. HRESULT hr = HrAddProvider(&rgProviders[nIdx]);
  854. TraceHr(ttidWizard, FAL, hr, FALSE,
  855. "FSetupRequestWizardPages - Failed to load provider #%d",nIdx);
  856. }
  857. }
  858. }
  859. //
  860. // Function: CWizard::HrCreateWizProviderPages
  861. //
  862. // Purpose: Load the requested wizard provider's pages, if requested.
  863. // Otherwise return the expected page count.
  864. //
  865. // Parameters: fCountOnly [IN] - If True, only the maximum number of
  866. // pages this routine will create need
  867. // be determined.
  868. // pnPages [IN] - Increment by the number of pages
  869. // to create/created
  870. //
  871. // Returns: HRESULT, S_OK on success
  872. //
  873. HRESULT CWizard::HrCreateWizProviderPages(BOOL fCountOnly, UINT *pcPages)
  874. {
  875. TraceFileFunc(ttidGuiModeSetup);
  876. HRESULT hr = S_OK;
  877. ULONG ulCnt = 0;
  878. ULONG ulIdx;
  879. Assert(NULL != m_pSetupData);
  880. Assert(NULL != m_pUiContext);
  881. // If provider loading was deferred, load them now
  882. //
  883. if (FDeferredProviderLoad())
  884. {
  885. // Count the maximum number of pages
  886. for (ulIdx=0; ulIdx<m_ulWizProviderCnt; ulIdx++)
  887. {
  888. HRESULT hrTmp = m_rgpWizProviders[ulIdx]->HrCompleteDeferredLoad();
  889. }
  890. // Deferred Load is no longer true. Reset the state
  891. //
  892. DeferredLoadComplete();
  893. }
  894. if (fCountOnly)
  895. {
  896. // Count the maximum number of pages
  897. for (ulIdx=0; ulIdx<m_ulWizProviderCnt; ulIdx++)
  898. {
  899. Assert(m_rgpWizProviders[ulIdx]);
  900. if (m_rgpWizProviders[ulIdx]->UlGetMaxPageCount(m_pUiContext))
  901. {
  902. ulCnt += m_rgpWizProviders[ulIdx]->UlGetMaxPageCount(m_pUiContext);
  903. ulCnt += 1; // For the guard page
  904. }
  905. }
  906. }
  907. else
  908. {
  909. TraceTag(ttidWizard, "Loading each providers pages");
  910. bCallRasDlgEntry = TRUE;
  911. // Load the pages
  912. for (ulIdx=0; ulIdx<m_ulWizProviderCnt; ulIdx++)
  913. {
  914. Assert(m_rgpWizProviders[ulIdx]);
  915. Assert(0xFFFFFFFF != m_rgpWizProviders[ulIdx]->UlGetMaxPageCount(m_pUiContext));
  916. if (0 != m_rgpWizProviders[ulIdx]->UlGetMaxPageCount(m_pUiContext))
  917. {
  918. HRESULT hrTmp = m_rgpWizProviders[ulIdx]->HrAddPages(m_pUiContext);
  919. TraceHr(ttidWizard, FAL, hrTmp, S_FALSE == hrTmp,
  920. "CWizard::HrCreateWizProviderPages - %d", ulIdx);
  921. // We only care about out of memory errors when adding pages.
  922. // Providers which fail to add pages are removed from the
  923. // provider list m_rgpWizProviders.
  924. //
  925. if (E_OUTOFMEMORY == hrTmp)
  926. {
  927. hr = hrTmp;
  928. goto Error;
  929. }
  930. }
  931. }
  932. // Cull the providers which loaded no pages
  933. ULONG ulNewCnt = 0;
  934. for (ulIdx=0; ulIdx<m_ulWizProviderCnt; ulIdx++)
  935. {
  936. if (0 != m_rgpWizProviders[ulIdx]->ULPageCount())
  937. {
  938. m_rgpWizProviders[ulNewCnt++] = m_rgpWizProviders[ulIdx];
  939. }
  940. else
  941. {
  942. delete m_rgpWizProviders[ulIdx];
  943. }
  944. }
  945. m_ulWizProviderCnt = ulNewCnt;
  946. // Now count how many provider pages were actually loaded, and create
  947. // their associated guard pages
  948. for (ulIdx=0; ulIdx<m_ulWizProviderCnt; ulIdx++)
  949. {
  950. if (m_rgpWizProviders[ulIdx]->ULPageCount())
  951. {
  952. // Create the guard page for this provider
  953. // Note that the guard page's id is (CWizProvider *)
  954. hr = HrCreateGuardPage(this, m_rgpWizProviders[ulIdx]);
  955. if (SUCCEEDED(hr))
  956. {
  957. // Includes the guard page
  958. ulCnt += (m_rgpWizProviders[ulIdx]->ULPageCount() + 1);
  959. }
  960. else
  961. {
  962. m_rgpWizProviders[ulIdx]->DeleteHPages();
  963. TraceHr(ttidWizard, FAL, hr, FALSE,"CWizard::HrCreateWizProviderPages - Guard Page Create Failed");
  964. hr = S_OK;
  965. }
  966. }
  967. }
  968. }
  969. (*pcPages) += ulCnt;
  970. Error:
  971. TraceHr(ttidWizard, FAL, hr, S_FALSE == hr,"CWizard::HrCreateWizProviderPages");
  972. return hr;
  973. }
  974. //
  975. // Function: CWizard:AppendProviderPages
  976. //
  977. // Purpose: Append wizard provider pages and their associated guard pages
  978. // to the HPROPSHEETPAGE array
  979. //
  980. // Parameters: pahpsp [IN,OUT] - Ptr to the HPROPSHEETPAGE array which will
  981. // receive the provider pages.
  982. // pcPages [IN] - Ptr to indicate the number of pages added to
  983. // the pahpsp array
  984. // Returns: nothing
  985. //
  986. VOID CWizard::AppendProviderPages(HPROPSHEETPAGE *pahpsp, UINT *pcPages)
  987. {
  988. TraceFileFunc(ttidGuiModeSetup);
  989. ULONG ulIdx;
  990. // Now count how many provider pages were actually loaded, and create
  991. // their associated guard pages
  992. for (ulIdx=0; ulIdx<m_ulWizProviderCnt; ulIdx++)
  993. {
  994. ULONG ulPageCnt = m_rgpWizProviders[ulIdx]->ULPageCount();
  995. if (ulPageCnt)
  996. {
  997. m_rgpWizProviders[ulIdx]->XFerDeleteResponsibilities();
  998. // Copy the providers pages
  999. memcpy(&pahpsp[*pcPages], m_rgpWizProviders[ulIdx]->PHPropPages(),
  1000. sizeof(HPROPSHEETPAGE) * ulPageCnt);
  1001. (*pcPages) += ulPageCnt;
  1002. // Append the guard page
  1003. AppendGuardPage(this, m_rgpWizProviders[ulIdx], pahpsp, pcPages);
  1004. }
  1005. }
  1006. }
  1007. //
  1008. // Function: CWizard:LoadAndInsertDeferredProviderPages
  1009. //
  1010. // Purpose: Insert wizard provider pages and their associated guard pages
  1011. // directly into the wizard
  1012. //
  1013. // Parameters: hwndPropSheet [IN] - Handle to the property sheet
  1014. // iddAfterPage [IN] - Page to insert after.
  1015. //
  1016. // Returns: nothing
  1017. //
  1018. VOID CWizard::LoadAndInsertDeferredProviderPages(HWND hwndPropSheet, UINT iddAfterPage)
  1019. {
  1020. TraceFileFunc(ttidGuiModeSetup);
  1021. HRESULT hr;
  1022. UINT cPages = 0;
  1023. // Create the pages
  1024. //
  1025. hr = HrCreateWizProviderPages(FALSE, &cPages);
  1026. if (SUCCEEDED(hr))
  1027. {
  1028. HPROPSHEETPAGE hPage = GetPageHandle(iddAfterPage);
  1029. Assert(hPage);
  1030. for (ULONG ulIdx=0; ulIdx<m_ulWizProviderCnt; ulIdx++)
  1031. {
  1032. ULONG ulPageCnt = m_rgpWizProviders[ulIdx]->ULPageCount();
  1033. Assert(0xFFFFFFFF != ulPageCnt);
  1034. if (ulPageCnt)
  1035. {
  1036. BOOL fRet;
  1037. HPROPSHEETPAGE hpsp = NULL;
  1038. m_rgpWizProviders[ulIdx]->XFerDeleteResponsibilities();
  1039. // Get the guard page and insert
  1040. //
  1041. cPages = 0;
  1042. AppendGuardPage(this, m_rgpWizProviders[ulIdx], &hpsp, &cPages);
  1043. fRet = (BOOL)PropSheet_InsertPage(hwndPropSheet, hPage, hpsp);
  1044. Assert(fRet);
  1045. // Copy the providers pages.
  1046. do
  1047. {
  1048. hpsp = (m_rgpWizProviders[ulIdx]->PHPropPages())[ulPageCnt - 1];
  1049. fRet = (BOOL)PropSheet_InsertPage(hwndPropSheet, hPage, hpsp);
  1050. Assert(fRet);
  1051. }
  1052. while (--ulPageCnt>0);
  1053. }
  1054. }
  1055. }
  1056. TraceHr(ttidWizard, FAL, hr, FALSE,"CWizard::LoadAndInsertDeferredProviderPages");
  1057. }
  1058. //
  1059. // Function: CWizard::RegisterPage
  1060. //
  1061. // Purpose: Allow a wizard internal page to register a callback function
  1062. // and a page specific LPARAM along with the HPROPSHEETPAGE.
  1063. //
  1064. // Parameters: ulId [IN] - A page specific value, must be unique amoung
  1065. // all registering pages
  1066. // hpsp [IN] - Handle to the property page being registered
  1067. // pfnCleanup [IN] - Callback function to call before CWizard
  1068. // is destroyed.
  1069. // lParam [IN] - Page specific parameter.
  1070. //
  1071. // Returns: nothing
  1072. //
  1073. VOID CWizard::RegisterPage(LPARAM ulId, HPROPSHEETPAGE hpsp,
  1074. PFNPAGECLEANPROC pfnCleanup, LPARAM lParam)
  1075. {
  1076. TraceFileFunc(ttidGuiModeSetup);
  1077. #if DBG
  1078. Assert(m_eMaxInternalPages + m_eMaxProviders> m_ulPageDataCnt);
  1079. for (UINT nIdx=0;nIdx<m_ulPageDataCnt; nIdx++)
  1080. {
  1081. Assert(ulId != m_rgPageData[nIdx].ulId);
  1082. }
  1083. #endif
  1084. m_rgPageData[m_ulPageDataCnt].ulId = ulId;
  1085. m_rgPageData[m_ulPageDataCnt].hPage = hpsp;
  1086. m_rgPageData[m_ulPageDataCnt].lParam = lParam;
  1087. m_rgPageData[m_ulPageDataCnt].PageDirection = NWPD_FORWARD;
  1088. m_rgPageData[m_ulPageDataCnt].pfn = pfnCleanup;
  1089. m_ulPageDataCnt++;
  1090. }
  1091. //
  1092. // Function: CWizard::GetPageData
  1093. //
  1094. // Purpose: Retrieve data cached by a page via the RegisterPage
  1095. //
  1096. // Parameters: ulId [IN] - A page specific value, must be unique amoung
  1097. // all registering pages
  1098. //
  1099. // Returns: LPARAM, the data associated with the registered page
  1100. //
  1101. LPARAM CWizard::GetPageData(LPARAM ulId)
  1102. {
  1103. TraceFileFunc(ttidGuiModeSetup);
  1104. Assert(m_ulPageDataMRU < m_ulPageDataCnt);
  1105. if (ulId == m_rgPageData[m_ulPageDataMRU].ulId)
  1106. {
  1107. return (m_rgPageData[m_ulPageDataMRU].lParam);
  1108. }
  1109. for (ULONG ulIdx=0; ulIdx<m_ulPageDataCnt; ulIdx++)
  1110. {
  1111. if (ulId == m_rgPageData[ulIdx].ulId)
  1112. {
  1113. m_ulPageDataMRU = ulIdx;
  1114. return (m_rgPageData[ulIdx].lParam);
  1115. }
  1116. }
  1117. Assert(0); // PageData not found
  1118. return 0L;
  1119. }
  1120. //
  1121. // Function: CWizard::SetPageData
  1122. //
  1123. // Purpose: Set data value for a page registered via the RegisterPage
  1124. //
  1125. // Parameters: ulId [IN] - A page specific value, must be unique amoung
  1126. // all registering pages
  1127. // lParam [IN] - Data to cache with registered page
  1128. //
  1129. // Returns: nothing
  1130. //
  1131. VOID CWizard::SetPageData(LPARAM ulId, LPARAM lParam)
  1132. {
  1133. TraceFileFunc(ttidGuiModeSetup);
  1134. for (ULONG ulIdx=0; ulIdx<m_ulPageDataCnt; ulIdx++)
  1135. {
  1136. if (ulId == m_rgPageData[ulIdx].ulId)
  1137. {
  1138. m_rgPageData[ulIdx].lParam = lParam;
  1139. return;
  1140. }
  1141. }
  1142. Assert(0); // Page not found
  1143. }
  1144. //
  1145. // Function: CWizard::GetPageIndexFromIID
  1146. //
  1147. // Purpose: Set the page index
  1148. //
  1149. // Parameters: ulId [IN] - A page specific value, must be unique amoung
  1150. // all registering pages
  1151. //
  1152. // Returns: nothing
  1153. //
  1154. UINT CWizard::GetPageIndexFromIID(LPARAM ulId)
  1155. {
  1156. TraceFileFunc(ttidGuiModeSetup);
  1157. for (ULONG ulIdx=0; ulIdx<m_ulPageDataCnt; ulIdx++)
  1158. {
  1159. if (ulId == m_rgPageData[ulIdx].ulId)
  1160. {
  1161. return ulIdx;
  1162. }
  1163. }
  1164. AssertSz(0, "GetPageIndexFromIID: Invalid page of the NCW requested"); // Page not found
  1165. return 0;
  1166. }
  1167. // Function: CWizard::GetPageIndexFromHPage
  1168. //
  1169. // Purpose: Set the page index
  1170. //
  1171. // Parameters: hPage [IN] - A PROPSHEETPAGE
  1172. //
  1173. // Returns: nothing
  1174. //
  1175. UINT CWizard::GetPageIndexFromHPage(HPROPSHEETPAGE hPage)
  1176. {
  1177. TraceFileFunc(ttidGuiModeSetup);
  1178. for (ULONG ulIdx = 0; ulIdx < m_ulPageDataCnt; ulIdx++)
  1179. {
  1180. if (hPage == m_rgPageData[ulIdx].hPage)
  1181. {
  1182. return ulIdx;
  1183. }
  1184. }
  1185. AssertSz(0, "GetPageIndexFromHPage: Invalid page of the NCW requested"); // Page not found
  1186. return 0;
  1187. }
  1188. //
  1189. // Function: CWizard::GetPageOrigin
  1190. //
  1191. // Purpose: Retrieve data cached by a page via the RegisterPage
  1192. //
  1193. // Parameters: ulId [IN] - A page specific value, must be unique amoung
  1194. // all registering pages
  1195. //
  1196. // Returns: LPARAM, the data associated with the registered page
  1197. //
  1198. LPARAM CWizard::GetPageOrigin(LPARAM ulId, UINT *pOriginIDC)
  1199. {
  1200. TraceFileFunc(ttidGuiModeSetup);
  1201. Assert(m_ulPageDataMRU < m_ulPageDataCnt);
  1202. if (ulId == m_rgPageData[m_ulPageDataMRU].ulId)
  1203. {
  1204. if (pOriginIDC)
  1205. {
  1206. *pOriginIDC = m_rgPageData[m_ulPageDataMRU].PageOriginIDC;
  1207. }
  1208. return (m_rgPageData[m_ulPageDataMRU].PageOrigin);
  1209. }
  1210. for (ULONG ulIdx=0; ulIdx<m_ulPageDataCnt; ulIdx++)
  1211. {
  1212. if (ulId == m_rgPageData[ulIdx].ulId)
  1213. {
  1214. m_ulPageDataMRU = ulIdx;
  1215. if (pOriginIDC)
  1216. {
  1217. *pOriginIDC = m_rgPageData[ulIdx].PageOriginIDC;
  1218. }
  1219. return (m_rgPageData[ulIdx].PageOrigin);
  1220. }
  1221. }
  1222. Assert(0); // PageData not found
  1223. return 0L;
  1224. }
  1225. //
  1226. // Function: CWizard::SetPageOrigin
  1227. //
  1228. // Purpose: Set data value for a page registered via the RegisterPage
  1229. //
  1230. // Parameters: ulId [IN] - A page specific value, must be unique amoung
  1231. // all registering pages
  1232. // uiOrigin[IN] - Origin of page
  1233. //
  1234. // Returns: nothing
  1235. //
  1236. VOID CWizard::SetPageOrigin(LPARAM ulId, UINT uiOrigin, UINT uiOriginIDC)
  1237. {
  1238. TraceFileFunc(ttidGuiModeSetup);
  1239. for (ULONG ulIdx=0; ulIdx<m_ulPageDataCnt; ulIdx++)
  1240. {
  1241. if (ulId == m_rgPageData[ulIdx].ulId)
  1242. {
  1243. m_rgPageData[ulIdx].PageOrigin = uiOrigin;
  1244. m_rgPageData[ulIdx].PageOriginIDC = uiOriginIDC;
  1245. return;
  1246. }
  1247. }
  1248. Assert(0); // Page not found
  1249. }
  1250. //
  1251. // Function: CWizard::GetPageHandle
  1252. //
  1253. // Purpose: Retrieve PropSheet Page handle cached by a page via the
  1254. // RegisterPage
  1255. //
  1256. // Parameters: ulId [IN] - A page specific value, must be unique amoung
  1257. // all registering pages
  1258. //
  1259. // Returns: HPROPSHEETPAGE, the propsheet handle associated with the
  1260. // registered page
  1261. //
  1262. HPROPSHEETPAGE CWizard::GetPageHandle(LPARAM ulId)
  1263. {
  1264. TraceFileFunc(ttidGuiModeSetup);
  1265. Assert(m_ulPageDataMRU < m_ulPageDataCnt);
  1266. if (ulId == m_rgPageData[m_ulPageDataMRU].ulId)
  1267. {
  1268. return (m_rgPageData[m_ulPageDataMRU].hPage);
  1269. }
  1270. for (ULONG ulIdx=0; ulIdx<m_ulPageDataCnt; ulIdx++)
  1271. {
  1272. if (ulId == m_rgPageData[ulIdx].ulId)
  1273. {
  1274. m_ulPageDataMRU = ulIdx;
  1275. return (m_rgPageData[ulIdx].hPage);
  1276. }
  1277. }
  1278. Assert(0); // Page Handle not found
  1279. return NULL;
  1280. }
  1281. //
  1282. // Function: CWizard::GetPageDirection
  1283. //
  1284. // Purpose: Retrieve page direction associated with a page
  1285. //
  1286. // Parameters: ulId [IN] - A page specific value, must be unique amoung
  1287. // all registering pages
  1288. //
  1289. // Returns: PAGEDIRECTION, the direction of travel associated with the
  1290. // specified page. Note that the meaning of the direction is
  1291. // up to the page. The wizard code initializes all the page
  1292. // directions to NWPD_FORWARD before executing a providers pages.
  1293. //
  1294. PAGEDIRECTION CWizard::GetPageDirection(LPARAM ulId)
  1295. {
  1296. TraceFileFunc(ttidGuiModeSetup);
  1297. Assert(m_ulPageDataMRU < m_ulPageDataCnt);
  1298. if (ulId == m_rgPageData[m_ulPageDataMRU].ulId)
  1299. {
  1300. return (m_rgPageData[m_ulPageDataMRU].PageDirection);
  1301. }
  1302. for (ULONG ulIdx=0; ulIdx<m_ulPageDataCnt; ulIdx++)
  1303. {
  1304. if (ulId == m_rgPageData[ulIdx].ulId)
  1305. {
  1306. m_ulPageDataMRU = ulIdx;
  1307. return (m_rgPageData[ulIdx].PageDirection);
  1308. }
  1309. }
  1310. Assert(0); // PageData not found
  1311. return NWPD_FORWARD;
  1312. }
  1313. //
  1314. // Function: CWizard::SetPageDirection
  1315. //
  1316. // Purpose: Retrieve page direction associated with a page
  1317. //
  1318. // Parameters: ulId [IN] - A page specific value, must be unique amoung
  1319. // all registering pages
  1320. // PageDirection [IN] - the new page direction setting
  1321. //
  1322. // Returns: nothing
  1323. //
  1324. VOID CWizard::SetPageDirection(LPARAM ulId, PAGEDIRECTION PageDirection)
  1325. {
  1326. TraceFileFunc(ttidGuiModeSetup);
  1327. for (ULONG ulIdx=0; ulIdx<m_ulPageDataCnt; ulIdx++)
  1328. {
  1329. if (ulId == m_rgPageData[ulIdx].ulId)
  1330. {
  1331. m_rgPageData[ulIdx].PageDirection = PageDirection;
  1332. return;
  1333. }
  1334. }
  1335. Assert(0); // PageData not found
  1336. }
  1337. //
  1338. // Function: CWizardUiContext::AddRef
  1339. //
  1340. // Purpose: Increment the reference count on this object
  1341. //
  1342. // Parameters: none
  1343. //
  1344. // Returns: ULONG
  1345. //
  1346. STDMETHODIMP_(ULONG) CWizardUiContext::AddRef()
  1347. {
  1348. return ++m_cRef;
  1349. }
  1350. //
  1351. // Function: CWizardUiContext::Release
  1352. //
  1353. // Purpose: Decrement the reference count on this object
  1354. //
  1355. // Parameters: none
  1356. //
  1357. // Returns: ULONG
  1358. //
  1359. STDMETHODIMP_(ULONG) CWizardUiContext::Release()
  1360. {
  1361. ULONG cRef = --m_cRef;
  1362. if (cRef == 0)
  1363. {
  1364. delete this;
  1365. }
  1366. return cRef;
  1367. }
  1368. //
  1369. // Function: CWizardUiContext::QueryInterface
  1370. //
  1371. // Purpose: Allows for the querying of alternate interfaces
  1372. //
  1373. // Parameters: riid [IN] - Interface to retrieve
  1374. // ppvObj [OUT] - Retrieved interface if function succeeds
  1375. //
  1376. // Returns: HRESULT, S_OK on success E_NOINTERFACE on failure
  1377. //
  1378. STDMETHODIMP CWizardUiContext::QueryInterface(REFIID riid, LPVOID FAR *ppvObj)
  1379. {
  1380. HRESULT hr = S_OK;
  1381. *ppvObj = NULL;
  1382. if ((riid == IID_IUnknown) || (riid == IID_INetConnectionWizardUiContext))
  1383. {
  1384. *ppvObj = (LPVOID)this;
  1385. AddRef();
  1386. }
  1387. else
  1388. {
  1389. hr = E_NOINTERFACE;
  1390. }
  1391. return hr;
  1392. }
  1393. STDMETHODIMP CWizardUiContext::GetINetCfg(INetCfg ** ppINetCfg)
  1394. {
  1395. HRESULT hr = E_FAIL;
  1396. if (NULL == ppINetCfg)
  1397. {
  1398. hr = E_INVALIDARG;
  1399. }
  1400. else if (NULL != m_pINetCfg)
  1401. {
  1402. *ppINetCfg = m_pINetCfg;
  1403. AddRefObj(*ppINetCfg);
  1404. hr = S_OK;
  1405. }
  1406. return hr;
  1407. }