add SetPrinterDataExW.exe.
[gd/win32-spoolss/.git] / EnumPrinterDataEx.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
12 #define ENUM_KEY_NAME   "PrinterDriverData"
13
14 int main (int argc, char* argv[])
15 {
16
17         HANDLE                  printer;
18         DWORD                   i, status, needed, returned;
19         PRINTER_ENUM_VALUES     *buffer = NULL;
20
21
22         if (argc < 2)
23         {
24                 fprintf (stderr, "useage: %s <printername>\n", argv[0]);
25                 exit (-1);
26         }
27
28         /* open the server */
29         if (!OpenPrinter (argv[1], &printer, NULL))
30                 PrintLastError();
31         else
32                 printf ("Printer [%s] opened successfully.\n\n", argv[1]);
33
34
35         needed = returned = 0;
36         status = EnumPrinterDataEx(printer, ENUM_KEY_NAME, (LPBYTE)buffer, 0, &needed, &returned);
37         if (status == ERROR_MORE_DATA)
38         {
39                 if ((buffer = malloc(needed)) == NULL)
40                 {
41                         fprintf (stderr, "Unable to malloc enough space for [%d] bytes\n", needed);
42                         exit (-1);
43                 }
44
45                 status = EnumPrinterDataEx(printer, ENUM_KEY_NAME, (LPBYTE)buffer, needed, &needed, &returned);
46                 if (status == ERROR_SUCCESS)
47                 {
48                         printf ("Printer Enum Values :\n");
49                         for (i=0; i<returned; i++)
50                         {
51                                 print_printer_enum_values (&buffer[i]);
52                                 printf ("\n");
53                         }
54                 }
55                 free (buffer);
56         }
57         else if (status != ERROR_SUCCESS)
58                 PrintLastError();
59
60
61         /* close the server */
62         if (!ClosePrinter(printer))
63                 PrintLastError();
64         else
65                 printf ("Printer [%s] closed successfully.\n", argv[1]);
66
67         return 0;
68
69 }