1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| const
DLLName = 'DLLTestVC.dll';
//function Add(a,b:double):double; stdcall; external DLLName;
type
TDLLSomme = function (param1,param2: double): double; cdecl;
procedure TForm4.Button1Click(Sender: TObject);
var
hDLL: THandle;
Somme: TDLLSomme;
a,b: double;
begin
hDLL:= LoadLibrary(pChar(DLLName));
if (hDLL < HINSTANCE_ERROR) then
raise Exception.Create(DLLName + 'erreur au chargement' +
SysErrorMessage(GetLastError));
try
@Somme:=GetProcAddress(hDLL,'Add');
if Assigned(Somme) then
begin
a:= 2.5;
b:= 1.5;
label1.Caption:= FloatToStrF(Somme(a,b),ffFixed,5,2);
end else ShowMessage('La fonction "Add" n''a pas été trouvée dans la DLL');
finally
FreeLibrary(hDLL);
end;
end; |
Partager