P
pu-tian
Unregistered / Unconfirmed
GUEST, unregistred user!
主工程
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
主单员文件
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Menus;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
type
tfun=function(app:TApplication):TForm;
var
f:tfun;
h:HWND;
frm:tform;
begin
h:=loadlibrary(pchar('Project2.dll'));
@F:=GetProcAddress(h,'CF');
frm:=f(Application);
frm.Show;
end;
end.
////////////////////////////////////////////////////////////////////////////
///Dll工程文件
////////////////////////////////////////////////////////////////////////////
Library Project2;
uses
Forms,
Windows,
SysUtils,
Messages,
Classes,
Unit2 in 'Unit2.pas' {Form2};
{$R *.res}
var
DLLApp: TApplication;
function CF(App: TApplication):TForm;
begin
Application := App;
Application.CreateForm(TForm2, Form2);
result:=Form2;
end;
procedure ExitDLL(reason:Integer);
begin
if Reason = DLL_PROCESS_ATTACH then
begin
Application := DLLApp;
end;
end;
exports
CF;
begin
DLLApp := Application;
DLLProc := @ExitDLL;
end.
//////////////////////////////////////////////////////////////////////////
//Dll单元文件
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus;
type
TForm2 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
end.
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
主单员文件
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Menus;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
type
tfun=function(app:TApplication):TForm;
var
f:tfun;
h:HWND;
frm:tform;
begin
h:=loadlibrary(pchar('Project2.dll'));
@F:=GetProcAddress(h,'CF');
frm:=f(Application);
frm.Show;
end;
end.
////////////////////////////////////////////////////////////////////////////
///Dll工程文件
////////////////////////////////////////////////////////////////////////////
Library Project2;
uses
Forms,
Windows,
SysUtils,
Messages,
Classes,
Unit2 in 'Unit2.pas' {Form2};
{$R *.res}
var
DLLApp: TApplication;
function CF(App: TApplication):TForm;
begin
Application := App;
Application.CreateForm(TForm2, Form2);
result:=Form2;
end;
procedure ExitDLL(reason:Integer);
begin
if Reason = DLL_PROCESS_ATTACH then
begin
Application := DLLApp;
end;
end;
exports
CF;
begin
DLLApp := Application;
DLLProc := @ExitDLL;
end.
//////////////////////////////////////////////////////////////////////////
//Dll单元文件
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus;
type
TForm2 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
end.