2 * Print processor implementation.
4 * Copyright 2022 Piotr Caban for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 /* Missing datatypes support:
31 * Implement print processor features like e.g. printing multiple copies. */
37 #include "ddk/winsplp.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(winprint
);
43 #define PP_MAGIC 0x952173fd
53 static struct pp_data
* get_handle_data(HANDLE pp
)
55 struct pp_data
*ret
= (struct pp_data
*)pp
;
57 if (!ret
|| ret
->magic
!= PP_MAGIC
)
59 SetLastError(ERROR_INVALID_HANDLE
);
65 BOOL WINAPI
EnumPrintProcessorDatatypesW(WCHAR
*server
, WCHAR
*name
, DWORD level
,
66 BYTE
*datatypes
, DWORD size
, DWORD
*needed
, DWORD
*no
)
68 static const WCHAR raw
[] = L
"RAW";
70 DATATYPES_INFO_1W
*info
= (DATATYPES_INFO_1W
*)datatypes
;
72 TRACE("%s, %s, %ld, %p, %ld, %p, %p\n", debugstr_w(server
), debugstr_w(name
),
73 level
, datatypes
, size
, needed
, no
);
77 SetLastError(ERROR_INVALID_PARAMETER
);
82 *needed
= sizeof(*info
) + sizeof(raw
);
84 if (level
!= 1 || (size
&& !datatypes
))
86 SetLastError(ERROR_INVALID_PARAMETER
);
92 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
97 info
->pName
= (WCHAR
*)(info
+ 1);
98 memcpy(info
+ 1, raw
, sizeof(raw
));
102 HANDLE WINAPI
OpenPrintProcessor(WCHAR
*port
, PRINTPROCESSOROPENDATA
*open_data
)
104 struct pp_data
*data
;
107 TRACE("%s, %p\n", debugstr_w(port
), open_data
);
109 if (!port
|| !open_data
|| !open_data
->pDatatype
)
111 SetLastError(ERROR_INVALID_PARAMETER
);
114 if (wcscmp(open_data
->pDatatype
, L
"RAW"))
116 SetLastError(ERROR_INVALID_DATATYPE
);
120 if (!OpenPrinterW(port
, &hport
, NULL
))
123 data
= LocalAlloc(LMEM_FIXED
| LMEM_ZEROINIT
, sizeof(*data
));
126 data
->magic
= PP_MAGIC
;
128 data
->doc_name
= wcsdup(open_data
->pDocumentName
);
129 data
->out_file
= wcsdup(open_data
->pOutputFile
);
133 BOOL WINAPI
PrintDocumentOnPrintProcessor(HANDLE pp
, WCHAR
*doc_name
)
135 struct pp_data
*data
= get_handle_data(pp
);
141 TRACE("%p, %s\n", pp
, debugstr_w(doc_name
));
146 if (!OpenPrinterW(doc_name
, &spool_data
, NULL
))
149 info
.pDocName
= data
->doc_name
;
150 info
.pOutputFile
= data
->out_file
;
151 info
.pDatatype
= (WCHAR
*)L
"RAW";
152 if (!StartDocPrinterW(data
->hport
, 1, (BYTE
*)&info
))
154 ClosePrinter(spool_data
);
158 while (ReadPrinter(spool_data
, buf
, sizeof(buf
), &r
) && r
)
160 if (!WritePrinter(data
->hport
, buf
, r
, &w
) || r
!= w
)
162 ClosePrinter(spool_data
);
163 EndDocPrinter(data
->hport
);
167 ClosePrinter(spool_data
);
169 return EndDocPrinter(data
->hport
);
172 BOOL WINAPI
ControlPrintProcessor(HANDLE pp
, DWORD cmd
)
174 FIXME("%p, %ld\n", pp
, cmd
);
175 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
179 BOOL WINAPI
ClosePrintProcessor(HANDLE pp
)
181 struct pp_data
*data
= get_handle_data(pp
);
188 ClosePrinter(data
->hport
);
189 free(data
->doc_name
);
190 free(data
->out_file
);
192 memset(data
, 0, sizeof(*data
));
197 HRESULT WINAPI
DllRegisterServer(void)
199 AddPrintProcessorW(NULL
, (WCHAR
*)L
"Windows 4.0", (WCHAR
*)L
"winprint.dll", (WCHAR
*)L
"winprint");
200 AddPrintProcessorW(NULL
, NULL
, (WCHAR
*)L
"winprint.dll", (WCHAR
*)L
"winprint");