2 * PROJECT: ReactOS Spooler API
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Functions for managing print jobs
5 * COPYRIGHT: Copyright 2015-2018 Colin Finck (colin@reactos.org)
9 #include <marshalling/jobs.h>
12 AddJobA(HANDLE hPrinter
, DWORD Level
, PBYTE pData
, DWORD cbBuf
, PDWORD pcbNeeded
)
14 TRACE("AddJobA(%p, %lu, %p, %lu, %p)\n", hPrinter
, Level
, pData
, cbBuf
, pcbNeeded
);
20 AddJobW(HANDLE hPrinter
, DWORD Level
, PBYTE pData
, DWORD cbBuf
, PDWORD pcbNeeded
)
23 PSPOOLER_HANDLE pHandle
= (PSPOOLER_HANDLE
)hPrinter
;
25 TRACE("AddJobW(%p, %lu, %p, %lu, %p)\n", hPrinter
, Level
, pData
, cbBuf
, pcbNeeded
);
29 dwErrorCode
= ERROR_INVALID_HANDLE
;
36 dwErrorCode
= _RpcAddJob(pHandle
->hPrinter
, Level
, pData
, cbBuf
, pcbNeeded
);
38 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
40 dwErrorCode
= RpcExceptionCode();
41 ERR("_RpcAddJob failed with exception code %lu!\n", dwErrorCode
);
45 if (dwErrorCode
== ERROR_SUCCESS
)
47 // Replace relative offset addresses in the output by absolute pointers.
48 MarshallUpStructure(cbBuf
, pData
, AddJobInfo1Marshalling
.pInfo
, AddJobInfo1Marshalling
.cbStructureSize
, TRUE
);
52 SetLastError(dwErrorCode
);
53 return (dwErrorCode
== ERROR_SUCCESS
);
57 EnumJobsA(HANDLE hPrinter
, DWORD FirstJob
, DWORD NoJobs
, DWORD Level
, PBYTE pJob
, DWORD cbBuf
, PDWORD pcbNeeded
, PDWORD pcReturned
)
59 TRACE("EnumJobsA(%p, %lu, %lu, %lu, %p, %lu, %p, %p)\n", hPrinter
, FirstJob
, NoJobs
, Level
, pJob
, cbBuf
, pcbNeeded
, pcReturned
);
65 EnumJobsW(HANDLE hPrinter
, DWORD FirstJob
, DWORD NoJobs
, DWORD Level
, PBYTE pJob
, DWORD cbBuf
, PDWORD pcbNeeded
, PDWORD pcReturned
)
68 PSPOOLER_HANDLE pHandle
= (PSPOOLER_HANDLE
)hPrinter
;
70 TRACE("EnumJobsW(%p, %lu, %lu, %lu, %p, %lu, %p, %p)\n", hPrinter
, FirstJob
, NoJobs
, Level
, pJob
, cbBuf
, pcbNeeded
, pcReturned
);
74 dwErrorCode
= ERROR_INVALID_HANDLE
;
81 dwErrorCode
= _RpcEnumJobs(pHandle
->hPrinter
, FirstJob
, NoJobs
, Level
, pJob
, cbBuf
, pcbNeeded
, pcReturned
);
83 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
85 dwErrorCode
= RpcExceptionCode();
86 ERR("_RpcEnumJobs failed with exception code %lu!\n", dwErrorCode
);
90 if (dwErrorCode
== ERROR_SUCCESS
)
92 // Replace relative offset addresses in the output by absolute pointers for JOB_INFO_1W and JOB_INFO_2W.
96 MarshallUpStructuresArray(cbBuf
, pJob
, *pcReturned
, pJobInfoMarshalling
[Level
]->pInfo
, pJobInfoMarshalling
[Level
]->cbStructureSize
, TRUE
);
101 SetLastError(dwErrorCode
);
102 return (dwErrorCode
== ERROR_SUCCESS
);
106 GetJobA(HANDLE hPrinter
, DWORD JobId
, DWORD Level
, PBYTE pJob
, DWORD cbBuf
, PDWORD pcbNeeded
)
108 TRACE("GetJobA(%p, %lu, %lu, %p, %lu, %p)\n", hPrinter
, JobId
, Level
, pJob
, cbBuf
, pcbNeeded
);
114 GetJobW(HANDLE hPrinter
, DWORD JobId
, DWORD Level
, PBYTE pJob
, DWORD cbBuf
, PDWORD pcbNeeded
)
117 PSPOOLER_HANDLE pHandle
= (PSPOOLER_HANDLE
)hPrinter
;
119 TRACE("GetJobW(%p, %lu, %lu, %p, %lu, %p)\n", hPrinter
, JobId
, Level
, pJob
, cbBuf
, pcbNeeded
);
123 dwErrorCode
= ERROR_INVALID_HANDLE
;
130 dwErrorCode
= _RpcGetJob(pHandle
->hPrinter
, JobId
, Level
, pJob
, cbBuf
, pcbNeeded
);
132 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
134 dwErrorCode
= RpcExceptionCode();
135 ERR("_RpcGetJob failed with exception code %lu!\n", dwErrorCode
);
139 if (dwErrorCode
== ERROR_SUCCESS
)
141 // Replace relative offset addresses in the output by absolute pointers.
142 ASSERT(Level
>= 1 && Level
<= 2);
143 MarshallUpStructure(cbBuf
, pJob
, pJobInfoMarshalling
[Level
]->pInfo
, pJobInfoMarshalling
[Level
]->cbStructureSize
, TRUE
);
147 SetLastError(dwErrorCode
);
148 return (dwErrorCode
== ERROR_SUCCESS
);
152 ScheduleJob(HANDLE hPrinter
, DWORD dwJobID
)
155 PSPOOLER_HANDLE pHandle
= (PSPOOLER_HANDLE
)hPrinter
;
157 TRACE("ScheduleJob(%p, %lu)\n", hPrinter
, dwJobID
);
161 dwErrorCode
= ERROR_INVALID_HANDLE
;
168 dwErrorCode
= _RpcScheduleJob(pHandle
->hPrinter
, dwJobID
);
170 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
172 dwErrorCode
= RpcExceptionCode();
173 ERR("_RpcScheduleJob failed with exception code %lu!\n", dwErrorCode
);
178 SetLastError(dwErrorCode
);
179 return (dwErrorCode
== ERROR_SUCCESS
);
183 SetJobA(HANDLE hPrinter
, DWORD JobId
, DWORD Level
, PBYTE pJobInfo
, DWORD Command
)
185 TRACE("SetJobA(%p, %lu, %lu, %p, %lu)\n", hPrinter
, JobId
, Level
, pJobInfo
, Command
);
191 SetJobW(HANDLE hPrinter
, DWORD JobId
, DWORD Level
, PBYTE pJobInfo
, DWORD Command
)
194 PSPOOLER_HANDLE pHandle
= (PSPOOLER_HANDLE
)hPrinter
;
195 WINSPOOL_JOB_CONTAINER JobContainer
;
197 TRACE("SetJobW(%p, %lu, %lu, %p, %lu)\n", hPrinter
, JobId
, Level
, pJobInfo
, Command
);
201 dwErrorCode
= ERROR_INVALID_HANDLE
;
205 // pJobContainer->JobInfo is a union of pointers, so we can just set any element to our BYTE pointer.
206 JobContainer
.Level
= Level
;
207 JobContainer
.JobInfo
.Level1
= (WINSPOOL_JOB_INFO_1
*)pJobInfo
;
212 dwErrorCode
= _RpcSetJob(pHandle
->hPrinter
, JobId
, &JobContainer
, Command
);
214 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
216 dwErrorCode
= RpcExceptionCode();
217 ERR("_RpcSetJob failed with exception code %lu!\n", dwErrorCode
);
222 SetLastError(dwErrorCode
);
223 return (dwErrorCode
== ERROR_SUCCESS
);