使用.net将unicode打印到LPT1点阵打印机?

时间:2014-09-02 18:10:56

标签: .net vb.net winforms unicode printing

我有8个点阵打印机,只有LPT端口。我必须每月打印6张Lacs账单。主要问题是要打印的数据现在是unicode。我正在使用Code:

Public Const FILE_ATTRIBUTE_NORMAL As Short = &H80
Public Const INVALID_HANDLE_VALUE As Short = -1
Public Const GENERIC_READ As UInteger = &H80000000L
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 IntPtr
End Function

Public Shared Sub sendTextToLPT1(ByVal receiptText As String)
    Dim ptr As IntPtr = CreateFile("LPT1", GENERIC_WRITE, 0, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero)
    ' Is bad handle? INVALID_HANDLE_VALUE 
    If ptr.ToInt32() = -1 Then
        ' ask the framework to marshall the win32 error code to an exception 
        Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error())
    Else
        Dim lpt As New FileStream(ptr, FileAccess.ReadWrite)
        Dim buffer(2047) As Byte
        buffer = System.Text.Encoding.Unicode.GetBytes(receiptText)
        lpt.Write(buffer, 0, buffer.Length)
        lpt.Close()
    End If
End Sub

无法使用此代码打印unicode hindi文本。

 如何将unicode印地语数据打印到LPT端口?

0 个答案:

没有答案