读IC卡问题,DELPHI环境下编译运行正确,独立运行出错.请前辈救急! 我只有这么多分了!!!! ( 积分: 100 )

  • 主题发起人 主题发起人 jxdxlzx
  • 开始时间 开始时间
J

jxdxlzx

Unregistered / Unconfirmed
GUEST, unregistred user!
var
Form1: TForm1;
function OpenPort(PortName:string;PortHandle:ip):integer;stdcall;external 'micro900.dll';
function ClosePort():integer;stdcall;external 'micro900.dll';
function SelectPort(PortHandle:integer):integer;stdcall;external 'micro900.dll';
function PowerOn():integer;stdcall;external 'micro900.dll';
function PowerOff():integer;stdcall;external 'micro900.dll';
function CardPresent():integer;stdcall;external 'micro900.dll';
function CardChanged():integer;stdcall;external 'micro900.dll';
function GetCardType(ATRBuffer:string):integer;stdcall;external 'micro900.dll';
function GetCardName(CardType:integer):pchar;stdcall;external 'micro900.dll';
function Read_4428_With_PB(StrartPos:integer;NOB:integer;Bfr:Pchar;PB_Bfr:Pchar):Integer;stdcall;external 'micro900.dll';
function Read_4442_With_PB(StrartPos:integer;NOB:integer;Bfr:Pchar;PB_Bfr:Pchar):Integer;stdcall;external 'micro900.dll';
function Write_4442_PB(StrartPos:integer):Integer;stdcall;external 'micro900.dll';
function Write_4442(StrartPos:integer;DestByte:char;PBSetFlag:char):Integer;stdcall;external 'micro900.dll';
function Write_4442_Array(StrartPos:integer;NOB:integer;Bfr:Pchar;PB_Bfr:Pchar):Integer;stdcall;external 'micro900.dll';
function Verify_4442_PSC(PSC1:Char;PSC2:char;PSC3:char):Integer;stdcall;external 'micro900.dll';
function Read_4442_SM(SM_Bfr:Pchar):Integer;stdcall;external 'micro900.dll';
function Write_4442_SM(SMAddress:integer;SMByte:char):Integer;stdcall;external 'micro900.dll';

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
result,aa,bb:integer;
porth:ip;
ATR:Pchar;
cc:string;
gg:string;
StrartPos:integer;
NOB:integer;
Bfr:array[0..1024] of char;
PB_Bfr:array[0..1024] of char;
begin
aa:=0;
porth:=@aa;
result:=OpenPort('COM1',Porth);
bb:=porth^;
cc:=inttostr(bb);
edit1.Text:=cc;
result:=CardPresent();
if result<>1 then
showmessage('没有插入IC卡')
else
begin
edit1.Text:='有IC卡';
if CardChanged()<>1 then
showmessage('没换IC卡')
else
edit2.Text:='新IC卡';
result:=GetCardType(ATR); ////////可能错在此处,在DELPHI环境下编译运行可以返回正确的值,独立运行时不能返回正确的值.未安装DELPHI的机子上运行可以得出正确结果,安装了DELPHI后就不能独立运行得出正确结果..呜呜呜.....///
edit3.Text:=atr^;
edit4.Text:=inttostr(result);
if result>0 then
begin
gg:=GetCardName(result);
edit5.Text:=gg;
if result=4 then
begin
StrartPos:=0;
NOB:=1024;
gg:='1111';
result:=Read_4428_With_PB(StrartPos,NOB,Bfr,PB_Bfr);
gg:=bfr;
edit3.Text:=inttohex(strtoint(inttostr(ord(bfr[17]))),2)+' '+ inttohex(strtoint(inttostr(ord(bfr[18]))),2)+' '+ inttohex(strtoint(inttostr(ord(bfr[19]))),2);
edit6.Text:='line'+#100#101#102;
edit7.Text:='hex'+chr(strtoint('$65'))+chr(strtoint('$66'));
end;
end;

end;

end;
 
var
Form1: TForm1;
function OpenPort(PortName:string;PortHandle:ip):integer;stdcall;external 'micro900.dll';
function ClosePort():integer;stdcall;external 'micro900.dll';
function SelectPort(PortHandle:integer):integer;stdcall;external 'micro900.dll';
function PowerOn():integer;stdcall;external 'micro900.dll';
function PowerOff():integer;stdcall;external 'micro900.dll';
function CardPresent():integer;stdcall;external 'micro900.dll';
function CardChanged():integer;stdcall;external 'micro900.dll';
function GetCardType(ATRBuffer:string):integer;stdcall;external 'micro900.dll';
function GetCardName(CardType:integer):pchar;stdcall;external 'micro900.dll';
function Read_4428_With_PB(StrartPos:integer;NOB:integer;Bfr:Pchar;PB_Bfr:Pchar):Integer;stdcall;external 'micro900.dll';
function Read_4442_With_PB(StrartPos:integer;NOB:integer;Bfr:Pchar;PB_Bfr:Pchar):Integer;stdcall;external 'micro900.dll';
function Write_4442_PB(StrartPos:integer):Integer;stdcall;external 'micro900.dll';
function Write_4442(StrartPos:integer;DestByte:char;PBSetFlag:char):Integer;stdcall;external 'micro900.dll';
function Write_4442_Array(StrartPos:integer;NOB:integer;Bfr:Pchar;PB_Bfr:Pchar):Integer;stdcall;external 'micro900.dll';
function Verify_4442_PSC(PSC1:Char;PSC2:char;PSC3:char):Integer;stdcall;external 'micro900.dll';
function Read_4442_SM(SM_Bfr:Pchar):Integer;stdcall;external 'micro900.dll';
function Write_4442_SM(SMAddress:integer;SMByte:char):Integer;stdcall;external 'micro900.dll';

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
result,aa,bb:integer;
porth:ip;
ATR:Pchar;
cc:string;
gg:string;
StrartPos:integer;
NOB:integer;
Bfr:array[0..1024] of char;
PB_Bfr:array[0..1024] of char;
begin
aa:=0;
porth:=@aa;
result:=OpenPort('COM1',Porth);
bb:=porth^;
cc:=inttostr(bb);
edit1.Text:=cc;
result:=CardPresent();
if result<>1 then
showmessage('没有插入IC卡')
else
begin
edit1.Text:='有IC卡';
if CardChanged()<>1 then
showmessage('没换IC卡')
else
edit2.Text:='新IC卡';
result:=GetCardType(ATR); ////////可能错在此处,在DELPHI环境下编译运行可以返回正确的值,独立运行时不能返回正确的值.未安装DELPHI的机子上运行可以得出正确结果,安装了DELPHI后就不能独立运行得出正确结果..呜呜呜.....///
edit3.Text:=atr^;
edit4.Text:=inttostr(result);
if result>0 then
begin
gg:=GetCardName(result);
edit5.Text:=gg;
if result=4 then
begin
StrartPos:=0;
NOB:=1024;
gg:='1111';
result:=Read_4428_With_PB(StrartPos,NOB,Bfr,PB_Bfr);
gg:=bfr;
edit3.Text:=inttohex(strtoint(inttostr(ord(bfr[17]))),2)+' '+ inttohex(strtoint(inttostr(ord(bfr[18]))),2)+' '+ inttohex(strtoint(inttostr(ord(bfr[19]))),2);
edit6.Text:='line'+#100#101#102;
edit7.Text:='hex'+chr(strtoint('$65'))+chr(strtoint('$66'));
end;
end;

end;

end;
 
自已顶,高手快来!!!
 
路过的大哥们请留下一点痕迹,帮我顶一下吧!!!小弟谢过了!!!
 
再顶一次!!
 
在你的
then
Begin
showmessage('没有插入IC卡');
ClosePort():
Exit;
End;

例如:

st:=rf_authentication(icdev,0,sector);
if st<>0 then
Begin
Application.MessageBox('卡验证密码错误A,请换卡!!!','错误提示3',MB_ICONQUESTION+MB_OK);
st:=rf_exit(icdev);
Exit;
end;

st:=rf_HL_read(icdev,1,block,snr,@databuff,@ssnr);
St:=rf_decrypt(Pchar(EnCardPass),@DataBuff,16,Data1);
if St<>0 Then
Begin
Application.MessageBox('读卡错误,请换卡!!!','错误提示3',MB_ICONQUESTION+MB_OK);
st:=rf_exit(icdev);
Exit;
End
 
你把dll函数声明中的所有String类型换成Pchar类型试试
 
你将你的DLL导出函数检查一下呢,是不是应该将String改为PChar?
 
装了DELPHI6就好了,后来让厂家换了一个驱动程序也就好了.很感谢大家的支持.
 
后退
顶部