从dll调用一个窗体,现在碰到一个问题,
如果主程序引用了xpman单元(xp主题),这样从dll中的调用的窗体也具有xp主题,但在关闭程序时会报错。(窗体中有button,memo等控件,若没有任何控件,不会报错)。错误是uxtheme.dll抛出来的。不知道谁有解决方法 ?
用的是delphi7, 其它版本还没试过。

解决方案 »

  1.   

    这是动态库的代码library dlltest;uses
      SysUtils,
      Classes,
      Forms,
      Unit1 in 'Unit1.pas' {Form1}; //窗体TForm1, 就放一个speedbutton{$R *.res}function TestForm(App: TApplication): TForm; stdcall;
    begin
      Application.Handle := App.Handle;
      if Form1 = nil then
        Form1 := TForm1.Create(Application);
      Result := Form1;
    end;exports TestForm;begin
    end.
    下面是主程序中调用的代码uses XPMan;  //使用xp主题
    ...
    function TestForm(App: TApplication): TForm; stdcall; external 'dlltest.dll';implementation{$R *.dfm}procedure TForm2.Button1Click(Sender: TObject);
    var
      AForm: TForm;
    begin
      AForm := TestForm(Application);
      AForm.Show;
    end;
    这样调用后,关掉主程序时就会报错,(当然,你的系统必须是xp模式)
      

  2.   

    procedure TForm2.Button1Click(Sender: TObject);
    var
      AForm: TForm;
    begin
      AForm := TestForm(nil);
      AForm.ShowMoudel;
    end;
      

  3.   


    procedure TForm2.Button1Click(Sender: TObject); 
    var 
      AForm: TForm; 
    begin 
      AForm := TestForm(nil); 
      AForm.ShowModal; 
    end; 或者在dll中uses XPman试试
      

  4.   

    呵呵,你的问题我遇到过。先包含Uses ActiveX,然后在你的程序中执行CoInitialize(nil);
    于是,你的问题解决了。至于什么原理,你可以在网上搜一下CoInitialize函数的功能即可。
      

  5.   

    dll的所有对象,都修要手工删除!
      

  6.   

    用了CoInitialize(nil);
    还是没解决问题呀 还有谁有高招?
      

  7.   


    library dlltest;uses
      SysUtils,
      Classes,
      Windows,
      Forms,
      Unit1 in 'Unit1.pas' {Form1}; //窗体TForm1, 就放一个speedbutton{$R *.res}var
      DllAppHandle: THandle;  //.......//DLL入口函数
    procedure DllEntryPoint(dwReason : DWORD);
    begin
      case dwReason of
         DLL_PROCESS_ATTACH : ;
         DLL_PROCESS_DETACH : begin
                                Application.Handle := DllAppHandle;
                              end;
         DLL_THREAD_ATTACH : ;
         DLL_THREAD_DETACH : ;
      end;
    end;function TestForm(App: TApplication): TForm; stdcall;
    begin
      Application.Handle := App.Handle;
      if Form1 = nil then
        Form1 := TForm1.Create(Application);   //换成Form1 := TForm1.Create(nil)试试
      Result := Form1;
    end;exports TestForm;begin
      DllAppHandle := Application.Handle;
      DllProc := @DllEntryPoint;
    end.
      

  8.   

    确实不行的话,留个E-mail我发个通过接口显示DLL中窗体的例子给你,也许对你有用。
      

  9.   

    学习
    senyangwu 发个给我,谢谢
    [email protected]