JK105Pro.dll是用C写的DLL文件(IC卡读写器接口),现在要在DELPHI6中调用int opencard_h(char *sReply)接口函数(整型),其中sReply是DLL调用后的返回字符串值,在DELPHI中应该如何调用啊?该接口函数好象是先在DELPHI中传入一个sReply的String,然后调用接口函数后返回sReply的值。我用DELPHI6做了以下动态调用程序,但是在调用接口函数的时候出现地址冲突的错误,请高手指点迷津,问题解决后马上给分!先谢谢了!拜托各位兄弟了!
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
  type
    TOpenCard_h = function(var sReply:String):Integer;stdcall;
    err1=class(exception);
    err2=class(exception);.......procedure TForm1.Button3Click(Sender: TObject);          //打开卡片
var
  filename:pchar;
  DllHandle1: THandle;
  opencard_h:TOpenCard_h;
  i:Integer;
  sReply:String;
begin
    filename:=pchar(extractfilepath(application.ExeName)+'JK105Pro.dll');
    DllHandle1:=loadlibrary(filename);
    if DllHandle1=0 then
        err2.Create('DLL调用出错')
    else
        @opencard_h:=GetProcAddress(DllHandle1,'opencard_h');
    if not(@opencard_h=nil) then
    begin
        sReply:='';
        i:=opencard_h(sReply);
        ShowMessage(IntToStr(i)); // 
    end
    else RaiseLastWin32Error;
    //freelibrary(DllHandle1);
end;

解决方案 »

  1.   

    delphi我刚学,以后多关照啊。
      

  2.   

    是哪一句话出错了?
    有可能使返回了一个已经析构了的对象============================================================================
    http://www.betajin.com/alphasun/index.htm           给我发信息请附带原帖地址
    http://alphasun.18en.com/                    http://shakingtoolkit.9126.com/
    DocWizard C++程序文档自动生成工具 | Wave OpenGL | HttpProxy | AjaxParser词法分析
      

  3.   

    加个
    SetLength(sReply,11111111)可以用了吗?
    如果可一给回个信
    [email protected]
      

  4.   

    问题已经解决了,如下:
    type
        TOpenCard_h = function(sReply:Pchar):Integer;stdcall;
    ...
    procedure TForm1.Button3Click(Sender: TObject);          //打开卡片
    var
      filename:pchar;
      DllHandle1: THandle;
      opencard_h:TOpenCard_h;
      i:Integer;
      sReply:Array [0..100] of char;
    ....