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.

316 lines
6.6 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: cgroups.cxx
  7. //
  8. // Contents: Group object
  9. //
  10. // History: Mar-18-965 t-ptam (PatrickT) Migrated.
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "NWCOMPAT.hxx"
  14. #pragma hdrstop
  15. //
  16. // Class CNWCOMPATGroupCollection
  17. //
  18. DEFINE_IDispatch_Implementation(CNWCOMPATGroupCollection)
  19. //----------------------------------------------------------------------------
  20. //
  21. // Function:
  22. //
  23. // Synopsis:
  24. //
  25. //----------------------------------------------------------------------------
  26. CNWCOMPATGroupCollection::CNWCOMPATGroupCollection():
  27. _ParentType(0),
  28. _ServerName(NULL),
  29. _pDispMgr(NULL)
  30. {
  31. VariantInit(&_vFilter);
  32. ENLIST_TRACKING(CNWCOMPATGroupCollection);
  33. }
  34. //----------------------------------------------------------------------------
  35. //
  36. // Function:
  37. //
  38. // Synopsis:
  39. //
  40. //----------------------------------------------------------------------------
  41. CNWCOMPATGroupCollection::~CNWCOMPATGroupCollection( )
  42. {
  43. if (_ServerName)
  44. ADsFreeString(_ServerName);
  45. delete _pDispMgr;
  46. VariantClear(&_vFilter);
  47. }
  48. //----------------------------------------------------------------------------
  49. //
  50. // Function:
  51. //
  52. // Synopsis:
  53. //
  54. //----------------------------------------------------------------------------
  55. HRESULT
  56. CNWCOMPATGroupCollection::CreateGroupCollection(
  57. BSTR Parent,
  58. ULONG ParentType,
  59. BSTR ServerName,
  60. BSTR GroupName,
  61. CCredentials &Credentials,
  62. REFIID riid,
  63. void **ppvObj
  64. )
  65. {
  66. CNWCOMPATGroupCollection FAR * pGroup = NULL;
  67. HRESULT hr = S_OK;
  68. hr = AllocateGroupCollectionObject(&pGroup);
  69. BAIL_ON_FAILURE(hr);
  70. hr = pGroup->InitializeCoreObject(
  71. Parent,
  72. GroupName,
  73. L"group",
  74. NO_SCHEMA,
  75. CLSID_NWCOMPATGroup,
  76. ADS_OBJECT_UNBOUND
  77. );
  78. BAIL_ON_FAILURE(hr);
  79. hr = ADsAllocString( ServerName , &pGroup->_ServerName);
  80. BAIL_ON_FAILURE(hr);
  81. pGroup->_ParentType = ParentType;
  82. pGroup->_Credentials = Credentials;
  83. hr = pGroup->QueryInterface(riid, ppvObj);
  84. BAIL_ON_FAILURE(hr);
  85. pGroup->Release();
  86. RRETURN(hr);
  87. error:
  88. delete pGroup;
  89. NW_RRETURN_EXP_IF_ERR(hr);
  90. }
  91. //----------------------------------------------------------------------------
  92. //
  93. // Function:
  94. //
  95. // Synopsis:
  96. //
  97. //----------------------------------------------------------------------------
  98. STDMETHODIMP
  99. CNWCOMPATGroupCollection::QueryInterface(
  100. REFIID iid,
  101. LPVOID FAR* ppv
  102. )
  103. {
  104. if (ppv == NULL) {
  105. RRETURN(E_POINTER);
  106. }
  107. if (IsEqualIID(iid, IID_IUnknown))
  108. {
  109. *ppv = (IADsMembers FAR *) this;
  110. }
  111. else if (IsEqualIID(iid, IID_IADsMembers))
  112. {
  113. *ppv = (IADsMembers FAR *) this;
  114. }
  115. else if (IsEqualIID(iid, IID_IDispatch))
  116. {
  117. *ppv = (IADsMembers FAR *) this;
  118. }
  119. else if (IsEqualIID(iid, IID_ISupportErrorInfo))
  120. {
  121. *ppv = (ISupportErrorInfo FAR *) this;
  122. }
  123. else
  124. {
  125. *ppv = NULL;
  126. return E_NOINTERFACE;
  127. }
  128. AddRef();
  129. return NOERROR;
  130. }
  131. /* ISupportErrorInfo method */
  132. STDMETHODIMP
  133. CNWCOMPATGroupCollection::InterfaceSupportsErrorInfo(
  134. THIS_ REFIID riid
  135. )
  136. {
  137. if (IsEqualIID(riid, IID_IADsMembers)) {
  138. RRETURN(S_OK);
  139. } else {
  140. RRETURN(S_FALSE);
  141. }
  142. }
  143. //----------------------------------------------------------------------------
  144. //
  145. // Function:
  146. //
  147. // Synopsis:
  148. //
  149. //----------------------------------------------------------------------------
  150. STDMETHODIMP
  151. CNWCOMPATGroupCollection::get_Count(
  152. long FAR* retval
  153. )
  154. {
  155. NW_RRETURN_EXP_IF_ERR(E_NOTIMPL);
  156. }
  157. //----------------------------------------------------------------------------
  158. //
  159. // Function:
  160. //
  161. // Synopsis:
  162. //
  163. //----------------------------------------------------------------------------
  164. STDMETHODIMP
  165. CNWCOMPATGroupCollection::get_Filter(
  166. THIS_ VARIANT FAR* pVar
  167. )
  168. {
  169. HRESULT hr;
  170. VariantInit(pVar);
  171. hr = VariantCopy(pVar, &_vFilter);
  172. NW_RRETURN_EXP_IF_ERR(hr);
  173. }
  174. //----------------------------------------------------------------------------
  175. //
  176. // Function:
  177. //
  178. // Synopsis:
  179. //
  180. //----------------------------------------------------------------------------
  181. STDMETHODIMP
  182. CNWCOMPATGroupCollection::put_Filter(
  183. THIS_ VARIANT Var
  184. )
  185. {
  186. HRESULT hr;
  187. hr = VariantCopy(&_vFilter, &Var);
  188. NW_RRETURN_EXP_IF_ERR(hr);
  189. }
  190. //----------------------------------------------------------------------------
  191. //
  192. // Function:
  193. //
  194. // Synopsis:
  195. //
  196. //----------------------------------------------------------------------------
  197. STDMETHODIMP
  198. CNWCOMPATGroupCollection::get__NewEnum(
  199. THIS_ IUnknown * FAR* retval
  200. )
  201. {
  202. HRESULT hr;
  203. IUnknown FAR* punkEnum=NULL;
  204. IEnumVARIANT * penum = NULL;
  205. *retval = NULL;
  206. hr = CNWCOMPATGroupCollectionEnum::Create(
  207. (CNWCOMPATGroupCollectionEnum **)&penum,
  208. _Parent,
  209. _ParentType,
  210. _ADsPath,
  211. _ServerName,
  212. _Name,
  213. _Credentials,
  214. _vFilter
  215. );
  216. BAIL_ON_FAILURE(hr);
  217. hr = penum->QueryInterface(
  218. IID_IUnknown,
  219. (VOID FAR* FAR*)retval
  220. );
  221. BAIL_ON_FAILURE(hr);
  222. if (penum) {
  223. penum->Release();
  224. }
  225. RRETURN(NOERROR);
  226. error:
  227. if (penum) {
  228. delete penum;
  229. }
  230. NW_RRETURN_EXP_IF_ERR(hr);
  231. }
  232. //----------------------------------------------------------------------------
  233. //
  234. // Function:
  235. //
  236. // Synopsis:
  237. //
  238. //----------------------------------------------------------------------------
  239. HRESULT
  240. CNWCOMPATGroupCollection::AllocateGroupCollectionObject(
  241. CNWCOMPATGroupCollection ** ppGroup
  242. )
  243. {
  244. CNWCOMPATGroupCollection FAR * pGroup = NULL;
  245. CDispatchMgr FAR * pDispMgr = NULL;
  246. HRESULT hr = S_OK;
  247. pGroup = new CNWCOMPATGroupCollection();
  248. if (pGroup == NULL) {
  249. hr = E_OUTOFMEMORY;
  250. }
  251. BAIL_ON_FAILURE(hr);
  252. pDispMgr = new CDispatchMgr;
  253. if (pDispMgr == NULL) {
  254. hr = E_OUTOFMEMORY;
  255. }
  256. BAIL_ON_FAILURE(hr);
  257. hr = LoadTypeInfoEntry(
  258. pDispMgr,
  259. LIBID_ADs,
  260. IID_IADsMembers,
  261. (IADsMembers *)pGroup,
  262. DISPID_NEWENUM
  263. );
  264. BAIL_ON_FAILURE(hr);
  265. pGroup->_pDispMgr = pDispMgr;
  266. *ppGroup = pGroup;
  267. RRETURN(hr);
  268. error:
  269. if (pGroup) {
  270. delete pGroup;
  271. }
  272. if (pDispMgr) {
  273. delete pDispMgr;
  274. }
  275. RRETURN(hr);
  276. }