sexta-feira, 30 de setembro de 2016

DELPHI - Como lêr funções/procedures na DLL - How to read function/procedure in the DLL

Segue abaixo uma das formas para ler DLLs no Delphi.
A dll tem que estar na mesma pasta do executavel.
var
  DLLHandle :THandle;
  NomeDaFuncaoOuProcedure :function(Parametro1:String; Parametro2 :Integer):String; stdcall;
  Retorno :String;
begin
  try
    try
      DLLHandle := LoadLibrary('NomeDaDLL.dll');

   if DLLHandle > 0 then
   begin
    NomeDaFuncaoOuProcedure := GetProcAddress(DLLHandle, 'NomeDaFuncaoOuProcedure');

    Retorno := NomeDaFuncaoOuProcedure(Parametro1, Parametro2);
   end
  raise Exception.Create('DLL não encontrada.');
    finally
      FreeLibrary(DLLHandle);
    end;
  except on E: Exception do
    ShowMessage(E.Message);
  end;
end;

Nenhum comentário:

Postar um comentário