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.

142 lines
3.8 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: caccess.cxx
  7. //
  8. // Contents: Microsoft OleDB/OleDS Data Source Object for ADSI
  9. //
  10. // Implementation of the Extended Buffer Object used for storing
  11. // accessor handles.
  12. //
  13. // History: 10-01-96 shanksh Created.
  14. //----------------------------------------------------------------------------
  15. #include "oleds.hxx"
  16. #pragma hdrstop
  17. // --------------------------- C E X T B U F F E R ---------------------------
  18. //
  19. // Implementation class for the Extended Buffer object.
  20. //-----------------------------------------------------------------------------
  21. // CExtBuff::CExtBuff
  22. //
  23. // @mfunc CExtBuff constructor.
  24. //
  25. // @rdesc NONE
  26. //-----------------------------------------------------------------------------
  27. CExtBuff::CExtBuff(
  28. void
  29. )
  30. {
  31. _cItem = 0;
  32. _cItemMax = 0;
  33. _rgItem = NULL;
  34. }
  35. //-----------------------------------------------------------------------------
  36. // CExtBuff::~CExtBuff
  37. //
  38. // @mfunc CExtBuff destructor.
  39. //
  40. // @rdesc NONE
  41. //-----------------------------------------------------------------------------
  42. CExtBuff::~CExtBuff(
  43. void
  44. )
  45. {
  46. if (_rgItem)
  47. FreeADsMem(_rgItem);
  48. }
  49. //-----------------------------------------------------------------------------
  50. // FInit::CExtBuff
  51. //
  52. // CExtBuff initialization (memory allocation for the default item
  53. // happens here).
  54. //
  55. // @rdesc Did the Initialization Succeed
  56. // @flag TRUE | Initialization succeeded
  57. // @flag FALSE | Initializtion failed
  58. //-----------------------------------------------------------------------------
  59. BOOL CExtBuff::FInit(
  60. ULONG cbItem, // size of items to store
  61. VOID *pvItemDefault // points to a default value to return
  62. // when an element asked for doesn't exist
  63. )
  64. {
  65. ULONG_PTR hItemDefault;
  66. ADsAssert(cbItem);
  67. ADsAssert(HIWORD(cbItem) == 0);
  68. _cbItem = cbItem;
  69. _rgItem = (BYTE *)AllocADsMem((CEXTBUFFER_DITEM*_cbItem));
  70. if (_rgItem == NULL)
  71. return FALSE;
  72. _cItemMax = CEXTBUFFER_DITEM;
  73. // It's the first insertion so hItemDefault is always 0 and consequently
  74. // we don't need to store it.
  75. if (pvItemDefault)
  76. return (InsertIntoExtBuffer(pvItemDefault, hItemDefault) == NOERROR);
  77. else
  78. return TRUE;
  79. }
  80. //------------------------------------------------------------------------------
  81. // CExtBuff::InsertIntoExtBuffer
  82. //
  83. // @mfunc Stores an item in the Extended Buffer.
  84. //
  85. // @rdesc Returns one of the following values:
  86. // @flag S_OK | insertion succeeded,
  87. // @flag E_OUTOFMEMORY | insertion failed because of memory allocation
  88. // failure
  89. //-----------------------------------------------------------------------------------
  90. STDMETHODIMP CExtBuff::InsertIntoExtBuffer(
  91. VOID *pvItem, // pointer to item to be stored
  92. ULONG_PTR &hItem // points to where the item handle is returned
  93. )
  94. {
  95. // If the buffer capacity is exhausted it needs to be reallocated. Buffer capacity
  96. // is increased by a fixed quantum.
  97. if (_cItem == _cItemMax) {
  98. BYTE *pbTmp;
  99. pbTmp = (BYTE *)ReallocADsMem(
  100. _rgItem,
  101. _cItemMax * _cbItem,
  102. (_cItemMax +CEXTBUFFER_DITEM)*_cbItem
  103. );
  104. if (pbTmp == NULL)
  105. RRETURN (E_OUTOFMEMORY);
  106. // Buffer capacity increased.
  107. _cItemMax += CEXTBUFFER_DITEM;
  108. _rgItem = pbTmp;
  109. }
  110. // Copy the item.
  111. memcpy( (_rgItem + _cItem*_cbItem), (BYTE *)pvItem, _cbItem );
  112. _cItem++;
  113. // Index of the item constitues its handle.
  114. hItem = _cItem -1;
  115. return NOERROR;
  116. }