Hi Lee,
Thanks for the tip. This could help me in my other printing problems. But unfortunately, this is not what I need at the moment.
I am trying to print a batch of records directly to a barcode printer, which is a network printer, using TCP/IP.
Initially (for investigation purposes), I have these scripts:
*******start code*******
Public Class PrintBarCode
Inherits System.Web.UI.Page
Public Const GENERIC_WRITE = &H40000000
Public Const OPEN_EXISTING = 3
Public Const FILE_SHARE_WRITE = &H2
Public Shared LPTPORT As String
Public Shared hPort As Integer
Public Shared retval As Integer
Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" ( _
ByVal lpFileName As String, ByVal dwDesiredAccess As Integer, _
ByVal dwShareMode As Integer, _
ByRef lpSecurityAttributes As SECURITY_ATTRIBUTES, _
ByVal dwCreationDisposition As Integer, ByVal dwFlagsAndAttributes As Integer, _
ByVal hTemplateFile As Integer) As Integer
Public Declare Function CloseHandle Lib "kernel32" Alias "CloseHandle" (ByVal hObject As Integer) As Integer
Dim retval As Integer
Public Structure SECURITY_ATTRIBUTES
Private nLength As Integer
Private lpSecurityDescriptor As Integer
Private bInheritHandle As Integer
End Structure
Public Shared Function Print()
Dim Texxxt As String
Dim SA As SECURITY_ATTRIBUTES
Dim SA
Dim outFile As FileStream, hPortP As IntPtr
LPTPORT = "LPT1"
Texxxt = "testing"
hPort = CreateFile(LPTPORT, GENERIC_WRITE, FILE_SHARE_WRITE, SA, OPEN_EXISTING, 0, 0)
hPortP = New IntPtr(hPort) convert Integer to IntPtr
outFile = New FileStream(hPortP, FileAccess.Write, False) Create FileStream using Handle
Dim fileWriter As New StreamWriter(outFile)
MessageBox.Show(RichTextBox1.Text)
fileWriter.AutoFlush = False
fileWriter.WriteLine("Testing")
fileWriter.WriteLine("Hello World2")
fileWriter.WriteLine("Hello World1")
fileWriter.WriteLine("Hello World2")
fileWriter.Write(Chr(12)) 12
fileWriter.Flush()
fileWriter.Close()
outFile.Close()
retval = CloseHandle(hPort)
End Function
End Class
*******end code*******
This also came from a help...
Using LPT1 or any other local printers work but when I change the value for LPTPORT with a network printer, "//dbpweb03/Prodigy Label Printer" which is the barcode printer, the CreateFile() function returns -1.
to give you an idea of what I really need, below are foxpro codes, which does print records directly to a barcode printer. It also sends escape characters to automatically configures the barcode printer at runtime:
? CHR(2) + "L" + CHR(13) &&: ENABLE PRINT MODE
? "H15" + CHR(13) && : SET BURN TIME (HIGHER = DARKER)
? "PC" + CHR(13) && : SET PRINT SPEED TO 2.0 IPS
? "SC" + CHR(13) && : SET SLEW RATE TO 2.0 IPS
? "O0000"+CHR(13) && : SPITS OUT THE LABEL IN BATCH
MODE
prints one by one a record
? CHR(2) + "L" + CHR(13) &&: ENABLE PRINT MODE
? "H15" + CHR(13) && : SET BURN TIME (HIGHER = DARKER)
? "PC" + CHR(13) && : SET PRINT SPEED TO 2.0 IPS
? "SC" + CHR(13) && : SET SLEW RATE TO 2.0 IPS
? "O0000"+CHR(13) && : SPITS OUT THE LABEL IN BATCH
MODE
I hope you could help me on this. This is actually my first time to use VB.NET so any tips will be of great help.
Hope to hear from you soon. Thanks in advance
...
Susana