.net如何实现小票打印?如果测试成功,给100分
目前,做一个用.NET实现小票打印的程序,从目前网上找到的各个版本来讲,都不能很好满足.NET小票打印。
以下程序,不执行打印命令,说是“没有连接打印机或者打印机端口不是LPT1”
到底LPT是否可以用?请高手解决,谢谢。
<%@ import Namespace="System.IO"%>
<script language="vb" runat="server">
Const GENERIC_READ = &H80000000
Const GENERIC_WRITE = &H40000000
Const OPEN_EXISTING = 3
Private yhflag = 0
Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Integer, ByVal dwShareMode As Integer, ByVal lpSecurityAttributes As Integer, ByVal dwCreationDisposition As Integer, ByVal dwFlagsAndAttributes As Integer, ByVal hTemplateFile As Integer) As IntPtr
Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Try
Dim iHandle As IntPtr
iHandle = CreateFile("LPT", GENERIC_READ Or GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0)
If (iHandle.ToInt32 = -1) Then
MsgBox("没有连接打印机或者打印机端口不是LPT1")
Exit Sub
Else
Dim fs As New FileStream(iHandle, FileAccess.ReadWrite)
Dim sr As New StreamReader(fs) '读数据
Dim sw As New StreamWriter(fs, System.Text.Encoding.Default) '写数据
sw.Write("打印了还等什么")
sw.WriteLine() ''得让他分行
sw.WriteLine()
sw.Write((Chr(27)).ToString() + "p" + (Chr(0)).ToString() + ((Chr(60))).ToString() + ((Chr(255))).ToString()) '''''''开钱箱
sw.Close()
fs.Close()
End If
Catch ex As Exception
MsgBox("没有连接打印机!")
End Try
End Sub
</script>