Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2004
    Posts
    17

    Unanswered: Retrieving List of Bins for a Printer

    I see that GetBinList is used to retrieve a list of PaperBins for a particular printer, where is the API info for that call?

    Miles

  2. #2
    Join Date
    Jan 2004
    Posts
    17

    Re: Retrieving List of Bins for a Printer

    Originally posted by milestone
    I see that GetBinList is used to retrieve a list of PaperBins for a particular printer, where is the API info for that call?

    Miles
    I found it!

    Declaration for DeviceCapabilities function API call.
    Private Declare Function DeviceCapabilities Lib "winspool.drv" _
    Alias "DeviceCapabilitiesA" (ByVal lpsDeviceName As String, _
    ByVal lpPort As String, ByVal iIndex As Long, lpOutput As Any, _
    ByVal lpDevMode As Long) As Long

    ' DeviceCapabilities function constants.
    Private Const DC_BINNAMES = 12
    Private Const DC_BINS = 6
    Private Const DEFAULT_VALUES = 0

    Sub GetBinList(strName As String)
    Dim lngBinCount As Long
    Dim lngCounter As Long
    Dim hPrinter As Long
    Dim strDeviceName As String
    Dim strDevicePort As String
    Dim strBinNamesList As String
    Dim strBinName As String
    Dim intLength As Integer
    Dim strMsg As String
    Dim aintNumBin() As Integer

    ' Get name and port of the default printer.
    strDeviceName = Application.Printers(strName).DeviceName
    strDevicePort = Application.Printers(strName).Port

    ' Get count of paper bin names supported by the printer.
    lngBinCount = DeviceCapabilities(lpsDeviceName:=strDeviceName, _
    lpPort:=strDevicePort, _
    iIndex:=DC_BINNAMES, _
    lpOutput:=ByVal vbNullString, _
    lpDevMode:=DEFAULT_VALUES)
    ' Re-dimension array to count of paper bins.
    ReDim aintNumBin(1 To lngBinCount)

    ' Pad variable to accept 24 bytes for each bin name.
    strBinNamesList = String(Number:=24 * lngBinCount, Character:=0)

    ' Get string buffer of paper bin names supported by printer.
    lngBinCount = DeviceCapabilities(lpsDeviceName:=strDeviceName, _
    lpPort:=strDevicePort, _
    iIndex:=DC_BINNAMES, _
    lpOutput:=strBinNamesList, _
    lpDevMode:=DEFAULT_VALUES)

    ' Get array of paper bin numbers supported by the printer.
    lngBinCount = DeviceCapabilities(lpsDeviceName:=strDeviceName, _
    lpPort:=strDevicePort, _
    iIndex:=DC_BINS, _
    lpOutput:=aintNumBin(1), _
    lpDevMode:=DEFAULT_VALUES)

    ' List available paper bin names.
    strMsg = "Paper bins available for " & strDeviceName & vbCrLf
    For lngCounter = 1 To lngBinCount

    ' Parse a paper bin name from string buffer.
    strBinName = Mid(String:=strBinNamesList, _
    Start:=24 * (lngCounter - 1) + 1, _
    Length:=24)
    intLength = VBA.InStr(Start:=1, _
    String1:=strBinName, String2:=Chr(0)) - 1
    strBinName = Left(String:=strBinName, _
    Length:=intLength)

    ' Add bin name and number to the text string for the message box.
    strMsg = strMsg & vbCrLf & aintNumBin(lngCounter) _
    & vbTab & strBinName

    Next lngCounter

    ' Show paper bin numbers and names in a message box.
    MsgBox Prompt:=strMsg

    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •