从dll调用一个窗体,现在碰到一个问题,
如果主程序引用了xpman单元(xp主题),这样从dll中的调用的窗体也具有xp主题,但在关闭程序时会报错。(窗体中有button,memo等控件,若没有任何控件,不会报错)。错误是uxtheme.dll抛出来的。不知道谁有解决方法 ?
用的是delphi7, 其它版本还没试过。
如果主程序引用了xpman单元(xp主题),这样从dll中的调用的窗体也具有xp主题,但在关闭程序时会报错。(窗体中有button,memo等控件,若没有任何控件,不会报错)。错误是uxtheme.dll抛出来的。不知道谁有解决方法 ?
用的是delphi7, 其它版本还没试过。
解决方案 »
- (100分提問)inno setup 5编绎安装后连不上 sql server服务器
- 一个小问题?
- 想挑战高难度的朋友请进来看看:在fastreport中如何制作高难度的报表?重酬!!!
- 在一个表中选择到符合条件的记录后放到dbgrid中,然后供用户再从中挑选,最后存入另外一个表中,怎么做??
- 请问开发一个考勤就餐系统(IC卡)大概要多长时间?
- RegisterComponentEditor的问题,高手请进
- Listview最多能容纳多少行(在vsReport模式下)?
- 请问,如何用代码在自己的应用程序中得到一个系统dll文件的版本信息?最好写出例程.给分!!
- 如何删除已经注册的远程数据模块?
- IP的问题
- 如何把一个数据库中的表拷贝到另一个数据库中
- 关于调用dll文件的问题
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模式)
var
AForm: TForm;
begin
AForm := TestForm(nil);
AForm.ShowMoudel;
end;
procedure TForm2.Button1Click(Sender: TObject);
var
AForm: TForm;
begin
AForm := TestForm(nil);
AForm.ShowModal;
end; 或者在dll中uses XPman试试
于是,你的问题解决了。至于什么原理,你可以在网上搜一下CoInitialize函数的功能即可。
还是没解决问题呀 还有谁有高招?
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.
senyangwu 发个给我,谢谢
[email protected]