add SetPrinterDataExW.exe.
[gd/win32-spoolss/.git] / SetPrinterDataEx.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 server */
27         if (!OpenPrinter (argv[1], &printer, NULL))
28                 PrintLastError();
29         else
30                 printf ("Printer [%s] opened successfully.\n\n", argv[1]);
31
32
33         status=GetPrinterDataEx(printer, "PrinterDriverData", argv[2], &type, pData, 0, &pcbData);
34         if ((status != ERROR_SUCCESS) && (status != ERROR_MORE_DATA))
35         {
36                 PrintLastError();
37                 ClosePrinter (printer);
38                 exit (-1);
39         }
40
41         if ((pData = (LPBYTE)malloc(pcbData)) == NULL)
42         {
43                 fprintf (stderr, "Unable to malloc memory for Value Data!\n");
44                 exit (-1);
45         }
46
47         status = GetPrinterDataEx(printer, "PrinterDriverData", argv[2], &type, pData, pcbData, &pcbData);
48         if (status == ERROR_SUCCESS)
49         {
50                 LPBYTE          ptr = pData;
51
52                 printf ("\tValue Name = %s\n", argv[2]);
53                 printf ("\tType = %d\n", type);
54                 printf ("\tData = 0x%x bytes\n", pcbData);
55                 i = 0;
56                 while (i < pcbData)
57                 {
58                         printf ("\t0x%x", *(ptr));
59                         *ptr = *ptr < 1;
60                         ptr++;
61                         if (i%4 == 3)
62                                 printf ("\n");
63                         i++;
64                 }
65                 printf ("\n");
66         }
67
68         printf ("Shifting everything to the right one bit...\n\n");
69
70         status = SetPrinterDataEx(printer, "PrinterDriverData", argv[2], type, pData, pcbData);
71         if (status == ERROR_SUCCESS)
72         {
73                 printf ("\tValue Name = %s\n", argv[2]);
74                 printf ("\tType = %d\n", type);
75                 printf ("\tData = 0x%x bytes\n", pcbData);
76                 i = 0;
77                 while (i < pcbData)
78                 {
79                         printf ("\t0x%x", *(pData++));
80                         if (i%4 == 3)
81                                 printf ("\n");
82                         i++;
83                 }
84                 printf ("\n");
85         }
86         else
87                 PrintLastError();
88
89         printf ("\n");
90
91
92
93         /* close the server */
94         if (!ClosePrinter(printer))
95                 PrintLastError();
96         else
97                 printf ("Printer [%s] closed successfully.\n", argv[1]);
98
99         return 0;
100
101 }