本人正在做一个二次开发,刚学delphi不久。有一些二次开发的资料。是一个.dll动态库,附加了其中一些函数的说明,其中的写类型的函数本人找了一些参照研究了之后还能凑合着用用,就是一些关于读记录的函数可能我的用法就有问题了,代码贴出来让各位路过的高手帮帮忙,看看到底是什么地方出问题了。
    {ReadCardSN 
   Function ReadCardSN(Devno:Integer; Var CardSn:Integer):Integer
    功能说明:读卡号。
    参数说明: DevNo 为设备号(0——254),255 为广播号 CardSN 返回卡号
   返回值:调用成功,返回1,否则,返回0。}
   以上括号部分是其中一个函数的说明
  我在程序中调用的时候是在implementation下面这样调用的。
  Function ReadCardSN(Devno:Integer; Var CardSn:Integer):Integer;stdcall;external 'YET-100Comm.dll';//读取控制器当前状态
    procedure TForm1.Button6Click(Sender: TObject);
var
Com:string;
jh,hc,BR,CtrNo,rs,CardSn:Integer;
begin
  com:=com1
  jh:=100
  BR:=9600;
  hc:=OpenCommPort(PChar(Com),BR);
  if hc=-1 then
    begin
      showmessage('打开通信端口失败');
      CloseCommPort(hc);
      exit;
    end else
    begin
      rs:=ReadCardSN(jh,CardSn);
      if rs=1 then
        begin
        showmessage('成功')
        edit1.text:=inttostr(CardSn);//我的目的是调用成功后返回它的卡号
        end;
        else
        showmessage('失败');
      CloseCommPort(hc);
    end;
end;
请问路过的各位高手是不是我的调用的写法上有很严重的问题啊,望赐教,谢谢~

解决方案 »

  1.   

       呵呵~程序编译都通过了,但是运行exe文件的时候会报错的说:external exception c0000008;这个我也不知道是什么意思。
      

  2.   

    把函数的原型声明贴出来看看,估计是你在delphi的函数声明有问题。
    一般返回参数会传送地址
      

  3.   

    看不出来什么明显的问题
            showmessage('成功')
            edit1.text:=inttostr(CardSn);//我的目的是调用成功后返回它的卡号
    这两句顺序换一下,不知道执行后提示成功还是失败?
      

  4.   

    var
      Form1: TForm1;implementation  function OpenCommPort(port:pchar;baudrate:integer):integer;stdcall;external 'YET-100Comm.dll';
      function CloseCommPort(hc:integer):integer;stdcall;external 'YET-100Comm.dll';
      function WriteTime(hc:integer;devno:integer;DT:string):integer;stdcall;external 'YET-100Comm.dll';
      function AddList(hc,devno:integer;CardNo:integer;Name:string;GH:string;PW:string;LT:string;D1,D2:integer):integer;stdcall;external 'YET-100Comm.dll';
      Function SetShowTitle(hc,Devno:Integer; StrTitle:String):Integer;stdcall;external 'YET-100Comm.dll';
      Function SetDevNo(hc,OldDevno,NewDevno:Integer):Integer;stdcall;external 'YET-100Comm.dll';
      Function OpenDoor(hc,Devno,CtrNo:Integer):Integer;stdcall;external 'YET-100Comm.dll';//软件开门
      Function WriteBackLight(Devno,intSetup:Integer):Integer;stdcall;external 'YET-100Comm.dll';
      Function DevReset(hc,Devno:Integer):Integer;stdcall;external 'YET-100Comm.dll';
      Function ReadCardSN(Devno:Integer; Var CardSn:Integer):Integer;stdcall;external 'YET-100Comm.dll';
    {$R *.dfm}以上是我引用的函数,就是这个读类型的函数不行
      

  5.   

    要原型,你的YET-100Comm.dll就是拿delphi写的?
      

  6.   

        这个YET-100Comm.dll别人给的,我是基于他的函数说明做一个二次开发,现在我是想知道,我的做法到底有什么问题的
      

  7.   

    要不你先试试
    把Function ReadCardSN(Devno:Integer; Var CardSn:Integer):Integer;stdcall;external 'YET-100Comm.dll';
    改为Function ReadCardSN(Devno:Integer; CardSn:pchar):Integer;stdcall;external 'YET-100Comm.dll';rs:=ReadCardSN(jh,CardSn); 
    改为rs:=ReadCardSN(jh,@CardSn); 
      

  8.   

    ReadCardSN 
    Function ReadCardSN(Devno:Integer; Var CardSn:Integer):Integer
    功能说明:读卡号。
    参数说明: DevNo 为设备号(0——254),255 为广播号 CardSN 返回卡号
    返回值:调用成功,返回1,否则,返回0。ReadDevAbout 
    Function ReadDevAbout(Devno:Integer; Var strAbout:ShortString):Integer
    功能说明:读取设备厂商信息。
    参数说明: DevNo 为设备号
    strAout 返回设备厂商信息
    返回值:调用成功,返回1,否则,返回0。ReadDevSN 
    Function ReadDevSN(Devno:Integer; Var strSn:ShortString):Integer
    功能说明:读设备序列号
    参数说明:  DevNo 为设备号(0——254),255 为广播号 strSN 返回设备序列号返回值:调用成功,返回1,否则,返回0。以上是关于这个库的其中三个读类型的函数说明。我先试试楼上的说法,谢谢~
      

  9.   

      up~up~up~ 还是报同样的错,都快崩溃了。加分求援~~~