function GetReturnStr(Source: PChar; Dest: PChar): Integer; //
var S: string;
begin
S :=StrPas(Source);
S :='DllOne---'+S;
Dest :=PChar(S);
Result :=1;
end;
exports
GetReturnStr;
begin
end.
调用代码如下:
type
TGetReturnStr = function(Source: PChar; Dest: PChar): Integer;
procedure TForm1.bDLLOneClick(Sender: TObject);
var aptr: TFarproc;
lhnd: THandle;
i: integer;
Source1,Dest1: PChar;
S: string;
begin
lhnd :=LoadLibrary('DllOne.dll');
if lhnd>32 then
begin
try
GetMem(Source1,Length(trim(mSource.Text))+1);
StrPCopy(Source1,trim(mSource.Text));
Dest1 := '';
aptr :=GetprocAddress(lhnd,'GetReturnStr');
if (aptr<>nil) then
begin
i :=aptr(Source1,Dest1);
mDest.Text :=intToStr(i)+'---'+StrPas(Dest1);
end;
finally
FreeLibrary(lhnd);
end;
end;
end;
function GetReturnStr(Source: PChar; Dest: PChar): Integer; stdcall; //
var S: string;
begin
S :=StrPas(Source);
S :='DllOne---'+S;
Dest :=PChar(S);
Result :=1;
end;
exports
GetReturnStr;
begin
end.
调用代码如下:
type
TGetReturnStr = function(Source: PChar; Dest: PChar): Integer;
procedure TForm1.bDLLOneClick(Sender: TObject);
var aptr: TFarproc;
lhnd: THandle;
i: integer;
Source1,Dest1: PChar;
S: string;
begin
lhnd :=LoadLibrary('DllOne.dll');
if lhnd>32 then
begin
try
GetMem(Source1,Length(trim(mSource.Text))+1);
StrPCopy(Source1,trim(mSource.Text));
Dest1 := '';
aptr :=GetprocAddress(lhnd,'GetReturnStr');
if (aptr<>nil) then
begin
i :=TGetReturnStr(aptr)(Source1,Dest1);
mDest.Text :=intToStr(i)+'---'+StrPas(Dest1);
end;
finally
FreeLibrary(lhnd);
end;
end;
end;