首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

调用其他语言dll出现access violation ataddress有关问题

2013-07-08 
调用其他语言dll出现access violation ataddress问题公司给出的接口说明读二代身份证原型:int ReadCard(ch

调用其他语言dll出现access violation ataddress问题
公司给出的接口说明
读二代身份证
原型:int ReadCard(char *Name,
char *Sex,
char *Nation,
char *Birthday,
char *Address,
char *ID,
char *Department,
char *StartDate,
char *EndDate,
char *Reserve,
char *AppAddress1,
char *PhotoData)
参数:Name姓名
Sex性别
Nation民族
Birthday生日
Address住址
ID身份证号
Department发证机关
StartDate起始日期
EndDate终止日期
Reserve预留信息
AppAddress1 预留地址
PhotoData照片信息
返回:
=0成功
<0失败
程序如下
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  OpenCom = function (Comport:integer;Baud:integer):integer;stdcall;
  SelModule = function (PortType:integer;Module:integer):integer;stdcall;
  CloseCom = function ():integer;stdcall;   
  ReadCard = function (Name:pChar;Sex:pChar;Nation:pChar;Birthday:pChar;
      Address:pChar;ID:pChar;Department:pChar;StartDate:pChar;EndDate:pChar;
      Reserve:pChar;AppAddress1:pChar;PhotoData:pChar):integer;stdcall;
  TForm1 = class(TForm)
    Button1: TButton;                           
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var DllHandle:THandle;
    ComPort,Baud,HBaud,result:integer;
    PortType,Module:integer;
    sfzName,sfzSex,sfzNation,sfzBirthday,sfzAddress,sfzID,sfzDepartment,
    sfzStartDate,sfzEndDate,sfzReserve,sfzAppAddress1,sfzPhotoData:string;
    oc:OpenCom;
    sm:SelModule;
    cc:CloseCom;
    rc:ReadCard;
begin

  ComPort:=1;Baud:=9600;HBaud:=115200;result:=22;
  PortType:=0;Module:=3;



  DLLHandle:=LoadLibrary('JCJP_API.dll');
  if DLLHandle<>0 then
  begin
    @oc:=GetProcAddress(DllHandle,'Open_Com');

    if @oc<>nil then
    begin
      if( oc(ComPort,Baud) = 0 )then
      begin
        @sm:= GetProcAddress(DllHandle,'Sel_Module');
        if @sm<>nil then
        begin
          if(sm(PortType,Module) = 0)then
          begin
            @cc:= GetProcAddress(DllHandle,'Close_Com');
            if( cc()=0)then
            begin
               @oc:=GetProcAddress(DllHandle,'Open_Com');
               if(@oc<>nil)then
               begin
               if(oc(ComPort,HBaud)=0)then
               begin
                 @rc:= GetProcAddress(DllHandle,'ReadCard');
                 if @rc<>nil then
                 begin
                   try
                     if(rc(@sfzName,@sfzSex,@sfzNation,@sfzBirthday,@sfzAddress,@sfzID,@sfzDepartment,
                            @sfzStartDate,@sfzEndDate,@sfzReserve,@sfzAppAddress1,@sfzPhotoData)=0)then
                     begin
                       // showmessage(sfzID);


                       showmessage('222'+sfzName);
                       showmessage('222');
                     end
                     else
                     begin
                       showmessage('没有找到二代身份证,读取失败!');
                     end;
                   except
                     on E:exception do
                     showmessage(e.Message);
                   end;
                   result:=sm(PortType,0);
                   result:=cc();
                 end
                 else
                   showmessage('rc is nil');
               end
               else
                 showmessage('高频打开串口失败');
               end
               else
                 showmessage('oc is nil');
            end
            else


              showmessage('关闭串口失败');
          end
          else
          begin
            showmessage('选择模式失败');
          end;
        end
        else
        begin
          showmessage('sm is nil');
        end;
      end
      else
        showmessage('串口打开失败!');
    end
    else
      showmessage('oc is nil');
  end
  else
    showmessage('222');
    FreeLibrary(DLLHandle);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  close;
end;


end.

-----------------------------------------
把下面这句删掉一切正常。
rc( sfzName,@sfzSex,@sfzNation,@sfzBirthday,@sfzAddress,
@sfzID,@sfzDepartment,@sfzStartDate,@sfzEndDate,@sfzReserve,
@sfzAppAddress1,@sfzPhotoData)=0
请高手帮忙look look dll? Windows 指针?
[解决办法]
定义sfzName等参照如下,试试


我的方法


function ReadBaseInfosPhoto(Name,Sex,Folk,BirthDay,ID,Address,Issue,dBegin,dEnd,Photopath:PAnsiChar):integer;stdcall;External '.\dll\sdtapi.dll';


type
  TIDCardInfo=record
    _Name:array[1..31] of AnsiChar;
    _Sex:array[1..3] of AnsiChar;
    _Folk:array[1..10] of AnsiChar;
    _Birthday:array[1..9] of AnsiChar;
    _Addr:array[1..71] of AnsiChar;
    _ID:array[1..19] of AnsiChar;


    _Issue:array[1..31] of AnsiChar;
    _dBegin:array[1..9] of AnsiChar;
    _dEnd:array[1..9] of AnsiChar;
  private
    Fport:Integer;         //端口状态
    Fauthenticate:Integer; //认证状态
    Freadinfo:Integer;     //读卡状态
  end;


ReadCard.Freadinfo:=ReadBaseInfosPhoto(@ReadCard._Name,@ReadCard._Sex,@ReadCard._Folk,@ReadCard._Birthday,@ReadCard._ID,@ReadCard._Addr,@ReadCard._Issue,@ReadCard._dBegin,@ReadCard._dEnd,PAnsiChar(AnsiString(Fphotopath)));


[解决办法]
多设断点,仔细看,是在哪报错
慢慢来吧
[解决办法]
我也曾经碰到过这个问题,运行时设置兼容模式即可。

热点排行