problem z obsluga dll

0
library D66;

{$R *.res}

function D66Koduj(S: String): String;
var
 I:integer;
 Tmp: String[255];
begin
 if Length(S)=0 then exit;
 for I:=1 to Length(S) do
 begin
  Tmp[i]:=char(ord(S[i])+66);
 end;
 result:=Tmp;
end;

function D66Dekoduj(S: String): String;
var
 I:integer;
 Tmp: String[255];
begin
 if Length(S)=0 then exit;
 for I:=1 to Length(S) do
 begin
  Tmp[i]:=char(ord(S[i])-66);
 end;
 result:=Tmp;
end;

exports D66Koduj, D66Dekoduj;

end.

Po odwolaniu sie do funkcji 'D66Koduj' mniej wiecej tak:

Unit Unit1
...
...
const
 libname = 'd66.dll';

function D66Koduj(S:String):String;external libname;
function D66Dekoduj(S:String):String;external libname;

procedure TForm1.btnKodujClick(Sender: TObject);
begin
 edtdekod.Text:=d66koduj(edtkod.Text);
 edtKod.text:='';
 btnKoduj.Enabled:=not btnkoduj.Enabled;
 btnDekoduj.Enabled:=not btndekoduj.Enabled;
end;

procedure TForm1.btnDekodujClick(Sender: TObject);
begin
 edtkod.Text:=d66dekoduj(edtdekod.Text);
 edtDekod.Text:='';
 btnKoduj.Enabled:=not btnkoduj.Enabled;
 btnDekoduj.Enabled:=not btndekoduj.Enabled;
end;

wystepuje blad "Invalid pointer operation". Zdarza się jednak że funkcja jest wykonywana.

0

yyyy a powiesz moze gdzie ten blad wywala?

0

Powiem tylko tyle, mimo wszedzie pojawiajacych sie opisow uzycia zmiennych string podczas komunikacji miedzy programem a biblioteka nie dziala to jak nalezy, ja taki problem rozwiazalem poprzez konwersje zmiennych string do pchar.

0

Nie wiem jak to jest z waszym Delphi ale moje przy każdym nowym projekcie dołącza do źródła taki komentarz:

{ 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.
}

Czy cos tu jest niejasne ??

1 użytkowników online, w tym zalogowanych: 0, gości: 1