library P1001;
{ 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
Windows,
Messages,
Graphics,
Controls,
Forms,
Dialogs,
SysUtils,
Classes,
Ufrm1001 in 'Ufrm1001.pas' {frm1001},
UGlobal in '..CommonUGlobal.pas',
UTR_Thread in 'UTR_Thread.pas',
Ufrm4041 in '..CommonUfrm4041.pas' {frm4041},
SYSDAQCHARTLib_TLB in '..CommonSYSDAQCHARTLib_TLB.pas';
var
dllApp1001 : TApplication;
procedure MydllProc(Reason: Integer); register;
begin
if Reason = dll_PROCESS_DETACH then
{ dll이 메모리에서 내려갈때}
{ 애플리케이션 포인터를 원위치 시킨다. }
if Assigned(dllApp1001) then
Application := dllApp1001;
end;
//-----------------------------------------------------------------------------//
// 폼생성 //
//-----------------------------------------------------------------------------//
function Create_Frm1001(ParentApp:TApplication; nAddress:integer):THandle;cdecl;
var
FRM1001D : Tfrm1001;
i : integer;
result_boolean : boolean;
begin
if not Assigned(dllApp1001) then
begin
dllApp1001 := Application;
Application := ParentApp;
end;
i:=0 ;
result_boolean := true;
while i <= screen.FormCount-1 do
begin
if (uppercase(Screen.Forms[I].Name) = 'FRM1001') then
begin
Screen.Forms[I].bringtofront;
result_boolean := false;
Break;
end;
i := i + 1;
end;
if result_boolean then
begin
FRM1001D := Tfrm1001.Create(Application.MainForm);
FRM1001D.Main_Info := @Main_Information(Ptr(nAddress)^);
FRM1001D.dllApp := dllApp1001;
FRM1001D.MainApp := Application;
FRM1001D.Show;
result := FRM1001D.Handle;
end;
end;
//-----------------------------------------------------------------------------//
// DLL이 닫히기 전에 Applicationd을 원래 포인터로 지정한다. //
//-----------------------------------------------------------------------------//
procedure UnLoadLibrary;cdecl;
begin
if Assigned(dllApp1001) then
Application := dllApp1001;
end;
{$R *.res}
exports
Create_Frm1001,
UnLoadLibrary;
begin
{ dllApp1001 변수를 초기화 한다. }
dllApp1001 := nil;
DLLProc := @MydllProc;
end.
위는 dll 생성하는 소스입니다.
그런데 위의dll은 main이라는 exe화일을 실행한거에서요
dll 를 종료하지않고 바로 main.exe 를 종료하면 에러가 납니다
어떻게 해야 할지 알려주세요
main.exe의 close 부분에서는 dll 을
if not (GetProcAddress(P1001DLLHDL,'UnLoadLibrary') = nil) then
begin
UnLoadLibary := GetProcAddress(P1001DLLHDL,'UnLoadLibrary');
UnLoadLibary;
end;
아래처럼 dll을 종료하거든요
그런데 런타임 에러가 납니다
부탁드립니다