温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Delphi中动态调用DLL中的窗体

发布时间:2020-07-05 04:39:06 来源:网络 阅读:1142 作者:hack9527 栏目:软件技术

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.

 

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI