library dllTry;uses
//... // fun1
function fun1(): Integer;
begin
  // ...
end;// fun2
function fun2(): Integer;
begin
  // ...
end;exports
fun1, fun2;end.程序结构大概是这样,调用时,fun1可以,fun2却不成,提示找不到这个函数。改了改名字,不可以。把fun1的内容copy,改个名字,再调用,还是不可以。

解决方案 »

  1.   

    最好在输出时定义一个INDEX,这样就不存在写法问题了.
      

  2.   

    最好在后面加上stdcall
    function fun2(): Integer;stdcall;
    begin
      // ...
    end;
      

  3.   

    例子:
    -------------
    library CompareP;uses
      SysUtils,
      Classes;
    {$R *.res}
    Function MinN(ArrayInput:Array of double):double;stdCall;
    var
      i:integer;
    begin
      Result:=ArrayInput[low(ArrayInput)];
      For i:=low(ArrayInput) to high(ArrayInput) do
      begin
        if Result > ArrayInput[i] then
           Result:=ArrayInput[i];
      end;
    end;Function MaxN(ArrayInput:Array of double):double;stdCall;
    var
      i:integer;
    begin
      Result:=ArrayInput[low(ArrayInput)];
      For i:=low(ArrayInput) to high(ArrayInput) do
      begin
        if Result <= ArrayInput[i] then
            Result:=ArrayInput[i]
        else
            Result:=Result;
      end;
    end;
    exports
      MinN,
      MaxN;
      
    begin
    end.
    --------------------------------
    调用
    unit CallDLL;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TCallDllF = class(TForm)
        Button1: TButton;
      procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
      Function MaxN(ArrayInput:Array of double)
                                      :double;stdCall;external 'bin\CompareP.dll';
      Function MinN(ArrayInput:Array of double)
                                      :double;stdCall;external 'bin\CompareP.dll';
    var
      CallDllF: TCallDllF;implementation{$R *.dfm}procedure TCallDllF.Button1Click(Sender: TObject);
    var
      DoubleArray:array of double;
      i,j:integer;begin
      Canvas.TextOut(40,40,(TimeToStr(now())));
      setLength(DoubleArray,100000);  for i:=low(DoubleArray) to high(DoubleArray) do
        DoubleArray[i]:=i;//random(i)+10;
      for j:=0 to 1000 do
      Caption:= FloatToStr(MinN(DoubleArray))
                +'     '+
                FloatToStr(MaxN(DoubleArray));
      Canvas.TextOut(40,80,(TimeToStr(now())));
    end;end.