-
hi there.
thanks for looking at this post again. i have tried everything to use the api call to set the printer to a state of 'paused', with no luck whatsoever. here is the code that i am using, could you take a look at it and give me your comments.
really appreciated.
'Variable Declarations
Dim longbuffer() As Long ' resizable array receives information from the function
Dim PrintInfo() As PRINTER_INFO_2 ' values inside longbuffer() will be put into here
Dim numbytes As Long ' size in bytes of longbuffer()
Dim numneeded As Long ' receives number of bytes necessary if longbuffer() is too small
Dim c As Integer ' counter variable
Dim Retval, ret As Long ' return values
Dim numprinters As Long ' receives number of printers found
Dim PrinterStruct As PRINTER_DEFAULTS
Dim hPrinter As Long
Dim PrinterName As String
numbytes = 3076
ReDim longbuffer(0 To numbytes / 4) As Long
Retval = EnumPrinters(PRINTER_ENUM_LOCAL, "", 2,longbuffer_ _(0), numbytes, numneeded, numprinters)
If Retval = 0 Then
numbytes = numneeded
ReDim longbuffer(0 To numbytes / 4) As Long
Retval = EnumPrinters(PRINTER_ENUM_LOCAL, "", 2,_
_longbuffer(0), numbytes, numneeded, numprinters)
End If
ReDim PrintInfo(0 To numprinters - 1) As PRINTER_INFO_2
For c = 0 To numprinters - 1
PrintInfo(c).pPrinterName = Space(lstrlen(longbuffer(4 * c_
_+ 1)))
PrintInfo(c).Status = longbuffer(4 * c + 18)
'Initialize the Printer structure
PrinterStruct.pDatatype = vbNullString
PrinterStruct.pDevMode.dmSize = Len(PrinterStruct.pDevMode)
PrinterStruct.DesiredAccess = PRINTER_ALL_ACCESS
Retval = OpenPrinter("HP Deskjet 690C", hPrinter, _
_PrinterStruct)
'-----This is where the problem arises, and it does nothing!
ret = SetPrinter(hPrinter, 0, 0, PRINTER_CONTROL_PAUSE)
Retval = CloseHandle(hPrinter) ' this does not work either!
Thanks again.
Looking forward to your expert help.
andrew
-
I think you've got the PRINTER_DEFAULTS structure wrong, or rather you've used the declaration from the API viewer which is wrong!
What You need is:
Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" _
(ByVal pPrinterName As String, phPrinter As Long, pDefault As Any) As Long
Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Declare Function SetPrinter Lib "winspool.drv" _
Alias "SetPrinterA" _
(ByVal hPrinter As Long, _
ByVal Level As Long, _
pPrinter As Any, _
ByVal Command As Long) As Long
Type PRINTER_DEFAULTS
pDatatype As String
pDevMode As Long
pDesiredAccess As Long
End Type
Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
Public Const PRINTER_ACCESS_ADMINISTER = &H4
Public Const PRINTER_ACCESS_USE = &H8
Public Const PRINTER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or PRINTER_ACCESS_ADMINISTER Or PRINTER_ACCESS_USE)
Public Const PRINTER_CONTROL_PAUSE = 1
Public Const PRINTER_CONTROL_RESUME = 2
Public Const PRINTER_CONTROL_SET_DEFAULT = 4
Then:
Dim PrinterStruct As PRINTER_DEFAULTS
Dim lngResult as Long
PrinterStruct.pDatatype = vbNullString
PrinterStruct.pDevMode = 0
PrinterStruct.pDesiredAccess = PRINTER_ALL_ACCESS
lngResult = OpenPrinter(strPrinterName, hPrinter, PrinterStruct)
lngResult = SetPrinter(hPrinter, 0, vbNull, PRINTER_CONTROL_PAUSE)
lngResult = ClosePrinter(hPrinter)
There is some code on the VBNet site that enumerates printers, have a look at:
http://www.mvps.org/vbnet/code/enums/enumprinters.htm
This is a good starting point for adding this code in the efreshPrinterQueue (which is what I did to test it!)
-
Thanks a million
Thanks a million.
After hours of trying, you produce something which works in under 2 minutes!
Thanks!
Hope your programming goes well.
Yours gratefully
Andrew