Recent

Author Topic: Porting eConsole to Lazarus : Full emulation  (Read 3470 times)

mmab

  • Jr. Member
  • **
  • Posts: 89
Porting eConsole to Lazarus : Full emulation
« on: February 16, 2012, 08:48:35 pm »
Porting eConsole to Lazarus : Full emulation

Hi I am trying to bring the spawning capability of eConsole : http://www.corion.net/econsole/  for cmd.exe emulation.
I extracted the needed section from eConsole however, I am having hard time to get it working.

Here is the code (you can find the whole project in the attachment)
Code: [Select]
Procedure TForm1.ReadInfo;

Var Info : TConsoleScreenBufferInfo;
    Buffer : Pointer;
    BufSize : LongInt;

    LeftUpper : TCOORD;

    Region : TSmallRect;
    Target : TSmallRect;
    TargetSize : TCOORD;

    S : String;
    BytesRead:longword;
Begin

  RefreshTimer.Enabled := False;

  If not GetConsoleScreenBufferInfo( console, Info )
    then  RaiseLastWin32Error();

  Region := Info.srWindow;

  FillChar( Target, SizeOf( Target ), 0 );

  TargetSize.X := Region.Right - Region.Left +1;
  TargetSize.Y := Region.Bottom - Region.Top +1;
  Target.Right := Region.Right - Region.Left +1;
  Target.Bottom := Region.Bottom - Region.Top +1;

  FillChar( LeftUpper, SizeOf( LeftUpper ), 0 );
  LeftUpper.X:=TargetSize.X;
  LeftUpper.y:=TargetSize.y;
  BufSize := (Target.Right)* (Target.Bottom)* SizeOf( TCharInfo );
 Buffer := AllocMem(BufSize) ;
try
 if ReadConsoleOutput(shellwnd,Buffer,TargetSize,LeftUpper,Region) then
   begin

        OemToAnsi(Buffer,Buffer) ;
        AMemo.Text := AMemo.text + String(Buffer) ;
   end
 else begin
   if amemo.Lines.Strings[amemo.Lines.Count-1]<>'no' then
      amemo.Lines.add('no');

   end;
  finally
    FreeMem( Buffer, BufSize );
  end;
  RefreshTimer.Enabled := True;
End;   


The problem is to identify the location of cmd window and use ReadConsoleOutput to get buffer.
I know it is possible to get and interact with the cmd using Tprocess but, it does not give you the full emulation.
Any ideas how to fix this?

thanks

Leledumbo

  • Hero Member
  • *****
  • Posts: 8819
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Porting eConsole to Lazarus : Full emulation
« Reply #1 on: February 17, 2012, 03:15:16 am »
First question: what's wrong with the code? Compile error? Runtime error? You can't get the console buffer? What?

mmab

  • Jr. Member
  • **
  • Posts: 89
Re: Porting eConsole to Lazarus : Full emulation
« Reply #2 on: February 17, 2012, 03:46:44 am »
There is no error with the code.
It simply can't locate the shell windows position accurately (My guess). Due to that, ReadConsoleOutput  cannot retrieve correct info.

« Last Edit: February 17, 2012, 03:55:48 am by mmab »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8819
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Porting eConsole to Lazarus : Full emulation
« Reply #3 on: February 17, 2012, 04:04:41 am »
Reading MSDN, looks like you've done it right. I'm not sure about this one though:
Quote
AMemo.Text := AMemo.text + String(Buffer);
Are you sure the buffer pointed by Buffer forms AnsiString format?

 

TinyPortal © 2005-2018