Exp=M
ModuleFileName=SoftKey.sru
@end
$PBExportHeader$softkey.sru
forward
global type softkey from nonvisualobject
end type
end forward

global type softkey from nonvisualobject
end type
global softkey softkey

type prototypes
//ڹȫⲿú
PUBLIC FUNCTION int FindPort_3 (string filename,int pos,ref string keypath_1) LIBRARY "my3l_ex.DLL"
PUBLIC FUNCTION int Cal_2(string FileName, int start,int len,ref int ele1,ref int ele2,ref int  ele3,ref int  ele4,string InPath,int cycle) LIBRARY "my3l_ex.DLL" 
PUBLIC FUNCTION int y_or (int p1,int p2) LIBRARY "my3l_ex.DLL"
PUBLIC FUNCTION int y_and (int p1,int p2) LIBRARY "my3l_ex.DLL"
PUBLIC FUNCTION int stoi_2 (string inchar,ref int yp1,ref int yp2) LIBRARY "my3l_ex.DLL"
PUBLIC FUNCTION int itos_2 (int p1,int p2,ref string outchar) LIBRARY "my3l_ex.DLL" 
PUBLIC FUNCTION int FindPort_4 (string filename,int pos,ref string HKey,ref string LKey,ref string keypath_1) LIBRARY "my3l_ex.DLL" 
PUBLIC FUNCTION int FindPort(int pos,ref string keypath_1) LIBRARY "my3l_ex.DLL" 
PUBLIC FUNCTION int CalculateEx_2(char EncData [], ref int ele1,ref int ele2,ref int  ele3,ref int  ele4,string keypath_1,int nlen,int  Cycle)LIBRARY "my3l_ex.DLL" 
PUBLIC FUNCTION int E_Dec_6(string HKey, string LKey, char InData_2 [] , ref char OutPData [],string keypath_1)LIBRARY "my3l_ex.DLL" 
PUBLIC FUNCTION int GetIDVersionEx (ref long ID, ref int version, string keypath_1)LIBRARY "my3l_ex.DLL" 
PUBLIC FUNCTION int YReadEx (int Address, ref int OutDatar, string keypath_1) LIBRARY "my3l_ex.DLL"
PUBLIC FUNCTION int YWriteEx (int InData, int Address, string keypath_1) LIBRARY "my3l_ex.DLL"
PUBLIC FUNCTION int ReadString (ref string OutString, int Address , int nlen, string keypath_1) LIBRARY "my3l_ex.DLL" 
PUBLIC FUNCTION int WriteString (string InString, int Address, string keypath_1)LIBRARY "my3l_ex.DLL" 	
end prototypes

type variables
long lasterror
string KeyPath;
//lasterrorĴKeyPathڵ豸·
string E_Hkey  //ȨŸ8λ
string E_Lkey //Ȩŵ8λ
end variables

forward prototypes
public subroutine ini ()
public function long getlasterror ()
public function boolean checkkey ()
public subroutine ini_2 (string HKey,string LKey)
public function long yadd (  long a, long b )
public function Boolean yand ( Boolean a, Boolean b )
public function boolean Ycompare ( long yp1, long yp2, string exp )
public function boolean ycomparestring ( string s1, string s2, string exp)
public function long ydecrease (  long a, long b )
public function long ydivide (  long a, long b )
public function long ymultiply ( long a, long b )
public function Boolean yor ( Boolean a, Boolean b )
public function long ysetvalue ( long a )
public function string ystrcat ( string s1, string s2)
public function string ystrcpy (  string s1)
public function unsignedlong y_xor (unsignedlong n1, unsignedlong n2)
public function boolean  F_ReadKey()
public function string uf_long2hex (unsignedlong ai_value)
end prototypes

public function string uf_long2hex (unsignedlong ai_value);  string bin,hex
  String   ls_return   
  Long   lenbin,duan,i,j   
  String   aa[50],a[50],b[4]   
    

  if   ai_value   =   0   then   
  return   '00'   
  else   
  do   while   ai_value   >   0   
  bin   =   bin   +   String(Mod(ai_value,2))   
  ai_value   =   ai_value   /   2   
  loop   
  end   if   
    


  lenbin   =   Len(bin)   
  if   Mod(lenbin,4)   >   0   then   
  duan   =   lenbin   /   4   +   1   
  else   
  duan   =   lenbin   /4   
  end   if   
  for   i   =   duan   To   1   Step   -1   
  aa[duan]   =   Mid(bin,i   *   4   -   3   ,4)   
  a[duan]   =   '0'   
  for   j   =   1   To   4   
  b[j]   =   Mid(aa[duan],j,1)   
  if   b[j]   <>   ''   then   
  a[duan]   =   String(Integer(a[duan])   +   2^(j   -1   )   *   Integer(b[j]))   
  end   if   
  choose   case   Integer(a[duan])   
  case   10   
  a[duan]   =   'A'   
  case   11   
  a[duan]   =   'B'   
  case   12   
  a[duan]   =   'C'   
  case   13   
  a[duan]   =   'D'   
  case   14   
  a[duan]   =   'E'   
  case   15   
  a[duan]   =   'F'   
  end   choose   
  next   
  hex   =   hex   +   a[duan]   
  next   
  ls_return   =   hex    
    
  if   len(ls_return)   <   2   then   
  ls_return   =   '0'   +   ls_return   
  end   if   
    
  return   ls_return   
    
    

end function

public function boolean  F_ReadKey();
//ȡָеȨ
int OutData
int n
E_HKey=""
E_LKey=""
For n = 0 To 3
  If YReadEx(n, OutData, KeyPath) <> 0 Then return False
  If Len(uf_long2hex(OutData)) > 1 Then
    E_Hkey = uf_long2hex(OutData) + E_Hkey
  Else
   E_Hkey = "0" + uf_long2hex(OutData) + E_Hkey
  End If
Next 
For n = 4 To 7
  If YReadEx(n, OutData, KeyPath) <> 0 Then return False
  If Len(uf_long2hex(OutData)) > 1 Then
    E_Lkey = uf_long2hex(OutData) + E_Lkey
  Else
   E_Lkey = "0" + uf_long2hex(OutData) + E_Lkey
  End If
Next 
return  True
End Function

public function unsignedlong y_xor (unsignedlong n1, unsignedlong n2); unsignedlong     max,n,rtn;   
  long   i;   
  boolean   bit1[1   to   32],bit2[1   to   32];   
  /////////   
  max   =   2^32   -1;   
  for   i=1   to   32   
  bit1[i]=false     
  bit2[i]=false   
  next   
  for   i=31   to   0   step   -1   
  n   =   2^i;   
  if   n1>=n   then   
  bit1[i+1]=true;   
  n1   =   n1   -   n;   
  else   
  bit1[i+1]=false;   
  end   if   
  if   n2>=n   then   
  bit2[i+1]=true;   
  n2   =   n2   -   n;     
  else   
  bit2[i+1]=false;   
  end   if   
  next   
  for   i=1   to   32   
  if   bit1[i]   <>   bit2[i]   then   
  rtn   +=   2^(i   -1);   
  end   if   
  next      
    
  return   rtn;   

end function

public function long getlasterror ();
//GetLastError
//ĿģȡĴ룬Ϊ0ʾûд
//ؽĴ
//ע⣺ûڳʼһȫֱlong lasterror
	return LastError  
end function

#ini#
#CheckKey#
#Ini_2#
#YAdd#
#Yand#
#Ycompare#
#YCompareString#
#YDecrease#
#YDivide#
#Ymultiply#
#Yor#
#YSetValue#
#Ystrcat#
#Ystrcpy#

on softkey.create
call super::create
TriggerEvent( this, "constructor" )
end on

on softkey.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on

