Ver Funções de uma dll

Delphi

22/07/2005

olá pessoal,

como eu faço para ver as functions q tem dentro de uma dll?


Tap_pedroso

Tap_pedroso

Curtidas 0

Respostas

Daemon

Daemon

22/07/2005

....então cara. ..o lance é o seguinte. ..eu criei uma dll com validações e fiz um sistema baseado no que vc quer, segue abaixo as funções que vc vai precisar:

var
   gsValidacoes: TStrings;


em ´[b:afaedde4d9]Private[/b:afaedde4d9]´ vc declara:
   FhDllHandle: Integer; // Handle para a DLL
    FfnValidation: TValidationFunction;
    FslFunctionNames: TStringList;



e essas Funções:

//Para Carregar a DLL
procedure TdmPrin.Validacoes;
begin
   {
   gsValidacoes := TStrings.Create;
   FslFunctionNames := TstringList.Create;
   {}

   if fnLoadDll(´VALIDA.DLL´) then
      frmCadastro.lbValidacoes.Items.Assign(FslFunctionNames)
   else
      ShowMessage(´Erro ao carregar DLL !!!´);

end;

//Carrega a DLL
function TdmPrin.fnLoadDll(DllName: String): Boolean;
var
   pAux: array[0..2047] of char;
begin

   Result := False;
   try
      FslFunctionNames := TStringList.Create;

      // Carrega a Dll
      FhDllHandle := LoadLibrary(PChar(DllName));
      if FhDllHandle <> 0 then
      begin
         // Pega o endereço da função Open...
         @FfnValidation := GetProcAddress(FhDllHandle,´VldGetFunctionNames´);
         if @FfnValidation <> nil then
         begin
            if FfnValidation(pAux,SizeOf(pAux)) then
            begin
               FslFunctionNames.Text := StrPas(pAux);
               Result := True;
            end;
         end
         else
         begin
            // Descarrega a DLL, pois não encontrou as funções necessárias
            FreeLibrary(FhDllHandle);
            FhDllHandle := 0;
         end;
      end;
   except on E:Exception do
      Application.ShowException(E);
   end;

end;

//Carrega a DLL
function TdmPrin.Validar(campo:String; var valor:string):boolean;
var
   slAux: TStringList;
   pAux: array[0..2047] of char;

begin

   result := false;
   if @FfnValidation <> nil then
   begin

      StrPCopy(pAux,Valor);
      if FfnValidation(pAux,Length(Valor)) then
      begin
         Valor := StrPas(pAux);
         result := true;
      end
      else
         Application.MessageBox(PChar(´Valor inválido para o campo: ´ + QuotedStr(campo) + ´.´), ´Atenção´, mb_IconWarning + MB_Ok);

      {
      if ListBox1.Items.Names[ListBox1.ItemIndex] <> ´VldVerificaNaTabela´ then
      begin

         StrPCopy(pAux,Valor);
         if FfnValidation(pAux,Length(Valor)) then
         begin
            Valor := StrPas(pAux);
            ShowMessage(´VALIDAÇÃO OK !´);
         end
         else
         begin
            ShowMessage(´Valor inválido !!!´);
         end;
      end
      else
      begin
         slAux := TStringList.Create;
         try
            slAux.Add(Format(´DataBaseName=¬s´,[Edit2.Text])); // DataBaseName da Tabela
            slAux.Add(Format(´TableName=¬s´,[Edit3.Text])); // Nome da Tabela
            slAux.Add(Edit1.Text); // Condição SQL
            StrPCopy(pAux,slAux.Text);
            if FfnValidation(pAux,SizeOf(pAux)) then
            begin
               ShowMessage(´ACHOU REGISTRO NA TABELA!´);
               Memo1.Lines.Text := StrPas(pAux);
            end
            else
            begin
               ShowMessage(´NÂO ACHOU registro!!!´);
               Memo1.Clear;
            end;
         finally
            slAux.Free;
         end;
      end;
      {}
   end
   else
     result := true;
end;

//Define o nome da função
procedure TdmPrin.SetValidacao(Validacao:String);
begin

  @FfnValidation := GetProcAddress(FhDllHandle,PChar(Validacao));

end;



.....se tente fazer isso com uma dll que tenha ai ......se não conseguir entender. ....dah um toque. ..

flws...


GOSTEI 0
POSTAR