I want to do a print of the dos program that supports lpt1 then I want to do the print by redirecting to the usb port and below the file path asc file. how can do a raw print of the asc file that is or with other solutions do directly or through a temp file that has the extension "tmp". Please the best solution. Thanks
my path asc file is C:\vDos\#LPT1.asc
my path temp file is C:\Users\Admin\AppData\Local\Temp\vDos
Public Class Form1
Public Const FILE_ATTRIBUTE_NORMAL As Short = &H80
Public Const INVALID_HANDLE_VALUE As Short = -1
Public Const GENERIC_READ As UInteger = &H80000000UI
Public Const GENERIC_WRITE As UInteger = &H40000000
Public Const CREATE_NEW As UInteger = 1
Public Const CREATE_ALWAYS As UInteger = 2
Public Const OPEN_EXISTING As UInteger = 3
<DllImport("kernel32.dll", SetLastError:=True)>
Shared Function CreateFile(ByVal lpFileName As String, ByVal dwDesiredAccess As UInteger, ByVal dwShareMode As UInteger, ByVal lpSecurityAttributes As IntPtr, ByVal dwCreationDisposition As UInteger, ByVal dwFlagsAndAttributes As UInteger, ByVal hTemplateFile As IntPtr) As SafeFileHandle
End Function
Public Shared Sub sendTextToLPT1(ByVal receiptText As String)
Using ptr As SafeFileHandle = CreateFile("LPT1", GENERIC_WRITE, 0, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero)
' Is bad handle? INVALID_HANDLE_VALUE
If ptr.IsInvalid Then
' ask the framework to marshall the win32 error code to an exception
Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error())
Else
Using lpt As New FileStream(ptr, FileAccess.ReadWrite)
Dim buffer(2047) As Byte
'Check to see if your printer support ASCII encoding or Unicode.
'If unicode is supported, use the following:
'buffer = System.Text.Encoding.Unicode.GetBytes(Temp);
buffer = System.Text.Encoding.ASCII.GetBytes(receiptText)
lpt.Write(buffer, 0, buffer.Length)
lpt.Close()
End Using
End If
End Using
End Sub
Private Sub btnPrint_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
Dim s As String = "C:\vDos\#LPT1.ASC"
Dim p As New PrintDocument()
AddHandler p.PrintPage, Sub(sender1 As Object, e1 As PrintPageEventArgs)
e1.Graphics.DrawString(s, New Font("Times New Roman", 12), New SolidBrush(Color.Black), New RectangleF(0, 0, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height))
End Sub
Try
p.Print()
Catch ex As Exception
Throw New Exception("Exception Occured While Printing", ex)
End Try
End Sub
End Class