看看我的程序代码出现什么问题?特急!!!!
下面的代码为调用dll(驱动扫描仪,扫描发票,然后识别成文字)在第一次调用时可以扫描识别,但是再次点击扫描按钮时,整个程序自动退出,请问各位怎么办?特急!
procedure Tmainform.N9Click(Sender: TObject);
type
TIntFunc=function(i:pchar):integer;stdcall;
var
Th:Thandle;
Tf1,Tf2:TIntFunc;
Tp1,Tp2:TFarProc;
lib:string;
Scanner,filepath:pchar;
//sd:array[1..19] of char;
dwRetn:integer;
begin
//showmessage(' 扫描前请先装入发票!');
lib:=p_path+'\EtcVatScan.dll';
Th:=LoadLibrary(pchar(lib)); {装载DLL}
if Th>0 then
try
Tp1:=GetProcAddress(Th,PChar('C_getScanner')); //获取扫描仪类型
Tp2:=GetProcAddress(Th,PChar('C_getetcvatfile'));//指令扫描仪进行扫描识别,并返回最后的识别文本文件ETCVAT.TXT全路径。
if (Tp1<>nil) and (Tp2<>nil) then
if Tp1<>nil then
begin
Tf1:=TIntFunc(Tp1);
GetMem(Scanner,60);//为将要得到的名字分配内存
dwRetn := Tf1(Scanner);
showmessage(string(Scanner)+'as:'+inttostr(dwRetn));
FreeMem(Scanner,0); // 释放分配的内存
if dwRetn=1 then
begin
GetMem(filepath,200);
Tf2:=TIntFunc(Tp2);
dwRetn := Tf2(filepath);
if dwRetn=0 then
showmessage(string(filepath)+'as:'+inttostr(dwRetn))
else
showmessage('as:'+inttostr(dwRetn));
FreeMem(filepath,0); // 释放分配的内存
end;
end
else
ShowMessage('C_getScanner函数没有找到');
finally
FreeLibrary(Th); //释放DLL
end
else
ShowMessage('扫描库'+lib+'未找到,加载不成功!');
end;