//获取硬盘序列号
void Getnum()
{
BOOL res;
char strDriver[]="C:\\";
char strVolName[256];
DWORD nVolNum;
DWORD nMcm;
DWORD nFsf;
char strFsys[256];
DWORD nID;
CString strID;
CString strTemp;
res=GetVolumeInformation(strDriver,strVolName,127,&nVolNum,&nMcm,&nFsf,strFsys,127);
nID=nVolNum+123456789;
strID.Format("%d",nID);
for(int i=0;i {
strTemp.AppendChar(strID[strID.GetLength()-1-i]);
}
SetDlgItemText(IDC_EDIT1,strTemp.GetBuffer());
}
//验证注册码
void YanZheng()
{
char strNew1[256];
char strNew2[256];
char strNew[256];
CString strTemp;
int nTemp;
int nNum;
GetDlgItemText(IDC_EDIT1,strNew1,256);
GetDlgItemText(IDC_EDIT2,strNew2,256);
GetDlgItemText(IDC_EDIT2,strNew,256);
nNum=atoi(strNew2);
nNum+=123456789;
strTemp.Format("%d",nNum);
nTemp=strlen(strNew2);
for(int j=0;j {
strNew2[j]=strTemp[nTemp-1-j];
}
if(strcmp(strNew1,strNew2)==0)
{
WriteRegSN("sn1",atoi(strNew1));
WriteRegSN("sn2",atoi(strNew));
WriteRegSN("Isrun",1);
AfxMessageBox("注册成功,谢谢!");
}
else
{
AfxMessageBox("注册失败,请重新注册!");
}
}
//从注册表读取信息
int ReadRegSN(char *ValueName)
{
HKEY hKey;
int reValue;
DWORD dwtype;
DWORD sl=256;
char sz[256];
LONG lResult=RegOpenKey(HKEY_LOCAL_MACHINE,"SOFTWARE\\EaOilCan",&hKey);
if (lResult !=ERROR_SUCCESS)
{
//AfxMessageBox("读取信息错误!");
return -1;
}
lResult=RegQueryValueEx(hKey,ValueName,NULL,&dwtype,(LPBYTE)sz,&sl);
if(lResult != ERROR_SUCCESS)
{
//AfxMessageBox("读取信息错误!");
return -1;
}
reValue=atoi(sz);
RegCloseKey(hKey);
return reValue;
}
//在注册表中写入数据
BOOL CSnDlg::WriteRegSN(char *ValueName,int nValue)
{
HKEY hKey;
unsigned char sz[10];
char sTemp[10];
DWORD sl=10;
_itoa(nValue,sTemp,10);
strcpy((char*)sz,sTemp);
DWORD dwtype=REG_SZ;
LONG lResult=RegOpenKey(HKEY_LOCAL_MACHINE,"SOFTWARE\\EaOilCan",&hKey);
if (lResult != ERROR_SUCCESS)
{
AfxMessageBox("写入信息错误!");
return FALSE;
}
lResult=RegSetValueEx(hKey,ValueName,NULL,dwtype,sz,sl);
if(lResult != ERROR_SUCCESS)
{
AfxMessageBox("写入读取信息错误!");
return FALSE;
}
RegCloseKey(hKey);
return TRUE;
}
//程序开始处的判断
nNum=ReadReg();
nIsrun=ReadRegIsrun();
if(nIsrun !=2)
{
if(nIsrun != 1)
{
CSnDlg snDlg;
snDlg.DoModal();
if(nNum>0)
{
WriteReg(nNum-1);
}
else
{
WriteRegIsrun(2);
AfxMessageBox("试用期已到,请与公司联系获得正式版本!");
exit(0);
}
}
else
{
}
}
else
{
AfxMessageBox("试用期已结束,请与公司联系获得正式版本!");
exit(1);
}
阅读(744) | 评论(0) | 转发(0) |