Displaying Text Messages on the Console


Author:  snowsnowsnow
Date:  Wednesday, June 14, 2006 06:34 AM  
In wandering around MSDN, I found the AttachConsole function, and this gives a Q&D way to do it - according to the docs, this works only on XP+. Also, it doesn't really write to standard output - you can't redirect or pipe it. But it does provide a simple, easy way to display short messages on the console from which the WB app is launched.

Here's my code (best is to run this via: start /w foo.wbt):

kern32 = DllLoad("kernel32")
DLLCall(kern32,long:"AttachConsole",long:-1)
hStdOutput = DLLCall(kern32, long:"GetStdHandle", long:-11)
mret = BinaryAlloc(4)
s = "This is a test%@CRLF%"
DLLCall(kern32, long:"WriteFile", long:hStdOutput, lpstr:s, long:StrLen(s), lpbi
nary:mret, lpnull)
Message("mret = ",BinaryPeek4(mret,0))

Article ID:   W16997