5a5493ca8616659b9e5fc37c679105418ce33d4e
[reactos.git] / reactos / win32ss / printing / base / winspool / printprocessors.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 Print Processors
5 * COPYRIGHT: Copyright 2015 Colin Finck <colin@reactos.org>
6 */
7
8 #include "precomp.h"
9
10 static void
11 _MarshallUpDatatypesInfo(PDATATYPES_INFO_1W pDatatypesInfo1)
12 {
13 // Replace relative offset addresses in the output by absolute pointers.
14 pDatatypesInfo1->pName = (PWSTR)((ULONG_PTR)pDatatypesInfo1->pName + (ULONG_PTR)pDatatypesInfo1);
15 }
16
17 static void
18 _MarshallUpPrintProcessorInfo(PPRINTPROCESSOR_INFO_1W pPrintProcessorInfo1)
19 {
20 // Replace relative offset addresses in the output by absolute pointers.
21 pPrintProcessorInfo1->pName = (PWSTR)((ULONG_PTR)pPrintProcessorInfo1->pName + (ULONG_PTR)pPrintProcessorInfo1);
22 }
23
24 BOOL WINAPI
25 EnumPrintProcessorDatatypesA(PSTR pName, LPSTR pPrintProcessorName, DWORD Level, PBYTE pDatatypes, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
26 {
27 return FALSE;
28 }
29
30 BOOL WINAPI
31 EnumPrintProcessorDatatypesW(PWSTR pName, LPWSTR pPrintProcessorName, DWORD Level, PBYTE pDatatypes, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
32 {
33 DWORD dwErrorCode;
34 DWORD i;
35 PBYTE p = pDatatypes;
36
37 // Do the RPC call
38 RpcTryExcept
39 {
40 dwErrorCode = _RpcEnumPrintProcessorDatatypes(pName, pPrintProcessorName, Level, pDatatypes, cbBuf, pcbNeeded, pcReturned);
41 }
42 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
43 {
44 dwErrorCode = RpcExceptionCode();
45 ERR("_RpcEnumPrintProcessorDatatypes failed with exception code %lu!\n", dwErrorCode);
46 }
47 RpcEndExcept;
48
49 if (dwErrorCode == ERROR_SUCCESS)
50 {
51 // Replace relative offset addresses in the output by absolute pointers.
52 for (i = 0; i < *pcReturned; i++)
53 {
54 _MarshallUpDatatypesInfo((PDATATYPES_INFO_1W)p);
55 p += sizeof(DATATYPES_INFO_1W);
56 }
57 }
58
59 SetLastError(dwErrorCode);
60 return (dwErrorCode == ERROR_SUCCESS);
61 }
62
63 BOOL WINAPI
64 EnumPrintProcessorsW(PWSTR pName, PWSTR pEnvironment, DWORD Level, PBYTE pPrintProcessorInfo, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
65 {
66 DWORD dwErrorCode;
67 DWORD i;
68 PBYTE p = pPrintProcessorInfo;
69
70 // Do the RPC call
71 RpcTryExcept
72 {
73 dwErrorCode = _RpcEnumPrintProcessors(pName, pEnvironment, Level, pPrintProcessorInfo, cbBuf, pcbNeeded, pcReturned);
74 }
75 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
76 {
77 dwErrorCode = RpcExceptionCode();
78 ERR("_RpcEnumPrintProcessors failed with exception code %lu!\n", dwErrorCode);
79 }
80 RpcEndExcept;
81
82 if (dwErrorCode == ERROR_SUCCESS)
83 {
84 // Replace relative offset addresses in the output by absolute pointers.
85 for (i = 0; i < *pcReturned; i++)
86 {
87 _MarshallUpPrintProcessorInfo((PPRINTPROCESSOR_INFO_1W)p);
88 p += sizeof(PRINTPROCESSOR_INFO_1W);
89 }
90 }
91
92 SetLastError(dwErrorCode);
93 return (dwErrorCode == ERROR_SUCCESS);
94 }
95
96 BOOL WINAPI
97 GetPrintProcessorDirectoryW(PWSTR pName, PWSTR pEnvironment, DWORD Level, PBYTE pPrintProcessorInfo, DWORD cbBuf, PDWORD pcbNeeded)
98 {
99 BOOL bReturnValue = FALSE;
100 DWORD dwErrorCode;
101
102 // Do the RPC call
103 RpcTryExcept
104 {
105 dwErrorCode = _RpcGetPrintProcessorDirectory(pName, pEnvironment, Level, pPrintProcessorInfo, cbBuf, pcbNeeded);
106 SetLastError(dwErrorCode);
107 bReturnValue = (dwErrorCode == ERROR_SUCCESS);
108 }
109 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
110 {
111 ERR("_RpcGetPrintProcessorDirectory failed with exception code %lu!\n", RpcExceptionCode());
112 }
113 RpcEndExcept;
114
115 return bReturnValue;
116 }