OpenPrinter function
The OpenPrinter function gets the identity handle of the specified printer or print server.
BOOL OpenPrinter (
LPTSTR pPrinterName,//pointer to printer or server name
Lphandle Phprinter,//handle to printer or server
Lpprinter_defaults pdefault//pointer to printer default structure
);
Parameters
pPrinterName
Refers to a null-terminated string that specifies the name of the printer or print server.
Phprinter
Point to a variable to receive a handle that identifies an open printer or print server object.
Pdefault
Point to a printer_defaults structure. This value can be empty.
return value
If the function succeeds, the return value is Non-zero.
If the function fails, the return value is zero. To get an extended error message, call the GetLastError function.
Note
The Pdefault parameter allows an application
To specify the data type and device mode values for the StartDocPrinter function to submit the printed document. However, once the file has been started,
These values can be overridden (overwritten) using the Setjob function.
Printer_defaults one of the data structure members desiredaccess, pointing to the OpenPrinter handle permission specified by Pdefault.
If the application wants to open a printer to perform administrative tasks.
For example, the SetPrinter function should turn on the printer and printer_all_access permissions.
If an application only performs a basic print business, the printer_access_use is sufficient.
Desiredaccess member Printer_defaults was ignored in Windows 95:openprinter.
The application can determine what permissions the customer has on the print server, or get a print server handle to invoke Waitforprinterchange.
In this way, it should require that OpenPrinter and pprintername be set to the name of the server and that a service permission value, such as server_all_access, should be specified.
Members of the PRINTER_DEFAULTS structure Pdatatype and pDevMode should be set to null.
This handle may be passed to the ClosePrinter or Waitforprinterchange function after such a call.
If the user does not hold permission to open a specified printer or print server, the OpenPrinter call will fail with the expected license, and
GetLastError returns the value error_access_denied.