2 * PROJECT: ReactOS Standard Print Processor
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Printing a job with RAW datatype
5 * COPYRIGHT: Copyright 2015 Colin Finck (colin@reactos.org)
14 * Pointer to a WINPRINT_HANDLE structure containing information about this job.
16 * @param pwszPrinterAndJob
17 * String in the format "Printer, Job N" that is passed to OpenPrinterW to read from the spooled print job.
20 * An error code indicating success or failure.
23 PrintRawJob(PWINPRINT_HANDLE pHandle
, PWSTR pwszPrinterAndJob
)
25 // Use a read buffer of 256 KB size like Windows does.
26 const DWORD cbReadBuffer
= 262144;
28 BOOL bStartedDoc
= FALSE
;
34 HANDLE hPrintMonitor
= NULL
;
37 // Open the spooled job to read from it.
38 if (!OpenPrinterW(pwszPrinterAndJob
, &hPrintJob
, NULL
))
40 dwErrorCode
= GetLastError();
41 ERR("OpenPrinterW failed for \"%S\" with error %lu!\n", pwszPrinterAndJob
, GetLastError());
45 // Open a Print Monitor handle to write to it.
46 if (!OpenPrinterW(pHandle
->pwszPrinterPort
, &hPrintMonitor
, NULL
))
48 dwErrorCode
= GetLastError();
49 ERR("OpenPrinterW failed for \"%S\" with error %lu!\n", pHandle
->pwszPrinterPort
, GetLastError());
53 // Fill the Document Information.
54 DocInfo1
.pDatatype
= pHandle
->pwszDatatype
;
55 DocInfo1
.pDocName
= pHandle
->pwszDocumentName
;
56 DocInfo1
.pOutputFile
= pHandle
->pwszOutputFile
;
58 // Tell the Print Monitor that we're starting a new document.
59 if (!StartDocPrinterW(hPrintMonitor
, 1, (PBYTE
)&DocInfo1
))
61 dwErrorCode
= GetLastError();
62 ERR("StartDocPrinterW failed with error %lu!\n", GetLastError());
68 // Allocate a read buffer on the heap. This would easily exceed the stack size.
69 pBuffer
= DllAllocSplMem(cbReadBuffer
);
72 dwErrorCode
= ERROR_NOT_ENOUGH_MEMORY
;
73 ERR("DllAllocSplMem failed with error %lu!\n", GetLastError());
77 // Loop as long as data is available.
78 while (ReadPrinter(hPrintJob
, pBuffer
, cbReadBuffer
, &cbRead
) && cbRead
)
80 // Write it to the Print Monitor.
81 WritePrinter(hPrintMonitor
, pBuffer
, cbRead
, &cbWritten
);
84 dwErrorCode
= ERROR_SUCCESS
;
88 DllFreeSplMem(pBuffer
);
91 EndDocPrinter(hPrintMonitor
);
94 ClosePrinter(hPrintMonitor
);
97 ClosePrinter(hPrintJob
);