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.

206 lines
3.8 KiB

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