ReactOS 0.4.16-dev-197-g92996da
spoolfile.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Spooler API
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Functions related to Spool Files and printing
5 * COPYRIGHT: Copyright 1998-2020 ReactOS
6 */
7
8#include "precomp.h"
9
10
13{
14 DWORD dwErrorCode, cpid;
15 WINSPOOL_FILE_INFO_CONTAINER FileInfoContainer;
17 PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
18 HANDLE hHandle = NULL;
19
20 FIXME("GetSpoolFileHandle(%p)\n", hPrinter);
21
22 if ( IntProtectHandle( hPrinter, FALSE ) )
23 {
24 dwErrorCode = ERROR_INVALID_HANDLE;
25 }
26 else
27 {
28 if ( pHandle->hSpoolFileHandle != INVALID_HANDLE_VALUE )
29 {
30 hHandle = pHandle->hSpoolFileHandle;
31 }
32 else
33 {
34 cpid = GetCurrentProcessId();
35
36 FileInfoContainer.Level = 1;
37 FileInfoContainer.FileInfo.pFileInfo1 = &wsplfi;
38
39 // Do the RPC call.
41 {
42 dwErrorCode = _RpcGetSpoolFileInfo2( &pHandle->hPrinter, cpid, 1, &FileInfoContainer );
43 }
45 {
46 dwErrorCode = RpcExceptionCode();
47 ERR("_RpcGetSpoolFileInfo failed with exception code %lu!\n", dwErrorCode);
48 }
50
51 if (dwErrorCode == ERROR_SUCCESS)
52 {
53 pHandle->hSpoolFileHandle = wsplfi.hSpoolFileHandle;
54 pHandle->dwOptions = wsplfi.dwOptions;
55 hHandle = pHandle->hSpoolFileHandle;
56 }
57 }
58 IntUnprotectHandle(pHandle);
59 }
60 SetLastError(dwErrorCode);
61 return hHandle;
62}
63
65CommitSpoolData( HANDLE hPrinter, HANDLE hSpoolFile, DWORD cbCommit )
66{
67 DWORD dwErrorCode, cpid;
68 WINSPOOL_FILE_INFO_CONTAINER FileInfoContainer;
70 PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
72
73 FIXME("CommitSpoolData(%p, %p, %d)\n", hPrinter,hSpoolFile,cbCommit);
74
75 if ( IntProtectHandle( hPrinter, FALSE ) )
76 {
77 return hHandle;
78 }
79
80 if ( pHandle->hSpoolFileHandle == INVALID_HANDLE_VALUE || pHandle->hSpoolFileHandle != hSpoolFile )
81 {
82 dwErrorCode = ERROR_INVALID_HANDLE;
83 }
84 else
85 {
86 cpid = GetCurrentProcessId();
87
88 FileInfoContainer.Level = 1;
89 FileInfoContainer.FileInfo.pFileInfo1 = &wsplfi;
90
91 // Do the RPC call.
93 {
94 dwErrorCode = _RpcCommitSpoolData2( &pHandle->hPrinter, cpid, cbCommit, 1, &FileInfoContainer );
95 }
97 {
98 dwErrorCode = RpcExceptionCode();
99 ERR("_RpcCommitSpoolData failed with exception code %lu!\n", dwErrorCode);
100 }
102
103 if (dwErrorCode == ERROR_SUCCESS)
104 {
106 {
107 CloseHandle( pHandle->hSpoolFileHandle );
108 pHandle->hSpoolFileHandle = wsplfi.hSpoolFileHandle;
109 }
110 hHandle = pHandle->hSpoolFileHandle;
111 }
112 IntUnprotectHandle(pHandle);
113 }
114 SetLastError(dwErrorCode);
115 return hHandle;
116}
117
119CloseSpoolFileHandle( HANDLE hPrinter, HANDLE hSpoolFile )
120{
121 DWORD dwErrorCode;
122 PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
123
124 FIXME("CloseSpoolFileHandle(%p, %p)\n", hPrinter,hSpoolFile);
125
126 if ( IntProtectHandle( hPrinter, FALSE ) )
127 {
128 return FALSE;
129 }
130 if ( pHandle->hSpoolFileHandle == hSpoolFile )
131 {
132 CloseHandle( pHandle->hSpoolFileHandle );
134
135 // Do the RPC call.
137 {
138 dwErrorCode = _RpcCloseSpoolFileHandle( &pHandle->hPrinter );
139 }
141 {
142 dwErrorCode = RpcExceptionCode();
143 ERR("_RpcloseSpoolFileHandle failed with exception code %lu!\n", dwErrorCode);
144 }
146 }
147 else
148 {
149 dwErrorCode = ERROR_INVALID_HANDLE;
150 }
151 IntUnprotectHandle(pHandle);
152 SetLastError(dwErrorCode);
153 return (dwErrorCode == ERROR_SUCCESS);
154}
#define FIXME(fmt,...)
Definition: precomp.h:53
#define ERR(fmt,...)
Definition: precomp.h:57
DWORD _RpcGetSpoolFileInfo2(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD dwProcessId, DWORD Level, WINSPOOL_FILE_INFO_CONTAINER *pFileInfoContainer)
Definition: spoolfile.c:49
DWORD _RpcCommitSpoolData2(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD dwProcessId, DWORD cbCommit, DWORD Level, WINSPOOL_FILE_INFO_CONTAINER *pFileInfoContainer)
Definition: spoolfile.c:77
DWORD _RpcCloseSpoolFileHandle(WINSPOOL_PRINTER_HANDLE hPrinter)
Definition: spoolfile.c:104
HANDLE WINAPI CommitSpoolData(HANDLE hPrinter, HANDLE hSpoolFile, DWORD cbCommit)
Definition: spoolfile.c:65
BOOL WINAPI CloseSpoolFileHandle(HANDLE hPrinter, HANDLE hSpoolFile)
Definition: spoolfile.c:119
HANDLE WINAPI GetSpoolFileHandle(HANDLE hPrinter)
Definition: spoolfile.c:12
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define SetLastError(x)
Definition: compat.h:752
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define RpcEndExcept
Definition: rpc.h:128
#define RpcTryExcept
Definition: rpc.h:126
#define RpcExcept(expr)
Definition: rpc.h:127
#define RpcExceptionCode()
Definition: rpc.h:132
HANDLE hSpoolFileHandle
Definition: precomp.h:53
DWORD dwOptions
Definition: precomp.h:54
HANDLE hPrinter
Definition: precomp.h:50
WINSPOOL_HANDLE hSpoolFileHandle
Definition: winspool.idl:840
union _WINSPOOL_FILE_INFO_CONTAINER::@3443 FileInfo
WINSPOOL_FILE_INFO_1 * pFileInfo1
Definition: winspool.idl:852
struct _SPOOLER_HANDLE * PSPOOLER_HANDLE
BOOL WINAPI IntUnprotectHandle(HANDLE)
Definition: utils.c:171
LONG WINAPI IntProtectHandle(HANDLE, BOOL)
Definition: utils.c:107
DWORD WINAPI GetCurrentProcessId(void)
Definition: proc.c:1158
#define WINAPI
Definition: msvc.h:6