转别人的1.首先用delphi建一个dll工程:代码如下:library Project2;uses SysUtils, Classes, Unit1 in 'Unit1.pas' {Form1}; //dll中的窗体为Form1procedure ShowTest();stdcall; //dll函数 用于显示窗体varf:TForm1;beginf:=TForm1.Create(nil);try f.ShowModal;finally f.Free;end;end;{$R *.res}exports ShowTest; //外部调用函数beginend.2.新建Form1窗体,窗体为空窗体--》Unit1.pas。unit Unit1;interfaceusesWindows, SysUtils, Controls, Forms;typeTForm1 = class(TForm)private { Private declarations }public { Public declarations }end;varForm1: TForm1;implementation{$R *.dfm}end.3. CTRL+F9编译dll。 编译成功,并生成Project2.dll4.新建工程,Project1. 采用动态调用dll方式:unit Unit_main;interfaceusesWindows, SysUtils, Classes, Controls, Forms, StdCtrls;typeTForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject);private { Private declarations }public { Public declarations }end;varForm1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);typemypointer=Procedure();stdcall;varHandle:THandle;frm_p:mypointer;beginHandle:=loadlibrary('Project2.dll');if Handle>32 thenbegin frm_p:=GetProcAddress(Handle,'ShowTest'); if @frm_p<>nil then frm_p;end;Freelibrary(Handle);end;end.5. 修改Project1.dpr文件,加上Sharemem: uses Sharemem ,Forms, //添加Sharemem Unit_main in 'Unit_main.pas' {Form1};6. 运行Project1,点击Button1,实现调用出dll窗体。本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/genispan/archive/2009/03/11/3981926.aspx