Y
yanghai0437
Unregistered / Unconfirmed
GUEST, unregistred user!
因为我在函数的参数中使用了Pchar类型,但是Pb调用时有时候正确有时候不正确,
不知道是为什么,而我用delphi写的测试程序调用就没有问题,请大家帮忙。
function IC_WriteFinger(bufchar;sKeyChar):Integer;
stdcall;
var
Str_char:array[0..256] of char;
my,mm,md:String;
ny,nm,nd:Byte;
i,nLen:Integer;
mStrdata,smKey:String;
mEnDatabuf:String;
st:smallint;
begin
if sKey=nil then
begin
Result:=IC_GetICMainKey_Err;
Exit;
end;
mStrdata :=sKey;
if Length(mStrdata)<1 then
begin
//密钥不正确
Result:=IC_GetICMainKey_Err;
Exit;
end;
//解密
smKey := DESryStr(sKey,StrDES_EncryptKey);
//得到数据
mStrdata := buf;
// StrCopy(PChar(mStrdata),buf);
//加密 数据
mEnDatabuf := EncryStr(mStrdata,smKey);
StrCopy(Str_char,PChar(mEnDatabuf));
nLen:=Length(mEnDatabuf);
st:=swr_xxxx(icdev,32,nLen,Str_char);
//写入数据
if st<>0 then
begin
Result := IC_Write_CARD_ERR;
exit;
end;
Result:=IC_WriteDoorFlag(IC_FLAG_USED);
end;
function IC_GetFinger(nIndex:byte;sKeyChar;bufChar;bIsDp:boolean):Integer;stdcall;
var
Str_char:array[0..200] of char;
mStrdata,menbuf:String;
smKey:String;
_Addr:Integer;
st:smallint;
const
_Length = 200;
begin
if (nIndex<1)or(nIndex>3) then
nIndex:=1;
_Addr :=500;
st:=srd_XXxX(icdev,_Addr,_Length,Str_char);
//读取指定位置的数据
if st <> 0 then
begin
Result := IC_READ_CARD_ERR;
Exit;
end;
mStrdata:='';
mStrdata:=Copy(Str_char,0,_Length);
if bIsDp then
smKey := StrDES_EncryptKey
else
//解密主密钥
smKey := DESryStr(sKey,StrDES_EncryptKey);
//解密数据
menbuf := DESryStr(mStrdata,smKey);
// StrCopy(buf,PChar(menbuf));//这样写就会有时候正确有时候不正确
for i:=1 to length(menbuf)do
buf[i-1] :=membuf;
//这样写就没有出错,但是Pb调用后,pb就会偶尔报错,
Result := IC_SUCCESS;
end;
不知道是为什么,而我用delphi写的测试程序调用就没有问题,请大家帮忙。
function IC_WriteFinger(bufchar;sKeyChar):Integer;
stdcall;
var
Str_char:array[0..256] of char;
my,mm,md:String;
ny,nm,nd:Byte;
i,nLen:Integer;
mStrdata,smKey:String;
mEnDatabuf:String;
st:smallint;
begin
if sKey=nil then
begin
Result:=IC_GetICMainKey_Err;
Exit;
end;
mStrdata :=sKey;
if Length(mStrdata)<1 then
begin
//密钥不正确
Result:=IC_GetICMainKey_Err;
Exit;
end;
//解密
smKey := DESryStr(sKey,StrDES_EncryptKey);
//得到数据
mStrdata := buf;
// StrCopy(PChar(mStrdata),buf);
//加密 数据
mEnDatabuf := EncryStr(mStrdata,smKey);
StrCopy(Str_char,PChar(mEnDatabuf));
nLen:=Length(mEnDatabuf);
st:=swr_xxxx(icdev,32,nLen,Str_char);
//写入数据
if st<>0 then
begin
Result := IC_Write_CARD_ERR;
exit;
end;
Result:=IC_WriteDoorFlag(IC_FLAG_USED);
end;
function IC_GetFinger(nIndex:byte;sKeyChar;bufChar;bIsDp:boolean):Integer;stdcall;
var
Str_char:array[0..200] of char;
mStrdata,menbuf:String;
smKey:String;
_Addr:Integer;
st:smallint;
const
_Length = 200;
begin
if (nIndex<1)or(nIndex>3) then
nIndex:=1;
_Addr :=500;
st:=srd_XXxX(icdev,_Addr,_Length,Str_char);
//读取指定位置的数据
if st <> 0 then
begin
Result := IC_READ_CARD_ERR;
Exit;
end;
mStrdata:='';
mStrdata:=Copy(Str_char,0,_Length);
if bIsDp then
smKey := StrDES_EncryptKey
else
//解密主密钥
smKey := DESryStr(sKey,StrDES_EncryptKey);
//解密数据
menbuf := DESryStr(mStrdata,smKey);
// StrCopy(buf,PChar(menbuf));//这样写就会有时候正确有时候不正确
for i:=1 to length(menbuf)do
buf[i-1] :=membuf;
//这样写就没有出错,但是Pb调用后,pb就会偶尔报错,
Result := IC_SUCCESS;
end;