| | | | Enumerating Printer Drivers | | | | | | Windows also implements the EnumPrinterDrivers enumeration function that enumerates the available printer drivers on a system: | | BOOL EnumPrinterDrivers( LPTSTR pName, // pointer to server name LPTSTR pEnvironment, // pointer to environment name DWORD Level, // structure level LPBYTE pDriverInfo, // pointer to an array of structures DWORD cbBuf, // size, in bytes, of array LPDWORD pcbNeeded, // pointer to number of bytes copied (or required) LPDWORD pcReturned // pointer to number of DRIVER_INFO. structures ); | | | | In VB, we can write this as: | | | | | | Declare Function EnumPrinterDrivers Lib "winspool.drv" _ Alias "EnumPrinterDriversA" ( _ ByVal pName As String, _ ByVal pEnvironment As String, _ ByVal Level As Long, _ pDriverInfo As Long, _ ByVal cdBuf As Long, _ pcbNeeded As Long, _ pcReturned As Long _ ) As Long | | | | | | Once again, this is a complex function, and we just consider an example. Of the three different DRIVER_INFO structures, we consider only: | | | | | | Type DRIVER_INFO_2 cVersion As Long pName As Long pEnvironment As Long pDriverPath As Long pDataFile As Long pConfigFile As Long End Type | | | | | | Here is some code to enumerate printer drivers: | | | | | | Sub ListDrivers() Dim lNeeded As Long Dim lReturned As Long Dim lData() As Long Dim di2 As DRIVER_INFO_2 Dim i As Integer ReDim lData(0 To 4000) EnumPrinterDrivers vbNullString, vbNullString, 2, lData(0), _ 4000, lNeeded, lReturned Debug.Print "Needed: " & lNeeded Debug.Print "Returned: " & lReturned | | |