How To Determine Available PaperBins with DeviceCapabilities API

Article translations Article translations
Article ID: 194789 - View products that this article applies to.
This article was previously published under Q194789
Expand all | Collapse all

On This Page


If setting the PaperBin property of the Printer object fails to select the desired bin, it might be because the printer driver does not recognize the value being assigned. For example, you assign the constant for the upper bin (vbPRBNUpper) and it fails. It turns out that the printer driver considers its upper bin to be the Cassette bin. In this case, you need to use the Cassette constant to select the printer's upper bin.

This article shows how to enumerate a printer's paper bins.


Step-by-Step Example

  1. Create a Standard EXE project in Visual Basic. Form1 is created by default.
  2. Add a CommandButton and TextBox to the form.
  3. Set Text1's ScrollBar property to "2 - Vertical" and the MultiLine property to "True."
  4. Place the following code into Form1's code window:
    Option Explicit
    Private Declare Function DeviceCapabilities Lib "winspool.drv" _
       Alias "DeviceCapabilitiesA" (ByVal lpDeviceName As String, _
       ByVal lpPort As String, ByVal iIndex As Long, lpOutput As Any, _
       ByVal dev As Long) As Long
    Private Const DC_BINS = 6
    Private Const DC_BINNAMES = 12
    Private Sub Command1_Click()
       Dim prn As Printer
       Dim dwbins As Long
       Dim ct As Long
       Dim nameslist As String
       Dim nextString As String
       Dim numBin() As Integer
       Text1.Font.Name = "Courier New"
       Text1.Font.Size = 12
       Text1.Text = ""
       For Each prn In Printers
            dwbins = DeviceCapabilities(prn.DeviceName, prn.Port, _
              DC_BINS, ByVal vbNullString, 0)
            ReDim numBin(1 To dwbins)
            nameslist = String(24 * dwbins, 0)
            dwbins = DeviceCapabilities(prn.DeviceName, prn.Port, _
              DC_BINS, numBin(1), 0)
            dwbins = DeviceCapabilities(prn.DeviceName, prn.Port, _
              DC_BINNAMES, ByVal nameslist, 0)
            If Text1.Text <> "" Then
               Text1.Text = Text1.Text & vbCrLf & vbCrLf
            End If
            Text1.Text = Text1.Text & prn.DeviceName
            For ct = 1 To dwbins
               nextString = Mid(nameslist, 24 * (ct - 1) + 1, 24)
               nextString = Left(nextString, InStr(1, nextString, _
                 Chr(0)) - 1)
               nextString = String(6 - Len(CStr(numBin(ct))), " ") & _
               numBin(ct) & "  " & nextString
               Text1.Text = Text1.Text & vbCrLf & nextString
            Next ct
       Next prn
    End Sub
    Private Sub Form_Load()
       ' Size and position the Form and controls
       Me.Height = 7000
       Me.Width = 7000
       Text1.Top = 100
       Text1.Left = 100
       Text1.Height = 6450
       Text1.Width = 5000
       Text1.Text = ""   ' Clear the TextBox
       Command1.Left = 5300
       Command1.Top = 1000
       Command1.Width = 1500
       Command1.Caption = "List Bins"
    End Sub
  5. Run the project and click on the CommandButton labeled "List Bins." The TextBox is filled with a list of all installed printers and the PaperBin settings each one supports.

    NOTE: This approach lists all PaperBins known to the printer driver, but every bin listed is not guaranteed to be physically installed on the printer. For example, some printers are available with an optional envelope feeder. This selection is reported by the API even if that feature is not currently installed on the printer.


Article ID: 194789 - Last Review: March 7, 2005 - Revision: 2.3
  • Microsoft Visual Basic 5.0 Learning Edition
  • Microsoft Visual Basic 6.0 Learning Edition
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic 6.0 Enterprise Edition
  • Microsoft Visual Basic 4.0 Standard Edition
  • Microsoft Visual Basic 4.0 Professional Edition
  • Microsoft Visual Basic 4.0 32-Bit Enterprise Edition
kbhowto kbprint kbapi KB194789

Give Feedback


Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from