我试了一下,总是报访问冲突

解决方案 »

  1.   

    这几天刚写了一个,给你参考参考!///////////////////////////////////////////////////////////////////
    // DLL 代码
    unit frmDllMain_Base;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;
      
    type
      TDllMainForm = class(TForm)
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
      private
        //
      public
        //
      end;////////////////////////=>//////////////////////////////////
    var
        DllForm: TDllMainForm;
    ////////////////////////<=//////////////////////////////////{Declare the export function}
    function GetDLLForm(app: TApplication): TForm; stdcall;implementation{$R *.dfm}////export function
    exports
        GetDllForm;//// 返回DLL中的主窗口对象
    function GetDLLForm(app: TApplication): TForm; stdcall;
    begin
        Application.Handle:=app.Handle;
        DllForm:=TDllMainForm.Create(Application); //.MainForm);
        result := DllForm;
    end;////
    procedure TDllMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
        TDllMainForm(LongInt(Self)).Release;
    end;end./////////////////////////////////////////////////////////////
    // 调用显示DLL中的窗口
    procedure TfrmMain.ShowDllMainForm(dllFileName);
    var
      DGetDllForm: TDGetDllForm;
      frm: TForm;
    begin
      try
        //导入DLL库
        LibHandle:=LoadLibrary(PChar(dllFileName));
        try
          if LibHandle<>0 then
          begin
            //获得DLL中获取DLL主窗口的函数
            @DGetDllForm:=GetProcAddress(LibHandle,'GetDLLForm');
            if not Assigned(DGetDllForm) then
                raise Exception.Create('DLL error!'+#13#10+dllFileName);        //从DLL中导入DLL主窗口并显示
            if not (@DGetDllForm = nil) then
            begin          
              frm:=DGetDllForm(Application);
              frm.Show;
            end;
          end;
        finally
          //FreeLibrary(LibHandle);
        end;
      except
        on E: Exception do MessageDlg(E.Message,mtError,[mbOK],0);
      end;
    end;
      

  2.   

    感谢cmmi的代码,不过与我的问题不一样。我在DLL中的窗体是childForm,调用的是MDIFORM。
      

  3.   

    有没有把build with run time package选上啊!以前我做这个时也是这个问题
    选上这个好像就没有了!