[PRINTING]
[reactos.git] / reactos / win32ss / printing / processors / winprint / main.c
1 /*
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>
6 */
7
8 #include "precomp.h"
9
10 PCWSTR pwszDatatypes[] = {
11 L"RAW",
12 0
13 };
14
15 /**
16 * @name EnumPrintProcessorDatatypesW
17 *
18 * Obtains an array of all datatypes supported by this Print Processor.
19 *
20 * @param pName
21 * Server Name. Ignored here, because every caller of EnumPrintProcessorDatatypesW is interested in this Print Processor's information.
22 *
23 * @param pPrintProcessorName
24 * Print Processor Name. Ignored here, because every caller of EnumPrintProcessorDatatypesW is interested in this Print Processor's information.
25 *
26 * @param Level
27 * The level of the structure supplied through pDatatypes. This must be 1.
28 *
29 * @param pDatatypes
30 * Pointer to the buffer that receives an array of DATATYPES_INFO_1W structures.
31 * Can be NULL if you just want to know the required size of the buffer.
32 *
33 * @param cbBuf
34 * Size of the buffer you supplied for pDatatypes, in bytes.
35 *
36 * @param pcbNeeded
37 * Pointer to a variable that receives the required size of the buffer for pDatatypes, in bytes.
38 * This parameter mustn't be NULL!
39 *
40 * @param pcReturned
41 * Pointer to a variable that receives the number of elements of the DATATYPES_INFO_1W array.
42 * This parameter mustn't be NULL!
43 *
44 * @return
45 * TRUE if we successfully copied the array into pDatatypes, FALSE otherwise.
46 * A more specific error code can be obtained through GetLastError.
47 */
48 BOOL WINAPI
49 EnumPrintProcessorDatatypesW(LPWSTR pName, LPWSTR pPrintProcessorName, DWORD Level, LPBYTE pDatatypes, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned)
50 {
51 DWORD cbDatatype;
52 DWORD dwOffsets[_countof(pwszDatatypes)];
53 PCWSTR* pCurrentDatatype;
54 PDWORD pCurrentOffset = dwOffsets;
55
56 // Sanity checks
57 if (Level != 1 || !pcbNeeded || !pcReturned)
58 return FALSE;
59
60 // Count the required buffer size and the number of datatypes.
61 *pcbNeeded = 0;
62 *pcReturned = 0;
63
64 for (pCurrentDatatype = pwszDatatypes; *pCurrentDatatype; pCurrentDatatype++)
65 {
66 cbDatatype = (wcslen(*pCurrentDatatype) + 1) * sizeof(WCHAR);
67 *pcbNeeded += sizeof(DATATYPES_INFO_1W) + cbDatatype;
68
69 // Also calculate the offset in the output buffer of the pointer to this datatype string.
70 *pCurrentOffset = *pcReturned * sizeof(DATATYPES_INFO_1W) + FIELD_OFFSET(DATATYPES_INFO_1W, pName);
71
72 *pcReturned++;
73 pCurrentOffset++;
74 }
75
76 // Check if the supplied buffer is large enough.
77 if (cbBuf < *pcbNeeded)
78 {
79 SetLastError(ERROR_INSUFFICIENT_BUFFER);
80 return FALSE;
81 }
82
83 // Check if a buffer was supplied at all.
84 if (!pDatatypes)
85 {
86 SetLastError(ERROR_INVALID_PARAMETER);
87 return FALSE;
88 }
89
90 // Copy over all datatypes.
91 *pCurrentOffset = MAXDWORD;
92 PackStrings(pwszDatatypes, pDatatypes, dwOffsets, &pDatatypes[*pcbNeeded]);
93
94 return TRUE;
95 }