PAGUE 6 MESES
LEVE 12 MESES
GARANTIR DESCONTO

Fórum Erro retorno DLL #375463

30/09/2009

0

Fiz uma simples DLL, e o retorno dela funciona correta quando declarada implicitamente. Porém quando ela é declarada explicitamente (dinamica) ela retorna um valor nada a ver.

Abaixo DLL:

library DLL;

uses
SysUtils,
Classes;

{$R *.res}

function Triple(N: Integer): Integer; stdcall;
begin
Result := N * 3;
end;

function Double (N: Integer): Integer; stdcall;
begin
Result := N * 2;
end;

exports
Triple, Double;

begin
end.


Fonte que chama ela:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, Unit2;

type
  TForm1 = class(TForm)
    ProgressBar1: TProgressBar;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    ProgressBar2: TProgressBar;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    Testes  : TMinha;
    Testes1 : TMinha;

  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function Triple(N : Integer) : Integer; stdcall; external ´R:\DLL.DLL´;

procedure TForm1.Button5Click(Sender: TObject);
begin
   ShowMessage(IntToStr(Triple(2)));
end;

procedure TForm1.Button6Click(Sender: TObject);
var
   Janela : THandle;
   Trip : function(N : Integer) : Integer;
begin
   Janela := LoadLibrary(´R:\DLL.DLL´);
   @Trip := GetProcAddress(Janela, ´Triple´);
   if @Trip = nil then
      ShowMessage(´Erro´)
   else
      ShowMessage(IntToStr(Trip(3)));
end;



Et.vinny

Et.vinny

Responder

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar