Leaked source code of windows server 2003
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.

372 lines
8.1 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. {
  29. ENLIST_TRACKING(CNWCOMPATJobCollection);
  30. }
  31. //----------------------------------------------------------------------------
  32. //
  33. // Function: CNWCOMPATJobCollection::CreateJobCollection
  34. //
  35. // Synopsis:
  36. //
  37. //----------------------------------------------------------------------------
  38. HRESULT
  39. CNWCOMPATJobCollection::CreateJobCollection(
  40. BSTR bstrParent,
  41. BSTR bstrPrinterName,
  42. REFIID riid,
  43. void **ppvObj
  44. )
  45. {
  46. CNWCOMPATJobCollection FAR * pJobs = NULL;
  47. HRESULT hr = S_OK;
  48. hr = AllocateJobCollectionObject(&pJobs);
  49. BAIL_ON_FAILURE(hr);
  50. hr = pJobs->InitializeCoreObject(
  51. bstrParent,
  52. bstrPrinterName,
  53. PRINTER_CLASS_NAME,
  54. NO_SCHEMA,
  55. CLSID_NWCOMPATPrintQueue,
  56. ADS_OBJECT_UNBOUND
  57. );
  58. BAIL_ON_FAILURE(hr);
  59. hr = pJobs->QueryInterface(riid, ppvObj);
  60. BAIL_ON_FAILURE(hr);
  61. pJobs->Release();
  62. RRETURN(hr);
  63. error:
  64. delete pJobs;
  65. RRETURN_EXP_IF_ERR(hr);
  66. }
  67. //----------------------------------------------------------------------------
  68. //
  69. // Function: CNWCOMPATJobCollection::~CNWCOMPATJobCollection
  70. //
  71. // Synopsis:
  72. //
  73. //----------------------------------------------------------------------------
  74. CNWCOMPATJobCollection::~CNWCOMPATJobCollection( )
  75. {
  76. delete _pDispMgr;
  77. }
  78. //----------------------------------------------------------------------------
  79. //
  80. // Function: CNWCOMPATJobCollection::QueryInterface
  81. //
  82. // Synopsis:
  83. //
  84. //----------------------------------------------------------------------------
  85. STDMETHODIMP
  86. CNWCOMPATJobCollection::QueryInterface(
  87. REFIID iid,
  88. LPVOID FAR* ppv
  89. )
  90. {
  91. if (ppv == NULL) {
  92. RRETURN(E_POINTER);
  93. }
  94. if (IsEqualIID(iid, IID_IUnknown))
  95. {
  96. *ppv = (IADsCollection FAR *) this;
  97. }
  98. else if (IsEqualIID(iid, IID_IADsCollection))
  99. {
  100. *ppv = (IADsCollection FAR *) this;
  101. }
  102. else if (IsEqualIID(iid, IID_IDispatch))
  103. {
  104. *ppv = (IADsCollection FAR *) this;
  105. }
  106. else if (IsEqualIID(iid, IID_ISupportErrorInfo))
  107. {
  108. *ppv = (ISupportErrorInfo FAR *) this;
  109. }
  110. else
  111. {
  112. *ppv = NULL;
  113. return E_NOINTERFACE;
  114. }
  115. AddRef();
  116. return NOERROR;
  117. }
  118. //----------------------------------------------------------------------------
  119. //
  120. // Function: CNWCOMPATJobCollection::InterfaceSupportsErrorInfo
  121. //
  122. // Synopsis:
  123. //
  124. //----------------------------------------------------------------------------
  125. STDMETHODIMP
  126. CNWCOMPATJobCollection::InterfaceSupportsErrorInfo(
  127. THIS_ REFIID riid
  128. )
  129. {
  130. if (IsEqualIID(riid, IID_IADsCollection)) {
  131. RRETURN(S_OK);
  132. } else {
  133. RRETURN(S_FALSE);
  134. }
  135. }
  136. //----------------------------------------------------------------------------
  137. //
  138. // Function: CNWCOMPATJobCollection::get__NewEnum
  139. //
  140. // Synopsis:
  141. //
  142. //----------------------------------------------------------------------------
  143. STDMETHODIMP
  144. CNWCOMPATJobCollection::get__NewEnum(
  145. THIS_ IUnknown FAR* FAR* retval
  146. )
  147. {
  148. HRESULT hr = S_OK;
  149. IEnumVARIANT * pEnum = NULL;
  150. WCHAR szPrinterName[MAX_PATH];
  151. //
  152. // Validate input parameter.
  153. //
  154. if (!retval) {
  155. RRETURN(E_ADS_BAD_PARAMETER);
  156. }
  157. *retval = NULL;
  158. //
  159. // Express printer name as an ADsPath.
  160. //
  161. wsprintf(szPrinterName,
  162. L"%s/%s",
  163. _Parent,
  164. _Name );
  165. //
  166. // Create enumerator.
  167. //
  168. hr = CNWCOMPATJobCollectionEnum::Create(
  169. (CNWCOMPATJobCollectionEnum **)&pEnum,
  170. szPrinterName
  171. );
  172. BAIL_ON_FAILURE(hr);
  173. hr = pEnum->QueryInterface(
  174. IID_IUnknown,
  175. (VOID FAR* FAR*)retval
  176. );
  177. BAIL_ON_FAILURE(hr);
  178. if (pEnum) {
  179. pEnum->Release();
  180. }
  181. //
  182. // Return.
  183. //
  184. RRETURN(NOERROR);
  185. error:
  186. if (pEnum) {
  187. delete pEnum;
  188. }
  189. RRETURN_EXP_IF_ERR(hr);
  190. }
  191. //----------------------------------------------------------------------------
  192. //
  193. // Function: CNWCOMPATJobCollection::GetObject
  194. //
  195. // Synopsis:
  196. //
  197. //----------------------------------------------------------------------------
  198. STDMETHODIMP
  199. CNWCOMPATJobCollection::GetObject(
  200. THIS_ BSTR bstrName,
  201. VARIANT FAR* pvItem
  202. )
  203. {
  204. HRESULT hr = S_OK;
  205. DWORD dwJobId = 0;
  206. IDispatch *pDispatch = NULL;
  207. //
  208. // Validate input parameters.
  209. //
  210. if(!bstrName || !pvItem){
  211. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  212. }
  213. //
  214. // Convert bstrName, which is a JobId, into DWORD.
  215. //
  216. dwJobId = (DWORD)_wtol(bstrName);
  217. //
  218. // Create the desire print job object.
  219. //
  220. hr = CNWCOMPATPrintJob::CreatePrintJob(
  221. _ADsPath,
  222. dwJobId,
  223. ADS_OBJECT_BOUND,
  224. IID_IDispatch,
  225. (void **)&pDispatch
  226. );
  227. BAIL_ON_FAILURE(hr);
  228. //
  229. // stick this IDispatch pointer into a caller provided variant
  230. //
  231. VariantInit(pvItem);
  232. V_VT(pvItem) = VT_DISPATCH;
  233. V_DISPATCH(pvItem) = pDispatch;
  234. error:
  235. RRETURN_EXP_IF_ERR(hr);
  236. }
  237. //----------------------------------------------------------------------------
  238. //
  239. // Function: CNWCOMPATJobCollection::Add
  240. //
  241. // Synopsis:
  242. //
  243. //----------------------------------------------------------------------------
  244. STDMETHODIMP
  245. CNWCOMPATJobCollection::Add(
  246. THIS_ BSTR bstrNewItem,
  247. VARIANT vItem
  248. )
  249. {
  250. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  251. }
  252. //----------------------------------------------------------------------------
  253. //
  254. // Function: CNWCOMPATJobCollection::Remove
  255. //
  256. // Synopsis:
  257. //
  258. //----------------------------------------------------------------------------
  259. STDMETHODIMP
  260. CNWCOMPATJobCollection::Remove(
  261. THIS_ BSTR bstrItemToBeRemoved
  262. )
  263. {
  264. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  265. }
  266. //----------------------------------------------------------------------------
  267. //
  268. // Function: CNWCOMPATJobCollection::AllocateJobCollectionObject
  269. //
  270. // Synopsis:
  271. //
  272. //----------------------------------------------------------------------------
  273. HRESULT
  274. CNWCOMPATJobCollection::AllocateJobCollectionObject(
  275. CNWCOMPATJobCollection ** ppJob
  276. )
  277. {
  278. CNWCOMPATJobCollection FAR * pJob = NULL;
  279. CAggregatorDispMgr FAR * pDispMgr = NULL;
  280. HRESULT hr = S_OK;
  281. //
  282. // Allocate memory for a JobCollection object.
  283. //
  284. pJob = new CNWCOMPATJobCollection();
  285. if (pJob == NULL) {
  286. hr = E_OUTOFMEMORY;
  287. }
  288. BAIL_ON_FAILURE(hr);
  289. //
  290. // Create a Dispatch Manager object.
  291. //
  292. pDispMgr = new CAggregatorDispMgr;
  293. if (pDispMgr == NULL) {
  294. hr = E_OUTOFMEMORY;
  295. }
  296. BAIL_ON_FAILURE(hr);
  297. //
  298. // Load type info.
  299. //
  300. hr = LoadTypeInfoEntry(
  301. pDispMgr,
  302. LIBID_ADs,
  303. IID_IADsCollection,
  304. (IADsCollection *)pJob,
  305. DISPID_NEWENUM
  306. );
  307. BAIL_ON_FAILURE(hr);
  308. //
  309. // Return.
  310. //
  311. pJob->_pDispMgr = pDispMgr;
  312. *ppJob = pJob;
  313. RRETURN(hr);
  314. error:
  315. delete pJob;
  316. delete pDispMgr;
  317. RRETURN(hr);
  318. }