Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Caling DLL from Delphi

Status
Not open for further replies.

ManojKG

Programmer
Sep 30, 2002
6
0
0
IN
hello,

I am having some Delphi compiled DLLs, and i am calling them in my application using Loadlibrary() function and the procedures using getproaddress().

Now the problem is while opening a form in the DLL through exe, a new instance are created and showing that in the tast bar.

I want the form to be displayed in the same handler of exe.

please give me a small example to call DLLs in delphi in proper way.


Manoj
 
hi Manoj,

please refer to Delphi help topic "TApplication.Handle".

Inside your DLL you have to set Application.Handle to the handle of the exe's main form.

I do this the following way:


in DLL:

var
MainFormHandle: THandle = 0;
procedure SetMainHandle(aHandle: THandle);
begin
MainFormHandle := aHandle;
end;
procedure DoIt(blabla...); // your code to show a form
begin
end;

export both procedures from the DLL


now in the main (exe) program write:

type
TSetMainHandleProc = procedure(aHandle: THandle);
TDoItProc = procedure(blabla...);
begin
DLLHandle := LoadLibrary(...);
p := GetProcAddress(DLLHandle, 'SetMainHandle');
TSetMainHandleProc(p)(Application.MainForm.Handle);
p := GetProcAddress(DLLHandle, 'DoIt');
TDoItProc(p)(blabla); // Do something with DoIt
end;

initialize the DLL with following code:

procedure DoIt(blabla...);
begin
Application.Handle := GetMainFormHandle;
...; // rest of your code
end;


this will avoid creating a task bar entry for each of your dll forms.
Anyway I still cannot minimize the DLL's forms together with the main programm....

wbr
Roderich
 
sorry, with this code Application.Handle inside the DLL is set twice.


this code is not needed:

initialize the DLL with following code:

procedure DoIt(blabla...);
begin
Application.Handle := GetMainFormHandle;
...; // rest of your code
end;


wbr
Roderich
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top