Please don't laugh if this question is too simple for you.

I am trying to write a programm which consists of several independent procedures. How can I make it take command line parameters for each procedure? For example test.exe /aaa and only aaa proc is processed?

Posted on 2002-08-11 14:48:43 by shafieian
Uhm.... read the commandline, compare it and call the suitable function?
Posted on 2002-08-11 15:04:55 by bazik
Conditional compilation, the IFDEF macro should prove most usefull.
Posted on 2002-08-11 22:36:23 by Ernie
How to do some (very) simple command line parsing:
For this recipe you will need -

1) New InString function available from all good cookery stores and here!
2) Some command line arguments.
3) An assembler (I prefere MASM, although some like the home grown variety), and linker.
4) The windows 32bit API.

Take the new InString function from its packaging, and paste in over the top of the old.
Be careful to keep a backup!
This should then be assemled, left to simmer for 15 minutes, then linked in to the all new masm32.lib

Take the command line arguments you've chosen, and add to the following code:

.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib

CmdLine dd 0
MyOption1 db "/aaa", 0

invoke GetCommandLine
mov CmdLine, eax

invoke InString, 1, CmdLine, ADDR MyOption1
or eax, eax
jle @F
invoke MessageBox, NULL, ADDR MyOption1, NULL, MB_OK

invoke ExitProcess, NULL

end start

I've added a generic option (MyOption1), but you of course can add any option you like, just remember to boil them thoroughly before adding them to the mix.

You will of course need to have multiple copies of the InString function call, once for each command line argument. You can always of course do something a little more daring than just call the MessageBox API! Just remember, if you include real code in there, the jle @F could cause problem, and you may have to use a more reliable label name.

Assemble, link, and season according to taste.

Serve piping hot, and maybe with a side helping of salad!

Mirno "The Naked Coder" - its not a pretty sight.
Posted on 2002-08-12 09:20:09 by Mirno