ggn
New Member
Posts: 3
|
Post by ggn on Aug 30, 2012 14:08:30 GMT 1
Hello,
I've been writing a small utility in GFA 32 for a couple of years now and recently I decided to add command line support to it (so batch operations can be performed easily). Reading the command line was simple enough when I found a ready library inside the GFA 32 source archive, but I'd like to give some output back to the user via console (for example, if the program is invoked via cmd.exe). So far I haven't been able to find any info or sample code, so could anyone here point me to a snippet of code?
Thanks in advance and keep coding!
|
|
|
Post by dragonjim on Sept 11, 2012 13:49:33 GMT 1
You may have some success with the following Windows APIs: Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) As Long Declare Function WriteConsole Lib "kernel32" Alias "WriteConsoleA" (ByVal hConsoleOutput As Long, lpBuffer As Long, _ ByVal nNumberOfCharsToWrite As Long, lpNumberOfCharsWritten As Long, lpReserved As Long) As Long The former gets the handle of the Console; the latter writes a string to it. Other APIs and Console Functions can be found at msdn.microsoft.com/en-us/library/ms682073(v=vs.85).aspxHope this is helpful.
|
|
ggn
New Member
Posts: 3
|
Post by ggn on Sept 17, 2012 11:45:31 GMT 1
Well, I've tried lots of ideas but it still doesn't work as it should on Windows7x32. Here's one of my experiments:
Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) As Long Declare Function WriteConsole Lib "kernel32" Alias "WriteConsoleA" (ByVal hConsoleOutput As Long, lpBuffer As Long, _ ByVal nNumberOfCharsToWrite As Long, lpNumberOfCharsWritten As Long, lpReserved As Long) As Long
Dim mymessage As String Dim hstdin As Long Dim length As Long
hstdin = GetStdHandle(STD_OUTPUT_HANDLE) mymessage = "testing!" length = Len(mymessage) WriteConsole(hstdin, V:mymessage, length, Null, Null)
If I use GetLastError() after the writeconsole() I get an error code of 6, which is "invalid handle". I tried some other ideas like attachconsole(-1), opening file handles, but again no go.
Anyone could test this snippet on XP? Or, anyone have any other ideas?
|
|
|
Post by dragonjim on Sept 20, 2012 12:21:16 GMT 1
Ran your example in XP and there was no error message both from interpreter and from compiled program. I tried using the FreeConsole() and AllocConsole() API functions and got a new window with some gobbledegook in the top left hand corner and the error no 8. I also tried making the message a Variant (closer to unicode I believe) but that just gave slightly more interesting gobbledegook! My gut feeling is that the function is failing on the second parameter but I haven't got a clue why. To try and end on a more hopeful note, the only half-decent vb example I can find after a quick trawl of the internet is at www.dreamincode.net/forums/topic/10002-writing-console-applications-in-vb-6/, (it bears some startling similarities to one of the examples in the API Guide!). I know it doesn't do exactly what you were after but it might be worth fiddling around with this to see what happens?
|
|
ggn
New Member
Posts: 3
|
Post by ggn on Sept 24, 2012 17:12:28 GMT 1
Well, that VB thread you posted says that you have to compile the program as a console application. I haven't seen that anywhere in the GB compiler, so I guess it's not possible. (unless the GB32 maintainer can say otherwise?)
|
|
|
Post by 649psoft2 on Oct 15, 2012 19:43:35 GMT 1
You might want to try the MS-DOS version of GFA basic for the console batch processing program.
|
|