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