ReactOS  0.4.14-dev-998-g623dd26
precomp.h File Reference
#include <stdlib.h>
#include <windef.h>
#include <winbase.h>
#include <wingdi.h>
#include <winreg.h>
#include <winspool.h>
#include <winsplp.h>
#include <spoolss.h>
#include <wine/debug.h>
Include dependency graph for precomp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _WINPRINT_HANDLE
 

Macros

#define WIN32_NO_STATUS
 

Typedefs

typedef struct _WINPRINT_HANDLE WINPRINT_HANDLE
 
typedef struct _WINPRINT_HANDLEPWINPRINT_HANDLE
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (winprint)
 
DWORD PrintRawJob (PWINPRINT_HANDLE pHandle, PWSTR pwszPrinterAndJob)
 

Macro Definition Documentation

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 11 of file precomp.h.

Typedef Documentation

◆ PWINPRINT_HANDLE

◆ WINPRINT_HANDLE

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;
35  PBYTE pBuffer = 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 
86 Cleanup:
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 }
LPWSTR pDocName
Definition: winspool.h:556
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
BOOL WINAPI DllFreeSplMem(PVOID pMem)
Definition: memory.c:112
LPWSTR pOutputFile
Definition: winspool.h:557
DWORD WINAPI StartDocPrinterW(HANDLE hPrinter, DWORD Level, LPBYTE pDocInfo)
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
unsigned int BOOL
Definition: ntddk_ex.h:94
WINBOOL WINAPI ClosePrinter(HANDLE hPrinter)
Definition: printers.c:12
smooth NULL
Definition: ftsmooth.c:416
PVOID pBuffer
LPWSTR pDatatype
Definition: winspool.h:558
PWSTR pwszOutputFile
Definition: precomp.h:32
WINBOOL WINAPI WritePrinter(HANDLE hPrinter, LPVOID pBuf, DWORD cbBuf, LPDWORD pcWritten)
PWSTR pwszDocumentName
Definition: precomp.h:31
unsigned long DWORD
Definition: ntddk_ex.h:95
WINBOOL WINAPI ReadPrinter(HANDLE hPrinter, LPVOID pBuf, DWORD cbBuf, LPDWORD pNoBytesRead)
static const WCHAR Cleanup[]
Definition: register.c:80
#define ERR(fmt,...)
Definition: debug.h:109
WINBOOL WINAPI OpenPrinterW(LPWSTR pPrinterName, LPHANDLE phPrinter, LPPRINTER_DEFAULTSW pDefault)
Definition: printers.c:1884
PWSTR pwszPrinterPort
Definition: precomp.h:33
WINBOOL WINAPI EndDocPrinter(HANDLE hPrinter)
Definition: printers.c:36
PVOID WINAPI DllAllocSplMem(DWORD dwBytes)
Definition: memory.c:95
PWSTR pwszDatatype
Definition: precomp.h:30
BYTE * PBYTE
Definition: pedump.c:66

Referenced by PrintDocumentOnPrintProcessor().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( winprint  )