本人试图将程序模块化,只要一个主界面,其它子窗体都封装在不同的DLL里,但是我没有做过不知道怎样写一个带窗体的dll,并在主窗口去调用这个dll。所以希望高手们提供一个完整的实例学习一下,谢谢
    mailaddress:     [email protected]

解决方案 »

  1.   

    【更正】mailaddress:     [email protected]
      

  2.   

    library Project1;{ 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,
      Unit1 in 'Unit1.pas' {Form1};{$R *.RES}function Returnstr:string;stdcall;
    begin
      with TForm1.Create(nil) do
      try
        showmodal;
        Result := trim(edit1.text);
      finally
        free;
      end;
    end;exports
      Returnstr;begin
    end.
    这是dll的代码。
    procedure TForm1.Button1Click(Sender: TObject);
    var
      DllHandle : THandle=0;
      Rd : function : String; stdcall;
    begin
      DllHandle := LoadLibrary('mydll.dll');
      if DllHandle > 0 then
        @Rd := GetProcAddress(DllHandle,'ShowMainForm')
      else
      begin
        DllHandle := 0;
        @Rd := nil;
      end;  if (DllHandle > 0) and (@Rd <> nil) then
        edit1.text := Rd
      else
        edit1.text := '';
    end;
    这是调用的代码。
      

  3.   

    你加我的QQ吧,我不懂的地方可以请教请教。QQ:348296115
      

  4.   

    //你要引用的窗体unit unit1;interfaceuses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls;type
    TForm1 = class(TForm)
    Label1: TLabel;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;var
    Form1: TForm1;
    ApplicationName: String;
    procedure LoadForm(Handle: THandle; AppName: ShortString); export;implementation{$R *.dfm}
    procedure LoadForm(Handle: THandle; AppName: ShortString);
    begin
    Application.Handle := Handle;
    ApplicationName := AppName;
    Form1 := TForm1.Create(Application);
    try
      Form1.ShowModal;
    finally
      Form1.Free;
    end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      self.close;
    end;end.
    //Dll代码 
    library usedll;uses
    SysUtils,
    Classes,
    Unit1 in 'Unit1.pas' {Form1};{$R *.res}
    exports
      LoadForm index 1;
    beginend.//建立一个工程调用DLL
    unit Unit2;interfaceuses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls;
    type
    TForm2 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;var
    Form2: TForm2;
      procedure LoadForm; external 'usedll.dll' index 1;
    implementation{$R *.dfm}procedure TForm2.Button1Click(Sender: TObject);
    begin
      LoadForm;
    end;end.
      

  5.   

    Error:
       Project Project2.exe raised exception class EOSError with message 'System Error.Code:1400.无效的窗口句柄。',Process stopped.Use Step or Run to continue.只要我有收获一定给分。