Im totaly lame in asm but i have to do some somethig.
I need to run program with i get from command line, but whne i use GetCommandLine I get sth like this: "C:\myprog.exe" C:\progtorun.exe . How can i get only C:\progrtorun.exe ? maybe you've got some sources

Posted on 2001-08-04 09:49:29 by lasic
You must parse the command line yourself an extract the parameters you need ...

I belive that WinMain also has a parameter that has the command line string without the program name itself maybe you can use that if you are lazy...

But its a simple string parseing routine, a good starting point for a newbie ;)
Posted on 2001-08-04 10:01:09 by BogdanOntanu
Bogdan, if I'm not much mistaken WinMain is C-specific, and the
string parsing handled by the C runtime startup code...
Posted on 2001-08-04 10:14:47 by f0dder
Maybe its true

i have been working with VC++ 6.0 too much lately (doh money makeing ;) )

but my win32API help say:

The WinMain function is called by the system as the initial entry point for a Windows-based application.

int WINAPI WinMain(

HINSTANCE hInstance, // handle of current instance
HINSTANCE hPrevInstance, // handle of previous instance
LPSTR lpszCmdLine, // pointer to command line
int nCmdShow // show state of window


Identifies the current instance of the application.


Identifies the previous instance of the application. For a Win32-based application, this parameter is always NULL.


Points to a null-terminated string specifying the command line for the application.


Specifies how the window is to be shown. This parameter can be one of the following values:

............. removed text here ..............

So its possible that OS calls your proggy entry point with those parameters on stack :) and C dosent get the credit here ;) dont you think?
Posted on 2001-08-04 10:21:30 by BogdanOntanu
Nope, coz MSDN is *very* much biased towards C :). Actually, on
entrypoint, there aren't much you can depend on... well, a RET *just*
on entrypoint will usually (9x, NT4, win2k, probably others as well)
take you to kernel32.ExitThread (or somethign similar), but but even
*that* is undocumented. So I'm 99.9% sure that it's the c
runtime libs doing the argv splitting...
Posted on 2001-08-04 10:28:37 by f0dder

You can find an example with comment in
The code is in GetGuidName function.

There is another way I can think of. You can use
GetCommandLineW instead of GetCommandLineA. The parse the
pointer returned by it using CommandLineToArgvW. It will give
you everything in argc, argv format. Needless to say, they are all
in Unicode.
Posted on 2001-08-04 12:35:39 by sjhenry

Finds the command line arguments within a given path.

LPTSTR PathGetArgs( LPCTSTR pszPath );

Parameters pszPath - A pointer to a string containing the path
to be searched.

Return Values -
Returns a pointer to a null-terminated string containing the arguments portion of the path if successful; if there are no arguments the function returns a pointer to the end of the input string. If the function is given a NULL agrument it returns NULL.

Version 4.71 and later of Shlwapi.dll

Windows NT/2000: Requires Windows 2000 (or Windows NT 4.0 with Internet Explorer 4.0 or later).
Windows 95/98: Requires Windows 98 (or Windows 95 with Internet Explorer 4.0 or later).
Header: Declared in shlwapi.h.
Import Library: shlwapi.lib.

good luck, G. Falen
Posted on 2001-08-04 13:21:19 by gfalen
When you are making your program be aware that quotes are not always needed/used. But if there is a quote then that file string ends at the next quote.

Also users happen to forget the second quote on an argument now and then, so make sure you check if the end of string is reached.
Posted on 2001-08-04 19:48:23 by Issvar
There is a simple approach here, the MASM32 library has 3 command line parsing procedures, you can either use them as is or use them as a basis to write your own.

Posted on 2001-08-04 20:09:48 by hutch--
I've got something like yours....
my prog was: someprog.exe and i needed to parse it a command line like C:\My proyects\progtorun.exe, so i've obtained
someprog.exe C:\My proyects\progtorun.exe
as argument. So my solution was (even not the best because i'm a newbie and i'm sure that there's a better one) to move the pointer x places to "C:\..."
it was something like that:
invoke GetCommandLine
mov argv, eax
add argv, 10
invoke main, argv

Posted on 2001-08-04 23:05:08 by MasmUser
Attached is an .ASM file that I wrote as part of
my very first Win32ASM program, (before I knew
about the command line routines already included
in MASM32). The attachment parses the CommandLine
taking into consideration:
1)No Arguments
2)Matching single (') and double (")quotes to
enclose literal arguments with spaces and quotes.

An array of 80 addresses is reserved to store the
address of the command line arguments. You can
then just go thru the array to handle all the

The only drawback is that the original command
line is itself modified by placing a Hex 0 at the
end of each argument so that each argument can
then be processed as a zero terminated string.

Posted on 2001-08-05 00:02:05 by farrier
Attachment for previous post now attached:

Posted on 2001-08-05 16:26:38 by farrier