saving screenshot

delphi package - automated exception handling
Post Reply
tojo77
Posts: 3
Joined: Mon Aug 23, 2004 12:50 pm

saving screenshot

Post by tojo77 »

Hi!

I registered my own exception-handler and I want to take a screenshot and save it to disk, before showing the exception.
I tried this with

Code: Select all

...
screen := TFileStream.Create( 'test.png', fmCreate );
try
   WriteToStreamRaw( screen, CreateScreenShotPng( st256Colors ) );
finally
   screen.Free;
end;
...
where WriteToStreamRaw looks like this:

Code: Select all

procedure WriteToStreamRaw(Stream: TStream; Text: string);
var
  Len: integer;
  buf: PChar;
begin
  with Stream do
  begin
    Len := length(text);
    buf := StrAlloc(Len+1);
    StrPCopy(buf, Text);
    WriteBuffer(buf^, Len);
    StrDispose(buf);
  end;
end;
The File is being saved, but the PNG is corrupt!!

I'm using madExcept 2.7c. What am I doing wrong??

thx,
Tom.
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

StrPCopy stops at the first #0 character. You can't use that for binary files. Use this one instead:

Code: Select all

procedure WriteToStreamRaw(Stream: TStream; Text: string);
begin
  if Text <> '' then 
    Stream.WriteBuffer(Text[1], Length(Text));
end;
Post Reply