RE: [advanced_delphi] problem closing DLL load direct And indirect
"rizky" <[email protected]>
| Newsgroups | gmane.comp.lang.delphi.programming |
|---|---|
| Message-ID | <!~!UENERkVCMDkAAQACAAAAAAAAAAAAAAAAABgAAAAAAAAAYmQ7wwSlbkWa9nZkbLYY8sKAAAAQAAAAGvYQAJpTGUesheiL5jJTmAEAAAAA@sierad.co.id> |
For Ernesto Cullen :
Thank you man for your help...but it still doesn't work, the
EAccessViolation still appear I give you my code list if there is
something wrong with my code ..???
For Louis Nardozi :
The @sForm.free; // or equivalent, there is no @sForm.free methode on
my procedure but thanks anyway
Stay With Me Guys I need every help...thank you
On My DLL :
procedure ShowForm(ahandle:Thandle);export;stdcall;
implementation
{$R *.DFM}
procedure ShowForm(ahandle:Thandle);stdcall;
begin
Application.handle:=ahandle;
frmRkp:= TfrmRkp.Create(application);
try
frmRkp.ShowModal;
finally
frmRkp.free;
end;
end;
On My Main Form :
implementation
uses uDLL; //I use additional unit.pas to declare the procedure that I
want to export, im not using form unit.pas coz it //will make
my exe file bigger...is it ok with it ?
{ unit uDLL;
interface
type
tHandle = integer;
{$IFNDEF RekapPertumbuhanAngkatan}
procedure ShowForm(ahandle :
Thandle);stdcall;
{$ENDIF}
implementation
{$IFNDEF RekapPertumbuhanAngkatan}
procedure ShowForm;external
'RekapPertumbuhanAngkatan.dll' name 'ShowForm';
{$ENDIF}
end.}
type
tShowForm = procedure(ahandle:Thandle);stdcall;
procedure TfrmMain.Button1Click(Sender: TObject);
var
lhandle : tHandle;
sForm:tShowForm;
cDll:pChar;
begin
if cbListModule.Text <> '' then
begin
cDll := StrPCopy(cDll,cbListModule.Text+'.dll');
lHandle:=LoadLibrary(cDll);
try
if lHandle = 0 then
raise eDllLoadError.create('Dll Tidak Ada');
@sForm:= GetProcAddress(lhandle,'ShowForm');
if not (@sform = nil) then
begin
showform(Application.Handle);
end
else
RaiseLastWin32Error;
finally
FreeLibrary(lhandle);
end;
end;
end;
Richness Is Not Measure By How Much You Have...
But How Less You Need....
RichKey
-----Original Message-----
From: Ernesto Cullen [mailto:[email protected]]
Sent: Tuesday, January 01, 2002 9:55 PM
To: [email protected]
Subject: Re: [advanced_delphi] problem closing DLL load direct And
indirect
I don't know why the difference between the two methods, but maybe your
problem is that the dll have its own copy of TApplication and the
messages
for your dll's form are directed to it; when you get rid of the dll, the
messages are still sent to that (now invalid) instance of TApplication!
Try
this: after loading the library, assign its Application pointer to your
main application variable:
In your dll:
procedure ShowForm1(AHandle: THandle); stdcall;
begin
// Copy application handle to DLL's TApplication object
Application.Handle := AHandle;
Form1 := TForm1.Create(Application);
try
Form1.ShowModal;
Finally
Form1.Free;
end;
end;
In your main program:
@sForm:= GetProcAddress(LibHandle, 'ShowForm1');
if @sForm = nil then
RaiseLastWin32Error
else
MostrarForm1(Application.Handle);
Ernesto Cullen
-----Original Message-----
From: Louis Nardozi [mailto:[email protected]]
Sent: Tuesday, August 05, 2003 6:14 AM
To: [email protected]
Subject: Re: [advanced_delphi] problem closing DLL load direct And
indirect
rizky wrote:
> i have a problem when closing dll form which is load indirect (list
> 01)...the error message EAccessviolation keep appear when i click the
> close window button (x) or use the ' form.close ' syntax...but if i
> load the dll directly(list 02) the problem doesn't appear....So whats
> the different between that two method ?, which one should i use best
> ?, is there any other technique that i can use ?, and how can i get
> out from the error message if i want to use the indirect technique ?
>
> thanks a bunch guys....i really appriciate any help and suggestion
> that given to this message...
>
>
> list 01 :
> procedure TfrmMain.Button1Click(Sender: TObject);
> var
> lhandle : tHandle;
> sForm:tShowForm;
> cDll:pChar;
> begin
> if cbListModule.Text <> '' then
> begin
> cDll := StrPCopy(cDll,cbListModule.Text+'.dll'); //get DLL
> Name from combobox
> lHandle:=LoadLibrary(cDll); // Load DLL indirect
> try
> if lHandle = 0 then
> raise eDllLoadError.create('Dll Tidak Ada');
> @sForm:= GetProcAddress(lhandle,'ShowForm');
> if not (@sform = nil) then
> begin
> showform;
> end
> else
> RaiseLastWin32Error;
> finally
@sForm.free; // or equivalent
>
> FreeLibrary(lhandle);
> end;
> end;
> end;
>
>
>
> list 02 :
> procedure TfrmMain.Button1Click(Sender: TObject);
> var
> lhandle : tHandle;
> sForm:tShowForm;
> cDll:pChar;
> begin
> if cbListModule.Text <> '' then
> begin
> lHandle:=LoadLibrary('RekapPertumbuhanAngkatan.dll'); // Load
> DLL Direct
> try
> if lHandle = 0 then
> raise eDllLoadError.create('Dll Tidak Ada');
> @sForm:= GetProcAddress(lhandle,'ShowForm');
> if not (@sform = nil) then
> begin
> showform;
> end
> else
> RaiseLastWin32Error;
> finally
> FreeLibrary(lhandle);
> end;
> end;
> end;
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for Your HP, Epson, Canon or Lexmark
Printer at Myinks.com. Free s/h on orders $50 or more to the US & Canada. http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/sO0ANB/LIdGAA/ySSFAA/i7folB/TM
---------------------------------------------------------------------~->
CodeCoffer - new Delphi code protection Tool!
http://www.delphicollection.com/public/CodeCoffer.htm
---------------------------------------------------------------
Unsubscribe:[email protected]
List owner:[email protected]
---------------------------------------------------------------
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/