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.

1054 lines
26 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. printhlp.cxx
  5. Abstract:
  6. Helper functions for printer object
  7. Author:
  8. Ram Viswanathan ( ramv)
  9. Revision History:
  10. --*/
  11. #include "winnt.hxx"
  12. #pragma hdrstop
  13. /*+------------------------------------------------------------------------
  14. * Helper functions follow
  15. *-------------------------------------------------------------------------
  16. */
  17. //
  18. // mapping WinNT Status Codes to ADs Status Codes and vice versa
  19. //
  20. typedef struct _PrintStatusList {
  21. DWORD dwWinNTPrintStatus;
  22. DWORD dwADsPrintStatus;
  23. } PRINT_STATUS_LIST, *PPRINT_STATUS_LIST;
  24. PRINT_STATUS_LIST PrintStatusList[] =
  25. {
  26. {PRINTER_STATUS_PAUSED, ADS_PRINTER_PAUSED},
  27. {PRINTER_STATUS_PENDING_DELETION, ADS_PRINTER_PENDING_DELETION}
  28. };
  29. BOOL PrinterStatusWinNTToADs( DWORD dwWinNTStatus,
  30. DWORD *pdwADsStatus)
  31. {
  32. BOOL found = FALSE;
  33. int i;
  34. for (i=0;i<2;i++){
  35. if(dwWinNTStatus == PrintStatusList[i].dwWinNTPrintStatus){
  36. *pdwADsStatus = PrintStatusList[i].dwADsPrintStatus;
  37. found = TRUE;
  38. break;
  39. }
  40. }
  41. return (found);
  42. }
  43. BOOL PrinterStatusADsToWinNT( DWORD dwADsStatus,
  44. DWORD *pdwWinNTStatus)
  45. {
  46. BOOL found = FALSE;
  47. int i;
  48. for (i=0;i<2;i++){
  49. if(dwADsStatus == PrintStatusList[i].dwADsPrintStatus){
  50. *pdwWinNTStatus = PrintStatusList[i].dwWinNTPrintStatus;
  51. found = TRUE;
  52. break;
  53. }
  54. }
  55. return (found);
  56. }
  57. BOOL
  58. WinNTEnumPrinters(
  59. DWORD dwType,
  60. LPTSTR lpszName,
  61. DWORD dwLevel,
  62. LPBYTE *lplpbPrinters,
  63. LPDWORD lpdwReturned
  64. )
  65. {
  66. BOOL bStatus = FALSE;
  67. DWORD dwPassed = 1024;
  68. DWORD dwNeeded = 0;
  69. DWORD dwError = 0;
  70. LPBYTE pMem = NULL;
  71. pMem = (LPBYTE)AllocADsMem(dwPassed);
  72. if (!pMem) {
  73. goto error;
  74. }
  75. bStatus = EnumPrinters(dwType,
  76. lpszName,
  77. dwLevel,
  78. pMem,
  79. dwPassed,
  80. &dwNeeded,
  81. lpdwReturned);
  82. if (!bStatus) {
  83. if ((dwError = GetLastError()) != ERROR_INSUFFICIENT_BUFFER) {
  84. goto error;
  85. }
  86. if (pMem) {
  87. FreeADsMem(pMem);
  88. }
  89. pMem = (LPBYTE)AllocADsMem(dwNeeded);
  90. if (!pMem) {
  91. goto error;
  92. }
  93. dwPassed = dwNeeded;
  94. bStatus = EnumPrinters(dwType,
  95. lpszName,
  96. dwLevel,
  97. pMem,
  98. dwPassed,
  99. &dwNeeded,
  100. lpdwReturned);
  101. if (!bStatus) {
  102. goto error;
  103. }
  104. }
  105. *lplpbPrinters = pMem;
  106. return(TRUE);
  107. error:
  108. if (pMem) {
  109. FreeADsMem(pMem);
  110. }
  111. return(FALSE);
  112. }
  113. BOOL
  114. WinNTGetPrinter(HANDLE hPrinter,
  115. DWORD dwLevel,
  116. LPBYTE *lplpbPrinters)
  117. {
  118. BOOL bStatus = FALSE;
  119. DWORD dwPassed = 1024;
  120. DWORD dwNeeded = 0;
  121. DWORD dwError = 0;
  122. LPBYTE pMem = NULL;
  123. pMem = (LPBYTE)AllocADsMem(dwPassed);
  124. if (!pMem) {
  125. goto error;
  126. }
  127. bStatus = GetPrinter(hPrinter,
  128. dwLevel,
  129. pMem,
  130. dwPassed,
  131. &dwNeeded);
  132. if (!bStatus) {
  133. if ((dwError = GetLastError()) != ERROR_INSUFFICIENT_BUFFER) {
  134. goto error;
  135. }
  136. if (pMem) {
  137. FreeADsMem(pMem);
  138. }
  139. pMem = (LPBYTE)AllocADsMem(dwNeeded);
  140. if (!pMem) {
  141. goto error;
  142. }
  143. dwPassed = dwNeeded;
  144. bStatus = GetPrinter(hPrinter,
  145. dwLevel,
  146. pMem,
  147. dwPassed,
  148. &dwNeeded);
  149. if (!bStatus) {
  150. goto error;
  151. }
  152. }
  153. *lplpbPrinters = pMem;
  154. return(TRUE);
  155. error:
  156. if (pMem) {
  157. FreeADsMem(pMem);
  158. }
  159. return(FALSE);
  160. }
  161. HRESULT
  162. GetPrinterInfo(
  163. THIS_ LPPRINTER_INFO_2 *lplpPrinterInfo2,
  164. LPWSTR pszPrinterName
  165. )
  166. {
  167. //
  168. // Do a GetPrinter call to pszPrinterName
  169. //
  170. BOOL fStatus = FALSE;
  171. PRINTER_DEFAULTS PrinterDefaults = {0, 0, PRINTER_ACCESS_USE |
  172. READ_CONTROL};
  173. DWORD LastError = 0;
  174. HANDLE hPrinter = NULL;
  175. LPBYTE pMem = NULL;
  176. HRESULT hr = S_OK;
  177. ADsAssert(pszPrinterName);
  178. fStatus = OpenPrinter(pszPrinterName,
  179. &hPrinter,
  180. &PrinterDefaults
  181. );
  182. if (!fStatus) {
  183. LastError = GetLastError();
  184. switch (LastError) {
  185. case ERROR_ACCESS_DENIED:
  186. {
  187. PRINTER_DEFAULTS PrinterDefaults = {0, 0, PRINTER_ACCESS_USE};
  188. fStatus = OpenPrinter(pszPrinterName,
  189. &hPrinter,
  190. &PrinterDefaults
  191. );
  192. if (fStatus) {
  193. break;
  194. }
  195. }
  196. default:
  197. RRETURN(HRESULT_FROM_WIN32(GetLastError()));
  198. }
  199. }
  200. fStatus = WinNTGetPrinter(hPrinter,
  201. 2,
  202. (LPBYTE *)&pMem
  203. );
  204. if (!fStatus) {
  205. hr = HRESULT_FROM_WIN32(GetLastError());
  206. goto cleanup;
  207. }
  208. *lplpPrinterInfo2 = (LPPRINTER_INFO_2)pMem;
  209. cleanup:
  210. if(hPrinter)
  211. fStatus = ClosePrinter(hPrinter);
  212. RRETURN(hr);
  213. }
  214. //+---------------------------------------------------------------------------
  215. //
  216. // Function: Set
  217. //
  218. // Synopsis: Helper function called by CADsPrintQueue:SetInfo
  219. //
  220. // Arguments:
  221. //
  222. // Returns: HRESULT.
  223. //
  224. // Modifies:
  225. //
  226. // History: 11-08-95 RamV Created
  227. //
  228. //----------------------------------------------------------------------------
  229. HRESULT
  230. Set(
  231. LPPRINTER_INFO_2 lpPrinterInfo2,
  232. LPTSTR pszPrinterName
  233. )
  234. {
  235. BOOL fStatus = FALSE;
  236. PRINTER_DEFAULTS PrinterDefaults = {0, 0, PRINTER_ALL_ACCESS};
  237. HANDLE hPrinter = NULL;
  238. HRESULT hr;
  239. ADsAssert(pszPrinterName);
  240. fStatus = OpenPrinter(pszPrinterName,
  241. &hPrinter,
  242. &PrinterDefaults
  243. );
  244. if (!fStatus) {
  245. goto error;
  246. }
  247. fStatus = SetPrinter(hPrinter,
  248. 2,
  249. (LPBYTE)lpPrinterInfo2,
  250. 0
  251. );
  252. if (!fStatus) {
  253. goto error;
  254. }
  255. fStatus = ClosePrinter(hPrinter);
  256. RRETURN(S_OK);
  257. error:
  258. hr = HRESULT_FROM_WIN32(GetLastError());
  259. if(hPrinter)
  260. fStatus = ClosePrinter(hPrinter);
  261. RRETURN(hr);
  262. }
  263. //+---------------------------------------------------------------------------
  264. //
  265. // Function: Unmarshall
  266. //
  267. // Synopsis: Unmarshalls information from a PRINTER_INFO_2 to a
  268. // WinNT Printer object.Frees PRINTER_INFO_2 object.
  269. //
  270. // Arguments: [lpPrinterInfo2] -- Pointer to a PRINTER_INFO_2 struct
  271. //
  272. // Returns: HRESULT
  273. //
  274. // Modifies: GeneralInfo and Operation Functional sets
  275. //
  276. // History: 11/08/95 RamV Created
  277. //
  278. //----------------------------------------------------------------------------
  279. HRESULT
  280. CWinNTPrintQueue::UnMarshall(
  281. LPPRINTER_INFO_2 lpPrinterInfo2,
  282. BOOL fExplicit
  283. )
  284. {
  285. HRESULT hr;
  286. VARIANT vPortNames;
  287. PNTOBJECT pNtObject;
  288. hr = SetLPTSTRPropertyInCache(_pPropertyCache,
  289. TEXT("PrinterName"),
  290. lpPrinterInfo2->pPrinterName,
  291. fExplicit
  292. );
  293. hr = SetLPTSTRPropertyInCache(_pPropertyCache,
  294. TEXT("Model"),
  295. lpPrinterInfo2->pDriverName,
  296. fExplicit
  297. );
  298. hr = SetLPTSTRPropertyInCache(_pPropertyCache,
  299. TEXT("PrintProcessor"),
  300. lpPrinterInfo2->pPrintProcessor,
  301. fExplicit
  302. );
  303. hr = SetLPTSTRPropertyInCache(_pPropertyCache,
  304. TEXT("Location"),
  305. lpPrinterInfo2->pLocation,
  306. fExplicit
  307. );
  308. hr = SetLPTSTRPropertyInCache(_pPropertyCache,
  309. TEXT("Datatype"),
  310. lpPrinterInfo2->pDatatype,
  311. fExplicit
  312. );
  313. hr = SetLPTSTRPropertyInCache(_pPropertyCache,
  314. TEXT("BannerPage"),
  315. lpPrinterInfo2->pSepFile,
  316. fExplicit
  317. );
  318. hr = SetLPTSTRPropertyInCache(_pPropertyCache,
  319. TEXT("Description"),
  320. lpPrinterInfo2->pComment,
  321. fExplicit
  322. );
  323. hr = SetLPTSTRPropertyInCache(_pPropertyCache,
  324. TEXT("PrinterPath"),
  325. lpPrinterInfo2->pPrinterName,
  326. fExplicit
  327. );
  328. hr = SetDWORDPropertyInCache(_pPropertyCache,
  329. TEXT("Priority"),
  330. lpPrinterInfo2->Priority,
  331. fExplicit
  332. );
  333. hr = SetDelimitedStringPropertyInCache(_pPropertyCache,
  334. TEXT("PrintDevices"),
  335. lpPrinterInfo2->pPortName,
  336. fExplicit
  337. );
  338. hr = SetDWORDPropertyInCache(_pPropertyCache,
  339. TEXT("DefaultJobPriority"),
  340. lpPrinterInfo2->DefaultPriority,
  341. fExplicit
  342. );
  343. hr = SetDWORDPropertyInCache(_pPropertyCache,
  344. TEXT("JobCount"),
  345. lpPrinterInfo2->cJobs,
  346. fExplicit
  347. );
  348. hr = SetDWORDPropertyInCache(_pPropertyCache,
  349. TEXT("Attributes"),
  350. lpPrinterInfo2->Attributes,
  351. fExplicit
  352. );
  353. hr = SetDATEPropertyInCache(_pPropertyCache,
  354. TEXT("StartTime"),
  355. lpPrinterInfo2->StartTime,
  356. fExplicit
  357. );
  358. hr = SetDATEPropertyInCache(_pPropertyCache,
  359. TEXT("UntilTime"),
  360. lpPrinterInfo2->UntilTime,
  361. fExplicit
  362. );
  363. hr = SetLPTSTRPropertyInCache(
  364. _pPropertyCache,
  365. TEXT("Name"),
  366. _Name,
  367. fExplicit
  368. );
  369. RRETURN(S_OK);
  370. }
  371. //+---------------------------------------------------------------------------
  372. //
  373. // Function: MarshallAndSet
  374. //
  375. // Synopsis: Marshalls information from a Printer object to a
  376. // PRINTER_INFO_2 structure
  377. //
  378. // Arguments: [lpPrinterInfo2] -- Pointer to a PRINTER_INFO_2 struct.
  379. //
  380. // Returns: HRESULT
  381. //
  382. // Modifies:
  383. //
  384. // History: 11/09/95 RamV Created
  385. //
  386. //----------------------------------------------------------------------------
  387. HRESULT
  388. CWinNTPrintQueue::MarshallAndSet(
  389. LPPRINTER_INFO_2 lpPrinterInfo2
  390. )
  391. {
  392. HRESULT hr =S_OK;
  393. DWORD dwPriority;
  394. LPTSTR pszPrinterName = NULL;
  395. LPTSTR pszDriverName = NULL;
  396. LPTSTR pszComment = NULL;
  397. LPTSTR pszLocation = NULL;
  398. LPTSTR pszDatatype = NULL;
  399. LPTSTR pszPrintProcessor = NULL;
  400. LPTSTR pszBannerPage = NULL;
  401. VARIANT vPortNames;
  402. PNTOBJECT pNtObject = NULL;
  403. LPTSTR pszPorts = NULL;
  404. DWORD dwSyntaxId;
  405. DWORD dwTimeValue;
  406. DWORD dwNumValues = 0;
  407. DWORD dwAttributes;
  408. DWORD dwUpdatedProps = 0;
  409. //
  410. // We can set the update variable based on the number
  411. // of properties in the cache.
  412. //
  413. hr = _pPropertyCache->get_PropertyCount(&dwUpdatedProps);
  414. if (dwUpdatedProps != 0) {
  415. //
  416. // We can do all this to get the props
  417. //
  418. hr = GetLPTSTRPropertyFromCache(
  419. _pPropertyCache,
  420. TEXT("PrinterName"),
  421. &pszPrinterName
  422. );
  423. if(SUCCEEDED(hr)){
  424. lpPrinterInfo2->pPrinterName= pszPrinterName;
  425. }
  426. hr = GetLPTSTRPropertyFromCache(
  427. _pPropertyCache,
  428. TEXT("Model"),
  429. &pszDriverName
  430. );
  431. if(SUCCEEDED(hr)){
  432. lpPrinterInfo2->pDriverName = pszDriverName;
  433. }
  434. hr = GetLPTSTRPropertyFromCache(
  435. _pPropertyCache,
  436. TEXT("PrintProcessor"),
  437. &pszPrintProcessor
  438. );
  439. if(SUCCEEDED(hr)){
  440. lpPrinterInfo2->pPrintProcessor = pszPrintProcessor;
  441. }
  442. hr = GetLPTSTRPropertyFromCache(
  443. _pPropertyCache,
  444. TEXT("Description"),
  445. &pszComment
  446. );
  447. if(SUCCEEDED(hr)){
  448. lpPrinterInfo2->pComment = pszComment;
  449. }
  450. hr = GetLPTSTRPropertyFromCache(
  451. _pPropertyCache,
  452. TEXT("Location"),
  453. &pszLocation
  454. );
  455. if(SUCCEEDED(hr)){
  456. lpPrinterInfo2->pLocation = pszLocation;
  457. }
  458. hr = GetLPTSTRPropertyFromCache(
  459. _pPropertyCache,
  460. TEXT("Datatype"),
  461. &pszDatatype
  462. );
  463. if(SUCCEEDED(hr)){
  464. lpPrinterInfo2->pDatatype = pszDatatype;
  465. }
  466. hr = GetLPTSTRPropertyFromCache(
  467. _pPropertyCache,
  468. TEXT("BannerPage"),
  469. &pszBannerPage
  470. );
  471. if(SUCCEEDED(hr)){
  472. lpPrinterInfo2->pSepFile = pszBannerPage;
  473. }
  474. hr = GetDWORDPropertyFromCache(
  475. _pPropertyCache,
  476. TEXT("Priority"),
  477. &dwPriority
  478. );
  479. if(SUCCEEDED(hr)){
  480. lpPrinterInfo2->Priority = dwPriority;
  481. }
  482. hr = GetDWORDPropertyFromCache(
  483. _pPropertyCache,
  484. TEXT("DefaultJobPriority"),
  485. &dwPriority
  486. );
  487. if(SUCCEEDED(hr)){
  488. lpPrinterInfo2->DefaultPriority = dwPriority;
  489. }
  490. //
  491. // will NOT marshall or set job count on the server
  492. //
  493. hr = GetDWORDPropertyFromCache(
  494. _pPropertyCache,
  495. TEXT("Attributes"),
  496. &dwAttributes
  497. );
  498. if(SUCCEEDED(hr)){
  499. lpPrinterInfo2->Attributes = dwAttributes;
  500. }
  501. hr = GetDelimitedStringPropertyFromCache(
  502. _pPropertyCache,
  503. TEXT("PrintDevices"),
  504. &pszPorts
  505. );
  506. if(SUCCEEDED(hr)){
  507. lpPrinterInfo2->pPortName = pszPorts;
  508. }
  509. hr = GetDATEPropertyFromCache(
  510. _pPropertyCache,
  511. TEXT("StartTime"),
  512. &dwTimeValue
  513. );
  514. if(SUCCEEDED(hr)){
  515. lpPrinterInfo2->StartTime = dwTimeValue;
  516. }
  517. hr = GetDATEPropertyFromCache(
  518. _pPropertyCache,
  519. TEXT("UntilTime"),
  520. &dwTimeValue
  521. );
  522. if(SUCCEEDED(hr)){
  523. lpPrinterInfo2->UntilTime = dwTimeValue;
  524. }
  525. //
  526. // Need to do the set
  527. //
  528. hr = Set(lpPrinterInfo2,
  529. _pszPrinterName);
  530. //
  531. // only this hr gets recorded
  532. //
  533. BAIL_IF_ERROR(hr);
  534. }
  535. cleanup:
  536. if(pszDriverName)
  537. FreeADsStr(pszDriverName);
  538. if(pszComment)
  539. FreeADsStr(pszComment);
  540. if(pszLocation)
  541. FreeADsStr(pszLocation);
  542. if(pszDatatype)
  543. FreeADsStr(pszDatatype);
  544. if(pszPrintProcessor)
  545. FreeADsStr(pszPrintProcessor);
  546. if(pszBannerPage)
  547. FreeADsStr(pszBannerPage);
  548. if(pszPorts){
  549. FreeADsStr(pszPorts);
  550. }
  551. RRETURN(hr);
  552. }
  553. HRESULT
  554. WinNTDeletePrinter( POBJECTINFO pObjectInfo)
  555. {
  556. WCHAR szUncServerName[MAX_PATH];
  557. WCHAR szUncPrinterName[MAX_PATH];
  558. HANDLE hPrinter = NULL;
  559. PRINTER_DEFAULTS PrinterDefaults = {0, 0, PRINTER_ALL_ACCESS};
  560. BOOL fStatus = FALSE;
  561. HRESULT hr = S_OK;
  562. //
  563. // first open printer to get a handle to it
  564. //
  565. hr = MakeUncName(pObjectInfo->ComponentArray[1],
  566. szUncServerName
  567. );
  568. BAIL_ON_FAILURE(hr);
  569. //
  570. // Make sure we don't overrun the buffer
  571. // Account for both slashes and the null terminator
  572. //
  573. if (wcslen(szUncServerName) + wcslen(pObjectInfo->ComponentArray[2]) > MAX_PATH - 3)
  574. BAIL_ON_FAILURE(hr = E_INVALIDARG);
  575. wcscpy(szUncPrinterName, szUncServerName);
  576. wcscat(szUncPrinterName, L"\\");
  577. wcscat(szUncPrinterName, (LPTSTR)pObjectInfo->ComponentArray[2]);
  578. fStatus = OpenPrinter((LPTSTR)szUncPrinterName,
  579. &hPrinter,
  580. &PrinterDefaults
  581. );
  582. if (!fStatus) {
  583. hr = HRESULT_FROM_WIN32(GetLastError());
  584. goto error;
  585. }
  586. fStatus = DeletePrinter(hPrinter);
  587. //
  588. // Always close the printer handle, even if we deleted the printer.
  589. //
  590. ClosePrinter(hPrinter);
  591. if (!fStatus) {
  592. hr = HRESULT_FROM_WIN32(GetLastError());
  593. goto error;
  594. }
  595. error:
  596. RRETURN(hr);
  597. }
  598. HRESULT
  599. PrinterNameFromObjectInfo(
  600. POBJECTINFO pObjectInfo,
  601. LPTSTR szUncPrinterName
  602. )
  603. {
  604. if(!pObjectInfo){
  605. RRETURN(S_OK);
  606. }
  607. if(!((pObjectInfo->NumComponents == 3) ||(pObjectInfo->NumComponents == 4)) ){
  608. RRETURN(E_ADS_BAD_PATHNAME);
  609. }
  610. if(pObjectInfo->NumComponents == 3) {
  611. wcscpy(szUncPrinterName, TEXT("\\\\"));
  612. wcscat(szUncPrinterName, pObjectInfo->ComponentArray[1]);
  613. wcscat(szUncPrinterName, TEXT("\\"));
  614. wcscat(szUncPrinterName, pObjectInfo->ComponentArray[2]);
  615. } else {
  616. wcscpy(szUncPrinterName, TEXT("\\\\"));
  617. wcscat(szUncPrinterName, pObjectInfo->ComponentArray[0]);
  618. wcscat(szUncPrinterName, TEXT("\\"));
  619. wcscat(szUncPrinterName, pObjectInfo->ComponentArray[1]);
  620. }
  621. RRETURN(S_OK);
  622. }
  623. #if (!defined(BUILD_FOR_NT40))
  624. //+---------------------------------------------------------------------------
  625. //
  626. // Function: MarshallAndSet
  627. //
  628. // Synopsis: Marshalls information from a Printer object to a
  629. // PRINTER_INFO_7 structure
  630. //
  631. // Arguments: [lpPrinterInfo7] -- Pointer to a PRINTER_INFO_2 struct.
  632. //
  633. // Returns: HRESULT
  634. //
  635. // Modifies:
  636. //
  637. // History: 11/09/95 RamV Created
  638. //
  639. //----------------------------------------------------------------------------
  640. HRESULT
  641. CWinNTPrintQueue::MarshallAndSet(
  642. LPPRINTER_INFO_7 lpPrinterInfo7
  643. )
  644. {
  645. HRESULT hr =S_OK;
  646. DWORD dwAction;
  647. LPTSTR pszObjectGUID = NULL;
  648. BOOL fSetInfoNeeded = FALSE;
  649. hr = GetLPTSTRPropertyFromCache(
  650. _pPropertyCache,
  651. TEXT("ObjectGUID"),
  652. &pszObjectGUID
  653. );
  654. if(SUCCEEDED(hr)){
  655. fSetInfoNeeded = TRUE;
  656. lpPrinterInfo7->pszObjectGUID = pszObjectGUID;
  657. }
  658. hr = GetDWORDPropertyFromCache(
  659. _pPropertyCache,
  660. TEXT("Action"),
  661. &dwAction
  662. );
  663. if(SUCCEEDED(hr)){
  664. fSetInfoNeeded = TRUE;
  665. lpPrinterInfo7->dwAction = dwAction;
  666. }
  667. //
  668. // Need to do the set if flag is set
  669. //
  670. if (fSetInfoNeeded) {
  671. hr = SetPrinter7(lpPrinterInfo7,
  672. _pszPrinterName);
  673. //
  674. // only this hr gets recorded
  675. //
  676. BAIL_IF_ERROR(hr);
  677. }
  678. else {
  679. //
  680. // Need to this - if we are here it means that the hr is
  681. // probably set as prop was not found in cache.
  682. hr = S_OK;
  683. }
  684. cleanup:
  685. if(pszObjectGUID)
  686. FreeADsStr(pszObjectGUID);
  687. RRETURN(hr);
  688. }
  689. HRESULT
  690. GetPrinterInfo7(
  691. THIS_ LPPRINTER_INFO_7 *lplpPrinterInfo7,
  692. LPWSTR pszPrinterName
  693. )
  694. {
  695. //
  696. // Do a GetPrinter call to pszPrinterName
  697. //
  698. BOOL fStatus = FALSE;
  699. PRINTER_DEFAULTS PrinterDefaults = {0, 0, PRINTER_ACCESS_USE |
  700. READ_CONTROL};
  701. DWORD LastError = 0;
  702. HANDLE hPrinter = NULL;
  703. LPBYTE pMem = NULL;
  704. HRESULT hr = S_OK;
  705. ADsAssert(pszPrinterName);
  706. fStatus = OpenPrinter(pszPrinterName,
  707. &hPrinter,
  708. &PrinterDefaults
  709. );
  710. if (!fStatus) {
  711. LastError = GetLastError();
  712. switch (LastError) {
  713. case ERROR_ACCESS_DENIED:
  714. {
  715. PRINTER_DEFAULTS PrinterDefaults = {0, 0, PRINTER_ACCESS_USE};
  716. fStatus = OpenPrinter(pszPrinterName,
  717. &hPrinter,
  718. &PrinterDefaults
  719. );
  720. if (fStatus) {
  721. break;
  722. }
  723. }
  724. default:
  725. RRETURN(HRESULT_FROM_WIN32(GetLastError()));
  726. }
  727. }
  728. fStatus = WinNTGetPrinter(hPrinter,
  729. 7,
  730. (LPBYTE *)&pMem
  731. );
  732. if (!fStatus) {
  733. hr = HRESULT_FROM_WIN32(GetLastError());
  734. goto cleanup;
  735. }
  736. *lplpPrinterInfo7 = (LPPRINTER_INFO_7)pMem;
  737. cleanup:
  738. if(hPrinter)
  739. fStatus = ClosePrinter(hPrinter);
  740. RRETURN(hr);
  741. }
  742. HRESULT
  743. SetPrinter7(
  744. LPPRINTER_INFO_7 lpPrinterInfo7,
  745. LPTSTR pszPrinterName
  746. )
  747. {
  748. BOOL fStatus = FALSE;
  749. PRINTER_DEFAULTS PrinterDefaults = {0, 0, PRINTER_ALL_ACCESS};
  750. HANDLE hPrinter = NULL;
  751. HRESULT hr;
  752. ADsAssert(pszPrinterName);
  753. fStatus = OpenPrinter(pszPrinterName,
  754. &hPrinter,
  755. &PrinterDefaults
  756. );
  757. if (!fStatus) {
  758. goto error;
  759. }
  760. fStatus = SetPrinter(hPrinter,
  761. 7,
  762. (LPBYTE)lpPrinterInfo7,
  763. 0
  764. );
  765. if (!fStatus) {
  766. goto error;
  767. }
  768. fStatus = ClosePrinter(hPrinter);
  769. RRETURN(S_OK);
  770. error:
  771. hr = HRESULT_FROM_WIN32(GetLastError());
  772. if(hPrinter)
  773. fStatus = ClosePrinter(hPrinter);
  774. RRETURN(hr);
  775. }
  776. //+---------------------------------------------------------------------------
  777. //
  778. // Function: Unmarshall
  779. //
  780. // Synopsis: Unmarshalls information from a PRINTER_INFO_2 to a
  781. // WinNT Printer object.Frees PRINTER_INFO_2 object.
  782. //
  783. // Arguments: [lpPrinterInfo2] -- Pointer to a PRINTER_INFO_2 struct
  784. //
  785. // Returns: HRESULT
  786. //
  787. // Modifies: GeneralInfo and Operation Functional sets
  788. //
  789. // History: 11/08/95 RamV Created
  790. //
  791. //----------------------------------------------------------------------------
  792. HRESULT
  793. CWinNTPrintQueue::UnMarshall7(
  794. LPPRINTER_INFO_7 lpPrinterInfo7,
  795. BOOL fExplicit
  796. )
  797. {
  798. HRESULT hr;
  799. VARIANT vPortNames;
  800. PNTOBJECT pNtObject;
  801. hr = SetLPTSTRPropertyInCache(_pPropertyCache,
  802. TEXT("ObjectGUID"),
  803. lpPrinterInfo7->pszObjectGUID,
  804. fExplicit
  805. );
  806. hr = SetDWORDPropertyInCache(_pPropertyCache,
  807. TEXT("Action"),
  808. lpPrinterInfo7->dwAction,
  809. fExplicit
  810. );
  811. RRETURN(S_OK);
  812. }
  813. #endif