matt23lucier
MIS
I am attempting to print to an Eltron 2442 printer to print labels. I have the program working in VB6 and I convert to the program to VB.NET and make some adjustments and then nothing prints out. There are no errors detected and nothing happens. Here is the code that does the printing:
I also have the following functions declared:
Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, ByVal phPrn As Long, ByVal pDefault As Object) As Boolean
Private Declare Function StartDocPrinter Lib "winspool.drv" Alias "StartDocPrinterA" (ByVal hPrn As Long, ByVal Level As Long, ByVal pDocInfo As DOC_INFO_1) As Long
Private Declare Function StartPagePrinter Lib "winspool.drv" (ByVal hPrn As Long) As Long
Private Declare Function WritePrinter Lib "winspool.drv" (ByVal hPrn As Long, ByVal pBuf As Object, ByVal cdBuf As Long, ByVal pcWritten As Long) As Long
Private Declare Function EndPagePrinter Lib "winspool.drv" (ByVal hPrn As Long) As Long
Private Declare Function EndDocPrinter Lib "winspool.drv" (ByVal hPrn As Long) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrn As Long) As Long
Here is the code that does the actual printing. I send thise method the file where the data is that needs to be printed and the name of the printer.
Private Sub SpoolFile(ByVal sFile As String, ByVal PrnName As String
Dim hPrn As Long
Dim Buffer() As Byte
Dim hFile As Integer
Dim Written As Long
Dim di As DOC_INFO_1
Dim I As Long
Const BufSize As Long = &H4000
Try
di.pDocName = sFile
di.pOutputFile = vbNullString
di.pDatatype = "RAW"
Call OpenPrinter(PrnName, hPrn, 0)
Call StartDocPrinter(hPrn, 1, di)
Call StartPagePrinter(hPrn)
hFile = FreeFile()
FileOpen(hFile, sFile, OpenMode.Binary, OpenAccess.Read)
ReDim Buffer(BufSize)
For I = 1 To LOF(hFile) \ BufSize
FileGet(hFile, Buffer)
Call WritePrinter(hPrn, Buffer, BufSize, Written)
Next I
If LOF(hFile) Mod BufSize Then
ReDim Buffer((LOF(hFile) Mod BufSize) - 1)
FileGet(hFile, Buffer)
Call WritePrinter(hPrn, Buffer, UBound(Buffer), Written)
End If
FileClose(hFile)
Call EndPagePrinter(hPrn)
Call EndDocPrinter(hPrn)
Call ClosePrinter(hPrn)
Catch ex As Exception
MessageBox.Show("Error " & ex.ToString())
End Try
End Sub
Thank you for your help.
Matt
I also have the following functions declared:
Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, ByVal phPrn As Long, ByVal pDefault As Object) As Boolean
Private Declare Function StartDocPrinter Lib "winspool.drv" Alias "StartDocPrinterA" (ByVal hPrn As Long, ByVal Level As Long, ByVal pDocInfo As DOC_INFO_1) As Long
Private Declare Function StartPagePrinter Lib "winspool.drv" (ByVal hPrn As Long) As Long
Private Declare Function WritePrinter Lib "winspool.drv" (ByVal hPrn As Long, ByVal pBuf As Object, ByVal cdBuf As Long, ByVal pcWritten As Long) As Long
Private Declare Function EndPagePrinter Lib "winspool.drv" (ByVal hPrn As Long) As Long
Private Declare Function EndDocPrinter Lib "winspool.drv" (ByVal hPrn As Long) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrn As Long) As Long
Here is the code that does the actual printing. I send thise method the file where the data is that needs to be printed and the name of the printer.
Private Sub SpoolFile(ByVal sFile As String, ByVal PrnName As String
Dim hPrn As Long
Dim Buffer() As Byte
Dim hFile As Integer
Dim Written As Long
Dim di As DOC_INFO_1
Dim I As Long
Const BufSize As Long = &H4000
Try
di.pDocName = sFile
di.pOutputFile = vbNullString
di.pDatatype = "RAW"
Call OpenPrinter(PrnName, hPrn, 0)
Call StartDocPrinter(hPrn, 1, di)
Call StartPagePrinter(hPrn)
hFile = FreeFile()
FileOpen(hFile, sFile, OpenMode.Binary, OpenAccess.Read)
ReDim Buffer(BufSize)
For I = 1 To LOF(hFile) \ BufSize
FileGet(hFile, Buffer)
Call WritePrinter(hPrn, Buffer, BufSize, Written)
Next I
If LOF(hFile) Mod BufSize Then
ReDim Buffer((LOF(hFile) Mod BufSize) - 1)
FileGet(hFile, Buffer)
Call WritePrinter(hPrn, Buffer, UBound(Buffer), Written)
End If
FileClose(hFile)
Call EndPagePrinter(hPrn)
Call EndDocPrinter(hPrn)
Call ClosePrinter(hPrn)
Catch ex As Exception
MessageBox.Show("Error " & ex.ToString())
End Try
End Sub
Thank you for your help.
Matt