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.

106 lines
3.1 KiB

  1. //
  2. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  3. //
  4. // ***************************************************************************
  5. //
  6. // Original Author: Rajesh Rao
  7. //
  8. // $Author: rajeshr $
  9. // $Date: 6/11/98 4:43p $
  10. // $Workfile:adsihelp.cpp $
  11. //
  12. // $Modtime: 6/11/98 11:21a $
  13. // $Revision: 1 $
  14. // $Nokeywords: $
  15. //
  16. //
  17. // Description: Contains the implementation the CADSIHelper class. This is
  18. // a class that has many static helper functions pertaining to ADSI
  19. //***************************************************************************
  20. /////////////////////////////////////////////////////////////////////////
  21. #include <windows.h>
  22. #include <activeds.h>
  23. #include "adsihelp.h"
  24. //***************************************************************************
  25. //
  26. // CADSiHelper::ProcessBSTRArrayProperty
  27. //
  28. // Purpose: Processes a variant containing an array of BSTR or a single BSTR
  29. //
  30. // Parameters:
  31. // pVariant : The variant to be processed
  32. // ppStrPropertyValue : The addres of the pointer to a BSTR array where the list of BSTRS representing
  33. // the ADSI paths of the derived classes will be put
  34. // lNumber : The number of elements in the retrieved array.
  35. //
  36. //
  37. // Return Value: The COM value representing the return status. It is the responsibility
  38. // of the caller to release the array that is returned, as well as its contents. The varinat
  39. // passed in is not cleared
  40. //
  41. //***************************************************************************
  42. HRESULT CADSIHelper :: ProcessBSTRArrayProperty(VARIANT *pVariant, BSTR **ppStrPropertyValues, LONG *lpNumber)
  43. {
  44. HRESULT result = S_OK;
  45. VARIANT vTemp;
  46. if(pVariant->vt == VT_BSTR) // When the number of values is 1
  47. {
  48. *lpNumber = 1;
  49. *ppStrPropertyValues = new BSTR[*lpNumber];
  50. (*ppStrPropertyValues)[0] = SysAllocString(pVariant->bstrVal);
  51. }
  52. else if (pVariant->vt == (VT_VARIANT|VT_ARRAY) )
  53. {
  54. SAFEARRAY *pSafeArray = pVariant->parray;
  55. *lpNumber = 0;
  56. if(SUCCEEDED(result = SafeArrayGetUBound(pSafeArray, 1, lpNumber)) )
  57. {
  58. *ppStrPropertyValues = new BSTR[*lpNumber];
  59. for(LONG index=0L; index<(*lpNumber); index++)
  60. {
  61. if( FAILED( result = SafeArrayGetElement(pSafeArray, &index, (LPVOID)&vTemp) ))
  62. {
  63. // Reset the count to the actual number retrieved
  64. *lpNumber = index;
  65. break;
  66. }
  67. (*ppStrPropertyValues)[index] = SysAllocString(vTemp.bstrVal);
  68. VariantClear(&vTemp);
  69. }
  70. }
  71. }
  72. else
  73. result = E_FAIL;
  74. return result;
  75. }
  76. //***************************************************************************
  77. //
  78. // CADSiHelper :: DeallocateBSTRArray
  79. //
  80. // Purpose: Deallocates an array of BSTRs and its contents
  81. //
  82. // Parameters:
  83. // pStrPropertyValue : The pointer to the array to be deallocated
  84. // lNumber : The number of elements in the array.
  85. //
  86. //
  87. // Return Value: None
  88. //
  89. //***************************************************************************
  90. void CADSIHelper :: DeallocateBSTRArray(BSTR *pStrPropertyValue, LONG lNumber)
  91. {
  92. for(lNumber--; lNumber>=0; lNumber--)
  93. SysFreeString(pStrPropertyValue[lNumber]);
  94. delete [] pStrPropertyValue;
  95. pStrPropertyValue = NULL ;
  96. }