Attribute VB_Name = "Bxlprint"

    'This file supports all Platforms, but this sample code only supports PDA Platforms
    'so if you want to use this sample code in PC platform, you should create a new project for
    'PC Platform and add file in your project.

   ' Public Const BXLDIR As String = "bxl.dll"
    

    'Method return value
    Public Const BXL_SUCCESS As Integer = 0
    Public Const BXL_READBUFFER_EMPTY As Integer = -1

    Public Const BXL_OTHERPTR_OPENED As Integer = -100
    Public Const BXL_NOT_OPENED As Integer = -101
    Public Const BXL_CREATE_ERROR As Integer = -102
    Public Const BXL_STATUS_ERROR As Integer = -103
    Public Const BXL_WATING_OPEN As Integer = -104
    Public Const BXL_CONNECT_ERROR As Integer = -105
    Public Const BXL_BDADDR_ERROR As Integer = -106
    Public Const BXL_NOT_SUPPORT As Integer = -107
    Public Const BXL_BAD_ARGUMENT As Integer = -108
    Public Const BXL_BUFFER_ERROR   As Integer = -109

    Public Const BXL_REGISTRY_ERROR As Integer = -200
    Public Const BXL_WRITE_ERROR As Integer = -300
    Public Const BXL_READ_ERROR As Integer = -301

    Public Const BXL_BITMAPLOAD_ERROR As Integer = -400
    Public Const BXL_BITMAPDATA_ERROR As Integer = -401

    Public Const BXL_BC_DATA_ERROR As Integer = -500
    Public Const BXL_BC_NOT_SUPPORT As Integer = -501

    'MSR State Return
    Public Const BXLMSR_FAILEDMODE As Integer = -601
    Public Const BXLMSR_NOTREADY As Integer = -602
    Public Const BXLMSR_DATAEMPTY As Integer = -603

    'Printer Status flag
    Public Const BXL_STS_NORMAL As Integer = 0
    Public Const BXL_STS_PAPEREMPTY As Integer = 1
    Public Const BXL_STS_COVEROPEN As Integer = 2
    Public Const BXL_STS_POWEROVER As Integer = 4
    Public Const BXL_STS_MSR_READY As Integer = 8
    Public Const BXL_STS_PRINTING As Integer = 16
    Public Const BXL_STS_ERROR As Integer = 32
    Public Const BXL_STS_NOT_OPEN As Integer = 64
    Public Const BXL_STS_ERROR_OCCUR As Integer = 128

    'Power Status
    Public Const BXL_PWR_HIGH As Integer = 0
    Public Const BXL_PWR_MIDDLE As Integer = 1
    Public Const BXL_PWR_LOW As Integer = 2
    Public Const BXL_PWR_SMALL As Integer = 3
    Public Const BXL_PWR_NOT As Integer = 4

    'Alignment Code
    Public Const BXL_ALIGNMENT_LEFT As Integer = 0
    Public Const BXL_ALIGNMENT_CENTER As Integer = 1
    Public Const BXL_ALIGNMENT_RIGHT As Integer = 2

    '//Text Attribute
    Public Const BXL_FT_DEFAULT As Integer = 0
    Public Const BXL_FT_FONTB As Integer = 1
    Public Const BXL_FT_FONTC As Integer = 16
    Public Const BXL_FT_BOLD As Integer = 2
    Public Const BXL_FT_UNDERLINE As Integer = 4
    Public Const BXL_FT_REVERSE As Integer = 8
    Public Const BXL_ExFT_CHINA_FONTA As Integer = 0
    Public Const BXL_ExFT_CHINA_FONTB As Integer = 32

    'Text Size Attribute
    Public Const BXL_TS_0WIDTH As Integer = 0
    Public Const BXL_TS_1WIDTH As Integer = 16
    Public Const BXL_TS_2WIDTH As Integer = 32
    Public Const BXL_TS_3WIDTH As Integer = 48
    Public Const BXL_TS_4WIDTH As Integer = 64
    Public Const BXL_TS_5WIDTH As Integer = 80
    Public Const BXL_TS_6WIDTH As Integer = 96
    Public Const BXL_TS_7WIDTH As Integer = 112

    Public Const BXL_TS_0HEIGHT As Integer = 0
    Public Const BXL_TS_1HEIGHT As Integer = 1
    Public Const BXL_TS_2HEIGHT As Integer = 2
    Public Const BXL_TS_3HEIGHT As Integer = 3
    Public Const BXL_TS_4HEIGHT As Integer = 4
    Public Const BXL_TS_5HEIGHT As Integer = 5
    Public Const BXL_TS_6HEIGHT As Integer = 6
    Public Const BXL_TS_7HEIGHT As Integer = 7

    'Width Full
    Public Const BXL_WIDTH_FULL As Integer = -1
    Public Const BXL_WIDTH_NONE As Integer = -2

    'Barcode
    Public Const BXL_BCS_PDF417               As Integer = 200
    Public Const BXL_BCS_QRCODE_MODEL2  As Integer = 202
    Public Const BXL_BCS_QRCODE_MODEL1  As Integer = 203
    Public Const BXL_BCS_DATAMATRIX         As Integer = 204
    Public Const BXL_BCS_MAXICODE_MODE2 As Integer = 205
    Public Const BXL_BCS_MAXICODE_MODE3 As Integer = 206
    Public Const BXL_BCS_MAXICODE_MODE4 As Integer = 207

    Public Const BXL_BCS_UPCA As Integer = 101
    Public Const BXL_BCS_UPCE As Integer = 102
    Public Const BXL_BCS_EAN8 As Integer = 103
    Public Const BXL_BCS_EAN13 As Integer = 104
    Public Const BXL_BCS_JAN8 As Integer = 105
    Public Const BXL_BCS_JAN13 As Integer = 106
    Public Const BXL_BCS_ITF As Integer = 107
    Public Const BXL_BCS_Codabar As Integer = 108
    Public Const BXL_BCS_Code39 As Integer = 109
    Public Const BXL_BCS_Code93 As Integer = 110
    Public Const BXL_BCS_Code128 As Integer = 111

    'Barcode text position
    Public Const BXL_BC_TEXT_NONE As Integer = 0
    Public Const BXL_BC_TEXT_ABOVE As Integer = 1
    Public Const BXL_BC_TEXT_BELOW As Integer = 2

   'CharaterSet
    Public Const BXL_CS_PC437 As Integer = 0
    Public Const BXL_CS_PC850 As Integer = 2
    Public Const BXL_CS_PC860 As Integer = 3
    Public Const BXL_CS_PC863 As Integer = 4
    Public Const BXL_CS_PC865 As Integer = 5
    Public Const BXL_CS_WPC1252 As Integer = 16
    Public Const BXL_CS_PC866 As Integer = 17
    Public Const BXL_CS_PC852 As Integer = 18
    Public Const BXL_CS_PC858 As Integer = 19
    Public Const BXL_CS_PC864 As Integer = 22
    Public Const BXL_CS_THAI42 As Integer = 23
    Public Const BXL_CS_WPC1253 As Integer = 24
    Public Const BXL_CS_WPC1254 As Integer = 25
    Public Const BXL_CS_WPC1257 As Integer = 26
    Public Const BXL_CS_FARSI As Integer = 27
    Public Const BXL_CS_WPC1251 As Integer = 28
    Public Const BXL_CS_PC737 As Integer = 29
    Public Const BXL_CS_PC775 As Integer = 30
    Public Const BXL_CS_THAI14 As Integer = 31
    Public Const BXL_CS_PC862 As Integer = 33
    Public Const BXL_CS_THAI11 As Integer = 34
    Public Const BXL_CS_PC855 As Integer = 36
    Public Const BXL_CS_PC857 As Integer = 37
    Public Const BXL_CS_PC928 As Integer = 38
    Public Const BXL_CS_THAI16 As Integer = 39
    Public Const BXL_CS_WPC1256 As Integer = 40
    Public Const BXL_CS_USER As Integer = 255

    'International CharacterSet
    Public Const BXL_ICS_USA As Integer = 0
    Public Const BXL_ICS_FRANCE As Integer = 1
    Public Const BXL_ICS_GERMANY As Integer = 2
    Public Const BXL_ICS_UK As Integer = 3
    Public Const BXL_ICS_DENMARK1 As Integer = 4
    Public Const BXL_ICS_SWEDEN As Integer = 5
    Public Const BXL_ICS_ITALY As Integer = 6
    Public Const BXL_ICS_SPAIN As Integer = 7
    Public Const BXL_ICS_NORWAY As Integer = 9
    Public Const BXL_ICS_DENMARK2 As Integer = 10

    'MSR Mode
    Public Const BXL_MSRMODE_CMDTRACK12 As Integer = 0
    Public Const BXL_MSRMODE_CMDTRACK23 As Integer = 1
    Public Const BXL_MSRMODE_AUTOTRACK1 As Integer = 2
    Public Const BXL_MSRMODE_AUTOTRACK2_1 As Integer = 3
    Public Const BXL_MSRMODE_AUTOTRACK12 As Integer = 4
    Public Const BXL_MSRMODE_AUTOTRACK2_2 As Integer = 5
    Public Const BXL_MSRMODE_AUTOTRACK3 As Integer = 6
    Public Const BXL_MSRMODE_AUTOTRACK23 As Integer = 7
    
    
    Public Const WM_MSR_ARRIVED As Integer = 1027
    Public Const BXL_LPARAM_MSR As Integer = 10

        'wParam argument
    Public Const BXL_MSG_TRACK1 As Integer = 1
    Public Const BXL_MSG_TRACK2 As Integer = 2
    Public Const BXL_MSG_TRACK3 As Integer = 4
    Public Const BXL_MSG_TRACK_ENCRIPTION As Integer = 8
    
    Public Const BXL_PD_LEFT_TO_RIGHT As Integer = 48
    Public Const BXL_PD_BOTTOM_TO_TOP As Integer = 49
    Public Const BXL_PD_RIGHT_TO_LEFT As Integer = 50
    Public Const BXL_PD_TOP_TO_BOTTOM As Integer = 51
    
        'SCR
    Public Const BXL_SCR_RESPONSE_ERR As Integer = -700

    Public Const BXL_SCR_MODE_APDU As Integer = 0
    Public Const BXL_SCR_MODE_TPDU As Integer = 1
                      
    Public Const BXL_SCR_STS_1_8V As Integer = 0
    Public Const BXL_SCR_STS_5V As Integer = 1
    Public Const BXL_SCR_STS_3V As Integer = 2
    Public Const BXL_SCR_STS_POWERED As Integer = 4
    Public Const BXL_SCR_STS_INSERTED As Integer = 8
    
    public const BXL_SCR_SMARTCARD As Integer = 0x30
    public const BXL_SCR_SAM1 As Integer = 0x31
    public const BXL_SCR_SAM2 As Integer = 0x32
    
    
    Public Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
    Public Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
    
    
    Public Declare Function PrinterOpen Lib "bxl" (ByVal strOutPortName As String, ByVal lTimeout As Long) As Long
    Public Declare Function PrinterClose Lib "bxl" () As Long
    
    Public Declare Function PrintText Lib "bxl" (ByVal Data As String, ByVal Alignment As Long, ByVal attr As Long, ByVal TextSize As Long) As Long
    Public Declare Function LineFeed Lib "bxl" (ByVal nFeed As Long) As Long
    Public Declare Function PrintBitmap Lib "bxl" (ByVal FileName As String, ByVal Width As Long, ByVal Alignment As Long, ByVal Level As Long) As Long
    Public Declare Function PrintBarcode Lib "bxl" (ByVal Data As Any, ByVal Symbology As Long, ByVal Height As Long, ByVal Width As Long, ByVal Alignment As Long, ByVal TextPosition As Long) As Long
    
    Public Declare Function SetCharacterSet Lib "bxl" (ByVal Value As Long) As Long
    Public Declare Function SetInterChrSet Lib "bxl" (ByVal Value As Long) As Long
    Public Declare Function GetCharacterSet Lib "bxl" () As Long
    Public Declare Function GetInterChrSet Lib "bxl" () As Long
    
    Public Declare Function DirectIO Lib "bxl" (Data As Any, ByVal iWrite As Long, pRequest As Any, ByRef iRead As Long) As Long
    
    Public Declare Function MsrReadReady Lib "bxl" () As Long
    Public Declare Function MsrReadCancel Lib "bxl" () As Long
    Public Declare Function MsrReadTrack Lib "bxl" (ByVal Data1 As String, ByVal Data2 As String, ByVal Data3 As String) As Long
    Public Declare Function MsrReadFullTrack Lib "bxl" (Data As String, ByVal iLen As Long) As Long
    Public Declare Function MsrRead1Track Lib "bxl" (ByVal Data As String, ByVal iLen As Long) As Long
    Public Declare Function MsrRead2Track Lib "bxl" (ByVal Data As String, ByVal iLen As Long) As Long
    Public Declare Function MsrRead3Track Lib "bxl" (ByVal Data As String, ByVal iLen As Long) As Long
    Public Declare Function GetTrack1 Lib "bxl" () As String
    Public Declare Function GetTrack2 Lib "bxl" () As String
    Public Declare Function GetTrack3 Lib "bxl" () As String   
   
    Public Declare Function CheckPrinter Lib "bxl" () As Long
    Public Declare Function GetPowerValue Lib "bxl" () As Long
    Public Declare Function GetStat Lib "bxl" () As Long
    Public Declare Function GetResultCode Lib "bxl" () As Long
 
    Public Declare Function FormFeed Lib "bxl" (ByVal nFeed As Long) As Long
    Public Declare Function NextPrintPos Lib "bxl" () As Long
    Public Declare Function InitializePrinter Lib "bxl" () As Long
    Public Declare Function SelectMode Lib "bxl" (ByVal bLabelMode As Boolean) As Long
    Public Declare Function AutoCalibration Lib "bxl" () As Long            
   
    Public Declare Function SelectPageMode Lib "bxl" (ByVal bPageMode As Boolean) As Long
    Public Declare Function SetPrintAreaInPageMode Lib "bxl" (ByVal x As Long, ByVal y As Long, ByVal width As Long, ByVal height As Long) As Long
    Public Declare Function SelectPrintDirectionInPageMode Lib "bxl" (ByVal printDirection As Long) As Long
    Public Declare Function SetAbsolutePrintPosition Lib "bxl" (ByVal motionUnit As Long) As Long
    Public Declare Function SetAbsoluteVerticalPrintPositionInPageMode Lib "bxl" (ByVal motionUnit As Long) As Long
    Public Declare Function PrintDataInPageMode Lib "bxl" () As Long
   
    Public Declare Function SetPrintAreaInPM Lib "bxl" (ByVal x As Long, ByVal y As Long, ByVal width As Long, ByVal height As Long) As Long
    Public Declare Function SetPrintDirectionInPM Lib "bxl" (ByVal printDirection As Long) As Long
    Public Declare Function SetVerticalPositionInPM Lib "bxl" (ByVal motionUnit As Long) As Long
    Public Declare Function SetHorizontalPositionInPM Lib "bxl" (ByVal motionUnit As Long) As Long
   
   
    Public Declare Function ScrPowerDown Lib "bxl" (ByRef ResponseS As Byte) As Long
    Public Declare Function ScrPowerUp Lib "bxl" (pATR As Any, ByRef ATRLen As Long, ByRef ResponseS As Byte) As Long
    Public Declare Function ScrExchangeAPDU Lib "bxl" (ByVal pCmdAPDU As Any, ByVal cmdAPDULen As Long, pRspAPDU As Any, ByRef rspAPDULen As Long, ResponseS As Byte) As Long
    Public Declare Function ScrOperationMode Lib "bxl" (ByVal mode As Long, ByRef ResponseS As Byte) As Long
    Public Declare Function ScrChkCardStatus Lib "bxl" (ByRef pStatus As Byte, ByRef ResponseS As Byte) As Long
    Public Declare Function ScrSelectCard Lib "bxl" (ByVal mode As Long, ByRef ResponseS As Byte) As Long
    Public Declare Function ScrGetCard Lib "bxl" () As Long
                              
    Public Function IsValidLib(ByVal LibName As String) As Boolean
        Dim hLib As Long
        hLib = LoadLibrary(LibName)
        If hLib <> 0 Then
            FreeLibrary (hLib)
            IsValidLib = True
        Else
            IsValidLib = False
        End If
    End Function

    Public Function StringToAscii(ByRef Cmd() As Byte, ByVal pos As Integer, ByVal Data As String) As Integer
        Dim i As Integer
        For i = 1 To Len(Data)
            Cmd(pos) = Asc(Mid(Data, i, 1))
            pos = pos + 1
        Next i
        StringToAscii = pos
    End Function



