ReactOS  0.4.12-dev-432-g3463b2d
main.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <windows.h>
3 
4 void Usage(WCHAR* name)
5 {
6  wprintf(L"Usage: %s testfile\n", name);
7 }
8 
9 int 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 
92 Cleanup:
93  if (hPrinter)
94  ClosePrinter(hPrinter);
95 
98 
99  return ReturnValue;
100 }
static int argc
Definition: ServiceArgs.c:12
LPWSTR pDocName
Definition: winspool.h:556
#define CloseHandle
Definition: compat.h:398
__wchar_t WCHAR
Definition: xmlstorage.h:180
DWORD dwFileSize
Definition: more.c:36
DWORD WINAPI StartDocPrinterW(HANDLE hPrinter, DWORD Level, LPBYTE pDocInfo)
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
WINBOOL WINAPI StartPagePrinter(HANDLE hPrinter)
Definition: printers.c:237
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1635
#define INVALID_FILE_SIZE
Definition: winbase.h:529
#define wprintf(...)
Definition: whoami.c:18
#define argv
Definition: mplay32.c:18
int wmain(int argc, WCHAR *argv[])
Definition: main.c:247
unsigned char * LPBYTE
Definition: typedefs.h:52
UINT32 void void ** ReturnValue
Definition: acevents.h:213
WINBOOL WINAPI ClosePrinter(HANDLE hPrinter)
Definition: printers.c:12
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define OPEN_EXISTING
Definition: compat.h:426
WINBOOL WINAPI WritePrinter(HANDLE hPrinter, LPVOID pBuf, DWORD cbBuf, LPDWORD pcWritten)
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:481
static const WCHAR L[]
Definition: oid.c:1087
unsigned char BYTE
Definition: mem.h:68
#define GENERIC_READ
Definition: compat.h:124
WINBOOL WINAPI EndPagePrinter(HANDLE hPrinter)
Definition: printers.c:51
static const WCHAR Cleanup[]
Definition: register.c:80
_In_ HANDLE hFile
Definition: mswsock.h:90
WINBOOL WINAPI OpenPrinterW(LPWSTR pPrinterName, LPHANDLE phPrinter, LPPRINTER_DEFAULTSW pDefault)
Definition: printers.c:757
void Usage(WCHAR *name)
Definition: main.c:4
#define min(a, b)
Definition: monoChain.cc:55
#define CreateFileW
Definition: compat.h:400
Definition: name.c:36
WINBOOL WINAPI EndDocPrinter(HANDLE hPrinter)
Definition: printers.c:36
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
#define printf
Definition: config.h:203