Console work

Archives Forums/BlitzPlus Programming/Console work

Eikon(Posted 2004) [#1]
* I found out that running this code in the regular IDE instead of Protean makes it work. I guess thats something Rob will have to look into. WriteConsole still isn't working but at least AllocConsole doesnt bomb anymore *

I've been trying to do some Console API work in B+ but the AllocConsole function never succeeds. Is it impossible to create a console window in B+?
format_code('
; Userlib
.lib "kernel32.dll"
AllocConsole%()
GetStdHandle%(nStdHandle%)
SetConsoleTitle%(lpConsoleTitle$):"SetConsoleTitleA"
SetConsoleTextAttribute%(hConsoleOutput%, wAttributes%)
WriteConsole%(hConsoleOutput%, lpBuffer$, nCharToWrite%, lpCharsWritten%, lpReserved):"WriteConsoleA"
')
format_code('
Local hConsoleOut%, hConsoleIn%

Const STD_OUTPUT_HANDLE = -11
Const STD_INPUT_HANDLE = -10
Const INVALID_HANDLE_VALUE = -1

Ret% = AllocConsole()
If Ret% = 0 Then Notify "Console Allocation Failed"

; // Output
hConsoleOut% = GetStdHandle(STD_OUTPUT_HANDLE)
If hConsoleOut% = INVALID_HANDLE_VALUE Then Notify "Unable to get STDOUT"

; // Input
hConsoleIn% = GetStdHandle(STD_INPUT_HANDLE)
If hConsoleIn% = INVALID_HANDLE_VALUE Then Notify "Unable to get STDIN"

SetConsoleTitle "My Console App"

Output$ = "Hello World"
WriteConsole hConsoleOut%, Output$, Len(Output$), 0, 0
')
If anyone can figure it out or has an explanation as to why it fails, please let me know.


soja(Posted 2004) [#2]
Incidentally, I've done a lot of console stuff before. It's a pain in the butt and I wish that BlitzPlus supported reading from and writing to stdin/stdout. Anyway, if you have a specific question in the future, I might have an answer.


Eikon(Posted 2004) [#3]
Thanks for the offer soja, ill let you know if I need anything. If anyone cares, the new version of Protean to be released tommorow will include a "real console mode" option that should solve this issue.