2 * PROJECT: ReactOS Print Spooler Service
3 * LICENSE: GNU GPLv2 or any later version as published by the Free Software Foundation
4 * PURPOSE: Functions related to Printers and printing
5 * COPYRIGHT: Copyright 2015 Colin Finck <colin@reactos.org>
11 _MarshallDownPrinterInfo(PBYTE pPrinterInfo
, DWORD Level
)
13 PPRINTER_INFO_1W pPrinterInfo1
;
14 PPRINTER_INFO_2W pPrinterInfo2
;
16 // Replace absolute pointer addresses in the output by relative offsets.
19 pPrinterInfo1
= (PPRINTER_INFO_1W
)pPrinterInfo
;
21 pPrinterInfo1
->pName
= (PWSTR
)((ULONG_PTR
)pPrinterInfo1
->pName
- (ULONG_PTR
)pPrinterInfo1
);
22 pPrinterInfo1
->pDescription
= (PWSTR
)((ULONG_PTR
)pPrinterInfo1
->pDescription
- (ULONG_PTR
)pPrinterInfo1
);
23 pPrinterInfo1
->pComment
= (PWSTR
)((ULONG_PTR
)pPrinterInfo1
->pComment
- (ULONG_PTR
)pPrinterInfo1
);
27 pPrinterInfo2
= (PPRINTER_INFO_2W
)pPrinterInfo
;
29 pPrinterInfo2
->pPrinterName
= (PWSTR
)((ULONG_PTR
)pPrinterInfo2
->pPrinterName
- (ULONG_PTR
)pPrinterInfo2
);
30 pPrinterInfo2
->pShareName
= (PWSTR
)((ULONG_PTR
)pPrinterInfo2
->pShareName
- (ULONG_PTR
)pPrinterInfo2
);
31 pPrinterInfo2
->pPortName
= (PWSTR
)((ULONG_PTR
)pPrinterInfo2
->pPortName
- (ULONG_PTR
)pPrinterInfo2
);
32 pPrinterInfo2
->pDriverName
= (PWSTR
)((ULONG_PTR
)pPrinterInfo2
->pDriverName
- (ULONG_PTR
)pPrinterInfo2
);
33 pPrinterInfo2
->pComment
= (PWSTR
)((ULONG_PTR
)pPrinterInfo2
->pComment
- (ULONG_PTR
)pPrinterInfo2
);
34 pPrinterInfo2
->pLocation
= (PWSTR
)((ULONG_PTR
)pPrinterInfo2
->pLocation
- (ULONG_PTR
)pPrinterInfo2
);
35 pPrinterInfo2
->pDevMode
= (PDEVMODEW
)((ULONG_PTR
)pPrinterInfo2
->pDevMode
- (ULONG_PTR
)pPrinterInfo2
);
36 pPrinterInfo2
->pSepFile
= (PWSTR
)((ULONG_PTR
)pPrinterInfo2
->pSepFile
- (ULONG_PTR
)pPrinterInfo2
);
37 pPrinterInfo2
->pPrintProcessor
= (PWSTR
)((ULONG_PTR
)pPrinterInfo2
->pPrintProcessor
- (ULONG_PTR
)pPrinterInfo2
);
38 pPrinterInfo2
->pDatatype
= (PWSTR
)((ULONG_PTR
)pPrinterInfo2
->pDatatype
- (ULONG_PTR
)pPrinterInfo2
);
39 pPrinterInfo2
->pParameters
= (PWSTR
)((ULONG_PTR
)pPrinterInfo2
->pParameters
- (ULONG_PTR
)pPrinterInfo2
);
41 if (pPrinterInfo2
->pServerName
)
42 pPrinterInfo2
->pServerName
= (PWSTR
)((ULONG_PTR
)pPrinterInfo2
->pServerName
- (ULONG_PTR
)pPrinterInfo2
);
44 if (pPrinterInfo2
->pSecurityDescriptor
)
45 pPrinterInfo2
->pSecurityDescriptor
= (PWSTR
)((ULONG_PTR
)pPrinterInfo2
->pSecurityDescriptor
- (ULONG_PTR
)pPrinterInfo2
);
50 _RpcAbortPrinter(WINSPOOL_PRINTER_HANDLE hPrinter
)
53 return ERROR_INVALID_FUNCTION
;
57 _RpcAddPrinter(WINSPOOL_HANDLE pName
, WINSPOOL_PRINTER_CONTAINER
* pPrinterContainer
, WINSPOOL_DEVMODE_CONTAINER
* pDevModeContainer
, WINSPOOL_SECURITY_CONTAINER
* pSecurityContainer
, WINSPOOL_PRINTER_HANDLE
* pHandle
)
60 return ERROR_INVALID_FUNCTION
;
64 _RpcAddPrinterEx(WINSPOOL_HANDLE pName
, WINSPOOL_PRINTER_CONTAINER
* pPrinterContainer
, WINSPOOL_DEVMODE_CONTAINER
* pDevModeContainer
, WINSPOOL_SECURITY_CONTAINER
* pSecurityContainer
, WINSPOOL_SPLCLIENT_CONTAINER
* pClientInfo
, WINSPOOL_PRINTER_HANDLE
* pHandle
)
67 return ERROR_INVALID_FUNCTION
;
71 _RpcClosePrinter(WINSPOOL_PRINTER_HANDLE
* phPrinter
)
75 dwErrorCode
= RpcImpersonateClient(NULL
);
76 if (dwErrorCode
!= ERROR_SUCCESS
)
78 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode
);
82 if (ClosePrinter(*phPrinter
))
85 dwErrorCode
= GetLastError();
92 _RpcDeletePrinter(WINSPOOL_PRINTER_HANDLE hPrinter
)
95 return ERROR_INVALID_FUNCTION
;
99 _RpcEndDocPrinter(WINSPOOL_PRINTER_HANDLE hPrinter
)
103 dwErrorCode
= RpcImpersonateClient(NULL
);
104 if (dwErrorCode
!= ERROR_SUCCESS
)
106 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode
);
110 EndDocPrinter(hPrinter
);
111 dwErrorCode
= GetLastError();
118 _RpcEndPagePrinter(WINSPOOL_PRINTER_HANDLE hPrinter
)
122 dwErrorCode
= RpcImpersonateClient(NULL
);
123 if (dwErrorCode
!= ERROR_SUCCESS
)
125 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode
);
129 EndPagePrinter(hPrinter
);
130 dwErrorCode
= GetLastError();
137 _RpcEnumPrinters(DWORD Flags
, WINSPOOL_HANDLE Name
, DWORD Level
, BYTE
* pPrinterEnum
, DWORD cbBuf
, DWORD
* pcbNeeded
, DWORD
* pcReturned
)
141 PBYTE p
= pPrinterEnum
;
143 dwErrorCode
= RpcImpersonateClient(NULL
);
144 if (dwErrorCode
!= ERROR_SUCCESS
)
146 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode
);
150 EnumPrintersW(Flags
, Name
, Level
, pPrinterEnum
, cbBuf
, pcbNeeded
, pcReturned
);
151 dwErrorCode
= GetLastError();
153 if (dwErrorCode
== ERROR_SUCCESS
)
155 // Replace absolute pointer addresses in the output by relative offsets.
156 for (i
= 0; i
< *pcReturned
; i
++)
158 _MarshallDownPrinterInfo(p
, Level
);
161 p
+= sizeof(PRINTER_INFO_1W
);
163 p
+= sizeof(PRINTER_INFO_2W
);
172 _RpcFlushPrinter(WINSPOOL_PRINTER_HANDLE hPrinter
, BYTE
* pBuf
, DWORD cbBuf
, DWORD
* pcWritten
, DWORD cSleep
)
175 return ERROR_INVALID_FUNCTION
;
179 _RpcGetPrinter(WINSPOOL_PRINTER_HANDLE hPrinter
, DWORD Level
, BYTE
* pPrinter
, DWORD cbBuf
, DWORD
* pcbNeeded
)
182 return ERROR_INVALID_FUNCTION
;
186 _RpcOpenPrinter(WINSPOOL_HANDLE pPrinterName
, WINSPOOL_PRINTER_HANDLE
* phPrinter
, WCHAR
* pDatatype
, WINSPOOL_DEVMODE_CONTAINER
* pDevModeContainer
, DWORD AccessRequired
)
189 PRINTER_DEFAULTSW Default
;
191 dwErrorCode
= RpcImpersonateClient(NULL
);
192 if (dwErrorCode
!= ERROR_SUCCESS
)
194 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode
);
198 Default
.DesiredAccess
= AccessRequired
;
199 Default
.pDatatype
= pDatatype
;
200 Default
.pDevMode
= (PDEVMODEW
)pDevModeContainer
->pDevMode
;
202 OpenPrinterW(pPrinterName
, phPrinter
, &Default
);
203 dwErrorCode
= GetLastError();
210 _RpcOpenPrinterEx(WINSPOOL_HANDLE pPrinterName
, WINSPOOL_PRINTER_HANDLE
* pHandle
, WCHAR
* pDatatype
, WINSPOOL_DEVMODE_CONTAINER
* pDevModeContainer
, DWORD AccessRequired
, WINSPOOL_SPLCLIENT_CONTAINER
* pClientInfo
)
213 return ERROR_INVALID_FUNCTION
;
217 _RpcReadPrinter(WINSPOOL_PRINTER_HANDLE hPrinter
, BYTE
* pBuf
, DWORD cbBuf
, DWORD
* pcNoBytesRead
)
221 dwErrorCode
= RpcImpersonateClient(NULL
);
222 if (dwErrorCode
!= ERROR_SUCCESS
)
224 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode
);
228 ReadPrinter(hPrinter
, pBuf
, cbBuf
, pcNoBytesRead
);
229 dwErrorCode
= GetLastError();
236 _RpcResetPrinter(WINSPOOL_PRINTER_HANDLE hPrinter
, WCHAR
* pDatatype
, WINSPOOL_DEVMODE_CONTAINER
* pDevModeContainer
)
239 return ERROR_INVALID_FUNCTION
;
246 return ERROR_INVALID_FUNCTION
;
253 return ERROR_INVALID_FUNCTION
;
257 _RpcSetPrinter(WINSPOOL_PRINTER_HANDLE hPrinter
, WINSPOOL_PRINTER_CONTAINER
* pPrinterContainer
, WINSPOOL_DEVMODE_CONTAINER
* pDevModeContainer
, WINSPOOL_SECURITY_CONTAINER
* pSecurityContainer
, DWORD Command
)
260 return ERROR_INVALID_FUNCTION
;
264 _RpcStartDocPrinter(WINSPOOL_PRINTER_HANDLE hPrinter
, WINSPOOL_DOC_INFO_CONTAINER
* pDocInfoContainer
, DWORD
* pJobId
)
268 dwErrorCode
= RpcImpersonateClient(NULL
);
269 if (dwErrorCode
!= ERROR_SUCCESS
)
271 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode
);
275 *pJobId
= StartDocPrinterW(hPrinter
, pDocInfoContainer
->Level
, (PBYTE
)pDocInfoContainer
->DocInfo
.pDocInfo1
);
276 dwErrorCode
= GetLastError();
283 _RpcStartPagePrinter(WINSPOOL_PRINTER_HANDLE hPrinter
)
287 dwErrorCode
= RpcImpersonateClient(NULL
);
288 if (dwErrorCode
!= ERROR_SUCCESS
)
290 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode
);
294 StartPagePrinter(hPrinter
);
295 dwErrorCode
= GetLastError();
302 _RpcWritePrinter(WINSPOOL_PRINTER_HANDLE hPrinter
, BYTE
* pBuf
, DWORD cbBuf
, DWORD
* pcWritten
)
306 dwErrorCode
= RpcImpersonateClient(NULL
);
307 if (dwErrorCode
!= ERROR_SUCCESS
)
309 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode
);
313 WritePrinter(hPrinter
, pBuf
, cbBuf
, pcWritten
);
314 dwErrorCode
= GetLastError();