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.

125 lines
3.3 KiB

  1. /*---------------------------------------------------------------------------
  2. File: TAttrNode.cpp
  3. Comments: implementation of the TAttrNode class.
  4. (c) Copyright 1999, Mission Critical Software, Inc., All Rights Reserved
  5. Proprietary and confidential to Mission Critical Software, Inc.
  6. REVISION LOG ENTRY
  7. Revision By: Sham Chauthani
  8. Revised on 07/02/99 12:40:00
  9. ---------------------------------------------------------------------------
  10. */
  11. #include "stdafx.h"
  12. #include "AttrNode.h"
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. //////////////////////////////////////////////////////////////////////
  19. // Construction/Destruction
  20. //////////////////////////////////////////////////////////////////////
  21. TAttrNode::TAttrNode(
  22. long nCnt, //in -Number of columns to set
  23. _variant_t val[] //in -Array of column values
  24. )
  25. {
  26. SAFEARRAY * pArray;
  27. SAFEARRAYBOUND bd = { nCnt, 0 };
  28. _variant_t HUGEP * pData;
  29. pArray = ::SafeArrayCreate(VT_VARIANT, 1, &bd);
  30. ::SafeArrayAccessData(pArray, (void**)&pData);
  31. for ( long i = 0; i < nCnt; i++ )
  32. pData[i] = val[i];
  33. ::SafeArrayUnaccessData(pArray);
  34. m_Val.vt = VT_ARRAY | VT_VARIANT;
  35. m_Val.parray = pArray;
  36. m_nElts = new long[nCnt];
  37. if (!m_nElts)
  38. return;
  39. for (int ndx = 0; ndx < nCnt; ndx++)
  40. {
  41. m_nElts[ndx] = 0;
  42. }
  43. }
  44. TAttrNode::~TAttrNode()
  45. {
  46. if (m_nElts)
  47. delete [] m_nElts;
  48. }
  49. HRESULT TAttrNode::Add(long nOrigCol, long nCol, _variant_t val[])
  50. {
  51. if (!m_nElts)
  52. return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
  53. SAFEARRAY * pArray = NULL;
  54. SAFEARRAYBOUND bd = { m_nElts[nOrigCol], 0 };
  55. _variant_t HUGEP * pData;
  56. HRESULT hr;
  57. SAFEARRAY * pVars;
  58. SAFEARRAY * psaTemp;
  59. _variant_t HUGEP * pTemp;
  60. long nCnt;
  61. pVars = m_Val.parray;
  62. hr = ::SafeArrayAccessData(pVars, (void HUGEP **) &pData);
  63. if(SUCCEEDED(hr) )
  64. {
  65. if ( pData->vt & VT_ARRAY )
  66. pArray = pData[nOrigCol].parray;
  67. else
  68. hr = E_INVALIDARG;
  69. }
  70. if(SUCCEEDED(hr) )
  71. hr = ::SafeArrayUnaccessData(pVars);
  72. if ( SUCCEEDED(hr) )
  73. {
  74. if ( val[nCol].vt & VT_ARRAY )
  75. {
  76. // Get the current number of elts
  77. m_nElts[nOrigCol] = pArray->rgsabound->cElements;
  78. // Get the number of new elts
  79. nCnt = val[nCol].parray->rgsabound->cElements;
  80. // Get the array to transfer data.
  81. psaTemp = val[nCol].parray;
  82. // Extend the array to support the new values.
  83. bd.cElements = m_nElts[nOrigCol] + nCnt;
  84. hr = ::SafeArrayRedim(pArray, &bd);
  85. if ( SUCCEEDED(hr) )
  86. hr = ::SafeArrayAccessData(pArray, (void HUGEP **)&pData);
  87. if ( SUCCEEDED(hr) )
  88. {
  89. hr = ::SafeArrayAccessData(psaTemp, (void HUGEP **)&pTemp);
  90. if ( SUCCEEDED(hr) )
  91. {
  92. for ( long i = m_nElts[nOrigCol]; i < m_nElts[nOrigCol] + nCnt; i++ )
  93. pData[i] = pTemp[i - m_nElts[nOrigCol]];
  94. hr = ::SafeArrayUnaccessData(psaTemp);
  95. }
  96. hr = ::SafeArrayUnaccessData(pArray);
  97. }
  98. }
  99. }
  100. return hr;
  101. }