Gibt bei folgender Implementierung Haken und Ösen, oder geht das prinzipiell in Ordnung?
Delphi-Quellcode:
procedure TForm2.Button1Click(Sender: TObject);
type
Tp=Procedure(s:TStreamAdapter);
var
ms:TMemoryStream;
isa:TStreamAdapter;
s:
String;
h:THandle;
p:
Tp;
begin
s :='
Nur ein Test ohne weiteren Sinn';
ms := TMemoryStream.Create;
isa:=TStreamAdapter.Create(ms);
try
ms.
Write(s[1],Length(s) * SizeOf(Char));
h := LoadLibrary('
ShowStream.dll');
if h <> 0
then
try
@p := GetProcAddress(h,'
ShowAStream');
p(isa);
finally
FreeLibrary(h);
end;
finally
isa.Free;
ms.Free;
end;
end;
____________________________________________________
library ShowStream;
uses
SysUtils,
Classes,
Dialogs;
{$R *.res}
Procedure ShowAStream(isa:TStreamAdapter);
var
ms:TMemoryStream;
s:
String;
begin
ms:=TMemoryStream.Create;
try
ms.LoadFromStream(isa.Stream);
SetLength(s,ms.Size);
ms.
Read(s[1],ms.Size);
Showmessage(s);
finally
ms.Free;
end;
end;
Exports
ShowAStream
index 1;
begin
end.