AddPrinter

  BOOL AddPrinter(pName, Level, pPrinter)    
  LPSTR pName;    
  DWORD Level;    
  LPBYTE pPrinter;    

The AddPrinter function creates a printer.

Parameters

pName

Points to a NULL terminated string specifying the Server that the Print Processor is to be added to. If NULL, then the Print Processor is installed locally.

Level

This value must be two.

pPrinter

This points to a PRINTER_INFO_2 structure, and must have set at a minimum the elements:

pPrinterName, pPortName, and pDriverName.

The following elements are optional:

pPrintProcessor, pShareName, pComment, pLocation, pDevMode, pSepFile, pDatatype, pParameters, pSecurityDescriptor, Attributes, Priority, DefaultPriority, StartTime, UntilTime.

The following elements cannot be set, and can only be retrieved with the GetPrinter function:

Status, cJobs, AveragePPM;

Return Value

The return value is TRUE if the function was successful, or FALSE if an error occurred. To obtain extended error information, use the GetLastError function.

Comments

After an application creates a printer with the AddPrinter function, it must use the PrinterProperties function to set the correct printer driver settings for the new printer.

The AddPrinter function will fail if a printer of the same name already exists, unless that printer is marked as pending deletion. In that case, the existing printer will not be deleted, and the AddPrinter creation parameters will be used to change the existing printer settings (as if the application had used the SetPrinter function).

See Also

DeletePrinter, GetPrinter, PrinterProperties, SetPrinter