I have been trying to capture stdout and stderr output from a DLL compiled in MSVC++ that my Delphi app statically links to, but so far have been unsuccessful.
procedure Test;
var
fs: TFileStream;
begin
fs := TFileStream.Create('C:\temp\output.log', fmCreate or fmShareDenyWrite);
SetStdHandle(STD_OUTPUT_HANDLE, fs.Handle);
SetStdHandle(STD_ERROR_HANDLE, fs.Handle);
dllFunc(0); // Writes to stdout in MSVC++ console app, but not here
// fs.Length is always zero
fs.Free;
end;
Thought I was on the right track, but it does not work.
Any help would be appreciated.
If the DLL grabs the stdout handles when it is loaded, then you will need to dynamically load the DLL after you have changed the stdout handles in your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With