problem z obsluga dll

0
Kopiuj
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:

Kopiuj
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.

KB
  • Rejestracja:ponad 20 lat
  • Ostatnio:około 20 lat
  • Postów:35
0

yyyy a powiesz moze gdzie ten blad wywala?

aZgon
  • Rejestracja:ponad 22 lata
  • Ostatnio:10 miesięcy
  • Postów:488
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.


Nie ma jutra bez komputra. :-)
DO
  • Rejestracja:ponad 22 lata
  • Ostatnio:około 15 lat
  • Postów:731
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 ??


80% problemów które pojawiają sie na forum w postach rozwiązaliby samodzielnie ich autorzy, gdyby nie mieli internetu...

Zarejestruj się i dołącz do największej społeczności programistów w Polsce.

Otrzymaj wsparcie, dziel się wiedzą i rozwijaj swoje umiejętności z najlepszymi.