News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

argc andd argv ??????/

Started by pwnpwn, August 28, 2010, 04:58:05 PM

Previous topic - Next topic

bomz

this code may work uncorrect in one case, when you start program from the shell menu and use in registry
HKEY_CLASSES_ROOT\*\shell
"PATH\MYPROG.exe" "%1"
strange, but system add one space, like you start it from batch file as:
"PATH\MYPROG.exe"  "%1"
so you may use:
"PATH\MYPROG.exe""%1"  - in registry

or add to code

;cmp byte ptr [eax], ' '
;jne No_Shell
;inc eax
;No_Shell:

name of file can't begin from space so this code stay  universal.
I can't say anything about "microsoft command line from shell menu rules" so I comment this strings

GregL

bomz,

For what it's worth,  attached is an example of using __getmainargs to get argc and argv.

bomz

#17
I prefer not use macros, you write code once and when may use it always. but thanks I read code this interesting. I need to read help for masm

even invoke....
it's difficult to say using English: ~ author of topic (and others) need some simple tasks to learn assembler. if he C programmer there is no sense to learn assembler he needs stay in object(?) logics. if he understand how work this code, ready part give him expectation(?) he may still in assembler. C good language with powerful compiling, I am sure have possibility to use assembler includes for huge computations.

Vortex

Hi bomz,

Here is another example for you.


include CmdLineParam.inc

.data

_format     db 'Command line parameter %d = %s',13,10,0

.data?

buffer      db 256 dup(?)

.code

main PROC C USES ebx esi edi argc:DWORD,argv:DWORD

    xor     edi,edi

    mov     ebx,argc    ; number of command line parameters
    mov     esi,argv    ; pointer to the array of command line parameters

@@:

    add     edi,1
    invoke  wsprintf,ADDR buffer,ADDR _format,edi,DWORD PTR [esi]
    invoke  StdOut,ADDR buffer
    add     esi,4
    dec     ebx
    jnz     @b

    ret

main ENDP

END


I recommend you to study Greg's code. It's a nice example showing how to use the C run-time library function __getmainargs

bomz

#19
yeah
Quote
Msvcrt.dll

Msvcrt.dll is the Microsoft Visual C++ Run-Time for Visual C++ versions 4.2 to 6.0. It provides programs compiled with these versions of Visual C++ a typical set of library functions required by C and C++ programs. These include string manipulation, memory allocation, C-style input/output calls, etc.

It has also shipped with Windows versions since Windows 2000 for use by other Windows components. In older versions of Windows, programs which linked against Msvcrt.dll were expected to install a compatible copy in the System32 folder, but this contributed to DLL Hell.

Versions of Visual C++ before 4.0 and since 7.0 have used differently named DLLs for each version (msvcr20.dll, msvcr70.dll, msvcr71.dll, etc). Applications are required to install the appropriate version.[4]
why you use masm for C library?

that code need for non english windows
invoke CharToOem, addr buffer, addr String


invoke lstrlen, addr String
Quote
lea edi,String
xor ecx,ecx
dec ecx
xor eax,eax
cld
repnz scasb
not ecx
dec ecx

jj2007

#20
What is expert opinion on this commandline:
get cl.exe arg1 "second arg"   'third arg' fourth_arg

Masm32 yields this:
arg #0 =        get cl.exe
arg #1 =        arg1
arg #2 =        second arg
arg #3 =        'third
arg #4 =        arg'
arg #5 =        fourth_arg


The fact that it splits 'third arg' is somewhat irritating. MSDN has apparently no clearly defined rules. Would you expect one arg returned for 'third arg'?? I would.

On a side note:
Quote
[when launching CommandLineCheck -a testing, ]GetCommandLine() api returns CommandLineCheck -a testing.

The same command if I run in windows 2008, then the api returns CommandLineCheck  -a testing.
Please note that there is two spaces between exe name(CommandLineCheck) and the option(-a) provided.
http://social.msdn.microsoft.com/Forums/en/vclanguage/thread/5e737981-3ce1-4742-aa84-9d3f8c7a6b1d
(with various comments attempting to justify this broken API :green2)

bomz

if you mean two spaces between parameteres - I analyze today how INVOKE crt___getmainargs works. because it from C library, as I know microsoft supports C so I may be sure in it absolutely correct reaction on double spaces. I don't know why they need this construction - 'double spaces', but C library cut(ignore) one of them

' is not equal to "

to better understand logics of command line subroutine -  so batch file

MYPROG.EXE "%1"
batch compatibility

but when you use commandline in your programs and your parameters is not path you may use your own subroutine like that
-help
-h
/help

GregL

Quote from: VortexI recommend you to study Greg's code. It's a nice example showing how to use the C run-time library function __getmainargs

Thanks Vortex.