Hi,

Little problem here. For example: i will run my exe with parametr program.exe hello
How could i get this hello parametr in my program. How my program is able to read cmd line ?
:alright:
thanks for answering my stupid quest...
Posted on 2002-01-08 15:25:05 by Marty
Good question, want to know myself.

I am thinking the stack?
Posted on 2002-01-08 16:10:30 by -T-
Take a look at the GetCL function in the masm32 library (masm32.lib/inc, m32lib.hlp) from the masm package.

Thomas
Posted on 2002-01-08 16:30:55 by Thomas
Hi,

for non-MASM users :-)

call GetCommendLine

from kernel32.lib does the job.
BTW You have to strip off the appname from
the string and remember the difference in command line arguments when starting from dos box and windows.

Bye Miracle
Posted on 2002-01-09 04:32:42 by miracle
call GetCommandLine

:(
Posted on 2002-01-09 04:34:16 by miracle
I have been struggling with the same thing myself. I searched through some of the old posts and cobbled this together.

.DATA
command db ?
command2 db ?
stinfo db STARTUPINFO
pinfo db PROCESS_INFORMATION

.CODE

start:
invoke GetCL, 1, addr command
invoke GetCL, 2, addr command2
invoke MessageBox, NULL, addr command2, addr command, NULL
invoke ExitProcess, NULL
end start

Everything compiles fine and it will return command lines, however if I give it

test.exe hello world

I get output like command = hworld command2=world

I don?t know what I'm doing wrong. Maybe because I?m running on a Win 2k box? I have also tried the GetCommandLine approach but all of the string parsing that becomes necessary is difficult for a newbie to learn. With my get command line I was able to get the first argument by just adding 8 or 9 to the pointer but then how do I parse out just to the first space, and the get the data just after the first space? Anyhow maybe my example will help you figure it out. If you do let me know :)

P.S. anyone know where a good string tutorial is located. I found one in one of the old posts, but it was to thick with jargon for me to understand.
Posted on 2002-01-09 08:27:31 by emonk
emonk,

You've probably figured this out by now, but:

The problem is that you have only reserved one
byte each for

command db ?
command2 db ?

you need to do something like:

command db 60 dup(0)
command2 db 60 dup(0)

to allow room to store the command line arguments

farrier
Posted on 2002-01-09 17:22:38 by farrier
I just ran a couple of days ago over this little piece of code...

Written by Dolphinz:

I think this code will work enough, and get the command line parameters. Using the function GetCommandLineA(), will return us the the command line parameters.


call GetCommandLineA
mov edi,eax ; pointer of command line
mov ecx, -1 ; counter
mov al, 0 ; search byte
push edi ; save pointer
repnz scasb ; search for end of pointer
not ecx ; number of bytes read
pop edi ; pointer to command line
mov al, 20h ; search byte
repnz scasb ; get length of parameter
dec ecx ; skip extra space...
test ecx,ecx ; something there?
jnz command_line_ok
;
; Error occured
ret
command_line_ok:
; EDI = pointer to command line parameters.
Posted on 2002-01-09 18:08:41 by JimmyClif
Check out the API call CommandLineToArgvW also. It will take the string returned by GetCommandLine and parse it into a C style argv and argc. Haven't tried it yet but it may make some of the C people a little more at home.
Posted on 2002-01-09 19:44:54 by rdaneel
rdaneel, CommandLineToArgvW is only valid in windows xp.
Posted on 2002-01-09 21:30:17 by Betrayed
[b]Requirements:[/b]

Windows NT/2000/XP: Included in Windows NT 3.5 and later.
Windows 95/98/Me: Unsupported.
Header: Declared in Shellapi.h; include Windows.h.
Library: Use Shell32.lib.
Unicode: Implemented only as Unicode.
Posted on 2002-01-09 21:41:06 by bitRAKE
PlatformSDK says CommandLineToArgvW has been included since
NT 3.5. No 9x support though.

If you do GetCommandLine yourself, there's a few things to consider.
The first part will always be your executable name. This *should*
be a full path, possibly in the 8.3 tilde-name format. It might or
might not be quoted in \" quotes - you must handle both situations.
After your executable name comes a \0 or a (possibly variable) amount
of spaces.
Then comes parameters, which might or might not be \" quoted.

Yep, this is some parsing stuff to do, but once you got it right, you
can reuse it. Or just use GetCL, I presume it's written correctly
(and if you're using tasm, just make the switch to masm mmm'kay? ;)).
Posted on 2002-01-09 21:41:28 by f0dder
f0dder, I must have beat you mearly by seconds. :grin:

I would like to add that you must pass a Unicode string to CommandLineToArgvW.
(i.e. use GetCommandLineW)
Posted on 2002-01-09 21:58:59 by bitRAKE
Hrm, sorry about that. My version of msdn says its only valid with xp but when I look on the web I see other wise... Oh well you can never trust what you read.
Posted on 2002-01-10 21:51:12 by Betrayed