Forum > General

How to use DLL include a form ? why my code error?

(1/2) > >>

qiaoqia6448:
Main Application:

procedure TForm1.Button1Click(Sender: TObject);
var
   temp:integer;
   shandle:THandle;
   FPointer:Pointer;
   myfunc:TShowForm;
begin
   
    shandle:= LoadLibrary('prodll');
    if shandle<>0 then
    try
      FPointer:= GetProcAddress(shandle,'Showwindow');
      if FPointer<>nil then
      begin
         myfunc:=TShowForm(FPointer);
         myfunc;
      end else showmessage('No this proc!');
    finally
        FreeLibrary(shandle);
       
    end;
end;         


The DLL exports:

procedure ShowWindow ; stdcall;
begin

   try
      application.CreateForm(TForm1,form1);
     try
        form1.ShowModal;
     finally
         form1.Free;
     end;
   except on E:exception do
        messagedlg('Error in DllForm:'+E.message,mtError,[mbOK],0);
   end;
end;                         

If I close the DLL's form ,the Application will close too .

Leledumbo:
What if you call Show instead of ShowModal. Forms created with Application.CreateForm AFAIK has no owner (or is it desktop?). Or try creating with TForm1.Create.

captian jaster:
I can't quite put my finger on your problem..
Using units this way never gave me a problem but I have never tried it with a DLL.
Try:
Removing Stdcall(I doubt this has anything to with it. But I can't figure anything out)
Try to show the modal without using Application.CreateForm
Try using Show Instead of ShowModal

Martin_fr:
- Search the bug tracker, there is a known issue, that you can not use froms in dll.
- You can also search the "bounty" page of the wiki, afaik there is a bounty on it.
- And there are more posts about it in the forum.


In short the DLL has it's own application instance (and other global instances too).
the dll does not know about the form outside the dll (and the main app, does not know about the form inside the dll.

So in your case the application in the dll, believes the *last* form was closed => close application

qiaoqia6448:
In Dlephi:
   there is a procedure where in the dll can do
       procedure SynAPP(App:THandle);stdcall;
       begin
            Application.Handle:=App;
       end;
   call the procedure then Use DLL to tall the dll's form the Application's real Handle.
But in Lazarus ,there is'nt Application.Handle property.
 :'( How?

My English is poor...........

Navigation

[0] Message Index

[#] Next page

Go to full version