[PRINTING]
[reactos.git] / rosapps / applications / cmdutils / winspool_print / main.c
1 #include <stdio.h>
2 #include <windows.h>
3
4 int main()
5 {
6 int ReturnValue = 1;
7 DWORD dwRead;
8 DWORD dwWritten;
9 HANDLE hFile = INVALID_HANDLE_VALUE;
10 HANDLE hPrinter = NULL;
11 DOC_INFO_1W docInfo;
12 BYTE Buffer[20000];
13
14 hFile = CreateFileW(L"testfile", GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
15 if (hFile == INVALID_HANDLE_VALUE)
16 {
17 printf("CreateFileW failed, last error is %lu!\n", GetLastError());
18 goto Cleanup;
19 }
20
21 if (!ReadFile(hFile, Buffer, sizeof(Buffer), &dwRead, NULL))
22 {
23 printf("ReadFile failed, last error is %lu!\n", GetLastError());
24 goto Cleanup;
25 }
26
27 if (!OpenPrinterW(L"Dummy Printer On LPT1", &hPrinter, NULL))
28 {
29 printf("OpenPrinterW failed, last error is %lu!\n", GetLastError());
30 goto Cleanup;
31 }
32
33 ZeroMemory(&docInfo, sizeof(docInfo));
34 docInfo.pDocName = L"winspool_print";
35
36 if (!StartDocPrinterW(hPrinter, 1, (LPBYTE)&docInfo))
37 {
38 printf("StartDocPrinterW failed, last error is %lu!\n", GetLastError());
39 goto Cleanup;
40 }
41
42 if (!StartPagePrinter(hPrinter))
43 {
44 printf("StartPagePrinter failed, last error is %lu!\n", GetLastError());
45 goto Cleanup;
46 }
47
48 if (!WritePrinter(hPrinter, Buffer, dwRead, &dwWritten))
49 {
50 printf("WritePrinter failed, last error is %lu!\n", GetLastError());
51 goto Cleanup;
52 }
53
54 if (!EndPagePrinter(hPrinter))
55 {
56 printf("EndPagePrinter failed, last error is %lu!\n", GetLastError());
57 goto Cleanup;
58 }
59
60 if (!EndDocPrinter(hPrinter))
61 {
62 printf("EndDocPrinter failed, last error is %lu!\n", GetLastError());
63 goto Cleanup;
64 }
65
66 ReturnValue = 0;
67
68 Cleanup:
69 if (hFile != INVALID_HANDLE_VALUE)
70 CloseHandle(hFile);
71
72 if (hPrinter)
73 ClosePrinter(hPrinter);
74
75 return ReturnValue;
76 }