Announcement

Collapse
No announcement yet.

Help me witht his API function!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Help me witht his API function!

    I am trying to retrieve the recognised printer trays (bins) using an API Function from VBA. It is returning a -1 value therefore an error. I want to getlasterror but haven't a clue on retrieving dll error messages so maybe someone could help me out with that.

    In the meantime though this is the code...

    Private Const DC_BINS = 6
    Private Const DC_BINNAMES = 12
    Private Const ActivePrinter = "HP LaserJet 2200"

    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

    Public Function GetBinNumbers() As Variant

    Dim iBins As Long
    Dim iBinArray() As Integer
    Dim sPort As String
    Dim sCurrentPrinter As String

    'Get the printer & port of the printer
    sPort = Trim$(Mid$(ActivePrinter, InStrRev(ActivePrinter, " ") + 1))
    sCurrentPrinter = Trim$(Left$(ActivePrinter, _
    InStr(ActivePrinter, " on ")))

    'Find out how many printer bins there are
    iBins = DeviceCapabilities(sCurrentPrinter, sPort, _
    DC_BINS, ByVal vbNullString, 0)

    'Set the array of bin numbers to the right size ***
    ReDim iBinArray(0 To iBins - 1)

    'Load the array with the bin numbers
    iBins = DeviceCapabilities(sCurrentPrinter, sPort, _
    DC_BINS, iBinArray(0), 0)

    'Return the array to the calling routine
    GetBinNumbers = iBinArray
    End Function


    It is failing where I marked *** due to the fact iBins value is set to -1. A quick online search revealed -1 is a sign that the API function failed.

    Any ideas?

    Cheers folks!

    #2
    As an update to this - I now have tracked the dll error code to 1801. So if anyone knows anything about dll error codes and what one 1801 is, that'd be great!!!


    EDIT: Ok I found it. Invalid Printer name? INVALID PRINTER NAME? I have wasted hours on...INVALID PRINTER NAME? Bah.
    Last edited by SharkAttack; 08-02-2005, 15:59.

    Comment

    Working...
    X