Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleGet a printer's DRIVER_INFO_2 information
Keywordsprinter, driver, driver information, DRIVER_INFO_2
CategoriesGraphics
 
Thanks to Jacob Schäffer.

Use the OpenPrinter API function to get the printer's handle. Then use GetPrinterDriver to get the DRIVER_INFO_2 information. Use the StringFromPointer function (not shown here) to copy the string values returned from a buffer into the DRIVER_INFO_2 structure.

After getting the DRIVER_INFO_2 information, his program displays it in a FlexGrid control.

 
' Return True if the printer is a PostScript printer.
Private Function GetDriverInfo2(ByVal printer_name As _
    String) As DRIVER_INFO_2
Dim h_printer As Long
Dim buf_len As Long
Dim buf() As Long
Dim driver_info As DRIVER_INFO_2

    ' Get the printer's handle.
    If OpenPrinter(printer_name, h_printer, ByVal 0&) = 0 _
        Then
        MsgBox "Error opening printer " & printer_name & _
            "." & vbCrLf & _
            Err.Description
        GetDriverInfo2 = driver_info
        Exit Function
    Else
        ' See how much space we need for the
        ' driver info structure with its strings.
        ReDim buf(1 To 1)
        GetPrinterDriver h_printer, "", 2, _
            buf(1), 0, buf_len

        ' Get the data.
        ReDim buf(1 To buf_len / 4 + 1)
        If GetPrinterDriver(h_printer, "", 2, _
            buf(1), buf_len, buf_len) = 0 _
        Then
            MsgBox "Error getting driver information for " _
                & printer_name & "." & vbCrLf & _
                Err.Description
            GetDriverInfo2 = driver_info
            ClosePrinter h_printer
            Exit Function
        End If

        ' Get the information.
        driver_info.cVersion = buf(1)
        driver_info.pName = StringFromPointer(buf(2), 1024)
        driver_info.pEnvironment = _
            StringFromPointer(buf(3), 1024)
        driver_info.pDriverPath = StringFromPointer(buf(4), _
            1024)
        driver_info.pDataFile = StringFromPointer(buf(5), _
            1024)
        driver_info.pConfigFile = StringFromPointer(buf(6), _
            1024)

        GetDriverInfo2 = driver_info

        ClosePrinter h_printer
    End If
End Function
 
Jacob Schäffer says you can tell if a printer is a PostScript printer by checking the DRIVER_INFO_2 structure's lpDataFile entry for the .PPD extension. This doesn't seem to work with my ancient DEClaser 2100, though.

Also included in the download Zip file is some more comprehensive code by Jacob Schäffer for working with printer information.

 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated