我的源程序如下:
unit IC_PK;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, StdCtrls;
function Cardcomm(fd:integer;Len:integer;Commstr:string;var lenr:integer;resp
char):integer;
function CreateNewCard(fd:integer):string;
implementation
Function ICC_tsi_apiC(fd:integer;len:integer;comm
char;var lenr:integer;resp
char):integer;
stdcall;far;external 'crcwc.dll';
Function ICC_reset(fd:integer;var lenr:byte;resp
char):word; stdcall;far;external 'crwicc.dll';
function Cardcomm(fd:integer;Len:integer;Commstr:string;var lenr:integer;resp
char):integer;
var
ret:word;
begin
ret:=ICC_tsi_apiC(fd,len,Pchar(Commstr),lenr,resp);
Cardcomm:=ret;
end;
function CreateNewCard(fd:integer):string;
var
Comm,resp
char;
ret:word;
lent:byte;
tmpResp,MyRet:string;
lenr:integer;
begin
Getmem(comm,270);
Getmem(resp,256);
lenr:=0;
SetLength(tmpResp, 256);
SetLength(MyRet, 256);
Cardcomm(fd,7,'00A40000023F00',lenr,resp);
Cardcomm(fd,21,'00200001080000000000000000',lenr,resp);
Cardcomm(fd,5,'800e000000',lenr,resp);
ret:=ICC_reset(fd,lent,resp);
Cardcomm(fd,12,'80E00000073F0050FF00FFFF',lenr,resp);
Cardcomm(fd,18,'80D401010D3AF0020A330000000000000000',lenr,resp);
Cardcomm(fd,22,'80E01000113805E8f0f095FFFFA00000000386990701',lenr,resp);
Cardcomm(fd,7,'00a40000021000',lenr,resp);
Cardcomm(fd,12,'80E00000073F0100FF00FFFF',lenr,resp);
Cardcomm(fd,14,'80D40101093AF0020A3338383838',lenr,resp);
Cardcomm(fd,12,'80E00007073D0280F0F0FFFF',lenr,resp);
Cardcomm(fd,12,'80E00002073e0100F0F0FFFF',lenr,resp);
Cardcomm(fd,12,'80E00008072800FFF0F0FFFF',lenr,resp);
Cardcomm(fd,5,'80CE000700',lenr,resp);
while ret<>27904 do
ret:=Cardcomm(fd,5,'0000000000',lenr,resp);
Cardcomm(fd,5,'80CE000700',lenr,resp);
StrCopy(comm,'00d0820087');
StrCopy(comm+10,resp);
tmpResp:=string(resp);
Myret:=tmpResp;
Cardcomm(fd,280,comm,lenr,resp);
StrCopy(comm,'00D6880087');
StrCopy(comm+10,Pchar(tmpResp));
Cardcomm(fd,280,comm,lenr,resp);
// freemem(comm); //注意这里:如果不注释掉此行,则运行到这里产生访问地址冲突 ,如果注释掉则运行正常,返回结果也正确,但是就会出现以下错误:我一退出程序,就出现如下错误:
//project demo.exe raised exception class EInvalidPointer with
//message 'Invalid pointer operation'. Process stopped . Use step or run to continue
// freemem(resp);
CreateNewCard:=Myret;
end;