[SPOOLSS] [SPOOLSV] [WINSPOOL]
[reactos.git] / reactos / win32ss / printing / base / winspool / printers.c
1 /*
2 * PROJECT: ReactOS Spooler API
3 * LICENSE: GNU LGPL v2.1 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>
6 */
7
8 #include "precomp.h"
9
10 BOOL WINAPI
11 EnumPrintersA(DWORD Flags, LPSTR Name, DWORD Level, LPBYTE pPrinterEnum, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned)
12 {
13 return FALSE;
14 }
15
16 BOOL WINAPI
17 EnumPrintersW(DWORD Flags, LPWSTR Name, DWORD Level, LPBYTE pPrinterEnum, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned)
18 {
19 BOOL bReturnValue = FALSE;
20 DWORD dwErrorCode;
21
22 // Do the RPC call
23 RpcTryExcept
24 {
25 dwErrorCode = _RpcEnumPrinters(Flags, Name, Level, pPrinterEnum, cbBuf, pcbNeeded, pcReturned);
26 if (dwErrorCode)
27 {
28 ERR("_RpcEnumPrinters failed with error %lu!\n", dwErrorCode);
29 }
30
31 bReturnValue = (dwErrorCode == ERROR_SUCCESS);
32 }
33 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
34 {
35 ERR("_RpcEnumPrinters failed with exception code %lu!\n", RpcExceptionCode());
36 }
37 RpcEndExcept;
38
39 return bReturnValue;
40 }
41
42 BOOL WINAPI
43 ClosePrinter(HANDLE hPrinter)
44 {
45 return FALSE;
46 }
47
48 DWORD WINAPI
49 DeviceCapabilitiesA(LPCSTR pDevice, LPCSTR pPort, WORD fwCapability, LPSTR pOutput, const DEVMODEA* pDevMode)
50 {
51 return 0;
52 }
53
54 DWORD WINAPI
55 DeviceCapabilitiesW(LPCWSTR pDevice, LPCWSTR pPort, WORD fwCapability, LPWSTR pOutput, const DEVMODEW* pDevMode)
56 {
57 return 0;
58 }
59
60 LONG WINAPI
61 DocumentPropertiesA(HWND hWnd, HANDLE hPrinter, LPSTR pDeviceName, PDEVMODEA pDevModeOutput, PDEVMODEA pDevModeInput, DWORD fMode)
62 {
63 return 0;
64 }
65
66 LONG WINAPI
67 DocumentPropertiesW(HWND hWnd, HANDLE hPrinter, LPWSTR pDeviceName, PDEVMODEW pDevModeOutput, PDEVMODEW pDevModeInput, DWORD fMode)
68 {
69 return 0;
70 }
71
72 BOOL WINAPI
73 EndDocPrinter(HANDLE hPrinter)
74 {
75 return FALSE;
76 }
77
78 BOOL WINAPI
79 EndPagePrinter(HANDLE hPrinter)
80 {
81 return FALSE;
82 }
83
84 BOOL WINAPI
85 GetDefaultPrinterA(LPSTR pszBuffer, LPDWORD pcchBuffer)
86 {
87 return FALSE;
88 }
89
90 BOOL WINAPI
91 GetDefaultPrinterW(LPWSTR pszBuffer, LPDWORD pcchBuffer)
92 {
93 return FALSE;
94 }
95
96 BOOL WINAPI
97 GetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD pcbNeeded)
98 {
99 return FALSE;
100 }
101
102 BOOL WINAPI
103 GetPrinterDriverA(HANDLE hPrinter, LPSTR pEnvironment, DWORD Level, LPBYTE pDriverInfo, DWORD cbBuf, LPDWORD pcbNeeded)
104 {
105 return FALSE;
106 }
107
108 BOOL WINAPI
109 GetPrinterDriverW(HANDLE hPrinter, LPWSTR pEnvironment, DWORD Level, LPBYTE pDriverInfo, DWORD cbBuf, LPDWORD pcbNeeded)
110 {
111 return FALSE;
112 }
113
114 BOOL WINAPI
115 GetPrinterW(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD pcbNeeded)
116 {
117 return FALSE;
118 }
119
120 BOOL WINAPI
121 OpenPrinterA(LPSTR pPrinterName, LPHANDLE phPrinter, LPPRINTER_DEFAULTSA pDefault)
122 {
123 BOOL bReturnValue = FALSE;
124 PWSTR pwszPrinterName = NULL;
125 PWSTR pwszDatatype = NULL;
126 PRINTER_DEFAULTSW wDefault = { 0 };
127 size_t StringLength;
128
129 if (pPrinterName)
130 {
131 // Convert pPrinterName to a Unicode string pwszPrinterName
132 StringLength = strlen(pPrinterName) + 1;
133
134 pwszPrinterName = HeapAlloc(GetProcessHeap(), 0, StringLength * sizeof(WCHAR));
135 if (!pwszPrinterName)
136 {
137 ERR("HeapAlloc failed for pwszPrinterName with last error %lu!\n", GetLastError());
138 goto Cleanup;
139 }
140
141 MultiByteToWideChar(CP_ACP, 0, pPrinterName, -1, pwszPrinterName, StringLength);
142 }
143
144 if (pDefault)
145 {
146 wDefault.DesiredAccess = pDefault->DesiredAccess;
147
148 if (pDefault->pDatatype)
149 {
150 // Convert pDefault->pDatatype to a Unicode string pwszDatatype that later becomes wDefault.pDatatype
151 StringLength = strlen(pDefault->pDatatype) + 1;
152
153 pwszDatatype = HeapAlloc(GetProcessHeap(), 0, StringLength * sizeof(WCHAR));
154 if (!pwszDatatype)
155 {
156 ERR("HeapAlloc failed for pwszDatatype with last error %lu!\n", GetLastError());
157 goto Cleanup;
158 }
159
160 MultiByteToWideChar(CP_ACP, 0, pDefault->pDatatype, -1, pwszDatatype, StringLength);
161 wDefault.pDatatype = pwszDatatype;
162 }
163
164 if (pDefault->pDevMode)
165 wDefault.pDevMode = GdiConvertToDevmodeW(pDefault->pDevMode);
166 }
167
168 bReturnValue = OpenPrinterW(pwszPrinterName, phPrinter, &wDefault);
169
170 Cleanup:
171 if (wDefault.pDevMode)
172 HeapFree(GetProcessHeap(), 0, wDefault.pDevMode);
173
174 if (pwszPrinterName)
175 HeapFree(GetProcessHeap(), 0, pwszPrinterName);
176
177 if (pwszDatatype)
178 HeapFree(GetProcessHeap(), 0, pwszDatatype);
179
180 return bReturnValue;
181 }
182
183 BOOL WINAPI
184 OpenPrinterW(LPWSTR pPrinterName, LPHANDLE phPrinter, LPPRINTER_DEFAULTSW pDefault)
185 {
186 BOOL bReturnValue = FALSE;
187 DWORD dwErrorCode;
188 PWSTR pDatatype = NULL;
189 WINSPOOL_DEVMODE_CONTAINER DevModeContainer;
190 WINSPOOL_DEVMODE_CONTAINER* pDevModeContainer = NULL;
191 ACCESS_MASK AccessRequired = 0;
192
193 // Prepare the additional parameters in the format required by _RpcOpenPrinter
194 if (pDefault)
195 {
196 pDatatype = pDefault->pDatatype;
197 DevModeContainer.cbBuf = sizeof(DEVMODEW);
198 DevModeContainer.pDevMode = (BYTE*)pDefault->pDevMode;
199 pDevModeContainer = &DevModeContainer;
200 AccessRequired = pDefault->DesiredAccess;
201 }
202
203 // Do the RPC call
204 RpcTryExcept
205 {
206 dwErrorCode = _RpcOpenPrinter(pPrinterName, phPrinter, pDatatype, pDevModeContainer, AccessRequired);
207 if (dwErrorCode)
208 {
209 ERR("_RpcOpenPrinter failed with error %lu!\n", dwErrorCode);
210 }
211
212 bReturnValue = (dwErrorCode == ERROR_SUCCESS);
213 }
214 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
215 {
216 ERR("_RpcOpenPrinter failed with exception code %lu!\n", RpcExceptionCode());
217 }
218 RpcEndExcept;
219
220 return bReturnValue;
221 }
222
223 DWORD WINAPI
224 StartDocPrinterW(HANDLE hPrinter, DWORD Level, LPBYTE pDocInfo)
225 {
226 return 0;
227 }
228
229 BOOL WINAPI
230 StartPagePrinter(HANDLE hPrinter)
231 {
232 return FALSE;
233 }
234
235 BOOL WINAPI
236 WritePrinter(HANDLE hPrinter, LPVOID pBuf, DWORD cbBuf, LPDWORD pcWritten)
237 {
238 return FALSE;
239 }
240
241 BOOL WINAPI
242 XcvDataW(HANDLE hXcv, PCWSTR pszDataName, PBYTE pInputData, DWORD cbInputData, PBYTE pOutputData, DWORD cbOutputData, PDWORD pcbOutputNeeded, PDWORD pdwStatus)
243 {
244 return FALSE;
245 }