Hi,
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?
Thanks
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?
Thanks
Uhm.... read the commandline, compare it and call the suitable function?
Conditional compilation, the IFDEF macro should prove most usefull.
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.
Step1:
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
Step2:
Take the command line arguments you've chosen, and add to the following code:
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.
Step3:
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.
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.
Step1:
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
Step2:
Take the command line arguments you've chosen, and add to the following code:
.486
.model flat,stdcall
option casemap:none
.nolist
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
.list
.data
CmdLine dd 0
MyOption1 db "/aaa", 0
.code
start:
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.
Step3:
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.