5,391
社区成员
发帖
与我相关
我的任务
分享
library Project2;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
Forms,
Classes,
Windows,
SysUtils,
Dialogs,
Unit2 in 'Unit2.pas' {Form2};
{$R *.res}
var
DLLAPP : TApplication;
DLLScr: TScreen;
i : Integer;
function MyTestOpen(App: TApplication; Scr: TScreen) : TForm;
var
APt : PLongint;
begin
Application := App;
DLLScr := Scr;
Application.Title := 'aaaaaaaa';
Application.CreateForm(TForm2, Form2);
Form2.Show;
result := nil;
end;
procedure ExitDLL(Reason: Integer);
begin
if Reason = DLL_PROCESS_DETACH then
begin
if Assigned(Form2) then
begin
FreeAndNil(Form2);
end;
Application := DLLApp;
Screen := DLLScr;
end;
end;
exports
MyTestOpen;
begin
DLLAPP := Application;
DLLScr := Screen;
DllProc := @ExitDLL;
end.
procedure TForm1.aaaa1Click(Sender: TObject);
type
DLLForm = function(App: TApplication; Scr: TScreen): TForm;
var
DLLHandle: THandle;
DLLSub: DLLForm;
begin
DLLHandle := LoadLibrary('D:\Test\DLL\Project2.dll');
if DLLHandle <> 0 then
begin
@DLLSub := GetProcAddress(DLLHandle, 'MyTestOpen');
if Assigned(DLLSub) then
begin
DLLForm := DLLSub(Application, Screen);
end;
end;
FreeLibrary(DLLHandle);
end;