我新建了一个application,在form内添加一个button控件,在button的onclick事件中调用SafeEngine.dll中的SEH_InitialSession过程,可是运行时会报如下错误:Access violation at address 1000C8B1 in module 'SafeEngine.dll'.Write of address 00000002.请问主要是哪方面出错啦?    我的源码如下:
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;  procedure SEH_InitialSession(PriKeyDevType: Integer; const  strPrivKeyDevParam: WideString;const strPriKeyPass: WideString; lPriKeyTimeout: Integer;CertChainDevType: Integer; const
strCertChainDevParam: WideString;const strCertChainPass:
WideString);StdCall;type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation
procedure SEH_InitialSession;external 'SafeEngine.dll' name 'SEH_InitialSession';
{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
SEH_InitialSession(2,'userkey.key','sheca',1000,2,'CertChain.spc','');
end;end.

解决方案 »

  1.   

    不清楚没有这样用过我一直用API:LoadLibrary和GetProcessAddress
      

  2.   

    有可能是过程用WideString传递参数引起的,在DLL中用char * 声明参数
    并在输出声明前加 external "C"
      

  3.   

    我只有dll和接口说明文档,摘抄相关部分如下:SHE_InitialSession函数
    在调用以下函数前必须先调用此函数初始化.
    功能:初始化环境,从设备中读取私钥、根证书。
    语法:int  SEH_InitialSession(unsigned short privatekeydevicetype,  char *privatekeydeviceparameter, char *privatekeypassword,  unsigned long privatekeytimeout,  unsigned short rootcertdevicetype,  char *rootcertdeviceparameter,  char *rootcertpassword )是不是我用的参数类型不对呀?能否给出完整的函数定义段,在onclick事件中
    原先的SEH_InitialSession(2,'userkey.key','sheca',1000,2,'CertChain.spc','')又要怎样改呀?另to dw601211:按照你的方法,我这段程序要做哪些修改呀?请指教
      

  4.   

    这样是对的:
    implementation;
    function SEH_InitialSession(PriKeyDevType: Integer; const  strPrivKeyDevParam: WideString;const strPriKeyPass: WideString; lPriKeyTimeout: Integer;CertChainDevType: Integer; const
    strCertChainDevParam: WideString;const strCertChainPass:
    WideString):integer;decall;external 'SafeEngine.dll' ;‘;decall;external 'SafeEngine.dll' ;’该不分好象有点问题,你在调试一下
      

  5.   

    1、的确要加上external 'SafeEngine.dll' ;
    2、但使用stdcall还是decall就看说明书和Demo吧,调用普通的API使用stdcall;
    3、你函数的声明有问题。你看看说明书,凡是原函数定义为char *的地方一律使用PChar类型代替,举例如下:假设函数f需要PChar类型的参数
    var
      s: String;
      ws: WideString;
    begin
      f(PChar(s));
      f(PChar(String(ws)));
    end;