RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
Delphi中动态调用DLL中的窗体

DLL链接库代码

兴安网站制作公司哪家好,找成都创新互联!从网页设计、网站建设、微信开发、APP开发、响应式网站建设等网站项目制作,到程序开发,运营维护。成都创新互联成立于2013年到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选成都创新互联

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://sczitong.cn/article/pescoo.html