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.

439 lines
9.1 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. cprinter.cxx
  5. Abstract:
  6. Contains methods for PrintQueue object, GeneralInfo property set
  7. and Operation property set for the Print Queue object for the Windows NT
  8. provider
  9. Author:
  10. Ram Viswanathan (ramv) 11-09-95
  11. Revision History:
  12. --*/
  13. #include "winnt.hxx"
  14. #pragma hdrstop
  15. //
  16. // CWinNTPrintQueue
  17. //
  18. STDMETHODIMP
  19. CWinNTPrintQueue::put_Model(THIS_ BSTR bstrModel)
  20. {
  21. PUT_PROPERTY_BSTR((IADsPrintQueue *)this, Model);
  22. }
  23. STDMETHODIMP
  24. CWinNTPrintQueue::get_Model(THIS_ BSTR FAR* retval)
  25. {
  26. GET_PROPERTY_BSTR((IADsPrintQueue *)this, Model);
  27. }
  28. STDMETHODIMP
  29. CWinNTPrintQueue::put_Datatype(THIS_ BSTR bstrDatatype)
  30. {
  31. PUT_PROPERTY_BSTR((IADsPrintQueue *)this, Datatype);
  32. }
  33. STDMETHODIMP
  34. CWinNTPrintQueue::get_Datatype(THIS_ BSTR *retval)
  35. {
  36. GET_PROPERTY_BSTR((IADsPrintQueue *)this, Datatype);
  37. }
  38. STDMETHODIMP
  39. CWinNTPrintQueue::put_Description(THIS_ BSTR bstrDescription)
  40. {
  41. PUT_PROPERTY_BSTR((IADsPrintQueue *)this, Description);
  42. }
  43. STDMETHODIMP
  44. CWinNTPrintQueue::get_Description(THIS_ BSTR FAR* retval)
  45. {
  46. GET_PROPERTY_BSTR((IADsPrintQueue *)this, Description);
  47. }
  48. STDMETHODIMP CWinNTPrintQueue::put_Location(THIS_ BSTR bstrLocation)
  49. {
  50. PUT_PROPERTY_BSTR((IADsPrintQueue *)this, Location);
  51. }
  52. STDMETHODIMP CWinNTPrintQueue::get_Location(THIS_ BSTR FAR* retval)
  53. {
  54. GET_PROPERTY_BSTR((IADsPrintQueue *)this, Location);
  55. }
  56. STDMETHODIMP
  57. CWinNTPrintQueue::put_Priority(THIS_ LONG lPriority)
  58. {
  59. PUT_PROPERTY_LONG((IADsPrintQueue *)this, Priority);
  60. }
  61. STDMETHODIMP
  62. CWinNTPrintQueue::get_Priority(THIS_ LONG FAR* retval)
  63. {
  64. GET_PROPERTY_LONG((IADsPrintQueue *)this, Priority);
  65. }
  66. STDMETHODIMP
  67. CWinNTPrintQueue::put_StartTime(THIS_ DATE daStartTime)
  68. {
  69. PUT_PROPERTY_DATE((IADsPrintQueue *)this, StartTime);
  70. }
  71. STDMETHODIMP
  72. CWinNTPrintQueue::get_StartTime(THIS_ DATE FAR* retval)
  73. {
  74. GET_PROPERTY_DATE((IADsPrintQueue *)this, StartTime);
  75. }
  76. STDMETHODIMP
  77. CWinNTPrintQueue::put_UntilTime(THIS_ DATE daUntilTime)
  78. {
  79. PUT_PROPERTY_DATE((IADsPrintQueue *)this, UntilTime);
  80. }
  81. STDMETHODIMP
  82. CWinNTPrintQueue::get_UntilTime(THIS_ DATE FAR* retval)
  83. {
  84. GET_PROPERTY_DATE((IADsPrintQueue *)this, UntilTime);
  85. }
  86. STDMETHODIMP
  87. CWinNTPrintQueue::put_DefaultJobPriority(THIS_ LONG lDefaultJobPriority)
  88. {
  89. PUT_PROPERTY_LONG((IADsPrintQueue *)this, DefaultJobPriority);
  90. }
  91. STDMETHODIMP
  92. CWinNTPrintQueue::get_DefaultJobPriority(THIS_ LONG FAR* retval)
  93. {
  94. GET_PROPERTY_LONG((IADsPrintQueue *)this, DefaultJobPriority);
  95. }
  96. STDMETHODIMP
  97. CWinNTPrintQueue::put_BannerPage(THIS_ BSTR bstrBannerPage)
  98. {
  99. PUT_PROPERTY_BSTR((IADsPrintQueue *)this, BannerPage);
  100. }
  101. STDMETHODIMP
  102. CWinNTPrintQueue::get_BannerPage(THIS_ BSTR FAR* retval)
  103. {
  104. GET_PROPERTY_BSTR((IADsPrintQueue *)this, BannerPage);
  105. }
  106. STDMETHODIMP
  107. CWinNTPrintQueue::get_PrinterPath(THIS_ BSTR FAR* retval)
  108. {
  109. HRESULT hr;
  110. hr = ADsAllocString(_pszPrinterName, retval);
  111. RRETURN_EXP_IF_ERR(hr);
  112. }
  113. STDMETHODIMP
  114. CWinNTPrintQueue::put_PrinterPath(THIS_ BSTR bstrPrinterPath)
  115. {
  116. //
  117. // Cannot change this in Windows NT!
  118. //
  119. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  120. }
  121. STDMETHODIMP
  122. CWinNTPrintQueue::get_PrintProcessor(THIS_ BSTR FAR* retval)
  123. {
  124. GET_PROPERTY_BSTR((IADsPrintQueue *)this, PrintProcessor);
  125. }
  126. STDMETHODIMP
  127. CWinNTPrintQueue::put_PrintProcessor(THIS_ BSTR bstrPrintProcessor)
  128. {
  129. PUT_PROPERTY_BSTR((IADsPrintQueue *)this, PrintProcessor);
  130. }
  131. STDMETHODIMP
  132. CWinNTPrintQueue::get_PrintDevices(THIS_ VARIANT FAR* retval)
  133. {
  134. GET_PROPERTY_VARIANT((IADsPrintQueue *)this, PrintDevices);
  135. }
  136. STDMETHODIMP
  137. CWinNTPrintQueue::put_PrintDevices(THIS_ VARIANT vPrintDevices)
  138. {
  139. PUT_PROPERTY_VARIANT((IADsPrintQueue *)this, PrintDevices);
  140. }
  141. STDMETHODIMP
  142. CWinNTPrintQueue::get_NetAddresses(THIS_ VARIANT FAR* retval)
  143. {
  144. GET_PROPERTY_VARIANT((IADsPrintQueue *)this, NetAddresses);
  145. }
  146. STDMETHODIMP
  147. CWinNTPrintQueue::put_NetAddresses(THIS_ VARIANT vNetAddresses)
  148. {
  149. PUT_PROPERTY_VARIANT((IADsPrintQueue *)this, NetAddresses);
  150. }
  151. //
  152. // Class CWinNTPrintQueue
  153. //
  154. /* IADsFSPrintQueueOperation methods */
  155. STDMETHODIMP
  156. CWinNTPrintQueue::PrintJobs(
  157. THIS_ IADsCollection * FAR* ppCollection
  158. )
  159. {
  160. //
  161. // The job collection object is created and it is passed the printer
  162. // name. It uses this to create a printer object
  163. //
  164. HRESULT hr = S_OK;
  165. CWinNTPrintJobsCollection * pJobsCollection = NULL;
  166. hr = CWinNTPrintJobsCollection::Create(_ADsPath,
  167. _Credentials,
  168. &pJobsCollection);
  169. BAIL_IF_ERROR(hr);
  170. hr = pJobsCollection->QueryInterface(IID_IADsCollection,
  171. (void **) ppCollection);
  172. BAIL_IF_ERROR(hr);
  173. pJobsCollection->Release();
  174. cleanup:
  175. if(FAILED(hr)){
  176. delete pJobsCollection;
  177. }
  178. RRETURN_EXP_IF_ERR(hr);
  179. }
  180. //+------------------------------------------------------------------------
  181. //
  182. // Function: CWinNTPrintQueue::Pause
  183. //
  184. // Synopsis: Binds to real printer as specified in _bstrPrinterName
  185. // and attempts to pause the real printer.
  186. //
  187. // Arguments: none
  188. //
  189. // Returns: HRESULT.
  190. //
  191. // Modifies: nothing
  192. //
  193. // History: 11-07-95 RamV Created
  194. // Appropriated from Old NetOle Code.
  195. //
  196. //---------------------------------------------------------------------------
  197. STDMETHODIMP
  198. CWinNTPrintQueue::Pause(THIS)
  199. {
  200. BOOL fStatus = FALSE;
  201. PRINTER_DEFAULTS PrinterDefaults = {0, 0, PRINTER_ACCESS_ADMINISTER};
  202. HANDLE hPrinter = NULL;
  203. HRESULT hr = S_OK;
  204. fStatus = OpenPrinter(
  205. (LPTSTR)_pszPrinterName,
  206. &hPrinter,
  207. &PrinterDefaults);
  208. if (!fStatus) {
  209. goto error;
  210. }
  211. fStatus = SetPrinter(hPrinter,
  212. 0,
  213. NULL,
  214. PRINTER_CONTROL_PAUSE);
  215. if (!fStatus) {
  216. goto error;
  217. }
  218. fStatus = ClosePrinter(hPrinter);
  219. RRETURN(S_OK);
  220. error:
  221. hr = HRESULT_FROM_WIN32(GetLastError());
  222. if(hPrinter)
  223. fStatus = ClosePrinter(hPrinter);
  224. RRETURN_EXP_IF_ERR(hr);
  225. }
  226. //+---------------------------------------------------------------------------
  227. //
  228. // Function: CWinNTPrintQueue::Resume
  229. //
  230. // Synopsis: Binds to real printer as specified in _bstrPrinterName and
  231. // attempts to resume the real printer.
  232. //
  233. // Arguments: void
  234. //
  235. // Returns: HRESULT.
  236. //
  237. // Modifies:
  238. //
  239. // History: 11-07-95 RamV Created
  240. // Appropriated from old NetOle Project
  241. //----------------------------------------------------------------------------
  242. STDMETHODIMP
  243. CWinNTPrintQueue::Resume(THIS)
  244. {
  245. BOOL fStatus = FALSE;
  246. PRINTER_DEFAULTS PrinterDefaults = {0, 0, PRINTER_ACCESS_ADMINISTER};
  247. HANDLE hPrinter = NULL;
  248. HRESULT hr = S_OK;
  249. fStatus = OpenPrinter(
  250. (LPTSTR)_pszPrinterName,
  251. &hPrinter,
  252. &PrinterDefaults);
  253. if (!fStatus) {
  254. goto error;
  255. }
  256. fStatus = SetPrinter(hPrinter,
  257. 0,
  258. NULL,
  259. PRINTER_CONTROL_RESUME);
  260. if (!fStatus) {
  261. goto error;
  262. }
  263. fStatus = ClosePrinter(hPrinter);
  264. RRETURN(S_OK);
  265. error:
  266. hr = HRESULT_FROM_WIN32(GetLastError());
  267. if(hPrinter)
  268. fStatus = ClosePrinter(hPrinter);
  269. RRETURN_EXP_IF_ERR(hr);
  270. }
  271. //+---------------------------------------------------------------------------
  272. //
  273. // Function: CWinNTPrintQueue::Purge
  274. //
  275. // Synopsis: Binds to real printer as specified in _PrinterName and attempts
  276. // to purge the real printer.
  277. //
  278. // Arguments: void
  279. //
  280. // Returns: HRESULT.
  281. //
  282. // Modifies:
  283. //
  284. // History: 11-07-95 RamV Created
  285. // Appropriated from old NetOle Code
  286. //----------------------------------------------------------------------------
  287. STDMETHODIMP
  288. CWinNTPrintQueue::Purge(THIS)
  289. {
  290. BOOL fStatus = FALSE;
  291. PRINTER_DEFAULTS PrinterDefaults = {0, 0, PRINTER_ACCESS_ADMINISTER};
  292. PRINTER_INFO_2 PrinterInfo2;
  293. HANDLE hPrinter = NULL;
  294. HRESULT hr = S_OK;
  295. fStatus = OpenPrinter(
  296. (LPTSTR)_pszPrinterName,
  297. &hPrinter,
  298. &PrinterDefaults);
  299. if (!fStatus) {
  300. goto error;
  301. }
  302. fStatus = SetPrinter(hPrinter,
  303. 0,
  304. NULL,
  305. PRINTER_CONTROL_PURGE);
  306. if (!fStatus) {
  307. goto error;
  308. }
  309. fStatus = ClosePrinter(hPrinter);
  310. RRETURN(S_OK);
  311. error:
  312. hr = HRESULT_FROM_WIN32(GetLastError());
  313. if(hPrinter)
  314. fStatus = ClosePrinter(hPrinter);
  315. RRETURN_EXP_IF_ERR(hr);
  316. }
  317. STDMETHODIMP
  318. CWinNTPrintQueue::get_Status(THIS_ long FAR* retval)
  319. {
  320. HRESULT hr =S_OK;
  321. LPPRINTER_INFO_2 lpPrinterInfo2 = NULL;
  322. DWORD dwStatus;
  323. BOOL found;
  324. //
  325. // We return the WinNT Status Code as the ADS status code
  326. //
  327. hr = GetPrinterInfo(
  328. &lpPrinterInfo2,
  329. _pszPrinterName
  330. );
  331. BAIL_IF_ERROR(hr);
  332. *retval = lpPrinterInfo2->Status;
  333. cleanup:
  334. if(lpPrinterInfo2){
  335. FreeADsMem((LPBYTE)lpPrinterInfo2);
  336. }
  337. RRETURN_EXP_IF_ERR(hr);
  338. }