Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 143
  • Last Modified:

connection to dll

Hello,

Is ther an easy way to connect delphi application with DLL (not ocx/activeX) ?


thank you
Asi
0
asi
Asked:
asi
  • 2
1 Solution
 
mokuleCommented:

Suppose You have library Export.Dll with procedure _WriteTXT.
Put the line below to Your interface section and You can use it.

procedure _WriteTXT(fname,tekst: PChar);cdecl; external 'Export.Dll';

Of course cdecl use when appropriate.
0
 
Ivanov_GCommented:

   another possibility :

   procedure YourProcedureName (Param1, Param2 : Integer); {$IFDEF WIN32} stdcall;{$ENDIF}
   ...
   var DLLHandle : Integer;
   ...
      DLLHandle := LoadLibrary(YourDLLlibrary.dll);
      @YourProcedureName := GetProcAddress(DLLHandle, 'ProcedureInDLL');

   and then you execute YourProcedureName as usual.
0
 
Melih SARICACommented:
Here is a small dll sample:

library MyLibrary;

uses ........ ;
exports
   myProcedure;

Procedure myProcedure(mEdit:Tedit);safecall;
begin
   mEdit.text:='Hello From DLL';
end;

end;

And the way to Call it from  ur Delphi application
 there r 2 ways.. as Ivanov and mokule says...

in the way mokule said..

  dll is loaded when ur application is start running .. loaded in to the memory.. And ur procedure ll be loaded too

but in the way Ivanov told;
  UR dll ll be loaded with the procedure loadlibrary and ur procedure ll be loaded with GetProcAddress..

The way ivanov told is the best in my opinion.. Why ?  Only ur application ll be loaded in to the memory.. it means , if u use lots of dll's u wont  waste memory with loading unused procedures.  U ll load the Dll's when ever u want..  U ll have a control over all Dll's and procs. Loading and unloading..

 
 
 

 
i
0
 
Ivanov_GCommented:

   I think so, because when you finish executing the function you can cal

   FreeLibrary(DLLHandle);

   and relese some memory
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now