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.

241 lines
5.6 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: cenumvar.cxx
  7. //
  8. // Contents: Windows NT 3.5 Enumerator Code
  9. //
  10. // CNWCOMPATNamespaceEnum::Create
  11. // CNWCOMPATNamespaceEnum::CNWCOMPATNamespaceEnum
  12. // CNWCOMPATNamespaceEnum::~CNWCOMPATNamespaceEnum
  13. // CNWCOMPATNamespaceEnum::QueryInterface
  14. // CNWCOMPATNamespaceEnum::AddRef
  15. // CNWCOMPATNamespaceEnum::Release
  16. // CNWCOMPATNamespaceEnum::Next
  17. // CNWCOMPATNamespaceEnum::Skip
  18. // CNWCOMPATNamespaceEnum::Clone
  19. //
  20. // History:
  21. //----------------------------------------------------------------------------
  22. #include "NWCOMPAT.hxx"
  23. #pragma hdrstop
  24. //+---------------------------------------------------------------------------
  25. //
  26. // Function: CNWCOMPATNamespaceEnum::Create
  27. //
  28. // Synopsis:
  29. //
  30. // Arguments: [pCollection]
  31. // [ppEnumVariant]
  32. //
  33. // Returns: HRESULT
  34. //
  35. // Modifies:
  36. //
  37. // History: 01-30-95 krishnag Created.
  38. //
  39. //----------------------------------------------------------------------------
  40. HRESULT
  41. CNWCOMPATNamespaceEnum::Create(
  42. CNWCOMPATNamespaceEnum FAR* FAR* ppenumvariant
  43. )
  44. {
  45. HRESULT hr = S_OK;
  46. CNWCOMPATNamespaceEnum FAR* penumvariant = NULL;
  47. penumvariant = new CNWCOMPATNamespaceEnum();
  48. if (penumvariant == NULL){
  49. hr = E_OUTOFMEMORY;
  50. BAIL_ON_FAILURE(hr);
  51. }
  52. hr = NWApiGetAnyBinderyHandle(
  53. &penumvariant->_hConn
  54. );
  55. *ppenumvariant = penumvariant;
  56. RRETURN(hr);
  57. error:
  58. if (penumvariant) {
  59. delete penumvariant;
  60. }
  61. RRETURN_EXP_IF_ERR(hr);
  62. }
  63. //+---------------------------------------------------------------------------
  64. //
  65. // Function: CNWCOMPATNamespaceEnum::CNWCOMPATNamespaceEnum
  66. //
  67. // Synopsis:
  68. //
  69. //
  70. // Arguments:
  71. //
  72. //
  73. // Returns:
  74. //
  75. // Modifies:
  76. //
  77. // History: 01-30-95 krishnag Created.
  78. //
  79. //----------------------------------------------------------------------------
  80. CNWCOMPATNamespaceEnum::CNWCOMPATNamespaceEnum()
  81. {
  82. _dwResumeObjectID = 0xffffffff;
  83. _hConn = NULL;
  84. }
  85. //+---------------------------------------------------------------------------
  86. //
  87. // Function: CNWCOMPATNamespaceEnum::~CNWCOMPATNamespaceEnum
  88. //
  89. // Synopsis:
  90. //
  91. //
  92. // Arguments:
  93. //
  94. // Returns:
  95. //
  96. // Modifies:
  97. //
  98. // History: 01-30-95 krishnag Created.
  99. //
  100. //----------------------------------------------------------------------------
  101. CNWCOMPATNamespaceEnum::~CNWCOMPATNamespaceEnum()
  102. {
  103. if (_hConn) {
  104. NWApiReleaseBinderyHandle(_hConn);
  105. }
  106. }
  107. //+---------------------------------------------------------------------------
  108. //
  109. // Function: CNWCOMPATNamespaceEnum::Next
  110. //
  111. // Synopsis: Returns cElements number of requested ADs objects in the
  112. // array supplied in pvar.
  113. //
  114. // Arguments: [cElements] -- The number of elements requested by client
  115. // [pvar] -- ptr to array of VARIANTs to for return objects
  116. // [pcElementFetched] -- if non-NULL, then number of elements
  117. // -- actually returned is placed here
  118. //
  119. // Returns: HRESULT -- S_OK if number of elements requested are returned
  120. // -- S_FALSE if number of elements is < requested
  121. //
  122. // Modifies:
  123. //
  124. // History:
  125. //
  126. //----------------------------------------------------------------------------
  127. STDMETHODIMP
  128. CNWCOMPATNamespaceEnum::Next(
  129. ULONG cElements,
  130. VARIANT FAR* pvar,
  131. ULONG FAR* pcElementFetched
  132. )
  133. {
  134. ULONG cElementFetched = 0;
  135. HRESULT hr = S_OK;
  136. hr = EnumComputers(
  137. cElements,
  138. pvar,
  139. &cElementFetched
  140. );
  141. if (pcElementFetched) {
  142. *pcElementFetched = cElementFetched;
  143. }
  144. RRETURN_EXP_IF_ERR(hr);
  145. }
  146. //----------------------------------------------------------------------------
  147. //
  148. // Function: CNWCOMPATNamespaceEnum::EnumComputers
  149. //
  150. // Synopsis:
  151. //
  152. //----------------------------------------------------------------------------
  153. HRESULT
  154. CNWCOMPATNamespaceEnum::EnumComputers(
  155. ULONG cElements,
  156. VARIANT FAR* pvar,
  157. ULONG FAR* pcElementFetched
  158. )
  159. {
  160. HRESULT hr = S_OK;
  161. IDispatch *pDispatch = NULL;
  162. DWORD i = 0;
  163. while (i < cElements) {
  164. hr = GetComputerObject(&pDispatch);
  165. if (hr == S_FALSE) {
  166. break;
  167. }
  168. VariantInit(&pvar[i]);
  169. pvar[i].vt = VT_DISPATCH;
  170. pvar[i].pdispVal = pDispatch;
  171. (*pcElementFetched)++;
  172. i++;
  173. }
  174. return(hr);
  175. }
  176. //----------------------------------------------------------------------------
  177. //
  178. // Function: CNWCOMPATNamespaceEnum::GetComputerObject
  179. //
  180. // Synopsis:
  181. //
  182. //----------------------------------------------------------------------------
  183. HRESULT
  184. CNWCOMPATNamespaceEnum::GetComputerObject(
  185. IDispatch ** ppDispatch
  186. )
  187. {
  188. LPWSTR pszObjectName = NULL;
  189. HRESULT hr = S_OK;
  190. *ppDispatch = NULL;
  191. hr = NWApiObjectEnum(
  192. _hConn,
  193. OT_FILE_SERVER,
  194. &pszObjectName,
  195. &_dwResumeObjectID
  196. );
  197. BAIL_ON_FAILURE(hr);
  198. //
  199. // Now send back the current object
  200. //
  201. hr = CNWCOMPATComputer::CreateComputer(
  202. bstrProviderPrefix,
  203. pszObjectName,
  204. ADS_OBJECT_BOUND,
  205. IID_IDispatch,
  206. (void **)ppDispatch
  207. );
  208. BAIL_ON_FAILURE(hr);
  209. error:
  210. if (pszObjectName) {
  211. FreeADsStr(pszObjectName);
  212. }
  213. RRETURN_ENUM_STATUS(hr);
  214. }