I made few search queries here and there, found some stuff, but mainly useless stuff. Even stuff that made me have to use another person's DLL - does it sound reasonable ?? If I'd want to use external code I'd use C++ hehe :lol
So, after I got the command line and seperated it from my module name, how do I make something to be like the nice argv & argc of C++ ?
Please don't offer any external-dependant stuff coz I'm here to try and make original code.
If you wanna see what I got so far...
; #########################################################################
.486
.model flat, stdcall
option casemap :none ; case sensitive
; #########################################################################
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
; #########################################################################
Main proto
; #########################################################################
.data
CmdLine dd 0
szModuleName db 256 dup (0)
wModuleNameSize dword 0
; #########################################################################
.code
start:
call Main
invoke ExitProcess,0
Main proc
invoke GetModuleFileName,NULL,addr szModuleName,256
mov wModuleNameSize,eax
invoke GetCommandLine ;get cmd line
mov CmdLine,eax ;store it
mov eax,wModuleNameSize
add eax,2
add CmdLine,eax
mov eax,CmdLine
.if byte ptr [eax]==0 ;no cmd line?
ret ;bad
.else
.if byte ptr [eax+1]==0 ;checking for the damn SPACE :)
ret ;bad
.else
inc eax ;it seems like a real cmd line, so we cut off the SPACE
.endif
.endif
mov CmdLine,eax
;now CmdLine has the command line (without the module name and the other crap)
ret
Main endp
end start
Have a good evning everyone ! :U
Check the M32Lib for MASM32.
There are CommandLine ( CL ) functions in there already. Besides, the source is there for the functions, just in case you need to modify the source for your own use.
Regards, P1 :8)
eliran,
I have seen few command line procedures that use the architecture of the old C style argv-argc although I have seen it done somewhere. The author was a young guy called "f0dder". If you are not burdened by architecture of that age you have a couple of choices to use as examples from the masm32 library, the lowest level is a procedure called "ArgByNumber" which will either pick out arguments by their number or stream arguments until you get to the end of the command line.
It is actually a left to right table driven parser and while its speed is a bit overkill for something as short as a 32k command line, it is fast and flexible and you can do what you like with arguments as you stream through them.
I see. I just didn't like the fact that GetCL invokes GetCommandLine each time I call it. I'll see if I can modify it. Thank you all :clap:
eliran,
Here is a set of procedures to parse command line parameters both for GUI and console applications :
http://www.masmforum.com/simple/index.php?topic=166.0
invoke GetCommandLineW
invoke CommandLineToArgvW,eax,o temp
cmp temp,2
jne initiated
mov esi,[eax+4]
2 means exe and 1 paran
at [eax+4] is offset of second param in unicode so do
lodsw & stosb
Check the masm32lib help file in \masm32\help, there's a commandline section.
FWIW, for the February 2003 PSDK, src\crt\stdargv.c contains the source for the standard and wildcard _setargv routines.