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.

245 lines
5.8 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. CCredentials &Credentials,
  43. CNWCOMPATNamespaceEnum FAR* FAR* ppenumvariant
  44. )
  45. {
  46. HRESULT hr = S_OK;
  47. CNWCOMPATNamespaceEnum FAR* penumvariant = NULL;
  48. penumvariant = new CNWCOMPATNamespaceEnum();
  49. if (penumvariant == NULL){
  50. hr = E_OUTOFMEMORY;
  51. BAIL_ON_FAILURE(hr);
  52. }
  53. hr = NWApiGetAnyBinderyHandle(
  54. &penumvariant->_hConn
  55. );
  56. penumvariant->_Credentials = Credentials;
  57. *ppenumvariant = penumvariant;
  58. RRETURN(hr);
  59. error:
  60. if (penumvariant) {
  61. delete penumvariant;
  62. }
  63. NW_RRETURN_EXP_IF_ERR(hr);
  64. }
  65. //+---------------------------------------------------------------------------
  66. //
  67. // Function: CNWCOMPATNamespaceEnum::CNWCOMPATNamespaceEnum
  68. //
  69. // Synopsis:
  70. //
  71. //
  72. // Arguments:
  73. //
  74. //
  75. // Returns:
  76. //
  77. // Modifies:
  78. //
  79. // History: 01-30-95 krishnag Created.
  80. //
  81. //----------------------------------------------------------------------------
  82. CNWCOMPATNamespaceEnum::CNWCOMPATNamespaceEnum()
  83. {
  84. _dwResumeObjectID = 0xffffffff;
  85. _hConn = NULL;
  86. }
  87. //+---------------------------------------------------------------------------
  88. //
  89. // Function: CNWCOMPATNamespaceEnum::~CNWCOMPATNamespaceEnum
  90. //
  91. // Synopsis:
  92. //
  93. //
  94. // Arguments:
  95. //
  96. // Returns:
  97. //
  98. // Modifies:
  99. //
  100. // History: 01-30-95 krishnag Created.
  101. //
  102. //----------------------------------------------------------------------------
  103. CNWCOMPATNamespaceEnum::~CNWCOMPATNamespaceEnum()
  104. {
  105. if (_hConn) {
  106. NWApiReleaseBinderyHandle(_hConn);
  107. }
  108. }
  109. //+---------------------------------------------------------------------------
  110. //
  111. // Function: CNWCOMPATNamespaceEnum::Next
  112. //
  113. // Synopsis: Returns cElements number of requested ADs objects in the
  114. // array supplied in pvar.
  115. //
  116. // Arguments: [cElements] -- The number of elements requested by client
  117. // [pvar] -- ptr to array of VARIANTs to for return objects
  118. // [pcElementFetched] -- if non-NULL, then number of elements
  119. // -- actually returned is placed here
  120. //
  121. // Returns: HRESULT -- S_OK if number of elements requested are returned
  122. // -- S_FALSE if number of elements is < requested
  123. //
  124. // Modifies:
  125. //
  126. // History:
  127. //
  128. //----------------------------------------------------------------------------
  129. STDMETHODIMP
  130. CNWCOMPATNamespaceEnum::Next(
  131. ULONG cElements,
  132. VARIANT FAR* pvar,
  133. ULONG FAR* pcElementFetched
  134. )
  135. {
  136. ULONG cElementFetched = 0;
  137. HRESULT hr = S_OK;
  138. hr = EnumComputers(
  139. cElements,
  140. pvar,
  141. &cElementFetched
  142. );
  143. if (pcElementFetched) {
  144. *pcElementFetched = cElementFetched;
  145. }
  146. NW_RRETURN_EXP_IF_ERR(hr);
  147. }
  148. //----------------------------------------------------------------------------
  149. //
  150. // Function: CNWCOMPATNamespaceEnum::EnumComputers
  151. //
  152. // Synopsis:
  153. //
  154. //----------------------------------------------------------------------------
  155. HRESULT
  156. CNWCOMPATNamespaceEnum::EnumComputers(
  157. ULONG cElements,
  158. VARIANT FAR* pvar,
  159. ULONG FAR* pcElementFetched
  160. )
  161. {
  162. HRESULT hr = S_OK;
  163. IDispatch *pDispatch = NULL;
  164. DWORD i = 0;
  165. while (i < cElements) {
  166. hr = GetComputerObject(&pDispatch);
  167. if (hr == S_FALSE) {
  168. break;
  169. }
  170. VariantInit(&pvar[i]);
  171. pvar[i].vt = VT_DISPATCH;
  172. pvar[i].pdispVal = pDispatch;
  173. (*pcElementFetched)++;
  174. i++;
  175. }
  176. return(hr);
  177. }
  178. //----------------------------------------------------------------------------
  179. //
  180. // Function: CNWCOMPATNamespaceEnum::GetComputerObject
  181. //
  182. // Synopsis:
  183. //
  184. //----------------------------------------------------------------------------
  185. HRESULT
  186. CNWCOMPATNamespaceEnum::GetComputerObject(
  187. IDispatch ** ppDispatch
  188. )
  189. {
  190. LPWSTR pszObjectName = NULL;
  191. HRESULT hr = S_OK;
  192. *ppDispatch = NULL;
  193. hr = NWApiObjectEnum(
  194. _hConn,
  195. OT_FILE_SERVER,
  196. &pszObjectName,
  197. &_dwResumeObjectID
  198. );
  199. BAIL_ON_FAILURE(hr);
  200. //
  201. // Now send back the current object
  202. //
  203. hr = CNWCOMPATComputer::CreateComputer(
  204. L"NWCOMPAT:", // BUGBUG - 1) Hardcoded. 2) Not NW312
  205. pszObjectName,
  206. _Credentials,
  207. ADS_OBJECT_BOUND,
  208. IID_IDispatch,
  209. (void **)ppDispatch
  210. );
  211. BAIL_ON_FAILURE(hr);
  212. error:
  213. if (pszObjectName) {
  214. FreeADsStr(pszObjectName);
  215. }
  216. RRETURN_ENUM_STATUS(hr);
  217. }