G
Guest
I'm trying to get the hardware ID for the printers on a machine. Below is my
code. The problem appears to get in my second call to GetPrinterDriver. I
think it may be a problem with the DRIVER_INFO_6 definition. Any help would
be appreciated.
Thanks in Advance.
--
Eric Howard
Director of Process Automation
Synergis Technologies, Inc.
<StructLayout(LayoutKind.Sequential)> _
Private Structure DRIVER_INFO_6
Public cVersion As Int32
Public pName As String ' QMS 810
Public pEnvironment As String ' Win32 x86
Public pDriverPath As String ' c:\drivers\pscript.dll
Public pDataFile As String ' c:\drivers\QMS810.PPD
Public pConfigFile As String ' c:\drivers\PSCRPTUI.DLL
Public pHelpFile As String ' c:\drivers\PSCRPTUI.HLP
Public pDependentFiles As String '
Public pMonitorName As String ' "PJL monitor"
Public pDefaultDataType As String ' "EMF"
Public pszzPreviousNames As String
Public ftDriverDate As FILETIME
Public dwlDriverVersion As Int32
Public pszMfgName As String
Public pszOEMUrl As String
Public pszHardwareID As String
Public pszProvider As String
End Structure
<DllImport("winspool.drv", EntryPoint:="OpenPrinterA", _
SetLastError:=True, CharSet:=CharSet.Ansi, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Function OpenPrinter(ByVal pPrinterName As String, _
ByRef phPrinter As Int32, _
ByVal pDefault As Int32 _
) As Boolean
End Function
<DllImport("winspool.drv", EntryPoint:="ClosePrinter", _
SetLastError:=True, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Function ClosePrinter(ByVal hPrinter As Int32) As Boolean
End Function
<DllImport("winspool.drv", EntryPoint:="GetPrinterDriverA", _
SetLastError:=True, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Private Function GetPrinterDriver(ByVal hPrinter As Int32, _
ByVal pEnvironment As String, _
ByVal Level As Int32, _
ByRef pDriverInfo As DRIVER_INFO_6, _
ByVal cdBuf As Int32, _
ByRef pcbNeeded As Int32 _
) As Boolean
End Function
Sub Main()
Dim lIndex As Integer
Dim sName As String
Dim hResult As Int32
Dim hPrinter As Int32
Dim vInfo As DRIVER_INFO_6
Dim lBytesNeeded As Integer
For lIndex = 0 To PrinterSettings.InstalledPrinters.Count - 1
sName = PrinterSettings.InstalledPrinters.Item(lIndex)
If Not OpenPrinter(sName, hPrinter, 0) Then
Throw New ApiException(Marshal.GetLastWin32Error,
"OpenPrinter")
Else
Try
GetPrinterDriver(hPrinter, vbNullString, 6, vInfo, 0,
lBytesNeeded)
GetPrinterDriver(hPrinter, vbNullString, 6, vInfo,
lBytesNeeded, lBytesNeeded)
Catch ex As Exception
If ClosePrinter(hPrinter) Then
Throw ex
Else
Throw New ApiException("ClosePrinter")
End If
End Try
End If
Console.WriteLine(sName)
Next
Console.ReadLine()
End Sub
code. The problem appears to get in my second call to GetPrinterDriver. I
think it may be a problem with the DRIVER_INFO_6 definition. Any help would
be appreciated.
Thanks in Advance.
--
Eric Howard
Director of Process Automation
Synergis Technologies, Inc.
<StructLayout(LayoutKind.Sequential)> _
Private Structure DRIVER_INFO_6
Public cVersion As Int32
Public pName As String ' QMS 810
Public pEnvironment As String ' Win32 x86
Public pDriverPath As String ' c:\drivers\pscript.dll
Public pDataFile As String ' c:\drivers\QMS810.PPD
Public pConfigFile As String ' c:\drivers\PSCRPTUI.DLL
Public pHelpFile As String ' c:\drivers\PSCRPTUI.HLP
Public pDependentFiles As String '
Public pMonitorName As String ' "PJL monitor"
Public pDefaultDataType As String ' "EMF"
Public pszzPreviousNames As String
Public ftDriverDate As FILETIME
Public dwlDriverVersion As Int32
Public pszMfgName As String
Public pszOEMUrl As String
Public pszHardwareID As String
Public pszProvider As String
End Structure
<DllImport("winspool.drv", EntryPoint:="OpenPrinterA", _
SetLastError:=True, CharSet:=CharSet.Ansi, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Function OpenPrinter(ByVal pPrinterName As String, _
ByRef phPrinter As Int32, _
ByVal pDefault As Int32 _
) As Boolean
End Function
<DllImport("winspool.drv", EntryPoint:="ClosePrinter", _
SetLastError:=True, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Function ClosePrinter(ByVal hPrinter As Int32) As Boolean
End Function
<DllImport("winspool.drv", EntryPoint:="GetPrinterDriverA", _
SetLastError:=True, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Private Function GetPrinterDriver(ByVal hPrinter As Int32, _
ByVal pEnvironment As String, _
ByVal Level As Int32, _
ByRef pDriverInfo As DRIVER_INFO_6, _
ByVal cdBuf As Int32, _
ByRef pcbNeeded As Int32 _
) As Boolean
End Function
Sub Main()
Dim lIndex As Integer
Dim sName As String
Dim hResult As Int32
Dim hPrinter As Int32
Dim vInfo As DRIVER_INFO_6
Dim lBytesNeeded As Integer
For lIndex = 0 To PrinterSettings.InstalledPrinters.Count - 1
sName = PrinterSettings.InstalledPrinters.Item(lIndex)
If Not OpenPrinter(sName, hPrinter, 0) Then
Throw New ApiException(Marshal.GetLastWin32Error,
"OpenPrinter")
Else
Try
GetPrinterDriver(hPrinter, vbNullString, 6, vInfo, 0,
lBytesNeeded)
GetPrinterDriver(hPrinter, vbNullString, 6, vInfo,
lBytesNeeded, lBytesNeeded)
Catch ex As Exception
If ClosePrinter(hPrinter) Then
Throw ex
Else
Throw New ApiException("ClosePrinter")
End If
End Try
End If
Console.WriteLine(sName)
Next
Console.ReadLine()
End Sub