我建了一个DLL文件,里面有一个MDI子窗体,一个创建该窗体的函数,DLL工程中也用exports导出这个函数了,可是为什么我调这个函数后创建窗体的时候会出现错误呢?如果把这个窗体放到Application工程中就不会出错了,谁有遇到这样的问题,请帮帮忙啊
unit unitUserListInit;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, DBClient, MConnect, SConnect, unitUserListWin;function OpenUserList(PublicSocketConnection:TObject):Boolean;implementationfunction OpenUserList(PublicSocketConnection:TObject):Boolean;
begin
  frmUserList:=TfrmUserList.Create(Application);     //执行到这儿出错
  frmUserList.Show;
  OpenUserList:=False;
end;end.调用的地方unit unitMainWin;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, unitDLLInterface;type
  TfrmMainWin = class(TForm)
    mmMainMenu: TMainMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    N3: TMenuItem;
    N4: TMenuItem;
    N5: TMenuItem;
    procedure N2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  frmMainWin: TfrmMainWin;implementationuses unitUserListWin;{$R *.dfm}function OpenUserList(PublicSocketConnection:TObject):Boolean;far;external 'UserListDLL.dll'procedure TfrmMainWin.N2Click(Sender: TObject);
begin
  OpenUserList(mmMainMenu);
end;end.

解决方案 »

  1.   

    不知道楼主的PublicSocketConnection:TObject参数的用途
    你试着先把主程序的Application.Handle作为参数传给DLL
    比如:
      procedure SetAppHandle(AHandle:HWND);StdCall;
      begin
        Application.Handle:=AHandle;
      end;然后再调用你的过程,看看
      

  2.   

    呵呵,mdi+dl  l确实比较麻烦,这个问题问我就对了,我去年公司做项目时也遇到这个问题。因为dll shi function ShowForm(app: TApplication):boolean;stdcall;
    var
      p:PLongInt;
    begin
      p := @(Application.MainForm);
      p^ := LongInt(mainForm);
      if frmChild = nil then
        frmChild := TFormDLL.Create(app);
      try
        Form1.Show;
        result := true;
      except
        result:= false;
      end;
    end;
    ////////////////////////////////////////function OpenUserLi(PublicSocketConnection:TObject):Boolean;stdcall;external 'UserListDLL.dll'procedure TfrmMainWin.N2Click(Sender: TObject);
    begin
      ShowForm(application);
    end;
      

  3.   

    因为DLL是外部工程,有自己的APPLICATION,在调用时要传入宿主(主程序)程序的APPLICATION 或着APPLICATION.MAINFORM,仿真宿主程序的子窗体(这是MDI 和SDI 的不同)
      

  4.   

    //送你个完整的例子;只要自己创建一个TfrmDLLForm就可以了。library P_MyDLL;uses
      SysUtils,
      Forms,
      Windows,
      Messages,
      Classes,
      ActiveX,
      DLLFormUnit in 'DLLFormUnit.pas' {frmDLLForm};{$R *.res}var
      DLLApp: TApplication;
      DLLScr: TScreen;
    function CreateDLLForm(App: TApplication; Scr: TScreen):TForm;
    begin
      Application := App;
      Screen := Scr;  //CoInitialize(nil) ;
      Application.CreateForm(TfrmDLLForm, frmDLLForm);
      result:=frmDLLForm;end;procedure ExitDLL(Reason: Integer);
    begin
      if(Reason = DLL_PROCESS_ATTACH) then 
      begin
        CoInitialize(nil) ;
      end ;  if Reason = DLL_PROCESS_DETACH then
      begin
        Application := DLLApp;
        Screen := DLLScr;
        CoUninitialize ;
      end;
    end;exports
      CreateDLLForm;begin
      DLLApp := Application;
      DLLScr := Screen;
      DLLProc := @ExitDLL;end.
      

  5.   

    去DELPHI盒子找例子,里面有一个