2 * PROJECT: ReactOS Standard Print Processor
3 * LICENSE: GNU LGPL v2.1 or any later version as published by the Free Software Foundation
4 * PURPOSE: Main functions
5 * COPYRIGHT: Copyright 2015 Colin Finck <colin@reactos.org>
11 static PCWSTR _pwszDatatypes
[] = {
18 * @name ClosePrintProcessor
20 * Closes a Print Processor Handle that has previously been opened through OpenPrintProcessor.
22 * @param hPrintProcessor
23 * The return value of a previous successful OpenPrintProcessor call.
26 * TRUE if the Print Processor Handle was successfully closed, FALSE otherwise.
27 * A more specific error code can be obtained through GetLastError.
30 ClosePrintProcessor(HANDLE hPrintProcessor
)
33 PWINPRINT_HANDLE pHandle
;
38 dwErrorCode
= ERROR_INVALID_HANDLE
;
42 pHandle
= (PWINPRINT_HANDLE
)hPrintProcessor
;
44 // Free all structure fields for which memory has been allocated.
45 if (pHandle
->pwszDatatype
)
46 DllFreeSplStr(pHandle
->pwszDatatype
);
48 if (pHandle
->pwszDocumentName
)
49 DllFreeSplStr(pHandle
->pwszDocumentName
);
51 if (pHandle
->pwszOutputFile
)
52 DllFreeSplStr(pHandle
->pwszOutputFile
);
54 if (pHandle
->pwszPrinterPort
)
55 DllFreeSplStr(pHandle
->pwszPrinterPort
);
57 // Finally free the WINSPOOL_HANDLE structure itself.
58 DllFreeSplMem(pHandle
);
59 dwErrorCode
= ERROR_SUCCESS
;
62 SetLastError(dwErrorCode
);
63 return (dwErrorCode
== ERROR_SUCCESS
);
67 ControlPrintProcessor(HANDLE hPrintProcessor
, DWORD Command
)
74 * @name EnumPrintProcessorDatatypesW
76 * Obtains an array of all datatypes supported by this Print Processor.
79 * Server Name. Ignored here, because every caller of EnumPrintProcessorDatatypesW is interested in this Print Processor's information.
81 * @param pPrintProcessorName
82 * Print Processor Name. Ignored here, because every caller of EnumPrintProcessorDatatypesW is interested in this Print Processor's information.
85 * The level of the structure supplied through pDatatypes. This must be 1.
88 * Pointer to the buffer that receives an array of DATATYPES_INFO_1W structures.
89 * Can be NULL if you just want to know the required size of the buffer.
92 * Size of the buffer you supplied for pDatatypes, in bytes.
95 * Pointer to a variable that receives the required size of the buffer for pDatatypes, in bytes.
96 * This parameter mustn't be NULL!
99 * Pointer to a variable that receives the number of elements of the DATATYPES_INFO_1W array.
100 * This parameter mustn't be NULL!
103 * TRUE if we successfully copied the array into pDatatypes, FALSE otherwise.
104 * A more specific error code can be obtained through GetLastError.
107 EnumPrintProcessorDatatypesW(LPWSTR pName
, LPWSTR pPrintProcessorName
, DWORD Level
, LPBYTE pDatatypes
, DWORD cbBuf
, LPDWORD pcbNeeded
, LPDWORD pcReturned
)
111 DWORD dwOffsets
[_countof(_pwszDatatypes
)];
112 PCWSTR
* pCurrentDatatype
;
113 PDWORD pCurrentOffset
= dwOffsets
;
116 if (Level
!= 1 || !pcbNeeded
|| !pcReturned
)
118 dwErrorCode
= ERROR_INVALID_PARAMETER
;
122 // Count the required buffer size and the number of datatypes.
126 for (pCurrentDatatype
= _pwszDatatypes
; *pCurrentDatatype
; pCurrentDatatype
++)
128 cbDatatype
= (wcslen(*pCurrentDatatype
) + 1) * sizeof(WCHAR
);
129 *pcbNeeded
+= sizeof(DATATYPES_INFO_1W
) + cbDatatype
;
131 // Also calculate the offset in the output buffer of the pointer to this datatype string.
132 *pCurrentOffset
= *pcReturned
* sizeof(DATATYPES_INFO_1W
) + FIELD_OFFSET(DATATYPES_INFO_1W
, pName
);
138 // Check if the supplied buffer is large enough.
139 if (cbBuf
< *pcbNeeded
)
141 dwErrorCode
= ERROR_INSUFFICIENT_BUFFER
;
145 // Check if a buffer was supplied at all.
148 dwErrorCode
= ERROR_INVALID_PARAMETER
;
152 // Copy over all datatypes.
153 *pCurrentOffset
= MAXDWORD
;
154 PackStrings(_pwszDatatypes
, pDatatypes
, dwOffsets
, &pDatatypes
[*pcbNeeded
]);
156 dwErrorCode
= ERROR_SUCCESS
;
159 SetLastError(dwErrorCode
);
160 return (dwErrorCode
== ERROR_SUCCESS
);
165 GetPrintProcessorCapabilities(PWSTR pValueName
, DWORD dwAttributes
, PBYTE pData
, DWORD nSize
, PDWORD pcbNeeded
)
172 * @name OpenPrintProcessor
174 * Prepares this Print Processor for processing a document.
176 * @param pPrinterName
177 * String in the format "\\COMPUTERNAME\Port:, Port" that is passed to OpenPrinterW for writing to the Print Monitor on the specified port.
179 * @param pPrintProcessorOpenData
180 * Pointer to a PRINTPROCESSOROPENDATA structure containing details about the print job to be processed.
183 * A Print Processor handle on success or NULL in case of a failure. This handle has to be passed to PrintDocumentOnPrintProcessor to do the actual processing.
184 * A more specific error code can be obtained through GetLastError.
187 OpenPrintProcessor(PWSTR pPrinterName
, PPRINTPROCESSOROPENDATA pPrintProcessorOpenData
)
190 HANDLE hReturnValue
= NULL
;
191 PWINPRINT_HANDLE pHandle
= NULL
;
194 // This time a datatype needs to be given. We can't fall back to a default here.
195 if (!pPrintProcessorOpenData
|| !pPrintProcessorOpenData
->pDatatype
|| !*pPrintProcessorOpenData
->pDatatype
)
197 dwErrorCode
= ERROR_INVALID_PARAMETER
;
201 // Create a new WINPRINT_HANDLE structure. and fill the relevant fields.
202 pHandle
= DllAllocSplMem(sizeof(WINPRINT_HANDLE
));
204 // Check what datatype was given.
205 if (wcsicmp(pPrintProcessorOpenData
->pDatatype
, L
"RAW") == 0)
207 pHandle
->Datatype
= RAW
;
211 dwErrorCode
= ERROR_INVALID_DATATYPE
;
215 // Fill the relevant fields.
216 pHandle
->dwJobID
= pPrintProcessorOpenData
->JobId
;
217 pHandle
->pwszDatatype
= AllocSplStr(pPrintProcessorOpenData
->pDatatype
);
218 pHandle
->pwszDocumentName
= AllocSplStr(pPrintProcessorOpenData
->pDocumentName
);
219 pHandle
->pwszOutputFile
= AllocSplStr(pPrintProcessorOpenData
->pOutputFile
);
220 pHandle
->pwszPrinterPort
= AllocSplStr(pPrintProcessorOpenData
->pPrinterName
);
222 // We were successful! Return the handle and don't let the cleanup routine free it.
223 dwErrorCode
= ERROR_SUCCESS
;
224 hReturnValue
= pHandle
;
229 DllFreeSplMem(pHandle
);
231 SetLastError(dwErrorCode
);
236 * @name PrintDocumentOnPrintProcessor
238 * Prints a document on this Print Processor after a handle for the document has been opened through OpenPrintProcessor.
240 * @param hPrintProcessor
241 * The return value of a previous successful OpenPrintProcessor call.
243 * @param pDocumentName
244 * String in the format "Printer, Job N" describing the spooled job that is to be processed.
247 * TRUE if the document was successfully processed by this Print Processor, FALSE otherwise.
248 * A more specific error code can be obtained through GetLastError.
251 PrintDocumentOnPrintProcessor(HANDLE hPrintProcessor
, PWSTR pDocumentName
)
254 PWINPRINT_HANDLE pHandle
;
257 if (!hPrintProcessor
)
259 dwErrorCode
= ERROR_INVALID_HANDLE
;
263 pHandle
= (PWINPRINT_HANDLE
)hPrintProcessor
;
265 // Call the corresponding Print function for the datatype.
266 if (pHandle
->Datatype
== RAW
)
267 dwErrorCode
= PrintRawJob(pHandle
, pDocumentName
);
270 SetLastError(dwErrorCode
);
271 return (dwErrorCode
== ERROR_SUCCESS
);