add SetPrinterDataExW.exe.
[gd/win32-spoolss/.git] / SetPrinterData.c
1 /******************************************************************
2  * SPOOLSS regression testing code for Samba print servers
3  *
4  *****************************************************************/
5
6 #include <windows.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include "printlib.h"
10
11 int main (int argc, char* argv[])
12 {
13
14         HANDLE                  printer;
15         DWORD                   type, pcbData;
16         LPBYTE                  pData = NULL;
17         DWORD                   i, status;
18
19
20         if (argc < 3)
21         {
22                 fprintf (stderr, "useage: %s <printername> <value name>\n", argv[0]);
23                 exit (-1);
24         }
25
26         /* open the printer */
27         if (!OpenPrinter (argv[1], &printer, NULL))
28         {
29                 fprintf (stderr, "Unable to open %s!\n", argv[1]);
30                 exit (-1);
31         }
32         else
33         {
34                 printf ("Printer [%s] opened successfully.\n\n", argv[1]);
35         }
36
37         status=GetPrinterData(printer, argv[2], &type, pData, 0, &pcbData);
38         if ((status != ERROR_SUCCESS) && (status != ERROR_MORE_DATA))
39         {
40                 PrintLastError();
41                 ClosePrinter (printer);
42                 exit (-1);
43         }
44
45         if ((pData = (LPBYTE)malloc(pcbData)) == NULL)
46         {
47                 fprintf (stderr, "Unable to malloc memory for Value Data!\n");
48                 exit (-1);
49         }
50
51         status = GetPrinterData(printer, argv[2], &type, pData, pcbData, &pcbData);
52         if (status == ERROR_SUCCESS)
53         {
54                 LPBYTE          ptr = pData;
55
56                 printf ("\tValue Name = %s\n", argv[2]);
57                 printf ("\tType = %d\n", type);
58                 printf ("\tData = 0x%x bytes\n", pcbData);
59                 i = 0;
60                 while (i < pcbData)
61                 {
62                         printf ("\t0x%x", *(ptr));
63                         *ptr = *ptr < 1;
64                         ptr++;
65                         if (i%4 == 3)
66                                 printf ("\n");
67                         i++;
68                 }
69                 printf ("\n");
70         }
71
72         printf ("Shifting everything to the right one bit...\n\n");
73
74         status = SetPrinterData(printer, argv[2], type, pData, pcbData);
75         if (status == ERROR_SUCCESS)
76         {
77                 printf ("\tValue Name = %s\n", argv[2]);
78                 printf ("\tType = %d\n", type);
79                 printf ("\tData = 0x%x bytes\n", pcbData);
80                 i = 0;
81                 while (i < pcbData)
82                 {
83                         printf ("\t0x%x", *(pData++));
84                         if (i%4 == 3)
85                                 printf ("\n");
86                         i++;
87                 }
88                 printf ("\n");
89         }
90         else
91                 PrintLastError();
92
93         printf ("\n");
94
95
96
97         /* close the printer */
98         if (!ClosePrinter(printer))
99         {
100                 fprintf (stderr, "Error closing printer!\n");
101                 exit (-1);
102         }
103         else
104         {
105                 printf ("Printer [%s] closed successfully.\n", argv[1]);
106         }
107
108         return 0;
109
110 }