'From 'http://www.vbapi.com/ref/p/printerproperties.html
Private Declare Function EnumPrinters Lib "winspool.drv" Alias "EnumPrintersA" (ByVal flags As Long, ByVal name As String, ByVal Level As Long, pPrinterEnum As Long, ByVal cdBuf As Long, pcbNeeded As Long, pcReturned As Long) As Long
Private Declare Function lstrcpy Lib "kernel32.dll" Alias "lstrcpyA" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
Private Declare Function lstrlen Lib "kernel32.dll" Alias "lstrlenA" (ByVal lpString As Any) As Long
Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, pDefault As Any) As Long
Private Declare Function PrinterProperties Lib "winspool.drv" (ByVal hWnd As Long, ByVal hPrinter As Long) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
' Declarations and such needed for the example:
' (Copy them to the (declarations) section of a module.)
Private Type PRINTER_INFO_1
flags As Long
pDescription As String
pName As String
pComment As String
End Type
Private Const PRINTER_ENUM_DEFAULT = &H1
Private Sub Command1_Click
Dim pi1 As PRINTER_INFO_1 ' a little info about the printer
Dim bytesNeeded As Long ' size needed for buffer
Dim numPrinters As Long ' number of printers enumerated (should be 1)
Dim buffer() As Long ' buffer for printer information
Dim slength As Long ' length of string to copy
Dim hPrinter As Long ' handle to the printer
Dim retval As Long ' generic return value
' Figure out how much space is needed to store the printer information.
retval = EnumPrinters(PRINTER_ENUM_DEFAULT, vbNullString, 1, ByVal 0, 0, bytesNeeded, numPrinters)
' Allocate that much space in the buffer array.
ReDim buffer(0 To bytesNeeded / 4 - 1) As Long
' Get information about the default printer.
retval = EnumPrinters(PRINTER_ENUM_DEFAULT, vbNullString, 1, buffer(0), bytesNeeded, _
bytesNeeded, numPrinters)
' Make sure we were successful.
If retval = 0 Or numPrinters <> 1 Then
MsgBox "No default printer or some other error."
Exit Sub
End If
' Copy the data into the structure.
With pi1
' Copy numerical data directly.
.flags = buffer(0)
' Strings require more work, since the buffer holds pointers to them.
.pDescription = Space(lstrlen(buffer(1)))
retval = lstrcpy(.pDescription, buffer(1))
.pName = Space(lstrlen(buffer(2)))
retval = lstrcpy(.pName, buffer(2))
.pComment = Space(lstrlen(buffer(3)))
retval = lstrcpy(.pComment, buffer(3))
End With
' Open the printer.
retval = OpenPrinter(pi1.pName, hPrinter, ByVal CLng(0))
If retval <> 0 Then
' Display the properties dialog.
retval = PrinterProperties(Me.hWnd, hPrinter)
' Close the printer.
retval = ClosePrinter(hPrinter)
Else
MsgBox "Unable to open printer!"
End If
End Sub