Menu Search

Borland Delphi

DLL - Loadlibrary Dynamic or static
procedure TForm1.Button2Click(Sender: TObject);
type
TCircleAreaFunc = function (const radius: double) : double; stdcall;
var
dllHandle : cardinal;
circleAreaFunc : TCircleAreaFunc;
begin
dllHandle := LoadLibrary(´circle.dll´) ;
if dllHandle <> 0 then
begin
@circleAreaFunc := GetProcAddress(dllHandle, ´CircleArea´) ;
if Assigned (circleAreaFunc) then
begin
circleAreaFunc(15); //call the function
ShowMessage(FloatToStr(circleAreaFunc(15))+´ found´) ;
end
else
ShowMessage(´"CircleArea" function not found´) ;
FreeLibrary(dllHandle) ;
end
else
begin
ShowMessage(´circle.dll not found / not loaded´) ;
end;
end;


procedure TForm1.Button3Click(Sender: TObject);
type
TFunc = function () : PChar; stdcall;
var
dllHandle : cardinal;
Func : TFunc;
s : String;
begin
dllHandle := LoadLibrary(´circle.dll´) ;
if dllHandle <> 0 then
begin
@Func := GetProcAddress(dllHandle, ´getDLLTitle´) ;
if Assigned (Func) then
begin
s := Func(); //call the function
ShowMessage(s+´ found´);
end
else
ShowMessage(´"getDLLTitle" function not found´) ;
FreeLibrary(dllHandle) ;
end
else
begin
ShowMessage(´circle.dll not found / not loaded´) ;
end;
end;
//Static
function CircleArea(const radius : double) : double; external ´circle.dll´;


//DLL Source Code
library circle;

uses
SysUtils, Classes, Math;

{$R *.res}
function getDLLTitle() : PChar; stdcall;
begin
result := ´circle.dll´;
end;

function CircleArea(const radius : double) : double; stdcall;
begin
result := radius * radius * PI;
end;

exports
CircleArea,
getDLLTitle;

begin
end.

Liste

Index | List
  • Vorherige
  • Seite #n
  • #n
  • #c
  • Seite #n
  • Nächste
Index | List
  • Vorherige
  • Seite #n
  • #n
  • #c
  • Seite #n
  • Nächste

Index

Index | List
  • Vorherige
  • Seite #n
  • #n
  • #c
  • Seite #n
  • Nächste
Index | List
  • Vorherige
  • Seite #n
  • #n
  • #c
  • Seite #n
  • Nächste

LetzteChance.Org - Links -

PDF/ZIP/Word