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.

230 lines
4.8 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. /*++
  3. Copyright (C) Microsoft Corporation, 1998 - 1999
  4. Module Name:
  5. IASIPAttributeEditor.cpp
  6. Abstract:
  7. Implementation file for the CIASIPAttributeEditor class.
  8. Revision History:
  9. mmaguire 06/25/98 - created
  10. --*/
  11. //////////////////////////////////////////////////////////////////////////////
  12. //////////////////////////////////////////////////////////////////////////////
  13. // BEGIN INCLUDES
  14. //
  15. // standard includes:
  16. //
  17. #include "Precompiled.h"
  18. //
  19. // where we can find declaration for main class in this file:
  20. //
  21. #include "IASIPAttributeEditor.h"
  22. #include "IASIPEditorPage.h"
  23. //
  24. // where we can find declarations needed in this file:
  25. //
  26. //
  27. // END INCLUDES
  28. //////////////////////////////////////////////////////////////////////////////
  29. //////////////////////////////////////////////////////////////////////////////
  30. /*++
  31. CIASIPAttributeEditor::ShowEditor
  32. IIASAttributeEditor interface implementation
  33. --*/
  34. //////////////////////////////////////////////////////////////////////////////
  35. STDMETHODIMP CIASIPAttributeEditor::ShowEditor( /*[in, out]*/ BSTR *pReserved )
  36. {
  37. TRACE(_T("CIASIPAttributeEditor::ShowEditor\n"));
  38. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  39. HRESULT hr = S_OK;
  40. try
  41. {
  42. // Load page title.
  43. // ::CString strPageTitle;
  44. // strPageTitle.LoadString(IDS_IAS_IP_EDITOR_TITLE);
  45. //
  46. // CPropertySheet propSheet( (LPCTSTR)strPageTitle );
  47. //
  48. // IP Address Editor
  49. //
  50. IPEditorPage cppPage;
  51. // Initialize the page's data exchange fields with info from IAttributeInfo
  52. CComBSTR bstrName;
  53. CComBSTR bstrSyntax;
  54. ATTRIBUTEID Id = ATTRIBUTE_UNDEFINED;
  55. if( m_spIASAttributeInfo )
  56. {
  57. hr = m_spIASAttributeInfo->get_AttributeName( &bstrName );
  58. if( FAILED(hr) ) throw hr;
  59. m_spIASAttributeInfo->get_SyntaxString( &bstrSyntax );
  60. if( FAILED(hr) ) throw hr;
  61. m_spIASAttributeInfo->get_AttributeID( &Id );
  62. if( FAILED(hr) ) throw hr;
  63. }
  64. cppPage.m_strAttrName = bstrName;
  65. cppPage.m_strAttrFormat = bstrSyntax;
  66. // Attribute type is actually attribute ID in string format
  67. WCHAR szTempId[MAX_PATH];
  68. wsprintf(szTempId, _T("%ld"), Id);
  69. cppPage.m_strAttrType = szTempId;
  70. // Initialize the page's data exchange fields with info from VARIANT value passed in.
  71. if ( V_VT(m_pvarValue) != VT_EMPTY )
  72. {
  73. _ASSERTE( V_VT(m_pvarValue) == VT_I4 );
  74. cppPage.m_dwIpAddr = V_I4(m_pvarValue);
  75. cppPage.m_fIpAddrPreSet = TRUE;
  76. }
  77. // propSheet.AddPage(&cppPage);
  78. // int iResult = propSheet.DoModal();
  79. int iResult = cppPage.DoModal();
  80. if (IDOK == iResult)
  81. {
  82. // Initialize the variant that was passed in.
  83. VariantClear(m_pvarValue);
  84. // Save the value that the user edited to the variant.
  85. V_VT(m_pvarValue) = VT_I4;
  86. V_I4(m_pvarValue) = cppPage.m_dwIpAddr;
  87. }
  88. else
  89. {
  90. hr = S_FALSE;
  91. }
  92. //
  93. // delete the property page pointer
  94. //
  95. // propSheet.RemovePage(&cppPage);
  96. }
  97. catch( HRESULT & hr )
  98. {
  99. return hr;
  100. }
  101. catch(...)
  102. {
  103. return hr = E_FAIL;
  104. }
  105. return hr;
  106. }
  107. //////////////////////////////////////////////////////////////////////////////
  108. /*++
  109. CIASIPAttributeEditor::SetAttributeValue
  110. IIASAttributeEditor interface implementation
  111. --*/
  112. //////////////////////////////////////////////////////////////////////////////
  113. STDMETHODIMP CIASIPAttributeEditor::SetAttributeValue(VARIANT * pValue)
  114. {
  115. TRACE(_T("CIASIPAttributeEditor::SetAttributeValue\n"));
  116. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  117. // Check for preconditions.
  118. if( ! pValue )
  119. {
  120. return E_INVALIDARG;
  121. }
  122. if( V_VT(pValue) != VT_I4 && V_VT(pValue) != VT_EMPTY )
  123. {
  124. return E_INVALIDARG;
  125. }
  126. m_pvarValue = pValue;
  127. return S_OK;
  128. }
  129. //////////////////////////////////////////////////////////////////////////////
  130. /*++
  131. CIASIPAttributeEditor::get_ValueAsString
  132. IIASAttributeEditor interface implementation
  133. --*/
  134. //////////////////////////////////////////////////////////////////////////////
  135. STDMETHODIMP CIASIPAttributeEditor::get_ValueAsString(BSTR * pbstrDisplayText )
  136. {
  137. TRACE(_T("CIASIPAttributeEditor::get_ValueAsString\n"));
  138. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  139. // Check for preconditions.
  140. if( ! pbstrDisplayText )
  141. {
  142. return E_INVALIDARG;
  143. }
  144. CComBSTR bstrDisplay;
  145. // This if falls through so get a blank string for any other types.
  146. if( V_VT(m_pvarValue) == VT_I4 )
  147. {
  148. DWORD dwAddress = V_I4(m_pvarValue);
  149. WORD hi = HIWORD(dwAddress);
  150. WORD lo = LOWORD(dwAddress);
  151. WCHAR szTemp[255];
  152. wsprintf( szTemp, _T("%-d.%-d.%-d.%d"), HIBYTE(hi), LOBYTE(hi), HIBYTE(lo), LOBYTE(lo));
  153. bstrDisplay = szTemp;
  154. }
  155. *pbstrDisplayText = bstrDisplay.Copy();
  156. return S_OK;
  157. }