VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Opening the Commond window and sending command line parameter from VB Form Short and simple.

by Sujit Sahu (1 Submission)
Category: Windows API Call/Explanation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 26th September 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Opening the Commond window and sending command line parameter from VB Form Short and simple.

API Declarations



Declare Function AllocConsole Lib "kernel32" () As Long
Declare Function FreeConsole Lib "kernel32" () As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) _
As Long
Declare Function GetStdHandle Lib "kernel32" (ByVal _
nStdHandle As Long) As Long
Declare Function WriteConsole Lib "kernel32" Alias "WriteConsoleA" _
(ByVal hConsoleOutput As Long, lpBuffer As Any, ByVal _
nNumberOfCharsToWrite As Long, lpNumberOfCharsWritten As Long, _
lpReserved As Any) As Long

Public Const STD_OUTPUT_HANDLE = -11&


Rate Opening the Commond window and sending command line parameter from VB Form Short and simple.





Dim hConsole As Long
Private Sub Command1_Click()
   Dim Result As Long, sOut As String, cWritten As Long
     sOut = Trim(Text1.Text) '& vbCrLf
     Result = WriteConsole(hConsole, ByVal sOut, Len(sOut), cWritten, _
                           ByVal 0&)
                           
      Shell sOut
      
   End Sub

   Private Sub Form_Load()
     If AllocConsole() Then
       hConsole = GetStdHandle(STD_OUTPUT_HANDLE)
       If hConsole = 0 Then MsgBox "Couldn't allocate STDOUT"
     Else
       MsgBox "Couldn't allocate console"
     End If
   End Sub

   Private Sub Form_Unload(Cancel As Integer)
     CloseHandle hConsole
     FreeConsole
   End Sub




Download this snippet    Add to My Saved Code

Opening the Commond window and sending command line parameter from VB Form Short and simple. Comments

No comments have been posted about Opening the Commond window and sending command line parameter from VB Form Short and simple.. Why not be the first to post a comment about Opening the Commond window and sending command line parameter from VB Form Short and simple..

Post your comment

Subject:
Message:
0/1000 characters