Exp=M
ModuleFileName=SoftKey.cpp
@end
                                        
//´칤Զɣѡģ顱
#include "stdafx.h"
#include <time.h>
#include <math.h>
#include <string.h>
#include "Client.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

BOOL SoftKey::load_lib(void)
{
		hlib=LoadLibraryW(L"ClientKeyDll");
		l_ConnectServer=(int  (__stdcall * ) (char *,int ))GetProcAddress(hlib,"ConnectServer"); 
		if(l_ConnectServer==NULL)return FALSE;
		l_DisconnectServer=(int (__stdcall * ) ())GetProcAddress(hlib,"DisconnectServer"); 
		if(l_DisconnectServer==NULL)return FALSE;
		l_FindPort_2=(int (__stdcall *)(  int ,char *,int ,char *))GetProcAddress(hlib,"FindPort_2");
		if(l_FindPort_2==NULL)return FALSE;
		l_FindPort_3=(int (__stdcall *)(char  *,   int ,char *))GetProcAddress(hlib,"FindPort_3");
		if(l_FindPort_3==NULL)return FALSE;
		l_FindPort_4=(int (__stdcall *)(char  *,   int ,char *,char *,char *))GetProcAddress(hlib,"FindPort_4");
		if(l_FindPort_4==NULL)return FALSE;
		l_Cal_2=(int (__stdcall *)(char  *, int ,int ,BYTE * ,BYTE * ,
								 BYTE * ,BYTE * ,char *,int ))GetProcAddress(hlib,"Cal_2");
		if(l_Cal_2==NULL)return FALSE;
		l_CalculateEx_3=(int (__stdcall *)(char  *, int ,int , BYTE * ,BYTE * ,
								 BYTE * ,BYTE * ,char *,int ))GetProcAddress(hlib,"CalculateEx_3");
		if(l_CalculateEx_3==NULL)return FALSE;
		l_E_Ex_3=(int (__stdcall*)(char * ,char *,char *,char *,char *))GetProcAddress(hlib,"E_Ex_3");
		if(l_E_Ex_3==NULL)return FALSE;
		l_YReadEx=(int (__stdcall*)(short ,BYTE *,char *))GetProcAddress(hlib,"YReadEx");
		if(l_YReadEx==NULL)return FALSE;
		l_E_Dec_6=(int (__stdcall*)(char * ,char *,BYTE * ,BYTE *,char *))GetProcAddress(hlib,"E_Dec_6");
		if(l_E_Dec_6==NULL)return FALSE;
		l_FindPort=(int (__stdcall *)(  int ,char *))GetProcAddress(hlib,"FindPort");
		if(l_FindPort==NULL)return FALSE;
		l_CalculateEx_2=(int (__stdcall *)(BYTE  *,  BYTE * ,BYTE * ,
								 BYTE * ,BYTE * ,char *,int,int ))GetProcAddress(hlib,"CalculateEx_2");
		if(l_CalculateEx_2==NULL)return FALSE;
		l_AutoDisConnect=(void (__stdcall*)(int ,BOOL))GetProcAddress(hlib,"AutoDisConnect");
		if(l_AutoDisConnect==NULL)return FALSE;
	return TRUE;
}
//'ServerConnect
//'Ŀģӷ
//'1servername ҪӵķƻIPַ
//'2port Ӷ˿,˿ںſԶ
//'ؽ0ʾɹӷʾʧ
//'ע⣺ʹκκ֮ǰһҪȵøúini֮ǰڳ˳ʱмһҪʹDisConnectServerϿ
int SoftKey::ConnectServer (WCHAR *InServerName,int Port)
{
	char *ServerName=NULL;
	int numlen;
	numlen=WideCharToMultiByte(0,0,InServerName,-1,NULL,0,NULL,FALSE);
	if(numlen>0)
	{
		ServerName=new char[numlen];
		WideCharToMultiByte(0,0,InServerName,-1,ServerName,numlen,NULL,FALSE);
	}
	int ret;
	ret=(*l_ConnectServer)(ServerName,Port);
	if (ret!=0 )
	{
		  MessageBoxW(NULL, L"ӷ" ,L"",MB_OK);
	}
	AutoDisConnect(60000, TRUE); //'ڳʱԶϿЧӣʱʱΪ60
	delete [] ServerName;
	return	ret;
}
int SoftKey::DisconnectServer ()
{
	return (*l_DisconnectServer)();
}
int SoftKey::FindPort(  int start,char *OutPath)
{
	return (*l_FindPort)(start,OutPath);
}
int SoftKey::FindPort_2(  int start,char *FileName,int pos,char *OutPath)
{
	return (*l_FindPort_2)(start,FileName,pos,OutPath);
}
int SoftKey::FindPort_3(char  *FileName,   int pos,char *OutPath)
{
	return (*l_FindPort_3)(FileName,pos,OutPath);
}
int SoftKey::FindPort_4(char  *FileName,   int pos,char *HKey,char *LKey,char *OutPath)
{
	return (*l_FindPort_4)(FileName,pos,HKey,LKey,OutPath);
}
int SoftKey::Cal_2(char  *FileName, int start,int len,BYTE * ele1,BYTE * ele2,
						 BYTE * ele3,BYTE * ele4,char *InPath,int cycle)
{
	return (*l_Cal_2)(FileName,start,len,ele1,ele2,ele3,ele4,InPath,cycle);
}
int SoftKey::CalculateEx_3(char  *FileName, int start,int len, BYTE * ele1,BYTE * ele2,
						 BYTE * ele3,BYTE * ele4,char *InPath,int cycle)
{
	return (*l_CalculateEx_3)(FileName,start,len,ele1,ele2,ele3,ele4,InPath,cycle);
}
int SoftKey::E_Ex_3(char * HKey,char *LKey,char *FileName,char *DestName,char *InPath)
{
	return (*l_E_Ex_3)(HKey,LKey,FileName,DestName,InPath);
}
int SoftKey::YReadEx(short Address,BYTE *OutData,char *InPath)
{
	return (*l_YReadEx)( Address,OutData,InPath);
}

int SoftKey::E_Dec_6(char * HKey,char *LKey,BYTE * array_ele2,BYTE *out_array,char *InPath)
{
	return (*l_E_Dec_6)(HKey,LKey,array_ele2,out_array,InPath);
}

int SoftKey::CalculateEx_2( BYTE * array_ele, BYTE * ele1,BYTE * ele2,
						 BYTE * ele3,BYTE * ele4,char *InPath,int len,int cycle)
{
	return (*l_CalculateEx_2)( array_ele,  ele1, ele2, ele3, ele4,InPath,len,cycle);
}
void SoftKey::AutoDisConnect(int timer,BOOL biao)
{
	 (*l_AutoDisConnect)(timer,biao);
}
SoftKey::SoftKey()
{
	LastError=0;
	ZeroMemory(KeyPath,sizeof(KeyPath));
	if(!load_lib())
	{
		MessageBoxW(NULL,L"ҲClientKeyDll̬⣬ȷϵͳдӦĶ̬⣬Ȼг",L"",MB_OK);
	}
}

SoftKey::~SoftKey()
{
	FreeLibrary(hlib);
}

//GetLastError
//ĿģȡĴ룬Ϊ0ʾûд
//ؽĴ
int SoftKey::YGetLastError()
{
	return LastError;
}

#Ini#

#Ini_2#

#compare#

#YAdd#

#YCheckKey#

#YCompareString#

#YCompareStringNoCase#

#YDecrease#

#YDivide#

#Ymultiply#

#YSetValue#

#Ystrcat#

#Ystrcpy#

#Ystrncat#

#YAnd#

#Yor#

