Exp=M
ModuleFileName=SoftKey.vb
@end
                                        
Option Strict Off
Option Explicit On 
Imports System.Runtime.InteropServices
Imports System.Text
Public Class SoftKey

    Public LastError As Integer 'Ĵ
    Public KeyPath As String
    Public E_Hkey As String
    Public E_Lkey As String
    '//¶˶my3l_ex̬ĵ
    <DllImport("my3l_ex.dll", CharSet:=CharSet.Ansi)> Public Shared Function FindPort_3(ByVal filename As String, ByVal pos As Integer, ByVal OutPath As StringBuilder) As Integer
    End Function
    <DllImport("my3l_ex.dll", CharSet:=CharSet.Ansi)> Public Shared Function FindPort_4(ByVal filename As String, ByVal pos As Integer, ByVal HKey As String, ByVal LKey As String, ByVal OutPath As StringBuilder) As Integer
    End Function
    <DllImport("my3l_ex.dll", CharSet:=CharSet.Ansi)> Public Shared Function Cal_2(ByVal filename As String, ByVal start As Integer, ByVal vlen As Integer, ByRef ele1 As Byte, ByRef ele2 As Byte, ByRef ele3 As Byte, ByRef ele4 As Byte, ByVal KeyPah As String, ByVal cycle As Integer) As Integer
    End Function
    <DllImport("my3l_ex.dll", CharSet:=CharSet.Ansi)> Public Shared Function GetIDVersionEx(ByRef ID As Integer, ByRef version As Integer, ByVal KeyPah As String) As Integer
    End Function
    <DllImport("my3l_ex.dll", CharSet:=CharSet.Ansi)> Public Shared Function GetVersion_2(ByRef VersionEx As Integer, ByVal KeyPah As String) As Integer
    End Function
    <DllImport("my3l_ex.dll", CharSet:=CharSet.Ansi)> Public Shared Function YReadEx(ByVal Address As Integer, ByRef OutData As Byte, ByVal KeyPah As String) As Integer
    End Function
    <DllImport("my3l_ex.dll", CharSet:=CharSet.Ansi)> Public Shared Function YWriteEx(ByVal InData As Byte, ByVal Address As Integer, ByVal KeyPah As String) As Integer
    End Function
    <DllImport("my3l_ex.dll", CharSet:=CharSet.Ansi)> Public Shared Function ReadString(ByVal OutString As String, ByVal Address As Integer, ByVal vlen As Integer, ByVal KeyPah As String) As Integer
    End Function
    <DllImport("my3l_ex.dll", CharSet:=CharSet.Ansi)> Public Shared Function WriteString(ByVal InString As String, ByVal Address As Integer, ByVal KeyPah As String) As Integer
    End Function
    <DllImport("my3l_ex.dll", CharSet:=CharSet.Ansi)> Public Shared Function FindPort(ByVal pos As Integer, ByVal OutPath As StringBuilder) As Integer
    End Function
    <DllImport("my3l_ex.dll", CharSet:=CharSet.Ansi)> Public Shared Function E_Dec_6(ByVal HKey As String, ByVal LKey As String, ByVal array_ele2() As Byte, ByVal out_array() As Byte, ByVal KeyPah As String) As Integer
    End Function
    <DllImport("my3l_ex.dll", CharSet:=CharSet.Ansi)> Public Shared Function CalculateEx_2(ByVal array_ele() As Byte, ByRef ele1 As Byte, ByRef ele2 As Byte, _
                            ByRef ele3 As Byte, ByRef ele4 As Byte, ByVal KeyPah As String, ByVal mylen As Integer, ByVal cycle As Integer) As Integer
    End Function
    '//ºڽֽתΪַ
    Public Function ByteConvertString(ByVal buffer() As Byte) As String
        Dim null_string() As Char = {Chr(0), Chr(0)}
        Dim encoding As System.Text.Encoding = System.Text.Encoding.Default
        ByteConvertString = encoding.GetString(buffer).TrimEnd(null_string)
    End Function
    '//ºڽַתΪֽ
    Public Function StringConvertByte(ByVal buffer() As Byte, ByVal InS As String) As Boolean
        Try
            Dim n As Integer
            Dim temp() As Byte = System.Text.Encoding.Default.GetBytes(InS)
            If temp.Length > 50 Then Return False
            For n = 1 To temp.Length
                buffer(n - 1) = temp(n - 1)
            Next n
        Catch
            Return True
        End Try
        Return True
    End Function

    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub
    'ȡָеȨ
    Public Function F_ReadKey() As Boolean
        Dim OutData As Byte
        Dim n As Integer
        E_Hkey = ""
        E_Lkey = ""
        For n = 0 To 3
            If YReadEx(n, OutData, KeyPath) <> 0 Then F_ReadKey = False : Exit Function
            If Len(Hex(OutData)) > 1 Then
                E_Hkey = Hex(OutData) + E_Hkey
            Else
                E_Hkey = "0" + Hex(OutData) + E_Hkey
            End If
        Next n
        For n = 4 To 7
            If YReadEx(n, OutData, KeyPath) <> 0 Then F_ReadKey = False : Exit Function
            If Len(Hex(OutData)) > 1 Then
                E_Lkey = Hex(OutData) + E_Lkey
            Else
                E_Lkey = "0" + Hex(OutData) + E_Lkey
            End If
        Next n
        F_ReadKey = True
    End Function


    'GetLastError
    'ĿģȡĴ룬Ϊ0ʾûд
    'ؽĴ
    Public Function YGetLastError() As Integer
        YGetLastError = LastError
    End Function
    
    #INI#
    #Ini_2#
	#Ystrcat#
	#YCompareString#
	#Ystrcpy#
	#YAdd#
	#YSetValue#
	#YDivide#
	#Ymultiply#
	#YDecrease#
	#Ycompare#
	#YCheckKey#
	#YAnd#
	#Yor#
End Class
