Registriert seit: 6. Apr 2011
Ort: Berlin
3.070 Beiträge
Delphi 10.4 Sydney
|
AW: Stream aus DLL empfangen?
7. Apr 2020, 09:35
Delphi-Quellcode:
program IStreamTest;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
System.Classes,
Winapi.Windows,
Winapi.ActiveX;
// In der DLL
function DLLFunctionToFillStream( const AStreamForDLL: IStream): Boolean stdcall;
var
SampleBuffer: TBytes;
BytesWritten: FixedUInt;
HR: HRESULT;
begin
SampleBuffer := [$D, $E, $A, $D, $B, $E, $E, $F];
HR := AStreamForDLL. Write(SampleBuffer, Length(SampleBuffer), @BytesWritten);
Result := Succeeded(HR) and (BytesWritten > 0);
if not Result then
begin
// Fehlercode von HR loggen, Festplatte formattieren, Selbstzerstörung starten....das übliche!
end;
end;
// Dein Programm
procedure Main;
var
YourStream: TBytesStream;
StreamForDLL: IStream;
DebugStr: string;
I: Integer;
begin
YourStream := TBytesStream.Create;
StreamForDLL := TStreamAdapter.Create(YourStream, TStreamOwnership.soOwned);
if DLLFunctionToFillStream(StreamForDLL) then
begin
Writeln(' Success!');
DebugStr := ' ';
for I := 0 to YourStream.Size - 1 do
DebugStr := DebugStr + YourStream.Bytes[I].ToHexString(1);
Writeln(DebugStr);
end;
end;
begin
try
Main;
except
on E: Exception do
Writeln(E.ClassName, ' : ', E. Message);
end;
Readln;
end.
|
|
Zitat
|