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.

930 lines
21 KiB

  1. /*++
  2. Copyright (c) 1995-1996 Microsoft Corporation
  3. Module Name:
  4. cjob.cxx
  5. Abstract:
  6. Contains methods for Print Job object and its property sets for the
  7. Windows NT provider. Objects whose methods are supported here are
  8. CWinNTPrintJob,
  9. CWinNTPrintJob and
  10. CWinNTPrintJob.
  11. Author:
  12. Ram Viswanathan (ramv) 11-18-95
  13. Revision History:
  14. --*/
  15. #include "winnt.hxx"
  16. #pragma hdrstop
  17. #define INITGUID
  18. //
  19. // class CWinNTPrintJob Methods
  20. //
  21. DEFINE_IDispatch_ExtMgr_Implementation(CWinNTPrintJob);
  22. DEFINE_IADsExtension_ExtMgr_Implementation(CWinNTPrintJob);
  23. DEFINE_IADs_TempImplementation(CWinNTPrintJob);
  24. DEFINE_IADs_PutGetImplementation(CWinNTPrintJob, PrintJobClass,gdwJobTableSize);
  25. DEFINE_IADsPropertyList_Implementation(CWinNTPrintJob, PrintJobClass,gdwJobTableSize)
  26. CWinNTPrintJob::CWinNTPrintJob()
  27. {
  28. _pDispMgr = NULL;
  29. _pExtMgr = NULL;
  30. _hprinter = NULL;
  31. _lJobId = 0;
  32. _pszPrinterName = NULL;
  33. _pszPrinterPath = NULL;
  34. _pPropertyCache = NULL;
  35. ENLIST_TRACKING(CWinNTPrintJob);
  36. return;
  37. }
  38. CWinNTPrintJob::~CWinNTPrintJob()
  39. {
  40. if(_pszPrinterName){
  41. FreeADsStr(_pszPrinterName);
  42. }
  43. if(_pszPrinterPath){
  44. FreeADsStr(_pszPrinterPath);
  45. }
  46. _hprinter = NULL;
  47. delete _pExtMgr; // created last, destroyed first
  48. delete _pDispMgr;
  49. delete _pPropertyCache;
  50. return;
  51. }
  52. HRESULT
  53. CWinNTPrintJob::CreatePrintJob(
  54. LPTSTR pszPrinterPath,
  55. LONG lJobId,
  56. DWORD dwObjectState,
  57. REFIID riid,
  58. CWinNTCredentials& Credentials,
  59. LPVOID *ppvoid
  60. )
  61. {
  62. CWinNTPrintJob *pCWinNTPrintJob = NULL;
  63. HRESULT hr;
  64. TCHAR szJobName[MAX_LONG_LENGTH];
  65. POBJECTINFO pObjectInfo = NULL;
  66. TCHAR szUncPrinterName[MAX_PATH];
  67. //
  68. // Create the job object
  69. //
  70. hr = AllocatePrintJobObject(pszPrinterPath,
  71. &pCWinNTPrintJob
  72. );
  73. BAIL_ON_FAILURE(hr);
  74. ADsAssert(pCWinNTPrintJob->_pDispMgr);
  75. //
  76. // convert the JobId that we have into a string that we move
  77. // into the Name field
  78. //
  79. _ltow(lJobId, szJobName, 10);
  80. hr = pCWinNTPrintJob->InitializeCoreObject(pszPrinterPath,
  81. szJobName,
  82. PRINTJOB_CLASS_NAME,
  83. PRINTJOB_SCHEMA_NAME,
  84. CLSID_WinNTPrintJob,
  85. dwObjectState);
  86. BAIL_ON_FAILURE(hr);
  87. hr = BuildObjectInfo(pszPrinterPath,
  88. &pObjectInfo);
  89. BAIL_ON_FAILURE(hr);
  90. hr = PrinterNameFromObjectInfo(pObjectInfo,
  91. szUncPrinterName);
  92. BAIL_ON_FAILURE(hr);
  93. pCWinNTPrintJob->_Credentials = Credentials;
  94. hr = pCWinNTPrintJob->_Credentials.RefServer(
  95. pObjectInfo->ComponentArray[1]);
  96. BAIL_ON_FAILURE(hr);
  97. pCWinNTPrintJob->_pszPrinterName =
  98. AllocADsStr(szUncPrinterName);
  99. if(!(pCWinNTPrintJob->_pszPrinterName)){
  100. hr = E_OUTOFMEMORY;
  101. goto error;
  102. }
  103. pCWinNTPrintJob->_lJobId = lJobId;
  104. hr = SetLPTSTRPropertyInCache(pCWinNTPrintJob->_pPropertyCache,
  105. TEXT("HostPrintQueue"),
  106. pszPrinterPath,
  107. TRUE
  108. );
  109. //
  110. // Load ext mgr and extensions
  111. //
  112. hr = ADSILoadExtensionManager(
  113. PRINTJOB_CLASS_NAME,
  114. (IADsPrintJob *) pCWinNTPrintJob,
  115. pCWinNTPrintJob->_pDispMgr,
  116. Credentials,
  117. &pCWinNTPrintJob->_pExtMgr
  118. );
  119. BAIL_ON_FAILURE(hr);
  120. ADsAssert(pCWinNTPrintJob->_pExtMgr);
  121. // check if the call is from UMI
  122. if(Credentials.GetFlags() & ADS_AUTH_RESERVED) {
  123. //
  124. // we do not pass riid to InitUmiObject below. This is because UMI object
  125. // does not support IDispatch. There are several places in ADSI code where
  126. // riid passed into this function is defaulted to IID_IDispatch -
  127. // IADsContainer::Create for example. To handle these cases, we always
  128. // request IID_IUnknown from the UMI object. Subsequent code within UMI
  129. // will QI for the appropriate interface.
  130. //
  131. // Printjob objects have "" as their ADsPath. Just set the class for
  132. // iddentification purposes.
  133. pCWinNTPrintJob->_CompClasses[0] = L"PrintJob";
  134. hr = pCWinNTPrintJob->InitUmiObject(
  135. pCWinNTPrintJob->_Credentials,
  136. PrintJobClass,
  137. gdwJobTableSize,
  138. pCWinNTPrintJob->_pPropertyCache,
  139. (IUnknown *)(INonDelegatingUnknown *) pCWinNTPrintJob,
  140. pCWinNTPrintJob->_pExtMgr,
  141. IID_IUnknown,
  142. ppvoid
  143. );
  144. BAIL_ON_FAILURE(hr);
  145. FreeObjectInfo(pObjectInfo);
  146. //
  147. // UMI object was created and the interface was obtained successfully.
  148. // UMI object now has a reference to the inner unknown of IADs, since
  149. // the call to Release() below is not going to be made in this case.
  150. //
  151. RRETURN(hr);
  152. }
  153. hr = pCWinNTPrintJob->QueryInterface( riid,(void **)ppvoid);
  154. BAIL_ON_FAILURE(hr);
  155. pCWinNTPrintJob->Release();
  156. FreeObjectInfo(pObjectInfo);
  157. RRETURN(hr);
  158. error:
  159. FreeObjectInfo(pObjectInfo);
  160. delete pCWinNTPrintJob;
  161. RRETURN (hr);
  162. }
  163. HRESULT
  164. CWinNTPrintJob::AllocatePrintJobObject(
  165. LPTSTR pszPrinterPath,
  166. CWinNTPrintJob ** ppPrintJob
  167. )
  168. {
  169. CWinNTPrintJob FAR * pPrintJob = NULL;
  170. HRESULT hr = S_OK;
  171. pPrintJob = new CWinNTPrintJob();
  172. if (pPrintJob == NULL) {
  173. hr = E_OUTOFMEMORY;
  174. }
  175. BAIL_ON_FAILURE(hr);
  176. pPrintJob->_pszPrinterPath =
  177. AllocADsStr(pszPrinterPath);
  178. if(!(pPrintJob->_pszPrinterPath)){
  179. hr = E_OUTOFMEMORY;
  180. goto error;
  181. }
  182. pPrintJob->_pDispMgr = new CAggregatorDispMgr;
  183. if (pPrintJob->_pDispMgr == NULL) {
  184. hr = E_OUTOFMEMORY;
  185. }
  186. BAIL_ON_FAILURE(hr);
  187. hr = LoadTypeInfoEntry(
  188. pPrintJob->_pDispMgr,
  189. LIBID_ADs,
  190. IID_IADsPrintJob,
  191. (IADsPrintJob *)pPrintJob,
  192. DISPID_REGULAR
  193. );
  194. BAIL_ON_FAILURE(hr);
  195. hr = LoadTypeInfoEntry(
  196. pPrintJob->_pDispMgr,
  197. LIBID_ADs,
  198. IID_IADsPrintJobOperations,
  199. (IADsPrintJobOperations *)pPrintJob,
  200. DISPID_REGULAR
  201. );
  202. BAIL_ON_FAILURE(hr);
  203. hr = LoadTypeInfoEntry(
  204. pPrintJob->_pDispMgr,
  205. LIBID_ADs,
  206. IID_IADsPropertyList,
  207. (IADsPropertyList *)pPrintJob,
  208. DISPID_VALUE
  209. );
  210. BAIL_ON_FAILURE(hr);
  211. hr = CPropertyCache::createpropertycache(
  212. PrintJobClass,
  213. gdwJobTableSize,
  214. (CCoreADsObject *)pPrintJob,
  215. &(pPrintJob->_pPropertyCache)
  216. );
  217. BAIL_ON_FAILURE(hr);
  218. (pPrintJob->_pDispMgr)->RegisterPropertyCache(
  219. pPrintJob->_pPropertyCache
  220. );
  221. *ppPrintJob = pPrintJob;
  222. RRETURN(hr);
  223. error:
  224. //
  225. // direct memeber assignement assignement at pt of creation, so
  226. // do NOT delete _pPropertyCache or _pDisMgr here to avoid attempt
  227. // of deletion again in pPrintJob destructor and AV
  228. //
  229. delete pPrintJob;
  230. RRETURN_EXP_IF_ERR(hr);
  231. }
  232. /* IUnknown methods for printer object */
  233. //----------------------------------------------------------------------------
  234. // Function: QueryInterface
  235. //
  236. // Synopsis: If this object is aggregated within another object, then
  237. // all calls will delegate to the outer object. Otherwise, the
  238. // non-delegating QI is called
  239. //
  240. // Arguments:
  241. //
  242. // iid interface requested
  243. // ppInterface Returns pointer to interface requested. NULL if interface
  244. // is not supported.
  245. //
  246. // Returns: S_OK on success. Error code otherwise.
  247. //
  248. // Modifies: *ppInterface to return interface pointer
  249. //
  250. //----------------------------------------------------------------------------
  251. STDMETHODIMP CWinNTPrintJob::QueryInterface(
  252. REFIID iid,
  253. LPVOID *ppInterface
  254. )
  255. {
  256. if(_pUnkOuter != NULL)
  257. RRETURN(_pUnkOuter->QueryInterface(
  258. iid,
  259. ppInterface
  260. ));
  261. RRETURN(NonDelegatingQueryInterface(
  262. iid,
  263. ppInterface
  264. ));
  265. }
  266. //----------------------------------------------------------------------------
  267. // Function: AddRef
  268. //
  269. // Synopsis: IUnknown::AddRef. If this object is aggregated within
  270. // another, all calls will delegate to the outer object.
  271. // Otherwise, the non-delegating AddRef is called
  272. //
  273. // Arguments:
  274. //
  275. // None
  276. //
  277. // Returns: New reference count
  278. //
  279. // Modifies: Nothing
  280. //
  281. //----------------------------------------------------------------------------
  282. STDMETHODIMP_(ULONG) CWinNTPrintJob::AddRef(void)
  283. {
  284. if(_pUnkOuter != NULL)
  285. RRETURN(_pUnkOuter->AddRef());
  286. RRETURN(NonDelegatingAddRef());
  287. }
  288. //----------------------------------------------------------------------------
  289. // Function: Release
  290. //
  291. // Synopsis: IUnknown::Release. If this object is aggregated within
  292. // another, all calls will delegate to the outer object.
  293. // Otherwise, the non-delegating Release is called
  294. //
  295. // Arguments:
  296. //
  297. // None
  298. //
  299. // Returns: New reference count
  300. //
  301. // Modifies: Nothing
  302. //
  303. //----------------------------------------------------------------------------
  304. STDMETHODIMP_(ULONG) CWinNTPrintJob::Release(void)
  305. {
  306. if(_pUnkOuter != NULL)
  307. RRETURN(_pUnkOuter->Release());
  308. RRETURN(NonDelegatingRelease());
  309. }
  310. //----------------------------------------------------------------------------
  311. STDMETHODIMP
  312. CWinNTPrintJob::NonDelegatingQueryInterface(REFIID riid, LPVOID FAR* ppvObj)
  313. {
  314. HRESULT hr = S_OK;
  315. if(!ppvObj){
  316. RRETURN(E_POINTER);
  317. }
  318. if (IsEqualIID(riid, IID_IUnknown))
  319. {
  320. *ppvObj = (IADsPrintJob *)this;
  321. }
  322. else if (IsEqualIID(riid, IID_IDispatch))
  323. {
  324. *ppvObj = (IADsPrintJob *)this;
  325. }
  326. else if (IsEqualIID(riid, IID_ISupportErrorInfo))
  327. {
  328. *ppvObj = (ISupportErrorInfo FAR *)this;
  329. }
  330. else if (IsEqualIID(riid, IID_IADs))
  331. {
  332. *ppvObj = (IADsPrintJob FAR *) this;
  333. }
  334. else if (IsEqualIID(riid, IID_IADsPropertyList))
  335. {
  336. *ppvObj = (IADsPropertyList FAR *) this;
  337. }
  338. else if (IsEqualIID(riid, IID_IADsPrintJob))
  339. {
  340. *ppvObj = (IADsPrintJob FAR *) this;
  341. }
  342. else if (IsEqualIID(riid, IID_IADsPrintJobOperations))
  343. {
  344. *ppvObj = (IADsPrintJobOperations FAR *) this;
  345. }
  346. else if( (_pDispatch != NULL) &&
  347. IsEqualIID(riid, IID_IADsExtension) )
  348. {
  349. *ppvObj = (IADsExtension *) this;
  350. }
  351. else if (_pExtMgr)
  352. {
  353. RRETURN( _pExtMgr->QueryInterface(riid, ppvObj));
  354. }
  355. else
  356. {
  357. *ppvObj = NULL;
  358. RRETURN(E_NOINTERFACE);
  359. }
  360. ((LPUNKNOWN)*ppvObj)->AddRef();
  361. RRETURN(S_OK);
  362. }
  363. /* ISupportErrorInfo method */
  364. STDMETHODIMP
  365. CWinNTPrintJob::InterfaceSupportsErrorInfo(
  366. THIS_ REFIID riid
  367. )
  368. {
  369. if (IsEqualIID(riid, IID_IADs) ||
  370. IsEqualIID(riid, IID_IADsPrintJob) ||
  371. IsEqualIID(riid, IID_IADsPrintJobOperations) |\
  372. IsEqualIID(riid, IID_IADsPropertyList)) {
  373. RRETURN(S_OK);
  374. } else {
  375. RRETURN(S_FALSE);
  376. }
  377. }
  378. //+-----------------------------------------------------------------
  379. //
  380. // Function: SetInfo
  381. //
  382. // Synopsis: Binds to real printer as specified in _PrinterName and attempts
  383. // to set the real printer.
  384. //
  385. // Arguments: void
  386. //
  387. // Returns: HRESULT.
  388. //
  389. // Modifies:
  390. //
  391. // History: 11/08/95 RamV Created
  392. // part of code appropriated from NetOle project
  393. //----------------------------------------------------------------------------
  394. STDMETHODIMP
  395. CWinNTPrintJob::SetInfo(THIS)
  396. {
  397. BOOL fStatus = FALSE;
  398. LPJOB_INFO_2 lpJobInfo2 = NULL;
  399. HRESULT hr;
  400. //
  401. // do a getinfo to refresh those properties that arent being set
  402. //
  403. hr = GetJobInfo(2,
  404. (LPBYTE*)&lpJobInfo2,
  405. _pszPrinterName,
  406. _lJobId);
  407. BAIL_IF_ERROR(hr);
  408. hr = MarshallAndSet(lpJobInfo2,
  409. _pszPrinterName,
  410. _lJobId);
  411. BAIL_IF_ERROR(hr);
  412. if(SUCCEEDED(hr))
  413. _pPropertyCache->ClearModifiedFlags();
  414. cleanup:
  415. if(lpJobInfo2){
  416. FreeADsMem((LPBYTE)lpJobInfo2);
  417. }
  418. RRETURN_EXP_IF_ERR(hr);
  419. }
  420. STDMETHODIMP
  421. CWinNTPrintJob::GetInfo(THIS_ DWORD dwApiLevel, BOOL fExplicit)
  422. {
  423. LPJOB_INFO_1 lpJobInfo1 = NULL;
  424. LPJOB_INFO_2 lpJobInfo2 = NULL;
  425. HRESULT hr = S_OK;
  426. switch (dwApiLevel) {
  427. case 1:
  428. hr = GetJobInfo(dwApiLevel,
  429. (LPBYTE*)&lpJobInfo1,
  430. _pszPrinterName,
  431. _lJobId
  432. );
  433. BAIL_IF_ERROR(hr);
  434. hr = UnMarshallLevel1(lpJobInfo1,
  435. fExplicit
  436. );
  437. BAIL_IF_ERROR(hr);
  438. break;
  439. case 2:
  440. hr = GetJobInfo(dwApiLevel,
  441. (LPBYTE *)&lpJobInfo2,
  442. _pszPrinterName,
  443. _lJobId
  444. );
  445. BAIL_IF_ERROR(hr);
  446. hr = UnMarshallLevel2(lpJobInfo2,
  447. fExplicit
  448. );
  449. BAIL_IF_ERROR(hr);
  450. break;
  451. default:
  452. hr = E_FAIL;
  453. break;
  454. }
  455. cleanup:
  456. if (lpJobInfo1) {
  457. FreeADsMem(lpJobInfo1);
  458. }
  459. if (lpJobInfo2) {
  460. FreeADsMem(lpJobInfo2);
  461. }
  462. RRETURN_EXP_IF_ERR(hr);
  463. }
  464. //+---------------------------------------------------------------------------
  465. //
  466. // Function: GetInfo
  467. //
  468. // Synopsis: Binds to real printer as specified in _PrinterName and attempts
  469. // to get information from the real printer.
  470. //
  471. // Arguments: void
  472. //
  473. // Returns: HRESULT.
  474. //
  475. // Modifies:
  476. //
  477. // History: 11/08/95 RamV Created
  478. // part of code appropriated from NetOle project
  479. //----------------------------------------------------------------------------
  480. STDMETHODIMP
  481. CWinNTPrintJob::GetInfo(THIS)
  482. {
  483. RRETURN(GetInfo(2, TRUE));
  484. }
  485. STDMETHODIMP
  486. CWinNTPrintJob::ImplicitGetInfo(THIS)
  487. {
  488. RRETURN(GetInfo(2, FALSE));
  489. }
  490. STDMETHODIMP
  491. CWinNTPrintJob::get_Description(THIS_ BSTR FAR* retval)
  492. {
  493. GET_PROPERTY_BSTR((IADsPrintJob *)this, Description);
  494. }
  495. STDMETHODIMP
  496. CWinNTPrintJob::put_Description(THIS_ BSTR bstrDescription)
  497. {
  498. PUT_PROPERTY_BSTR((IADsPrintJob *)this, Description);
  499. }
  500. STDMETHODIMP
  501. CWinNTPrintJob::get_HostPrintQueue(THIS_ BSTR FAR* retval)
  502. {
  503. GET_PROPERTY_BSTR((IADsPrintJob *)this, HostPrintQueue);
  504. }
  505. STDMETHODIMP
  506. CWinNTPrintJob::get_User(THIS_ BSTR FAR* retval)
  507. {
  508. GET_PROPERTY_BSTR((IADsPrintJob *)this, User);
  509. }
  510. STDMETHODIMP
  511. CWinNTPrintJob::get_UserPath(THIS_ BSTR FAR* retval)
  512. {
  513. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  514. }
  515. STDMETHODIMP
  516. CWinNTPrintJob::put_Priority(THIS_ LONG lPriority)
  517. {
  518. PUT_PROPERTY_LONG((IADsPrintJob *)this, Priority);
  519. }
  520. STDMETHODIMP
  521. CWinNTPrintJob::get_Priority(THIS_ LONG FAR* retval)
  522. {
  523. GET_PROPERTY_LONG((IADsPrintJob *)this, Priority);
  524. }
  525. STDMETHODIMP
  526. CWinNTPrintJob::get_TimeSubmitted(THIS_ DATE FAR* retval)
  527. {
  528. GET_PROPERTY_DATE((IADsPrintJob *)this, TimeSubmitted);
  529. }
  530. STDMETHODIMP
  531. CWinNTPrintJob::get_TotalPages(THIS_ LONG FAR* retval)
  532. {
  533. GET_PROPERTY_LONG((IADsPrintJob *)this, TotalPages);
  534. }
  535. STDMETHODIMP
  536. CWinNTPrintJob::put_StartTime(THIS_ DATE daStartTime)
  537. {
  538. PUT_PROPERTY_DATE((IADsPrintJob *)this, StartTime);
  539. }
  540. STDMETHODIMP
  541. CWinNTPrintJob::get_StartTime(THIS_ DATE FAR* retval)
  542. {
  543. GET_PROPERTY_DATE((IADsPrintJob *)this, StartTime);
  544. }
  545. STDMETHODIMP
  546. CWinNTPrintJob::put_UntilTime(THIS_ DATE daUntilTime)
  547. {
  548. PUT_PROPERTY_DATE((IADsPrintJob *)this, UntilTime);
  549. }
  550. STDMETHODIMP
  551. CWinNTPrintJob::get_UntilTime(THIS_ DATE FAR* retval)
  552. {
  553. GET_PROPERTY_DATE((IADsPrintJob *)this, UntilTime);
  554. }
  555. STDMETHODIMP
  556. CWinNTPrintJob::get_Size(THIS_ LONG FAR* retval)
  557. {
  558. GET_PROPERTY_LONG((IADsPrintJob *)this, Size);
  559. }
  560. STDMETHODIMP
  561. CWinNTPrintJob::put_Notify(THIS_ BSTR bstrNotify)
  562. {
  563. PUT_PROPERTY_BSTR((IADsPrintJob *)this, Notify);
  564. }
  565. STDMETHODIMP
  566. CWinNTPrintJob::get_Notify(THIS_ BSTR FAR* retval)
  567. {
  568. GET_PROPERTY_BSTR((IADsPrintJob *)this, Notify);
  569. }
  570. STDMETHODIMP
  571. CWinNTPrintJob::put_NotifyPath(THIS_ BSTR bstrNotify)
  572. {
  573. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  574. }
  575. STDMETHODIMP
  576. CWinNTPrintJob::get_NotifyPath(THIS_ BSTR FAR* retval)
  577. {
  578. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  579. }
  580. STDMETHODIMP
  581. CWinNTPrintJob::put_Position(THIS_ LONG lPosition)
  582. {
  583. PUT_PROPERTY_LONG((IADsPrintJob *)this, Position);
  584. }
  585. STDMETHODIMP
  586. CWinNTPrintJob::get_Position(THIS_ LONG FAR* retval)
  587. {
  588. GET_PROPERTY_LONG((IADsPrintJob *)this, Position);
  589. }
  590. STDMETHODIMP
  591. CWinNTPrintJob::get_PagesPrinted(THIS_ LONG FAR* retval)
  592. {
  593. GET_PROPERTY_LONG((IADsPrintJob *)this, PagesPrinted);
  594. }
  595. STDMETHODIMP
  596. CWinNTPrintJob::get_TimeElapsed(THIS_ LONG FAR* retval)
  597. {
  598. GET_PROPERTY_LONG((IADsPrintJob *)this, TimeElapsed);
  599. }
  600. //+------------------------------------------------------------------------
  601. //
  602. // Function: CWinNTPrintJob::Pause
  603. //
  604. // Synopsis: Binds to real printer as specified in _lpszPrinterName and attempts
  605. // to pause this job.
  606. //
  607. // Arguments: none
  608. //
  609. // Returns: HRESULT.
  610. //
  611. // Modifies: nothing
  612. //
  613. // History: 11-07-95 RamV Created
  614. //
  615. //---------------------------------------------------------------------------
  616. STDMETHODIMP
  617. CWinNTPrintJob::Pause(THIS)
  618. {
  619. BOOL fStatus = FALSE;
  620. PRINTER_DEFAULTS PrinterDefaults = {0, 0, PRINTER_ACCESS_USE};
  621. HANDLE hPrinter = NULL;
  622. HRESULT hr = S_OK;
  623. //
  624. // we need to open the printer with the right printer
  625. // defaults in order to perform the operations that we
  626. // have here
  627. //
  628. fStatus = OpenPrinter((LPTSTR)_pszPrinterName,
  629. &hPrinter,
  630. &PrinterDefaults
  631. );
  632. if (!fStatus) {
  633. hr = HRESULT_FROM_WIN32(GetLastError());
  634. goto cleanup;
  635. }
  636. fStatus = SetJob (hPrinter,
  637. _lJobId,
  638. 0,
  639. NULL,
  640. JOB_CONTROL_PAUSE
  641. );
  642. if (!fStatus) {
  643. hr = HRESULT_FROM_WIN32(GetLastError());
  644. goto cleanup;
  645. }
  646. cleanup:
  647. fStatus = ClosePrinter(hPrinter);
  648. RRETURN_EXP_IF_ERR(hr);
  649. }
  650. STDMETHODIMP
  651. CWinNTPrintJob::Resume(THIS)
  652. {
  653. BOOL fStatus = FALSE;
  654. PRINTER_DEFAULTS PrinterDefaults = {0, 0, PRINTER_ACCESS_USE};
  655. HANDLE hPrinter = NULL;
  656. HRESULT hr = S_OK;
  657. //
  658. // we need to open the printer with the right printer
  659. // defaults in order to perform the operations that we
  660. // have here
  661. //
  662. fStatus = OpenPrinter((LPTSTR)_pszPrinterName,
  663. &hPrinter,
  664. &PrinterDefaults
  665. );
  666. if (!fStatus) {
  667. hr =HRESULT_FROM_WIN32(GetLastError());
  668. goto cleanup;
  669. }
  670. fStatus = SetJob (hPrinter,
  671. _lJobId,
  672. 0,
  673. NULL,
  674. JOB_CONTROL_RESUME
  675. );
  676. if (!fStatus) {
  677. hr = HRESULT_FROM_WIN32(GetLastError());
  678. goto cleanup;
  679. }
  680. cleanup:
  681. fStatus = ClosePrinter(hPrinter);
  682. RRETURN_EXP_IF_ERR(hr);
  683. }
  684. STDMETHODIMP
  685. CWinNTPrintJob::Remove(THIS)
  686. {
  687. BOOL fStatus = FALSE;
  688. PRINTER_DEFAULTS PrinterDefaults = {0, 0, PRINTER_ACCESS_USE};
  689. HANDLE hPrinter = NULL;
  690. HRESULT hr = S_OK;
  691. fStatus = OpenPrinter((LPTSTR)_pszPrinterName,
  692. &hPrinter,
  693. &PrinterDefaults
  694. );
  695. if (!fStatus) {
  696. hr = HRESULT_FROM_WIN32(GetLastError());
  697. goto cleanup;
  698. }
  699. //
  700. // se JOB_CONTROL_DELETE instead of JOB_CONTROL_CANCEL as DELETE works
  701. // even when a print job has been restarted while CANCLE won't
  702. //
  703. fStatus = SetJob (hPrinter,
  704. _lJobId,
  705. 0,
  706. NULL,
  707. JOB_CONTROL_DELETE
  708. );
  709. if (!fStatus) {
  710. hr = HRESULT_FROM_WIN32(GetLastError());
  711. goto cleanup;
  712. }
  713. cleanup:
  714. fStatus = ClosePrinter(hPrinter);
  715. RRETURN_EXP_IF_ERR(hr);
  716. }
  717. STDMETHODIMP
  718. CWinNTPrintJob::get_Status(THIS_ long FAR* retval)
  719. {
  720. HRESULT hr =S_OK;
  721. LPJOB_INFO_1 lpJobInfo1 = NULL;
  722. BOOL found;
  723. DWORD dwStatus;
  724. if(!retval){
  725. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  726. }
  727. hr = GetJobInfo(1,
  728. (LPBYTE*)&lpJobInfo1,
  729. _pszPrinterName,
  730. _lJobId);
  731. BAIL_IF_ERROR(hr);
  732. //
  733. // instead of a conversion routine, just return the WinNT
  734. // Status code
  735. //
  736. *retval = lpJobInfo1->Status;
  737. cleanup:
  738. if(lpJobInfo1){
  739. FreeADsMem((LPBYTE)lpJobInfo1);
  740. }
  741. RRETURN_EXP_IF_ERR(hr);
  742. }