Hello...

I coded this simple proc today...
I post it because I didn't see any code doing this before...
Hutch made procs for retrieving arguments, one after the others though... what I needed was a pointer to the whole arguments, and GetCommandLine returns the command line with the executable file path and name.

I hope it is useful to somebody...

It is tiny (19 bytes) and only uses eax (no push/pops "overhead"... :cool: )
Optimizations are welcome !

GetPointerToCommandLineArgs proc

call GetCommandLine
cmp byte ptr [eax], '"'
jne @@exit ;if there's no argument, exit (returns the Module Filename)
@@:
inc eax
cmp byte ptr [eax], '"'
jne @B
inc eax ; " character
inc eax ; space character between the module file name and the command line args
@@exit:
ret
GetPointerToCommandLineArgs endp
Posted on 2002-01-31 12:31:06 by JCP
check Path*() functions from shlwapi.dll, i think that there is some parsing cmd line args function.... but if u wanna make one by yourself...its up to u (since u may code one more faster...) .

hoppe it help...

jean / coder7345
Posted on 2002-02-01 08:39:28 by coder
Readiosys, the first char in the string returned by GetCommandLine
doesn't have to be a quote. It usually is if you run the file from
explorer, but if you run it from ie CreateProcess or through cmd.exe,
the first char doesn't have to be a quote... but there can still be
commandline arguments.

Also, the arguments might be quoted, or they might not. Not all
apps have good argument handling :/. A little test that simply
does MessageBox with GetCommandLine shows that there's a few
different formats depending on how the executable is invoked.
Posted on 2002-02-03 17:30:12 by f0dder
Yes, I noticed what you say...

Right now it seems to work in all cases I tested... but if there's no arguments, the pointer may point to :

- The module file name
- *nothing*

depending as you said the manner of the file has been launched...

I noticed this *problem* too and it annoy me a bit, I will try to make an "universal" method, but since you can also have space in directories names and file... scan for a specific character may not be that reliable... I'm tired and have a lot of work, but at the present moment, I don't see a clean way to do it "universaly"...

Anyway, thanks for the report. ;)
Posted on 2002-02-07 11:49:46 by JCP
Processing the commandline across different versions of windows is a pain as there are a lot of variations, console/CreateProcess/WinExec/Explorer/Winfile and different windows version do different things with all of them.

One could get the sneaking suspicion that Microsoft did not want the universal commandline system to continue running and have continually changed how it works so that ARGV ARGC style code gets broken.

I have had 3 goes at it so far but there are situations where they will not always work.

Regards,

hutch@movsd.com
Posted on 2002-02-07 21:04:06 by hutch--
i usually do this:

                        call      GetCommandLineA

mov esi, eax
xor ecx, ecx
__skip_cmd: lodsb
test al, al
jz __end_cmdline
cmp al, '"'
jnz __space_check
inc ecx
jmp __skip_cmd
__space_check: cmp al, ' '
jnz __skip_cmd
and ecx, 1
jnz __skip_cmd
__end_cmdline:
Posted on 2002-02-08 06:54:13 by cynix

One could get the sneaking suspicion that Microsoft did not want the universal commandline system to continue running and have continually changed how it works so that ARGV ARGC style code gets broken.

... from the man who wrote incorrect file mapping code and blaimed
microsoft and wouldn't listen to any sense no matter how patiently
it was explained to him...

If you want your app to just run on win32, it's not hard to parse
the commandline at all, as long as you use your common sense.
There's various ways arguments can be passed, sure, but it's not
a problem.
Posted on 2002-02-08 12:14:35 by f0dder