调用Dll里面的窗体
2020-12-13 05:38
interface
uses
Windows, Messages, SysUtils,
Variants, Classes, Graphics, Controls, Forms,
Dialogs,
StdCtrls;
//-------------------------------------------------------------------------------
procedure Dll_Showform();stdcall;external ‘project2.dll‘; //1无参数
直接调用
procedure
Dll_Createform(Left,Top,Width,Height:Integer);stdcall;external ‘project2.dll‘;//2带参数了
function DLL_GetValue():string;stdcall;external ‘project2.dll‘;//3获得返回值
//-------------------------------------------------------------------------------
type
TfrmMain1 = class(TForm)
Button1:
TButton;
Button2:
TButton;
Button3:
TButton;
Memo1:
TMemo;
Button4:
TButton;
procedure
Button1Click(Sender: TObject);
procedure Button2Click(Sender:
TObject);
procedure
Button3Click(Sender: TObject);
procedure Button4Click(Sender:
TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmMain1: TfrmMain1;
implementation
{$R
*.dfm}
//------------------------------------------------------------------------------
procedure TfrmMain1.Button1Click(Sender:
TObject);
begin
Dll_Showform;
end;
//------------------------------------------------------------------------------
procedure TfrmMain1.Button2Click(Sender:
TObject);
var
x,y:Integer;
begin
x:=frmMain1.left+Button2.left+8; //Left
y:=frmMain1.Top+Button2.Top +Button2.Height+28; //Top
Dll_Createform(x,y,400,400);
// Dll_Createform(0,0,100,200);
end;
//------------------------------------------------------------------------------
procedure TfrmMain1.Button3Click(Sender:
TObject);
begin
Memo1.Text:=DLL_GetValue;
end;
//------------------------------------------------------------------------------
type
TSetCaption = procedure(text:string); stdcall;//4回调
procedure
TfrmMain1.Button4Click(Sender: TObject);
var
pSetTitle:
TSetCaption;
h:THandle;
begin
h:=LoadLibrary(PChar(‘project2.dll‘));
pSetTitle
:= TSetCaption( GetProcAddress(h, PChar(‘DLL_SetTitle‘)) );
if h = 0 then
Exit;
if
Assigned(pSetTitle) then
pSetTitle(‘Hello
World!‘);
FreeLibrary(h);
end;
end.
下一篇:Python基础(二)