ReactOS 0.4.16-dev-297-gc569aee
printers.c File Reference
#include "precomp.h"
Include dependency graph for printers.c:

Go to the source code of this file.

Functions

BOOL WINAPI AbortPrinter (HANDLE hPrinter)
 
HANDLE WINAPI AddPrinterExW (PWSTR pName, DWORD Level, PBYTE pPrinter, PBYTE pClientInfo, DWORD ClientInfoLevel)
 
HANDLE WINAPI AddPrinterW (PWSTR pName, DWORD Level, PBYTE pPrinter)
 
BOOL WINAPI ClosePrinter (HANDLE hPrinter)
 
BOOL WINAPI DeletePrinter (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 GetPrinterW (HANDLE hPrinter, DWORD Level, PBYTE pPrinter, DWORD cbBuf, PDWORD pcbNeeded)
 
DWORD WINAPI PrinterMessageBoxW (HANDLE hPrinter, DWORD Error, HWND hWnd, LPWSTR pText, LPWSTR pCaption, DWORD dwType)
 
BOOL WINAPI OpenPrinterW (PWSTR pPrinterName, PHANDLE phPrinter, PPRINTER_DEFAULTSW pDefault)
 
BOOL WINAPI ReadPrinter (HANDLE hPrinter, PVOID pBuf, DWORD cbBuf, PDWORD pNoBytesRead)
 
BOOL WINAPI SeekPrinter (HANDLE hPrinter, LARGE_INTEGER liDistanceToMove, PLARGE_INTEGER pliNewPointer, DWORD dwMoveMethod, BOOL bWrite)
 
BOOL WINAPI SetPrinterW (HANDLE hPrinter, DWORD Level, PBYTE pPrinter, DWORD Command)
 
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

◆ AbortPrinter()

BOOL WINAPI AbortPrinter ( HANDLE  hPrinter)

Definition at line 11 of file printers.c.

12{
14
15 // Sanity checks.
16 if (!pHandle)
17 {
19 return FALSE;
20 }
21
22 return pHandle->pPrintProvider->PrintProvider.fpAbortPrinter(pHandle->hPrinter);
23}
#define FALSE
Definition: types.h:117
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
PSPOOLSS_PRINT_PROVIDER pPrintProvider
Definition: precomp.h:46
PRINTPROVIDOR PrintProvider
Definition: precomp.h:36
struct _SPOOLSS_PRINTER_HANDLE * PSPOOLSS_PRINTER_HANDLE

Referenced by _RpcAbortPrinter().

◆ AddPrinterExW()

HANDLE WINAPI AddPrinterExW ( PWSTR  pName,
DWORD  Level,
PBYTE  pPrinter,
PBYTE  pClientInfo,
DWORD  ClientInfoLevel 
)

Definition at line 29 of file printers.c.

30{
31 BOOL bReturnValue;
33 HANDLE hPrinter = NULL;
34 PWSTR pPrinterName = NULL;
37 PSPOOLSS_PRINT_PROVIDER pPrintProvider;
38
39 if ( Level != 2 )
40 {
41 FIXME( "Unsupported level %d\n", Level );
43 return hPrinter;
44 }
45 else
46 {
47 PPRINTER_INFO_2W pi2w = (PPRINTER_INFO_2W)pPrinter;
48 pPrinterName = pi2w->pPrinterName;
49 }
50
51 // Loop through all Print Providers to find one able to open this Printer.
53 {
55
56 hPrinter = pPrintProvider->PrintProvider.fpAddPrinterEx(pName, Level, pPrinter, pClientInfo, ClientInfoLevel);
57
58 bReturnValue = GetLastError();
59
60 // Fallback.... ?
61
62 if ( hPrinter == NULL && bReturnValue == ERROR_NOT_SUPPORTED )
63 {
64 hPrinter = pPrintProvider->PrintProvider.fpAddPrinter(pName, Level, pPrinter);
65 }
66
67 bReturnValue = GetLastError();
68
69 if ( bReturnValue == ROUTER_SUCCESS && hPrinter )
70 {
71 // This Print Provider has opened this Printer.
72 // Store this information and return a handle.
73 pHandle = DllAllocSplMem(sizeof(SPOOLSS_PRINTER_HANDLE));
74 if (!pHandle)
75 {
76 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
77 ERR("DllAllocSplMem failed!\n");
78 goto Cleanup;
79 }
80
81 pHandle->pPrintProvider = pPrintProvider;
82 pHandle->hPrinter = hPrinter;
83
84 dwErrorCode = ERROR_SUCCESS;
85 goto Cleanup;
86 }
87 else if (bReturnValue == ROUTER_STOP_ROUTING)
88 {
89 ERR("A Print Provider returned ROUTER_STOP_ROUTING for Printer \"%S\"!\n", pPrinterName);
90 dwErrorCode = GetLastError();
91 goto Cleanup;
92 }
93 }
94
96 // 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.
97 if (dwErrorCode == ERROR_INVALID_NAME)
98 dwErrorCode = ERROR_INVALID_PRINTER_NAME;
99
100 SetLastError(dwErrorCode);
101 return hPrinter;
102}
#define FIXME(fmt,...)
Definition: precomp.h:53
#define ERR(fmt,...)
Definition: precomp.h:57
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define ERROR_NOT_SUPPORTED
Definition: compat.h:100
#define ERROR_INVALID_NAME
Definition: compat.h:103
static const WCHAR Cleanup[]
Definition: register.c:80
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
PLIST_ENTRY pEntry
Definition: fxioqueue.cpp:4484
static LPSTR pName
Definition: security.c:75
#define ROUTER_STOP_ROUTING
Definition: winsplp.h:42
#define ROUTER_SUCCESS
Definition: winsplp.h:41
base of all file and directory entries
Definition: entries.h:83
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
LPWSTR pPrinterName
Definition: winspool.h:63
uint16_t * PWSTR
Definition: typedefs.h:56
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
LIST_ENTRY PrintProviderList
Definition: main.c:12
PVOID WINAPI DllAllocSplMem(DWORD dwBytes)
Definition: memory.c:95
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define ERROR_INVALID_LEVEL
Definition: winerror.h:196
#define ERROR_INVALID_PRINTER_NAME
Definition: winerror.h:1108
struct _PRINTER_INFO_2W * PPRINTER_INFO_2W
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:56

◆ AddPrinterW()

HANDLE WINAPI AddPrinterW ( PWSTR  pName,
DWORD  Level,
PBYTE  pPrinter 
)

Definition at line 105 of file printers.c.

106{
107 BOOL bReturnValue;
108 DWORD dwErrorCode = ERROR_INVALID_PRINTER_NAME;
109 HANDLE hPrinter = NULL;
110 PWSTR pPrinterName = NULL;
113 PSPOOLSS_PRINT_PROVIDER pPrintProvider;
114
115 FIXME("AddPrinterW(%S, %lu, %p)\n", pName, Level, pPrinter);
116
117 if ( Level != 2 )
118 {
119 FIXME( "Unsupported level %d\n", Level );
121 return hPrinter;
122 }
123 else
124 {
125 PPRINTER_INFO_2W pi2w = (PPRINTER_INFO_2W)pPrinter;
126 pPrinterName = pi2w->pPrinterName;
127 }
128
129 // Xp return AddPrinterExW( pName, Level, pPrinter, NULL, 0); but,,,, W7u just Forward Direct.
130
131 // Loop through all Print Providers to find one able to open this Printer.
133 {
135
136 hPrinter = pPrintProvider->PrintProvider.fpAddPrinter(pName, Level, pPrinter);
137
138 bReturnValue = GetLastError();
139
140 if ( bReturnValue == ROUTER_SUCCESS && hPrinter )
141 {
142 // This Print Provider has opened this Printer.
143 // Store this information and return a handle.
144 pHandle = DllAllocSplMem(sizeof(SPOOLSS_PRINTER_HANDLE));
145 if (!pHandle)
146 {
147 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
148 ERR("DllAllocSplMem failed!\n");
149 goto Cleanup;
150 }
151
152 pHandle->pPrintProvider = pPrintProvider;
153 pHandle->hPrinter = hPrinter;
154
155 dwErrorCode = ERROR_SUCCESS;
156 goto Cleanup;
157 }
158 else if (bReturnValue == ROUTER_STOP_ROUTING)
159 {
160 ERR("A Print Provider returned ROUTER_STOP_ROUTING for Printer \"%S\"!\n", pPrinterName);
161 dwErrorCode = GetLastError();
162 goto Cleanup;
163 }
164 }
165
166Cleanup:
167 // 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.
168 if (dwErrorCode == ERROR_INVALID_NAME)
169 dwErrorCode = ERROR_INVALID_PRINTER_NAME;
170
171 SetLastError(dwErrorCode);
172 return hPrinter;
173}

Referenced by AddPrinterA().

◆ ClosePrinter()

BOOL WINAPI ClosePrinter ( HANDLE  hPrinter)

Definition at line 176 of file printers.c.

177{
178 BOOL bReturnValue;
180
181 FIXME("ClosePrinter %p\n",hPrinter);
182
183 // Sanity checks.
184 if (!pHandle)
185 {
187 return FALSE;
188 }
189
190 // FIXME: Call FindClosePrinterChangeNotification for all created change notifications (according to MSDN).
191
192 // Call CloseHandle of the Print Provider.
193 bReturnValue = pHandle->pPrintProvider->PrintProvider.fpClosePrinter(pHandle->hPrinter);
194 FIXME("ClosePrinter 2\n");
195 // Free our handle information.
196 DllFreeSplMem(pHandle);
197 FIXME("ClosePrinter 3\n");
198 return bReturnValue;
199}
BOOL WINAPI DllFreeSplMem(PVOID pMem)
Definition: memory.c:112

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

◆ DeletePrinter()

BOOL WINAPI DeletePrinter ( HANDLE  hPrinter)

Definition at line 202 of file printers.c.

203{
205
206 // Sanity checks.
207 if (!pHandle)
208 {
210 return FALSE;
211 }
212
213 return pHandle->pPrintProvider->PrintProvider.fpDeletePrinter(pHandle->hPrinter);
214}

Referenced by _RpcDeletePrinter().

◆ EndDocPrinter()

BOOL WINAPI EndDocPrinter ( HANDLE  hPrinter)

Definition at line 217 of file printers.c.

218{
220
221 // Sanity checks.
222 if (!pHandle)
223 {
225 return FALSE;
226 }
227
228 return pHandle->pPrintProvider->PrintProvider.fpEndDocPrinter(pHandle->hPrinter);
229}

Referenced by _RpcEndDocPrinter().

◆ EndPagePrinter()

BOOL WINAPI EndPagePrinter ( HANDLE  hPrinter)

Definition at line 232 of file printers.c.

233{
235
236 // Sanity checks.
237 if (!pHandle)
238 {
240 return FALSE;
241 }
242
243 return pHandle->pPrintProvider->PrintProvider.fpEndPagePrinter(pHandle->hPrinter);
244}

Referenced by _RpcEndPagePrinter().

◆ EnumPrintersW()

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

Definition at line 247 of file printers.c.

248{
249 DWORD cbCallBuffer;
250 DWORD cbNeeded;
251 DWORD dwErrorCode = MAXDWORD;
252 DWORD dwReturned;
253 PBYTE pCallBuffer;
254 BOOL Ret = FALSE;
255 PSPOOLSS_PRINT_PROVIDER pPrintProvider;
257
258 // Begin counting.
259 *pcbNeeded = 0;
260 *pcReturned = 0;
261
262 if (cbBuf && !pPrinterEnum)
263 {
264 dwErrorCode = ERROR_INVALID_USER_BUFFER;
265 goto Cleanup;
266 }
267
268 // At the beginning, we have the full buffer available.
269 cbCallBuffer = cbBuf;
270 pCallBuffer = pPrinterEnum;
271
272 // Loop through all Print Providers.
274 {
276
277 // Call the EnumPrinters function of this Print Provider.
278 cbNeeded = 0;
279 dwReturned = 0;
280 Ret = pPrintProvider->PrintProvider.fpEnumPrinters(Flags, Name, Level, pCallBuffer, cbCallBuffer, &cbNeeded, &dwReturned);
281
282 if ( !Ret )
283 {
284 dwErrorCode = GetLastError();
285 }
286
287 // Add the returned counts to the total values.
288 *pcbNeeded += cbNeeded;
289 *pcReturned += dwReturned;
290
291 // Reduce the available buffer size for the next call without risking an underflow.
292 if (cbNeeded < cbCallBuffer)
293 cbCallBuffer -= cbNeeded;
294 else
295 cbCallBuffer = 0;
296
297 // Advance the buffer if the caller provided it.
298 if (pCallBuffer)
299 pCallBuffer += cbNeeded;
300
301 // dwErrorCode shall not be overwritten if a previous EnumPrinters call already succeeded.
302 if (dwErrorCode != ERROR_SUCCESS)
303 dwErrorCode = GetLastError();
304 }
305
306Cleanup:
307 SetLastError(dwErrorCode);
308 return (dwErrorCode == ERROR_SUCCESS);
309}
#define MAXDWORD
BYTE * PBYTE
Definition: pedump.c:66
_In_ DWORD _Out_ PDWORD pcbNeeded
Definition: winddi.h:3828
#define ERROR_INVALID_USER_BUFFER
Definition: winerror.h:1091
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by _RpcEnumPrinters(), and EnumPrintersA().

◆ GetPrinterW()

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

Definition at line 312 of file printers.c.

313{
315
316 // Sanity checks.
317 if (!pHandle)
318 {
320 return FALSE;
321 }
322
323 return pHandle->pPrintProvider->PrintProvider.fpGetPrinter(pHandle->hPrinter, Level, pPrinter, cbBuf, pcbNeeded);
324}

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 345 of file printers.c.

346{
347 BOOL bReturnValue;
348 DWORD dwErrorCode = ERROR_INVALID_PRINTER_NAME;
349 HANDLE hPrinter;
352 PSPOOLSS_PRINT_PROVIDER pPrintProvider;
353
354 // Loop through all Print Providers to find one able to open this Printer.
356 {
358
359 bReturnValue = pPrintProvider->PrintProvider.fpOpenPrinter(pPrinterName, &hPrinter, pDefault);
360 if (bReturnValue == ROUTER_SUCCESS)
361 {
362 // This Print Provider has opened this Printer.
363 // Store this information and return a handle.
364 pHandle = DllAllocSplMem(sizeof(SPOOLSS_PRINTER_HANDLE));
365 if (!pHandle)
366 {
367 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
368 ERR("DllAllocSplMem failed!\n");
369 goto Cleanup;
370 }
371
372 pHandle->pPrintProvider = pPrintProvider;
373 pHandle->hPrinter = hPrinter;
374 *phPrinter = (HANDLE)pHandle;
375
376 dwErrorCode = ERROR_SUCCESS;
377 goto Cleanup;
378 }
379 else if (bReturnValue == ROUTER_STOP_ROUTING)
380 {
381 ERR("A Print Provider returned ROUTER_STOP_ROUTING for Printer \"%S\"!\n", pPrinterName);
382 dwErrorCode = GetLastError();
383 goto Cleanup;
384 }
385 }
386
387Cleanup:
388 // 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.
389 if (dwErrorCode == ERROR_INVALID_NAME)
390 dwErrorCode = ERROR_INVALID_PRINTER_NAME;
391
392 SetLastError(dwErrorCode);
393 return (dwErrorCode == ERROR_SUCCESS);
394}
PVOID HANDLE
Definition: typedefs.h:73

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

◆ PrinterMessageBoxW()

DWORD WINAPI PrinterMessageBoxW ( HANDLE  hPrinter,
DWORD  Error,
HWND  hWnd,
LPWSTR  pText,
LPWSTR  pCaption,
DWORD  dwType 
)

Definition at line 330 of file printers.c.

331{
333
334 // Sanity checks.
335 if (!pHandle)
336 {
338 return FALSE;
339 }
340
341 return pHandle->pPrintProvider->PrintProvider.fpPrinterMessageBox(pHandle->hPrinter, Error, hWnd, pText, pCaption, dwType);
342}
HWND hWnd
Definition: settings.c:17
BOOL Error
Definition: chkdsk.c:66
LPCSTR pText
Definition: txtscale.cpp:79

◆ ReadPrinter()

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

Definition at line 397 of file printers.c.

398{
400
401 // Sanity checks.
402 if (!pHandle)
403 {
405 return FALSE;
406 }
407
408 return pHandle->pPrintProvider->PrintProvider.fpReadPrinter(pHandle->hPrinter, pBuf, cbBuf, pNoBytesRead);
409}

Referenced by _RpcReadPrinter().

◆ SeekPrinter()

BOOL WINAPI SeekPrinter ( HANDLE  hPrinter,
LARGE_INTEGER  liDistanceToMove,
PLARGE_INTEGER  pliNewPointer,
DWORD  dwMoveMethod,
BOOL  bWrite 
)

Definition at line 412 of file printers.c.

413{
415
416 // Sanity checks.
417 if (!pHandle)
418 {
420 return FALSE;
421 }
422
423 return pHandle->pPrintProvider->PrintProvider.fpSeekPrinter( pHandle->hPrinter, liDistanceToMove, pliNewPointer, dwMoveMethod, bWrite );
424}

Referenced by _RpcSeekPrinter().

◆ SetPrinterW()

BOOL WINAPI SetPrinterW ( HANDLE  hPrinter,
DWORD  Level,
PBYTE  pPrinter,
DWORD  Command 
)

Definition at line 427 of file printers.c.

428{
430
431 // Sanity checks.
432 if (!pHandle)
433 {
435 return FALSE;
436 }
437
438 return pHandle->pPrintProvider->PrintProvider.fpSetPrinter( pHandle->hPrinter, Level, pPrinter, Command );
439}
Definition: shell.h:41

Referenced by SetPrinterA().

◆ StartDocPrinterW()

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

Definition at line 442 of file printers.c.

443{
445
446 // Sanity checks.
447 if (!pHandle)
448 {
450 return FALSE;
451 }
452
453 return pHandle->pPrintProvider->PrintProvider.fpStartDocPrinter(pHandle->hPrinter, Level, pDocInfo);
454}

Referenced by _RpcStartDocPrinter(), and StartDocPrinterA().

◆ StartPagePrinter()

BOOL WINAPI StartPagePrinter ( HANDLE  hPrinter)

Definition at line 457 of file printers.c.

458{
460
461 // Sanity checks.
462 if (!pHandle)
463 {
465 return FALSE;
466 }
467
468 return pHandle->pPrintProvider->PrintProvider.fpStartPagePrinter(pHandle->hPrinter);
469}

Referenced by _RpcStartPagePrinter().

◆ WritePrinter()

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

Definition at line 472 of file printers.c.

473{
475
476 // Sanity checks.
477 if (!pHandle)
478 {
480 return FALSE;
481 }
482
483 return pHandle->pPrintProvider->PrintProvider.fpWritePrinter(pHandle->hPrinter, pBuf, cbBuf, pcWritten);
484}

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 487 of file printers.c.

488{
490
491 FIXME("XcvDataW( %p, %S,,,)\n",hXcv, pszDataName);
492
493 // Sanity checks.
494 if (!pHandle)
495 {
497 return FALSE;
498 }
499
500 return pHandle->pPrintProvider->PrintProvider.fpXcvData(pHandle->hPrinter, pszDataName, pInputData, cbInputData, pOutputData, cbOutputData, pcbOutputNeeded, pdwStatus);
501}
static HANDLE hXcv
Definition: localmon.c:73