ReactOS 0.4.15-dev-5669-g09dde2c
main.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <windows.h>
3
5{
6 wprintf(L"Usage: %s testfile\n", name);
7}
8
9int wmain(int argc, WCHAR* argv[])
10{
11 int ReturnValue = 1;
13 DWORD dwRead, dwWritten;
15 HANDLE hPrinter = NULL;
16 DOC_INFO_1W docInfo;
17 BYTE Buffer[4096];
18
19 if (argc <= 1)
20 {
21 Usage(argv[0]);
22 return 0;
23 }
24
27 {
28 printf("CreateFileW failed, last error is %lu!\n", GetLastError());
29 goto Cleanup;
30 }
31
34 {
35 printf("File is too big, or GetFileSize failed; last error is %lu!\n", GetLastError());
36 goto Cleanup;
37 }
38
39 if (!OpenPrinterW(L"Dummy Printer On LPT1", &hPrinter, NULL))
40 {
41 printf("OpenPrinterW failed, last error is %lu!\n", GetLastError());
42 goto Cleanup;
43 }
44
45 /* Print to a printer, with the "RAW" datatype (pDatatype == NULL or "RAW") */
46 ZeroMemory(&docInfo, sizeof(docInfo));
47 docInfo.pDocName = L"winspool_print";
48
49 if (!StartDocPrinterW(hPrinter, 1, (LPBYTE)&docInfo))
50 {
51 printf("StartDocPrinterW failed, last error is %lu!\n", GetLastError());
52 goto Cleanup;
53 }
54
55 if (!StartPagePrinter(hPrinter))
56 {
57 printf("StartPagePrinter failed, last error is %lu!\n", GetLastError());
58 goto Cleanup;
59 }
60
61 while (dwFileSize > 0)
62 {
63 dwRead = min(sizeof(Buffer), dwFileSize);
64 if (!ReadFile(hFile, Buffer, dwRead, &dwRead, NULL))
65 {
66 printf("ReadFile failed, last error is %lu!\n", GetLastError());
67 goto Cleanup;
68 }
69 dwFileSize -= dwRead;
70
71 if (!WritePrinter(hPrinter, Buffer, dwRead, &dwWritten))
72 {
73 printf("WritePrinter failed, last error is %lu!\n", GetLastError());
74 goto Cleanup;
75 }
76 }
77
78 if (!EndPagePrinter(hPrinter))
79 {
80 printf("EndPagePrinter failed, last error is %lu!\n", GetLastError());
81 goto Cleanup;
82 }
83
84 if (!EndDocPrinter(hPrinter))
85 {
86 printf("EndDocPrinter failed, last error is %lu!\n", GetLastError());
87 goto Cleanup;
88 }
89
90 ReturnValue = 0;
91
93 if (hPrinter)
94 ClosePrinter(hPrinter);
95
98
99 return ReturnValue;
100}
static int argc
Definition: ServiceArgs.c:12
UINT32 void void ** ReturnValue
Definition: acevents.h:216
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define CreateFileW
Definition: compat.h:741
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
static const WCHAR Cleanup[]
Definition: register.c:80
unsigned long DWORD
Definition: ntddk_ex.h:95
#define printf
Definition: freeldr.h:94
_Must_inspect_result_ _In_ USAGE _In_ USHORT _In_ USAGE Usage
Definition: hidpi.h:384
#define min(a, b)
Definition: monoChain.cc:55
DWORD dwFileSize
Definition: more.c:40
#define argv
Definition: mplay32.c:18
_In_ HANDLE hFile
Definition: mswsock.h:90
#define L(x)
Definition: ntvdm.h:50
int wmain()
LPWSTR pDocName
Definition: winspool.h:616
Definition: name.c:39
unsigned char * LPBYTE
Definition: typedefs.h:53
#define wprintf(...)
Definition: whoami.c:18
#define ZeroMemory
Definition: winbase.h:1670
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
#define INVALID_FILE_SIZE
Definition: winbase.h:548
WINBOOL WINAPI EndPagePrinter(HANDLE hPrinter)
Definition: printers.c:232
DWORD WINAPI StartDocPrinterW(HANDLE hPrinter, DWORD Level, LPBYTE pDocInfo)
WINBOOL WINAPI StartPagePrinter(HANDLE hPrinter)
Definition: printers.c:457
WINBOOL WINAPI OpenPrinterW(LPWSTR pPrinterName, LPHANDLE phPrinter, LPPRINTER_DEFAULTSW pDefault)
Definition: printers.c:2624
WINBOOL WINAPI EndDocPrinter(HANDLE hPrinter)
Definition: printers.c:217
WINBOOL WINAPI ClosePrinter(HANDLE hPrinter)
Definition: printers.c:176
WINBOOL WINAPI WritePrinter(HANDLE hPrinter, LPVOID pBuf, DWORD cbBuf, LPDWORD pcWritten)
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned char BYTE
Definition: xxhash.c:193