|
-
Aug 8th, 2010, 04:04 AM
#8
Re: Show All String Characters
Yeah, well, it is done the C/C++ way. And from what I've read in C/C++ they have other easier means available as well. Argv gives a challenging return value. Anyway, the good thing is that there is atleast something available that can be used via VB6 as well.
If you only want the complete string to work with you can use GetCommandLineW, create a BSTR out of it and parse it manually.
Code:
Option Explicit
Private Declare Function GetCommandLineW Lib "kernel32" () As Long
Private Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long
Private Declare Sub PutMem4 Lib "msvbvm60" (ByVal Ptr As Long, ByVal Value As Long)
Private Declare Function SysAllocStringLen Lib "oleaut32" (ByVal Ptr As Long, ByVal Length As Long) As Long
Public Function CommandW() As String
Dim Ptr As Long: Ptr = GetCommandLineW
If Ptr Then
PutMem4 VarPtr(CommandW), SysAllocStringLen(Ptr, lstrlenW(Ptr))
If AscW(CommandW) = 34 Then
CommandW = Mid$(CommandW, InStr(CommandW, """ ") + 2)
Else
CommandW = Mid$(CommandW, InStr(CommandW, " ") + 1)
End If
End If
End Function
If you wonder why I use Mid$ to cut the string it is because the first part of the string contains the full path to the executable. Something we don't want with VB6 compatibility.
Edit!
And yes, GetCommandLineW does contain a trailing space even when there are no parameters given at all. I didn't check whether there is always a trailing space character.
Last edited by Merri; Aug 8th, 2010 at 04:11 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|