Older Version Newer Version

bshipps64 bshipps64 Feb 18, 2006 - "Misc formatting changes"

GetCommandLineArgs$ sub

An example of using the Windows API to retrieve the entire command line, then parsing that line it to extract just the arguments passed to the executable.
Ex:
If cmdLine$ contains
then args$ will be assigned the value "/switch"
If cmdLine$ contains ""C:\test
args$ will be assigned "/someSwitch /anotherSwitch"
 sub GetCommandLineArgs$ byref args$ 
q$ = chr$(34)

'API call returns pointer to a string
'containing command line contents
calldll #kernel32, "GetCommandLineA",_
pointer as ulong

'Use winstring() to actually get the string
'from pointer
cmdLine$ = trim$(winstring(pointer))
cLen = len(cmdLine$)

'Extract just the arguments from the variable
if (left$(cmdLine$, 1) = q$) then
qPos = instr(cmdLine$, q$, 2)
args$ = trim$(right$(cmdLine$, cLen - qPos))
else
pLen = len(word$(cmdLine$,1))
args$ = trim$(right$(cmdLine$, cLen - pLen))
end if
end sub