ReadConsoleOutput() API help

Windows specific forum
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

ReadConsoleOutput() API help

Post by jassing »

I'm trying to use ReadConsoleOutput() -- I see someone tried, but was unsuccessful. I, too, am ending up with failed results.
I suspect my failure is in not sending the right parameters...
And at this point, I have really pooched my demo to the point I'm not even sure what I was trying to do (with parameters, structure definitions, etc)
I'll try to tidy it up and post my best guess soon...
PureGuy
Enthusiast
Enthusiast
Posts: 102
Joined: Mon Aug 30, 2010 11:51 am

Re: ReadConsoleOutput() API help

Post by PureGuy »

HI jassing,

Did you found any solution for ReadConsoleOutput?
I'm getting error 87 - wrong parameter whatever i try.
PureGuy
Enthusiast
Enthusiast
Posts: 102
Joined: Mon Aug 30, 2010 11:51 am

Re: ReadConsoleOutput() API help

Post by PureGuy »

Here is what I have so far:

Code: Select all


cinfo.CONSOLE_SCREEN_BUFFER_INFO
Prototype AttachConsole(dwProcessId.l)
OpenLibrary(0, "Kernel32.dll")
AttachConsole.AttachConsole = GetFunction(0, "AttachConsole")
CloseLibrary(0)

Program = RunProgram("cmd.exe", "/k echo Hello!", "", #PB_Program_Open)
If IsProgram(Program)
  PID.l = ProgramID(Program)
  CloseProgram(Program)  
EndIf

Delay(1000)

If AttachConsole(PID)

  handle = GetStdHandle_(#STD_OUTPUT_HANDLE) 
  If handle
    If GetConsoleScreenBufferInfo_(handle,cinfo)
         
      lWidth.l      = cinfo\srWindow\right  - cinfo\srWindow\left
      lHeight.l     = cinfo\srWindow\bottom - cinfo\srWindow\top
     
      *pBuffer = AllocateMemory(SizeOf(CHAR_INFO) * lWidth * lHeight)
      
      dwBufferSize.coord
      dwBufferSize\x = lWidth
      dwBufferSize\y = lHeight
      
      dwBufferCoord.coord
      dwBufferCoord\x = 0
      dwBufferCoord\y = 0
        
      pRect.SMALL_RECT
      pRect\left    = cinfo\srWindow\left
      pRect\top     = cinfo\srWindow\top
      pRect\right   = cinfo\srWindow\right
      pRect\bottom  = cinfo\srWindow\bottom
    
    
      If ReadConsoleOutput_(handle, *pBuffer, dwBufferSize.coord, dwBufferCoord.coord, pRect.Small_Rect)
        Debug "Success!"
      Else
        Debug "Failed!"
      EndIf
    
    EndIf
  EndIf
  FreeConsole_()
EndIf
    

Post Reply