i've got a small problem.
In my DLL i've got:
uses
ShareMem,
SysUtils,
Classes,
Dialogs;
function My_func (Param1, Param2, Param3: PAnsiChar) : Integer;
var
s1,s2,s3 : string;
begin
s1 := string(Param1);
s2 := string(Param2);
s3 := string(Param3);
ShowMessage(s1);
ShowMessage(s2);
ShowMessage(s3);
My_func := 0;
end;
And the call from my TestUnit.pas
unit Utestunit;
interface
uses
ShareMem, Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;
procedure Button1Click(Sender: TObject);
type
TMy_func = function (Param1, Param2, Param3: PAnsiChar) : Integer; StdCall;
var
my_func : TMyfunc;
error_code:integer;
My_library : THandle;
the_end : Boolean;
path_library,
path_library_full : string;
test1,
test2,
test3 : array [0..255] of AnsiChar;
begin
// open the DLL
path_library := ExtractFilePath(Application.ExeName)+'DLLRS_DLL.dll';
path_library_full := ExtractFilePath(Application.ExeName)+'DLL';
SetCurrentDir(path_library_full);
try
the_end := False;
My_library := SafeLoadLibrary(PChar(path_library));
if My_library > 32 then
begin
@My_func := GetProcAddress(My_library, PChar('My_func'));
if @My_func = nil then
begin
ShowMessage('There is no library in '+path_library);
the_end := True;
end;
end
else
begin
error_code := GetLastError;
ShowMessage('B??d biblioteki '+ sciezka_biblioteki+' nr:'+IntToStr(error_code));
the_end := True;
end;
if not the_end then
begin
// the calling
test1 := 'My string nr 1';
test2 := 'My string nr 2';
test3 := 'My string nr 3';
kod_bledu := My_func(
test1,
test2,
test3
);
end;
finally
FreeLibrary(My_library);
SetCurrentDir(ExtractFilePath(Application.ExeName))
end;
end;
The results are:
My string nr 1
trash
trash
as the messages from my DLL.
Why only the first result is good while the rest trash is?
It's only the test in my app.
question from:
https://stackoverflow.com/questions/65643673/the-results-from-dll-in-delphi-where-the-parameters-are-pansichar 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…