ReactOS 0.4.15-dev-8131-g4988de4
main.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Standard Print Processor
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Main functions
5 * COPYRIGHT: Copyright 2015-2017 Colin Finck (colin@reactos.org)
6 */
7
8#include "precomp.h"
9
10// Local Constants
12 L"RAW",
13 0
14};
15
16
31{
32 DWORD dwErrorCode;
33 PWINPRINT_HANDLE pHandle;
34
35 TRACE("ClosePrintProcessor(%p)\n", hPrintProcessor);
36
37 // Sanity checks
38 if (!hPrintProcessor)
39 {
40 dwErrorCode = ERROR_INVALID_HANDLE;
41 goto Cleanup;
42 }
43
44 pHandle = (PWINPRINT_HANDLE)hPrintProcessor;
45
46 // Free all structure fields for which memory has been allocated.
47 if (pHandle->pwszDatatype)
49
50 if (pHandle->pwszDocumentName)
52
53 if (pHandle->pwszOutputFile)
55
56 if (pHandle->pwszPrinterPort)
58
59 // Finally free the WINSPOOL_HANDLE structure itself.
60 DllFreeSplMem(pHandle);
61 dwErrorCode = ERROR_SUCCESS;
62
64 SetLastError(dwErrorCode);
65 return (dwErrorCode == ERROR_SUCCESS);
66}
67
70{
71 TRACE("ControlPrintProcessor(%p, %lu)\n", hPrintProcessor, Command);
72
74 return FALSE;
75}
76
111EnumPrintProcessorDatatypesW(PWSTR pName, PWSTR pPrintProcessorName, DWORD Level, PBYTE pDatatypes, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
112{
113 DWORD cbDatatype;
114 DWORD dwDatatypeCount = 0;
115 DWORD dwOffsets[_countof(_pwszDatatypes)];
116 PCWSTR* pCurrentDatatype;
117 PDWORD pCurrentOffset = dwOffsets;
118
119 TRACE("EnumPrintProcessorDatatypesW(%S, %S, %lu, %p, %lu, %p, %p)\n", pName, pPrintProcessorName, Level, pDatatypes, cbBuf, pcbNeeded, pcReturned);
120
121 // Sanity checks
122 if (Level != 1 || !pcbNeeded || !pcReturned)
123 return FALSE;
124
125 // Count the required buffer size and the number of datatypes.
126 *pcbNeeded = 0;
127 *pcReturned = 0;
128
129 for (pCurrentDatatype = _pwszDatatypes; *pCurrentDatatype; pCurrentDatatype++)
130 {
131 cbDatatype = (wcslen(*pCurrentDatatype) + 1) * sizeof(WCHAR);
132 *pcbNeeded += sizeof(DATATYPES_INFO_1W) + cbDatatype;
133
134 // Also calculate the offset in the output buffer of the pointer to this datatype string.
135 *pCurrentOffset = dwDatatypeCount * sizeof(DATATYPES_INFO_1W) + FIELD_OFFSET(DATATYPES_INFO_1W, pName);
136
137 dwDatatypeCount++;
138 pCurrentOffset++;
139 }
140
141 // Check if the supplied buffer is large enough.
142 if (cbBuf < *pcbNeeded)
143 {
145 return FALSE;
146 }
147
148 // Check if a buffer was supplied at all.
149 if (!pDatatypes)
150 {
152 return FALSE;
153 }
154
155 // Copy over all datatypes.
156 *pCurrentOffset = MAXDWORD;
157 PackStrings(_pwszDatatypes, pDatatypes, dwOffsets, &pDatatypes[*pcbNeeded]);
158
159 *pcReturned = dwDatatypeCount;
160 return TRUE;
161}
162
163
166{
167 TRACE("GetPrintProcessorCapabilities(%S, %lu, %p, %lu, %p)\n", pValueName, dwAttributes, pData, nSize, pcbNeeded);
168
170 return 0;
171}
172
189OpenPrintProcessor(PWSTR pPrinterName, PPRINTPROCESSOROPENDATA pPrintProcessorOpenData)
190{
191 DWORD dwErrorCode;
192 HANDLE hReturnValue = NULL;
193 PWINPRINT_HANDLE pHandle = NULL;
194
195 TRACE("OpenPrintProcessor(%S, %p)\n", pPrinterName, pPrintProcessorOpenData);
196
197 // Sanity checks
198 // This time a datatype needs to be given. We can't fall back to a default here.
199 if (!pPrintProcessorOpenData || !pPrintProcessorOpenData->pDatatype || !*pPrintProcessorOpenData->pDatatype)
200 {
201 dwErrorCode = ERROR_INVALID_PARAMETER;
202 goto Cleanup;
203 }
204
205 // Create a new WINPRINT_HANDLE structure and fill the relevant fields.
206 pHandle = DllAllocSplMem(sizeof(WINPRINT_HANDLE));
207
208 // Check what datatype was given.
209 if (wcsicmp(pPrintProcessorOpenData->pDatatype, L"RAW") == 0)
210 {
211 pHandle->Datatype = RAW;
212 }
213 else
214 {
215 dwErrorCode = ERROR_INVALID_DATATYPE;
216 goto Cleanup;
217 }
218
219 // Fill the relevant fields.
220 pHandle->dwJobID = pPrintProcessorOpenData->JobId;
221 pHandle->pwszDatatype = AllocSplStr(pPrintProcessorOpenData->pDatatype);
222 pHandle->pwszDocumentName = AllocSplStr(pPrintProcessorOpenData->pDocumentName);
223 pHandle->pwszOutputFile = AllocSplStr(pPrintProcessorOpenData->pOutputFile);
224 pHandle->pwszPrinterPort = AllocSplStr(pPrinterName);
225
226 // We were successful! Return the handle and don't let the cleanup routine free it.
227 dwErrorCode = ERROR_SUCCESS;
228 hReturnValue = pHandle;
229 pHandle = NULL;
230
231Cleanup:
232 if (pHandle)
233 DllFreeSplMem(pHandle);
234
235 SetLastError(dwErrorCode);
236 return hReturnValue;
237}
238
255PrintDocumentOnPrintProcessor(HANDLE hPrintProcessor, PWSTR pDocumentName)
256{
257 DWORD dwErrorCode;
258 PWINPRINT_HANDLE pHandle;
259
260 TRACE("PrintDocumentOnPrintProcessor(%p, %S)\n", hPrintProcessor, pDocumentName);
261
262 // Sanity checks
263 if (!hPrintProcessor)
264 {
265 dwErrorCode = ERROR_INVALID_HANDLE;
266 goto Cleanup;
267 }
268
269 pHandle = (PWINPRINT_HANDLE)hPrintProcessor;
270
271 // Call the corresponding Print function for the datatype.
272 if (pHandle->Datatype == RAW)
273 dwErrorCode = PrintRawJob(pHandle, pDocumentName);
274
275Cleanup:
276 SetLastError(dwErrorCode);
277 return (dwErrorCode == ERROR_SUCCESS);
278}
PBYTE WINAPI PackStrings(PCWSTR *pSource, PBYTE pDest, const DWORD *DestOffsets, PBYTE pEnd)
Definition: tools.c:39
#define UNIMPLEMENTED
Definition: debug.h:118
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
#define wcsicmp
Definition: compat.h:15
static const WCHAR Cleanup[]
Definition: register.c:80
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define RAW(x)
Definition: genincdata.c:42
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
static LPSTR pName
Definition: security.c:75
#define MAXDWORD
#define L(x)
Definition: ntvdm.h:50
BYTE * PBYTE
Definition: pedump.c:66
DWORD * PDWORD
Definition: pedump.c:68
#define _countof(array)
Definition: sndvol32.h:70
#define TRACE(s)
Definition: solgame.cpp:4
Definition: shell.h:41
enum _WINPRINT_HANDLE::@5128 Datatype
PWSTR pwszOutputFile
Definition: precomp.h:32
PWSTR pwszPrinterPort
Definition: precomp.h:33
PWSTR pwszDocumentName
Definition: precomp.h:31
PWSTR pwszDatatype
Definition: precomp.h:30
DWORD dwJobID
Definition: precomp.h:29
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830
uint16_t * PWSTR
Definition: typedefs.h:56
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
DWORD dwAttributes
Definition: vdmdbg.h:34
BOOL WINAPI DllFreeSplMem(PVOID pMem)
Definition: memory.c:112
PVOID WINAPI DllAllocSplMem(DWORD dwBytes)
Definition: memory.c:95
BOOL WINAPI DllFreeSplStr(PWSTR pwszString)
Definition: memory.c:130
PWSTR WINAPI AllocSplStr(PCWSTR pwszInput)
Definition: memory.c:56
BOOL WINAPI EnumPrintProcessorDatatypesW(PWSTR pName, PWSTR pPrintProcessorName, DWORD Level, PBYTE pDatatypes, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
Definition: main.c:111
static PCWSTR _pwszDatatypes[]
Definition: main.c:11
BOOL WINAPI PrintDocumentOnPrintProcessor(HANDLE hPrintProcessor, PWSTR pDocumentName)
Definition: main.c:255
BOOL WINAPI ControlPrintProcessor(HANDLE hPrintProcessor, DWORD Command)
Definition: main.c:69
HANDLE WINAPI OpenPrintProcessor(PWSTR pPrinterName, PPRINTPROCESSOROPENDATA pPrintProcessorOpenData)
Definition: main.c:189
BOOL WINAPI ClosePrintProcessor(HANDLE hPrintProcessor)
Definition: main.c:30
DWORD WINAPI GetPrintProcessorCapabilities(PWSTR pValueName, DWORD dwAttributes, PBYTE pData, DWORD nSize, PDWORD pcbNeeded)
Definition: main.c:165
DWORD PrintRawJob(PWINPRINT_HANDLE pHandle, PWSTR pwszPrinterAndJob)
Definition: raw.c:23
struct _WINPRINT_HANDLE * PWINPRINT_HANDLE
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2084
_In_ DWORD _Out_ PDWORD pcbNeeded
Definition: winddi.h:3828
#define WINAPI
Definition: msvc.h:6
#define ERROR_INVALID_DATATYPE
Definition: winerror.h:1111
struct _DATATYPES_INFO_1W DATATYPES_INFO_1W
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:56
__wchar_t WCHAR
Definition: xmlstorage.h:180