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.

216 lines
4.1 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: cgroup.cxx
  7. //
  8. // Contents: Group object
  9. //
  10. // History: 11-1-95 krishnag Created.
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "procs.hxx"
  14. #pragma hdrstop
  15. #include "nds.hxx"
  16. // Class CNDSGroupCollection
  17. DEFINE_IDispatch_Implementation(CNDSGroupCollection)
  18. CNDSGroupCollection::CNDSGroupCollection():
  19. _ADsPath(NULL),
  20. _pDispMgr(NULL)
  21. {
  22. VariantInit(&_vMembers);
  23. VariantInit(&_vFilter);
  24. ENLIST_TRACKING(CNDSGroupCollection);
  25. }
  26. HRESULT
  27. CNDSGroupCollection::CreateGroupCollection(
  28. BSTR bstrADsPath,
  29. VARIANT varMembers,
  30. CCredentials& Credentials,
  31. REFIID riid,
  32. void **ppvObj
  33. )
  34. {
  35. CNDSGroupCollection FAR * pGroup = NULL;
  36. HRESULT hr = S_OK;
  37. hr = AllocateGroupCollectionObject(Credentials, &pGroup);
  38. BAIL_ON_FAILURE(hr);
  39. hr = ADsAllocString(bstrADsPath, &(pGroup->_ADsPath));
  40. BAIL_ON_FAILURE(hr);
  41. hr = VariantCopy(&(pGroup->_vMembers), &varMembers);
  42. BAIL_ON_FAILURE(hr);
  43. hr = pGroup->QueryInterface(riid, ppvObj);
  44. BAIL_ON_FAILURE(hr);
  45. pGroup->Release();
  46. RRETURN(hr);
  47. error:
  48. delete pGroup;
  49. RRETURN(hr);
  50. }
  51. CNDSGroupCollection::~CNDSGroupCollection( )
  52. {
  53. VariantClear(&_vMembers);
  54. VariantClear(&_vFilter);
  55. delete _pDispMgr;
  56. if (_ADsPath) {
  57. ADsFreeString(_ADsPath);
  58. _ADsPath = NULL;
  59. }
  60. }
  61. STDMETHODIMP
  62. CNDSGroupCollection::QueryInterface(
  63. REFIID iid,
  64. LPVOID FAR* ppv
  65. )
  66. {
  67. if (ppv == NULL) {
  68. RRETURN(E_POINTER);
  69. }
  70. if (IsEqualIID(iid, IID_IUnknown))
  71. {
  72. *ppv = (IADsMembers FAR *) this;
  73. }
  74. else if (IsEqualIID(iid, IID_IADsMembers))
  75. {
  76. *ppv = (IADsMembers FAR *) this;
  77. }
  78. else if (IsEqualIID(iid, IID_IDispatch))
  79. {
  80. *ppv = (IADsMembers FAR *) this;
  81. }
  82. else
  83. {
  84. *ppv = NULL;
  85. return E_NOINTERFACE;
  86. }
  87. AddRef();
  88. return NOERROR;
  89. }
  90. STDMETHODIMP
  91. CNDSGroupCollection::get_Count(long FAR* retval)
  92. {
  93. RRETURN(E_NOTIMPL);
  94. }
  95. STDMETHODIMP
  96. CNDSGroupCollection::get_Filter(THIS_ VARIANT FAR* pVar)
  97. {
  98. VariantInit(pVar);
  99. RRETURN(VariantCopy(pVar, &_vFilter));
  100. }
  101. STDMETHODIMP
  102. CNDSGroupCollection::put_Filter(THIS_ VARIANT Var)
  103. {
  104. VariantClear(&_vFilter);
  105. RRETURN(VariantCopy(&_vFilter, &Var));
  106. }
  107. STDMETHODIMP
  108. CNDSGroupCollection::get__NewEnum(
  109. THIS_ IUnknown * FAR* retval
  110. )
  111. {
  112. HRESULT hr;
  113. IUnknown FAR* punkEnum=NULL;
  114. IEnumVARIANT * penum = NULL;
  115. if (!retval) {
  116. RRETURN(E_ADS_BAD_PARAMETER);
  117. }
  118. *retval = NULL;
  119. hr = CNDSGroupCollectionEnum::Create(
  120. _ADsPath,
  121. _Credentials,
  122. (CNDSGroupCollectionEnum **)&penum,
  123. _vMembers
  124. );
  125. BAIL_ON_FAILURE(hr);
  126. hr = penum->QueryInterface(
  127. IID_IUnknown,
  128. (VOID FAR* FAR*)retval
  129. );
  130. BAIL_ON_FAILURE(hr);
  131. if (penum) {
  132. penum->Release();
  133. }
  134. RRETURN(NOERROR);
  135. error:
  136. if (penum) {
  137. delete penum;
  138. }
  139. RRETURN(hr);
  140. }
  141. HRESULT
  142. CNDSGroupCollection::AllocateGroupCollectionObject(
  143. CCredentials& Credentials,
  144. CNDSGroupCollection ** ppGroup
  145. )
  146. {
  147. CNDSGroupCollection FAR * pGroup = NULL;
  148. CDispatchMgr FAR * pDispMgr = NULL;
  149. HRESULT hr = S_OK;
  150. pGroup = new CNDSGroupCollection();
  151. if (pGroup == NULL) {
  152. hr = E_OUTOFMEMORY;
  153. }
  154. BAIL_ON_FAILURE(hr);
  155. pDispMgr = new CDispatchMgr;
  156. if (pDispMgr == NULL) {
  157. hr = E_OUTOFMEMORY;
  158. }
  159. BAIL_ON_FAILURE(hr);
  160. hr = LoadTypeInfoEntry(pDispMgr,
  161. LIBID_ADs,
  162. IID_IADsMembers,
  163. (IADsMembers *)pGroup,
  164. DISPID_NEWENUM
  165. );
  166. BAIL_ON_FAILURE(hr);
  167. pGroup->_Credentials = Credentials;
  168. pGroup->_pDispMgr = pDispMgr;
  169. *ppGroup = pGroup;
  170. RRETURN(hr);
  171. error:
  172. delete pDispMgr;
  173. RRETURN(hr);
  174. }