ReactOS 0.4.15-dev-5672-gf73ac17
raw.c File Reference
#include "precomp.h"
Include dependency graph for raw.c:

Go to the source code of this file.

Functions

PrintRawJob
Parameters
pHandlePointer to a WINPRINT_HANDLE structure containing information about this job.
pwszPrinterAndJobString in the format "Printer, Job N" that is passed to OpenPrinterW to read from the spooled print job.
Returns
An error code indicating success or failure.
DWORD PrintRawJob (PWINPRINT_HANDLE pHandle, PWSTR pwszPrinterAndJob)
 

Function Documentation

◆ PrintRawJob()

DWORD PrintRawJob ( PWINPRINT_HANDLE  pHandle,
PWSTR  pwszPrinterAndJob 
)

Definition at line 23 of file raw.c.

24{
25 // Use a read buffer of 256 KB size like Windows does.
26 const DWORD cbReadBuffer = 262144;
27
28 BOOL bStartedDoc = FALSE;
29 DOC_INFO_1W DocInfo1;
30 DWORD cbRead;
31 DWORD cbWritten;
32 DWORD dwErrorCode;
33 HANDLE hPrintJob;
34 HANDLE hPrintMonitor = NULL;
36
37 // Open the spooled job to read from it.
38 if (!OpenPrinterW(pwszPrinterAndJob, &hPrintJob, NULL))
39 {
40 dwErrorCode = GetLastError();
41 ERR("OpenPrinterW failed for \"%S\" with error %lu!\n", pwszPrinterAndJob, GetLastError());
42 goto Cleanup;
43 }
44
45 // Open a Print Monitor handle to write to it.
46 if (!OpenPrinterW(pHandle->pwszPrinterPort, &hPrintMonitor, NULL))
47 {
48 dwErrorCode = GetLastError();
49 ERR("OpenPrinterW failed for \"%S\" with error %lu!\n", pHandle->pwszPrinterPort, GetLastError());
50 goto Cleanup;
51 }
52
53 // Fill the Document Information.
54 DocInfo1.pDatatype = pHandle->pwszDatatype;
55 DocInfo1.pDocName = pHandle->pwszDocumentName;
56 DocInfo1.pOutputFile = pHandle->pwszOutputFile;
57
58 // Tell the Print Monitor that we're starting a new document.
59 if (!StartDocPrinterW(hPrintMonitor, 1, (PBYTE)&DocInfo1))
60 {
61 dwErrorCode = GetLastError();
62 ERR("StartDocPrinterW failed with error %lu!\n", GetLastError());
63 goto Cleanup;
64 }
65
66 bStartedDoc = TRUE;
67
68 // Allocate a read buffer on the heap. This would easily exceed the stack size.
69 pBuffer = DllAllocSplMem(cbReadBuffer);
70 if (!pBuffer)
71 {
72 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
73 ERR("DllAllocSplMem failed with error %lu!\n", GetLastError());
74 goto Cleanup;
75 }
76
77 // Loop as long as data is available.
78 while (ReadPrinter(hPrintJob, pBuffer, cbReadBuffer, &cbRead) && cbRead)
79 {
80 // Write it to the Print Monitor.
81 WritePrinter(hPrintMonitor, pBuffer, cbRead, &cbWritten);
82 }
83
84 dwErrorCode = ERROR_SUCCESS;
85
87 if (pBuffer)
89
90 if (bStartedDoc)
91 EndDocPrinter(hPrintMonitor);
92
93 if (hPrintMonitor)
94 ClosePrinter(hPrintMonitor);
95
96 if (hPrintJob)
97 ClosePrinter(hPrintJob);
98
99 return dwErrorCode;
100}
#define ERR(fmt,...)
Definition: debug.h:110
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static const WCHAR Cleanup[]
Definition: register.c:80
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
BYTE * PBYTE
Definition: pedump.c:66
PVOID pBuffer
LPWSTR pOutputFile
Definition: winspool.h:617
LPWSTR pDatatype
Definition: winspool.h:618
LPWSTR pDocName
Definition: winspool.h:616
PWSTR pwszOutputFile
Definition: precomp.h:32
PWSTR pwszPrinterPort
Definition: precomp.h:33
PWSTR pwszDocumentName
Definition: precomp.h:31
PWSTR pwszDatatype
Definition: precomp.h:30
BOOL WINAPI DllFreeSplMem(PVOID pMem)
Definition: memory.c:112
PVOID WINAPI DllAllocSplMem(DWORD dwBytes)
Definition: memory.c:95
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
WINBOOL WINAPI ReadPrinter(HANDLE hPrinter, LPVOID pBuf, DWORD cbBuf, LPDWORD pNoBytesRead)
DWORD WINAPI StartDocPrinterW(HANDLE hPrinter, DWORD Level, LPBYTE pDocInfo)
WINBOOL WINAPI OpenPrinterW(LPWSTR pPrinterName, LPHANDLE phPrinter, LPPRINTER_DEFAULTSW pDefault)
Definition: printers.c:2624
WINBOOL WINAPI EndDocPrinter(HANDLE hPrinter)
Definition: printers.c:217
WINBOOL WINAPI ClosePrinter(HANDLE hPrinter)
Definition: printers.c:176
WINBOOL WINAPI WritePrinter(HANDLE hPrinter, LPVOID pBuf, DWORD cbBuf, LPDWORD pcWritten)

Referenced by PrintDocumentOnPrintProcessor().