ReadfromConsoleApp




Declare Function ReadConsoleOutputCharacter Lib "kernel32" _
Alias "ReadConsoleOutputCharacterA" (ByVal hConsoleOutput As Long, _
ByVal lpCharacter As String, ByVal nLength As Long, _
ByVal dwReadX As Integer, ByVal dwReadY As Integer, _
lpNumberOfCharsRead As Long) As Long
'3. The first character position In Console Screen Buffer Is (0,0).

> hi,
>
> I found In winapi a ReadConsoleOutput To Read the Text of a Shell window,
> but doen't work ?!
> It runs And returns Nothing !
> Does anybody know why Or have already had the same problem ?
>
> Thanx In advance,
>
> Fabien
>
>
>
> Type COORD
> X As Integer
> Y As Integer
> End Type
>
> Public Const PROCESS_ALL_ACCESS = &H1F0FFF
>
> Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As
Long,
> ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
> Declare Function ReadConsoleOutputCharacter Lib "kernel32" Alias
> "ReadConsoleOutputCharacterW" (handle As Long, ByVal buffer As String,
nbcar
> As Long, position As COORD, ByVal caracteres As Long) As Long
>
> Sub Test()
> Dim buff As String, position As COORD, caracteres As Long, nbcar As
> Long, handle As Long, Processus As Long
>
> Processus = Shell("C:\test.bat")
> handle = OpenProcess(PROCESS_ALL_ACCESS, 0, Processus)
>
> position.X = 1
> position.Y = 1
> nbcar = 100
>
> buff = String(nbcar + 1, " ")
> msg = ReadConsoleOutputCharacter(handle, buff, nbcar, position,
> caracteres)
> MsgBox caracteres
>
> End Sub
>
>
See KB Article : Q171654

1. You need Console Screen Buffer handle instead of Process
handle. See Microsoft KB Q171654.

2. You have wrong declaration of ReadConsoleOutputCharacter
Function.










( readfromconsoleapp.html )- by Paolo Puglisi - Modifica del 17/12/2023