Attribute VB_Name = "Module2"
Private Declare Function GetProfileInt Lib "kernel32" _
    Alias "GetPrivateProfileIntA" (ByVal SecName As String, _
                                   ByVal EntrName As String, _
                                   ByVal DefNum As Integer, _
                                   ByVal FileName As String) As Long

Private Declare Function GetProfileStr Lib "kernel32" _
    Alias "GetPrivateProfileStringA" (ByVal SecName As String, _
                                      ByVal EntrName As String, _
                                      ByVal DefString As String, _
                                      ByVal buff As String, _
                                      ByVal BuffSize As Long, _
                                      ByVal FileName As String) As Long
'DRIVER INFO
Private Const DRIVER_PROFILE_NAME = "driver_list.ini"
Private Const SEC_DRV_INFO = "DRIVER_INFO"
Private Const ENTR_DRV_NUM = "driver_num"
Private Const ENTR_DRV_NAME = "name"
Private Const ENTR_FONT_IDX = "font_index"
Private Const ENTR_FONTS = "font_num"
Private Const ENTR_BARCODE_PRN = "barcode_prn"
Private Const ENTR_PAPER_CUT = "paper_cut"
Private Const ENTR_CUST_DISP = "cust_disp"
Private Const ENTR_PAPER_TYP = "paper_type"
'FONT INFO
Private Const FONT_PROFILE_NAME = "font_list.ini"
Private Const SEC_FONT_INFO = "FONT_INFO"
Private Const ENTR_FONT_NUM = "font_num"
Private Const ENTR_FONT_NAME = "name"
Private Const ENTR_SIZE_NUM = "size_num"
Private Const ENTR_SIZE_1 = "size1"
Private Const ENTR_SIZE_2 = "size2"
Private Const ENTR_FONT_TYPE = "type"
'BARCODE FINT INFO
Private Const BARCODEFONT_PROFILE_NAME = "barcode_list.ini"
Private Const SEC_BARFONT_INFO = "BARCODE_FONT_INFO"
Private Const ENTR_BARFONT_NUM = "font_num"
Private Const ENTR_BARFONT_NAME = "name"
Private Const ENTR_BARSIZE_NUM = "size_num"
Private Const ENTR_BARSIZE_1 = "size1"
Private Const ENTR_BARSIZE_2 = "size2"
Private Const ENTR_BARSIZE_3 = "size3"
Private Const ENTR_BARSIZE_4 = "size4"
Private Const ENTR_BARFONT_TYPE = "type"

Private Const SIZE_PROFILE_DATA = 255
Public Sub Clear_TMPrinterData()
    Erase TMDriver
    intDrvCount = 0
    Erase TMFont
    intPFontCount = 0
    Erase BarcodeFont
    intBFontCount = 0
End Sub

Public Function Init_TMPrinterData()
Dim driver_num As Long
Dim ini_path As String
Dim i As Long
Dim wk_sec_name As String
Dim buff As String * SIZE_PROFILE_DATA
Dim len_buff, wk_len As Long
Dim font_num As Long

    'Initialization of a paper source message.
    TMPaper(0) = "Receipt"
    TMPaper(1) = "Slip"
    TMPaper(2) = "Journal"
    TMPaper(3) = "Validation"
    TMPaper(4) = "Label"
    TMPaper(5) = "Receipt/Journal"
    TMPaper(6) = "Endorse"

    'Initialization of a printer driver table.
    ini_path = App.Path & "\" & DRIVER_PROFILE_NAME
    driver_num = GetProfileInt(SEC_DRV_INFO, ENTR_DRV_NUM, 0, ini_path)
    ReDim TMDriver(driver_num)
    
    For i = 0 To driver_num - 1
        wk_sec_name = "DRV_" & Format$(i + 1, "0000")
        len_buff = GetProfileStr(wk_sec_name, ENTR_DRV_NAME, "", buff, SIZE_PROFILE_DATA, ini_path)
        If (len_buff > 0) Then
            TMDriver(i).Name = Left$(buff, len_buff): buff = ""
            TMDriver(i).idx = GetProfileInt(wk_sec_name, ENTR_FONT_IDX, 0, ini_path)
            TMDriver(i).num = GetProfileInt(wk_sec_name, ENTR_FONTS, 0, ini_path)
            TMDriver(i).BFont = GetProfileInt(wk_sec_name, ENTR_BARCODE_PRN, 0, ini_path)
            TMDriver(i).PCut = GetProfileInt(wk_sec_name, ENTR_PAPER_CUT, 0, ini_path)
            '>>> V1.58 DM-D Sample Modify 1999-11-04 >>>
            'TMDriver(i).CDisplay = GetProfileInt(wk_sec_name, ENTR_CUST_DISP, 0, ini_path)
            TMDriver(i).CDisplay = 1
            '<<< V1.58 DM-D Sample Modify 1999-11-04 <<<
            TMDriver(i).Paper = GetProfileInt(wk_sec_name, ENTR_PAPER_TYP, 0, ini_path)

        End If
    Next i
    intDrvCount = driver_num - 1

    'Initialization of a printer font table.
    ini_path = App.Path & "\" & FONT_PROFILE_NAME
    font_num = GetProfileInt(SEC_FONT_INFO, ENTR_FONT_NUM, 0, ini_path)
    ReDim TMFont(font_num)
    
    For i = 0 To font_num - 1
        wk_sec_name = "FONT_" & Format$(i + 1, "0000")
        len_buff = GetProfileStr(wk_sec_name, ENTR_FONT_NAME, "", buff, SIZE_PROFILE_DATA, ini_path)
        If (len_buff > 0) Then
            wk_len = Len(Trim$(buff)) - 1
            TMFont(i).Name = Left$(buff, wk_len): buff = ""
            TMFont(i).num = GetProfileInt(wk_sec_name, ENTR_SIZE_NUM, 0, ini_path)
            wk_len = GetProfileStr(wk_sec_name, ENTR_SIZE_1, "", buff, SIZE_PROFILE_DATA, ini_path)
            TMFont(i).Size(0) = Left$(buff, wk_len): buff = ""
            wk_len = GetProfileStr(wk_sec_name, ENTR_SIZE_2, "", buff, SIZE_PROFILE_DATA, ini_path)
            TMFont(i).Size(1) = Left$(buff, wk_len): buff = ""
            TMFont(i).Type = GetProfileInt(wk_sec_name, ENTR_FONT_TYPE, 0, ini_path)
        End If
    Next i
    intPFontCount = font_num - 1


    'Initialization of a bar-code font table.
    ini_path = App.Path & "\" & BARCODEFONT_PROFILE_NAME
    font_num = GetProfileInt(SEC_BARFONT_INFO, ENTR_BARFONT_NUM, 0, ini_path)
    ReDim BarcodeFont(font_num)
    
    For i = 0 To font_num - 1
        wk_sec_name = "BARFONT_" & Format$(i + 1, "0000")
        len_buff = GetProfileStr(wk_sec_name, ENTR_BARFONT_NAME, "", buff, SIZE_PROFILE_DATA, ini_path)
        If (len_buff > 0) Then
            wk_len = Len(Trim$(buff)) - 1
            BarcodeFont(i).Name = Left$(buff, wk_len): buff = ""
            BarcodeFont(i).num = GetProfileInt(wk_sec_name, ENTR_BARSIZE_NUM, 0, ini_path)
            wk_len = GetProfileStr(wk_sec_name, ENTR_BARSIZE_1, "", buff, SIZE_PROFILE_DATA, ini_path)
            BarcodeFont(i).Size(0) = Left$(buff, wk_len): buff = ""
            wk_len = GetProfileStr(wk_sec_name, ENTR_BARSIZE_2, "", buff, SIZE_PROFILE_DATA, ini_path)
            BarcodeFont(i).Size(1) = Left$(buff, wk_len): buff = ""
            wk_len = GetProfileStr(wk_sec_name, ENTR_BARSIZE_3, "", buff, SIZE_PROFILE_DATA, ini_path)
            BarcodeFont(i).Size(2) = Left$(buff, wk_len): buff = ""
            wk_len = GetProfileStr(wk_sec_name, ENTR_BARSIZE_4, "", buff, SIZE_PROFILE_DATA, ini_path)
            BarcodeFont(i).Size(3) = Left$(buff, wk_len): buff = ""
            BarcodeFont(i).Type = GetProfileInt(wk_sec_name, ENTR_BARFONT_TYPE, 0, ini_path)
        End If
    Next i
    intBFontCount = font_num - 1

End Function

