GetEntireCmdLine




' From a UseNetPosting by Karl E Peterson

'


Option Explicit

Private Declare Function GetCommandLine Lib "kernel32" Alias _
"GetCommandLineW" () As Long

Private Declare Sub CopyMem Lib "kernel32" Alias _
"RtlMoveMemory" (pTo As Any, uFrom As Any, ByVal lSize As Long)
Private Declare Function lstrlenW Lib "kernel32" _
(ByVal lpString As Long) As Long

Public Sub Main()
Dim lpCmdLine As Long
lpCmdLine = GetCommandLine()
MsgBox PointerToStringW(lpCmdLine), , "Command Line"
End Sub

Private Function PointerToStringW(lpStringW As Long) As String
Dim Buffer() As Byte
Dim nLen As Long

If lpStringW Then
nLen = lstrlenW(lpStringW) * 2
If nLen Then
ReDim Buffer(0 To (nLen - 1)) As Byte
CopyMem Buffer(0), ByVal lpStringW, nLen
PointerToStringW = Buffer
End If
End If
End Function

'As it turned out, the Declare For this Function was *totally* hosed In

'Win32Api.txt -- could be why it was blowing On you. It *Is* interesting, though,

'that the behavior Is very different between NT And 98! In both environments, I

'switched To the directory of the EXE listed above, And entered...

'

'X:\Code\VBW32\Modules>cmdline testing 1 2 3

'

'NT returned...

'

'cmdline testing 1 2 3

'

'While 98 returned...

'

'"X:\CODE\VBW32\MODULES\CMDLINE.EXE" testing 1 2 3










( getentirecmdline.html )- by Paolo Puglisi - Modifica del 17/12/2023