VB6.0 provides the command () interface to provide support for command line parameters. Therefore, all input parameters can be obtained through the command () function, but it is unfriendly, all the parameters of VB are combined and become a string. When there are multiple parameters, it is not convenient to use them. Therefore, the followingCodeCode, I do not remember where it comes from, if you areArticlePlease let me know .@@
Option Explicit
Private Declare Function Getcommandlinew Lib " Kernel32 " () As Long
Private Declare Function Lstrlenw Lib " Kernel32 " ( Byval Lpstring As Long ) As Long
Private Declare Function CommandlinetoargvwLib " Shell32 " ( Byval Lpcmdline As Long , Pnnumargs As Long ) As Long
Private Declare Function Localfree Lib " Kernel32 " ( Byval Hmem As Long ) As Long
Private Declare Sub Copymemory Lib " Kernel32 " Alias " Rtlmovememory " (Destination As Any, Source As Any, Byval Length As Long )
Public Function Splitcmd ( Byref Argc As Long , Byref Argv () As String )
Dim Nnumargs As Long ' // Number of command line parameters
Dim Lpszarglist As Long ' // Command line parameter array address
Dim LpszargAs Long ' // Address of each command line parameter
Dim Narglength As Long ' // Command line parameter length
Dim Szarg () As Byte ' // Command line parameters
Dim I As Long
Lpszarglist = commandlinetoargvw (getcommandlinew (), nnumargs)
If Lpszarglist Then
Argc = nnumargs ' // Total number of outputs
Redim Argv (nnumargs- 1 )
Copymemory Byval Varptr (lpszarg ),Byval Lpszarglist, 4 ' // Obtain the argv (0) address.
For I = 0 To Nnumargs- 1
Narglength = lstrlenw (lpszarg)
Redim Szarg (narglength * 2 - 1 )
CopymemoryByval Varptr (szarg ( 0 )), Byval Lpszarg, narglength * 2
Argv (I) = CSTR (Szarg)
Lpszarg = lpszarg + narglength * 2 + 2
Next
Erase Szarg
Call Localfree (lpszarglist)
End If
End Function
The call method is simple. The entry function splitcmd (ByrefArgcAs Long,ByrefArgv ()As String), The first parameter is the input parameter: the total number of parameters, and the second parameter is the parameter array. It must be noted that the return value of this function is the same as that of C, there must be at least one value in argc, that isProgramThe argv (0) is the path of the program. The following describes how to use argv (0.
Option Explicit
Private Sub Form_load ()
Dim Argc As Long , Argv () As String
Dim I As Integer , Szcmd As String
Call Splitcmd (argc, argv ())
For I = 0 To Argc- 1
Szcmd = szcmd & I & vbtab & argv (I) & vbcrlf
Next
Msgbox Szcmd
End sub
The result is as follows:
Now, everything goes smoothly.
Girl does not cry (QQ: 191035066) @