|
发表于 2020-12-19 11:30:01
|
显示全部楼层
上面那个反了。下面这个才正确
extern "C" __declspec(dllexport) __int16 __stdcall ATOH(char *A,char *H,__int16 hlen)
{
__int16 len=2*hlen;
__int16 alen=strlen(A);
__int16 i,j;
char *Au = new char[len];
i=0;
if(alen<len)
{
for(i=0;i<(len-alen);i++)
{
Au[i]=0x30;
}
}
for(;i<len;i++)Au[i]=A[i];
j=0;
for(i=0;i<len;i++)
{
if((Au[i]>0x2f)&&(Au[i]<0x3a))
{
H[j]=Au[i]-0x30;
H[j]=(H[j]<<4)&0xf0;
}
else if((Au[i]>0x40)&&(Au[i]<0x47))
{
H[j]=Au[i]-0x37;
H[j]=(H[j]<<4)&0xf0;
}
else if((Au[i]>0x60)&&(Au[i]<0x67))
{
H[j]=Au[i]-0x57;
H[j]=(H[j]<<4)&0xf0;
}
else H[j]=0;
i++;
if((Au[i]>0x2f)&&(Au[i]<0x3a))
{
H[j]+=Au[i]-0x30;
}
else if((Au[i]>0x40)&&(Au[i]<0x47))
{
H[j]+=Au[i]-0x37;
}
else if((Au[i]>0x60)&&(Au[i]<0x67))
{
H[j]+=Au[i]-0x57;
}
j++;
}
delete []Au;
return j;
}
调用:
//-----------------------------------得到姓名
static unsigned char data[2048];
sTemp1 = "";
sName = "";
iTemp1 = byData[giarIDToAdd[i] + 8];
if(iTemp1 != 0xFF){
for(j=8;j<=15;j++){
if(byData[giarIDToAdd[i] + j]!=32){
iTemp1 = byData[giarIDToAdd[i] + j];
sTemp1 += StrPas(cbf_10_16(iTemp1));
}
}
ATOH(sTemp1.c_str(),data,sTemp1.Length()/2);
sPY = StrPas(cbf_MakeSpellCode(data,2,255));
sName = StrPas(data);
}
//-----------------------------------得到姓名
sTemp1 = "";
sName = " ";
sPY = "";
if(byData[iPos + 8] != 0xFF){
BYTE byName[9];
memset(byName,0,9);
for(j=0;j<8;j++){
if(byData[iPos + 8 + j] != 0xFF){
//if(byData[iPos + 8 + j] < 0x20){
// byName[j] = 0x20;
//}
//else{
byName[j] = byData[iPos + 8 + j];
//}
}
}
char *chName = (char *)byName;
sName = static_cast<AnsiString>(chName);
sPY = StrPas(cbf_MakeSpellCode(chName,2,255));
} |
|