dos2unix everything
[gd/win32-spoolss/.git] / AddPrinterEx.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 <string.h>
10 #include "printlib.h"
11
12
13 int main (int argc, char* argv[])
14 {
15         PRINTER_INFO_2          buffer;
16         HANDLE                          printer;
17         LPVOID                          lpMsgBuf;
18
19         if (argc < 5)
20         {
21                 fprintf (stderr, "useage: %s <servername> <printername> <sharename> <port name>\n", argv[0]);
22                 exit (-1);
23         }
24
25         memset(&buffer, 0 , sizeof(buffer));
26
27         buffer.pServerName      = strdup (argv[1]);
28         buffer.pPrinterName = strdup (argv[2]);
29         buffer.pShareName       = strdup (argv[3]);
30         buffer.pPortName        = strdup (argv[4]);
31         buffer.pDriverName      = strdup ("Apple LaserWriter II NTX v51.8");
32         buffer.pPrintProcessor  = strdup ("winprint");
33         buffer.pDatatype        = strdup ("RAW");
34         buffer.Attributes       = PRINTER_ATTRIBUTE_SHARED;
35         buffer.pSecurityDescriptor = NULL;
36
37
38         printf ("Attempting to add printer [%s] on server [%s]\n",
39                 buffer.pPrinterName, buffer.pServerName);
40         printf ("\nPrinter Info 1:\n");
41         print_printer_info_2 (&buffer);
42         printf ("\n");
43
44         printer = AddPrinter (buffer.pServerName, 2, (LPBYTE)(&buffer));
45         if ( printer == NULL)
46         {
47                 FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
48                         FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(),
49                         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
50                         (LPTSTR) &lpMsgBuf, 0, NULL);
51                 printf ("ERROR : %s\n", (char*)lpMsgBuf);
52                 LocalFree (lpMsgBuf);
53         }
54         else
55         {
56                 printf ("Printer [%s] added successfully on server [%s]!\n",
57                         buffer.pPrinterName, buffer.pServerName);
58                 if (!ClosePrinter (printer))
59                         fprintf (stderr, "Error closing printer handle!\n");
60                 else
61                         printf ("Printer handle closed successfully.\n");
62         }
63
64         return 0;
65
66 }