How do i get the argv and argc array using Aurora?
The argv array and argc count are created by the C startup routine and are not a part of the Windows OS. You can, however, retrieve the entire command line used to start your executable using the API function GetCommandLineA/W
Here is a previous discussion on the subject:
http://www.ionicwind.com/forums/index.php/topic,59.15.html
Which includes code to parse the command line to create your own parameter array.
Paul.
I see, thanks.
Is there any chance of these being added natively to Aurora? as these are used alot.
Paul, i use modified consolestartup and winstartup where is a call to crtdll::__GetMainArgs, then argc and argv are passed to the main function.
The stack pointer is saved/restored in .bss section and i never got problems with this modification.
invoke __GetMainArgs, _argc, _argv, _env, 0
invoke main, [$_argc], [$_argv]
mov ÂÃ, Ã‚Ã, [_exitcode], eax
mov ÂÃ, Ã‚Ã, esp, [_stack]
...
segment .bss
$_argcÂÃ, Ã‚Ã, resd 1
$_argvÂÃ, Ã‚Ã, resd 1
$_envÂÃ, Ã‚Ã, resd 1
global sub main(int argc, string *argv[])
{
if (argc > 1) MessageBox(0, *(string)(argv[1]));
}
Kale, try this:
import int cdecl __GetMainArgs(int *argc, string *argv, string *environ, opt int unknown=0);
sub main()
{
int argc;
string *argv[1];
string *environ[1];
__GetMainArgs(&argc, &argv, &environ);
main2(argc, argv);
}
sub main2(int argc, string *argv[])
{
for (int a=0; a<argc; a++)
{
print("argument ",a," :", *(string)(argv[a]));
}
*argv[0] = readln();
}
Interesting hack Sapero. Although I do think it would be cool to have these added to Aurora. Either as an optional argument in main() or perhaps just as globals so you can access them anywhere.
Lewis
I agree this is something that should be built in. I like Paul's idea of GetArgCount and GetArgString. It's not hard to create a command line parser (especially for someone who created Aurora :D) but it's a really standard feature that should be included I think.
GetArgCount, GetArgString and GetArgStringW are now in Beta1 Rev 3. Available this evening to a computer near you ;)
Quote from: Paul Turley on November 06, 2006, 06:01:44 PM
GetArgCount, GetArgString and GetArgStringW are now in Beta1 Rev 3. Available this evening to a computer near you ;)
Very Very Cool! Thanks Paul! :D
Thanks, that'll be a nice addition.