由于好几个EXE都有ABOUT窗体。就想把ABOUT做成DLL然后给EXE调用。建立了一个ABOUT.DLL,工程文件代码如下
library About;uses
SysUtils,
Classes,
AboutFrm in 'AboutFrm.pas' {FormAbout},
PubUnit in 'PubUnit.pas';{$R *.res}exports
ShowAboutFrm;beginend.
AboutFrm是窗体,其中没有加任何代码PubUnit是自己加的一个UNIT,代码如下unit PubUnit;interface
Uses Forms;procedure ShowAboutFrm(AHandle: THandle; ACaption: String);stdcall;implementation
Uses AboutFrm;procedure ShowAboutFrm(AHandle: THandle; ACaption: String);
var
AboutFrm: TFormAbout;
begin
Application.Handle := AHandle;
AboutFrm := TFormAbout.Create(Application); //创建并显示窗体
try
AboutFrm.Caption :=ACaption;
AboutFrm.ShowModal; //显示方式为模式化
finally
AboutFrm.Free; //用完后卸载该窗体
end;
end;
end.
程序调用的地方是这么写的
var
OneHandle:THandle;
ShowAboutFrm:procedure(AHandle: THandle; ACaption: String);stdcall;
begin try
try
OneHandle:=LoadLibrary('About.Dll');
if OneHandle<>0 then
@ShowAboutFrm := GetProcAddress(OneHandle,'ShowAboutFrm');
if Not (@ShowAboutFrm<>nil) then
ShowAboutFrm(Application.Handle,'关于')
else
RaiseLastWin32Error;
except
On E:Exception do
ShowMSG(E.Message);
end;
finally
FreeLibrary(OneHandle);
end;
end;程序运行时总报 A call to an OS function failed谢谢
library About;uses
SysUtils,
Classes,
AboutFrm in 'AboutFrm.pas' {FormAbout},
PubUnit in 'PubUnit.pas';{$R *.res}exports
ShowAboutFrm;beginend.
AboutFrm是窗体,其中没有加任何代码PubUnit是自己加的一个UNIT,代码如下unit PubUnit;interface
Uses Forms;procedure ShowAboutFrm(AHandle: THandle; ACaption: String);stdcall;implementation
Uses AboutFrm;procedure ShowAboutFrm(AHandle: THandle; ACaption: String);
var
AboutFrm: TFormAbout;
begin
Application.Handle := AHandle;
AboutFrm := TFormAbout.Create(Application); //创建并显示窗体
try
AboutFrm.Caption :=ACaption;
AboutFrm.ShowModal; //显示方式为模式化
finally
AboutFrm.Free; //用完后卸载该窗体
end;
end;
end.
程序调用的地方是这么写的
var
OneHandle:THandle;
ShowAboutFrm:procedure(AHandle: THandle; ACaption: String);stdcall;
begin try
try
OneHandle:=LoadLibrary('About.Dll');
if OneHandle<>0 then
@ShowAboutFrm := GetProcAddress(OneHandle,'ShowAboutFrm');
if Not (@ShowAboutFrm<>nil) then
ShowAboutFrm(Application.Handle,'关于')
else
RaiseLastWin32Error;
except
On E:Exception do
ShowMSG(E.Message);
end;
finally
FreeLibrary(OneHandle);
end;
end;程序运行时总报 A call to an OS function failed谢谢
解决方案 »
- 哪里能下载ARCGIS engine SDK for delphi?
- ADO插入数据的问题,在线等,解决完即给分,谢谢!
- 控件移动问题
- 好几年没来CSDN了,成立了公司,选择了别的行业,感触多多,散分
- 我晕,为什么那么简单的代码都不能实现窗口关闭??
- 关于数据显示的问题!! 请进来
- 请问如何向多个程序发消息?
- 哪里有单独安装 PARADOX 的程序?
- 如何使用TWebBrowser的Post方法,提交用户名和密码给163.com的首页
- 哪里有RSA加密的delphi源代码下载呀?
- 如何向dbgrid中连续添加多行以后,一起向数据库中保存?
- 一段sql语句,我执行like可以,执行<和>都无法返回数据
改為: ACaption: pchar;或者在代碼中修改如下:uses
ShareMem,
SysUtils,
Classes,
...兩邊都要加上這個 ShareMem
RaiseLastWin32Error;
except
On E:Exception do
ShowMSG(E.Message);
end;這部分代碼, 好象沒什麼用
ShowAboutFrm(Application.Handle,'关于')
else
RaiseLastWin32Error;