ReactOS  0.4.15-dev-499-g1f31905
printers.c File Reference
#include "precomp.h"
Include dependency graph for printers.c:

Go to the source code of this file.

Functions

BOOL WINAPI ClosePrinter (HANDLE hPrinter)
 
BOOL WINAPI EndDocPrinter (HANDLE hPrinter)
 
BOOL WINAPI EndPagePrinter (HANDLE hPrinter)
 
BOOL WINAPI EnumPrintersW (DWORD Flags, PWSTR Name, DWORD Level, PBYTE pPrinterEnum, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
 
BOOL WINAPI GetPrinterDriverW (HANDLE hPrinter, PWSTR pEnvironment, DWORD Level, PBYTE pDriverInfo, DWORD cbBuf, PDWORD pcbNeeded)
 
BOOL WINAPI GetPrinterW (HANDLE hPrinter, DWORD Level, PBYTE pPrinter, DWORD cbBuf, PDWORD pcbNeeded)
 
BOOL WINAPI OpenPrinterW (PWSTR pPrinterName, PHANDLE phPrinter, PPRINTER_DEFAULTSW pDefault)
 
BOOL WINAPI ReadPrinter (HANDLE hPrinter, PVOID pBuf, DWORD cbBuf, PDWORD pNoBytesRead)
 
DWORD WINAPI StartDocPrinterW (HANDLE hPrinter, DWORD Level, PBYTE pDocInfo)
 
BOOL WINAPI StartPagePrinter (HANDLE hPrinter)
 
BOOL WINAPI WritePrinter (HANDLE hPrinter, PVOID pBuf, DWORD cbBuf, PDWORD pcWritten)
 
BOOL WINAPI XcvDataW (HANDLE hXcv, PCWSTR pszDataName, PBYTE pInputData, DWORD cbInputData, PBYTE pOutputData, DWORD cbOutputData, PDWORD pcbOutputNeeded, PDWORD pdwStatus)
 

Function Documentation

◆ ClosePrinter()

BOOL WINAPI ClosePrinter ( HANDLE  hPrinter)

Definition at line 12 of file printers.c.

13 {
14  BOOL bReturnValue;
16 
17  // Sanity checks.
18  if (!pHandle)
19  {
21  return FALSE;
22  }
23 
24  // FIXME: Call FindClosePrinterChangeNotification for all created change notifications (according to MSDN).
25 
26  // Call CloseHandle of the Print Provider.
27  bReturnValue = pHandle->pPrintProvider->PrintProvider.fpClosePrinter(pHandle->hPrinter);
28 
29  // Free our handle information.
30  DllFreeSplMem(pHandle);
31 
32  return bReturnValue;
33 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
BOOL WINAPI DllFreeSplMem(PVOID pMem)
Definition: memory.c:112
struct _SPOOLSS_PRINTER_HANDLE * PSPOOLSS_PRINTER_HANDLE
unsigned int BOOL
Definition: ntddk_ex.h:94
#define SetLastError(x)
Definition: compat.h:418
PRINTPROVIDOR PrintProvider
Definition: precomp.h:36
PSPOOLSS_PRINT_PROVIDER pPrintProvider
Definition: precomp.h:46

Referenced by _RpcClosePrinter(), DeviceCapabilitiesW(), DocumentPropertiesW(), and SpoolerPrinterEvent().

◆ EndDocPrinter()

BOOL WINAPI EndDocPrinter ( HANDLE  hPrinter)

Definition at line 36 of file printers.c.

37 {
39 
40  // Sanity checks.
41  if (!pHandle)
42  {
44  return FALSE;
45  }
46 
47  return pHandle->pPrintProvider->PrintProvider.fpEndDocPrinter(pHandle->hPrinter);
48 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
struct _SPOOLSS_PRINTER_HANDLE * PSPOOLSS_PRINTER_HANDLE
#define SetLastError(x)
Definition: compat.h:418
PRINTPROVIDOR PrintProvider
Definition: precomp.h:36
PSPOOLSS_PRINT_PROVIDER pPrintProvider
Definition: precomp.h:46

Referenced by _RpcEndDocPrinter().

◆ EndPagePrinter()

BOOL WINAPI EndPagePrinter ( HANDLE  hPrinter)

Definition at line 51 of file printers.c.

52 {
54 
55  // Sanity checks.
56  if (!pHandle)
57  {
59  return FALSE;
60  }
61 
62  return pHandle->pPrintProvider->PrintProvider.fpEndPagePrinter(pHandle->hPrinter);
63 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
struct _SPOOLSS_PRINTER_HANDLE * PSPOOLSS_PRINTER_HANDLE
#define SetLastError(x)
Definition: compat.h:418
PRINTPROVIDOR PrintProvider
Definition: precomp.h:36
PSPOOLSS_PRINT_PROVIDER pPrintProvider
Definition: precomp.h:46

Referenced by _RpcEndPagePrinter().

◆ EnumPrintersW()

BOOL WINAPI EnumPrintersW ( DWORD  Flags,
PWSTR  Name,
DWORD  Level,
PBYTE  pPrinterEnum,
DWORD  cbBuf,
PDWORD  pcbNeeded,
PDWORD  pcReturned 
)

Definition at line 66 of file printers.c.

67 {
68  DWORD cbCallBuffer;
69  DWORD cbNeeded;
70  DWORD dwErrorCode = MAXDWORD;
71  DWORD dwReturned;
72  PBYTE pCallBuffer;
73  PSPOOLSS_PRINT_PROVIDER pPrintProvider;
74  PLIST_ENTRY pEntry;
75 
76  // Begin counting.
77  *pcbNeeded = 0;
78  *pcReturned = 0;
79 
80  if (cbBuf && !pPrinterEnum)
81  {
82  dwErrorCode = ERROR_INVALID_USER_BUFFER;
83  goto Cleanup;
84  }
85 
86  // At the beginning, we have the full buffer available.
87  cbCallBuffer = cbBuf;
88  pCallBuffer = pPrinterEnum;
89 
90  // Loop through all Print Providers.
91  for (pEntry = PrintProviderList.Flink; pEntry != &PrintProviderList; pEntry = pEntry->Flink)
92  {
93  pPrintProvider = CONTAINING_RECORD(pEntry, SPOOLSS_PRINT_PROVIDER, Entry);
94 
95  // Call the EnumPrinters function of this Print Provider.
96  cbNeeded = 0;
97  dwReturned = 0;
98  pPrintProvider->PrintProvider.fpEnumPrinters(Flags, Name, Level, pCallBuffer, cbCallBuffer, &cbNeeded, &dwReturned);
99 
100  // Add the returned counts to the total values.
101  *pcbNeeded += cbNeeded;
102  *pcReturned += dwReturned;
103 
104  // Reduce the available buffer size for the next call without risking an underflow.
105  if (cbNeeded < cbCallBuffer)
106  cbCallBuffer -= cbNeeded;
107  else
108  cbCallBuffer = 0;
109 
110  // Advance the buffer if the caller provided it.
111  if (pCallBuffer)
112  pCallBuffer += cbNeeded;
113 
114  // dwErrorCode shall not be overwritten if a previous EnumPrinters call already succeeded.
115  if (dwErrorCode != ERROR_SUCCESS)
116  dwErrorCode = GetLastError();
117  }
118 
119 Cleanup:
120  SetLastError(dwErrorCode);
121  return (dwErrorCode == ERROR_SUCCESS);
122 }
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
#define ERROR_INVALID_USER_BUFFER
Definition: winerror.h:1091
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define MAXDWORD
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
LIST_ENTRY PrintProviderList
Definition: main.c:12
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:418
Definition: typedefs.h:118
static const WCHAR Cleanup[]
Definition: register.c:80
_In_ DWORD _Out_ PDWORD pcbNeeded
Definition: winddi.h:3827
PRINTPROVIDOR PrintProvider
Definition: precomp.h:36
BYTE * PBYTE
Definition: pedump.c:66
base of all file and directory entries
Definition: entries.h:82

Referenced by _RpcEnumPrinters(), and EnumPrintersA().

◆ GetPrinterDriverW()

BOOL WINAPI GetPrinterDriverW ( HANDLE  hPrinter,
PWSTR  pEnvironment,
DWORD  Level,
PBYTE  pDriverInfo,
DWORD  cbBuf,
PDWORD  pcbNeeded 
)

Definition at line 125 of file printers.c.

126 {
128 
129  // Sanity checks.
130  if (!pHandle)
131  {
133  return FALSE;
134  }
135 
136  return pHandle->pPrintProvider->PrintProvider.fpGetPrinterDriver(pHandle->hPrinter, pEnvironment, Level, pDriverInfo, cbBuf, pcbNeeded);
137 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
struct _SPOOLSS_PRINTER_HANDLE * PSPOOLSS_PRINTER_HANDLE
#define SetLastError(x)
Definition: compat.h:418
_In_ DWORD _Out_ PDWORD pcbNeeded
Definition: winddi.h:3827
PRINTPROVIDOR PrintProvider
Definition: precomp.h:36
PSPOOLSS_PRINT_PROVIDER pPrintProvider
Definition: precomp.h:46

Referenced by LoadPrinterDriver().

◆ GetPrinterW()

BOOL WINAPI GetPrinterW ( HANDLE  hPrinter,
DWORD  Level,
PBYTE  pPrinter,
DWORD  cbBuf,
PDWORD  pcbNeeded 
)

Definition at line 140 of file printers.c.

141 {
143 
144  // Sanity checks.
145  if (!pHandle)
146  {
148  return FALSE;
149  }
150 
151  return pHandle->pPrintProvider->PrintProvider.fpGetPrinter(pHandle->hPrinter, Level, pPrinter, cbBuf, pcbNeeded);
152 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
struct _SPOOLSS_PRINTER_HANDLE * PSPOOLSS_PRINTER_HANDLE
#define SetLastError(x)
Definition: compat.h:418
_In_ DWORD _Out_ PDWORD pcbNeeded
Definition: winddi.h:3827
PRINTPROVIDOR PrintProvider
Definition: precomp.h:36
PSPOOLSS_PRINT_PROVIDER pPrintProvider
Definition: precomp.h:46

Referenced by _RpcGetPrinter(), get_devmodeW(), GetPrinterA(), IntFixUpDevModeNames(), PrinterProperties(), QuerySpoolMode(), and StartDocDlgW().

◆ OpenPrinterW()

BOOL WINAPI OpenPrinterW ( PWSTR  pPrinterName,
PHANDLE  phPrinter,
PPRINTER_DEFAULTSW  pDefault 
)

Definition at line 155 of file printers.c.

156 {
157  BOOL bReturnValue;
158  DWORD dwErrorCode = ERROR_INVALID_PRINTER_NAME;
159  HANDLE hPrinter;
160  PLIST_ENTRY pEntry;
161  PSPOOLSS_PRINTER_HANDLE pHandle;
162  PSPOOLSS_PRINT_PROVIDER pPrintProvider;
163 
164  // Loop through all Print Providers to find one able to open this Printer.
165  for (pEntry = PrintProviderList.Flink; pEntry != &PrintProviderList; pEntry = pEntry->Flink)
166  {
167  pPrintProvider = CONTAINING_RECORD(pEntry, SPOOLSS_PRINT_PROVIDER, Entry);
168 
169  bReturnValue = pPrintProvider->PrintProvider.fpOpenPrinter(pPrinterName, &hPrinter, pDefault);
170  if (bReturnValue == ROUTER_SUCCESS)
171  {
172  // This Print Provider has opened this Printer.
173  // Store this information and return a handle.
174  pHandle = DllAllocSplMem(sizeof(SPOOLSS_PRINTER_HANDLE));
175  if (!pHandle)
176  {
177  dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
178  ERR("DllAllocSplMem failed!\n");
179  goto Cleanup;
180  }
181 
182  pHandle->pPrintProvider = pPrintProvider;
183  pHandle->hPrinter = hPrinter;
184  *phPrinter = (HANDLE)pHandle;
185 
186  dwErrorCode = ERROR_SUCCESS;
187  goto Cleanup;
188  }
189  else if (bReturnValue == ROUTER_STOP_ROUTING)
190  {
191  ERR("A Print Provider returned ROUTER_STOP_ROUTING for Printer \"%S\"!\n", pPrinterName);
192  dwErrorCode = GetLastError();
193  goto Cleanup;
194  }
195  }
196 
197 Cleanup:
198  // ERROR_INVALID_NAME by the Print Provider is translated to ERROR_INVALID_PRINTER_NAME here, but not in other APIs as far as I know.
199  if (dwErrorCode == ERROR_INVALID_NAME)
200  dwErrorCode = ERROR_INVALID_PRINTER_NAME;
201 
202  SetLastError(dwErrorCode);
203  return (dwErrorCode == ERROR_SUCCESS);
204 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ROUTER_SUCCESS
Definition: winsplp.h:41
#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
#define ROUTER_STOP_ROUTING
Definition: winsplp.h:42
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
LIST_ENTRY PrintProviderList
Definition: main.c:12
PVOID HANDLE
Definition: typedefs.h:72
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:418
Definition: typedefs.h:118
static const WCHAR Cleanup[]
Definition: register.c:80
#define ERROR_INVALID_PRINTER_NAME
Definition: winerror.h:1108
#define ERR(fmt,...)
Definition: debug.h:110
#define ERROR_INVALID_NAME
Definition: compat.h:93
PRINTPROVIDOR PrintProvider
Definition: precomp.h:36
PVOID WINAPI DllAllocSplMem(DWORD dwBytes)
Definition: memory.c:95
base of all file and directory entries
Definition: entries.h:82
PSPOOLSS_PRINT_PROVIDER pPrintProvider
Definition: precomp.h:46

Referenced by _RpcOpenPrinter(), DeviceCapabilitiesW(), DocumentPropertiesW(), OpenPrinterA(), and SpoolerPrinterEvent().

◆ ReadPrinter()

BOOL WINAPI ReadPrinter ( HANDLE  hPrinter,
PVOID  pBuf,
DWORD  cbBuf,
PDWORD  pNoBytesRead 
)

Definition at line 207 of file printers.c.

208 {
210 
211  // Sanity checks.
212  if (!pHandle)
213  {
215  return FALSE;
216  }
217 
218  return pHandle->pPrintProvider->PrintProvider.fpReadPrinter(pHandle->hPrinter, pBuf, cbBuf, pNoBytesRead);
219 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
struct _SPOOLSS_PRINTER_HANDLE * PSPOOLSS_PRINTER_HANDLE
#define SetLastError(x)
Definition: compat.h:418
PRINTPROVIDOR PrintProvider
Definition: precomp.h:36
PSPOOLSS_PRINT_PROVIDER pPrintProvider
Definition: precomp.h:46

Referenced by _RpcReadPrinter().

◆ StartDocPrinterW()

DWORD WINAPI StartDocPrinterW ( HANDLE  hPrinter,
DWORD  Level,
PBYTE  pDocInfo 
)

Definition at line 222 of file printers.c.

223 {
225 
226  // Sanity checks.
227  if (!pHandle)
228  {
230  return FALSE;
231  }
232 
233  return pHandle->pPrintProvider->PrintProvider.fpStartDocPrinter(pHandle->hPrinter, Level, pDocInfo);
234 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
struct _SPOOLSS_PRINTER_HANDLE * PSPOOLSS_PRINTER_HANDLE
#define SetLastError(x)
Definition: compat.h:418
PRINTPROVIDOR PrintProvider
Definition: precomp.h:36
PSPOOLSS_PRINT_PROVIDER pPrintProvider
Definition: precomp.h:46

Referenced by _RpcStartDocPrinter(), and StartDocPrinterA().

◆ StartPagePrinter()

BOOL WINAPI StartPagePrinter ( HANDLE  hPrinter)

Definition at line 237 of file printers.c.

238 {
240 
241  // Sanity checks.
242  if (!pHandle)
243  {
245  return FALSE;
246  }
247 
248  return pHandle->pPrintProvider->PrintProvider.fpStartPagePrinter(pHandle->hPrinter);
249 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
struct _SPOOLSS_PRINTER_HANDLE * PSPOOLSS_PRINTER_HANDLE
#define SetLastError(x)
Definition: compat.h:418
PRINTPROVIDOR PrintProvider
Definition: precomp.h:36
PSPOOLSS_PRINT_PROVIDER pPrintProvider
Definition: precomp.h:46

Referenced by _RpcStartPagePrinter().

◆ WritePrinter()

BOOL WINAPI WritePrinter ( HANDLE  hPrinter,
PVOID  pBuf,
DWORD  cbBuf,
PDWORD  pcWritten 
)

Definition at line 252 of file printers.c.

253 {
255 
256  // Sanity checks.
257  if (!pHandle)
258  {
260  return FALSE;
261  }
262 
263  return pHandle->pPrintProvider->PrintProvider.fpWritePrinter(pHandle->hPrinter, pBuf, cbBuf, pcWritten);
264 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
struct _SPOOLSS_PRINTER_HANDLE * PSPOOLSS_PRINTER_HANDLE
#define SetLastError(x)
Definition: compat.h:418
PRINTPROVIDOR PrintProvider
Definition: precomp.h:36
PSPOOLSS_PRINT_PROVIDER pPrintProvider
Definition: precomp.h:46

Referenced by _RpcWritePrinter().

◆ XcvDataW()

BOOL WINAPI XcvDataW ( HANDLE  hXcv,
PCWSTR  pszDataName,
PBYTE  pInputData,
DWORD  cbInputData,
PBYTE  pOutputData,
DWORD  cbOutputData,
PDWORD  pcbOutputNeeded,
PDWORD  pdwStatus 
)

Definition at line 267 of file printers.c.

268 {
270 
271  // Sanity checks.
272  if (!pHandle)
273  {
275  return FALSE;
276  }
277 
278  return pHandle->pPrintProvider->PrintProvider.fpXcvData(pHandle->hPrinter, pszDataName, pInputData, cbInputData, pOutputData, cbOutputData, pcbOutputNeeded, pdwStatus);
279 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
struct _SPOOLSS_PRINTER_HANDLE * PSPOOLSS_PRINTER_HANDLE
#define SetLastError(x)
Definition: compat.h:418
PRINTPROVIDOR PrintProvider
Definition: precomp.h:36
static HANDLE hXcv
Definition: localmon.c:73
PSPOOLSS_PRINT_PROVIDER pPrintProvider
Definition: precomp.h:46