Problema na criação de DLLs (Urgente)

12/07/2008

0

Estou tentando criar uma DLL com o Delphi 7. O problema é que para toda DLL que eu crio nenhuma funciona. Sendo mais claro: No ato do desenvolvimento fica tudo certinho, mas quando vou utilizada a mesma não funciona, daí quando vou ´debugar´ colocando um ´breakpoint´, apesar da linha estar correta, o ´breakpoint´ aponta como se fosse uma linha errada. O que pode ser isso? Como posso resolver esse problema? Faz tempo que ´bato-cabeça´ e não consigo resolver. Cheguei ao ponto de FORMATAR a máquina e instalar somente o Windows XP, Delphi 7, Interbase e o Office XP. Não coloquei mais nada. Tudo não tentativa de descartar qualquer falha de sistema.

Obrigado a todos e aguardo qualquer orientação.


Aprendiz_ce

Aprendiz_ce

Responder

Posts

12/07/2008

Luiz Henrique

Bom dia Aprendiz_ce

Possuo algumas DLL´s em funcionamento, de todo tipo e de varios objetivos, todas funcionam bem, pois o Delphi posso te assegurar que nao tem problema quanto a isso. Se vc nos disser o erro que da e postar a tua DLL aqui, poderemos te ajudar.

Abraço , T+


Responder

12/07/2008

Aprendiz_ce

[quote:80addcbcde=´Luiz Henrique´]Bom dia Aprendiz_ce

Possuo algumas DLL´s em funcionamento, de todo tipo e de varios objetivos, todas funcionam bem, pois o Delphi posso te assegurar que nao tem problema quanto a isso. Se vc nos disser o erro que da e postar a tua DLL aqui, poderemos te ajudar.

Abraço , T+[/quote:80addcbcde]

Olá,

Também concordo com você quanto ao Delphi... Daí a minha surpresa!

Vou passar um código bem simples que testei por ultimo, mas que não consigo fazer funcionar.

Segue abaixo:

program Project1;

uses
Forms,
Unit1 in ´Unit1.pas´ ;

{$R *.res}

begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

unit Unit1;

interface

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

type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

function Max(a, b : double):double;stdcall;

var
Form1: TForm1;

implementation

{$R *.dfm}

function Max(a, b : double):double;external ´project1´;

procedure TForm1.Button1Click(Sender: TObject);
var
x, y, resultado : double;
begin
x := StrToFloat(Edit1.Text);
y := StrToFloat(Edit2.Text);
resultado := Max(x,y);
ShowMessage(´Valor Máximo ´ +FloatToStr(resultado));
end;

end.

Quando tento utiliza-la a segunte mendagem é retornada:

Aplicativo não inicializado corretamente (0xc000007b). Clique em ´OK´ para finalizar e execução.

Obs. Tanto faz quando a mesma é carregada por outro programa ou quando tento depura-la sem ´breakpoint´... Se coloco um ´breakpoint´ mesmo que veja bem no inicio de um eventos... É apontado como erro (sinal de ´x´ em vermelho).

E aí, o que pode ser? Estou preocupado, pois minha cabeça pode rolar...

Muito obrigado pela sua atenção e aguardo retorno.

Abraço.


Responder

12/07/2008

Aprendiz_ce

Faltou o principal...

library Project1;

{ Important note about DLL memory management: ShareMem must be the
first unit in your library´s USES clause AND your project´s (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }

uses
SysUtils,
Classes;

{$R *.res}

Function Max(a, b : double ) : double ; Export ; stdcall ;
begin
If (a > b) then
Result := a
else
Result := b ;
end ;

begin
end.


Responder

14/07/2008

Niubi

Me parece que em sua api faltou vc exportar sua função.


Responder

14/07/2008

Luiz Henrique

Blz aprendiz...

faça estes ajustes que vai funcionar:
Na dll.
...
{$R *.res}

Function Max(a, b : double ) : double ; stdcall ;
begin
If (a > b) then
Result := a
else
Result := b ;
end;

exports Max;

end.

...na execucao...somente esta declaracao...

{$R *.dfm}

function Max(a, b : double):double; stdcall; external ´project1´;


...blz, espero que ajude, t+


Responder

14/07/2008

Aprendiz_ce

[quote:313efd319f=´Luiz Henrique´]Blz aprendiz...

faça estes ajustes que vai funcionar:
Na dll.
...
{$R *.res}

Function Max(a, b : double ) : double ; stdcall ;
begin
If (a > b) then
Result := a
else
Result := b ;
end;

exports Max;

end.

...na execucao...somente esta declaracao...

{$R *.dfm}

function Max(a, b : double):double; stdcall; external ´project1´;


...blz, espero que ajude, t+[/quote:313efd319f]


OK!

Obrigado pela sua atenção.


Responder

16/07/2008

Psyjacko

essa linha
{$R *.res}
vc remove da DLL e detalhe tem que botar no exports o nome da Function e o Index dela na função , exemplo :
library Project1;

{ Important note about DLL memory management: ShareMem must be the
  first unit in your library´s USES clause AND your project´s (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }

uses
  SysUtils,
  Classes;

Function Soma(a,b:Integer):Integer;export;stdcall;
begin
   Result := a + b;
end;
//
Function Subtracao(a,b:Integer):Integer;export;stdcall;
begin
   Result := a - b;
end;
exports
   soma index 1;
   Subtracao index 2;
begin
end.


flw , abraços


Responder

16/07/2008

Aprendiz_ce

essa linha [quote:50c8103700]{$R *.res}
vc remove da DLL e detalhe tem que botar no exports o nome da Function e o Index dela na função , exemplo :
library Project1;

{ Important note about DLL memory management: ShareMem must be the
  first unit in your library´s USES clause AND your project´s (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }

uses
  SysUtils,
  Classes;

Function Soma(a,b:Integer):Integer;export;stdcall;
begin
   Result := a + b;
end;
//
Function Subtracao(a,b:Integer):Integer;export;stdcall;
begin
   Result := a - b;
end;
exports
   soma index 1;
   Subtracao index 2;
begin
end.


flw , abraços[/quote:50c8103700]

Beleza!!!

Obrigado pela sua atenção.

Abraço.


Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

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

Aceitar