Buffer do Console de Leitura / Saída C ++
Minha pergunta é bem simples, mas a solução parece absolutamente impossível para mim.
Eu tenho um servidor de jogo dedicado (JEDI ACADEMY JAMPDED), que é um aplicativo de console. Ele escreve algumas informações continuamente e eu quero manipular os dados de alguma forma. Seria fácil se eu pudesse ler a saída dele com o externo.
Problema: Ele não grava na saída padrão, portanto, não pode ser canalizado com o arquivo em lotes e o popen também não funciona.
Então eu queria fazer com WINAPI. Consegui criar o processo, mas ainda não consegui ler a saída.
Eu tentei estes:
Como faço para chamar :: CreateProcess em c + + para iniciar um executável do Windows?
CreateProcess e CreatePipe para executar um processo e retornar a saída como uma string no VC ++
E o exemplo oficial do MSDN, mas ainda nada.
Este é o jampded.exe:
Eu recebi um código visual básico do meu amigo, que lê o ConsoleInput do Ingame, então tenho certeza de que é possível ler o console:
SNIPPET:
Global hWnd = FindWindow_(#Null,"Jedi Knight Academy MP Console") ;console window
Global hWnd2 = FindWindow_(#Null,"Jedi Knight®: Jedi Academy (MP)") ;actual game window
Global inputhWnd = FindWindowEx_(hwnd,0,"edit",0) ;the one to send stuff to
Global consolehWnd = FindWindowEx_(hwnd,inputhWnd,"edit",0) ;the one to read the console from
Procedure checkConsole()
Protected wholetext.s, oldtext.s,text.s, checkname.s
Repeat
wholetext = getText()
If wholetext
text = StringField(wholetext,CountString(wholetext,#CRLF$),#CRLF$)
If oldtext <> text
oldtext = text
analyseConsole(@text)
EndIf
EndIf
Delay(20)
writePreferences()
Until quit
EndProcedure
Procedure.s getText()
Protected wholetext.s
If hWnd And hWnd2
If Not inputhWnd Or Not consolehWnd
inputhWnd = FindWindowEx_(hWnd,0,"edit",0)
consolehWnd = FindWindowEx_(hWnd,inputhWnd,"edit",0)
EndIf
length = SendMessage_(consolehWnd, #WM_GETTEXTLENGTH, 0, 0)
wholetext = Space(length)
SendMessage_(consolehWnd,#WM_GETTEXT,length + SizeOf(Character),@wholetext)
ProcedureReturn wholetext
Else
If FindWindow_(#Null,"Jedi Knight Academy MP Console")
hWnd = FindWindow_(#Null,"Jedi Knight Academy MP Console")
hWnd2 = FindWindow_(#Null,"Jedi Knight®: Jedi Academy (MP)")
inputhWnd = FindWindowEx_(hwnd,0,"edit",0)
consolehWnd = FindWindowEx_(hwnd,inputhWnd,"edit",0)
EndIf
ProcedureReturn ""
EndIf
If @wholetext > 0
FreeMemory(@wholetext)
EndIf
EndProcedure
Talvez isso possa ajudar a mim e aos outros também :)