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.

410 lines
8.5 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996
  5. //
  6. // File: cjobs.cxx
  7. //
  8. // Contents: Job collection object
  9. //
  10. // History: May-08-96 t-ptam (PatrickT) Created.
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "NWCOMPAT.hxx"
  14. #pragma hdrstop
  15. //
  16. // Macro-iszed implementation.
  17. //
  18. DEFINE_IDispatch_Implementation(CNWCOMPATJobCollection)
  19. //----------------------------------------------------------------------------
  20. //
  21. // Function: CNWCOMPATJobCollection::CNWCOMPATJobCollection
  22. //
  23. // Synopsis:
  24. //
  25. //----------------------------------------------------------------------------
  26. CNWCOMPATJobCollection::CNWCOMPATJobCollection():
  27. _pDispMgr(NULL),
  28. _hConn(NULL)
  29. {
  30. ENLIST_TRACKING(CNWCOMPATJobCollection);
  31. }
  32. //----------------------------------------------------------------------------
  33. //
  34. // Function: CNWCOMPATJobCollection::CreateJobCollection
  35. //
  36. // Synopsis:
  37. //
  38. //----------------------------------------------------------------------------
  39. HRESULT
  40. CNWCOMPATJobCollection::CreateJobCollection(
  41. BSTR bstrParent,
  42. BSTR bstrPrinterName,
  43. CCredentials &Credentials,
  44. REFIID riid,
  45. void **ppvObj
  46. )
  47. {
  48. CNWCOMPATJobCollection FAR * pJobs = NULL;
  49. HRESULT hr = S_OK;
  50. POBJECTINFO pObjectInfo = NULL;
  51. hr = AllocateJobCollectionObject(&pJobs);
  52. BAIL_ON_FAILURE(hr);
  53. hr = pJobs->InitializeCoreObject(
  54. bstrParent,
  55. bstrPrinterName,
  56. PRINTER_CLASS_NAME,
  57. NO_SCHEMA,
  58. CLSID_NWCOMPATPrintQueue,
  59. ADS_OBJECT_UNBOUND
  60. );
  61. BAIL_ON_FAILURE(hr);
  62. pJobs->_Credentials = Credentials;
  63. //
  64. // Componentize ADs name.
  65. //
  66. hr = BuildObjectInfo(
  67. pJobs->_Parent,
  68. pJobs->_Name,
  69. &pObjectInfo
  70. );
  71. BAIL_ON_FAILURE(hr);
  72. //
  73. // Get a handle to the bindery this object resides on.
  74. //
  75. hr = NWApiGetBinderyHandle(
  76. &pJobs->_hConn,
  77. pObjectInfo->ComponentArray[0],
  78. pJobs->_Credentials
  79. );
  80. BAIL_ON_FAILURE(hr);
  81. hr = pJobs->QueryInterface(riid, ppvObj);
  82. BAIL_ON_FAILURE(hr);
  83. pJobs->Release();
  84. FreeObjectInfo(pObjectInfo);
  85. RRETURN(hr);
  86. error:
  87. if (pObjectInfo)
  88. FreeObjectInfo(pObjectInfo);
  89. delete pJobs;
  90. NW_RRETURN_EXP_IF_ERR(hr);
  91. }
  92. //----------------------------------------------------------------------------
  93. //
  94. // Function: CNWCOMPATJobCollection::~CNWCOMPATJobCollection
  95. //
  96. // Synopsis:
  97. //
  98. //----------------------------------------------------------------------------
  99. CNWCOMPATJobCollection::~CNWCOMPATJobCollection( )
  100. {
  101. delete _pDispMgr;
  102. if (_hConn)
  103. NWApiReleaseBinderyHandle(_hConn);
  104. }
  105. //----------------------------------------------------------------------------
  106. //
  107. // Function: CNWCOMPATJobCollection::QueryInterface
  108. //
  109. // Synopsis:
  110. //
  111. //----------------------------------------------------------------------------
  112. STDMETHODIMP
  113. CNWCOMPATJobCollection::QueryInterface(
  114. REFIID iid,
  115. LPVOID FAR* ppv
  116. )
  117. {
  118. if (ppv == NULL) {
  119. RRETURN(E_POINTER);
  120. }
  121. if (IsEqualIID(iid, IID_IUnknown))
  122. {
  123. *ppv = (IADsCollection FAR *) this;
  124. }
  125. else if (IsEqualIID(iid, IID_IADsCollection))
  126. {
  127. *ppv = (IADsCollection FAR *) this;
  128. }
  129. else if (IsEqualIID(iid, IID_IDispatch))
  130. {
  131. *ppv = (IADsCollection FAR *) this;
  132. }
  133. else if (IsEqualIID(iid, IID_ISupportErrorInfo))
  134. {
  135. *ppv = (ISupportErrorInfo FAR *) this;
  136. }
  137. else
  138. {
  139. *ppv = NULL;
  140. return E_NOINTERFACE;
  141. }
  142. AddRef();
  143. return NOERROR;
  144. }
  145. //----------------------------------------------------------------------------
  146. //
  147. // Function: CNWCOMPATJobCollection::InterfaceSupportsErrorInfo
  148. //
  149. // Synopsis:
  150. //
  151. //----------------------------------------------------------------------------
  152. STDMETHODIMP
  153. CNWCOMPATJobCollection::InterfaceSupportsErrorInfo(
  154. THIS_ REFIID riid
  155. )
  156. {
  157. if (IsEqualIID(riid, IID_IADsCollection)) {
  158. RRETURN(S_OK);
  159. } else {
  160. RRETURN(S_FALSE);
  161. }
  162. }
  163. //----------------------------------------------------------------------------
  164. //
  165. // Function: CNWCOMPATJobCollection::get__NewEnum
  166. //
  167. // Synopsis:
  168. //
  169. //----------------------------------------------------------------------------
  170. STDMETHODIMP
  171. CNWCOMPATJobCollection::get__NewEnum(
  172. THIS_ IUnknown FAR* FAR* retval
  173. )
  174. {
  175. HRESULT hr = S_OK;
  176. IEnumVARIANT * pEnum = NULL;
  177. WCHAR szPrinterName[MAX_PATH];
  178. //
  179. // Validate input parameter.
  180. //
  181. if (!retval) {
  182. RRETURN(E_ADS_BAD_PARAMETER);
  183. }
  184. *retval = NULL;
  185. //
  186. // Express printer name as an ADsPath.
  187. //
  188. wsprintf(szPrinterName,
  189. L"%s/%s",
  190. _Parent,
  191. _Name );
  192. //
  193. // Create enumerator.
  194. //
  195. hr = CNWCOMPATJobCollectionEnum::Create(
  196. (CNWCOMPATJobCollectionEnum **)&pEnum,
  197. szPrinterName,
  198. _Credentials
  199. );
  200. BAIL_ON_FAILURE(hr);
  201. hr = pEnum->QueryInterface(
  202. IID_IUnknown,
  203. (VOID FAR* FAR*)retval
  204. );
  205. BAIL_ON_FAILURE(hr);
  206. if (pEnum) {
  207. pEnum->Release();
  208. }
  209. //
  210. // Return.
  211. //
  212. RRETURN(NOERROR);
  213. error:
  214. if (pEnum) {
  215. delete pEnum;
  216. }
  217. NW_RRETURN_EXP_IF_ERR(hr);
  218. }
  219. //----------------------------------------------------------------------------
  220. //
  221. // Function: CNWCOMPATJobCollection::GetObject
  222. //
  223. // Synopsis:
  224. //
  225. //----------------------------------------------------------------------------
  226. STDMETHODIMP
  227. CNWCOMPATJobCollection::GetObject(
  228. THIS_ BSTR bstrName,
  229. VARIANT FAR* pvItem
  230. )
  231. {
  232. HRESULT hr = S_OK;
  233. DWORD dwJobId = 0;
  234. IDispatch *pDispatch = NULL;
  235. //
  236. // Validate input parameters.
  237. //
  238. if(!bstrName || !pvItem){
  239. NW_RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  240. }
  241. //
  242. // Convert bstrName, which is a JobId, into DWORD.
  243. //
  244. dwJobId = (DWORD)_wtol(bstrName);
  245. //
  246. // Create the desire print job object.
  247. //
  248. hr = CNWCOMPATPrintJob::CreatePrintJob(
  249. _ADsPath,
  250. dwJobId,
  251. _Credentials,
  252. ADS_OBJECT_BOUND,
  253. IID_IDispatch,
  254. (void **)&pDispatch
  255. );
  256. BAIL_ON_FAILURE(hr);
  257. //
  258. // stick this IDispatch pointer into a caller provided variant
  259. //
  260. VariantInit(pvItem);
  261. V_VT(pvItem) = VT_DISPATCH;
  262. V_DISPATCH(pvItem) = pDispatch;
  263. error:
  264. NW_RRETURN_EXP_IF_ERR(hr);
  265. }
  266. //----------------------------------------------------------------------------
  267. //
  268. // Function: CNWCOMPATJobCollection::Add
  269. //
  270. // Synopsis:
  271. //
  272. //----------------------------------------------------------------------------
  273. STDMETHODIMP
  274. CNWCOMPATJobCollection::Add(
  275. THIS_ BSTR bstrNewItem,
  276. VARIANT vItem
  277. )
  278. {
  279. NW_RRETURN_EXP_IF_ERR(E_NOTIMPL);
  280. }
  281. //----------------------------------------------------------------------------
  282. //
  283. // Function: CNWCOMPATJobCollection::Remove
  284. //
  285. // Synopsis:
  286. //
  287. //----------------------------------------------------------------------------
  288. STDMETHODIMP
  289. CNWCOMPATJobCollection::Remove(
  290. THIS_ BSTR bstrItemToBeRemoved
  291. )
  292. {
  293. NW_RRETURN_EXP_IF_ERR(E_NOTIMPL);
  294. }
  295. //----------------------------------------------------------------------------
  296. //
  297. // Function: CNWCOMPATJobCollection::AllocateJobCollectionObject
  298. //
  299. // Synopsis:
  300. //
  301. //----------------------------------------------------------------------------
  302. HRESULT
  303. CNWCOMPATJobCollection::AllocateJobCollectionObject(
  304. CNWCOMPATJobCollection ** ppJob
  305. )
  306. {
  307. CNWCOMPATJobCollection FAR * pJob = NULL;
  308. CDispatchMgr FAR * pDispMgr = NULL;
  309. HRESULT hr = S_OK;
  310. //
  311. // Allocate memory for a JobCollection object.
  312. //
  313. pJob = new CNWCOMPATJobCollection();
  314. if (pJob == NULL) {
  315. hr = E_OUTOFMEMORY;
  316. }
  317. BAIL_ON_FAILURE(hr);
  318. //
  319. // Create a Dispatch Manager object.
  320. //
  321. pDispMgr = new CDispatchMgr;
  322. if (pDispMgr == NULL) {
  323. hr = E_OUTOFMEMORY;
  324. }
  325. BAIL_ON_FAILURE(hr);
  326. //
  327. // Load type info.
  328. //
  329. hr = LoadTypeInfoEntry(
  330. pDispMgr,
  331. LIBID_ADs,
  332. IID_IADsCollection,
  333. (IADsCollection *)pJob,
  334. DISPID_NEWENUM
  335. );
  336. BAIL_ON_FAILURE(hr);
  337. //
  338. // Return.
  339. //
  340. pJob->_pDispMgr = pDispMgr;
  341. *ppJob = pJob;
  342. RRETURN(hr);
  343. error:
  344. delete pJob;
  345. delete pDispMgr;
  346. RRETURN(hr);
  347. }