J
jxdxlzx
Unregistered / Unconfirmed
GUEST, unregistred user!
这段代码我在窗体中运行正常,可转换成DLL后,程序调用报Invalid pointer operation我实在是找不到原因,请各位大虾指点迷津!!
unit Unit1;//DLL的代码
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
ip=^integer;
///////////////调用外部IC卡读卡器的DLL函数
function OpenPort(PortName:string;PortHandle:ip):integer;stdcall;external 'mi00.dll';
function ClosePort():integer;stdcall;external 'mi00.dll';
function SelectPort(PortHandle:integer):integer;stdcall;external 'mi00.dll';
function PowerOn():integer;stdcall;external 'mi00.dll';
function PowerOff():integer;stdcall;external 'mi00.dll';
function CardPresent():integer;stdcall;external 'mi00.dll';
function CardChanged():integer;stdcall;external 'mi00.dll';
function GetCardType(ATRBuffer:string):integer;stdcall;external 'mi00.dll';
function GetCardName(CardType:integer)char;stdcall;external 'mi00.dll';
function Read_4428_With_PB(StrartPos:integer;NOB:integer;Bfrchar;PB_Bfrchar):Integer;stdcall;external 'mi00.dll';
function Read_4442_With_PB(StrartPos:integer;NOB:integer;Bfrchar;PB_Bfrchar):Integer;stdcall;external 'mi00.dll';
///////////////输出函数
function Ric():string;export; //读IC卡30-37内容
////////////////////////
implementation
function Ric():string;
var
re,aa:integer;
porth:ip;
ATR:array[0..3] of char;
StrartPos:integer;
NOB:integer;
Bfr:array[0..256] of char;
PB_Bfr:array[0..256] of char;
i:integer;
str,str1:string;
begin
re:=OpenPort('COM1',Porth);//打开端口
if re=0 then //安装读卡器检测
begin
str1:='';
re:=PowerOn();
re:=CardPresent();
if re<>1 then
showmessage('没有插入IC卡')
else
begin
re:=GetCardType(ATR);
if re>0 then
begin
if re=2 then
begin
StrartPos:=0;
NOB:=256;
re:=Read_4442_With_PB(StrartPos,NOB,Bfr,PB_Bfr);
str1:='';
for i:=30 to 37 do
begin
str:=bfr;
str1:=str1+str;
end;
end
else //判断4442卡
showmessage('对不起卡型不对,请检查IC卡');
end
else
showmessage('对不起未知IC卡,请检查IC卡');
end;
re:=PowerOff();
re:=ClosePort();
end
else
showmessage('没有检测到读卡器,请检查读卡器连线是否正常!'); //读卡器检测
Result:=str1;
end;
end.
unit Unit1;//DLL的代码
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
ip=^integer;
///////////////调用外部IC卡读卡器的DLL函数
function OpenPort(PortName:string;PortHandle:ip):integer;stdcall;external 'mi00.dll';
function ClosePort():integer;stdcall;external 'mi00.dll';
function SelectPort(PortHandle:integer):integer;stdcall;external 'mi00.dll';
function PowerOn():integer;stdcall;external 'mi00.dll';
function PowerOff():integer;stdcall;external 'mi00.dll';
function CardPresent():integer;stdcall;external 'mi00.dll';
function CardChanged():integer;stdcall;external 'mi00.dll';
function GetCardType(ATRBuffer:string):integer;stdcall;external 'mi00.dll';
function GetCardName(CardType:integer)char;stdcall;external 'mi00.dll';
function Read_4428_With_PB(StrartPos:integer;NOB:integer;Bfrchar;PB_Bfrchar):Integer;stdcall;external 'mi00.dll';
function Read_4442_With_PB(StrartPos:integer;NOB:integer;Bfrchar;PB_Bfrchar):Integer;stdcall;external 'mi00.dll';
///////////////输出函数
function Ric():string;export; //读IC卡30-37内容
////////////////////////
implementation
function Ric():string;
var
re,aa:integer;
porth:ip;
ATR:array[0..3] of char;
StrartPos:integer;
NOB:integer;
Bfr:array[0..256] of char;
PB_Bfr:array[0..256] of char;
i:integer;
str,str1:string;
begin
re:=OpenPort('COM1',Porth);//打开端口
if re=0 then //安装读卡器检测
begin
str1:='';
re:=PowerOn();
re:=CardPresent();
if re<>1 then
showmessage('没有插入IC卡')
else
begin
re:=GetCardType(ATR);
if re>0 then
begin
if re=2 then
begin
StrartPos:=0;
NOB:=256;
re:=Read_4442_With_PB(StrartPos,NOB,Bfr,PB_Bfr);
str1:='';
for i:=30 to 37 do
begin
str:=bfr;
str1:=str1+str;
end;
end
else //判断4442卡
showmessage('对不起卡型不对,请检查IC卡');
end
else
showmessage('对不起未知IC卡,请检查IC卡');
end;
re:=PowerOff();
re:=ClosePort();
end
else
showmessage('没有检测到读卡器,请检查读卡器连线是否正常!'); //读卡器检测
Result:=str1;
end;
end.