重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

Delphi中动态调用DLL中的窗体-创新互联

DLL链接库代码

目前成都创新互联已为超过千家的企业提供了网站建设、域名、网站空间网站运营、企业网站设计、新宁网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
Library Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1};
Function ShowForm(AHandle:THandle):Boolean;StdCall;
var
AForm:TForm1;
begin
Result:=False;
Application.Handle:=AHandle;
AForm:=TForm1.Create(Application);
Try
AForm.ShowModal;
Result:=True;
Finally
AForm.Free;
end;
end;
{$R *.res}
exports
ShowForm;
begin
end.

Form中调用代码

unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TShowForm=Function (AHandle:THandle):Boolean;Stdcall;   //001
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var mainfrm,DllForm:THandle;                            //002
ShowForm:TShowForm;                            //003
begin
mainfrm:=Form1.Handle;                           //004
DllForm:=LoadLibrary('hello.dll');              //005
Try
begin
if DllForm<>0 then
begin
@ShowForm:=GetProcAddress(DllForm,'ShowForm');
ShowForm(mainfrm);
end
else
begin
RaiseLastWin32Error;
end;
end;
Finally
FreeLibrary(DllForm);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
end;
end.

当前名称:Delphi中动态调用DLL中的窗体-创新互联
文章分享:http://cqcxhl.com/article/csdiis.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP