Exp=M
ModuleFileName=SoftKey.cls
@end
                                                       
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "SoftKey"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
'//¶˶ClientKeyDll̬ĵ
Private Declare Function ConnectServer Lib "ClientKeyDll" (ByVal servername As String, ByVal port As integer) As Integer
Private Declare Function DisconnectServer Lib "ClientKeyDll" () As Integer
Private Declare Function FindPort_3 Lib "ClientKeyDll" (ByVal filename As String, ByVal pos As Long, ByVal OutPath As String) As Integer
Private Declare Function FindPort_4 Lib "ClientKeyDll" (ByVal filename As String, ByVal pos As Long, ByVal HKey As String, ByVal LKey As String, ByVal OutPath As String) As Integer
Private Declare Function Cal_2 Lib "ClientKeyDll" (ByVal filename As String, ByVal start As Long, ByVal vlen As Integer, ByRef ele1 As Integer, ByRef ele2 As Integer, ByRef ele3 As Integer, ByRef ele4 As Integer, ByVal InPath As String, ByVal cycle As Integer) As Integer
Private Declare Function GetIDVersionEx Lib "ClientKeyDll" (ByRef ID As Long, ByRef version As Integer, ByVal InPath As String) As Integer
Private Declare Function GetVersion_2 Lib "ClientKeyDll" (ByRef VersionEx As Integer, ByVal InPath As String) As Integer
Private Declare Function F_YReadEx Lib "ClientKeyDll" Alias "YReadEx" (ByVal Address As Integer, ByRef OutData As Integer, ByVal InPath As String) As Integer
Private Declare Function F_YWriteEx Lib "ClientKeyDll" Alias "YWriteEx" (ByVal InData As Integer, ByVal Address As Integer, ByVal InPath As String) As Integer
Private Declare Function F_ReadString Lib "ClientKeyDll" Alias "ReadString" (ByVal OutString As String, ByVal Address As Long, ByVal vlen As Long, ByVal Path As String) As Integer
Private Declare Function F_WriteString Lib "ClientKeyDll" Alias "WriteString" (ByVal InString As String, ByVal Address As Long, ByVal Path As String) As Integer
Private Declare Function F_NT_YReadEx Lib "ClientKeyDll" Alias "NT_YReadEx" (ByVal OutData As Long, ByVal Address As Integer, ByVal mylen As Integer, ByVal HKey As String, ByVal LKey As String, ByVal InPath As String) As Integer
Private Declare Function F_NT_YWriteEx Lib "ClientKeyDll" Alias "NT_YWriteEx" (ByVal InData As Long, ByVal Address As Integer, ByVal mylen As Integer, ByVal HKey As String, ByVal LKey As String, ByVal InPath As String) As Integer
Private Declare Function F_NT_ReadString Lib "ClientKeyDll" Alias "NT_ReadString" (ByVal OutString As String, ByVal Address As Integer, ByVal mylen As Long, ByVal HKey As String, ByVal LKey As String, ByVal InPath As String) As Integer
Private Declare Function F_NT_WriteString Lib "ClientKeyDll" Alias "NT_WriteString" (ByVal InString As String, ByVal Address As Integer, ByVal HKey As String, ByVal LKey As String, ByVal InPath As String) As Integer
Private Declare Function FindPort Lib "ClientKeyDll" (ByVal pos As Long, ByVal OutPath As String) As Integer
Private Declare Function E_Dec_6 Lib "ClientKeyDll" (ByVal HKey As String, ByVal LKey As String, ByVal array_ele2 As Long, ByVal out_array As Long, ByVal InPath As String) As Integer
Private Declare Function CalculateEx_2 Lib "ClientKeyDll" (ByVal array_ele As Long, ByRef ele1 As Integer, ByRef ele2 As Integer, _
                         ByRef ele3 As Integer, ByRef ele4 As Integer, ByVal InPath As String, ByVal mylen As Long, ByVal cycle As Long) As Integer
Private Declare sub AutoDisConnect Lib "ClientKeyDll" (ByVal m_timer As Long, ByVal biao As boolean)

public LastError As Long 'Ĵ
public KeyPath As String
Public E_Hkey As String
Public E_Lkey As String

'ȡָеȨ
Public Function F_ReadKey() As Boolean
Dim OutData As Integer
Dim n As Integer
E_HKey=""
E_LKey=""
For n = 0 To 3
  If F_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 F_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


Function StripTerminator(ByVal strString As String) As String
    Dim intZeroPos As Integer

    intZeroPos = InStr(strString, Chr$(0))
    If intZeroPos > 0 Then
        StripTerminator = Left$(strString, intZeroPos - 1)
    Else
        StripTerminator = strString
    End If
    StripTerminator = Trim(StripTerminator)
End Function
'YGetID
'ĿģؼID
'ؽؼID
Public Function YGetID() As Long
    Dim m_Version As Integer
    Dim m_id As Long
     LastError = GetIDVersionEx(m_id, m_Version, KeyPath)
    YGetID = m_id
End Function
'YGetVersion
'ĿģӼİ汾
'ؽӼİ汾
Public Function YGetVersion() As Integer
    Dim m_id As Long
    Dim m_Version As Integer
     LastError = GetIDVersionEx(m_id, m_Version, KeyPath)
    YGetVersion = m_Version
End Function
'YGetVersionEx
'Ŀģؼչ汾
'ؽؼչ汾
Public Function YGetVersionEx() As Integer
   Dim m_VersionEx As Integer
   LastError = GetVersion_2(m_VersionEx, KeyPath)
   YGetVersionEx = m_VersionEx
End Function
'YReadEx
'ĿģӼжȡָⲿݡ
'1Ҫȡڵĵַⲿַռ0ʼ511
'ؽҪȡ
Public Function YReadEx(Address As Integer) As Integer
    If Address < 0 Or Address > 511 Then
        MsgBox "ַȡķΧ", vbOKOnly, ""
        LastError = -8001
        Exit Function
    End If
    LastError = F_YReadEx(Address, YReadEx, KeyPath)
    If LastError <> 0 Then
        MsgBox "ʧ", vbOKOnly, ""
    End If
End Function
'YWriteEx
'Ŀģָд뵽ⲿС
'1Ҫд
'2Ҫдڵĵַⲿַռ0ʼ511ķΧΪ(31-479),ΪЩַܻᱻʹõ
'ؽ0ʾдɹֵʾʧ
Public Function YWriteEx(InData As Integer, Address As Integer) As Integer
    If Address < 31 Or Address > 479 Then
        MsgBox "ַдķΧ31-479ΪЩַܻᱻʹõȷʵҪдЩΧ޸Ӧĸô", vbOKOnly, ""
        LastError = -8001
        Exit Function
    End If
    LastError = F_YWriteEx(InData, Address, KeyPath)
    YWriteEx = LastError
    If LastError <> 0 Then
        MsgBox "дʧ", vbOKOnly, ""
    End If
End Function
'YReadString
'ĿģӼеⲿжȡַ(ȡ̶ȵַ)
'1Ҫȡڵĵַⲿַռ0ʼ511
'.2Ҫȡַĳ
'ؽҪȡ
Public Function YReadString(Address As Integer, ReadLen As Integer) As String
   YReadString = Space$(ReadLen + 1)
    If Address < 0 Or Address + ReadLen - 1 > 511 Then
        MsgBox "ַȡķΧ", vbOKOnly, ""
        LastError = -8001
        Exit Function
    End If
     LastError = F_ReadString(YReadString, Address, ReadLen, KeyPath)
    If LastError <> 0 Then
        MsgBox "Ӵжַʧ", vbOKOnly, ""
    End If
    YReadString = StripTerminator(YReadString)
End Function
'YWriteString
'Ŀģַָд뵽ⲿС(д̶ȵַ)
'1Ҫд뵽еַ
'2Ҫдڵĵַⲿַռ0ʼ511ķΧΪ(31-479),ΪЩַܻᱻʹõ
'ؽؽ<1ʾдʧܣ򷵻дַĳ
Public Function YWriteString(InString As String, Address As Integer) As Integer
    If Address < 31 Or Address + Len(InString) - 1 > 479 Then
        MsgBox "ַдķΧ31-479ΪЩַܻᱻʹõȷʵҪдЩΧ޸Ӧĸô", vbOKOnly, ""
        LastError = -8001
        Exit Function
    End If
    YWriteString = F_WriteString(InString, Address, KeyPath)
    If YWriteString < 1 Then
        LastError = YWriteString
        MsgBox "дַʧ", vbOKOnly, ""
    End If
End Function
'YReadString_2
'ĿģӼеⲿжȡַ(ȡɱ䳤ȵַ)
'1Ҫȡڵĵַⲿַռ0ʼ511
'ؽҪȡ
Public Function YReadString_2(Address As Integer) As String
    Dim ReadLen As Integer
    ReadLen = YReadEx(Address)
    YReadString_2 = YReadString(Address + 1, ReadLen)
End Function
'YWriteString_2
'Ŀģַָд뵽ⲿС(дɱ䳤ȵַ)
'1Ҫд뵽еַ
'2Ҫдڵĵַⲿַռ0ʼ511ķΧΪ(31-479),ΪЩַܻᱻʹõ
'ؽؽ<1ʾдʧܣ򷵻дַĳ
Public Function YWriteString_2(InString As String, Address As Integer) As Integer
    YWriteString_2 = YWriteString(InString, Address + 1)
    LastError = YWriteEx(YWriteString_2, Address)
End Function
'NT_YReadEx(ʱ)
'ĿģӼжȡָڲݡ
'1Ҫȡڵĵַڲַռ0ʼ27
'2,3
'ؽҪȡ
Public Function NT_YReadEx(Address As Integer, HKey As String, LKey As String) As Integer
    If Address < 0 Or Address > 27 Then
        MsgBox "ַȡķΧ", vbOKOnly, ""
        LastError = -8002
        Exit Function
    End If
    Dim buf() As Byte
    ReDim buf(1)
    LastError = F_NT_YReadEx(VarPtr(buf(0)), Address, 1, HKey, LKey, KeyPath)
    If LastError <> 0 Then
        MsgBox "ʧܣǷΪʱֻʱžڲ", vbOKOnly, ""
    End If
    NT_YReadEx = buf(0)
End Function
'NT_YWriteEx(ʱ)
'Ŀģָд뵽ڲС
'1Ҫд
'2Ҫдڵĵַڲַռ0ʼ27
'3,4д
'ؽ0ʾдɹֵʾʧ
Public Function NT_YWriteEx(InData As Integer, Address As Integer, HKey As String, LKey As String) As Integer
    If Address < 0 Or Address > 27 Then
        MsgBox "ַΧ", vbOKOnly, ""
        LastError = -8002
        Exit Function
    End If
    Dim buf() As Byte
    ReDim buf(0)
    buf(0) = InData
    LastError = F_NT_YWriteEx(VarPtr(buf(0)), Address, 1, HKey, LKey, KeyPath)
    NT_YWriteEx = LastError
    If LastError <> 0 Then
        MsgBox "дʧܣǷΪʱֻʱžڲ", vbOKOnly, ""
    End If
End Function
'NT_YReadString(ʱ)
'ĿģӼеڲжȡַ(ȡ̶ȵַ)
'1Ҫȡڵĵַڲַռ0ʼ27
'.2Ҫȡַĳ
'3,4
'ؽҪȡ
Public Function NT_YReadString(Address As Integer, ReadLen As Long, HKey As String, LKey As String) As String
     NT_YReadString = Space$(ReadLen + 1)
    If Address < 0 Or Address + ReadLen - 1 > 27 Then
        MsgBox "ַȡķΧ", vbOKOnly, ""
        LastError = -8001
        Exit Function
    End If
     LastError = F_NT_ReadString(NT_YReadString, Address, ReadLen, HKey, LKey, KeyPath)
    If LastError <> 0 Then
        MsgBox "ӴжַʧܣǷΪʱֻʱžڲ", vbOKOnly, ""
    End If
    NT_YReadString = StripTerminator(NT_YReadString)
End Function
'NT_YWriteString(ʱ)
'Ŀģַָд뵽ڲС(д̶ȵַ)
'1Ҫд뵽еַ
'2Ҫдڵĵַڲַռ0ʼ27
'3,4д
'ؽؽ<1ʾдʧܣ򷵻дַĳ
Public Function NT_YWriteString(InString As String, Address As Integer, HKey As String, LKey As String) As Integer
    If Address < 0 Or Address + Len(InString) - 1 > 27 Then
        MsgBox "ַΧ", vbOKOnly, ""
        LastError = -8002
        Exit Function
    End If
    NT_YWriteString = F_NT_WriteString(InString, Address, HKey, LKey, KeyPath)
    LastError = NT_YWriteString
    If NT_YWriteString < 1 Then
        MsgBox "дַʧܣǷΪʱֻʱžڲ", vbOKOnly, ""
    End If
End Function
'NT_YReadString_2(ʱ)
'ĿģӼеڲжȡַ(ȡɱ䳤ȵַ)
'1Ҫȡڵĵַڲַռ0ʼ27
'2,3
'ؽҪȡ
Public Function NT_YReadString_2(Address As Integer, HKey As String, LKey As String) As String
    Dim ReadLen As Long
    ReadLen = NT_YReadEx(Address, HKey, LKey)
    NT_YReadString_2 = NT_YReadString(Address + 1, ReadLen, HKey, LKey)
End Function
'NT_YWriteString_2(ʱ)
'Ŀģַָд뵽ڲС(дɱ䳤ȵַ)
'1Ҫд뵽еַ
'2Ҫдڵĵַڲַռ0ʼ27
'3,4д
'ؽؽ<1ʾдʧܣ򷵻дַĳ
Public Function NT_YWriteString_2(InString As String, Address As Integer, HKey As String, LKey As String) As Integer
    NT_YWriteString_2 = NT_YWriteString(InString, Address + 1, HKey, LKey)
    LastError = NT_YWriteEx(NT_YWriteString_2, Address, HKey, LKey)
End Function


'GetLastError
'ĿģȡĴ룬Ϊ0ʾûд
'ؽĴ
Public Function YGetLastError() As Long
    YGetLastError = LastError
End Function

'ServerConnect
'Ŀģӷ
'1servername ҪӵķƻIPַ
'2port Ӷ˿,˿ںſԶ
'ؽ0ʾɹӷʾʧ
'ע⣺ʹκκ֮ǰһҪȵøúini֮ǰڳ˳ʱмһҪʹDisConnectServerϿ
Public Function ServerConnect(servername As String, port As integer)As Integer
	ServerConnect=ConnectServer(servername,port)
	if ServerConnect<>0 then 
		  MsgBox "ӷ򣬴Ϊ" + Str(ServerConnect)
	end if
        AutoDisConnect 60000, True 'ڳʱԶϿЧӣʱʱΪ60
End Function

'ServerDisConnect
'ĿģϿ
'ؽ0ʾɹϿʾʧ
'ע⣺ڳ˳ʱмһҪʹDisConnectServerϿ
Public Function ServerDisConnect()
       DisconnectServer
End Function

#ini#

#Ini_2#

#Ystrcat#

#YCompareString#

#Ystrcpy#

#YAdd#

#YSetValue#

#YDivide#

#Ymultiply#

#YDecrease#

#Ycompare#

#CheckKey#

#YAnd#

#Yor#