gav12345
09-04-2013, 02:13 AM
Hi,
I’m trying to gain access to default printer, to set printing from double sided to single sided (and then back again). However, I'm unable to get a handle on the printer. Can anyone suggest what I'm doing wrong here?
To do this, we’re using the OpenPrinter function (http://msdn.microsoft.com/en-us/library/windows/desktop/dd162751(v=vs.85).aspx)
In my code I've created a PRINTER_DEFAULTS type for the printer default values parameter of the OpenPrinter function:
Private Type PRINTER_DEFAULTS
pDatatype As Long
pDevmode As Long
DesiredAccess As Long
End Type
I have then created a constant named SERVER_ALL_ACCESS (set to appropriate hex value with high printer access privileges):
Private Const SERVER_ALL_ACCESS = &HF000C
I've then declared various variables to be passed to the OpenPrinter function, including one for the PRINTER_DEFAULTS type:
Dim hPrinter As Long
Dim pd As PRINTER_DEFAULTS
Dim sPrinterName As String
I've currently hard-coded the printer name, but hope to use ActivePrinter when this initial issue is resolved:
sPrinterName = “\\(ServerName)\(PrinterName)”
Have set the printer defaults DesiredAccess to the SERVER_ALL_ACCESS constant defined earlier:
pd.DesiredAccess = SERVER_ALL_ACCESS
When calling the OpenPrinter function, iRet always returns zero - i.e. I can't get a handle on the printer:
iRet = OpenPrinter(sPrinterName, hPrinter, pd)
If (iRet = 0) Or (hPrinter = 0) Then
Exit Function
End If
This is the call to the OpenPrinter function:
Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, pDefault As PRINTER_DEFAULTS) As Long
I’m trying to gain access to default printer, to set printing from double sided to single sided (and then back again). However, I'm unable to get a handle on the printer. Can anyone suggest what I'm doing wrong here?
To do this, we’re using the OpenPrinter function (http://msdn.microsoft.com/en-us/library/windows/desktop/dd162751(v=vs.85).aspx)
In my code I've created a PRINTER_DEFAULTS type for the printer default values parameter of the OpenPrinter function:
Private Type PRINTER_DEFAULTS
pDatatype As Long
pDevmode As Long
DesiredAccess As Long
End Type
I have then created a constant named SERVER_ALL_ACCESS (set to appropriate hex value with high printer access privileges):
Private Const SERVER_ALL_ACCESS = &HF000C
I've then declared various variables to be passed to the OpenPrinter function, including one for the PRINTER_DEFAULTS type:
Dim hPrinter As Long
Dim pd As PRINTER_DEFAULTS
Dim sPrinterName As String
I've currently hard-coded the printer name, but hope to use ActivePrinter when this initial issue is resolved:
sPrinterName = “\\(ServerName)\(PrinterName)”
Have set the printer defaults DesiredAccess to the SERVER_ALL_ACCESS constant defined earlier:
pd.DesiredAccess = SERVER_ALL_ACCESS
When calling the OpenPrinter function, iRet always returns zero - i.e. I can't get a handle on the printer:
iRet = OpenPrinter(sPrinterName, hPrinter, pd)
If (iRet = 0) Or (hPrinter = 0) Then
Exit Function
End If
This is the call to the OpenPrinter function:
Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, pDefault As PRINTER_DEFAULTS) As Long