views:

27

answers:

1

Hey all, i am trying to send some text to a console box (dos box) from my vb program but i can not seem to get it working.

Here is my current code:

Dim blah As Long
Private Const WM_GETTEXT As Integer = &HD
Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As String) As IntPtr

blah = FindWindow1(vbNullString, "Form1")
blah = FindWindowEx(blah, vbNullString, "ConsoleWindowClass", vbNullString)
Debug.Print(blah)
SendMessage(blah, WM_SETTEXT, 200, "A")

Though that does work, it only puts a A for the title bar and not within the console.

Any help would be great! :o)

David

+1  A: 

I've not tried it but I think you might want to look at AttachConsole to attach your process to the console of the command line process. Then you should be able to use the Console.WriteLine and similar methods I'd assume.

You can find a sample (in C#, but should be easy to convert to VB using one of the online converters) on the PInvoke page.

ho1
Unless he wants to interact with the program in the console.
SLaks
I didn't know that, thanks.
ho1