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.

186 lines
4.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: L A N W I Z F N. C P P
  7. //
  8. // Contents: Help member functions of the LAN ConnectionUI object
  9. // used to implement the Lan Connection Wizard
  10. //
  11. // Notes:
  12. //
  13. // Created: tongl 24 Oct 1997
  14. //
  15. //----------------------------------------------------------------------------
  16. #include "pch.h"
  17. #pragma hdrstop
  18. #include "nsbase.h"
  19. #include "lanuiobj.h"
  20. #include "lancmn.h"
  21. #include "lanwiz.h"
  22. #include "ncnetcon.h"
  23. //+---------------------------------------------------------------------------
  24. //
  25. // Member: CLanConnectionUi::HrSetupWizPages
  26. //
  27. // Purpose: Setup the needed wizard pages based on the context
  28. //
  29. // Arguments:
  30. // pContext [in]
  31. // pahpsp [out]
  32. // pcPages [out]
  33. //
  34. // Returns: HRESULT, Error code.
  35. //
  36. // Author: tongl 9 Oct 1997
  37. //
  38. // Notes:
  39. //
  40. HRESULT CLanConnectionUi::HrSetupWizPages(INetConnectionWizardUiContext* pContext,
  41. HPROPSHEETPAGE ** pahpsp, INT * pcPages)
  42. {
  43. HRESULT hr = S_OK;
  44. int cPages = 0;
  45. HPROPSHEETPAGE *ahpsp = NULL;
  46. // We now have only 1 page no matter what
  47. cPages = 1;
  48. // Lan wizard page
  49. if (!m_pWizPage)
  50. m_pWizPage = new CLanWizPage(static_cast<INetConnectionPropertyUi *>(this));
  51. // Allocate a buffer large enough to hold the handles to all of our
  52. // wizard pages.
  53. ahpsp = (HPROPSHEETPAGE *)CoTaskMemAlloc(sizeof(HPROPSHEETPAGE)
  54. * cPages);
  55. if (!ahpsp)
  56. {
  57. hr = E_OUTOFMEMORY;
  58. return hr;
  59. }
  60. // Check for read-only mode
  61. if (UM_READONLY == pContext->GetUnattendedModeFlags())
  62. {
  63. // If read-only, remember this
  64. m_pWizPage->SetReadOnlyMode(TRUE);
  65. }
  66. cPages =0;
  67. DWORD dwFlags = PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
  68. PCWSTR pszTitle = SzLoadIds(IDS_LANWIZ_TITLE);
  69. PCWSTR pszSubTitle = SzLoadIds(IDS_LANWIZ_SUBTITLE);
  70. ahpsp[cPages++] = m_pWizPage->CreatePage(IDD_LANWIZ_DLG, dwFlags,
  71. pszTitle,
  72. pszSubTitle);
  73. *pahpsp = ahpsp;
  74. *pcPages = cPages;
  75. return hr;
  76. }
  77. //+---------------------------------------------------------------------------
  78. //
  79. // Member: CLanConnectionUi::HrGetLanConnection
  80. //
  81. // Purpose: Return an existing connection or create a new one if none
  82. // exists
  83. //
  84. // Arguments:
  85. //
  86. // Returns: HRESULT, Error code.
  87. //
  88. // Author: tongl 30 Oct 1997
  89. //
  90. // Notes:
  91. //
  92. HRESULT CLanConnectionUi::HrGetLanConnection(INetLanConnection ** ppLanCon)
  93. {
  94. Assert(ppLanCon);
  95. // Initialize output parameter.
  96. //
  97. *ppLanCon = NULL;
  98. INetLanConnection* pLanCon = NULL;
  99. BOOL fFoundConnection = FALSE;
  100. INetConnectionManager* pConMan;
  101. HRESULT hr = HrCreateInstance(
  102. CLSID_LanConnectionManager,
  103. CLSCTX_SERVER | CLSCTX_NO_CODE_DOWNLOAD,
  104. &pConMan);
  105. TraceHr(ttidError, FAL, hr, FALSE, "HrCreateInstance");
  106. if (SUCCEEDED(hr))
  107. {
  108. GUID guidAdapter;
  109. hr = m_pnccAdapter->GetInstanceGuid(&guidAdapter);
  110. CIterNetCon ncIter(pConMan, NCME_DEFAULT);
  111. INetConnection* pCon;
  112. while (SUCCEEDED(hr) && !fFoundConnection &&
  113. (S_OK == ncIter.HrNext(&pCon)))
  114. {
  115. if (FPconnEqualGuid (pCon, guidAdapter))
  116. {
  117. hr = HrQIAndSetProxyBlanket(pCon, &pLanCon);
  118. if (SUCCEEDED(hr))
  119. {
  120. fFoundConnection = TRUE;
  121. }
  122. }
  123. ReleaseObj(pCon);
  124. }
  125. #if DBG
  126. if (SUCCEEDED(hr) && !fFoundConnection)
  127. {
  128. // If it's not caused by a non-functioning device, we need to assert
  129. ULONG ulProblem;
  130. HRESULT hrTmp = m_pnccAdapter->GetDeviceStatus(&ulProblem);
  131. if (SUCCEEDED(hrTmp))
  132. {
  133. if (FIsDeviceFunctioning(ulProblem))
  134. {
  135. TraceTag(ttidLanUi, "m_pnccAdapter->GetDeviceStatus: ulProblem "
  136. "= 0x%08X.", ulProblem);
  137. AssertSz(FALSE, "How come the LAN connection does not exist after enumeration?");
  138. }
  139. }
  140. }
  141. #endif
  142. ReleaseObj (pConMan);
  143. }
  144. if ((S_OK == hr) && fFoundConnection)
  145. {
  146. Assert(pLanCon);
  147. *ppLanCon = pLanCon;
  148. }
  149. else
  150. {
  151. TraceTag(ttidError, "Error! CLanConnectionUi::HrGetLanConnection is called on non-existing adapter.");
  152. hr = E_FAIL;
  153. }
  154. TraceError("CLanConnectionUi::HrGetLanConnection", hr);
  155. return hr;
  156. }