Results 1 to 2 of 2

Thread: Trying to send command line to a Dos App need Help

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2001
    Location
    Nebraska
    Posts
    46

    Trying to send command line to a Dos App need Help

    Hello everyone I need help trying to write a command line to a doss application is there a way I can send characters to a dos window? I have seen few API examples and alot of people saying you can't do it is there any easy way of doing this? Please help.

    Robb

  2. #2
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    in VB.NET it is simple, but in VB5/6 it is really complicated. and it doesnt seem to work for XP

    VB Code:
    1. Private Const STD_OUTPUT_HANDLE = -11&
    2. Private Const STD_INPUT_HANDLE = -10&
    3. Private Const STD_ERROR_HANDLE = -12&
    4. Private Const INVALID_HANDLE_VALUE = -1&
    5. Private Const CONSOLE_FULLSCREEN = 1 ' fullscreen console
    6. Private Const CONSOLE_FULLSCREEN_HARDWARE = 2 ' console owns the hardware
    7. Private Type COORD
    8.     x As Integer
    9.     y As Integer
    10. End Type
    11. Private Type CONSOLE_FONT_INFO
    12.     nFont As Long
    13.     dwFontSize As COORD
    14. End Type
    15. Private Declare Function AllocConsole Lib "kernel32" () As Long
    16. Private Declare Function FreeConsole Lib "kernel32" () As Long
    17. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    18. Private Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) As Long
    19. Private Declare Function GetConsoleDisplayMode Lib "kernel32" (lpModeFlags As Long) As Long
    20. Private Declare Function GetConsoleFontSize Lib "kernel32" (ByVal hConsoleOutput As Long, ByVal nFont As Long) As COORD
    21. Private Declare Function GetCurrentConsoleFont Lib "kernel32" (ByVal hConsoleOutput As Long, ByVal bMaximumWindow As Long, lpConsoleCurrentFont As CONSOLE_FONT_INFO) As Long
    22. Private Declare Function GetConsoleProcessList Lib "kernel32" (lpdwProcessList As Long, ByVal dwProcessCount As Long) As Long
    23. Private hConsoleOut As Long, hConsoleIn As Long, hConsoleErr As Long
    24. Private Sub Form_Load()
    25.     'KPD-Team 2001
    26.     'URL: [url]http://www.allapi.net/[/url]
    27.     'E-Mail: [email][email protected][/email]
    28.     'Create console
    29.     Dim CurrentFont As CONSOLE_FONT_INFO
    30.     Dim Ret As Long, ProcessList() As Long, Cnt As Long
    31.     'create the console
    32.     If AllocConsole() Then
    33.         hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE)
    34.         If hConsoleOut = INVALID_HANDLE_VALUE Then MsgBox "Unable to get STDOUT"
    35.         hConsoleIn = GetStdHandle(STD_INPUT_HANDLE)
    36.         If hConsoleOut = INVALID_HANDLE_VALUE Then MsgBox "Unable to get STDIN"
    37.     Else
    38.         MsgBox "Couldn't allocate console"
    39.     End If
    40.     'Get the current display mode
    41.     GetConsoleDisplayMode Ret
    42.     If Ret = CONSOLE_FULLSCREEN Then
    43.         MsgBox "Full-screen console. The console is in this mode as soon as the window is maximized. At this point, the transition to full-screen mode can still fail."
    44.     ElseIf Ret = CONSOLE_FULLSCREEN_HARDWARE Then
    45.         MsgBox "Full-screen console communicating directly with the video hardware. This mode is set after the console is in CONSOLE_FULLSCREEN mode to indicate that the transition to full-screen mode has completed."
    46.     End If
    47.     'Get the current console font
    48.     GetCurrentConsoleFont hConsoleOut, 0, CurrentFont
    49.     'Get the size of the current console font
    50.     CurrentFont.dwFontSize = GetConsoleFontSize(hConsoleOut, CurrentFont.nFont)
    51.     MsgBox "Current console font dimensions: " & CurrentFont.dwFontSize.x & "x" & CurrentFont.dwFontSize.y
    52.     'Create a buffer of Longs
    53.     ReDim ProcessList(0 To 9) As Long
    54.     'Get the list of process IDs associated with this console
    55.     Ret = GetConsoleProcessList(ProcessList(0), 10)
    56.     'If the buffer was not large enough...
    57.     If Ret > 9 Then
    58.         '...create a larger buffer
    59.         ReDim ProcessList(0 To Ret - 1) As Long
    60.         'and retry
    61.         Ret = GetConsoleProcessList(ProcessList(0), Ret + 1)
    62.     End If
    63.     'Show all associated processes in the debug window
    64.     For Cnt = 0 To Ret - 1
    65.         Debug.Print "Associated process: " + CStr(ProcessList(Cnt))
    66.     Next Cnt
    67. End Sub
    68. Private Sub Form_Unload(Cancel As Integer)
    69.     'Delete console
    70.     CloseHandle hConsoleOut
    71.     CloseHandle hConsoleIn
    72.     FreeConsole
    73. End Sub
    Remember, if someone's post was not helpful, you can always rate their post negatively .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width