我在看书上的DLL部分,我照着书上的例子做了一个程序,但是一执行就显示“链接文件PROJECT1。EXE到不存在的输出TEST_dll.dll:test“,这是怎么回事?当我编译DLL文件时,系统弹出一个错误对话框,显示"cannot debug project unless a host application is defined.use the run|parameters ... dialog box",是不是这个地方出错啊,是什么地方错啊,
以下是我的源程序
test_dll部分:library test_dll;{ 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,
  test_function in 'test_function.pas';{$R *.res}begin
end.test_function部分:unit test_function;
interface
uses
        dialogs,controls,messages,windows,sysutils,classes;function test(x:string):string;stdcall;implementationfunction test(x:string):string;
begin
        showmessage(x);
end;
end.unit1部分:
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;function test(x:string):string stdcall;external 'test_dll.dll';var
  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
        test('button 1');
end;procedure TForm1.Button2Click(Sender: TObject);
begin
        test('button 2');
end;procedure TForm1.Button3Click(Sender: TObject);
begin
        test('button 3');
end;end.
 

解决方案 »

  1.   

    >>function test(x:string):string;
    1. 要引用ShareMem,返回类型最好是Pchar;
    2. 你函数主体没有返回值,Result.还不如用Procedure test(x:String);函数Test()要有输出exports
    library test_dll
    uses
      SysUtils,
      Classes,
      test_function in 'test_function.pas';{$R *.res}exports
      test;
    begin
    end.
      

  2.   

    你有将文件dll文件考到同一个目录吗?
      

  3.   

    x变量不能用string 用 pchar 是一试
      

  4.   

    DLL不能直接按F9,要在run|parameters加参数.
      

  5.   

    这种写法不对!!!!! 你好象忘了在DLL中写导出函数的那两句!
     ......{$R *.res}Exports
      test index 0;  //index 0 可有可无begin
    end.而且在DLL中函数参数传递字符串的时候需要采用PCHAR而不是STRING, 这样在用别的语言编写的程序调此DLL的时候不会出错!