sdll文件如下:library sdll;
uses
  SysUtils,
  Classes;
  function GetInteger(I:Integer): Integer;stdcall;
  function GetDouble(D:Double): Double;stdcall;
{$R *.res}
  function GetInteger(I:Integer): Integer;stdcall;
  begin
    Result := I;
  end;  function GetDouble(D:Double): Double;stdcall;
  begin
    Result := D;
  end;
exports
  GetInteger,
  GetDouble;
begin
end.调用dll文件:unit usedll1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
  function GetDouble(D:Double): Double;stdcall;external 'sdll.dll';
  function GetInteger(I:Integer): Integer;stdcall;external 'sdll.dll';
var
  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
  edit1.Text := inttostr(GetInteger(100));
end;end.运行后就是报错如下:project f:\delphi\usedll.exe faulted with message:'access violation at ox77f8ea53:write of address ox00030cb4'.process stopped.use step or run to continue.由于是第一次搞DLL,望大家指导指导!多谢了!

解决方案 »

  1.   

    library sdll;
    uses
      SysUtils,
      Classes;
      //function GetInteger(I:Integer): Integer;stdcall;
      //function GetDouble(D:Double): Double;stdcall;//--------把这两行去掉就行了。^_^
    {$R *.res}
      function GetInteger(I:Integer): Integer;stdcall;
      begin
        Result := I;
      end;  function GetDouble(D:Double): Double;stdcall;
      begin
        Result := D;
      end;
    exports
      GetInteger,
      GetDouble;
    begin
    end.
      

  2.   

    +上 
    uses 
     ShareMem;
      

  3.   

    procedure TForm1.Button2Click(Sender: TObject);
    type
    TGetDouble=function(D:Double):Integer;stdcall;
    var
    D: Double;
    DLLHandle: THandle;
    Func: TGetDouble;
    begin
    DLLHandle := LoadLibrary('sdll.dll');
    try
      @Func := GetProcAddress(DLLHandle, 'GetDouble');
      if Assigned(@Func) then
      begin
        D := Func(2.2);//为什么 D=1073846681?????
        Edit1.Text := FloatToStr(D);
      end;
      finally
        FreeLibrary(DLLHandle);
      end;
    end;在动态调用的时候为什么 D=1073846681
      

  4.   

    因为:
    type
      TGetDouble=function(D:Double):Integer;stdcall;
                                    ^这里写错了
      

  5.   

    jadeluo(秀峰):
    能说的详细一点吗?那应该怎么写才是对的?多谢了!