最近写了一个演示的小软件,用来演示卫星的数据传送。
原本是个exe可执行文件,现在想将它改为dll,这样方便以后在其它地方调用,不知该如何下手,请赐教。
分少的话,可以再加

解决方案 »

  1.   

    在Delphi中,你的exe是建立一个Application之后,编译生成的。如果想作成.dll的话,你可以这样做:New--dll wizard,之后,加入你在Application的所有Form和Unit,然后你再写一个导出函数就可以了。我给你个.dll工程文件的例子:
    library BK_TJQZ;{ 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
      ShareMem,  //注意,必须引用
      windows,
      SysUtils,
      Classes,
      Forms,
      paramlist,
      TJQZ in 'TJQZ.pas' {TJQZForm},
      TjQzScCyj in 'TjQzScCyj.pas' {TjQzScCyjForm};{$R *.res}function ShowForm  //这就是我要导出的函数(FormName:String;FormParams:TFormparams;modal:Boolean):Boolean ;stdcall;
    begin
      if UpperCase(FormName)='TTJQZFORM' then
      begin
        if TJQZFORM=nil then
        begin
          TJQZFORM:=TTJQZFORM.Create(Application);
          TJQZFORM.MyParams := FormParams;
        end;
        Result := True;
        if modal then
          TJQZFORM.ShowModal
        else
          TJQZFORM.Show;
      end
      else begin
        Result := False;
        Application.MessageBox('Form没有找到!','提示', mb_ok);
      end;
    end;
      Exports
        ShowForm;begin
    end.调用:
    procedure TForm1.Button14Click(Sender: TObject);
    var
      TempShowForm : TShowForm;
      MyHandle : THandle;
    begin
        MyHandle := LoadLibrary(PChar('E:\Code\DDZInput\'+'BK_TJQZ.dll'));
        if MyHandle <> 0 then
          @TempShowForm := GetProcAddress(MyHandle, 'ShowForm');
        if @TempShowForm <> nil then
          TempShowForm('TTJQZFORM', TempFormParams, True);end;