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.

128 lines
3.2 KiB

  1. // DENames.cpp : Implementation of CDEGetBlockFmtNamesParam
  2. // Copyright (c)1997-1999 Microsoft Corporation, All Rights Reserved
  3. #include "stdafx.h"
  4. #include "DHTMLEd.h"
  5. #include "DENames.h"
  6. /////////////////////////////////////////////////////////////////////////////
  7. // CDEGetBlockFmtNamesParam
  8. CDEGetBlockFmtNamesParam::CDEGetBlockFmtNamesParam()
  9. {
  10. m_pNamesArray = NULL;
  11. m_pNamesArray = SafeArrayCreateVector(VT_VARIANT, 0, 0);
  12. _ASSERTE(m_pNamesArray);
  13. }
  14. CDEGetBlockFmtNamesParam::~CDEGetBlockFmtNamesParam()
  15. {
  16. if (m_pNamesArray)
  17. SafeArrayDestroy(m_pNamesArray);
  18. }
  19. // This will always retreive a SafeArray of Variants containing BSTRs.
  20. //
  21. STDMETHODIMP CDEGetBlockFmtNamesParam::get_Names(VARIANT * pVal)
  22. {
  23. HRESULT hr = S_OK;
  24. _ASSERTE(pVal);
  25. if (NULL == pVal)
  26. return E_INVALIDARG;
  27. VariantClear(pVal);
  28. V_VT(pVal) = VT_ARRAY|VT_VARIANT;
  29. hr = SafeArrayCopy(m_pNamesArray, &(V_ARRAY(pVal)));
  30. return hr;
  31. }
  32. // The SafeArray gotten received from Trident is (currently) an array for BSTRs.
  33. // This works fine with VB, but not VBS or JScript.
  34. // We'll do the work at this end to copy the supplied array over to our private
  35. // storage as a SafeArray of Variants containing BSTRs.
  36. //
  37. STDMETHODIMP CDEGetBlockFmtNamesParam::put_Names(VARIANT* newVal)
  38. {
  39. HRESULT hr = S_OK;
  40. LONG lLBound, lUBound, lIndex;
  41. _ASSERTE ( m_pNamesArray );
  42. _ASSERTE(VT_ARRAY == V_VT(newVal));
  43. _ASSERTE(NULL != V_ARRAY(newVal));
  44. if (VT_ARRAY != V_VT(newVal))
  45. return E_INVALIDARG;
  46. if (NULL == V_ARRAY(newVal))
  47. return E_INVALIDARG;
  48. SafeArrayGetLBound(V_ARRAY(newVal), 1, &lLBound);
  49. SafeArrayGetUBound(V_ARRAY(newVal), 1, &lUBound);
  50. SAFEARRAYBOUND rgsaBound[1];
  51. rgsaBound[0].lLbound = 0;
  52. rgsaBound[0].cElements = ( lUBound - lLBound ) + 1;
  53. hr = SafeArrayRedim ( m_pNamesArray, rgsaBound );
  54. _ASSERTE ( SUCCEEDED ( hr ) );
  55. if ( FAILED ( hr ) )
  56. {
  57. SafeArrayDestroy ( V_ARRAY(newVal) );
  58. return hr;
  59. }
  60. // Copy all BSTRs or Variants from the source array to Variants in the m_pNamesArray
  61. VARIANT var;
  62. BSTR bstr = NULL;
  63. VariantInit ( &var );
  64. for (lIndex=lLBound; lIndex<=lUBound; lIndex++)
  65. {
  66. if ( FADF_BSTR & V_ARRAY(newVal)->fFeatures )
  67. {
  68. hr = SafeArrayGetElement(V_ARRAY(newVal), &lIndex, &bstr);
  69. _ASSERTE ( SUCCEEDED ( hr ) );
  70. if ( FAILED ( hr ) )
  71. break;
  72. // BSTR was copied, we can stick it in a variant, no release or duplicating needed.
  73. var.vt = VT_BSTR;
  74. var.bstrVal = bstr;
  75. }
  76. else if ( FADF_VARIANT & V_ARRAY(newVal)->fFeatures )
  77. {
  78. hr = SafeArrayGetElement(V_ARRAY(newVal), &lIndex, &var);
  79. _ASSERTE ( SUCCEEDED ( hr ) );
  80. if ( FAILED ( hr ) )
  81. break;
  82. hr = VariantChangeType ( &var, &var, 0, VT_BSTR );
  83. _ASSERTE ( SUCCEEDED ( hr ) );
  84. if ( FAILED ( hr ) )
  85. break;
  86. }
  87. else
  88. {
  89. _ASSERTE ( ( FADF_BSTR | FADF_VARIANT ) & V_ARRAY(newVal)->fFeatures );
  90. hr = E_UNEXPECTED;
  91. break;
  92. }
  93. hr = SafeArrayPutElement ( m_pNamesArray, &lIndex, &var );
  94. _ASSERTE ( SUCCEEDED ( hr ) );
  95. VariantClear ( &var );
  96. }
  97. VariantClear ( &var ); // In case a break occurred.
  98. SafeArrayDestroy ( V_ARRAY(newVal) );
  99. return hr;
  100. }