主窗体为fsMDIForm!!!!子窗体为fsMDIChild。。可以调用,问题就是在关闭主窗体的时候出错!提示该内存不能为“read”!
这是为什么?
这是调用代码!!!!!
var
DLLHandle: THandle;
  DLLSub: InvokeDLLForm;
begin
  DLLHandle := LoadLibrary('Project1.dll');
  if DLLHandle <> 0 then
  begin
    @DLLSub := GetProcAddress(DLLHandle, 'CreateDLLForm');
    if Assigned(DLLSub) then
    begin
      DLLForm := DLLSub(Application, Screen);
    end;
  end;
end;

解决方案 »

  1.   

    var
    DLLHandle: THandle;
      DLLSub: InvokeDLLForm;
    begin
      DLLHandle := LoadLibrary('Project1.dll');
      if DLLHandle <> 0 then
      begin
        @DLLSub := GetProcAddress(DLLHandle, 'CreateDLLForm');
        if Assigned(DLLSub) then
        begin
          DLLForm := DLLSub(Application, Screen);
        end;
      end;
      FreeLibrary(DLLHandle);//释放资源
    end;
      

  2.   

    你在DLL中存在CreateDLLForm函数,但存在FreeDellForm类似的函数吗? 是不是这个问题
      

  3.   

    我估计是我的DLL有问题!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,
      Forms,
      Windows,
      Messages,
      Unit1 in 'Unit1.pas' {Form1};{$R *.res}var
      DLLApp: TApplication;
      DLLScr: TScreen;function CreateDLLForm(App: TApplication; Scr: TScreen):TForm;
    var
      ptr:PLongInt;
    begin
      Application := App;
      Screen := Scr;
      Application.CreateForm(TForm1, Form1);
      result:=form1;
    end;procedure ExitDLL(Reason: Integer);
    begin
      if Reason = DLL_PROCESS_DETACH then
      begin
        Application := DLLApp;
        Screen := DLLScr;
        FreeAndNil(Form1); // 卸载时释放资源
        SendMessage(Application.Handle, WM_CLOSE, 0, 0);
        FreeLibrary(Application.Handle);  end;
    end;exports
      CreateDLLForm;
    begin
      DLLApp := Application;
      DLLScr := Screen;
      DLLProc := @ExitDLL;
    end.
      

  4.   

    不行呀!大哥能在帮我看看吗?
    其实我这里
    DLLProc := @ExitDLL;//这里已经是表示DLL 卸载时恢复原来的对象!
      

  5.   

    把以下几句去掉即可
        FreeAndNil(Form1); // 卸载时释放资源
        SendMessage(Application.Handle, WM_CLOSE, 0, 0);
        FreeLibrary(Application.Handle);