主程序exe文件分为了几个模块,每个模块分别调用不同的dll,有下面两个文件解决不了啊,请大家帮帮忙,想想~~
1。主程序,如何把参数传给dll?并且dll如何把结果,如一个变量的值返回给主程序?
2。主程序已经有一个adoconnection,连接了数据库,dll怎样继续使用主程序的那个数据库连接?还有这个主程序是一个三层结构的客户端,使用了一个tcpconnect,连接到远程provider,这个dll怎么继续使用这个连接呢

解决方案 »

  1.   


    传入adoconnection:DLL:
    library prjDLL;{ 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,
      Forms,
      Windows,
      Messages,
      Classes,
      DLLFormUnit in 'DLLFormUnit.pas' {frmDLLForm},
      AboutUnit in 'AboutUnit.pas' {frmAbout};{$R *.res}var
      DLLApp: TApplication;
      //DLLScr: TScreen;
    procedure CreateDLLForm(App: TApplication; AC: Tadoconnection);
    var
      ptr:PLongInt;
    begin
      Application := App;
      ///Screen := Scr;
      Application.CreateForm(TfrmDLLForm, frmDLLForm);
      TfrmDLLForm.Tadoconnection1=AC;
      //Application.CreateForm(TfrmAbout, frmAbout);
      result:=frmDLLForm;
    end;procedure ExitDLL(Reason: Integer);
    begin
      if Reason = DLL_PROCESS_DETACH then
      begin
        Application := DLLApp;
        //Screen := DLLScr;
      end;
    end;
    exports
      CreateDLLForm;begin
      DLLApp := Application;
      //DLLScr := Screen;
      DLLProc := @ExitDLL;end.主程序:procedure TfrmMain.mi_inDLLClick(Sender: TObject);
    type
      InvokeDLLForm=procedure (App: TApplication; AC: Tadoconnection)
    var
      DLLHandle: THandle;
      DLLSub: InvokeDLLForm;begin
      DLLHandle := LoadLibrary('prjDLL.dll');
      if DLLHandle <> 0 then
      begin
        @DLLSub := GetProcAddress(DLLHandle, 'CreateDLLForm');
        if Assigned(DLLSub) then
        begin
          DLLForm := DLLSub(Application, adoconnection1);
        end;
      end;
    end;
      

  2.   

    你的问题可能有点不很清楚,一般调用DLL较多的是其中的过程或函数,如果主程在过程或函数的参数项中放入你说的要传的实例,都可以传到DLL模块中去。包括数据库连接,数据库连接肯定有一个类型,如Tconnection,在函数的参数项中定义此输入类型的入口参数,在主程中将一连接实例放入调用即可,自然返回结果。
      可能你说的是多种数据交换,在这种情况下,效率最高的是使用内存映像文件,较麻烦,可查相关资料。
      

  3.   

    就像  “qinget(C#热恋中)”  说的那样就行了,dll调用他写的很清楚了,三层结构我也才开始研究,也就没什么可说的了,在delphi园地有一个三层结构的源码例子,可以去下载来看看。
      

  4.   

    用var传变量地址就可以了吧,我这是菜鸟的想法而已