一直提示DLL中的函数未声明
下面是DLL代码:library MyDLL;{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }uses
  SysUtils,
  Classes;{$R *.res}
  function MyNum(const x, y: Integer; var z:string):Integer;stdcall;
  begin
    if x > y then
    z := '数字一大于数字二'
    else if x < y then
    z := '数字一小于数字二'
    else if x = y then
    z := '数字一等于数字二';
    Result := 0;
  end;
exports MyNum;begin
end.
 
下面是调用DLL的程序代码:type
  MyNum2 = function(const x, y: Integer; var z: string):Integer; //
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    MyNum3: MyNum2;      //
    MyHandle: LongWord;  //
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;
  mystr: string;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
  MyNum(StrToInt(Edit1.Text), StrToInt(Edit2.Text), mystr);  //此处提示函数未声明
  ShowMessage(mystr);
  FreeLibrary(MyHandle);
end;procedure TForm1.FormCreate(Sender: TObject);
begin
  MyHandle := LoadLibrary('MyDLL.dll');   
  if MyHandle <> 0 then
  MyNum3 := GetProcAddress(MyHandle,'MyNum');
end;end.
帮忙看一下问题出在哪里,谢谢

解决方案 »

  1.   

    type
      MyNum2 = function(const x, y: Integer; var z: string):Integer;  stdcall;
      

  2.   

    DLLlibrary Project1;uses
      SysUtils,
      Classes;{$R *.res}function MyNum(const x, y: Integer; var z:PChar):Integer;stdcall;
    begin
      if x > y then z := '数字一大于数字二'
      else if x < y then z := '数字一小于数字二'
      else if x = y then z := '数字一等于数字二';
      Result := 0;
    end;exports
      MyNum;begin
    end.
    Application
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;  TMyFun = function(const x, y: Integer; var z: PChar):Integer;stdcall;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      i:Integer;
      Str:PChar;
      FunNum:TMyFun;
      MyHandle:Cardinal;
    begin
      MyHandle :=LoadLibrary('MyFun.dll');
      if MyHandle <>0 then
        @FunNum :=GetProcAddress(MyHandle,'MyNum');
      i:=FunNum(1,2,Str);
      ShowMessage(IntToStr(i) + Str);
      FreeLibrary(MyHandle);
    end;end.
    感觉你的DLL里边用Procedure应该好一些.因为你的返回值感觉根本没用!
      

  3.   

    //调用, 使用MyNum3,  MyNum这里是一个函数类型。
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      MyNum3(StrToInt(Edit1.Text), StrToInt(Edit2.Text), mystr);  //此处提示函数未声明
      ShowMessage(mystr);
      FreeLibrary(MyHandle);
    end;
      

  4.   

    @MyNum3 := GetProcAddress(MyHandle,'MyNum');
      

  5.   

    创建一个引入单元,
    unit mynumunit;
    interface
    function MyNum(const x, y: Integer; var z:string):Integer;stdcall;
    inplementation
    function mynum: external 'mydll';
    end.   把这个单元加入主单元use子句中
      

  6.   

    在调用程序中函数要定义为stdcall
    type
      MyNum2 = function(const x, y: Integer; var z: string):Integer;stdcall;
      

  7.   

    application那个也要加stdcall修饰
      

  8.   

    占个位置
    继续努力学习中..........
    顶顶帖子,接分中........顶顶帖子,高手们也请多多赐教
    http://topic.csdn.net/u/20110913/13/59f92d11-1fb0-4b7e-9c4a-e93d8f19c689.html
    http://topic.csdn.net/u/20110611/12/3258c959-4f28-46b7-b5d6-46135d73036b.html
    http://topic.csdn.net/u/20110722/14/89f7440b-c4d7-4c9a-a4bb-a503f5135db2.html
    http://topic.csdn.net/u/20110729/10/a7bfaf06-0cf9-4580-8e91-d4e0b92066c6.html
    http://topic.csdn.net/u/20110811/16/e56e7cc1-d8c9-40af-92e3-c24ca103d17d.html
    http://topic.csdn.net/u/20110830/13/dfae4ca5-d2b9-4889-8a3c-6f7fb61936c9.html
    http://topic.csdn.net/u/20110905/12/a1161adb-8e5d-491a-b302-c9722edf2dab.html
    http://topic.csdn.net/u/20110913/16/2dbcc9db-8f71-40c5-901f-afae9026f7c2.html
    http://topic.csdn.net/u/20110913/13/59f92d11-1fb0-4b7e-9c4a-e93d8f19c689.html
      

  9.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      MyNum3(StrToInt(Edit1.Text), StrToInt(Edit2.Text), mystr);  //此处提示函数未声明
      ShowMessage(mystr);
      FreeLibrary(MyHandle);
    end;你搞错函数对象名了
      

  10.   

    MyNum3 := GetProcAddress(MyHandle,'MyNum');
    改为
    @MyNum3 := GetProcAddress(MyHandle,'MyNum');这实际上是指针函数的用法!
      

  11.   

    还有这句
    MyNum(StrToInt(Edit1.Text), StrToInt(Edit2.Text), mystr); 
    应改为
    MyNum3(StrToInt(Edit1.Text), StrToInt(Edit2.Text), mystr);