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-2016 Colin Finck <colin@reactos.org>
9 #include <prtprocenv.h>
12 _MarshallUpDatatypesInfo(PDATATYPES_INFO_1W pDatatypesInfo1
)
14 // Replace relative offset addresses in the output by absolute pointers.
15 pDatatypesInfo1
->pName
= (PWSTR
)((ULONG_PTR
)pDatatypesInfo1
->pName
+ (ULONG_PTR
)pDatatypesInfo1
);
19 _MarshallUpPrintProcessorInfo(PPRINTPROCESSOR_INFO_1W pPrintProcessorInfo1
)
21 // Replace relative offset addresses in the output by absolute pointers.
22 pPrintProcessorInfo1
->pName
= (PWSTR
)((ULONG_PTR
)pPrintProcessorInfo1
->pName
+ (ULONG_PTR
)pPrintProcessorInfo1
);
26 AddPrintProcessorW(PWSTR pName
, PWSTR pEnvironment
, PWSTR pPathName
, PWSTR pPrintProcessorName
)
33 DeletePrintProcessorW(PWSTR pName
, PWSTR pEnvironment
, PWSTR pPrintProcessorName
)
40 EnumPrintProcessorDatatypesA(PSTR pName
, LPSTR pPrintProcessorName
, DWORD Level
, PBYTE pDatatypes
, DWORD cbBuf
, PDWORD pcbNeeded
, PDWORD pcReturned
)
47 EnumPrintProcessorDatatypesW(PWSTR pName
, LPWSTR pPrintProcessorName
, DWORD Level
, PBYTE pDatatypes
, DWORD cbBuf
, PDWORD pcbNeeded
, PDWORD pcReturned
)
56 dwErrorCode
= _RpcEnumPrintProcessorDatatypes(pName
, pPrintProcessorName
, Level
, pDatatypes
, cbBuf
, pcbNeeded
, pcReturned
);
58 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
60 dwErrorCode
= RpcExceptionCode();
61 ERR("_RpcEnumPrintProcessorDatatypes failed with exception code %lu!\n", dwErrorCode
);
65 if (dwErrorCode
== ERROR_SUCCESS
)
67 // Replace relative offset addresses in the output by absolute pointers.
68 for (i
= 0; i
< *pcReturned
; i
++)
70 _MarshallUpDatatypesInfo((PDATATYPES_INFO_1W
)p
);
71 p
+= sizeof(DATATYPES_INFO_1W
);
75 SetLastError(dwErrorCode
);
76 return (dwErrorCode
== ERROR_SUCCESS
);
80 EnumPrintProcessorsW(PWSTR pName
, PWSTR pEnvironment
, DWORD Level
, PBYTE pPrintProcessorInfo
, DWORD cbBuf
, PDWORD pcbNeeded
, PDWORD pcReturned
)
84 PBYTE p
= pPrintProcessorInfo
;
86 // Choose our current environment if the caller didn't give any.
88 pEnvironment
= (PWSTR
)wszCurrentEnvironment
;
93 dwErrorCode
= _RpcEnumPrintProcessors(pName
, pEnvironment
, Level
, pPrintProcessorInfo
, cbBuf
, pcbNeeded
, pcReturned
);
95 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
97 dwErrorCode
= RpcExceptionCode();
101 if (dwErrorCode
== ERROR_SUCCESS
)
103 // Replace relative offset addresses in the output by absolute pointers.
104 for (i
= 0; i
< *pcReturned
; i
++)
106 _MarshallUpPrintProcessorInfo((PPRINTPROCESSOR_INFO_1W
)p
);
107 p
+= sizeof(PRINTPROCESSOR_INFO_1W
);
111 SetLastError(dwErrorCode
);
112 return (dwErrorCode
== ERROR_SUCCESS
);
116 GetPrintProcessorDirectoryA(PSTR pName
, PSTR pEnvironment
, DWORD Level
, PBYTE pPrintProcessorInfo
, DWORD cbBuf
, PDWORD pcbNeeded
)
118 BOOL bReturnValue
= FALSE
;
120 PWSTR pwszName
= NULL
;
121 PWSTR pwszEnvironment
= NULL
;
122 PWSTR pwszPrintProcessorInfo
= NULL
;
126 // Convert pName to a Unicode string pwszName.
129 pwszName
= HeapAlloc(hProcessHeap
, 0, (cch
+ 1) * sizeof(WCHAR
));
132 ERR("HeapAlloc failed for pwszName with last error %lu!\n", GetLastError());
136 MultiByteToWideChar(CP_ACP
, 0, pName
, -1, pwszName
, cch
+ 1);
141 // Convert pEnvironment to a Unicode string pwszEnvironment.
142 cch
= strlen(pEnvironment
);
144 pwszEnvironment
= HeapAlloc(hProcessHeap
, 0, (cch
+ 1) * sizeof(WCHAR
));
145 if (!pwszEnvironment
)
147 ERR("HeapAlloc failed for pwszEnvironment with last error %lu!\n", GetLastError());
151 MultiByteToWideChar(CP_ACP
, 0, pEnvironment
, -1, pwszEnvironment
, cch
+ 1);
154 if (cbBuf
&& pPrintProcessorInfo
)
156 // Allocate a temporary buffer for the Unicode result.
157 // We can just go with cbBuf here. The user should have set it based on pcbNeeded returned in a previous call and our
158 // pcbNeeded is the same for the A and W functions.
159 pwszPrintProcessorInfo
= HeapAlloc(hProcessHeap
, 0, cbBuf
);
160 if (!pwszPrintProcessorInfo
)
162 ERR("HeapAlloc failed for pwszPrintProcessorInfo with last error %lu!\n", GetLastError());
167 bReturnValue
= GetPrintProcessorDirectoryW(pwszName
, pwszEnvironment
, Level
, (PBYTE
)pwszPrintProcessorInfo
, cbBuf
, pcbNeeded
);
171 // Convert pwszPrintProcessorInfo to an ANSI string pPrintProcessorInfo.
172 WideCharToMultiByte(CP_ACP
, 0, pwszPrintProcessorInfo
, -1, (PSTR
)pPrintProcessorInfo
, cbBuf
, NULL
, NULL
);
177 HeapFree(hProcessHeap
, 0, pwszName
);
180 HeapFree(hProcessHeap
, 0, pwszEnvironment
);
182 if (pwszPrintProcessorInfo
)
183 HeapFree(hProcessHeap
, 0, pwszPrintProcessorInfo
);
189 GetPrintProcessorDirectoryW(PWSTR pName
, PWSTR pEnvironment
, DWORD Level
, PBYTE pPrintProcessorInfo
, DWORD cbBuf
, PDWORD pcbNeeded
)
196 dwErrorCode
= ERROR_INVALID_LEVEL
;
200 // Choose our current environment if the caller didn't give any.
202 pEnvironment
= (PWSTR
)wszCurrentEnvironment
;
207 dwErrorCode
= _RpcGetPrintProcessorDirectory(pName
, pEnvironment
, Level
, pPrintProcessorInfo
, cbBuf
, pcbNeeded
);
209 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
211 dwErrorCode
= RpcExceptionCode();
216 SetLastError(dwErrorCode
);
217 return (dwErrorCode
== ERROR_SUCCESS
);